Form_Home.cs 592 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using Microsoft.Win32;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using HslCommunication.LogNet;
  13. using MainForm.FaForm;
  14. using Sunny.UI;
  15. using MainForm.ClassFile.XiaomiAPI;
  16. using System.Diagnostics;
  17. using MainForm.Models;
  18. using SqlSugar;
  19. using EasyModbus;
  20. using ModBusClientSimple.Util;
  21. using csharp_networkprotocol_hpsocket;
  22. using MqttnetServerWin;
  23. using Sunny.UI.Win32;
  24. using MainForm.ClassFile.XiaomiAPI_AGV;
  25. using MainForm.ClassFile.XiaomiAPI_RouteCom;
  26. using HslCommunication.Controls;
  27. using EIP_Protocol;
  28. using MainForm.ClassFile.XiaomiAPI_MES;
  29. using NPOI.Util;
  30. using static MainForm.SQLHelper;
  31. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationInbound;
  32. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound;
  33. using MainForm.ClassFile.ProjectClass;
  34. using CommonLib;
  35. using Org.BouncyCastle.Asn1.IsisMtt;
  36. using System.Web.Services.Description;
  37. using System.Numerics;
  38. using MathNet.Numerics.RootFinding;
  39. using HslCommunication.Enthernet;
  40. /*
  41. * 注:本源码对外提供,所以有些地方使用中文命名方法及变量
  42. */
  43. namespace MainForm
  44. {
  45. /// <summary>
  46. /// 记录日志的委托
  47. /// </summary>
  48. /// <param name="logType">日志类型</param>
  49. /// <param name="message">日志信息</param>
  50. public delegate void HomeMessageHandler(LogType logType, string message);
  51. /// <summary>
  52. /// 主页窗体
  53. /// </summary>
  54. public partial class Form_Home : Form
  55. {
  56. #region 常量
  57. //文本常量
  58. private const string Head = "开始采集";
  59. private const string Tail = "采集完成";
  60. private const string Body = "工位出站数据";
  61. private const string BodyCheck = "工位点检数据";
  62. private const string BodyRun = "整线运行数据";
  63. private const string BodyAlarm = "整线报警数据";
  64. #endregion 常量
  65. #region 变量
  66. /// <summary>
  67. /// 委托-记录日志的方法
  68. /// </summary>
  69. public event HomeMessageHandler MessageEvent;
  70. /// <summary>
  71. /// 日志接口
  72. /// </summary>
  73. ILogNet _PLCLogNet;
  74. /// <summary>
  75. /// 用于记录IOT MQTT日志
  76. /// </summary>
  77. ILogNet _IOTMqttLogNet;
  78. /// <summary>
  79. /// 用于记录AGV MQTT日志
  80. /// </summary>
  81. ILogNet _AGVMqttLogNet;
  82. //private int DataSwitch = 1; // 1-SQLServer;2-Excel
  83. // 定义信号量,index0给MES(true有信号,false无信号;set()让被控线程运行,Reset()让被控线程停止;WaitOne(等待时间)等待线程运行)
  84. // 间隔时间
  85. private int IntervalReadPLC = 300; //ms 读PLC
  86. private int IntervalMonitorMES = 1000; //ms MES心跳
  87. private int IntervalAlarm = 1000; //ms 数据(报警)查询与设备运行信息
  88. // 软件状态
  89. private bool IsRun = true;
  90. #region PLC 与 TCP对象
  91. // 定义一个字典,存plc对象(通讯)
  92. ModbusClientHelper plc1Alarm; // PLC‘运行数据’与‘报警数据’线程用ModbusTCP
  93. Dictionary<int, ModbusClientHelper> Funs = new Dictionary<int, ModbusClientHelper>();
  94. // 定义TCPClient对象列表
  95. Dictionary<int, HPSocket_TcpClientHelper> _HPSocket_TcpClients = new Dictionary<int, HPSocket_TcpClientHelper>();
  96. // 定义MQTTHelper对象
  97. MQTTHelper _MQTTHelper = new MQTTHelper();
  98. #endregion PLC 与 TCP对象
  99. /// <summary>
  100. /// 上次的设备运行信息
  101. /// </summary>
  102. private string lineWorkingData1_OldStr = string.Empty;
  103. /// <summary>
  104. /// 设备报警字典-当前结果
  105. /// Dictionary<工位代码,List<报警信息>>
  106. /// </summary>
  107. private Dictionary<string, List<Alarm>> DicAlarms_Cur = new Dictionary<string, List<Alarm>>();
  108. Dictionary<int, Inovance_EIP> FunsEip = new Dictionary<int, Inovance_EIP>();
  109. /// <summary>
  110. /// 单机用-设备状态
  111. /// </summary>
  112. XiaomiDeviceState xmDeviceState = XiaomiDeviceState.Uninitialized;
  113. #endregion 变量
  114. #region 窗体基础事件
  115. /// <summary>
  116. /// 初始化
  117. /// </summary>
  118. public Form_Home()
  119. {
  120. InitializeComponent();
  121. CheckForIllegalCrossThreadCalls = false; // 不检查跨线程访问
  122. _PLCLogNet = new LogNetDateTime(GlobalContext.PlcLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  123. _IOTMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  124. _AGVMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  125. GlobalContext.Set += new Action(UpdateProductInfo); // 产品信息变化时更新UI
  126. }
  127. /// <summary>
  128. /// 窗体加载事件
  129. /// </summary>
  130. private void Form_Home_Load(object sender, EventArgs e)
  131. {
  132. try
  133. {
  134. AddMessage(LogType.Info, "开始初始化程序");
  135. InitalDicAlarm(); // 实例化报警字典
  136. //组建plc对象字典
  137. //plc1Alarm = new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort);
  138. //plc1Alarm = new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine1Address);
  139. if (GlobalContext.IsUsePLC1)
  140. FunsEip.Add(1, new Inovance_EIP(GlobalContext.PC1Address, GlobalContext.Machine1Address)); //OP10 壳体清洁上料装备
  141. //Funs.Add(1, new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort, 2001)); // Tray盘上料装备(板测)
  142. if (GlobalContext.IsUsePLC2)
  143. //Funs.Add(2, new ModbusClientHelper(GlobalContext.Machine2Address, GlobalContext.MachinePort, 2001)); // FCT(板测),
  144. FunsEip.Add(2, new Inovance_EIP(GlobalContext.PC2Address, GlobalContext.Machine2Address)); //OP20 顶盖上料设备
  145. if (GlobalContext.IsUsePLC3)
  146. FunsEip.Add(3, new Inovance_EIP(GlobalContext.PC3Address, GlobalContext.Machine3Address)); //OP30 点胶设备
  147. //Funs.Add(3, new ModbusClientHelper(GlobalContext.Machine3Address, GlobalContext.MachinePort, 2001)); // 值板机,
  148. if (GlobalContext.IsUsePLC4)
  149. FunsEip.Add(4, new Inovance_EIP(GlobalContext.PC4Address, GlobalContext.Machine4Address)); //OP40 3D胶线检测
  150. //Funs.Add(4, new ModbusClientHelper(GlobalContext.Machine4Address, GlobalContext.MachinePort, 2001)); // 取放桁
  151. if (GlobalContext.IsUsePLC5)
  152. FunsEip.Add(5, new Inovance_EIP(GlobalContext.PC5Address, GlobalContext.Machine5Address)); //OP50 ADD PCB板上料
  153. //Funs.Add(5, new ModbusClientHelper(GlobalContext.Machine5Address, GlobalContext.MachinePort, 2001)); //Tray盘下料装备
  154. if (GlobalContext.IsUsePLC6)
  155. FunsEip.Add(6, new Inovance_EIP(GlobalContext.PC6Address, GlobalContext.Machine6Address)); //OP60 顶盖装配
  156. if (GlobalContext.IsUsePLC7)
  157. FunsEip.Add(7, new Inovance_EIP(GlobalContext.PC7Address, GlobalContext.Machine7Address)); //OP70 锁螺丝
  158. if (GlobalContext.IsUsePLC8)
  159. FunsEip.Add(8, new Inovance_EIP(GlobalContext.PC8Address, GlobalContext.Machine8Address)); //OP80 3D螺丝高度检测,NG出料站
  160. if (GlobalContext.IsUsePLC9)
  161. FunsEip.Add(9, new Inovance_EIP(GlobalContext.PC9Address, GlobalContext.Machine9Address)); //OP90 下料站
  162. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  163. {
  164. if (plcEIP != null)
  165. {
  166. try
  167. {
  168. (int, string) result = plcEIP.Connect();
  169. }
  170. catch (Exception ex)
  171. {
  172. MessageBox.Show($"PLC[{plcEIP._pcIPStr}]连接失败!失败信息:" + ex.Message,
  173. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  174. }
  175. }
  176. }
  177. /*
  178. //plc1Alarm.Connect();
  179. foreach (ModbusClientHelper modbusClient in Funs.Values)
  180. {
  181. if (modbusClient != null)
  182. {
  183. try
  184. {
  185. modbusClient.Connect();
  186. }
  187. catch (Exception ex)
  188. {
  189. MessageBox.Show($"PLC[{modbusClient.IPAddress}:{modbusClient.Port}]连接失败!失败信息:" + ex.Message,
  190. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  191. }
  192. }
  193. }
  194. */
  195. // 采集任务
  196. Task TaskReadAlarm = new Task(ReadAlarmAllPLC); // 线程-获取线体报警数据
  197. List<Task> TaskReadProcess = new List<Task>(); // 线程-触发点位(PLC)的线程
  198. //TaskReadProcess.Add(new Task(() => { ReadStation_DownOrderInfo(1); })); // 下发机种
  199. if (GlobalContext.IsUsePLC1)
  200. TaskReadProcess.Add(new Task(() => { ReadStation_S1(1); })); //OP10 壳体清洁上料装备
  201. if (GlobalContext.IsUsePLC2)
  202. TaskReadProcess.Add(new Task(() => { ReadStation_S2(2); })); //OP20 顶盖上料设备
  203. if (GlobalContext.IsUsePLC3)
  204. TaskReadProcess.Add(new Task(() => { ReadStation_S3(3); })); //OP30 点胶设备
  205. if (GlobalContext.IsUsePLC4)
  206. TaskReadProcess.Add(new Task(() => { ReadStation_S4(4); })); //OP40 点胶检测设备
  207. if (GlobalContext.IsUsePLC5)
  208. TaskReadProcess.Add(new Task(() => { ReadStation_S5(5); })); //OP50 ADD PCB板上料设备
  209. if (GlobalContext.IsUsePLC6)
  210. TaskReadProcess.Add(new Task(() => { ReadStation_S6(6); })); //OP60 顶盖装配设备
  211. if (GlobalContext.IsUsePLC7)
  212. TaskReadProcess.Add(new Task(() => { ReadStation_S7(7); })); //OP70 锁螺丝设备
  213. if (GlobalContext.IsUsePLC8)
  214. TaskReadProcess.Add(new Task(() => { ReadStation_S8(8); })); //OP80 3D螺丝高度检测设备
  215. if (GlobalContext.IsUsePLC9)
  216. TaskReadProcess.Add(new Task(() => { ReadStation_S9(9); }));
  217. #region 初始化
  218. try
  219. {
  220. // 开启边线MES(绑定/查询数据)
  221. //int mesRoute = XiaomiMES_RouteCommunication.Init();
  222. //if (mesRoute == 0)
  223. //{
  224. // //picMESStatus.Image = imageListState.Images[1];
  225. // //GlobalContext.MESIsConnect = true;
  226. // AddMessage(LogType.Info, "小米MES边线初始连接成功!");
  227. //}
  228. //else
  229. //{
  230. // //picMESStatus.Image = imageListState.Images[0];
  231. // //GlobalContext.MESIsConnect = false;
  232. // AddMessage(LogType.Info, $"小米MES边线初始连接失败!");
  233. //}
  234. // 开启MES(Http)
  235. if (GlobalContext.IsUseMES)
  236. {
  237. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  238. if (mesret)
  239. {
  240. picMESStatus.Image = imageListState.Images[1];
  241. GlobalContext.MESIsConnect = true;
  242. AddMessage(LogType.Info, "小米MES初始连接成功!");
  243. }
  244. else
  245. {
  246. picMESStatus.Image = imageListState.Images[0];
  247. GlobalContext.MESIsConnect = false;
  248. AddMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]初始连接失败!");
  249. }
  250. }
  251. // 开启IOT(MQTT)
  252. if (GlobalContext.IsUseIot)
  253. {
  254. string addr = GlobalContext.MQTTServerHost;
  255. int port = GlobalContext.MQTTServerPort;
  256. //生产环境需要修改
  257. int qmttResult = XiaomiMqttClient_Extend.OpenWithMqttServer("127.0.0.1", 6666, GlobalContext.MqttServerPath, GlobalContext.MqttServerName);
  258. XiaomiMqttResponse_ErrCode response_ErrCode = (XiaomiMqttResponse_ErrCode)qmttResult;
  259. if (response_ErrCode == XiaomiMqttResponse_ErrCode.OK)
  260. {
  261. picIot.Image = imageListState.Images[1];
  262. AddMessage(LogType.Info, "小米IOT MQTT初始连接成功!");
  263. // 设置回调函数
  264. //XiaomiMqttClient_Extend.SetCallbackWithDataId(CallbackWithDataId);
  265. // 配置参数
  266. XiaomiMqttLoginFunAndParam param = new XiaomiMqttLoginFunAndParam();
  267. XiaomiMqttLoginFunAndParam2Station param2 = new XiaomiMqttLoginFunAndParam2Station();
  268. // fds
  269. param.parameter.fds.address = "http://file-cm.be.mi.com/file/x5/file/upload/mqtt";
  270. param.parameter.fds.appId = "Auto-Soft";
  271. param.parameter.fds.appKey = "d11ec2b9-0e7a-4086-a80c-a1ec716e0896";
  272. // mes
  273. param.parameter.mes.address = GlobalContext.ServerIp;
  274. param.parameter.mes.appId = GlobalContext.MESAppId;
  275. param.parameter.mes.appKey = GlobalContext.MESAppKey;
  276. // mqtt
  277. param.parameter.mqtt.address = GlobalContext.MQTTServerHost;
  278. param.parameter.mqtt.port = GlobalContext.MQTTServerPort;
  279. param.parameter.mqtt.username = GlobalContext.MQTTAppId;
  280. param.parameter.mqtt.password = GlobalContext.MQTTAppPwd;
  281. // 设备配置
  282. param.parameter.equipment.factoryCode = GlobalContext.Factory_Code;
  283. if (GlobalContext.IsUsePLC1)
  284. {
  285. param.parameter.equipment.deviceCode = GlobalContext.S1_device_code; // 装备编码
  286. param.parameter.equipment.stationCode = GlobalContext.S1_station; // ⼯位Id
  287. }
  288. if (GlobalContext.IsUsePLC2)
  289. {
  290. param.parameter.equipment.deviceCode = GlobalContext.S2_device_code; // 装备编码
  291. param.parameter.equipment.stationCode = GlobalContext.S2_station; // ⼯位Id
  292. }
  293. if (GlobalContext.IsUsePLC3)
  294. {
  295. param2.left.parameter.equipment.deviceCode = GlobalContext.s3_1_device_code; // 装备编码
  296. param2.left.parameter.equipment.stationCode = GlobalContext.s3_1_station; // ⼯位Id
  297. param2.right.parameter.equipment.deviceCode = GlobalContext.s3_2_device_code; // 装备编码
  298. param2.right.parameter.equipment.stationCode = GlobalContext.s3_2_station; // ⼯位Id
  299. }
  300. if (GlobalContext.IsUsePLC4)
  301. {
  302. param.parameter.equipment.deviceCode = GlobalContext.s4_device_code; // 装备编码
  303. param.parameter.equipment.stationCode = GlobalContext.s4_station; // ⼯位Id
  304. }
  305. if (GlobalContext.IsUsePLC5)
  306. {
  307. param.parameter.equipment.deviceCode = GlobalContext.s5_device_code; // 装备编码
  308. param.parameter.equipment.stationCode = GlobalContext.s5_station; // ⼯位Id
  309. }
  310. if (GlobalContext.IsUsePLC6)
  311. {
  312. param.parameter.equipment.deviceCode = GlobalContext.s6_device_code; // 装备编码
  313. param.parameter.equipment.stationCode = GlobalContext.s6_station; // ⼯位Id
  314. }
  315. if (GlobalContext.IsUsePLC7)
  316. {
  317. param2.left.parameter.equipment.deviceCode = GlobalContext.s7_1_device_code; // 装备编码
  318. param2.left.parameter.equipment.stationCode = GlobalContext.s7_1_station; // ⼯位Id
  319. param2.right.parameter.equipment.deviceCode = GlobalContext.s7_1_device_code; // 装备编码
  320. param2.right.parameter.equipment.stationCode = GlobalContext.s7_1_station; // ⼯位Id
  321. }
  322. if (GlobalContext.IsUsePLC8)
  323. {
  324. param.parameter.equipment.deviceCode = GlobalContext.s8_device_code; // 装备编码
  325. param.parameter.equipment.stationCode = GlobalContext.s8_station; // ⼯位Id
  326. }
  327. if (GlobalContext.IsUsePLC9)
  328. {
  329. param.parameter.equipment.deviceCode = GlobalContext.s9_device_code; // 装备编码
  330. param.parameter.equipment.stationCode = GlobalContext.s9_station; // ⼯位Id
  331. }
  332. param.parameter.equipment.project = GlobalContext.Project_Code;
  333. param.parameter.equipment.productMode = "debug";
  334. //
  335. param.parameter.other.logLevel = 0;
  336. param.parameter.other.LogPath = "D:\\Test";
  337. XiaomiMqttClient_Extend.ParameterConfig(param);
  338. }
  339. else
  340. {
  341. picIot.Image = imageListState.Images[0];
  342. AddMessage(LogType.Info, $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]初始连接失败!--- {response_ErrCode.ToString()}");
  343. }
  344. }
  345. // 开启AGV(Http与MQTT)
  346. if (GlobalContext.IsUseAGV)
  347. {
  348. // AGV HTTP
  349. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  350. if (mesret1)
  351. {
  352. picAgvHttp.Image = imageListState.Images[1];
  353. AddMessage(LogType.Info, "AGV Http初始连接成功!");
  354. }
  355. else
  356. {
  357. picAgvHttp.Image = imageListState.Images[0];
  358. AddMessage(LogType.Info, $"AGV Http[{GlobalContext.AGVHttpHost}]初始连接失败!");
  359. }
  360. string agvMqttIp = GlobalContext.MQTTServerHost;
  361. int agvMqttPort = GlobalContext.MQTTServerPort;
  362. Action<ResultData_MQTT> callback = AGVMqttShowLog;
  363. ResultData_MQTT result_MQTT = _MQTTHelper.CreateMQTTClientAndStart(agvMqttIp, agvMqttPort, null, null, callback).Result; // 连接MQTT服务器
  364. // AGV MQTT
  365. if (result_MQTT.ResultCode == 1)
  366. {
  367. picAgvMqtt.Image = imageListState.Images[1];
  368. GlobalContext.AGVMQTTIsConnect = true;
  369. AddMessage(LogType.Info, "小米AGV MQTT初始连接成功!");
  370. ResultData_MQTT result = XiaomiAGVMQTT_Base.DeviceTopicAGV(ref _MQTTHelper, GlobalContext.AGVMQTTDeviceCode);
  371. AddMessage(LogType.Info, $"小米AGV MQTT订阅{GlobalContext.AGVMQTTDeviceCode}--- [{result.ResultCode}]{result.ResultMsg}!");
  372. }
  373. else
  374. {
  375. picAgvMqtt.Image = imageListState.Images[0];
  376. GlobalContext.AGVMQTTIsConnect = false;
  377. AddMessage(LogType.Info, $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]初始连接失败!--- [{result_MQTT.ResultCode}]{result_MQTT.ResultMsg}");
  378. }
  379. }
  380. // 持续监视MES、IOT、AGV HTTP、AGV MQTT连接状态
  381. Task.Run(MonitorMESConnect);
  382. // 查询PLC连接状态
  383. foreach (int plcNo in FunsEip.Keys)
  384. {
  385. bool connected = FunsEip[plcNo].IsConnected;
  386. if (connected)
  387. {
  388. string msg = plcNo.ToString() + "工位初始连接成功---" + FunsEip[plcNo]._pcIPStr;
  389. AddMessage(LogType.Info, msg);
  390. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI
  391. }
  392. else
  393. {
  394. string msg = plcNo.ToString() + "工位初始连接失败---" + FunsEip[plcNo]._pcIPStr;
  395. AddMessage(LogType.Info, msg);
  396. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  397. }
  398. }
  399. // PLC4时 初始化扫码器TCP
  400. //if (GlobalContext.IsUsePLC4)
  401. // HpTCPClientInit();
  402. // 开启PLC的业务处理线程-监听PLC点位+状态
  403. foreach (Task task in TaskReadProcess)
  404. {
  405. if (task != null)
  406. task.Start();
  407. }
  408. //// 开启iot的线程
  409. TaskReadAlarm.Start();
  410. ////下传MES信息给1工位(先判断下plc对象数量)
  411. //if (Funs.Count > 1)
  412. // DownLoadProductInfo(1);
  413. AddMessage(LogType.Info, "程序初始化完成");
  414. }
  415. catch (Exception ex)
  416. {
  417. string str = ex.StackTrace;
  418. this.BeginInvoke(new Action(() =>
  419. {
  420. AddMessage(LogType.Error, "初始化PLC连接失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  421. }));
  422. }
  423. #endregion
  424. }
  425. catch (Exception ex)
  426. {
  427. string str = ex.StackTrace;
  428. OnMessage(LogType.Info, "主窗体的首页初始化出错!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
  429. if (ex.Message != null && ex.Message.Contains("timed out"))
  430. MessageBox.Show("主窗体的首页初始化出错!异常信息:PLC连接超时!" + ex.Message);
  431. else
  432. MessageBox.Show("主窗体的首页初始化出错!异常信息:" + ex.Message);
  433. }
  434. }
  435. /// <summary>
  436. /// 窗体关闭事件
  437. /// </summary>
  438. private void Form_Home_FormClosed(object sender, FormClosedEventArgs e)
  439. {
  440. Closed2();
  441. }
  442. public void Closed2()
  443. {
  444. try
  445. {
  446. IsRun = false;
  447. Thread.Sleep(IntervalReadPLC);
  448. // 断开TCP
  449. int count = _HPSocket_TcpClients.Count();
  450. for (int i = 0; i < count; i++)
  451. {
  452. try
  453. {
  454. if (_HPSocket_TcpClients[i] != null && _HPSocket_TcpClients[i]._client.IsConnected)
  455. {
  456. _HPSocket_TcpClients[i].Stop();
  457. _HPSocket_TcpClients[i]._client.OnPrepareConnect -= OnPrepareConnect; // 准备连接了事件
  458. _HPSocket_TcpClients[i]._client.OnConnect -= OnConnect; // 连接事件
  459. _HPSocket_TcpClients[i]._client.OnSend -= OnSend; // 数据包发送事件
  460. _HPSocket_TcpClients[i]._client.OnReceive -= OnReceive; // 数据包到达事件
  461. _HPSocket_TcpClients[i]._client.OnClose -= OnClose; // TCP连接关闭事件
  462. }
  463. }
  464. catch { }
  465. }
  466. // 关闭Iot
  467. try { XiaomiMqttClient_Extend.CloseWithMqttServer(GlobalContext.MqttServerPath, GlobalContext.MqttServerName); } catch { }
  468. // 关闭AGV Mqtt
  469. try { _MQTTHelper.DisconnectAsync_Client().Wait(); } catch { }
  470. }
  471. catch { }
  472. }
  473. #endregion 窗体基础事件
  474. #region 监控MES状态
  475. /// <summary>
  476. /// 监控MES连接状态
  477. /// </summary>
  478. private void MonitorMESConnect()
  479. {
  480. while (IsRun) // 运行被控线程
  481. {
  482. try
  483. {
  484. // 开启MES(Http)
  485. if (GlobalContext.IsUseMES)
  486. {
  487. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  488. if (mesret)
  489. {
  490. picMESStatus.Image = imageListState.Images[1];
  491. GlobalContext.MESIsConnect = true;
  492. }
  493. else
  494. {
  495. picMESStatus.Image = imageListState.Images[0];
  496. GlobalContext.MESIsConnect = false;
  497. OnMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]连接失败");
  498. }
  499. }
  500. // 开启IOT(MQTT)
  501. if (GlobalContext.IsUseIot)
  502. {
  503. bool iIot = XiaomiMqttClient.IsOpen;
  504. if (iIot)
  505. picIot.Image = imageListState.Images[1];
  506. else
  507. {
  508. picIot.Image = imageListState.Images[0];
  509. OnMessage(LogType.Info, $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]连接失败");
  510. }
  511. }
  512. // 开启AGV(Http与MQTT)
  513. if (GlobalContext.IsUseAGV)
  514. {
  515. // AGV Http
  516. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  517. if (mesret1)
  518. picAgvHttp.Image = imageListState.Images[1];
  519. else
  520. {
  521. picAgvHttp.Image = imageListState.Images[0];
  522. OnMessage(LogType.Info, $"小米AGV Http[{GlobalContext.AGVHttpHost}]连接失败");
  523. }
  524. // AGV MQTT
  525. if (GlobalContext.AGVMQTTIsConnect)
  526. picAgvMqtt.Image = imageListState.Images[1];
  527. else
  528. {
  529. picAgvMqtt.Image = imageListState.Images[0];
  530. OnMessage(LogType.Info, $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]连接失败");
  531. }
  532. }
  533. }
  534. catch (Exception ex)
  535. {
  536. string str = ex.StackTrace;
  537. AddMessage(LogType.Error, "监控MES心跳失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  538. }
  539. Thread.Sleep(IntervalMonitorMES);
  540. }
  541. }
  542. #endregion 监控MES连接状态
  543. #region 采集设备状态、运行数据、报警数据
  544. /// <summary>
  545. /// 请求设备状态 5000
  546. /// </summary>
  547. /// <param name="no">1</param>
  548. /// <param name="stationNameStr"></param>
  549. /// <returns>0:证明未连接到PLC;1,代表设备控制状态处于运行状态;2,代表设备控制状态处于故障状态;3,代表设备控制状态处于缺料状态;4,代表设备控制状态处于待机状态;5,代表设备控制状态处于维修状态;</returns>
  550. public int GetDeviceStatus(int plcNo, string stationNameStr = "[S0]壳体上料")
  551. {
  552. try
  553. {
  554. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  555. {
  556. short result = Funs[plcNo].ReadHoldingRegisters<short>(5000); // 5000
  557. return result;
  558. }
  559. else
  560. {
  561. return 0;
  562. }
  563. }
  564. catch (Exception ex)
  565. {
  566. string str = ex.StackTrace;
  567. AddMessage_Station(stationNameStr, LogType.Error, "请求设备状态失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  568. return 0;
  569. }
  570. }
  571. /// <summary>
  572. /// 检查是否可采集点检数据 - 不取新值
  573. /// 5000不为1时可点检
  574. /// </summary>
  575. /// <returns></returns>
  576. public bool CheckCanSpotcheck1(int deviceState)
  577. {
  578. //return true;
  579. //D5000 = 1,代表设备控制状态处于运行状态
  580. //D5000 = 2, 代表设备控制状态处于故障状态
  581. //D5000 = 3,代表设备控制状态处于缺料状态
  582. //D5000 = 4, 代表设备控制状态处于待机状态
  583. //D5000 = 5,代表设备控制状态处于维修状态
  584. return deviceState != 1;
  585. }
  586. /// <summary>
  587. /// 检查是否可采集产品数据 - 不取新值
  588. /// </summary>
  589. /// <returns></returns>
  590. public bool CheckCanCollData(int deviceState)
  591. {
  592. return deviceState == 0; // 点检时该值不为0
  593. }
  594. /// <summary>
  595. /// 采集到的设备状态
  596. /// </summary>
  597. private string _DeviceStates = "未知状态";
  598. private string _DeviceStates_Old = "未知状态";
  599. /// <summary>
  600. /// 获取设备报警数据与获取设备运行信息
  601. /// </summary>
  602. private async void ReadAlarmAllPLC()
  603. {
  604. // [S1] Tray盘上料装备(板测)
  605. // [S2] FCT(板测)
  606. // [S3] 值板机
  607. // [S4] 取放桁架
  608. // [S5] Tray盘下料装备
  609. /// 上位机心跳
  610. /// 获取设备报警数据与状态信息
  611. string stationNameStr = "获取设备报警数据与状态信息";
  612. // 已连接到PLC
  613. while (IsRun)
  614. {
  615. try
  616. {
  617. //if (!GlobalContext._IsCon_plc1Alarm)
  618. //{
  619. // UpdatePLCMonitor(1, -2, 0);
  620. // continue;
  621. //}
  622. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  623. {
  624. if (plcEIP != null)
  625. {
  626. if (plcEIP.IsConnected)
  627. {
  628. #region 主页展示设备运行状态并上传到IOT中
  629. switch (xmDeviceState)
  630. {
  631. case XiaomiDeviceState.Uninitialized: // 未初始化状态(未初始状态,需先初始化装备才能运行)
  632. _DeviceStates = "未初始化状态";
  633. lblDeviceStates.Text = _DeviceStates;
  634. break;
  635. case XiaomiDeviceState.Initializing: // 初始化状态(初始化进行中)
  636. _DeviceStates = "初始化状态";
  637. lblDeviceStates.Text = _DeviceStates;
  638. break;
  639. case XiaomiDeviceState.Initialized: // 初始化完成状态(初始化完成)
  640. _DeviceStates = "初始化完成状态";
  641. lblDeviceStates.Text = _DeviceStates;
  642. break;
  643. case XiaomiDeviceState.Running: // 运行状态(正常运行中)
  644. _DeviceStates = "运行状态";
  645. lblDeviceStates.Text = _DeviceStates;
  646. break;
  647. case XiaomiDeviceState.Paused: // 暂停状态(设备运行中人工操作暂停,进入此状态)
  648. _DeviceStates = "暂停状态";
  649. lblDeviceStates.Text = _DeviceStates;
  650. break;
  651. case XiaomiDeviceState.Fault: // 故障状态(发生故障后进入此状态,同时停止运行)
  652. _DeviceStates = "故障状态";
  653. lblDeviceStates.Text = _DeviceStates;
  654. break;
  655. case XiaomiDeviceState.Alarm: // 警报状态(产生报警后进入此状态,同时停止运行)
  656. _DeviceStates = "警报状态";
  657. lblDeviceStates.Text = _DeviceStates;
  658. break;
  659. }
  660. if (!_DeviceStates.Equals(_DeviceStates_Old))
  661. {
  662. var iotResult = SaveDeviceStateData(stationNameStr, xmDeviceState); // 上传+保存
  663. if (iotResult.Item1 == 1)
  664. {
  665. _DeviceStates_Old = _DeviceStates;
  666. AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + $"_上传设备状态到Iot成功!");
  667. }
  668. else
  669. AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + $"_上传设备状态到Iot失败!报错信息:[{iotResult.Item1}]_{iotResult.Item2}");
  670. }
  671. #endregion 主页展示设备运行状态并上传到IOT中
  672. }
  673. }
  674. }
  675. //if (plc1Alarm.IsConnected) // 检查PLC是否已连接上
  676. //{
  677. // DateTime dtNow = DateTime.Now;
  678. // //#region 获取设备运行信息
  679. // //try
  680. // //{
  681. // // LineWorkingData_ThisTime lineWorkingData1 = new LineWorkingData_ThisTime();
  682. // // lineWorkingData1.GUID = Guid.NewGuid().ToString();
  683. // // lineWorkingData1.LineName = GlobalContext.LineCode;
  684. // // //
  685. // // lineWorkingData1.BootTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5500); // 本次开机时间(整线)D5500 h
  686. // // lineWorkingData1.NormalTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5502); // 本次开机运行时间(整线)D5502 h
  687. // // lineWorkingData1.StandbyTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5504); // 本次开机待机时间(整线)D5504 h
  688. // // lineWorkingData1.FaultTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5506); // 本次开机故障时间(整线)D5506 h
  689. // // lineWorkingData1.MaterialShortageTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5508); // 本次开机缺料时间(整线)D5508 h
  690. // // lineWorkingData1.MaintenanceTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5510); // 本次开机维修时间(整线)D5510 h
  691. // // lineWorkingData1.FaultNumber = plc1Alarm.ReadHoldingRegisters<short>(5514); // 本次开机故障停机次数(整线)D5514
  692. // // lineWorkingData1.OutputNumber = plc1Alarm.ReadHoldingRegisters<short>(5700); // 本次开机产量(整线) D5700
  693. // // lineWorkingData1.QualifiedNumber = plc1Alarm.ReadHoldingRegisters<short>(5704); // 本次开机合格数量(整线) D5704
  694. // // lineWorkingData1.QualifiedRate = plc1Alarm.ReadHoldingRegisters<float>(5710); // 本次开机合格率(整线) D5710
  695. // // lineWorkingData1.DesignRhythm = plc1Alarm.ReadHoldingRegisters<float>(5714); // 设计节拍(整线) D5714
  696. // // lineWorkingData1.RealityRhythm = plc1Alarm.ReadHoldingRegisters<float>(5716); // 本次开机实际节拍(整线) D5716
  697. // // lineWorkingData1.CreateTime = DateTime.Now;
  698. // // string lineWorkingData1_Str = JsonConvert.SerializeObject(lineWorkingData1);
  699. // // // UI展示-展示到设备状态页
  700. // // if (string.IsNullOrEmpty(lineWorkingData1_OldStr)) // 软件启动后第一次运行
  701. // // {
  702. // // // 查询数据库最新一条数据,确定是不是更新
  703. // // string qSql = @"SELECT top(1) [GUID]
  704. // // ,[LineName]
  705. // // ,[BootTimeLong]
  706. // // ,[NormalTimeLong]
  707. // // ,[StandbyTimeLong]
  708. // // ,[FaultTimeLong]
  709. // // ,[MaterialShortageTimeLong]
  710. // // ,[MaintenanceTimeLong]
  711. // // ,[FaultNumber]
  712. // // ,[OutputNumber]
  713. // // ,[QualifiedNumber]
  714. // // ,[QualifiedRate]
  715. // // ,[DesignRhythm]
  716. // // ,[RealityRhythm]
  717. // // ,[CreateTime]
  718. // // FROM [LineWorkingData]
  719. // // where [CreateTime] > '{0}'
  720. // // and [LineName]='{1}'
  721. // // order by [CreateTime] desc
  722. // // ";
  723. // // qSql = string.Format(qSql, DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00", lineWorkingData1.LineName);
  724. // // var ds = SQLHelper_New.Query(qSql, null);
  725. // // if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  726. // // {
  727. // // var dataDBlast = new LineWorkingData_ThisTime();
  728. // // dataDBlast.GUID = ds.Tables[0].Rows[0][0].ToString(); // 主键
  729. // // dataDBlast.LineName = ds.Tables[0].Rows[0][1].ToString(); // 线体名称
  730. // // dataDBlast.BootTimeLong = Convert.ToSingle(ds.Tables[0].Rows[0][2].ToString()); // 本次开机时间(整线)
  731. // // dataDBlast.CreateTime = Convert.ToDateTime(ds.Tables[0].Rows[0][14].ToString()); // 创建时间
  732. // // if (lineWorkingData1.BootTimeLong > dataDBlast.BootTimeLong) // 需要更新的情况;不需要更新的走后面的插入
  733. // // {
  734. // // dataDBlast.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  735. // // dataDBlast.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  736. // // dataDBlast.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  737. // // dataDBlast.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  738. // // dataDBlast.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  739. // // dataDBlast.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  740. // // dataDBlast.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  741. // // dataDBlast.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  742. // // dataDBlast.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  743. // // dataDBlast.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  744. // // dataDBlast.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  745. // // dataDBlast.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  746. // // string usql = dataDBlast.ToStringUpdate();
  747. // // SQLHelper_New.ExecuteSQL(usql, null);
  748. // // lineWorkingData1_OldStr = JsonConvert.SerializeObject(dataDBlast);
  749. // // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  750. // // //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  751. // // }
  752. // // }
  753. // // else
  754. // // {
  755. // // // 插入
  756. // // SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  757. // // lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  758. // // AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  759. // // //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  760. // // }
  761. // // }
  762. // // else if (!lineWorkingData1_Str.Equals(lineWorkingData1_OldStr)) // 非“软件启动后第一次运行”
  763. // // {
  764. // // LineWorkingData_ThisTime lineWorkingData1_Old = string.IsNullOrEmpty(lineWorkingData1_OldStr) ? lineWorkingData1 : JsonConvert.DeserializeObject<LineWorkingData_ThisTime>(lineWorkingData1_OldStr); // 上次的状态信息
  765. // // //// 本次开机设备运行情况
  766. // // //LineWorkingData1_ThisTime lineWorkingData_UI = JsonConvert.DeserializeObject<LineWorkingData1_ThisTime>(lineWorkingData1_OldStr);
  767. // // //Task.Run(() =>
  768. // // //{
  769. // // // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  770. // // // {
  771. // // // Form_Main.formDevAlarm.UpdDeviceStatus_ThisTime(lineWorkingData_UI); // UI更新
  772. // // // }
  773. // // //});
  774. // // // 本日设备运行情况
  775. // // // 存数据库(开机时间>上次的开机时间,则更新上次记录;<则作为新数据插入)
  776. // // if (lineWorkingData1.BootTimeLong > lineWorkingData1_Old.BootTimeLong)
  777. // // {
  778. // // // 更新
  779. // // lineWorkingData1_Old.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  780. // // lineWorkingData1_Old.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  781. // // lineWorkingData1_Old.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  782. // // lineWorkingData1_Old.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  783. // // lineWorkingData1_Old.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  784. // // lineWorkingData1_Old.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  785. // // lineWorkingData1_Old.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  786. // // lineWorkingData1_Old.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  787. // // lineWorkingData1_Old.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  788. // // lineWorkingData1_Old.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  789. // // lineWorkingData1_Old.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  790. // // lineWorkingData1_Old.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  791. // // SQLHelper_New.ExecuteSQL(lineWorkingData1_Old.ToStringUpdate(), null);
  792. // // lineWorkingData1_OldStr = JsonConvert.SerializeObject(lineWorkingData1_Old);
  793. // // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  794. // // //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  795. // // }
  796. // // else if (lineWorkingData1.BootTimeLong < lineWorkingData1_Old.BootTimeLong)
  797. // // {
  798. // // // 插入
  799. // // SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  800. // // lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  801. // // AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  802. // // //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  803. // // }
  804. // // await Task.Run(() =>
  805. // // {
  806. // // try
  807. // // {
  808. // // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  809. // // {
  810. // // Form_Main.formDevAlarm.UpdDeviceStatus_Today(); // UI更新
  811. // // }
  812. // // }
  813. // // catch { }
  814. // // });
  815. // // }
  816. // //}
  817. // //catch (Exception ex)
  818. // //{
  819. // // string str = ex.StackTrace;
  820. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取设备运行信息出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  821. // //}
  822. // //#endregion 获取设备运行信息
  823. // #region 报警数据
  824. // try
  825. // {
  826. // List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
  827. // bool isNeedUpdUI = false; // 是否需要更新历史报警UI
  828. // // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
  829. // var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.LineCode];
  830. // for (int i = 0; i < dicAlarms_Cur_PLC1.Count; i++) // 读取
  831. // {
  832. // short shortBuf = plc1Alarm.ReadHoldingRegisters<short>(dicAlarms_Cur_PLC1[i].关联的PLC地址);
  833. // dicAlarms_Cur_PLC1[i].是否报警 = shortBuf != 0;
  834. // if (dicAlarms_Cur_PLC1[i].上次的运行状态 != dicAlarms_Cur_PLC1[i].是否报警)
  835. // {
  836. // isNeedUpdUI = true; // 需要更新历史报警UI信息
  837. // // 记录
  838. // dicAlarms_Cur_PLC1[i].上次的运行状态 = dicAlarms_Cur_PLC1[i].是否报警;
  839. // switch (dicAlarms_Cur_PLC1[i].是否报警)
  840. // {
  841. // case true: // 报警
  842. // dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  843. // {
  844. // GUID = Guid.NewGuid().ToString(),
  845. // LineName = GlobalContext.LineCode, // 线体
  846. // AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  847. // AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  848. // StartTime = dtNow // 开始时间
  849. // };
  850. // // 传输到页面
  851. // deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
  852. // {
  853. // 线体名称 = dicAlarms_Cur_PLC1[i].报警数据.LineName,
  854. // 报警类型 = dicAlarms_Cur_PLC1[i].报警数据.AlarmType,
  855. // 报警内容 = dicAlarms_Cur_PLC1[i].报警数据.AlarmDesc,
  856. // 开始时间 = dtNow
  857. // });
  858. // // 新增到数据库
  859. // var data1 = dicAlarms_Cur_PLC1[i].报警数据;
  860. // SaveAlarmDataByDB(stationNameStr, data1, false);
  861. // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  862. // break;
  863. // case false: // 消除报警
  864. // if (dicAlarms_Cur_PLC1[i].报警数据 == null || string.IsNullOrEmpty(dicAlarms_Cur_PLC1[i].报警数据.GUID))
  865. // {
  866. // dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  867. // {
  868. // GUID = Guid.NewGuid().ToString(),
  869. // LineName = GlobalContext.LineCode, // 线体
  870. // AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  871. // AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  872. // StartTime = dtNow, // 开始时间
  873. // EndTime = dtNow, // 开始时间
  874. // PersistTime = 1, // 耗时1s
  875. // };
  876. // // 新增
  877. // var data2 = dicAlarms_Cur_PLC1[i].报警数据;
  878. // SaveAlarmDataByDB(stationNameStr, data2, false);
  879. // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  880. // }
  881. // else
  882. // {
  883. // dicAlarms_Cur_PLC1[i].报警数据.EndTime = dtNow; // 开始时间
  884. // dicAlarms_Cur_PLC1[i].报警数据.PersistTime = Convert.ToInt32((dicAlarms_Cur_PLC1[i].报警数据.EndTime
  885. // - dicAlarms_Cur_PLC1[i].报警数据.StartTime).TotalSeconds); // 耗时s
  886. // // 修改
  887. // var data3 = dicAlarms_Cur_PLC1[i].报警数据;
  888. // SaveAlarmDataByDB(stationNameStr, data3, true);
  889. // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  890. // }
  891. // break;
  892. // default:
  893. // break;
  894. // }
  895. // }
  896. // }
  897. // DicAlarms_Cur[GlobalContext.LineCode] = dicAlarms_Cur_PLC1;
  898. // // 有新报警则更新
  899. // if (isNeedUpdUI)
  900. // {
  901. // // UI展示 - 展示到设备状态页
  902. // await Task.Run(() =>
  903. // {
  904. // try
  905. // {
  906. // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
  907. // {
  908. // Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
  909. // if (Form_Main.formDevAlarm.Visible)
  910. // {
  911. // Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
  912. // }
  913. // }
  914. // }
  915. // catch { }
  916. // });
  917. // }
  918. // }
  919. // catch (Exception ex)
  920. // {
  921. // string str = ex.StackTrace;
  922. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  923. // }
  924. // #endregion 报警数据
  925. // UpdatePLCMonitor(1, -2, 1);
  926. //}
  927. //else
  928. //{
  929. // UpdatePLCMonitor(1, -2, 0);
  930. //}
  931. }
  932. catch (Exception ex)
  933. {
  934. //AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  935. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_采集运行数据与报警数据出错!错误信息:" + ex.Message.ToString());
  936. }
  937. Thread.Sleep(IntervalAlarm);
  938. }
  939. }
  940. #endregion 轮询PLC
  941. #region 下发订单信息
  942. ///// <summary>
  943. ///// 壳体上料(下发工单)的交互逻辑
  944. ///// </summary>
  945. ///// <param name="no"></param>
  946. ///// <exception cref="NotImplementedException"></exception>
  947. //private void ReadStation_DownOrderInfo(int plcNo)
  948. //{
  949. // // [S1] Tray盘上料装备(板测)
  950. // // [S2] FCT(板测)
  951. // // [S3] 值板机
  952. // // [S4] 取放桁架
  953. // // [S5] Tray盘下料装备
  954. // /// 上位机心跳
  955. // /// 获取设备报警数据与状态信息
  956. // string stationNameStr = "[S0]壳体上料";
  957. // while (IsRun)
  958. // {
  959. // try
  960. // {
  961. // if (!GlobalContext._IsCon_Funs1)
  962. // {
  963. // UpdatePLCMonitor(plcNo, 0);
  964. // continue;
  965. // }
  966. // if (Funs[plcNo].isConnected) // 检查PLC是否已连接上
  967. // {
  968. // #region 壳体上料(下发工单)
  969. // try
  970. // {
  971. // Funs[plcNo].Read_Int_Tag("500", 1, out short[] iiMes0);
  972. // Funs[plcNo].Read_Int_Tag("501", 1, out short[] iiPlc0);
  973. // bool mES_FLAG_1 = iiMes0[0] == 1 ? true : false; // MES_FLAG_1
  974. // bool pLC_Flag_1 = iiPlc0[0] == 1 ? true : false; // PLC_FLAG_1
  975. // // 重置数据和信号
  976. // if (mES_FLAG_1 && pLC_Flag_1) // 1 1
  977. // {
  978. // // 清空写给PLC的数据
  979. // int[] i497 = new int[1] { 0 };
  980. // Funs[plcNo].Write_DInt_Tag("497", 1, i497); // SN号(数字部分)重置信号
  981. // // MES_Flag重置为0
  982. // int[] i500 = new int[1] { 0 };
  983. // Funs[plcNo].Write_DInt_Tag("500", 1, i500); // MES_FLAG_1
  984. // }
  985. // }
  986. // catch (Exception ex)
  987. // {
  988. // string str = ex.StackTrace;
  989. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}下发订单信息运行出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  990. // }
  991. // #endregion 壳体上料(下发工单)
  992. // UpdatePLCMonitor(plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  993. // }
  994. // else
  995. // {
  996. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  997. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  998. //
  999. // Funs[plcNo].Connect();
  1000. // }
  1001. // }
  1002. // catch (Exception ex)
  1003. // {
  1004. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  1005. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1006. //
  1007. // Funs[plcNo].ReConnect();
  1008. // }
  1009. // Thread.Sleep(IntervalReadPLC);
  1010. // }
  1011. //}
  1012. ///// <summary>
  1013. ///// 下发订单信息到PLC
  1014. ///// </summary>
  1015. ///// <param name="no">PLC编号</param>
  1016. //private void DownLoadProductInfo(int plcNo, string stationNameStr = "[S0]壳体上料")
  1017. //{
  1018. // try
  1019. // {
  1020. // if (!string.IsNullOrEmpty(GlobalContext.Mtltmrk))
  1021. // {
  1022. // Funs[plcNo].Write_String_Tag("568", 1, GlobalContext.Mtltmrk); // 产品型号(mtltmrk)
  1023. // WritePLCLog(LogType.Debug, GlobalContext.Mtltmrk);
  1024. // }
  1025. // Funs[plcNo].Write_DInt_Tag("500", 1, new Int32[1] { 1 }); // MES_FLAG_1
  1026. // }
  1027. // catch (Exception ex)
  1028. // {
  1029. // string str = ex.StackTrace;
  1030. // AddMessage_Station(stationNameStr, LogType.Error, "下发订单信息到PLC失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1031. // }
  1032. //}
  1033. /// <summary>
  1034. /// 下发清料信号
  1035. /// </summary>
  1036. /// <param name="no">PLC编号</param>
  1037. public bool ClearProducts(int plcNo, string stationNameStr = "[S0]壳体上料")
  1038. {
  1039. try
  1040. {
  1041. //Funs[plcNo].ReadHoldingRegisters<int>(496); //
  1042. AddMessage_Station(stationNameStr, LogType.Info, "下发了清料信号!");
  1043. return true;
  1044. }
  1045. catch (Exception ex)
  1046. {
  1047. string str = ex.StackTrace;
  1048. AddMessage_Station(stationNameStr, LogType.Error, "下发清料信号失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1049. return false;
  1050. }
  1051. }
  1052. #endregion 下发订单信息
  1053. #region Xiaomi 贲流
  1054. #region 公共方法
  1055. private static bool ProgressState = false;
  1056. private static readonly object lockObj = new object(); // 锁对象
  1057. private static bool isCollectingFlagLeft;
  1058. private static bool isCollectingFlagRight;
  1059. /// <summary>
  1060. /// float[]转为string
  1061. /// </summary>
  1062. public string FloatArrayToString(float[] nScrewResults)
  1063. {
  1064. // 使用 "R" 格式说明符来保证浮点数的往返精度,不添加 'f' 后缀
  1065. return string.Join(",", Array.ConvertAll(nScrewResults, element => element.ToString("R")));
  1066. }
  1067. /// <summary>
  1068. /// short[]转为string
  1069. /// </summary>
  1070. public string ShortArrayToString(short[] nScrewResults)
  1071. {
  1072. // 使用 string.Join 来连接数组元素,并使用逗号作为分隔符
  1073. return string.Join(",", nScrewResults);
  1074. }
  1075. /// <summary>
  1076. /// 写入PLC重复三次
  1077. /// </summary>
  1078. public (int, string) WriteResultToPlc<T>(int plcNo, string stationNameStr, string strTagName, int nCount, T inObj)
  1079. {
  1080. int i = 0;
  1081. int nRet = 0;
  1082. string strRet = "";
  1083. try
  1084. {
  1085. while (i < 3) // 最多上传三次
  1086. {
  1087. (nRet, strRet) = FunsEip[plcNo].Write_SingleTag<T>(strTagName, nCount, inObj);
  1088. if (nRet == 0) //成功
  1089. {
  1090. break;
  1091. }
  1092. else
  1093. {
  1094. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站结果写入PLC出错!错误信息:" + strRet);
  1095. i++;
  1096. }
  1097. }
  1098. return (nRet, strRet);
  1099. }
  1100. catch (Exception ex)
  1101. {
  1102. return (1, ex.Message);
  1103. }
  1104. }
  1105. public (int, string) SaveScrewDataToTxt(string direction, string ProductBarcode, float[] fScrewTimes, short[] nScrewOrders, short[] nScrewResults)
  1106. {
  1107. try
  1108. {
  1109. // 获取当前日期
  1110. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1111. // 构建保存路径
  1112. string basePath = AppDomain.CurrentDomain.BaseDirectory; // 获取执行文件的目录
  1113. string savePath = Path.Combine(basePath, "screw", dateFolder, ProductBarcode, direction,"螺丝Mes数据");
  1114. // 确保目录存在
  1115. Directory.CreateDirectory(savePath);
  1116. // 文件名
  1117. string fileName = $"{ProductBarcode}_{DateTime.Now.ToString("HHmmss")}.txt";
  1118. string filePath = Path.Combine(savePath, fileName);
  1119. // 确保不会超出数组长度,只取前14个或数组的实际长度
  1120. int count = Math.Min(14, fScrewTimes.Length);
  1121. using (StreamWriter sw = new StreamWriter(filePath))
  1122. {
  1123. for (int i = 0; i < count; i++)
  1124. {
  1125. sw.WriteLine($"{ProductBarcode}{"_"}{i + 1}");
  1126. sw.WriteLine($"锁附时间:{fScrewTimes[i]}");
  1127. sw.WriteLine($"锁附顺序:{nScrewOrders[i]}");
  1128. sw.WriteLine($"锁附结果:{nScrewResults[i]}");
  1129. sw.WriteLine(); // 空行分隔不同螺丝的信息
  1130. }
  1131. }
  1132. return (0, "");
  1133. }
  1134. catch (Exception ex)
  1135. {
  1136. return (1, ex.Message);
  1137. }
  1138. }
  1139. /// <summary>
  1140. /// 调用进站接口并保存进站数据
  1141. /// </summary>
  1142. /// <param name="stationNameStr">工站信息</param>
  1143. /// <param name="workorder_code">工单号</param>
  1144. /// <param name="mtltmrk">型号(物料号)</param>
  1145. /// <param name="sn">产品SN</param>
  1146. /// <param name="items">进站数据</param>
  1147. /// <returns>1成功;5MES报警;6上位机报警</returns>
  1148. public int SaveStationInData(string stationNameStr, string workorder_code, string mtltmrk, string sn, List<TestItem> items, string MachineId, string StationId)
  1149. {
  1150. int result = 0;
  1151. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1152. inRequest_Body.machineId = MachineId; // 装备ID(可配置)
  1153. inRequest_Body.stationId = StationId; // ⼯位ID(可配置)
  1154. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1155. inRequest_Body.clientTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1156. inRequest_Body.unitSn = sn; // 产品SN
  1157. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1158. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1159. string json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1160. StationIn stationIn = new StationIn()
  1161. {
  1162. Workorder_code = workorder_code, // 车间订单号
  1163. Mtltmrk = mtltmrk, // 产品型号(物料号)
  1164. Sn = sn, // SN
  1165. StationIn_body = json_Body, // 进站接口Json数据 - Body
  1166. Parameter_values = items, // 进站数据
  1167. Write_user = inRequest_Body.userId, // 员工Id
  1168. Test_time = inRequest_Body.clientTime // 进站时间
  1169. };
  1170. // 本地数据
  1171. string sql = stationIn.ToStringInsert(0);
  1172. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1173. result = ret == "成功" ? 1 : 6;
  1174. //await Task.Delay(200);
  1175. // 上传MES
  1176. if (GlobalContext.IsSendStationIn)
  1177. {
  1178. try
  1179. {
  1180. XmMES_StationInResponse response = new XmMES_StationInResponse();
  1181. string mesRet = string.Empty;
  1182. int i = 0;
  1183. while (i < 2) // 1009会多次尝试上传
  1184. {
  1185. response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  1186. if (response != null && response.header.code == "200")
  1187. break;
  1188. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1189. i++;
  1190. i++;
  1191. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1192. // 记录失败原因
  1193. OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + json_Body);
  1194. }
  1195. if (response?.header?.code == "200")
  1196. {
  1197. string sql_Upd = stationIn.ToStringUpdateStatusByID(1);
  1198. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1199. result = ret_Upd == "成功" ? 1 : 6;
  1200. AddMessage( LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---成功");
  1201. }
  1202. else
  1203. {
  1204. result = 5;
  1205. AddMessage(LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---失败!接口报错信息:" + mesRet);
  1206. }
  1207. string sql_response = stationIn.ToStringUpdateStationInReturn_body(JsonConvert.SerializeObject(response));
  1208. SQLHelper_New.ExecuteNonQuery(sql_response, null);
  1209. }
  1210. catch (Exception ex)
  1211. {
  1212. result = 6;
  1213. string str = ex.StackTrace;
  1214. AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传进站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1215. }
  1216. }
  1217. return result;
  1218. }
  1219. /// <summary>
  1220. /// 选择如何记录出站数据
  1221. /// </summary>
  1222. /// <param name="items">出站数据</param>
  1223. /// <param name="equipmentCode">设备编号</param>
  1224. /// <param name="processItem">测试项目</param>
  1225. /// <param name="workorder_code">车间订单号</param>
  1226. /// <param name="batch_num">批次号</param>
  1227. /// <param name="mtltmrk">型号</param>
  1228. /// <param name="proDate">日期</param>
  1229. /// <param name="supplierCode">供应商代码</param>
  1230. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1231. /// <returns>上传成功时返回1;失败返回0</returns>
  1232. private int SwitctProcessData(string stationNameStr, List<TestItem> items, string equipmentCode, string processItem,
  1233. string workorder_code, string batch_num, string mtltmrk, string proDate,
  1234. string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string MachineId, string StationId, string PartBarcode)
  1235. {
  1236. return SaveProcessDataByDB(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num, mtltmrk,
  1237. proDate, supplierCode, sn, pass, vehicleSn, vehicleSlot, MachineId, StationId, PartBarcode);
  1238. }
  1239. /// <summary>
  1240. /// 添加出站数据(提交到MES+本地保存到数据库)
  1241. /// </summary>
  1242. /// <param name="items">出站数据</param>
  1243. /// <param name="equipmentCode">设备编号</param>
  1244. /// <param name="processItem">测试项目</param>
  1245. /// <param name="workorder_code">车间订单号</param>
  1246. /// <param name="batch_num">批次号</param>
  1247. /// <param name="mtltmrk">型号</param>
  1248. /// <param name="proDate">日期</param>
  1249. /// <param name="supplierCode">供应商代码</param>
  1250. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1251. /// <returns>上传成功时返回1;失败返回0</returns>
  1252. public int SaveProcessDataByDB(string stationNameStr, List<TestItem> items, string equipmentCode,
  1253. string processItem, string workorder_code, string batch_num, string mtltmrk,
  1254. string proDate, string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string machineId, string stationId, string partBarcode)
  1255. {
  1256. int upload = 0;
  1257. int result = 0;
  1258. ProcessData processData = new ProcessData()
  1259. {
  1260. Equipment_code = equipmentCode,
  1261. Workorder_code = workorder_code,
  1262. Batch_number = batch_num,
  1263. Sn = sn, // SN
  1264. Testitem = processItem,
  1265. Parameter_values = items,
  1266. Write_user = GlobalContext.CurrentUser,
  1267. Test_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  1268. };
  1269. // 本地数据
  1270. string sql = processData.ToStringInsert(upload);
  1271. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1272. //AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地出站数据---" + ret));
  1273. // 上传MES
  1274. if (GlobalContext.IsSendProcessData)
  1275. {
  1276. try
  1277. {
  1278. string id = processData.ID.Copy();
  1279. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1280. outRequest_Body.machineId = machineId; // 装备id(可配置)
  1281. outRequest_Body.stationId = stationId; // ⼯位ID(可配置)
  1282. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1283. outRequest_Body.clientTime = processData.Test_time; // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1284. outRequest_Body.unitSn = sn; // 产品SN
  1285. outRequest_Body.state = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL
  1286. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1287. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1288. outRequest_Body.unitData.vehicleData.vehicleSn = vehicleSn;
  1289. outRequest_Body.unitData.vehicleData.vehicleType = string.Empty;
  1290. outRequest_Body.unitData.vehicleData.slot = vehicleSlot;
  1291. if (!string.IsNullOrEmpty(partBarcode))
  1292. {
  1293. outRequest_Body.unitData.keyMaterial.Add(
  1294. new XmMES_StationOutRequest_Body.XmStationOut_KeyMaterial()
  1295. {
  1296. bindSort = 1,
  1297. materialSn = partBarcode
  1298. }); // 设备数据 - 部件码
  1299. }
  1300. string jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1301. if (GlobalContext.IsSendProcessData)
  1302. {
  1303. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1304. string mesRet = string.Empty;
  1305. int i = 0;
  1306. while (i < 2) // 1009会多次尝试上传
  1307. {
  1308. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1309. if (response != null && response.header.code == "200")
  1310. break;
  1311. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1312. i++;
  1313. i++;
  1314. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1315. // 记录失败原因
  1316. OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + jsonstr1);
  1317. }
  1318. if (response?.header?.code == "200")
  1319. {
  1320. string sql_Upd = ProcessData.ToStringUpdateStatusByID(1, id);
  1321. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1322. result = 1;
  1323. //AddMessage_Station(stationNameStr, LogType.Info, $"更新【出站数据 id {id}】上传状态---" + ret_Upd);
  1324. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---成功");
  1325. }
  1326. else
  1327. {
  1328. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---失败!接口报错信息:"+ mesRet);
  1329. }
  1330. string sql_UpStationout = ProcessData.ToStringUpdateStationOut_body(JsonConvert.SerializeObject(outRequest_Body),
  1331. JsonConvert.SerializeObject(response), id);
  1332. SQLHelper_New.ExecuteNonQuery(sql_UpStationout, null);
  1333. }
  1334. }
  1335. catch (Exception ex)
  1336. {
  1337. string str = ex.StackTrace;
  1338. AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传出站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1339. }
  1340. }
  1341. return result;
  1342. }
  1343. //private void CollectAndProcessDataLeft(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1344. //{
  1345. // Stopwatch stopwatch = new Stopwatch();
  1346. // stopwatch.Start();
  1347. // try
  1348. // {
  1349. // // 初始化 AtlasScrew 实例
  1350. // AtlasScrew atlasScrew1 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1351. // atlasScrew1.Initial();
  1352. // // 存储结果的列表
  1353. // List<(double Angle, double Torque, double StartTorque, double MaxTorque)> results = new List<(double, double, double, double)>();
  1354. // // 存储角度和扭力的字符串列表
  1355. // List<string> angleStrs = new List<string>();
  1356. // List<string> torqueStrs = new List<string>();
  1357. // // 上一次获取的数据
  1358. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1359. // while (isExitAtlasLeft) // 检查是否收集数据
  1360. // {
  1361. // // 获取当前数据
  1362. // var currentResult = atlasScrew1.GetResults();
  1363. // // 判断是否为新数据
  1364. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1365. // {
  1366. // OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1367. // // 更新角度和扭力的字符串列表
  1368. // angleStrs.Add(currentResult.JD_MEAN.ToString());
  1369. // torqueStrs.Add(currentResult.NL_MEAN.ToString());
  1370. // // 计算角度、扭力、起始扭力和最大扭力
  1371. // double[] angles = angleStrs.Select(a => double.Parse(a)).ToArray();
  1372. // double[] torques = torqueStrs.Select(a => double.Parse(a)).ToArray();
  1373. // double startTorque = torques.Length > 0 ? torques[0] : -1; // 起始扭力
  1374. // double maxTorque = torques.Length > 0 ? torques.Max() : -1; // 最大扭力
  1375. // // 将新数据添加到结果列表
  1376. // results.Add((angles.Last(), torques.Last(), startTorque, maxTorque));
  1377. // // 更新上一次获取的数据
  1378. // lastResult = currentResult;
  1379. // }
  1380. // // 等待一段时间后再次检查
  1381. // Thread.Sleep(20); // 轮询间隔时间
  1382. // // 如果触发了出站,则退出循环
  1383. // if (!isExitAtlasLeft)
  1384. // {
  1385. // break;
  1386. // }
  1387. // }
  1388. // // 生成文件名
  1389. // string fileName = $"{sn}_{direction}_{DateTime.Now:yyyyMMddHHmmss}.txt";
  1390. // // 写入数据到文件
  1391. // using (StreamWriter writer = new StreamWriter(fileName))
  1392. // {
  1393. // // 写入标题行
  1394. // writer.WriteLine("角度, 扭力, 起始扭力, 最大扭力");
  1395. // // 写入每一行数据
  1396. // foreach (var result in results)
  1397. // {
  1398. // writer.WriteLine($"{result.Angle}, {result.Torque}, {result.StartTorque}, {result.MaxTorque}");
  1399. // }
  1400. // }
  1401. // stopwatch.Stop();
  1402. // AddMessage(LogType.Info, $"数据采集完成并保存到文件 {fileName}; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1403. // }
  1404. // catch (Exception ex)
  1405. // {
  1406. // AddMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1407. // }
  1408. // finally
  1409. // {
  1410. // // 重置标志变量
  1411. // isExitAtlasLeft = false;
  1412. // }
  1413. //}
  1414. //private void CollectAndProcessDataRight(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1415. //{
  1416. // Stopwatch stopwatch = new Stopwatch();
  1417. // stopwatch.Start();
  1418. // try
  1419. // {
  1420. // // 初始化 AtlasScrew 实例
  1421. // AtlasScrew atlasScrew2 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1422. // atlasScrew2.Initial();
  1423. // // 存储结果的列表
  1424. // List<(double JD_MEAN, double NL_MEAN)> results = new List<(double JD_MEAN, double NL_MEAN)>();
  1425. // // 上一次获取的数据
  1426. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1427. // while (isExitAtlasRight) // 检查是否收集数据
  1428. // {
  1429. // // 获取当前数据
  1430. // var currentResult = atlasScrew2.GetResults();
  1431. // // 判断是否为新数据
  1432. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1433. // {
  1434. // AddMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1435. // // 将新数据写入PLC
  1436. // //WriteDataToPlc(plcNo, stationNameStr, tagMesCommName, currentResult.JD_MEAN, currentResult.NL_MEAN);
  1437. // // 将新数据添加到结果列表
  1438. // results.Add(currentResult);
  1439. // // 更新上一次获取的数据
  1440. // lastResult = currentResult;
  1441. // }
  1442. // // 等待一段时间后再次检查
  1443. // Thread.Sleep(20); // 轮询间隔时间
  1444. // // 如果触发了出站,则退出循环
  1445. // if (!isExitAtlasRight)
  1446. // {
  1447. // break;
  1448. // }
  1449. // }
  1450. // // 将所有数据写入文件
  1451. // //WriteDataToFile(sn, direction, results);
  1452. // stopwatch.Stop();
  1453. // OnMessage(LogType.Info, $"螺丝数据采集完成;总用时{stopwatch.ElapsedMilliseconds}ms");
  1454. // }
  1455. // catch (Exception ex)
  1456. // {
  1457. // OnMessage(LogType.Error, $"螺丝数据采集过程中发生错误: {ex.Message}");
  1458. // }
  1459. // finally
  1460. // {
  1461. // // 重置标志变量
  1462. // isExitAtlasRight = false;
  1463. // }
  1464. //}
  1465. private void CollectAndProcessDataLeft(AtlasScrew atlasScrew, string sn, string direction)
  1466. {
  1467. Stopwatch stopwatch = new Stopwatch();
  1468. stopwatch.Start();
  1469. int nRet = 0;
  1470. string strRet = "";
  1471. try
  1472. {
  1473. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1474. while (isCollectingFlagLeft)
  1475. {
  1476. // 从缓存中获取所有未处理的数据
  1477. var cachedData = atlasScrew.GetCachedDataLeft();
  1478. foreach (var currentResult in cachedData)
  1479. {
  1480. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1481. {
  1482. continue; // 跳过无效数据
  1483. }
  1484. OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1485. // 写入PLC
  1486. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1487. {
  1488. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1489. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1490. };
  1491. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1492. if (nRet != 0)
  1493. {
  1494. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1495. }
  1496. else
  1497. {
  1498. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1499. }
  1500. // 构建保存路径
  1501. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1502. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1503. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  1504. Directory.CreateDirectory(savePath); // 确保目录存在
  1505. // 构建文件名(以 SN + 序号命名)
  1506. string fileName = $"{sn}_{fileCounter}.txt";
  1507. string filePath = Path.Combine(savePath, fileName);
  1508. // 写入文件
  1509. using (StreamWriter writer = new StreamWriter(filePath))
  1510. {
  1511. writer.WriteLine("精度, 扭力");
  1512. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1513. for (int i = 0; i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length; i++)
  1514. {
  1515. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1516. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1517. writer.WriteLine($"{precision}, {torque}");
  1518. }
  1519. }
  1520. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1521. // 增加文件计数器
  1522. fileCounter++;
  1523. }
  1524. // 如果没有更多数据,则短暂休眠以节省资源
  1525. if (!cachedData.Any())
  1526. {
  1527. Thread.Sleep(10); // 根据需要调整休眠时间
  1528. }
  1529. // 如果触发了出站,则退出循环
  1530. if (!isCollectingFlagLeft)
  1531. {
  1532. break;
  1533. }
  1534. }
  1535. stopwatch.Stop();
  1536. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1537. }
  1538. catch (Exception ex)
  1539. {
  1540. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1541. }
  1542. finally
  1543. {
  1544. isCollectingFlagLeft = false;
  1545. }
  1546. }
  1547. private void CollectAndProcessDataRight(AtlasScrew atlasScrew, string sn, string direction)
  1548. {
  1549. Stopwatch stopwatch = new Stopwatch();
  1550. stopwatch.Start();
  1551. int nRet = 0;
  1552. string strRet = "";
  1553. try
  1554. {
  1555. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1556. while (isCollectingFlagRight)
  1557. {
  1558. // 从缓存中获取所有未处理的数据
  1559. var cachedData = atlasScrew.GetCachedDataLeft();
  1560. foreach (var currentResult in cachedData)
  1561. {
  1562. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1563. {
  1564. continue; // 跳过无效数据
  1565. }
  1566. OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1567. // 写入PLC
  1568. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1569. {
  1570. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1571. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1572. };
  1573. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1574. if (nRet != 0)
  1575. {
  1576. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1577. }
  1578. else
  1579. {
  1580. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1581. }
  1582. // 构建保存路径
  1583. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1584. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1585. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction,"曲线");
  1586. Directory.CreateDirectory(savePath); // 确保目录存在
  1587. // 构建文件名(以 SN + 序号命名)
  1588. string fileName = $"{sn}_{fileCounter}.txt";
  1589. string filePath = Path.Combine(savePath, fileName);
  1590. // 写入文件
  1591. using (StreamWriter writer = new StreamWriter(filePath))
  1592. {
  1593. writer.WriteLine("精度, 扭力");
  1594. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1595. for (int i = 0; i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length; i++)
  1596. {
  1597. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1598. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1599. writer.WriteLine($"{precision}, {torque}");
  1600. }
  1601. }
  1602. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1603. // 增加文件计数器
  1604. fileCounter++;
  1605. }
  1606. // 如果没有更多数据,则短暂休眠以节省资源
  1607. if (!cachedData.Any())
  1608. {
  1609. Thread.Sleep(10); // 根据需要调整休眠时间
  1610. }
  1611. // 如果触发了出站,则退出循环
  1612. if (!isCollectingFlagRight)
  1613. {
  1614. break;
  1615. }
  1616. }
  1617. stopwatch.Stop();
  1618. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1619. }
  1620. catch (Exception ex)
  1621. {
  1622. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1623. }
  1624. finally
  1625. {
  1626. isCollectingFlagRight = false;
  1627. }
  1628. }
  1629. #endregion
  1630. #region S1
  1631. /// <summary>
  1632. /// [S1] 壳体清洁上料装备
  1633. /// </summary>
  1634. /// <param name="plcNo">PLC编号</param>
  1635. private void ReadStation_S1(int plcNo)
  1636. {
  1637. string stationCode = "[OP10]";
  1638. string stationName = "壳体清洁上料";
  1639. string stationNameStr = stationCode + stationName;
  1640. string tagBaseName = "g_OP10_MES"; //标签变量名称
  1641. string tagMesCommName = "mesCommToPC"; //标签变量名称
  1642. string tagAgvCommName = "agvCommFrmPC";
  1643. string tagBarsetName = "BarcodeSet";
  1644. // 触发信号字典
  1645. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  1646. s1PLCSignal_Old.Add("a1OEEType", 0); // 节拍类型(plc写入)
  1647. // PLC数据字典 赋值
  1648. //s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  1649. s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  1650. s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  1651. s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  1652. OP10_MesData_t stPLC_MesData; //PLC的MES数据
  1653. (int, string) result;
  1654. while (true)
  1655. {
  1656. try
  1657. {
  1658. if (!GlobalContext._IsCon_Funs1)
  1659. {
  1660. UpdatePLCMonitor(1, plcNo, 0);
  1661. continue;
  1662. }
  1663. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  1664. {
  1665. Stopwatch stopwatch1 = new Stopwatch();
  1666. Stopwatch stopwatch2 = new Stopwatch();
  1667. stopwatch1.Start();
  1668. stopwatch2.Start();
  1669. #region 一次性读取所有数据
  1670. // 一次性读取所有数据
  1671. result = FunsEip[plcNo].Read_SingleTag<OP10_MesData_t>(tagBaseName, 1, out stPLC_MesData,this); //读取单个结构体数据
  1672. if (result.Item1 != 0)
  1673. {
  1674. //richTextBox1.AppendText("\n" + strRet);
  1675. }
  1676. else
  1677. {
  1678. //richTextBox1.AppendText("\n" + "读取成功");
  1679. //设备状态
  1680. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  1681. xmDeviceState = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7) ? XiaomiDeviceState.Unknown : (XiaomiDeviceState)xmDeviceStateInt;
  1682. s1PLCData["a1OEEPartNo"] = stPLC_MesData.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  1683. s1PLCData["a1OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  1684. s1PLCData["a1OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
  1685. }
  1686. #endregion 一次性读取所有数据
  1687. stopwatch2.Stop();
  1688. #region 进站
  1689. try
  1690. {
  1691. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  1692. {
  1693. lock (lockObj)
  1694. {
  1695. if (!ProgressState)
  1696. {
  1697. ProgressState = true;
  1698. Task.Run(() => S1进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, out ProgressState));
  1699. }
  1700. }
  1701. }
  1702. }
  1703. catch (Exception ex)
  1704. {
  1705. ProgressState = false;
  1706. string str = ex.StackTrace;
  1707. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1708. }
  1709. #endregion 进站
  1710. #region 出站
  1711. try
  1712. {
  1713. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  1714. {
  1715. lock (lockObj)
  1716. {
  1717. if (!ProgressState)
  1718. {
  1719. ProgressState = true;
  1720. Task.Run(() => S1出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  1721. stPLC_MesData.mesCommFrmPLC.cmd = 0;//清除入站申请
  1722. }
  1723. }
  1724. }
  1725. }
  1726. catch (Exception ex)
  1727. {
  1728. ProgressState = false;
  1729. string str = ex.StackTrace;
  1730. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1731. }
  1732. #endregion 出站
  1733. #region 节拍接口
  1734. try
  1735. {
  1736. int a1OEEPLC_FLAG = (int)s1PLCData["a1OEEType"];
  1737. int a1OEEPLC_FLAGOld = (int)s1PLCSignal_Old["a1OEEType"];
  1738. if (a1OEEPLC_FLAG != a1OEEPLC_FLAGOld)
  1739. {
  1740. if (a1OEEPLC_FLAG == 1)
  1741. Task.Run(() => S1节拍接口(plcNo, stationNameStr, tagBaseName, stPLC_MesData)); // MreTasks[4].Set();
  1742. s1PLCSignal_Old["a1OEEType"] = s1PLCData["a1OEEType"];
  1743. }
  1744. }
  1745. catch (Exception ex)
  1746. {
  1747. string str = ex.StackTrace;
  1748. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1749. }
  1750. #endregion
  1751. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1752. stopwatch1.Stop();
  1753. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  1754. }
  1755. else
  1756. {
  1757. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1758. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1759. FunsEip[plcNo].Connect(); // 重连
  1760. }
  1761. }
  1762. catch (Exception ex)
  1763. {
  1764. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1765. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1766. }
  1767. Thread.Sleep(IntervalReadPLC);
  1768. }
  1769. }
  1770. /// <summary>
  1771. /// [S1] 壳体清洁上料 - 进站
  1772. /// </summary>
  1773. /// <param name="plcNo">PLC编号</param>
  1774. /// <param name="stationNameStr">工站全称</param>
  1775. /// <param name="stPLC_MesData"></param>
  1776. /// <param name="tagMesCommName"></param>
  1777. private void S1进站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName, out bool ProgressState)
  1778. {
  1779. Stopwatch stopwatch1 = new Stopwatch();
  1780. Stopwatch stopwatch2 = new Stopwatch();
  1781. try
  1782. {
  1783. stopwatch1.Start();
  1784. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  1785. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有OP10和OP50返回
  1786. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1787. string MachineId = GlobalContext.S1_MachineId; // 装备ID(可配置)
  1788. string StationId = GlobalContext.S1_StationId; // 工位ID(可配置)
  1789. if (string.IsNullOrEmpty(sn))
  1790. {
  1791. ProgressState = false;
  1792. return;
  1793. }
  1794. //正式生产就用PLC中取的
  1795. //sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode;
  1796. //测试先用9码,正式直接用PLC得到的SN码,截取成9位码
  1797. sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  1798. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  1799. //绑定载具和产品
  1800. ResponseMessage message = new ResponseMessage();
  1801. message = SQLHelper.InsertCarrierBind(CarrierBarcode, sn);
  1802. if (message.result == false)
  1803. {
  1804. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  1805. }
  1806. // 产品SN进站
  1807. List<TestItem> item = new List<TestItem>();
  1808. stopwatch2.Start();
  1809. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  1810. stopwatch2.Stop();
  1811. //指令执行结果 1:OK 110:失败
  1812. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  1813. //进站结果写入PLC
  1814. CommandFromPLC resultToPlC = new CommandFromPLC();
  1815. resultToPlC.cmd = 0;
  1816. resultToPlC.cmdParam = 0;
  1817. resultToPlC.cmdResult = mesResultFrmWeb;
  1818. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1819. }
  1820. catch (Exception ex)
  1821. {
  1822. string str = ex.StackTrace;
  1823. AddMessage( LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1824. CommandFromPLC resultToPlC = new CommandFromPLC();
  1825. resultToPlC.cmd = 0;
  1826. resultToPlC.cmdParam = 0; //指令参数
  1827. resultToPlC.cmdResult = 110;
  1828. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1829. }
  1830. stopwatch1.Stop();
  1831. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  1832. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1833. ProgressState = false;
  1834. }
  1835. /// <summary>
  1836. /// [S1] 壳体清洁上料 - 出站接口
  1837. /// </summary>
  1838. private void S1出站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  1839. {
  1840. Stopwatch stopwatch1 = new Stopwatch();
  1841. Stopwatch stopwatch2 = new Stopwatch();
  1842. try
  1843. {
  1844. stopwatch1.Start();
  1845. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  1846. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  1847. string processItem = stationName; // 项目
  1848. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  1849. string supplierCode = ""; // 供应商代码
  1850. string workorder_code = GlobalContext.WorkOrderCode; // 工单号 现在没用上
  1851. string batch_num = GlobalContext.BatchNumber; // 批次号 现在没用上
  1852. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号 现在没用上
  1853. string sn = string.Empty;
  1854. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1855. string MachineId = GlobalContext.S1_MachineId; // 装备id(可配置)
  1856. string StationId = GlobalContext.S1_StationId; // ⼯位ID(可配置)
  1857. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  1858. a1Result = 1;
  1859. bool pass = a1Result == 1;
  1860. //根据载具码获取产品码
  1861. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  1862. if (string.IsNullOrEmpty(strProductBarcode))
  1863. {
  1864. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  1865. }
  1866. sn = strProductBarcode;
  1867. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  1868. List<TestItem> items = new List<TestItem>();
  1869. items.Add(new TestItem()
  1870. {
  1871. Parameter_name = "载具码",
  1872. Parameter_value = CarrierBarcode,
  1873. Parameter_unit = ""
  1874. });
  1875. items.Add(new TestItem()
  1876. {
  1877. Parameter_name = "产品码",
  1878. Parameter_value = sn,
  1879. Parameter_unit = ""
  1880. });
  1881. //出站接口
  1882. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  1883. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  1884. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  1885. stopwatch2.Start();
  1886. //进站结果写入PLC
  1887. CommandFromPLC resultToPlC = new CommandFromPLC();
  1888. resultToPlC.cmd = 0;
  1889. resultToPlC.cmdParam = 0; //指令参数
  1890. resultToPlC.cmdResult = mesResultFrmWeb;
  1891. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1892. stopwatch2.Stop();
  1893. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  1894. //保存PLC返回MES数据到本地
  1895. ResponseMessage message = new ResponseMessage();
  1896. message = SQLHelper.InsertOp10Data(CarrierBarcode, sn, 1,
  1897. stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.fCleanAirPress, stPLC_MesData.mesData.fCleanSpeed,
  1898. stPLC_MesData.mesData.fWindBladeHeight, stPLC_MesData.mesData.fCleanTime, stPLC_MesData.mesData.nCleanCount,
  1899. stPLC_MesData.mesData.nRemainCount);
  1900. if (message.result == false)
  1901. {
  1902. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  1903. }
  1904. AddMessage(LogType.Info, stationNameStr + "_保存出站数据结束");
  1905. }
  1906. catch (Exception ex)
  1907. {
  1908. stopwatch2.Start();
  1909. CommandFromPLC resultToPlC = new CommandFromPLC();
  1910. resultToPlC.cmd = 0;
  1911. resultToPlC.cmdParam = 0; //指令参数
  1912. resultToPlC.cmdResult = 110;
  1913. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1914. stopwatch2.Stop();
  1915. string str = ex.StackTrace;
  1916. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1917. }
  1918. stopwatch1.Stop();
  1919. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1920. ProgressState = false;
  1921. }
  1922. #endregion
  1923. #region S2
  1924. /// <summary>
  1925. /// [S2] 上盖板上料装备
  1926. /// </summary>
  1927. /// <param name="plcNo">PLC编号</param>
  1928. private void ReadStation_S2(int plcNo)
  1929. {
  1930. string stationCode = "[OP20]";
  1931. string stationName = "上盖板上料装备";
  1932. string stationNameStr = stationCode + stationName;
  1933. string tagBaseName = "g_OP20_MES"; //标签变量名称
  1934. string tagMesCommName = "mesCommToPC"; //标签变量名称
  1935. string tagAgvCommName = "agvCommFrmPC";
  1936. string tagBarsetName = "BarcodeSet";
  1937. OP20_MesData_t stPLC_MesData; //PLC的MES数据
  1938. (int, string) result;
  1939. while (true)
  1940. {
  1941. try
  1942. {
  1943. if (!GlobalContext._IsCon_Funs2)
  1944. {
  1945. UpdatePLCMonitor(1, plcNo, 0);
  1946. continue;
  1947. }
  1948. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  1949. {
  1950. Stopwatch stopwatch1 = new Stopwatch();
  1951. Stopwatch stopwatch2 = new Stopwatch();
  1952. stopwatch1.Start();
  1953. stopwatch2.Start();
  1954. #region 一次性读取所有数据
  1955. // 一次性读取所有数据
  1956. result = FunsEip[plcNo].Read_SingleTag<OP20_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  1957. if (result.Item1 != 0)
  1958. {
  1959. //richTextBox1.AppendText("\n" + strRet);
  1960. }
  1961. else
  1962. {
  1963. //richTextBox1.AppendText("\n" + "读取成功");
  1964. }
  1965. #endregion 一次性读取所有数据
  1966. stopwatch2.Stop();
  1967. #region 进站
  1968. try
  1969. {
  1970. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  1971. {
  1972. lock (lockObj)
  1973. {
  1974. if (!ProgressState)
  1975. {
  1976. ProgressState = true;
  1977. Task.Run(() => S2进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  1978. }
  1979. }
  1980. }
  1981. }
  1982. catch (Exception ex)
  1983. {
  1984. ProgressState = false;
  1985. string str = ex.StackTrace;
  1986. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1987. }
  1988. #endregion 进站
  1989. #region 出站
  1990. try
  1991. {
  1992. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  1993. {
  1994. lock (lockObj)
  1995. {
  1996. if (!ProgressState)
  1997. {
  1998. ProgressState = true;
  1999. Task.Run(() => S2出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2000. stPLC_MesData.mesCommFrmPLC.cmd = 0;//清除入站申请
  2001. }
  2002. }
  2003. }
  2004. }
  2005. catch (Exception ex)
  2006. {
  2007. ProgressState = false;
  2008. string str = ex.StackTrace;
  2009. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2010. }
  2011. #endregion 出站
  2012. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2013. stopwatch1.Stop();
  2014. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  2015. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2016. }
  2017. else
  2018. {
  2019. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2020. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2021. FunsEip[plcNo].Connect();
  2022. }
  2023. }
  2024. catch (Exception ex)
  2025. {
  2026. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2027. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2028. //Funs[plcNo].ReConnect();
  2029. }
  2030. Thread.Sleep(IntervalReadPLC);
  2031. }
  2032. }
  2033. /// <summary>
  2034. /// [S2] 上盖板上料装备
  2035. /// </summary>
  2036. /// <param name="plcNo">PLC编号</param>
  2037. /// <param name="stationNameStr">工站全称</param>
  2038. private void S2进站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2039. {
  2040. Stopwatch stopwatch1 = new Stopwatch();
  2041. Stopwatch stopwatch2 = new Stopwatch();
  2042. try
  2043. {
  2044. stopwatch1.Start();
  2045. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2046. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有10和50返回
  2047. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  2048. string MachineId = GlobalContext.S2_MachineId; // 装备ID(可配置)
  2049. string StationId = GlobalContext.S2_StationId; // 工位ID(可配置)
  2050. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2051. //根据载具码获取产品码
  2052. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2053. if (string.IsNullOrEmpty(strProductBarcode))
  2054. {
  2055. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2056. }
  2057. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  2058. //if (sn != strProductBarcode)
  2059. //{
  2060. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  2061. //}
  2062. sn = strProductBarcode;
  2063. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2064. // 产品SN(物料码)校验
  2065. List<TestItem> item = new List<TestItem>();
  2066. stopwatch2.Start();
  2067. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2068. stopwatch2.Stop();
  2069. //指令执行结果 1:OK 110:失败
  2070. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2071. //进站结果写入PLC
  2072. CommandFromPLC resultToPlC = new CommandFromPLC();
  2073. resultToPlC.cmd = 0;
  2074. resultToPlC.cmdParam = 0; //指令参数
  2075. resultToPlC.cmdResult = mesResultFrmWeb;
  2076. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2077. }
  2078. catch (Exception ex)
  2079. {
  2080. string str = ex.StackTrace;
  2081. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2082. CommandFromPLC resultToPlC = new CommandFromPLC();
  2083. resultToPlC.cmd = 0;
  2084. resultToPlC.cmdParam = 0; //指令参数
  2085. resultToPlC.cmdResult = 110;
  2086. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2087. }
  2088. stopwatch1.Stop();
  2089. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2090. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2091. ProgressState = false;
  2092. }
  2093. /// <summary>
  2094. /// [S2] 上盖板上料装备 - 出站接口
  2095. /// </summary>
  2096. private void S2出站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2097. {
  2098. Stopwatch stopwatch1 = new Stopwatch();
  2099. Stopwatch stopwatch2 = new Stopwatch();
  2100. try
  2101. {
  2102. stopwatch1.Start();
  2103. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2104. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2105. string processItem = stationName; // 测试项目
  2106. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2107. string supplierCode = ""; // 供应商代码
  2108. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2109. string batch_num = GlobalContext.BatchNumber; // 批次号
  2110. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2111. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2112. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2113. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; //部件码
  2114. string MachineId = GlobalContext.S2_MachineId; // 装备id(可配置) // ZS
  2115. string StationId = GlobalContext.S2_StationId; // ⼯位ID(可配置) // ZS
  2116. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2117. bool pass = a1Result == 1;
  2118. //根据载具码获取产品码
  2119. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2120. if (string.IsNullOrEmpty(strProductBarcode))
  2121. {
  2122. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2123. }
  2124. sn = strProductBarcode;
  2125. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2126. List<TestItem> items = new List<TestItem>();
  2127. items.Add(new TestItem()
  2128. {
  2129. Parameter_name = "载具码",
  2130. Parameter_value = CarrierBarcode,
  2131. Parameter_unit = ""
  2132. });
  2133. items.Add(new TestItem()
  2134. {
  2135. Parameter_name = "产品码",
  2136. Parameter_value = sn,
  2137. Parameter_unit = ""
  2138. });
  2139. items.Add(new TestItem()
  2140. {
  2141. Parameter_name = "部件码",
  2142. Parameter_value = PartBarcode,
  2143. Parameter_unit = ""
  2144. });
  2145. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2146. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode);
  2147. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2148. stopwatch2.Start();
  2149. //进站结果写入PLC
  2150. CommandFromPLC resultToPlC = new CommandFromPLC();
  2151. resultToPlC.cmd = 0;
  2152. resultToPlC.cmdParam = 0; //指令参数
  2153. resultToPlC.cmdResult = mesResultFrmWeb;
  2154. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2155. stopwatch2.Stop();
  2156. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2157. //保存PLC返回MES数据到本地
  2158. ResponseMessage message = new ResponseMessage();
  2159. message = SQLHelper.InsertOp20Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.nRemainCount);
  2160. if (message.result == false)
  2161. {
  2162. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2163. }
  2164. if (!string.IsNullOrEmpty(PartBarcode))
  2165. {
  2166. message = SQLHelper.InsertOp20Product(CarrierBarcode, sn, PartBarcode);
  2167. if (message.result == false)
  2168. {
  2169. AddMessage(LogType.Error, message.text);
  2170. }
  2171. }
  2172. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2173. }
  2174. catch (Exception ex)
  2175. {
  2176. stopwatch2.Start();
  2177. CommandFromPLC resultToPlC = new CommandFromPLC();
  2178. resultToPlC.cmd = 0;
  2179. resultToPlC.cmdParam = 0; //指令参数
  2180. resultToPlC.cmdResult = 110;
  2181. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2182. stopwatch2.Stop();
  2183. string str = ex.StackTrace;
  2184. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2185. }
  2186. stopwatch1.Stop();
  2187. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2188. ProgressState = false;
  2189. }
  2190. #endregion
  2191. #region S3
  2192. /// <summary>
  2193. /// [S3] 点散热胶装备
  2194. /// </summary>
  2195. /// <param name="plcNo">PLC编号</param>
  2196. private void ReadStation_S3(int plcNo)
  2197. {
  2198. string stationCode = "[OP30]";
  2199. string stationName = "点散热胶装备";
  2200. string stationNameStr = stationCode + stationName;
  2201. string tagBaseName = "g_OP30_MES"; //标签变量名称
  2202. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2203. string tagAgvCommName = "agvCommFrmPC";
  2204. string tagBarsetName = "BarcodeSet";
  2205. OP30_MesData_t stPLC_MesData; //PLC的MES数据
  2206. (int, string) result;
  2207. #region 创建字典
  2208. // 触发信号字典 赋值
  2209. s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  2210. s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  2211. s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  2212. s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2213. s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2214. // PLC数据字典 赋值
  2215. s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  2216. s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  2217. s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2218. s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  2219. s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  2220. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2221. s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  2222. s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  2223. s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  2224. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2225. s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  2226. s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  2227. s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  2228. s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2229. s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  2230. s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  2231. //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  2232. s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  2233. s3PLCData.Add("c1Result", 0); // 产品结果
  2234. s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2235. s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  2236. s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  2237. s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  2238. #endregion 创建字典
  2239. while (true)
  2240. {
  2241. try
  2242. {
  2243. if (!GlobalContext._IsCon_Funs2)
  2244. {
  2245. UpdatePLCMonitor(1, plcNo, 0);
  2246. continue;
  2247. }
  2248. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2249. {
  2250. Stopwatch stopwatch1 = new Stopwatch();
  2251. Stopwatch stopwatch2 = new Stopwatch();
  2252. stopwatch1.Start();
  2253. stopwatch2.Start();
  2254. #region 一次性读取所有数据
  2255. // 一次性读取所有数据
  2256. result = FunsEip[plcNo].Read_SingleTag<OP30_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2257. if (result.Item1 != 0)
  2258. {
  2259. //richTextBox1.AppendText("\n" + strRet);
  2260. }
  2261. else
  2262. {
  2263. //richTextBox1.AppendText("\n" + "读取成功");
  2264. }
  2265. #endregion 一次性读取所有数据
  2266. stopwatch2.Stop();
  2267. #region 左边进站
  2268. try
  2269. {
  2270. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2271. {
  2272. lock (lockObj)
  2273. {
  2274. if (!ProgressState)
  2275. {
  2276. ProgressState = true;
  2277. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState));
  2278. }
  2279. }
  2280. }
  2281. }
  2282. catch (Exception ex)
  2283. {
  2284. ProgressState = false;
  2285. string str = ex.StackTrace;
  2286. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2287. }
  2288. #endregion 左边进站
  2289. #region 左边出站
  2290. try
  2291. {
  2292. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2293. {
  2294. lock (lockObj)
  2295. {
  2296. if (!ProgressState)
  2297. {
  2298. ProgressState = true;
  2299. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left", out ProgressState));
  2300. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  2301. }
  2302. }
  2303. }
  2304. }
  2305. catch (Exception ex)
  2306. {
  2307. ProgressState = false;
  2308. string str = ex.StackTrace;
  2309. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2310. }
  2311. #endregion 左边出站
  2312. #region 右边进站
  2313. try
  2314. {
  2315. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2316. {
  2317. lock (lockObj)
  2318. {
  2319. if (!ProgressState)
  2320. {
  2321. ProgressState = true;
  2322. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, tagBaseName + ".Right." + tagBarsetName,"Right", out ProgressState));
  2323. }
  2324. }
  2325. }
  2326. }
  2327. catch (Exception ex)
  2328. {
  2329. ProgressState = false;
  2330. string str = ex.StackTrace;
  2331. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2332. }
  2333. #endregion 右边进站
  2334. #region 右边出站
  2335. try
  2336. {
  2337. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2338. {
  2339. lock (lockObj)
  2340. {
  2341. if (!ProgressState)
  2342. {
  2343. ProgressState = true;
  2344. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right", out ProgressState));
  2345. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  2346. }
  2347. }
  2348. }
  2349. }
  2350. catch (Exception ex)
  2351. {
  2352. string str = ex.StackTrace;
  2353. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2354. }
  2355. #endregion 右边出站
  2356. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2357. stopwatch1.Stop();
  2358. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  2359. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2360. }
  2361. else
  2362. {
  2363. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2364. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2365. FunsEip[plcNo].Connect();
  2366. }
  2367. }
  2368. catch (Exception ex)
  2369. {
  2370. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2371. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2372. //Funs[plcNo].ReConnect();
  2373. }
  2374. Thread.Sleep(IntervalReadPLC);
  2375. }
  2376. }
  2377. /// <summary>
  2378. /// [S3] 点散热胶装备 - 进站
  2379. /// </summary>
  2380. /// <param name="plcNo">PLC编号</param>
  2381. /// <param name="stationNameStr">工站全称</param>
  2382. private void S3进站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName, string tagBarsetName,string direction, out bool ProgressState)
  2383. {
  2384. Stopwatch stopwatch1 = new Stopwatch();
  2385. Stopwatch stopwatch2 = new Stopwatch();
  2386. try
  2387. {
  2388. stopwatch1.Start();
  2389. AddMessage(LogType.Info, stationNameStr + "_"+ direction+"_进站开始");
  2390. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2391. string MachineId = GlobalContext.S3_MachineId; // 装备ID(可配置)
  2392. string StationId=string.Empty;
  2393. if (direction=="Left")
  2394. {
  2395. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  2396. }
  2397. if (direction == "Right")
  2398. {
  2399. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  2400. }
  2401. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2402. //载具码验证产品码
  2403. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2404. if (string.IsNullOrEmpty(strProductBarcode))
  2405. {
  2406. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2407. }
  2408. sn = strProductBarcode;
  2409. AddMessage(LogType.Info, $"载具码:{strProductBarcode};产品码:{sn}");
  2410. // 产品SN(物料码)校验
  2411. List<TestItem> item = new List<TestItem>();
  2412. stopwatch2.Start();
  2413. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2414. stopwatch2.Stop();
  2415. //指令执行结果 1:OK 110:失败
  2416. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2417. //进站结果写入PLC
  2418. CommandFromPLC resultToPlC = new CommandFromPLC();
  2419. resultToPlC.cmd = 0;
  2420. resultToPlC.cmdParam = 0; //指令参数
  2421. resultToPlC.cmdResult = mesResultFrmWeb;
  2422. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2423. }
  2424. catch (Exception ex)
  2425. {
  2426. string str = ex.StackTrace;
  2427. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2428. CommandFromPLC resultToPlC = new CommandFromPLC();
  2429. resultToPlC.cmd = 0;
  2430. resultToPlC.cmdParam = 0; //指令参数
  2431. resultToPlC.cmdResult = 110;
  2432. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2433. }
  2434. stopwatch1.Stop();
  2435. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  2436. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2437. ProgressState = false;
  2438. }
  2439. /// <summary>
  2440. /// [S3] 点散热胶装备 - 出站
  2441. /// </summary>
  2442. private void S3出站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, string direction, out bool ProgressState)
  2443. {
  2444. Stopwatch stopwatch1 = new Stopwatch();
  2445. Stopwatch stopwatch2 = new Stopwatch();
  2446. try
  2447. {
  2448. stopwatch1.Start();
  2449. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  2450. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2451. string processItem = stationName; // 测试项目
  2452. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2453. string supplierCode = ""; // 供应商代码
  2454. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2455. string batch_num = GlobalContext.BatchNumber; // 批次号
  2456. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2457. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2458. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2459. string MachineId = GlobalContext.S3_MachineId; // 装备id(可配置)
  2460. string StationId = string.Empty;
  2461. if (direction == "Left")
  2462. {
  2463. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  2464. }
  2465. if (direction == "Right")
  2466. {
  2467. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  2468. }
  2469. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2470. bool pass = a1Result == 1;
  2471. //根据载具码获取产品码
  2472. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2473. if (string.IsNullOrEmpty(strProductBarcode))
  2474. {
  2475. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2476. }
  2477. sn = strProductBarcode;
  2478. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2479. List<TestItem> items = new List<TestItem>();
  2480. items.Add(new TestItem()
  2481. {
  2482. Parameter_name = "载具码",
  2483. Parameter_value = CarrierBarcode,
  2484. Parameter_unit = ""
  2485. });
  2486. items.Add(new TestItem()
  2487. {
  2488. Parameter_name = "产品码",
  2489. Parameter_value = sn,
  2490. Parameter_unit = ""
  2491. });
  2492. int result1 = 1;
  2493. if (direction == "Right")
  2494. {
  2495. result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2496. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  2497. }
  2498. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2499. stopwatch2.Start();
  2500. //进站结果写入PLC
  2501. CommandFromPLC resultToPlC = new CommandFromPLC();
  2502. resultToPlC.cmd = 0;
  2503. resultToPlC.cmdParam = 0; //指令参数
  2504. resultToPlC.cmdResult = mesResultFrmWeb;
  2505. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2506. stopwatch2.Stop();
  2507. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  2508. //保存PLC返回MES数据到本地
  2509. ResponseMessage message = new ResponseMessage();
  2510. if (direction == "Left")
  2511. {
  2512. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  2513. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  2514. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  2515. message = SQLHelper.InsertOp301Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  2516. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  2517. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  2518. if (message.result == false)
  2519. {
  2520. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2521. }
  2522. }
  2523. if (direction == "Right")
  2524. {
  2525. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  2526. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  2527. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  2528. message = SQLHelper.InsertOp302Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  2529. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  2530. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  2531. if (message.result == false)
  2532. {
  2533. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2534. }
  2535. }
  2536. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2537. }
  2538. catch (Exception ex)
  2539. {
  2540. stopwatch2.Start();
  2541. CommandFromPLC resultToPlC = new CommandFromPLC();
  2542. resultToPlC.cmd = 0;
  2543. resultToPlC.cmdParam = 0; //指令参数
  2544. resultToPlC.cmdResult = 110;
  2545. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2546. stopwatch2.Stop();
  2547. string str = ex.StackTrace;
  2548. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2549. }
  2550. stopwatch1.Stop();
  2551. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2552. ProgressState = false;
  2553. }
  2554. #endregion S3
  2555. #region S4
  2556. /// <summary>
  2557. /// [S4] 点胶检测设备
  2558. /// </summary>
  2559. /// <param name="plcNo">PLC编号</param>
  2560. private void ReadStation_S4(int plcNo)
  2561. {
  2562. string stationCode = "[OP40]";
  2563. string stationName = "胶线检测";
  2564. string stationNameStr = stationCode + stationName;
  2565. string tagBaseName = "g_OP40_MES"; //标签变量名称
  2566. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2567. string tagAgvCommName = "agvCommFrmPC";
  2568. string tagBarsetName = "BarcodeSet";
  2569. OP40_MesData_t stPLC_MesData; //PLC的MES数据
  2570. (int, string) result;
  2571. while (true)
  2572. {
  2573. try
  2574. {
  2575. if (!GlobalContext._IsCon_Funs1)
  2576. {
  2577. UpdatePLCMonitor(1, plcNo, 0);
  2578. continue;
  2579. }
  2580. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2581. {
  2582. Stopwatch stopwatch1 = new Stopwatch();
  2583. Stopwatch stopwatch2 = new Stopwatch();
  2584. stopwatch1.Start();
  2585. stopwatch2.Start();
  2586. #region 一次性读取所有数据
  2587. // 一次性读取所有数据
  2588. result = FunsEip[plcNo].Read_SingleTag<OP40_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2589. if (result.Item1 != 0)
  2590. {
  2591. //richTextBox1.AppendText("\n" + strRet);
  2592. }
  2593. else
  2594. {
  2595. //richTextBox1.AppendText("\n" + "读取成功");
  2596. }
  2597. #endregion 一次性读取所有数据
  2598. stopwatch2.Stop();
  2599. #region 进站
  2600. try
  2601. {
  2602. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2603. {
  2604. lock (lockObj)
  2605. {
  2606. if (!ProgressState)
  2607. {
  2608. ProgressState = true;
  2609. Task.Run(() => S4进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2610. }
  2611. }
  2612. }
  2613. }
  2614. catch (Exception ex)
  2615. {
  2616. ProgressState = false;
  2617. string str = ex.StackTrace;
  2618. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2619. }
  2620. #endregion 进站
  2621. #region 出站
  2622. try
  2623. {
  2624. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2625. {
  2626. lock (lockObj)
  2627. {
  2628. if (!ProgressState)
  2629. {
  2630. ProgressState = true;
  2631. Task.Run(() => S4出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2632. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  2633. }
  2634. }
  2635. }
  2636. }
  2637. catch (Exception ex)
  2638. {
  2639. string str = ex.StackTrace;
  2640. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2641. }
  2642. #endregion 出站
  2643. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2644. stopwatch1.Stop();
  2645. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2646. }
  2647. else
  2648. {
  2649. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2650. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2651. FunsEip[plcNo].Connect(); // 重连
  2652. }
  2653. }
  2654. catch (Exception ex)
  2655. {
  2656. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2657. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2658. }
  2659. Thread.Sleep(IntervalReadPLC);
  2660. }
  2661. }
  2662. /// <summary>
  2663. /// [S4] 点胶检测设备 - 进站
  2664. /// </summary>
  2665. /// <param name="plcNo">PLC编号</param>
  2666. /// <param name="stationNameStr">工站全称</param>
  2667. /// <param name="stPLC_MesData"></param>
  2668. /// <param name="tagMesCommName"></param>
  2669. private void S4进站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2670. {
  2671. Stopwatch stopwatch1 = new Stopwatch();
  2672. Stopwatch stopwatch2 = new Stopwatch();
  2673. try
  2674. {
  2675. stopwatch1.Start();
  2676. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2677. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2678. string MachineId = GlobalContext.S4_MachineId; // 装备ID(可配置)
  2679. string StationId = GlobalContext.S4_StationId; // 工位ID(可配置)
  2680. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2681. //载具码验证产品码
  2682. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2683. if (string.IsNullOrEmpty(strProductBarcode))
  2684. {
  2685. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2686. }
  2687. sn = strProductBarcode;
  2688. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2689. // 产品SN(物料码)校验
  2690. List<TestItem> item = new List<TestItem>();
  2691. stopwatch2.Start();
  2692. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2693. stopwatch2.Stop();
  2694. //指令执行结果 1:OK 110:失败
  2695. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2696. //进站结果写入PLC
  2697. CommandFromPLC resultToPlC = new CommandFromPLC();
  2698. resultToPlC.cmd = 0;
  2699. resultToPlC.cmdParam = 0; //指令参数
  2700. resultToPlC.cmdResult = mesResultFrmWeb;
  2701. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2702. }
  2703. catch (Exception ex)
  2704. {
  2705. string str = ex.StackTrace;
  2706. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2707. CommandFromPLC resultToPlC = new CommandFromPLC();
  2708. resultToPlC.cmd = 0;
  2709. resultToPlC.cmdParam = 0; //指令参数
  2710. resultToPlC.cmdResult = 110;
  2711. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2712. }
  2713. stopwatch1.Stop();
  2714. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2715. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2716. ProgressState = false;
  2717. }
  2718. /// <summary>
  2719. /// [S4] 点胶检测设备 - 出站接口
  2720. /// </summary>
  2721. private void S4出站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2722. {
  2723. Stopwatch stopwatch1 = new Stopwatch();
  2724. Stopwatch stopwatch2 = new Stopwatch();
  2725. try
  2726. {
  2727. stopwatch1.Start();
  2728. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2729. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2730. string processItem = stationName; // 测试项目
  2731. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2732. string supplierCode = ""; // 供应商代码
  2733. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2734. string batch_num = GlobalContext.BatchNumber; // 批次号
  2735. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2736. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2737. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2738. string MachineId = GlobalContext.S4_MachineId; // 装备id(可配置) // ZS
  2739. string StationId = GlobalContext.S4_StationId; // ⼯位ID(可配置) // ZS
  2740. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2741. bool pass = a1Result == 1;
  2742. //根据载具码获取产品码
  2743. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2744. if (string.IsNullOrEmpty(strProductBarcode))
  2745. {
  2746. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2747. }
  2748. sn = strProductBarcode;
  2749. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2750. List<TestItem> items = new List<TestItem>();
  2751. items.Add(new TestItem()
  2752. {
  2753. Parameter_name = "载具码",
  2754. Parameter_value = CarrierBarcode,
  2755. Parameter_unit = ""
  2756. });
  2757. items.Add(new TestItem()
  2758. {
  2759. Parameter_name = "产品码",
  2760. Parameter_value = sn,
  2761. Parameter_unit = ""
  2762. });
  2763. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2764. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  2765. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2766. stopwatch2.Start();
  2767. //进站结果写入PLC
  2768. CommandFromPLC resultToPlC = new CommandFromPLC();
  2769. resultToPlC.cmd = 0;
  2770. resultToPlC.cmdParam = 0; //指令参数
  2771. resultToPlC.cmdResult = mesResultFrmWeb;
  2772. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2773. stopwatch2.Stop();
  2774. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2775. //保存PLC返回MES数据到本地
  2776. ResponseMessage message = new ResponseMessage();
  2777. string strGluePosX = FloatArrayToString(stPLC_MesData.mesData.fGluePosX);
  2778. string strGluePosY = FloatArrayToString(stPLC_MesData.mesData.fGluePosY);
  2779. string strGlue_Areas = FloatArrayToString(stPLC_MesData.mesData.fGlue_Areas);
  2780. string strGlue_Heights = FloatArrayToString(stPLC_MesData.mesData.fGlue_Heights);
  2781. message = SQLHelper.InsertOp40Data(CarrierBarcode, sn, strGluePosX,
  2782. strGluePosY, strGlue_Areas, strGlue_Heights, stPLC_MesData.mesData.nResult, "");
  2783. if (message.result == false)
  2784. {
  2785. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2786. }
  2787. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2788. }
  2789. catch (Exception ex)
  2790. {
  2791. stopwatch2.Start();
  2792. CommandFromPLC resultToPlC = new CommandFromPLC();
  2793. resultToPlC.cmd = 0;
  2794. resultToPlC.cmdParam = 0; //指令参数
  2795. resultToPlC.cmdResult = 110;
  2796. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2797. stopwatch2.Stop();
  2798. string str = ex.StackTrace;
  2799. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2800. }
  2801. stopwatch1.Stop();
  2802. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2803. ProgressState = false;
  2804. }
  2805. #endregion
  2806. #region S5
  2807. /// <summary>
  2808. /// [S5] 点胶检测设备
  2809. /// </summary>
  2810. /// <param name="plcNo">PLC编号</param>
  2811. private void ReadStation_S5(int plcNo)
  2812. {
  2813. string stationCode = "[OP50]";
  2814. string stationName = "ADD板上料组装装备";
  2815. string stationNameStr = stationCode + stationName;
  2816. string tagBaseName = "g_OP50_MES"; //标签变量名称
  2817. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2818. string tagAgvCommName = "agvCommFrmPC";
  2819. string tagBarsetName = "BarcodeSet";
  2820. OP50_MesData_t stPLC_MesData; //PLC的MES数据
  2821. (int, string) result;
  2822. while (true)
  2823. {
  2824. try
  2825. {
  2826. if (!GlobalContext._IsCon_Funs1)
  2827. {
  2828. UpdatePLCMonitor(1, plcNo, 0);
  2829. continue;
  2830. }
  2831. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2832. {
  2833. Stopwatch stopwatch1 = new Stopwatch();
  2834. Stopwatch stopwatch2 = new Stopwatch();
  2835. stopwatch1.Start();
  2836. stopwatch2.Start();
  2837. #region 一次性读取所有数据
  2838. // 一次性读取所有数据
  2839. result = FunsEip[plcNo].Read_SingleTag<OP50_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2840. if (result.Item1 != 0)
  2841. {
  2842. //richTextBox1.AppendText("\n" + strRet);
  2843. }
  2844. else
  2845. {
  2846. //richTextBox1.AppendText("\n" + "读取成功");
  2847. }
  2848. #endregion 一次性读取所有数据
  2849. stopwatch2.Stop();
  2850. #region 进站
  2851. try
  2852. {
  2853. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2854. {
  2855. lock (lockObj)
  2856. {
  2857. if (!ProgressState)
  2858. {
  2859. ProgressState = true;
  2860. Task.Run(() => S5进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2861. }
  2862. }
  2863. }
  2864. }
  2865. catch (Exception ex)
  2866. {
  2867. ProgressState = false;
  2868. string str = ex.StackTrace;
  2869. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2870. }
  2871. #endregion 进站
  2872. #region 出站
  2873. try
  2874. {
  2875. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2876. {
  2877. lock (lockObj)
  2878. {
  2879. if (!ProgressState)
  2880. {
  2881. ProgressState = true;
  2882. Task.Run(() => S5出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2883. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  2884. }
  2885. }
  2886. }
  2887. }
  2888. catch (Exception ex)
  2889. {
  2890. ProgressState = false;
  2891. string str = ex.StackTrace;
  2892. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2893. }
  2894. #endregion 出站
  2895. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2896. stopwatch1.Stop();
  2897. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2898. }
  2899. else
  2900. {
  2901. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2902. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2903. FunsEip[plcNo].Connect(); // 重连
  2904. }
  2905. }
  2906. catch (Exception ex)
  2907. {
  2908. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2909. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2910. }
  2911. Thread.Sleep(IntervalReadPLC);
  2912. }
  2913. }
  2914. /// <summary>
  2915. /// [S5] 点胶检测设备 - 进站
  2916. /// </summary>
  2917. /// <param name="plcNo">PLC编号</param>
  2918. /// <param name="stationNameStr">工站全称</param>
  2919. /// <param name="stPLC_MesData"></param>
  2920. /// <param name="tagMesCommName"></param>
  2921. private void S5进站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2922. {
  2923. Stopwatch stopwatch1 = new Stopwatch();
  2924. Stopwatch stopwatch2 = new Stopwatch();
  2925. try
  2926. {
  2927. stopwatch1.Start();
  2928. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2929. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2930. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  2931. string MachineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  2932. string StationId = GlobalContext.S5_StationId; // 工位ID(可配置)
  2933. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2934. //载具码验证产品码 //载具码验证产品码
  2935. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2936. if (string.IsNullOrEmpty(strProductBarcode))
  2937. {
  2938. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2939. }
  2940. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  2941. //if (sn != strProductBarcode)
  2942. //{
  2943. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  2944. //}
  2945. sn = strProductBarcode;
  2946. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2947. // 产品SN(物料码)校验
  2948. List<TestItem> item = new List<TestItem>();
  2949. stopwatch2.Start();
  2950. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2951. stopwatch2.Stop();
  2952. //指令执行结果 1:OK 110:失败
  2953. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2954. //进站结果写入PLC
  2955. CommandFromPLC resultToPlC = new CommandFromPLC();
  2956. resultToPlC.cmd = 0;
  2957. resultToPlC.cmdParam = 0; //指令参数
  2958. resultToPlC.cmdResult = mesResultFrmWeb;
  2959. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2960. }
  2961. catch (Exception ex)
  2962. {
  2963. string str = ex.StackTrace;
  2964. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2965. CommandFromPLC resultToPlC = new CommandFromPLC();
  2966. resultToPlC.cmd = 0;
  2967. resultToPlC.cmdParam = 0; //指令参数
  2968. resultToPlC.cmdResult = 110;
  2969. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2970. }
  2971. stopwatch1.Stop();
  2972. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2973. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2974. ProgressState = false;
  2975. }
  2976. /// <summary>
  2977. /// [S5] 点胶检测设备 - 出站接口
  2978. /// </summary>
  2979. private void S5出站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2980. {
  2981. Stopwatch stopwatch1 = new Stopwatch();
  2982. Stopwatch stopwatch2 = new Stopwatch();
  2983. try
  2984. {
  2985. stopwatch1.Start();
  2986. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2987. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2988. string processItem = stationName; // 测试项目
  2989. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2990. string supplierCode = ""; // 供应商代码
  2991. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2992. string batch_num = GlobalContext.BatchNumber; // 批次号
  2993. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2994. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2995. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; // 产品条码;
  2996. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2997. string MachineId = GlobalContext.S5_MachineId; // 装备id(可配置) // ZS
  2998. string StationId = GlobalContext.S5_StationId; // ⼯位ID(可配置) // ZS
  2999. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3000. bool pass = a1Result == 1;
  3001. //根据载具码获取产品码
  3002. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3003. if (string.IsNullOrEmpty(strProductBarcode))
  3004. {
  3005. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3006. }
  3007. sn = strProductBarcode;
  3008. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3009. List<TestItem> items = new List<TestItem>();
  3010. items.Add(new TestItem()
  3011. {
  3012. Parameter_name = "载具码",
  3013. Parameter_value = CarrierBarcode,
  3014. Parameter_unit = ""
  3015. });
  3016. items.Add(new TestItem()
  3017. {
  3018. Parameter_name = "产品码",
  3019. Parameter_value = sn,
  3020. Parameter_unit = ""
  3021. });
  3022. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3023. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode);
  3024. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3025. stopwatch2.Start();
  3026. //进站结果写入PLC
  3027. CommandFromPLC resultToPlC = new CommandFromPLC();
  3028. resultToPlC.cmd = 0;
  3029. resultToPlC.cmdParam = 0; //指令参数
  3030. resultToPlC.cmdResult = mesResultFrmWeb;
  3031. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3032. stopwatch2.Stop();
  3033. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3034. //保存PLC返回MES数据到本地
  3035. ResponseMessage message = new ResponseMessage();
  3036. message = SQLHelper.InsertOp50Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsAddPCBAsmOK,
  3037. stPLC_MesData.mesData.nHaveAddPCB, stPLC_MesData.mesData.fForceAddPCB, stPLC_MesData.mesData.nRemainCount, "");
  3038. if (message.result == false)
  3039. {
  3040. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3041. }
  3042. //保存部件码信息
  3043. if (!string.IsNullOrEmpty(PartBarcode))
  3044. {
  3045. message = SQLHelper.InsertOp50Product(CarrierBarcode, sn, PartBarcode);
  3046. if (message.result == false)
  3047. {
  3048. AddMessage(LogType.Info, stationNameStr + "_保存部件码信息失败");
  3049. }
  3050. }
  3051. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3052. }
  3053. catch (Exception ex)
  3054. {
  3055. stopwatch2.Start();
  3056. CommandFromPLC resultToPlC = new CommandFromPLC();
  3057. resultToPlC.cmd = 0;
  3058. resultToPlC.cmdParam = 0; //指令参数
  3059. resultToPlC.cmdResult = 110;
  3060. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3061. stopwatch2.Stop();
  3062. string str = ex.StackTrace;
  3063. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3064. }
  3065. stopwatch1.Stop();
  3066. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3067. ProgressState = false;
  3068. }
  3069. #endregion
  3070. #region S6
  3071. /// <summary>
  3072. /// [S6] 顶盖装配设备
  3073. /// </summary>
  3074. /// <param name="plcNo">PLC编号</param>
  3075. private void ReadStation_S6(int plcNo)
  3076. {
  3077. string stationCode = "[OP60]";
  3078. string stationName = "组上盖板";
  3079. string stationNameStr = stationCode + stationName;
  3080. string tagBaseName = "g_OP60_MES"; //标签变量名称
  3081. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3082. string tagAgvCommName = "agvCommFrmPC";
  3083. string tagBarsetName = "BarcodeSet";
  3084. OP60_MesData_t stPLC_MesData; //PLC的MES数据
  3085. (int, string) result;
  3086. while (true)
  3087. {
  3088. try
  3089. {
  3090. if (!GlobalContext._IsCon_Funs1)
  3091. {
  3092. UpdatePLCMonitor(1, plcNo, 0);
  3093. continue;
  3094. }
  3095. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3096. {
  3097. Stopwatch stopwatch1 = new Stopwatch();
  3098. Stopwatch stopwatch2 = new Stopwatch();
  3099. stopwatch1.Start();
  3100. stopwatch2.Start();
  3101. #region 一次性读取所有数据
  3102. // 一次性读取所有数据
  3103. result = FunsEip[plcNo].Read_SingleTag<OP60_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3104. if (result.Item1 != 0)
  3105. {
  3106. //richTextBox1.AppendText("\n" + strRet);
  3107. }
  3108. else
  3109. {
  3110. //richTextBox1.AppendText("\n" + "读取成功");
  3111. }
  3112. #endregion 一次性读取所有数据
  3113. stopwatch2.Stop();
  3114. #region 进站
  3115. try
  3116. {
  3117. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3118. {
  3119. lock (lockObj)
  3120. {
  3121. if (!ProgressState)
  3122. {
  3123. ProgressState = true;
  3124. Task.Run(() => S6进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3125. }
  3126. }
  3127. }
  3128. }
  3129. catch (Exception ex)
  3130. {
  3131. ProgressState = false;
  3132. string str = ex.StackTrace;
  3133. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3134. }
  3135. #endregion 进站
  3136. #region 出站
  3137. try
  3138. {
  3139. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3140. {
  3141. lock (lockObj)
  3142. {
  3143. if (!ProgressState)
  3144. {
  3145. ProgressState = true; ;
  3146. Task.Run(() => S6出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3147. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  3148. }
  3149. }
  3150. }
  3151. }
  3152. catch (Exception ex)
  3153. {
  3154. ProgressState = false;
  3155. string str = ex.StackTrace;
  3156. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3157. }
  3158. #endregion 出站
  3159. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3160. stopwatch1.Stop();
  3161. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3162. }
  3163. else
  3164. {
  3165. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3166. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3167. FunsEip[plcNo].Connect(); // 重连
  3168. }
  3169. }
  3170. catch (Exception ex)
  3171. {
  3172. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3173. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3174. }
  3175. Thread.Sleep(IntervalReadPLC);
  3176. }
  3177. }
  3178. /// <summary>
  3179. /// [S6] 顶盖装配设备 - 进站
  3180. /// </summary>
  3181. /// <param name="plcNo">PLC编号</param>
  3182. /// <param name="stationNameStr">工站全称</param>
  3183. /// <param name="stPLC_MesData"></param>
  3184. /// <param name="tagMesCommName"></param>
  3185. private void S6进站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3186. {
  3187. Stopwatch stopwatch1 = new Stopwatch();
  3188. Stopwatch stopwatch2 = new Stopwatch();
  3189. try
  3190. {
  3191. stopwatch1.Start();
  3192. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3193. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3194. string MachineId = GlobalContext.S6_MachineId; // 装备ID(可配置)
  3195. string StationId = GlobalContext.S6_StationId; // 工位ID(可配置)
  3196. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3197. //载具码验证产品码
  3198. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3199. if (string.IsNullOrEmpty(strProductBarcode))
  3200. {
  3201. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3202. }
  3203. sn = strProductBarcode;
  3204. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3205. // 产品SN(物料码)校验
  3206. List<TestItem> item = new List<TestItem>();
  3207. stopwatch2.Start();
  3208. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3209. stopwatch2.Stop();
  3210. //指令执行结果 1:OK 110:失败
  3211. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3212. //进站结果写入PLC
  3213. CommandFromPLC resultToPlC = new CommandFromPLC();
  3214. resultToPlC.cmd = 0;
  3215. resultToPlC.cmdParam = 0; //指令参数
  3216. resultToPlC.cmdResult = mesResultFrmWeb;
  3217. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3218. }
  3219. catch (Exception ex)
  3220. {
  3221. string str = ex.StackTrace;
  3222. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3223. CommandFromPLC resultToPlC = new CommandFromPLC();
  3224. resultToPlC.cmd = 0;
  3225. resultToPlC.cmdParam = 0; //指令参数
  3226. resultToPlC.cmdResult = 110;
  3227. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3228. }
  3229. stopwatch1.Stop();
  3230. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3231. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3232. ProgressState = false;
  3233. }
  3234. /// <summary>
  3235. /// [S6] 顶盖装配设备 - 出站接口
  3236. /// </summary>
  3237. private void S6出站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3238. {
  3239. Stopwatch stopwatch1 = new Stopwatch();
  3240. Stopwatch stopwatch2 = new Stopwatch();
  3241. try
  3242. {
  3243. stopwatch1.Start();
  3244. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3245. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3246. string processItem = stationName; // 测试项目
  3247. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3248. string supplierCode = ""; // 供应商代码
  3249. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3250. string batch_num = GlobalContext.BatchNumber; // 批次号
  3251. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3252. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3253. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3254. string MachineId = GlobalContext.S6_MachineId; // 装备id(可配置) // ZS
  3255. string StationId = GlobalContext.S6_StationId; // ⼯位ID(可配置) // ZS
  3256. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3257. bool pass = a1Result == 1;
  3258. //根据载具码获取产品码
  3259. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3260. if (string.IsNullOrEmpty(strProductBarcode))
  3261. {
  3262. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3263. }
  3264. sn = strProductBarcode;
  3265. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3266. List<TestItem> items = new List<TestItem>();
  3267. items.Add(new TestItem()
  3268. {
  3269. Parameter_name = "载具码",
  3270. Parameter_value = CarrierBarcode,
  3271. Parameter_unit = ""
  3272. });
  3273. items.Add(new TestItem()
  3274. {
  3275. Parameter_name = "产品码",
  3276. Parameter_value = sn,
  3277. Parameter_unit = ""
  3278. });
  3279. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3280. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3281. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3282. stopwatch2.Start();
  3283. //进站结果写入PLC
  3284. CommandFromPLC resultToPlC = new CommandFromPLC();
  3285. resultToPlC.cmd = 0;
  3286. resultToPlC.cmdParam = 0; //指令参数
  3287. resultToPlC.cmdResult = mesResultFrmWeb;
  3288. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3289. stopwatch2.Stop();
  3290. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3291. //保存PLC返回MES数据到本地
  3292. ResponseMessage message = new ResponseMessage();
  3293. message = SQLHelper.InsertOp60Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsTopCoverAsmOK,
  3294. stPLC_MesData.mesData.nHaveTopCover, stPLC_MesData.mesData.fForceTopCover, "");
  3295. if (message.result == false)
  3296. {
  3297. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3298. }
  3299. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3300. }
  3301. catch (Exception ex)
  3302. {
  3303. stopwatch2.Start();
  3304. CommandFromPLC resultToPlC = new CommandFromPLC();
  3305. resultToPlC.cmd = 0;
  3306. resultToPlC.cmdParam = 0; //指令参数
  3307. resultToPlC.cmdResult = 110;
  3308. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3309. stopwatch2.Stop();
  3310. string str = ex.StackTrace;
  3311. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3312. }
  3313. stopwatch1.Stop();
  3314. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3315. ProgressState = false;
  3316. }
  3317. #endregion
  3318. #region S7
  3319. /// <summary>
  3320. /// [S7] 锁螺丝设备
  3321. /// </summary>
  3322. /// <param name="plcNo">PLC编号</param>
  3323. private void ReadStation_S7(int plcNo)
  3324. {
  3325. string stationCode = "[OP70]";
  3326. string stationName = "上盖板锁螺丝";
  3327. string stationNameStr = stationCode + stationName;
  3328. string tagBaseName = "g_OP70_MES"; //标签变量名称
  3329. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3330. string tagAgvCommName = "agvCommFrmPC";
  3331. string tagBarsetName = "BarcodeSet";
  3332. string tagScrewDataset = "screwDataset";
  3333. OP70_MesData_t stPLC_MesData; //PLC的MES数据
  3334. (int, string) result;
  3335. AtlasScrew atlasScrewLeft= new AtlasScrew(GlobalContext.AtlasAddressLeft, GlobalContext.AtlasAddressPort, 3000, 3000,"Left");
  3336. atlasScrewLeft.Initial();
  3337. AtlasScrew atlasScrewRight = new AtlasScrew(GlobalContext.AtlasAddressRight, GlobalContext.AtlasAddressPort, 3000, 3000,"Right");
  3338. atlasScrewRight.Initial();
  3339. while (true)
  3340. {
  3341. try
  3342. {
  3343. if (!GlobalContext._IsCon_Funs1)
  3344. {
  3345. UpdatePLCMonitor(1, plcNo, 0);
  3346. continue;
  3347. }
  3348. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3349. {
  3350. Stopwatch stopwatch1 = new Stopwatch();
  3351. Stopwatch stopwatch2 = new Stopwatch();
  3352. stopwatch1.Start();
  3353. stopwatch2.Start();
  3354. #region 一次性读取所有数据
  3355. // 一次性读取所有数据
  3356. result = FunsEip[plcNo].Read_SingleTag<OP70_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3357. if (result.Item1 != 0)
  3358. {
  3359. //richTextBox1.AppendText("\n" + strRet);
  3360. }
  3361. else
  3362. {
  3363. //richTextBox1.AppendText("\n" + "读取成功");
  3364. }
  3365. #endregion 一次性读取所有数据
  3366. stopwatch2.Stop();
  3367. #region 左边进站
  3368. try
  3369. {
  3370. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3371. {
  3372. lock (lockObj)
  3373. {
  3374. if (!ProgressState)
  3375. {
  3376. ProgressState = true;
  3377. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, tagBaseName + ".Left." + tagBarsetName,"Left", out ProgressState, atlasScrewLeft));
  3378. }
  3379. }
  3380. }
  3381. }
  3382. catch (Exception ex)
  3383. {
  3384. ProgressState = false;
  3385. string str = ex.StackTrace;
  3386. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3387. }
  3388. #endregion 左边进站
  3389. #region 左边出站
  3390. try
  3391. {
  3392. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3393. {
  3394. lock (lockObj)
  3395. {
  3396. if (!ProgressState)
  3397. {
  3398. ProgressState = true;
  3399. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left", out ProgressState));
  3400. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  3401. }
  3402. }
  3403. }
  3404. }
  3405. catch (Exception ex)
  3406. {
  3407. ProgressState = false;
  3408. string str = ex.StackTrace;
  3409. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3410. }
  3411. #endregion 左边出站
  3412. #region 右边进站
  3413. try
  3414. {
  3415. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3416. {
  3417. lock (lockObj)
  3418. {
  3419. if (!ProgressState)
  3420. {
  3421. ProgressState = true;
  3422. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, tagBaseName + ".Right" + tagBarsetName,"Right", out ProgressState, atlasScrewRight));
  3423. }
  3424. }
  3425. }
  3426. }
  3427. catch (Exception ex)
  3428. {
  3429. ProgressState = false;
  3430. string str = ex.StackTrace;
  3431. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3432. }
  3433. #endregion 右边进站
  3434. #region 右边出站
  3435. try
  3436. {
  3437. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3438. {
  3439. lock (lockObj)
  3440. {
  3441. if (!ProgressState)
  3442. {
  3443. ProgressState = true;
  3444. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right", out ProgressState));
  3445. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  3446. }
  3447. }
  3448. }
  3449. }
  3450. catch (Exception ex)
  3451. {
  3452. ProgressState = false;
  3453. string str = ex.StackTrace;
  3454. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3455. }
  3456. #endregion 右边出站
  3457. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3458. stopwatch1.Stop();
  3459. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3460. }
  3461. else
  3462. {
  3463. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3464. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3465. FunsEip[plcNo].Connect(); // 重连
  3466. }
  3467. }
  3468. catch (Exception ex)
  3469. {
  3470. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3471. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3472. }
  3473. Thread.Sleep(IntervalReadPLC);
  3474. }
  3475. }
  3476. /// <summary>
  3477. /// [S7] 锁螺丝设备 - 进站
  3478. /// </summary>
  3479. /// <param name="plcNo">PLC编号</param>
  3480. /// <param name="stationNameStr">工站全称</param>
  3481. /// <param name="stPLC_MesData"></param>
  3482. /// <param name="tagMesCommName"></param>
  3483. private void S7进站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName, string tagBarsetName, string direction,out bool ProgressState, AtlasScrew atlasScrew)
  3484. {
  3485. Stopwatch stopwatch1 = new Stopwatch();
  3486. Stopwatch stopwatch2 = new Stopwatch();
  3487. string atlasSn=string.Empty;
  3488. try
  3489. {
  3490. stopwatch1.Start();
  3491. AddMessage(LogType.Info, stationNameStr +"_"+ direction+"_进站开始");
  3492. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3493. string MachineId = GlobalContext.S7_MachineId; // 装备ID(可配置)
  3494. string StationId = string.Empty; // 工位ID(可配置)
  3495. if (direction == "Left")
  3496. {
  3497. StationId = GlobalContext.S7_StationId_1;
  3498. }
  3499. if (direction == "Right")
  3500. {
  3501. StationId = GlobalContext.S7_StationId_2;
  3502. }
  3503. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3504. //载具码验证产品码
  3505. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3506. if (string.IsNullOrEmpty(strProductBarcode))
  3507. {
  3508. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3509. }
  3510. sn = strProductBarcode;
  3511. atlasSn= strProductBarcode;
  3512. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3513. if (direction == "Left")
  3514. {
  3515. isCollectingFlagLeft = false;//采集螺丝数据结束
  3516. }
  3517. if (direction == "Right")
  3518. {
  3519. isCollectingFlagRight = false;//采集螺丝数据结束
  3520. }
  3521. // 产品SN(物料码)校验
  3522. List<TestItem> item = new List<TestItem>();
  3523. stopwatch2.Start();
  3524. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3525. stopwatch2.Stop();
  3526. //指令执行结果 1:OK 110:失败
  3527. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3528. //进站结果写入PLC
  3529. CommandFromPLC resultToPlC = new CommandFromPLC();
  3530. resultToPlC.cmd = 0;
  3531. resultToPlC.cmdParam = 0; //指令参数
  3532. resultToPlC.cmdResult = mesResultFrmWeb;
  3533. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3534. }
  3535. catch (Exception ex)
  3536. {
  3537. string str = ex.StackTrace;
  3538. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3539. CommandFromPLC resultToPlC = new CommandFromPLC();
  3540. resultToPlC.cmd = 0;
  3541. resultToPlC.cmdParam = 0; //指令参数
  3542. resultToPlC.cmdResult = 110;
  3543. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3544. }
  3545. stopwatch1.Stop();
  3546. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  3547. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3548. ProgressState = false;
  3549. //开始采集螺丝数据
  3550. if (direction == "Left")
  3551. {
  3552. isCollectingFlagLeft = true;
  3553. CollectAndProcessDataLeft(atlasScrew, atlasSn, direction);
  3554. }
  3555. if (direction == "Right")
  3556. {
  3557. isCollectingFlagRight = true;
  3558. CollectAndProcessDataRight(atlasScrew, atlasSn, direction);
  3559. }
  3560. }
  3561. /// <summary>
  3562. /// [S7] 锁螺丝设备 - 出站
  3563. /// </summary>
  3564. private void S7出站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, string direction, out bool ProgressState)
  3565. {
  3566. Stopwatch stopwatch1 = new Stopwatch();
  3567. Stopwatch stopwatch2 = new Stopwatch();
  3568. try
  3569. {
  3570. stopwatch1.Start();
  3571. AddMessage(LogType.Info, stationNameStr +"_"+ direction+ "_出站开始");
  3572. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3573. string processItem = stationName; // 测试项目
  3574. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3575. string supplierCode = ""; // 供应商代码
  3576. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3577. string batch_num = GlobalContext.BatchNumber; // 批次号
  3578. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3579. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3580. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3581. string MachineId = GlobalContext.S7_MachineId; // 装备id(可配置)
  3582. string StationId = string.Empty; // 工位ID(可配置)
  3583. if (direction == "Left")
  3584. {
  3585. StationId = GlobalContext.S7_StationId_1;
  3586. }
  3587. if (direction == "Right")
  3588. {
  3589. StationId = GlobalContext.S7_StationId_2;
  3590. }
  3591. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3592. a1Result = 1;
  3593. bool pass = a1Result == 1;
  3594. //根据载具码获取产品码
  3595. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3596. if (string.IsNullOrEmpty(strProductBarcode))
  3597. {
  3598. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3599. }
  3600. sn = strProductBarcode;
  3601. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3602. List<TestItem> items = new List<TestItem>();
  3603. items.Add(new TestItem()
  3604. {
  3605. Parameter_name = "载具码",
  3606. Parameter_value = CarrierBarcode,
  3607. Parameter_unit = ""
  3608. });
  3609. items.Add(new TestItem()
  3610. {
  3611. Parameter_name = "产品码",
  3612. Parameter_value = sn,
  3613. Parameter_unit = ""
  3614. });
  3615. int result1 = 1;
  3616. if (direction == "Right")
  3617. {
  3618. SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3619. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3620. }
  3621. //if (direction == "Left")
  3622. //{
  3623. // isCollectingFlagLeft = false;//采集螺丝数据结束
  3624. //}
  3625. //if (direction == "Right")
  3626. //{
  3627. // isCollectingFlagRight = false;//采集螺丝数据结束
  3628. //}
  3629. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3630. stopwatch2.Start();
  3631. //进站结果写入PLC
  3632. CommandFromPLC resultToPlC = new CommandFromPLC();
  3633. resultToPlC.cmd = 0;
  3634. resultToPlC.cmdParam = 0; //指令参数
  3635. resultToPlC.cmdResult = mesResultFrmWeb;
  3636. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3637. stopwatch2.Stop();
  3638. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  3639. //保存PLC返回MES数据到本地
  3640. ResponseMessage message = new ResponseMessage();
  3641. if (direction == "Left")
  3642. {
  3643. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  3644. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  3645. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3646. message = SQLHelper.InsertOp701Data(CarrierBarcode, sn, strMesHeightInfos,
  3647. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  3648. if (message.result == false)
  3649. {
  3650. AddMessage(LogType.Info, stationNameStr + "_Left_保存加工数据失败");
  3651. }
  3652. }
  3653. if (direction == "Right")
  3654. {
  3655. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  3656. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  3657. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3658. message = SQLHelper.InsertOp702Data(CarrierBarcode, sn, strMesHeightInfos,
  3659. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  3660. if (message.result == false)
  3661. {
  3662. AddMessage(LogType.Info, stationNameStr + "__Right_保存加工数据失败");
  3663. }
  3664. }
  3665. //保存螺丝数据到txt
  3666. (int, string) result = SaveScrewDataToTxt(direction, sn, stPLC_MesData.mesData.fScrewTimes, stPLC_MesData.mesData.nScrewOrders, stPLC_MesData.mesData.nScrewResults);
  3667. if (result.Item1 != 0)
  3668. {
  3669. AddMessage(LogType.Error, $"{stationNameStr}螺丝数据保存失败 " + message.text);
  3670. }
  3671. AddMessage(LogType.Info, stationNameStr + "_"+ direction+"_保存加工数据到本地成功");
  3672. }
  3673. catch (Exception ex)
  3674. {
  3675. stopwatch2.Start();
  3676. CommandFromPLC resultToPlC = new CommandFromPLC();
  3677. resultToPlC.cmd = 0;
  3678. resultToPlC.cmdParam = 0; //指令参数
  3679. resultToPlC.cmdResult = 110;
  3680. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3681. stopwatch2.Stop();
  3682. string str = ex.StackTrace;
  3683. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3684. }
  3685. stopwatch1.Stop();
  3686. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3687. ProgressState = false;
  3688. }
  3689. #endregion
  3690. #region S8
  3691. /// <summary>
  3692. /// [S8] 3D螺丝高度检测设备
  3693. /// </summary>
  3694. /// <param name="plcNo">PLC编号</param>
  3695. private void ReadStation_S8(int plcNo)
  3696. {
  3697. string stationCode = "[OP80]";
  3698. string stationName = "NG下料";
  3699. string stationNameStr = stationCode + stationName;
  3700. string tagBaseName = "g_OP80_MES"; //标签变量名称
  3701. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3702. string tagAgvCommName = "agvCommFrmPC";
  3703. string tagBarsetName = "BarcodeSet";
  3704. OP80_MesData_t stPLC_MesData; //PLC的MES数据
  3705. (int, string) result;
  3706. while (true)
  3707. {
  3708. try
  3709. {
  3710. if (!GlobalContext._IsCon_Funs1)
  3711. {
  3712. UpdatePLCMonitor(1, plcNo, 0);
  3713. continue;
  3714. }
  3715. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3716. {
  3717. Stopwatch stopwatch1 = new Stopwatch();
  3718. Stopwatch stopwatch2 = new Stopwatch();
  3719. stopwatch1.Start();
  3720. stopwatch2.Start();
  3721. #region 一次性读取所有数据
  3722. // 一次性读取所有数据
  3723. result = FunsEip[plcNo].Read_SingleTag<OP80_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3724. if (result.Item1 != 0)
  3725. {
  3726. //richTextBox1.AppendText("\n" + strRet);
  3727. }
  3728. else
  3729. {
  3730. //richTextBox1.AppendText("\n" + "读取成功");
  3731. }
  3732. #endregion 一次性读取所有数据
  3733. stopwatch2.Stop();
  3734. #region 进站
  3735. try
  3736. {
  3737. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3738. {
  3739. lock (lockObj)
  3740. {
  3741. if (!ProgressState)
  3742. {
  3743. ProgressState = true;
  3744. Task.Run(() => S8进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3745. }
  3746. }
  3747. }
  3748. }
  3749. catch (Exception ex)
  3750. {
  3751. ProgressState = false;
  3752. string str = ex.StackTrace;
  3753. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3754. }
  3755. #endregion 进站
  3756. #region 出站
  3757. try
  3758. {
  3759. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3760. {
  3761. lock (lockObj)
  3762. {
  3763. if (!ProgressState)
  3764. {
  3765. ProgressState = true;
  3766. Task.Run(() => S8出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3767. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  3768. }
  3769. }
  3770. }
  3771. }
  3772. catch (Exception ex)
  3773. {
  3774. ProgressState = false;
  3775. string str = ex.StackTrace;
  3776. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3777. }
  3778. #endregion 出站
  3779. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3780. stopwatch1.Stop();
  3781. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3782. }
  3783. else
  3784. {
  3785. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3786. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3787. FunsEip[plcNo].Connect(); // 重连
  3788. }
  3789. }
  3790. catch (Exception ex)
  3791. {
  3792. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3793. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3794. }
  3795. Thread.Sleep(IntervalReadPLC);
  3796. }
  3797. }
  3798. /// <summary>
  3799. /// [S8] 3D螺丝高度检测设备 - 进站
  3800. /// </summary>
  3801. /// <param name="plcNo">PLC编号</param>
  3802. /// <param name="stationNameStr">工站全称</param>
  3803. /// <param name="stPLC_MesData"></param>
  3804. /// <param name="tagMesCommName"></param>
  3805. private void S8进站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3806. {
  3807. Stopwatch stopwatch1 = new Stopwatch();
  3808. Stopwatch stopwatch2 = new Stopwatch();
  3809. try
  3810. {
  3811. stopwatch1.Start();
  3812. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3813. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3814. string MachineId = GlobalContext.S8_MachineId; // 装备ID(可配置)
  3815. string StationId = GlobalContext.S8_StationId; // 工位ID(可配置)
  3816. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3817. //载具码验证产品码
  3818. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3819. if (string.IsNullOrEmpty(strProductBarcode))
  3820. {
  3821. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3822. }
  3823. sn = strProductBarcode;
  3824. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3825. // 产品SN(物料码)校验
  3826. List<TestItem> item = new List<TestItem>();
  3827. stopwatch2.Start();
  3828. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3829. stopwatch2.Stop();
  3830. //指令执行结果 1:OK 110:失败
  3831. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3832. //进站结果写入PLC
  3833. CommandFromPLC resultToPlC = new CommandFromPLC();
  3834. resultToPlC.cmd = 0;
  3835. resultToPlC.cmdParam = 0; //指令参数
  3836. resultToPlC.cmdResult = mesResultFrmWeb;
  3837. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3838. }
  3839. catch (Exception ex)
  3840. {
  3841. string str = ex.StackTrace;
  3842. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3843. CommandFromPLC resultToPlC = new CommandFromPLC();
  3844. resultToPlC.cmd = 0;
  3845. resultToPlC.cmdParam = 0; //指令参数
  3846. resultToPlC.cmdResult = 110;
  3847. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3848. }
  3849. stopwatch1.Stop();
  3850. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3851. ProgressState = false;
  3852. }
  3853. /// <summary>
  3854. /// [S8] 3D螺丝高度检测设备 - 出站接口
  3855. /// </summary>
  3856. private void S8出站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3857. {
  3858. Stopwatch stopwatch1 = new Stopwatch();
  3859. Stopwatch stopwatch2 = new Stopwatch();
  3860. try
  3861. {
  3862. stopwatch1.Start();
  3863. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3864. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3865. string processItem = stationName; // 测试项目
  3866. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3867. string supplierCode = ""; // 供应商代码
  3868. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3869. string batch_num = GlobalContext.BatchNumber; // 批次号
  3870. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3871. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3872. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3873. string MachineId = GlobalContext.S8_MachineId; // 装备id(可配置) // ZS
  3874. string StationId = GlobalContext.S8_StationId; // ⼯位ID(可配置) // ZS
  3875. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3876. bool pass = a1Result == 1;
  3877. //根据载具码获取产品码
  3878. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3879. if (string.IsNullOrEmpty(strProductBarcode))
  3880. {
  3881. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3882. }
  3883. sn = strProductBarcode;
  3884. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3885. List<TestItem> items = new List<TestItem>();
  3886. items.Add(new TestItem()
  3887. {
  3888. Parameter_name = "载具码",
  3889. Parameter_value = CarrierBarcode,
  3890. Parameter_unit = ""
  3891. });
  3892. items.Add(new TestItem()
  3893. {
  3894. Parameter_name = "产品码",
  3895. Parameter_value = sn,
  3896. Parameter_unit = ""
  3897. });
  3898. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3899. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3900. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3901. stopwatch2.Start();
  3902. //进站结果写入PLC
  3903. CommandFromPLC resultToPlC = new CommandFromPLC();
  3904. resultToPlC.cmd = 0;
  3905. resultToPlC.cmdParam = 0; //指令参数
  3906. resultToPlC.cmdResult = mesResultFrmWeb;
  3907. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3908. stopwatch2.Stop();
  3909. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3910. //保存PLC返回MES数据到本地
  3911. ResponseMessage message = new ResponseMessage();
  3912. string strScrewHeights = FloatArrayToString(stPLC_MesData.mesData.fScrewHeights);
  3913. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3914. message = SQLHelper.InsertOp80Data(CarrierBarcode, sn, strScrewHeights, strScrewResults);
  3915. if (message.result == false)
  3916. {
  3917. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3918. }
  3919. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3920. }
  3921. catch (Exception ex)
  3922. {
  3923. stopwatch2.Start();
  3924. CommandFromPLC resultToPlC = new CommandFromPLC();
  3925. resultToPlC.cmd = 0;
  3926. resultToPlC.cmdParam = 0; //指令参数
  3927. resultToPlC.cmdResult = 110;
  3928. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3929. stopwatch2.Stop();
  3930. string str = ex.StackTrace;
  3931. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3932. }
  3933. stopwatch1.Stop();
  3934. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3935. ProgressState = false;
  3936. }
  3937. #endregion
  3938. #region S9
  3939. /// <summary>
  3940. /// [S9] 下料设备
  3941. /// </summary>
  3942. /// <param name="plcNo">PLC编号</param>
  3943. private void ReadStation_S9(int plcNo)
  3944. {
  3945. string stationCode = "[OP90]";
  3946. string stationName = "半成品下料";
  3947. string stationNameStr = stationCode + stationName;
  3948. string tagBaseName = "g_OP90_MES"; //标签变量名称
  3949. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3950. string tagAgvCommName = "agvCommFrmPC";
  3951. string tagBarsetName = "BarcodeSet";
  3952. OP90_MesData_t stPLC_MesData; //PLC的MES数据
  3953. (int, string) result;
  3954. while (true)
  3955. {
  3956. try
  3957. {
  3958. if (!GlobalContext._IsCon_Funs1)
  3959. {
  3960. UpdatePLCMonitor(1, plcNo, 0);
  3961. continue;
  3962. }
  3963. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3964. {
  3965. Stopwatch stopwatch1 = new Stopwatch();
  3966. Stopwatch stopwatch2 = new Stopwatch();
  3967. stopwatch1.Start();
  3968. stopwatch2.Start();
  3969. #region 一次性读取所有数据
  3970. // 一次性读取所有数据
  3971. result = FunsEip[plcNo].Read_SingleTag<OP90_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3972. if (result.Item1 != 0)
  3973. {
  3974. //richTextBox1.AppendText("\n" + strRet);
  3975. }
  3976. else
  3977. {
  3978. //richTextBox1.AppendText("\n" + "读取成功");
  3979. }
  3980. #endregion 一次性读取所有数据
  3981. stopwatch2.Stop();
  3982. #region 进站
  3983. try
  3984. {
  3985. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3986. {
  3987. lock (lockObj)
  3988. {
  3989. if (!ProgressState)
  3990. {
  3991. ProgressState = true;
  3992. Task.Run(() => S9进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3993. }
  3994. }
  3995. }
  3996. }
  3997. catch (Exception ex)
  3998. {
  3999. ProgressState = false;
  4000. string str = ex.StackTrace;
  4001. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4002. }
  4003. #endregion 进站
  4004. #region 出站
  4005. try
  4006. {
  4007. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  4008. {
  4009. lock (lockObj)
  4010. {
  4011. if (!ProgressState)
  4012. {
  4013. ProgressState = true;
  4014. Task.Run(() => S9出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  4015. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  4016. }
  4017. }
  4018. }
  4019. }
  4020. catch (Exception ex)
  4021. {
  4022. ProgressState = false;
  4023. string str = ex.StackTrace;
  4024. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4025. }
  4026. #endregion 出站
  4027. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4028. stopwatch1.Stop();
  4029. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4030. }
  4031. else
  4032. {
  4033. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4034. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4035. FunsEip[plcNo].Connect(); // 重连
  4036. }
  4037. }
  4038. catch (Exception ex)
  4039. {
  4040. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4041. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4042. }
  4043. Thread.Sleep(IntervalReadPLC);
  4044. }
  4045. }
  4046. /// <summary>
  4047. /// [S9] 下料设备 - 进站
  4048. /// </summary>
  4049. /// <param name="plcNo">PLC编号</param>
  4050. /// <param name="stationNameStr">工站全称</param>
  4051. /// <param name="stPLC_MesData"></param>
  4052. /// <param name="tagMesCommName"></param>
  4053. private void S9进站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  4054. {
  4055. Stopwatch stopwatch1 = new Stopwatch();
  4056. Stopwatch stopwatch2 = new Stopwatch();
  4057. try
  4058. {
  4059. stopwatch1.Start();
  4060. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  4061. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  4062. string MachineId = GlobalContext.S9_MachineId; // 装备ID(可配置)
  4063. string StationId = GlobalContext.S9_StationId; // 工位ID(可配置)
  4064. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  4065. //载具码验证产品码
  4066. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  4067. if (string.IsNullOrEmpty(strProductBarcode))
  4068. {
  4069. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4070. }
  4071. sn = strProductBarcode;
  4072. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  4073. // 产品SN(物料码)校验
  4074. List<TestItem> item = new List<TestItem>();
  4075. stopwatch2.Start();
  4076. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  4077. stopwatch2.Stop();
  4078. //指令执行结果 1:OK 110:失败
  4079. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  4080. //进站结果写入PLC
  4081. CommandFromPLC resultToPlC = new CommandFromPLC();
  4082. resultToPlC.cmd = 0;
  4083. resultToPlC.cmdParam = 0; //指令参数
  4084. resultToPlC.cmdResult = mesResultFrmWeb;
  4085. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4086. }
  4087. catch (Exception ex)
  4088. {
  4089. string str = ex.StackTrace;
  4090. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4091. CommandFromPLC resultToPlC = new CommandFromPLC();
  4092. resultToPlC.cmd = 0;
  4093. resultToPlC.cmdParam = 0; //指令参数
  4094. resultToPlC.cmdResult = 110;
  4095. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4096. }
  4097. stopwatch1.Stop();
  4098. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  4099. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4100. ProgressState = false;
  4101. }
  4102. /// <summary>
  4103. /// [S9] 下料设备 - 出站接口
  4104. /// </summary>
  4105. private void S9出站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  4106. {
  4107. Stopwatch stopwatch1 = new Stopwatch();
  4108. Stopwatch stopwatch2 = new Stopwatch();
  4109. try
  4110. {
  4111. stopwatch1.Start();
  4112. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  4113. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4114. string processItem = stationName; // 测试项目
  4115. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4116. string supplierCode = ""; // 供应商代码
  4117. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4118. string batch_num = GlobalContext.BatchNumber; // 批次号
  4119. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4120. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4121. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4122. string MachineId = GlobalContext.S9_MachineId; // 装备id(可配置) // ZS
  4123. string StationId = GlobalContext.S9_StationId; // ⼯位ID(可配置) // ZS
  4124. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4125. bool pass = a1Result == 1;
  4126. //根据载具码获取产品码
  4127. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4128. if (string.IsNullOrEmpty(strProductBarcode))
  4129. {
  4130. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4131. }
  4132. sn = strProductBarcode;
  4133. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  4134. List<TestItem> items = new List<TestItem>();
  4135. items.Add(new TestItem()
  4136. {
  4137. Parameter_name = "载具码",
  4138. Parameter_value = CarrierBarcode,
  4139. Parameter_unit = ""
  4140. });
  4141. items.Add(new TestItem()
  4142. {
  4143. Parameter_name = "产品码",
  4144. Parameter_value = sn,
  4145. Parameter_unit = ""
  4146. });
  4147. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4148. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  4149. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4150. stopwatch2.Start();
  4151. //进站结果写入PLC
  4152. CommandFromPLC resultToPlC = new CommandFromPLC();
  4153. resultToPlC.cmd = 0;
  4154. resultToPlC.cmdParam = 0; //指令参数
  4155. resultToPlC.cmdResult = mesResultFrmWeb;
  4156. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4157. stopwatch2.Stop();
  4158. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  4159. //保存PLC返回MES数据到本地
  4160. ResponseMessage message = new ResponseMessage();
  4161. message = SQLHelper.InsertOp90Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.nRemainCount);
  4162. if (message.result == false)
  4163. {
  4164. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4165. }
  4166. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4167. if (result1 == 1)
  4168. {
  4169. //载具码解除绑定
  4170. message = SQLHelper.DelCarrierBind(CarrierBarcode);
  4171. if (message.result == false)
  4172. {
  4173. AddMessage(LogType.Error, message.text);
  4174. }
  4175. }
  4176. }
  4177. catch (Exception ex)
  4178. {
  4179. stopwatch2.Start();
  4180. CommandFromPLC resultToPlC = new CommandFromPLC();
  4181. resultToPlC.cmd = 0;
  4182. resultToPlC.cmdParam = 0; //指令参数
  4183. resultToPlC.cmdResult = 110;
  4184. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4185. stopwatch2.Stop();
  4186. string str = ex.StackTrace;
  4187. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4188. }
  4189. stopwatch1.Stop();
  4190. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4191. ProgressState = false;
  4192. }
  4193. #endregion
  4194. #endregion Xiaomi
  4195. #region PLC1 张超凡
  4196. #region [S1] Tray盘上料装备(板测)
  4197. /// <summary>
  4198. /// S1工位的数据- 触发信号上次的值
  4199. /// </summary>
  4200. private Dictionary<string, object> s1PLCSignal_Old = new Dictionary<string, object>();
  4201. /// <summary>
  4202. /// S1工位的数据(含触发信号)
  4203. /// </summary>
  4204. private Dictionary<string, object> s1PLCData = new Dictionary<string, object>();
  4205. /// <summary>
  4206. /// S1工位的数据- 回写点位
  4207. /// </summary>
  4208. private Dictionary<string, WriteToPLC_Flag> s1PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  4209. ///// <summary>
  4210. ///// 触发信号
  4211. ///// </summary>
  4212. //private ManualResetEvent[] MreTasks;
  4213. /// <summary>
  4214. /// [S1] Tray盘上料装备(板测)
  4215. /// </summary>
  4216. /// <param name="plcNo">PLC编号</param>
  4217. //private void ReadStation_S1(int plcNo)
  4218. //{
  4219. // // [S1] Tray盘上料装备
  4220. // // [S2] FCT
  4221. // // [S3] 值板机
  4222. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  4223. // // [S5] Tray盘下料装备
  4224. // string stationCode = "[S1]";
  4225. // string stationName = "Tray盘上料装备";
  4226. // string stationNameStr = stationCode + stationName;
  4227. // #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4228. // // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4229. // s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  4230. // s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  4231. // s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  4232. // s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  4233. // s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4234. // s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  4235. // s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  4236. // s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  4237. // s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  4238. // // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4239. // s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  4240. // s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
  4241. // s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
  4242. // s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  4243. // s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
  4244. // s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
  4245. // s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  4246. // s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
  4247. // s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
  4248. // s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
  4249. // s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
  4250. // s1PLCData.Add("a1Result", 0); // 产品结果
  4251. // s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  4252. // s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
  4253. // s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
  4254. // s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
  4255. // s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
  4256. // s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4257. // s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
  4258. // s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  4259. // s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  4260. // s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
  4261. // s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  4262. // s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  4263. // s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
  4264. // s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
  4265. // s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  4266. // s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
  4267. // s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
  4268. // #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4269. // while (IsRun)
  4270. // {
  4271. // try
  4272. // {
  4273. // if (!GlobalContext._IsCon_Funs1)
  4274. // {
  4275. // UpdatePLCMonitor(1, plcNo, 0);
  4276. // continue;
  4277. // }
  4278. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  4279. // {
  4280. // Stopwatch stopwatch1 = new Stopwatch();
  4281. // Stopwatch stopwatch2 = new Stopwatch();
  4282. // stopwatch1.Start();
  4283. // stopwatch2.Start();
  4284. // #region 一次性读取所有数据
  4285. // // 一次性读取所有数据
  4286. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  4287. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  4288. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  4289. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 33);
  4290. // int[] datas = data1.Concat(data2).ToArray();
  4291. // datas = datas.Concat(data3).ToArray();
  4292. // datas = datas.Concat(data4).ToArray();
  4293. // s1PLCData["a1PLC_FLAG_VehicleStates"] = datas[2]; // 载具进站查询状态
  4294. // s1PLCData["a1MES_FLAG_VehicleStates"] = datas[3];
  4295. // int[] a1ProductSN_VehicleStatesData = datas.Skip(4).Take(20).ToArray();
  4296. // s1PLCData["a1ProductSN_VehicleStates"] = ModbusClient.ConvertRegistersToString(a1ProductSN_VehicleStatesData, 0, 40);
  4297. // s1PLCData["a1PLC_FLAG_Check"] = datas[76]; // 上料进站校验
  4298. // s1PLCData["a1MES_FLAG_Check"] = datas[77];
  4299. // int[] a1ProductSN_CheckData = datas.Skip(78).Take(20).ToArray();
  4300. // s1PLCData["a1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(a1ProductSN_CheckData, 0, 40);
  4301. // s1PLCData["a1PLC_FLAG"] = datas[108]; // 出站接口
  4302. // s1PLCData["a1MES_FLAG"] = datas[109];
  4303. // int[] a1ProductSNData = datas.Skip(110).Take(20).ToArray();
  4304. // s1PLCData["a1ProductSN"] = ModbusClient.ConvertRegistersToString(a1ProductSNData, 0, 40);
  4305. // int[] a1PartNo1Data = datas.Skip(130).Take(20).ToArray();
  4306. // s1PLCData["a1PartNo1"] = ModbusClient.ConvertRegistersToString(a1PartNo1Data, 0, 40);
  4307. // int[] a1PartNo2Data = datas.Skip(150).Take(20).ToArray();
  4308. // s1PLCData["a1PartNo2"] = ModbusClient.ConvertRegistersToString(a1PartNo2Data, 0, 40);
  4309. // s1PLCData["a1Result"] = datas[170];
  4310. // s1PLCData["a1PLC_FLAG_ICT"] = datas[181]; // 将SN发给ICT标机(串口)
  4311. // s1PLCData["a1MES_FLAG_ICT"] = datas[182];
  4312. // int[] a1ProductSN_ICTData = datas.Skip(183).Take(20).ToArray();
  4313. // s1PLCData["a1ProductSN_ICT"] = ModbusClient.ConvertRegistersToString(a1ProductSN_ICTData, 0, 40);
  4314. // int[] a1PartNo1_ICTData = datas.Skip(203).Take(20).ToArray();
  4315. // s1PLCData["a1PartNo1_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo1_ICTData, 0, 40);
  4316. // int[] a1PartNo2_ICTData = datas.Skip(223).Take(20).ToArray();
  4317. // s1PLCData["a1PartNo2_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo2_ICTData, 0, 40);
  4318. // s1PLCData["a1OEEPLC_FLAG"] = datas[253]; // 节拍接口
  4319. // s1PLCData["a1OEEMES_FLAG"] = datas[254];
  4320. // int[] a1OEEPartNoData = datas.Skip(255).Take(20).ToArray();
  4321. // s1PLCData["a1OEEPartNo"] = ModbusClient.ConvertRegistersToString(a1OEEPartNoData, 0, 40); // 物料码(物料码还未绑定载具SN时必填)
  4322. // int[] a1OEEVehicleCodeData = datas.Skip(275).Take(20).ToArray();
  4323. // s1PLCData["a1OEEVehicleCode"] = ModbusClient.ConvertRegistersToString(a1OEEVehicleCodeData, 0, 40); // 载具SN
  4324. // s1PLCData["a1OEEPartNum"] = datas[295]; // 穴位号
  4325. // s1PLCData["a1OEEType"] = datas[296]; // 节拍类型(plc写入)
  4326. // s1PLCData["a1AGVUpCall"] = datas[307]; // AGV上料
  4327. // s1PLCData["a1AGVUpStart"] = datas[308];
  4328. // s1PLCData["a1AGVUpEnd"] = datas[309];
  4329. // s1PLCData["a1AGVDownCall"] = datas[320]; // AGV下料
  4330. // s1PLCData["a1AGVDownStart"] = datas[321];
  4331. // s1PLCData["a1AGVDownEnd"] = datas[322];
  4332. // #endregion 一次性读取所有数据
  4333. // stopwatch2.Stop();
  4334. // #region 回写操作,写后清空flag
  4335. // PLCWriteData(Funs[plcNo], ref s1PLCData, ref s1PLCWriteData);
  4336. // #endregion 回写操作,写后清空flag
  4337. // #region 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  4338. // try
  4339. // {
  4340. // int a1PLC_FLAG_VehicleStates = (int)s1PLCData["a1PLC_FLAG_VehicleStates"];
  4341. // int a1MES_FLAG_VehicleStates = (int)s1PLCData["a1MES_FLAG_VehicleStates"];
  4342. // int a1PLC_FLAG_VehicleStatesOld = (int)s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"];
  4343. // if (a1PLC_FLAG_VehicleStates != a1PLC_FLAG_VehicleStatesOld)
  4344. // {
  4345. // if (a1PLC_FLAG_VehicleStates == 1 && a1MES_FLAG_VehicleStates == 0) // 0->1
  4346. // Task.Run(() => S1载具进站查询状态(plcNo, stationNameStr)); // MreTasks[1].Set();
  4347. // else if (a1PLC_FLAG_VehicleStates == 0 && a1MES_FLAG_VehicleStates != 0)
  4348. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  4349. // s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"] = s1PLCData["a1PLC_FLAG_VehicleStates"];
  4350. // }
  4351. // }
  4352. // catch (Exception ex)
  4353. // {
  4354. // // 6代表上位机报警
  4355. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6);
  4356. // string str = ex.StackTrace;
  4357. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4358. // }
  4359. // #endregion 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  4360. // #region 上料进站校验
  4361. // try
  4362. // {
  4363. // int a1PLC_FLAG_Check = (int)s1PLCData["a1PLC_FLAG_Check"];
  4364. // int a1MES_FLAG_Check = (int)s1PLCData["a1MES_FLAG_Check"];
  4365. // int a1PLC_FLAG_CheckOld = (int)s1PLCSignal_Old["a1PLC_FLAG_Check"];
  4366. // if (a1PLC_FLAG_Check != a1PLC_FLAG_CheckOld)
  4367. // {
  4368. // if (a1PLC_FLAG_Check == 1 && a1MES_FLAG_Check == 0) // 0->1
  4369. // Task.Run(() => S1上料进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  4370. // else if (a1PLC_FLAG_Check == 0 && a1MES_FLAG_Check != 0)
  4371. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  4372. // s1PLCSignal_Old["a1PLC_FLAG_Check"] = s1PLCData["a1PLC_FLAG_Check"];
  4373. // }
  4374. // }
  4375. // catch (Exception ex)
  4376. // {
  4377. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  4378. // string str = ex.StackTrace;
  4379. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4380. // }
  4381. // #endregion 上料进站校验
  4382. // #region Tray盘上料装备-出站接口
  4383. // try
  4384. // {
  4385. // int a1PLC_FLAG = (int)s1PLCData["a1PLC_FLAG"];
  4386. // int a1MES_FLAG = (int)s1PLCData["a1MES_FLAG"];
  4387. // int a1PLC_FLAGOld = (int)s1PLCSignal_Old["a1PLC_FLAG"];
  4388. // if (a1PLC_FLAG != a1PLC_FLAGOld)
  4389. // {
  4390. // if (a1PLC_FLAG == 1 && a1MES_FLAG == 0) // 0->1
  4391. // Task.Run(() => S1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  4392. // else if (a1PLC_FLAG == 0 && a1MES_FLAG != 0)
  4393. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)0);
  4394. // s1PLCSignal_Old["a1PLC_FLAG"] = s1PLCData["a1PLC_FLAG"];
  4395. // }
  4396. // }
  4397. // catch (Exception ex)
  4398. // {
  4399. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)6); // 6代表上位机报警
  4400. // string str = ex.StackTrace;
  4401. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4402. // }
  4403. // #endregion Tray盘上料装备-出站接口
  4404. // #region Tray盘上料装备-将SN发给ICT标机
  4405. // try
  4406. // {
  4407. // int a1PLC_FLAG_ICT = (int)s1PLCData["a1PLC_FLAG_ICT"];
  4408. // int a1MES_FLAG_ICT = (int)s1PLCData["a1MES_FLAG_ICT"];
  4409. // int a1PLC_FLAG_ICTOld = (int)s1PLCSignal_Old["a1PLC_FLAG_ICT"];
  4410. // if (a1PLC_FLAG_ICT != a1PLC_FLAG_ICTOld)
  4411. // {
  4412. // if (a1PLC_FLAG_ICT == 1 && a1MES_FLAG_ICT == 0) // 0->1
  4413. // Task.Run(() => S1将SN发给ICT标机(plcNo, stationNameStr)); // MreTasks[3].Set();
  4414. // else if (a1PLC_FLAG_ICT == 0 && a1MES_FLAG_ICT != 0)
  4415. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)0);
  4416. // s1PLCSignal_Old["a1PLC_FLAG_ICT"] = s1PLCData["a1PLC_FLAG_ICT"];
  4417. // }
  4418. // }
  4419. // catch (Exception ex)
  4420. // {
  4421. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  4422. // string str = ex.StackTrace;
  4423. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4424. // }
  4425. // #endregion Tray盘上料装备-将SN发给ICT标机
  4426. // #region Tray盘上料装备-点检数据
  4427. // //try
  4428. // //{
  4429. // // Funs[plcNo].Read_Int_Tag("828", 1, out short[] iPLC_Flag); // PLC_Flag
  4430. // // Funs[plcNo].Read_Int_Tag("829", 1, out short[] iMES_Flag); // MES_Flag
  4431. // // bool pLC_Flag = iPLC_Flag[0] == 1 ? true : false; // PLC_Flag
  4432. // // bool mES_Flag = iMES_Flag[0] == 1 ? true : false; // MES_Flag
  4433. // // if (pLC_Flag && !mES_Flag) // 1 0
  4434. // // {
  4435. // // AddMessage_Station(stationNameStr, LogType.Info, Head + stationNameStr + BodyCheck);
  4436. // // await Task.Run(() => { DoOneCheckData_Tray盘上料装备(plcNo, stationCode, stationName); });
  4437. // // AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + BodyCheck + Tail);
  4438. // // }
  4439. // // else if (!pLC_Flag && mES_Flag) // 0 1
  4440. // // {
  4441. // // // 清空写给PLC的数据
  4442. // // // MES_Flag重置为0
  4443. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 0 });
  4444. // // }
  4445. // //}
  4446. // //catch (Exception ex)
  4447. // //{
  4448. // // // MES_Flag 为2上位机报错
  4449. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  4450. // // string str = ex.StackTrace;
  4451. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}点检运行出错!错误信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4452. // //}
  4453. // #endregion Tray盘上料装备-点检数据
  4454. // #region 节拍接口
  4455. // try
  4456. // {
  4457. // int a1OEEPLC_FLAG = (int)s1PLCData["a1OEEPLC_FLAG"];
  4458. // int a1OEEMES_FLAG = (int)s1PLCData["a1OEEMES_FLAG"];
  4459. // int a1OEEPLC_FLAGOld = (int)s1PLCSignal_Old["a1OEEPLC_FLAG"];
  4460. // if (a1OEEPLC_FLAG != a1OEEPLC_FLAGOld)
  4461. // {
  4462. // if (a1OEEPLC_FLAG == 1 && a1OEEMES_FLAG == 0) // 0->1
  4463. // Task.Run(() => S1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  4464. // else if (a1OEEPLC_FLAG == 0 && a1OEEMES_FLAG != 0)
  4465. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)0); //
  4466. // s1PLCSignal_Old["a1OEEPLC_FLAG"] = s1PLCData["a1OEEPLC_FLAG"];
  4467. // }
  4468. // }
  4469. // catch (Exception ex)
  4470. // {
  4471. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  4472. // string str = ex.StackTrace;
  4473. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4474. // }
  4475. // #endregion 节拍接口
  4476. // #region AGV上料
  4477. // // AGV上料叫AGV信号
  4478. // try
  4479. // {
  4480. // int a1AGVUpCall = (int)s1PLCData["a1AGVUpCall"];
  4481. // int a1AGVUpCallOld = (int)s1PLCSignal_Old["a1AGVUpCall"];
  4482. // if (a1AGVUpCall != a1AGVUpCallOld)
  4483. // {
  4484. // if (a1AGVUpCall == 1) // 0->1
  4485. // Task.Run(() => S1AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  4486. // s1PLCSignal_Old["a1AGVUpCall"] = s1PLCData["a1AGVUpCall"];
  4487. // }
  4488. // }
  4489. // catch (Exception ex)
  4490. // {
  4491. // Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  4492. // string str = ex.StackTrace;
  4493. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4494. // }
  4495. // // AGV上料完成信号
  4496. // try
  4497. // {
  4498. // int a1AGVUpEnd = (int)s1PLCData["a1AGVUpEnd"];
  4499. // int a1AGVUpEndOld = (int)s1PLCSignal_Old["a1AGVUpEnd"];
  4500. // if (a1AGVUpEnd != a1AGVUpEndOld)
  4501. // {
  4502. // if (a1AGVUpEnd == 1) // 0->1
  4503. // Task.Run(() => S1AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  4504. // s1PLCSignal_Old["a1AGVUpEnd"] = s1PLCData["a1AGVUpEnd"];
  4505. // }
  4506. // }
  4507. // catch (Exception ex)
  4508. // {
  4509. // Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  4510. // string str = ex.StackTrace;
  4511. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4512. // }
  4513. // #endregion AGV上料
  4514. // #region AGV下料
  4515. // // AGV下料叫agv信号
  4516. // try
  4517. // {
  4518. // int a1AGVDownCall = (int)s1PLCData["a1AGVDownCall"];
  4519. // int a1AGVDownCallOld = (int)s1PLCSignal_Old["a1AGVDownCall"];
  4520. // if (a1AGVDownCall != a1AGVDownCallOld)
  4521. // {
  4522. // if (a1AGVDownCall == 1) // 0->1
  4523. // Task.Run(() => S1AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  4524. // s1PLCSignal_Old["a1AGVDownCall"] = s1PLCData["a1AGVDownCall"];
  4525. // }
  4526. // }
  4527. // catch (Exception ex)
  4528. // {
  4529. // Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  4530. // string str = ex.StackTrace;
  4531. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4532. // }
  4533. // // AGV下料完成信号
  4534. // try
  4535. // {
  4536. // int a1AGVDownEnd = (int)s1PLCData["a1AGVDownEnd"];
  4537. // int a1AGVDownEndOld = (int)s1PLCSignal_Old["a1AGVDownEnd"];
  4538. // if (a1AGVDownEnd != a1AGVDownEndOld)
  4539. // {
  4540. // if (a1AGVDownEnd == 1) // 0->1
  4541. // Task.Run(() => S1AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  4542. // s1PLCSignal_Old["a1AGVDownEnd"] = s1PLCData["a1AGVDownEnd"];
  4543. // }
  4544. // }
  4545. // catch (Exception ex)
  4546. // {
  4547. // Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  4548. // string str = ex.StackTrace;
  4549. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4550. // }
  4551. // #endregion AGV下料
  4552. // #region 心跳
  4553. // try
  4554. // {
  4555. // short states = 0;
  4556. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  4557. // }
  4558. // catch (Exception ex)
  4559. // {
  4560. // string str = ex.StackTrace;
  4561. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4562. // }
  4563. // #endregion 心跳
  4564. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4565. // stopwatch1.Stop();
  4566. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  4567. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4568. // }
  4569. // else
  4570. // {
  4571. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4572. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4573. // Funs[plcNo].Connect(); // 重连
  4574. // }
  4575. // }
  4576. // catch (Exception ex)
  4577. // {
  4578. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4579. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4580. // Funs[plcNo].ReConnect();
  4581. // }
  4582. // Thread.Sleep(IntervalReadPLC);
  4583. // }
  4584. //}
  4585. /// <summary>
  4586. /// [S1] Tray盘上料装备(板测)- 载具进站查询状态
  4587. /// </summary>
  4588. /// <param name="plcNo">PLC编号</param>
  4589. /// <param name="stationNameStr">工站全称</param>
  4590. private void S1载具进站查询状态(int plcNo, string stationNameStr)
  4591. {
  4592. Stopwatch stopwatch1 = new Stopwatch();
  4593. Stopwatch stopwatch2 = new Stopwatch();
  4594. try
  4595. {
  4596. stopwatch1.Start();
  4597. string sn = (string)s1PLCData["a1ProductSN_VehicleStates"]; // 产品SN(载具码)
  4598. sn = sn.Replace("\0", "");
  4599. #region 查询载具上的产品信息
  4600. string cavityData = string.Empty;
  4601. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  4602. if (string.IsNullOrEmpty(cavityData))
  4603. cavityData = "";
  4604. if (snResult != 0)
  4605. {
  4606. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  4607. writeToPLC_Flag1.Name = "a1MES_FLAG_VehicleStates";
  4608. writeToPLC_Flag1.Adress = 2003;
  4609. writeToPLC_Flag1.Value = (short)6;
  4610. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag1);
  4611. stopwatch1.Stop();
  4612. AddMessage(LogType.Info, stationNameStr + $"_载具进站查询状态失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  4613. return;
  4614. }
  4615. #endregion 查询载具上的产品信息
  4616. string[] cavitySNs = cavityData.Split('.');
  4617. string a1CavitySN1_VehicleStates = ""; // 穴位1物料SN(上位机写入)
  4618. string a1CavitySN2_VehicleStates = ""; // 穴位2物料SN(上位机写入)
  4619. short a1CavityResult1_VehicleStates = 1; // 1空;2ng;3假产品;
  4620. short a1CavityResult2_VehicleStates = 1; // 1空;2ng;3假产品;
  4621. if (cavitySNs != null && cavitySNs.Length >= 2)
  4622. {
  4623. a1CavitySN1_VehicleStates = cavitySNs[0];
  4624. a1CavitySN2_VehicleStates = cavitySNs[1];
  4625. a1CavityResult1_VehicleStates = 2;
  4626. a1CavityResult2_VehicleStates = 2;
  4627. }
  4628. if (a1CavitySN1_VehicleStates == "假产品")
  4629. a1CavityResult1_VehicleStates = 3;
  4630. if (a1CavitySN2_VehicleStates == "假产品")
  4631. a1CavityResult2_VehicleStates = 3;
  4632. short mES_Flag = 1; // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  4633. // 回写
  4634. stopwatch2.Start();
  4635. //Funs[plcNo].WriteMultipleRegisters<string>(2024, a1CavitySN1_VehicleStates, 20);
  4636. //Funs[plcNo].WriteMultipleRegisters<string>(2044, a1CavitySN2_VehicleStates, 20);
  4637. //Funs[plcNo].WriteMultipleRegisters<short>(2064, a1CavityResult1_VehicleStates);
  4638. //Funs[plcNo].WriteMultipleRegisters<short>(2065, a1CavityResult2_VehicleStates);
  4639. //// MES_Flag
  4640. //Funs[plcNo].WriteMultipleRegisters<short>(2003, mES_Flag);
  4641. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4642. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  4643. writeToPLC_Flag.Adress = 2003;
  4644. writeToPLC_Flag.Value = mES_Flag;
  4645. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  4646. {
  4647. Name = "a1CavitySN1_VehicleStates",
  4648. Adress = 2024,
  4649. ValueType = PLCValueType.String,
  4650. ValueTypeStrLength = 20,
  4651. Value = a1CavitySN1_VehicleStates
  4652. });
  4653. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位2物料SN(上位机写入)
  4654. {
  4655. Name = "a1CavitySN2_VehicleStates",
  4656. Adress = 2044,
  4657. ValueType = PLCValueType.String,
  4658. ValueTypeStrLength = 20,
  4659. Value = a1CavitySN2_VehicleStates
  4660. });
  4661. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  4662. {
  4663. Name = "a1CavityResult1_VehicleStates",
  4664. Adress = 2064,
  4665. ValueType = PLCValueType.Short,
  4666. Value = a1CavityResult1_VehicleStates
  4667. });
  4668. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  4669. {
  4670. Name = "a1CavityResult2_VehicleStates",
  4671. Adress = 2065,
  4672. ValueType = PLCValueType.Short,
  4673. Value = a1CavityResult2_VehicleStates
  4674. });
  4675. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  4676. stopwatch2.Stop();
  4677. }
  4678. catch (Exception ex)
  4679. {
  4680. string str = ex.StackTrace;
  4681. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4682. // MES_Flag
  4683. stopwatch2.Start();
  4684. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  4685. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4686. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  4687. writeToPLC_Flag.Adress = 2003;
  4688. writeToPLC_Flag.Value = (short)6;
  4689. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  4690. stopwatch2.Stop();
  4691. }
  4692. stopwatch1.Stop();
  4693. AddMessage(LogType.Info, stationNameStr + "_载具进站查询状态;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4694. }
  4695. /// <summary>
  4696. /// [S1] Tray盘上料装备(板测)- 上料进站校验
  4697. /// </summary>
  4698. /// <param name="plcNo">PLC编号</param>
  4699. /// <param name="stationNameStr">工站全称</param>
  4700. private void S1上料进站校验(int plcNo, string stationNameStr)
  4701. {
  4702. Stopwatch stopwatch1 = new Stopwatch();
  4703. Stopwatch stopwatch2 = new Stopwatch();
  4704. try
  4705. {
  4706. stopwatch1.Start();
  4707. string sn = (string)s1PLCData["a1ProductSN_Check"]; // 产品SN(物料码)
  4708. sn = sn.Replace("\0", "");
  4709. // 保存进站数据+调用进站MES接口
  4710. List<TestItem> item = new List<TestItem>();
  4711. stopwatch2.Start();
  4712. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, out string errorMsg);
  4713. stopwatch2.Stop();
  4714. short a1MES_FLAG_Check = (short)result;
  4715. //Funs[plcNo].WriteMultipleRegisters<short>(2077, a1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  4716. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4717. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  4718. writeToPLC_Flag.Adress = 2077;
  4719. writeToPLC_Flag.Value = a1MES_FLAG_Check;
  4720. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  4721. }
  4722. catch (Exception ex)
  4723. {
  4724. string str = ex.StackTrace;
  4725. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4726. // MES_Flag
  4727. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  4728. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4729. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  4730. writeToPLC_Flag.Adress = 2077;
  4731. writeToPLC_Flag.Value = (short)6;
  4732. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  4733. }
  4734. stopwatch1.Stop();
  4735. AddMessage(LogType.Info, stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4736. }
  4737. /// <summary>
  4738. /// [S1] Tray盘上料装备(板测)- 出站接口
  4739. /// </summary>
  4740. /// <param name="plcNo"></param>
  4741. /// <param name="stationCode"></param>
  4742. /// <param name="stationName"></param>
  4743. private void S1出站接口(int plcNo, string stationCode, string stationName)
  4744. {
  4745. Stopwatch stopwatch1 = new Stopwatch();
  4746. Stopwatch stopwatch2 = new Stopwatch();
  4747. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4748. string stationNameStr = stationCode + stationName;
  4749. string processItem = stationName; // 测试项目
  4750. try
  4751. {
  4752. stopwatch1.Start();
  4753. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4754. //string batch_num = GlobalContext.BatchNumber; // 批次号
  4755. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4756. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4757. string sn = (string)s1PLCData["a1ProductSN"]; // 产品SN(载具SN码)
  4758. sn = sn.Replace("\0", "");
  4759. string partNo1 = (string)s1PLCData["a1PartNo1"]; // 物料码1(穴位1)
  4760. partNo1 = partNo1.Replace("\0", "");
  4761. string partNo2 = (string)s1PLCData["a1PartNo2"]; // 物料码2(穴位2)
  4762. partNo2 = partNo2.Replace("\0", "");
  4763. int a1Result = (int)s1PLCData["a1Result"]; // 产品结果
  4764. bool pass = a1Result == 1;
  4765. stopwatch2.Start();
  4766. // 产品1
  4767. List<TestItem> items = new List<TestItem>();
  4768. items.Add(new TestItem()
  4769. {
  4770. Parameter_name = "载具码",
  4771. Parameter_value = sn,
  4772. Parameter_unit = ""
  4773. });
  4774. items.Add(new TestItem()
  4775. {
  4776. Parameter_name = "载具穴号",
  4777. Parameter_value = "1",
  4778. Parameter_unit = ""
  4779. });
  4780. items.Add(new TestItem()
  4781. {
  4782. Parameter_name = "产品结果",
  4783. Parameter_value = a1Result == 1 ? "OK" : "NG",
  4784. Parameter_unit = ""
  4785. });
  4786. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4787. , workorder_code, mtltmrk, partNo1, pass, sn, "1");
  4788. // 产品2
  4789. items = new List<TestItem>();
  4790. items.Add(new TestItem()
  4791. {
  4792. Parameter_name = "载具码",
  4793. Parameter_value = sn,
  4794. Parameter_unit = ""
  4795. });
  4796. items.Add(new TestItem()
  4797. {
  4798. Parameter_name = "载具穴号",
  4799. Parameter_value = "2",
  4800. Parameter_unit = ""
  4801. });
  4802. items.Add(new TestItem()
  4803. {
  4804. Parameter_name = "产品结果",
  4805. Parameter_value = a1Result == 1 ? "OK" : "NG",
  4806. Parameter_unit = ""
  4807. });
  4808. int result2 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4809. , workorder_code, mtltmrk, partNo2, pass, sn, "2");
  4810. short result = 0;
  4811. List<int> results = new List<int>() { result1, result2 };
  4812. if (result1 == 1 && result2 == 1)
  4813. result = 1;
  4814. else if (results.Contains(3))
  4815. result = 3;
  4816. else if (results.Contains(2))
  4817. result = 2;
  4818. else if (results.Contains(4))
  4819. result = 4;
  4820. else
  4821. result = 4;
  4822. stopwatch2.Stop();
  4823. #region 存储绑定数据到 边线MES系统中
  4824. if (result == 1)
  4825. {
  4826. string data = string.Concat(partNo1, ".", partNo2);
  4827. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  4828. if (resultMesR != 0)
  4829. {
  4830. result = 4;
  4831. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  4832. }
  4833. }
  4834. #endregion 存储绑定数据到 边线MES系统中
  4835. // MES_Flag 为MES报错
  4836. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4837. //Funs[plcNo].WriteMultipleRegisters<short>(2109, result); // 4代表上位机报警
  4838. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4839. writeToPLC_Flag.Name = "a1MES_FLAG";
  4840. writeToPLC_Flag.Adress = 2109;
  4841. writeToPLC_Flag.Value = result;
  4842. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  4843. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  4844. }
  4845. catch (Exception ex)
  4846. {
  4847. stopwatch2.Restart();
  4848. // MES_Flag 为4上位机报错
  4849. //Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)4); // 4代表上位机报警
  4850. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4851. writeToPLC_Flag.Name = "a1MES_FLAG";
  4852. writeToPLC_Flag.Adress = 2109;
  4853. writeToPLC_Flag.Value = (short)4;
  4854. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  4855. stopwatch2.Stop();
  4856. string str = ex.StackTrace;
  4857. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4858. }
  4859. stopwatch1.Stop();
  4860. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4861. }
  4862. //// 上传点检数据_ [S1] Tray盘上料装备(板测)
  4863. //private void DoOneCheckData_Tray盘上料装备(int plcNo, string stationCode, string stationName)
  4864. //{
  4865. // string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4866. // string stationNameStr = stationCode + stationName;
  4867. // string processItem = stationName; // 测试项目
  4868. // try
  4869. // {
  4870. // string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4871. // string accno = "1"; // 工序编号
  4872. // Funs[plcNo].Read_Real_Tag("896", 1, out float[] float0);
  4873. // float travelLimitUp = float0[0]; // 胶圈装配行程设定上限
  4874. // List<OneCheckItem> items = new List<OneCheckItem>()
  4875. // {
  4876. // new OneCheckItem()
  4877. // {
  4878. // Onecheck_name="胶圈装配行程设定上限",
  4879. // Onecheck_content="上限值",
  4880. // Onecheck_result=$"正常|胶圈装配行程设定上限{travelLimitUp} mm"
  4881. // },
  4882. // };
  4883. // OneCheckData oneCheckData = new OneCheckData()
  4884. // {
  4885. // Line_code = GlobalContext.LineCode,
  4886. // Line_name = GlobalContext.LineName,
  4887. // Equipment_code = equipmentCode,
  4888. // Equipment_name = equipmentCode,
  4889. // Workorder_code = workorder_code,
  4890. // Procedure_code = accno,
  4891. // Procedure_name = processItem,
  4892. // Oneckeck_values = items,
  4893. // Onecheck_empcode = "",
  4894. // Onecheck_empname = "",
  4895. // Onecheck_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  4896. // };
  4897. // int result1 = SaveOneCheckDataByDBAndSubmit(oneCheckData, equipmentCode, processItem);
  4898. // //int result = result1 == 1 ? 1 : (GlobalContext.IsSendCheckOneData ? 4 : 1);
  4899. // short result = result1 == 1 ? (short)1 : (short)2;
  4900. // // MES_Flag 为4MES报错
  4901. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { result });
  4902. // WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  4903. // }
  4904. // catch (Exception ex)
  4905. // {
  4906. // // MES_Flag 为2上位机报错
  4907. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  4908. // string str = ex.StackTrace;
  4909. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}点检报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4910. // }
  4911. //}
  4912. // ReadStation_S1_2 节拍接口+AGV
  4913. /// <summary>
  4914. /// [S1] Tray盘上料装备(板测)- 将SN发给ICT标机(串口)
  4915. /// </summary>
  4916. /// <param name="plcNo">PLC编号</param>
  4917. /// <param name="stationNameStr">工站全称</param>
  4918. private void S1将SN发给ICT标机(int plcNo, string stationNameStr)
  4919. {
  4920. Stopwatch stopwatch1 = new Stopwatch();
  4921. Stopwatch stopwatch2 = new Stopwatch();
  4922. try
  4923. {
  4924. stopwatch1.Start();
  4925. string a1ProductSN_ICT = (string)s1PLCData["a1ProductSN_ICT"]; // 产品SN(载具SN)
  4926. a1ProductSN_ICT = a1ProductSN_ICT.Replace("\0", "");
  4927. string a1PartNo1_ICT = (string)s1PLCData["a1PartNo1_ICT"]; // 物料码1(穴位1)
  4928. a1PartNo1_ICT = a1PartNo1_ICT.Replace("\0", "");
  4929. string a1PartNo2_ICT = (string)s1PLCData["a1PartNo2_ICT"]; // 物料码2(穴位2)
  4930. a1PartNo2_ICT = a1PartNo2_ICT.Replace("\0", "");
  4931. // ZS 将SN发给ICT标机(串口)
  4932. short a1MES_FLAG_ICT = 1;
  4933. stopwatch2.Start();
  4934. // MES_Flag
  4935. //Funs[plcNo].WriteMultipleRegisters<short>(2182, a1MES_FLAG_ICT); // 上位机发送1代表OK;2代表失败;4代表上位机报警;
  4936. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4937. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  4938. writeToPLC_Flag.Adress = 2182;
  4939. writeToPLC_Flag.Value = a1MES_FLAG_ICT;
  4940. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  4941. stopwatch2.Stop();
  4942. }
  4943. catch (Exception ex)
  4944. {
  4945. string str = ex.StackTrace;
  4946. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4947. stopwatch2.Start();
  4948. // MES_Flag
  4949. //Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  4950. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4951. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  4952. writeToPLC_Flag.Adress = 2182;
  4953. writeToPLC_Flag.Value = (short)4;
  4954. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  4955. stopwatch2.Stop();
  4956. }
  4957. stopwatch1.Stop();
  4958. AddMessage(LogType.Info, stationNameStr + "_将SN发给ICT标机;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4959. }
  4960. /// <summary>
  4961. /// [S1] Tray盘上料装备(板测)- 节拍接口
  4962. /// </summary>
  4963. /// <param name="plcNo">PLC编号</param>
  4964. /// <param name="stationNameStr">工站全称</param>
  4965. private void S1节拍接口(int plcNo, string stationNameStr,string tagMesCommName, OP10_MesData_t stPLC_MesData)
  4966. {
  4967. Stopwatch stopwatch1 = new Stopwatch();
  4968. Stopwatch stopwatch2 = new Stopwatch();
  4969. IoT_DataSet_t iot_data;
  4970. string resultStr = string.Empty;
  4971. try
  4972. {
  4973. stopwatch1.Start();
  4974. string oEEType = ((int)s1PLCData["a1OEEType"]).ToString(); // 节拍类型(plc写入)
  4975. string a1OEEPartNo = (string)s1PLCData["a1OEEPartNo"]; // 物料码
  4976. a1OEEPartNo = a1OEEPartNo.Replace("\0", "");
  4977. string a1OEEVehicleCode = (string)s1PLCData["a1OEEVehicleCode"]; // 载具SN
  4978. a1OEEVehicleCode = a1OEEVehicleCode.Replace("\0", "");
  4979. //string a1OEEPartNum = ((int)s1PLCData["a1OEEPartNum"]).ToString(); // 穴位号
  4980. //a1OEEPartNum = a1OEEPartNum.Replace("\0", "");
  4981. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  4982. if (!actionBool)
  4983. {
  4984. stopwatch2.Start();
  4985. //写入PLC
  4986. iot_data.machineState = stPLC_MesData.iotData.machineState;
  4987. iot_data.work_type = stPLC_MesData.iotData.work_type;
  4988. iot_data.testStatus = stPLC_MesData.iotData.testStatus;
  4989. iot_data.BeatAction = stPLC_MesData.iotData.BeatAction;
  4990. iot_data.beatReturn = 2;//NG
  4991. iot_data.fault_codes = stPLC_MesData.iotData.fault_codes;
  4992. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4993. stopwatch2.Stop();
  4994. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4995. return;
  4996. }
  4997. //作业开始后要有物料和载具信息
  4998. if (string.IsNullOrEmpty(a1OEEPartNo) && string.IsNullOrEmpty(a1OEEVehicleCode) && Convert.ToInt32(oEEType) > 2)
  4999. {
  5000. stopwatch2.Start();
  5001. //写入PLC
  5002. iot_data.machineState = stPLC_MesData.iotData.machineState;
  5003. iot_data.work_type = stPLC_MesData.iotData.work_type;
  5004. iot_data.testStatus = stPLC_MesData.iotData.testStatus;
  5005. iot_data.BeatAction = stPLC_MesData.iotData.BeatAction;
  5006. iot_data.beatReturn = 2;//NG
  5007. iot_data.fault_codes = stPLC_MesData.iotData.fault_codes;
  5008. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5009. stopwatch2.Stop();
  5010. AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + $"_[{a1OEEVehicleCode}][{a1OEEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5011. return;
  5012. }
  5013. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a1OEEPartNo))
  5014. {
  5015. stopwatch2.Start();
  5016. //写入PLC
  5017. iot_data.machineState = stPLC_MesData.iotData.machineState;
  5018. iot_data.work_type = stPLC_MesData.iotData.work_type;
  5019. iot_data.testStatus = stPLC_MesData.iotData.testStatus;
  5020. iot_data.BeatAction = stPLC_MesData.iotData.BeatAction;
  5021. iot_data.beatReturn = 2;//NG
  5022. iot_data.fault_codes = stPLC_MesData.iotData.fault_codes;
  5023. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5024. stopwatch2.Stop();
  5025. AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + $"_[{a1OEEVehicleCode}][{a1OEEPartNo}]上传节拍失败!物料码不可为空;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5026. return;
  5027. }
  5028. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a1OEEVehicleCode))
  5029. {
  5030. stopwatch2.Start();
  5031. //写入PLC
  5032. iot_data.machineState = stPLC_MesData.iotData.machineState;
  5033. iot_data.work_type = stPLC_MesData.iotData.work_type;
  5034. iot_data.testStatus = stPLC_MesData.iotData.testStatus;
  5035. iot_data.BeatAction = stPLC_MesData.iotData.BeatAction;
  5036. iot_data.beatReturn = 2;//NG
  5037. iot_data.fault_codes = stPLC_MesData.iotData.fault_codes;
  5038. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5039. stopwatch2.Stop();
  5040. AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + $"_[{a1OEEVehicleCode}][{a1OEEPartNo}]上传节拍失败!载具码不可为空;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5041. return;
  5042. }
  5043. short a1OEEMES_FLAG = 0;
  5044. // 上传OEE
  5045. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a1OEEPartNo, a1OEEVehicleCode);
  5046. a1OEEMES_FLAG = result.Item1;
  5047. resultStr = result.Item2;
  5048. stopwatch2.Start();
  5049. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5050. writeToPLC_Flag.Name = "a1OEEMES_FLAG";
  5051. writeToPLC_Flag.Adress = 2254;
  5052. writeToPLC_Flag.Value = a1OEEMES_FLAG;
  5053. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
  5054. stopwatch2.Stop();
  5055. }
  5056. catch (Exception ex)
  5057. {
  5058. string str = ex.StackTrace;
  5059. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5060. // MES_Flag
  5061. stopwatch2.Start();
  5062. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  5063. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5064. writeToPLC_Flag.Name = "a1OEEMES_FLAG";
  5065. writeToPLC_Flag.Adress = 2254;
  5066. writeToPLC_Flag.Value = (short)4;
  5067. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
  5068. stopwatch2.Stop();
  5069. }
  5070. stopwatch1.Stop();
  5071. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5072. }
  5073. /// <summary>
  5074. /// [S1] Tray盘上料装备(板测)- AGV上料叫agv
  5075. /// </summary>
  5076. /// <param name="plcNo">PLC编号</param>
  5077. /// <param name="stationNameStr">工站全称</param>
  5078. private void S1AGV上料叫agv(int plcNo, string stationNameStr)
  5079. {
  5080. Stopwatch stopwatch1 = new Stopwatch();
  5081. Stopwatch stopwatch2 = new Stopwatch();
  5082. try
  5083. {
  5084. stopwatch1.Start();
  5085. // ZS 呼叫AGV
  5086. short a1AGVUpCall = 2;
  5087. stopwatch2.Start();
  5088. // a1AGVUpCall
  5089. //Funs[plcNo].WriteMultipleRegisters<short>(2307, a1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5090. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5091. writeToPLC_Flag.Name = "a1AGVUpCall";
  5092. writeToPLC_Flag.Adress = 2307;
  5093. writeToPLC_Flag.Value = a1AGVUpCall;
  5094. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  5095. stopwatch2.Stop();
  5096. }
  5097. catch (Exception ex)
  5098. {
  5099. string str = ex.StackTrace;
  5100. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5101. // a1AGVUpCall
  5102. stopwatch2.Start();
  5103. //Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  5104. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5105. writeToPLC_Flag.Name = "a1AGVUpCall";
  5106. writeToPLC_Flag.Adress = 2307;
  5107. writeToPLC_Flag.Value = (short)4;
  5108. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  5109. stopwatch2.Stop();
  5110. }
  5111. stopwatch1.Stop();
  5112. AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5113. }
  5114. /// <summary>
  5115. /// [S1] Tray盘上料装备(板测)- AGV上料完成
  5116. /// </summary>
  5117. /// <param name="plcNo">PLC编号</param>
  5118. /// <param name="stationNameStr">工站全称</param>
  5119. private void S1AGV上料完成(int plcNo, string stationNameStr)
  5120. {
  5121. Stopwatch stopwatch1 = new Stopwatch();
  5122. Stopwatch stopwatch2 = new Stopwatch();
  5123. try
  5124. {
  5125. stopwatch1.Start();
  5126. // ZS AGV上料完成,让小车离开
  5127. short a1AGVUpEnd = 2;
  5128. stopwatch2.Start();
  5129. // a1AGVUpEnd
  5130. //Funs[plcNo].WriteMultipleRegisters<short>(2309, a1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5131. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5132. writeToPLC_Flag.Name = "a1AGVUpEnd";
  5133. writeToPLC_Flag.Adress = 2309;
  5134. writeToPLC_Flag.Value = a1AGVUpEnd;
  5135. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  5136. stopwatch2.Stop();
  5137. }
  5138. catch (Exception ex)
  5139. {
  5140. string str = ex.StackTrace;
  5141. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5142. // a1AGVUpEnd
  5143. stopwatch2.Start();
  5144. //Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  5145. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5146. writeToPLC_Flag.Name = "a1AGVUpEnd";
  5147. writeToPLC_Flag.Adress = 2309;
  5148. writeToPLC_Flag.Value = (short)4;
  5149. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  5150. stopwatch2.Stop();
  5151. }
  5152. stopwatch1.Stop();
  5153. AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5154. }
  5155. /// <summary>
  5156. /// [S1] Tray盘上料装备(板测)- AGV下料叫agv
  5157. /// </summary>
  5158. /// <param name="plcNo">PLC编号</param>
  5159. /// <param name="stationNameStr">工站全称</param>
  5160. private void S1AGV下料叫agv(int plcNo, string stationNameStr)
  5161. {
  5162. Stopwatch stopwatch1 = new Stopwatch();
  5163. Stopwatch stopwatch2 = new Stopwatch();
  5164. try
  5165. {
  5166. stopwatch1.Start();
  5167. // ZS 呼叫AGV
  5168. short a1AGVDownCall = 2;
  5169. stopwatch2.Start();
  5170. // a1AGVDownCall
  5171. //Funs[plcNo].WriteMultipleRegisters<short>(2320, a1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5172. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5173. writeToPLC_Flag.Name = "a1AGVDownCall";
  5174. writeToPLC_Flag.Adress = 2320;
  5175. writeToPLC_Flag.Value = a1AGVDownCall;
  5176. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  5177. stopwatch2.Stop();
  5178. }
  5179. catch (Exception ex)
  5180. {
  5181. string str = ex.StackTrace;
  5182. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5183. // a1AGVDownCall
  5184. stopwatch2.Start();
  5185. //Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  5186. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5187. writeToPLC_Flag.Name = "a1AGVDownCall";
  5188. writeToPLC_Flag.Adress = 2320;
  5189. writeToPLC_Flag.Value = (short)4;
  5190. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  5191. stopwatch2.Stop();
  5192. }
  5193. stopwatch1.Stop();
  5194. AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5195. }
  5196. /// <summary>
  5197. /// [S1] Tray盘上料装备(板测)- AGV下料完成
  5198. /// </summary>
  5199. /// <param name="plcNo">PLC编号</param>
  5200. /// <param name="stationNameStr">工站全称</param>
  5201. private void S1AGV下料完成(int plcNo, string stationNameStr)
  5202. {
  5203. Stopwatch stopwatch1 = new Stopwatch();
  5204. Stopwatch stopwatch2 = new Stopwatch();
  5205. try
  5206. {
  5207. stopwatch1.Start();
  5208. // ZS AGV上料完成,让小车离开
  5209. short a1AGVDownEnd = 2;
  5210. stopwatch2.Start();
  5211. // a1AGVDownEnd
  5212. //Funs[plcNo].WriteMultipleRegisters<short>(2322, a1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5213. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5214. writeToPLC_Flag.Name = "a1AGVDownEnd";
  5215. writeToPLC_Flag.Adress = 2322;
  5216. writeToPLC_Flag.Value = a1AGVDownEnd;
  5217. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  5218. stopwatch2.Stop();
  5219. }
  5220. catch (Exception ex)
  5221. {
  5222. string str = ex.StackTrace;
  5223. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5224. // a1AGVDownEnd
  5225. stopwatch2.Start();
  5226. //Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  5227. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5228. writeToPLC_Flag.Name = "a1AGVDownEnd";
  5229. writeToPLC_Flag.Adress = 2322;
  5230. writeToPLC_Flag.Value = (short)4;
  5231. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  5232. stopwatch2.Stop();
  5233. }
  5234. stopwatch1.Stop();
  5235. AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5236. }
  5237. #endregion [S1] Tray盘上料装备(板测)
  5238. #endregion PLC1 张超凡
  5239. #region PLC2 李晓奇
  5240. #region [S2] FCT(板测)
  5241. /// <summary>
  5242. /// S2工位的数据- 触发信号上次的值
  5243. /// </summary>
  5244. private Dictionary<string, object> s2PLCSignal_Old = new Dictionary<string, object>();
  5245. /// <summary>
  5246. /// S2工位的数据(含触发信号)
  5247. /// </summary>
  5248. private Dictionary<string, object> s2PLCData = new Dictionary<string, object>();
  5249. /// <summary>
  5250. /// S2工位的数据- 回写点位
  5251. /// </summary>
  5252. private Dictionary<string, WriteToPLC_Flag> s2PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  5253. /// <summary>
  5254. /// [S2] FCT(板测)
  5255. /// </summary>
  5256. /// <param name="plcNo">PLC编号</param>
  5257. //private void ReadStation_S2(int plcNo)
  5258. //{
  5259. // // [S1] Tray盘上料装备
  5260. // // [S2] FCT
  5261. // // [S3] 值板机
  5262. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  5263. // // [S5] Tray盘下料装备
  5264. // /// 上位机心跳
  5265. // /// 获取设备报警数据与状态信息
  5266. // string stationCode = "[S2]";
  5267. // string stationName = "FCT";
  5268. // string stationNameStr = stationCode + stationName;
  5269. // #region 创建字典
  5270. // // 触发信号字典 赋值
  5271. // s2PLCSignal_Old.Add("b1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5272. // s2PLCSignal_Old.Add("b1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑/绑定(产品换载具)
  5273. // s2PLCSignal_Old.Add("b1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5274. // s2PLCSignal_Old.Add("b1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5275. // // PLC数据字典 赋值
  5276. // s2PLCData.Add("b1PLC_FLAG_Check", 0); // 进站校验
  5277. // s2PLCData.Add("b1MES_FLAG_Check", 0);
  5278. // s2PLCData.Add("b1ProductSN_Check", 0);
  5279. // s2PLCData.Add("b1PLC_FLAG_Unbind", 0); // 二穴载具解绑/绑定(产品换载具)
  5280. // s2PLCData.Add("b1MES_FLAG_Unbind", 0);
  5281. // s2PLCData.Add("b1ProductSN_Unbind", "");
  5282. // s2PLCData.Add("b1ProductSN_Bind", "");
  5283. // s2PLCData.Add("b1Part1SN_Bind", "");
  5284. // s2PLCData.Add("b1Part2SN_Bind", "");
  5285. // s2PLCData.Add("b1PLC_FLAG", 0); // 出站接口
  5286. // s2PLCData.Add("b1MES_FLAG", 0);
  5287. // s2PLCData.Add("b1ProductSN", 0);
  5288. // s2PLCData.Add("b1Part1Result", 0);
  5289. // s2PLCData.Add("b1Part2Result", 0);
  5290. // s2PLCData.Add("b1OEEPLC_FLAG", 0); // 节拍接口
  5291. // s2PLCData.Add("b1OEEMES_FLAG", 0);
  5292. // s2PLCData.Add("b1OEEProductSN", "");
  5293. // s2PLCData.Add("b1OEEType", 0);
  5294. // #endregion 创建字典
  5295. // while (IsRun)
  5296. // {
  5297. // try
  5298. // {
  5299. // if (!GlobalContext._IsCon_Funs2)
  5300. // {
  5301. // UpdatePLCMonitor(1, plcNo, 0);
  5302. // continue;
  5303. // }
  5304. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  5305. // {
  5306. // Stopwatch stopwatch1 = new Stopwatch();
  5307. // Stopwatch stopwatch2 = new Stopwatch();
  5308. // stopwatch1.Start();
  5309. // stopwatch2.Start();
  5310. // #region 一次性读取所有数据
  5311. // // 一次性读取所有数据
  5312. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100); //
  5313. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100); //
  5314. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 35); //
  5315. // int[] datas = data1.Concat(data2).ToArray();
  5316. // datas = datas.Concat(data3).ToArray();
  5317. // s2PLCData["b1PLC_FLAG_Check"] = datas[2]; // 进站校验
  5318. // s2PLCData["b1MES_FLAG_Check"] = datas[3];
  5319. // int[] b1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  5320. // s2PLCData["b1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(b1ProductSN_CheckData, 0, 40);
  5321. // s2PLCData["b1PLC_FLAG_Unbind"] = datas[76]; // 二穴载具解绑/绑定(产品换载具)
  5322. // s2PLCData["b1MES_FLAG_Unbind"] = datas[77];
  5323. // int[] b1ProductSN_UnbindData = datas.Skip(78).Take(20).ToArray();
  5324. // s2PLCData["b1ProductSN_Unbind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_UnbindData, 0, 40);
  5325. // int[] b1ProductSN_BindData = datas.Skip(98).Take(20).ToArray();
  5326. // s2PLCData["b1ProductSN_Bind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_BindData, 0, 40);
  5327. // int[] b1Part1SN_BindData = datas.Skip(118).Take(20).ToArray();
  5328. // s2PLCData["b1Part1SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part1SN_BindData, 0, 40);
  5329. // int[] b1Part2SN_BindData = datas.Skip(138).Take(20).ToArray();
  5330. // s2PLCData["b1Part2SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part2SN_BindData, 0, 40);
  5331. // s2PLCData["b1PLC_FLAG"] = datas[168]; // 出站接口
  5332. // s2PLCData["b1MES_FLAG"] = datas[169];
  5333. // int[] b1ProductSNData = datas.Skip(170).Take(20).ToArray();
  5334. // s2PLCData["b1ProductSN"] = ModbusClient.ConvertRegistersToString(b1ProductSNData, 0, 40);
  5335. // s2PLCData["b1Part1Result"] = datas[190];
  5336. // s2PLCData["b1Part2Result"] = datas[191];
  5337. // s2PLCData["b1OEEPLC_FLAG"] = datas[202]; // 节拍接口
  5338. // s2PLCData["b1OEEMES_FLAG"] = datas[203];
  5339. // int[] b1OEEProductSNData = datas.Skip(204).Take(20).ToArray();
  5340. // s2PLCData["b1OEEProductSN"] = ModbusClient.ConvertRegistersToString(b1OEEProductSNData, 0, 40);
  5341. // s2PLCData["b1OEEType"] = datas[224];
  5342. // #endregion 一次性读取所有数据
  5343. // stopwatch2.Stop();
  5344. // #region 回写操作,写后清空flag
  5345. // PLCWriteData(Funs[plcNo], ref s2PLCData, ref s2PLCWriteData);
  5346. // #endregion 回写操作,写后清空flag
  5347. // #region 进站校验
  5348. // try
  5349. // {
  5350. // int b1PLC_FLAG_Check = (int)s2PLCData["b1PLC_FLAG_Check"];
  5351. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  5352. // int b1PLC_FLAG_CheckOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Check"];
  5353. // if (b1PLC_FLAG_Check != b1PLC_FLAG_CheckOld)
  5354. // {
  5355. // if (b1PLC_FLAG_Check == 1 && b1MES_FLAG_Check == 0) // 0->1
  5356. // Task.Run(() => S2进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  5357. // else if (b1PLC_FLAG_Check == 0 && b1MES_FLAG_Check != 0)
  5358. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  5359. // s2PLCSignal_Old["b1PLC_FLAG_Check"] = s2PLCData["b1PLC_FLAG_Check"];
  5360. // }
  5361. // }
  5362. // catch (Exception ex)
  5363. // {
  5364. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5365. // string str = ex.StackTrace;
  5366. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5367. // }
  5368. // #endregion 进站校验
  5369. // #region 二穴载具解绑/绑定(产品换载具)
  5370. // try
  5371. // {
  5372. // int b1PLC_FLAG_Unbind = (int)s2PLCData["b1PLC_FLAG_Unbind"];
  5373. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  5374. // int b1PLC_FLAG_UnbindOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Unbind"];
  5375. // if (b1PLC_FLAG_Unbind != b1PLC_FLAG_UnbindOld)
  5376. // {
  5377. // if (b1PLC_FLAG_Unbind == 1 && b1MES_FLAG_Check == 0) // 0->1
  5378. // Task.Run(() => S2二穴载具解绑绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  5379. // else if (b1PLC_FLAG_Unbind == 0 && b1MES_FLAG_Check != 0)
  5380. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  5381. // s2PLCSignal_Old["b1PLC_FLAG_Unbind"] = s2PLCData["b1PLC_FLAG_Unbind"];
  5382. // }
  5383. // }
  5384. // catch (Exception ex)
  5385. // {
  5386. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  5387. // string str = ex.StackTrace;
  5388. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5389. // }
  5390. // #endregion 二穴载具解绑/绑定(产品换载具)
  5391. // #region FCT-出站接口
  5392. // try
  5393. // {
  5394. // int b1PLC_FLAG = (int)s2PLCData["b1PLC_FLAG"];
  5395. // int b1MES_FLAG = (int)s2PLCData["b1MES_FLAG"];
  5396. // int b1PLC_FLAGOld = (int)s2PLCSignal_Old["b1PLC_FLAG"];
  5397. // if (b1PLC_FLAG != b1PLC_FLAGOld)
  5398. // {
  5399. // if (b1PLC_FLAG == 1 && b1MES_FLAG == 0) // 0->1
  5400. // Task.Run(() => S2出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  5401. // else if (b1PLC_FLAG == 0 && b1MES_FLAG != 0)
  5402. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)0);
  5403. // }
  5404. // }
  5405. // catch (Exception ex)
  5406. // {
  5407. // // MES_Flag 为6上位机报错
  5408. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)6); // 6代表上位机报警
  5409. // string str = ex.StackTrace;
  5410. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}上传出站数据出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5411. // }
  5412. // #endregion FCT-出站接口
  5413. // #region 节拍接口
  5414. // try
  5415. // {
  5416. // int b1OEEPLC_FLAG = (int)s2PLCData["b1OEEPLC_FLAG"];
  5417. // int b1OEEMES_FLAG = (int)s2PLCData["b1OEEMES_FLAG"];
  5418. // int b1OEEPLC_FLAGOld = (int)s2PLCSignal_Old["b1OEEPLC_FLAG"];
  5419. // if (b1OEEPLC_FLAG != b1OEEPLC_FLAGOld)
  5420. // {
  5421. // if (b1OEEPLC_FLAG == 1 && b1OEEMES_FLAG == 0) // 0->1
  5422. // Task.Run(() => S2节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  5423. // else if (b1OEEPLC_FLAG == 0 && b1OEEMES_FLAG != 0)
  5424. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)0);
  5425. // s2PLCSignal_Old["b1OEEPLC_FLAG"] = s2PLCData["b1OEEPLC_FLAG"];
  5426. // }
  5427. // }
  5428. // catch (Exception ex)
  5429. // {
  5430. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  5431. // string str = ex.StackTrace;
  5432. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5433. // }
  5434. // #endregion 节拍接口
  5435. // #region 心跳
  5436. // try
  5437. // {
  5438. // short states = 0;
  5439. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  5440. // }
  5441. // catch (Exception ex)
  5442. // {
  5443. // string str = ex.StackTrace;
  5444. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5445. // }
  5446. // #endregion 心跳
  5447. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5448. // stopwatch1.Stop();
  5449. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  5450. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5451. // }
  5452. // else
  5453. // {
  5454. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5455. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5456. // Funs[plcNo].Connect();
  5457. // }
  5458. // }
  5459. // catch (Exception ex)
  5460. // {
  5461. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5462. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5463. // Funs[plcNo].ReConnect();
  5464. // }
  5465. // Thread.Sleep(IntervalReadPLC);
  5466. // }
  5467. //}
  5468. /// <summary>
  5469. /// [S2] FCT(板测)- 进站校验
  5470. /// </summary>
  5471. /// <param name="plcNo">PLC编号</param>
  5472. /// <param name="stationNameStr">工站全称</param>
  5473. private void S2进站校验(int plcNo, string stationNameStr)
  5474. {
  5475. Stopwatch stopwatch1 = new Stopwatch();
  5476. Stopwatch stopwatch2 = new Stopwatch();
  5477. try
  5478. {
  5479. stopwatch1.Start();
  5480. string sn = (string)s2PLCData["b1ProductSN_Check"]; // 产品SN(载具码)
  5481. sn = sn.Replace("\0", "");
  5482. #region 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  5483. // 查询物料码By载具码 并判断是不是假产品
  5484. string cavityData = string.Empty;
  5485. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  5486. if (string.IsNullOrEmpty(cavityData))
  5487. cavityData = "";
  5488. if (snResult != 0)
  5489. {
  5490. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5491. writeToPLC_Flag1.Name = "b1MES_FLAG_Check";
  5492. writeToPLC_Flag1.Adress = 2003;
  5493. writeToPLC_Flag1.Value = (short)6;
  5494. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag1);
  5495. stopwatch1.Stop();
  5496. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5497. return;
  5498. }
  5499. #endregion 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  5500. string[] cavitySNs = cavityData.Split('.');
  5501. string b1Part1SN_Check = ""; // 穴位1物料SN(上位机写入)
  5502. string b1Part2SN_Check = ""; // 穴位2物料SN(上位机写入)
  5503. short b1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  5504. short b1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  5505. if (cavitySNs != null && cavitySNs.Length >= 2)
  5506. {
  5507. b1Part1SN_Check = cavitySNs[0];
  5508. b1Part2SN_Check = cavitySNs[1];
  5509. b1Part1Result_Check = 2;
  5510. b1Part2Result_Check = 2;
  5511. }
  5512. if (b1Part1SN_Check == "假产品")
  5513. b1Part1Result_Check = 3;
  5514. if (b1Part2SN_Check == "假产品")
  5515. b1Part2Result_Check = 3;
  5516. // 调用MES进站
  5517. stopwatch2.Start();
  5518. // 调用MES进站 - 产品1
  5519. List<TestItem> item;
  5520. int result1 = b1Part1Result_Check;
  5521. if (result1 != 3)
  5522. {
  5523. item = new List<TestItem>();
  5524. item.Add(new TestItem()
  5525. {
  5526. Parameter_name = "载具码",
  5527. Parameter_value = sn,
  5528. });
  5529. item.Add(new TestItem()
  5530. {
  5531. Parameter_name = "载具穴号",
  5532. Parameter_value = "1",
  5533. });
  5534. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, b1Part1SN_Check, item, out string errorMsg);
  5535. }
  5536. // 调用MES进站 - 产品2
  5537. int result2 = b1Part2Result_Check;
  5538. if (result2 != 3)
  5539. {
  5540. item = new List<TestItem>();
  5541. item.Add(new TestItem()
  5542. {
  5543. Parameter_name = "载具码",
  5544. Parameter_value = sn,
  5545. });
  5546. item.Add(new TestItem()
  5547. {
  5548. Parameter_name = "载具穴号",
  5549. Parameter_value = "2",
  5550. });
  5551. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, b1Part2SN_Check, item, out string errorMsg);
  5552. }
  5553. stopwatch2.Stop();
  5554. b1Part1Result_Check = result1 == 1 ? (short)1 : (short)2; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  5555. b1Part2Result_Check = result2 == 1 ? (short)1 : (short)2; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  5556. int result = result1;
  5557. if (result == 1)
  5558. result = result2;
  5559. short b1MES_FLAG_Check = (short)result;
  5560. //Funs[plcNo].WriteMultipleRegisters<string>(2024, b1Part1SN_Check, 20);
  5561. //Funs[plcNo].WriteMultipleRegisters<string>(2044, b1Part2SN_Check, 20);
  5562. //Funs[plcNo].WriteMultipleRegisters<short>(2064, b1Part1Result_Check);
  5563. //Funs[plcNo].WriteMultipleRegisters<short>(2065, b1Part2Result_Check);
  5564. //// MES_Flag
  5565. //Funs[plcNo].WriteMultipleRegisters<short>(2003, b1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5566. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5567. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  5568. writeToPLC_Flag.Adress = 2003;
  5569. writeToPLC_Flag.Value = b1MES_FLAG_Check;
  5570. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5571. {
  5572. Name = "b1Part1SN_Check",
  5573. Adress = 2024,
  5574. ValueType = PLCValueType.String,
  5575. ValueTypeStrLength = 20,
  5576. Value = b1Part1SN_Check
  5577. });
  5578. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5579. {
  5580. Name = "b1Part2SN_Check",
  5581. Adress = 2044,
  5582. ValueType = PLCValueType.String,
  5583. ValueTypeStrLength = 20,
  5584. Value = b1Part2SN_Check
  5585. });
  5586. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5587. {
  5588. Name = "b1Part1Result_Check",
  5589. Adress = 2064,
  5590. ValueType = PLCValueType.Short,
  5591. Value = b1Part1Result_Check
  5592. });
  5593. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5594. {
  5595. Name = "b1Part2Result_Check",
  5596. Adress = 2065,
  5597. ValueType = PLCValueType.Short,
  5598. Value = b1Part2Result_Check
  5599. });
  5600. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  5601. }
  5602. catch (Exception ex)
  5603. {
  5604. string str = ex.StackTrace;
  5605. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5606. // MES_Flag
  5607. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5608. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5609. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  5610. writeToPLC_Flag.Adress = 2003;
  5611. writeToPLC_Flag.Value = (short)6;
  5612. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  5613. }
  5614. stopwatch1.Stop();
  5615. AddMessage(LogType.Info, stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5616. }
  5617. /// <summary>
  5618. /// [S2] FCT(板测)- 二穴载具解绑绑定
  5619. /// </summary>
  5620. /// <param name="plcNo">PLC编号</param>
  5621. /// <param name="stationNameStr">工站全称</param>
  5622. private void S2二穴载具解绑绑定(int plcNo, string stationNameStr)
  5623. {
  5624. Stopwatch stopwatch1 = new Stopwatch();
  5625. Stopwatch stopwatch2 = new Stopwatch();
  5626. try
  5627. {
  5628. stopwatch1.Start();
  5629. // 产品换载具
  5630. string b1ProductSN_Unbind = (string)s2PLCData["b1ProductSN_Unbind"]; // 原二穴载具SN(需要解绑的)
  5631. b1ProductSN_Unbind = b1ProductSN_Unbind.Replace("\0", "");
  5632. string b1ProductSN_Bind = (string)s2PLCData["b1ProductSN_Bind"]; // 新二穴载具SN(需要绑定的)
  5633. b1ProductSN_Bind = b1ProductSN_Bind.Replace("\0", "");
  5634. string b1Part1SN_Bind = (string)s2PLCData["b1Part1SN_Bind"]; // 穴位1物料SN(plc写入)
  5635. b1Part1SN_Bind = b1Part1SN_Bind.Replace("\0", "");
  5636. string b1Part2SN_Bind = (string)s2PLCData["b1Part2SN_Bind"]; // 穴位2物料SN(plc写入)
  5637. b1Part2SN_Bind = b1Part2SN_Bind.Replace("\0", "");
  5638. stopwatch2.Start();
  5639. #region 查询载具上的产品信息
  5640. //string cavityData = string.Empty;
  5641. //int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN_Unbind, ref cavityData);
  5642. //if (string.IsNullOrEmpty(cavityData))
  5643. // cavityData = "";
  5644. //if (snResult != 0)
  5645. //{
  5646. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5647. // writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5648. // writeToPLC_Flag.Adress = 2077;
  5649. // writeToPLC_Flag.Value = (short)6;
  5650. // SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5651. // stopwatch1.Stop();
  5652. // AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑绑定失败!MES边线软件_二穴载具查询返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5653. // return;
  5654. //}
  5655. #endregion 查询载具上的产品信息
  5656. #region 解绑(边线MES系统)
  5657. int snResult = XiaomiMES_RouteCommunication.SNDeleteData(b1ProductSN_Unbind);
  5658. if (snResult != 0)
  5659. {
  5660. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5661. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  5662. writeToPLC_Flag1.Adress = 2077;
  5663. writeToPLC_Flag1.Value = (short)6;
  5664. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  5665. stopwatch1.Stop();
  5666. AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑失败!MES边线软件_二穴载具[{b1ProductSN_Unbind}]解绑返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5667. return;
  5668. }
  5669. #endregion 解绑(边线MES系统)
  5670. #region 存储绑定数据到 边线MES系统中
  5671. string data = string.Concat(b1Part1SN_Bind, ".", b1Part2SN_Bind);
  5672. snResult = XiaomiMES_RouteCommunication.SNBindData(b1ProductSN_Bind, data);
  5673. if (snResult != 0)
  5674. {
  5675. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5676. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  5677. writeToPLC_Flag1.Adress = 2077;
  5678. writeToPLC_Flag1.Value = (short)6;
  5679. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  5680. stopwatch1.Stop();
  5681. AddMessage(LogType.Info, stationNameStr + $"_二穴载具绑定失败!MES边线软件_二穴载具[{b1ProductSN_Bind}]绑定[{data}]返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5682. return;
  5683. }
  5684. #endregion 存储绑定数据到 边线MES系统中
  5685. stopwatch2.Stop();
  5686. short b1MES_FLAG_Unbind = 1;
  5687. // MES_Flag
  5688. //Funs[plcNo].WriteMultipleRegisters<short>(2077, b1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5689. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5690. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5691. writeToPLC_Flag.Adress = 2077;
  5692. writeToPLC_Flag.Value = b1MES_FLAG_Unbind;
  5693. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5694. }
  5695. catch (Exception ex)
  5696. {
  5697. string str = ex.StackTrace;
  5698. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5699. // MES_Flag
  5700. stopwatch2.Start();
  5701. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  5702. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5703. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5704. writeToPLC_Flag.Adress = 2077;
  5705. writeToPLC_Flag.Value = (short)6;
  5706. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5707. stopwatch2.Stop();
  5708. }
  5709. stopwatch1.Stop();
  5710. AddMessage(LogType.Info, stationNameStr + "_二穴载具解绑绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5711. }
  5712. //// 上次采集到的SN
  5713. //private string sn_FCT = string.Empty;
  5714. /// <summary>
  5715. /// [S2] FCT(板测)- 出站数据
  5716. /// </summary>
  5717. private void S2出站接口(int plcNo, string stationCode, string stationName)
  5718. {
  5719. Stopwatch stopwatch1 = new Stopwatch();
  5720. Stopwatch stopwatch2 = new Stopwatch();
  5721. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5722. string stationNameStr = stationCode + stationName;
  5723. string processItem = stationName; // 测试项目
  5724. try
  5725. {
  5726. stopwatch1.Start();
  5727. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5728. //string batch_num = GlobalContext.BatchNumber; // 批次号
  5729. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5730. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5731. string b1ProductSN = (string)s2PLCData["b1ProductSN"]; // 产品SN(载具SN)
  5732. int b1Part1Result = (int)s2PLCData["b1Part1Result"]; // 产品1结果
  5733. int b1Part2Result = (int)s2PLCData["b1Part2Result"]; // 产品2结果
  5734. bool pass1 = b1Part1Result == 1;
  5735. bool pass2 = b1Part2Result == 1;
  5736. #region 根据 载具SN 查 物料SN
  5737. string cavityData = string.Empty;
  5738. int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN, ref cavityData);
  5739. if (string.IsNullOrEmpty(cavityData))
  5740. cavityData = "";
  5741. if (snResult != 0)
  5742. {
  5743. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5744. writeToPLC_Flag1.Name = "b1MES_FLAG";
  5745. writeToPLC_Flag1.Adress = 2169;
  5746. writeToPLC_Flag1.Value = (short)4;
  5747. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag1);
  5748. stopwatch1.Stop();
  5749. AddMessage(LogType.Info, stationNameStr + $"_上传出站数据失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5750. return;
  5751. }
  5752. #endregion 根据 载具SN 查 物料SN
  5753. string[] cavitySNs = cavityData.Split('.');
  5754. string b1ProductSN1 = string.Empty;
  5755. string b1ProductSN2 = string.Empty;
  5756. if (cavitySNs != null && cavitySNs.Length >= 2)
  5757. {
  5758. b1ProductSN1 = cavitySNs[0];
  5759. b1ProductSN2 = cavitySNs[1];
  5760. }
  5761. stopwatch2.Start();
  5762. // 产品1
  5763. int result1 = 0;
  5764. if (b1ProductSN1 == "假产品")
  5765. result1 = 1;
  5766. else
  5767. {
  5768. List<TestItem> items1 = new List<TestItem>();
  5769. items1.Add(new TestItem()
  5770. {
  5771. Parameter_name = "载具码",
  5772. Parameter_value = b1ProductSN.ToString(),
  5773. Parameter_unit = ""
  5774. });
  5775. items1.Add(new TestItem()
  5776. {
  5777. Parameter_name = "载具穴号",
  5778. Parameter_value = "1",
  5779. Parameter_unit = ""
  5780. });
  5781. items1.Add(new TestItem()
  5782. {
  5783. Parameter_name = "产品结果",
  5784. Parameter_value = b1Part1Result == 1 ? "OK" : "NG",
  5785. Parameter_unit = ""
  5786. });
  5787. result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  5788. , workorder_code, mtltmrk, b1ProductSN1, pass1, b1ProductSN, "1");
  5789. }
  5790. // 产品2
  5791. int result2 = 0;
  5792. if (b1ProductSN1 == "假产品")
  5793. result2 = 1;
  5794. else
  5795. {
  5796. List<TestItem> items2 = new List<TestItem>();
  5797. items2.Add(new TestItem()
  5798. {
  5799. Parameter_name = "载具码",
  5800. Parameter_value = b1ProductSN.ToString(),
  5801. Parameter_unit = ""
  5802. });
  5803. items2.Add(new TestItem()
  5804. {
  5805. Parameter_name = "载具穴号",
  5806. Parameter_value = "2",
  5807. Parameter_unit = ""
  5808. });
  5809. items2.Add(new TestItem()
  5810. {
  5811. Parameter_name = "产品结果",
  5812. Parameter_value = b1Part2Result == 1 ? "OK" : "NG",
  5813. Parameter_unit = ""
  5814. });
  5815. result2 = SwitctProcessData(stationNameStr, items2, equipmentCode, processItem
  5816. , workorder_code, mtltmrk, b1ProductSN2, pass2, b1ProductSN, "2");
  5817. }
  5818. short result = 0;
  5819. List<int> results = new List<int>() { result1, result2 };
  5820. if (result1 == 1 && result2 == 1)
  5821. result = 1;
  5822. else if (results.Contains(3))
  5823. result = 3;
  5824. else if (results.Contains(2))
  5825. result = 2;
  5826. else if (results.Contains(4))
  5827. result = 4;
  5828. else
  5829. result = 4;
  5830. stopwatch2.Stop();
  5831. //Funs[plcNo].WriteMultipleRegisters<short>(2169, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5832. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5833. writeToPLC_Flag.Name = "b1MES_FLAG";
  5834. writeToPLC_Flag.Adress = 2169;
  5835. writeToPLC_Flag.Value = result;
  5836. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  5837. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  5838. }
  5839. catch (Exception ex)
  5840. {
  5841. stopwatch2.Restart();
  5842. // MES_Flag 为4上位机报错
  5843. //Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)4); // 4代表上位机报警
  5844. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5845. writeToPLC_Flag.Name = "b1MES_FLAG";
  5846. writeToPLC_Flag.Adress = 2169;
  5847. writeToPLC_Flag.Value = (short)4;
  5848. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  5849. stopwatch2.Stop();
  5850. string str = ex.StackTrace;
  5851. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}出站数据报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5852. }
  5853. stopwatch1.Stop();
  5854. AddMessage(LogType.Info, stationNameStr + "_出站数据;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5855. }
  5856. /// <summary>
  5857. /// [S2] FCT(板测)- 节拍接口
  5858. /// </summary>
  5859. /// <param name="plcNo">PLC编号</param>
  5860. /// <param name="stationNameStr">工站全称</param>
  5861. private void S2节拍接口(int plcNo, string stationNameStr)
  5862. {
  5863. Stopwatch stopwatch1 = new Stopwatch();
  5864. Stopwatch stopwatch2 = new Stopwatch();
  5865. string resultStr = string.Empty;
  5866. try
  5867. {
  5868. stopwatch1.Start();
  5869. string oEEType = ((int)s2PLCData["b1OEEType"]).ToString(); // 节拍类型(plc写入)
  5870. string b1OEEProductSN = (string)s2PLCData["b1OEEProductSN"]; // 载具SN
  5871. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  5872. if (!actionBool)
  5873. {
  5874. stopwatch2.Start();
  5875. // MES_Flag
  5876. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5877. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5878. writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
  5879. writeToPLC_Flag1.Adress = 2203;
  5880. writeToPLC_Flag1.Value = (short)4;
  5881. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
  5882. stopwatch2.Stop();
  5883. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5884. return;
  5885. }
  5886. string b1OEEPartNo = string.Empty; // 物料码
  5887. if (string.IsNullOrEmpty(b1OEEProductSN))
  5888. {
  5889. stopwatch2.Start();
  5890. // MES_Flag
  5891. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5892. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5893. writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
  5894. writeToPLC_Flag1.Adress = 2203;
  5895. writeToPLC_Flag1.Value = (short)1;
  5896. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
  5897. stopwatch2.Stop();
  5898. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5899. return;
  5900. }
  5901. else
  5902. { // 查产品SN
  5903. b1OEEPartNo = "Test"; // ZS
  5904. }
  5905. short b1OEEMES_FLAG = 0;
  5906. // 上传OEE
  5907. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, b1OEEPartNo, b1OEEProductSN);
  5908. b1OEEMES_FLAG = result.Item1;
  5909. resultStr = result.Item2;
  5910. stopwatch2.Start();
  5911. // MES_Flag
  5912. //Funs[plcNo].WriteMultipleRegisters<short>(2203, b1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5913. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5914. writeToPLC_Flag.Name = "b1OEEMES_FLAG";
  5915. writeToPLC_Flag.Adress = 2203;
  5916. writeToPLC_Flag.Value = b1OEEMES_FLAG;
  5917. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
  5918. stopwatch2.Stop();
  5919. }
  5920. catch (Exception ex)
  5921. {
  5922. string str = ex.StackTrace;
  5923. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5924. // MES_Flag
  5925. stopwatch2.Start();
  5926. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  5927. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5928. writeToPLC_Flag.Name = "b1OEEMES_FLAG";
  5929. writeToPLC_Flag.Adress = 2203;
  5930. writeToPLC_Flag.Value = (short)4;
  5931. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
  5932. stopwatch2.Stop();
  5933. }
  5934. stopwatch1.Stop();
  5935. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5936. }
  5937. #endregion [S2] FCT(板测)
  5938. #endregion PLC2 李晓奇
  5939. #region PLC3 刘永村
  5940. #region [S3] 值板机
  5941. /// <summary>
  5942. /// S3工位的数据- 触发信号上次的值
  5943. /// </summary>
  5944. private Dictionary<string, object> s3PLCSignal_Old = new Dictionary<string, object>();
  5945. /// <summary>
  5946. /// S3工位的数据(含触发信号)
  5947. /// </summary>
  5948. private Dictionary<string, object> s3PLCData = new Dictionary<string, object>();
  5949. /// <summary>
  5950. /// S3工位的数据- 回写点位
  5951. /// </summary>
  5952. private Dictionary<string, WriteToPLC_Flag> s3PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  5953. /// <summary>
  5954. /// [S3] 值板机
  5955. /// </summary>
  5956. /// <param name="plcNo">PLC编号</param>
  5957. //private void ReadStation_S3(int plcNo)
  5958. //{
  5959. // // [S1] Tray盘上料装备
  5960. // // [S2] FCT
  5961. // // [S3] 值板机
  5962. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  5963. // // [S5] Tray盘下料装备
  5964. // /// 上位机心跳
  5965. // /// 获取设备报警数据与状态信息
  5966. // string stationCode = "[S3]";
  5967. // string stationName = "值板机";
  5968. // string stationNameStr = stationCode + stationName;
  5969. // #region 创建字典
  5970. // // 触发信号字典 赋值
  5971. // s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5972. // s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  5973. // s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  5974. // s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5975. // s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5976. // // PLC数据字典 赋值
  5977. // s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5978. // s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  5979. // s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5980. // s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  5981. // s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  5982. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5983. // s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5984. // s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  5985. // s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  5986. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5987. // s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  5988. // s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  5989. // s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  5990. // s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5991. // s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  5992. // s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  5993. // //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  5994. // s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5995. // s3PLCData.Add("c1Result", 0); // 产品结果
  5996. // s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5997. // s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  5998. // s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  5999. // s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  6000. // #endregion 创建字典
  6001. // while (IsRun)
  6002. // {
  6003. // try
  6004. // {
  6005. // if (!GlobalContext._IsCon_Funs3)
  6006. // {
  6007. // UpdatePLCMonitor(1, plcNo, 0);
  6008. // continue;
  6009. // }
  6010. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  6011. // {
  6012. // Stopwatch stopwatch1 = new Stopwatch();
  6013. // Stopwatch stopwatch2 = new Stopwatch();
  6014. // stopwatch1.Start();
  6015. // stopwatch2.Start();
  6016. // #region 一次性读取所有数据
  6017. // // 一次性读取所有数据
  6018. // ModbusClientHelper modbusClientHelper = Funs[plcNo];
  6019. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  6020. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  6021. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 36);
  6022. // int[] datas = data1.Concat(data2).ToArray();
  6023. // datas = datas.Concat(data3).ToArray();
  6024. // s3PLCData["c1PLC_FLAG_Check"] = datas[2]; // PLC_FLAG 进站校验
  6025. // s3PLCData["c1MES_FLAG_Check"] = datas[3]; // MES_FLAG
  6026. // int[] c1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  6027. // s3PLCData["c1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(c1ProductSN_CheckData, 0, 40); // 产品SN(二穴载具SN)
  6028. // s3PLCData["c1PLC_FLAG_Unbind"] = datas[81]; // PLC_FLAG 二穴载具解绑
  6029. // s3PLCData["c1MES_FLAG_Unbind"] = datas[82]; // MES_FLAG
  6030. // s3PLCData["c1VehicleCavity_Unbind"] = datas[103]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6031. // s3PLCData["c1PLC_FLAG_Bind"] = datas[114]; // PLC_FLAG 二穴载具绑定
  6032. // s3PLCData["c1MES_FLAG_Bind"] = datas[115]; // MES_FLAG
  6033. // s3PLCData["c1CavityReverse_Bind"] = datas[136]; // 是否是两个穴位交换
  6034. // s3PLCData["c1VehicleCavityFr_Bind"] = datas[137]; // 来源穴位号(产品取自二穴载具哪个穴位)
  6035. // s3PLCData["c1VehicleCavityTo_Bind"] = datas[138]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  6036. // s3PLCData["c1PLC_FLAG"] = datas[149]; // PLC_FLAG 出站接口
  6037. // s3PLCData["c1MES_FLAG"] = datas[150]; // MES_FLAG
  6038. // int[] c1ProductSNData = datas.Skip(151).Take(20).ToArray();
  6039. // s3PLCData["c1ProductSN"] = ModbusClient.ConvertRegistersToString(c1ProductSNData, 0, 40); // 产品SN(一穴载具SN)
  6040. // s3PLCData["c1VehicleCavity"] = datas[191]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6041. // s3PLCData["c1Result"] = datas[192]; // 产品结果
  6042. // s3PLCData["c1OEEPLC_FLAG"] = datas[203]; // PLC_FLAG 节拍接口
  6043. // s3PLCData["c1OEEMES_FLAG"] = datas[204]; // MES_FLAG
  6044. // int[] c1OEEProductSNData = datas.Skip(205).Take(20).ToArray();
  6045. // s3PLCData["c1OEEProductSN"] = ModbusClient.ConvertRegistersToString(c1OEEProductSNData, 0, 40); // 产品SN(载具SN)
  6046. // s3PLCData["c1OEEType"] = datas[225]; // 节拍类型(plc写入)
  6047. // #endregion 一次性读取所有数据
  6048. // stopwatch2.Stop();
  6049. // #region 回写操作,写后清空flag
  6050. // PLCWriteData(Funs[plcNo], ref s3PLCData, ref s3PLCWriteData);
  6051. // #endregion 回写操作,写后清空flag
  6052. // #region S3进站校验
  6053. // try
  6054. // {
  6055. // int c1PLC_FLAG_Check = (int)s3PLCData["c1PLC_FLAG_Check"];
  6056. // int c1MES_FLAG_Check = (int)s3PLCData["c1MES_FLAG_Check"];
  6057. // int c1PLC_FLAG_CheckOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Check"];
  6058. // if (c1PLC_FLAG_Check != c1PLC_FLAG_CheckOld)
  6059. // {
  6060. // if (c1PLC_FLAG_Check == 1 && c1MES_FLAG_Check == 0) // 0->1
  6061. // Task.Run(() => S3进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  6062. // else if (c1PLC_FLAG_Check == 0 && c1MES_FLAG_Check != 0)
  6063. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  6064. // s3PLCSignal_Old["c1PLC_FLAG_Check"] = s3PLCData["c1PLC_FLAG_Check"];
  6065. // }
  6066. // }
  6067. // catch (Exception ex)
  6068. // {
  6069. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  6070. // string str = ex.StackTrace;
  6071. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6072. // }
  6073. // #endregion S3进站校验
  6074. // #region S3二穴载具解绑
  6075. // try
  6076. // {
  6077. // int c1PLC_FLAG_Unbind = (int)s3PLCData["c1PLC_FLAG_Unbind"];
  6078. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Unbind"];
  6079. // int c1PLC_FLAG_UnbindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Unbind"];
  6080. // if (c1PLC_FLAG_Unbind != c1PLC_FLAG_UnbindOld)
  6081. // {
  6082. // if (c1PLC_FLAG_Unbind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  6083. // Task.Run(() => S3二穴载具解绑(plcNo, stationNameStr)); // MreTasks[2].Set();
  6084. // else if (c1PLC_FLAG_Unbind == 0 && c1MES_FLAG_Bind != 0)
  6085. // Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)0);
  6086. // s3PLCSignal_Old["c1PLC_FLAG_Unbind"] = s3PLCData["c1PLC_FLAG_Unbind"];
  6087. // }
  6088. // }
  6089. // catch (Exception ex)
  6090. // {
  6091. // Funs[plcNo].WriteMultipleRegisters<short>(2083, (short)6); // 6代表上位机报警
  6092. // string str = ex.StackTrace;
  6093. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6094. // }
  6095. // #endregion S3二穴载具解绑
  6096. // #region S3二穴载具绑定
  6097. // try
  6098. // {
  6099. // int c1PLC_FLAG_Bind = (int)s3PLCData["c1PLC_FLAG_Bind"];
  6100. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Bind"];
  6101. // int c1PLC_FLAG_BindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Bind"];
  6102. // if (c1PLC_FLAG_Bind != c1PLC_FLAG_BindOld)
  6103. // {
  6104. // if (c1PLC_FLAG_Bind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  6105. // Task.Run(() => S3二穴载具绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  6106. // else if (c1PLC_FLAG_Bind == 0 && c1MES_FLAG_Bind != 0)
  6107. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)0);
  6108. // s3PLCSignal_Old["c1PLC_FLAG_Bind"] = s3PLCData["c1PLC_FLAG_Bind"];
  6109. // }
  6110. // }
  6111. // catch (Exception ex)
  6112. // {
  6113. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  6114. // string str = ex.StackTrace;
  6115. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6116. // }
  6117. // #endregion S3二穴载具绑定
  6118. // #region S3出站接口(+一穴载具绑定)
  6119. // try
  6120. // {
  6121. // int c1PLC_FLAG = (int)s3PLCData["c1PLC_FLAG"];
  6122. // int c1MES_FLAG = (int)s3PLCData["c1MES_FLAG"];
  6123. // int c1PLC_FLAGOld = (int)s3PLCSignal_Old["c1PLC_FLAG"];
  6124. // if (c1PLC_FLAG != c1PLC_FLAGOld)
  6125. // {
  6126. // if (c1PLC_FLAG == 1 && c1MES_FLAG == 0) // 0->1
  6127. // Task.Run(() => S3出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  6128. // else if (c1PLC_FLAG == 0 && c1MES_FLAG != 0)
  6129. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)0);
  6130. // s3PLCSignal_Old["c1PLC_FLAG"] = s3PLCData["c1PLC_FLAG"];
  6131. // }
  6132. // }
  6133. // catch (Exception ex)
  6134. // {
  6135. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)6); // 6代表上位机报警
  6136. // string str = ex.StackTrace;
  6137. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6138. // }
  6139. // #endregion S3出站接口(+一穴载具绑定)
  6140. // #region S3节拍接口
  6141. // try
  6142. // {
  6143. // int c1OEEPLC_FLAG = (int)s3PLCData["c1OEEPLC_FLAG"];
  6144. // int c1OEEMES_FLAG = (int)s3PLCData["c1OEEMES_FLAG"];
  6145. // int c1OEEPLC_FLAGOld = (int)s3PLCSignal_Old["c1OEEPLC_FLAG"];
  6146. // if (c1OEEPLC_FLAG != c1OEEPLC_FLAGOld)
  6147. // {
  6148. // if (c1OEEPLC_FLAG == 1 && c1OEEMES_FLAG == 0) // 0->1
  6149. // Task.Run(() => S3节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  6150. // else if (c1OEEPLC_FLAG == 0 && c1OEEMES_FLAG != 0)
  6151. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)0);
  6152. // s3PLCSignal_Old["c1OEEPLC_FLAG"] = s3PLCData["c1OEEPLC_FLAG"];
  6153. // }
  6154. // }
  6155. // catch (Exception ex)
  6156. // {
  6157. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  6158. // string str = ex.StackTrace;
  6159. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6160. // }
  6161. // #endregion S3节拍接口
  6162. // #region 心跳
  6163. // try
  6164. // {
  6165. // short states = 0;
  6166. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  6167. // }
  6168. // catch (Exception ex)
  6169. // {
  6170. // string str = ex.StackTrace;
  6171. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6172. // }
  6173. // #endregion 心跳
  6174. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  6175. // stopwatch1.Stop();
  6176. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  6177. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  6178. // }
  6179. // else
  6180. // {
  6181. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6182. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  6183. // Funs[plcNo].Connect();
  6184. // }
  6185. // }
  6186. // catch (Exception ex)
  6187. // {
  6188. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6189. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6190. // Funs[plcNo].ReConnect();
  6191. // }
  6192. // Thread.Sleep(IntervalReadPLC);
  6193. // }
  6194. //}
  6195. /// <summary>
  6196. /// [S3] 值板机- 进站校验
  6197. /// </summary>
  6198. /// <param name="plcNo">PLC编号</param>
  6199. /// <param name="stationNameStr">工站全称</param>
  6200. private void S3进站校验(int plcNo, string stationNameStr)
  6201. {
  6202. Stopwatch stopwatch1 = new Stopwatch();
  6203. Stopwatch stopwatch2 = new Stopwatch();
  6204. try
  6205. {
  6206. stopwatch1.Start();
  6207. string sn = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(载具码)
  6208. sn = sn.Replace("\0", "");
  6209. #region 查询载具上的产品信息
  6210. string cavityData = string.Empty;
  6211. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  6212. if (string.IsNullOrEmpty(cavityData))
  6213. cavityData = "";
  6214. if (snResult != 0)
  6215. {
  6216. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6217. writeToPLC_Flag1.Name = "c1MES_FLAG_Check";
  6218. writeToPLC_Flag1.Adress = 2003;
  6219. writeToPLC_Flag1.Value = (short)6;
  6220. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag1);
  6221. stopwatch1.Stop();
  6222. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6223. return;
  6224. }
  6225. #endregion 查询载具上的产品信息
  6226. string[] cavitySNs = cavityData.Split('.');
  6227. string part1Str = ""; // 产品1的SN码
  6228. string part2Str = ""; // 产品2的SN码
  6229. short c1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  6230. short c1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  6231. if (cavitySNs != null && cavitySNs.Length >= 2)
  6232. {
  6233. part1Str = cavitySNs[0];
  6234. part2Str = cavitySNs[1];
  6235. c1Part1Result_Check = 2;
  6236. c1Part2Result_Check = 2;
  6237. }
  6238. if (part1Str == "假产品")
  6239. c1Part1Result_Check = 3;
  6240. if (part2Str == "假产品")
  6241. c1Part2Result_Check = 3;
  6242. // 调用MES进站
  6243. stopwatch2.Start();
  6244. // 调用MES进站 - 产品1
  6245. List<TestItem> item;
  6246. int result1 = c1Part1Result_Check;
  6247. if (result1 != 3)
  6248. {
  6249. item = new List<TestItem>();
  6250. item.Add(new TestItem()
  6251. {
  6252. Parameter_name = "载具码",
  6253. Parameter_value = sn,
  6254. });
  6255. item.Add(new TestItem()
  6256. {
  6257. Parameter_name = "载具穴号",
  6258. Parameter_value = "1",
  6259. });
  6260. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, part1Str, item, out string errorMsg);
  6261. }
  6262. // 调用MES进站 - 产品2
  6263. int result2 = c1Part2Result_Check;
  6264. if (result2 != 3)
  6265. {
  6266. item = new List<TestItem>();
  6267. item.Add(new TestItem()
  6268. {
  6269. Parameter_name = "载具码",
  6270. Parameter_value = sn,
  6271. });
  6272. item.Add(new TestItem()
  6273. {
  6274. Parameter_name = "载具穴号",
  6275. Parameter_value = "2",
  6276. });
  6277. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, part2Str, item, out string errorMsg);
  6278. }
  6279. stopwatch2.Stop();
  6280. if (result1 == 2)
  6281. c1Part1Result_Check = 2;
  6282. if (result2 == 2)
  6283. c1Part2Result_Check = 2;
  6284. int result = result1;
  6285. if (result == 1)
  6286. result = result2;
  6287. short c1Part1Num_Check = 0; // 穴位1产品返修次数(上位机写入)
  6288. short c1Part2Num_Check = 0; // 穴位2产品返修次数(上位机写入)
  6289. short c1MES_FLAG_Check = (short)result;
  6290. //Funs[plcNo].WriteMultipleRegisters<short>(2024, c1Part1Result_Check);
  6291. //Funs[plcNo].WriteMultipleRegisters<short>(2025, c1Part2Result_Check);
  6292. //Funs[plcNo].WriteMultipleRegisters<short>(2026, c1Part1Num_Check);
  6293. //Funs[plcNo].WriteMultipleRegisters<short>(2027, c1Part2Num_Check);
  6294. //// MES_Flag
  6295. //Funs[plcNo].WriteMultipleRegisters<short>(2003, c1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6296. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6297. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  6298. writeToPLC_Flag.Adress = 2003;
  6299. writeToPLC_Flag.Value = c1MES_FLAG_Check;
  6300. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6301. {
  6302. Name = "c1Part1Result_Check",
  6303. Adress = 2024,
  6304. ValueType = PLCValueType.Short,
  6305. Value = c1Part1Result_Check
  6306. });
  6307. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6308. {
  6309. Name = "c1Part2Result_Check",
  6310. Adress = 2025,
  6311. ValueType = PLCValueType.Short,
  6312. Value = c1Part2Result_Check
  6313. });
  6314. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6315. {
  6316. Name = "c1Part1Num_Check",
  6317. Adress = 2026,
  6318. ValueType = PLCValueType.Short,
  6319. Value = c1Part1Num_Check
  6320. });
  6321. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6322. {
  6323. Name = "c1Part2Num_Check",
  6324. Adress = 2027,
  6325. ValueType = PLCValueType.Short,
  6326. Value = c1Part2Num_Check
  6327. });
  6328. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  6329. }
  6330. catch (Exception ex)
  6331. {
  6332. string str = ex.StackTrace;
  6333. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6334. // MES_Flag
  6335. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  6336. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6337. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  6338. writeToPLC_Flag.Adress = 2003;
  6339. writeToPLC_Flag.Value = (short)6;
  6340. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  6341. }
  6342. stopwatch1.Stop();
  6343. AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6344. }
  6345. /// <summary>
  6346. /// [S3] 值板机 - 二穴载具解绑
  6347. /// </summary>
  6348. /// <param name="plcNo">PLC编号</param>
  6349. /// <param name="stationNameStr">工站全称</param>
  6350. private void S3二穴载具解绑(int plcNo, string stationNameStr)
  6351. {
  6352. Stopwatch stopwatch1 = new Stopwatch();
  6353. Stopwatch stopwatch2 = new Stopwatch();
  6354. try
  6355. {
  6356. stopwatch1.Start();
  6357. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  6358. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6359. int c1VehicleCavity_Unbind = (int)s3PLCData["c1VehicleCavity_Unbind"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6360. // 解绑
  6361. #region 查询载具上的产品信息
  6362. string cavityData = string.Empty;
  6363. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6364. if (string.IsNullOrEmpty(cavityData))
  6365. cavityData = "";
  6366. if (snResult != 0)
  6367. {
  6368. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6369. writeToPLC_Flag1.Name = "c1MES_FLAG_Unbind";
  6370. writeToPLC_Flag1.Adress = 2082;
  6371. writeToPLC_Flag1.Value = (short)6;
  6372. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag1);
  6373. stopwatch1.Stop();
  6374. AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6375. return;
  6376. }
  6377. #endregion 查询载具上的产品信息
  6378. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  6379. #region 解绑
  6380. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  6381. {
  6382. // 删除
  6383. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6384. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res1}");
  6385. }
  6386. else
  6387. {
  6388. string data_new = string.Join(".", cavitySNs);
  6389. // 删除再插入
  6390. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6391. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6392. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res2},{res3}");
  6393. }
  6394. #endregion 解绑
  6395. short c1MES_FLAG_Unbind = 1;
  6396. stopwatch2.Start();
  6397. // MES_Flag
  6398. //Funs[plcNo].WriteMultipleRegisters<short>(2082, c1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6399. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6400. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  6401. writeToPLC_Flag.Adress = 2082;
  6402. writeToPLC_Flag.Value = c1MES_FLAG_Unbind;
  6403. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  6404. stopwatch2.Stop();
  6405. }
  6406. catch (Exception ex)
  6407. {
  6408. string str = ex.StackTrace;
  6409. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6410. // MES_Flag
  6411. stopwatch2.Start();
  6412. //Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)6); // 6代表上位机报警
  6413. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6414. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  6415. writeToPLC_Flag.Adress = 2082;
  6416. writeToPLC_Flag.Value = (short)6;
  6417. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  6418. stopwatch2.Stop();
  6419. }
  6420. stopwatch1.Stop();
  6421. AddMessage(LogType.Info, stationNameStr + "_二穴载具解绑;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6422. }
  6423. /// <summary>
  6424. /// [S3] 值板机 - 二穴载具绑定
  6425. /// </summary>
  6426. /// <param name="plcNo">PLC编号</param>
  6427. /// <param name="stationNameStr">工站全称</param>
  6428. private void S3二穴载具绑定(int plcNo, string stationNameStr)
  6429. {
  6430. Stopwatch stopwatch1 = new Stopwatch();
  6431. Stopwatch stopwatch2 = new Stopwatch();
  6432. try
  6433. {
  6434. stopwatch1.Start();
  6435. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  6436. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6437. int c1CavityReverse_Bind = (int)s3PLCData["c1CavityReverse_Bind"]; // 是否是两个穴位交换
  6438. int c1VehicleCavityFr_Bind = (int)s3PLCData["c1VehicleCavityFr_Bind"]; // 来源穴位号(产品取自二穴载具哪个穴位)
  6439. int c1VehicleCavityTo_Bind = (int)s3PLCData["c1VehicleCavityTo_Bind"]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  6440. stopwatch2.Start();
  6441. #region 查询载具上的产品信息
  6442. string cavityData = string.Empty;
  6443. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6444. if (string.IsNullOrEmpty(cavityData))
  6445. cavityData = "";
  6446. if (snResult != 0)
  6447. {
  6448. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6449. writeToPLC_Flag1.Name = "c1MES_FLAG_Bind";
  6450. writeToPLC_Flag1.Adress = 2115;
  6451. writeToPLC_Flag1.Value = (short)6;
  6452. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag1);
  6453. stopwatch1.Stop();
  6454. AddMessage(LogType.Info, stationNameStr + $"_二穴载具绑定失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6455. return;
  6456. }
  6457. #endregion 查询载具上的产品信息
  6458. // 产品换载具
  6459. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  6460. string partSn1 = "";
  6461. string partSn2 = "";
  6462. if (cavitySNs != null && cavitySNs.Length >= 2)
  6463. {
  6464. partSn1 = cavitySNs[0];
  6465. partSn2 = cavitySNs[1];
  6466. }
  6467. string data_new = string.Empty;
  6468. // 是否是两个穴位交换
  6469. if (c1CavityReverse_Bind == 1)
  6470. {
  6471. // 交换
  6472. data_new = string.Concat(partSn2, ".", partSn1);
  6473. }
  6474. else
  6475. { // 不交换
  6476. string sn = string.Copy(cavitySNs[c1VehicleCavityFr_Bind]);
  6477. cavitySNs[c1VehicleCavityTo_Bind] = sn;
  6478. cavitySNs[c1VehicleCavityFr_Bind] = "";
  6479. data_new = string.Join(".", cavitySNs);
  6480. }
  6481. // 删除再插入
  6482. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6483. int res2 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6484. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-_二穴载具绑定SN{c1ProductSN_Check}---{res1},{res2}");
  6485. stopwatch2.Stop();
  6486. short c1MES_FLAG_Bind = 1;
  6487. // MES_Flag
  6488. //Funs[plcNo].WriteMultipleRegisters<short>(2115, c1MES_FLAG_Bind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6489. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6490. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  6491. writeToPLC_Flag.Adress = 2115;
  6492. writeToPLC_Flag.Value = c1MES_FLAG_Bind;
  6493. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  6494. }
  6495. catch (Exception ex)
  6496. {
  6497. string str = ex.StackTrace;
  6498. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6499. // MES_Flag
  6500. stopwatch2.Start();
  6501. //Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  6502. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6503. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  6504. writeToPLC_Flag.Adress = 2115;
  6505. writeToPLC_Flag.Value = (short)6;
  6506. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  6507. stopwatch2.Stop();
  6508. }
  6509. stopwatch1.Stop();
  6510. AddMessage(LogType.Info, stationNameStr + "_二穴载具绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6511. }
  6512. //// 上次采集到的SN
  6513. //private string sn_值板机 = string.Empty;
  6514. /// <summary>
  6515. /// [S3] 值板机 - 出站接口
  6516. /// </summary>
  6517. /// <param name="plcNo">PLC编号</param>
  6518. private void S3出站接口(int plcNo, string stationCode, string stationName)
  6519. {
  6520. Stopwatch stopwatch1 = new Stopwatch();
  6521. Stopwatch stopwatch2 = new Stopwatch();
  6522. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6523. string stationNameStr = stationCode + stationName;
  6524. string processItem = stationName; // 测试项目
  6525. try
  6526. {
  6527. stopwatch1.Start();
  6528. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6529. //string batch_num = GlobalContext.BatchNumber; // 批次号
  6530. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6531. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6532. string sn = (string)s3PLCData["c1ProductSN"]; // 产品SN(一穴载具SN)
  6533. sn = sn.Replace("\0", "");
  6534. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 二穴载具SN(产品取自哪个二穴载具)
  6535. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6536. int c1VehicleCavity = (int)s3PLCData["c1VehicleCavity"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6537. int c1Result = (int)s3PLCData["c1Result"]; // 产品结果
  6538. bool pass = c1Result == 1;
  6539. // 查sn
  6540. #region 查询载具上的产品信息
  6541. string cavityData = string.Empty;
  6542. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6543. if (string.IsNullOrEmpty(cavityData))
  6544. cavityData = "";
  6545. if (snResult != 0)
  6546. {
  6547. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6548. writeToPLC_Flag1.Name = "c1MES_FLAG";
  6549. writeToPLC_Flag1.Adress = 2150;
  6550. writeToPLC_Flag1.Value = (short)4;
  6551. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag1);
  6552. stopwatch1.Stop();
  6553. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6554. return;
  6555. }
  6556. #endregion 查询载具上的产品信息
  6557. string[] cavitySNs = cavityData.Split('.');
  6558. string productSN = "";
  6559. if (cavitySNs != null && cavitySNs.Length >= 2)
  6560. {
  6561. productSN = cavitySNs[c1VehicleCavity];
  6562. cavitySNs[c1VehicleCavity] = "";
  6563. }
  6564. stopwatch2.Start();
  6565. List<TestItem> items = new List<TestItem>();
  6566. items.Add(new TestItem()
  6567. {
  6568. Parameter_name = "二穴载具码",
  6569. Parameter_value = c1ProductSN_Check,
  6570. Parameter_unit = ""
  6571. });
  6572. items.Add(new TestItem()
  6573. {
  6574. Parameter_name = "二穴载具穴号",
  6575. Parameter_value = c1VehicleCavity.ToString(),
  6576. Parameter_unit = ""
  6577. });
  6578. items.Add(new TestItem()
  6579. {
  6580. Parameter_name = "一穴载具码",
  6581. Parameter_value = sn,
  6582. Parameter_unit = ""
  6583. });
  6584. items.Add(new TestItem()
  6585. {
  6586. Parameter_name = "一穴载具穴号",
  6587. Parameter_value = "1",
  6588. Parameter_unit = ""
  6589. });
  6590. items.Add(new TestItem()
  6591. {
  6592. Parameter_name = "产品结果",
  6593. Parameter_value = c1Result == 1 ? "OK" : "NG",
  6594. Parameter_unit = ""
  6595. });
  6596. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  6597. , workorder_code, mtltmrk, productSN, pass, sn, "1");
  6598. short result = (short)result1;
  6599. stopwatch2.Stop();
  6600. #region 存储绑定数据到 边线MES系统中
  6601. if (result == 1)
  6602. {
  6603. string data = string.Concat(productSN);
  6604. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  6605. if (resultMesR != 0)
  6606. {
  6607. result = 4;
  6608. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  6609. }
  6610. }
  6611. #endregion 存储绑定数据到 边线MES系统中
  6612. #region 产品从 来源载具(二穴载具)中删除
  6613. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  6614. {
  6615. // 删除
  6616. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6617. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res1}");
  6618. }
  6619. else
  6620. {
  6621. string data_new = string.Join(".", cavitySNs);
  6622. // 删除再插入
  6623. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6624. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6625. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res2},{res3}");
  6626. }
  6627. #endregion 产品从 来源载具(二穴载具)中删除
  6628. // MES_Flag 为MES报错
  6629. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6630. //Funs[plcNo].WriteMultipleRegisters<short>(2150, result); // 4代表上位机报警
  6631. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6632. writeToPLC_Flag.Name = "c1MES_FLAG";
  6633. writeToPLC_Flag.Adress = 2150;
  6634. writeToPLC_Flag.Value = result;
  6635. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  6636. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  6637. }
  6638. catch (Exception ex)
  6639. {
  6640. stopwatch2.Restart();
  6641. // MES_Flag 为4上位机报错
  6642. //Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)4); // 4代表上位机报警
  6643. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6644. writeToPLC_Flag.Name = "c1MES_FLAG";
  6645. writeToPLC_Flag.Adress = 2150;
  6646. writeToPLC_Flag.Value = (short)4;
  6647. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  6648. stopwatch2.Stop();
  6649. string str = ex.StackTrace;
  6650. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6651. }
  6652. stopwatch1.Stop();
  6653. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6654. }
  6655. /// <summary>
  6656. /// [S3] 值板机- 节拍接口
  6657. /// </summary>
  6658. /// <param name="plcNo">PLC编号</param>
  6659. /// <param name="stationNameStr">工站全称</param>
  6660. private void S3节拍接口(int plcNo, string stationNameStr)
  6661. {
  6662. Stopwatch stopwatch1 = new Stopwatch();
  6663. Stopwatch stopwatch2 = new Stopwatch();
  6664. string resultStr = string.Empty;
  6665. try
  6666. {
  6667. stopwatch1.Start();
  6668. string oEEType = ((int)s3PLCData["c1OEEType"]).ToString(); // 节拍类型(plc写入)
  6669. string c1OEEProductSN = (string)s3PLCData["c1OEEProductSN"]; // 载具SN
  6670. c1OEEProductSN = c1OEEProductSN.Replace("\0", "");
  6671. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  6672. if (!actionBool)
  6673. {
  6674. stopwatch2.Start();
  6675. // MES_Flag
  6676. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6677. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6678. writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
  6679. writeToPLC_Flag1.Adress = 2204;
  6680. writeToPLC_Flag1.Value = (short)4;
  6681. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
  6682. stopwatch2.Stop();
  6683. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6684. return;
  6685. }
  6686. string c1OEEPartNo = string.Empty; // 物料码
  6687. if (string.IsNullOrEmpty(c1OEEProductSN))
  6688. {
  6689. stopwatch2.Start();
  6690. // MES_Flag
  6691. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6692. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6693. writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
  6694. writeToPLC_Flag1.Adress = 2204;
  6695. writeToPLC_Flag1.Value = (short)1;
  6696. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
  6697. stopwatch2.Stop();
  6698. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6699. return;
  6700. }
  6701. else
  6702. { // 查产品SN
  6703. c1OEEPartNo = "Test"; // ZS
  6704. }
  6705. short c1OEEMES_FLAG = 0;
  6706. // 上传OEE
  6707. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, c1OEEPartNo, c1OEEProductSN);
  6708. c1OEEMES_FLAG = result.Item1;
  6709. resultStr = result.Item2;
  6710. stopwatch2.Start();
  6711. // MES_Flag
  6712. //Funs[plcNo].WriteMultipleRegisters<short>(2204, c1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6713. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6714. writeToPLC_Flag.Name = "c1OEEMES_FLAG";
  6715. writeToPLC_Flag.Adress = 2204;
  6716. writeToPLC_Flag.Value = c1OEEMES_FLAG;
  6717. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
  6718. stopwatch2.Stop();
  6719. }
  6720. catch (Exception ex)
  6721. {
  6722. string str = ex.StackTrace;
  6723. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6724. // MES_Flag
  6725. stopwatch2.Start();
  6726. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  6727. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6728. writeToPLC_Flag.Name = "c1OEEMES_FLAG";
  6729. writeToPLC_Flag.Adress = 2204;
  6730. writeToPLC_Flag.Value = (short)4;
  6731. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
  6732. stopwatch2.Stop();
  6733. }
  6734. stopwatch1.Stop();
  6735. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6736. }
  6737. #endregion [S3] 值板机
  6738. #endregion PLC3 刘永村
  6739. #region PLC4 刘果段
  6740. #region [S4] 取放桁架
  6741. /// <summary>
  6742. /// S4工位的数据- 触发信号上次的值
  6743. /// </summary>
  6744. private Dictionary<string, object> s4PLCSignal_Old = new Dictionary<string, object>();
  6745. /// <summary>
  6746. /// S4工位的数据(含触发信号)
  6747. /// </summary>
  6748. private Dictionary<string, object> s4PLCData = new Dictionary<string, object>();
  6749. /// <summary>
  6750. /// S4工位的数据- 回写点位
  6751. /// </summary>
  6752. private Dictionary<string, WriteToPLC_Flag> s4PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  6753. /// <summary>
  6754. /// [S4] 取放桁架
  6755. /// </summary>
  6756. /// <param name="plcNo">PLC编号</param>
  6757. //private void ReadStation_S4(int plcNo)
  6758. //{
  6759. // // [S1] Tray盘上料装备
  6760. // // [S2] FCT
  6761. // // [S3] 值板机
  6762. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  6763. // // [S5] Tray盘下料装备
  6764. // /// 上位机心跳
  6765. // /// 获取设备报警数据与状态信息
  6766. // string stationCode = "[S4_1]";
  6767. // string stationName = "载具下线装备";
  6768. // string stationNameStr = stationCode + stationName;
  6769. // string stationCode2 = "[S4_2]";
  6770. // string stationName2 = "桁架";
  6771. // string stationNameStr2 = stationCode2 + stationName2;
  6772. // string stationCode3 = "[S4_3]";
  6773. // string stationName3 = "提升机1";
  6774. // string stationNameStr3 = stationCode3 + stationName3;
  6775. // string stationCode4 = "[S4_4]";
  6776. // string stationName4 = "提升机2";
  6777. // string stationNameStr4 = stationCode4 + stationName4;
  6778. // string stationCode5 = "[S4_5]";
  6779. // string stationName5 = "载具上线装备";
  6780. // string stationNameStr5 = stationCode5 + stationName5;
  6781. // #region 创建字典
  6782. // // 触发信号字典 赋值
  6783. // s4PLCSignal_Old.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6784. // s4PLCSignal_Old.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  6785. // s4PLCSignal_Old.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6786. // s4PLCSignal_Old.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6787. // s4PLCSignal_Old.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  6788. // s4PLCSignal_Old.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  6789. // s4PLCSignal_Old.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  6790. // s4PLCSignal_Old.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6791. // s4PLCSignal_Old.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  6792. // s4PLCSignal_Old.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  6793. // s4PLCSignal_Old.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6794. // // PLC数据字典 赋值
  6795. // // 载具下线装备(弹夹上线)
  6796. // s4PLCData.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6797. // s4PLCData.Add("d1BulletclipCode", ""); // 扫到的码
  6798. // s4PLCData.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  6799. // s4PLCData.Add("d1VehicleCode", ""); // 扫到的码
  6800. // s4PLCData.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6801. // s4PLCData.Add("d1MES_FLAG", 0); // MES_FLAG
  6802. // s4PLCData.Add("d1ProductSN", ""); // 产品SN(弹夹码)
  6803. // s4PLCData.Add("d1VehicleCode1", ""); // 载具1码(弹夹穴位1)
  6804. // s4PLCData.Add("d1VehicleCode2", ""); // 载具2码(弹夹穴位2)
  6805. // s4PLCData.Add("d1VehicleCode3", ""); // 载具3码(弹夹穴位3)
  6806. // s4PLCData.Add("d1VehicleCode4", ""); // 载具4码(弹夹穴位4)
  6807. // s4PLCData.Add("d1VehicleCode5", ""); // 载具5码(弹夹穴位5)
  6808. // s4PLCData.Add("d1VehicleCode6", ""); // 载具6码(弹夹穴位6)
  6809. // s4PLCData.Add("d1VehicleCode7", ""); // 载具7码(弹夹穴位7)
  6810. // s4PLCData.Add("d1VehicleCode8", ""); // 载具8码(弹夹穴位8)
  6811. // s4PLCData.Add("d1VehicleCode9", ""); // 载具9码(弹夹穴位9)
  6812. // s4PLCData.Add("d1VehicleCode10", ""); // 载具10码(弹夹穴位10)
  6813. // s4PLCData.Add("d1Result", 0); // 产品结果
  6814. // s4PLCData.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6815. // s4PLCData.Add("d1OEEMES_FLAG", 0); // MES_FLAG
  6816. // s4PLCData.Add("d1OEEProductSN", "");// 产品SN(载具SN)
  6817. // s4PLCData.Add("d1OEEType", 0); // 节拍类型(plc写入)
  6818. // s4PLCData.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  6819. // s4PLCData.Add("d2BulletclipStates", 0); // 弹夹状态
  6820. // s4PLCData.Add("d2BulletclipCode", ""); // 扫到的码
  6821. // // 真空标机(提升机)
  6822. // s4PLCData.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  6823. // s4PLCData.Add("d3MES_FLAG", 0); // MES_FLAG
  6824. // s4PLCData.Add("d3Type", 0); // 进站还是出站
  6825. // s4PLCData.Add("d3ProductSN", ""); // 产品SN(弹夹码)
  6826. // s4PLCData.Add("d3Result", 0); // 产品结果
  6827. // s4PLCData.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  6828. // s4PLCData.Add("d4MES_FLAG", 0); // MES_FLAG
  6829. // s4PLCData.Add("d4Type", 0); // 进站还是出站
  6830. // s4PLCData.Add("d4ProductSN", ""); // 产品SN(弹夹码)
  6831. // s4PLCData.Add("d4Result", 0); // 产品结果
  6832. // // 载具上线装备(弹夹下线)
  6833. // s4PLCData.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6834. // s4PLCData.Add("d5BulletclipCode", ""); // 扫到的码
  6835. // s4PLCData.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  6836. // s4PLCData.Add("d5VehicleCode", ""); // 扫到的码
  6837. // s4PLCData.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  6838. // s4PLCData.Add("d5MES_FLAG", 0); // MES_FLAG
  6839. // s4PLCData.Add("d5ProductSN", ""); // 产品SN(弹夹码)
  6840. // s4PLCData.Add("d5VehicleCode1", ""); // 载具1码(弹夹穴位1)
  6841. // s4PLCData.Add("d5VehicleCode2", ""); // 载具2码(弹夹穴位2)
  6842. // s4PLCData.Add("d5VehicleCode3", ""); // 载具3码(弹夹穴位3)
  6843. // s4PLCData.Add("d5VehicleCode4", ""); // 载具4码(弹夹穴位4)
  6844. // s4PLCData.Add("d5VehicleCode5", ""); // 载具5码(弹夹穴位5)
  6845. // s4PLCData.Add("d5VehicleCode6", ""); // 载具6码(弹夹穴位6)
  6846. // s4PLCData.Add("d5VehicleCode7", ""); // 载具7码(弹夹穴位7)
  6847. // s4PLCData.Add("d5VehicleCode8", ""); // 载具8码(弹夹穴位8)
  6848. // s4PLCData.Add("d5VehicleCode9", ""); // 载具9码(弹夹穴位9)
  6849. // s4PLCData.Add("d5VehicleCode10", ""); // 载具10码(弹夹穴位10)
  6850. // s4PLCData.Add("d5Result", 0); // 产品结果
  6851. // s4PLCData.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6852. // s4PLCData.Add("d5OEEMES_FLAG", 0); // MES_FLAG
  6853. // s4PLCData.Add("d5OEEProductSN", "");// 产品SN(载具SN)
  6854. // s4PLCData.Add("d5OEEType", 0); // 节拍类型(plc写入)
  6855. // #endregion 创建字典
  6856. // while (IsRun)
  6857. // {
  6858. // try
  6859. // {
  6860. // if (!GlobalContext._IsCon_Funs4)
  6861. // {
  6862. // UpdatePLCMonitor(1, plcNo, 0);
  6863. // continue;
  6864. // }
  6865. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  6866. // {
  6867. // Stopwatch stopwatch1 = new Stopwatch();
  6868. // Stopwatch stopwatch2 = new Stopwatch();
  6869. // stopwatch1.Start();
  6870. // stopwatch2.Start();
  6871. // #region 一次性读取所有数据
  6872. // // 载具下线装备(弹夹上线)
  6873. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  6874. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  6875. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  6876. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 100);
  6877. // int[] data5 = Funs[plcNo].ReadHoldingRegisters(2400, 100);
  6878. // int[] data6 = Funs[plcNo].ReadHoldingRegisters(2500, 100);
  6879. // int[] data7 = Funs[plcNo].ReadHoldingRegisters(2600, 100);
  6880. // int[] data8 = Funs[plcNo].ReadHoldingRegisters(2700, 100);
  6881. // int[] data9 = Funs[plcNo].ReadHoldingRegisters(2800, 100);
  6882. // int[] data10 = Funs[plcNo].ReadHoldingRegisters(2900, 56);
  6883. // int[] datas = data1.Concat(data2).ToArray();
  6884. // datas = datas.Concat(data3).ToArray();
  6885. // datas = datas.Concat(data4).ToArray();
  6886. // datas = datas.Concat(data5).ToArray();
  6887. // datas = datas.Concat(data6).ToArray();
  6888. // datas = datas.Concat(data7).ToArray();
  6889. // datas = datas.Concat(data8).ToArray();
  6890. // datas = datas.Concat(data9).ToArray();
  6891. // datas = datas.Concat(data10).ToArray();
  6892. // // 载具下线装备(弹夹上线)
  6893. // s4PLCData["d1BulletclipScanCode"] = datas[2]; // 扫码信号 弹夹扫码
  6894. // int[] d1BulletclipCodeData = datas.Skip(3).Take(20).ToArray();
  6895. // s4PLCData["d1BulletclipCode"] = ModbusClient.ConvertRegistersToString(d1BulletclipCodeData, 0, 40);
  6896. // s4PLCData["d1VehicleScanCode"] = datas[33]; // 扫码信号 载具扫码
  6897. // int[] d1VehicleCodeData = datas.Skip(34).Take(20).ToArray();
  6898. // s4PLCData["d1VehicleCode"] = ModbusClient.ConvertRegistersToString(d1VehicleCodeData, 0, 40);
  6899. // s4PLCData["d1PLC_FLAG"] = datas[64]; // PLC_FLAG 出站接口
  6900. // s4PLCData["d1MES_FLAG"] = datas[65];
  6901. // int[] d1ProductSNData = datas.Skip(66).Take(20).ToArray();
  6902. // s4PLCData["d1ProductSN"] = ModbusClient.ConvertRegistersToString(d1ProductSNData, 0, 40); // 产品SN(物料码)
  6903. // int[] d1VehicleCode1Data = datas.Skip(86).Take(20).ToArray();
  6904. // s4PLCData["d1VehicleCode1"] = ModbusClient.ConvertRegistersToString(d1VehicleCode1Data, 0, 40);
  6905. // int[] d1VehicleCode2Data = datas.Skip(106).Take(20).ToArray();
  6906. // s4PLCData["d1VehicleCode2"] = ModbusClient.ConvertRegistersToString(d1VehicleCode2Data, 0, 40);
  6907. // int[] d1VehicleCode3Data = datas.Skip(126).Take(20).ToArray();
  6908. // s4PLCData["d1VehicleCode3"] = ModbusClient.ConvertRegistersToString(d1VehicleCode3Data, 0, 40);
  6909. // int[] d1VehicleCode4Data = datas.Skip(146).Take(20).ToArray();
  6910. // s4PLCData["d1VehicleCode4"] = ModbusClient.ConvertRegistersToString(d1VehicleCode4Data, 0, 40);
  6911. // int[] d1VehicleCode5Data = datas.Skip(166).Take(20).ToArray();
  6912. // s4PLCData["d1VehicleCode5"] = ModbusClient.ConvertRegistersToString(d1VehicleCode5Data, 0, 40);
  6913. // int[] d1VehicleCode6Data = datas.Skip(186).Take(20).ToArray();
  6914. // s4PLCData["d1VehicleCode6"] = ModbusClient.ConvertRegistersToString(d1VehicleCode6Data, 0, 40);
  6915. // int[] d1VehicleCode7Data = datas.Skip(206).Take(20).ToArray();
  6916. // s4PLCData["d1VehicleCode7"] = ModbusClient.ConvertRegistersToString(d1VehicleCode7Data, 0, 40);
  6917. // int[] d1VehicleCode8Data = datas.Skip(226).Take(20).ToArray();
  6918. // s4PLCData["d1VehicleCode8"] = ModbusClient.ConvertRegistersToString(d1VehicleCode8Data, 0, 40);
  6919. // int[] d1VehicleCode9Data = datas.Skip(246).Take(20).ToArray();
  6920. // s4PLCData["d1VehicleCode9"] = ModbusClient.ConvertRegistersToString(d1VehicleCode9Data, 0, 40);
  6921. // int[] d1VehicleCode10Data = datas.Skip(266).Take(20).ToArray();
  6922. // s4PLCData["d1VehicleCode10"] = ModbusClient.ConvertRegistersToString(d1VehicleCode10Data, 0, 40);
  6923. // int[] d1VehicleCode11Data = datas.Skip(286).Take(20).ToArray();
  6924. // s4PLCData["d1VehicleCode11"] = ModbusClient.ConvertRegistersToString(d1VehicleCode11Data, 0, 40);
  6925. // int[] d1VehicleCode12Data = datas.Skip(306).Take(20).ToArray();
  6926. // s4PLCData["d1VehicleCode12"] = ModbusClient.ConvertRegistersToString(d1VehicleCode12Data, 0, 40);
  6927. // int[] d1VehicleCode13Data = datas.Skip(326).Take(20).ToArray();
  6928. // s4PLCData["d1VehicleCode13"] = ModbusClient.ConvertRegistersToString(d1VehicleCode13Data, 0, 40);
  6929. // int[] d1VehicleCode14Data = datas.Skip(346).Take(20).ToArray();
  6930. // s4PLCData["d1VehicleCode14"] = ModbusClient.ConvertRegistersToString(d1VehicleCode14Data, 0, 40);
  6931. // int[] d1VehicleCode15Data = datas.Skip(366).Take(20).ToArray();
  6932. // s4PLCData["d1VehicleCode15"] = ModbusClient.ConvertRegistersToString(d1VehicleCode15Data, 0, 40);
  6933. // s4PLCData["d1Result"] = datas[386];
  6934. // s4PLCData["d1OEEPLC_FLAG"] = datas[397]; // PLC_FLAG 节拍接口
  6935. // s4PLCData["d1OEEMES_FLAG"] = datas[398];
  6936. // int[] d1OEEProductSNData = datas.Skip(399).Take(20).ToArray();
  6937. // s4PLCData["d1OEEProductSN"] = ModbusClient.ConvertRegistersToString(d1OEEProductSNData, 0, 40);
  6938. // s4PLCData["d1OEEType"] = datas[419];
  6939. // // 桁架(查询标机中弹夹的状态)
  6940. // s4PLCData["d2BulletclipScanCode"] = datas[430];
  6941. // s4PLCData["d2BulletclipStates"] = datas[431];
  6942. // int[] d2BulletclipCodeData = datas.Skip(432).Take(20).ToArray();
  6943. // s4PLCData["d2BulletclipCode"] = ModbusClient.ConvertRegistersToString(d2BulletclipCodeData, 0, 40);
  6944. // // 真空标机
  6945. // s4PLCData["d3PLC_FLAG"] = datas[462]; // 真空标机1 出站接口
  6946. // s4PLCData["d3MES_FLAG"] = datas[463];
  6947. // int[] d3ProductSNData = datas.Skip(464).Take(20).ToArray();
  6948. // s4PLCData["d3ProductSN"] = ModbusClient.ConvertRegistersToString(d3ProductSNData, 0, 40);
  6949. // s4PLCData["d3Result"] = datas[484];
  6950. // s4PLCData["d3Type"] = datas[485];
  6951. // s4PLCData["d4PLC_FLAG"] = datas[495]; // 真空标机2 出站接口
  6952. // s4PLCData["d4MES_FLAG"] = datas[496];
  6953. // int[] d4ProductSNData = datas.Skip(497).Take(20).ToArray();
  6954. // s4PLCData["d4ProductSN"] = ModbusClient.ConvertRegistersToString(d4ProductSNData, 0, 40);
  6955. // s4PLCData["d4Result"] = datas[517];
  6956. // s4PLCData["d4Type"] = datas[518];
  6957. // // 载具上线装备(弹夹下线)
  6958. // s4PLCData["d5BulletclipScanCode"] = datas[528]; // 扫码信号 弹夹扫码
  6959. // int[] d5BulletclipCodeData = datas.Skip(529).Take(20).ToArray();
  6960. // s4PLCData["d5BulletclipCode"] = ModbusClient.ConvertRegistersToString(d5BulletclipCodeData, 0, 40);
  6961. // s4PLCData["d5VehicleScanCode"] = datas[559]; // 扫码信号 载具扫码
  6962. // int[] d5VehicleCodeData = datas.Skip(560).Take(20).ToArray();
  6963. // s4PLCData["d5VehicleCode"] = ModbusClient.ConvertRegistersToString(d5VehicleCodeData, 0, 40);
  6964. // s4PLCData["d5PLC_FLAG"] = datas[590]; // PLC_FLAG 出站接口
  6965. // s4PLCData["d5MES_FLAG"] = datas[591];
  6966. // int[] d5ProductSNData = datas.Skip(592).Take(20).ToArray();
  6967. // s4PLCData["d5ProductSN"] = ModbusClient.ConvertRegistersToString(d5ProductSNData, 0, 40); // 产品SN(物料码)
  6968. // int[] d5VehicleCode1Data = datas.Skip(612).Take(20).ToArray();
  6969. // s4PLCData["d5VehicleCode1"] = ModbusClient.ConvertRegistersToString(d5VehicleCode1Data, 0, 40);
  6970. // int[] d5VehicleCode2Data = datas.Skip(632).Take(20).ToArray();
  6971. // s4PLCData["d5VehicleCode2"] = ModbusClient.ConvertRegistersToString(d5VehicleCode2Data, 0, 40);
  6972. // int[] d5VehicleCode3Data = datas.Skip(652).Take(20).ToArray();
  6973. // s4PLCData["d5VehicleCode3"] = ModbusClient.ConvertRegistersToString(d5VehicleCode3Data, 0, 40);
  6974. // int[] d5VehicleCode4Data = datas.Skip(672).Take(20).ToArray();
  6975. // s4PLCData["d5VehicleCode4"] = ModbusClient.ConvertRegistersToString(d5VehicleCode4Data, 0, 40);
  6976. // int[] d5VehicleCode5Data = datas.Skip(692).Take(20).ToArray();
  6977. // s4PLCData["d5VehicleCode5"] = ModbusClient.ConvertRegistersToString(d5VehicleCode5Data, 0, 40);
  6978. // int[] d5VehicleCode6Data = datas.Skip(712).Take(20).ToArray();
  6979. // s4PLCData["d5VehicleCode6"] = ModbusClient.ConvertRegistersToString(d5VehicleCode6Data, 0, 40);
  6980. // int[] d5VehicleCode7Data = datas.Skip(732).Take(20).ToArray();
  6981. // s4PLCData["d5VehicleCode7"] = ModbusClient.ConvertRegistersToString(d5VehicleCode7Data, 0, 40);
  6982. // int[] d5VehicleCode8Data = datas.Skip(752).Take(20).ToArray();
  6983. // s4PLCData["d5VehicleCode8"] = ModbusClient.ConvertRegistersToString(d5VehicleCode8Data, 0, 40);
  6984. // int[] d5VehicleCode9Data = datas.Skip(772).Take(20).ToArray();
  6985. // s4PLCData["d5VehicleCode9"] = ModbusClient.ConvertRegistersToString(d5VehicleCode9Data, 0, 40);
  6986. // int[] d5VehicleCode10Data = datas.Skip(792).Take(20).ToArray();
  6987. // s4PLCData["d5VehicleCode10"] = ModbusClient.ConvertRegistersToString(d5VehicleCode10Data, 0, 40);
  6988. // int[] d5VehicleCode11Data = datas.Skip(812).Take(20).ToArray();
  6989. // s4PLCData["d5VehicleCode11"] = ModbusClient.ConvertRegistersToString(d5VehicleCode11Data, 0, 40);
  6990. // int[] d5VehicleCode12Data = datas.Skip(832).Take(20).ToArray();
  6991. // s4PLCData["d5VehicleCode12"] = ModbusClient.ConvertRegistersToString(d5VehicleCode12Data, 0, 40);
  6992. // int[] d5VehicleCode13Data = datas.Skip(852).Take(20).ToArray();
  6993. // s4PLCData["d5VehicleCode13"] = ModbusClient.ConvertRegistersToString(d5VehicleCode13Data, 0, 40);
  6994. // int[] d5VehicleCode14Data = datas.Skip(872).Take(20).ToArray();
  6995. // s4PLCData["d5VehicleCode14"] = ModbusClient.ConvertRegistersToString(d5VehicleCode14Data, 0, 40);
  6996. // int[] d5VehicleCode15Data = datas.Skip(892).Take(20).ToArray();
  6997. // s4PLCData["d5VehicleCode15"] = ModbusClient.ConvertRegistersToString(d5VehicleCode15Data, 0, 40);
  6998. // s4PLCData["d5Result"] = datas[912];
  6999. // s4PLCData["d5OEEPLC_FLAG"] = datas[923]; // PLC_FLAG 节拍接口
  7000. // s4PLCData["d5OEEMES_FLAG"] = datas[924];
  7001. // int[] d5OEEProductSNData = datas.Skip(925).Take(20).ToArray();
  7002. // s4PLCData["d5OEEProductSN"] = ModbusClient.ConvertRegistersToString(d5OEEProductSNData, 0, 40);
  7003. // s4PLCData["d5OEEType"] = datas[945];
  7004. // #endregion 一次性读取所有数据
  7005. // stopwatch2.Stop();
  7006. // #region 回写操作,写后清空flag
  7007. // PLCWriteData(Funs[plcNo], ref s4PLCData, ref s4PLCWriteData);
  7008. // #endregion 回写操作,写后清空flag
  7009. // // N801A-S4_1 弹夹扫码
  7010. // #region N801A-S4_1 弹夹扫码
  7011. // try
  7012. // {
  7013. // int d1BulletclipScanCode = (int)s4PLCData["d1BulletclipScanCode"];
  7014. // int d1BulletclipScanCodeOld = (int)s4PLCSignal_Old["d1BulletclipScanCode"];
  7015. // if (d1BulletclipScanCode != d1BulletclipScanCodeOld)
  7016. // {
  7017. // if (d1BulletclipScanCode == 1) // 0->1
  7018. // Task.Run(() => S4_1弹夹扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  7019. // s4PLCSignal_Old["d1BulletclipScanCode"] = s4PLCData["d1BulletclipScanCode"];
  7020. // }
  7021. // }
  7022. // catch (Exception ex)
  7023. // {
  7024. // Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  7025. // string str = ex.StackTrace;
  7026. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7027. // }
  7028. // #endregion N801A-S4_1 弹夹扫码
  7029. // // N801A-S4_1 载具扫码
  7030. // #region N801A-S4_1 载具扫码
  7031. // try
  7032. // {
  7033. // int d1VehicleScanCode = (int)s4PLCData["d1VehicleScanCode"];
  7034. // int d1VehicleScanCodeOld = (int)s4PLCSignal_Old["d1VehicleScanCode"];
  7035. // if (d1VehicleScanCode != d1VehicleScanCodeOld)
  7036. // {
  7037. // if (d1VehicleScanCode == 1) // 0->1
  7038. // Task.Run(() => S4_1载具扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  7039. // s4PLCSignal_Old["d1VehicleScanCode"] = s4PLCData["d1VehicleScanCode"];
  7040. // }
  7041. // }
  7042. // catch (Exception ex)
  7043. // {
  7044. // Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  7045. // string str = ex.StackTrace;
  7046. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7047. // }
  7048. // #endregion N801A-S4_1 载具扫码
  7049. // // N801A-S4_1 出站接口
  7050. // #region N801A-S4_1 出站接口
  7051. // try
  7052. // {
  7053. // int d1PLC_FLAG = (int)s4PLCData["d1PLC_FLAG"];
  7054. // int d1MES_FLAG = (int)s4PLCData["d1MES_FLAG"];
  7055. // int d1PLC_FLAGOld = (int)s4PLCSignal_Old["d1PLC_FLAG"];
  7056. // if (d1PLC_FLAG != d1PLC_FLAGOld)
  7057. // {
  7058. // if (d1PLC_FLAG == 1 && d1MES_FLAG == 0) // 0->1
  7059. // Task.Run(() => S4_1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  7060. // else if (d1PLC_FLAG == 0 && d1MES_FLAG != 0)
  7061. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)0);
  7062. // s4PLCSignal_Old["d1PLC_FLAG"] = s4PLCData["d1PLC_FLAG"];
  7063. // }
  7064. // }
  7065. // catch (Exception ex)
  7066. // {
  7067. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)6); // 6代表上位机报警
  7068. // string str = ex.StackTrace;
  7069. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7070. // }
  7071. // #endregion N801A-S4_1 出站接口
  7072. // // N801A-S4_1 节拍接口
  7073. // #region N801A-S4_1 节拍接口
  7074. // try
  7075. // {
  7076. // int d1OEEPLC_FLAG = (int)s4PLCData["d1OEEPLC_FLAG"];
  7077. // int d1OEEMES_FLAG = (int)s4PLCData["d1OEEMES_FLAG"];
  7078. // int d1OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d1OEEPLC_FLAG"];
  7079. // if (d1OEEPLC_FLAG != d1OEEPLC_FLAGOld)
  7080. // {
  7081. // if (d1OEEPLC_FLAG == 1 && d1OEEMES_FLAG == 0) // 0->1
  7082. // Task.Run(() => S4_1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  7083. // else if (d1OEEPLC_FLAG == 0 && d1OEEMES_FLAG != 0)
  7084. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)0);
  7085. // s4PLCSignal_Old["d1OEEPLC_FLAG"] = s4PLCData["d1OEEPLC_FLAG"];
  7086. // }
  7087. // }
  7088. // catch (Exception ex)
  7089. // {
  7090. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  7091. // string str = ex.StackTrace;
  7092. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7093. // }
  7094. // #endregion N801A-S4_1 节拍接口
  7095. // // N801A-S4_2 桁架(查询标机中弹夹的状态) 数据
  7096. // #region N801A-S4_2 桁架(查询标机中弹夹的状态)
  7097. // try
  7098. // {
  7099. // int d2BulletclipScanCode = (int)s4PLCData["d2BulletclipScanCode"];
  7100. // int d2BulletclipScanCodeOld = (int)s4PLCSignal_Old["d2BulletclipScanCode"];
  7101. // if (d2BulletclipScanCode != d2BulletclipScanCodeOld)
  7102. // {
  7103. // if (d2BulletclipScanCode == 1) // 0->1
  7104. // Task.Run(() => S4_2桁架(plcNo, stationNameStr2)); // MreTasks[1].Set();
  7105. // s4PLCSignal_Old["d2BulletclipScanCode"] = s4PLCData["d2BulletclipScanCode"];
  7106. // }
  7107. // }
  7108. // catch (Exception ex)
  7109. // {
  7110. // Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  7111. // string str = ex.StackTrace;
  7112. // AddMessage_Station(stationNameStr2, LogType.Error, $"PLC{plcNo}_{stationNameStr2} 桁架出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7113. // }
  7114. // #endregion N801A-S4_2 桁架(查询标机中弹夹的状态)
  7115. // // N801A-S4_3 真空标机1 数据
  7116. // #region N801A-S4_3 真空标机1
  7117. // try
  7118. // {
  7119. // int d3PLC_FLAG = (int)s4PLCData["d3PLC_FLAG"];
  7120. // int d3MES_FLAG = (int)s4PLCData["d3MES_FLAG"];
  7121. // int d3PLC_FLAGOld = (int)s4PLCSignal_Old["d3PLC_FLAG"];
  7122. // if (d3PLC_FLAG != d3PLC_FLAGOld)
  7123. // {
  7124. // if (d3PLC_FLAG == 1 && d3MES_FLAG == 0) // 0->1
  7125. // {
  7126. // int stationType = (int)s4PLCData["d3Type"];
  7127. // if (stationType == 1)
  7128. // {
  7129. // // S4_3进站接口
  7130. // Task.Run(() => S4_3进站接口(plcNo, stationNameStr3)); // MreTasks[3].Set();
  7131. // }
  7132. // else if (stationType == 2)
  7133. // {
  7134. // // S4_3出站接口
  7135. // Task.Run(() => S4_3出站接口(plcNo, stationCode3, stationName3)); // MreTasks[3].Set();
  7136. // }
  7137. // }
  7138. // else if (d3PLC_FLAG == 0 && d3MES_FLAG != 0)
  7139. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)0);
  7140. // s4PLCSignal_Old["d3PLC_FLAG"] = s4PLCData["d3PLC_FLAG"];
  7141. // }
  7142. // }
  7143. // catch (Exception ex)
  7144. // {
  7145. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  7146. // string str = ex.StackTrace;
  7147. // AddMessage_Station(stationNameStr3, LogType.Error, $"PLC{plcNo}_{stationNameStr3} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7148. // }
  7149. // #endregion N801A-S4_3 真空标机1
  7150. // // N801A-S4_4 真空标机2 数据
  7151. // #region N801A-S4_4 真空标机2
  7152. // try
  7153. // {
  7154. // int d4PLC_FLAG = (int)s4PLCData["d4PLC_FLAG"];
  7155. // int d4MES_FLAG = (int)s4PLCData["d4MES_FLAG"];
  7156. // int d4PLC_FLAGOld = (int)s4PLCSignal_Old["d4PLC_FLAG"];
  7157. // if (d4PLC_FLAG != d4PLC_FLAGOld)
  7158. // {
  7159. // if (d4PLC_FLAG == 1 && d4MES_FLAG == 0) // 0->1
  7160. // {
  7161. // int stationType = (int)s4PLCData["d4Type"];
  7162. // if (stationType == 1)
  7163. // {
  7164. // // S4_4进站接口
  7165. // Task.Run(() => S4_4进站接口(plcNo, stationNameStr4)); // MreTasks[3].Set();
  7166. // }
  7167. // else if (stationType == 2)
  7168. // {
  7169. // // S4_4出站接口
  7170. // Task.Run(() => S4_4出站接口(plcNo, stationCode4, stationName4)); // MreTasks[3].Set();
  7171. // }
  7172. // }
  7173. // else if (d4PLC_FLAG == 0 && d4MES_FLAG != 0)
  7174. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)0);
  7175. // s4PLCSignal_Old["d4PLC_FLAG"] = s4PLCData["d4PLC_FLAG"];
  7176. // }
  7177. // }
  7178. // catch (Exception ex)
  7179. // {
  7180. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  7181. // string str = ex.StackTrace;
  7182. // AddMessage_Station(stationNameStr4, LogType.Error, $"PLC{plcNo}_{stationNameStr4} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7183. // }
  7184. // #endregion N801A-S4_4 真空标机2
  7185. // // N801A-S4_5 弹夹扫码 数据
  7186. // #region N801A-S4_5 弹夹扫码
  7187. // try
  7188. // {
  7189. // int d5BulletclipScanCode = (int)s4PLCData["d5BulletclipScanCode"];
  7190. // int d5BulletclipScanCodeOld = (int)s4PLCSignal_Old["d5BulletclipScanCode"];
  7191. // if (d5BulletclipScanCode != d5BulletclipScanCodeOld)
  7192. // {
  7193. // if (d5BulletclipScanCode == 1) // 0->1
  7194. // Task.Run(() => S4_5弹夹扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  7195. // s4PLCSignal_Old["d5BulletclipScanCode"] = s4PLCData["d5BulletclipScanCode"];
  7196. // }
  7197. // }
  7198. // catch (Exception ex)
  7199. // {
  7200. // Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  7201. // string str = ex.StackTrace;
  7202. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7203. // }
  7204. // #endregion N801A-S4_5 弹夹扫码
  7205. // // N801A-S4_5 载具扫码 数据
  7206. // #region N801A-S4_5 载具扫码
  7207. // try
  7208. // {
  7209. // int d5VehicleScanCode = (int)s4PLCData["d5VehicleScanCode"];
  7210. // int d5VehicleScanCodeOld = (int)s4PLCSignal_Old["d5VehicleScanCode"];
  7211. // if (d5VehicleScanCode != d5VehicleScanCodeOld)
  7212. // {
  7213. // if (d5VehicleScanCode == 1) // 0->1
  7214. // Task.Run(() => S4_5载具扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  7215. // s4PLCSignal_Old["d5VehicleScanCode"] = s4PLCData["d5VehicleScanCode"];
  7216. // }
  7217. // }
  7218. // catch (Exception ex)
  7219. // {
  7220. // Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  7221. // string str = ex.StackTrace;
  7222. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7223. // }
  7224. // #endregion N801A-S4_5 载具扫码
  7225. // // N801A-S4_5 出站接口(扫完所有码后立即上传) 数据
  7226. // #region N801A-S4_5 出站接口
  7227. // try
  7228. // {
  7229. // int d5PLC_FLAG = (int)s4PLCData["d5PLC_FLAG"];
  7230. // int d5MES_FLAG = (int)s4PLCData["d5MES_FLAG"];
  7231. // int d5PLC_FLAGOld = (int)s4PLCSignal_Old["d5PLC_FLAG"];
  7232. // if (d5PLC_FLAG != d5PLC_FLAGOld)
  7233. // {
  7234. // if (d5PLC_FLAG == 1 && d5MES_FLAG == 0) // 0->1
  7235. // Task.Run(() => S4_5出站接口(plcNo, stationCode5, stationName5)); // MreTasks[3].Set();
  7236. // else if (d5PLC_FLAG == 0 && d5MES_FLAG != 0)
  7237. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)0);
  7238. // s4PLCSignal_Old["d5PLC_FLAG"] = s4PLCData["d5PLC_FLAG"];
  7239. // }
  7240. // }
  7241. // catch (Exception ex)
  7242. // {
  7243. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)6); // 6代表上位机报警
  7244. // string str = ex.StackTrace;
  7245. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7246. // }
  7247. // #endregion N801A-S4_5 出站接口
  7248. // // N801A-S4_5 节拍接口 数据
  7249. // #region N801A-S4_5 节拍接口
  7250. // try
  7251. // {
  7252. // int d5OEEPLC_FLAG = (int)s4PLCData["d5OEEPLC_FLAG"];
  7253. // int d5OEEMES_FLAG = (int)s4PLCData["d5OEEMES_FLAG"];
  7254. // int d5OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d5OEEPLC_FLAG"];
  7255. // if (d5OEEPLC_FLAG != d5OEEPLC_FLAGOld)
  7256. // {
  7257. // if (d5OEEPLC_FLAG == 1 && d5OEEMES_FLAG == 0) // 0->1
  7258. // Task.Run(() => S4_5节拍接口(plcNo, stationNameStr5)); // MreTasks[4].Set();
  7259. // else if (d5OEEPLC_FLAG == 0 && d5OEEMES_FLAG != 0)
  7260. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)0);
  7261. // s4PLCSignal_Old["d5OEEPLC_FLAG"] = s4PLCData["d5OEEPLC_FLAG"];
  7262. // }
  7263. // }
  7264. // catch (Exception ex)
  7265. // {
  7266. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  7267. // string str = ex.StackTrace;
  7268. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7269. // }
  7270. // #endregion N801A-S4_5 节拍接口
  7271. // #region 心跳
  7272. // try
  7273. // {
  7274. // short states = 0;
  7275. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  7276. // }
  7277. // catch (Exception ex)
  7278. // {
  7279. // string str = ex.StackTrace;
  7280. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7281. // }
  7282. // #endregion 心跳
  7283. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  7284. // stopwatch1.Stop();
  7285. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  7286. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  7287. // }
  7288. // else
  7289. // {
  7290. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7291. // AddMessage_Station(stationNameStr5, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr5 + "连接失败!");
  7292. // Funs[plcNo].Connect();
  7293. // }
  7294. // }
  7295. // catch (Exception ex)
  7296. // {
  7297. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7298. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5}运行出错!错误信息:" + ex.Message.ToString());
  7299. // Funs[plcNo].ReConnect();
  7300. // }
  7301. // Thread.Sleep(IntervalReadPLC);
  7302. // }
  7303. //}
  7304. /// <summary>
  7305. /// [S4] 取放桁架 - S4_1弹夹扫码
  7306. /// </summary>
  7307. /// <param name="plcNo">PLC编号</param>
  7308. /// <param name="stationNameStr">工站全称</param>
  7309. private void S4_1弹夹扫码(int plcNo, string stationNameStr)
  7310. {
  7311. Stopwatch stopwatch1 = new Stopwatch();
  7312. Stopwatch stopwatch2 = new Stopwatch();
  7313. try
  7314. {
  7315. stopwatch1.Start();
  7316. // ZS 弹夹扫码
  7317. string d1BulletclipCode = " "; // 扫到的码
  7318. short d1BulletclipScanCode = 2;
  7319. stopwatch2.Start();
  7320. //Funs[plcNo].WriteMultipleRegisters<string>(2003, d1BulletclipCode, 20);
  7321. //// MES_Flag
  7322. //Funs[plcNo].WriteMultipleRegisters<short>(2002, d1BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7323. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7324. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  7325. writeToPLC_Flag.Adress = 2002;
  7326. writeToPLC_Flag.Value = d1BulletclipScanCode;
  7327. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7328. {
  7329. Name = "d1BulletclipCode",
  7330. Adress = 2003,
  7331. ValueType = PLCValueType.String,
  7332. ValueTypeStrLength = 20,
  7333. Value = d1BulletclipCode
  7334. });
  7335. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  7336. stopwatch2.Stop();
  7337. }
  7338. catch (Exception ex)
  7339. {
  7340. string str = ex.StackTrace;
  7341. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7342. stopwatch2.Start();
  7343. //Funs[plcNo].WriteMultipleRegisters<string>(2003, " ", 20);
  7344. //// MES_Flag
  7345. //Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  7346. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7347. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  7348. writeToPLC_Flag.Adress = 2002;
  7349. writeToPLC_Flag.Value = (short)6;
  7350. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7351. {
  7352. Name = "d1BulletclipCode",
  7353. Adress = 2003,
  7354. ValueType = PLCValueType.String,
  7355. ValueTypeStrLength = 20,
  7356. Value = " "
  7357. });
  7358. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  7359. stopwatch2.Stop();
  7360. }
  7361. stopwatch1.Stop();
  7362. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7363. }
  7364. /// <summary>
  7365. /// [S4] 取放桁架 - S4_1载具扫码
  7366. /// </summary>
  7367. /// <param name="plcNo">PLC编号</param>
  7368. /// <param name="stationNameStr">工站全称</param>
  7369. private void S4_1载具扫码(int plcNo, string stationNameStr)
  7370. {
  7371. Stopwatch stopwatch1 = new Stopwatch();
  7372. Stopwatch stopwatch2 = new Stopwatch();
  7373. try
  7374. {
  7375. stopwatch1.Start();
  7376. // ZS 载具扫码
  7377. string d1VehicleCode = ""; // 扫到的码
  7378. short d1VehicleScanCode = 2;
  7379. #region 进站
  7380. if (d1VehicleScanCode == 2 && !string.IsNullOrEmpty(d1VehicleCode))
  7381. {
  7382. #region 查询载具上的产品信息
  7383. string cavityData = string.Empty;
  7384. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d1VehicleCode, ref cavityData);
  7385. if (string.IsNullOrEmpty(cavityData))
  7386. cavityData = "";
  7387. if (snResult != 0)
  7388. {
  7389. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7390. writeToPLC_Flag1.Name = "d1VehicleScanCode";
  7391. writeToPLC_Flag1.Adress = 2033;
  7392. writeToPLC_Flag1.Value = (short)6; // 6代表上位机报警
  7393. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7394. {
  7395. Name = "d1VehicleCode",
  7396. Adress = 2034,
  7397. ValueType = PLCValueType.String,
  7398. ValueTypeStrLength = 20,
  7399. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  7400. });
  7401. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag1);
  7402. stopwatch1.Stop();
  7403. AddMessage(LogType.Info, stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7404. return;
  7405. }
  7406. string[] cavitySNs = cavityData.Split('.');
  7407. string partNo = "";
  7408. if (cavitySNs != null && cavitySNs.Length >= 1)
  7409. {
  7410. partNo = cavitySNs[0];
  7411. }
  7412. #endregion 查询载具上的产品信息
  7413. List<TestItem> item = new List<TestItem>();
  7414. item.Add(new TestItem()
  7415. {
  7416. Parameter_name = "载具码",
  7417. Parameter_value = d1VehicleCode,
  7418. });
  7419. item.Add(new TestItem()
  7420. {
  7421. Parameter_name = "载具穴号",
  7422. Parameter_value = "1",
  7423. });
  7424. stopwatch2.Start();
  7425. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  7426. stopwatch2.Stop();
  7427. d1VehicleScanCode = (short)result == 1 ? d1VehicleScanCode : (short)result;
  7428. }
  7429. #endregion 进站
  7430. //Funs[plcNo].WriteMultipleRegisters<string>(2034, d1VehicleCode, 20);
  7431. //// MES_Flag
  7432. //Funs[plcNo].WriteMultipleRegisters<short>(2033, d1VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7433. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7434. writeToPLC_Flag.Name = "d1VehicleScanCode";
  7435. writeToPLC_Flag.Adress = 2033;
  7436. writeToPLC_Flag.Value = d1VehicleScanCode;
  7437. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7438. {
  7439. Name = "d1VehicleCode",
  7440. Adress = 2034,
  7441. ValueType = PLCValueType.String,
  7442. ValueTypeStrLength = 20,
  7443. Value = d1VehicleCode
  7444. });
  7445. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  7446. }
  7447. catch (Exception ex)
  7448. {
  7449. string str = ex.StackTrace;
  7450. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7451. stopwatch2.Start();
  7452. //Funs[plcNo].WriteMultipleRegisters<string>(2034, " ", 20);
  7453. //// MES_Flag
  7454. //Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  7455. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7456. writeToPLC_Flag.Name = "d1VehicleScanCode";
  7457. writeToPLC_Flag.Adress = 2033;
  7458. writeToPLC_Flag.Value = (short)6; // 6代表上位机报警
  7459. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7460. {
  7461. Name = "d1VehicleCode",
  7462. Adress = 2034,
  7463. ValueType = PLCValueType.String,
  7464. ValueTypeStrLength = 20,
  7465. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  7466. });
  7467. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  7468. stopwatch2.Stop();
  7469. }
  7470. stopwatch1.Stop();
  7471. AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7472. }
  7473. // 上次采集到的SN
  7474. //private string sn_S4_1出站接口 = string.Empty;
  7475. /// <summary>
  7476. /// [S4] 取放桁架 - S4_1出站接口
  7477. /// </summary>
  7478. private void S4_1出站接口(int plcNo, string stationCode, string stationName)
  7479. {
  7480. Stopwatch stopwatch1 = new Stopwatch();
  7481. Stopwatch stopwatch2 = new Stopwatch();
  7482. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7483. string stationNameStr = stationCode + stationName;
  7484. string processItem = stationName; // 测试项目
  7485. try
  7486. {
  7487. stopwatch1.Start();
  7488. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7489. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7490. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7491. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7492. string sn = (string)s4PLCData["d1ProductSN"]; // 产品SN(弹夹码)
  7493. sn = sn.Replace("\0", "");
  7494. string d1VehicleCode1 = (string)s4PLCData["d1VehicleCode1"]; // 载具1码(弹夹穴位1)
  7495. d1VehicleCode1 = d1VehicleCode1.Replace("\0", "");
  7496. string d1VehicleCode2 = (string)s4PLCData["d1VehicleCode2"]; // 载具2码(弹夹穴位2)
  7497. d1VehicleCode2 = d1VehicleCode2.Replace("\0", "");
  7498. string d1VehicleCode3 = (string)s4PLCData["d1VehicleCode3"]; // 载具3码(弹夹穴位3)
  7499. d1VehicleCode3 = d1VehicleCode3.Replace("\0", "");
  7500. string d1VehicleCode4 = (string)s4PLCData["d1VehicleCode4"]; // 载具4码(弹夹穴位4)
  7501. d1VehicleCode4 = d1VehicleCode4.Replace("\0", "");
  7502. string d1VehicleCode5 = (string)s4PLCData["d1VehicleCode5"]; // 载具5码(弹夹穴位5)
  7503. d1VehicleCode5 = d1VehicleCode5.Replace("\0", "");
  7504. string d1VehicleCode6 = (string)s4PLCData["d1VehicleCode6"]; // 载具6码(弹夹穴位6)
  7505. d1VehicleCode6 = d1VehicleCode6.Replace("\0", "");
  7506. string d1VehicleCode7 = (string)s4PLCData["d1VehicleCode7"]; // 载具7码(弹夹穴位7)
  7507. d1VehicleCode7 = d1VehicleCode7.Replace("\0", "");
  7508. string d1VehicleCode8 = (string)s4PLCData["d1VehicleCode8"]; // 载具8码(弹夹穴位8)
  7509. d1VehicleCode8 = d1VehicleCode8.Replace("\0", "");
  7510. string d1VehicleCode9 = (string)s4PLCData["d1VehicleCode9"]; // 载具9码(弹夹穴位9)
  7511. d1VehicleCode9 = d1VehicleCode9.Replace("\0", "");
  7512. string d1VehicleCode10 = (string)s4PLCData["d1VehicleCode10"]; // 载具10码(弹夹穴位10)
  7513. d1VehicleCode10 = d1VehicleCode10.Replace("\0", "");
  7514. string d1VehicleCode11 = (string)s4PLCData["d1VehicleCode11"]; // 载具11码(弹夹穴位11)
  7515. d1VehicleCode11 = d1VehicleCode11.Replace("\0", "");
  7516. string d1VehicleCode12 = (string)s4PLCData["d1VehicleCode12"]; // 载具12码(弹夹穴位12)
  7517. d1VehicleCode12 = d1VehicleCode12.Replace("\0", "");
  7518. string d1VehicleCode13 = (string)s4PLCData["d1VehicleCode13"]; // 载具13码(弹夹穴位13)
  7519. d1VehicleCode13 = d1VehicleCode13.Replace("\0", "");
  7520. string d1VehicleCode14 = (string)s4PLCData["d1VehicleCode14"]; // 载具14码(弹夹穴位14)
  7521. d1VehicleCode14 = d1VehicleCode14.Replace("\0", "");
  7522. string d1VehicleCode15 = (string)s4PLCData["d1VehicleCode15"]; // 载具15码(弹夹穴位15)
  7523. d1VehicleCode15 = d1VehicleCode15.Replace("\0", "");
  7524. int d1Result = (int)s4PLCData["d1Result"]; // 产品结果
  7525. bool pass = d1Result == 1;
  7526. // 存 载具SN列表
  7527. List<string> vehicleCodes = new List<string>()
  7528. {
  7529. d1VehicleCode1,d1VehicleCode2,d1VehicleCode3,d1VehicleCode4,d1VehicleCode5,
  7530. d1VehicleCode6,d1VehicleCode7,d1VehicleCode8,d1VehicleCode9,d1VehicleCode10,
  7531. d1VehicleCode11,d1VehicleCode12,d1VehicleCode13,d1VehicleCode14,d1VehicleCode15
  7532. };
  7533. // 统一查 产品SN列表
  7534. List<string> partNos = new List<string>();
  7535. foreach (string vehicleCode in vehicleCodes)
  7536. {
  7537. if (string.IsNullOrEmpty(vehicleCode))
  7538. partNos.Add("");
  7539. else
  7540. {
  7541. string partNo = "";
  7542. #region 查询载具上的产品信息
  7543. string cavityData = string.Empty;
  7544. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7545. if (string.IsNullOrEmpty(cavityData))
  7546. cavityData = "";
  7547. if (snResult != 0)
  7548. {
  7549. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7550. writeToPLC_Flag1.Name = "d1MES_FLAG";
  7551. writeToPLC_Flag1.Adress = 2065;
  7552. writeToPLC_Flag1.Value = (short)4;
  7553. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag1);
  7554. stopwatch1.Stop();
  7555. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7556. return;
  7557. }
  7558. string[] cavitySNs = cavityData.Split('.');
  7559. if (cavitySNs != null && cavitySNs.Length >= 1)
  7560. partNo = cavitySNs[0];
  7561. #endregion 查询载具上的产品信息
  7562. partNos.Add(partNo);
  7563. }
  7564. }
  7565. // 统一上传
  7566. stopwatch2.Start();
  7567. List<int> results = new List<int>();
  7568. for (int i = 0; i < partNos.Count; i++)
  7569. {
  7570. string index = (i + 1).ToString(); // 弹夹穴号
  7571. if (string.IsNullOrEmpty(partNos[i]))
  7572. results.Add(1);
  7573. else
  7574. {
  7575. List<TestItem> items1 = new List<TestItem>();
  7576. items1.Add(new TestItem()
  7577. {
  7578. Parameter_name = "弹夹码",
  7579. Parameter_value = sn,
  7580. Parameter_unit = ""
  7581. });
  7582. items1.Add(new TestItem()
  7583. {
  7584. Parameter_name = "弹夹穴号",
  7585. Parameter_value = index,
  7586. Parameter_unit = ""
  7587. });
  7588. items1.Add(new TestItem()
  7589. {
  7590. Parameter_name = "载具码",
  7591. Parameter_value = vehicleCodes[i],
  7592. Parameter_unit = ""
  7593. });
  7594. items1.Add(new TestItem()
  7595. {
  7596. Parameter_name = "载具穴号",
  7597. Parameter_value = "1",
  7598. Parameter_unit = ""
  7599. });
  7600. items1.Add(new TestItem()
  7601. {
  7602. Parameter_name = "产品结果",
  7603. Parameter_value = d1Result == 1 ? "OK" : "NG",
  7604. Parameter_unit = ""
  7605. });
  7606. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  7607. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  7608. results.Add(result1);
  7609. }
  7610. }
  7611. short result = 0;
  7612. if (results.All(a => a == 1))
  7613. result = 1;
  7614. else if (results.Contains(3))
  7615. result = 3;
  7616. else if (results.Contains(2))
  7617. result = 2;
  7618. else if (results.Contains(4))
  7619. result = 4;
  7620. else
  7621. result = 4;
  7622. stopwatch2.Stop();
  7623. #region 存储绑定数据到 边线MES系统中
  7624. if (result == 1)
  7625. {
  7626. string data = string.Join(".", vehicleCodes);
  7627. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  7628. if (resultMesR != 0)
  7629. {
  7630. result = 4;
  7631. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  7632. }
  7633. }
  7634. #endregion 存储绑定数据到 边线MES系统中
  7635. // MES_Flag 为4MES报错
  7636. //Funs[plcNo].WriteMultipleRegisters<short>(2065, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7637. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7638. writeToPLC_Flag.Name = "d1MES_FLAG";
  7639. writeToPLC_Flag.Adress = 2065;
  7640. writeToPLC_Flag.Value = result;
  7641. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  7642. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  7643. }
  7644. catch (Exception ex)
  7645. {
  7646. stopwatch2.Restart();
  7647. // MES_Flag 为4上位机报错
  7648. //Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)4); // 4代表上位机报警
  7649. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7650. writeToPLC_Flag.Name = "d1MES_FLAG";
  7651. writeToPLC_Flag.Adress = 2065;
  7652. writeToPLC_Flag.Value = (short)4;
  7653. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  7654. stopwatch2.Stop();
  7655. string str = ex.StackTrace;
  7656. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7657. }
  7658. stopwatch1.Stop();
  7659. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7660. }
  7661. /// <summary>
  7662. /// [S4] 取放桁架 - S4_1节拍接口
  7663. /// </summary>
  7664. /// <param name="plcNo">PLC编号</param>
  7665. /// <param name="stationNameStr">工站全称</param>
  7666. private void S4_1节拍接口(int plcNo, string stationNameStr)
  7667. {
  7668. Stopwatch stopwatch1 = new Stopwatch();
  7669. Stopwatch stopwatch2 = new Stopwatch();
  7670. string resultStr = string.Empty;
  7671. try
  7672. {
  7673. stopwatch1.Start();
  7674. string oEEType = ((int)s4PLCData["d1OEEType"]).ToString(); // 节拍类型(plc写入)
  7675. string d1OEEProductSN = (string)s4PLCData["d1OEEProductSN"]; // 载具SN
  7676. d1OEEProductSN = d1OEEProductSN.Replace("\0", "");
  7677. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  7678. if (!actionBool)
  7679. {
  7680. stopwatch2.Start();
  7681. // MES_Flag
  7682. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7683. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7684. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  7685. writeToPLC_Flag1.Adress = 2398;
  7686. writeToPLC_Flag1.Value = (short)4;
  7687. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  7688. stopwatch2.Stop();
  7689. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7690. return;
  7691. }
  7692. string d1OEEPartNo = string.Empty; // 物料码
  7693. if (string.IsNullOrEmpty(d1OEEProductSN))
  7694. {
  7695. stopwatch2.Start();
  7696. // MES_Flag
  7697. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7698. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7699. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  7700. writeToPLC_Flag1.Adress = 2398;
  7701. writeToPLC_Flag1.Value = (short)1;
  7702. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  7703. stopwatch2.Stop();
  7704. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7705. return;
  7706. }
  7707. else
  7708. { // 查产品SN ZS
  7709. d1OEEPartNo = "Test";
  7710. }
  7711. short d1OEEMES_FLAG = 0;
  7712. // 上传OEE
  7713. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d1OEEPartNo, d1OEEProductSN);
  7714. d1OEEMES_FLAG = result.Item1;
  7715. resultStr = result.Item2;
  7716. stopwatch2.Start();
  7717. // MES_Flag
  7718. //Funs[plcNo].WriteMultipleRegisters<short>(2398, d1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7719. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7720. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  7721. writeToPLC_Flag.Adress = 2398;
  7722. writeToPLC_Flag.Value = d1OEEMES_FLAG;
  7723. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  7724. stopwatch2.Stop();
  7725. }
  7726. catch (Exception ex)
  7727. {
  7728. string str = ex.StackTrace;
  7729. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7730. // MES_Flag
  7731. stopwatch2.Start();
  7732. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  7733. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7734. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  7735. writeToPLC_Flag.Adress = 2398;
  7736. writeToPLC_Flag.Value = (short)4;
  7737. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  7738. stopwatch2.Stop();
  7739. }
  7740. stopwatch1.Stop();
  7741. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7742. }
  7743. /// <summary>
  7744. /// [S4] 取放桁架 - S4_2桁架
  7745. /// </summary>
  7746. /// <param name="plcNo">PLC编号</param>
  7747. /// <param name="stationNameStr">工站全称</param>
  7748. private void S4_2桁架(int plcNo, string stationNameStr)
  7749. {
  7750. Stopwatch stopwatch1 = new Stopwatch();
  7751. Stopwatch stopwatch2 = new Stopwatch();
  7752. try
  7753. {
  7754. stopwatch1.Start();
  7755. // ZS 弹夹扫码
  7756. string d2BulletclipCode = " "; // 扫到的码
  7757. short d2BulletclipStates = 1; // 弹夹状态(上位机写入)
  7758. short d2BulletclipScanCode = 2;
  7759. stopwatch2.Start();
  7760. //Funs[plcNo].WriteMultipleRegisters<string>(2432, d2BulletclipCode, 20); // 扫到的码
  7761. //Funs[plcNo].WriteMultipleRegisters<short>(2431, d2BulletclipStates); // 弹夹状态(上位机写入)
  7762. //// MES_Flag
  7763. //Funs[plcNo].WriteMultipleRegisters<short>(2430, d2BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7764. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7765. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  7766. writeToPLC_Flag.Adress = 2430;
  7767. writeToPLC_Flag.Value = d2BulletclipScanCode;
  7768. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7769. {
  7770. Name = "d2BulletclipCode",
  7771. Adress = 2432,
  7772. ValueType = PLCValueType.String,
  7773. ValueTypeStrLength = 20,
  7774. Value = d2BulletclipCode
  7775. });
  7776. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7777. {
  7778. Name = "d2BulletclipStates",
  7779. Adress = 2431,
  7780. ValueType = PLCValueType.Short,
  7781. Value = d2BulletclipStates
  7782. });
  7783. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  7784. stopwatch2.Stop();
  7785. }
  7786. catch (Exception ex)
  7787. {
  7788. string str = ex.StackTrace;
  7789. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7790. stopwatch2.Start();
  7791. Funs[plcNo].WriteMultipleRegisters<string>(2432, " ", 20);
  7792. Funs[plcNo].WriteMultipleRegisters<short>(2431, (short)0);
  7793. // MES_Flag
  7794. Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  7795. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7796. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  7797. writeToPLC_Flag.Adress = 2430;
  7798. writeToPLC_Flag.Value = (short)6;
  7799. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7800. {
  7801. Name = "d2BulletclipCode",
  7802. Adress = 2432,
  7803. ValueType = PLCValueType.String,
  7804. ValueTypeStrLength = 20,
  7805. Value = " "
  7806. });
  7807. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7808. {
  7809. Name = "d2BulletclipStates",
  7810. Adress = 2431,
  7811. ValueType = PLCValueType.Short,
  7812. Value = (short)0
  7813. });
  7814. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  7815. stopwatch2.Stop();
  7816. }
  7817. stopwatch1.Stop();
  7818. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7819. }
  7820. // 上次采集到的SN
  7821. //private string sn_S4_3进站接口 = string.Empty;
  7822. /// <summary>
  7823. /// [S4] 取放桁架 - S4_3进站接口(提升机1)
  7824. /// </summary>
  7825. private void S4_3进站接口(int plcNo, string stationNameStr)
  7826. {
  7827. Stopwatch stopwatch1 = new Stopwatch();
  7828. Stopwatch stopwatch2 = new Stopwatch();
  7829. try
  7830. {
  7831. stopwatch1.Start();
  7832. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  7833. sn = sn.Replace("\0", "");
  7834. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  7835. #region 查询15个载具码
  7836. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7837. string vehicleData = string.Empty;
  7838. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7839. if (string.IsNullOrEmpty(vehicleData))
  7840. vehicleData = "";
  7841. if (snResult != 0)
  7842. {
  7843. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7844. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7845. writeToPLC_Flag1.Adress = 2463;
  7846. writeToPLC_Flag1.Value = (short)4;
  7847. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7848. stopwatch1.Stop();
  7849. AddMessage(LogType.Info, stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7850. return;
  7851. }
  7852. string[] cavitySNs = vehicleData.Split('.');
  7853. if (cavitySNs != null && cavitySNs.Length > 0)
  7854. {
  7855. for (int i = 0; i < cavitySNs.Length; i++)
  7856. {
  7857. if (string.IsNullOrEmpty(cavitySNs[i]))
  7858. vehicleCodes.Add("");
  7859. else
  7860. vehicleCodes.Add(cavitySNs[i]);
  7861. }
  7862. }
  7863. #endregion 查询15个载具码
  7864. #region 查询15个产品SN
  7865. List<string> portNos = new List<string>(); // 15个产品SN
  7866. foreach (string vehicleCode in vehicleCodes)
  7867. {
  7868. if (string.IsNullOrEmpty(vehicleCode))
  7869. portNos.Add("");
  7870. else
  7871. {
  7872. // 查询
  7873. string cavityData = string.Empty;
  7874. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7875. if (string.IsNullOrEmpty(cavityData))
  7876. cavityData = "";
  7877. if (snResult1 != 0)
  7878. {
  7879. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7880. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7881. writeToPLC_Flag1.Adress = 2463;
  7882. writeToPLC_Flag1.Value = (short)4;
  7883. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7884. stopwatch1.Stop();
  7885. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7886. return;
  7887. }
  7888. string[] partSNs = cavityData.Split('.');
  7889. if (partSNs != null && partSNs.Length >= 1)
  7890. portNos.Add(partSNs[0]);
  7891. else
  7892. portNos.Add("");
  7893. }
  7894. }
  7895. #endregion 查询15个产品SN
  7896. // 调用MES进站(最多15个)
  7897. stopwatch2.Start();
  7898. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  7899. for (int i = 0; i < vehicleCodes.Count; i++)
  7900. {
  7901. // 循环进站
  7902. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  7903. {
  7904. // 产品SN(物料码)校验
  7905. string portNo = portNos[i];
  7906. List<TestItem> item = new List<TestItem>();
  7907. item.Add(new TestItem()
  7908. {
  7909. Parameter_name = "弹夹码",
  7910. Parameter_value = sn,
  7911. });
  7912. item.Add(new TestItem()
  7913. {
  7914. Parameter_name = "弹夹穴位",
  7915. Parameter_value = (i + 1).ToString(),
  7916. });
  7917. item.Add(new TestItem()
  7918. {
  7919. Parameter_name = "载具码",
  7920. Parameter_value = vehicleCodes[i],
  7921. });
  7922. item.Add(new TestItem()
  7923. {
  7924. Parameter_name = "载具穴号",
  7925. Parameter_value = "1",
  7926. });
  7927. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  7928. }
  7929. }
  7930. stopwatch2.Stop();
  7931. short result = 0;
  7932. bool haveMesWarn = results.Contains(5);
  7933. bool havePCWarn = results.Contains(6);
  7934. if (haveMesWarn)
  7935. result = 2; // 5->2
  7936. else if (havePCWarn)
  7937. result = 6; // 6->4
  7938. else
  7939. result = 1;
  7940. // MES_Flag 为4MES报错
  7941. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7942. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7943. writeToPLC_Flag.Name = "d3MES_FLAG";
  7944. writeToPLC_Flag.Adress = 2463;
  7945. writeToPLC_Flag.Value = result;
  7946. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7947. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  7948. }
  7949. catch (Exception ex)
  7950. {
  7951. stopwatch2.Stop();
  7952. // MES_Flag 为4上位机报错
  7953. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  7954. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7955. writeToPLC_Flag.Name = "d3MES_FLAG";
  7956. writeToPLC_Flag.Adress = 2463;
  7957. writeToPLC_Flag.Value = (short)4;
  7958. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7959. string str = ex.StackTrace;
  7960. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7961. }
  7962. stopwatch1.Stop();
  7963. AddMessage(LogType.Info, stationNameStr + "_S4_3进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7964. }
  7965. // 上次采集到的SN
  7966. //private string sn_S4_3出站接口 = string.Empty;
  7967. /// <summary>
  7968. /// [S4] 取放桁架 - S4_3出站接口(提升机1)
  7969. /// </summary>
  7970. private void S4_3出站接口(int plcNo, string stationCode, string stationName)
  7971. {
  7972. Stopwatch stopwatch1 = new Stopwatch();
  7973. Stopwatch stopwatch2 = new Stopwatch();
  7974. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7975. string stationNameStr = stationCode + stationName;
  7976. string processItem = stationName; // 测试项目
  7977. try
  7978. {
  7979. stopwatch1.Start();
  7980. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7981. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7982. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7983. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7984. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  7985. sn = sn.Replace("\0", "");
  7986. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  7987. bool isPass = d3Result == 1; // 产品结果 bool
  7988. #region 查询15个载具码
  7989. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7990. string vehicleData = string.Empty;
  7991. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7992. if (string.IsNullOrEmpty(vehicleData))
  7993. vehicleData = "";
  7994. if (snResult1 != 0)
  7995. {
  7996. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7997. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7998. writeToPLC_Flag1.Adress = 2463;
  7999. writeToPLC_Flag1.Value = (short)4;
  8000. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  8001. stopwatch1.Stop();
  8002. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8003. return;
  8004. }
  8005. string[] cavitySNs = vehicleData.Split('.');
  8006. if (cavitySNs != null && cavitySNs.Length > 0)
  8007. {
  8008. for (int i = 0; i < cavitySNs.Length; i++)
  8009. {
  8010. if (string.IsNullOrEmpty(cavitySNs[i]))
  8011. vehicleCodes.Add("");
  8012. else
  8013. vehicleCodes.Add(cavitySNs[i]);
  8014. }
  8015. }
  8016. #endregion 查询15个载具码
  8017. // 统一查 产品SN列表
  8018. List<string> partNos = new List<string>();
  8019. foreach (string vehicleCode in vehicleCodes)
  8020. {
  8021. if (string.IsNullOrEmpty(vehicleCode))
  8022. partNos.Add("");
  8023. else
  8024. {
  8025. string partNo = "";
  8026. #region 查询载具上的产品信息
  8027. string cavityData = string.Empty;
  8028. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8029. if (string.IsNullOrEmpty(cavityData))
  8030. cavityData = "";
  8031. if (snResult != 0)
  8032. {
  8033. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8034. writeToPLC_Flag1.Name = "d3MES_FLAG";
  8035. writeToPLC_Flag1.Adress = 2463;
  8036. writeToPLC_Flag1.Value = (short)4;
  8037. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  8038. stopwatch1.Stop();
  8039. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8040. return;
  8041. }
  8042. string[] partSNs = cavityData.Split('.');
  8043. if (partSNs != null && partSNs.Length >= 1)
  8044. partNo = partSNs[0];
  8045. #endregion 查询载具上的产品信息
  8046. partNos.Add(partNo);
  8047. }
  8048. }
  8049. // 统一上传 - 调用MES出站
  8050. stopwatch2.Start();
  8051. List<int> results = new List<int>();
  8052. for (int i = 0; i < partNos.Count; i++)
  8053. {
  8054. string index = (i + 1).ToString(); // 弹夹穴号
  8055. if (string.IsNullOrEmpty(partNos[i]))
  8056. results.Add(1);
  8057. else
  8058. {
  8059. List<TestItem> items1 = new List<TestItem>();
  8060. items1.Add(new TestItem()
  8061. {
  8062. Parameter_name = "弹夹码",
  8063. Parameter_value = sn,
  8064. Parameter_unit = ""
  8065. });
  8066. items1.Add(new TestItem()
  8067. {
  8068. Parameter_name = "弹夹穴号",
  8069. Parameter_value = index,
  8070. Parameter_unit = ""
  8071. });
  8072. items1.Add(new TestItem()
  8073. {
  8074. Parameter_name = "载具码",
  8075. Parameter_value = vehicleCodes[i],
  8076. Parameter_unit = ""
  8077. });
  8078. items1.Add(new TestItem()
  8079. {
  8080. Parameter_name = "载具穴号",
  8081. Parameter_value = "1",
  8082. Parameter_unit = ""
  8083. });
  8084. items1.Add(new TestItem()
  8085. {
  8086. Parameter_name = "产品结果",
  8087. Parameter_value = d3Result == 1 ? "OK" : "NG",
  8088. Parameter_unit = ""
  8089. });
  8090. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  8091. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  8092. results.Add(result1);
  8093. }
  8094. }
  8095. short result = 0;
  8096. if (results.All(a => a == 1))
  8097. result = 1;
  8098. else if (results.Contains(3))
  8099. result = 3;
  8100. else if (results.Contains(2))
  8101. result = 2;
  8102. else if (results.Contains(4))
  8103. result = 4;
  8104. else
  8105. result = 4;
  8106. stopwatch2.Stop();
  8107. // MES_Flag 为4MES报错
  8108. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8109. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8110. writeToPLC_Flag.Name = "d3MES_FLAG";
  8111. writeToPLC_Flag.Adress = 2463;
  8112. writeToPLC_Flag.Value = result;
  8113. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  8114. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8115. }
  8116. catch (Exception ex)
  8117. {
  8118. stopwatch2.Restart();
  8119. // MES_Flag 为4上位机报错
  8120. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  8121. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8122. writeToPLC_Flag.Name = "d3MES_FLAG";
  8123. writeToPLC_Flag.Adress = 2463;
  8124. writeToPLC_Flag.Value = (short)4;
  8125. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  8126. string str = ex.StackTrace;
  8127. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8128. stopwatch2.Stop();
  8129. }
  8130. stopwatch1.Stop();
  8131. AddMessage(LogType.Info, stationNameStr + "_S4_3出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8132. }
  8133. // 上次采集到的SN
  8134. //private string sn_S4_4进站接口 = string.Empty;
  8135. /// <summary>
  8136. /// [S4] 取放桁架 - S4_4进站接口(提升机2)
  8137. /// </summary>
  8138. private void S4_4进站接口(int plcNo, string stationNameStr)
  8139. {
  8140. Stopwatch stopwatch1 = new Stopwatch();
  8141. Stopwatch stopwatch2 = new Stopwatch();
  8142. try
  8143. {
  8144. stopwatch1.Start();
  8145. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  8146. sn = sn.Replace("\0", "");
  8147. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  8148. #region 查询15个载具码
  8149. List<string> vehicleCodes = new List<string>(); // 15个载具码
  8150. string vehicleData = string.Empty;
  8151. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  8152. if (string.IsNullOrEmpty(vehicleData))
  8153. vehicleData = "";
  8154. if (snResult != 0)
  8155. {
  8156. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8157. writeToPLC_Flag1.Name = "d3MES_FLAG";
  8158. writeToPLC_Flag1.Adress = 2463;
  8159. writeToPLC_Flag1.Value = (short)4;
  8160. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  8161. stopwatch1.Stop();
  8162. AddMessage(LogType.Info, stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8163. return;
  8164. }
  8165. string[] cavitySNs = vehicleData.Split('.');
  8166. if (cavitySNs != null && cavitySNs.Length > 0)
  8167. {
  8168. for (int i = 0; i < cavitySNs.Length; i++)
  8169. {
  8170. if (string.IsNullOrEmpty(cavitySNs[i]))
  8171. vehicleCodes.Add("");
  8172. else
  8173. vehicleCodes.Add(cavitySNs[i]);
  8174. }
  8175. }
  8176. #endregion 查询15个载具码
  8177. #region 查询15个产品SN
  8178. List<string> portNos = new List<string>(); // 15个产品SN
  8179. foreach (string vehicleCode in vehicleCodes)
  8180. {
  8181. if (string.IsNullOrEmpty(vehicleCode))
  8182. portNos.Add("");
  8183. else
  8184. {
  8185. // 查询
  8186. string cavityData = string.Empty;
  8187. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8188. if (string.IsNullOrEmpty(cavityData))
  8189. cavityData = "";
  8190. if (snResult1 != 0)
  8191. {
  8192. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8193. writeToPLC_Flag1.Name = "d3MES_FLAG";
  8194. writeToPLC_Flag1.Adress = 2463;
  8195. writeToPLC_Flag1.Value = (short)4;
  8196. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  8197. stopwatch1.Stop();
  8198. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8199. return;
  8200. }
  8201. string[] partSNs = cavityData.Split('.');
  8202. if (partSNs != null && partSNs.Length >= 1)
  8203. portNos.Add(partSNs[0]);
  8204. else
  8205. portNos.Add("");
  8206. }
  8207. }
  8208. #endregion 查询15个产品SN
  8209. // 调用MES进站(最多15个)
  8210. stopwatch2.Start();
  8211. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  8212. for (int i = 0; i < vehicleCodes.Count; i++)
  8213. {
  8214. // 循环进站
  8215. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  8216. {
  8217. // 产品SN(物料码)校验
  8218. string portNo = portNos[i];
  8219. List<TestItem> item = new List<TestItem>();
  8220. item.Add(new TestItem()
  8221. {
  8222. Parameter_name = "弹夹码",
  8223. Parameter_value = sn,
  8224. });
  8225. item.Add(new TestItem()
  8226. {
  8227. Parameter_name = "弹夹穴位",
  8228. Parameter_value = (i + 1).ToString(),
  8229. });
  8230. item.Add(new TestItem()
  8231. {
  8232. Parameter_name = "载具码",
  8233. Parameter_value = vehicleCodes[i],
  8234. });
  8235. item.Add(new TestItem()
  8236. {
  8237. Parameter_name = "载具穴号",
  8238. Parameter_value = "1",
  8239. });
  8240. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  8241. }
  8242. }
  8243. stopwatch2.Stop();
  8244. short result = 0;
  8245. bool haveMesWarn = results.Contains(5);
  8246. bool havePCWarn = results.Contains(6);
  8247. if (haveMesWarn)
  8248. result = 2; // 5->2
  8249. else if (havePCWarn)
  8250. result = 6; // 6->4
  8251. else
  8252. result = 1;
  8253. // MES_Flag 为4MES报错
  8254. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8255. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8256. writeToPLC_Flag.Name = "d4MES_FLAG";
  8257. writeToPLC_Flag.Adress = 2496;
  8258. writeToPLC_Flag.Value = result;
  8259. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8260. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8261. }
  8262. catch (Exception ex)
  8263. {
  8264. stopwatch2.Stop();
  8265. // MES_Flag 为4上位机报错
  8266. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  8267. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8268. writeToPLC_Flag.Name = "d4MES_FLAG";
  8269. writeToPLC_Flag.Adress = 2496;
  8270. writeToPLC_Flag.Value = (short)4;
  8271. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8272. string str = ex.StackTrace;
  8273. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8274. }
  8275. stopwatch1.Stop();
  8276. AddMessage(LogType.Info, stationNameStr + "_S4_4进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8277. }
  8278. // 上次采集到的SN
  8279. //private string sn_S4_4出站接口 = string.Empty;
  8280. /// <summary>
  8281. /// [S4] 取放桁架 - S4_4出站接口(提升机2)
  8282. /// </summary>
  8283. private void S4_4出站接口(int plcNo, string stationCode, string stationName)
  8284. {
  8285. Stopwatch stopwatch1 = new Stopwatch();
  8286. Stopwatch stopwatch2 = new Stopwatch();
  8287. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8288. string stationNameStr = stationCode + stationName;
  8289. string processItem = stationName; // 测试项目
  8290. try
  8291. {
  8292. stopwatch1.Start();
  8293. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8294. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8295. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8296. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8297. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  8298. sn = sn.Replace("\0", "");
  8299. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  8300. bool isPass = d4Result == 1; // 产品结果 bool
  8301. #region 查询15个载具码
  8302. List<string> vehicleCodes = new List<string>(); // 15个载具码
  8303. string vehicleData = string.Empty;
  8304. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  8305. if (string.IsNullOrEmpty(vehicleData))
  8306. vehicleData = "";
  8307. if (snResult1 != 0)
  8308. {
  8309. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8310. writeToPLC_Flag1.Name = "d4MES_FLAG";
  8311. writeToPLC_Flag1.Adress = 2496;
  8312. writeToPLC_Flag1.Value = (short)4;
  8313. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  8314. stopwatch1.Stop();
  8315. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8316. return;
  8317. }
  8318. string[] cavitySNs = vehicleData.Split('.');
  8319. if (cavitySNs != null && cavitySNs.Length > 0)
  8320. {
  8321. for (int i = 0; i < cavitySNs.Length; i++)
  8322. {
  8323. if (string.IsNullOrEmpty(cavitySNs[i]))
  8324. vehicleCodes.Add("");
  8325. else
  8326. vehicleCodes.Add(cavitySNs[i]);
  8327. }
  8328. }
  8329. #endregion 查询15个载具码
  8330. // 统一查 产品SN列表
  8331. List<string> partNos = new List<string>();
  8332. foreach (string vehicleCode in vehicleCodes)
  8333. {
  8334. if (string.IsNullOrEmpty(vehicleCode))
  8335. partNos.Add("");
  8336. else
  8337. {
  8338. string partNo = "";
  8339. #region 查询载具上的产品信息
  8340. string cavityData = string.Empty;
  8341. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8342. if (string.IsNullOrEmpty(cavityData))
  8343. cavityData = "";
  8344. if (snResult != 0)
  8345. {
  8346. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8347. writeToPLC_Flag1.Name = "d4MES_FLAG";
  8348. writeToPLC_Flag1.Adress = 2496;
  8349. writeToPLC_Flag1.Value = (short)4;
  8350. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  8351. stopwatch1.Stop();
  8352. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8353. return;
  8354. }
  8355. string[] partSNs = cavityData.Split('.');
  8356. if (partSNs != null && partSNs.Length >= 1)
  8357. partNo = partSNs[0];
  8358. #endregion 查询载具上的产品信息
  8359. partNos.Add(partNo);
  8360. }
  8361. }
  8362. // 调用MES出站
  8363. stopwatch2.Start();
  8364. // 统一上传
  8365. List<int> results = new List<int>();
  8366. for (int i = 0; i < partNos.Count; i++)
  8367. {
  8368. string index = (i + 1).ToString(); // 弹夹穴号
  8369. if (string.IsNullOrEmpty(partNos[i]))
  8370. results.Add(1);
  8371. else
  8372. {
  8373. List<TestItem> items1 = new List<TestItem>();
  8374. items1.Add(new TestItem()
  8375. {
  8376. Parameter_name = "弹夹码",
  8377. Parameter_value = sn,
  8378. Parameter_unit = ""
  8379. });
  8380. items1.Add(new TestItem()
  8381. {
  8382. Parameter_name = "弹夹穴号",
  8383. Parameter_value = index,
  8384. Parameter_unit = ""
  8385. });
  8386. items1.Add(new TestItem()
  8387. {
  8388. Parameter_name = "载具码",
  8389. Parameter_value = vehicleCodes[i],
  8390. Parameter_unit = ""
  8391. });
  8392. items1.Add(new TestItem()
  8393. {
  8394. Parameter_name = "载具穴号",
  8395. Parameter_value = "1",
  8396. Parameter_unit = ""
  8397. });
  8398. items1.Add(new TestItem()
  8399. {
  8400. Parameter_name = "产品结果",
  8401. Parameter_value = d4Result == 1 ? "OK" : "NG",
  8402. Parameter_unit = ""
  8403. });
  8404. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  8405. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  8406. results.Add(result1);
  8407. }
  8408. }
  8409. short result = 0;
  8410. if (results.All(a => a == 1))
  8411. result = 1;
  8412. else if (results.Contains(3))
  8413. result = 3;
  8414. else if (results.Contains(2))
  8415. result = 2;
  8416. else if (results.Contains(4))
  8417. result = 4;
  8418. else
  8419. result = 4;
  8420. stopwatch2.Stop();
  8421. // MES_Flag 为4MES报错
  8422. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8423. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8424. writeToPLC_Flag.Name = "d4MES_FLAG";
  8425. writeToPLC_Flag.Adress = 2496;
  8426. writeToPLC_Flag.Value = result;
  8427. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8428. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8429. }
  8430. catch (Exception ex)
  8431. {
  8432. stopwatch2.Restart();
  8433. // MES_Flag 为4上位机报错
  8434. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  8435. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8436. writeToPLC_Flag.Name = "d4MES_FLAG";
  8437. writeToPLC_Flag.Adress = 2496;
  8438. writeToPLC_Flag.Value = (short)4;
  8439. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8440. string str = ex.StackTrace;
  8441. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8442. stopwatch2.Stop();
  8443. }
  8444. stopwatch1.Stop();
  8445. AddMessage(LogType.Info, stationNameStr + "_S4_4出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8446. }
  8447. /// <summary>
  8448. /// [S4] 取放桁架 - S4_5弹夹扫码
  8449. /// </summary>
  8450. /// <param name="plcNo">PLC编号</param>
  8451. /// <param name="stationNameStr">工站全称</param>
  8452. private void S4_5弹夹扫码(int plcNo, string stationNameStr)
  8453. {
  8454. Stopwatch stopwatch1 = new Stopwatch();
  8455. Stopwatch stopwatch2 = new Stopwatch();
  8456. try
  8457. {
  8458. stopwatch1.Start();
  8459. // ZS 弹夹扫码
  8460. string d5BulletclipCode = " "; // 扫到的码
  8461. short d5BulletclipScanCode = 2;
  8462. stopwatch2.Start();
  8463. //Funs[plcNo].WriteMultipleRegisters<string>(2529, d5BulletclipCode, 20);
  8464. //// MES_Flag
  8465. //Funs[plcNo].WriteMultipleRegisters<short>(2528, d5BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  8466. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8467. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  8468. writeToPLC_Flag.Adress = 2528;
  8469. writeToPLC_Flag.Value = d5BulletclipScanCode;
  8470. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8471. {
  8472. Name = "d5BulletclipCode",
  8473. Adress = 2529,
  8474. ValueType = PLCValueType.String,
  8475. ValueTypeStrLength = 20,
  8476. Value = d5BulletclipCode
  8477. });
  8478. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  8479. stopwatch2.Stop();
  8480. }
  8481. catch (Exception ex)
  8482. {
  8483. string str = ex.StackTrace;
  8484. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8485. stopwatch2.Start();
  8486. //Funs[plcNo].WriteMultipleRegisters<string>(2529, " ", 20);
  8487. //// MES_Flag
  8488. //Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  8489. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8490. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  8491. writeToPLC_Flag.Adress = 2528;
  8492. writeToPLC_Flag.Value = (short)6;
  8493. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8494. {
  8495. Name = "d5BulletclipCode",
  8496. Adress = 2529,
  8497. ValueType = PLCValueType.String,
  8498. ValueTypeStrLength = 20,
  8499. Value = " "
  8500. });
  8501. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  8502. stopwatch2.Stop();
  8503. }
  8504. stopwatch1.Stop();
  8505. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8506. }
  8507. /// <summary>
  8508. /// [S4] 取放桁架 - S4_5载具扫码
  8509. /// </summary>
  8510. /// <param name="plcNo">PLC编号</param>
  8511. /// <param name="stationNameStr">工站全称</param>
  8512. private void S4_5载具扫码(int plcNo, string stationNameStr)
  8513. {
  8514. Stopwatch stopwatch1 = new Stopwatch();
  8515. Stopwatch stopwatch2 = new Stopwatch();
  8516. try
  8517. {
  8518. stopwatch1.Start();
  8519. // ZS 载具扫码
  8520. string d5VehicleCode = " "; // 扫到的码
  8521. short d5VehicleScanCode = 2;
  8522. #region 进站
  8523. if (d5VehicleScanCode == 2 && !string.IsNullOrEmpty(d5VehicleCode))
  8524. {
  8525. // 查产品SN
  8526. #region 查询载具上的产品信息
  8527. string cavityData = string.Empty;
  8528. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d5VehicleCode, ref cavityData);
  8529. if (string.IsNullOrEmpty(cavityData))
  8530. cavityData = "";
  8531. if (snResult != 0)
  8532. {
  8533. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8534. writeToPLC_Flag1.Name = "d5VehicleScanCode";
  8535. writeToPLC_Flag1.Adress = 2559;
  8536. writeToPLC_Flag1.Value = (short)6;
  8537. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8538. {
  8539. Name = "d5VehicleCode",
  8540. Adress = 2560,
  8541. ValueType = PLCValueType.String,
  8542. ValueTypeStrLength = 20,
  8543. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  8544. });
  8545. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag1);
  8546. stopwatch1.Stop();
  8547. AddMessage(LogType.Info, stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8548. return;
  8549. }
  8550. string[] cavitySNs = cavityData.Split('.');
  8551. string partNo = "";
  8552. if (cavitySNs != null && cavitySNs.Length >= 1)
  8553. {
  8554. partNo = cavitySNs[0];
  8555. }
  8556. #endregion 查询载具上的产品信息
  8557. List<TestItem> item = new List<TestItem>();
  8558. item.Add(new TestItem()
  8559. {
  8560. Parameter_name = "载具码",
  8561. Parameter_value = d5VehicleCode,
  8562. });
  8563. item.Add(new TestItem()
  8564. {
  8565. Parameter_name = "载具穴号",
  8566. Parameter_value = "1",
  8567. });
  8568. stopwatch2.Start();
  8569. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  8570. stopwatch2.Stop();
  8571. d5VehicleScanCode = (short)result == 1 ? d5VehicleScanCode : (short)result;
  8572. }
  8573. #endregion 进站
  8574. //Funs[plcNo].WriteMultipleRegisters<string>(2560, d5VehicleCode, 20);
  8575. //// MES_Flag
  8576. //Funs[plcNo].WriteMultipleRegisters<short>(2559, d5VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  8577. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8578. writeToPLC_Flag.Name = "d5VehicleScanCode";
  8579. writeToPLC_Flag.Adress = 2559;
  8580. writeToPLC_Flag.Value = d5VehicleScanCode;
  8581. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8582. {
  8583. Name = "d5VehicleCode",
  8584. Adress = 2560,
  8585. ValueType = PLCValueType.String,
  8586. ValueTypeStrLength = 20,
  8587. Value = d5VehicleCode
  8588. });
  8589. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  8590. }
  8591. catch (Exception ex)
  8592. {
  8593. string str = ex.StackTrace;
  8594. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8595. stopwatch2.Start();
  8596. //Funs[plcNo].WriteMultipleRegisters<string>(2560, " ", 20);
  8597. //// MES_Flag
  8598. //Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  8599. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8600. writeToPLC_Flag.Name = "d5VehicleScanCode";
  8601. writeToPLC_Flag.Adress = 2559;
  8602. writeToPLC_Flag.Value = (short)6;
  8603. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8604. {
  8605. Name = "d5VehicleCode",
  8606. Adress = 2560,
  8607. ValueType = PLCValueType.String,
  8608. ValueTypeStrLength = 20,
  8609. Value = " "
  8610. });
  8611. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  8612. stopwatch2.Stop();
  8613. }
  8614. stopwatch1.Stop();
  8615. AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8616. }
  8617. // 上次采集到的SN
  8618. //private string sn_S4_5出站接口 = string.Empty;
  8619. /// <summary>
  8620. /// [S4] 取放桁架 - S4_5出站接口
  8621. /// </summary>
  8622. private void S4_5出站接口(int plcNo, string stationCode, string stationName)
  8623. {
  8624. Stopwatch stopwatch1 = new Stopwatch();
  8625. Stopwatch stopwatch2 = new Stopwatch();
  8626. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8627. string stationNameStr = stationCode + stationName;
  8628. string processItem = stationName; // 测试项目
  8629. try
  8630. {
  8631. stopwatch1.Start();
  8632. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8633. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8634. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8635. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8636. string sn = (string)s4PLCData["d5ProductSN"]; // 产品SN(弹夹码)
  8637. sn = sn.Replace("\0", "");
  8638. string d5VehicleCode1 = (string)s4PLCData["d5VehicleCode1"]; // 载具1码(弹夹穴位1)
  8639. d5VehicleCode1 = d5VehicleCode1.Replace("\0", "");
  8640. string d5VehicleCode2 = (string)s4PLCData["d5VehicleCode2"]; // 载具2码(弹夹穴位2)
  8641. d5VehicleCode2 = d5VehicleCode2.Replace("\0", "");
  8642. string d5VehicleCode3 = (string)s4PLCData["d5VehicleCode3"]; // 载具3码(弹夹穴位3)
  8643. d5VehicleCode3 = d5VehicleCode3.Replace("\0", "");
  8644. string d5VehicleCode4 = (string)s4PLCData["d5VehicleCode4"]; // 载具4码(弹夹穴位4)
  8645. d5VehicleCode4 = d5VehicleCode4.Replace("\0", "");
  8646. string d5VehicleCode5 = (string)s4PLCData["d5VehicleCode5"]; // 载具5码(弹夹穴位5)
  8647. d5VehicleCode5 = d5VehicleCode5.Replace("\0", "");
  8648. string d5VehicleCode6 = (string)s4PLCData["d5VehicleCode6"]; // 载具6码(弹夹穴位6)
  8649. d5VehicleCode6 = d5VehicleCode6.Replace("\0", "");
  8650. string d5VehicleCode7 = (string)s4PLCData["d5VehicleCode7"]; // 载具7码(弹夹穴位7)
  8651. d5VehicleCode7 = d5VehicleCode7.Replace("\0", "");
  8652. string d5VehicleCode8 = (string)s4PLCData["d5VehicleCode8"]; // 载具8码(弹夹穴位8)
  8653. d5VehicleCode8 = d5VehicleCode8.Replace("\0", "");
  8654. string d5VehicleCode9 = (string)s4PLCData["d5VehicleCode9"]; // 载具9码(弹夹穴位9)
  8655. d5VehicleCode9 = d5VehicleCode9.Replace("\0", "");
  8656. string d5VehicleCode10 = (string)s4PLCData["d5VehicleCode10"]; // 载具10码(弹夹穴位10)
  8657. d5VehicleCode10 = d5VehicleCode10.Replace("\0", "");
  8658. string d5VehicleCode11 = (string)s4PLCData["d5VehicleCode11"]; // 载具11码(弹夹穴位11)
  8659. d5VehicleCode11 = d5VehicleCode11.Replace("\0", "");
  8660. string d5VehicleCode12 = (string)s4PLCData["d5VehicleCode12"]; // 载具12码(弹夹穴位12)
  8661. d5VehicleCode12 = d5VehicleCode12.Replace("\0", "");
  8662. string d5VehicleCode13 = (string)s4PLCData["d5VehicleCode13"]; // 载具13码(弹夹穴位13)
  8663. d5VehicleCode13 = d5VehicleCode13.Replace("\0", "");
  8664. string d5VehicleCode14 = (string)s4PLCData["d5VehicleCode14"]; // 载具14码(弹夹穴位14)
  8665. d5VehicleCode14 = d5VehicleCode14.Replace("\0", "");
  8666. string d5VehicleCode15 = (string)s4PLCData["d5VehicleCode15"]; // 载具15码(弹夹穴位15)
  8667. d5VehicleCode15 = d5VehicleCode15.Replace("\0", "");
  8668. int d5Result = (int)s4PLCData["d5Result"]; // 产品结果
  8669. bool pass = d5Result == 1;
  8670. // 存 载具SN列表
  8671. List<string> vehicleCodes = new List<string>()
  8672. {
  8673. d5VehicleCode1,d5VehicleCode2,d5VehicleCode3,d5VehicleCode4,d5VehicleCode5,
  8674. d5VehicleCode6,d5VehicleCode7,d5VehicleCode8,d5VehicleCode9,d5VehicleCode10,
  8675. d5VehicleCode11,d5VehicleCode12,d5VehicleCode13,d5VehicleCode14,d5VehicleCode15
  8676. };
  8677. // 统一查 产品SN列表
  8678. List<string> partNos = new List<string>();
  8679. foreach (string vehicleCode in vehicleCodes)
  8680. {
  8681. if (string.IsNullOrEmpty(vehicleCode))
  8682. partNos.Add("");
  8683. else
  8684. {
  8685. string partNo = "";
  8686. #region 查询载具上的产品信息
  8687. string cavityData = string.Empty;
  8688. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8689. if (string.IsNullOrEmpty(cavityData))
  8690. cavityData = "";
  8691. if (snResult != 0)
  8692. {
  8693. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8694. writeToPLC_Flag1.Name = "d5MES_FLAG";
  8695. writeToPLC_Flag1.Adress = 2591;
  8696. writeToPLC_Flag1.Value = (short)4;
  8697. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag1);
  8698. stopwatch1.Stop();
  8699. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8700. return;
  8701. }
  8702. string[] cavitySNs = cavityData.Split('.');
  8703. if (cavitySNs != null && cavitySNs.Length >= 1)
  8704. partNo = cavitySNs[0];
  8705. #endregion 查询载具上的产品信息
  8706. partNos.Add(partNo);
  8707. }
  8708. }
  8709. // 统一上传
  8710. stopwatch2.Start();
  8711. List<int> results = new List<int>();
  8712. for (int i = 0; i < partNos.Count; i++)
  8713. {
  8714. string index = (i + 1).ToString(); // 弹夹穴号
  8715. if (string.IsNullOrEmpty(partNos[i]))
  8716. results.Add(1);
  8717. else
  8718. {
  8719. List<TestItem> items1 = new List<TestItem>();
  8720. items1.Add(new TestItem()
  8721. {
  8722. Parameter_name = "弹夹码",
  8723. Parameter_value = sn,
  8724. Parameter_unit = ""
  8725. });
  8726. items1.Add(new TestItem()
  8727. {
  8728. Parameter_name = "弹夹穴号",
  8729. Parameter_value = index,
  8730. Parameter_unit = ""
  8731. });
  8732. items1.Add(new TestItem()
  8733. {
  8734. Parameter_name = "载具码",
  8735. Parameter_value = vehicleCodes[i],
  8736. Parameter_unit = ""
  8737. });
  8738. items1.Add(new TestItem()
  8739. {
  8740. Parameter_name = "载具穴号",
  8741. Parameter_value = "1",
  8742. Parameter_unit = ""
  8743. });
  8744. items1.Add(new TestItem()
  8745. {
  8746. Parameter_name = "产品结果",
  8747. Parameter_value = d5Result == 1 ? "OK" : "NG",
  8748. Parameter_unit = ""
  8749. });
  8750. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  8751. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  8752. results.Add(result1);
  8753. }
  8754. }
  8755. short result = 0;
  8756. if (results.All(a => a == 1))
  8757. result = 1;
  8758. else if (results.Contains(3))
  8759. result = 3;
  8760. else if (results.Contains(2))
  8761. result = 2;
  8762. else if (results.Contains(4))
  8763. result = 4;
  8764. else
  8765. result = 4;
  8766. stopwatch2.Stop();
  8767. #region 存储绑定数据到 边线MES系统中
  8768. if (result == 1)
  8769. {
  8770. // 删除绑定信息
  8771. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  8772. if (resultMesR != 0)
  8773. {
  8774. result = 4;
  8775. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  8776. }
  8777. }
  8778. #endregion 存储绑定数据到 边线MES系统中
  8779. // MES_Flag 为4MES报错
  8780. //Funs[plcNo].WriteMultipleRegisters<short>(2591, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8781. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8782. writeToPLC_Flag.Name = "d5MES_FLAG";
  8783. writeToPLC_Flag.Adress = 2591;
  8784. writeToPLC_Flag.Value = result;
  8785. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  8786. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  8787. }
  8788. catch (Exception ex)
  8789. {
  8790. stopwatch2.Restart();
  8791. // MES_Flag 为4上位机报错
  8792. //Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)4); // 4代表上位机报警
  8793. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8794. writeToPLC_Flag.Name = "d5MES_FLAG";
  8795. writeToPLC_Flag.Adress = 2591;
  8796. writeToPLC_Flag.Value = (short)4;
  8797. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  8798. stopwatch2.Stop();
  8799. string str = ex.StackTrace;
  8800. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8801. }
  8802. stopwatch1.Stop();
  8803. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8804. }
  8805. /// <summary>
  8806. /// [S4] 取放桁架 - S4_5节拍接口
  8807. /// </summary>
  8808. /// <param name="plcNo">PLC编号</param>
  8809. /// <param name="stationNameStr">工站全称</param>
  8810. private void S4_5节拍接口(int plcNo, string stationNameStr)
  8811. {
  8812. Stopwatch stopwatch1 = new Stopwatch();
  8813. Stopwatch stopwatch2 = new Stopwatch();
  8814. string resultStr = string.Empty;
  8815. try
  8816. {
  8817. stopwatch1.Start();
  8818. string oEEType = ((int)s4PLCData["d5OEEType"]).ToString(); // 节拍类型(plc写入)
  8819. string d5OEEProductSN = (string)s4PLCData["d5OEEProductSN"]; // 载具SN
  8820. d5OEEProductSN = d5OEEProductSN.Replace("\0", "");
  8821. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  8822. if (!actionBool)
  8823. {
  8824. stopwatch2.Start();
  8825. // MES_Flag
  8826. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 上位机;发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警
  8827. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8828. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  8829. writeToPLC_Flag1.Adress = 2924;
  8830. writeToPLC_Flag1.Value = (short)4;
  8831. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  8832. stopwatch2.Stop();
  8833. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8834. return;
  8835. }
  8836. string d5OEEPartNo = string.Empty; // 物料码
  8837. if (string.IsNullOrEmpty(d5OEEProductSN))
  8838. {
  8839. stopwatch2.Start();
  8840. // MES_Flag
  8841. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8842. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8843. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  8844. writeToPLC_Flag1.Adress = 2924;
  8845. writeToPLC_Flag1.Value = (short)1;
  8846. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  8847. stopwatch2.Stop();
  8848. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8849. return;
  8850. }
  8851. else
  8852. { // 查产品SN
  8853. d5OEEPartNo = "Test"; // ZS
  8854. }
  8855. short d5OEEMES_FLAG = 0;
  8856. // 上传OEE
  8857. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d5OEEPartNo, d5OEEProductSN);
  8858. d5OEEMES_FLAG = result.Item1;
  8859. resultStr = result.Item2;
  8860. stopwatch2.Start();
  8861. // MES_Flag
  8862. //Funs[plcNo].WriteMultipleRegisters<short>(2924, d5OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8863. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8864. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  8865. writeToPLC_Flag.Adress = 2924;
  8866. writeToPLC_Flag.Value = d5OEEMES_FLAG;
  8867. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  8868. stopwatch2.Stop();
  8869. }
  8870. catch (Exception ex)
  8871. {
  8872. string str = ex.StackTrace;
  8873. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8874. // MES_Flag
  8875. stopwatch2.Start();
  8876. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  8877. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8878. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  8879. writeToPLC_Flag.Adress = 2924;
  8880. writeToPLC_Flag.Value = (short)4;
  8881. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  8882. stopwatch2.Stop();
  8883. }
  8884. stopwatch1.Stop();
  8885. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8886. }
  8887. #endregion [S4] 取放桁架
  8888. #endregion PLC4 刘果段
  8889. #region PLC5 张超凡
  8890. #region [S5] Tray盘下料装备
  8891. /// <summary>
  8892. /// S5工位的数据- 触发信号上次的值
  8893. /// </summary>
  8894. private Dictionary<string, object> s5PLCSignal_Old = new Dictionary<string, object>();
  8895. /// <summary>
  8896. /// S5工位的数据(含触发信号)
  8897. /// </summary>
  8898. private Dictionary<string, object> s5PLCData = new Dictionary<string, object>();
  8899. /// <summary>
  8900. /// S5工位的数据- 回写点位
  8901. /// </summary>
  8902. private Dictionary<string, WriteToPLC_Flag> s5PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  8903. /// <summary>
  8904. /// [S5] Tray盘下料装备
  8905. /// </summary>
  8906. /// <param name="plcNo">PLC编号</param>
  8907. //private void ReadStation_S5(int plcNo)
  8908. //{
  8909. // // [S1] Tray盘上料装备
  8910. // // [S2] FCT
  8911. // // [S3] 值板机
  8912. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  8913. // // [S5] Tray盘下料装备
  8914. // /// 上位机心跳
  8915. // /// 获取设备报警数据与状态信息
  8916. // string stationCode = "[S5]";
  8917. // string stationName = "Tray盘下料装备";
  8918. // string stationNameStr = stationCode + stationName;
  8919. // #region 创建字典
  8920. // // 触发信号字典 赋值
  8921. // s5PLCSignal_Old.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8922. // s5PLCSignal_Old.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8923. // s5PLCSignal_Old.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8924. // s5PLCSignal_Old.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  8925. // s5PLCSignal_Old.Add("e1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  8926. // s5PLCSignal_Old.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  8927. // s5PLCSignal_Old.Add("e1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  8928. // // PLC数据字典 赋值
  8929. // s5PLCData.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8930. // s5PLCData.Add("e1MES_FLAG_Check", 0); // MES_FLAG
  8931. // s5PLCData.Add("e1ProductSN_Check", ""); //
  8932. // s5PLCData.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8933. // s5PLCData.Add("e1MES_FLAG", 0); // MES_FLAG
  8934. // s5PLCData.Add("e1ProductSN", ""); // 产品SN
  8935. // s5PLCData.Add("e1PartNo", ""); // 物料码
  8936. // s5PLCData.Add("e1Result", 0); // 产品结果
  8937. // s5PLCData.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8938. // s5PLCData.Add("e1OEEMES_FLAG", 0); // MES_FLAG
  8939. // s5PLCData.Add("e1OEEProductSN", "");// 产品SN(载具SN)
  8940. // s5PLCData.Add("e1OEEType", 0); // 节拍类型(plc写入)
  8941. // s5PLCData.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  8942. // s5PLCData.Add("e1AGVUpStart", 0); // AGV上料开始信号
  8943. // s5PLCData.Add("e1AGVUpEnd", 0); // AGV上料完成信号
  8944. // s5PLCData.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  8945. // s5PLCData.Add("e1AGVDownStart", 0); // AGV下料开始信号
  8946. // s5PLCData.Add("e1AGVDownEnd", 0); // AGV下料完成信号
  8947. // #endregion 创建字典
  8948. // while (IsRun)
  8949. // {
  8950. // try
  8951. // {
  8952. // if (!GlobalContext._IsCon_Funs5)
  8953. // {
  8954. // UpdatePLCMonitor(1, plcNo, 0);
  8955. // continue;
  8956. // }
  8957. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  8958. // {
  8959. // Stopwatch stopwatch1 = new Stopwatch();
  8960. // Stopwatch stopwatch2 = new Stopwatch();
  8961. // stopwatch1.Start();
  8962. // stopwatch2.Start();
  8963. // #region 一次性读取所有数据
  8964. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  8965. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 46);
  8966. // int[] datas = data1.Concat(data2).ToArray();
  8967. // s5PLCData["e1PLC_FLAG_Check"] = datas[2]; // 进站校验
  8968. // s5PLCData["e1MES_FLAG_Check"] = datas[3];
  8969. // int[] e1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  8970. // s5PLCData["e1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(e1ProductSN_CheckData, 0, 40);
  8971. // s5PLCData["e1PLC_FLAG"] = datas[34]; // 出站接口
  8972. // s5PLCData["e1MES_FLAG"] = datas[35];
  8973. // int[] e1ProductSNData = datas.Skip(36).Take(20).ToArray();
  8974. // s5PLCData["e1ProductSN"] = ModbusClient.ConvertRegistersToString(e1ProductSNData, 0, 40);
  8975. // int[] e1PartNoData = datas.Skip(56).Take(20).ToArray();
  8976. // s5PLCData["e1PartNo"] = ModbusClient.ConvertRegistersToString(e1PartNoData, 0, 40);
  8977. // s5PLCData["e1Result"] = datas[76];
  8978. // s5PLCData["e1OEEPLC_FLAG"] = datas[87]; // 节拍接口
  8979. // s5PLCData["e1OEEMES_FLAG"] = datas[88];
  8980. // int[] e1OEEProductSNData = datas.Skip(89).Take(20).ToArray();
  8981. // s5PLCData["e1OEEProductSN"] = ModbusClient.ConvertRegistersToString(e1OEEProductSNData, 0, 40);
  8982. // s5PLCData["e1OEEType"] = datas[109];
  8983. // s5PLCData["e1AGVUpCall"] = datas[120]; // AGV上料
  8984. // s5PLCData["e1AGVUpStart"] = datas[121];
  8985. // s5PLCData["e1AGVUpEnd"] = datas[122];
  8986. // s5PLCData["e1AGVDownCall"] = datas[133]; // AGV下料
  8987. // s5PLCData["e1AGVDownStart"] = datas[134];
  8988. // s5PLCData["e1AGVDownEnd"] = datas[135];
  8989. // #endregion 一次性读取所有数据
  8990. // stopwatch2.Stop();
  8991. // #region 回写操作,写后清空flag
  8992. // PLCWriteData(Funs[plcNo], ref s5PLCData, ref s5PLCWriteData);
  8993. // #endregion 回写操作,写后清空flag
  8994. // #region 进站校验
  8995. // try
  8996. // {
  8997. // int e1PLC_FLAG_Check = (int)s5PLCData["e1PLC_FLAG_Check"];
  8998. // int e1MES_FLAG_Check = (int)s5PLCData["e1MES_FLAG_Check"];
  8999. // int e1PLC_FLAG_CheckOld = (int)s5PLCSignal_Old["e1PLC_FLAG_Check"];
  9000. // if (e1PLC_FLAG_Check != e1PLC_FLAG_CheckOld)
  9001. // {
  9002. // if (e1PLC_FLAG_Check == 1 && e1MES_FLAG_Check == 0) // 0->1
  9003. // Task.Run(() => S5进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  9004. // else if (e1PLC_FLAG_Check == 0 && e1MES_FLAG_Check != 0)
  9005. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  9006. // s5PLCSignal_Old["e1PLC_FLAG_Check"] = s5PLCData["e1PLC_FLAG_Check"];
  9007. // }
  9008. // }
  9009. // catch (Exception ex)
  9010. // {
  9011. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  9012. // string str = ex.StackTrace;
  9013. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9014. // }
  9015. // #endregion 进站校验
  9016. // #region 出站接口
  9017. // try
  9018. // {
  9019. // int e1PLC_FLAG = (int)s5PLCData["e1PLC_FLAG"];
  9020. // int e1MES_FLAG = (int)s5PLCData["e1MES_FLAG"];
  9021. // int e1PLC_FLAGOld = (int)s5PLCSignal_Old["e1PLC_FLAG"];
  9022. // if (e1PLC_FLAG != e1PLC_FLAGOld)
  9023. // {
  9024. // if (e1PLC_FLAG == 1 && e1MES_FLAG == 0) // 0->1
  9025. // Task.Run(() => S5出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  9026. // else if (e1PLC_FLAG == 0 && e1MES_FLAG != 0)
  9027. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)0);
  9028. // s5PLCSignal_Old["e1PLC_FLAG"] = s5PLCData["e1PLC_FLAG"];
  9029. // }
  9030. // }
  9031. // catch (Exception ex)
  9032. // {
  9033. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)6); // 6代表上位机报警
  9034. // string str = ex.StackTrace;
  9035. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9036. // }
  9037. // #endregion 出站接口
  9038. // #region 节拍接口
  9039. // try
  9040. // {
  9041. // int e1OEEPLC_FLAG = (int)s5PLCData["e1OEEPLC_FLAG"];
  9042. // int e1OEEMES_FLAG = (int)s5PLCData["e1OEEMES_FLAG"];
  9043. // int e1OEEPLC_FLAGOld = (int)s5PLCSignal_Old["e1OEEPLC_FLAG"];
  9044. // if (e1OEEPLC_FLAG != e1OEEPLC_FLAGOld)
  9045. // {
  9046. // if (e1OEEPLC_FLAG == 1 && e1OEEMES_FLAG == 0) // 0->1
  9047. // Task.Run(() => S5节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  9048. // else if (e1OEEPLC_FLAG == 0 && e1OEEMES_FLAG != 0)
  9049. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)0);
  9050. // s5PLCSignal_Old["e1OEEPLC_FLAG"] = s5PLCData["e1OEEPLC_FLAG"];
  9051. // }
  9052. // }
  9053. // catch (Exception ex)
  9054. // {
  9055. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  9056. // string str = ex.StackTrace;
  9057. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9058. // }
  9059. // #endregion 节拍接口
  9060. // #region AGV上料
  9061. // // AGV上料叫AGV信号
  9062. // try
  9063. // {
  9064. // int e1AGVUpCall = (int)s5PLCData["e1AGVUpCall"];
  9065. // int e1AGVUpCallOld = (int)s5PLCSignal_Old["e1AGVUpCall"];
  9066. // if (e1AGVUpCall != e1AGVUpCallOld)
  9067. // {
  9068. // if (e1AGVUpCall == 1) // 0->1
  9069. // Task.Run(() => S5AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  9070. // s5PLCSignal_Old["e1AGVUpCall"] = s5PLCData["e1AGVUpCall"];
  9071. // }
  9072. // }
  9073. // catch (Exception ex)
  9074. // {
  9075. // Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  9076. // string str = ex.StackTrace;
  9077. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9078. // }
  9079. // // AGV上料完成信号
  9080. // try
  9081. // {
  9082. // int e1AGVUpEnd = (int)s5PLCData["e1AGVUpEnd"];
  9083. // int e1AGVUpEndOld = (int)s5PLCSignal_Old["e1AGVUpEnd"];
  9084. // if (e1AGVUpEnd != e1AGVUpEndOld)
  9085. // {
  9086. // if (e1AGVUpEnd == 1) // 0->1
  9087. // Task.Run(() => S5AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  9088. // s5PLCSignal_Old["e1AGVUpEnd"] = s5PLCData["e1AGVUpEnd"];
  9089. // }
  9090. // }
  9091. // catch (Exception ex)
  9092. // {
  9093. // Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  9094. // string str = ex.StackTrace;
  9095. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9096. // }
  9097. // #endregion AGV上料
  9098. // #region AGV下料
  9099. // // AGV下料叫agv信号
  9100. // try
  9101. // {
  9102. // int e1AGVDownCall = (int)s5PLCData["e1AGVDownCall"];
  9103. // int e1AGVDownCallOld = (int)s5PLCSignal_Old["e1AGVDownCall"];
  9104. // if (e1AGVDownCall != e1AGVDownCallOld)
  9105. // {
  9106. // if (e1AGVDownCall == 1) // 0->1
  9107. // Task.Run(() => S5AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  9108. // s5PLCSignal_Old["e1AGVDownCall"] = s5PLCData["e1AGVDownCall"];
  9109. // }
  9110. // }
  9111. // catch (Exception ex)
  9112. // {
  9113. // Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  9114. // string str = ex.StackTrace;
  9115. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9116. // }
  9117. // // AGV下料完成信号
  9118. // try
  9119. // {
  9120. // int e1AGVDownEnd = (int)s5PLCData["e1AGVDownEnd"];
  9121. // int e1AGVDownEndOld = (int)s5PLCSignal_Old["e1AGVDownEnd"];
  9122. // if (e1AGVDownEnd != e1AGVDownEndOld)
  9123. // {
  9124. // if (e1AGVDownEnd == 1) // 0->1
  9125. // Task.Run(() => S5AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  9126. // s5PLCSignal_Old["e1AGVDownEnd"] = s5PLCData["e1AGVDownEnd"];
  9127. // }
  9128. // }
  9129. // catch (Exception ex)
  9130. // {
  9131. // Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  9132. // string str = ex.StackTrace;
  9133. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9134. // }
  9135. // #endregion AGV下料
  9136. // #region 心跳
  9137. // try
  9138. // {
  9139. // short states = 0;
  9140. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  9141. // }
  9142. // catch (Exception ex)
  9143. // {
  9144. // string str = ex.StackTrace;
  9145. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9146. // }
  9147. // #endregion 心跳
  9148. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  9149. // stopwatch1.Stop();
  9150. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  9151. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  9152. // }
  9153. // else
  9154. // {
  9155. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9156. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  9157. // Funs[plcNo].Connect();
  9158. // }
  9159. // }
  9160. // catch (Exception ex)
  9161. // {
  9162. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9163. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  9164. // Funs[plcNo].ReConnect();
  9165. // }
  9166. // Thread.Sleep(IntervalReadPLC);
  9167. // }
  9168. //}
  9169. /// <summary>
  9170. /// [S5] Tray盘下料装备 - 进站校验
  9171. /// </summary>
  9172. /// <param name="plcNo">PLC编号</param>
  9173. /// <param name="stationNameStr">工站全称</param>
  9174. private void S5进站校验(int plcNo, string stationNameStr)
  9175. {
  9176. Stopwatch stopwatch1 = new Stopwatch();
  9177. Stopwatch stopwatch2 = new Stopwatch();
  9178. try
  9179. {
  9180. stopwatch1.Start();
  9181. string sn = (string)s5PLCData["e1ProductSN_Check"]; // 产品SN(载具码)
  9182. sn = sn.Replace("\0", "");
  9183. // 获取产品SN By 载具码
  9184. #region 查询载具上的产品信息
  9185. string cavityData = string.Empty;
  9186. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  9187. if (string.IsNullOrEmpty(cavityData))
  9188. cavityData = "";
  9189. if (snResult != 0)
  9190. {
  9191. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9192. writeToPLC_Flag1.Name = "e1MES_FLAG_Check";
  9193. writeToPLC_Flag1.Adress = 2003;
  9194. writeToPLC_Flag1.Value = (short)6;
  9195. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag1);
  9196. stopwatch1.Stop();
  9197. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9198. return;
  9199. }
  9200. string[] cavitySNs = cavityData.Split('.');
  9201. string partNo = string.Empty;
  9202. if (cavitySNs != null && cavitySNs.Length >= 1)
  9203. partNo = cavitySNs[0];
  9204. #endregion 查询载具上的产品信息
  9205. // 产品SN(物料码)校验
  9206. List<TestItem> item = new List<TestItem>();
  9207. item.Add(new TestItem()
  9208. {
  9209. Parameter_name = "载具码",
  9210. Parameter_value = sn,
  9211. });
  9212. item.Add(new TestItem()
  9213. {
  9214. Parameter_name = "载具穴号",
  9215. Parameter_value = "1",
  9216. });
  9217. stopwatch2.Start();
  9218. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  9219. stopwatch2.Stop();
  9220. short e1MES_FLAG_Check = (short)result;
  9221. // MES_Flag
  9222. //Funs[plcNo].WriteMultipleRegisters<short>(2003, e1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  9223. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9224. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  9225. writeToPLC_Flag.Adress = 2003;
  9226. writeToPLC_Flag.Value = e1MES_FLAG_Check;
  9227. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  9228. }
  9229. catch (Exception ex)
  9230. {
  9231. string str = ex.StackTrace;
  9232. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9233. // MES_Flag
  9234. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  9235. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9236. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  9237. writeToPLC_Flag.Adress = 2003;
  9238. writeToPLC_Flag.Value = (short)6;
  9239. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  9240. }
  9241. stopwatch1.Stop();
  9242. AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9243. }
  9244. /// <summary>
  9245. /// [S5] Tray盘下料装备 - 出站接口
  9246. /// </summary>
  9247. /// <param name="plcNo"></param>
  9248. /// <param name="stationCode"></param>
  9249. /// <param name="stationName"></param>
  9250. private void S5出站接口(int plcNo, string stationCode, string stationName)
  9251. {
  9252. Stopwatch stopwatch1 = new Stopwatch();
  9253. Stopwatch stopwatch2 = new Stopwatch();
  9254. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  9255. string stationNameStr = stationCode + stationName;
  9256. string processItem = stationName; // 测试项目
  9257. try
  9258. {
  9259. stopwatch1.Start();
  9260. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  9261. //string batch_num = GlobalContext.BatchNumber; // 批次号
  9262. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  9263. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  9264. string sn = (string)s5PLCData["e1ProductSN"]; // 产品SN(载具SN码)
  9265. sn = sn.Replace("\0", "");
  9266. //string partNo = (string)s5PLCData["e1PartNo"]; // 物料码
  9267. //partNo = partNo.Replace("\0", "");
  9268. #region 查询载具上的产品信息
  9269. string cavityData = string.Empty;
  9270. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  9271. if (string.IsNullOrEmpty(cavityData))
  9272. cavityData = "";
  9273. if (snResult != 0)
  9274. {
  9275. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9276. writeToPLC_Flag1.Name = "e1MES_FLAG";
  9277. writeToPLC_Flag1.Adress = 2035;
  9278. writeToPLC_Flag1.Value = (short)4;
  9279. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag1);
  9280. stopwatch1.Stop();
  9281. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9282. return;
  9283. }
  9284. string[] cavitySNs = cavityData.Split('.');
  9285. string partNo = string.Empty;
  9286. if (cavitySNs != null && cavitySNs.Length >= 1)
  9287. partNo = cavitySNs[0];
  9288. #endregion 查询载具上的产品信息
  9289. int e1Result = (int)s5PLCData["e1Result"]; // 产品结果
  9290. bool pass = e1Result == 1;
  9291. stopwatch2.Start();
  9292. // 上传MES
  9293. List<TestItem> items = new List<TestItem>();
  9294. items.Add(new TestItem()
  9295. {
  9296. Parameter_name = "载具码",
  9297. Parameter_value = sn,
  9298. Parameter_unit = ""
  9299. });
  9300. items.Add(new TestItem()
  9301. {
  9302. Parameter_name = "载具穴号",
  9303. Parameter_value = "1",
  9304. Parameter_unit = ""
  9305. });
  9306. items.Add(new TestItem()
  9307. {
  9308. Parameter_name = "产品结果",
  9309. Parameter_value = e1Result == 1 ? "OK" : "NG",
  9310. Parameter_unit = ""
  9311. });
  9312. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  9313. , workorder_code, mtltmrk, partNo, pass, sn, "1");
  9314. //int result = result1 == 1 ? 1 : (GlobalContext.IsSendProcessData ? 4 : 1);
  9315. short result = result1 == 1 ? (short)1 : (short)3;
  9316. stopwatch2.Stop();
  9317. #region 存储绑定数据到 边线MES系统中
  9318. if (result == 1)
  9319. {
  9320. // 删除绑定信息
  9321. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  9322. if (resultMesR != 0)
  9323. {
  9324. result = 4;
  9325. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  9326. }
  9327. }
  9328. #endregion 存储绑定数据到 边线MES系统中
  9329. // MES_Flag 为MES报错
  9330. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9331. //Funs[plcNo].WriteMultipleRegisters<short>(2035, result); // 4代表上位机报警
  9332. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9333. writeToPLC_Flag.Name = "e1MES_FLAG";
  9334. writeToPLC_Flag.Adress = 2035;
  9335. writeToPLC_Flag.Value = result;
  9336. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  9337. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  9338. }
  9339. catch (Exception ex)
  9340. {
  9341. stopwatch2.Restart();
  9342. // MES_Flag 为4上位机报错
  9343. //Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)4); // 4代表上位机报警
  9344. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9345. writeToPLC_Flag.Name = "e1MES_FLAG";
  9346. writeToPLC_Flag.Adress = 2035;
  9347. writeToPLC_Flag.Value = (short)4;
  9348. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  9349. stopwatch2.Stop();
  9350. string str = ex.StackTrace;
  9351. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9352. }
  9353. stopwatch1.Stop();
  9354. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9355. }
  9356. /// <summary>
  9357. /// [S5] Tray盘下料装备 - 节拍接口
  9358. /// </summary>
  9359. /// <param name="plcNo">PLC编号</param>
  9360. /// <param name="stationNameStr">工站全称</param>
  9361. private void S5节拍接口(int plcNo, string stationNameStr)
  9362. {
  9363. Stopwatch stopwatch1 = new Stopwatch();
  9364. Stopwatch stopwatch2 = new Stopwatch();
  9365. string resultStr = string.Empty;
  9366. try
  9367. {
  9368. stopwatch1.Start();
  9369. string oEEType = ((int)s5PLCData["e1OEEType"]).ToString(); // 节拍类型(plc写入)
  9370. string e1OEEProductSN = (string)s5PLCData["e1OEEProductSN"]; // 载具SN
  9371. e1OEEProductSN = e1OEEProductSN.Replace("\0", "");
  9372. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  9373. if (!actionBool)
  9374. {
  9375. stopwatch2.Start();
  9376. // MES_Flag
  9377. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9378. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9379. writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  9380. writeToPLC_Flag1.Adress = 2088;
  9381. writeToPLC_Flag1.Value = (short)4;
  9382. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  9383. stopwatch2.Stop();
  9384. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9385. return;
  9386. }
  9387. string e1OEEPartNo = string.Empty; // 物料码
  9388. if (string.IsNullOrEmpty(e1OEEProductSN))
  9389. {
  9390. stopwatch2.Start();
  9391. // MES_Flag
  9392. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9393. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9394. writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  9395. writeToPLC_Flag1.Adress = 2088;
  9396. writeToPLC_Flag1.Value = (short)1;
  9397. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  9398. stopwatch2.Stop();
  9399. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9400. return;
  9401. }
  9402. else
  9403. { // 查产品SN
  9404. e1OEEPartNo = "Test"; // ZS
  9405. }
  9406. short e1OEEMES_FLAG = 0;
  9407. // 上传OEE
  9408. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, e1OEEPartNo, e1OEEProductSN);
  9409. e1OEEMES_FLAG = result.Item1;
  9410. resultStr = result.Item2;
  9411. stopwatch2.Start();
  9412. // MES_Flag
  9413. //Funs[plcNo].WriteMultipleRegisters<short>(2088, e1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9414. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9415. writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  9416. writeToPLC_Flag.Adress = 2088;
  9417. writeToPLC_Flag.Value = e1OEEMES_FLAG;
  9418. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  9419. stopwatch2.Stop();
  9420. }
  9421. catch (Exception ex)
  9422. {
  9423. string str = ex.StackTrace;
  9424. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9425. // MES_Flag
  9426. stopwatch2.Start();
  9427. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  9428. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9429. writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  9430. writeToPLC_Flag.Adress = 2088;
  9431. writeToPLC_Flag.Value = (short)4;
  9432. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  9433. stopwatch2.Stop();
  9434. }
  9435. stopwatch1.Stop();
  9436. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9437. }
  9438. /// <summary>
  9439. /// [S5] Tray盘下料装备 - AGV上料叫agv
  9440. /// </summary>
  9441. /// <param name="plcNo">PLC编号</param>
  9442. /// <param name="stationNameStr">工站全称</param>
  9443. private void S5AGV上料叫agv(int plcNo, string stationNameStr)
  9444. {
  9445. Stopwatch stopwatch1 = new Stopwatch();
  9446. Stopwatch stopwatch2 = new Stopwatch();
  9447. try
  9448. {
  9449. stopwatch1.Start();
  9450. // ZS 呼叫AGV
  9451. short e1AGVUpCall = 2;
  9452. stopwatch2.Start();
  9453. // e1AGVUpCall
  9454. //Funs[plcNo].WriteMultipleRegisters<short>(2120, e1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9455. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9456. writeToPLC_Flag.Name = "e1AGVUpCall";
  9457. writeToPLC_Flag.Adress = 2120;
  9458. writeToPLC_Flag.Value = e1AGVUpCall;
  9459. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  9460. stopwatch2.Stop();
  9461. }
  9462. catch (Exception ex)
  9463. {
  9464. string str = ex.StackTrace;
  9465. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9466. // e1AGVUpCall
  9467. stopwatch2.Start();
  9468. //Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  9469. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9470. writeToPLC_Flag.Name = "e1AGVUpCall";
  9471. writeToPLC_Flag.Adress = 2120;
  9472. writeToPLC_Flag.Value = (short)4;
  9473. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  9474. stopwatch2.Stop();
  9475. }
  9476. stopwatch1.Stop();
  9477. AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9478. }
  9479. /// <summary>
  9480. /// [S5] Tray盘下料装备 - AGV上料完成
  9481. /// </summary>
  9482. /// <param name="plcNo">PLC编号</param>
  9483. /// <param name="stationNameStr">工站全称</param>
  9484. private void S5AGV上料完成(int plcNo, string stationNameStr)
  9485. {
  9486. Stopwatch stopwatch1 = new Stopwatch();
  9487. Stopwatch stopwatch2 = new Stopwatch();
  9488. try
  9489. {
  9490. stopwatch1.Start();
  9491. // ZS AGV上料完成,让小车离开
  9492. short e1AGVUpEnd = 2;
  9493. stopwatch2.Start();
  9494. // e1AGVUpEnd
  9495. //Funs[plcNo].WriteMultipleRegisters<short>(2122, e1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9496. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9497. writeToPLC_Flag.Name = "e1AGVUpEnd";
  9498. writeToPLC_Flag.Adress = 2122;
  9499. writeToPLC_Flag.Value = e1AGVUpEnd;
  9500. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  9501. stopwatch2.Stop();
  9502. }
  9503. catch (Exception ex)
  9504. {
  9505. string str = ex.StackTrace;
  9506. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9507. // e1AGVUpEnd
  9508. stopwatch2.Start();
  9509. //Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  9510. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9511. writeToPLC_Flag.Name = "e1AGVUpEnd";
  9512. writeToPLC_Flag.Adress = 2122;
  9513. writeToPLC_Flag.Value = (short)4;
  9514. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  9515. stopwatch2.Stop();
  9516. }
  9517. stopwatch1.Stop();
  9518. AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9519. }
  9520. /// <summary>
  9521. /// [S5] Tray盘下料装备 - AGV下料叫agv
  9522. /// </summary>
  9523. /// <param name="plcNo">PLC编号</param>
  9524. /// <param name="stationNameStr">工站全称</param>
  9525. private void S5AGV下料叫agv(int plcNo, string stationNameStr)
  9526. {
  9527. Stopwatch stopwatch1 = new Stopwatch();
  9528. Stopwatch stopwatch2 = new Stopwatch();
  9529. try
  9530. {
  9531. stopwatch1.Start();
  9532. // ZS 呼叫AGV
  9533. short e1AGVDownCall = 2;
  9534. stopwatch2.Start();
  9535. // e1AGVDownCall
  9536. //Funs[plcNo].WriteMultipleRegisters<short>(2133, e1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9537. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9538. writeToPLC_Flag.Name = "e1AGVDownCall";
  9539. writeToPLC_Flag.Adress = 2133;
  9540. writeToPLC_Flag.Value = e1AGVDownCall;
  9541. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  9542. stopwatch2.Stop();
  9543. }
  9544. catch (Exception ex)
  9545. {
  9546. string str = ex.StackTrace;
  9547. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9548. // e1AGVDownCall
  9549. stopwatch2.Start();
  9550. //Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  9551. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9552. writeToPLC_Flag.Name = "e1AGVDownCall";
  9553. writeToPLC_Flag.Adress = 2133;
  9554. writeToPLC_Flag.Value = (short)4;
  9555. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  9556. stopwatch2.Stop();
  9557. }
  9558. stopwatch1.Stop();
  9559. AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9560. }
  9561. /// <summary>
  9562. /// [S5] Tray盘下料装备 - AGV下料完成
  9563. /// </summary>
  9564. /// <param name="plcNo">PLC编号</param>
  9565. /// <param name="stationNameStr">工站全称</param>
  9566. private void S5AGV下料完成(int plcNo, string stationNameStr)
  9567. {
  9568. Stopwatch stopwatch1 = new Stopwatch();
  9569. Stopwatch stopwatch2 = new Stopwatch();
  9570. try
  9571. {
  9572. stopwatch1.Start();
  9573. // ZS AGV上料完成,让小车离开
  9574. short e1AGVDownEnd = 2;
  9575. stopwatch2.Start();
  9576. // e1AGVDownEnd
  9577. //Funs[plcNo].WriteMultipleRegisters<short>(2135, e1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9578. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9579. writeToPLC_Flag.Name = "e1AGVDownEnd";
  9580. writeToPLC_Flag.Adress = 2135;
  9581. writeToPLC_Flag.Value = e1AGVDownEnd;
  9582. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  9583. stopwatch2.Stop();
  9584. }
  9585. catch (Exception ex)
  9586. {
  9587. string str = ex.StackTrace;
  9588. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9589. // e1AGVDownEnd
  9590. stopwatch2.Start();
  9591. //Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  9592. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9593. writeToPLC_Flag.Name = "e1AGVDownEnd";
  9594. writeToPLC_Flag.Adress = 2135;
  9595. writeToPLC_Flag.Value = (short)4;
  9596. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  9597. stopwatch2.Stop();
  9598. }
  9599. stopwatch1.Stop();
  9600. AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9601. }
  9602. #endregion [S5] Tray盘下料装备
  9603. #endregion PLC5 张超凡
  9604. #region 缓存读取到的PLC数据 与 需要写入的PLC数据
  9605. /// <summary>
  9606. /// PLC读取到的数据 -添加数据
  9607. /// </summary>
  9608. public static void SxPLCData_Add(ref Dictionary<string, object> sxPlcData, string newKey, object newValue)
  9609. {
  9610. if (sxPlcData.ContainsKey(newKey))
  9611. sxPlcData[newKey] = newValue;
  9612. else
  9613. sxPlcData.Add(newKey, newValue);
  9614. }
  9615. /// <summary>
  9616. /// PLC需要写入的数据 -添加数据
  9617. /// </summary>
  9618. public static void SxPLCWriteData_Add(ref Dictionary<string, WriteToPLC_Flag> sxPLCWriteData, string newKey, WriteToPLC_Flag newValue)
  9619. {
  9620. if (sxPLCWriteData.ContainsKey(newKey))
  9621. sxPLCWriteData[newKey] = newValue;
  9622. else
  9623. sxPLCWriteData.Add(newKey, newValue);
  9624. }
  9625. /// <summary>
  9626. /// PLC回写操作,写后清空flag
  9627. /// </summary>
  9628. /// <param name="modbusClient">modbus对象</param>
  9629. /// <param name="pLCReadDatas">读取到的数据字典</param>
  9630. /// <param name="pLCWriteDatas">需要写入的数据</param>
  9631. public static void PLCWriteData(ModbusClientHelper modbusClient, ref Dictionary<string, object> pLCReadDatas, ref Dictionary<string, WriteToPLC_Flag> pLCWriteDataDic)
  9632. {
  9633. if (pLCWriteDataDic != null && pLCWriteDataDic.Count > 0)
  9634. {
  9635. List<WriteToPLC_Flag> pLCWriteDatas = pLCWriteDataDic.Values.ToList();
  9636. for (int i = 0; i < pLCWriteDatas.Count; i++)
  9637. {
  9638. string mesFlagName = pLCWriteDatas[i].Name;
  9639. int mesFlagAdress = pLCWriteDatas[i].Adress;
  9640. short mesFlagValue = (short)pLCWriteDatas[i].Value; // short
  9641. if (mesFlagValue != 0) // 不为0则证明需要写入结果信息
  9642. {
  9643. // 先回写数据
  9644. List<WriteToPLC_Data> writeToPLCDatas = pLCWriteDatas[i].WriteToPLCDatas;
  9645. for (int j = 0; j < writeToPLCDatas.Count; j++)
  9646. {
  9647. int mesDataAdress = writeToPLCDatas[j].Adress;
  9648. PLCValueType mesDataType = writeToPLCDatas[j].ValueType;
  9649. switch (mesDataType)
  9650. {
  9651. case PLCValueType.Short:
  9652. short mesDataValueShort = (short)writeToPLCDatas[j].Value;
  9653. modbusClient.WriteMultipleRegisters<short>(mesDataAdress, mesDataValueShort);
  9654. break;
  9655. case PLCValueType.String:
  9656. string mesDataValueStr = (string)writeToPLCDatas[j].Value;
  9657. int mesDataValueStrLength = writeToPLCDatas[j].ValueTypeStrLength;
  9658. modbusClient.WriteMultipleRegisters<string>(mesDataAdress, mesDataValueStr, mesDataValueStrLength);
  9659. break;
  9660. }
  9661. }
  9662. // 再回写信号
  9663. modbusClient.WriteMultipleRegisters<short>(mesFlagAdress, mesFlagValue);
  9664. // 存储读取数据的字典
  9665. pLCReadDatas[mesFlagName] = (int)mesFlagValue;
  9666. // 存储写入数据的字典 - 清空写入值
  9667. pLCWriteDatas[i].Value = (short)0;
  9668. pLCWriteDataDic[mesFlagName] = pLCWriteDatas[i];
  9669. }
  9670. }
  9671. }
  9672. }
  9673. /// <summary>
  9674. /// 提交点检数据到MES - 取数据库中缓存的 点检数据
  9675. /// </summary>
  9676. /// <param name="no">3</param>
  9677. /// <param name="stationCode">设备编号</param>
  9678. /// <param name="stationNameStr">设备名称</param>
  9679. /// <param name="plcOrder">车间订单号</param>
  9680. private void SubmitOneCheckDataToMESByDB(int plcNo, int stationCode, string stationNameStr, string plcOrder)
  9681. {
  9682. try
  9683. {
  9684. /// [S2]FCT (2-上传点检数据;102-清空该工单该工单的所有点检项缓存)
  9685. /// [S3]值板机 (3-上传点检数据;103-清空该工单该工单的所有点检项缓存)
  9686. /// [S4]取放桁架 (4-上传点检数据;104-清空该工单该工单的所有点检项缓存)
  9687. /// [S6]CCD检测 (6-上传点检数据;106-清空该工单该工单的所有点检项缓存)
  9688. int result1 = 0;
  9689. switch (stationCode)
  9690. {
  9691. case 2:
  9692. case 3:
  9693. case 4:
  9694. case 6:
  9695. result1 = SubmitToMESByDB(stationCode.ToString(), stationNameStr, plcOrder);
  9696. break;
  9697. case 102:
  9698. result1 = ClearOneCheckDataByDB("2", stationNameStr, plcOrder);
  9699. break;
  9700. case 103:
  9701. result1 = ClearOneCheckDataByDB("3", stationNameStr, plcOrder);
  9702. break;
  9703. case 104:
  9704. result1 = ClearOneCheckDataByDB("4", stationNameStr, plcOrder);
  9705. break;
  9706. case 106:
  9707. result1 = ClearOneCheckDataByDB("6", stationNameStr, plcOrder);
  9708. break;
  9709. default:
  9710. // MES_Flag 为“6未找到正确设备编号”
  9711. Funs[plcNo].WriteMultipleRegisters<int>(2406, 6);
  9712. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!未找到需要点检的正确设备编号");
  9713. return;
  9714. }
  9715. short result = result1 == 1 ? (short)1 : (short)2;
  9716. Funs[plcNo].WriteMultipleRegisters<int>(2406, result); // MES_Flag 为4MES报错
  9717. OnMessage(LogType.Debug, $"PLC{plcNo}_PLC通知MES上传点检数据运行完毕!-Write" + (result == 1 ? "成功!" : "失败!"));
  9718. }
  9719. catch (Exception ex)
  9720. {
  9721. // MES_Flag 为2上位机报错
  9722. Funs[plcNo].WriteMultipleRegisters<int>(2406, 2);
  9723. string str = ex.StackTrace;
  9724. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9725. }
  9726. }
  9727. #endregion 缓存读取到的PLC数据 与 需要写入的PLC数据
  9728. #region UI刷新
  9729. /// <summary>
  9730. /// 更新商品信息的UI + 下发产品信息(SN)
  9731. /// </summary>
  9732. private void UpdateProductInfo()
  9733. {
  9734. currentWC.Text = GlobalContext.WorkOrderCode; // 订单号
  9735. currentMtltmrk.Text = GlobalContext.Mtltmrk; // 产品型号
  9736. //currentBN.Text = GlobalContext.BatchNumber; // 批次号
  9737. //txt_CurSupplierCode.Text = ""; // 供应商代号
  9738. }
  9739. /// <summary>
  9740. /// 更新PLC连接状态的UI
  9741. /// </summary>
  9742. /// <param name="no">PLC编号</param>
  9743. /// <param name="status">状态</param>
  9744. private void UpdatePLCMonitor(int imgNo, int plcNo, int status)
  9745. {
  9746. if (this != null && !this.IsDisposed)
  9747. {
  9748. switch (imgNo)
  9749. {
  9750. case 1:
  9751. this.BeginInvoke(new Action(() =>
  9752. {
  9753. picPLC.Image = imageListState.Images[status];
  9754. }));
  9755. break;
  9756. case 2:
  9757. this.BeginInvoke(new Action(() =>
  9758. {
  9759. pictureBox2.Image = imageListState.Images[status];
  9760. }));
  9761. break;
  9762. case 3:
  9763. this.BeginInvoke(new Action(() =>
  9764. {
  9765. pictureBox3.Image = imageListState.Images[status];
  9766. }));
  9767. break;
  9768. case 4:
  9769. this.BeginInvoke(new Action(() =>
  9770. {
  9771. pictureBox4.Image = imageListState.Images[status];
  9772. }));
  9773. break;
  9774. case 5:
  9775. this.BeginInvoke(new Action(() =>
  9776. {
  9777. pictureBox5.Image = imageListState.Images[status];
  9778. }));
  9779. break;
  9780. case 6:
  9781. this.BeginInvoke(new Action(() =>
  9782. {
  9783. pictureBox6.Image = imageListState.Images[status];
  9784. }));
  9785. break;
  9786. case 7:
  9787. this.BeginInvoke(new Action(() =>
  9788. {
  9789. pictureBox7.Image = imageListState.Images[status];
  9790. }));
  9791. break;
  9792. case 8:
  9793. this.BeginInvoke(new Action(() =>
  9794. {
  9795. pictureBox8.Image = imageListState.Images[status];
  9796. }));
  9797. break;
  9798. default:
  9799. break;
  9800. }
  9801. }
  9802. Task.Run(() => // 更新PLC交互页的指示灯
  9803. {
  9804. try
  9805. {
  9806. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  9807. {
  9808. Form_Main.formPLCDB.UpdatePLCFunMonitor(plcNo, status);
  9809. }
  9810. }
  9811. catch { }
  9812. });
  9813. }
  9814. #endregion UI刷新
  9815. #region 日志
  9816. /// <summary>
  9817. /// 添加各工位运行日志(同步至PLC交互页面)
  9818. /// </summary>
  9819. /// <param name="stationNameStr">工站名称</param>
  9820. /// <param name="logType">日志类型</param>
  9821. /// <param name="message">日志内容</param>
  9822. /// <param name="snNumber">产品数字SN</param>
  9823. public void AddMessage_Station(string stationNameStr, LogType logType, string message, string snNumber = "")
  9824. {
  9825. if (!(stationNameStr.Equals("获取设备报警数据与状态信息")
  9826. && (message.Contains("更新整线运行数据完毕") || message.Contains("更新整线报警数据完毕"))
  9827. ))
  9828. {
  9829. AddMessage(logType, message); // 首页展示+日志记录
  9830. }
  9831. PLCDBFormMessage plcMessage = new PLCDBFormMessage()
  9832. {
  9833. StationName = stationNameStr,
  9834. SnNumber = snNumber,
  9835. Message = message,
  9836. CreateTime = DateTime.Now
  9837. };
  9838. // PLC交互页展示
  9839. Task.Run(() =>
  9840. {
  9841. try
  9842. {
  9843. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  9844. {
  9845. Form_Main.formPLCDB.UpdateMessage(plcMessage);
  9846. }
  9847. }
  9848. catch { }
  9849. });
  9850. }
  9851. /// <summary>
  9852. /// 添加运行日志
  9853. /// </summary>
  9854. /// <param name="logType">日志类型</param>
  9855. /// <param name="message">日志内容</param>
  9856. public void AddMessage(LogType logType, string message)
  9857. {
  9858. OnMessage(logType, message);
  9859. string date = DateTime.Now.ToString("yyyy/MM/dd");
  9860. string time = DateTime.Now.ToString("HH:mm:ss:fff");
  9861. string msgShow = time + "--> " + message + "\r\n";
  9862. this.BeginInvoke(new Action(() =>
  9863. {
  9864. systemLog.Rows.Insert(0, date, time, message);
  9865. if (systemLog.Rows.Count >= 100)
  9866. systemLog.Rows.RemoveAt(systemLog.Rows.Count - 1);
  9867. }));
  9868. }
  9869. /// <summary>
  9870. /// 添加运行日志-保存
  9871. /// </summary>
  9872. /// <param name="logType">日志类型</param>
  9873. /// <param name="message">日志内容</param>
  9874. private void OnMessage(LogType logType, string msg)
  9875. {
  9876. MessageEvent?.Invoke(logType, msg);
  9877. }
  9878. /// <summary>
  9879. /// 保存PLC写入日志
  9880. /// </summary>
  9881. /// <param name="logType"></param>
  9882. /// <param name="logValue"></param>
  9883. private void WritePLCLog(LogType logType, string logValue)
  9884. {
  9885. switch ((int)logType)
  9886. {
  9887. case 0:
  9888. _PLCLogNet.WriteDebug(logValue);
  9889. break;
  9890. case 1:
  9891. _PLCLogNet.WriteInfo(logValue);
  9892. break;
  9893. case 2:
  9894. _PLCLogNet.WriteWarn(logValue);
  9895. break;
  9896. case 3:
  9897. _PLCLogNet.WriteError(logValue);
  9898. break;
  9899. default:
  9900. _PLCLogNet.WriteFatal(logValue);
  9901. break;
  9902. }
  9903. }
  9904. /// <summary>
  9905. /// IOT Mqtt回调方法- With DataId
  9906. /// </summary>
  9907. /// <param name="id"></param>
  9908. /// <param name="v"></param>
  9909. /// <param name="dataId"></param>
  9910. public void CallbackWithDataId(string id, string msg, string dataId)
  9911. {
  9912. //_MqttLogNet.WriteInfo("-------CallbackWithDataId-------");
  9913. //byte[] buffer1 = Encoding.Default.GetBytes(v);
  9914. //byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);
  9915. //string strBuffer = Encoding.Default.GetString(buffer2, 0, buffer2.Length);
  9916. //Console.WriteLine("{0} -> {1} {2}", id, strBuffer, dataId);
  9917. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  9918. _IOTMqttLogNet.WriteInfo($"{datetime}-> [消息ID:{id}][事件ID:{dataId}]{msg}");
  9919. }
  9920. /// <summary>
  9921. /// AGV Mqtt回调方法- 记录Log并处理数据
  9922. /// </summary>
  9923. /// <param name="obj"></param>
  9924. private void AGVMqttShowLog(ResultData_MQTT resultData_MQTT)
  9925. {
  9926. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  9927. _AGVMqttLogNet.WriteInfo($"{datetime}->返回结果:{resultData_MQTT.ResultCode},返回信息:{resultData_MQTT.ResultMsg}");
  9928. // 接收到的信息
  9929. string topic = (string)resultData_MQTT.ResultObject1; // 订阅的标识
  9930. string jsonData = (string)resultData_MQTT.ResultObject2; // 订阅的数据
  9931. if (resultData_MQTT.ResultCode == 1 && !string.IsNullOrEmpty(topic)) // 是接收到的数据
  9932. {
  9933. }
  9934. }
  9935. #endregion 日志
  9936. /// <summary>
  9937. /// 实例化报警字典
  9938. /// </summary>
  9939. private void InitalDicAlarm()
  9940. {
  9941. #region 第一个工站(这里未区分工位,所以下面出现的‘工位代码’使用‘线别代码’代替)
  9942. List<Alarm> keyValues1 = new List<Alarm>
  9943. {
  9944. #region 第一组报警(电机)
  9945. new Alarm { 报警类型 = "电机故障", 报警详情 = "料盘搬运_Y轴电机故障" ,关联的PLC地址 = 5100 },
  9946. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_X轴电机故障" ,关联的PLC地址 = 5101 },
  9947. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_Z轴电机故障" ,关联的PLC地址 = 5102 },
  9948. new Alarm { 报警类型 = "电机故障", 报警详情 = "载具搬运_X轴电机故障" ,关联的PLC地址 = 5103 },
  9949. new Alarm { 报警类型 = "电机故障", 报警详情 = "镭射_X轴电机故障" ,关联的PLC地址 = 5104 },
  9950. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_X轴电机故障" ,关联的PLC地址 = 5105 },
  9951. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_Z轴电机故障" ,关联的PLC地址 = 5106 },
  9952. new Alarm { 报警类型 = "电机故障", 报警详情 = "下相机_X轴电机故障" ,关联的PLC地址 = 5107 },
  9953. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_Y轴电机故障" ,关联的PLC地址 = 5108 },
  9954. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_X轴电机故障" ,关联的PLC地址 = 5109 },
  9955. #endregion 第一组报警(电机)
  9956. #region 第二组报警(气缸)
  9957. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料进退气缸故障" ,关联的PLC地址 = 5200 },
  9958. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料升降气缸故障" ,关联的PLC地址 = 5201 },
  9959. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓顶升气缸故障" ,关联的PLC地址 = 5202 },
  9960. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体取料夹爪气缸故障" ,关联的PLC地址 = 5203 },
  9961. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料仓顶升气缸故障" ,关联的PLC地址 = 5204 },
  9962. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料平移气缸故障" ,关联的PLC地址 = 5205 },
  9963. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料升降气缸故障" ,关联的PLC地址 = 5206 },
  9964. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料夹爪气缸故障" ,关联的PLC地址 = 5207 },
  9965. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料旋转气缸故障" ,关联的PLC地址 = 5208 },
  9966. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装平移气缸故障" ,关联的PLC地址 = 5209 },
  9967. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装升降气缸故障" ,关联的PLC地址 = 5210 },
  9968. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装夹爪气缸故障" ,关联的PLC地址 = 5211 },
  9969. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装撑开气缸故障" ,关联的PLC地址 = 5212 },
  9970. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸1故障" ,关联的PLC地址 = 5213 },
  9971. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸2故障" ,关联的PLC地址 = 5214 },
  9972. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具下料移载气缸故障" ,关联的PLC地址 = 5215 },
  9973. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具侧推气缸故障" ,关联的PLC地址 = 5216 },
  9974. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具回流气缸故障" ,关联的PLC地址 = 5217 },
  9975. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2压料气缸故障" ,关联的PLC地址 = 5218 },
  9976. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2电测气缸故障" ,关联的PLC地址 = 5219 },
  9977. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2气密气缸故障" ,关联的PLC地址 = 5220 },
  9978. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3下压气缸故障" ,关联的PLC地址 = 5221 },
  9979. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3上顶气缸故障" ,关联的PLC地址 = 5222 },
  9980. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位5相机升降气缸故障" ,关联的PLC地址 = 5223 },
  9981. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组升降气缸故障" ,关联的PLC地址 = 5224 },
  9982. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸1故障" ,关联的PLC地址 = 5225 },
  9983. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸2故障" ,关联的PLC地址 = 5226 },
  9984. new Alarm { 报警类型 = "气缸故障", 报警详情 = "机械手夹爪气缸故障" ,关联的PLC地址 = 5227 },
  9985. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位4:镭射压料气缸故障" ,关联的PLC地址 = 5228 },
  9986. #endregion 第二组报警(气缸)
  9987. #region 第三组报警(其他故障)
  9988. new Alarm { 报警类型 = "其他故障", 报警详情 = "上料处缺料报警" ,关联的PLC地址 = 5300 },
  9989. new Alarm { 报警类型 = "其他故障", 报警详情 = "震盘缺料报警" ,关联的PLC地址 = 5301 },
  9990. new Alarm { 报警类型 = "其他故障", 报警详情 = "成品仓料满报警" ,关联的PLC地址 = 5302 },
  9991. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照超时报警" ,关联的PLC地址 = 5303 },
  9992. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照NG报警" ,关联的PLC地址 = 5304 },
  9993. new Alarm { 报警类型 = "其他故障", 报警详情 = "玻璃门打开报警" ,关联的PLC地址 = 5305 },
  9994. #endregion 第三组报警(其他故障)
  9995. };
  9996. DicAlarms_Cur.Add(GlobalContext.LineCode, keyValues1); // 这里使用线体代替工位
  9997. #endregion 第一个工站(这里使用线体代替工位)
  9998. # region 第二个工站-原来的写法(废弃)
  9999. //keyValues = new Dictionary<int, AlarmData[]>();
  10000. ////1
  10001. //dicAlarmName = new Dictionary<int, Alarm>();
  10002. //dicAlarmName.Add(0, new Alarm { Name = "M01衬套组模组X电机报警" });
  10003. //dicAlarmName.Add(1, new Alarm { Name = "M02衬套组模组Y电机报警" });
  10004. //dicAlarmName.Add(2, new Alarm { Name = "M03衬套组模组Z电机报警" });
  10005. //dicAlarmName.Add(3, new Alarm { Name = "M04衬套组模组U电机报警" });
  10006. //dicAlarmName.Add(4, new Alarm { Name = "M05外流线皮带电机报警" });
  10007. //alarmDatas = new AlarmData[dicAlarmName.Count];
  10008. //for (int i = 0; i < dicAlarmName.Count; i++)
  10009. //{
  10010. // alarmDatas[i] = new AlarmData();
  10011. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  10012. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  10013. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  10014. // alarmDatas[i].AlarmType = 1;
  10015. //}
  10016. //keyValues.Add(1, alarmDatas);
  10017. ////2
  10018. //dicAlarmName = new Dictionary<int, Alarm>();
  10019. //dicAlarmName.Add(0, new Alarm { Name = "C01定位气缸故障" });
  10020. //dicAlarmName.Add(1, new Alarm { Name = "C02左推料气缸故障" });
  10021. //dicAlarmName.Add(2, new Alarm { Name = "C03右推料气缸故障" });
  10022. //dicAlarmName.Add(3, new Alarm { Name = "C04左压料气缸故障" });
  10023. //dicAlarmName.Add(4, new Alarm { Name = "C05右压料气缸故障" });
  10024. //dicAlarmName.Add(5, new Alarm { Name = "C06切料气缸故障" });
  10025. //dicAlarmName.Add(6, new Alarm { Name = "C07左入料吹气气缸故障" });
  10026. //dicAlarmName.Add(7, new Alarm { Name = "C08右入料吹气气缸故障" });
  10027. //alarmDatas = new AlarmData[dicAlarmName.Count];
  10028. //for (int i = 0; i < dicAlarmName.Count; i++)
  10029. //{
  10030. // alarmDatas[i] = new AlarmData();
  10031. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  10032. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  10033. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  10034. // alarmDatas[i].AlarmType = 2;
  10035. //}
  10036. //keyValues.Add(2, alarmDatas);
  10037. ////3
  10038. //dicAlarmName = new Dictionary<int, Alarm>();
  10039. //dicAlarmName.Add(0, new Alarm { Name = "安全门报警" });
  10040. //dicAlarmName.Add(1, new Alarm { Name = "联机通信故障" });
  10041. //dicAlarmName.Add(2, new Alarm { Name = "连续NG报警" });
  10042. //dicAlarmName.Add(3, new Alarm { Name = "合格率低于设定值报警" });
  10043. //alarmDatas = new AlarmData[dicAlarmName.Count];
  10044. //for (int i = 0; i < dicAlarmName.Count; i++)
  10045. //{
  10046. // alarmDatas[i] = new AlarmData();
  10047. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-3";
  10048. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  10049. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  10050. // alarmDatas[i].AlarmType = 3;
  10051. //}
  10052. //keyValues.Add(3, alarmDatas);
  10053. //DicAlarms.Add(2, keyValues);
  10054. #endregion 第二个工站-原来的写法(废弃)
  10055. }
  10056. }
  10057. }