Form_Home.cs 595 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207
  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. if (GlobalContext.IsUsePLC2)
  142. //Funs.Add(2, new ModbusClientHelper(GlobalContext.Machine2Address, GlobalContext.MachinePort, 2001)); // FCT(板测),
  143. FunsEip.Add(2, new Inovance_EIP(GlobalContext.PC2Address, GlobalContext.Machine2Address)); //OP20 顶盖上料设备
  144. if (GlobalContext.IsUsePLC3)
  145. FunsEip.Add(3, new Inovance_EIP(GlobalContext.PC3Address, GlobalContext.Machine3Address)); //OP30 点胶设备
  146. if (GlobalContext.IsUsePLC4)
  147. FunsEip.Add(4, new Inovance_EIP(GlobalContext.PC4Address, GlobalContext.Machine4Address)); //OP40 3D胶线检测
  148. if (GlobalContext.IsUsePLC5)
  149. FunsEip.Add(5, new Inovance_EIP(GlobalContext.PC5Address, GlobalContext.Machine5Address)); //OP50 ADD PCB板上料
  150. if (GlobalContext.IsUsePLC6)
  151. FunsEip.Add(6, new Inovance_EIP(GlobalContext.PC6Address, GlobalContext.Machine6Address)); //OP60 顶盖装配
  152. if (GlobalContext.IsUsePLC7)
  153. FunsEip.Add(7, new Inovance_EIP(GlobalContext.PC7Address, GlobalContext.Machine7Address)); //OP70 锁螺丝
  154. if (GlobalContext.IsUsePLC8)
  155. FunsEip.Add(8, new Inovance_EIP(GlobalContext.PC8Address, GlobalContext.Machine8Address)); //OP80 3D螺丝高度检测,NG出料站
  156. if (GlobalContext.IsUsePLC9)
  157. FunsEip.Add(9, new Inovance_EIP(GlobalContext.PC9Address, GlobalContext.Machine9Address)); //OP90 下料站
  158. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  159. {
  160. if (plcEIP != null)
  161. {
  162. try
  163. {
  164. (int, string) result = plcEIP.Connect();
  165. }
  166. catch (Exception ex)
  167. {
  168. MessageBox.Show($"PLC[{plcEIP._pcIPStr}]连接失败!失败信息:" + ex.Message,
  169. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  170. }
  171. }
  172. }
  173. /*
  174. //plc1Alarm.Connect();
  175. foreach (ModbusClientHelper modbusClient in Funs.Values)
  176. {
  177. if (modbusClient != null)
  178. {
  179. try
  180. {
  181. modbusClient.Connect();
  182. }
  183. catch (Exception ex)
  184. {
  185. MessageBox.Show($"PLC[{modbusClient.IPAddress}:{modbusClient.Port}]连接失败!失败信息:" + ex.Message,
  186. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  187. }
  188. }
  189. }
  190. */
  191. // 采集任务
  192. Task TaskReadAlarm = new Task(ReadAlarmAllPLC); // 线程-获取线体报警数据
  193. List<Task> TaskReadProcess = new List<Task>(); // 线程-触发点位(PLC)的线程
  194. //TaskReadProcess.Add(new Task(() => { ReadStation_DownOrderInfo(1); })); // 下发机种
  195. if (GlobalContext.IsUsePLC1)
  196. TaskReadProcess.Add(new Task(() => { ReadStation_S1(1); })); //OP10 壳体清洁上料装备
  197. if (GlobalContext.IsUsePLC2)
  198. TaskReadProcess.Add(new Task(() => { ReadStation_S2(2); })); //OP20 顶盖上料设备
  199. if (GlobalContext.IsUsePLC3)
  200. TaskReadProcess.Add(new Task(() => { ReadStation_S3(3); })); //OP30 点胶设备
  201. if (GlobalContext.IsUsePLC4)
  202. TaskReadProcess.Add(new Task(() => { ReadStation_S4(4); })); //OP40 点胶检测设备
  203. if (GlobalContext.IsUsePLC5)
  204. TaskReadProcess.Add(new Task(() => { ReadStation_S5(5); })); //OP50 ADD PCB板上料设备
  205. if (GlobalContext.IsUsePLC6)
  206. TaskReadProcess.Add(new Task(() => { ReadStation_S6(6); })); //OP60 顶盖装配设备
  207. if (GlobalContext.IsUsePLC7)
  208. TaskReadProcess.Add(new Task(() => { ReadStation_S7(7); })); //OP70 锁螺丝设备
  209. if (GlobalContext.IsUsePLC8)
  210. TaskReadProcess.Add(new Task(() => { ReadStation_S8(8); })); //OP80 3D螺丝高度检测设备
  211. if (GlobalContext.IsUsePLC9)
  212. TaskReadProcess.Add(new Task(() => { ReadStation_S9(9); }));
  213. #region 初始化
  214. try
  215. {
  216. // 开启边线MES(绑定/查询数据)
  217. //int mesRoute = XiaomiMES_RouteCommunication.Init();
  218. //if (mesRoute == 0)
  219. //{
  220. // //picMESStatus.Image = imageListState.Images[1];
  221. // //GlobalContext.MESIsConnect = true;
  222. // AddMessage(LogType.Info, "小米MES边线初始连接成功!");
  223. //}
  224. //else
  225. //{
  226. // //picMESStatus.Image = imageListState.Images[0];
  227. // //GlobalContext.MESIsConnect = false;
  228. // AddMessage(LogType.Info, $"小米MES边线初始连接失败!");
  229. //}
  230. // 开启MES(Http)
  231. if (GlobalContext.IsUseMES)
  232. {
  233. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  234. if (mesret)
  235. {
  236. picMESStatus.Image = imageListState.Images[1];
  237. GlobalContext.MESIsConnect = true;
  238. AddMessage(LogType.Info, "小米MES初始连接成功!");
  239. }
  240. else
  241. {
  242. picMESStatus.Image = imageListState.Images[0];
  243. GlobalContext.MESIsConnect = false;
  244. AddMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]初始连接失败!");
  245. }
  246. }
  247. // 开启IOT(MQTT)
  248. if (GlobalContext.IsUseIot)
  249. {
  250. string addr = GlobalContext.MQTTServerHost;
  251. int port = GlobalContext.MQTTServerPort;
  252. //生产环境需要修改
  253. int qmttResult = XiaomiMqttClient_Extend.OpenWithMqttServer("127.0.0.1", 6666, GlobalContext.MqttServerPath, GlobalContext.MqttServerName);
  254. XiaomiMqttResponse_ErrCode response_ErrCode = (XiaomiMqttResponse_ErrCode)qmttResult;
  255. if (response_ErrCode == XiaomiMqttResponse_ErrCode.OK)
  256. {
  257. picIot.Image = imageListState.Images[1];
  258. AddMessage(LogType.Info, "小米IOT MQTT初始连接成功!");
  259. // 设置回调函数
  260. //XiaomiMqttClient_Extend.SetCallbackWithDataId(CallbackWithDataId);
  261. // 配置参数
  262. XiaomiMqttLoginFunAndParam param = new XiaomiMqttLoginFunAndParam();
  263. // fds
  264. param.parameter.fds.address = "http://file-cm.be.mi.com/file/x5/file/upload/mqtt";
  265. param.parameter.fds.appId = "Auto-Soft";
  266. param.parameter.fds.appKey = "d11ec2b9-0e7a-4086-a80c-a1ec716e0896";
  267. // mes
  268. param.parameter.mes.address = GlobalContext.ServerIp;
  269. param.parameter.mes.appId = GlobalContext.MESAppId;
  270. param.parameter.mes.appKey = GlobalContext.MESAppKey;
  271. // mqtt
  272. param.parameter.mqtt.address = GlobalContext.MQTTServerHost;
  273. param.parameter.mqtt.port = GlobalContext.MQTTServerPort;
  274. param.parameter.mqtt.username = GlobalContext.MQTTAppId;
  275. param.parameter.mqtt.password = GlobalContext.MQTTAppPwd;
  276. // 设备配置
  277. param.parameter.equipment.factoryCode = GlobalContext.Factory_Code;
  278. if (GlobalContext.IsUsePLC1)
  279. {
  280. param.parameter.equipment.deviceCode = GlobalContext.S1_device_code; // 装备编码
  281. param.parameter.equipment.stationCode = GlobalContext.S1_station; // ⼯位Id
  282. }
  283. if (GlobalContext.IsUsePLC2)
  284. {
  285. param.parameter.equipment.deviceCode = GlobalContext.S2_device_code; // 装备编码
  286. param.parameter.equipment.stationCode = GlobalContext.S2_station; // ⼯位Id
  287. }
  288. if (GlobalContext.IsUsePLC3)
  289. {
  290. param.parameter.equipment.deviceCode = GlobalContext.s3_1_device_code; // 装备编码
  291. param.parameter.equipment.stationCode = GlobalContext.s3_1_station; // ⼯位Id
  292. }
  293. if (GlobalContext.IsUsePLC4)
  294. {
  295. param.parameter.equipment.deviceCode = GlobalContext.s4_device_code; // 装备编码
  296. param.parameter.equipment.stationCode = GlobalContext.s4_station; // ⼯位Id
  297. }
  298. if (GlobalContext.IsUsePLC5)
  299. {
  300. param.parameter.equipment.deviceCode = GlobalContext.s5_device_code; // 装备编码
  301. param.parameter.equipment.stationCode = GlobalContext.s5_station; // ⼯位Id
  302. }
  303. if (GlobalContext.IsUsePLC6)
  304. {
  305. param.parameter.equipment.deviceCode = GlobalContext.s6_device_code; // 装备编码
  306. param.parameter.equipment.stationCode = GlobalContext.s6_station; // ⼯位Id
  307. }
  308. if (GlobalContext.IsUsePLC7)
  309. {
  310. param.parameter.equipment.deviceCode = GlobalContext.s7_1_device_code; // 装备编码
  311. param.parameter.equipment.stationCode = GlobalContext.s7_1_station; // ⼯位Id
  312. }
  313. if (GlobalContext.IsUsePLC8)
  314. {
  315. param.parameter.equipment.deviceCode = GlobalContext.s8_device_code; // 装备编码
  316. param.parameter.equipment.stationCode = GlobalContext.s8_station; // ⼯位Id
  317. }
  318. if (GlobalContext.IsUsePLC9)
  319. {
  320. param.parameter.equipment.deviceCode = GlobalContext.s9_device_code; // 装备编码
  321. param.parameter.equipment.stationCode = GlobalContext.s9_station; // ⼯位Id
  322. }
  323. param.parameter.equipment.project = GlobalContext.Project_Code;
  324. param.parameter.equipment.productMode = "debug";
  325. //
  326. param.parameter.other.logLevel = 0;
  327. param.parameter.other.LogPath = GlobalContext.WorkLogDir;
  328. XiaomiMqttClient_Extend.ParameterConfig(param);
  329. }
  330. else
  331. {
  332. picIot.Image = imageListState.Images[0];
  333. AddMessage(LogType.Info, $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]初始连接失败!--- {response_ErrCode.ToString()}");
  334. }
  335. }
  336. // 开启AGV(Http与MQTT)
  337. if (GlobalContext.IsUseAGV)
  338. {
  339. // AGV HTTP
  340. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  341. if (mesret1)
  342. {
  343. picAgvHttp.Image = imageListState.Images[1];
  344. AddMessage(LogType.Info, "AGV Http初始连接成功!");
  345. }
  346. else
  347. {
  348. picAgvHttp.Image = imageListState.Images[0];
  349. AddMessage(LogType.Info, $"AGV Http[{GlobalContext.AGVHttpHost}]初始连接失败!");
  350. }
  351. string agvMqttIp = GlobalContext.MQTTServerHost;
  352. int agvMqttPort = GlobalContext.MQTTServerPort;
  353. Action<ResultData_MQTT> callback = AGVMqttShowLog;
  354. ResultData_MQTT result_MQTT = _MQTTHelper.CreateMQTTClientAndStart(agvMqttIp, agvMqttPort, null, null, callback).Result; // 连接MQTT服务器
  355. // AGV MQTT
  356. if (result_MQTT.ResultCode == 1)
  357. {
  358. picAgvMqtt.Image = imageListState.Images[1];
  359. GlobalContext.AGVMQTTIsConnect = true;
  360. AddMessage(LogType.Info, "小米AGV MQTT初始连接成功!");
  361. ResultData_MQTT result = XiaomiAGVMQTT_Base.DeviceTopicAGV(ref _MQTTHelper, GlobalContext.AGVMQTTDeviceCode);
  362. AddMessage(LogType.Info, $"小米AGV MQTT订阅{GlobalContext.AGVMQTTDeviceCode}--- [{result.ResultCode}]{result.ResultMsg}!");
  363. }
  364. else
  365. {
  366. picAgvMqtt.Image = imageListState.Images[0];
  367. GlobalContext.AGVMQTTIsConnect = false;
  368. AddMessage(LogType.Info, $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]初始连接失败!--- [{result_MQTT.ResultCode}]{result_MQTT.ResultMsg}");
  369. }
  370. }
  371. // 持续监视MES、IOT、AGV HTTP、AGV MQTT连接状态
  372. Task.Run(MonitorMESConnect);
  373. // 查询PLC连接状态
  374. foreach (int plcNo in FunsEip.Keys)
  375. {
  376. bool connected = FunsEip[plcNo].IsConnected;
  377. if (connected)
  378. {
  379. string msg = plcNo.ToString() + "工位初始连接成功---" + FunsEip[plcNo]._pcIPStr;
  380. AddMessage(LogType.Info, msg);
  381. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI
  382. }
  383. else
  384. {
  385. string msg = plcNo.ToString() + "工位初始连接失败---" + FunsEip[plcNo]._pcIPStr;
  386. AddMessage(LogType.Info, msg);
  387. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  388. }
  389. }
  390. // PLC4时 初始化扫码器TCP
  391. //if (GlobalContext.IsUsePLC4)
  392. // HpTCPClientInit();
  393. // 开启PLC的业务处理线程-监听PLC点位+状态
  394. foreach (Task task in TaskReadProcess)
  395. {
  396. if (task != null)
  397. task.Start();
  398. }
  399. //// 开启iot的线程
  400. TaskReadAlarm.Start();
  401. ////下传MES信息给1工位(先判断下plc对象数量)
  402. //if (Funs.Count > 1)
  403. // DownLoadProductInfo(1);
  404. AddMessage(LogType.Info, "程序初始化完成");
  405. }
  406. catch (Exception ex)
  407. {
  408. string str = ex.StackTrace;
  409. this.BeginInvoke(new Action(() =>
  410. {
  411. AddMessage(LogType.Error, "初始化PLC连接失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  412. }));
  413. }
  414. #endregion
  415. }
  416. catch (Exception ex)
  417. {
  418. string str = ex.StackTrace;
  419. OnMessage(LogType.Info, "主窗体的首页初始化出错!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
  420. if (ex.Message != null && ex.Message.Contains("timed out"))
  421. MessageBox.Show("主窗体的首页初始化出错!异常信息:PLC连接超时!" + ex.Message);
  422. else
  423. MessageBox.Show("主窗体的首页初始化出错!异常信息:" + ex.Message);
  424. }
  425. }
  426. /// <summary>
  427. /// 窗体关闭事件
  428. /// </summary>
  429. private void Form_Home_FormClosed(object sender, FormClosedEventArgs e)
  430. {
  431. Closed2();
  432. }
  433. public void Closed2()
  434. {
  435. try
  436. {
  437. IsRun = false;
  438. Thread.Sleep(IntervalReadPLC);
  439. // 断开TCP
  440. int count = _HPSocket_TcpClients.Count();
  441. for (int i = 0; i < count; i++)
  442. {
  443. try
  444. {
  445. if (_HPSocket_TcpClients[i] != null && _HPSocket_TcpClients[i]._client.IsConnected)
  446. {
  447. _HPSocket_TcpClients[i].Stop();
  448. _HPSocket_TcpClients[i]._client.OnPrepareConnect -= OnPrepareConnect; // 准备连接了事件
  449. _HPSocket_TcpClients[i]._client.OnConnect -= OnConnect; // 连接事件
  450. _HPSocket_TcpClients[i]._client.OnSend -= OnSend; // 数据包发送事件
  451. _HPSocket_TcpClients[i]._client.OnReceive -= OnReceive; // 数据包到达事件
  452. _HPSocket_TcpClients[i]._client.OnClose -= OnClose; // TCP连接关闭事件
  453. }
  454. }
  455. catch { }
  456. }
  457. // 关闭Iot
  458. try { XiaomiMqttClient_Extend.CloseWithMqttServer(GlobalContext.MqttServerPath, GlobalContext.MqttServerName); } catch { }
  459. // 关闭AGV Mqtt
  460. try { _MQTTHelper.DisconnectAsync_Client().Wait(); } catch { }
  461. }
  462. catch { }
  463. }
  464. #endregion 窗体基础事件
  465. #region 监控MES状态
  466. /// <summary>
  467. /// 监控MES连接状态
  468. /// </summary>
  469. private void MonitorMESConnect()
  470. {
  471. while (IsRun) // 运行被控线程
  472. {
  473. try
  474. {
  475. // 开启MES(Http)
  476. if (GlobalContext.IsUseMES)
  477. {
  478. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  479. if (mesret)
  480. {
  481. picMESStatus.Image = imageListState.Images[1];
  482. GlobalContext.MESIsConnect = true;
  483. }
  484. else
  485. {
  486. picMESStatus.Image = imageListState.Images[0];
  487. GlobalContext.MESIsConnect = false;
  488. OnMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]连接失败");
  489. }
  490. }
  491. // 开启IOT(MQTT)
  492. if (GlobalContext.IsUseIot)
  493. {
  494. bool iIot = XiaomiMqttClient.IsOpen;
  495. if (iIot)
  496. picIot.Image = imageListState.Images[1];
  497. else
  498. {
  499. picIot.Image = imageListState.Images[0];
  500. OnMessage(LogType.Info, $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]连接失败");
  501. }
  502. }
  503. // 开启AGV(Http与MQTT)
  504. if (GlobalContext.IsUseAGV)
  505. {
  506. // AGV Http
  507. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  508. if (mesret1)
  509. picAgvHttp.Image = imageListState.Images[1];
  510. else
  511. {
  512. picAgvHttp.Image = imageListState.Images[0];
  513. OnMessage(LogType.Info, $"小米AGV Http[{GlobalContext.AGVHttpHost}]连接失败");
  514. }
  515. // AGV MQTT
  516. if (GlobalContext.AGVMQTTIsConnect)
  517. picAgvMqtt.Image = imageListState.Images[1];
  518. else
  519. {
  520. picAgvMqtt.Image = imageListState.Images[0];
  521. OnMessage(LogType.Info, $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]连接失败");
  522. }
  523. }
  524. }
  525. catch (Exception ex)
  526. {
  527. string str = ex.StackTrace;
  528. AddMessage(LogType.Error, "监控MES心跳失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  529. }
  530. Thread.Sleep(IntervalMonitorMES);
  531. }
  532. }
  533. #endregion 监控MES连接状态
  534. #region 采集设备状态、运行数据、报警数据
  535. /// <summary>
  536. /// 请求设备状态 5000
  537. /// </summary>
  538. /// <param name="no">1</param>
  539. /// <param name="stationNameStr"></param>
  540. /// <returns>0:证明未连接到PLC;1,代表设备控制状态处于运行状态;2,代表设备控制状态处于故障状态;3,代表设备控制状态处于缺料状态;4,代表设备控制状态处于待机状态;5,代表设备控制状态处于维修状态;</returns>
  541. public int GetDeviceStatus(int plcNo, string stationNameStr = "[S0]壳体上料")
  542. {
  543. try
  544. {
  545. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  546. {
  547. short result = Funs[plcNo].ReadHoldingRegisters<short>(5000); // 5000
  548. return result;
  549. }
  550. else
  551. {
  552. return 0;
  553. }
  554. }
  555. catch (Exception ex)
  556. {
  557. string str = ex.StackTrace;
  558. AddMessage_Station(stationNameStr, LogType.Error, "请求设备状态失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  559. return 0;
  560. }
  561. }
  562. /// <summary>
  563. /// 检查是否可采集点检数据 - 不取新值
  564. /// 5000不为1时可点检
  565. /// </summary>
  566. /// <returns></returns>
  567. public bool CheckCanSpotcheck1(int deviceState)
  568. {
  569. //return true;
  570. //D5000 = 1,代表设备控制状态处于运行状态
  571. //D5000 = 2, 代表设备控制状态处于故障状态
  572. //D5000 = 3,代表设备控制状态处于缺料状态
  573. //D5000 = 4, 代表设备控制状态处于待机状态
  574. //D5000 = 5,代表设备控制状态处于维修状态
  575. return deviceState != 1;
  576. }
  577. /// <summary>
  578. /// 检查是否可采集产品数据 - 不取新值
  579. /// </summary>
  580. /// <returns></returns>
  581. public bool CheckCanCollData(int deviceState)
  582. {
  583. return deviceState == 0; // 点检时该值不为0
  584. }
  585. /// <summary>
  586. /// 采集到的设备状态
  587. /// </summary>
  588. private string _DeviceStates = "未知状态";
  589. private string _DeviceStates_Old = "未知状态";
  590. /// <summary>
  591. /// 获取设备报警数据与获取设备运行信息
  592. /// </summary>
  593. private async void ReadAlarmAllPLC()
  594. {
  595. // [S1] Tray盘上料装备(板测)
  596. // [S2] FCT(板测)
  597. // [S3] 值板机
  598. // [S4] 取放桁架
  599. // [S5] Tray盘下料装备
  600. /// 上位机心跳
  601. /// 获取设备报警数据与状态信息
  602. string stationNameStr = "获取设备报警数据与状态信息";
  603. // 已连接到PLC
  604. while (IsRun)
  605. {
  606. try
  607. {
  608. //if (!GlobalContext._IsCon_plc1Alarm)
  609. //{
  610. // UpdatePLCMonitor(1, -2, 0);
  611. // continue;
  612. //}
  613. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  614. {
  615. if (plcEIP != null)
  616. {
  617. if (plcEIP.IsConnected)
  618. {
  619. #region 主页展示设备运行状态并上传到IOT中
  620. switch (xmDeviceState)
  621. {
  622. case XiaomiDeviceState.Uninitialized: // 未初始化状态(未初始状态,需先初始化装备才能运行)
  623. _DeviceStates = "未初始化状态";
  624. lblDeviceStates.Text = _DeviceStates;
  625. break;
  626. case XiaomiDeviceState.Initializing: // 初始化状态(初始化进行中)
  627. _DeviceStates = "初始化状态";
  628. lblDeviceStates.Text = _DeviceStates;
  629. break;
  630. case XiaomiDeviceState.Initialized: // 初始化完成状态(初始化完成)
  631. _DeviceStates = "初始化完成状态";
  632. lblDeviceStates.Text = _DeviceStates;
  633. break;
  634. case XiaomiDeviceState.Running: // 运行状态(正常运行中)
  635. _DeviceStates = "运行状态";
  636. lblDeviceStates.Text = _DeviceStates;
  637. break;
  638. case XiaomiDeviceState.Paused: // 暂停状态(设备运行中人工操作暂停,进入此状态)
  639. _DeviceStates = "暂停状态";
  640. lblDeviceStates.Text = _DeviceStates;
  641. break;
  642. case XiaomiDeviceState.Fault: // 故障状态(发生故障后进入此状态,同时停止运行)
  643. _DeviceStates = "故障状态";
  644. lblDeviceStates.Text = _DeviceStates;
  645. break;
  646. case XiaomiDeviceState.Alarm: // 警报状态(产生报警后进入此状态,同时停止运行)
  647. _DeviceStates = "警报状态";
  648. lblDeviceStates.Text = _DeviceStates;
  649. break;
  650. }
  651. if (!_DeviceStates.Equals(_DeviceStates_Old))
  652. {
  653. var iotResult = SaveDeviceStateData(stationNameStr, xmDeviceState); // 上传+保存
  654. if (iotResult.Item1 == 1)
  655. {
  656. _DeviceStates_Old = _DeviceStates;
  657. AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + $"_上传设备状态到Iot成功!");
  658. }
  659. else
  660. AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + $"_上传设备状态到Iot失败!报错信息:[{iotResult.Item1}]_{iotResult.Item2}");
  661. }
  662. #endregion 主页展示设备运行状态并上传到IOT中
  663. }
  664. }
  665. }
  666. //if (plc1Alarm.IsConnected) // 检查PLC是否已连接上
  667. //{
  668. // DateTime dtNow = DateTime.Now;
  669. // //#region 获取设备运行信息
  670. // //try
  671. // //{
  672. // // LineWorkingData_ThisTime lineWorkingData1 = new LineWorkingData_ThisTime();
  673. // // lineWorkingData1.GUID = Guid.NewGuid().ToString();
  674. // // lineWorkingData1.LineName = GlobalContext.LineCode;
  675. // // //
  676. // // lineWorkingData1.BootTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5500); // 本次开机时间(整线)D5500 h
  677. // // lineWorkingData1.NormalTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5502); // 本次开机运行时间(整线)D5502 h
  678. // // lineWorkingData1.StandbyTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5504); // 本次开机待机时间(整线)D5504 h
  679. // // lineWorkingData1.FaultTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5506); // 本次开机故障时间(整线)D5506 h
  680. // // lineWorkingData1.MaterialShortageTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5508); // 本次开机缺料时间(整线)D5508 h
  681. // // lineWorkingData1.MaintenanceTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5510); // 本次开机维修时间(整线)D5510 h
  682. // // lineWorkingData1.FaultNumber = plc1Alarm.ReadHoldingRegisters<short>(5514); // 本次开机故障停机次数(整线)D5514
  683. // // lineWorkingData1.OutputNumber = plc1Alarm.ReadHoldingRegisters<short>(5700); // 本次开机产量(整线) D5700
  684. // // lineWorkingData1.QualifiedNumber = plc1Alarm.ReadHoldingRegisters<short>(5704); // 本次开机合格数量(整线) D5704
  685. // // lineWorkingData1.QualifiedRate = plc1Alarm.ReadHoldingRegisters<float>(5710); // 本次开机合格率(整线) D5710
  686. // // lineWorkingData1.DesignRhythm = plc1Alarm.ReadHoldingRegisters<float>(5714); // 设计节拍(整线) D5714
  687. // // lineWorkingData1.RealityRhythm = plc1Alarm.ReadHoldingRegisters<float>(5716); // 本次开机实际节拍(整线) D5716
  688. // // lineWorkingData1.CreateTime = DateTime.Now;
  689. // // string lineWorkingData1_Str = JsonConvert.SerializeObject(lineWorkingData1);
  690. // // // UI展示-展示到设备状态页
  691. // // if (string.IsNullOrEmpty(lineWorkingData1_OldStr)) // 软件启动后第一次运行
  692. // // {
  693. // // // 查询数据库最新一条数据,确定是不是更新
  694. // // string qSql = @"SELECT top(1) [GUID]
  695. // // ,[LineName]
  696. // // ,[BootTimeLong]
  697. // // ,[NormalTimeLong]
  698. // // ,[StandbyTimeLong]
  699. // // ,[FaultTimeLong]
  700. // // ,[MaterialShortageTimeLong]
  701. // // ,[MaintenanceTimeLong]
  702. // // ,[FaultNumber]
  703. // // ,[OutputNumber]
  704. // // ,[QualifiedNumber]
  705. // // ,[QualifiedRate]
  706. // // ,[DesignRhythm]
  707. // // ,[RealityRhythm]
  708. // // ,[CreateTime]
  709. // // FROM [LineWorkingData]
  710. // // where [CreateTime] > '{0}'
  711. // // and [LineName]='{1}'
  712. // // order by [CreateTime] desc
  713. // // ";
  714. // // qSql = string.Format(qSql, DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00", lineWorkingData1.LineName);
  715. // // var ds = SQLHelper_New.Query(qSql, null);
  716. // // if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  717. // // {
  718. // // var dataDBlast = new LineWorkingData_ThisTime();
  719. // // dataDBlast.GUID = ds.Tables[0].Rows[0][0].ToString(); // 主键
  720. // // dataDBlast.LineName = ds.Tables[0].Rows[0][1].ToString(); // 线体名称
  721. // // dataDBlast.BootTimeLong = Convert.ToSingle(ds.Tables[0].Rows[0][2].ToString()); // 本次开机时间(整线)
  722. // // dataDBlast.CreateTime = Convert.ToDateTime(ds.Tables[0].Rows[0][14].ToString()); // 创建时间
  723. // // if (lineWorkingData1.BootTimeLong > dataDBlast.BootTimeLong) // 需要更新的情况;不需要更新的走后面的插入
  724. // // {
  725. // // dataDBlast.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  726. // // dataDBlast.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  727. // // dataDBlast.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  728. // // dataDBlast.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  729. // // dataDBlast.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  730. // // dataDBlast.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  731. // // dataDBlast.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  732. // // dataDBlast.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  733. // // dataDBlast.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  734. // // dataDBlast.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  735. // // dataDBlast.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  736. // // dataDBlast.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  737. // // string usql = dataDBlast.ToStringUpdate();
  738. // // SQLHelper_New.ExecuteSQL(usql, null);
  739. // // lineWorkingData1_OldStr = JsonConvert.SerializeObject(dataDBlast);
  740. // // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  741. // // //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  742. // // }
  743. // // }
  744. // // else
  745. // // {
  746. // // // 插入
  747. // // SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  748. // // lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  749. // // AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  750. // // //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  751. // // }
  752. // // }
  753. // // else if (!lineWorkingData1_Str.Equals(lineWorkingData1_OldStr)) // 非“软件启动后第一次运行”
  754. // // {
  755. // // LineWorkingData_ThisTime lineWorkingData1_Old = string.IsNullOrEmpty(lineWorkingData1_OldStr) ? lineWorkingData1 : JsonConvert.DeserializeObject<LineWorkingData_ThisTime>(lineWorkingData1_OldStr); // 上次的状态信息
  756. // // //// 本次开机设备运行情况
  757. // // //LineWorkingData1_ThisTime lineWorkingData_UI = JsonConvert.DeserializeObject<LineWorkingData1_ThisTime>(lineWorkingData1_OldStr);
  758. // // //Task.Run(() =>
  759. // // //{
  760. // // // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  761. // // // {
  762. // // // Form_Main.formDevAlarm.UpdDeviceStatus_ThisTime(lineWorkingData_UI); // UI更新
  763. // // // }
  764. // // //});
  765. // // // 本日设备运行情况
  766. // // // 存数据库(开机时间>上次的开机时间,则更新上次记录;<则作为新数据插入)
  767. // // if (lineWorkingData1.BootTimeLong > lineWorkingData1_Old.BootTimeLong)
  768. // // {
  769. // // // 更新
  770. // // lineWorkingData1_Old.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  771. // // lineWorkingData1_Old.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  772. // // lineWorkingData1_Old.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  773. // // lineWorkingData1_Old.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  774. // // lineWorkingData1_Old.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  775. // // lineWorkingData1_Old.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  776. // // lineWorkingData1_Old.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  777. // // lineWorkingData1_Old.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  778. // // lineWorkingData1_Old.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  779. // // lineWorkingData1_Old.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  780. // // lineWorkingData1_Old.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  781. // // lineWorkingData1_Old.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  782. // // SQLHelper_New.ExecuteSQL(lineWorkingData1_Old.ToStringUpdate(), null);
  783. // // lineWorkingData1_OldStr = JsonConvert.SerializeObject(lineWorkingData1_Old);
  784. // // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  785. // // //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  786. // // }
  787. // // else if (lineWorkingData1.BootTimeLong < lineWorkingData1_Old.BootTimeLong)
  788. // // {
  789. // // // 插入
  790. // // SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  791. // // lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  792. // // AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  793. // // //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  794. // // }
  795. // // await Task.Run(() =>
  796. // // {
  797. // // try
  798. // // {
  799. // // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  800. // // {
  801. // // Form_Main.formDevAlarm.UpdDeviceStatus_Today(); // UI更新
  802. // // }
  803. // // }
  804. // // catch { }
  805. // // });
  806. // // }
  807. // //}
  808. // //catch (Exception ex)
  809. // //{
  810. // // string str = ex.StackTrace;
  811. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取设备运行信息出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  812. // //}
  813. // //#endregion 获取设备运行信息
  814. // #region 报警数据
  815. // try
  816. // {
  817. // List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
  818. // bool isNeedUpdUI = false; // 是否需要更新历史报警UI
  819. // // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
  820. // var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.LineCode];
  821. // for (int i = 0; i < dicAlarms_Cur_PLC1.Count; i++) // 读取
  822. // {
  823. // short shortBuf = plc1Alarm.ReadHoldingRegisters<short>(dicAlarms_Cur_PLC1[i].关联的PLC地址);
  824. // dicAlarms_Cur_PLC1[i].是否报警 = shortBuf != 0;
  825. // if (dicAlarms_Cur_PLC1[i].上次的运行状态 != dicAlarms_Cur_PLC1[i].是否报警)
  826. // {
  827. // isNeedUpdUI = true; // 需要更新历史报警UI信息
  828. // // 记录
  829. // dicAlarms_Cur_PLC1[i].上次的运行状态 = dicAlarms_Cur_PLC1[i].是否报警;
  830. // switch (dicAlarms_Cur_PLC1[i].是否报警)
  831. // {
  832. // case true: // 报警
  833. // dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  834. // {
  835. // GUID = Guid.NewGuid().ToString(),
  836. // LineName = GlobalContext.LineCode, // 线体
  837. // AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  838. // AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  839. // StartTime = dtNow // 开始时间
  840. // };
  841. // // 传输到页面
  842. // deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
  843. // {
  844. // 线体名称 = dicAlarms_Cur_PLC1[i].报警数据.LineName,
  845. // 报警类型 = dicAlarms_Cur_PLC1[i].报警数据.AlarmType,
  846. // 报警内容 = dicAlarms_Cur_PLC1[i].报警数据.AlarmDesc,
  847. // 开始时间 = dtNow
  848. // });
  849. // // 新增到数据库
  850. // var data1 = dicAlarms_Cur_PLC1[i].报警数据;
  851. // SaveAlarmDataByDB(stationNameStr, data1, false);
  852. // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  853. // break;
  854. // case false: // 消除报警
  855. // if (dicAlarms_Cur_PLC1[i].报警数据 == null || string.IsNullOrEmpty(dicAlarms_Cur_PLC1[i].报警数据.GUID))
  856. // {
  857. // dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  858. // {
  859. // GUID = Guid.NewGuid().ToString(),
  860. // LineName = GlobalContext.LineCode, // 线体
  861. // AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  862. // AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  863. // StartTime = dtNow, // 开始时间
  864. // EndTime = dtNow, // 开始时间
  865. // PersistTime = 1, // 耗时1s
  866. // };
  867. // // 新增
  868. // var data2 = dicAlarms_Cur_PLC1[i].报警数据;
  869. // SaveAlarmDataByDB(stationNameStr, data2, false);
  870. // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  871. // }
  872. // else
  873. // {
  874. // dicAlarms_Cur_PLC1[i].报警数据.EndTime = dtNow; // 开始时间
  875. // dicAlarms_Cur_PLC1[i].报警数据.PersistTime = Convert.ToInt32((dicAlarms_Cur_PLC1[i].报警数据.EndTime
  876. // - dicAlarms_Cur_PLC1[i].报警数据.StartTime).TotalSeconds); // 耗时s
  877. // // 修改
  878. // var data3 = dicAlarms_Cur_PLC1[i].报警数据;
  879. // SaveAlarmDataByDB(stationNameStr, data3, true);
  880. // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  881. // }
  882. // break;
  883. // default:
  884. // break;
  885. // }
  886. // }
  887. // }
  888. // DicAlarms_Cur[GlobalContext.LineCode] = dicAlarms_Cur_PLC1;
  889. // // 有新报警则更新
  890. // if (isNeedUpdUI)
  891. // {
  892. // // UI展示 - 展示到设备状态页
  893. // await Task.Run(() =>
  894. // {
  895. // try
  896. // {
  897. // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
  898. // {
  899. // Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
  900. // if (Form_Main.formDevAlarm.Visible)
  901. // {
  902. // Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
  903. // }
  904. // }
  905. // }
  906. // catch { }
  907. // });
  908. // }
  909. // }
  910. // catch (Exception ex)
  911. // {
  912. // string str = ex.StackTrace;
  913. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  914. // }
  915. // #endregion 报警数据
  916. // UpdatePLCMonitor(1, -2, 1);
  917. //}
  918. //else
  919. //{
  920. // UpdatePLCMonitor(1, -2, 0);
  921. //}
  922. }
  923. catch (Exception ex)
  924. {
  925. //AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  926. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_采集运行数据与报警数据出错!错误信息:" + ex.Message.ToString());
  927. }
  928. Thread.Sleep(IntervalAlarm);
  929. }
  930. }
  931. #endregion 轮询PLC
  932. #region 下发订单信息
  933. ///// <summary>
  934. ///// 壳体上料(下发工单)的交互逻辑
  935. ///// </summary>
  936. ///// <param name="no"></param>
  937. ///// <exception cref="NotImplementedException"></exception>
  938. //private void ReadStation_DownOrderInfo(int plcNo)
  939. //{
  940. // // [S1] Tray盘上料装备(板测)
  941. // // [S2] FCT(板测)
  942. // // [S3] 值板机
  943. // // [S4] 取放桁架
  944. // // [S5] Tray盘下料装备
  945. // /// 上位机心跳
  946. // /// 获取设备报警数据与状态信息
  947. // string stationNameStr = "[S0]壳体上料";
  948. // while (IsRun)
  949. // {
  950. // try
  951. // {
  952. // if (!GlobalContext._IsCon_Funs1)
  953. // {
  954. // UpdatePLCMonitor(plcNo, 0);
  955. // continue;
  956. // }
  957. // if (Funs[plcNo].isConnected) // 检查PLC是否已连接上
  958. // {
  959. // #region 壳体上料(下发工单)
  960. // try
  961. // {
  962. // Funs[plcNo].Read_Int_Tag("500", 1, out short[] iiMes0);
  963. // Funs[plcNo].Read_Int_Tag("501", 1, out short[] iiPlc0);
  964. // bool mES_FLAG_1 = iiMes0[0] == 1 ? true : false; // MES_FLAG_1
  965. // bool pLC_Flag_1 = iiPlc0[0] == 1 ? true : false; // PLC_FLAG_1
  966. // // 重置数据和信号
  967. // if (mES_FLAG_1 && pLC_Flag_1) // 1 1
  968. // {
  969. // // 清空写给PLC的数据
  970. // int[] i497 = new int[1] { 0 };
  971. // Funs[plcNo].Write_DInt_Tag("497", 1, i497); // SN号(数字部分)重置信号
  972. // // MES_Flag重置为0
  973. // int[] i500 = new int[1] { 0 };
  974. // Funs[plcNo].Write_DInt_Tag("500", 1, i500); // MES_FLAG_1
  975. // }
  976. // }
  977. // catch (Exception ex)
  978. // {
  979. // string str = ex.StackTrace;
  980. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}下发订单信息运行出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  981. // }
  982. // #endregion 壳体上料(下发工单)
  983. // UpdatePLCMonitor(plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  984. // }
  985. // else
  986. // {
  987. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  988. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  989. //
  990. // Funs[plcNo].Connect();
  991. // }
  992. // }
  993. // catch (Exception ex)
  994. // {
  995. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  996. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  997. //
  998. // Funs[plcNo].ReConnect();
  999. // }
  1000. // Thread.Sleep(IntervalReadPLC);
  1001. // }
  1002. //}
  1003. ///// <summary>
  1004. ///// 下发订单信息到PLC
  1005. ///// </summary>
  1006. ///// <param name="no">PLC编号</param>
  1007. //private void DownLoadProductInfo(int plcNo, string stationNameStr = "[S0]壳体上料")
  1008. //{
  1009. // try
  1010. // {
  1011. // if (!string.IsNullOrEmpty(GlobalContext.Mtltmrk))
  1012. // {
  1013. // Funs[plcNo].Write_String_Tag("568", 1, GlobalContext.Mtltmrk); // 产品型号(mtltmrk)
  1014. // WritePLCLog(LogType.Debug, GlobalContext.Mtltmrk);
  1015. // }
  1016. // Funs[plcNo].Write_DInt_Tag("500", 1, new Int32[1] { 1 }); // MES_FLAG_1
  1017. // }
  1018. // catch (Exception ex)
  1019. // {
  1020. // string str = ex.StackTrace;
  1021. // AddMessage_Station(stationNameStr, LogType.Error, "下发订单信息到PLC失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1022. // }
  1023. //}
  1024. /// <summary>
  1025. /// 下发清料信号
  1026. /// </summary>
  1027. /// <param name="no">PLC编号</param>
  1028. public bool ClearProducts(int plcNo, string stationNameStr = "[S0]壳体上料")
  1029. {
  1030. try
  1031. {
  1032. //Funs[plcNo].ReadHoldingRegisters<int>(496); //
  1033. AddMessage_Station(stationNameStr, LogType.Info, "下发了清料信号!");
  1034. return true;
  1035. }
  1036. catch (Exception ex)
  1037. {
  1038. string str = ex.StackTrace;
  1039. AddMessage_Station(stationNameStr, LogType.Error, "下发清料信号失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1040. return false;
  1041. }
  1042. }
  1043. #endregion 下发订单信息
  1044. #region Xiaomi 贲流
  1045. #region 公共方法
  1046. private static bool ProgressState = false;
  1047. private static readonly object lockObj = new object(); // 锁对象
  1048. private static bool isCollectingFlagLeft;
  1049. private static bool isCollectingFlagRight;
  1050. /// <summary>
  1051. /// float[]转为string
  1052. /// </summary>
  1053. public string FloatArrayToString(float[] nScrewResults)
  1054. {
  1055. // 使用 "R" 格式说明符来保证浮点数的往返精度,不添加 'f' 后缀
  1056. return string.Join(",", Array.ConvertAll(nScrewResults, element => element.ToString("R")));
  1057. }
  1058. /// <summary>
  1059. /// short[]转为string
  1060. /// </summary>
  1061. public string ShortArrayToString(short[] nScrewResults)
  1062. {
  1063. // 使用 string.Join 来连接数组元素,并使用逗号作为分隔符
  1064. return string.Join(",", nScrewResults);
  1065. }
  1066. /// <summary>
  1067. /// 写入PLC重复三次
  1068. /// </summary>
  1069. public (int, string) WriteResultToPlc<T>(int plcNo, string stationNameStr, string strTagName, int nCount, T inObj)
  1070. {
  1071. int i = 0;
  1072. int nRet = 0;
  1073. string strRet = "";
  1074. try
  1075. {
  1076. while (i < 3) // 最多上传三次
  1077. {
  1078. (nRet, strRet) = FunsEip[plcNo].Write_SingleTag<T>(strTagName, nCount, inObj);
  1079. if (nRet == 0) //成功
  1080. {
  1081. break;
  1082. }
  1083. else
  1084. {
  1085. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站结果写入PLC出错!错误信息:" + strRet);
  1086. i++;
  1087. }
  1088. }
  1089. return (nRet, strRet);
  1090. }
  1091. catch (Exception ex)
  1092. {
  1093. return (1, ex.Message);
  1094. }
  1095. }
  1096. public (int, string) SaveScrewDataToTxt(string direction, string ProductBarcode, float[] fScrewTimes, short[] nScrewOrders, short[] nScrewResults)
  1097. {
  1098. try
  1099. {
  1100. // 获取当前日期
  1101. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1102. // 构建保存路径
  1103. string basePath = AppDomain.CurrentDomain.BaseDirectory; // 获取执行文件的目录
  1104. string savePath = Path.Combine(basePath, "screw", dateFolder, ProductBarcode, direction,"螺丝Mes数据");
  1105. // 确保目录存在
  1106. Directory.CreateDirectory(savePath);
  1107. // 文件名
  1108. string fileName = $"{ProductBarcode}_{DateTime.Now.ToString("HHmmss")}.txt";
  1109. string filePath = Path.Combine(savePath, fileName);
  1110. // 确保不会超出数组长度,只取前14个或数组的实际长度
  1111. int count = Math.Min(14, fScrewTimes.Length);
  1112. using (StreamWriter sw = new StreamWriter(filePath))
  1113. {
  1114. for (int i = 0; i < count; i++)
  1115. {
  1116. sw.WriteLine($"{ProductBarcode}{"_"}{i + 1}");
  1117. sw.WriteLine($"锁附时间:{fScrewTimes[i]}");
  1118. sw.WriteLine($"锁附顺序:{nScrewOrders[i]}");
  1119. sw.WriteLine($"锁附结果:{nScrewResults[i]}");
  1120. sw.WriteLine(); // 空行分隔不同螺丝的信息
  1121. }
  1122. }
  1123. return (0, "");
  1124. }
  1125. catch (Exception ex)
  1126. {
  1127. return (1, ex.Message);
  1128. }
  1129. }
  1130. public Dictionary<string, string> GetLastLineCompensation(string path,string direction,string sn)
  1131. {
  1132. // 创建字典存储补偿点及其对应的值
  1133. Dictionary<string, string> compensationDict = new Dictionary<string, string>();
  1134. try
  1135. {
  1136. //string path = GlobalContext.MESLaserRPath;
  1137. // 获取当前日期并格式化为 "yyyy-MM-dd" 格式
  1138. string currentDate = DateTime.Now.ToString("yyyy-MM-dd");
  1139. string filename = $"Laser-{currentDate}-W0.txt";
  1140. // 拼接完整路径
  1141. string fullPath = Path.Combine(path, filename);
  1142. string lastNonEmptyLine = "";
  1143. // 判断文件是否存在
  1144. if (File.Exists(fullPath))
  1145. {
  1146. //读取文件内容
  1147. string[] lines = File.ReadAllLines(fullPath);
  1148. // 获取最后一行数据(忽略标题行)
  1149. if (lines.Length > 1)
  1150. {
  1151. string lastLine = "";
  1152. for (int i = lines.Length - 1; i > 0; i--)
  1153. {
  1154. if (!string.IsNullOrEmpty(lines[i]))
  1155. {
  1156. lastLine = lines[i];
  1157. break;
  1158. }
  1159. }
  1160. // 将最后一行按逗号分隔
  1161. string[] values = lastLine.Split(',');
  1162. values[1] = sn;
  1163. string key = "三点激光_"+ direction; // 构造键名
  1164. string value = string.Join(",", values); // 获取值并去除多余空格
  1165. compensationDict[key] = value;
  1166. //// 提取“1点补偿”到“6点补偿”的值
  1167. //for (int i = 2; i <= 7 && i < values.Length; i++) // 从索引2开始,最多提取6个值
  1168. //{
  1169. // string key = $"{i - 1}点补偿"; // 构造键名
  1170. // string value = values[i].Trim(); // 获取值并去除多余空格
  1171. // compensationDict[key] = value;
  1172. //}
  1173. }
  1174. }
  1175. else
  1176. {
  1177. Console.WriteLine($"文件不存在: {fullPath}");
  1178. }
  1179. }
  1180. catch (Exception ex)
  1181. {
  1182. // 捕获异常并输出错误信息
  1183. Console.WriteLine($"发生错误: {ex.Message}");
  1184. }
  1185. return compensationDict;
  1186. }
  1187. /// <summary>
  1188. /// 调用进站接口并保存进站数据
  1189. /// </summary>
  1190. /// <param name="stationNameStr">工站信息</param>
  1191. /// <param name="workorder_code">工单号</param>
  1192. /// <param name="mtltmrk">型号(物料号)</param>
  1193. /// <param name="sn">产品SN</param>
  1194. /// <param name="items">进站数据</param>
  1195. /// <returns>1成功;5MES报警;6上位机报警</returns>
  1196. public int SaveStationInData(string stationNameStr, string workorder_code, string mtltmrk, string sn, List<TestItem> items, string MachineId, string StationId)
  1197. {
  1198. int result = 0;
  1199. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1200. inRequest_Body.machineId = MachineId; // 装备ID(可配置)
  1201. inRequest_Body.stationId = StationId; // ⼯位ID(可配置)
  1202. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1203. inRequest_Body.clientTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1204. inRequest_Body.unitSn = sn; // 产品SN
  1205. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1206. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1207. string json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1208. StationIn stationIn = new StationIn()
  1209. {
  1210. Workorder_code = workorder_code, // 车间订单号
  1211. Mtltmrk = mtltmrk, // 产品型号(物料号)
  1212. Sn = sn, // SN
  1213. StationIn_body = json_Body, // 进站接口Json数据 - Body
  1214. Parameter_values = items, // 进站数据
  1215. Write_user = inRequest_Body.userId, // 员工Id
  1216. Test_time = inRequest_Body.clientTime // 进站时间
  1217. };
  1218. // 本地数据
  1219. string sql = stationIn.ToStringInsert(0);
  1220. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1221. result = ret == "成功" ? 1 : 6;
  1222. //await Task.Delay(200);
  1223. // 上传MES
  1224. if (GlobalContext.IsSendStationIn)
  1225. {
  1226. try
  1227. {
  1228. XmMES_StationInResponse response = new XmMES_StationInResponse();
  1229. string mesRet = string.Empty;
  1230. int i = 0;
  1231. while (i < 2) // 1009会多次尝试上传
  1232. {
  1233. response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  1234. if (response != null && response.header.code == "200")
  1235. break;
  1236. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1237. i++;
  1238. i++;
  1239. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1240. // 记录失败原因
  1241. OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + json_Body);
  1242. }
  1243. if (response?.header?.code == "200")
  1244. {
  1245. string sql_Upd = stationIn.ToStringUpdateStatusByID(1);
  1246. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1247. result = ret_Upd == "成功" ? 1 : 6;
  1248. AddMessage( LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---成功");
  1249. }
  1250. else
  1251. {
  1252. result = 5;
  1253. AddMessage(LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---失败!接口报错信息:" + mesRet);
  1254. }
  1255. string sql_response = stationIn.ToStringUpdateStationInReturn_body(JsonConvert.SerializeObject(response));
  1256. SQLHelper_New.ExecuteNonQuery(sql_response, null);
  1257. }
  1258. catch (Exception ex)
  1259. {
  1260. result = 6;
  1261. string str = ex.StackTrace;
  1262. AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传进站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1263. }
  1264. }
  1265. return result;
  1266. }
  1267. /// <summary>
  1268. /// 选择如何记录出站数据
  1269. /// </summary>
  1270. /// <param name="items">出站数据</param>
  1271. /// <param name="equipmentCode">设备编号</param>
  1272. /// <param name="processItem">测试项目</param>
  1273. /// <param name="workorder_code">车间订单号</param>
  1274. /// <param name="batch_num">批次号</param>
  1275. /// <param name="mtltmrk">型号</param>
  1276. /// <param name="proDate">日期</param>
  1277. /// <param name="supplierCode">供应商代码</param>
  1278. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1279. /// <returns>上传成功时返回1;失败返回0</returns>
  1280. private int SwitctProcessData(string stationNameStr, List<TestItem> items, string equipmentCode, string processItem,
  1281. string workorder_code, string batch_num, string mtltmrk, string proDate,
  1282. string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string MachineId, string StationId, string PartBarcode,string direction="")
  1283. {
  1284. return SaveProcessDataByDB(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num, mtltmrk,
  1285. proDate, supplierCode, sn, pass, vehicleSn, vehicleSlot, MachineId, StationId, PartBarcode, direction);
  1286. }
  1287. /// <summary>
  1288. /// 添加出站数据(提交到MES+本地保存到数据库)
  1289. /// </summary>
  1290. /// <param name="items">出站数据</param>
  1291. /// <param name="equipmentCode">设备编号</param>
  1292. /// <param name="processItem">测试项目</param>
  1293. /// <param name="workorder_code">车间订单号</param>
  1294. /// <param name="batch_num">批次号</param>
  1295. /// <param name="mtltmrk">型号</param>
  1296. /// <param name="proDate">日期</param>
  1297. /// <param name="supplierCode">供应商代码</param>
  1298. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1299. /// <returns>上传成功时返回1;失败返回0</returns>
  1300. public int SaveProcessDataByDB(string stationNameStr, List<TestItem> items, string equipmentCode,
  1301. string processItem, string workorder_code, string batch_num, string mtltmrk,
  1302. string proDate, string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string machineId, string stationId, string partBarcode,string direction="")
  1303. {
  1304. int upload = 0;
  1305. int result = 0;
  1306. ProcessData processData = new ProcessData()
  1307. {
  1308. Equipment_code = equipmentCode,
  1309. Workorder_code = workorder_code,
  1310. Batch_number = batch_num,
  1311. Sn = sn, // SN
  1312. Testitem = processItem,
  1313. Parameter_values = items,
  1314. Write_user = GlobalContext.CurrentUser,
  1315. Test_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  1316. };
  1317. // 本地数据
  1318. string sql = processData.ToStringInsert(upload);
  1319. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1320. //AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地出站数据---" + ret));
  1321. // 上传MES
  1322. if (GlobalContext.IsSendProcessData)
  1323. {
  1324. try
  1325. {
  1326. string id = processData.ID.Copy();
  1327. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1328. outRequest_Body.machineId = machineId; // 装备id(可配置)
  1329. outRequest_Body.stationId = stationId; // ⼯位ID(可配置)
  1330. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1331. outRequest_Body.clientTime = processData.Test_time; // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1332. outRequest_Body.unitSn = sn; // 产品SN
  1333. outRequest_Body.state = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL
  1334. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1335. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1336. outRequest_Body.unitData.vehicleData.vehicleSn = vehicleSn;
  1337. outRequest_Body.unitData.vehicleData.vehicleType = string.Empty;
  1338. outRequest_Body.unitData.vehicleData.slot = vehicleSlot;
  1339. if (!string.IsNullOrEmpty(partBarcode))
  1340. {
  1341. outRequest_Body.unitData.keyMaterial.Add(
  1342. new XmMES_StationOutRequest_Body.XmStationOut_KeyMaterial()
  1343. {
  1344. bindSort = 1,
  1345. materialSn = partBarcode
  1346. }); // 设备数据 - 部件码
  1347. }
  1348. //OP30站读txt数据
  1349. if (stationNameStr.Contains("OP30"))
  1350. {
  1351. string path = "";
  1352. if (direction == "Left")
  1353. path = GlobalContext.MESLaserLPath;
  1354. else
  1355. path= GlobalContext.MESLaserRPath;
  1356. //字典存储数据
  1357. Dictionary<string, string> compensationDict = GetLastLineCompensation(path, direction,sn);
  1358. foreach (var kvp in compensationDict)
  1359. {
  1360. outRequest_Body.unitData.processData.Add(
  1361. new XmMES_StationOutRequest_Body.XmStationOut_ProcessData()
  1362. {
  1363. dataName = kvp.Key.ToString(),
  1364. dataValue = kvp.Value.ToString()
  1365. });
  1366. }
  1367. }
  1368. string jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1369. if (GlobalContext.IsSendProcessData)
  1370. {
  1371. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1372. string mesRet = string.Empty;
  1373. int i = 0;
  1374. while (i < 2) // 1009会多次尝试上传
  1375. {
  1376. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1377. if (response != null && response.header.code == "200")
  1378. {
  1379. OnMessage(LogType.Error, "上传出站数据到MES服务器---成功!请求信息:" + jsonstr1 + "返回信息:" + JsonConvert.SerializeObject(response.body));
  1380. break;
  1381. }
  1382. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1383. i++;
  1384. i++;
  1385. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1386. // 记录失败原因
  1387. OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + jsonstr1);
  1388. }
  1389. if (response?.header?.code == "200")
  1390. {
  1391. string sql_Upd = ProcessData.ToStringUpdateStatusByID(1, id);
  1392. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1393. result = 1;
  1394. //AddMessage_Station(stationNameStr, LogType.Info, $"更新【出站数据 id {id}】上传状态---" + ret_Upd);
  1395. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---成功");
  1396. }
  1397. else
  1398. {
  1399. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---失败!接口报错信息:"+ mesRet);
  1400. }
  1401. string sql_UpStationout = ProcessData.ToStringUpdateStationOut_body(JsonConvert.SerializeObject(outRequest_Body),
  1402. JsonConvert.SerializeObject(response), id);
  1403. SQLHelper_New.ExecuteNonQuery(sql_UpStationout, null);
  1404. }
  1405. }
  1406. catch (Exception ex)
  1407. {
  1408. string str = ex.StackTrace;
  1409. AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传出站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1410. }
  1411. }
  1412. return result;
  1413. }
  1414. //private void CollectAndProcessDataLeft(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 atlasScrew1 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1422. // atlasScrew1.Initial();
  1423. // // 存储结果的列表
  1424. // List<(double Angle, double Torque, double StartTorque, double MaxTorque)> results = new List<(double, double, double, double)>();
  1425. // // 存储角度和扭力的字符串列表
  1426. // List<string> angleStrs = new List<string>();
  1427. // List<string> torqueStrs = new List<string>();
  1428. // // 上一次获取的数据
  1429. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1430. // while (isExitAtlasLeft) // 检查是否收集数据
  1431. // {
  1432. // // 获取当前数据
  1433. // var currentResult = atlasScrew1.GetResults();
  1434. // // 判断是否为新数据
  1435. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1436. // {
  1437. // OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1438. // // 更新角度和扭力的字符串列表
  1439. // angleStrs.Add(currentResult.JD_MEAN.ToString());
  1440. // torqueStrs.Add(currentResult.NL_MEAN.ToString());
  1441. // // 计算角度、扭力、起始扭力和最大扭力
  1442. // double[] angles = angleStrs.Select(a => double.Parse(a)).ToArray();
  1443. // double[] torques = torqueStrs.Select(a => double.Parse(a)).ToArray();
  1444. // double startTorque = torques.Length > 0 ? torques[0] : -1; // 起始扭力
  1445. // double maxTorque = torques.Length > 0 ? torques.Max() : -1; // 最大扭力
  1446. // // 将新数据添加到结果列表
  1447. // results.Add((angles.Last(), torques.Last(), startTorque, maxTorque));
  1448. // // 更新上一次获取的数据
  1449. // lastResult = currentResult;
  1450. // }
  1451. // // 等待一段时间后再次检查
  1452. // Thread.Sleep(20); // 轮询间隔时间
  1453. // // 如果触发了出站,则退出循环
  1454. // if (!isExitAtlasLeft)
  1455. // {
  1456. // break;
  1457. // }
  1458. // }
  1459. // // 生成文件名
  1460. // string fileName = $"{sn}_{direction}_{DateTime.Now:yyyyMMddHHmmss}.txt";
  1461. // // 写入数据到文件
  1462. // using (StreamWriter writer = new StreamWriter(fileName))
  1463. // {
  1464. // // 写入标题行
  1465. // writer.WriteLine("角度, 扭力, 起始扭力, 最大扭力");
  1466. // // 写入每一行数据
  1467. // foreach (var result in results)
  1468. // {
  1469. // writer.WriteLine($"{result.Angle}, {result.Torque}, {result.StartTorque}, {result.MaxTorque}");
  1470. // }
  1471. // }
  1472. // stopwatch.Stop();
  1473. // AddMessage(LogType.Info, $"数据采集完成并保存到文件 {fileName}; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1474. // }
  1475. // catch (Exception ex)
  1476. // {
  1477. // AddMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1478. // }
  1479. // finally
  1480. // {
  1481. // // 重置标志变量
  1482. // isExitAtlasLeft = false;
  1483. // }
  1484. //}
  1485. //private void CollectAndProcessDataRight(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1486. //{
  1487. // Stopwatch stopwatch = new Stopwatch();
  1488. // stopwatch.Start();
  1489. // try
  1490. // {
  1491. // // 初始化 AtlasScrew 实例
  1492. // AtlasScrew atlasScrew2 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1493. // atlasScrew2.Initial();
  1494. // // 存储结果的列表
  1495. // List<(double JD_MEAN, double NL_MEAN)> results = new List<(double JD_MEAN, double NL_MEAN)>();
  1496. // // 上一次获取的数据
  1497. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1498. // while (isExitAtlasRight) // 检查是否收集数据
  1499. // {
  1500. // // 获取当前数据
  1501. // var currentResult = atlasScrew2.GetResults();
  1502. // // 判断是否为新数据
  1503. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1504. // {
  1505. // AddMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1506. // // 将新数据写入PLC
  1507. // //WriteDataToPlc(plcNo, stationNameStr, tagMesCommName, currentResult.JD_MEAN, currentResult.NL_MEAN);
  1508. // // 将新数据添加到结果列表
  1509. // results.Add(currentResult);
  1510. // // 更新上一次获取的数据
  1511. // lastResult = currentResult;
  1512. // }
  1513. // // 等待一段时间后再次检查
  1514. // Thread.Sleep(20); // 轮询间隔时间
  1515. // // 如果触发了出站,则退出循环
  1516. // if (!isExitAtlasRight)
  1517. // {
  1518. // break;
  1519. // }
  1520. // }
  1521. // // 将所有数据写入文件
  1522. // //WriteDataToFile(sn, direction, results);
  1523. // stopwatch.Stop();
  1524. // OnMessage(LogType.Info, $"螺丝数据采集完成;总用时{stopwatch.ElapsedMilliseconds}ms");
  1525. // }
  1526. // catch (Exception ex)
  1527. // {
  1528. // OnMessage(LogType.Error, $"螺丝数据采集过程中发生错误: {ex.Message}");
  1529. // }
  1530. // finally
  1531. // {
  1532. // // 重置标志变量
  1533. // isExitAtlasRight = false;
  1534. // }
  1535. //}
  1536. private void CollectAndProcessDataLeft(AtlasScrew atlasScrew, string sn, string direction)
  1537. {
  1538. Stopwatch stopwatch = new Stopwatch();
  1539. stopwatch.Start();
  1540. int nRet = 0;
  1541. string strRet = "";
  1542. try
  1543. {
  1544. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1545. while (isCollectingFlagLeft)
  1546. {
  1547. // 从缓存中获取所有未处理的数据
  1548. var cachedData = atlasScrew.GetCachedDataLeft();
  1549. foreach (var currentResult in cachedData)
  1550. {
  1551. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1552. {
  1553. continue; // 跳过无效数据
  1554. }
  1555. OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1556. // 写入PLC
  1557. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1558. {
  1559. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1560. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1561. };
  1562. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1563. if (nRet != 0)
  1564. {
  1565. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1566. }
  1567. else
  1568. {
  1569. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1570. }
  1571. // 构建保存路径
  1572. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1573. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1574. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  1575. Directory.CreateDirectory(savePath); // 确保目录存在
  1576. // 构建文件名(以 SN + 序号命名)
  1577. string fileName = $"{sn}_{fileCounter}.txt";
  1578. string filePath = Path.Combine(savePath, fileName);
  1579. // 写入文件
  1580. using (StreamWriter writer = new StreamWriter(filePath))
  1581. {
  1582. writer.WriteLine("精度, 扭力");
  1583. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1584. for (int i = 0; i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length; i++)
  1585. {
  1586. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1587. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1588. writer.WriteLine($"{precision}, {torque}");
  1589. }
  1590. }
  1591. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1592. // 增加文件计数器
  1593. fileCounter++;
  1594. }
  1595. // 如果没有更多数据,则短暂休眠以节省资源
  1596. if (!cachedData.Any())
  1597. {
  1598. Thread.Sleep(10); // 根据需要调整休眠时间
  1599. }
  1600. // 如果触发了出站,则退出循环
  1601. if (!isCollectingFlagLeft)
  1602. {
  1603. break;
  1604. }
  1605. }
  1606. stopwatch.Stop();
  1607. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1608. }
  1609. catch (Exception ex)
  1610. {
  1611. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1612. }
  1613. finally
  1614. {
  1615. isCollectingFlagLeft = false;
  1616. }
  1617. }
  1618. private void CollectAndProcessDataRight(AtlasScrew atlasScrew, string sn, string direction)
  1619. {
  1620. Stopwatch stopwatch = new Stopwatch();
  1621. stopwatch.Start();
  1622. int nRet = 0;
  1623. string strRet = "";
  1624. try
  1625. {
  1626. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1627. while (isCollectingFlagRight)
  1628. {
  1629. // 从缓存中获取所有未处理的数据
  1630. var cachedData = atlasScrew.GetCachedDataLeft();
  1631. foreach (var currentResult in cachedData)
  1632. {
  1633. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1634. {
  1635. continue; // 跳过无效数据
  1636. }
  1637. OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1638. // 写入PLC
  1639. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1640. {
  1641. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1642. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1643. };
  1644. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1645. if (nRet != 0)
  1646. {
  1647. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1648. }
  1649. else
  1650. {
  1651. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1652. }
  1653. // 构建保存路径
  1654. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1655. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1656. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction,"曲线");
  1657. Directory.CreateDirectory(savePath); // 确保目录存在
  1658. // 构建文件名(以 SN + 序号命名)
  1659. string fileName = $"{sn}_{fileCounter}.txt";
  1660. string filePath = Path.Combine(savePath, fileName);
  1661. // 写入文件
  1662. using (StreamWriter writer = new StreamWriter(filePath))
  1663. {
  1664. writer.WriteLine("精度, 扭力");
  1665. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1666. for (int i = 0; i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length; i++)
  1667. {
  1668. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1669. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1670. writer.WriteLine($"{precision}, {torque}");
  1671. }
  1672. }
  1673. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1674. // 增加文件计数器
  1675. fileCounter++;
  1676. }
  1677. // 如果没有更多数据,则短暂休眠以节省资源
  1678. if (!cachedData.Any())
  1679. {
  1680. Thread.Sleep(10); // 根据需要调整休眠时间
  1681. }
  1682. // 如果触发了出站,则退出循环
  1683. if (!isCollectingFlagRight)
  1684. {
  1685. break;
  1686. }
  1687. }
  1688. stopwatch.Stop();
  1689. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1690. }
  1691. catch (Exception ex)
  1692. {
  1693. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1694. }
  1695. finally
  1696. {
  1697. isCollectingFlagRight = false;
  1698. }
  1699. }
  1700. #endregion
  1701. #region S1
  1702. /// <summary>
  1703. /// [S1] 壳体清洁上料装备
  1704. /// </summary>
  1705. /// <param name="plcNo">PLC编号</param>
  1706. private void ReadStation_S1(int plcNo)
  1707. {
  1708. string stationCode = "[OP10]";
  1709. string stationName = "壳体清洁上料";
  1710. string stationNameStr = stationCode + stationName;
  1711. string tagBaseName = "g_OP10_MES"; //标签变量名称
  1712. string tagMesCommName = "mesCommToPC"; //标签变量名称
  1713. string tagAgvCommName = "agvCommFrmPC";
  1714. string tagBarsetName = "BarcodeSet";
  1715. // 触发信号字典
  1716. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  1717. s1PLCSignal_Old.Add("a1OEEType", 0); // 节拍类型(plc写入)
  1718. // PLC数据字典 赋值
  1719. //s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  1720. s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  1721. s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  1722. s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  1723. OP10_MesData_t stPLC_MesData; //PLC的MES数据
  1724. (int, string) result;
  1725. while (true)
  1726. {
  1727. try
  1728. {
  1729. if (!GlobalContext._IsCon_Funs1)
  1730. {
  1731. UpdatePLCMonitor(1, plcNo, 0);
  1732. continue;
  1733. }
  1734. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  1735. {
  1736. Stopwatch stopwatch1 = new Stopwatch();
  1737. Stopwatch stopwatch2 = new Stopwatch();
  1738. stopwatch1.Start();
  1739. stopwatch2.Start();
  1740. #region 一次性读取所有数据
  1741. // 一次性读取所有数据
  1742. result = FunsEip[plcNo].Read_SingleTag<OP10_MesData_t>(tagBaseName, 1, out stPLC_MesData,this); //读取单个结构体数据
  1743. if (result.Item1 != 0)
  1744. {
  1745. //richTextBox1.AppendText("\n" + strRet);
  1746. }
  1747. else
  1748. {
  1749. //richTextBox1.AppendText("\n" + "读取成功");
  1750. //设备状态
  1751. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  1752. xmDeviceState = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7) ? XiaomiDeviceState.Unknown : (XiaomiDeviceState)xmDeviceStateInt;
  1753. s1PLCData["a1OEEPartNo"] = stPLC_MesData.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  1754. s1PLCData["a1OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  1755. s1PLCData["a1OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
  1756. }
  1757. #endregion 一次性读取所有数据
  1758. stopwatch2.Stop();
  1759. #region 进站
  1760. try
  1761. {
  1762. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  1763. {
  1764. lock (lockObj)
  1765. {
  1766. if (!ProgressState)
  1767. {
  1768. ProgressState = true;
  1769. Task.Run(() => S1进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, out ProgressState));
  1770. }
  1771. }
  1772. }
  1773. }
  1774. catch (Exception ex)
  1775. {
  1776. ProgressState = false;
  1777. string str = ex.StackTrace;
  1778. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1779. }
  1780. #endregion 进站
  1781. #region 出站
  1782. try
  1783. {
  1784. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  1785. {
  1786. lock (lockObj)
  1787. {
  1788. if (!ProgressState)
  1789. {
  1790. ProgressState = true;
  1791. Task.Run(() => S1出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  1792. stPLC_MesData.mesCommFrmPLC.cmd = 0;//清除入站申请
  1793. }
  1794. }
  1795. }
  1796. }
  1797. catch (Exception ex)
  1798. {
  1799. ProgressState = false;
  1800. string str = ex.StackTrace;
  1801. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1802. }
  1803. #endregion 出站
  1804. #region 节拍接口
  1805. try
  1806. {
  1807. int a1OEEPLC_FLAG = (int)s1PLCData["a1OEEType"];
  1808. int a1OEEPLC_FLAGOld = (int)s1PLCSignal_Old["a1OEEType"];
  1809. if (a1OEEPLC_FLAG != a1OEEPLC_FLAGOld)
  1810. {
  1811. if (a1OEEPLC_FLAG == 1)
  1812. Task.Run(() => S1节拍接口(plcNo, stationNameStr, tagBaseName, stPLC_MesData)); // MreTasks[4].Set();
  1813. s1PLCSignal_Old["a1OEEType"] = s1PLCData["a1OEEType"];
  1814. }
  1815. }
  1816. catch (Exception ex)
  1817. {
  1818. string str = ex.StackTrace;
  1819. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1820. }
  1821. #endregion
  1822. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1823. stopwatch1.Stop();
  1824. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  1825. }
  1826. else
  1827. {
  1828. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1829. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1830. FunsEip[plcNo].Connect(); // 重连
  1831. }
  1832. }
  1833. catch (Exception ex)
  1834. {
  1835. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1836. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1837. }
  1838. Thread.Sleep(IntervalReadPLC);
  1839. }
  1840. }
  1841. /// <summary>
  1842. /// [S1] 壳体清洁上料 - 进站
  1843. /// </summary>
  1844. /// <param name="plcNo">PLC编号</param>
  1845. /// <param name="stationNameStr">工站全称</param>
  1846. /// <param name="stPLC_MesData"></param>
  1847. /// <param name="tagMesCommName"></param>
  1848. private void S1进站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName, out bool ProgressState)
  1849. {
  1850. Stopwatch stopwatch1 = new Stopwatch();
  1851. Stopwatch stopwatch2 = new Stopwatch();
  1852. try
  1853. {
  1854. stopwatch1.Start();
  1855. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  1856. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有OP10和OP50返回
  1857. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1858. string MachineId = GlobalContext.S1_MachineId; // 装备ID(可配置)
  1859. string StationId = GlobalContext.S1_StationId; // 工位ID(可配置)
  1860. if (string.IsNullOrEmpty(sn))
  1861. {
  1862. ProgressState = false;
  1863. return;
  1864. }
  1865. //正式生产就用PLC中取的
  1866. //sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode;
  1867. //测试先用9码,正式直接用PLC得到的SN码,截取成9位码
  1868. sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  1869. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  1870. //绑定载具和产品
  1871. ResponseMessage message = new ResponseMessage();
  1872. message = SQLHelper.InsertCarrierBind(CarrierBarcode, sn);
  1873. if (message.result == false)
  1874. {
  1875. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  1876. }
  1877. // 产品SN进站
  1878. List<TestItem> item = new List<TestItem>();
  1879. stopwatch2.Start();
  1880. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  1881. stopwatch2.Stop();
  1882. //指令执行结果 1:OK 110:失败
  1883. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  1884. //进站结果写入PLC
  1885. CommandFromPLC resultToPlC = new CommandFromPLC();
  1886. resultToPlC.cmd = 0;
  1887. resultToPlC.cmdParam = 0;
  1888. resultToPlC.cmdResult = mesResultFrmWeb;
  1889. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1890. }
  1891. catch (Exception ex)
  1892. {
  1893. string str = ex.StackTrace;
  1894. AddMessage( LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1895. CommandFromPLC resultToPlC = new CommandFromPLC();
  1896. resultToPlC.cmd = 0;
  1897. resultToPlC.cmdParam = 0; //指令参数
  1898. resultToPlC.cmdResult = 110;
  1899. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1900. }
  1901. stopwatch1.Stop();
  1902. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  1903. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1904. ProgressState = false;
  1905. }
  1906. /// <summary>
  1907. /// [S1] 壳体清洁上料 - 出站接口
  1908. /// </summary>
  1909. private void S1出站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  1910. {
  1911. Stopwatch stopwatch1 = new Stopwatch();
  1912. Stopwatch stopwatch2 = new Stopwatch();
  1913. try
  1914. {
  1915. stopwatch1.Start();
  1916. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  1917. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  1918. string processItem = stationName; // 项目
  1919. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  1920. string supplierCode = ""; // 供应商代码
  1921. string workorder_code = GlobalContext.WorkOrderCode; // 工单号 现在没用上
  1922. string batch_num = GlobalContext.BatchNumber; // 批次号 现在没用上
  1923. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号 现在没用上
  1924. string sn = string.Empty;
  1925. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1926. string MachineId = GlobalContext.S1_MachineId; // 装备id(可配置)
  1927. string StationId = GlobalContext.S1_StationId; // ⼯位ID(可配置)
  1928. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  1929. a1Result = 1;
  1930. bool pass = a1Result == 1;
  1931. //根据载具码获取产品码
  1932. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  1933. if (string.IsNullOrEmpty(strProductBarcode))
  1934. {
  1935. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  1936. }
  1937. sn = strProductBarcode;
  1938. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  1939. List<TestItem> items = new List<TestItem>();
  1940. items.Add(new TestItem()
  1941. {
  1942. Parameter_name = "载具码",
  1943. Parameter_value = CarrierBarcode,
  1944. Parameter_unit = ""
  1945. });
  1946. items.Add(new TestItem()
  1947. {
  1948. Parameter_name = "产品码",
  1949. Parameter_value = sn,
  1950. Parameter_unit = ""
  1951. });
  1952. //出站接口
  1953. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  1954. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  1955. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  1956. stopwatch2.Start();
  1957. //进站结果写入PLC
  1958. CommandFromPLC resultToPlC = new CommandFromPLC();
  1959. resultToPlC.cmd = 0;
  1960. resultToPlC.cmdParam = 0; //指令参数
  1961. resultToPlC.cmdResult = mesResultFrmWeb;
  1962. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1963. stopwatch2.Stop();
  1964. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  1965. //保存PLC返回MES数据到本地
  1966. ResponseMessage message = new ResponseMessage();
  1967. message = SQLHelper.InsertOp10Data(CarrierBarcode, sn, 1,
  1968. stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.fCleanAirPress, stPLC_MesData.mesData.fCleanSpeed,
  1969. stPLC_MesData.mesData.fWindBladeHeight, stPLC_MesData.mesData.fCleanTime, stPLC_MesData.mesData.nCleanCount,
  1970. stPLC_MesData.mesData.nRemainCount);
  1971. if (message.result == false)
  1972. {
  1973. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  1974. }
  1975. AddMessage(LogType.Info, stationNameStr + "_保存出站数据结束");
  1976. }
  1977. catch (Exception ex)
  1978. {
  1979. stopwatch2.Start();
  1980. CommandFromPLC resultToPlC = new CommandFromPLC();
  1981. resultToPlC.cmd = 0;
  1982. resultToPlC.cmdParam = 0; //指令参数
  1983. resultToPlC.cmdResult = 110;
  1984. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1985. stopwatch2.Stop();
  1986. string str = ex.StackTrace;
  1987. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1988. }
  1989. stopwatch1.Stop();
  1990. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1991. ProgressState = false;
  1992. }
  1993. #endregion
  1994. #region S2
  1995. /// <summary>
  1996. /// [S2] 上盖板上料装备
  1997. /// </summary>
  1998. /// <param name="plcNo">PLC编号</param>
  1999. private void ReadStation_S2(int plcNo)
  2000. {
  2001. string stationCode = "[OP20]";
  2002. string stationName = "上盖板上料装备";
  2003. string stationNameStr = stationCode + stationName;
  2004. string tagBaseName = "g_OP20_MES"; //标签变量名称
  2005. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2006. string tagAgvCommName = "agvCommFrmPC";
  2007. string tagBarsetName = "BarcodeSet";
  2008. OP20_MesData_t stPLC_MesData; //PLC的MES数据
  2009. (int, string) result;
  2010. while (true)
  2011. {
  2012. try
  2013. {
  2014. if (!GlobalContext._IsCon_Funs2)
  2015. {
  2016. UpdatePLCMonitor(1, plcNo, 0);
  2017. continue;
  2018. }
  2019. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2020. {
  2021. Stopwatch stopwatch1 = new Stopwatch();
  2022. Stopwatch stopwatch2 = new Stopwatch();
  2023. stopwatch1.Start();
  2024. stopwatch2.Start();
  2025. #region 一次性读取所有数据
  2026. // 一次性读取所有数据
  2027. result = FunsEip[plcNo].Read_SingleTag<OP20_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2028. if (result.Item1 != 0)
  2029. {
  2030. //richTextBox1.AppendText("\n" + strRet);
  2031. }
  2032. else
  2033. {
  2034. //richTextBox1.AppendText("\n" + "读取成功");
  2035. }
  2036. #endregion 一次性读取所有数据
  2037. stopwatch2.Stop();
  2038. #region 进站
  2039. try
  2040. {
  2041. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2042. {
  2043. lock (lockObj)
  2044. {
  2045. if (!ProgressState)
  2046. {
  2047. ProgressState = true;
  2048. Task.Run(() => S2进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2049. }
  2050. }
  2051. }
  2052. }
  2053. catch (Exception ex)
  2054. {
  2055. ProgressState = false;
  2056. string str = ex.StackTrace;
  2057. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2058. }
  2059. #endregion 进站
  2060. #region 出站
  2061. try
  2062. {
  2063. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2064. {
  2065. lock (lockObj)
  2066. {
  2067. if (!ProgressState)
  2068. {
  2069. ProgressState = true;
  2070. Task.Run(() => S2出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2071. stPLC_MesData.mesCommFrmPLC.cmd = 0;//清除入站申请
  2072. }
  2073. }
  2074. }
  2075. }
  2076. catch (Exception ex)
  2077. {
  2078. ProgressState = false;
  2079. string str = ex.StackTrace;
  2080. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2081. }
  2082. #endregion 出站
  2083. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2084. stopwatch1.Stop();
  2085. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  2086. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2087. }
  2088. else
  2089. {
  2090. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2091. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2092. FunsEip[plcNo].Connect();
  2093. }
  2094. }
  2095. catch (Exception ex)
  2096. {
  2097. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2098. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2099. //Funs[plcNo].ReConnect();
  2100. }
  2101. Thread.Sleep(IntervalReadPLC);
  2102. }
  2103. }
  2104. /// <summary>
  2105. /// [S2] 上盖板上料装备
  2106. /// </summary>
  2107. /// <param name="plcNo">PLC编号</param>
  2108. /// <param name="stationNameStr">工站全称</param>
  2109. private void S2进站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2110. {
  2111. Stopwatch stopwatch1 = new Stopwatch();
  2112. Stopwatch stopwatch2 = new Stopwatch();
  2113. try
  2114. {
  2115. stopwatch1.Start();
  2116. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2117. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有10和50返回
  2118. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  2119. string MachineId = GlobalContext.S2_MachineId; // 装备ID(可配置)
  2120. string StationId = GlobalContext.S2_StationId; // 工位ID(可配置)
  2121. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2122. //根据载具码获取产品码
  2123. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2124. if (string.IsNullOrEmpty(strProductBarcode))
  2125. {
  2126. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2127. }
  2128. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  2129. //if (sn != strProductBarcode)
  2130. //{
  2131. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  2132. //}
  2133. sn = strProductBarcode;
  2134. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2135. // 产品SN(物料码)校验
  2136. List<TestItem> item = new List<TestItem>();
  2137. stopwatch2.Start();
  2138. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2139. stopwatch2.Stop();
  2140. //指令执行结果 1:OK 110:失败
  2141. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2142. //进站结果写入PLC
  2143. CommandFromPLC resultToPlC = new CommandFromPLC();
  2144. resultToPlC.cmd = 0;
  2145. resultToPlC.cmdParam = 0; //指令参数
  2146. resultToPlC.cmdResult = mesResultFrmWeb;
  2147. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2148. }
  2149. catch (Exception ex)
  2150. {
  2151. string str = ex.StackTrace;
  2152. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2153. CommandFromPLC resultToPlC = new CommandFromPLC();
  2154. resultToPlC.cmd = 0;
  2155. resultToPlC.cmdParam = 0; //指令参数
  2156. resultToPlC.cmdResult = 110;
  2157. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2158. }
  2159. stopwatch1.Stop();
  2160. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2161. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2162. ProgressState = false;
  2163. }
  2164. /// <summary>
  2165. /// [S2] 上盖板上料装备 - 出站接口
  2166. /// </summary>
  2167. private void S2出站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2168. {
  2169. Stopwatch stopwatch1 = new Stopwatch();
  2170. Stopwatch stopwatch2 = new Stopwatch();
  2171. try
  2172. {
  2173. stopwatch1.Start();
  2174. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2175. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2176. string processItem = stationName; // 测试项目
  2177. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2178. string supplierCode = ""; // 供应商代码
  2179. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2180. string batch_num = GlobalContext.BatchNumber; // 批次号
  2181. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2182. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2183. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2184. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; //部件码
  2185. string MachineId = GlobalContext.S2_MachineId; // 装备id(可配置) // ZS
  2186. string StationId = GlobalContext.S2_StationId; // ⼯位ID(可配置) // ZS
  2187. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2188. bool pass = a1Result == 1;
  2189. //根据载具码获取产品码
  2190. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2191. if (string.IsNullOrEmpty(strProductBarcode))
  2192. {
  2193. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2194. }
  2195. sn = strProductBarcode;
  2196. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2197. List<TestItem> items = new List<TestItem>();
  2198. items.Add(new TestItem()
  2199. {
  2200. Parameter_name = "载具码",
  2201. Parameter_value = CarrierBarcode,
  2202. Parameter_unit = ""
  2203. });
  2204. items.Add(new TestItem()
  2205. {
  2206. Parameter_name = "产品码",
  2207. Parameter_value = sn,
  2208. Parameter_unit = ""
  2209. });
  2210. items.Add(new TestItem()
  2211. {
  2212. Parameter_name = "部件码",
  2213. Parameter_value = PartBarcode,
  2214. Parameter_unit = ""
  2215. });
  2216. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2217. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode);
  2218. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2219. stopwatch2.Start();
  2220. //进站结果写入PLC
  2221. CommandFromPLC resultToPlC = new CommandFromPLC();
  2222. resultToPlC.cmd = 0;
  2223. resultToPlC.cmdParam = 0; //指令参数
  2224. resultToPlC.cmdResult = mesResultFrmWeb;
  2225. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2226. stopwatch2.Stop();
  2227. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2228. //保存PLC返回MES数据到本地
  2229. ResponseMessage message = new ResponseMessage();
  2230. message = SQLHelper.InsertOp20Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.nRemainCount);
  2231. if (message.result == false)
  2232. {
  2233. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2234. }
  2235. if (!string.IsNullOrEmpty(PartBarcode))
  2236. {
  2237. message = SQLHelper.InsertOp20Product(CarrierBarcode, sn, PartBarcode);
  2238. if (message.result == false)
  2239. {
  2240. AddMessage(LogType.Error, message.text);
  2241. }
  2242. }
  2243. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2244. }
  2245. catch (Exception ex)
  2246. {
  2247. stopwatch2.Start();
  2248. CommandFromPLC resultToPlC = new CommandFromPLC();
  2249. resultToPlC.cmd = 0;
  2250. resultToPlC.cmdParam = 0; //指令参数
  2251. resultToPlC.cmdResult = 110;
  2252. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2253. stopwatch2.Stop();
  2254. string str = ex.StackTrace;
  2255. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2256. }
  2257. stopwatch1.Stop();
  2258. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2259. ProgressState = false;
  2260. }
  2261. #endregion
  2262. #region S3
  2263. /// <summary>
  2264. /// [S3] 点散热胶装备
  2265. /// </summary>
  2266. /// <param name="plcNo">PLC编号</param>
  2267. private void ReadStation_S3(int plcNo)
  2268. {
  2269. string stationCode = "[OP30]";
  2270. string stationName = "点散热胶装备";
  2271. string stationNameStr = stationCode + stationName;
  2272. string tagBaseName = "g_OP30_MES"; //标签变量名称
  2273. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2274. string tagAgvCommName = "agvCommFrmPC";
  2275. string tagBarsetName = "BarcodeSet";
  2276. OP30_MesData_t stPLC_MesData; //PLC的MES数据
  2277. (int, string) result;
  2278. #region 创建字典
  2279. // 触发信号字典 赋值
  2280. s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  2281. s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  2282. s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  2283. s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2284. s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2285. // PLC数据字典 赋值
  2286. s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  2287. s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  2288. s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2289. s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  2290. s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  2291. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2292. s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  2293. s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  2294. s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  2295. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2296. s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  2297. s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  2298. s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  2299. s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2300. s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  2301. s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  2302. //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  2303. s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  2304. s3PLCData.Add("c1Result", 0); // 产品结果
  2305. s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2306. s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  2307. s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  2308. s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  2309. #endregion 创建字典
  2310. while (true)
  2311. {
  2312. try
  2313. {
  2314. if (!GlobalContext._IsCon_Funs2)
  2315. {
  2316. UpdatePLCMonitor(1, plcNo, 0);
  2317. continue;
  2318. }
  2319. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2320. {
  2321. Stopwatch stopwatch1 = new Stopwatch();
  2322. Stopwatch stopwatch2 = new Stopwatch();
  2323. stopwatch1.Start();
  2324. stopwatch2.Start();
  2325. #region 一次性读取所有数据
  2326. // 一次性读取所有数据
  2327. result = FunsEip[plcNo].Read_SingleTag<OP30_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2328. if (result.Item1 != 0)
  2329. {
  2330. //richTextBox1.AppendText("\n" + strRet);
  2331. }
  2332. else
  2333. {
  2334. //richTextBox1.AppendText("\n" + "读取成功");
  2335. }
  2336. #endregion 一次性读取所有数据
  2337. stopwatch2.Stop();
  2338. #region 左边进站
  2339. try
  2340. {
  2341. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2342. {
  2343. lock (lockObj)
  2344. {
  2345. if (!ProgressState)
  2346. {
  2347. ProgressState = true;
  2348. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState));
  2349. }
  2350. }
  2351. }
  2352. }
  2353. catch (Exception ex)
  2354. {
  2355. ProgressState = false;
  2356. string str = ex.StackTrace;
  2357. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2358. }
  2359. #endregion 左边进站
  2360. #region 左边出站
  2361. try
  2362. {
  2363. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2364. {
  2365. lock (lockObj)
  2366. {
  2367. if (!ProgressState)
  2368. {
  2369. ProgressState = true;
  2370. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left", out ProgressState));
  2371. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  2372. }
  2373. }
  2374. }
  2375. }
  2376. catch (Exception ex)
  2377. {
  2378. ProgressState = false;
  2379. string str = ex.StackTrace;
  2380. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2381. }
  2382. #endregion 左边出站
  2383. #region 右边进站
  2384. try
  2385. {
  2386. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2387. {
  2388. lock (lockObj)
  2389. {
  2390. if (!ProgressState)
  2391. {
  2392. ProgressState = true;
  2393. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, tagBaseName + ".Right." + tagBarsetName,"Right", out ProgressState));
  2394. }
  2395. }
  2396. }
  2397. }
  2398. catch (Exception ex)
  2399. {
  2400. ProgressState = false;
  2401. string str = ex.StackTrace;
  2402. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2403. }
  2404. #endregion 右边进站
  2405. #region 右边出站
  2406. try
  2407. {
  2408. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2409. {
  2410. lock (lockObj)
  2411. {
  2412. if (!ProgressState)
  2413. {
  2414. ProgressState = true;
  2415. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right", out ProgressState));
  2416. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  2417. }
  2418. }
  2419. }
  2420. }
  2421. catch (Exception ex)
  2422. {
  2423. string str = ex.StackTrace;
  2424. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2425. }
  2426. #endregion 右边出站
  2427. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2428. stopwatch1.Stop();
  2429. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  2430. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2431. }
  2432. else
  2433. {
  2434. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2435. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2436. FunsEip[plcNo].Connect();
  2437. }
  2438. }
  2439. catch (Exception ex)
  2440. {
  2441. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2442. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2443. //Funs[plcNo].ReConnect();
  2444. }
  2445. Thread.Sleep(IntervalReadPLC);
  2446. }
  2447. }
  2448. /// <summary>
  2449. /// [S3] 点散热胶装备 - 进站
  2450. /// </summary>
  2451. /// <param name="plcNo">PLC编号</param>
  2452. /// <param name="stationNameStr">工站全称</param>
  2453. private void S3进站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName, string tagBarsetName,string direction, out bool ProgressState)
  2454. {
  2455. Stopwatch stopwatch1 = new Stopwatch();
  2456. Stopwatch stopwatch2 = new Stopwatch();
  2457. try
  2458. {
  2459. stopwatch1.Start();
  2460. AddMessage(LogType.Info, stationNameStr + "_"+ direction+"_进站开始");
  2461. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2462. string MachineId = GlobalContext.S3_MachineId; // 装备ID(可配置)
  2463. string StationId=string.Empty;
  2464. if (direction=="Left")
  2465. {
  2466. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  2467. }
  2468. if (direction == "Right")
  2469. {
  2470. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  2471. }
  2472. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2473. //载具码验证产品码
  2474. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2475. if (string.IsNullOrEmpty(strProductBarcode))
  2476. {
  2477. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2478. }
  2479. sn = strProductBarcode;
  2480. AddMessage(LogType.Info, $"载具码:{strProductBarcode};产品码:{sn}");
  2481. // 产品SN(物料码)校验
  2482. List<TestItem> item = new List<TestItem>();
  2483. stopwatch2.Start();
  2484. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2485. stopwatch2.Stop();
  2486. //指令执行结果 1:OK 110:失败
  2487. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2488. //进站结果写入PLC
  2489. CommandFromPLC resultToPlC = new CommandFromPLC();
  2490. resultToPlC.cmd = 0;
  2491. resultToPlC.cmdParam = 0; //指令参数
  2492. resultToPlC.cmdResult = mesResultFrmWeb;
  2493. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2494. }
  2495. catch (Exception ex)
  2496. {
  2497. string str = ex.StackTrace;
  2498. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2499. CommandFromPLC resultToPlC = new CommandFromPLC();
  2500. resultToPlC.cmd = 0;
  2501. resultToPlC.cmdParam = 0; //指令参数
  2502. resultToPlC.cmdResult = 110;
  2503. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2504. }
  2505. stopwatch1.Stop();
  2506. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  2507. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2508. ProgressState = false;
  2509. }
  2510. /// <summary>
  2511. /// [S3] 点散热胶装备 - 出站
  2512. /// </summary>
  2513. private void S3出站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, string direction, out bool ProgressState)
  2514. {
  2515. Stopwatch stopwatch1 = new Stopwatch();
  2516. Stopwatch stopwatch2 = new Stopwatch();
  2517. try
  2518. {
  2519. stopwatch1.Start();
  2520. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  2521. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2522. string processItem = stationName; // 测试项目
  2523. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2524. string supplierCode = ""; // 供应商代码
  2525. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2526. string batch_num = GlobalContext.BatchNumber; // 批次号
  2527. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2528. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2529. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2530. string MachineId = GlobalContext.S3_MachineId; // 装备id(可配置)
  2531. string StationId = string.Empty;
  2532. if (direction == "Left")
  2533. {
  2534. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  2535. }
  2536. if (direction == "Right")
  2537. {
  2538. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  2539. }
  2540. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2541. bool pass = a1Result == 1;
  2542. //根据载具码获取产品码
  2543. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2544. if (string.IsNullOrEmpty(strProductBarcode))
  2545. {
  2546. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2547. }
  2548. sn = strProductBarcode;
  2549. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2550. List<TestItem> items = new List<TestItem>();
  2551. items.Add(new TestItem()
  2552. {
  2553. Parameter_name = "载具码",
  2554. Parameter_value = CarrierBarcode,
  2555. Parameter_unit = ""
  2556. });
  2557. items.Add(new TestItem()
  2558. {
  2559. Parameter_name = "产品码",
  2560. Parameter_value = sn,
  2561. Parameter_unit = ""
  2562. });
  2563. int result1 = 1;
  2564. //if (direction == "Right")
  2565. //{
  2566. result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2567. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", direction);
  2568. //}
  2569. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2570. stopwatch2.Start();
  2571. //进站结果写入PLC
  2572. CommandFromPLC resultToPlC = new CommandFromPLC();
  2573. resultToPlC.cmd = 0;
  2574. resultToPlC.cmdParam = 0; //指令参数
  2575. resultToPlC.cmdResult = mesResultFrmWeb;
  2576. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2577. stopwatch2.Stop();
  2578. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  2579. //保存PLC返回MES数据到本地
  2580. ResponseMessage message = new ResponseMessage();
  2581. if (direction == "Left")
  2582. {
  2583. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  2584. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  2585. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  2586. message = SQLHelper.InsertOp301Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  2587. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  2588. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  2589. if (message.result == false)
  2590. {
  2591. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2592. }
  2593. }
  2594. if (direction == "Right")
  2595. {
  2596. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  2597. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  2598. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  2599. message = SQLHelper.InsertOp302Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  2600. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  2601. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  2602. if (message.result == false)
  2603. {
  2604. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2605. }
  2606. }
  2607. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2608. }
  2609. catch (Exception ex)
  2610. {
  2611. stopwatch2.Start();
  2612. CommandFromPLC resultToPlC = new CommandFromPLC();
  2613. resultToPlC.cmd = 0;
  2614. resultToPlC.cmdParam = 0; //指令参数
  2615. resultToPlC.cmdResult = 110;
  2616. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2617. stopwatch2.Stop();
  2618. string str = ex.StackTrace;
  2619. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2620. }
  2621. stopwatch1.Stop();
  2622. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2623. ProgressState = false;
  2624. }
  2625. #endregion S3
  2626. #region S4
  2627. /// <summary>
  2628. /// [S4] 点胶检测设备
  2629. /// </summary>
  2630. /// <param name="plcNo">PLC编号</param>
  2631. private void ReadStation_S4(int plcNo)
  2632. {
  2633. string stationCode = "[OP40]";
  2634. string stationName = "胶线检测";
  2635. string stationNameStr = stationCode + stationName;
  2636. string tagBaseName = "g_OP40_MES"; //标签变量名称
  2637. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2638. string tagAgvCommName = "agvCommFrmPC";
  2639. string tagBarsetName = "BarcodeSet";
  2640. OP40_MesData_t stPLC_MesData; //PLC的MES数据
  2641. (int, string) result;
  2642. while (true)
  2643. {
  2644. try
  2645. {
  2646. if (!GlobalContext._IsCon_Funs1)
  2647. {
  2648. UpdatePLCMonitor(1, plcNo, 0);
  2649. continue;
  2650. }
  2651. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2652. {
  2653. Stopwatch stopwatch1 = new Stopwatch();
  2654. Stopwatch stopwatch2 = new Stopwatch();
  2655. stopwatch1.Start();
  2656. stopwatch2.Start();
  2657. #region 一次性读取所有数据
  2658. // 一次性读取所有数据
  2659. result = FunsEip[plcNo].Read_SingleTag<OP40_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2660. if (result.Item1 != 0)
  2661. {
  2662. //richTextBox1.AppendText("\n" + strRet);
  2663. }
  2664. else
  2665. {
  2666. //richTextBox1.AppendText("\n" + "读取成功");
  2667. }
  2668. #endregion 一次性读取所有数据
  2669. stopwatch2.Stop();
  2670. #region 进站
  2671. try
  2672. {
  2673. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2674. {
  2675. lock (lockObj)
  2676. {
  2677. if (!ProgressState)
  2678. {
  2679. ProgressState = true;
  2680. Task.Run(() => S4进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2681. }
  2682. }
  2683. }
  2684. }
  2685. catch (Exception ex)
  2686. {
  2687. ProgressState = false;
  2688. string str = ex.StackTrace;
  2689. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2690. }
  2691. #endregion 进站
  2692. #region 出站
  2693. try
  2694. {
  2695. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2696. {
  2697. lock (lockObj)
  2698. {
  2699. if (!ProgressState)
  2700. {
  2701. ProgressState = true;
  2702. Task.Run(() => S4出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2703. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  2704. }
  2705. }
  2706. }
  2707. }
  2708. catch (Exception ex)
  2709. {
  2710. string str = ex.StackTrace;
  2711. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2712. }
  2713. #endregion 出站
  2714. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2715. stopwatch1.Stop();
  2716. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2717. }
  2718. else
  2719. {
  2720. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2721. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2722. FunsEip[plcNo].Connect(); // 重连
  2723. }
  2724. }
  2725. catch (Exception ex)
  2726. {
  2727. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2728. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2729. }
  2730. Thread.Sleep(IntervalReadPLC);
  2731. }
  2732. }
  2733. /// <summary>
  2734. /// [S4] 点胶检测设备 - 进站
  2735. /// </summary>
  2736. /// <param name="plcNo">PLC编号</param>
  2737. /// <param name="stationNameStr">工站全称</param>
  2738. /// <param name="stPLC_MesData"></param>
  2739. /// <param name="tagMesCommName"></param>
  2740. private void S4进站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2741. {
  2742. Stopwatch stopwatch1 = new Stopwatch();
  2743. Stopwatch stopwatch2 = new Stopwatch();
  2744. try
  2745. {
  2746. stopwatch1.Start();
  2747. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2748. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2749. string MachineId = GlobalContext.S4_MachineId; // 装备ID(可配置)
  2750. string StationId = GlobalContext.S4_StationId; // 工位ID(可配置)
  2751. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2752. //载具码验证产品码
  2753. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2754. if (string.IsNullOrEmpty(strProductBarcode))
  2755. {
  2756. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2757. }
  2758. sn = strProductBarcode;
  2759. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2760. // 产品SN(物料码)校验
  2761. List<TestItem> item = new List<TestItem>();
  2762. stopwatch2.Start();
  2763. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2764. stopwatch2.Stop();
  2765. //指令执行结果 1:OK 110:失败
  2766. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  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. }
  2774. catch (Exception ex)
  2775. {
  2776. string str = ex.StackTrace;
  2777. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2778. CommandFromPLC resultToPlC = new CommandFromPLC();
  2779. resultToPlC.cmd = 0;
  2780. resultToPlC.cmdParam = 0; //指令参数
  2781. resultToPlC.cmdResult = 110;
  2782. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2783. }
  2784. stopwatch1.Stop();
  2785. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2786. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2787. ProgressState = false;
  2788. }
  2789. /// <summary>
  2790. /// [S4] 点胶检测设备 - 出站接口
  2791. /// </summary>
  2792. private void S4出站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2793. {
  2794. Stopwatch stopwatch1 = new Stopwatch();
  2795. Stopwatch stopwatch2 = new Stopwatch();
  2796. try
  2797. {
  2798. stopwatch1.Start();
  2799. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2800. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2801. string processItem = stationName; // 测试项目
  2802. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2803. string supplierCode = ""; // 供应商代码
  2804. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2805. string batch_num = GlobalContext.BatchNumber; // 批次号
  2806. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2807. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2808. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2809. string MachineId = GlobalContext.S4_MachineId; // 装备id(可配置) // ZS
  2810. string StationId = GlobalContext.S4_StationId; // ⼯位ID(可配置) // ZS
  2811. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2812. bool pass = a1Result == 1;
  2813. //根据载具码获取产品码
  2814. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2815. if (string.IsNullOrEmpty(strProductBarcode))
  2816. {
  2817. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2818. }
  2819. sn = strProductBarcode;
  2820. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2821. List<TestItem> items = new List<TestItem>();
  2822. items.Add(new TestItem()
  2823. {
  2824. Parameter_name = "载具码",
  2825. Parameter_value = CarrierBarcode,
  2826. Parameter_unit = ""
  2827. });
  2828. items.Add(new TestItem()
  2829. {
  2830. Parameter_name = "产品码",
  2831. Parameter_value = sn,
  2832. Parameter_unit = ""
  2833. });
  2834. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2835. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  2836. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2837. stopwatch2.Start();
  2838. //进站结果写入PLC
  2839. CommandFromPLC resultToPlC = new CommandFromPLC();
  2840. resultToPlC.cmd = 0;
  2841. resultToPlC.cmdParam = 0; //指令参数
  2842. resultToPlC.cmdResult = mesResultFrmWeb;
  2843. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2844. stopwatch2.Stop();
  2845. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2846. //保存PLC返回MES数据到本地
  2847. ResponseMessage message = new ResponseMessage();
  2848. string strGluePosX = FloatArrayToString(stPLC_MesData.mesData.fGluePosX);
  2849. string strGluePosY = FloatArrayToString(stPLC_MesData.mesData.fGluePosY);
  2850. string strGlue_Areas = FloatArrayToString(stPLC_MesData.mesData.fGlue_Areas);
  2851. string strGlue_Heights = FloatArrayToString(stPLC_MesData.mesData.fGlue_Heights);
  2852. message = SQLHelper.InsertOp40Data(CarrierBarcode, sn, strGluePosX,
  2853. strGluePosY, strGlue_Areas, strGlue_Heights, stPLC_MesData.mesData.nResult, "");
  2854. if (message.result == false)
  2855. {
  2856. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2857. }
  2858. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2859. }
  2860. catch (Exception ex)
  2861. {
  2862. stopwatch2.Start();
  2863. CommandFromPLC resultToPlC = new CommandFromPLC();
  2864. resultToPlC.cmd = 0;
  2865. resultToPlC.cmdParam = 0; //指令参数
  2866. resultToPlC.cmdResult = 110;
  2867. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2868. stopwatch2.Stop();
  2869. string str = ex.StackTrace;
  2870. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2871. }
  2872. stopwatch1.Stop();
  2873. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2874. ProgressState = false;
  2875. }
  2876. #endregion
  2877. #region S5
  2878. /// <summary>
  2879. /// [S5] 点胶检测设备
  2880. /// </summary>
  2881. /// <param name="plcNo">PLC编号</param>
  2882. private void ReadStation_S5(int plcNo)
  2883. {
  2884. string stationCode = "[OP50]";
  2885. string stationName = "ADD板上料组装装备";
  2886. string stationNameStr = stationCode + stationName;
  2887. string tagBaseName = "g_OP50_MES"; //标签变量名称
  2888. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2889. string tagAgvCommName = "agvCommFrmPC";
  2890. string tagBarsetName = "BarcodeSet";
  2891. OP50_MesData_t stPLC_MesData; //PLC的MES数据
  2892. (int, string) result;
  2893. while (true)
  2894. {
  2895. try
  2896. {
  2897. if (!GlobalContext._IsCon_Funs1)
  2898. {
  2899. UpdatePLCMonitor(1, plcNo, 0);
  2900. continue;
  2901. }
  2902. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2903. {
  2904. Stopwatch stopwatch1 = new Stopwatch();
  2905. Stopwatch stopwatch2 = new Stopwatch();
  2906. stopwatch1.Start();
  2907. stopwatch2.Start();
  2908. #region 一次性读取所有数据
  2909. // 一次性读取所有数据
  2910. result = FunsEip[plcNo].Read_SingleTag<OP50_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2911. if (result.Item1 != 0)
  2912. {
  2913. //richTextBox1.AppendText("\n" + strRet);
  2914. }
  2915. else
  2916. {
  2917. //richTextBox1.AppendText("\n" + "读取成功");
  2918. }
  2919. #endregion 一次性读取所有数据
  2920. stopwatch2.Stop();
  2921. #region 进站
  2922. try
  2923. {
  2924. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2925. {
  2926. lock (lockObj)
  2927. {
  2928. if (!ProgressState)
  2929. {
  2930. ProgressState = true;
  2931. Task.Run(() => S5进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2932. }
  2933. }
  2934. }
  2935. }
  2936. catch (Exception ex)
  2937. {
  2938. ProgressState = false;
  2939. string str = ex.StackTrace;
  2940. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2941. }
  2942. #endregion 进站
  2943. #region 出站
  2944. try
  2945. {
  2946. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2947. {
  2948. lock (lockObj)
  2949. {
  2950. if (!ProgressState)
  2951. {
  2952. ProgressState = true;
  2953. Task.Run(() => S5出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2954. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  2955. }
  2956. }
  2957. }
  2958. }
  2959. catch (Exception ex)
  2960. {
  2961. ProgressState = false;
  2962. string str = ex.StackTrace;
  2963. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2964. }
  2965. #endregion 出站
  2966. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2967. stopwatch1.Stop();
  2968. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2969. }
  2970. else
  2971. {
  2972. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2973. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2974. FunsEip[plcNo].Connect(); // 重连
  2975. }
  2976. }
  2977. catch (Exception ex)
  2978. {
  2979. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2980. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2981. }
  2982. Thread.Sleep(IntervalReadPLC);
  2983. }
  2984. }
  2985. /// <summary>
  2986. /// [S5] 点胶检测设备 - 进站
  2987. /// </summary>
  2988. /// <param name="plcNo">PLC编号</param>
  2989. /// <param name="stationNameStr">工站全称</param>
  2990. /// <param name="stPLC_MesData"></param>
  2991. /// <param name="tagMesCommName"></param>
  2992. private void S5进站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2993. {
  2994. Stopwatch stopwatch1 = new Stopwatch();
  2995. Stopwatch stopwatch2 = new Stopwatch();
  2996. try
  2997. {
  2998. stopwatch1.Start();
  2999. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3000. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3001. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  3002. string MachineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  3003. string StationId = GlobalContext.S5_StationId; // 工位ID(可配置)
  3004. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3005. //载具码验证产品码 //载具码验证产品码
  3006. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3007. if (string.IsNullOrEmpty(strProductBarcode))
  3008. {
  3009. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3010. }
  3011. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  3012. //if (sn != strProductBarcode)
  3013. //{
  3014. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  3015. //}
  3016. sn = strProductBarcode;
  3017. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3018. // 产品SN(物料码)校验
  3019. List<TestItem> item = new List<TestItem>();
  3020. stopwatch2.Start();
  3021. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3022. stopwatch2.Stop();
  3023. //指令执行结果 1:OK 110:失败
  3024. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3025. //进站结果写入PLC
  3026. CommandFromPLC resultToPlC = new CommandFromPLC();
  3027. resultToPlC.cmd = 0;
  3028. resultToPlC.cmdParam = 0; //指令参数
  3029. resultToPlC.cmdResult = mesResultFrmWeb;
  3030. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3031. }
  3032. catch (Exception ex)
  3033. {
  3034. string str = ex.StackTrace;
  3035. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3036. CommandFromPLC resultToPlC = new CommandFromPLC();
  3037. resultToPlC.cmd = 0;
  3038. resultToPlC.cmdParam = 0; //指令参数
  3039. resultToPlC.cmdResult = 110;
  3040. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3041. }
  3042. stopwatch1.Stop();
  3043. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3044. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3045. ProgressState = false;
  3046. }
  3047. /// <summary>
  3048. /// [S5] 点胶检测设备 - 出站接口
  3049. /// </summary>
  3050. private void S5出站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3051. {
  3052. Stopwatch stopwatch1 = new Stopwatch();
  3053. Stopwatch stopwatch2 = new Stopwatch();
  3054. try
  3055. {
  3056. stopwatch1.Start();
  3057. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3058. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3059. string processItem = stationName; // 测试项目
  3060. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3061. string supplierCode = ""; // 供应商代码
  3062. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3063. string batch_num = GlobalContext.BatchNumber; // 批次号
  3064. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3065. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3066. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; // 产品条码;
  3067. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3068. string MachineId = GlobalContext.S5_MachineId; // 装备id(可配置) // ZS
  3069. string StationId = GlobalContext.S5_StationId; // ⼯位ID(可配置) // ZS
  3070. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3071. bool pass = a1Result == 1;
  3072. //根据载具码获取产品码
  3073. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3074. if (string.IsNullOrEmpty(strProductBarcode))
  3075. {
  3076. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3077. }
  3078. sn = strProductBarcode;
  3079. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3080. List<TestItem> items = new List<TestItem>();
  3081. items.Add(new TestItem()
  3082. {
  3083. Parameter_name = "载具码",
  3084. Parameter_value = CarrierBarcode,
  3085. Parameter_unit = ""
  3086. });
  3087. items.Add(new TestItem()
  3088. {
  3089. Parameter_name = "产品码",
  3090. Parameter_value = sn,
  3091. Parameter_unit = ""
  3092. });
  3093. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3094. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode);
  3095. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3096. stopwatch2.Start();
  3097. //进站结果写入PLC
  3098. CommandFromPLC resultToPlC = new CommandFromPLC();
  3099. resultToPlC.cmd = 0;
  3100. resultToPlC.cmdParam = 0; //指令参数
  3101. resultToPlC.cmdResult = mesResultFrmWeb;
  3102. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3103. stopwatch2.Stop();
  3104. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3105. //保存PLC返回MES数据到本地
  3106. ResponseMessage message = new ResponseMessage();
  3107. message = SQLHelper.InsertOp50Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsAddPCBAsmOK,
  3108. stPLC_MesData.mesData.nHaveAddPCB, stPLC_MesData.mesData.fForceAddPCB, stPLC_MesData.mesData.nRemainCount, "");
  3109. if (message.result == false)
  3110. {
  3111. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3112. }
  3113. //保存部件码信息
  3114. if (!string.IsNullOrEmpty(PartBarcode))
  3115. {
  3116. message = SQLHelper.InsertOp50Product(CarrierBarcode, sn, PartBarcode);
  3117. if (message.result == false)
  3118. {
  3119. AddMessage(LogType.Info, stationNameStr + "_保存部件码信息失败");
  3120. }
  3121. }
  3122. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3123. }
  3124. catch (Exception ex)
  3125. {
  3126. stopwatch2.Start();
  3127. CommandFromPLC resultToPlC = new CommandFromPLC();
  3128. resultToPlC.cmd = 0;
  3129. resultToPlC.cmdParam = 0; //指令参数
  3130. resultToPlC.cmdResult = 110;
  3131. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3132. stopwatch2.Stop();
  3133. string str = ex.StackTrace;
  3134. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3135. }
  3136. stopwatch1.Stop();
  3137. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3138. ProgressState = false;
  3139. }
  3140. #endregion
  3141. #region S6
  3142. /// <summary>
  3143. /// [S6] 顶盖装配设备
  3144. /// </summary>
  3145. /// <param name="plcNo">PLC编号</param>
  3146. private void ReadStation_S6(int plcNo)
  3147. {
  3148. string stationCode = "[OP60]";
  3149. string stationName = "组上盖板";
  3150. string stationNameStr = stationCode + stationName;
  3151. string tagBaseName = "g_OP60_MES"; //标签变量名称
  3152. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3153. string tagAgvCommName = "agvCommFrmPC";
  3154. string tagBarsetName = "BarcodeSet";
  3155. OP60_MesData_t stPLC_MesData; //PLC的MES数据
  3156. (int, string) result;
  3157. while (true)
  3158. {
  3159. try
  3160. {
  3161. if (!GlobalContext._IsCon_Funs1)
  3162. {
  3163. UpdatePLCMonitor(1, plcNo, 0);
  3164. continue;
  3165. }
  3166. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3167. {
  3168. Stopwatch stopwatch1 = new Stopwatch();
  3169. Stopwatch stopwatch2 = new Stopwatch();
  3170. stopwatch1.Start();
  3171. stopwatch2.Start();
  3172. #region 一次性读取所有数据
  3173. // 一次性读取所有数据
  3174. result = FunsEip[plcNo].Read_SingleTag<OP60_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3175. if (result.Item1 != 0)
  3176. {
  3177. //richTextBox1.AppendText("\n" + strRet);
  3178. }
  3179. else
  3180. {
  3181. //richTextBox1.AppendText("\n" + "读取成功");
  3182. }
  3183. #endregion 一次性读取所有数据
  3184. stopwatch2.Stop();
  3185. #region 进站
  3186. try
  3187. {
  3188. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3189. {
  3190. lock (lockObj)
  3191. {
  3192. if (!ProgressState)
  3193. {
  3194. ProgressState = true;
  3195. Task.Run(() => S6进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3196. }
  3197. }
  3198. }
  3199. }
  3200. catch (Exception ex)
  3201. {
  3202. ProgressState = false;
  3203. string str = ex.StackTrace;
  3204. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3205. }
  3206. #endregion 进站
  3207. #region 出站
  3208. try
  3209. {
  3210. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3211. {
  3212. lock (lockObj)
  3213. {
  3214. if (!ProgressState)
  3215. {
  3216. ProgressState = true; ;
  3217. Task.Run(() => S6出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3218. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  3219. }
  3220. }
  3221. }
  3222. }
  3223. catch (Exception ex)
  3224. {
  3225. ProgressState = false;
  3226. string str = ex.StackTrace;
  3227. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3228. }
  3229. #endregion 出站
  3230. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3231. stopwatch1.Stop();
  3232. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3233. }
  3234. else
  3235. {
  3236. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3237. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3238. FunsEip[plcNo].Connect(); // 重连
  3239. }
  3240. }
  3241. catch (Exception ex)
  3242. {
  3243. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3244. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3245. }
  3246. Thread.Sleep(IntervalReadPLC);
  3247. }
  3248. }
  3249. /// <summary>
  3250. /// [S6] 顶盖装配设备 - 进站
  3251. /// </summary>
  3252. /// <param name="plcNo">PLC编号</param>
  3253. /// <param name="stationNameStr">工站全称</param>
  3254. /// <param name="stPLC_MesData"></param>
  3255. /// <param name="tagMesCommName"></param>
  3256. private void S6进站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3257. {
  3258. Stopwatch stopwatch1 = new Stopwatch();
  3259. Stopwatch stopwatch2 = new Stopwatch();
  3260. try
  3261. {
  3262. stopwatch1.Start();
  3263. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3264. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3265. string MachineId = GlobalContext.S6_MachineId; // 装备ID(可配置)
  3266. string StationId = GlobalContext.S6_StationId; // 工位ID(可配置)
  3267. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3268. //载具码验证产品码
  3269. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3270. if (string.IsNullOrEmpty(strProductBarcode))
  3271. {
  3272. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3273. }
  3274. sn = strProductBarcode;
  3275. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3276. // 产品SN(物料码)校验
  3277. List<TestItem> item = new List<TestItem>();
  3278. stopwatch2.Start();
  3279. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3280. stopwatch2.Stop();
  3281. //指令执行结果 1:OK 110:失败
  3282. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  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. }
  3290. catch (Exception ex)
  3291. {
  3292. string str = ex.StackTrace;
  3293. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3294. CommandFromPLC resultToPlC = new CommandFromPLC();
  3295. resultToPlC.cmd = 0;
  3296. resultToPlC.cmdParam = 0; //指令参数
  3297. resultToPlC.cmdResult = 110;
  3298. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3299. }
  3300. stopwatch1.Stop();
  3301. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3302. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3303. ProgressState = false;
  3304. }
  3305. /// <summary>
  3306. /// [S6] 顶盖装配设备 - 出站接口
  3307. /// </summary>
  3308. private void S6出站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3309. {
  3310. Stopwatch stopwatch1 = new Stopwatch();
  3311. Stopwatch stopwatch2 = new Stopwatch();
  3312. try
  3313. {
  3314. stopwatch1.Start();
  3315. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3316. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3317. string processItem = stationName; // 测试项目
  3318. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3319. string supplierCode = ""; // 供应商代码
  3320. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3321. string batch_num = GlobalContext.BatchNumber; // 批次号
  3322. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3323. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3324. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3325. string MachineId = GlobalContext.S6_MachineId; // 装备id(可配置) // ZS
  3326. string StationId = GlobalContext.S6_StationId; // ⼯位ID(可配置) // ZS
  3327. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3328. bool pass = a1Result == 1;
  3329. //根据载具码获取产品码
  3330. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3331. if (string.IsNullOrEmpty(strProductBarcode))
  3332. {
  3333. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3334. }
  3335. sn = strProductBarcode;
  3336. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3337. List<TestItem> items = new List<TestItem>();
  3338. items.Add(new TestItem()
  3339. {
  3340. Parameter_name = "载具码",
  3341. Parameter_value = CarrierBarcode,
  3342. Parameter_unit = ""
  3343. });
  3344. items.Add(new TestItem()
  3345. {
  3346. Parameter_name = "产品码",
  3347. Parameter_value = sn,
  3348. Parameter_unit = ""
  3349. });
  3350. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3351. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3352. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3353. stopwatch2.Start();
  3354. //进站结果写入PLC
  3355. CommandFromPLC resultToPlC = new CommandFromPLC();
  3356. resultToPlC.cmd = 0;
  3357. resultToPlC.cmdParam = 0; //指令参数
  3358. resultToPlC.cmdResult = mesResultFrmWeb;
  3359. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3360. stopwatch2.Stop();
  3361. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3362. //保存PLC返回MES数据到本地
  3363. ResponseMessage message = new ResponseMessage();
  3364. message = SQLHelper.InsertOp60Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsTopCoverAsmOK,
  3365. stPLC_MesData.mesData.nHaveTopCover, stPLC_MesData.mesData.fForceTopCover, "");
  3366. if (message.result == false)
  3367. {
  3368. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3369. }
  3370. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3371. }
  3372. catch (Exception ex)
  3373. {
  3374. stopwatch2.Start();
  3375. CommandFromPLC resultToPlC = new CommandFromPLC();
  3376. resultToPlC.cmd = 0;
  3377. resultToPlC.cmdParam = 0; //指令参数
  3378. resultToPlC.cmdResult = 110;
  3379. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3380. stopwatch2.Stop();
  3381. string str = ex.StackTrace;
  3382. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3383. }
  3384. stopwatch1.Stop();
  3385. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3386. ProgressState = false;
  3387. }
  3388. #endregion
  3389. #region S7
  3390. /// <summary>
  3391. /// [S7] 锁螺丝设备
  3392. /// </summary>
  3393. /// <param name="plcNo">PLC编号</param>
  3394. private void ReadStation_S7(int plcNo)
  3395. {
  3396. string stationCode = "[OP70]";
  3397. string stationName = "上盖板锁螺丝";
  3398. string stationNameStr = stationCode + stationName;
  3399. string tagBaseName = "g_OP70_MES"; //标签变量名称
  3400. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3401. string tagAgvCommName = "agvCommFrmPC";
  3402. string tagBarsetName = "BarcodeSet";
  3403. string tagScrewDataset = "screwDataset";
  3404. OP70_MesData_t stPLC_MesData; //PLC的MES数据
  3405. (int, string) result;
  3406. AtlasScrew atlasScrewLeft= new AtlasScrew(GlobalContext.AtlasAddressLeft, GlobalContext.AtlasAddressPort, 3000, 3000,"Left");
  3407. atlasScrewLeft.Initial();
  3408. AtlasScrew atlasScrewRight = new AtlasScrew(GlobalContext.AtlasAddressRight, GlobalContext.AtlasAddressPort, 3000, 3000,"Right");
  3409. atlasScrewRight.Initial();
  3410. while (true)
  3411. {
  3412. try
  3413. {
  3414. if (!GlobalContext._IsCon_Funs1)
  3415. {
  3416. UpdatePLCMonitor(1, plcNo, 0);
  3417. continue;
  3418. }
  3419. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3420. {
  3421. Stopwatch stopwatch1 = new Stopwatch();
  3422. Stopwatch stopwatch2 = new Stopwatch();
  3423. stopwatch1.Start();
  3424. stopwatch2.Start();
  3425. #region 一次性读取所有数据
  3426. // 一次性读取所有数据
  3427. result = FunsEip[plcNo].Read_SingleTag<OP70_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3428. if (result.Item1 != 0)
  3429. {
  3430. //richTextBox1.AppendText("\n" + strRet);
  3431. }
  3432. else
  3433. {
  3434. //richTextBox1.AppendText("\n" + "读取成功");
  3435. }
  3436. #endregion 一次性读取所有数据
  3437. stopwatch2.Stop();
  3438. #region 左边进站
  3439. try
  3440. {
  3441. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3442. {
  3443. lock (lockObj)
  3444. {
  3445. if (!ProgressState)
  3446. {
  3447. ProgressState = true;
  3448. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, tagBaseName + ".Left." + tagBarsetName,"Left", out ProgressState, atlasScrewLeft));
  3449. }
  3450. }
  3451. }
  3452. }
  3453. catch (Exception ex)
  3454. {
  3455. ProgressState = false;
  3456. string str = ex.StackTrace;
  3457. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3458. }
  3459. #endregion 左边进站
  3460. #region 左边出站
  3461. try
  3462. {
  3463. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3464. {
  3465. lock (lockObj)
  3466. {
  3467. if (!ProgressState)
  3468. {
  3469. ProgressState = true;
  3470. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left", out ProgressState));
  3471. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  3472. }
  3473. }
  3474. }
  3475. }
  3476. catch (Exception ex)
  3477. {
  3478. ProgressState = false;
  3479. string str = ex.StackTrace;
  3480. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3481. }
  3482. #endregion 左边出站
  3483. #region 右边进站
  3484. try
  3485. {
  3486. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3487. {
  3488. lock (lockObj)
  3489. {
  3490. if (!ProgressState)
  3491. {
  3492. ProgressState = true;
  3493. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, tagBaseName + ".Right" + tagBarsetName,"Right", out ProgressState, atlasScrewRight));
  3494. }
  3495. }
  3496. }
  3497. }
  3498. catch (Exception ex)
  3499. {
  3500. ProgressState = false;
  3501. string str = ex.StackTrace;
  3502. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3503. }
  3504. #endregion 右边进站
  3505. #region 右边出站
  3506. try
  3507. {
  3508. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3509. {
  3510. lock (lockObj)
  3511. {
  3512. if (!ProgressState)
  3513. {
  3514. ProgressState = true;
  3515. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right", out ProgressState));
  3516. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  3517. }
  3518. }
  3519. }
  3520. }
  3521. catch (Exception ex)
  3522. {
  3523. ProgressState = false;
  3524. string str = ex.StackTrace;
  3525. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3526. }
  3527. #endregion 右边出站
  3528. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3529. stopwatch1.Stop();
  3530. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3531. }
  3532. else
  3533. {
  3534. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3535. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3536. FunsEip[plcNo].Connect(); // 重连
  3537. }
  3538. }
  3539. catch (Exception ex)
  3540. {
  3541. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3542. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3543. }
  3544. Thread.Sleep(IntervalReadPLC);
  3545. }
  3546. }
  3547. /// <summary>
  3548. /// [S7] 锁螺丝设备 - 进站
  3549. /// </summary>
  3550. /// <param name="plcNo">PLC编号</param>
  3551. /// <param name="stationNameStr">工站全称</param>
  3552. /// <param name="stPLC_MesData"></param>
  3553. /// <param name="tagMesCommName"></param>
  3554. private void S7进站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName, string tagBarsetName, string direction,out bool ProgressState, AtlasScrew atlasScrew)
  3555. {
  3556. Stopwatch stopwatch1 = new Stopwatch();
  3557. Stopwatch stopwatch2 = new Stopwatch();
  3558. string atlasSn=string.Empty;
  3559. try
  3560. {
  3561. stopwatch1.Start();
  3562. AddMessage(LogType.Info, stationNameStr +"_"+ direction+"_进站开始");
  3563. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3564. string MachineId = GlobalContext.S7_MachineId; // 装备ID(可配置)
  3565. string StationId = string.Empty; // 工位ID(可配置)
  3566. if (direction == "Left")
  3567. {
  3568. StationId = GlobalContext.S7_StationId_1;
  3569. }
  3570. if (direction == "Right")
  3571. {
  3572. StationId = GlobalContext.S7_StationId_2;
  3573. }
  3574. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3575. //载具码验证产品码
  3576. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3577. if (string.IsNullOrEmpty(strProductBarcode))
  3578. {
  3579. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3580. }
  3581. sn = strProductBarcode;
  3582. atlasSn= strProductBarcode;
  3583. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3584. if (direction == "Left")
  3585. {
  3586. isCollectingFlagLeft = false;//采集螺丝数据结束
  3587. }
  3588. if (direction == "Right")
  3589. {
  3590. isCollectingFlagRight = false;//采集螺丝数据结束
  3591. }
  3592. // 产品SN(物料码)校验
  3593. List<TestItem> item = new List<TestItem>();
  3594. stopwatch2.Start();
  3595. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3596. stopwatch2.Stop();
  3597. //指令执行结果 1:OK 110:失败
  3598. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3599. //进站结果写入PLC
  3600. CommandFromPLC resultToPlC = new CommandFromPLC();
  3601. resultToPlC.cmd = 0;
  3602. resultToPlC.cmdParam = 0; //指令参数
  3603. resultToPlC.cmdResult = mesResultFrmWeb;
  3604. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3605. }
  3606. catch (Exception ex)
  3607. {
  3608. string str = ex.StackTrace;
  3609. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3610. CommandFromPLC resultToPlC = new CommandFromPLC();
  3611. resultToPlC.cmd = 0;
  3612. resultToPlC.cmdParam = 0; //指令参数
  3613. resultToPlC.cmdResult = 110;
  3614. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3615. }
  3616. stopwatch1.Stop();
  3617. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  3618. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3619. ProgressState = false;
  3620. //开始采集螺丝数据
  3621. if (direction == "Left")
  3622. {
  3623. isCollectingFlagLeft = true;
  3624. CollectAndProcessDataLeft(atlasScrew, atlasSn, direction);
  3625. }
  3626. if (direction == "Right")
  3627. {
  3628. isCollectingFlagRight = true;
  3629. CollectAndProcessDataRight(atlasScrew, atlasSn, direction);
  3630. }
  3631. }
  3632. /// <summary>
  3633. /// [S7] 锁螺丝设备 - 出站
  3634. /// </summary>
  3635. private void S7出站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, string direction, out bool ProgressState)
  3636. {
  3637. Stopwatch stopwatch1 = new Stopwatch();
  3638. Stopwatch stopwatch2 = new Stopwatch();
  3639. try
  3640. {
  3641. stopwatch1.Start();
  3642. AddMessage(LogType.Info, stationNameStr +"_"+ direction+ "_出站开始");
  3643. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3644. string processItem = stationName; // 测试项目
  3645. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3646. string supplierCode = ""; // 供应商代码
  3647. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3648. string batch_num = GlobalContext.BatchNumber; // 批次号
  3649. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3650. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3651. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3652. string MachineId = GlobalContext.S7_MachineId; // 装备id(可配置)
  3653. string StationId = string.Empty; // 工位ID(可配置)
  3654. if (direction == "Left")
  3655. {
  3656. StationId = GlobalContext.S7_StationId_1;
  3657. }
  3658. if (direction == "Right")
  3659. {
  3660. StationId = GlobalContext.S7_StationId_2;
  3661. }
  3662. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3663. a1Result = 1;
  3664. bool pass = a1Result == 1;
  3665. //根据载具码获取产品码
  3666. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3667. if (string.IsNullOrEmpty(strProductBarcode))
  3668. {
  3669. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3670. }
  3671. sn = strProductBarcode;
  3672. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3673. List<TestItem> items = new List<TestItem>();
  3674. items.Add(new TestItem()
  3675. {
  3676. Parameter_name = "载具码",
  3677. Parameter_value = CarrierBarcode,
  3678. Parameter_unit = ""
  3679. });
  3680. items.Add(new TestItem()
  3681. {
  3682. Parameter_name = "产品码",
  3683. Parameter_value = sn,
  3684. Parameter_unit = ""
  3685. });
  3686. int result1 = 1;
  3687. if (direction == "Right")
  3688. {
  3689. SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3690. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3691. }
  3692. //if (direction == "Left")
  3693. //{
  3694. // isCollectingFlagLeft = false;//采集螺丝数据结束
  3695. //}
  3696. //if (direction == "Right")
  3697. //{
  3698. // isCollectingFlagRight = false;//采集螺丝数据结束
  3699. //}
  3700. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3701. stopwatch2.Start();
  3702. //进站结果写入PLC
  3703. CommandFromPLC resultToPlC = new CommandFromPLC();
  3704. resultToPlC.cmd = 0;
  3705. resultToPlC.cmdParam = 0; //指令参数
  3706. resultToPlC.cmdResult = mesResultFrmWeb;
  3707. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3708. stopwatch2.Stop();
  3709. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  3710. //保存PLC返回MES数据到本地
  3711. ResponseMessage message = new ResponseMessage();
  3712. if (direction == "Left")
  3713. {
  3714. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  3715. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  3716. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3717. message = SQLHelper.InsertOp701Data(CarrierBarcode, sn, strMesHeightInfos,
  3718. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  3719. if (message.result == false)
  3720. {
  3721. AddMessage(LogType.Info, stationNameStr + "_Left_保存加工数据失败");
  3722. }
  3723. }
  3724. if (direction == "Right")
  3725. {
  3726. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  3727. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  3728. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3729. message = SQLHelper.InsertOp702Data(CarrierBarcode, sn, strMesHeightInfos,
  3730. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  3731. if (message.result == false)
  3732. {
  3733. AddMessage(LogType.Info, stationNameStr + "__Right_保存加工数据失败");
  3734. }
  3735. }
  3736. //保存螺丝数据到txt
  3737. (int, string) result = SaveScrewDataToTxt(direction, sn, stPLC_MesData.mesData.fScrewTimes, stPLC_MesData.mesData.nScrewOrders, stPLC_MesData.mesData.nScrewResults);
  3738. if (result.Item1 != 0)
  3739. {
  3740. AddMessage(LogType.Error, $"{stationNameStr}螺丝数据保存失败 " + message.text);
  3741. }
  3742. AddMessage(LogType.Info, stationNameStr + "_"+ direction+"_保存加工数据到本地成功");
  3743. }
  3744. catch (Exception ex)
  3745. {
  3746. stopwatch2.Start();
  3747. CommandFromPLC resultToPlC = new CommandFromPLC();
  3748. resultToPlC.cmd = 0;
  3749. resultToPlC.cmdParam = 0; //指令参数
  3750. resultToPlC.cmdResult = 110;
  3751. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3752. stopwatch2.Stop();
  3753. string str = ex.StackTrace;
  3754. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3755. }
  3756. stopwatch1.Stop();
  3757. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3758. ProgressState = false;
  3759. }
  3760. #endregion
  3761. #region S8
  3762. /// <summary>
  3763. /// [S8] 3D螺丝高度检测设备
  3764. /// </summary>
  3765. /// <param name="plcNo">PLC编号</param>
  3766. private void ReadStation_S8(int plcNo)
  3767. {
  3768. string stationCode = "[OP80]";
  3769. string stationName = "NG下料";
  3770. string stationNameStr = stationCode + stationName;
  3771. string tagBaseName = "g_OP80_MES"; //标签变量名称
  3772. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3773. string tagAgvCommName = "agvCommFrmPC";
  3774. string tagBarsetName = "BarcodeSet";
  3775. OP80_MesData_t stPLC_MesData; //PLC的MES数据
  3776. (int, string) result;
  3777. while (true)
  3778. {
  3779. try
  3780. {
  3781. if (!GlobalContext._IsCon_Funs1)
  3782. {
  3783. UpdatePLCMonitor(1, plcNo, 0);
  3784. continue;
  3785. }
  3786. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3787. {
  3788. Stopwatch stopwatch1 = new Stopwatch();
  3789. Stopwatch stopwatch2 = new Stopwatch();
  3790. stopwatch1.Start();
  3791. stopwatch2.Start();
  3792. #region 一次性读取所有数据
  3793. // 一次性读取所有数据
  3794. result = FunsEip[plcNo].Read_SingleTag<OP80_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3795. if (result.Item1 != 0)
  3796. {
  3797. //richTextBox1.AppendText("\n" + strRet);
  3798. }
  3799. else
  3800. {
  3801. //richTextBox1.AppendText("\n" + "读取成功");
  3802. }
  3803. #endregion 一次性读取所有数据
  3804. stopwatch2.Stop();
  3805. #region 进站
  3806. try
  3807. {
  3808. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3809. {
  3810. lock (lockObj)
  3811. {
  3812. if (!ProgressState)
  3813. {
  3814. ProgressState = true;
  3815. Task.Run(() => S8进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3816. }
  3817. }
  3818. }
  3819. }
  3820. catch (Exception ex)
  3821. {
  3822. ProgressState = false;
  3823. string str = ex.StackTrace;
  3824. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3825. }
  3826. #endregion 进站
  3827. #region 出站
  3828. try
  3829. {
  3830. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3831. {
  3832. lock (lockObj)
  3833. {
  3834. if (!ProgressState)
  3835. {
  3836. ProgressState = true;
  3837. Task.Run(() => S8出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3838. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  3839. }
  3840. }
  3841. }
  3842. }
  3843. catch (Exception ex)
  3844. {
  3845. ProgressState = false;
  3846. string str = ex.StackTrace;
  3847. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3848. }
  3849. #endregion 出站
  3850. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3851. stopwatch1.Stop();
  3852. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3853. }
  3854. else
  3855. {
  3856. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3857. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3858. FunsEip[plcNo].Connect(); // 重连
  3859. }
  3860. }
  3861. catch (Exception ex)
  3862. {
  3863. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3864. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3865. }
  3866. Thread.Sleep(IntervalReadPLC);
  3867. }
  3868. }
  3869. /// <summary>
  3870. /// [S8] 3D螺丝高度检测设备 - 进站
  3871. /// </summary>
  3872. /// <param name="plcNo">PLC编号</param>
  3873. /// <param name="stationNameStr">工站全称</param>
  3874. /// <param name="stPLC_MesData"></param>
  3875. /// <param name="tagMesCommName"></param>
  3876. private void S8进站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3877. {
  3878. Stopwatch stopwatch1 = new Stopwatch();
  3879. Stopwatch stopwatch2 = new Stopwatch();
  3880. try
  3881. {
  3882. stopwatch1.Start();
  3883. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3884. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3885. string MachineId = GlobalContext.S8_MachineId; // 装备ID(可配置)
  3886. string StationId = GlobalContext.S8_StationId; // 工位ID(可配置)
  3887. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3888. //载具码验证产品码
  3889. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3890. if (string.IsNullOrEmpty(strProductBarcode))
  3891. {
  3892. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3893. }
  3894. sn = strProductBarcode;
  3895. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3896. // 产品SN(物料码)校验
  3897. List<TestItem> item = new List<TestItem>();
  3898. stopwatch2.Start();
  3899. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3900. stopwatch2.Stop();
  3901. //指令执行结果 1:OK 110:失败
  3902. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3903. //进站结果写入PLC
  3904. CommandFromPLC resultToPlC = new CommandFromPLC();
  3905. resultToPlC.cmd = 0;
  3906. resultToPlC.cmdParam = 0; //指令参数
  3907. resultToPlC.cmdResult = mesResultFrmWeb;
  3908. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3909. }
  3910. catch (Exception ex)
  3911. {
  3912. string str = ex.StackTrace;
  3913. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3914. CommandFromPLC resultToPlC = new CommandFromPLC();
  3915. resultToPlC.cmd = 0;
  3916. resultToPlC.cmdParam = 0; //指令参数
  3917. resultToPlC.cmdResult = 110;
  3918. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3919. }
  3920. stopwatch1.Stop();
  3921. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3922. ProgressState = false;
  3923. }
  3924. /// <summary>
  3925. /// [S8] 3D螺丝高度检测设备 - 出站接口
  3926. /// </summary>
  3927. private void S8出站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3928. {
  3929. Stopwatch stopwatch1 = new Stopwatch();
  3930. Stopwatch stopwatch2 = new Stopwatch();
  3931. try
  3932. {
  3933. stopwatch1.Start();
  3934. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3935. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3936. string processItem = stationName; // 测试项目
  3937. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3938. string supplierCode = ""; // 供应商代码
  3939. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3940. string batch_num = GlobalContext.BatchNumber; // 批次号
  3941. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3942. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3943. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3944. string MachineId = GlobalContext.S8_MachineId; // 装备id(可配置) // ZS
  3945. string StationId = GlobalContext.S8_StationId; // ⼯位ID(可配置) // ZS
  3946. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3947. bool pass = a1Result == 1;
  3948. //根据载具码获取产品码
  3949. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3950. if (string.IsNullOrEmpty(strProductBarcode))
  3951. {
  3952. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3953. }
  3954. sn = strProductBarcode;
  3955. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3956. List<TestItem> items = new List<TestItem>();
  3957. items.Add(new TestItem()
  3958. {
  3959. Parameter_name = "载具码",
  3960. Parameter_value = CarrierBarcode,
  3961. Parameter_unit = ""
  3962. });
  3963. items.Add(new TestItem()
  3964. {
  3965. Parameter_name = "产品码",
  3966. Parameter_value = sn,
  3967. Parameter_unit = ""
  3968. });
  3969. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3970. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3971. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3972. stopwatch2.Start();
  3973. //进站结果写入PLC
  3974. CommandFromPLC resultToPlC = new CommandFromPLC();
  3975. resultToPlC.cmd = 0;
  3976. resultToPlC.cmdParam = 0; //指令参数
  3977. resultToPlC.cmdResult = mesResultFrmWeb;
  3978. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3979. stopwatch2.Stop();
  3980. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3981. //保存PLC返回MES数据到本地
  3982. ResponseMessage message = new ResponseMessage();
  3983. string strScrewHeights = FloatArrayToString(stPLC_MesData.mesData.fScrewHeights);
  3984. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3985. message = SQLHelper.InsertOp80Data(CarrierBarcode, sn, strScrewHeights, strScrewResults);
  3986. if (message.result == false)
  3987. {
  3988. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3989. }
  3990. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3991. }
  3992. catch (Exception ex)
  3993. {
  3994. stopwatch2.Start();
  3995. CommandFromPLC resultToPlC = new CommandFromPLC();
  3996. resultToPlC.cmd = 0;
  3997. resultToPlC.cmdParam = 0; //指令参数
  3998. resultToPlC.cmdResult = 110;
  3999. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4000. stopwatch2.Stop();
  4001. string str = ex.StackTrace;
  4002. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4003. }
  4004. stopwatch1.Stop();
  4005. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4006. ProgressState = false;
  4007. }
  4008. #endregion
  4009. #region S9
  4010. /// <summary>
  4011. /// [S9] 下料设备
  4012. /// </summary>
  4013. /// <param name="plcNo">PLC编号</param>
  4014. private void ReadStation_S9(int plcNo)
  4015. {
  4016. string stationCode = "[OP90]";
  4017. string stationName = "半成品下料";
  4018. string stationNameStr = stationCode + stationName;
  4019. string tagBaseName = "g_OP90_MES"; //标签变量名称
  4020. string tagMesCommName = "mesCommToPC"; //标签变量名称
  4021. string tagAgvCommName = "agvCommFrmPC";
  4022. string tagBarsetName = "BarcodeSet";
  4023. OP90_MesData_t stPLC_MesData; //PLC的MES数据
  4024. (int, string) result;
  4025. while (true)
  4026. {
  4027. try
  4028. {
  4029. if (!GlobalContext._IsCon_Funs1)
  4030. {
  4031. UpdatePLCMonitor(1, plcNo, 0);
  4032. continue;
  4033. }
  4034. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  4035. {
  4036. Stopwatch stopwatch1 = new Stopwatch();
  4037. Stopwatch stopwatch2 = new Stopwatch();
  4038. stopwatch1.Start();
  4039. stopwatch2.Start();
  4040. #region 一次性读取所有数据
  4041. // 一次性读取所有数据
  4042. result = FunsEip[plcNo].Read_SingleTag<OP90_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  4043. if (result.Item1 != 0)
  4044. {
  4045. //richTextBox1.AppendText("\n" + strRet);
  4046. }
  4047. else
  4048. {
  4049. //richTextBox1.AppendText("\n" + "读取成功");
  4050. }
  4051. #endregion 一次性读取所有数据
  4052. stopwatch2.Stop();
  4053. #region 进站
  4054. try
  4055. {
  4056. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  4057. {
  4058. lock (lockObj)
  4059. {
  4060. if (!ProgressState)
  4061. {
  4062. ProgressState = true;
  4063. Task.Run(() => S9进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  4064. }
  4065. }
  4066. }
  4067. }
  4068. catch (Exception ex)
  4069. {
  4070. ProgressState = false;
  4071. string str = ex.StackTrace;
  4072. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4073. }
  4074. #endregion 进站
  4075. #region 出站
  4076. try
  4077. {
  4078. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  4079. {
  4080. lock (lockObj)
  4081. {
  4082. if (!ProgressState)
  4083. {
  4084. ProgressState = true;
  4085. Task.Run(() => S9出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  4086. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  4087. }
  4088. }
  4089. }
  4090. }
  4091. catch (Exception ex)
  4092. {
  4093. ProgressState = false;
  4094. string str = ex.StackTrace;
  4095. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4096. }
  4097. #endregion 出站
  4098. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4099. stopwatch1.Stop();
  4100. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4101. }
  4102. else
  4103. {
  4104. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4105. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4106. FunsEip[plcNo].Connect(); // 重连
  4107. }
  4108. }
  4109. catch (Exception ex)
  4110. {
  4111. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4112. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4113. }
  4114. Thread.Sleep(IntervalReadPLC);
  4115. }
  4116. }
  4117. /// <summary>
  4118. /// [S9] 下料设备 - 进站
  4119. /// </summary>
  4120. /// <param name="plcNo">PLC编号</param>
  4121. /// <param name="stationNameStr">工站全称</param>
  4122. /// <param name="stPLC_MesData"></param>
  4123. /// <param name="tagMesCommName"></param>
  4124. private void S9进站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  4125. {
  4126. Stopwatch stopwatch1 = new Stopwatch();
  4127. Stopwatch stopwatch2 = new Stopwatch();
  4128. try
  4129. {
  4130. stopwatch1.Start();
  4131. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  4132. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  4133. string MachineId = GlobalContext.S9_MachineId; // 装备ID(可配置)
  4134. string StationId = GlobalContext.S9_StationId; // 工位ID(可配置)
  4135. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  4136. //载具码验证产品码
  4137. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  4138. if (string.IsNullOrEmpty(strProductBarcode))
  4139. {
  4140. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4141. }
  4142. sn = strProductBarcode;
  4143. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  4144. // 产品SN(物料码)校验
  4145. List<TestItem> item = new List<TestItem>();
  4146. stopwatch2.Start();
  4147. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  4148. stopwatch2.Stop();
  4149. //指令执行结果 1:OK 110:失败
  4150. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  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. }
  4158. catch (Exception ex)
  4159. {
  4160. string str = ex.StackTrace;
  4161. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4162. CommandFromPLC resultToPlC = new CommandFromPLC();
  4163. resultToPlC.cmd = 0;
  4164. resultToPlC.cmdParam = 0; //指令参数
  4165. resultToPlC.cmdResult = 110;
  4166. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4167. }
  4168. stopwatch1.Stop();
  4169. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  4170. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4171. ProgressState = false;
  4172. }
  4173. /// <summary>
  4174. /// [S9] 下料设备 - 出站接口
  4175. /// </summary>
  4176. private void S9出站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  4177. {
  4178. Stopwatch stopwatch1 = new Stopwatch();
  4179. Stopwatch stopwatch2 = new Stopwatch();
  4180. try
  4181. {
  4182. stopwatch1.Start();
  4183. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  4184. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4185. string processItem = stationName; // 测试项目
  4186. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4187. string supplierCode = ""; // 供应商代码
  4188. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4189. string batch_num = GlobalContext.BatchNumber; // 批次号
  4190. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4191. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4192. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4193. string MachineId = GlobalContext.S9_MachineId; // 装备id(可配置) // ZS
  4194. string StationId = GlobalContext.S9_StationId; // ⼯位ID(可配置) // ZS
  4195. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4196. bool pass = a1Result == 1;
  4197. //根据载具码获取产品码
  4198. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4199. if (string.IsNullOrEmpty(strProductBarcode))
  4200. {
  4201. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4202. }
  4203. sn = strProductBarcode;
  4204. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  4205. List<TestItem> items = new List<TestItem>();
  4206. items.Add(new TestItem()
  4207. {
  4208. Parameter_name = "载具码",
  4209. Parameter_value = CarrierBarcode,
  4210. Parameter_unit = ""
  4211. });
  4212. items.Add(new TestItem()
  4213. {
  4214. Parameter_name = "产品码",
  4215. Parameter_value = sn,
  4216. Parameter_unit = ""
  4217. });
  4218. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4219. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  4220. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4221. stopwatch2.Start();
  4222. //进站结果写入PLC
  4223. CommandFromPLC resultToPlC = new CommandFromPLC();
  4224. resultToPlC.cmd = 0;
  4225. resultToPlC.cmdParam = 0; //指令参数
  4226. resultToPlC.cmdResult = mesResultFrmWeb;
  4227. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4228. stopwatch2.Stop();
  4229. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  4230. //保存PLC返回MES数据到本地
  4231. ResponseMessage message = new ResponseMessage();
  4232. message = SQLHelper.InsertOp90Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.nRemainCount);
  4233. if (message.result == false)
  4234. {
  4235. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4236. }
  4237. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4238. if (result1 == 1)
  4239. {
  4240. //载具码解除绑定
  4241. message = SQLHelper.DelCarrierBind(CarrierBarcode);
  4242. if (message.result == false)
  4243. {
  4244. AddMessage(LogType.Error, message.text);
  4245. }
  4246. }
  4247. }
  4248. catch (Exception ex)
  4249. {
  4250. stopwatch2.Start();
  4251. CommandFromPLC resultToPlC = new CommandFromPLC();
  4252. resultToPlC.cmd = 0;
  4253. resultToPlC.cmdParam = 0; //指令参数
  4254. resultToPlC.cmdResult = 110;
  4255. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4256. stopwatch2.Stop();
  4257. string str = ex.StackTrace;
  4258. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4259. }
  4260. stopwatch1.Stop();
  4261. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4262. ProgressState = false;
  4263. }
  4264. #endregion
  4265. #endregion Xiaomi
  4266. #region PLC1 张超凡
  4267. #region [S1] Tray盘上料装备(板测)
  4268. /// <summary>
  4269. /// S1工位的数据- 触发信号上次的值
  4270. /// </summary>
  4271. private Dictionary<string, object> s1PLCSignal_Old = new Dictionary<string, object>();
  4272. /// <summary>
  4273. /// S1工位的数据(含触发信号)
  4274. /// </summary>
  4275. private Dictionary<string, object> s1PLCData = new Dictionary<string, object>();
  4276. /// <summary>
  4277. /// S1工位的数据- 回写点位
  4278. /// </summary>
  4279. private Dictionary<string, WriteToPLC_Flag> s1PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  4280. ///// <summary>
  4281. ///// 触发信号
  4282. ///// </summary>
  4283. //private ManualResetEvent[] MreTasks;
  4284. /// <summary>
  4285. /// [S1] Tray盘上料装备(板测)
  4286. /// </summary>
  4287. /// <param name="plcNo">PLC编号</param>
  4288. //private void ReadStation_S1(int plcNo)
  4289. //{
  4290. // // [S1] Tray盘上料装备
  4291. // // [S2] FCT
  4292. // // [S3] 值板机
  4293. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  4294. // // [S5] Tray盘下料装备
  4295. // string stationCode = "[S1]";
  4296. // string stationName = "Tray盘上料装备";
  4297. // string stationNameStr = stationCode + stationName;
  4298. // #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4299. // // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4300. // s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  4301. // s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  4302. // s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  4303. // s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  4304. // s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4305. // s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  4306. // s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  4307. // s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  4308. // s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  4309. // // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4310. // s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  4311. // s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
  4312. // s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
  4313. // s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  4314. // s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
  4315. // s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
  4316. // s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  4317. // s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
  4318. // s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
  4319. // s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
  4320. // s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
  4321. // s1PLCData.Add("a1Result", 0); // 产品结果
  4322. // s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  4323. // s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
  4324. // s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
  4325. // s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
  4326. // s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
  4327. // s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4328. // s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
  4329. // s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  4330. // s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  4331. // s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
  4332. // s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  4333. // s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  4334. // s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
  4335. // s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
  4336. // s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  4337. // s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
  4338. // s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
  4339. // #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4340. // while (IsRun)
  4341. // {
  4342. // try
  4343. // {
  4344. // if (!GlobalContext._IsCon_Funs1)
  4345. // {
  4346. // UpdatePLCMonitor(1, plcNo, 0);
  4347. // continue;
  4348. // }
  4349. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  4350. // {
  4351. // Stopwatch stopwatch1 = new Stopwatch();
  4352. // Stopwatch stopwatch2 = new Stopwatch();
  4353. // stopwatch1.Start();
  4354. // stopwatch2.Start();
  4355. // #region 一次性读取所有数据
  4356. // // 一次性读取所有数据
  4357. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  4358. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  4359. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  4360. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 33);
  4361. // int[] datas = data1.Concat(data2).ToArray();
  4362. // datas = datas.Concat(data3).ToArray();
  4363. // datas = datas.Concat(data4).ToArray();
  4364. // s1PLCData["a1PLC_FLAG_VehicleStates"] = datas[2]; // 载具进站查询状态
  4365. // s1PLCData["a1MES_FLAG_VehicleStates"] = datas[3];
  4366. // int[] a1ProductSN_VehicleStatesData = datas.Skip(4).Take(20).ToArray();
  4367. // s1PLCData["a1ProductSN_VehicleStates"] = ModbusClient.ConvertRegistersToString(a1ProductSN_VehicleStatesData, 0, 40);
  4368. // s1PLCData["a1PLC_FLAG_Check"] = datas[76]; // 上料进站校验
  4369. // s1PLCData["a1MES_FLAG_Check"] = datas[77];
  4370. // int[] a1ProductSN_CheckData = datas.Skip(78).Take(20).ToArray();
  4371. // s1PLCData["a1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(a1ProductSN_CheckData, 0, 40);
  4372. // s1PLCData["a1PLC_FLAG"] = datas[108]; // 出站接口
  4373. // s1PLCData["a1MES_FLAG"] = datas[109];
  4374. // int[] a1ProductSNData = datas.Skip(110).Take(20).ToArray();
  4375. // s1PLCData["a1ProductSN"] = ModbusClient.ConvertRegistersToString(a1ProductSNData, 0, 40);
  4376. // int[] a1PartNo1Data = datas.Skip(130).Take(20).ToArray();
  4377. // s1PLCData["a1PartNo1"] = ModbusClient.ConvertRegistersToString(a1PartNo1Data, 0, 40);
  4378. // int[] a1PartNo2Data = datas.Skip(150).Take(20).ToArray();
  4379. // s1PLCData["a1PartNo2"] = ModbusClient.ConvertRegistersToString(a1PartNo2Data, 0, 40);
  4380. // s1PLCData["a1Result"] = datas[170];
  4381. // s1PLCData["a1PLC_FLAG_ICT"] = datas[181]; // 将SN发给ICT标机(串口)
  4382. // s1PLCData["a1MES_FLAG_ICT"] = datas[182];
  4383. // int[] a1ProductSN_ICTData = datas.Skip(183).Take(20).ToArray();
  4384. // s1PLCData["a1ProductSN_ICT"] = ModbusClient.ConvertRegistersToString(a1ProductSN_ICTData, 0, 40);
  4385. // int[] a1PartNo1_ICTData = datas.Skip(203).Take(20).ToArray();
  4386. // s1PLCData["a1PartNo1_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo1_ICTData, 0, 40);
  4387. // int[] a1PartNo2_ICTData = datas.Skip(223).Take(20).ToArray();
  4388. // s1PLCData["a1PartNo2_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo2_ICTData, 0, 40);
  4389. // s1PLCData["a1OEEPLC_FLAG"] = datas[253]; // 节拍接口
  4390. // s1PLCData["a1OEEMES_FLAG"] = datas[254];
  4391. // int[] a1OEEPartNoData = datas.Skip(255).Take(20).ToArray();
  4392. // s1PLCData["a1OEEPartNo"] = ModbusClient.ConvertRegistersToString(a1OEEPartNoData, 0, 40); // 物料码(物料码还未绑定载具SN时必填)
  4393. // int[] a1OEEVehicleCodeData = datas.Skip(275).Take(20).ToArray();
  4394. // s1PLCData["a1OEEVehicleCode"] = ModbusClient.ConvertRegistersToString(a1OEEVehicleCodeData, 0, 40); // 载具SN
  4395. // s1PLCData["a1OEEPartNum"] = datas[295]; // 穴位号
  4396. // s1PLCData["a1OEEType"] = datas[296]; // 节拍类型(plc写入)
  4397. // s1PLCData["a1AGVUpCall"] = datas[307]; // AGV上料
  4398. // s1PLCData["a1AGVUpStart"] = datas[308];
  4399. // s1PLCData["a1AGVUpEnd"] = datas[309];
  4400. // s1PLCData["a1AGVDownCall"] = datas[320]; // AGV下料
  4401. // s1PLCData["a1AGVDownStart"] = datas[321];
  4402. // s1PLCData["a1AGVDownEnd"] = datas[322];
  4403. // #endregion 一次性读取所有数据
  4404. // stopwatch2.Stop();
  4405. // #region 回写操作,写后清空flag
  4406. // PLCWriteData(Funs[plcNo], ref s1PLCData, ref s1PLCWriteData);
  4407. // #endregion 回写操作,写后清空flag
  4408. // #region 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  4409. // try
  4410. // {
  4411. // int a1PLC_FLAG_VehicleStates = (int)s1PLCData["a1PLC_FLAG_VehicleStates"];
  4412. // int a1MES_FLAG_VehicleStates = (int)s1PLCData["a1MES_FLAG_VehicleStates"];
  4413. // int a1PLC_FLAG_VehicleStatesOld = (int)s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"];
  4414. // if (a1PLC_FLAG_VehicleStates != a1PLC_FLAG_VehicleStatesOld)
  4415. // {
  4416. // if (a1PLC_FLAG_VehicleStates == 1 && a1MES_FLAG_VehicleStates == 0) // 0->1
  4417. // Task.Run(() => S1载具进站查询状态(plcNo, stationNameStr)); // MreTasks[1].Set();
  4418. // else if (a1PLC_FLAG_VehicleStates == 0 && a1MES_FLAG_VehicleStates != 0)
  4419. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  4420. // s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"] = s1PLCData["a1PLC_FLAG_VehicleStates"];
  4421. // }
  4422. // }
  4423. // catch (Exception ex)
  4424. // {
  4425. // // 6代表上位机报警
  4426. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6);
  4427. // string str = ex.StackTrace;
  4428. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4429. // }
  4430. // #endregion 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  4431. // #region 上料进站校验
  4432. // try
  4433. // {
  4434. // int a1PLC_FLAG_Check = (int)s1PLCData["a1PLC_FLAG_Check"];
  4435. // int a1MES_FLAG_Check = (int)s1PLCData["a1MES_FLAG_Check"];
  4436. // int a1PLC_FLAG_CheckOld = (int)s1PLCSignal_Old["a1PLC_FLAG_Check"];
  4437. // if (a1PLC_FLAG_Check != a1PLC_FLAG_CheckOld)
  4438. // {
  4439. // if (a1PLC_FLAG_Check == 1 && a1MES_FLAG_Check == 0) // 0->1
  4440. // Task.Run(() => S1上料进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  4441. // else if (a1PLC_FLAG_Check == 0 && a1MES_FLAG_Check != 0)
  4442. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  4443. // s1PLCSignal_Old["a1PLC_FLAG_Check"] = s1PLCData["a1PLC_FLAG_Check"];
  4444. // }
  4445. // }
  4446. // catch (Exception ex)
  4447. // {
  4448. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  4449. // string str = ex.StackTrace;
  4450. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4451. // }
  4452. // #endregion 上料进站校验
  4453. // #region Tray盘上料装备-出站接口
  4454. // try
  4455. // {
  4456. // int a1PLC_FLAG = (int)s1PLCData["a1PLC_FLAG"];
  4457. // int a1MES_FLAG = (int)s1PLCData["a1MES_FLAG"];
  4458. // int a1PLC_FLAGOld = (int)s1PLCSignal_Old["a1PLC_FLAG"];
  4459. // if (a1PLC_FLAG != a1PLC_FLAGOld)
  4460. // {
  4461. // if (a1PLC_FLAG == 1 && a1MES_FLAG == 0) // 0->1
  4462. // Task.Run(() => S1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  4463. // else if (a1PLC_FLAG == 0 && a1MES_FLAG != 0)
  4464. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)0);
  4465. // s1PLCSignal_Old["a1PLC_FLAG"] = s1PLCData["a1PLC_FLAG"];
  4466. // }
  4467. // }
  4468. // catch (Exception ex)
  4469. // {
  4470. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)6); // 6代表上位机报警
  4471. // string str = ex.StackTrace;
  4472. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4473. // }
  4474. // #endregion Tray盘上料装备-出站接口
  4475. // #region Tray盘上料装备-将SN发给ICT标机
  4476. // try
  4477. // {
  4478. // int a1PLC_FLAG_ICT = (int)s1PLCData["a1PLC_FLAG_ICT"];
  4479. // int a1MES_FLAG_ICT = (int)s1PLCData["a1MES_FLAG_ICT"];
  4480. // int a1PLC_FLAG_ICTOld = (int)s1PLCSignal_Old["a1PLC_FLAG_ICT"];
  4481. // if (a1PLC_FLAG_ICT != a1PLC_FLAG_ICTOld)
  4482. // {
  4483. // if (a1PLC_FLAG_ICT == 1 && a1MES_FLAG_ICT == 0) // 0->1
  4484. // Task.Run(() => S1将SN发给ICT标机(plcNo, stationNameStr)); // MreTasks[3].Set();
  4485. // else if (a1PLC_FLAG_ICT == 0 && a1MES_FLAG_ICT != 0)
  4486. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)0);
  4487. // s1PLCSignal_Old["a1PLC_FLAG_ICT"] = s1PLCData["a1PLC_FLAG_ICT"];
  4488. // }
  4489. // }
  4490. // catch (Exception ex)
  4491. // {
  4492. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  4493. // string str = ex.StackTrace;
  4494. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4495. // }
  4496. // #endregion Tray盘上料装备-将SN发给ICT标机
  4497. // #region Tray盘上料装备-点检数据
  4498. // //try
  4499. // //{
  4500. // // Funs[plcNo].Read_Int_Tag("828", 1, out short[] iPLC_Flag); // PLC_Flag
  4501. // // Funs[plcNo].Read_Int_Tag("829", 1, out short[] iMES_Flag); // MES_Flag
  4502. // // bool pLC_Flag = iPLC_Flag[0] == 1 ? true : false; // PLC_Flag
  4503. // // bool mES_Flag = iMES_Flag[0] == 1 ? true : false; // MES_Flag
  4504. // // if (pLC_Flag && !mES_Flag) // 1 0
  4505. // // {
  4506. // // AddMessage_Station(stationNameStr, LogType.Info, Head + stationNameStr + BodyCheck);
  4507. // // await Task.Run(() => { DoOneCheckData_Tray盘上料装备(plcNo, stationCode, stationName); });
  4508. // // AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + BodyCheck + Tail);
  4509. // // }
  4510. // // else if (!pLC_Flag && mES_Flag) // 0 1
  4511. // // {
  4512. // // // 清空写给PLC的数据
  4513. // // // MES_Flag重置为0
  4514. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 0 });
  4515. // // }
  4516. // //}
  4517. // //catch (Exception ex)
  4518. // //{
  4519. // // // MES_Flag 为2上位机报错
  4520. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  4521. // // string str = ex.StackTrace;
  4522. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}点检运行出错!错误信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4523. // //}
  4524. // #endregion Tray盘上料装备-点检数据
  4525. // #region 节拍接口
  4526. // try
  4527. // {
  4528. // int a1OEEPLC_FLAG = (int)s1PLCData["a1OEEPLC_FLAG"];
  4529. // int a1OEEMES_FLAG = (int)s1PLCData["a1OEEMES_FLAG"];
  4530. // int a1OEEPLC_FLAGOld = (int)s1PLCSignal_Old["a1OEEPLC_FLAG"];
  4531. // if (a1OEEPLC_FLAG != a1OEEPLC_FLAGOld)
  4532. // {
  4533. // if (a1OEEPLC_FLAG == 1 && a1OEEMES_FLAG == 0) // 0->1
  4534. // Task.Run(() => S1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  4535. // else if (a1OEEPLC_FLAG == 0 && a1OEEMES_FLAG != 0)
  4536. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)0); //
  4537. // s1PLCSignal_Old["a1OEEPLC_FLAG"] = s1PLCData["a1OEEPLC_FLAG"];
  4538. // }
  4539. // }
  4540. // catch (Exception ex)
  4541. // {
  4542. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  4543. // string str = ex.StackTrace;
  4544. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4545. // }
  4546. // #endregion 节拍接口
  4547. // #region AGV上料
  4548. // // AGV上料叫AGV信号
  4549. // try
  4550. // {
  4551. // int a1AGVUpCall = (int)s1PLCData["a1AGVUpCall"];
  4552. // int a1AGVUpCallOld = (int)s1PLCSignal_Old["a1AGVUpCall"];
  4553. // if (a1AGVUpCall != a1AGVUpCallOld)
  4554. // {
  4555. // if (a1AGVUpCall == 1) // 0->1
  4556. // Task.Run(() => S1AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  4557. // s1PLCSignal_Old["a1AGVUpCall"] = s1PLCData["a1AGVUpCall"];
  4558. // }
  4559. // }
  4560. // catch (Exception ex)
  4561. // {
  4562. // Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  4563. // string str = ex.StackTrace;
  4564. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4565. // }
  4566. // // AGV上料完成信号
  4567. // try
  4568. // {
  4569. // int a1AGVUpEnd = (int)s1PLCData["a1AGVUpEnd"];
  4570. // int a1AGVUpEndOld = (int)s1PLCSignal_Old["a1AGVUpEnd"];
  4571. // if (a1AGVUpEnd != a1AGVUpEndOld)
  4572. // {
  4573. // if (a1AGVUpEnd == 1) // 0->1
  4574. // Task.Run(() => S1AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  4575. // s1PLCSignal_Old["a1AGVUpEnd"] = s1PLCData["a1AGVUpEnd"];
  4576. // }
  4577. // }
  4578. // catch (Exception ex)
  4579. // {
  4580. // Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  4581. // string str = ex.StackTrace;
  4582. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4583. // }
  4584. // #endregion AGV上料
  4585. // #region AGV下料
  4586. // // AGV下料叫agv信号
  4587. // try
  4588. // {
  4589. // int a1AGVDownCall = (int)s1PLCData["a1AGVDownCall"];
  4590. // int a1AGVDownCallOld = (int)s1PLCSignal_Old["a1AGVDownCall"];
  4591. // if (a1AGVDownCall != a1AGVDownCallOld)
  4592. // {
  4593. // if (a1AGVDownCall == 1) // 0->1
  4594. // Task.Run(() => S1AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  4595. // s1PLCSignal_Old["a1AGVDownCall"] = s1PLCData["a1AGVDownCall"];
  4596. // }
  4597. // }
  4598. // catch (Exception ex)
  4599. // {
  4600. // Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  4601. // string str = ex.StackTrace;
  4602. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4603. // }
  4604. // // AGV下料完成信号
  4605. // try
  4606. // {
  4607. // int a1AGVDownEnd = (int)s1PLCData["a1AGVDownEnd"];
  4608. // int a1AGVDownEndOld = (int)s1PLCSignal_Old["a1AGVDownEnd"];
  4609. // if (a1AGVDownEnd != a1AGVDownEndOld)
  4610. // {
  4611. // if (a1AGVDownEnd == 1) // 0->1
  4612. // Task.Run(() => S1AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  4613. // s1PLCSignal_Old["a1AGVDownEnd"] = s1PLCData["a1AGVDownEnd"];
  4614. // }
  4615. // }
  4616. // catch (Exception ex)
  4617. // {
  4618. // Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  4619. // string str = ex.StackTrace;
  4620. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4621. // }
  4622. // #endregion AGV下料
  4623. // #region 心跳
  4624. // try
  4625. // {
  4626. // short states = 0;
  4627. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  4628. // }
  4629. // catch (Exception ex)
  4630. // {
  4631. // string str = ex.StackTrace;
  4632. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4633. // }
  4634. // #endregion 心跳
  4635. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4636. // stopwatch1.Stop();
  4637. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  4638. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4639. // }
  4640. // else
  4641. // {
  4642. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4643. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4644. // Funs[plcNo].Connect(); // 重连
  4645. // }
  4646. // }
  4647. // catch (Exception ex)
  4648. // {
  4649. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4650. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4651. // Funs[plcNo].ReConnect();
  4652. // }
  4653. // Thread.Sleep(IntervalReadPLC);
  4654. // }
  4655. //}
  4656. /// <summary>
  4657. /// [S1] Tray盘上料装备(板测)- 载具进站查询状态
  4658. /// </summary>
  4659. /// <param name="plcNo">PLC编号</param>
  4660. /// <param name="stationNameStr">工站全称</param>
  4661. private void S1载具进站查询状态(int plcNo, string stationNameStr)
  4662. {
  4663. Stopwatch stopwatch1 = new Stopwatch();
  4664. Stopwatch stopwatch2 = new Stopwatch();
  4665. try
  4666. {
  4667. stopwatch1.Start();
  4668. string sn = (string)s1PLCData["a1ProductSN_VehicleStates"]; // 产品SN(载具码)
  4669. sn = sn.Replace("\0", "");
  4670. #region 查询载具上的产品信息
  4671. string cavityData = string.Empty;
  4672. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  4673. if (string.IsNullOrEmpty(cavityData))
  4674. cavityData = "";
  4675. if (snResult != 0)
  4676. {
  4677. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  4678. writeToPLC_Flag1.Name = "a1MES_FLAG_VehicleStates";
  4679. writeToPLC_Flag1.Adress = 2003;
  4680. writeToPLC_Flag1.Value = (short)6;
  4681. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag1);
  4682. stopwatch1.Stop();
  4683. AddMessage(LogType.Info, stationNameStr + $"_载具进站查询状态失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  4684. return;
  4685. }
  4686. #endregion 查询载具上的产品信息
  4687. string[] cavitySNs = cavityData.Split('.');
  4688. string a1CavitySN1_VehicleStates = ""; // 穴位1物料SN(上位机写入)
  4689. string a1CavitySN2_VehicleStates = ""; // 穴位2物料SN(上位机写入)
  4690. short a1CavityResult1_VehicleStates = 1; // 1空;2ng;3假产品;
  4691. short a1CavityResult2_VehicleStates = 1; // 1空;2ng;3假产品;
  4692. if (cavitySNs != null && cavitySNs.Length >= 2)
  4693. {
  4694. a1CavitySN1_VehicleStates = cavitySNs[0];
  4695. a1CavitySN2_VehicleStates = cavitySNs[1];
  4696. a1CavityResult1_VehicleStates = 2;
  4697. a1CavityResult2_VehicleStates = 2;
  4698. }
  4699. if (a1CavitySN1_VehicleStates == "假产品")
  4700. a1CavityResult1_VehicleStates = 3;
  4701. if (a1CavitySN2_VehicleStates == "假产品")
  4702. a1CavityResult2_VehicleStates = 3;
  4703. short mES_Flag = 1; // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  4704. // 回写
  4705. stopwatch2.Start();
  4706. //Funs[plcNo].WriteMultipleRegisters<string>(2024, a1CavitySN1_VehicleStates, 20);
  4707. //Funs[plcNo].WriteMultipleRegisters<string>(2044, a1CavitySN2_VehicleStates, 20);
  4708. //Funs[plcNo].WriteMultipleRegisters<short>(2064, a1CavityResult1_VehicleStates);
  4709. //Funs[plcNo].WriteMultipleRegisters<short>(2065, a1CavityResult2_VehicleStates);
  4710. //// MES_Flag
  4711. //Funs[plcNo].WriteMultipleRegisters<short>(2003, mES_Flag);
  4712. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4713. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  4714. writeToPLC_Flag.Adress = 2003;
  4715. writeToPLC_Flag.Value = mES_Flag;
  4716. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  4717. {
  4718. Name = "a1CavitySN1_VehicleStates",
  4719. Adress = 2024,
  4720. ValueType = PLCValueType.String,
  4721. ValueTypeStrLength = 20,
  4722. Value = a1CavitySN1_VehicleStates
  4723. });
  4724. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位2物料SN(上位机写入)
  4725. {
  4726. Name = "a1CavitySN2_VehicleStates",
  4727. Adress = 2044,
  4728. ValueType = PLCValueType.String,
  4729. ValueTypeStrLength = 20,
  4730. Value = a1CavitySN2_VehicleStates
  4731. });
  4732. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  4733. {
  4734. Name = "a1CavityResult1_VehicleStates",
  4735. Adress = 2064,
  4736. ValueType = PLCValueType.Short,
  4737. Value = a1CavityResult1_VehicleStates
  4738. });
  4739. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  4740. {
  4741. Name = "a1CavityResult2_VehicleStates",
  4742. Adress = 2065,
  4743. ValueType = PLCValueType.Short,
  4744. Value = a1CavityResult2_VehicleStates
  4745. });
  4746. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  4747. stopwatch2.Stop();
  4748. }
  4749. catch (Exception ex)
  4750. {
  4751. string str = ex.StackTrace;
  4752. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4753. // MES_Flag
  4754. stopwatch2.Start();
  4755. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  4756. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4757. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  4758. writeToPLC_Flag.Adress = 2003;
  4759. writeToPLC_Flag.Value = (short)6;
  4760. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  4761. stopwatch2.Stop();
  4762. }
  4763. stopwatch1.Stop();
  4764. AddMessage(LogType.Info, stationNameStr + "_载具进站查询状态;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4765. }
  4766. /// <summary>
  4767. /// [S1] Tray盘上料装备(板测)- 上料进站校验
  4768. /// </summary>
  4769. /// <param name="plcNo">PLC编号</param>
  4770. /// <param name="stationNameStr">工站全称</param>
  4771. private void S1上料进站校验(int plcNo, string stationNameStr)
  4772. {
  4773. Stopwatch stopwatch1 = new Stopwatch();
  4774. Stopwatch stopwatch2 = new Stopwatch();
  4775. try
  4776. {
  4777. stopwatch1.Start();
  4778. string sn = (string)s1PLCData["a1ProductSN_Check"]; // 产品SN(物料码)
  4779. sn = sn.Replace("\0", "");
  4780. // 保存进站数据+调用进站MES接口
  4781. List<TestItem> item = new List<TestItem>();
  4782. stopwatch2.Start();
  4783. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, out string errorMsg);
  4784. stopwatch2.Stop();
  4785. short a1MES_FLAG_Check = (short)result;
  4786. //Funs[plcNo].WriteMultipleRegisters<short>(2077, a1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  4787. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4788. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  4789. writeToPLC_Flag.Adress = 2077;
  4790. writeToPLC_Flag.Value = a1MES_FLAG_Check;
  4791. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  4792. }
  4793. catch (Exception ex)
  4794. {
  4795. string str = ex.StackTrace;
  4796. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4797. // MES_Flag
  4798. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  4799. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4800. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  4801. writeToPLC_Flag.Adress = 2077;
  4802. writeToPLC_Flag.Value = (short)6;
  4803. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  4804. }
  4805. stopwatch1.Stop();
  4806. AddMessage(LogType.Info, stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4807. }
  4808. /// <summary>
  4809. /// [S1] Tray盘上料装备(板测)- 出站接口
  4810. /// </summary>
  4811. /// <param name="plcNo"></param>
  4812. /// <param name="stationCode"></param>
  4813. /// <param name="stationName"></param>
  4814. private void S1出站接口(int plcNo, string stationCode, string stationName)
  4815. {
  4816. Stopwatch stopwatch1 = new Stopwatch();
  4817. Stopwatch stopwatch2 = new Stopwatch();
  4818. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4819. string stationNameStr = stationCode + stationName;
  4820. string processItem = stationName; // 测试项目
  4821. try
  4822. {
  4823. stopwatch1.Start();
  4824. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4825. //string batch_num = GlobalContext.BatchNumber; // 批次号
  4826. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4827. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4828. string sn = (string)s1PLCData["a1ProductSN"]; // 产品SN(载具SN码)
  4829. sn = sn.Replace("\0", "");
  4830. string partNo1 = (string)s1PLCData["a1PartNo1"]; // 物料码1(穴位1)
  4831. partNo1 = partNo1.Replace("\0", "");
  4832. string partNo2 = (string)s1PLCData["a1PartNo2"]; // 物料码2(穴位2)
  4833. partNo2 = partNo2.Replace("\0", "");
  4834. int a1Result = (int)s1PLCData["a1Result"]; // 产品结果
  4835. bool pass = a1Result == 1;
  4836. stopwatch2.Start();
  4837. // 产品1
  4838. List<TestItem> items = new List<TestItem>();
  4839. items.Add(new TestItem()
  4840. {
  4841. Parameter_name = "载具码",
  4842. Parameter_value = sn,
  4843. Parameter_unit = ""
  4844. });
  4845. items.Add(new TestItem()
  4846. {
  4847. Parameter_name = "载具穴号",
  4848. Parameter_value = "1",
  4849. Parameter_unit = ""
  4850. });
  4851. items.Add(new TestItem()
  4852. {
  4853. Parameter_name = "产品结果",
  4854. Parameter_value = a1Result == 1 ? "OK" : "NG",
  4855. Parameter_unit = ""
  4856. });
  4857. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4858. , workorder_code, mtltmrk, partNo1, pass, sn, "1");
  4859. // 产品2
  4860. items = new List<TestItem>();
  4861. items.Add(new TestItem()
  4862. {
  4863. Parameter_name = "载具码",
  4864. Parameter_value = sn,
  4865. Parameter_unit = ""
  4866. });
  4867. items.Add(new TestItem()
  4868. {
  4869. Parameter_name = "载具穴号",
  4870. Parameter_value = "2",
  4871. Parameter_unit = ""
  4872. });
  4873. items.Add(new TestItem()
  4874. {
  4875. Parameter_name = "产品结果",
  4876. Parameter_value = a1Result == 1 ? "OK" : "NG",
  4877. Parameter_unit = ""
  4878. });
  4879. int result2 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4880. , workorder_code, mtltmrk, partNo2, pass, sn, "2");
  4881. short result = 0;
  4882. List<int> results = new List<int>() { result1, result2 };
  4883. if (result1 == 1 && result2 == 1)
  4884. result = 1;
  4885. else if (results.Contains(3))
  4886. result = 3;
  4887. else if (results.Contains(2))
  4888. result = 2;
  4889. else if (results.Contains(4))
  4890. result = 4;
  4891. else
  4892. result = 4;
  4893. stopwatch2.Stop();
  4894. #region 存储绑定数据到 边线MES系统中
  4895. if (result == 1)
  4896. {
  4897. string data = string.Concat(partNo1, ".", partNo2);
  4898. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  4899. if (resultMesR != 0)
  4900. {
  4901. result = 4;
  4902. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  4903. }
  4904. }
  4905. #endregion 存储绑定数据到 边线MES系统中
  4906. // MES_Flag 为MES报错
  4907. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4908. //Funs[plcNo].WriteMultipleRegisters<short>(2109, result); // 4代表上位机报警
  4909. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4910. writeToPLC_Flag.Name = "a1MES_FLAG";
  4911. writeToPLC_Flag.Adress = 2109;
  4912. writeToPLC_Flag.Value = result;
  4913. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  4914. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  4915. }
  4916. catch (Exception ex)
  4917. {
  4918. stopwatch2.Restart();
  4919. // MES_Flag 为4上位机报错
  4920. //Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)4); // 4代表上位机报警
  4921. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4922. writeToPLC_Flag.Name = "a1MES_FLAG";
  4923. writeToPLC_Flag.Adress = 2109;
  4924. writeToPLC_Flag.Value = (short)4;
  4925. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  4926. stopwatch2.Stop();
  4927. string str = ex.StackTrace;
  4928. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4929. }
  4930. stopwatch1.Stop();
  4931. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4932. }
  4933. //// 上传点检数据_ [S1] Tray盘上料装备(板测)
  4934. //private void DoOneCheckData_Tray盘上料装备(int plcNo, string stationCode, string stationName)
  4935. //{
  4936. // string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4937. // string stationNameStr = stationCode + stationName;
  4938. // string processItem = stationName; // 测试项目
  4939. // try
  4940. // {
  4941. // string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4942. // string accno = "1"; // 工序编号
  4943. // Funs[plcNo].Read_Real_Tag("896", 1, out float[] float0);
  4944. // float travelLimitUp = float0[0]; // 胶圈装配行程设定上限
  4945. // List<OneCheckItem> items = new List<OneCheckItem>()
  4946. // {
  4947. // new OneCheckItem()
  4948. // {
  4949. // Onecheck_name="胶圈装配行程设定上限",
  4950. // Onecheck_content="上限值",
  4951. // Onecheck_result=$"正常|胶圈装配行程设定上限{travelLimitUp} mm"
  4952. // },
  4953. // };
  4954. // OneCheckData oneCheckData = new OneCheckData()
  4955. // {
  4956. // Line_code = GlobalContext.LineCode,
  4957. // Line_name = GlobalContext.LineName,
  4958. // Equipment_code = equipmentCode,
  4959. // Equipment_name = equipmentCode,
  4960. // Workorder_code = workorder_code,
  4961. // Procedure_code = accno,
  4962. // Procedure_name = processItem,
  4963. // Oneckeck_values = items,
  4964. // Onecheck_empcode = "",
  4965. // Onecheck_empname = "",
  4966. // Onecheck_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  4967. // };
  4968. // int result1 = SaveOneCheckDataByDBAndSubmit(oneCheckData, equipmentCode, processItem);
  4969. // //int result = result1 == 1 ? 1 : (GlobalContext.IsSendCheckOneData ? 4 : 1);
  4970. // short result = result1 == 1 ? (short)1 : (short)2;
  4971. // // MES_Flag 为4MES报错
  4972. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { result });
  4973. // WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  4974. // }
  4975. // catch (Exception ex)
  4976. // {
  4977. // // MES_Flag 为2上位机报错
  4978. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  4979. // string str = ex.StackTrace;
  4980. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}点检报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4981. // }
  4982. //}
  4983. // ReadStation_S1_2 节拍接口+AGV
  4984. /// <summary>
  4985. /// [S1] Tray盘上料装备(板测)- 将SN发给ICT标机(串口)
  4986. /// </summary>
  4987. /// <param name="plcNo">PLC编号</param>
  4988. /// <param name="stationNameStr">工站全称</param>
  4989. private void S1将SN发给ICT标机(int plcNo, string stationNameStr)
  4990. {
  4991. Stopwatch stopwatch1 = new Stopwatch();
  4992. Stopwatch stopwatch2 = new Stopwatch();
  4993. try
  4994. {
  4995. stopwatch1.Start();
  4996. string a1ProductSN_ICT = (string)s1PLCData["a1ProductSN_ICT"]; // 产品SN(载具SN)
  4997. a1ProductSN_ICT = a1ProductSN_ICT.Replace("\0", "");
  4998. string a1PartNo1_ICT = (string)s1PLCData["a1PartNo1_ICT"]; // 物料码1(穴位1)
  4999. a1PartNo1_ICT = a1PartNo1_ICT.Replace("\0", "");
  5000. string a1PartNo2_ICT = (string)s1PLCData["a1PartNo2_ICT"]; // 物料码2(穴位2)
  5001. a1PartNo2_ICT = a1PartNo2_ICT.Replace("\0", "");
  5002. // ZS 将SN发给ICT标机(串口)
  5003. short a1MES_FLAG_ICT = 1;
  5004. stopwatch2.Start();
  5005. // MES_Flag
  5006. //Funs[plcNo].WriteMultipleRegisters<short>(2182, a1MES_FLAG_ICT); // 上位机发送1代表OK;2代表失败;4代表上位机报警;
  5007. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5008. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  5009. writeToPLC_Flag.Adress = 2182;
  5010. writeToPLC_Flag.Value = a1MES_FLAG_ICT;
  5011. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  5012. stopwatch2.Stop();
  5013. }
  5014. catch (Exception ex)
  5015. {
  5016. string str = ex.StackTrace;
  5017. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5018. stopwatch2.Start();
  5019. // MES_Flag
  5020. //Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  5021. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5022. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  5023. writeToPLC_Flag.Adress = 2182;
  5024. writeToPLC_Flag.Value = (short)4;
  5025. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  5026. stopwatch2.Stop();
  5027. }
  5028. stopwatch1.Stop();
  5029. AddMessage(LogType.Info, stationNameStr + "_将SN发给ICT标机;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5030. }
  5031. /// <summary>
  5032. /// [S1] Tray盘上料装备(板测)- 节拍接口
  5033. /// </summary>
  5034. /// <param name="plcNo">PLC编号</param>
  5035. /// <param name="stationNameStr">工站全称</param>
  5036. private void S1节拍接口(int plcNo, string stationNameStr,string tagMesCommName, OP10_MesData_t stPLC_MesData)
  5037. {
  5038. Stopwatch stopwatch1 = new Stopwatch();
  5039. Stopwatch stopwatch2 = new Stopwatch();
  5040. IoT_DataSet_t iot_data;
  5041. string resultStr = string.Empty;
  5042. try
  5043. {
  5044. stopwatch1.Start();
  5045. string oEEType = ((int)s1PLCData["a1OEEType"]).ToString(); // 节拍类型(plc写入)
  5046. string a1OEEPartNo = (string)s1PLCData["a1OEEPartNo"]; // 物料码
  5047. a1OEEPartNo = a1OEEPartNo.Replace("\0", "");
  5048. string a1OEEVehicleCode = (string)s1PLCData["a1OEEVehicleCode"]; // 载具SN
  5049. a1OEEVehicleCode = a1OEEVehicleCode.Replace("\0", "");
  5050. //string a1OEEPartNum = ((int)s1PLCData["a1OEEPartNum"]).ToString(); // 穴位号
  5051. //a1OEEPartNum = a1OEEPartNum.Replace("\0", "");
  5052. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  5053. if (!actionBool)
  5054. {
  5055. stopwatch2.Start();
  5056. //写入PLC
  5057. iot_data.machineState = stPLC_MesData.iotData.machineState;
  5058. iot_data.work_type = stPLC_MesData.iotData.work_type;
  5059. iot_data.testStatus = stPLC_MesData.iotData.testStatus;
  5060. iot_data.BeatAction = stPLC_MesData.iotData.BeatAction;
  5061. iot_data.beatReturn = 2;//NG
  5062. iot_data.fault_codes = stPLC_MesData.iotData.fault_codes;
  5063. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5064. stopwatch2.Stop();
  5065. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5066. return;
  5067. }
  5068. //作业开始后要有物料和载具信息
  5069. if (string.IsNullOrEmpty(a1OEEPartNo) && string.IsNullOrEmpty(a1OEEVehicleCode) && Convert.ToInt32(oEEType) > 2)
  5070. {
  5071. stopwatch2.Start();
  5072. //写入PLC
  5073. iot_data.machineState = stPLC_MesData.iotData.machineState;
  5074. iot_data.work_type = stPLC_MesData.iotData.work_type;
  5075. iot_data.testStatus = stPLC_MesData.iotData.testStatus;
  5076. iot_data.BeatAction = stPLC_MesData.iotData.BeatAction;
  5077. iot_data.beatReturn = 2;//NG
  5078. iot_data.fault_codes = stPLC_MesData.iotData.fault_codes;
  5079. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5080. stopwatch2.Stop();
  5081. AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + $"_[{a1OEEVehicleCode}][{a1OEEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5082. return;
  5083. }
  5084. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a1OEEPartNo))
  5085. {
  5086. stopwatch2.Start();
  5087. //写入PLC
  5088. iot_data.machineState = stPLC_MesData.iotData.machineState;
  5089. iot_data.work_type = stPLC_MesData.iotData.work_type;
  5090. iot_data.testStatus = stPLC_MesData.iotData.testStatus;
  5091. iot_data.BeatAction = stPLC_MesData.iotData.BeatAction;
  5092. iot_data.beatReturn = 2;//NG
  5093. iot_data.fault_codes = stPLC_MesData.iotData.fault_codes;
  5094. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5095. stopwatch2.Stop();
  5096. AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + $"_[{a1OEEVehicleCode}][{a1OEEPartNo}]上传节拍失败!物料码不可为空;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5097. return;
  5098. }
  5099. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a1OEEVehicleCode))
  5100. {
  5101. stopwatch2.Start();
  5102. //写入PLC
  5103. iot_data.machineState = stPLC_MesData.iotData.machineState;
  5104. iot_data.work_type = stPLC_MesData.iotData.work_type;
  5105. iot_data.testStatus = stPLC_MesData.iotData.testStatus;
  5106. iot_data.BeatAction = stPLC_MesData.iotData.BeatAction;
  5107. iot_data.beatReturn = 2;//NG
  5108. iot_data.fault_codes = stPLC_MesData.iotData.fault_codes;
  5109. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5110. stopwatch2.Stop();
  5111. AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + $"_[{a1OEEVehicleCode}][{a1OEEPartNo}]上传节拍失败!载具码不可为空;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5112. return;
  5113. }
  5114. short a1OEEMES_FLAG = 0;
  5115. // 上传OEE
  5116. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a1OEEPartNo, a1OEEVehicleCode);
  5117. a1OEEMES_FLAG = result.Item1;
  5118. resultStr = result.Item2;
  5119. stopwatch2.Start();
  5120. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5121. writeToPLC_Flag.Name = "a1OEEMES_FLAG";
  5122. writeToPLC_Flag.Adress = 2254;
  5123. writeToPLC_Flag.Value = a1OEEMES_FLAG;
  5124. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
  5125. stopwatch2.Stop();
  5126. }
  5127. catch (Exception ex)
  5128. {
  5129. string str = ex.StackTrace;
  5130. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5131. // MES_Flag
  5132. stopwatch2.Start();
  5133. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  5134. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5135. writeToPLC_Flag.Name = "a1OEEMES_FLAG";
  5136. writeToPLC_Flag.Adress = 2254;
  5137. writeToPLC_Flag.Value = (short)4;
  5138. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
  5139. stopwatch2.Stop();
  5140. }
  5141. stopwatch1.Stop();
  5142. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5143. }
  5144. /// <summary>
  5145. /// [S1] Tray盘上料装备(板测)- AGV上料叫agv
  5146. /// </summary>
  5147. /// <param name="plcNo">PLC编号</param>
  5148. /// <param name="stationNameStr">工站全称</param>
  5149. private void S1AGV上料叫agv(int plcNo, string stationNameStr)
  5150. {
  5151. Stopwatch stopwatch1 = new Stopwatch();
  5152. Stopwatch stopwatch2 = new Stopwatch();
  5153. try
  5154. {
  5155. stopwatch1.Start();
  5156. // ZS 呼叫AGV
  5157. short a1AGVUpCall = 2;
  5158. stopwatch2.Start();
  5159. // a1AGVUpCall
  5160. //Funs[plcNo].WriteMultipleRegisters<short>(2307, a1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5161. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5162. writeToPLC_Flag.Name = "a1AGVUpCall";
  5163. writeToPLC_Flag.Adress = 2307;
  5164. writeToPLC_Flag.Value = a1AGVUpCall;
  5165. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  5166. stopwatch2.Stop();
  5167. }
  5168. catch (Exception ex)
  5169. {
  5170. string str = ex.StackTrace;
  5171. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5172. // a1AGVUpCall
  5173. stopwatch2.Start();
  5174. //Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  5175. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5176. writeToPLC_Flag.Name = "a1AGVUpCall";
  5177. writeToPLC_Flag.Adress = 2307;
  5178. writeToPLC_Flag.Value = (short)4;
  5179. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  5180. stopwatch2.Stop();
  5181. }
  5182. stopwatch1.Stop();
  5183. AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5184. }
  5185. /// <summary>
  5186. /// [S1] Tray盘上料装备(板测)- AGV上料完成
  5187. /// </summary>
  5188. /// <param name="plcNo">PLC编号</param>
  5189. /// <param name="stationNameStr">工站全称</param>
  5190. private void S1AGV上料完成(int plcNo, string stationNameStr)
  5191. {
  5192. Stopwatch stopwatch1 = new Stopwatch();
  5193. Stopwatch stopwatch2 = new Stopwatch();
  5194. try
  5195. {
  5196. stopwatch1.Start();
  5197. // ZS AGV上料完成,让小车离开
  5198. short a1AGVUpEnd = 2;
  5199. stopwatch2.Start();
  5200. // a1AGVUpEnd
  5201. //Funs[plcNo].WriteMultipleRegisters<short>(2309, a1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5202. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5203. writeToPLC_Flag.Name = "a1AGVUpEnd";
  5204. writeToPLC_Flag.Adress = 2309;
  5205. writeToPLC_Flag.Value = a1AGVUpEnd;
  5206. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  5207. stopwatch2.Stop();
  5208. }
  5209. catch (Exception ex)
  5210. {
  5211. string str = ex.StackTrace;
  5212. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5213. // a1AGVUpEnd
  5214. stopwatch2.Start();
  5215. //Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  5216. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5217. writeToPLC_Flag.Name = "a1AGVUpEnd";
  5218. writeToPLC_Flag.Adress = 2309;
  5219. writeToPLC_Flag.Value = (short)4;
  5220. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  5221. stopwatch2.Stop();
  5222. }
  5223. stopwatch1.Stop();
  5224. AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5225. }
  5226. /// <summary>
  5227. /// [S1] Tray盘上料装备(板测)- AGV下料叫agv
  5228. /// </summary>
  5229. /// <param name="plcNo">PLC编号</param>
  5230. /// <param name="stationNameStr">工站全称</param>
  5231. private void S1AGV下料叫agv(int plcNo, string stationNameStr)
  5232. {
  5233. Stopwatch stopwatch1 = new Stopwatch();
  5234. Stopwatch stopwatch2 = new Stopwatch();
  5235. try
  5236. {
  5237. stopwatch1.Start();
  5238. // ZS 呼叫AGV
  5239. short a1AGVDownCall = 2;
  5240. stopwatch2.Start();
  5241. // a1AGVDownCall
  5242. //Funs[plcNo].WriteMultipleRegisters<short>(2320, a1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5243. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5244. writeToPLC_Flag.Name = "a1AGVDownCall";
  5245. writeToPLC_Flag.Adress = 2320;
  5246. writeToPLC_Flag.Value = a1AGVDownCall;
  5247. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  5248. stopwatch2.Stop();
  5249. }
  5250. catch (Exception ex)
  5251. {
  5252. string str = ex.StackTrace;
  5253. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5254. // a1AGVDownCall
  5255. stopwatch2.Start();
  5256. //Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  5257. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5258. writeToPLC_Flag.Name = "a1AGVDownCall";
  5259. writeToPLC_Flag.Adress = 2320;
  5260. writeToPLC_Flag.Value = (short)4;
  5261. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  5262. stopwatch2.Stop();
  5263. }
  5264. stopwatch1.Stop();
  5265. AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5266. }
  5267. /// <summary>
  5268. /// [S1] Tray盘上料装备(板测)- AGV下料完成
  5269. /// </summary>
  5270. /// <param name="plcNo">PLC编号</param>
  5271. /// <param name="stationNameStr">工站全称</param>
  5272. private void S1AGV下料完成(int plcNo, string stationNameStr)
  5273. {
  5274. Stopwatch stopwatch1 = new Stopwatch();
  5275. Stopwatch stopwatch2 = new Stopwatch();
  5276. try
  5277. {
  5278. stopwatch1.Start();
  5279. // ZS AGV上料完成,让小车离开
  5280. short a1AGVDownEnd = 2;
  5281. stopwatch2.Start();
  5282. // a1AGVDownEnd
  5283. //Funs[plcNo].WriteMultipleRegisters<short>(2322, a1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5284. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5285. writeToPLC_Flag.Name = "a1AGVDownEnd";
  5286. writeToPLC_Flag.Adress = 2322;
  5287. writeToPLC_Flag.Value = a1AGVDownEnd;
  5288. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  5289. stopwatch2.Stop();
  5290. }
  5291. catch (Exception ex)
  5292. {
  5293. string str = ex.StackTrace;
  5294. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5295. // a1AGVDownEnd
  5296. stopwatch2.Start();
  5297. //Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  5298. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5299. writeToPLC_Flag.Name = "a1AGVDownEnd";
  5300. writeToPLC_Flag.Adress = 2322;
  5301. writeToPLC_Flag.Value = (short)4;
  5302. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  5303. stopwatch2.Stop();
  5304. }
  5305. stopwatch1.Stop();
  5306. AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5307. }
  5308. #endregion [S1] Tray盘上料装备(板测)
  5309. #endregion PLC1 张超凡
  5310. #region PLC2 李晓奇
  5311. #region [S2] FCT(板测)
  5312. /// <summary>
  5313. /// S2工位的数据- 触发信号上次的值
  5314. /// </summary>
  5315. private Dictionary<string, object> s2PLCSignal_Old = new Dictionary<string, object>();
  5316. /// <summary>
  5317. /// S2工位的数据(含触发信号)
  5318. /// </summary>
  5319. private Dictionary<string, object> s2PLCData = new Dictionary<string, object>();
  5320. /// <summary>
  5321. /// S2工位的数据- 回写点位
  5322. /// </summary>
  5323. private Dictionary<string, WriteToPLC_Flag> s2PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  5324. /// <summary>
  5325. /// [S2] FCT(板测)
  5326. /// </summary>
  5327. /// <param name="plcNo">PLC编号</param>
  5328. //private void ReadStation_S2(int plcNo)
  5329. //{
  5330. // // [S1] Tray盘上料装备
  5331. // // [S2] FCT
  5332. // // [S3] 值板机
  5333. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  5334. // // [S5] Tray盘下料装备
  5335. // /// 上位机心跳
  5336. // /// 获取设备报警数据与状态信息
  5337. // string stationCode = "[S2]";
  5338. // string stationName = "FCT";
  5339. // string stationNameStr = stationCode + stationName;
  5340. // #region 创建字典
  5341. // // 触发信号字典 赋值
  5342. // s2PLCSignal_Old.Add("b1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5343. // s2PLCSignal_Old.Add("b1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑/绑定(产品换载具)
  5344. // s2PLCSignal_Old.Add("b1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5345. // s2PLCSignal_Old.Add("b1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5346. // // PLC数据字典 赋值
  5347. // s2PLCData.Add("b1PLC_FLAG_Check", 0); // 进站校验
  5348. // s2PLCData.Add("b1MES_FLAG_Check", 0);
  5349. // s2PLCData.Add("b1ProductSN_Check", 0);
  5350. // s2PLCData.Add("b1PLC_FLAG_Unbind", 0); // 二穴载具解绑/绑定(产品换载具)
  5351. // s2PLCData.Add("b1MES_FLAG_Unbind", 0);
  5352. // s2PLCData.Add("b1ProductSN_Unbind", "");
  5353. // s2PLCData.Add("b1ProductSN_Bind", "");
  5354. // s2PLCData.Add("b1Part1SN_Bind", "");
  5355. // s2PLCData.Add("b1Part2SN_Bind", "");
  5356. // s2PLCData.Add("b1PLC_FLAG", 0); // 出站接口
  5357. // s2PLCData.Add("b1MES_FLAG", 0);
  5358. // s2PLCData.Add("b1ProductSN", 0);
  5359. // s2PLCData.Add("b1Part1Result", 0);
  5360. // s2PLCData.Add("b1Part2Result", 0);
  5361. // s2PLCData.Add("b1OEEPLC_FLAG", 0); // 节拍接口
  5362. // s2PLCData.Add("b1OEEMES_FLAG", 0);
  5363. // s2PLCData.Add("b1OEEProductSN", "");
  5364. // s2PLCData.Add("b1OEEType", 0);
  5365. // #endregion 创建字典
  5366. // while (IsRun)
  5367. // {
  5368. // try
  5369. // {
  5370. // if (!GlobalContext._IsCon_Funs2)
  5371. // {
  5372. // UpdatePLCMonitor(1, plcNo, 0);
  5373. // continue;
  5374. // }
  5375. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  5376. // {
  5377. // Stopwatch stopwatch1 = new Stopwatch();
  5378. // Stopwatch stopwatch2 = new Stopwatch();
  5379. // stopwatch1.Start();
  5380. // stopwatch2.Start();
  5381. // #region 一次性读取所有数据
  5382. // // 一次性读取所有数据
  5383. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100); //
  5384. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100); //
  5385. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 35); //
  5386. // int[] datas = data1.Concat(data2).ToArray();
  5387. // datas = datas.Concat(data3).ToArray();
  5388. // s2PLCData["b1PLC_FLAG_Check"] = datas[2]; // 进站校验
  5389. // s2PLCData["b1MES_FLAG_Check"] = datas[3];
  5390. // int[] b1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  5391. // s2PLCData["b1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(b1ProductSN_CheckData, 0, 40);
  5392. // s2PLCData["b1PLC_FLAG_Unbind"] = datas[76]; // 二穴载具解绑/绑定(产品换载具)
  5393. // s2PLCData["b1MES_FLAG_Unbind"] = datas[77];
  5394. // int[] b1ProductSN_UnbindData = datas.Skip(78).Take(20).ToArray();
  5395. // s2PLCData["b1ProductSN_Unbind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_UnbindData, 0, 40);
  5396. // int[] b1ProductSN_BindData = datas.Skip(98).Take(20).ToArray();
  5397. // s2PLCData["b1ProductSN_Bind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_BindData, 0, 40);
  5398. // int[] b1Part1SN_BindData = datas.Skip(118).Take(20).ToArray();
  5399. // s2PLCData["b1Part1SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part1SN_BindData, 0, 40);
  5400. // int[] b1Part2SN_BindData = datas.Skip(138).Take(20).ToArray();
  5401. // s2PLCData["b1Part2SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part2SN_BindData, 0, 40);
  5402. // s2PLCData["b1PLC_FLAG"] = datas[168]; // 出站接口
  5403. // s2PLCData["b1MES_FLAG"] = datas[169];
  5404. // int[] b1ProductSNData = datas.Skip(170).Take(20).ToArray();
  5405. // s2PLCData["b1ProductSN"] = ModbusClient.ConvertRegistersToString(b1ProductSNData, 0, 40);
  5406. // s2PLCData["b1Part1Result"] = datas[190];
  5407. // s2PLCData["b1Part2Result"] = datas[191];
  5408. // s2PLCData["b1OEEPLC_FLAG"] = datas[202]; // 节拍接口
  5409. // s2PLCData["b1OEEMES_FLAG"] = datas[203];
  5410. // int[] b1OEEProductSNData = datas.Skip(204).Take(20).ToArray();
  5411. // s2PLCData["b1OEEProductSN"] = ModbusClient.ConvertRegistersToString(b1OEEProductSNData, 0, 40);
  5412. // s2PLCData["b1OEEType"] = datas[224];
  5413. // #endregion 一次性读取所有数据
  5414. // stopwatch2.Stop();
  5415. // #region 回写操作,写后清空flag
  5416. // PLCWriteData(Funs[plcNo], ref s2PLCData, ref s2PLCWriteData);
  5417. // #endregion 回写操作,写后清空flag
  5418. // #region 进站校验
  5419. // try
  5420. // {
  5421. // int b1PLC_FLAG_Check = (int)s2PLCData["b1PLC_FLAG_Check"];
  5422. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  5423. // int b1PLC_FLAG_CheckOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Check"];
  5424. // if (b1PLC_FLAG_Check != b1PLC_FLAG_CheckOld)
  5425. // {
  5426. // if (b1PLC_FLAG_Check == 1 && b1MES_FLAG_Check == 0) // 0->1
  5427. // Task.Run(() => S2进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  5428. // else if (b1PLC_FLAG_Check == 0 && b1MES_FLAG_Check != 0)
  5429. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  5430. // s2PLCSignal_Old["b1PLC_FLAG_Check"] = s2PLCData["b1PLC_FLAG_Check"];
  5431. // }
  5432. // }
  5433. // catch (Exception ex)
  5434. // {
  5435. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5436. // string str = ex.StackTrace;
  5437. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5438. // }
  5439. // #endregion 进站校验
  5440. // #region 二穴载具解绑/绑定(产品换载具)
  5441. // try
  5442. // {
  5443. // int b1PLC_FLAG_Unbind = (int)s2PLCData["b1PLC_FLAG_Unbind"];
  5444. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  5445. // int b1PLC_FLAG_UnbindOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Unbind"];
  5446. // if (b1PLC_FLAG_Unbind != b1PLC_FLAG_UnbindOld)
  5447. // {
  5448. // if (b1PLC_FLAG_Unbind == 1 && b1MES_FLAG_Check == 0) // 0->1
  5449. // Task.Run(() => S2二穴载具解绑绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  5450. // else if (b1PLC_FLAG_Unbind == 0 && b1MES_FLAG_Check != 0)
  5451. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  5452. // s2PLCSignal_Old["b1PLC_FLAG_Unbind"] = s2PLCData["b1PLC_FLAG_Unbind"];
  5453. // }
  5454. // }
  5455. // catch (Exception ex)
  5456. // {
  5457. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  5458. // string str = ex.StackTrace;
  5459. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5460. // }
  5461. // #endregion 二穴载具解绑/绑定(产品换载具)
  5462. // #region FCT-出站接口
  5463. // try
  5464. // {
  5465. // int b1PLC_FLAG = (int)s2PLCData["b1PLC_FLAG"];
  5466. // int b1MES_FLAG = (int)s2PLCData["b1MES_FLAG"];
  5467. // int b1PLC_FLAGOld = (int)s2PLCSignal_Old["b1PLC_FLAG"];
  5468. // if (b1PLC_FLAG != b1PLC_FLAGOld)
  5469. // {
  5470. // if (b1PLC_FLAG == 1 && b1MES_FLAG == 0) // 0->1
  5471. // Task.Run(() => S2出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  5472. // else if (b1PLC_FLAG == 0 && b1MES_FLAG != 0)
  5473. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)0);
  5474. // }
  5475. // }
  5476. // catch (Exception ex)
  5477. // {
  5478. // // MES_Flag 为6上位机报错
  5479. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)6); // 6代表上位机报警
  5480. // string str = ex.StackTrace;
  5481. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}上传出站数据出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5482. // }
  5483. // #endregion FCT-出站接口
  5484. // #region 节拍接口
  5485. // try
  5486. // {
  5487. // int b1OEEPLC_FLAG = (int)s2PLCData["b1OEEPLC_FLAG"];
  5488. // int b1OEEMES_FLAG = (int)s2PLCData["b1OEEMES_FLAG"];
  5489. // int b1OEEPLC_FLAGOld = (int)s2PLCSignal_Old["b1OEEPLC_FLAG"];
  5490. // if (b1OEEPLC_FLAG != b1OEEPLC_FLAGOld)
  5491. // {
  5492. // if (b1OEEPLC_FLAG == 1 && b1OEEMES_FLAG == 0) // 0->1
  5493. // Task.Run(() => S2节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  5494. // else if (b1OEEPLC_FLAG == 0 && b1OEEMES_FLAG != 0)
  5495. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)0);
  5496. // s2PLCSignal_Old["b1OEEPLC_FLAG"] = s2PLCData["b1OEEPLC_FLAG"];
  5497. // }
  5498. // }
  5499. // catch (Exception ex)
  5500. // {
  5501. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  5502. // string str = ex.StackTrace;
  5503. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5504. // }
  5505. // #endregion 节拍接口
  5506. // #region 心跳
  5507. // try
  5508. // {
  5509. // short states = 0;
  5510. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  5511. // }
  5512. // catch (Exception ex)
  5513. // {
  5514. // string str = ex.StackTrace;
  5515. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5516. // }
  5517. // #endregion 心跳
  5518. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5519. // stopwatch1.Stop();
  5520. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  5521. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5522. // }
  5523. // else
  5524. // {
  5525. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5526. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5527. // Funs[plcNo].Connect();
  5528. // }
  5529. // }
  5530. // catch (Exception ex)
  5531. // {
  5532. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5533. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5534. // Funs[plcNo].ReConnect();
  5535. // }
  5536. // Thread.Sleep(IntervalReadPLC);
  5537. // }
  5538. //}
  5539. /// <summary>
  5540. /// [S2] FCT(板测)- 进站校验
  5541. /// </summary>
  5542. /// <param name="plcNo">PLC编号</param>
  5543. /// <param name="stationNameStr">工站全称</param>
  5544. private void S2进站校验(int plcNo, string stationNameStr)
  5545. {
  5546. Stopwatch stopwatch1 = new Stopwatch();
  5547. Stopwatch stopwatch2 = new Stopwatch();
  5548. try
  5549. {
  5550. stopwatch1.Start();
  5551. string sn = (string)s2PLCData["b1ProductSN_Check"]; // 产品SN(载具码)
  5552. sn = sn.Replace("\0", "");
  5553. #region 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  5554. // 查询物料码By载具码 并判断是不是假产品
  5555. string cavityData = string.Empty;
  5556. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  5557. if (string.IsNullOrEmpty(cavityData))
  5558. cavityData = "";
  5559. if (snResult != 0)
  5560. {
  5561. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5562. writeToPLC_Flag1.Name = "b1MES_FLAG_Check";
  5563. writeToPLC_Flag1.Adress = 2003;
  5564. writeToPLC_Flag1.Value = (short)6;
  5565. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag1);
  5566. stopwatch1.Stop();
  5567. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5568. return;
  5569. }
  5570. #endregion 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  5571. string[] cavitySNs = cavityData.Split('.');
  5572. string b1Part1SN_Check = ""; // 穴位1物料SN(上位机写入)
  5573. string b1Part2SN_Check = ""; // 穴位2物料SN(上位机写入)
  5574. short b1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  5575. short b1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  5576. if (cavitySNs != null && cavitySNs.Length >= 2)
  5577. {
  5578. b1Part1SN_Check = cavitySNs[0];
  5579. b1Part2SN_Check = cavitySNs[1];
  5580. b1Part1Result_Check = 2;
  5581. b1Part2Result_Check = 2;
  5582. }
  5583. if (b1Part1SN_Check == "假产品")
  5584. b1Part1Result_Check = 3;
  5585. if (b1Part2SN_Check == "假产品")
  5586. b1Part2Result_Check = 3;
  5587. // 调用MES进站
  5588. stopwatch2.Start();
  5589. // 调用MES进站 - 产品1
  5590. List<TestItem> item;
  5591. int result1 = b1Part1Result_Check;
  5592. if (result1 != 3)
  5593. {
  5594. item = new List<TestItem>();
  5595. item.Add(new TestItem()
  5596. {
  5597. Parameter_name = "载具码",
  5598. Parameter_value = sn,
  5599. });
  5600. item.Add(new TestItem()
  5601. {
  5602. Parameter_name = "载具穴号",
  5603. Parameter_value = "1",
  5604. });
  5605. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, b1Part1SN_Check, item, out string errorMsg);
  5606. }
  5607. // 调用MES进站 - 产品2
  5608. int result2 = b1Part2Result_Check;
  5609. if (result2 != 3)
  5610. {
  5611. item = new List<TestItem>();
  5612. item.Add(new TestItem()
  5613. {
  5614. Parameter_name = "载具码",
  5615. Parameter_value = sn,
  5616. });
  5617. item.Add(new TestItem()
  5618. {
  5619. Parameter_name = "载具穴号",
  5620. Parameter_value = "2",
  5621. });
  5622. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, b1Part2SN_Check, item, out string errorMsg);
  5623. }
  5624. stopwatch2.Stop();
  5625. b1Part1Result_Check = result1 == 1 ? (short)1 : (short)2; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  5626. b1Part2Result_Check = result2 == 1 ? (short)1 : (short)2; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  5627. int result = result1;
  5628. if (result == 1)
  5629. result = result2;
  5630. short b1MES_FLAG_Check = (short)result;
  5631. //Funs[plcNo].WriteMultipleRegisters<string>(2024, b1Part1SN_Check, 20);
  5632. //Funs[plcNo].WriteMultipleRegisters<string>(2044, b1Part2SN_Check, 20);
  5633. //Funs[plcNo].WriteMultipleRegisters<short>(2064, b1Part1Result_Check);
  5634. //Funs[plcNo].WriteMultipleRegisters<short>(2065, b1Part2Result_Check);
  5635. //// MES_Flag
  5636. //Funs[plcNo].WriteMultipleRegisters<short>(2003, b1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5637. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5638. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  5639. writeToPLC_Flag.Adress = 2003;
  5640. writeToPLC_Flag.Value = b1MES_FLAG_Check;
  5641. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5642. {
  5643. Name = "b1Part1SN_Check",
  5644. Adress = 2024,
  5645. ValueType = PLCValueType.String,
  5646. ValueTypeStrLength = 20,
  5647. Value = b1Part1SN_Check
  5648. });
  5649. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5650. {
  5651. Name = "b1Part2SN_Check",
  5652. Adress = 2044,
  5653. ValueType = PLCValueType.String,
  5654. ValueTypeStrLength = 20,
  5655. Value = b1Part2SN_Check
  5656. });
  5657. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5658. {
  5659. Name = "b1Part1Result_Check",
  5660. Adress = 2064,
  5661. ValueType = PLCValueType.Short,
  5662. Value = b1Part1Result_Check
  5663. });
  5664. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5665. {
  5666. Name = "b1Part2Result_Check",
  5667. Adress = 2065,
  5668. ValueType = PLCValueType.Short,
  5669. Value = b1Part2Result_Check
  5670. });
  5671. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  5672. }
  5673. catch (Exception ex)
  5674. {
  5675. string str = ex.StackTrace;
  5676. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5677. // MES_Flag
  5678. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5679. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5680. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  5681. writeToPLC_Flag.Adress = 2003;
  5682. writeToPLC_Flag.Value = (short)6;
  5683. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  5684. }
  5685. stopwatch1.Stop();
  5686. AddMessage(LogType.Info, stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5687. }
  5688. /// <summary>
  5689. /// [S2] FCT(板测)- 二穴载具解绑绑定
  5690. /// </summary>
  5691. /// <param name="plcNo">PLC编号</param>
  5692. /// <param name="stationNameStr">工站全称</param>
  5693. private void S2二穴载具解绑绑定(int plcNo, string stationNameStr)
  5694. {
  5695. Stopwatch stopwatch1 = new Stopwatch();
  5696. Stopwatch stopwatch2 = new Stopwatch();
  5697. try
  5698. {
  5699. stopwatch1.Start();
  5700. // 产品换载具
  5701. string b1ProductSN_Unbind = (string)s2PLCData["b1ProductSN_Unbind"]; // 原二穴载具SN(需要解绑的)
  5702. b1ProductSN_Unbind = b1ProductSN_Unbind.Replace("\0", "");
  5703. string b1ProductSN_Bind = (string)s2PLCData["b1ProductSN_Bind"]; // 新二穴载具SN(需要绑定的)
  5704. b1ProductSN_Bind = b1ProductSN_Bind.Replace("\0", "");
  5705. string b1Part1SN_Bind = (string)s2PLCData["b1Part1SN_Bind"]; // 穴位1物料SN(plc写入)
  5706. b1Part1SN_Bind = b1Part1SN_Bind.Replace("\0", "");
  5707. string b1Part2SN_Bind = (string)s2PLCData["b1Part2SN_Bind"]; // 穴位2物料SN(plc写入)
  5708. b1Part2SN_Bind = b1Part2SN_Bind.Replace("\0", "");
  5709. stopwatch2.Start();
  5710. #region 查询载具上的产品信息
  5711. //string cavityData = string.Empty;
  5712. //int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN_Unbind, ref cavityData);
  5713. //if (string.IsNullOrEmpty(cavityData))
  5714. // cavityData = "";
  5715. //if (snResult != 0)
  5716. //{
  5717. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5718. // writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5719. // writeToPLC_Flag.Adress = 2077;
  5720. // writeToPLC_Flag.Value = (short)6;
  5721. // SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5722. // stopwatch1.Stop();
  5723. // AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑绑定失败!MES边线软件_二穴载具查询返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5724. // return;
  5725. //}
  5726. #endregion 查询载具上的产品信息
  5727. #region 解绑(边线MES系统)
  5728. int snResult = XiaomiMES_RouteCommunication.SNDeleteData(b1ProductSN_Unbind);
  5729. if (snResult != 0)
  5730. {
  5731. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5732. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  5733. writeToPLC_Flag1.Adress = 2077;
  5734. writeToPLC_Flag1.Value = (short)6;
  5735. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  5736. stopwatch1.Stop();
  5737. AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑失败!MES边线软件_二穴载具[{b1ProductSN_Unbind}]解绑返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5738. return;
  5739. }
  5740. #endregion 解绑(边线MES系统)
  5741. #region 存储绑定数据到 边线MES系统中
  5742. string data = string.Concat(b1Part1SN_Bind, ".", b1Part2SN_Bind);
  5743. snResult = XiaomiMES_RouteCommunication.SNBindData(b1ProductSN_Bind, data);
  5744. if (snResult != 0)
  5745. {
  5746. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5747. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  5748. writeToPLC_Flag1.Adress = 2077;
  5749. writeToPLC_Flag1.Value = (short)6;
  5750. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  5751. stopwatch1.Stop();
  5752. AddMessage(LogType.Info, stationNameStr + $"_二穴载具绑定失败!MES边线软件_二穴载具[{b1ProductSN_Bind}]绑定[{data}]返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5753. return;
  5754. }
  5755. #endregion 存储绑定数据到 边线MES系统中
  5756. stopwatch2.Stop();
  5757. short b1MES_FLAG_Unbind = 1;
  5758. // MES_Flag
  5759. //Funs[plcNo].WriteMultipleRegisters<short>(2077, b1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5760. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5761. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5762. writeToPLC_Flag.Adress = 2077;
  5763. writeToPLC_Flag.Value = b1MES_FLAG_Unbind;
  5764. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5765. }
  5766. catch (Exception ex)
  5767. {
  5768. string str = ex.StackTrace;
  5769. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5770. // MES_Flag
  5771. stopwatch2.Start();
  5772. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  5773. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5774. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5775. writeToPLC_Flag.Adress = 2077;
  5776. writeToPLC_Flag.Value = (short)6;
  5777. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5778. stopwatch2.Stop();
  5779. }
  5780. stopwatch1.Stop();
  5781. AddMessage(LogType.Info, stationNameStr + "_二穴载具解绑绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5782. }
  5783. //// 上次采集到的SN
  5784. //private string sn_FCT = string.Empty;
  5785. /// <summary>
  5786. /// [S2] FCT(板测)- 出站数据
  5787. /// </summary>
  5788. private void S2出站接口(int plcNo, string stationCode, string stationName)
  5789. {
  5790. Stopwatch stopwatch1 = new Stopwatch();
  5791. Stopwatch stopwatch2 = new Stopwatch();
  5792. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5793. string stationNameStr = stationCode + stationName;
  5794. string processItem = stationName; // 测试项目
  5795. try
  5796. {
  5797. stopwatch1.Start();
  5798. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5799. //string batch_num = GlobalContext.BatchNumber; // 批次号
  5800. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5801. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5802. string b1ProductSN = (string)s2PLCData["b1ProductSN"]; // 产品SN(载具SN)
  5803. int b1Part1Result = (int)s2PLCData["b1Part1Result"]; // 产品1结果
  5804. int b1Part2Result = (int)s2PLCData["b1Part2Result"]; // 产品2结果
  5805. bool pass1 = b1Part1Result == 1;
  5806. bool pass2 = b1Part2Result == 1;
  5807. #region 根据 载具SN 查 物料SN
  5808. string cavityData = string.Empty;
  5809. int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN, ref cavityData);
  5810. if (string.IsNullOrEmpty(cavityData))
  5811. cavityData = "";
  5812. if (snResult != 0)
  5813. {
  5814. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5815. writeToPLC_Flag1.Name = "b1MES_FLAG";
  5816. writeToPLC_Flag1.Adress = 2169;
  5817. writeToPLC_Flag1.Value = (short)4;
  5818. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag1);
  5819. stopwatch1.Stop();
  5820. AddMessage(LogType.Info, stationNameStr + $"_上传出站数据失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5821. return;
  5822. }
  5823. #endregion 根据 载具SN 查 物料SN
  5824. string[] cavitySNs = cavityData.Split('.');
  5825. string b1ProductSN1 = string.Empty;
  5826. string b1ProductSN2 = string.Empty;
  5827. if (cavitySNs != null && cavitySNs.Length >= 2)
  5828. {
  5829. b1ProductSN1 = cavitySNs[0];
  5830. b1ProductSN2 = cavitySNs[1];
  5831. }
  5832. stopwatch2.Start();
  5833. // 产品1
  5834. int result1 = 0;
  5835. if (b1ProductSN1 == "假产品")
  5836. result1 = 1;
  5837. else
  5838. {
  5839. List<TestItem> items1 = new List<TestItem>();
  5840. items1.Add(new TestItem()
  5841. {
  5842. Parameter_name = "载具码",
  5843. Parameter_value = b1ProductSN.ToString(),
  5844. Parameter_unit = ""
  5845. });
  5846. items1.Add(new TestItem()
  5847. {
  5848. Parameter_name = "载具穴号",
  5849. Parameter_value = "1",
  5850. Parameter_unit = ""
  5851. });
  5852. items1.Add(new TestItem()
  5853. {
  5854. Parameter_name = "产品结果",
  5855. Parameter_value = b1Part1Result == 1 ? "OK" : "NG",
  5856. Parameter_unit = ""
  5857. });
  5858. result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  5859. , workorder_code, mtltmrk, b1ProductSN1, pass1, b1ProductSN, "1");
  5860. }
  5861. // 产品2
  5862. int result2 = 0;
  5863. if (b1ProductSN1 == "假产品")
  5864. result2 = 1;
  5865. else
  5866. {
  5867. List<TestItem> items2 = new List<TestItem>();
  5868. items2.Add(new TestItem()
  5869. {
  5870. Parameter_name = "载具码",
  5871. Parameter_value = b1ProductSN.ToString(),
  5872. Parameter_unit = ""
  5873. });
  5874. items2.Add(new TestItem()
  5875. {
  5876. Parameter_name = "载具穴号",
  5877. Parameter_value = "2",
  5878. Parameter_unit = ""
  5879. });
  5880. items2.Add(new TestItem()
  5881. {
  5882. Parameter_name = "产品结果",
  5883. Parameter_value = b1Part2Result == 1 ? "OK" : "NG",
  5884. Parameter_unit = ""
  5885. });
  5886. result2 = SwitctProcessData(stationNameStr, items2, equipmentCode, processItem
  5887. , workorder_code, mtltmrk, b1ProductSN2, pass2, b1ProductSN, "2");
  5888. }
  5889. short result = 0;
  5890. List<int> results = new List<int>() { result1, result2 };
  5891. if (result1 == 1 && result2 == 1)
  5892. result = 1;
  5893. else if (results.Contains(3))
  5894. result = 3;
  5895. else if (results.Contains(2))
  5896. result = 2;
  5897. else if (results.Contains(4))
  5898. result = 4;
  5899. else
  5900. result = 4;
  5901. stopwatch2.Stop();
  5902. //Funs[plcNo].WriteMultipleRegisters<short>(2169, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5903. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5904. writeToPLC_Flag.Name = "b1MES_FLAG";
  5905. writeToPLC_Flag.Adress = 2169;
  5906. writeToPLC_Flag.Value = result;
  5907. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  5908. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  5909. }
  5910. catch (Exception ex)
  5911. {
  5912. stopwatch2.Restart();
  5913. // MES_Flag 为4上位机报错
  5914. //Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)4); // 4代表上位机报警
  5915. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5916. writeToPLC_Flag.Name = "b1MES_FLAG";
  5917. writeToPLC_Flag.Adress = 2169;
  5918. writeToPLC_Flag.Value = (short)4;
  5919. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  5920. stopwatch2.Stop();
  5921. string str = ex.StackTrace;
  5922. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}出站数据报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5923. }
  5924. stopwatch1.Stop();
  5925. AddMessage(LogType.Info, stationNameStr + "_出站数据;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5926. }
  5927. /// <summary>
  5928. /// [S2] FCT(板测)- 节拍接口
  5929. /// </summary>
  5930. /// <param name="plcNo">PLC编号</param>
  5931. /// <param name="stationNameStr">工站全称</param>
  5932. private void S2节拍接口(int plcNo, string stationNameStr)
  5933. {
  5934. Stopwatch stopwatch1 = new Stopwatch();
  5935. Stopwatch stopwatch2 = new Stopwatch();
  5936. string resultStr = string.Empty;
  5937. try
  5938. {
  5939. stopwatch1.Start();
  5940. string oEEType = ((int)s2PLCData["b1OEEType"]).ToString(); // 节拍类型(plc写入)
  5941. string b1OEEProductSN = (string)s2PLCData["b1OEEProductSN"]; // 载具SN
  5942. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  5943. if (!actionBool)
  5944. {
  5945. stopwatch2.Start();
  5946. // MES_Flag
  5947. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5948. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5949. writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
  5950. writeToPLC_Flag1.Adress = 2203;
  5951. writeToPLC_Flag1.Value = (short)4;
  5952. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
  5953. stopwatch2.Stop();
  5954. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5955. return;
  5956. }
  5957. string b1OEEPartNo = string.Empty; // 物料码
  5958. if (string.IsNullOrEmpty(b1OEEProductSN))
  5959. {
  5960. stopwatch2.Start();
  5961. // MES_Flag
  5962. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5963. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5964. writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
  5965. writeToPLC_Flag1.Adress = 2203;
  5966. writeToPLC_Flag1.Value = (short)1;
  5967. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
  5968. stopwatch2.Stop();
  5969. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5970. return;
  5971. }
  5972. else
  5973. { // 查产品SN
  5974. b1OEEPartNo = "Test"; // ZS
  5975. }
  5976. short b1OEEMES_FLAG = 0;
  5977. // 上传OEE
  5978. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, b1OEEPartNo, b1OEEProductSN);
  5979. b1OEEMES_FLAG = result.Item1;
  5980. resultStr = result.Item2;
  5981. stopwatch2.Start();
  5982. // MES_Flag
  5983. //Funs[plcNo].WriteMultipleRegisters<short>(2203, b1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5984. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5985. writeToPLC_Flag.Name = "b1OEEMES_FLAG";
  5986. writeToPLC_Flag.Adress = 2203;
  5987. writeToPLC_Flag.Value = b1OEEMES_FLAG;
  5988. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
  5989. stopwatch2.Stop();
  5990. }
  5991. catch (Exception ex)
  5992. {
  5993. string str = ex.StackTrace;
  5994. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5995. // MES_Flag
  5996. stopwatch2.Start();
  5997. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  5998. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5999. writeToPLC_Flag.Name = "b1OEEMES_FLAG";
  6000. writeToPLC_Flag.Adress = 2203;
  6001. writeToPLC_Flag.Value = (short)4;
  6002. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
  6003. stopwatch2.Stop();
  6004. }
  6005. stopwatch1.Stop();
  6006. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6007. }
  6008. #endregion [S2] FCT(板测)
  6009. #endregion PLC2 李晓奇
  6010. #region PLC3 刘永村
  6011. #region [S3] 值板机
  6012. /// <summary>
  6013. /// S3工位的数据- 触发信号上次的值
  6014. /// </summary>
  6015. private Dictionary<string, object> s3PLCSignal_Old = new Dictionary<string, object>();
  6016. /// <summary>
  6017. /// S3工位的数据(含触发信号)
  6018. /// </summary>
  6019. private Dictionary<string, object> s3PLCData = new Dictionary<string, object>();
  6020. /// <summary>
  6021. /// S3工位的数据- 回写点位
  6022. /// </summary>
  6023. private Dictionary<string, WriteToPLC_Flag> s3PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  6024. /// <summary>
  6025. /// [S3] 值板机
  6026. /// </summary>
  6027. /// <param name="plcNo">PLC编号</param>
  6028. //private void ReadStation_S3(int plcNo)
  6029. //{
  6030. // // [S1] Tray盘上料装备
  6031. // // [S2] FCT
  6032. // // [S3] 值板机
  6033. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  6034. // // [S5] Tray盘下料装备
  6035. // /// 上位机心跳
  6036. // /// 获取设备报警数据与状态信息
  6037. // string stationCode = "[S3]";
  6038. // string stationName = "值板机";
  6039. // string stationNameStr = stationCode + stationName;
  6040. // #region 创建字典
  6041. // // 触发信号字典 赋值
  6042. // s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  6043. // s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  6044. // s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  6045. // s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6046. // s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6047. // // PLC数据字典 赋值
  6048. // s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  6049. // s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  6050. // s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  6051. // s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  6052. // s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  6053. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  6054. // s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6055. // s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  6056. // s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  6057. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  6058. // s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  6059. // s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  6060. // s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  6061. // s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6062. // s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  6063. // s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  6064. // //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  6065. // s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6066. // s3PLCData.Add("c1Result", 0); // 产品结果
  6067. // s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6068. // s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  6069. // s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  6070. // s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  6071. // #endregion 创建字典
  6072. // while (IsRun)
  6073. // {
  6074. // try
  6075. // {
  6076. // if (!GlobalContext._IsCon_Funs3)
  6077. // {
  6078. // UpdatePLCMonitor(1, plcNo, 0);
  6079. // continue;
  6080. // }
  6081. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  6082. // {
  6083. // Stopwatch stopwatch1 = new Stopwatch();
  6084. // Stopwatch stopwatch2 = new Stopwatch();
  6085. // stopwatch1.Start();
  6086. // stopwatch2.Start();
  6087. // #region 一次性读取所有数据
  6088. // // 一次性读取所有数据
  6089. // ModbusClientHelper modbusClientHelper = Funs[plcNo];
  6090. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  6091. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  6092. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 36);
  6093. // int[] datas = data1.Concat(data2).ToArray();
  6094. // datas = datas.Concat(data3).ToArray();
  6095. // s3PLCData["c1PLC_FLAG_Check"] = datas[2]; // PLC_FLAG 进站校验
  6096. // s3PLCData["c1MES_FLAG_Check"] = datas[3]; // MES_FLAG
  6097. // int[] c1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  6098. // s3PLCData["c1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(c1ProductSN_CheckData, 0, 40); // 产品SN(二穴载具SN)
  6099. // s3PLCData["c1PLC_FLAG_Unbind"] = datas[81]; // PLC_FLAG 二穴载具解绑
  6100. // s3PLCData["c1MES_FLAG_Unbind"] = datas[82]; // MES_FLAG
  6101. // s3PLCData["c1VehicleCavity_Unbind"] = datas[103]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6102. // s3PLCData["c1PLC_FLAG_Bind"] = datas[114]; // PLC_FLAG 二穴载具绑定
  6103. // s3PLCData["c1MES_FLAG_Bind"] = datas[115]; // MES_FLAG
  6104. // s3PLCData["c1CavityReverse_Bind"] = datas[136]; // 是否是两个穴位交换
  6105. // s3PLCData["c1VehicleCavityFr_Bind"] = datas[137]; // 来源穴位号(产品取自二穴载具哪个穴位)
  6106. // s3PLCData["c1VehicleCavityTo_Bind"] = datas[138]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  6107. // s3PLCData["c1PLC_FLAG"] = datas[149]; // PLC_FLAG 出站接口
  6108. // s3PLCData["c1MES_FLAG"] = datas[150]; // MES_FLAG
  6109. // int[] c1ProductSNData = datas.Skip(151).Take(20).ToArray();
  6110. // s3PLCData["c1ProductSN"] = ModbusClient.ConvertRegistersToString(c1ProductSNData, 0, 40); // 产品SN(一穴载具SN)
  6111. // s3PLCData["c1VehicleCavity"] = datas[191]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6112. // s3PLCData["c1Result"] = datas[192]; // 产品结果
  6113. // s3PLCData["c1OEEPLC_FLAG"] = datas[203]; // PLC_FLAG 节拍接口
  6114. // s3PLCData["c1OEEMES_FLAG"] = datas[204]; // MES_FLAG
  6115. // int[] c1OEEProductSNData = datas.Skip(205).Take(20).ToArray();
  6116. // s3PLCData["c1OEEProductSN"] = ModbusClient.ConvertRegistersToString(c1OEEProductSNData, 0, 40); // 产品SN(载具SN)
  6117. // s3PLCData["c1OEEType"] = datas[225]; // 节拍类型(plc写入)
  6118. // #endregion 一次性读取所有数据
  6119. // stopwatch2.Stop();
  6120. // #region 回写操作,写后清空flag
  6121. // PLCWriteData(Funs[plcNo], ref s3PLCData, ref s3PLCWriteData);
  6122. // #endregion 回写操作,写后清空flag
  6123. // #region S3进站校验
  6124. // try
  6125. // {
  6126. // int c1PLC_FLAG_Check = (int)s3PLCData["c1PLC_FLAG_Check"];
  6127. // int c1MES_FLAG_Check = (int)s3PLCData["c1MES_FLAG_Check"];
  6128. // int c1PLC_FLAG_CheckOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Check"];
  6129. // if (c1PLC_FLAG_Check != c1PLC_FLAG_CheckOld)
  6130. // {
  6131. // if (c1PLC_FLAG_Check == 1 && c1MES_FLAG_Check == 0) // 0->1
  6132. // Task.Run(() => S3进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  6133. // else if (c1PLC_FLAG_Check == 0 && c1MES_FLAG_Check != 0)
  6134. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  6135. // s3PLCSignal_Old["c1PLC_FLAG_Check"] = s3PLCData["c1PLC_FLAG_Check"];
  6136. // }
  6137. // }
  6138. // catch (Exception ex)
  6139. // {
  6140. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  6141. // string str = ex.StackTrace;
  6142. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6143. // }
  6144. // #endregion S3进站校验
  6145. // #region S3二穴载具解绑
  6146. // try
  6147. // {
  6148. // int c1PLC_FLAG_Unbind = (int)s3PLCData["c1PLC_FLAG_Unbind"];
  6149. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Unbind"];
  6150. // int c1PLC_FLAG_UnbindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Unbind"];
  6151. // if (c1PLC_FLAG_Unbind != c1PLC_FLAG_UnbindOld)
  6152. // {
  6153. // if (c1PLC_FLAG_Unbind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  6154. // Task.Run(() => S3二穴载具解绑(plcNo, stationNameStr)); // MreTasks[2].Set();
  6155. // else if (c1PLC_FLAG_Unbind == 0 && c1MES_FLAG_Bind != 0)
  6156. // Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)0);
  6157. // s3PLCSignal_Old["c1PLC_FLAG_Unbind"] = s3PLCData["c1PLC_FLAG_Unbind"];
  6158. // }
  6159. // }
  6160. // catch (Exception ex)
  6161. // {
  6162. // Funs[plcNo].WriteMultipleRegisters<short>(2083, (short)6); // 6代表上位机报警
  6163. // string str = ex.StackTrace;
  6164. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6165. // }
  6166. // #endregion S3二穴载具解绑
  6167. // #region S3二穴载具绑定
  6168. // try
  6169. // {
  6170. // int c1PLC_FLAG_Bind = (int)s3PLCData["c1PLC_FLAG_Bind"];
  6171. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Bind"];
  6172. // int c1PLC_FLAG_BindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Bind"];
  6173. // if (c1PLC_FLAG_Bind != c1PLC_FLAG_BindOld)
  6174. // {
  6175. // if (c1PLC_FLAG_Bind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  6176. // Task.Run(() => S3二穴载具绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  6177. // else if (c1PLC_FLAG_Bind == 0 && c1MES_FLAG_Bind != 0)
  6178. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)0);
  6179. // s3PLCSignal_Old["c1PLC_FLAG_Bind"] = s3PLCData["c1PLC_FLAG_Bind"];
  6180. // }
  6181. // }
  6182. // catch (Exception ex)
  6183. // {
  6184. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  6185. // string str = ex.StackTrace;
  6186. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6187. // }
  6188. // #endregion S3二穴载具绑定
  6189. // #region S3出站接口(+一穴载具绑定)
  6190. // try
  6191. // {
  6192. // int c1PLC_FLAG = (int)s3PLCData["c1PLC_FLAG"];
  6193. // int c1MES_FLAG = (int)s3PLCData["c1MES_FLAG"];
  6194. // int c1PLC_FLAGOld = (int)s3PLCSignal_Old["c1PLC_FLAG"];
  6195. // if (c1PLC_FLAG != c1PLC_FLAGOld)
  6196. // {
  6197. // if (c1PLC_FLAG == 1 && c1MES_FLAG == 0) // 0->1
  6198. // Task.Run(() => S3出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  6199. // else if (c1PLC_FLAG == 0 && c1MES_FLAG != 0)
  6200. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)0);
  6201. // s3PLCSignal_Old["c1PLC_FLAG"] = s3PLCData["c1PLC_FLAG"];
  6202. // }
  6203. // }
  6204. // catch (Exception ex)
  6205. // {
  6206. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)6); // 6代表上位机报警
  6207. // string str = ex.StackTrace;
  6208. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6209. // }
  6210. // #endregion S3出站接口(+一穴载具绑定)
  6211. // #region S3节拍接口
  6212. // try
  6213. // {
  6214. // int c1OEEPLC_FLAG = (int)s3PLCData["c1OEEPLC_FLAG"];
  6215. // int c1OEEMES_FLAG = (int)s3PLCData["c1OEEMES_FLAG"];
  6216. // int c1OEEPLC_FLAGOld = (int)s3PLCSignal_Old["c1OEEPLC_FLAG"];
  6217. // if (c1OEEPLC_FLAG != c1OEEPLC_FLAGOld)
  6218. // {
  6219. // if (c1OEEPLC_FLAG == 1 && c1OEEMES_FLAG == 0) // 0->1
  6220. // Task.Run(() => S3节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  6221. // else if (c1OEEPLC_FLAG == 0 && c1OEEMES_FLAG != 0)
  6222. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)0);
  6223. // s3PLCSignal_Old["c1OEEPLC_FLAG"] = s3PLCData["c1OEEPLC_FLAG"];
  6224. // }
  6225. // }
  6226. // catch (Exception ex)
  6227. // {
  6228. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  6229. // string str = ex.StackTrace;
  6230. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6231. // }
  6232. // #endregion S3节拍接口
  6233. // #region 心跳
  6234. // try
  6235. // {
  6236. // short states = 0;
  6237. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  6238. // }
  6239. // catch (Exception ex)
  6240. // {
  6241. // string str = ex.StackTrace;
  6242. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6243. // }
  6244. // #endregion 心跳
  6245. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  6246. // stopwatch1.Stop();
  6247. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  6248. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  6249. // }
  6250. // else
  6251. // {
  6252. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6253. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  6254. // Funs[plcNo].Connect();
  6255. // }
  6256. // }
  6257. // catch (Exception ex)
  6258. // {
  6259. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6260. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6261. // Funs[plcNo].ReConnect();
  6262. // }
  6263. // Thread.Sleep(IntervalReadPLC);
  6264. // }
  6265. //}
  6266. /// <summary>
  6267. /// [S3] 值板机- 进站校验
  6268. /// </summary>
  6269. /// <param name="plcNo">PLC编号</param>
  6270. /// <param name="stationNameStr">工站全称</param>
  6271. private void S3进站校验(int plcNo, string stationNameStr)
  6272. {
  6273. Stopwatch stopwatch1 = new Stopwatch();
  6274. Stopwatch stopwatch2 = new Stopwatch();
  6275. try
  6276. {
  6277. stopwatch1.Start();
  6278. string sn = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(载具码)
  6279. sn = sn.Replace("\0", "");
  6280. #region 查询载具上的产品信息
  6281. string cavityData = string.Empty;
  6282. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  6283. if (string.IsNullOrEmpty(cavityData))
  6284. cavityData = "";
  6285. if (snResult != 0)
  6286. {
  6287. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6288. writeToPLC_Flag1.Name = "c1MES_FLAG_Check";
  6289. writeToPLC_Flag1.Adress = 2003;
  6290. writeToPLC_Flag1.Value = (short)6;
  6291. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag1);
  6292. stopwatch1.Stop();
  6293. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6294. return;
  6295. }
  6296. #endregion 查询载具上的产品信息
  6297. string[] cavitySNs = cavityData.Split('.');
  6298. string part1Str = ""; // 产品1的SN码
  6299. string part2Str = ""; // 产品2的SN码
  6300. short c1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  6301. short c1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  6302. if (cavitySNs != null && cavitySNs.Length >= 2)
  6303. {
  6304. part1Str = cavitySNs[0];
  6305. part2Str = cavitySNs[1];
  6306. c1Part1Result_Check = 2;
  6307. c1Part2Result_Check = 2;
  6308. }
  6309. if (part1Str == "假产品")
  6310. c1Part1Result_Check = 3;
  6311. if (part2Str == "假产品")
  6312. c1Part2Result_Check = 3;
  6313. // 调用MES进站
  6314. stopwatch2.Start();
  6315. // 调用MES进站 - 产品1
  6316. List<TestItem> item;
  6317. int result1 = c1Part1Result_Check;
  6318. if (result1 != 3)
  6319. {
  6320. item = new List<TestItem>();
  6321. item.Add(new TestItem()
  6322. {
  6323. Parameter_name = "载具码",
  6324. Parameter_value = sn,
  6325. });
  6326. item.Add(new TestItem()
  6327. {
  6328. Parameter_name = "载具穴号",
  6329. Parameter_value = "1",
  6330. });
  6331. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, part1Str, item, out string errorMsg);
  6332. }
  6333. // 调用MES进站 - 产品2
  6334. int result2 = c1Part2Result_Check;
  6335. if (result2 != 3)
  6336. {
  6337. item = new List<TestItem>();
  6338. item.Add(new TestItem()
  6339. {
  6340. Parameter_name = "载具码",
  6341. Parameter_value = sn,
  6342. });
  6343. item.Add(new TestItem()
  6344. {
  6345. Parameter_name = "载具穴号",
  6346. Parameter_value = "2",
  6347. });
  6348. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, part2Str, item, out string errorMsg);
  6349. }
  6350. stopwatch2.Stop();
  6351. if (result1 == 2)
  6352. c1Part1Result_Check = 2;
  6353. if (result2 == 2)
  6354. c1Part2Result_Check = 2;
  6355. int result = result1;
  6356. if (result == 1)
  6357. result = result2;
  6358. short c1Part1Num_Check = 0; // 穴位1产品返修次数(上位机写入)
  6359. short c1Part2Num_Check = 0; // 穴位2产品返修次数(上位机写入)
  6360. short c1MES_FLAG_Check = (short)result;
  6361. //Funs[plcNo].WriteMultipleRegisters<short>(2024, c1Part1Result_Check);
  6362. //Funs[plcNo].WriteMultipleRegisters<short>(2025, c1Part2Result_Check);
  6363. //Funs[plcNo].WriteMultipleRegisters<short>(2026, c1Part1Num_Check);
  6364. //Funs[plcNo].WriteMultipleRegisters<short>(2027, c1Part2Num_Check);
  6365. //// MES_Flag
  6366. //Funs[plcNo].WriteMultipleRegisters<short>(2003, c1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6367. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6368. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  6369. writeToPLC_Flag.Adress = 2003;
  6370. writeToPLC_Flag.Value = c1MES_FLAG_Check;
  6371. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6372. {
  6373. Name = "c1Part1Result_Check",
  6374. Adress = 2024,
  6375. ValueType = PLCValueType.Short,
  6376. Value = c1Part1Result_Check
  6377. });
  6378. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6379. {
  6380. Name = "c1Part2Result_Check",
  6381. Adress = 2025,
  6382. ValueType = PLCValueType.Short,
  6383. Value = c1Part2Result_Check
  6384. });
  6385. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6386. {
  6387. Name = "c1Part1Num_Check",
  6388. Adress = 2026,
  6389. ValueType = PLCValueType.Short,
  6390. Value = c1Part1Num_Check
  6391. });
  6392. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6393. {
  6394. Name = "c1Part2Num_Check",
  6395. Adress = 2027,
  6396. ValueType = PLCValueType.Short,
  6397. Value = c1Part2Num_Check
  6398. });
  6399. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  6400. }
  6401. catch (Exception ex)
  6402. {
  6403. string str = ex.StackTrace;
  6404. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6405. // MES_Flag
  6406. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  6407. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6408. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  6409. writeToPLC_Flag.Adress = 2003;
  6410. writeToPLC_Flag.Value = (short)6;
  6411. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  6412. }
  6413. stopwatch1.Stop();
  6414. AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6415. }
  6416. /// <summary>
  6417. /// [S3] 值板机 - 二穴载具解绑
  6418. /// </summary>
  6419. /// <param name="plcNo">PLC编号</param>
  6420. /// <param name="stationNameStr">工站全称</param>
  6421. private void S3二穴载具解绑(int plcNo, string stationNameStr)
  6422. {
  6423. Stopwatch stopwatch1 = new Stopwatch();
  6424. Stopwatch stopwatch2 = new Stopwatch();
  6425. try
  6426. {
  6427. stopwatch1.Start();
  6428. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  6429. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6430. int c1VehicleCavity_Unbind = (int)s3PLCData["c1VehicleCavity_Unbind"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6431. // 解绑
  6432. #region 查询载具上的产品信息
  6433. string cavityData = string.Empty;
  6434. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6435. if (string.IsNullOrEmpty(cavityData))
  6436. cavityData = "";
  6437. if (snResult != 0)
  6438. {
  6439. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6440. writeToPLC_Flag1.Name = "c1MES_FLAG_Unbind";
  6441. writeToPLC_Flag1.Adress = 2082;
  6442. writeToPLC_Flag1.Value = (short)6;
  6443. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag1);
  6444. stopwatch1.Stop();
  6445. AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6446. return;
  6447. }
  6448. #endregion 查询载具上的产品信息
  6449. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  6450. #region 解绑
  6451. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  6452. {
  6453. // 删除
  6454. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6455. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res1}");
  6456. }
  6457. else
  6458. {
  6459. string data_new = string.Join(".", cavitySNs);
  6460. // 删除再插入
  6461. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6462. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6463. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res2},{res3}");
  6464. }
  6465. #endregion 解绑
  6466. short c1MES_FLAG_Unbind = 1;
  6467. stopwatch2.Start();
  6468. // MES_Flag
  6469. //Funs[plcNo].WriteMultipleRegisters<short>(2082, c1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6470. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6471. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  6472. writeToPLC_Flag.Adress = 2082;
  6473. writeToPLC_Flag.Value = c1MES_FLAG_Unbind;
  6474. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  6475. stopwatch2.Stop();
  6476. }
  6477. catch (Exception ex)
  6478. {
  6479. string str = ex.StackTrace;
  6480. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6481. // MES_Flag
  6482. stopwatch2.Start();
  6483. //Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)6); // 6代表上位机报警
  6484. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6485. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  6486. writeToPLC_Flag.Adress = 2082;
  6487. writeToPLC_Flag.Value = (short)6;
  6488. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  6489. stopwatch2.Stop();
  6490. }
  6491. stopwatch1.Stop();
  6492. AddMessage(LogType.Info, stationNameStr + "_二穴载具解绑;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6493. }
  6494. /// <summary>
  6495. /// [S3] 值板机 - 二穴载具绑定
  6496. /// </summary>
  6497. /// <param name="plcNo">PLC编号</param>
  6498. /// <param name="stationNameStr">工站全称</param>
  6499. private void S3二穴载具绑定(int plcNo, string stationNameStr)
  6500. {
  6501. Stopwatch stopwatch1 = new Stopwatch();
  6502. Stopwatch stopwatch2 = new Stopwatch();
  6503. try
  6504. {
  6505. stopwatch1.Start();
  6506. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  6507. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6508. int c1CavityReverse_Bind = (int)s3PLCData["c1CavityReverse_Bind"]; // 是否是两个穴位交换
  6509. int c1VehicleCavityFr_Bind = (int)s3PLCData["c1VehicleCavityFr_Bind"]; // 来源穴位号(产品取自二穴载具哪个穴位)
  6510. int c1VehicleCavityTo_Bind = (int)s3PLCData["c1VehicleCavityTo_Bind"]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  6511. stopwatch2.Start();
  6512. #region 查询载具上的产品信息
  6513. string cavityData = string.Empty;
  6514. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6515. if (string.IsNullOrEmpty(cavityData))
  6516. cavityData = "";
  6517. if (snResult != 0)
  6518. {
  6519. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6520. writeToPLC_Flag1.Name = "c1MES_FLAG_Bind";
  6521. writeToPLC_Flag1.Adress = 2115;
  6522. writeToPLC_Flag1.Value = (short)6;
  6523. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag1);
  6524. stopwatch1.Stop();
  6525. AddMessage(LogType.Info, stationNameStr + $"_二穴载具绑定失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6526. return;
  6527. }
  6528. #endregion 查询载具上的产品信息
  6529. // 产品换载具
  6530. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  6531. string partSn1 = "";
  6532. string partSn2 = "";
  6533. if (cavitySNs != null && cavitySNs.Length >= 2)
  6534. {
  6535. partSn1 = cavitySNs[0];
  6536. partSn2 = cavitySNs[1];
  6537. }
  6538. string data_new = string.Empty;
  6539. // 是否是两个穴位交换
  6540. if (c1CavityReverse_Bind == 1)
  6541. {
  6542. // 交换
  6543. data_new = string.Concat(partSn2, ".", partSn1);
  6544. }
  6545. else
  6546. { // 不交换
  6547. string sn = string.Copy(cavitySNs[c1VehicleCavityFr_Bind]);
  6548. cavitySNs[c1VehicleCavityTo_Bind] = sn;
  6549. cavitySNs[c1VehicleCavityFr_Bind] = "";
  6550. data_new = string.Join(".", cavitySNs);
  6551. }
  6552. // 删除再插入
  6553. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6554. int res2 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6555. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-_二穴载具绑定SN{c1ProductSN_Check}---{res1},{res2}");
  6556. stopwatch2.Stop();
  6557. short c1MES_FLAG_Bind = 1;
  6558. // MES_Flag
  6559. //Funs[plcNo].WriteMultipleRegisters<short>(2115, c1MES_FLAG_Bind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6560. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6561. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  6562. writeToPLC_Flag.Adress = 2115;
  6563. writeToPLC_Flag.Value = c1MES_FLAG_Bind;
  6564. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  6565. }
  6566. catch (Exception ex)
  6567. {
  6568. string str = ex.StackTrace;
  6569. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6570. // MES_Flag
  6571. stopwatch2.Start();
  6572. //Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  6573. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6574. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  6575. writeToPLC_Flag.Adress = 2115;
  6576. writeToPLC_Flag.Value = (short)6;
  6577. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  6578. stopwatch2.Stop();
  6579. }
  6580. stopwatch1.Stop();
  6581. AddMessage(LogType.Info, stationNameStr + "_二穴载具绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6582. }
  6583. //// 上次采集到的SN
  6584. //private string sn_值板机 = string.Empty;
  6585. /// <summary>
  6586. /// [S3] 值板机 - 出站接口
  6587. /// </summary>
  6588. /// <param name="plcNo">PLC编号</param>
  6589. private void S3出站接口(int plcNo, string stationCode, string stationName)
  6590. {
  6591. Stopwatch stopwatch1 = new Stopwatch();
  6592. Stopwatch stopwatch2 = new Stopwatch();
  6593. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6594. string stationNameStr = stationCode + stationName;
  6595. string processItem = stationName; // 测试项目
  6596. try
  6597. {
  6598. stopwatch1.Start();
  6599. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6600. //string batch_num = GlobalContext.BatchNumber; // 批次号
  6601. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6602. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6603. string sn = (string)s3PLCData["c1ProductSN"]; // 产品SN(一穴载具SN)
  6604. sn = sn.Replace("\0", "");
  6605. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 二穴载具SN(产品取自哪个二穴载具)
  6606. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6607. int c1VehicleCavity = (int)s3PLCData["c1VehicleCavity"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6608. int c1Result = (int)s3PLCData["c1Result"]; // 产品结果
  6609. bool pass = c1Result == 1;
  6610. // 查sn
  6611. #region 查询载具上的产品信息
  6612. string cavityData = string.Empty;
  6613. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6614. if (string.IsNullOrEmpty(cavityData))
  6615. cavityData = "";
  6616. if (snResult != 0)
  6617. {
  6618. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6619. writeToPLC_Flag1.Name = "c1MES_FLAG";
  6620. writeToPLC_Flag1.Adress = 2150;
  6621. writeToPLC_Flag1.Value = (short)4;
  6622. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag1);
  6623. stopwatch1.Stop();
  6624. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6625. return;
  6626. }
  6627. #endregion 查询载具上的产品信息
  6628. string[] cavitySNs = cavityData.Split('.');
  6629. string productSN = "";
  6630. if (cavitySNs != null && cavitySNs.Length >= 2)
  6631. {
  6632. productSN = cavitySNs[c1VehicleCavity];
  6633. cavitySNs[c1VehicleCavity] = "";
  6634. }
  6635. stopwatch2.Start();
  6636. List<TestItem> items = new List<TestItem>();
  6637. items.Add(new TestItem()
  6638. {
  6639. Parameter_name = "二穴载具码",
  6640. Parameter_value = c1ProductSN_Check,
  6641. Parameter_unit = ""
  6642. });
  6643. items.Add(new TestItem()
  6644. {
  6645. Parameter_name = "二穴载具穴号",
  6646. Parameter_value = c1VehicleCavity.ToString(),
  6647. Parameter_unit = ""
  6648. });
  6649. items.Add(new TestItem()
  6650. {
  6651. Parameter_name = "一穴载具码",
  6652. Parameter_value = sn,
  6653. Parameter_unit = ""
  6654. });
  6655. items.Add(new TestItem()
  6656. {
  6657. Parameter_name = "一穴载具穴号",
  6658. Parameter_value = "1",
  6659. Parameter_unit = ""
  6660. });
  6661. items.Add(new TestItem()
  6662. {
  6663. Parameter_name = "产品结果",
  6664. Parameter_value = c1Result == 1 ? "OK" : "NG",
  6665. Parameter_unit = ""
  6666. });
  6667. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  6668. , workorder_code, mtltmrk, productSN, pass, sn, "1");
  6669. short result = (short)result1;
  6670. stopwatch2.Stop();
  6671. #region 存储绑定数据到 边线MES系统中
  6672. if (result == 1)
  6673. {
  6674. string data = string.Concat(productSN);
  6675. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  6676. if (resultMesR != 0)
  6677. {
  6678. result = 4;
  6679. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  6680. }
  6681. }
  6682. #endregion 存储绑定数据到 边线MES系统中
  6683. #region 产品从 来源载具(二穴载具)中删除
  6684. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  6685. {
  6686. // 删除
  6687. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6688. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res1}");
  6689. }
  6690. else
  6691. {
  6692. string data_new = string.Join(".", cavitySNs);
  6693. // 删除再插入
  6694. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6695. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6696. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res2},{res3}");
  6697. }
  6698. #endregion 产品从 来源载具(二穴载具)中删除
  6699. // MES_Flag 为MES报错
  6700. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6701. //Funs[plcNo].WriteMultipleRegisters<short>(2150, result); // 4代表上位机报警
  6702. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6703. writeToPLC_Flag.Name = "c1MES_FLAG";
  6704. writeToPLC_Flag.Adress = 2150;
  6705. writeToPLC_Flag.Value = result;
  6706. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  6707. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  6708. }
  6709. catch (Exception ex)
  6710. {
  6711. stopwatch2.Restart();
  6712. // MES_Flag 为4上位机报错
  6713. //Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)4); // 4代表上位机报警
  6714. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6715. writeToPLC_Flag.Name = "c1MES_FLAG";
  6716. writeToPLC_Flag.Adress = 2150;
  6717. writeToPLC_Flag.Value = (short)4;
  6718. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  6719. stopwatch2.Stop();
  6720. string str = ex.StackTrace;
  6721. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6722. }
  6723. stopwatch1.Stop();
  6724. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6725. }
  6726. /// <summary>
  6727. /// [S3] 值板机- 节拍接口
  6728. /// </summary>
  6729. /// <param name="plcNo">PLC编号</param>
  6730. /// <param name="stationNameStr">工站全称</param>
  6731. private void S3节拍接口(int plcNo, string stationNameStr)
  6732. {
  6733. Stopwatch stopwatch1 = new Stopwatch();
  6734. Stopwatch stopwatch2 = new Stopwatch();
  6735. string resultStr = string.Empty;
  6736. try
  6737. {
  6738. stopwatch1.Start();
  6739. string oEEType = ((int)s3PLCData["c1OEEType"]).ToString(); // 节拍类型(plc写入)
  6740. string c1OEEProductSN = (string)s3PLCData["c1OEEProductSN"]; // 载具SN
  6741. c1OEEProductSN = c1OEEProductSN.Replace("\0", "");
  6742. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  6743. if (!actionBool)
  6744. {
  6745. stopwatch2.Start();
  6746. // MES_Flag
  6747. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6748. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6749. writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
  6750. writeToPLC_Flag1.Adress = 2204;
  6751. writeToPLC_Flag1.Value = (short)4;
  6752. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
  6753. stopwatch2.Stop();
  6754. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6755. return;
  6756. }
  6757. string c1OEEPartNo = string.Empty; // 物料码
  6758. if (string.IsNullOrEmpty(c1OEEProductSN))
  6759. {
  6760. stopwatch2.Start();
  6761. // MES_Flag
  6762. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6763. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6764. writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
  6765. writeToPLC_Flag1.Adress = 2204;
  6766. writeToPLC_Flag1.Value = (short)1;
  6767. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
  6768. stopwatch2.Stop();
  6769. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6770. return;
  6771. }
  6772. else
  6773. { // 查产品SN
  6774. c1OEEPartNo = "Test"; // ZS
  6775. }
  6776. short c1OEEMES_FLAG = 0;
  6777. // 上传OEE
  6778. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, c1OEEPartNo, c1OEEProductSN);
  6779. c1OEEMES_FLAG = result.Item1;
  6780. resultStr = result.Item2;
  6781. stopwatch2.Start();
  6782. // MES_Flag
  6783. //Funs[plcNo].WriteMultipleRegisters<short>(2204, c1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6784. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6785. writeToPLC_Flag.Name = "c1OEEMES_FLAG";
  6786. writeToPLC_Flag.Adress = 2204;
  6787. writeToPLC_Flag.Value = c1OEEMES_FLAG;
  6788. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
  6789. stopwatch2.Stop();
  6790. }
  6791. catch (Exception ex)
  6792. {
  6793. string str = ex.StackTrace;
  6794. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6795. // MES_Flag
  6796. stopwatch2.Start();
  6797. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  6798. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6799. writeToPLC_Flag.Name = "c1OEEMES_FLAG";
  6800. writeToPLC_Flag.Adress = 2204;
  6801. writeToPLC_Flag.Value = (short)4;
  6802. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
  6803. stopwatch2.Stop();
  6804. }
  6805. stopwatch1.Stop();
  6806. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6807. }
  6808. #endregion [S3] 值板机
  6809. #endregion PLC3 刘永村
  6810. #region PLC4 刘果段
  6811. #region [S4] 取放桁架
  6812. /// <summary>
  6813. /// S4工位的数据- 触发信号上次的值
  6814. /// </summary>
  6815. private Dictionary<string, object> s4PLCSignal_Old = new Dictionary<string, object>();
  6816. /// <summary>
  6817. /// S4工位的数据(含触发信号)
  6818. /// </summary>
  6819. private Dictionary<string, object> s4PLCData = new Dictionary<string, object>();
  6820. /// <summary>
  6821. /// S4工位的数据- 回写点位
  6822. /// </summary>
  6823. private Dictionary<string, WriteToPLC_Flag> s4PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  6824. /// <summary>
  6825. /// [S4] 取放桁架
  6826. /// </summary>
  6827. /// <param name="plcNo">PLC编号</param>
  6828. //private void ReadStation_S4(int plcNo)
  6829. //{
  6830. // // [S1] Tray盘上料装备
  6831. // // [S2] FCT
  6832. // // [S3] 值板机
  6833. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  6834. // // [S5] Tray盘下料装备
  6835. // /// 上位机心跳
  6836. // /// 获取设备报警数据与状态信息
  6837. // string stationCode = "[S4_1]";
  6838. // string stationName = "载具下线装备";
  6839. // string stationNameStr = stationCode + stationName;
  6840. // string stationCode2 = "[S4_2]";
  6841. // string stationName2 = "桁架";
  6842. // string stationNameStr2 = stationCode2 + stationName2;
  6843. // string stationCode3 = "[S4_3]";
  6844. // string stationName3 = "提升机1";
  6845. // string stationNameStr3 = stationCode3 + stationName3;
  6846. // string stationCode4 = "[S4_4]";
  6847. // string stationName4 = "提升机2";
  6848. // string stationNameStr4 = stationCode4 + stationName4;
  6849. // string stationCode5 = "[S4_5]";
  6850. // string stationName5 = "载具上线装备";
  6851. // string stationNameStr5 = stationCode5 + stationName5;
  6852. // #region 创建字典
  6853. // // 触发信号字典 赋值
  6854. // s4PLCSignal_Old.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6855. // s4PLCSignal_Old.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  6856. // s4PLCSignal_Old.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6857. // s4PLCSignal_Old.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6858. // s4PLCSignal_Old.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  6859. // s4PLCSignal_Old.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  6860. // s4PLCSignal_Old.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  6861. // s4PLCSignal_Old.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6862. // s4PLCSignal_Old.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  6863. // s4PLCSignal_Old.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  6864. // s4PLCSignal_Old.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6865. // // PLC数据字典 赋值
  6866. // // 载具下线装备(弹夹上线)
  6867. // s4PLCData.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6868. // s4PLCData.Add("d1BulletclipCode", ""); // 扫到的码
  6869. // s4PLCData.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  6870. // s4PLCData.Add("d1VehicleCode", ""); // 扫到的码
  6871. // s4PLCData.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6872. // s4PLCData.Add("d1MES_FLAG", 0); // MES_FLAG
  6873. // s4PLCData.Add("d1ProductSN", ""); // 产品SN(弹夹码)
  6874. // s4PLCData.Add("d1VehicleCode1", ""); // 载具1码(弹夹穴位1)
  6875. // s4PLCData.Add("d1VehicleCode2", ""); // 载具2码(弹夹穴位2)
  6876. // s4PLCData.Add("d1VehicleCode3", ""); // 载具3码(弹夹穴位3)
  6877. // s4PLCData.Add("d1VehicleCode4", ""); // 载具4码(弹夹穴位4)
  6878. // s4PLCData.Add("d1VehicleCode5", ""); // 载具5码(弹夹穴位5)
  6879. // s4PLCData.Add("d1VehicleCode6", ""); // 载具6码(弹夹穴位6)
  6880. // s4PLCData.Add("d1VehicleCode7", ""); // 载具7码(弹夹穴位7)
  6881. // s4PLCData.Add("d1VehicleCode8", ""); // 载具8码(弹夹穴位8)
  6882. // s4PLCData.Add("d1VehicleCode9", ""); // 载具9码(弹夹穴位9)
  6883. // s4PLCData.Add("d1VehicleCode10", ""); // 载具10码(弹夹穴位10)
  6884. // s4PLCData.Add("d1Result", 0); // 产品结果
  6885. // s4PLCData.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6886. // s4PLCData.Add("d1OEEMES_FLAG", 0); // MES_FLAG
  6887. // s4PLCData.Add("d1OEEProductSN", "");// 产品SN(载具SN)
  6888. // s4PLCData.Add("d1OEEType", 0); // 节拍类型(plc写入)
  6889. // s4PLCData.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  6890. // s4PLCData.Add("d2BulletclipStates", 0); // 弹夹状态
  6891. // s4PLCData.Add("d2BulletclipCode", ""); // 扫到的码
  6892. // // 真空标机(提升机)
  6893. // s4PLCData.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  6894. // s4PLCData.Add("d3MES_FLAG", 0); // MES_FLAG
  6895. // s4PLCData.Add("d3Type", 0); // 进站还是出站
  6896. // s4PLCData.Add("d3ProductSN", ""); // 产品SN(弹夹码)
  6897. // s4PLCData.Add("d3Result", 0); // 产品结果
  6898. // s4PLCData.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  6899. // s4PLCData.Add("d4MES_FLAG", 0); // MES_FLAG
  6900. // s4PLCData.Add("d4Type", 0); // 进站还是出站
  6901. // s4PLCData.Add("d4ProductSN", ""); // 产品SN(弹夹码)
  6902. // s4PLCData.Add("d4Result", 0); // 产品结果
  6903. // // 载具上线装备(弹夹下线)
  6904. // s4PLCData.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6905. // s4PLCData.Add("d5BulletclipCode", ""); // 扫到的码
  6906. // s4PLCData.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  6907. // s4PLCData.Add("d5VehicleCode", ""); // 扫到的码
  6908. // s4PLCData.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  6909. // s4PLCData.Add("d5MES_FLAG", 0); // MES_FLAG
  6910. // s4PLCData.Add("d5ProductSN", ""); // 产品SN(弹夹码)
  6911. // s4PLCData.Add("d5VehicleCode1", ""); // 载具1码(弹夹穴位1)
  6912. // s4PLCData.Add("d5VehicleCode2", ""); // 载具2码(弹夹穴位2)
  6913. // s4PLCData.Add("d5VehicleCode3", ""); // 载具3码(弹夹穴位3)
  6914. // s4PLCData.Add("d5VehicleCode4", ""); // 载具4码(弹夹穴位4)
  6915. // s4PLCData.Add("d5VehicleCode5", ""); // 载具5码(弹夹穴位5)
  6916. // s4PLCData.Add("d5VehicleCode6", ""); // 载具6码(弹夹穴位6)
  6917. // s4PLCData.Add("d5VehicleCode7", ""); // 载具7码(弹夹穴位7)
  6918. // s4PLCData.Add("d5VehicleCode8", ""); // 载具8码(弹夹穴位8)
  6919. // s4PLCData.Add("d5VehicleCode9", ""); // 载具9码(弹夹穴位9)
  6920. // s4PLCData.Add("d5VehicleCode10", ""); // 载具10码(弹夹穴位10)
  6921. // s4PLCData.Add("d5Result", 0); // 产品结果
  6922. // s4PLCData.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6923. // s4PLCData.Add("d5OEEMES_FLAG", 0); // MES_FLAG
  6924. // s4PLCData.Add("d5OEEProductSN", "");// 产品SN(载具SN)
  6925. // s4PLCData.Add("d5OEEType", 0); // 节拍类型(plc写入)
  6926. // #endregion 创建字典
  6927. // while (IsRun)
  6928. // {
  6929. // try
  6930. // {
  6931. // if (!GlobalContext._IsCon_Funs4)
  6932. // {
  6933. // UpdatePLCMonitor(1, plcNo, 0);
  6934. // continue;
  6935. // }
  6936. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  6937. // {
  6938. // Stopwatch stopwatch1 = new Stopwatch();
  6939. // Stopwatch stopwatch2 = new Stopwatch();
  6940. // stopwatch1.Start();
  6941. // stopwatch2.Start();
  6942. // #region 一次性读取所有数据
  6943. // // 载具下线装备(弹夹上线)
  6944. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  6945. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  6946. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  6947. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 100);
  6948. // int[] data5 = Funs[plcNo].ReadHoldingRegisters(2400, 100);
  6949. // int[] data6 = Funs[plcNo].ReadHoldingRegisters(2500, 100);
  6950. // int[] data7 = Funs[plcNo].ReadHoldingRegisters(2600, 100);
  6951. // int[] data8 = Funs[plcNo].ReadHoldingRegisters(2700, 100);
  6952. // int[] data9 = Funs[plcNo].ReadHoldingRegisters(2800, 100);
  6953. // int[] data10 = Funs[plcNo].ReadHoldingRegisters(2900, 56);
  6954. // int[] datas = data1.Concat(data2).ToArray();
  6955. // datas = datas.Concat(data3).ToArray();
  6956. // datas = datas.Concat(data4).ToArray();
  6957. // datas = datas.Concat(data5).ToArray();
  6958. // datas = datas.Concat(data6).ToArray();
  6959. // datas = datas.Concat(data7).ToArray();
  6960. // datas = datas.Concat(data8).ToArray();
  6961. // datas = datas.Concat(data9).ToArray();
  6962. // datas = datas.Concat(data10).ToArray();
  6963. // // 载具下线装备(弹夹上线)
  6964. // s4PLCData["d1BulletclipScanCode"] = datas[2]; // 扫码信号 弹夹扫码
  6965. // int[] d1BulletclipCodeData = datas.Skip(3).Take(20).ToArray();
  6966. // s4PLCData["d1BulletclipCode"] = ModbusClient.ConvertRegistersToString(d1BulletclipCodeData, 0, 40);
  6967. // s4PLCData["d1VehicleScanCode"] = datas[33]; // 扫码信号 载具扫码
  6968. // int[] d1VehicleCodeData = datas.Skip(34).Take(20).ToArray();
  6969. // s4PLCData["d1VehicleCode"] = ModbusClient.ConvertRegistersToString(d1VehicleCodeData, 0, 40);
  6970. // s4PLCData["d1PLC_FLAG"] = datas[64]; // PLC_FLAG 出站接口
  6971. // s4PLCData["d1MES_FLAG"] = datas[65];
  6972. // int[] d1ProductSNData = datas.Skip(66).Take(20).ToArray();
  6973. // s4PLCData["d1ProductSN"] = ModbusClient.ConvertRegistersToString(d1ProductSNData, 0, 40); // 产品SN(物料码)
  6974. // int[] d1VehicleCode1Data = datas.Skip(86).Take(20).ToArray();
  6975. // s4PLCData["d1VehicleCode1"] = ModbusClient.ConvertRegistersToString(d1VehicleCode1Data, 0, 40);
  6976. // int[] d1VehicleCode2Data = datas.Skip(106).Take(20).ToArray();
  6977. // s4PLCData["d1VehicleCode2"] = ModbusClient.ConvertRegistersToString(d1VehicleCode2Data, 0, 40);
  6978. // int[] d1VehicleCode3Data = datas.Skip(126).Take(20).ToArray();
  6979. // s4PLCData["d1VehicleCode3"] = ModbusClient.ConvertRegistersToString(d1VehicleCode3Data, 0, 40);
  6980. // int[] d1VehicleCode4Data = datas.Skip(146).Take(20).ToArray();
  6981. // s4PLCData["d1VehicleCode4"] = ModbusClient.ConvertRegistersToString(d1VehicleCode4Data, 0, 40);
  6982. // int[] d1VehicleCode5Data = datas.Skip(166).Take(20).ToArray();
  6983. // s4PLCData["d1VehicleCode5"] = ModbusClient.ConvertRegistersToString(d1VehicleCode5Data, 0, 40);
  6984. // int[] d1VehicleCode6Data = datas.Skip(186).Take(20).ToArray();
  6985. // s4PLCData["d1VehicleCode6"] = ModbusClient.ConvertRegistersToString(d1VehicleCode6Data, 0, 40);
  6986. // int[] d1VehicleCode7Data = datas.Skip(206).Take(20).ToArray();
  6987. // s4PLCData["d1VehicleCode7"] = ModbusClient.ConvertRegistersToString(d1VehicleCode7Data, 0, 40);
  6988. // int[] d1VehicleCode8Data = datas.Skip(226).Take(20).ToArray();
  6989. // s4PLCData["d1VehicleCode8"] = ModbusClient.ConvertRegistersToString(d1VehicleCode8Data, 0, 40);
  6990. // int[] d1VehicleCode9Data = datas.Skip(246).Take(20).ToArray();
  6991. // s4PLCData["d1VehicleCode9"] = ModbusClient.ConvertRegistersToString(d1VehicleCode9Data, 0, 40);
  6992. // int[] d1VehicleCode10Data = datas.Skip(266).Take(20).ToArray();
  6993. // s4PLCData["d1VehicleCode10"] = ModbusClient.ConvertRegistersToString(d1VehicleCode10Data, 0, 40);
  6994. // int[] d1VehicleCode11Data = datas.Skip(286).Take(20).ToArray();
  6995. // s4PLCData["d1VehicleCode11"] = ModbusClient.ConvertRegistersToString(d1VehicleCode11Data, 0, 40);
  6996. // int[] d1VehicleCode12Data = datas.Skip(306).Take(20).ToArray();
  6997. // s4PLCData["d1VehicleCode12"] = ModbusClient.ConvertRegistersToString(d1VehicleCode12Data, 0, 40);
  6998. // int[] d1VehicleCode13Data = datas.Skip(326).Take(20).ToArray();
  6999. // s4PLCData["d1VehicleCode13"] = ModbusClient.ConvertRegistersToString(d1VehicleCode13Data, 0, 40);
  7000. // int[] d1VehicleCode14Data = datas.Skip(346).Take(20).ToArray();
  7001. // s4PLCData["d1VehicleCode14"] = ModbusClient.ConvertRegistersToString(d1VehicleCode14Data, 0, 40);
  7002. // int[] d1VehicleCode15Data = datas.Skip(366).Take(20).ToArray();
  7003. // s4PLCData["d1VehicleCode15"] = ModbusClient.ConvertRegistersToString(d1VehicleCode15Data, 0, 40);
  7004. // s4PLCData["d1Result"] = datas[386];
  7005. // s4PLCData["d1OEEPLC_FLAG"] = datas[397]; // PLC_FLAG 节拍接口
  7006. // s4PLCData["d1OEEMES_FLAG"] = datas[398];
  7007. // int[] d1OEEProductSNData = datas.Skip(399).Take(20).ToArray();
  7008. // s4PLCData["d1OEEProductSN"] = ModbusClient.ConvertRegistersToString(d1OEEProductSNData, 0, 40);
  7009. // s4PLCData["d1OEEType"] = datas[419];
  7010. // // 桁架(查询标机中弹夹的状态)
  7011. // s4PLCData["d2BulletclipScanCode"] = datas[430];
  7012. // s4PLCData["d2BulletclipStates"] = datas[431];
  7013. // int[] d2BulletclipCodeData = datas.Skip(432).Take(20).ToArray();
  7014. // s4PLCData["d2BulletclipCode"] = ModbusClient.ConvertRegistersToString(d2BulletclipCodeData, 0, 40);
  7015. // // 真空标机
  7016. // s4PLCData["d3PLC_FLAG"] = datas[462]; // 真空标机1 出站接口
  7017. // s4PLCData["d3MES_FLAG"] = datas[463];
  7018. // int[] d3ProductSNData = datas.Skip(464).Take(20).ToArray();
  7019. // s4PLCData["d3ProductSN"] = ModbusClient.ConvertRegistersToString(d3ProductSNData, 0, 40);
  7020. // s4PLCData["d3Result"] = datas[484];
  7021. // s4PLCData["d3Type"] = datas[485];
  7022. // s4PLCData["d4PLC_FLAG"] = datas[495]; // 真空标机2 出站接口
  7023. // s4PLCData["d4MES_FLAG"] = datas[496];
  7024. // int[] d4ProductSNData = datas.Skip(497).Take(20).ToArray();
  7025. // s4PLCData["d4ProductSN"] = ModbusClient.ConvertRegistersToString(d4ProductSNData, 0, 40);
  7026. // s4PLCData["d4Result"] = datas[517];
  7027. // s4PLCData["d4Type"] = datas[518];
  7028. // // 载具上线装备(弹夹下线)
  7029. // s4PLCData["d5BulletclipScanCode"] = datas[528]; // 扫码信号 弹夹扫码
  7030. // int[] d5BulletclipCodeData = datas.Skip(529).Take(20).ToArray();
  7031. // s4PLCData["d5BulletclipCode"] = ModbusClient.ConvertRegistersToString(d5BulletclipCodeData, 0, 40);
  7032. // s4PLCData["d5VehicleScanCode"] = datas[559]; // 扫码信号 载具扫码
  7033. // int[] d5VehicleCodeData = datas.Skip(560).Take(20).ToArray();
  7034. // s4PLCData["d5VehicleCode"] = ModbusClient.ConvertRegistersToString(d5VehicleCodeData, 0, 40);
  7035. // s4PLCData["d5PLC_FLAG"] = datas[590]; // PLC_FLAG 出站接口
  7036. // s4PLCData["d5MES_FLAG"] = datas[591];
  7037. // int[] d5ProductSNData = datas.Skip(592).Take(20).ToArray();
  7038. // s4PLCData["d5ProductSN"] = ModbusClient.ConvertRegistersToString(d5ProductSNData, 0, 40); // 产品SN(物料码)
  7039. // int[] d5VehicleCode1Data = datas.Skip(612).Take(20).ToArray();
  7040. // s4PLCData["d5VehicleCode1"] = ModbusClient.ConvertRegistersToString(d5VehicleCode1Data, 0, 40);
  7041. // int[] d5VehicleCode2Data = datas.Skip(632).Take(20).ToArray();
  7042. // s4PLCData["d5VehicleCode2"] = ModbusClient.ConvertRegistersToString(d5VehicleCode2Data, 0, 40);
  7043. // int[] d5VehicleCode3Data = datas.Skip(652).Take(20).ToArray();
  7044. // s4PLCData["d5VehicleCode3"] = ModbusClient.ConvertRegistersToString(d5VehicleCode3Data, 0, 40);
  7045. // int[] d5VehicleCode4Data = datas.Skip(672).Take(20).ToArray();
  7046. // s4PLCData["d5VehicleCode4"] = ModbusClient.ConvertRegistersToString(d5VehicleCode4Data, 0, 40);
  7047. // int[] d5VehicleCode5Data = datas.Skip(692).Take(20).ToArray();
  7048. // s4PLCData["d5VehicleCode5"] = ModbusClient.ConvertRegistersToString(d5VehicleCode5Data, 0, 40);
  7049. // int[] d5VehicleCode6Data = datas.Skip(712).Take(20).ToArray();
  7050. // s4PLCData["d5VehicleCode6"] = ModbusClient.ConvertRegistersToString(d5VehicleCode6Data, 0, 40);
  7051. // int[] d5VehicleCode7Data = datas.Skip(732).Take(20).ToArray();
  7052. // s4PLCData["d5VehicleCode7"] = ModbusClient.ConvertRegistersToString(d5VehicleCode7Data, 0, 40);
  7053. // int[] d5VehicleCode8Data = datas.Skip(752).Take(20).ToArray();
  7054. // s4PLCData["d5VehicleCode8"] = ModbusClient.ConvertRegistersToString(d5VehicleCode8Data, 0, 40);
  7055. // int[] d5VehicleCode9Data = datas.Skip(772).Take(20).ToArray();
  7056. // s4PLCData["d5VehicleCode9"] = ModbusClient.ConvertRegistersToString(d5VehicleCode9Data, 0, 40);
  7057. // int[] d5VehicleCode10Data = datas.Skip(792).Take(20).ToArray();
  7058. // s4PLCData["d5VehicleCode10"] = ModbusClient.ConvertRegistersToString(d5VehicleCode10Data, 0, 40);
  7059. // int[] d5VehicleCode11Data = datas.Skip(812).Take(20).ToArray();
  7060. // s4PLCData["d5VehicleCode11"] = ModbusClient.ConvertRegistersToString(d5VehicleCode11Data, 0, 40);
  7061. // int[] d5VehicleCode12Data = datas.Skip(832).Take(20).ToArray();
  7062. // s4PLCData["d5VehicleCode12"] = ModbusClient.ConvertRegistersToString(d5VehicleCode12Data, 0, 40);
  7063. // int[] d5VehicleCode13Data = datas.Skip(852).Take(20).ToArray();
  7064. // s4PLCData["d5VehicleCode13"] = ModbusClient.ConvertRegistersToString(d5VehicleCode13Data, 0, 40);
  7065. // int[] d5VehicleCode14Data = datas.Skip(872).Take(20).ToArray();
  7066. // s4PLCData["d5VehicleCode14"] = ModbusClient.ConvertRegistersToString(d5VehicleCode14Data, 0, 40);
  7067. // int[] d5VehicleCode15Data = datas.Skip(892).Take(20).ToArray();
  7068. // s4PLCData["d5VehicleCode15"] = ModbusClient.ConvertRegistersToString(d5VehicleCode15Data, 0, 40);
  7069. // s4PLCData["d5Result"] = datas[912];
  7070. // s4PLCData["d5OEEPLC_FLAG"] = datas[923]; // PLC_FLAG 节拍接口
  7071. // s4PLCData["d5OEEMES_FLAG"] = datas[924];
  7072. // int[] d5OEEProductSNData = datas.Skip(925).Take(20).ToArray();
  7073. // s4PLCData["d5OEEProductSN"] = ModbusClient.ConvertRegistersToString(d5OEEProductSNData, 0, 40);
  7074. // s4PLCData["d5OEEType"] = datas[945];
  7075. // #endregion 一次性读取所有数据
  7076. // stopwatch2.Stop();
  7077. // #region 回写操作,写后清空flag
  7078. // PLCWriteData(Funs[plcNo], ref s4PLCData, ref s4PLCWriteData);
  7079. // #endregion 回写操作,写后清空flag
  7080. // // N801A-S4_1 弹夹扫码
  7081. // #region N801A-S4_1 弹夹扫码
  7082. // try
  7083. // {
  7084. // int d1BulletclipScanCode = (int)s4PLCData["d1BulletclipScanCode"];
  7085. // int d1BulletclipScanCodeOld = (int)s4PLCSignal_Old["d1BulletclipScanCode"];
  7086. // if (d1BulletclipScanCode != d1BulletclipScanCodeOld)
  7087. // {
  7088. // if (d1BulletclipScanCode == 1) // 0->1
  7089. // Task.Run(() => S4_1弹夹扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  7090. // s4PLCSignal_Old["d1BulletclipScanCode"] = s4PLCData["d1BulletclipScanCode"];
  7091. // }
  7092. // }
  7093. // catch (Exception ex)
  7094. // {
  7095. // Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  7096. // string str = ex.StackTrace;
  7097. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7098. // }
  7099. // #endregion N801A-S4_1 弹夹扫码
  7100. // // N801A-S4_1 载具扫码
  7101. // #region N801A-S4_1 载具扫码
  7102. // try
  7103. // {
  7104. // int d1VehicleScanCode = (int)s4PLCData["d1VehicleScanCode"];
  7105. // int d1VehicleScanCodeOld = (int)s4PLCSignal_Old["d1VehicleScanCode"];
  7106. // if (d1VehicleScanCode != d1VehicleScanCodeOld)
  7107. // {
  7108. // if (d1VehicleScanCode == 1) // 0->1
  7109. // Task.Run(() => S4_1载具扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  7110. // s4PLCSignal_Old["d1VehicleScanCode"] = s4PLCData["d1VehicleScanCode"];
  7111. // }
  7112. // }
  7113. // catch (Exception ex)
  7114. // {
  7115. // Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  7116. // string str = ex.StackTrace;
  7117. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7118. // }
  7119. // #endregion N801A-S4_1 载具扫码
  7120. // // N801A-S4_1 出站接口
  7121. // #region N801A-S4_1 出站接口
  7122. // try
  7123. // {
  7124. // int d1PLC_FLAG = (int)s4PLCData["d1PLC_FLAG"];
  7125. // int d1MES_FLAG = (int)s4PLCData["d1MES_FLAG"];
  7126. // int d1PLC_FLAGOld = (int)s4PLCSignal_Old["d1PLC_FLAG"];
  7127. // if (d1PLC_FLAG != d1PLC_FLAGOld)
  7128. // {
  7129. // if (d1PLC_FLAG == 1 && d1MES_FLAG == 0) // 0->1
  7130. // Task.Run(() => S4_1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  7131. // else if (d1PLC_FLAG == 0 && d1MES_FLAG != 0)
  7132. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)0);
  7133. // s4PLCSignal_Old["d1PLC_FLAG"] = s4PLCData["d1PLC_FLAG"];
  7134. // }
  7135. // }
  7136. // catch (Exception ex)
  7137. // {
  7138. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)6); // 6代表上位机报警
  7139. // string str = ex.StackTrace;
  7140. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7141. // }
  7142. // #endregion N801A-S4_1 出站接口
  7143. // // N801A-S4_1 节拍接口
  7144. // #region N801A-S4_1 节拍接口
  7145. // try
  7146. // {
  7147. // int d1OEEPLC_FLAG = (int)s4PLCData["d1OEEPLC_FLAG"];
  7148. // int d1OEEMES_FLAG = (int)s4PLCData["d1OEEMES_FLAG"];
  7149. // int d1OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d1OEEPLC_FLAG"];
  7150. // if (d1OEEPLC_FLAG != d1OEEPLC_FLAGOld)
  7151. // {
  7152. // if (d1OEEPLC_FLAG == 1 && d1OEEMES_FLAG == 0) // 0->1
  7153. // Task.Run(() => S4_1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  7154. // else if (d1OEEPLC_FLAG == 0 && d1OEEMES_FLAG != 0)
  7155. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)0);
  7156. // s4PLCSignal_Old["d1OEEPLC_FLAG"] = s4PLCData["d1OEEPLC_FLAG"];
  7157. // }
  7158. // }
  7159. // catch (Exception ex)
  7160. // {
  7161. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  7162. // string str = ex.StackTrace;
  7163. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7164. // }
  7165. // #endregion N801A-S4_1 节拍接口
  7166. // // N801A-S4_2 桁架(查询标机中弹夹的状态) 数据
  7167. // #region N801A-S4_2 桁架(查询标机中弹夹的状态)
  7168. // try
  7169. // {
  7170. // int d2BulletclipScanCode = (int)s4PLCData["d2BulletclipScanCode"];
  7171. // int d2BulletclipScanCodeOld = (int)s4PLCSignal_Old["d2BulletclipScanCode"];
  7172. // if (d2BulletclipScanCode != d2BulletclipScanCodeOld)
  7173. // {
  7174. // if (d2BulletclipScanCode == 1) // 0->1
  7175. // Task.Run(() => S4_2桁架(plcNo, stationNameStr2)); // MreTasks[1].Set();
  7176. // s4PLCSignal_Old["d2BulletclipScanCode"] = s4PLCData["d2BulletclipScanCode"];
  7177. // }
  7178. // }
  7179. // catch (Exception ex)
  7180. // {
  7181. // Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  7182. // string str = ex.StackTrace;
  7183. // AddMessage_Station(stationNameStr2, LogType.Error, $"PLC{plcNo}_{stationNameStr2} 桁架出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7184. // }
  7185. // #endregion N801A-S4_2 桁架(查询标机中弹夹的状态)
  7186. // // N801A-S4_3 真空标机1 数据
  7187. // #region N801A-S4_3 真空标机1
  7188. // try
  7189. // {
  7190. // int d3PLC_FLAG = (int)s4PLCData["d3PLC_FLAG"];
  7191. // int d3MES_FLAG = (int)s4PLCData["d3MES_FLAG"];
  7192. // int d3PLC_FLAGOld = (int)s4PLCSignal_Old["d3PLC_FLAG"];
  7193. // if (d3PLC_FLAG != d3PLC_FLAGOld)
  7194. // {
  7195. // if (d3PLC_FLAG == 1 && d3MES_FLAG == 0) // 0->1
  7196. // {
  7197. // int stationType = (int)s4PLCData["d3Type"];
  7198. // if (stationType == 1)
  7199. // {
  7200. // // S4_3进站接口
  7201. // Task.Run(() => S4_3进站接口(plcNo, stationNameStr3)); // MreTasks[3].Set();
  7202. // }
  7203. // else if (stationType == 2)
  7204. // {
  7205. // // S4_3出站接口
  7206. // Task.Run(() => S4_3出站接口(plcNo, stationCode3, stationName3)); // MreTasks[3].Set();
  7207. // }
  7208. // }
  7209. // else if (d3PLC_FLAG == 0 && d3MES_FLAG != 0)
  7210. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)0);
  7211. // s4PLCSignal_Old["d3PLC_FLAG"] = s4PLCData["d3PLC_FLAG"];
  7212. // }
  7213. // }
  7214. // catch (Exception ex)
  7215. // {
  7216. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  7217. // string str = ex.StackTrace;
  7218. // AddMessage_Station(stationNameStr3, LogType.Error, $"PLC{plcNo}_{stationNameStr3} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7219. // }
  7220. // #endregion N801A-S4_3 真空标机1
  7221. // // N801A-S4_4 真空标机2 数据
  7222. // #region N801A-S4_4 真空标机2
  7223. // try
  7224. // {
  7225. // int d4PLC_FLAG = (int)s4PLCData["d4PLC_FLAG"];
  7226. // int d4MES_FLAG = (int)s4PLCData["d4MES_FLAG"];
  7227. // int d4PLC_FLAGOld = (int)s4PLCSignal_Old["d4PLC_FLAG"];
  7228. // if (d4PLC_FLAG != d4PLC_FLAGOld)
  7229. // {
  7230. // if (d4PLC_FLAG == 1 && d4MES_FLAG == 0) // 0->1
  7231. // {
  7232. // int stationType = (int)s4PLCData["d4Type"];
  7233. // if (stationType == 1)
  7234. // {
  7235. // // S4_4进站接口
  7236. // Task.Run(() => S4_4进站接口(plcNo, stationNameStr4)); // MreTasks[3].Set();
  7237. // }
  7238. // else if (stationType == 2)
  7239. // {
  7240. // // S4_4出站接口
  7241. // Task.Run(() => S4_4出站接口(plcNo, stationCode4, stationName4)); // MreTasks[3].Set();
  7242. // }
  7243. // }
  7244. // else if (d4PLC_FLAG == 0 && d4MES_FLAG != 0)
  7245. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)0);
  7246. // s4PLCSignal_Old["d4PLC_FLAG"] = s4PLCData["d4PLC_FLAG"];
  7247. // }
  7248. // }
  7249. // catch (Exception ex)
  7250. // {
  7251. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  7252. // string str = ex.StackTrace;
  7253. // AddMessage_Station(stationNameStr4, LogType.Error, $"PLC{plcNo}_{stationNameStr4} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7254. // }
  7255. // #endregion N801A-S4_4 真空标机2
  7256. // // N801A-S4_5 弹夹扫码 数据
  7257. // #region N801A-S4_5 弹夹扫码
  7258. // try
  7259. // {
  7260. // int d5BulletclipScanCode = (int)s4PLCData["d5BulletclipScanCode"];
  7261. // int d5BulletclipScanCodeOld = (int)s4PLCSignal_Old["d5BulletclipScanCode"];
  7262. // if (d5BulletclipScanCode != d5BulletclipScanCodeOld)
  7263. // {
  7264. // if (d5BulletclipScanCode == 1) // 0->1
  7265. // Task.Run(() => S4_5弹夹扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  7266. // s4PLCSignal_Old["d5BulletclipScanCode"] = s4PLCData["d5BulletclipScanCode"];
  7267. // }
  7268. // }
  7269. // catch (Exception ex)
  7270. // {
  7271. // Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  7272. // string str = ex.StackTrace;
  7273. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7274. // }
  7275. // #endregion N801A-S4_5 弹夹扫码
  7276. // // N801A-S4_5 载具扫码 数据
  7277. // #region N801A-S4_5 载具扫码
  7278. // try
  7279. // {
  7280. // int d5VehicleScanCode = (int)s4PLCData["d5VehicleScanCode"];
  7281. // int d5VehicleScanCodeOld = (int)s4PLCSignal_Old["d5VehicleScanCode"];
  7282. // if (d5VehicleScanCode != d5VehicleScanCodeOld)
  7283. // {
  7284. // if (d5VehicleScanCode == 1) // 0->1
  7285. // Task.Run(() => S4_5载具扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  7286. // s4PLCSignal_Old["d5VehicleScanCode"] = s4PLCData["d5VehicleScanCode"];
  7287. // }
  7288. // }
  7289. // catch (Exception ex)
  7290. // {
  7291. // Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  7292. // string str = ex.StackTrace;
  7293. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7294. // }
  7295. // #endregion N801A-S4_5 载具扫码
  7296. // // N801A-S4_5 出站接口(扫完所有码后立即上传) 数据
  7297. // #region N801A-S4_5 出站接口
  7298. // try
  7299. // {
  7300. // int d5PLC_FLAG = (int)s4PLCData["d5PLC_FLAG"];
  7301. // int d5MES_FLAG = (int)s4PLCData["d5MES_FLAG"];
  7302. // int d5PLC_FLAGOld = (int)s4PLCSignal_Old["d5PLC_FLAG"];
  7303. // if (d5PLC_FLAG != d5PLC_FLAGOld)
  7304. // {
  7305. // if (d5PLC_FLAG == 1 && d5MES_FLAG == 0) // 0->1
  7306. // Task.Run(() => S4_5出站接口(plcNo, stationCode5, stationName5)); // MreTasks[3].Set();
  7307. // else if (d5PLC_FLAG == 0 && d5MES_FLAG != 0)
  7308. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)0);
  7309. // s4PLCSignal_Old["d5PLC_FLAG"] = s4PLCData["d5PLC_FLAG"];
  7310. // }
  7311. // }
  7312. // catch (Exception ex)
  7313. // {
  7314. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)6); // 6代表上位机报警
  7315. // string str = ex.StackTrace;
  7316. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7317. // }
  7318. // #endregion N801A-S4_5 出站接口
  7319. // // N801A-S4_5 节拍接口 数据
  7320. // #region N801A-S4_5 节拍接口
  7321. // try
  7322. // {
  7323. // int d5OEEPLC_FLAG = (int)s4PLCData["d5OEEPLC_FLAG"];
  7324. // int d5OEEMES_FLAG = (int)s4PLCData["d5OEEMES_FLAG"];
  7325. // int d5OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d5OEEPLC_FLAG"];
  7326. // if (d5OEEPLC_FLAG != d5OEEPLC_FLAGOld)
  7327. // {
  7328. // if (d5OEEPLC_FLAG == 1 && d5OEEMES_FLAG == 0) // 0->1
  7329. // Task.Run(() => S4_5节拍接口(plcNo, stationNameStr5)); // MreTasks[4].Set();
  7330. // else if (d5OEEPLC_FLAG == 0 && d5OEEMES_FLAG != 0)
  7331. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)0);
  7332. // s4PLCSignal_Old["d5OEEPLC_FLAG"] = s4PLCData["d5OEEPLC_FLAG"];
  7333. // }
  7334. // }
  7335. // catch (Exception ex)
  7336. // {
  7337. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  7338. // string str = ex.StackTrace;
  7339. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7340. // }
  7341. // #endregion N801A-S4_5 节拍接口
  7342. // #region 心跳
  7343. // try
  7344. // {
  7345. // short states = 0;
  7346. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  7347. // }
  7348. // catch (Exception ex)
  7349. // {
  7350. // string str = ex.StackTrace;
  7351. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7352. // }
  7353. // #endregion 心跳
  7354. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  7355. // stopwatch1.Stop();
  7356. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  7357. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  7358. // }
  7359. // else
  7360. // {
  7361. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7362. // AddMessage_Station(stationNameStr5, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr5 + "连接失败!");
  7363. // Funs[plcNo].Connect();
  7364. // }
  7365. // }
  7366. // catch (Exception ex)
  7367. // {
  7368. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7369. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5}运行出错!错误信息:" + ex.Message.ToString());
  7370. // Funs[plcNo].ReConnect();
  7371. // }
  7372. // Thread.Sleep(IntervalReadPLC);
  7373. // }
  7374. //}
  7375. /// <summary>
  7376. /// [S4] 取放桁架 - S4_1弹夹扫码
  7377. /// </summary>
  7378. /// <param name="plcNo">PLC编号</param>
  7379. /// <param name="stationNameStr">工站全称</param>
  7380. private void S4_1弹夹扫码(int plcNo, string stationNameStr)
  7381. {
  7382. Stopwatch stopwatch1 = new Stopwatch();
  7383. Stopwatch stopwatch2 = new Stopwatch();
  7384. try
  7385. {
  7386. stopwatch1.Start();
  7387. // ZS 弹夹扫码
  7388. string d1BulletclipCode = " "; // 扫到的码
  7389. short d1BulletclipScanCode = 2;
  7390. stopwatch2.Start();
  7391. //Funs[plcNo].WriteMultipleRegisters<string>(2003, d1BulletclipCode, 20);
  7392. //// MES_Flag
  7393. //Funs[plcNo].WriteMultipleRegisters<short>(2002, d1BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7394. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7395. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  7396. writeToPLC_Flag.Adress = 2002;
  7397. writeToPLC_Flag.Value = d1BulletclipScanCode;
  7398. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7399. {
  7400. Name = "d1BulletclipCode",
  7401. Adress = 2003,
  7402. ValueType = PLCValueType.String,
  7403. ValueTypeStrLength = 20,
  7404. Value = d1BulletclipCode
  7405. });
  7406. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  7407. stopwatch2.Stop();
  7408. }
  7409. catch (Exception ex)
  7410. {
  7411. string str = ex.StackTrace;
  7412. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7413. stopwatch2.Start();
  7414. //Funs[plcNo].WriteMultipleRegisters<string>(2003, " ", 20);
  7415. //// MES_Flag
  7416. //Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  7417. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7418. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  7419. writeToPLC_Flag.Adress = 2002;
  7420. writeToPLC_Flag.Value = (short)6;
  7421. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7422. {
  7423. Name = "d1BulletclipCode",
  7424. Adress = 2003,
  7425. ValueType = PLCValueType.String,
  7426. ValueTypeStrLength = 20,
  7427. Value = " "
  7428. });
  7429. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  7430. stopwatch2.Stop();
  7431. }
  7432. stopwatch1.Stop();
  7433. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7434. }
  7435. /// <summary>
  7436. /// [S4] 取放桁架 - S4_1载具扫码
  7437. /// </summary>
  7438. /// <param name="plcNo">PLC编号</param>
  7439. /// <param name="stationNameStr">工站全称</param>
  7440. private void S4_1载具扫码(int plcNo, string stationNameStr)
  7441. {
  7442. Stopwatch stopwatch1 = new Stopwatch();
  7443. Stopwatch stopwatch2 = new Stopwatch();
  7444. try
  7445. {
  7446. stopwatch1.Start();
  7447. // ZS 载具扫码
  7448. string d1VehicleCode = ""; // 扫到的码
  7449. short d1VehicleScanCode = 2;
  7450. #region 进站
  7451. if (d1VehicleScanCode == 2 && !string.IsNullOrEmpty(d1VehicleCode))
  7452. {
  7453. #region 查询载具上的产品信息
  7454. string cavityData = string.Empty;
  7455. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d1VehicleCode, ref cavityData);
  7456. if (string.IsNullOrEmpty(cavityData))
  7457. cavityData = "";
  7458. if (snResult != 0)
  7459. {
  7460. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7461. writeToPLC_Flag1.Name = "d1VehicleScanCode";
  7462. writeToPLC_Flag1.Adress = 2033;
  7463. writeToPLC_Flag1.Value = (short)6; // 6代表上位机报警
  7464. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7465. {
  7466. Name = "d1VehicleCode",
  7467. Adress = 2034,
  7468. ValueType = PLCValueType.String,
  7469. ValueTypeStrLength = 20,
  7470. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  7471. });
  7472. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag1);
  7473. stopwatch1.Stop();
  7474. AddMessage(LogType.Info, stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7475. return;
  7476. }
  7477. string[] cavitySNs = cavityData.Split('.');
  7478. string partNo = "";
  7479. if (cavitySNs != null && cavitySNs.Length >= 1)
  7480. {
  7481. partNo = cavitySNs[0];
  7482. }
  7483. #endregion 查询载具上的产品信息
  7484. List<TestItem> item = new List<TestItem>();
  7485. item.Add(new TestItem()
  7486. {
  7487. Parameter_name = "载具码",
  7488. Parameter_value = d1VehicleCode,
  7489. });
  7490. item.Add(new TestItem()
  7491. {
  7492. Parameter_name = "载具穴号",
  7493. Parameter_value = "1",
  7494. });
  7495. stopwatch2.Start();
  7496. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  7497. stopwatch2.Stop();
  7498. d1VehicleScanCode = (short)result == 1 ? d1VehicleScanCode : (short)result;
  7499. }
  7500. #endregion 进站
  7501. //Funs[plcNo].WriteMultipleRegisters<string>(2034, d1VehicleCode, 20);
  7502. //// MES_Flag
  7503. //Funs[plcNo].WriteMultipleRegisters<short>(2033, d1VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7504. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7505. writeToPLC_Flag.Name = "d1VehicleScanCode";
  7506. writeToPLC_Flag.Adress = 2033;
  7507. writeToPLC_Flag.Value = d1VehicleScanCode;
  7508. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7509. {
  7510. Name = "d1VehicleCode",
  7511. Adress = 2034,
  7512. ValueType = PLCValueType.String,
  7513. ValueTypeStrLength = 20,
  7514. Value = d1VehicleCode
  7515. });
  7516. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  7517. }
  7518. catch (Exception ex)
  7519. {
  7520. string str = ex.StackTrace;
  7521. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7522. stopwatch2.Start();
  7523. //Funs[plcNo].WriteMultipleRegisters<string>(2034, " ", 20);
  7524. //// MES_Flag
  7525. //Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  7526. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7527. writeToPLC_Flag.Name = "d1VehicleScanCode";
  7528. writeToPLC_Flag.Adress = 2033;
  7529. writeToPLC_Flag.Value = (short)6; // 6代表上位机报警
  7530. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7531. {
  7532. Name = "d1VehicleCode",
  7533. Adress = 2034,
  7534. ValueType = PLCValueType.String,
  7535. ValueTypeStrLength = 20,
  7536. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  7537. });
  7538. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  7539. stopwatch2.Stop();
  7540. }
  7541. stopwatch1.Stop();
  7542. AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7543. }
  7544. // 上次采集到的SN
  7545. //private string sn_S4_1出站接口 = string.Empty;
  7546. /// <summary>
  7547. /// [S4] 取放桁架 - S4_1出站接口
  7548. /// </summary>
  7549. private void S4_1出站接口(int plcNo, string stationCode, string stationName)
  7550. {
  7551. Stopwatch stopwatch1 = new Stopwatch();
  7552. Stopwatch stopwatch2 = new Stopwatch();
  7553. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7554. string stationNameStr = stationCode + stationName;
  7555. string processItem = stationName; // 测试项目
  7556. try
  7557. {
  7558. stopwatch1.Start();
  7559. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7560. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7561. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7562. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7563. string sn = (string)s4PLCData["d1ProductSN"]; // 产品SN(弹夹码)
  7564. sn = sn.Replace("\0", "");
  7565. string d1VehicleCode1 = (string)s4PLCData["d1VehicleCode1"]; // 载具1码(弹夹穴位1)
  7566. d1VehicleCode1 = d1VehicleCode1.Replace("\0", "");
  7567. string d1VehicleCode2 = (string)s4PLCData["d1VehicleCode2"]; // 载具2码(弹夹穴位2)
  7568. d1VehicleCode2 = d1VehicleCode2.Replace("\0", "");
  7569. string d1VehicleCode3 = (string)s4PLCData["d1VehicleCode3"]; // 载具3码(弹夹穴位3)
  7570. d1VehicleCode3 = d1VehicleCode3.Replace("\0", "");
  7571. string d1VehicleCode4 = (string)s4PLCData["d1VehicleCode4"]; // 载具4码(弹夹穴位4)
  7572. d1VehicleCode4 = d1VehicleCode4.Replace("\0", "");
  7573. string d1VehicleCode5 = (string)s4PLCData["d1VehicleCode5"]; // 载具5码(弹夹穴位5)
  7574. d1VehicleCode5 = d1VehicleCode5.Replace("\0", "");
  7575. string d1VehicleCode6 = (string)s4PLCData["d1VehicleCode6"]; // 载具6码(弹夹穴位6)
  7576. d1VehicleCode6 = d1VehicleCode6.Replace("\0", "");
  7577. string d1VehicleCode7 = (string)s4PLCData["d1VehicleCode7"]; // 载具7码(弹夹穴位7)
  7578. d1VehicleCode7 = d1VehicleCode7.Replace("\0", "");
  7579. string d1VehicleCode8 = (string)s4PLCData["d1VehicleCode8"]; // 载具8码(弹夹穴位8)
  7580. d1VehicleCode8 = d1VehicleCode8.Replace("\0", "");
  7581. string d1VehicleCode9 = (string)s4PLCData["d1VehicleCode9"]; // 载具9码(弹夹穴位9)
  7582. d1VehicleCode9 = d1VehicleCode9.Replace("\0", "");
  7583. string d1VehicleCode10 = (string)s4PLCData["d1VehicleCode10"]; // 载具10码(弹夹穴位10)
  7584. d1VehicleCode10 = d1VehicleCode10.Replace("\0", "");
  7585. string d1VehicleCode11 = (string)s4PLCData["d1VehicleCode11"]; // 载具11码(弹夹穴位11)
  7586. d1VehicleCode11 = d1VehicleCode11.Replace("\0", "");
  7587. string d1VehicleCode12 = (string)s4PLCData["d1VehicleCode12"]; // 载具12码(弹夹穴位12)
  7588. d1VehicleCode12 = d1VehicleCode12.Replace("\0", "");
  7589. string d1VehicleCode13 = (string)s4PLCData["d1VehicleCode13"]; // 载具13码(弹夹穴位13)
  7590. d1VehicleCode13 = d1VehicleCode13.Replace("\0", "");
  7591. string d1VehicleCode14 = (string)s4PLCData["d1VehicleCode14"]; // 载具14码(弹夹穴位14)
  7592. d1VehicleCode14 = d1VehicleCode14.Replace("\0", "");
  7593. string d1VehicleCode15 = (string)s4PLCData["d1VehicleCode15"]; // 载具15码(弹夹穴位15)
  7594. d1VehicleCode15 = d1VehicleCode15.Replace("\0", "");
  7595. int d1Result = (int)s4PLCData["d1Result"]; // 产品结果
  7596. bool pass = d1Result == 1;
  7597. // 存 载具SN列表
  7598. List<string> vehicleCodes = new List<string>()
  7599. {
  7600. d1VehicleCode1,d1VehicleCode2,d1VehicleCode3,d1VehicleCode4,d1VehicleCode5,
  7601. d1VehicleCode6,d1VehicleCode7,d1VehicleCode8,d1VehicleCode9,d1VehicleCode10,
  7602. d1VehicleCode11,d1VehicleCode12,d1VehicleCode13,d1VehicleCode14,d1VehicleCode15
  7603. };
  7604. // 统一查 产品SN列表
  7605. List<string> partNos = new List<string>();
  7606. foreach (string vehicleCode in vehicleCodes)
  7607. {
  7608. if (string.IsNullOrEmpty(vehicleCode))
  7609. partNos.Add("");
  7610. else
  7611. {
  7612. string partNo = "";
  7613. #region 查询载具上的产品信息
  7614. string cavityData = string.Empty;
  7615. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7616. if (string.IsNullOrEmpty(cavityData))
  7617. cavityData = "";
  7618. if (snResult != 0)
  7619. {
  7620. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7621. writeToPLC_Flag1.Name = "d1MES_FLAG";
  7622. writeToPLC_Flag1.Adress = 2065;
  7623. writeToPLC_Flag1.Value = (short)4;
  7624. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag1);
  7625. stopwatch1.Stop();
  7626. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7627. return;
  7628. }
  7629. string[] cavitySNs = cavityData.Split('.');
  7630. if (cavitySNs != null && cavitySNs.Length >= 1)
  7631. partNo = cavitySNs[0];
  7632. #endregion 查询载具上的产品信息
  7633. partNos.Add(partNo);
  7634. }
  7635. }
  7636. // 统一上传
  7637. stopwatch2.Start();
  7638. List<int> results = new List<int>();
  7639. for (int i = 0; i < partNos.Count; i++)
  7640. {
  7641. string index = (i + 1).ToString(); // 弹夹穴号
  7642. if (string.IsNullOrEmpty(partNos[i]))
  7643. results.Add(1);
  7644. else
  7645. {
  7646. List<TestItem> items1 = new List<TestItem>();
  7647. items1.Add(new TestItem()
  7648. {
  7649. Parameter_name = "弹夹码",
  7650. Parameter_value = sn,
  7651. Parameter_unit = ""
  7652. });
  7653. items1.Add(new TestItem()
  7654. {
  7655. Parameter_name = "弹夹穴号",
  7656. Parameter_value = index,
  7657. Parameter_unit = ""
  7658. });
  7659. items1.Add(new TestItem()
  7660. {
  7661. Parameter_name = "载具码",
  7662. Parameter_value = vehicleCodes[i],
  7663. Parameter_unit = ""
  7664. });
  7665. items1.Add(new TestItem()
  7666. {
  7667. Parameter_name = "载具穴号",
  7668. Parameter_value = "1",
  7669. Parameter_unit = ""
  7670. });
  7671. items1.Add(new TestItem()
  7672. {
  7673. Parameter_name = "产品结果",
  7674. Parameter_value = d1Result == 1 ? "OK" : "NG",
  7675. Parameter_unit = ""
  7676. });
  7677. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  7678. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  7679. results.Add(result1);
  7680. }
  7681. }
  7682. short result = 0;
  7683. if (results.All(a => a == 1))
  7684. result = 1;
  7685. else if (results.Contains(3))
  7686. result = 3;
  7687. else if (results.Contains(2))
  7688. result = 2;
  7689. else if (results.Contains(4))
  7690. result = 4;
  7691. else
  7692. result = 4;
  7693. stopwatch2.Stop();
  7694. #region 存储绑定数据到 边线MES系统中
  7695. if (result == 1)
  7696. {
  7697. string data = string.Join(".", vehicleCodes);
  7698. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  7699. if (resultMesR != 0)
  7700. {
  7701. result = 4;
  7702. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  7703. }
  7704. }
  7705. #endregion 存储绑定数据到 边线MES系统中
  7706. // MES_Flag 为4MES报错
  7707. //Funs[plcNo].WriteMultipleRegisters<short>(2065, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7708. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7709. writeToPLC_Flag.Name = "d1MES_FLAG";
  7710. writeToPLC_Flag.Adress = 2065;
  7711. writeToPLC_Flag.Value = result;
  7712. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  7713. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  7714. }
  7715. catch (Exception ex)
  7716. {
  7717. stopwatch2.Restart();
  7718. // MES_Flag 为4上位机报错
  7719. //Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)4); // 4代表上位机报警
  7720. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7721. writeToPLC_Flag.Name = "d1MES_FLAG";
  7722. writeToPLC_Flag.Adress = 2065;
  7723. writeToPLC_Flag.Value = (short)4;
  7724. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  7725. stopwatch2.Stop();
  7726. string str = ex.StackTrace;
  7727. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7728. }
  7729. stopwatch1.Stop();
  7730. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7731. }
  7732. /// <summary>
  7733. /// [S4] 取放桁架 - S4_1节拍接口
  7734. /// </summary>
  7735. /// <param name="plcNo">PLC编号</param>
  7736. /// <param name="stationNameStr">工站全称</param>
  7737. private void S4_1节拍接口(int plcNo, string stationNameStr)
  7738. {
  7739. Stopwatch stopwatch1 = new Stopwatch();
  7740. Stopwatch stopwatch2 = new Stopwatch();
  7741. string resultStr = string.Empty;
  7742. try
  7743. {
  7744. stopwatch1.Start();
  7745. string oEEType = ((int)s4PLCData["d1OEEType"]).ToString(); // 节拍类型(plc写入)
  7746. string d1OEEProductSN = (string)s4PLCData["d1OEEProductSN"]; // 载具SN
  7747. d1OEEProductSN = d1OEEProductSN.Replace("\0", "");
  7748. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  7749. if (!actionBool)
  7750. {
  7751. stopwatch2.Start();
  7752. // MES_Flag
  7753. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7754. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7755. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  7756. writeToPLC_Flag1.Adress = 2398;
  7757. writeToPLC_Flag1.Value = (short)4;
  7758. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  7759. stopwatch2.Stop();
  7760. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7761. return;
  7762. }
  7763. string d1OEEPartNo = string.Empty; // 物料码
  7764. if (string.IsNullOrEmpty(d1OEEProductSN))
  7765. {
  7766. stopwatch2.Start();
  7767. // MES_Flag
  7768. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7769. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7770. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  7771. writeToPLC_Flag1.Adress = 2398;
  7772. writeToPLC_Flag1.Value = (short)1;
  7773. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  7774. stopwatch2.Stop();
  7775. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7776. return;
  7777. }
  7778. else
  7779. { // 查产品SN ZS
  7780. d1OEEPartNo = "Test";
  7781. }
  7782. short d1OEEMES_FLAG = 0;
  7783. // 上传OEE
  7784. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d1OEEPartNo, d1OEEProductSN);
  7785. d1OEEMES_FLAG = result.Item1;
  7786. resultStr = result.Item2;
  7787. stopwatch2.Start();
  7788. // MES_Flag
  7789. //Funs[plcNo].WriteMultipleRegisters<short>(2398, d1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7790. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7791. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  7792. writeToPLC_Flag.Adress = 2398;
  7793. writeToPLC_Flag.Value = d1OEEMES_FLAG;
  7794. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  7795. stopwatch2.Stop();
  7796. }
  7797. catch (Exception ex)
  7798. {
  7799. string str = ex.StackTrace;
  7800. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7801. // MES_Flag
  7802. stopwatch2.Start();
  7803. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  7804. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7805. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  7806. writeToPLC_Flag.Adress = 2398;
  7807. writeToPLC_Flag.Value = (short)4;
  7808. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  7809. stopwatch2.Stop();
  7810. }
  7811. stopwatch1.Stop();
  7812. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7813. }
  7814. /// <summary>
  7815. /// [S4] 取放桁架 - S4_2桁架
  7816. /// </summary>
  7817. /// <param name="plcNo">PLC编号</param>
  7818. /// <param name="stationNameStr">工站全称</param>
  7819. private void S4_2桁架(int plcNo, string stationNameStr)
  7820. {
  7821. Stopwatch stopwatch1 = new Stopwatch();
  7822. Stopwatch stopwatch2 = new Stopwatch();
  7823. try
  7824. {
  7825. stopwatch1.Start();
  7826. // ZS 弹夹扫码
  7827. string d2BulletclipCode = " "; // 扫到的码
  7828. short d2BulletclipStates = 1; // 弹夹状态(上位机写入)
  7829. short d2BulletclipScanCode = 2;
  7830. stopwatch2.Start();
  7831. //Funs[plcNo].WriteMultipleRegisters<string>(2432, d2BulletclipCode, 20); // 扫到的码
  7832. //Funs[plcNo].WriteMultipleRegisters<short>(2431, d2BulletclipStates); // 弹夹状态(上位机写入)
  7833. //// MES_Flag
  7834. //Funs[plcNo].WriteMultipleRegisters<short>(2430, d2BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7835. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7836. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  7837. writeToPLC_Flag.Adress = 2430;
  7838. writeToPLC_Flag.Value = d2BulletclipScanCode;
  7839. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7840. {
  7841. Name = "d2BulletclipCode",
  7842. Adress = 2432,
  7843. ValueType = PLCValueType.String,
  7844. ValueTypeStrLength = 20,
  7845. Value = d2BulletclipCode
  7846. });
  7847. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7848. {
  7849. Name = "d2BulletclipStates",
  7850. Adress = 2431,
  7851. ValueType = PLCValueType.Short,
  7852. Value = d2BulletclipStates
  7853. });
  7854. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  7855. stopwatch2.Stop();
  7856. }
  7857. catch (Exception ex)
  7858. {
  7859. string str = ex.StackTrace;
  7860. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7861. stopwatch2.Start();
  7862. Funs[plcNo].WriteMultipleRegisters<string>(2432, " ", 20);
  7863. Funs[plcNo].WriteMultipleRegisters<short>(2431, (short)0);
  7864. // MES_Flag
  7865. Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  7866. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7867. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  7868. writeToPLC_Flag.Adress = 2430;
  7869. writeToPLC_Flag.Value = (short)6;
  7870. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7871. {
  7872. Name = "d2BulletclipCode",
  7873. Adress = 2432,
  7874. ValueType = PLCValueType.String,
  7875. ValueTypeStrLength = 20,
  7876. Value = " "
  7877. });
  7878. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7879. {
  7880. Name = "d2BulletclipStates",
  7881. Adress = 2431,
  7882. ValueType = PLCValueType.Short,
  7883. Value = (short)0
  7884. });
  7885. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  7886. stopwatch2.Stop();
  7887. }
  7888. stopwatch1.Stop();
  7889. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7890. }
  7891. // 上次采集到的SN
  7892. //private string sn_S4_3进站接口 = string.Empty;
  7893. /// <summary>
  7894. /// [S4] 取放桁架 - S4_3进站接口(提升机1)
  7895. /// </summary>
  7896. private void S4_3进站接口(int plcNo, string stationNameStr)
  7897. {
  7898. Stopwatch stopwatch1 = new Stopwatch();
  7899. Stopwatch stopwatch2 = new Stopwatch();
  7900. try
  7901. {
  7902. stopwatch1.Start();
  7903. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  7904. sn = sn.Replace("\0", "");
  7905. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  7906. #region 查询15个载具码
  7907. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7908. string vehicleData = string.Empty;
  7909. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7910. if (string.IsNullOrEmpty(vehicleData))
  7911. vehicleData = "";
  7912. if (snResult != 0)
  7913. {
  7914. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7915. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7916. writeToPLC_Flag1.Adress = 2463;
  7917. writeToPLC_Flag1.Value = (short)4;
  7918. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7919. stopwatch1.Stop();
  7920. AddMessage(LogType.Info, stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7921. return;
  7922. }
  7923. string[] cavitySNs = vehicleData.Split('.');
  7924. if (cavitySNs != null && cavitySNs.Length > 0)
  7925. {
  7926. for (int i = 0; i < cavitySNs.Length; i++)
  7927. {
  7928. if (string.IsNullOrEmpty(cavitySNs[i]))
  7929. vehicleCodes.Add("");
  7930. else
  7931. vehicleCodes.Add(cavitySNs[i]);
  7932. }
  7933. }
  7934. #endregion 查询15个载具码
  7935. #region 查询15个产品SN
  7936. List<string> portNos = new List<string>(); // 15个产品SN
  7937. foreach (string vehicleCode in vehicleCodes)
  7938. {
  7939. if (string.IsNullOrEmpty(vehicleCode))
  7940. portNos.Add("");
  7941. else
  7942. {
  7943. // 查询
  7944. string cavityData = string.Empty;
  7945. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7946. if (string.IsNullOrEmpty(cavityData))
  7947. cavityData = "";
  7948. if (snResult1 != 0)
  7949. {
  7950. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7951. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7952. writeToPLC_Flag1.Adress = 2463;
  7953. writeToPLC_Flag1.Value = (short)4;
  7954. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7955. stopwatch1.Stop();
  7956. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7957. return;
  7958. }
  7959. string[] partSNs = cavityData.Split('.');
  7960. if (partSNs != null && partSNs.Length >= 1)
  7961. portNos.Add(partSNs[0]);
  7962. else
  7963. portNos.Add("");
  7964. }
  7965. }
  7966. #endregion 查询15个产品SN
  7967. // 调用MES进站(最多15个)
  7968. stopwatch2.Start();
  7969. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  7970. for (int i = 0; i < vehicleCodes.Count; i++)
  7971. {
  7972. // 循环进站
  7973. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  7974. {
  7975. // 产品SN(物料码)校验
  7976. string portNo = portNos[i];
  7977. List<TestItem> item = new List<TestItem>();
  7978. item.Add(new TestItem()
  7979. {
  7980. Parameter_name = "弹夹码",
  7981. Parameter_value = sn,
  7982. });
  7983. item.Add(new TestItem()
  7984. {
  7985. Parameter_name = "弹夹穴位",
  7986. Parameter_value = (i + 1).ToString(),
  7987. });
  7988. item.Add(new TestItem()
  7989. {
  7990. Parameter_name = "载具码",
  7991. Parameter_value = vehicleCodes[i],
  7992. });
  7993. item.Add(new TestItem()
  7994. {
  7995. Parameter_name = "载具穴号",
  7996. Parameter_value = "1",
  7997. });
  7998. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  7999. }
  8000. }
  8001. stopwatch2.Stop();
  8002. short result = 0;
  8003. bool haveMesWarn = results.Contains(5);
  8004. bool havePCWarn = results.Contains(6);
  8005. if (haveMesWarn)
  8006. result = 2; // 5->2
  8007. else if (havePCWarn)
  8008. result = 6; // 6->4
  8009. else
  8010. result = 1;
  8011. // MES_Flag 为4MES报错
  8012. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8013. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8014. writeToPLC_Flag.Name = "d3MES_FLAG";
  8015. writeToPLC_Flag.Adress = 2463;
  8016. writeToPLC_Flag.Value = result;
  8017. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  8018. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8019. }
  8020. catch (Exception ex)
  8021. {
  8022. stopwatch2.Stop();
  8023. // MES_Flag 为4上位机报错
  8024. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  8025. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8026. writeToPLC_Flag.Name = "d3MES_FLAG";
  8027. writeToPLC_Flag.Adress = 2463;
  8028. writeToPLC_Flag.Value = (short)4;
  8029. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  8030. string str = ex.StackTrace;
  8031. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8032. }
  8033. stopwatch1.Stop();
  8034. AddMessage(LogType.Info, stationNameStr + "_S4_3进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8035. }
  8036. // 上次采集到的SN
  8037. //private string sn_S4_3出站接口 = string.Empty;
  8038. /// <summary>
  8039. /// [S4] 取放桁架 - S4_3出站接口(提升机1)
  8040. /// </summary>
  8041. private void S4_3出站接口(int plcNo, string stationCode, string stationName)
  8042. {
  8043. Stopwatch stopwatch1 = new Stopwatch();
  8044. Stopwatch stopwatch2 = new Stopwatch();
  8045. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8046. string stationNameStr = stationCode + stationName;
  8047. string processItem = stationName; // 测试项目
  8048. try
  8049. {
  8050. stopwatch1.Start();
  8051. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8052. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8053. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8054. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8055. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  8056. sn = sn.Replace("\0", "");
  8057. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  8058. bool isPass = d3Result == 1; // 产品结果 bool
  8059. #region 查询15个载具码
  8060. List<string> vehicleCodes = new List<string>(); // 15个载具码
  8061. string vehicleData = string.Empty;
  8062. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  8063. if (string.IsNullOrEmpty(vehicleData))
  8064. vehicleData = "";
  8065. if (snResult1 != 0)
  8066. {
  8067. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8068. writeToPLC_Flag1.Name = "d3MES_FLAG";
  8069. writeToPLC_Flag1.Adress = 2463;
  8070. writeToPLC_Flag1.Value = (short)4;
  8071. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  8072. stopwatch1.Stop();
  8073. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8074. return;
  8075. }
  8076. string[] cavitySNs = vehicleData.Split('.');
  8077. if (cavitySNs != null && cavitySNs.Length > 0)
  8078. {
  8079. for (int i = 0; i < cavitySNs.Length; i++)
  8080. {
  8081. if (string.IsNullOrEmpty(cavitySNs[i]))
  8082. vehicleCodes.Add("");
  8083. else
  8084. vehicleCodes.Add(cavitySNs[i]);
  8085. }
  8086. }
  8087. #endregion 查询15个载具码
  8088. // 统一查 产品SN列表
  8089. List<string> partNos = new List<string>();
  8090. foreach (string vehicleCode in vehicleCodes)
  8091. {
  8092. if (string.IsNullOrEmpty(vehicleCode))
  8093. partNos.Add("");
  8094. else
  8095. {
  8096. string partNo = "";
  8097. #region 查询载具上的产品信息
  8098. string cavityData = string.Empty;
  8099. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8100. if (string.IsNullOrEmpty(cavityData))
  8101. cavityData = "";
  8102. if (snResult != 0)
  8103. {
  8104. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8105. writeToPLC_Flag1.Name = "d3MES_FLAG";
  8106. writeToPLC_Flag1.Adress = 2463;
  8107. writeToPLC_Flag1.Value = (short)4;
  8108. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  8109. stopwatch1.Stop();
  8110. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8111. return;
  8112. }
  8113. string[] partSNs = cavityData.Split('.');
  8114. if (partSNs != null && partSNs.Length >= 1)
  8115. partNo = partSNs[0];
  8116. #endregion 查询载具上的产品信息
  8117. partNos.Add(partNo);
  8118. }
  8119. }
  8120. // 统一上传 - 调用MES出站
  8121. stopwatch2.Start();
  8122. List<int> results = new List<int>();
  8123. for (int i = 0; i < partNos.Count; i++)
  8124. {
  8125. string index = (i + 1).ToString(); // 弹夹穴号
  8126. if (string.IsNullOrEmpty(partNos[i]))
  8127. results.Add(1);
  8128. else
  8129. {
  8130. List<TestItem> items1 = new List<TestItem>();
  8131. items1.Add(new TestItem()
  8132. {
  8133. Parameter_name = "弹夹码",
  8134. Parameter_value = sn,
  8135. Parameter_unit = ""
  8136. });
  8137. items1.Add(new TestItem()
  8138. {
  8139. Parameter_name = "弹夹穴号",
  8140. Parameter_value = index,
  8141. Parameter_unit = ""
  8142. });
  8143. items1.Add(new TestItem()
  8144. {
  8145. Parameter_name = "载具码",
  8146. Parameter_value = vehicleCodes[i],
  8147. Parameter_unit = ""
  8148. });
  8149. items1.Add(new TestItem()
  8150. {
  8151. Parameter_name = "载具穴号",
  8152. Parameter_value = "1",
  8153. Parameter_unit = ""
  8154. });
  8155. items1.Add(new TestItem()
  8156. {
  8157. Parameter_name = "产品结果",
  8158. Parameter_value = d3Result == 1 ? "OK" : "NG",
  8159. Parameter_unit = ""
  8160. });
  8161. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  8162. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  8163. results.Add(result1);
  8164. }
  8165. }
  8166. short result = 0;
  8167. if (results.All(a => a == 1))
  8168. result = 1;
  8169. else if (results.Contains(3))
  8170. result = 3;
  8171. else if (results.Contains(2))
  8172. result = 2;
  8173. else if (results.Contains(4))
  8174. result = 4;
  8175. else
  8176. result = 4;
  8177. stopwatch2.Stop();
  8178. // MES_Flag 为4MES报错
  8179. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8180. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8181. writeToPLC_Flag.Name = "d3MES_FLAG";
  8182. writeToPLC_Flag.Adress = 2463;
  8183. writeToPLC_Flag.Value = result;
  8184. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  8185. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8186. }
  8187. catch (Exception ex)
  8188. {
  8189. stopwatch2.Restart();
  8190. // MES_Flag 为4上位机报错
  8191. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  8192. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8193. writeToPLC_Flag.Name = "d3MES_FLAG";
  8194. writeToPLC_Flag.Adress = 2463;
  8195. writeToPLC_Flag.Value = (short)4;
  8196. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  8197. string str = ex.StackTrace;
  8198. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8199. stopwatch2.Stop();
  8200. }
  8201. stopwatch1.Stop();
  8202. AddMessage(LogType.Info, stationNameStr + "_S4_3出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8203. }
  8204. // 上次采集到的SN
  8205. //private string sn_S4_4进站接口 = string.Empty;
  8206. /// <summary>
  8207. /// [S4] 取放桁架 - S4_4进站接口(提升机2)
  8208. /// </summary>
  8209. private void S4_4进站接口(int plcNo, string stationNameStr)
  8210. {
  8211. Stopwatch stopwatch1 = new Stopwatch();
  8212. Stopwatch stopwatch2 = new Stopwatch();
  8213. try
  8214. {
  8215. stopwatch1.Start();
  8216. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  8217. sn = sn.Replace("\0", "");
  8218. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  8219. #region 查询15个载具码
  8220. List<string> vehicleCodes = new List<string>(); // 15个载具码
  8221. string vehicleData = string.Empty;
  8222. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  8223. if (string.IsNullOrEmpty(vehicleData))
  8224. vehicleData = "";
  8225. if (snResult != 0)
  8226. {
  8227. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8228. writeToPLC_Flag1.Name = "d3MES_FLAG";
  8229. writeToPLC_Flag1.Adress = 2463;
  8230. writeToPLC_Flag1.Value = (short)4;
  8231. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  8232. stopwatch1.Stop();
  8233. AddMessage(LogType.Info, stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8234. return;
  8235. }
  8236. string[] cavitySNs = vehicleData.Split('.');
  8237. if (cavitySNs != null && cavitySNs.Length > 0)
  8238. {
  8239. for (int i = 0; i < cavitySNs.Length; i++)
  8240. {
  8241. if (string.IsNullOrEmpty(cavitySNs[i]))
  8242. vehicleCodes.Add("");
  8243. else
  8244. vehicleCodes.Add(cavitySNs[i]);
  8245. }
  8246. }
  8247. #endregion 查询15个载具码
  8248. #region 查询15个产品SN
  8249. List<string> portNos = new List<string>(); // 15个产品SN
  8250. foreach (string vehicleCode in vehicleCodes)
  8251. {
  8252. if (string.IsNullOrEmpty(vehicleCode))
  8253. portNos.Add("");
  8254. else
  8255. {
  8256. // 查询
  8257. string cavityData = string.Empty;
  8258. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8259. if (string.IsNullOrEmpty(cavityData))
  8260. cavityData = "";
  8261. if (snResult1 != 0)
  8262. {
  8263. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8264. writeToPLC_Flag1.Name = "d3MES_FLAG";
  8265. writeToPLC_Flag1.Adress = 2463;
  8266. writeToPLC_Flag1.Value = (short)4;
  8267. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  8268. stopwatch1.Stop();
  8269. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8270. return;
  8271. }
  8272. string[] partSNs = cavityData.Split('.');
  8273. if (partSNs != null && partSNs.Length >= 1)
  8274. portNos.Add(partSNs[0]);
  8275. else
  8276. portNos.Add("");
  8277. }
  8278. }
  8279. #endregion 查询15个产品SN
  8280. // 调用MES进站(最多15个)
  8281. stopwatch2.Start();
  8282. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  8283. for (int i = 0; i < vehicleCodes.Count; i++)
  8284. {
  8285. // 循环进站
  8286. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  8287. {
  8288. // 产品SN(物料码)校验
  8289. string portNo = portNos[i];
  8290. List<TestItem> item = new List<TestItem>();
  8291. item.Add(new TestItem()
  8292. {
  8293. Parameter_name = "弹夹码",
  8294. Parameter_value = sn,
  8295. });
  8296. item.Add(new TestItem()
  8297. {
  8298. Parameter_name = "弹夹穴位",
  8299. Parameter_value = (i + 1).ToString(),
  8300. });
  8301. item.Add(new TestItem()
  8302. {
  8303. Parameter_name = "载具码",
  8304. Parameter_value = vehicleCodes[i],
  8305. });
  8306. item.Add(new TestItem()
  8307. {
  8308. Parameter_name = "载具穴号",
  8309. Parameter_value = "1",
  8310. });
  8311. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  8312. }
  8313. }
  8314. stopwatch2.Stop();
  8315. short result = 0;
  8316. bool haveMesWarn = results.Contains(5);
  8317. bool havePCWarn = results.Contains(6);
  8318. if (haveMesWarn)
  8319. result = 2; // 5->2
  8320. else if (havePCWarn)
  8321. result = 6; // 6->4
  8322. else
  8323. result = 1;
  8324. // MES_Flag 为4MES报错
  8325. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8326. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8327. writeToPLC_Flag.Name = "d4MES_FLAG";
  8328. writeToPLC_Flag.Adress = 2496;
  8329. writeToPLC_Flag.Value = result;
  8330. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8331. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8332. }
  8333. catch (Exception ex)
  8334. {
  8335. stopwatch2.Stop();
  8336. // MES_Flag 为4上位机报错
  8337. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  8338. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8339. writeToPLC_Flag.Name = "d4MES_FLAG";
  8340. writeToPLC_Flag.Adress = 2496;
  8341. writeToPLC_Flag.Value = (short)4;
  8342. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8343. string str = ex.StackTrace;
  8344. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8345. }
  8346. stopwatch1.Stop();
  8347. AddMessage(LogType.Info, stationNameStr + "_S4_4进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8348. }
  8349. // 上次采集到的SN
  8350. //private string sn_S4_4出站接口 = string.Empty;
  8351. /// <summary>
  8352. /// [S4] 取放桁架 - S4_4出站接口(提升机2)
  8353. /// </summary>
  8354. private void S4_4出站接口(int plcNo, string stationCode, string stationName)
  8355. {
  8356. Stopwatch stopwatch1 = new Stopwatch();
  8357. Stopwatch stopwatch2 = new Stopwatch();
  8358. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8359. string stationNameStr = stationCode + stationName;
  8360. string processItem = stationName; // 测试项目
  8361. try
  8362. {
  8363. stopwatch1.Start();
  8364. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8365. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8366. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8367. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8368. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  8369. sn = sn.Replace("\0", "");
  8370. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  8371. bool isPass = d4Result == 1; // 产品结果 bool
  8372. #region 查询15个载具码
  8373. List<string> vehicleCodes = new List<string>(); // 15个载具码
  8374. string vehicleData = string.Empty;
  8375. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  8376. if (string.IsNullOrEmpty(vehicleData))
  8377. vehicleData = "";
  8378. if (snResult1 != 0)
  8379. {
  8380. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8381. writeToPLC_Flag1.Name = "d4MES_FLAG";
  8382. writeToPLC_Flag1.Adress = 2496;
  8383. writeToPLC_Flag1.Value = (short)4;
  8384. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  8385. stopwatch1.Stop();
  8386. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8387. return;
  8388. }
  8389. string[] cavitySNs = vehicleData.Split('.');
  8390. if (cavitySNs != null && cavitySNs.Length > 0)
  8391. {
  8392. for (int i = 0; i < cavitySNs.Length; i++)
  8393. {
  8394. if (string.IsNullOrEmpty(cavitySNs[i]))
  8395. vehicleCodes.Add("");
  8396. else
  8397. vehicleCodes.Add(cavitySNs[i]);
  8398. }
  8399. }
  8400. #endregion 查询15个载具码
  8401. // 统一查 产品SN列表
  8402. List<string> partNos = new List<string>();
  8403. foreach (string vehicleCode in vehicleCodes)
  8404. {
  8405. if (string.IsNullOrEmpty(vehicleCode))
  8406. partNos.Add("");
  8407. else
  8408. {
  8409. string partNo = "";
  8410. #region 查询载具上的产品信息
  8411. string cavityData = string.Empty;
  8412. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8413. if (string.IsNullOrEmpty(cavityData))
  8414. cavityData = "";
  8415. if (snResult != 0)
  8416. {
  8417. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8418. writeToPLC_Flag1.Name = "d4MES_FLAG";
  8419. writeToPLC_Flag1.Adress = 2496;
  8420. writeToPLC_Flag1.Value = (short)4;
  8421. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  8422. stopwatch1.Stop();
  8423. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8424. return;
  8425. }
  8426. string[] partSNs = cavityData.Split('.');
  8427. if (partSNs != null && partSNs.Length >= 1)
  8428. partNo = partSNs[0];
  8429. #endregion 查询载具上的产品信息
  8430. partNos.Add(partNo);
  8431. }
  8432. }
  8433. // 调用MES出站
  8434. stopwatch2.Start();
  8435. // 统一上传
  8436. List<int> results = new List<int>();
  8437. for (int i = 0; i < partNos.Count; i++)
  8438. {
  8439. string index = (i + 1).ToString(); // 弹夹穴号
  8440. if (string.IsNullOrEmpty(partNos[i]))
  8441. results.Add(1);
  8442. else
  8443. {
  8444. List<TestItem> items1 = new List<TestItem>();
  8445. items1.Add(new TestItem()
  8446. {
  8447. Parameter_name = "弹夹码",
  8448. Parameter_value = sn,
  8449. Parameter_unit = ""
  8450. });
  8451. items1.Add(new TestItem()
  8452. {
  8453. Parameter_name = "弹夹穴号",
  8454. Parameter_value = index,
  8455. Parameter_unit = ""
  8456. });
  8457. items1.Add(new TestItem()
  8458. {
  8459. Parameter_name = "载具码",
  8460. Parameter_value = vehicleCodes[i],
  8461. Parameter_unit = ""
  8462. });
  8463. items1.Add(new TestItem()
  8464. {
  8465. Parameter_name = "载具穴号",
  8466. Parameter_value = "1",
  8467. Parameter_unit = ""
  8468. });
  8469. items1.Add(new TestItem()
  8470. {
  8471. Parameter_name = "产品结果",
  8472. Parameter_value = d4Result == 1 ? "OK" : "NG",
  8473. Parameter_unit = ""
  8474. });
  8475. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  8476. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  8477. results.Add(result1);
  8478. }
  8479. }
  8480. short result = 0;
  8481. if (results.All(a => a == 1))
  8482. result = 1;
  8483. else if (results.Contains(3))
  8484. result = 3;
  8485. else if (results.Contains(2))
  8486. result = 2;
  8487. else if (results.Contains(4))
  8488. result = 4;
  8489. else
  8490. result = 4;
  8491. stopwatch2.Stop();
  8492. // MES_Flag 为4MES报错
  8493. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8494. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8495. writeToPLC_Flag.Name = "d4MES_FLAG";
  8496. writeToPLC_Flag.Adress = 2496;
  8497. writeToPLC_Flag.Value = result;
  8498. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8499. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8500. }
  8501. catch (Exception ex)
  8502. {
  8503. stopwatch2.Restart();
  8504. // MES_Flag 为4上位机报错
  8505. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  8506. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8507. writeToPLC_Flag.Name = "d4MES_FLAG";
  8508. writeToPLC_Flag.Adress = 2496;
  8509. writeToPLC_Flag.Value = (short)4;
  8510. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8511. string str = ex.StackTrace;
  8512. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8513. stopwatch2.Stop();
  8514. }
  8515. stopwatch1.Stop();
  8516. AddMessage(LogType.Info, stationNameStr + "_S4_4出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8517. }
  8518. /// <summary>
  8519. /// [S4] 取放桁架 - S4_5弹夹扫码
  8520. /// </summary>
  8521. /// <param name="plcNo">PLC编号</param>
  8522. /// <param name="stationNameStr">工站全称</param>
  8523. private void S4_5弹夹扫码(int plcNo, string stationNameStr)
  8524. {
  8525. Stopwatch stopwatch1 = new Stopwatch();
  8526. Stopwatch stopwatch2 = new Stopwatch();
  8527. try
  8528. {
  8529. stopwatch1.Start();
  8530. // ZS 弹夹扫码
  8531. string d5BulletclipCode = " "; // 扫到的码
  8532. short d5BulletclipScanCode = 2;
  8533. stopwatch2.Start();
  8534. //Funs[plcNo].WriteMultipleRegisters<string>(2529, d5BulletclipCode, 20);
  8535. //// MES_Flag
  8536. //Funs[plcNo].WriteMultipleRegisters<short>(2528, d5BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  8537. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8538. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  8539. writeToPLC_Flag.Adress = 2528;
  8540. writeToPLC_Flag.Value = d5BulletclipScanCode;
  8541. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8542. {
  8543. Name = "d5BulletclipCode",
  8544. Adress = 2529,
  8545. ValueType = PLCValueType.String,
  8546. ValueTypeStrLength = 20,
  8547. Value = d5BulletclipCode
  8548. });
  8549. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  8550. stopwatch2.Stop();
  8551. }
  8552. catch (Exception ex)
  8553. {
  8554. string str = ex.StackTrace;
  8555. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8556. stopwatch2.Start();
  8557. //Funs[plcNo].WriteMultipleRegisters<string>(2529, " ", 20);
  8558. //// MES_Flag
  8559. //Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  8560. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8561. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  8562. writeToPLC_Flag.Adress = 2528;
  8563. writeToPLC_Flag.Value = (short)6;
  8564. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8565. {
  8566. Name = "d5BulletclipCode",
  8567. Adress = 2529,
  8568. ValueType = PLCValueType.String,
  8569. ValueTypeStrLength = 20,
  8570. Value = " "
  8571. });
  8572. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  8573. stopwatch2.Stop();
  8574. }
  8575. stopwatch1.Stop();
  8576. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8577. }
  8578. /// <summary>
  8579. /// [S4] 取放桁架 - S4_5载具扫码
  8580. /// </summary>
  8581. /// <param name="plcNo">PLC编号</param>
  8582. /// <param name="stationNameStr">工站全称</param>
  8583. private void S4_5载具扫码(int plcNo, string stationNameStr)
  8584. {
  8585. Stopwatch stopwatch1 = new Stopwatch();
  8586. Stopwatch stopwatch2 = new Stopwatch();
  8587. try
  8588. {
  8589. stopwatch1.Start();
  8590. // ZS 载具扫码
  8591. string d5VehicleCode = " "; // 扫到的码
  8592. short d5VehicleScanCode = 2;
  8593. #region 进站
  8594. if (d5VehicleScanCode == 2 && !string.IsNullOrEmpty(d5VehicleCode))
  8595. {
  8596. // 查产品SN
  8597. #region 查询载具上的产品信息
  8598. string cavityData = string.Empty;
  8599. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d5VehicleCode, ref cavityData);
  8600. if (string.IsNullOrEmpty(cavityData))
  8601. cavityData = "";
  8602. if (snResult != 0)
  8603. {
  8604. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8605. writeToPLC_Flag1.Name = "d5VehicleScanCode";
  8606. writeToPLC_Flag1.Adress = 2559;
  8607. writeToPLC_Flag1.Value = (short)6;
  8608. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8609. {
  8610. Name = "d5VehicleCode",
  8611. Adress = 2560,
  8612. ValueType = PLCValueType.String,
  8613. ValueTypeStrLength = 20,
  8614. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  8615. });
  8616. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag1);
  8617. stopwatch1.Stop();
  8618. AddMessage(LogType.Info, stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8619. return;
  8620. }
  8621. string[] cavitySNs = cavityData.Split('.');
  8622. string partNo = "";
  8623. if (cavitySNs != null && cavitySNs.Length >= 1)
  8624. {
  8625. partNo = cavitySNs[0];
  8626. }
  8627. #endregion 查询载具上的产品信息
  8628. List<TestItem> item = new List<TestItem>();
  8629. item.Add(new TestItem()
  8630. {
  8631. Parameter_name = "载具码",
  8632. Parameter_value = d5VehicleCode,
  8633. });
  8634. item.Add(new TestItem()
  8635. {
  8636. Parameter_name = "载具穴号",
  8637. Parameter_value = "1",
  8638. });
  8639. stopwatch2.Start();
  8640. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  8641. stopwatch2.Stop();
  8642. d5VehicleScanCode = (short)result == 1 ? d5VehicleScanCode : (short)result;
  8643. }
  8644. #endregion 进站
  8645. //Funs[plcNo].WriteMultipleRegisters<string>(2560, d5VehicleCode, 20);
  8646. //// MES_Flag
  8647. //Funs[plcNo].WriteMultipleRegisters<short>(2559, d5VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  8648. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8649. writeToPLC_Flag.Name = "d5VehicleScanCode";
  8650. writeToPLC_Flag.Adress = 2559;
  8651. writeToPLC_Flag.Value = d5VehicleScanCode;
  8652. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8653. {
  8654. Name = "d5VehicleCode",
  8655. Adress = 2560,
  8656. ValueType = PLCValueType.String,
  8657. ValueTypeStrLength = 20,
  8658. Value = d5VehicleCode
  8659. });
  8660. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  8661. }
  8662. catch (Exception ex)
  8663. {
  8664. string str = ex.StackTrace;
  8665. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8666. stopwatch2.Start();
  8667. //Funs[plcNo].WriteMultipleRegisters<string>(2560, " ", 20);
  8668. //// MES_Flag
  8669. //Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  8670. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8671. writeToPLC_Flag.Name = "d5VehicleScanCode";
  8672. writeToPLC_Flag.Adress = 2559;
  8673. writeToPLC_Flag.Value = (short)6;
  8674. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8675. {
  8676. Name = "d5VehicleCode",
  8677. Adress = 2560,
  8678. ValueType = PLCValueType.String,
  8679. ValueTypeStrLength = 20,
  8680. Value = " "
  8681. });
  8682. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  8683. stopwatch2.Stop();
  8684. }
  8685. stopwatch1.Stop();
  8686. AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8687. }
  8688. // 上次采集到的SN
  8689. //private string sn_S4_5出站接口 = string.Empty;
  8690. /// <summary>
  8691. /// [S4] 取放桁架 - S4_5出站接口
  8692. /// </summary>
  8693. private void S4_5出站接口(int plcNo, string stationCode, string stationName)
  8694. {
  8695. Stopwatch stopwatch1 = new Stopwatch();
  8696. Stopwatch stopwatch2 = new Stopwatch();
  8697. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8698. string stationNameStr = stationCode + stationName;
  8699. string processItem = stationName; // 测试项目
  8700. try
  8701. {
  8702. stopwatch1.Start();
  8703. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8704. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8705. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8706. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8707. string sn = (string)s4PLCData["d5ProductSN"]; // 产品SN(弹夹码)
  8708. sn = sn.Replace("\0", "");
  8709. string d5VehicleCode1 = (string)s4PLCData["d5VehicleCode1"]; // 载具1码(弹夹穴位1)
  8710. d5VehicleCode1 = d5VehicleCode1.Replace("\0", "");
  8711. string d5VehicleCode2 = (string)s4PLCData["d5VehicleCode2"]; // 载具2码(弹夹穴位2)
  8712. d5VehicleCode2 = d5VehicleCode2.Replace("\0", "");
  8713. string d5VehicleCode3 = (string)s4PLCData["d5VehicleCode3"]; // 载具3码(弹夹穴位3)
  8714. d5VehicleCode3 = d5VehicleCode3.Replace("\0", "");
  8715. string d5VehicleCode4 = (string)s4PLCData["d5VehicleCode4"]; // 载具4码(弹夹穴位4)
  8716. d5VehicleCode4 = d5VehicleCode4.Replace("\0", "");
  8717. string d5VehicleCode5 = (string)s4PLCData["d5VehicleCode5"]; // 载具5码(弹夹穴位5)
  8718. d5VehicleCode5 = d5VehicleCode5.Replace("\0", "");
  8719. string d5VehicleCode6 = (string)s4PLCData["d5VehicleCode6"]; // 载具6码(弹夹穴位6)
  8720. d5VehicleCode6 = d5VehicleCode6.Replace("\0", "");
  8721. string d5VehicleCode7 = (string)s4PLCData["d5VehicleCode7"]; // 载具7码(弹夹穴位7)
  8722. d5VehicleCode7 = d5VehicleCode7.Replace("\0", "");
  8723. string d5VehicleCode8 = (string)s4PLCData["d5VehicleCode8"]; // 载具8码(弹夹穴位8)
  8724. d5VehicleCode8 = d5VehicleCode8.Replace("\0", "");
  8725. string d5VehicleCode9 = (string)s4PLCData["d5VehicleCode9"]; // 载具9码(弹夹穴位9)
  8726. d5VehicleCode9 = d5VehicleCode9.Replace("\0", "");
  8727. string d5VehicleCode10 = (string)s4PLCData["d5VehicleCode10"]; // 载具10码(弹夹穴位10)
  8728. d5VehicleCode10 = d5VehicleCode10.Replace("\0", "");
  8729. string d5VehicleCode11 = (string)s4PLCData["d5VehicleCode11"]; // 载具11码(弹夹穴位11)
  8730. d5VehicleCode11 = d5VehicleCode11.Replace("\0", "");
  8731. string d5VehicleCode12 = (string)s4PLCData["d5VehicleCode12"]; // 载具12码(弹夹穴位12)
  8732. d5VehicleCode12 = d5VehicleCode12.Replace("\0", "");
  8733. string d5VehicleCode13 = (string)s4PLCData["d5VehicleCode13"]; // 载具13码(弹夹穴位13)
  8734. d5VehicleCode13 = d5VehicleCode13.Replace("\0", "");
  8735. string d5VehicleCode14 = (string)s4PLCData["d5VehicleCode14"]; // 载具14码(弹夹穴位14)
  8736. d5VehicleCode14 = d5VehicleCode14.Replace("\0", "");
  8737. string d5VehicleCode15 = (string)s4PLCData["d5VehicleCode15"]; // 载具15码(弹夹穴位15)
  8738. d5VehicleCode15 = d5VehicleCode15.Replace("\0", "");
  8739. int d5Result = (int)s4PLCData["d5Result"]; // 产品结果
  8740. bool pass = d5Result == 1;
  8741. // 存 载具SN列表
  8742. List<string> vehicleCodes = new List<string>()
  8743. {
  8744. d5VehicleCode1,d5VehicleCode2,d5VehicleCode3,d5VehicleCode4,d5VehicleCode5,
  8745. d5VehicleCode6,d5VehicleCode7,d5VehicleCode8,d5VehicleCode9,d5VehicleCode10,
  8746. d5VehicleCode11,d5VehicleCode12,d5VehicleCode13,d5VehicleCode14,d5VehicleCode15
  8747. };
  8748. // 统一查 产品SN列表
  8749. List<string> partNos = new List<string>();
  8750. foreach (string vehicleCode in vehicleCodes)
  8751. {
  8752. if (string.IsNullOrEmpty(vehicleCode))
  8753. partNos.Add("");
  8754. else
  8755. {
  8756. string partNo = "";
  8757. #region 查询载具上的产品信息
  8758. string cavityData = string.Empty;
  8759. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8760. if (string.IsNullOrEmpty(cavityData))
  8761. cavityData = "";
  8762. if (snResult != 0)
  8763. {
  8764. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8765. writeToPLC_Flag1.Name = "d5MES_FLAG";
  8766. writeToPLC_Flag1.Adress = 2591;
  8767. writeToPLC_Flag1.Value = (short)4;
  8768. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag1);
  8769. stopwatch1.Stop();
  8770. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8771. return;
  8772. }
  8773. string[] cavitySNs = cavityData.Split('.');
  8774. if (cavitySNs != null && cavitySNs.Length >= 1)
  8775. partNo = cavitySNs[0];
  8776. #endregion 查询载具上的产品信息
  8777. partNos.Add(partNo);
  8778. }
  8779. }
  8780. // 统一上传
  8781. stopwatch2.Start();
  8782. List<int> results = new List<int>();
  8783. for (int i = 0; i < partNos.Count; i++)
  8784. {
  8785. string index = (i + 1).ToString(); // 弹夹穴号
  8786. if (string.IsNullOrEmpty(partNos[i]))
  8787. results.Add(1);
  8788. else
  8789. {
  8790. List<TestItem> items1 = new List<TestItem>();
  8791. items1.Add(new TestItem()
  8792. {
  8793. Parameter_name = "弹夹码",
  8794. Parameter_value = sn,
  8795. Parameter_unit = ""
  8796. });
  8797. items1.Add(new TestItem()
  8798. {
  8799. Parameter_name = "弹夹穴号",
  8800. Parameter_value = index,
  8801. Parameter_unit = ""
  8802. });
  8803. items1.Add(new TestItem()
  8804. {
  8805. Parameter_name = "载具码",
  8806. Parameter_value = vehicleCodes[i],
  8807. Parameter_unit = ""
  8808. });
  8809. items1.Add(new TestItem()
  8810. {
  8811. Parameter_name = "载具穴号",
  8812. Parameter_value = "1",
  8813. Parameter_unit = ""
  8814. });
  8815. items1.Add(new TestItem()
  8816. {
  8817. Parameter_name = "产品结果",
  8818. Parameter_value = d5Result == 1 ? "OK" : "NG",
  8819. Parameter_unit = ""
  8820. });
  8821. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  8822. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  8823. results.Add(result1);
  8824. }
  8825. }
  8826. short result = 0;
  8827. if (results.All(a => a == 1))
  8828. result = 1;
  8829. else if (results.Contains(3))
  8830. result = 3;
  8831. else if (results.Contains(2))
  8832. result = 2;
  8833. else if (results.Contains(4))
  8834. result = 4;
  8835. else
  8836. result = 4;
  8837. stopwatch2.Stop();
  8838. #region 存储绑定数据到 边线MES系统中
  8839. if (result == 1)
  8840. {
  8841. // 删除绑定信息
  8842. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  8843. if (resultMesR != 0)
  8844. {
  8845. result = 4;
  8846. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  8847. }
  8848. }
  8849. #endregion 存储绑定数据到 边线MES系统中
  8850. // MES_Flag 为4MES报错
  8851. //Funs[plcNo].WriteMultipleRegisters<short>(2591, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8852. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8853. writeToPLC_Flag.Name = "d5MES_FLAG";
  8854. writeToPLC_Flag.Adress = 2591;
  8855. writeToPLC_Flag.Value = result;
  8856. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  8857. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  8858. }
  8859. catch (Exception ex)
  8860. {
  8861. stopwatch2.Restart();
  8862. // MES_Flag 为4上位机报错
  8863. //Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)4); // 4代表上位机报警
  8864. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8865. writeToPLC_Flag.Name = "d5MES_FLAG";
  8866. writeToPLC_Flag.Adress = 2591;
  8867. writeToPLC_Flag.Value = (short)4;
  8868. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  8869. stopwatch2.Stop();
  8870. string str = ex.StackTrace;
  8871. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8872. }
  8873. stopwatch1.Stop();
  8874. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8875. }
  8876. /// <summary>
  8877. /// [S4] 取放桁架 - S4_5节拍接口
  8878. /// </summary>
  8879. /// <param name="plcNo">PLC编号</param>
  8880. /// <param name="stationNameStr">工站全称</param>
  8881. private void S4_5节拍接口(int plcNo, string stationNameStr)
  8882. {
  8883. Stopwatch stopwatch1 = new Stopwatch();
  8884. Stopwatch stopwatch2 = new Stopwatch();
  8885. string resultStr = string.Empty;
  8886. try
  8887. {
  8888. stopwatch1.Start();
  8889. string oEEType = ((int)s4PLCData["d5OEEType"]).ToString(); // 节拍类型(plc写入)
  8890. string d5OEEProductSN = (string)s4PLCData["d5OEEProductSN"]; // 载具SN
  8891. d5OEEProductSN = d5OEEProductSN.Replace("\0", "");
  8892. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  8893. if (!actionBool)
  8894. {
  8895. stopwatch2.Start();
  8896. // MES_Flag
  8897. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 上位机;发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警
  8898. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8899. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  8900. writeToPLC_Flag1.Adress = 2924;
  8901. writeToPLC_Flag1.Value = (short)4;
  8902. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  8903. stopwatch2.Stop();
  8904. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8905. return;
  8906. }
  8907. string d5OEEPartNo = string.Empty; // 物料码
  8908. if (string.IsNullOrEmpty(d5OEEProductSN))
  8909. {
  8910. stopwatch2.Start();
  8911. // MES_Flag
  8912. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8913. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8914. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  8915. writeToPLC_Flag1.Adress = 2924;
  8916. writeToPLC_Flag1.Value = (short)1;
  8917. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  8918. stopwatch2.Stop();
  8919. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8920. return;
  8921. }
  8922. else
  8923. { // 查产品SN
  8924. d5OEEPartNo = "Test"; // ZS
  8925. }
  8926. short d5OEEMES_FLAG = 0;
  8927. // 上传OEE
  8928. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d5OEEPartNo, d5OEEProductSN);
  8929. d5OEEMES_FLAG = result.Item1;
  8930. resultStr = result.Item2;
  8931. stopwatch2.Start();
  8932. // MES_Flag
  8933. //Funs[plcNo].WriteMultipleRegisters<short>(2924, d5OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8934. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8935. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  8936. writeToPLC_Flag.Adress = 2924;
  8937. writeToPLC_Flag.Value = d5OEEMES_FLAG;
  8938. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  8939. stopwatch2.Stop();
  8940. }
  8941. catch (Exception ex)
  8942. {
  8943. string str = ex.StackTrace;
  8944. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8945. // MES_Flag
  8946. stopwatch2.Start();
  8947. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  8948. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8949. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  8950. writeToPLC_Flag.Adress = 2924;
  8951. writeToPLC_Flag.Value = (short)4;
  8952. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  8953. stopwatch2.Stop();
  8954. }
  8955. stopwatch1.Stop();
  8956. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8957. }
  8958. #endregion [S4] 取放桁架
  8959. #endregion PLC4 刘果段
  8960. #region PLC5 张超凡
  8961. #region [S5] Tray盘下料装备
  8962. /// <summary>
  8963. /// S5工位的数据- 触发信号上次的值
  8964. /// </summary>
  8965. private Dictionary<string, object> s5PLCSignal_Old = new Dictionary<string, object>();
  8966. /// <summary>
  8967. /// S5工位的数据(含触发信号)
  8968. /// </summary>
  8969. private Dictionary<string, object> s5PLCData = new Dictionary<string, object>();
  8970. /// <summary>
  8971. /// S5工位的数据- 回写点位
  8972. /// </summary>
  8973. private Dictionary<string, WriteToPLC_Flag> s5PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  8974. /// <summary>
  8975. /// [S5] Tray盘下料装备
  8976. /// </summary>
  8977. /// <param name="plcNo">PLC编号</param>
  8978. //private void ReadStation_S5(int plcNo)
  8979. //{
  8980. // // [S1] Tray盘上料装备
  8981. // // [S2] FCT
  8982. // // [S3] 值板机
  8983. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  8984. // // [S5] Tray盘下料装备
  8985. // /// 上位机心跳
  8986. // /// 获取设备报警数据与状态信息
  8987. // string stationCode = "[S5]";
  8988. // string stationName = "Tray盘下料装备";
  8989. // string stationNameStr = stationCode + stationName;
  8990. // #region 创建字典
  8991. // // 触发信号字典 赋值
  8992. // s5PLCSignal_Old.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8993. // s5PLCSignal_Old.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8994. // s5PLCSignal_Old.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8995. // s5PLCSignal_Old.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  8996. // s5PLCSignal_Old.Add("e1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  8997. // s5PLCSignal_Old.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  8998. // s5PLCSignal_Old.Add("e1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  8999. // // PLC数据字典 赋值
  9000. // s5PLCData.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  9001. // s5PLCData.Add("e1MES_FLAG_Check", 0); // MES_FLAG
  9002. // s5PLCData.Add("e1ProductSN_Check", ""); //
  9003. // s5PLCData.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  9004. // s5PLCData.Add("e1MES_FLAG", 0); // MES_FLAG
  9005. // s5PLCData.Add("e1ProductSN", ""); // 产品SN
  9006. // s5PLCData.Add("e1PartNo", ""); // 物料码
  9007. // s5PLCData.Add("e1Result", 0); // 产品结果
  9008. // s5PLCData.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  9009. // s5PLCData.Add("e1OEEMES_FLAG", 0); // MES_FLAG
  9010. // s5PLCData.Add("e1OEEProductSN", "");// 产品SN(载具SN)
  9011. // s5PLCData.Add("e1OEEType", 0); // 节拍类型(plc写入)
  9012. // s5PLCData.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  9013. // s5PLCData.Add("e1AGVUpStart", 0); // AGV上料开始信号
  9014. // s5PLCData.Add("e1AGVUpEnd", 0); // AGV上料完成信号
  9015. // s5PLCData.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  9016. // s5PLCData.Add("e1AGVDownStart", 0); // AGV下料开始信号
  9017. // s5PLCData.Add("e1AGVDownEnd", 0); // AGV下料完成信号
  9018. // #endregion 创建字典
  9019. // while (IsRun)
  9020. // {
  9021. // try
  9022. // {
  9023. // if (!GlobalContext._IsCon_Funs5)
  9024. // {
  9025. // UpdatePLCMonitor(1, plcNo, 0);
  9026. // continue;
  9027. // }
  9028. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  9029. // {
  9030. // Stopwatch stopwatch1 = new Stopwatch();
  9031. // Stopwatch stopwatch2 = new Stopwatch();
  9032. // stopwatch1.Start();
  9033. // stopwatch2.Start();
  9034. // #region 一次性读取所有数据
  9035. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  9036. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 46);
  9037. // int[] datas = data1.Concat(data2).ToArray();
  9038. // s5PLCData["e1PLC_FLAG_Check"] = datas[2]; // 进站校验
  9039. // s5PLCData["e1MES_FLAG_Check"] = datas[3];
  9040. // int[] e1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  9041. // s5PLCData["e1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(e1ProductSN_CheckData, 0, 40);
  9042. // s5PLCData["e1PLC_FLAG"] = datas[34]; // 出站接口
  9043. // s5PLCData["e1MES_FLAG"] = datas[35];
  9044. // int[] e1ProductSNData = datas.Skip(36).Take(20).ToArray();
  9045. // s5PLCData["e1ProductSN"] = ModbusClient.ConvertRegistersToString(e1ProductSNData, 0, 40);
  9046. // int[] e1PartNoData = datas.Skip(56).Take(20).ToArray();
  9047. // s5PLCData["e1PartNo"] = ModbusClient.ConvertRegistersToString(e1PartNoData, 0, 40);
  9048. // s5PLCData["e1Result"] = datas[76];
  9049. // s5PLCData["e1OEEPLC_FLAG"] = datas[87]; // 节拍接口
  9050. // s5PLCData["e1OEEMES_FLAG"] = datas[88];
  9051. // int[] e1OEEProductSNData = datas.Skip(89).Take(20).ToArray();
  9052. // s5PLCData["e1OEEProductSN"] = ModbusClient.ConvertRegistersToString(e1OEEProductSNData, 0, 40);
  9053. // s5PLCData["e1OEEType"] = datas[109];
  9054. // s5PLCData["e1AGVUpCall"] = datas[120]; // AGV上料
  9055. // s5PLCData["e1AGVUpStart"] = datas[121];
  9056. // s5PLCData["e1AGVUpEnd"] = datas[122];
  9057. // s5PLCData["e1AGVDownCall"] = datas[133]; // AGV下料
  9058. // s5PLCData["e1AGVDownStart"] = datas[134];
  9059. // s5PLCData["e1AGVDownEnd"] = datas[135];
  9060. // #endregion 一次性读取所有数据
  9061. // stopwatch2.Stop();
  9062. // #region 回写操作,写后清空flag
  9063. // PLCWriteData(Funs[plcNo], ref s5PLCData, ref s5PLCWriteData);
  9064. // #endregion 回写操作,写后清空flag
  9065. // #region 进站校验
  9066. // try
  9067. // {
  9068. // int e1PLC_FLAG_Check = (int)s5PLCData["e1PLC_FLAG_Check"];
  9069. // int e1MES_FLAG_Check = (int)s5PLCData["e1MES_FLAG_Check"];
  9070. // int e1PLC_FLAG_CheckOld = (int)s5PLCSignal_Old["e1PLC_FLAG_Check"];
  9071. // if (e1PLC_FLAG_Check != e1PLC_FLAG_CheckOld)
  9072. // {
  9073. // if (e1PLC_FLAG_Check == 1 && e1MES_FLAG_Check == 0) // 0->1
  9074. // Task.Run(() => S5进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  9075. // else if (e1PLC_FLAG_Check == 0 && e1MES_FLAG_Check != 0)
  9076. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  9077. // s5PLCSignal_Old["e1PLC_FLAG_Check"] = s5PLCData["e1PLC_FLAG_Check"];
  9078. // }
  9079. // }
  9080. // catch (Exception ex)
  9081. // {
  9082. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  9083. // string str = ex.StackTrace;
  9084. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9085. // }
  9086. // #endregion 进站校验
  9087. // #region 出站接口
  9088. // try
  9089. // {
  9090. // int e1PLC_FLAG = (int)s5PLCData["e1PLC_FLAG"];
  9091. // int e1MES_FLAG = (int)s5PLCData["e1MES_FLAG"];
  9092. // int e1PLC_FLAGOld = (int)s5PLCSignal_Old["e1PLC_FLAG"];
  9093. // if (e1PLC_FLAG != e1PLC_FLAGOld)
  9094. // {
  9095. // if (e1PLC_FLAG == 1 && e1MES_FLAG == 0) // 0->1
  9096. // Task.Run(() => S5出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  9097. // else if (e1PLC_FLAG == 0 && e1MES_FLAG != 0)
  9098. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)0);
  9099. // s5PLCSignal_Old["e1PLC_FLAG"] = s5PLCData["e1PLC_FLAG"];
  9100. // }
  9101. // }
  9102. // catch (Exception ex)
  9103. // {
  9104. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)6); // 6代表上位机报警
  9105. // string str = ex.StackTrace;
  9106. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9107. // }
  9108. // #endregion 出站接口
  9109. // #region 节拍接口
  9110. // try
  9111. // {
  9112. // int e1OEEPLC_FLAG = (int)s5PLCData["e1OEEPLC_FLAG"];
  9113. // int e1OEEMES_FLAG = (int)s5PLCData["e1OEEMES_FLAG"];
  9114. // int e1OEEPLC_FLAGOld = (int)s5PLCSignal_Old["e1OEEPLC_FLAG"];
  9115. // if (e1OEEPLC_FLAG != e1OEEPLC_FLAGOld)
  9116. // {
  9117. // if (e1OEEPLC_FLAG == 1 && e1OEEMES_FLAG == 0) // 0->1
  9118. // Task.Run(() => S5节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  9119. // else if (e1OEEPLC_FLAG == 0 && e1OEEMES_FLAG != 0)
  9120. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)0);
  9121. // s5PLCSignal_Old["e1OEEPLC_FLAG"] = s5PLCData["e1OEEPLC_FLAG"];
  9122. // }
  9123. // }
  9124. // catch (Exception ex)
  9125. // {
  9126. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  9127. // string str = ex.StackTrace;
  9128. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9129. // }
  9130. // #endregion 节拍接口
  9131. // #region AGV上料
  9132. // // AGV上料叫AGV信号
  9133. // try
  9134. // {
  9135. // int e1AGVUpCall = (int)s5PLCData["e1AGVUpCall"];
  9136. // int e1AGVUpCallOld = (int)s5PLCSignal_Old["e1AGVUpCall"];
  9137. // if (e1AGVUpCall != e1AGVUpCallOld)
  9138. // {
  9139. // if (e1AGVUpCall == 1) // 0->1
  9140. // Task.Run(() => S5AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  9141. // s5PLCSignal_Old["e1AGVUpCall"] = s5PLCData["e1AGVUpCall"];
  9142. // }
  9143. // }
  9144. // catch (Exception ex)
  9145. // {
  9146. // Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  9147. // string str = ex.StackTrace;
  9148. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9149. // }
  9150. // // AGV上料完成信号
  9151. // try
  9152. // {
  9153. // int e1AGVUpEnd = (int)s5PLCData["e1AGVUpEnd"];
  9154. // int e1AGVUpEndOld = (int)s5PLCSignal_Old["e1AGVUpEnd"];
  9155. // if (e1AGVUpEnd != e1AGVUpEndOld)
  9156. // {
  9157. // if (e1AGVUpEnd == 1) // 0->1
  9158. // Task.Run(() => S5AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  9159. // s5PLCSignal_Old["e1AGVUpEnd"] = s5PLCData["e1AGVUpEnd"];
  9160. // }
  9161. // }
  9162. // catch (Exception ex)
  9163. // {
  9164. // Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  9165. // string str = ex.StackTrace;
  9166. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9167. // }
  9168. // #endregion AGV上料
  9169. // #region AGV下料
  9170. // // AGV下料叫agv信号
  9171. // try
  9172. // {
  9173. // int e1AGVDownCall = (int)s5PLCData["e1AGVDownCall"];
  9174. // int e1AGVDownCallOld = (int)s5PLCSignal_Old["e1AGVDownCall"];
  9175. // if (e1AGVDownCall != e1AGVDownCallOld)
  9176. // {
  9177. // if (e1AGVDownCall == 1) // 0->1
  9178. // Task.Run(() => S5AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  9179. // s5PLCSignal_Old["e1AGVDownCall"] = s5PLCData["e1AGVDownCall"];
  9180. // }
  9181. // }
  9182. // catch (Exception ex)
  9183. // {
  9184. // Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  9185. // string str = ex.StackTrace;
  9186. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9187. // }
  9188. // // AGV下料完成信号
  9189. // try
  9190. // {
  9191. // int e1AGVDownEnd = (int)s5PLCData["e1AGVDownEnd"];
  9192. // int e1AGVDownEndOld = (int)s5PLCSignal_Old["e1AGVDownEnd"];
  9193. // if (e1AGVDownEnd != e1AGVDownEndOld)
  9194. // {
  9195. // if (e1AGVDownEnd == 1) // 0->1
  9196. // Task.Run(() => S5AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  9197. // s5PLCSignal_Old["e1AGVDownEnd"] = s5PLCData["e1AGVDownEnd"];
  9198. // }
  9199. // }
  9200. // catch (Exception ex)
  9201. // {
  9202. // Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  9203. // string str = ex.StackTrace;
  9204. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9205. // }
  9206. // #endregion AGV下料
  9207. // #region 心跳
  9208. // try
  9209. // {
  9210. // short states = 0;
  9211. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  9212. // }
  9213. // catch (Exception ex)
  9214. // {
  9215. // string str = ex.StackTrace;
  9216. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9217. // }
  9218. // #endregion 心跳
  9219. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  9220. // stopwatch1.Stop();
  9221. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  9222. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  9223. // }
  9224. // else
  9225. // {
  9226. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9227. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  9228. // Funs[plcNo].Connect();
  9229. // }
  9230. // }
  9231. // catch (Exception ex)
  9232. // {
  9233. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9234. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  9235. // Funs[plcNo].ReConnect();
  9236. // }
  9237. // Thread.Sleep(IntervalReadPLC);
  9238. // }
  9239. //}
  9240. /// <summary>
  9241. /// [S5] Tray盘下料装备 - 进站校验
  9242. /// </summary>
  9243. /// <param name="plcNo">PLC编号</param>
  9244. /// <param name="stationNameStr">工站全称</param>
  9245. private void S5进站校验(int plcNo, string stationNameStr)
  9246. {
  9247. Stopwatch stopwatch1 = new Stopwatch();
  9248. Stopwatch stopwatch2 = new Stopwatch();
  9249. try
  9250. {
  9251. stopwatch1.Start();
  9252. string sn = (string)s5PLCData["e1ProductSN_Check"]; // 产品SN(载具码)
  9253. sn = sn.Replace("\0", "");
  9254. // 获取产品SN By 载具码
  9255. #region 查询载具上的产品信息
  9256. string cavityData = string.Empty;
  9257. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  9258. if (string.IsNullOrEmpty(cavityData))
  9259. cavityData = "";
  9260. if (snResult != 0)
  9261. {
  9262. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9263. writeToPLC_Flag1.Name = "e1MES_FLAG_Check";
  9264. writeToPLC_Flag1.Adress = 2003;
  9265. writeToPLC_Flag1.Value = (short)6;
  9266. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag1);
  9267. stopwatch1.Stop();
  9268. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9269. return;
  9270. }
  9271. string[] cavitySNs = cavityData.Split('.');
  9272. string partNo = string.Empty;
  9273. if (cavitySNs != null && cavitySNs.Length >= 1)
  9274. partNo = cavitySNs[0];
  9275. #endregion 查询载具上的产品信息
  9276. // 产品SN(物料码)校验
  9277. List<TestItem> item = new List<TestItem>();
  9278. item.Add(new TestItem()
  9279. {
  9280. Parameter_name = "载具码",
  9281. Parameter_value = sn,
  9282. });
  9283. item.Add(new TestItem()
  9284. {
  9285. Parameter_name = "载具穴号",
  9286. Parameter_value = "1",
  9287. });
  9288. stopwatch2.Start();
  9289. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  9290. stopwatch2.Stop();
  9291. short e1MES_FLAG_Check = (short)result;
  9292. // MES_Flag
  9293. //Funs[plcNo].WriteMultipleRegisters<short>(2003, e1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  9294. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9295. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  9296. writeToPLC_Flag.Adress = 2003;
  9297. writeToPLC_Flag.Value = e1MES_FLAG_Check;
  9298. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  9299. }
  9300. catch (Exception ex)
  9301. {
  9302. string str = ex.StackTrace;
  9303. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9304. // MES_Flag
  9305. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  9306. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9307. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  9308. writeToPLC_Flag.Adress = 2003;
  9309. writeToPLC_Flag.Value = (short)6;
  9310. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  9311. }
  9312. stopwatch1.Stop();
  9313. AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9314. }
  9315. /// <summary>
  9316. /// [S5] Tray盘下料装备 - 出站接口
  9317. /// </summary>
  9318. /// <param name="plcNo"></param>
  9319. /// <param name="stationCode"></param>
  9320. /// <param name="stationName"></param>
  9321. private void S5出站接口(int plcNo, string stationCode, string stationName)
  9322. {
  9323. Stopwatch stopwatch1 = new Stopwatch();
  9324. Stopwatch stopwatch2 = new Stopwatch();
  9325. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  9326. string stationNameStr = stationCode + stationName;
  9327. string processItem = stationName; // 测试项目
  9328. try
  9329. {
  9330. stopwatch1.Start();
  9331. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  9332. //string batch_num = GlobalContext.BatchNumber; // 批次号
  9333. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  9334. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  9335. string sn = (string)s5PLCData["e1ProductSN"]; // 产品SN(载具SN码)
  9336. sn = sn.Replace("\0", "");
  9337. //string partNo = (string)s5PLCData["e1PartNo"]; // 物料码
  9338. //partNo = partNo.Replace("\0", "");
  9339. #region 查询载具上的产品信息
  9340. string cavityData = string.Empty;
  9341. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  9342. if (string.IsNullOrEmpty(cavityData))
  9343. cavityData = "";
  9344. if (snResult != 0)
  9345. {
  9346. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9347. writeToPLC_Flag1.Name = "e1MES_FLAG";
  9348. writeToPLC_Flag1.Adress = 2035;
  9349. writeToPLC_Flag1.Value = (short)4;
  9350. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag1);
  9351. stopwatch1.Stop();
  9352. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9353. return;
  9354. }
  9355. string[] cavitySNs = cavityData.Split('.');
  9356. string partNo = string.Empty;
  9357. if (cavitySNs != null && cavitySNs.Length >= 1)
  9358. partNo = cavitySNs[0];
  9359. #endregion 查询载具上的产品信息
  9360. int e1Result = (int)s5PLCData["e1Result"]; // 产品结果
  9361. bool pass = e1Result == 1;
  9362. stopwatch2.Start();
  9363. // 上传MES
  9364. List<TestItem> items = new List<TestItem>();
  9365. items.Add(new TestItem()
  9366. {
  9367. Parameter_name = "载具码",
  9368. Parameter_value = sn,
  9369. Parameter_unit = ""
  9370. });
  9371. items.Add(new TestItem()
  9372. {
  9373. Parameter_name = "载具穴号",
  9374. Parameter_value = "1",
  9375. Parameter_unit = ""
  9376. });
  9377. items.Add(new TestItem()
  9378. {
  9379. Parameter_name = "产品结果",
  9380. Parameter_value = e1Result == 1 ? "OK" : "NG",
  9381. Parameter_unit = ""
  9382. });
  9383. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  9384. , workorder_code, mtltmrk, partNo, pass, sn, "1");
  9385. //int result = result1 == 1 ? 1 : (GlobalContext.IsSendProcessData ? 4 : 1);
  9386. short result = result1 == 1 ? (short)1 : (short)3;
  9387. stopwatch2.Stop();
  9388. #region 存储绑定数据到 边线MES系统中
  9389. if (result == 1)
  9390. {
  9391. // 删除绑定信息
  9392. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  9393. if (resultMesR != 0)
  9394. {
  9395. result = 4;
  9396. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  9397. }
  9398. }
  9399. #endregion 存储绑定数据到 边线MES系统中
  9400. // MES_Flag 为MES报错
  9401. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9402. //Funs[plcNo].WriteMultipleRegisters<short>(2035, result); // 4代表上位机报警
  9403. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9404. writeToPLC_Flag.Name = "e1MES_FLAG";
  9405. writeToPLC_Flag.Adress = 2035;
  9406. writeToPLC_Flag.Value = result;
  9407. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  9408. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  9409. }
  9410. catch (Exception ex)
  9411. {
  9412. stopwatch2.Restart();
  9413. // MES_Flag 为4上位机报错
  9414. //Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)4); // 4代表上位机报警
  9415. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9416. writeToPLC_Flag.Name = "e1MES_FLAG";
  9417. writeToPLC_Flag.Adress = 2035;
  9418. writeToPLC_Flag.Value = (short)4;
  9419. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  9420. stopwatch2.Stop();
  9421. string str = ex.StackTrace;
  9422. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9423. }
  9424. stopwatch1.Stop();
  9425. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9426. }
  9427. /// <summary>
  9428. /// [S5] Tray盘下料装备 - 节拍接口
  9429. /// </summary>
  9430. /// <param name="plcNo">PLC编号</param>
  9431. /// <param name="stationNameStr">工站全称</param>
  9432. private void S5节拍接口(int plcNo, string stationNameStr)
  9433. {
  9434. Stopwatch stopwatch1 = new Stopwatch();
  9435. Stopwatch stopwatch2 = new Stopwatch();
  9436. string resultStr = string.Empty;
  9437. try
  9438. {
  9439. stopwatch1.Start();
  9440. string oEEType = ((int)s5PLCData["e1OEEType"]).ToString(); // 节拍类型(plc写入)
  9441. string e1OEEProductSN = (string)s5PLCData["e1OEEProductSN"]; // 载具SN
  9442. e1OEEProductSN = e1OEEProductSN.Replace("\0", "");
  9443. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  9444. if (!actionBool)
  9445. {
  9446. stopwatch2.Start();
  9447. // MES_Flag
  9448. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9449. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9450. writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  9451. writeToPLC_Flag1.Adress = 2088;
  9452. writeToPLC_Flag1.Value = (short)4;
  9453. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  9454. stopwatch2.Stop();
  9455. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9456. return;
  9457. }
  9458. string e1OEEPartNo = string.Empty; // 物料码
  9459. if (string.IsNullOrEmpty(e1OEEProductSN))
  9460. {
  9461. stopwatch2.Start();
  9462. // MES_Flag
  9463. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9464. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9465. writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  9466. writeToPLC_Flag1.Adress = 2088;
  9467. writeToPLC_Flag1.Value = (short)1;
  9468. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  9469. stopwatch2.Stop();
  9470. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9471. return;
  9472. }
  9473. else
  9474. { // 查产品SN
  9475. e1OEEPartNo = "Test"; // ZS
  9476. }
  9477. short e1OEEMES_FLAG = 0;
  9478. // 上传OEE
  9479. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, e1OEEPartNo, e1OEEProductSN);
  9480. e1OEEMES_FLAG = result.Item1;
  9481. resultStr = result.Item2;
  9482. stopwatch2.Start();
  9483. // MES_Flag
  9484. //Funs[plcNo].WriteMultipleRegisters<short>(2088, e1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9485. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9486. writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  9487. writeToPLC_Flag.Adress = 2088;
  9488. writeToPLC_Flag.Value = e1OEEMES_FLAG;
  9489. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  9490. stopwatch2.Stop();
  9491. }
  9492. catch (Exception ex)
  9493. {
  9494. string str = ex.StackTrace;
  9495. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9496. // MES_Flag
  9497. stopwatch2.Start();
  9498. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  9499. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9500. writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  9501. writeToPLC_Flag.Adress = 2088;
  9502. writeToPLC_Flag.Value = (short)4;
  9503. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  9504. stopwatch2.Stop();
  9505. }
  9506. stopwatch1.Stop();
  9507. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9508. }
  9509. /// <summary>
  9510. /// [S5] Tray盘下料装备 - AGV上料叫agv
  9511. /// </summary>
  9512. /// <param name="plcNo">PLC编号</param>
  9513. /// <param name="stationNameStr">工站全称</param>
  9514. private void S5AGV上料叫agv(int plcNo, string stationNameStr)
  9515. {
  9516. Stopwatch stopwatch1 = new Stopwatch();
  9517. Stopwatch stopwatch2 = new Stopwatch();
  9518. try
  9519. {
  9520. stopwatch1.Start();
  9521. // ZS 呼叫AGV
  9522. short e1AGVUpCall = 2;
  9523. stopwatch2.Start();
  9524. // e1AGVUpCall
  9525. //Funs[plcNo].WriteMultipleRegisters<short>(2120, e1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9526. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9527. writeToPLC_Flag.Name = "e1AGVUpCall";
  9528. writeToPLC_Flag.Adress = 2120;
  9529. writeToPLC_Flag.Value = e1AGVUpCall;
  9530. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  9531. stopwatch2.Stop();
  9532. }
  9533. catch (Exception ex)
  9534. {
  9535. string str = ex.StackTrace;
  9536. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9537. // e1AGVUpCall
  9538. stopwatch2.Start();
  9539. //Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  9540. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9541. writeToPLC_Flag.Name = "e1AGVUpCall";
  9542. writeToPLC_Flag.Adress = 2120;
  9543. writeToPLC_Flag.Value = (short)4;
  9544. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  9545. stopwatch2.Stop();
  9546. }
  9547. stopwatch1.Stop();
  9548. AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9549. }
  9550. /// <summary>
  9551. /// [S5] Tray盘下料装备 - AGV上料完成
  9552. /// </summary>
  9553. /// <param name="plcNo">PLC编号</param>
  9554. /// <param name="stationNameStr">工站全称</param>
  9555. private void S5AGV上料完成(int plcNo, string stationNameStr)
  9556. {
  9557. Stopwatch stopwatch1 = new Stopwatch();
  9558. Stopwatch stopwatch2 = new Stopwatch();
  9559. try
  9560. {
  9561. stopwatch1.Start();
  9562. // ZS AGV上料完成,让小车离开
  9563. short e1AGVUpEnd = 2;
  9564. stopwatch2.Start();
  9565. // e1AGVUpEnd
  9566. //Funs[plcNo].WriteMultipleRegisters<short>(2122, e1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9567. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9568. writeToPLC_Flag.Name = "e1AGVUpEnd";
  9569. writeToPLC_Flag.Adress = 2122;
  9570. writeToPLC_Flag.Value = e1AGVUpEnd;
  9571. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  9572. stopwatch2.Stop();
  9573. }
  9574. catch (Exception ex)
  9575. {
  9576. string str = ex.StackTrace;
  9577. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9578. // e1AGVUpEnd
  9579. stopwatch2.Start();
  9580. //Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  9581. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9582. writeToPLC_Flag.Name = "e1AGVUpEnd";
  9583. writeToPLC_Flag.Adress = 2122;
  9584. writeToPLC_Flag.Value = (short)4;
  9585. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  9586. stopwatch2.Stop();
  9587. }
  9588. stopwatch1.Stop();
  9589. AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9590. }
  9591. /// <summary>
  9592. /// [S5] Tray盘下料装备 - AGV下料叫agv
  9593. /// </summary>
  9594. /// <param name="plcNo">PLC编号</param>
  9595. /// <param name="stationNameStr">工站全称</param>
  9596. private void S5AGV下料叫agv(int plcNo, string stationNameStr)
  9597. {
  9598. Stopwatch stopwatch1 = new Stopwatch();
  9599. Stopwatch stopwatch2 = new Stopwatch();
  9600. try
  9601. {
  9602. stopwatch1.Start();
  9603. // ZS 呼叫AGV
  9604. short e1AGVDownCall = 2;
  9605. stopwatch2.Start();
  9606. // e1AGVDownCall
  9607. //Funs[plcNo].WriteMultipleRegisters<short>(2133, e1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9608. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9609. writeToPLC_Flag.Name = "e1AGVDownCall";
  9610. writeToPLC_Flag.Adress = 2133;
  9611. writeToPLC_Flag.Value = e1AGVDownCall;
  9612. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  9613. stopwatch2.Stop();
  9614. }
  9615. catch (Exception ex)
  9616. {
  9617. string str = ex.StackTrace;
  9618. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9619. // e1AGVDownCall
  9620. stopwatch2.Start();
  9621. //Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  9622. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9623. writeToPLC_Flag.Name = "e1AGVDownCall";
  9624. writeToPLC_Flag.Adress = 2133;
  9625. writeToPLC_Flag.Value = (short)4;
  9626. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  9627. stopwatch2.Stop();
  9628. }
  9629. stopwatch1.Stop();
  9630. AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9631. }
  9632. /// <summary>
  9633. /// [S5] Tray盘下料装备 - AGV下料完成
  9634. /// </summary>
  9635. /// <param name="plcNo">PLC编号</param>
  9636. /// <param name="stationNameStr">工站全称</param>
  9637. private void S5AGV下料完成(int plcNo, string stationNameStr)
  9638. {
  9639. Stopwatch stopwatch1 = new Stopwatch();
  9640. Stopwatch stopwatch2 = new Stopwatch();
  9641. try
  9642. {
  9643. stopwatch1.Start();
  9644. // ZS AGV上料完成,让小车离开
  9645. short e1AGVDownEnd = 2;
  9646. stopwatch2.Start();
  9647. // e1AGVDownEnd
  9648. //Funs[plcNo].WriteMultipleRegisters<short>(2135, e1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9649. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9650. writeToPLC_Flag.Name = "e1AGVDownEnd";
  9651. writeToPLC_Flag.Adress = 2135;
  9652. writeToPLC_Flag.Value = e1AGVDownEnd;
  9653. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  9654. stopwatch2.Stop();
  9655. }
  9656. catch (Exception ex)
  9657. {
  9658. string str = ex.StackTrace;
  9659. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9660. // e1AGVDownEnd
  9661. stopwatch2.Start();
  9662. //Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  9663. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9664. writeToPLC_Flag.Name = "e1AGVDownEnd";
  9665. writeToPLC_Flag.Adress = 2135;
  9666. writeToPLC_Flag.Value = (short)4;
  9667. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  9668. stopwatch2.Stop();
  9669. }
  9670. stopwatch1.Stop();
  9671. AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9672. }
  9673. #endregion [S5] Tray盘下料装备
  9674. #endregion PLC5 张超凡
  9675. #region 缓存读取到的PLC数据 与 需要写入的PLC数据
  9676. /// <summary>
  9677. /// PLC读取到的数据 -添加数据
  9678. /// </summary>
  9679. public static void SxPLCData_Add(ref Dictionary<string, object> sxPlcData, string newKey, object newValue)
  9680. {
  9681. if (sxPlcData.ContainsKey(newKey))
  9682. sxPlcData[newKey] = newValue;
  9683. else
  9684. sxPlcData.Add(newKey, newValue);
  9685. }
  9686. /// <summary>
  9687. /// PLC需要写入的数据 -添加数据
  9688. /// </summary>
  9689. public static void SxPLCWriteData_Add(ref Dictionary<string, WriteToPLC_Flag> sxPLCWriteData, string newKey, WriteToPLC_Flag newValue)
  9690. {
  9691. if (sxPLCWriteData.ContainsKey(newKey))
  9692. sxPLCWriteData[newKey] = newValue;
  9693. else
  9694. sxPLCWriteData.Add(newKey, newValue);
  9695. }
  9696. /// <summary>
  9697. /// PLC回写操作,写后清空flag
  9698. /// </summary>
  9699. /// <param name="modbusClient">modbus对象</param>
  9700. /// <param name="pLCReadDatas">读取到的数据字典</param>
  9701. /// <param name="pLCWriteDatas">需要写入的数据</param>
  9702. public static void PLCWriteData(ModbusClientHelper modbusClient, ref Dictionary<string, object> pLCReadDatas, ref Dictionary<string, WriteToPLC_Flag> pLCWriteDataDic)
  9703. {
  9704. if (pLCWriteDataDic != null && pLCWriteDataDic.Count > 0)
  9705. {
  9706. List<WriteToPLC_Flag> pLCWriteDatas = pLCWriteDataDic.Values.ToList();
  9707. for (int i = 0; i < pLCWriteDatas.Count; i++)
  9708. {
  9709. string mesFlagName = pLCWriteDatas[i].Name;
  9710. int mesFlagAdress = pLCWriteDatas[i].Adress;
  9711. short mesFlagValue = (short)pLCWriteDatas[i].Value; // short
  9712. if (mesFlagValue != 0) // 不为0则证明需要写入结果信息
  9713. {
  9714. // 先回写数据
  9715. List<WriteToPLC_Data> writeToPLCDatas = pLCWriteDatas[i].WriteToPLCDatas;
  9716. for (int j = 0; j < writeToPLCDatas.Count; j++)
  9717. {
  9718. int mesDataAdress = writeToPLCDatas[j].Adress;
  9719. PLCValueType mesDataType = writeToPLCDatas[j].ValueType;
  9720. switch (mesDataType)
  9721. {
  9722. case PLCValueType.Short:
  9723. short mesDataValueShort = (short)writeToPLCDatas[j].Value;
  9724. modbusClient.WriteMultipleRegisters<short>(mesDataAdress, mesDataValueShort);
  9725. break;
  9726. case PLCValueType.String:
  9727. string mesDataValueStr = (string)writeToPLCDatas[j].Value;
  9728. int mesDataValueStrLength = writeToPLCDatas[j].ValueTypeStrLength;
  9729. modbusClient.WriteMultipleRegisters<string>(mesDataAdress, mesDataValueStr, mesDataValueStrLength);
  9730. break;
  9731. }
  9732. }
  9733. // 再回写信号
  9734. modbusClient.WriteMultipleRegisters<short>(mesFlagAdress, mesFlagValue);
  9735. // 存储读取数据的字典
  9736. pLCReadDatas[mesFlagName] = (int)mesFlagValue;
  9737. // 存储写入数据的字典 - 清空写入值
  9738. pLCWriteDatas[i].Value = (short)0;
  9739. pLCWriteDataDic[mesFlagName] = pLCWriteDatas[i];
  9740. }
  9741. }
  9742. }
  9743. }
  9744. /// <summary>
  9745. /// 提交点检数据到MES - 取数据库中缓存的 点检数据
  9746. /// </summary>
  9747. /// <param name="no">3</param>
  9748. /// <param name="stationCode">设备编号</param>
  9749. /// <param name="stationNameStr">设备名称</param>
  9750. /// <param name="plcOrder">车间订单号</param>
  9751. private void SubmitOneCheckDataToMESByDB(int plcNo, int stationCode, string stationNameStr, string plcOrder)
  9752. {
  9753. try
  9754. {
  9755. /// [S2]FCT (2-上传点检数据;102-清空该工单该工单的所有点检项缓存)
  9756. /// [S3]值板机 (3-上传点检数据;103-清空该工单该工单的所有点检项缓存)
  9757. /// [S4]取放桁架 (4-上传点检数据;104-清空该工单该工单的所有点检项缓存)
  9758. /// [S6]CCD检测 (6-上传点检数据;106-清空该工单该工单的所有点检项缓存)
  9759. int result1 = 0;
  9760. switch (stationCode)
  9761. {
  9762. case 2:
  9763. case 3:
  9764. case 4:
  9765. case 6:
  9766. result1 = SubmitToMESByDB(stationCode.ToString(), stationNameStr, plcOrder);
  9767. break;
  9768. case 102:
  9769. result1 = ClearOneCheckDataByDB("2", stationNameStr, plcOrder);
  9770. break;
  9771. case 103:
  9772. result1 = ClearOneCheckDataByDB("3", stationNameStr, plcOrder);
  9773. break;
  9774. case 104:
  9775. result1 = ClearOneCheckDataByDB("4", stationNameStr, plcOrder);
  9776. break;
  9777. case 106:
  9778. result1 = ClearOneCheckDataByDB("6", stationNameStr, plcOrder);
  9779. break;
  9780. default:
  9781. // MES_Flag 为“6未找到正确设备编号”
  9782. Funs[plcNo].WriteMultipleRegisters<int>(2406, 6);
  9783. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!未找到需要点检的正确设备编号");
  9784. return;
  9785. }
  9786. short result = result1 == 1 ? (short)1 : (short)2;
  9787. Funs[plcNo].WriteMultipleRegisters<int>(2406, result); // MES_Flag 为4MES报错
  9788. OnMessage(LogType.Debug, $"PLC{plcNo}_PLC通知MES上传点检数据运行完毕!-Write" + (result == 1 ? "成功!" : "失败!"));
  9789. }
  9790. catch (Exception ex)
  9791. {
  9792. // MES_Flag 为2上位机报错
  9793. Funs[plcNo].WriteMultipleRegisters<int>(2406, 2);
  9794. string str = ex.StackTrace;
  9795. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9796. }
  9797. }
  9798. #endregion 缓存读取到的PLC数据 与 需要写入的PLC数据
  9799. #region UI刷新
  9800. /// <summary>
  9801. /// 更新商品信息的UI + 下发产品信息(SN)
  9802. /// </summary>
  9803. private void UpdateProductInfo()
  9804. {
  9805. currentWC.Text = GlobalContext.WorkOrderCode; // 订单号
  9806. currentMtltmrk.Text = GlobalContext.Mtltmrk; // 产品型号
  9807. //currentBN.Text = GlobalContext.BatchNumber; // 批次号
  9808. //txt_CurSupplierCode.Text = ""; // 供应商代号
  9809. }
  9810. /// <summary>
  9811. /// 更新PLC连接状态的UI
  9812. /// </summary>
  9813. /// <param name="no">PLC编号</param>
  9814. /// <param name="status">状态</param>
  9815. private void UpdatePLCMonitor(int imgNo, int plcNo, int status)
  9816. {
  9817. if (this != null && !this.IsDisposed)
  9818. {
  9819. switch (imgNo)
  9820. {
  9821. case 1:
  9822. this.BeginInvoke(new Action(() =>
  9823. {
  9824. picPLC.Image = imageListState.Images[status];
  9825. }));
  9826. break;
  9827. case 2:
  9828. this.BeginInvoke(new Action(() =>
  9829. {
  9830. pictureBox2.Image = imageListState.Images[status];
  9831. }));
  9832. break;
  9833. case 3:
  9834. this.BeginInvoke(new Action(() =>
  9835. {
  9836. pictureBox3.Image = imageListState.Images[status];
  9837. }));
  9838. break;
  9839. case 4:
  9840. this.BeginInvoke(new Action(() =>
  9841. {
  9842. pictureBox4.Image = imageListState.Images[status];
  9843. }));
  9844. break;
  9845. case 5:
  9846. this.BeginInvoke(new Action(() =>
  9847. {
  9848. pictureBox5.Image = imageListState.Images[status];
  9849. }));
  9850. break;
  9851. case 6:
  9852. this.BeginInvoke(new Action(() =>
  9853. {
  9854. pictureBox6.Image = imageListState.Images[status];
  9855. }));
  9856. break;
  9857. case 7:
  9858. this.BeginInvoke(new Action(() =>
  9859. {
  9860. pictureBox7.Image = imageListState.Images[status];
  9861. }));
  9862. break;
  9863. case 8:
  9864. this.BeginInvoke(new Action(() =>
  9865. {
  9866. pictureBox8.Image = imageListState.Images[status];
  9867. }));
  9868. break;
  9869. default:
  9870. break;
  9871. }
  9872. }
  9873. Task.Run(() => // 更新PLC交互页的指示灯
  9874. {
  9875. try
  9876. {
  9877. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  9878. {
  9879. Form_Main.formPLCDB.UpdatePLCFunMonitor(plcNo, status);
  9880. }
  9881. }
  9882. catch { }
  9883. });
  9884. }
  9885. #endregion UI刷新
  9886. #region 日志
  9887. /// <summary>
  9888. /// 添加各工位运行日志(同步至PLC交互页面)
  9889. /// </summary>
  9890. /// <param name="stationNameStr">工站名称</param>
  9891. /// <param name="logType">日志类型</param>
  9892. /// <param name="message">日志内容</param>
  9893. /// <param name="snNumber">产品数字SN</param>
  9894. public void AddMessage_Station(string stationNameStr, LogType logType, string message, string snNumber = "")
  9895. {
  9896. if (!(stationNameStr.Equals("获取设备报警数据与状态信息")
  9897. && (message.Contains("更新整线运行数据完毕") || message.Contains("更新整线报警数据完毕"))
  9898. ))
  9899. {
  9900. AddMessage(logType, message); // 首页展示+日志记录
  9901. }
  9902. PLCDBFormMessage plcMessage = new PLCDBFormMessage()
  9903. {
  9904. StationName = stationNameStr,
  9905. SnNumber = snNumber,
  9906. Message = message,
  9907. CreateTime = DateTime.Now
  9908. };
  9909. // PLC交互页展示
  9910. Task.Run(() =>
  9911. {
  9912. try
  9913. {
  9914. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  9915. {
  9916. Form_Main.formPLCDB.UpdateMessage(plcMessage);
  9917. }
  9918. }
  9919. catch { }
  9920. });
  9921. }
  9922. /// <summary>
  9923. /// 添加运行日志
  9924. /// </summary>
  9925. /// <param name="logType">日志类型</param>
  9926. /// <param name="message">日志内容</param>
  9927. public void AddMessage(LogType logType, string message)
  9928. {
  9929. OnMessage(logType, message);
  9930. string date = DateTime.Now.ToString("yyyy/MM/dd");
  9931. string time = DateTime.Now.ToString("HH:mm:ss:fff");
  9932. string msgShow = time + "--> " + message + "\r\n";
  9933. this.BeginInvoke(new Action(() =>
  9934. {
  9935. systemLog.Rows.Insert(0, date, time, message);
  9936. if (systemLog.Rows.Count >= 100)
  9937. systemLog.Rows.RemoveAt(systemLog.Rows.Count - 1);
  9938. }));
  9939. }
  9940. /// <summary>
  9941. /// 添加运行日志-保存
  9942. /// </summary>
  9943. /// <param name="logType">日志类型</param>
  9944. /// <param name="message">日志内容</param>
  9945. private void OnMessage(LogType logType, string msg)
  9946. {
  9947. MessageEvent?.Invoke(logType, msg);
  9948. }
  9949. /// <summary>
  9950. /// 保存PLC写入日志
  9951. /// </summary>
  9952. /// <param name="logType"></param>
  9953. /// <param name="logValue"></param>
  9954. private void WritePLCLog(LogType logType, string logValue)
  9955. {
  9956. switch ((int)logType)
  9957. {
  9958. case 0:
  9959. _PLCLogNet.WriteDebug(logValue);
  9960. break;
  9961. case 1:
  9962. _PLCLogNet.WriteInfo(logValue);
  9963. break;
  9964. case 2:
  9965. _PLCLogNet.WriteWarn(logValue);
  9966. break;
  9967. case 3:
  9968. _PLCLogNet.WriteError(logValue);
  9969. break;
  9970. default:
  9971. _PLCLogNet.WriteFatal(logValue);
  9972. break;
  9973. }
  9974. }
  9975. /// <summary>
  9976. /// IOT Mqtt回调方法- With DataId
  9977. /// </summary>
  9978. /// <param name="id"></param>
  9979. /// <param name="v"></param>
  9980. /// <param name="dataId"></param>
  9981. public void CallbackWithDataId(string id, string msg, string dataId)
  9982. {
  9983. //_MqttLogNet.WriteInfo("-------CallbackWithDataId-------");
  9984. //byte[] buffer1 = Encoding.Default.GetBytes(v);
  9985. //byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);
  9986. //string strBuffer = Encoding.Default.GetString(buffer2, 0, buffer2.Length);
  9987. //Console.WriteLine("{0} -> {1} {2}", id, strBuffer, dataId);
  9988. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  9989. _IOTMqttLogNet.WriteInfo($"{datetime}-> [消息ID:{id}][事件ID:{dataId}]{msg}");
  9990. }
  9991. /// <summary>
  9992. /// AGV Mqtt回调方法- 记录Log并处理数据
  9993. /// </summary>
  9994. /// <param name="obj"></param>
  9995. private void AGVMqttShowLog(ResultData_MQTT resultData_MQTT)
  9996. {
  9997. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  9998. _AGVMqttLogNet.WriteInfo($"{datetime}->返回结果:{resultData_MQTT.ResultCode},返回信息:{resultData_MQTT.ResultMsg}");
  9999. // 接收到的信息
  10000. string topic = (string)resultData_MQTT.ResultObject1; // 订阅的标识
  10001. string jsonData = (string)resultData_MQTT.ResultObject2; // 订阅的数据
  10002. if (resultData_MQTT.ResultCode == 1 && !string.IsNullOrEmpty(topic)) // 是接收到的数据
  10003. {
  10004. }
  10005. }
  10006. #endregion 日志
  10007. /// <summary>
  10008. /// 实例化报警字典
  10009. /// </summary>
  10010. private void InitalDicAlarm()
  10011. {
  10012. #region 第一个工站(这里未区分工位,所以下面出现的‘工位代码’使用‘线别代码’代替)
  10013. List<Alarm> keyValues1 = new List<Alarm>
  10014. {
  10015. #region 第一组报警(电机)
  10016. new Alarm { 报警类型 = "电机故障", 报警详情 = "料盘搬运_Y轴电机故障" ,关联的PLC地址 = 5100 },
  10017. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_X轴电机故障" ,关联的PLC地址 = 5101 },
  10018. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_Z轴电机故障" ,关联的PLC地址 = 5102 },
  10019. new Alarm { 报警类型 = "电机故障", 报警详情 = "载具搬运_X轴电机故障" ,关联的PLC地址 = 5103 },
  10020. new Alarm { 报警类型 = "电机故障", 报警详情 = "镭射_X轴电机故障" ,关联的PLC地址 = 5104 },
  10021. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_X轴电机故障" ,关联的PLC地址 = 5105 },
  10022. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_Z轴电机故障" ,关联的PLC地址 = 5106 },
  10023. new Alarm { 报警类型 = "电机故障", 报警详情 = "下相机_X轴电机故障" ,关联的PLC地址 = 5107 },
  10024. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_Y轴电机故障" ,关联的PLC地址 = 5108 },
  10025. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_X轴电机故障" ,关联的PLC地址 = 5109 },
  10026. #endregion 第一组报警(电机)
  10027. #region 第二组报警(气缸)
  10028. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料进退气缸故障" ,关联的PLC地址 = 5200 },
  10029. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料升降气缸故障" ,关联的PLC地址 = 5201 },
  10030. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓顶升气缸故障" ,关联的PLC地址 = 5202 },
  10031. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体取料夹爪气缸故障" ,关联的PLC地址 = 5203 },
  10032. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料仓顶升气缸故障" ,关联的PLC地址 = 5204 },
  10033. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料平移气缸故障" ,关联的PLC地址 = 5205 },
  10034. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料升降气缸故障" ,关联的PLC地址 = 5206 },
  10035. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料夹爪气缸故障" ,关联的PLC地址 = 5207 },
  10036. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料旋转气缸故障" ,关联的PLC地址 = 5208 },
  10037. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装平移气缸故障" ,关联的PLC地址 = 5209 },
  10038. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装升降气缸故障" ,关联的PLC地址 = 5210 },
  10039. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装夹爪气缸故障" ,关联的PLC地址 = 5211 },
  10040. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装撑开气缸故障" ,关联的PLC地址 = 5212 },
  10041. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸1故障" ,关联的PLC地址 = 5213 },
  10042. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸2故障" ,关联的PLC地址 = 5214 },
  10043. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具下料移载气缸故障" ,关联的PLC地址 = 5215 },
  10044. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具侧推气缸故障" ,关联的PLC地址 = 5216 },
  10045. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具回流气缸故障" ,关联的PLC地址 = 5217 },
  10046. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2压料气缸故障" ,关联的PLC地址 = 5218 },
  10047. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2电测气缸故障" ,关联的PLC地址 = 5219 },
  10048. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2气密气缸故障" ,关联的PLC地址 = 5220 },
  10049. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3下压气缸故障" ,关联的PLC地址 = 5221 },
  10050. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3上顶气缸故障" ,关联的PLC地址 = 5222 },
  10051. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位5相机升降气缸故障" ,关联的PLC地址 = 5223 },
  10052. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组升降气缸故障" ,关联的PLC地址 = 5224 },
  10053. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸1故障" ,关联的PLC地址 = 5225 },
  10054. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸2故障" ,关联的PLC地址 = 5226 },
  10055. new Alarm { 报警类型 = "气缸故障", 报警详情 = "机械手夹爪气缸故障" ,关联的PLC地址 = 5227 },
  10056. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位4:镭射压料气缸故障" ,关联的PLC地址 = 5228 },
  10057. #endregion 第二组报警(气缸)
  10058. #region 第三组报警(其他故障)
  10059. new Alarm { 报警类型 = "其他故障", 报警详情 = "上料处缺料报警" ,关联的PLC地址 = 5300 },
  10060. new Alarm { 报警类型 = "其他故障", 报警详情 = "震盘缺料报警" ,关联的PLC地址 = 5301 },
  10061. new Alarm { 报警类型 = "其他故障", 报警详情 = "成品仓料满报警" ,关联的PLC地址 = 5302 },
  10062. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照超时报警" ,关联的PLC地址 = 5303 },
  10063. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照NG报警" ,关联的PLC地址 = 5304 },
  10064. new Alarm { 报警类型 = "其他故障", 报警详情 = "玻璃门打开报警" ,关联的PLC地址 = 5305 },
  10065. #endregion 第三组报警(其他故障)
  10066. };
  10067. DicAlarms_Cur.Add(GlobalContext.LineCode, keyValues1); // 这里使用线体代替工位
  10068. #endregion 第一个工站(这里使用线体代替工位)
  10069. # region 第二个工站-原来的写法(废弃)
  10070. //keyValues = new Dictionary<int, AlarmData[]>();
  10071. ////1
  10072. //dicAlarmName = new Dictionary<int, Alarm>();
  10073. //dicAlarmName.Add(0, new Alarm { Name = "M01衬套组模组X电机报警" });
  10074. //dicAlarmName.Add(1, new Alarm { Name = "M02衬套组模组Y电机报警" });
  10075. //dicAlarmName.Add(2, new Alarm { Name = "M03衬套组模组Z电机报警" });
  10076. //dicAlarmName.Add(3, new Alarm { Name = "M04衬套组模组U电机报警" });
  10077. //dicAlarmName.Add(4, new Alarm { Name = "M05外流线皮带电机报警" });
  10078. //alarmDatas = new AlarmData[dicAlarmName.Count];
  10079. //for (int i = 0; i < dicAlarmName.Count; i++)
  10080. //{
  10081. // alarmDatas[i] = new AlarmData();
  10082. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  10083. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  10084. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  10085. // alarmDatas[i].AlarmType = 1;
  10086. //}
  10087. //keyValues.Add(1, alarmDatas);
  10088. ////2
  10089. //dicAlarmName = new Dictionary<int, Alarm>();
  10090. //dicAlarmName.Add(0, new Alarm { Name = "C01定位气缸故障" });
  10091. //dicAlarmName.Add(1, new Alarm { Name = "C02左推料气缸故障" });
  10092. //dicAlarmName.Add(2, new Alarm { Name = "C03右推料气缸故障" });
  10093. //dicAlarmName.Add(3, new Alarm { Name = "C04左压料气缸故障" });
  10094. //dicAlarmName.Add(4, new Alarm { Name = "C05右压料气缸故障" });
  10095. //dicAlarmName.Add(5, new Alarm { Name = "C06切料气缸故障" });
  10096. //dicAlarmName.Add(6, new Alarm { Name = "C07左入料吹气气缸故障" });
  10097. //dicAlarmName.Add(7, new Alarm { Name = "C08右入料吹气气缸故障" });
  10098. //alarmDatas = new AlarmData[dicAlarmName.Count];
  10099. //for (int i = 0; i < dicAlarmName.Count; i++)
  10100. //{
  10101. // alarmDatas[i] = new AlarmData();
  10102. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  10103. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  10104. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  10105. // alarmDatas[i].AlarmType = 2;
  10106. //}
  10107. //keyValues.Add(2, alarmDatas);
  10108. ////3
  10109. //dicAlarmName = new Dictionary<int, Alarm>();
  10110. //dicAlarmName.Add(0, new Alarm { Name = "安全门报警" });
  10111. //dicAlarmName.Add(1, new Alarm { Name = "联机通信故障" });
  10112. //dicAlarmName.Add(2, new Alarm { Name = "连续NG报警" });
  10113. //dicAlarmName.Add(3, new Alarm { Name = "合格率低于设定值报警" });
  10114. //alarmDatas = new AlarmData[dicAlarmName.Count];
  10115. //for (int i = 0; i < dicAlarmName.Count; i++)
  10116. //{
  10117. // alarmDatas[i] = new AlarmData();
  10118. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-3";
  10119. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  10120. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  10121. // alarmDatas[i].AlarmType = 3;
  10122. //}
  10123. //keyValues.Add(3, alarmDatas);
  10124. //DicAlarms.Add(2, keyValues);
  10125. #endregion 第二个工站-原来的写法(废弃)
  10126. }
  10127. }
  10128. }