Form_Home.cs 418 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846
  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 NPOI.Util;
  15. using Sunny.UI;
  16. using MainForm.ClassFile.XiaomiAPI;
  17. using System.Diagnostics;
  18. using MainForm.Models;
  19. using SqlSugar;
  20. using EasyModbus;
  21. using ModBusClientSimple.Util;
  22. using MainForm.ClassFile.XiaomiAPI_MES;
  23. using static MainForm.ClassFile.XiaomiAPI.XiaomiMqttClient_Extend;
  24. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound;
  25. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationInbound;
  26. using EIP_Protocol;
  27. using DevComponents.DotNetBar.Controls;
  28. using ICSharpCode.SharpZipLib.Zip;
  29. using static MainForm.SQLHelper;
  30. using NPOI.SS.Formula.Functions;
  31. using MainForm.ClassFile.ProjectClass;
  32. using HslCommunication.Controls;
  33. /*
  34. * 注:本源码对外提供,所以有些地方使用中文命名方法及变量
  35. */
  36. namespace MainForm
  37. {
  38. /// <summary>
  39. /// 记录日志的委托
  40. /// </summary>
  41. /// <param name="logType">日志类型</param>
  42. /// <param name="message">日志信息</param>
  43. public delegate void HomeMessageHandler(LogType logType, string message);
  44. /// <summary>
  45. /// 主页窗体
  46. /// </summary>
  47. public partial class Form_Home : Form
  48. {
  49. #region 常量
  50. //文本常量
  51. private const string Head = "开始采集";
  52. private const string Tail = "采集完成";
  53. private const string Body = "工位出站数据";
  54. private const string BodyCheck = "工位点检数据";
  55. private const string BodyRun = "整线运行数据";
  56. private const string BodyAlarm = "整线报警数据";
  57. #endregion 常量
  58. #region 变量
  59. /// <summary>
  60. /// 委托-记录日志的方法
  61. /// </summary>
  62. public event HomeMessageHandler MessageEvent;
  63. /// <summary>
  64. /// 日志接口
  65. /// </summary>
  66. ILogNet _PLCLogNet;
  67. /// <summary>
  68. /// 用于记录MQTT日志
  69. /// </summary>
  70. ILogNet _MqttLogNet;
  71. //private int DataSwitch = 1; // 1-SQLServer;2-Excel
  72. // 定义信号量,index0给MES(true有信号,false无信号;set()让被控线程运行,Reset()让被控线程停止;WaitOne(等待时间)等待线程运行)
  73. //间隔时间
  74. private int IntervalReadPLC = 300; //ms 读PLC
  75. private int IntervalMonitorMES = 1000; //ms MES心跳
  76. private int IntervalUpHead = 1000; //ms 上位机心跳(给PLC用)
  77. private int IntervalAlarm = 1000; //ms 数据(报警)查询与设备运行信息
  78. //定义一个字典,存plc对象(通讯)
  79. //ModbusClientHelper plc1Alarm; // PLC‘运行数据’与‘报警数据’线程用ModbusTCP
  80. //Dictionary<int, ModbusClientHelper> Funs = new Dictionary<int, ModbusClientHelper>();
  81. Inovance_EIP plc1Alarm; // PLC‘运行数据’与‘报警数据’线程用ModbusTCP
  82. Dictionary<int, Inovance_EIP> Funs = new Dictionary<int, Inovance_EIP>();
  83. /// <summary>
  84. /// 上次的设备运行信息
  85. /// </summary>
  86. private string lineWorkingData1_OldStr = string.Empty;
  87. /// <summary>
  88. /// 设备报警字典-当前结果
  89. /// Dictionary<工位代码,List<报警信息>>
  90. /// </summary>
  91. private Dictionary<string, List<Alarm>> DicAlarms_Cur = new Dictionary<string, List<Alarm>>();
  92. #endregion 变量
  93. #region 窗体基础事件
  94. /// <summary>
  95. /// 初始化
  96. /// </summary>
  97. public Form_Home()
  98. {
  99. InitializeComponent();
  100. CheckForIllegalCrossThreadCalls = false; // 不检查跨线程访问
  101. _PLCLogNet = new LogNetDateTime(GlobalContext.PlcLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  102. _MqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryHour); // 按小时记录日志
  103. GlobalContext.Set += new Action(UpdateProductInfo); // 产品信息变化时更新UI
  104. }
  105. /// <summary>
  106. /// 窗体加载事件
  107. /// </summary>
  108. private void Form_Home_Load(object sender, EventArgs e)
  109. {
  110. try
  111. {
  112. AddMessage(LogType.Info, "开始初始化程序");
  113. InitalDicAlarm(); // 实例化报警字典
  114. //组建plc对象字典
  115. //plc1Alarm = new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort);
  116. //plc1Alarm = new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine1Address);
  117. if (GlobalContext.IsUsePLC1)
  118. Funs.Add(1, new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine1Address)); //OP10 壳体清洁上料装备
  119. //Funs.Add(1, new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort, 2001)); // Tray盘上料装备(板测)
  120. if (GlobalContext.IsUsePLC2)
  121. //Funs.Add(2, new ModbusClientHelper(GlobalContext.Machine2Address, GlobalContext.MachinePort, 2001)); // FCT(板测),
  122. Funs.Add(2, new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine2Address)); //OP20 顶盖上料设备
  123. if (GlobalContext.IsUsePLC3)
  124. Funs.Add(3, new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine3Address)); //OP30 点胶设备
  125. //Funs.Add(3, new ModbusClientHelper(GlobalContext.Machine3Address, GlobalContext.MachinePort, 2001)); // 值板机,
  126. if (GlobalContext.IsUsePLC4)
  127. Funs.Add(4, new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine4Address)); //OP40 3D胶线检测
  128. //Funs.Add(4, new ModbusClientHelper(GlobalContext.Machine4Address, GlobalContext.MachinePort, 2001)); // 取放桁
  129. if (GlobalContext.IsUsePLC5)
  130. Funs.Add(5, new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine5Address)); //OP50 ADD PCB板上料
  131. //Funs.Add(5, new ModbusClientHelper(GlobalContext.Machine5Address, GlobalContext.MachinePort, 2001)); //Tray盘下料装备
  132. if (GlobalContext.IsUsePLC6)
  133. Funs.Add(6, new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine6Address)); //OP60 顶盖装配
  134. if (GlobalContext.IsUsePLC7)
  135. Funs.Add(7, new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine7Address)); //OP70 锁螺丝
  136. if (GlobalContext.IsUsePLC8)
  137. Funs.Add(8, new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine8Address)); //OP80 3D螺丝高度检测,NG出料站
  138. if (GlobalContext.IsUsePLC9)
  139. Funs.Add(9, new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine9Address)); //OP90 下料站
  140. foreach (Inovance_EIP plcEIP in Funs.Values)
  141. {
  142. if (plcEIP != null)
  143. {
  144. try
  145. {
  146. (int, string) result = plcEIP.Connect();
  147. }
  148. catch (Exception ex)
  149. {
  150. MessageBox.Show($"PLC[{GlobalContext.Machine1Address}]连接失败!失败信息:" + ex.Message,
  151. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  152. }
  153. }
  154. }
  155. /*
  156. //plc1Alarm.Connect();
  157. foreach (ModbusClientHelper modbusClient in Funs.Values)
  158. {
  159. if (modbusClient != null)
  160. {
  161. try
  162. {
  163. modbusClient.Connect();
  164. }
  165. catch (Exception ex)
  166. {
  167. MessageBox.Show($"PLC[{modbusClient.IPAddress}:{modbusClient.Port}]连接失败!失败信息:" + ex.Message,
  168. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  169. }
  170. }
  171. }
  172. */
  173. // 采集任务
  174. Task TaskReadAlarm = new Task(ReadAlarmAllPLC); // 线程-获取线体报警数据
  175. List<Task> TaskReadProcess = new List<Task>(); // 线程-触发点位(PLC)的线程
  176. //TaskReadProcess.Add(new Task(() => { ReadStation_DownOrderInfo(1); })); // 下发机种
  177. if (GlobalContext.IsUsePLC1)
  178. //ReadStation_S1(1);
  179. TaskReadProcess.Add(new Task(() => { ReadStation_S1(1); })); //OP10 壳体清洁上料装备
  180. if (GlobalContext.IsUsePLC2)
  181. TaskReadProcess.Add(new Task(() => { ReadStation_S2(2); })); //OP20 顶盖上料设备
  182. if (GlobalContext.IsUsePLC3)
  183. //TaskReadProcess.Add(new Task(() => { ReadStation_S3(3); })); //OP30 点胶设备
  184. if (GlobalContext.IsUsePLC4)
  185. TaskReadProcess.Add(new Task(() => { ReadStation_S4(4); })); //OP40 点胶检测设备
  186. if (GlobalContext.IsUsePLC5)
  187. TaskReadProcess.Add(new Task(() => { ReadStation_S5(5); })); //OP50 ADD PCB板上料设备
  188. if (GlobalContext.IsUsePLC6)
  189. TaskReadProcess.Add(new Task(() => { ReadStation_S6(6); })); //OP60 顶盖装配设备
  190. if (GlobalContext.IsUsePLC7)
  191. TaskReadProcess.Add(new Task(() => { ReadStation_S7(7); })); //OP70 锁螺丝设备
  192. if (GlobalContext.IsUsePLC8)
  193. TaskReadProcess.Add(new Task(() => { ReadStation_S8(8); })); //OP80 3D螺丝高度检测设备
  194. if (GlobalContext.IsUsePLC9)
  195. TaskReadProcess.Add(new Task(() => { ReadStation_S9(9); })); //OP90 下料设备
  196. #region 初始化
  197. try
  198. {
  199. // 开启MES(Http)
  200. //bool mesret = HttpUitls.PingIP(GlobalContext.ServerHost1);
  201. //if (mesret)
  202. //{
  203. // OnMessage(LogType.Info, "MES初始连接正常");
  204. // pictureBoxMESStatus.Image = imageListState.Images[1];
  205. // GlobalContext.MESIsConnect = true;
  206. //}
  207. //else
  208. //{
  209. // OnMessage(LogType.Info, "MES初始连接失败");
  210. // pictureBoxMESStatus.Image = imageListState.Images[0];
  211. // GlobalContext.MESIsConnect = false;
  212. //}
  213. // 开启IOT(MQTT)
  214. string addr = GlobalContext.MQTTServerHost;
  215. int port = GlobalContext.MQTTServerPort;
  216. //int qmttResult = XiaomiMqttClient_Extend.OpenWithMqttServer(addr, port, GlobalContext.MqttServerPath, GlobalContext.MqttServerName);
  217. //XiaomiMqttResponse_ErrCode response_ErrCode = (XiaomiMqttResponse_ErrCode)qmttResult;
  218. //if (response_ErrCode == XiaomiMqttResponse_ErrCode.OK)
  219. //{
  220. // AddMessage(LogType.Info, "小米MQTT连接成功!--- OK");
  221. // pictureBoxMESStatus.Image = imageListState.Images[1];
  222. // GlobalContext.IOTIsConnect1 = true;
  223. // XiaomiMqttClient_Extend.SetCallbackWithDataId(CallbackWithDataId);
  224. //}
  225. //else
  226. //{
  227. // AddMessage(LogType.Info, $"小米MQTT连接失败!--- {response_ErrCode.ToString()}");
  228. // pictureBoxMESStatus.Image = imageListState.Images[0];
  229. // GlobalContext.IOTIsConnect1 = false;
  230. //}
  231. // 开启AGV HTTP
  232. //bool mesret = HttpUitls.PingIP(GlobalContext.ServerHost1);
  233. //if (mesret)
  234. //{
  235. // OnMessage(LogType.Info, "MES初始连接正常");
  236. // pictureBoxMESStatus.Image = imageListState.Images[1];
  237. // GlobalContext.MESIsConnect = true;
  238. //}
  239. //else
  240. //{
  241. // OnMessage(LogType.Info, "MES初始连接失败");
  242. // pictureBoxMESStatus.Image = imageListState.Images[0];
  243. // GlobalContext.MESIsConnect = false;
  244. //}
  245. // 开启AGV MQTT
  246. // 持续监视MES、IOT、AGV HTTP、AGV MQTT连接状态
  247. Task.Run(MonitorMESConnect);
  248. // 查询PLC连接状态
  249. foreach (int plcNo in Funs.Keys)
  250. {
  251. bool connected = Funs[plcNo].IsConnected;
  252. if (connected)
  253. {
  254. string msg = plcNo.ToString() + "工位初始连接成功---" + Funs[plcNo]._plcIPStr;
  255. AddMessage(LogType.Info, msg);
  256. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI
  257. }
  258. else
  259. {
  260. string msg = plcNo.ToString() + "工位初始连接失败---" + Funs[plcNo]._plcIPStr;
  261. AddMessage(LogType.Info, msg);
  262. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  263. }
  264. }
  265. // 开启PLC的业务处理线程-监听PLC点位+状态
  266. foreach (Task task in TaskReadProcess)
  267. {
  268. if (task != null)
  269. task.Start();
  270. }
  271. //// 开启“获取线体报警数据”的线程
  272. //TaskReadAlarm.Start();
  273. ////下传MES信息给1工位(先判断下plc对象数量)
  274. //if (Funs.Count > 1)
  275. // DownLoadProductInfo(1);
  276. AddMessage(LogType.Info, "程序初始化完成");
  277. }
  278. catch (Exception ex)
  279. {
  280. string str = ex.StackTrace;
  281. this.BeginInvoke(new Action(() =>
  282. {
  283. AddMessage(LogType.Error, "初始化PLC连接失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  284. }));
  285. }
  286. #endregion
  287. }
  288. catch (Exception ex)
  289. {
  290. string str = ex.StackTrace;
  291. OnMessage(LogType.Info, "主窗体的首页初始化出错!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
  292. if (ex.Message != null && ex.Message.Contains("timed out"))
  293. MessageBox.Show("主窗体的首页初始化出错!异常信息:PLC连接超时!" + ex.Message);
  294. else
  295. MessageBox.Show("主窗体的首页初始化出错!异常信息:" + ex.Message);
  296. }
  297. }
  298. /// <summary>
  299. /// 窗体关闭事件
  300. /// </summary>
  301. private void Form_Home_FormClosed(object sender, FormClosedEventArgs e)
  302. {
  303. Closed2();
  304. }
  305. public void Closed2()
  306. {
  307. try
  308. {
  309. XiaomiMqttClient_Extend.CloseWithMqttServer(GlobalContext.MqttServerPath, GlobalContext.MqttServerName);
  310. }
  311. catch { }
  312. }
  313. #endregion 窗体基础事件
  314. #region 监控MES状态
  315. /// <summary>
  316. /// 监控MES连接状态
  317. /// </summary>
  318. private void MonitorMESConnect()
  319. {
  320. while (true) // 运行被控线程
  321. {
  322. bool mesret = XiaomiMqttClient.IsOpen;
  323. if (mesret)
  324. {
  325. pictureBoxMESStatus.Image = imageListState.Images[1];
  326. GlobalContext.IOTIsConnect1 = true;
  327. }
  328. else
  329. {
  330. OnMessage(LogType.Info, "MES1连接失败");
  331. pictureBoxMESStatus.Image = imageListState.Images[0];
  332. GlobalContext.IOTIsConnect1 = false;
  333. }
  334. Thread.Sleep(IntervalMonitorMES);
  335. }
  336. }
  337. #endregion 监控MES连接状态
  338. #region 采集设备状态、运行数据、报警数据
  339. /// <summary>
  340. /// 请求设备状态 5000
  341. /// </summary>
  342. /// <param name="no">1</param>
  343. /// <param name="stationNameStr"></param>
  344. /// <returns>0:证明未连接到PLC;1,代表设备控制状态处于运行状态;2,代表设备控制状态处于故障状态;3,代表设备控制状态处于缺料状态;4,代表设备控制状态处于待机状态;5,代表设备控制状态处于维修状态;</returns>
  345. public int GetDeviceStatus(int plcNo, string stationNameStr = "[S0]壳体上料")
  346. {
  347. try
  348. {
  349. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  350. {
  351. short result = 0; //Funs[plcNo].ReadHoldingRegisters<short>(5000); // 5000
  352. return result;
  353. }
  354. else
  355. {
  356. return 0;
  357. }
  358. }
  359. catch (Exception ex)
  360. {
  361. string str = ex.StackTrace;
  362. AddMessage_Station(stationNameStr, LogType.Error, "请求设备状态失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  363. return 0;
  364. }
  365. }
  366. /// <summary>
  367. /// 检查是否可采集点检数据 - 不取新值
  368. /// 5000不为1时可点检
  369. /// </summary>
  370. /// <returns></returns>
  371. public bool CheckCanSpotcheck1(int deviceState)
  372. {
  373. //return true;
  374. //D5000 = 1,代表设备控制状态处于运行状态
  375. //D5000 = 2, 代表设备控制状态处于故障状态
  376. //D5000 = 3,代表设备控制状态处于缺料状态
  377. //D5000 = 4, 代表设备控制状态处于待机状态
  378. //D5000 = 5,代表设备控制状态处于维修状态
  379. return deviceState != 1;
  380. }
  381. /// <summary>
  382. /// 检查是否可采集产品数据 - 不取新值
  383. /// </summary>
  384. /// <returns></returns>
  385. public bool CheckCanCollData(int deviceState)
  386. {
  387. return deviceState == 0; // 点检时该值不为0
  388. }
  389. /// <summary>
  390. /// 获取设备报警数据与获取设备运行信息
  391. /// </summary>
  392. private async void ReadAlarmAllPLC()
  393. {
  394. // [S1] Tray盘上料装备(板测)
  395. // [S2] FCT(板测)
  396. // [S3] 值板机
  397. // [S4] 取放桁架
  398. // [S5] Tray盘下料装备
  399. /// 上位机心跳
  400. /// 获取设备报警数据与状态信息
  401. string stationNameStr = "获取设备报警数据与状态信息";
  402. while (true)
  403. {
  404. try
  405. {
  406. if (!GlobalContext._IsCon_plc1Alarm)
  407. {
  408. UpdatePLCMonitor(1, -2, 0);
  409. continue;
  410. }
  411. if (plc1Alarm.IsConnected) // 检查PLC是否已连接上
  412. {
  413. DateTime dtNow = DateTime.Now;
  414. #region 获取设备运行信息
  415. try
  416. {
  417. LineWorkingData_ThisTime lineWorkingData1 = new LineWorkingData_ThisTime();
  418. lineWorkingData1.GUID = Guid.NewGuid().ToString();
  419. lineWorkingData1.LineName = GlobalContext.LineCode;
  420. //
  421. /*
  422. lineWorkingData1.BootTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5500); // 本次开机时间(整线)D5500 h
  423. lineWorkingData1.NormalTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5502); // 本次开机运行时间(整线)D5502 h
  424. lineWorkingData1.StandbyTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5504); // 本次开机待机时间(整线)D5504 h
  425. lineWorkingData1.FaultTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5506); // 本次开机故障时间(整线)D5506 h
  426. lineWorkingData1.MaterialShortageTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5508); // 本次开机缺料时间(整线)D5508 h
  427. lineWorkingData1.MaintenanceTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5510); // 本次开机维修时间(整线)D5510 h
  428. lineWorkingData1.FaultNumber = plc1Alarm.ReadHoldingRegisters<short>(5514); // 本次开机故障停机次数(整线)D5514
  429. lineWorkingData1.OutputNumber = plc1Alarm.ReadHoldingRegisters<short>(5700); // 本次开机产量(整线) D5700
  430. lineWorkingData1.QualifiedNumber = plc1Alarm.ReadHoldingRegisters<short>(5704); // 本次开机合格数量(整线) D5704
  431. lineWorkingData1.QualifiedRate = plc1Alarm.ReadHoldingRegisters<float>(5710); // 本次开机合格率(整线) D5710
  432. lineWorkingData1.DesignRhythm = plc1Alarm.ReadHoldingRegisters<float>(5714); // 设计节拍(整线) D5714
  433. lineWorkingData1.RealityRhythm = plc1Alarm.ReadHoldingRegisters<float>(5716); // 本次开机实际节拍(整线) D5716
  434. */
  435. lineWorkingData1.CreateTime = DateTime.Now;
  436. string lineWorkingData1_Str = JsonConvert.SerializeObject(lineWorkingData1);
  437. // UI展示-展示到设备状态页
  438. if (string.IsNullOrEmpty(lineWorkingData1_OldStr)) // 软件启动后第一次运行
  439. {
  440. // 查询数据库最新一条数据,确定是不是更新
  441. string qSql = @"SELECT top(1) [GUID]
  442. ,[LineName]
  443. ,[BootTimeLong]
  444. ,[NormalTimeLong]
  445. ,[StandbyTimeLong]
  446. ,[FaultTimeLong]
  447. ,[MaterialShortageTimeLong]
  448. ,[MaintenanceTimeLong]
  449. ,[FaultNumber]
  450. ,[OutputNumber]
  451. ,[QualifiedNumber]
  452. ,[QualifiedRate]
  453. ,[DesignRhythm]
  454. ,[RealityRhythm]
  455. ,[CreateTime]
  456. FROM [LineWorkingData]
  457. where [CreateTime] > '{0}'
  458. and [LineName]='{1}'
  459. order by [CreateTime] desc
  460. ";
  461. qSql = string.Format(qSql, DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00", lineWorkingData1.LineName);
  462. var ds = SQLHelper_New.Query(qSql, null);
  463. if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  464. {
  465. var dataDBlast = new LineWorkingData_ThisTime();
  466. dataDBlast.GUID = ds.Tables[0].Rows[0][0].ToString(); // 主键
  467. dataDBlast.LineName = ds.Tables[0].Rows[0][1].ToString(); // 线体名称
  468. dataDBlast.BootTimeLong = Convert.ToSingle(ds.Tables[0].Rows[0][2].ToString()); // 本次开机时间(整线)
  469. dataDBlast.CreateTime = Convert.ToDateTime(ds.Tables[0].Rows[0][14].ToString()); // 创建时间
  470. if (lineWorkingData1.BootTimeLong > dataDBlast.BootTimeLong) // 需要更新的情况;不需要更新的走后面的插入
  471. {
  472. dataDBlast.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  473. dataDBlast.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  474. dataDBlast.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  475. dataDBlast.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  476. dataDBlast.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  477. dataDBlast.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  478. dataDBlast.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  479. dataDBlast.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  480. dataDBlast.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  481. dataDBlast.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  482. dataDBlast.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  483. dataDBlast.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  484. string usql = dataDBlast.ToStringUpdate();
  485. SQLHelper_New.ExecuteSQL(usql, null);
  486. lineWorkingData1_OldStr = JsonConvert.SerializeObject(dataDBlast);
  487. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  488. //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  489. }
  490. }
  491. else
  492. {
  493. // 插入
  494. SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  495. lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  496. AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  497. //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  498. }
  499. }
  500. else if (!lineWorkingData1_Str.Equals(lineWorkingData1_OldStr)) // 非“软件启动后第一次运行”
  501. {
  502. LineWorkingData_ThisTime lineWorkingData1_Old = string.IsNullOrEmpty(lineWorkingData1_OldStr) ? lineWorkingData1 : JsonConvert.DeserializeObject<LineWorkingData_ThisTime>(lineWorkingData1_OldStr); // 上次的状态信息
  503. //// 本次开机设备运行情况
  504. //LineWorkingData1_ThisTime lineWorkingData_UI = JsonConvert.DeserializeObject<LineWorkingData1_ThisTime>(lineWorkingData1_OldStr);
  505. //Task.Run(() =>
  506. //{
  507. // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  508. // {
  509. // Form_Main.formDevAlarm.UpdDeviceStatus_ThisTime(lineWorkingData_UI); // UI更新
  510. // }
  511. //});
  512. // 本日设备运行情况
  513. // 存数据库(开机时间>上次的开机时间,则更新上次记录;<则作为新数据插入)
  514. if (lineWorkingData1.BootTimeLong > lineWorkingData1_Old.BootTimeLong)
  515. {
  516. // 更新
  517. lineWorkingData1_Old.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  518. lineWorkingData1_Old.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  519. lineWorkingData1_Old.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  520. lineWorkingData1_Old.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  521. lineWorkingData1_Old.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  522. lineWorkingData1_Old.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  523. lineWorkingData1_Old.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  524. lineWorkingData1_Old.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  525. lineWorkingData1_Old.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  526. lineWorkingData1_Old.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  527. lineWorkingData1_Old.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  528. lineWorkingData1_Old.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  529. SQLHelper_New.ExecuteSQL(lineWorkingData1_Old.ToStringUpdate(), null);
  530. lineWorkingData1_OldStr = JsonConvert.SerializeObject(lineWorkingData1_Old);
  531. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  532. //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  533. }
  534. else if (lineWorkingData1.BootTimeLong < lineWorkingData1_Old.BootTimeLong)
  535. {
  536. // 插入
  537. SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  538. lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  539. AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  540. //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  541. }
  542. await Task.Run(() =>
  543. {
  544. try
  545. {
  546. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  547. {
  548. Form_Main.formDevAlarm.UpdDeviceStatus_Today(); // UI更新
  549. }
  550. }
  551. catch { }
  552. });
  553. }
  554. }
  555. catch (Exception ex)
  556. {
  557. string str = ex.StackTrace;
  558. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取设备运行信息出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  559. }
  560. #endregion 获取设备运行信息
  561. #region 报警数据
  562. try
  563. {
  564. List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
  565. bool isNeedUpdUI = false; // 是否需要更新历史报警UI
  566. // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
  567. var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.LineCode];
  568. for (int i = 0; i < dicAlarms_Cur_PLC1.Count; i++) // 读取
  569. {
  570. short shortBuf = 0;// plc1Alarm.ReadHoldingRegisters<short>(dicAlarms_Cur_PLC1[i].关联的PLC地址);
  571. dicAlarms_Cur_PLC1[i].是否报警 = shortBuf != 0;
  572. if (dicAlarms_Cur_PLC1[i].上次的运行状态 != dicAlarms_Cur_PLC1[i].是否报警)
  573. {
  574. isNeedUpdUI = true; // 需要更新历史报警UI信息
  575. // 记录
  576. dicAlarms_Cur_PLC1[i].上次的运行状态 = dicAlarms_Cur_PLC1[i].是否报警;
  577. switch (dicAlarms_Cur_PLC1[i].是否报警)
  578. {
  579. case true: // 报警
  580. dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  581. {
  582. GUID = Guid.NewGuid().ToString(),
  583. LineName = GlobalContext.LineCode, // 线体
  584. AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  585. AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  586. StartTime = dtNow // 开始时间
  587. };
  588. // 传输到页面
  589. deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
  590. {
  591. 线体名称 = dicAlarms_Cur_PLC1[i].报警数据.LineName,
  592. 报警类型 = dicAlarms_Cur_PLC1[i].报警数据.AlarmType,
  593. 报警内容 = dicAlarms_Cur_PLC1[i].报警数据.AlarmDesc,
  594. 开始时间 = dtNow
  595. });
  596. // 新增到数据库
  597. var data1 = dicAlarms_Cur_PLC1[i].报警数据;
  598. SaveAlarmDataByDB(stationNameStr, data1, false);
  599. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  600. break;
  601. case false: // 消除报警
  602. if (dicAlarms_Cur_PLC1[i].报警数据 == null || string.IsNullOrEmpty(dicAlarms_Cur_PLC1[i].报警数据.GUID))
  603. {
  604. dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  605. {
  606. GUID = Guid.NewGuid().ToString(),
  607. LineName = GlobalContext.LineCode, // 线体
  608. AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  609. AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  610. StartTime = dtNow, // 开始时间
  611. EndTime = dtNow, // 开始时间
  612. PersistTime = 1, // 耗时1s
  613. };
  614. // 新增
  615. var data2 = dicAlarms_Cur_PLC1[i].报警数据;
  616. SaveAlarmDataByDB(stationNameStr, data2, false);
  617. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  618. }
  619. else
  620. {
  621. dicAlarms_Cur_PLC1[i].报警数据.EndTime = dtNow; // 开始时间
  622. dicAlarms_Cur_PLC1[i].报警数据.PersistTime = Convert.ToInt32((dicAlarms_Cur_PLC1[i].报警数据.EndTime
  623. - dicAlarms_Cur_PLC1[i].报警数据.StartTime).TotalSeconds); // 耗时s
  624. // 修改
  625. var data3 = dicAlarms_Cur_PLC1[i].报警数据;
  626. SaveAlarmDataByDB(stationNameStr, data3, true);
  627. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  628. }
  629. break;
  630. default:
  631. break;
  632. }
  633. }
  634. }
  635. DicAlarms_Cur[GlobalContext.LineCode] = dicAlarms_Cur_PLC1;
  636. // 有新报警则更新
  637. if (isNeedUpdUI)
  638. {
  639. // UI展示 - 展示到设备状态页
  640. await Task.Run(() =>
  641. {
  642. try
  643. {
  644. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
  645. {
  646. Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
  647. if (Form_Main.formDevAlarm.Visible)
  648. {
  649. Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
  650. }
  651. }
  652. }
  653. catch { }
  654. });
  655. }
  656. }
  657. catch (Exception ex)
  658. {
  659. string str = ex.StackTrace;
  660. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  661. }
  662. #endregion 报警数据
  663. UpdatePLCMonitor(1, -2, 1);
  664. }
  665. else
  666. {
  667. UpdatePLCMonitor(1, -2, 0);
  668. }
  669. }
  670. catch (Exception ex)
  671. {
  672. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  673. }
  674. Thread.Sleep(IntervalAlarm);
  675. }
  676. }
  677. #endregion 轮询PLC
  678. #region 下发订单信息
  679. ///// <summary>
  680. ///// 壳体上料(下发工单)的交互逻辑
  681. ///// </summary>
  682. ///// <param name="no"></param>
  683. ///// <exception cref="NotImplementedException"></exception>
  684. //private void ReadStation_DownOrderInfo(int plcNo)
  685. //{
  686. // // [S1] Tray盘上料装备(板测)
  687. // // [S2] FCT(板测)
  688. // // [S3] 值板机
  689. // // [S4] 取放桁架
  690. // // [S5] Tray盘下料装备
  691. // /// 上位机心跳
  692. // /// 获取设备报警数据与状态信息
  693. // string stationNameStr = "[S0]壳体上料";
  694. // while (true)
  695. // {
  696. // try
  697. // {
  698. // if (!GlobalContext._IsCon_Funs1)
  699. // {
  700. // UpdatePLCMonitor(plcNo, 0);
  701. // continue;
  702. // }
  703. // if (Funs[plcNo].isConnected) // 检查PLC是否已连接上
  704. // {
  705. // #region 壳体上料(下发工单)
  706. // try
  707. // {
  708. // Funs[plcNo].Read_Int_Tag("500", 1, out short[] iiMes0);
  709. // Funs[plcNo].Read_Int_Tag("501", 1, out short[] iiPlc0);
  710. // bool mES_FLAG_1 = iiMes0[0] == 1 ? true : false; // MES_FLAG_1
  711. // bool pLC_Flag_1 = iiPlc0[0] == 1 ? true : false; // PLC_FLAG_1
  712. // // 重置数据和信号
  713. // if (mES_FLAG_1 && pLC_Flag_1) // 1 1
  714. // {
  715. // // 清空写给PLC的数据
  716. // int[] i497 = new int[1] { 0 };
  717. // Funs[plcNo].Write_DInt_Tag("497", 1, i497); // SN号(数字部分)重置信号
  718. // // MES_Flag重置为0
  719. // int[] i500 = new int[1] { 0 };
  720. // Funs[plcNo].Write_DInt_Tag("500", 1, i500); // MES_FLAG_1
  721. // }
  722. // }
  723. // catch (Exception ex)
  724. // {
  725. // string str = ex.StackTrace;
  726. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}下发订单信息运行出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  727. // }
  728. // #endregion 壳体上料(下发工单)
  729. // UpdatePLCMonitor(plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  730. // }
  731. // else
  732. // {
  733. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  734. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  735. //
  736. // Funs[plcNo].Connect();
  737. // }
  738. // }
  739. // catch (Exception ex)
  740. // {
  741. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  742. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  743. //
  744. // Funs[plcNo].ReConnect();
  745. // }
  746. // Thread.Sleep(IntervalReadPLC);
  747. // }
  748. //}
  749. ///// <summary>
  750. ///// 下发订单信息到PLC
  751. ///// </summary>
  752. ///// <param name="no">PLC编号</param>
  753. //private void DownLoadProductInfo(int plcNo, string stationNameStr = "[S0]壳体上料")
  754. //{
  755. // try
  756. // {
  757. // if (!string.IsNullOrEmpty(GlobalContext.Mtltmrk))
  758. // {
  759. // Funs[plcNo].Write_String_Tag("568", 1, GlobalContext.Mtltmrk); // 产品型号(mtltmrk)
  760. // WritePLCLog(LogType.Debug, GlobalContext.Mtltmrk);
  761. // }
  762. // Funs[plcNo].Write_DInt_Tag("500", 1, new Int32[1] { 1 }); // MES_FLAG_1
  763. // }
  764. // catch (Exception ex)
  765. // {
  766. // string str = ex.StackTrace;
  767. // AddMessage_Station(stationNameStr, LogType.Error, "下发订单信息到PLC失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  768. // }
  769. //}
  770. /// <summary>
  771. /// 下发清料信号
  772. /// </summary>
  773. /// <param name="no">PLC编号</param>
  774. public bool ClearProducts(int plcNo, string stationNameStr = "[S0]壳体上料")
  775. {
  776. try
  777. {
  778. //Funs[plcNo].ReadHoldingRegisters<int>(496); //
  779. AddMessage_Station(stationNameStr, LogType.Info, "下发了清料信号!");
  780. return true;
  781. }
  782. catch (Exception ex)
  783. {
  784. string str = ex.StackTrace;
  785. AddMessage_Station(stationNameStr, LogType.Error, "下发清料信号失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  786. return false;
  787. }
  788. }
  789. #endregion 下发订单信息
  790. #region PLC1 贲流
  791. #region [S1] 壳体清洁上料装备
  792. /// <summary>
  793. /// S1工位的数据- 触发信号上次的值
  794. /// </summary>
  795. private Dictionary<string, object> s1PLCSignal_Old = new Dictionary<string, object>();
  796. /// <summary>
  797. /// S1工位的数据(含触发信号)
  798. /// </summary>
  799. private Dictionary<string, object> s1PLCData = new Dictionary<string, object>();
  800. /// <summary>
  801. /// S1工位的数据- 回写点位
  802. /// </summary>
  803. private Dictionary<string, WriteToPLC_Flag> s1PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  804. ///// <summary>
  805. ///// 触发信号
  806. ///// </summary>
  807. //private ManualResetEvent[] MreTasks;
  808. /// <summary>
  809. /// [S1] 壳体清洁上料装备
  810. /// </summary>
  811. /// <param name="plcNo">PLC编号</param>
  812. private void ReadStation_S1(int plcNo)
  813. {
  814. string stationCode = "[S1]";
  815. string stationName = "壳体清洁上料";
  816. string stationNameStr = stationCode + stationName;
  817. string tagBaseName = "g_OP10_MES"; //标签变量名称
  818. string tagMesCommName = "mesCommToPC"; //标签变量名称
  819. string tagAgvCommName = "agvCommFrmPC";
  820. string tagBarsetName = "BarcodeSet";
  821. OP10_MesData_t stPLC_MesData; //PLC的MES数据
  822. (int, string) result;
  823. bool ProgressState = true;
  824. #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  825. // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  826. s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  827. s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  828. s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  829. s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  830. s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  831. s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  832. s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  833. s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  834. s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  835. // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  836. s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  837. s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
  838. s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
  839. s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  840. s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
  841. s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
  842. s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  843. s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
  844. s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
  845. s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
  846. s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
  847. s1PLCData.Add("a1Result", 0); // 产品结果
  848. s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  849. s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
  850. s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
  851. s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
  852. s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
  853. s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  854. s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
  855. s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  856. s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  857. s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
  858. s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  859. s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  860. s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
  861. s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
  862. s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  863. s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
  864. s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
  865. #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  866. while (true)
  867. {
  868. try
  869. {
  870. if (!GlobalContext._IsCon_Funs1)
  871. {
  872. UpdatePLCMonitor(1, plcNo, 0);
  873. continue;
  874. }
  875. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  876. {
  877. Stopwatch stopwatch1 = new Stopwatch();
  878. Stopwatch stopwatch2 = new Stopwatch();
  879. stopwatch1.Start();
  880. stopwatch2.Start();
  881. #region 一次性读取所有数据
  882. // 一次性读取所有数据
  883. result = Funs[plcNo].Read_SingleTag<OP10_MesData_t>(tagBaseName, 1, out stPLC_MesData); //读取单个结构体数据
  884. if (result.Item1 != 0)
  885. {
  886. //richTextBox1.AppendText("\n" + strRet);
  887. }
  888. else
  889. {
  890. //richTextBox1.AppendText("\n" + "读取成功");
  891. }
  892. #endregion 一次性读取所有数据
  893. stopwatch2.Stop();
  894. #region 进站
  895. try
  896. {
  897. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation && ProgressState == true)
  898. {
  899. ProgressState = false;
  900. Task.Run(() => S1进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName,out ProgressState));
  901. }
  902. }
  903. catch (Exception ex)
  904. {
  905. ProgressState = false;
  906. string str = ex.StackTrace;
  907. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  908. }
  909. #endregion 进站
  910. #region 出站
  911. try
  912. {
  913. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation && ProgressState == true)
  914. {
  915. ProgressState = false;
  916. Task.Run(() => S1出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName,out ProgressState));
  917. }
  918. }
  919. catch (Exception ex)
  920. {
  921. string str = ex.StackTrace;
  922. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  923. }
  924. #endregion 进站
  925. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  926. stopwatch1.Stop();
  927. OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  928. }
  929. else
  930. {
  931. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  932. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  933. Funs[plcNo].Connect(); // 重连
  934. }
  935. }
  936. catch (Exception ex)
  937. {
  938. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  939. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  940. }
  941. Thread.Sleep(IntervalReadPLC);
  942. }
  943. }
  944. /// <summary>
  945. /// [S1] 壳体清洁上料 - 进站
  946. /// </summary>
  947. /// <param name="plcNo">PLC编号</param>
  948. /// <param name="stationNameStr">工站全称</param>
  949. /// <param name="stPLC_MesData"></param>
  950. /// <param name="tagMesCommName"></param>
  951. private void S1进站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName,out bool ProgressState)
  952. {
  953. int nRet=0;
  954. string strRet = "";
  955. Stopwatch stopwatch1 = new Stopwatch();
  956. Stopwatch stopwatch2 = new Stopwatch();
  957. ProgressState = true;
  958. try
  959. {
  960. stopwatch1.Start();
  961. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  962. string MachineId = GlobalContext.S1_MachineId; // 装备ID(可配置)
  963. string StationId = GlobalContext.S1_StationId; // 工位ID(可配置)
  964. // 产品SN(物料码)校验
  965. List<TestItem> item = new List<TestItem>();
  966. stopwatch2.Start();
  967. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  968. stopwatch2.Stop();
  969. //指令执行结果 1:OK 110:失败
  970. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  971. //进站结果写入PLC
  972. CommandFromPLC resultToPlC = new CommandFromPLC();
  973. resultToPlC.cmd = 0;
  974. resultToPlC.cmdParam = 0; //指令参数
  975. resultToPlC.cmdResult = mesResultFrmWeb;
  976. WriteResultToPlc(plcNo,stationNameStr, tagMesCommName,1, resultToPlC);
  977. }
  978. catch (Exception ex)
  979. {
  980. string str = ex.StackTrace;
  981. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  982. CommandFromPLC resultToPlC = new CommandFromPLC();
  983. resultToPlC.cmd = 0;
  984. resultToPlC.cmdParam = 0; //指令参数
  985. resultToPlC.cmdResult = 110;
  986. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  987. }
  988. stopwatch1.Stop();
  989. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  990. }
  991. /// <summary>
  992. /// 进出站结果写入PLC
  993. /// </summary>
  994. public void WriteResultToPlc(int plcNo,string stationNameStr,string strTagName, int nCount, CommandFromPLC resultToPlC)
  995. {
  996. int i = 0;
  997. int nRet = 0;
  998. string strRet = "";
  999. while (i < 3) // 最多上传三次
  1000. {
  1001. (nRet, strRet) = Funs[plcNo].Write_SingleTag<CommandFromPLC>(strTagName, nCount, resultToPlC);
  1002. if (nRet == 0) //成功
  1003. {
  1004. break;
  1005. }
  1006. else
  1007. {
  1008. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站结果写入PLC出错!错误信息:" + strRet);
  1009. i++;
  1010. }
  1011. }
  1012. }
  1013. /// <summary>
  1014. /// [S1] 壳体清洁上料 - 出站接口
  1015. /// </summary>
  1016. private void S1出站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName,string stationCode,string stationName, out bool ProgressState)
  1017. {
  1018. ProgressState = true;
  1019. Stopwatch stopwatch1 = new Stopwatch();
  1020. Stopwatch stopwatch2 = new Stopwatch();
  1021. try
  1022. {
  1023. stopwatch1.Start();
  1024. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  1025. string processItem = stationName; // 测试项目
  1026. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  1027. string supplierCode = ""; // 供应商代码
  1028. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  1029. string batch_num = GlobalContext.BatchNumber; // 批次号
  1030. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  1031. string sn=(string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  1032. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1033. string MachineId = GlobalContext.S1_MachineId; // 装备id(可配置) // ZS
  1034. string StationId = GlobalContext.S1_StationId; // ⼯位ID(可配置) // ZS
  1035. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  1036. bool pass = a1Result == 1;
  1037. List<TestItem> items = new List<TestItem>();
  1038. items.Add(new TestItem()
  1039. {
  1040. Parameter_name = "载具码",
  1041. Parameter_value = CarrierBarcode,
  1042. Parameter_unit = ""
  1043. });
  1044. items.Add(new TestItem()
  1045. {
  1046. Parameter_name = "产品码",
  1047. Parameter_value = mtltmrk,
  1048. Parameter_unit = ""
  1049. });
  1050. //绑定载具和产品
  1051. ResponseMessage message = new ResponseMessage();
  1052. message= SQLHelper.InsertCarrierBind(CarrierBarcode, CarrierBarcode, stationNameStr);
  1053. if (message.result==false)
  1054. {
  1055. AddMessage(LogType.Info, stationNameStr + "_载具码与产品码绑定失败");
  1056. }
  1057. //绑定PLC返回MES数据到本地
  1058. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  1059. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId);
  1060. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  1061. stopwatch2.Start();
  1062. //进站结果写入PLC
  1063. CommandFromPLC resultToPlC = new CommandFromPLC();
  1064. resultToPlC.cmd = 0;
  1065. resultToPlC.cmdParam = 0; //指令参数
  1066. resultToPlC.cmdResult = mesResultFrmWeb;
  1067. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1068. stopwatch2.Stop();
  1069. WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-Write" + (result1 == 1 ? "成功!" : "失败!"));
  1070. }
  1071. catch (Exception ex)
  1072. {
  1073. stopwatch2.Start();
  1074. CommandFromPLC resultToPlC = new CommandFromPLC();
  1075. resultToPlC.cmd = 0;
  1076. resultToPlC.cmdParam = 0; //指令参数
  1077. resultToPlC.cmdResult = 110;
  1078. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1079. stopwatch2.Stop();
  1080. string str = ex.StackTrace;
  1081. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{stationNameStr}]上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1082. }
  1083. stopwatch1.Stop();
  1084. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1085. }
  1086. //// 上传点检数据_ [S1] Tray盘上料装备(板测)
  1087. //private void DoOneCheckData_Tray盘上料装备(int plcNo, string stationCode, string stationName)
  1088. //{
  1089. // string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  1090. // string stationNameStr = stationCode + stationName;
  1091. // string processItem = stationName; // 测试项目
  1092. // try
  1093. // {
  1094. // string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  1095. // string accno = "1"; // 工序编号
  1096. // Funs[plcNo].Read_Real_Tag("896", 1, out float[] float0);
  1097. // float travelLimitUp = float0[0]; // 胶圈装配行程设定上限
  1098. // List<OneCheckItem> items = new List<OneCheckItem>()
  1099. // {
  1100. // new OneCheckItem()
  1101. // {
  1102. // Onecheck_name="胶圈装配行程设定上限",
  1103. // Onecheck_content="上限值",
  1104. // Onecheck_result=$"正常|胶圈装配行程设定上限{travelLimitUp} mm"
  1105. // },
  1106. // };
  1107. // OneCheckData oneCheckData = new OneCheckData()
  1108. // {
  1109. // Line_code = GlobalContext.LineCode,
  1110. // Line_name = GlobalContext.LineName,
  1111. // Equipment_code = equipmentCode,
  1112. // Equipment_name = equipmentCode,
  1113. // Workorder_code = workorder_code,
  1114. // Procedure_code = accno,
  1115. // Procedure_name = processItem,
  1116. // Oneckeck_values = items,
  1117. // Onecheck_empcode = "",
  1118. // Onecheck_empname = "",
  1119. // Onecheck_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  1120. // };
  1121. // int result1 = SaveOneCheckDataByDBAndSubmit(oneCheckData, equipmentCode, processItem);
  1122. // //int result = result1 == 1 ? 1 : (GlobalContext.IsSendCheckOneData ? 4 : 1);
  1123. // short result = result1 == 1 ? (short)1 : (short)2;
  1124. // // MES_Flag 为4MES报错
  1125. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { result });
  1126. // WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  1127. // }
  1128. // catch (Exception ex)
  1129. // {
  1130. // // MES_Flag 为2上位机报错
  1131. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  1132. // string str = ex.StackTrace;
  1133. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}点检报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1134. // }
  1135. //}
  1136. // ReadStation_S1_2 节拍接口+AGV
  1137. /// <summary>
  1138. /// [S1] Tray盘上料装备(板测)- 将SN发给ICT标机(串口)
  1139. /// </summary>
  1140. /// <param name="plcNo">PLC编号</param>
  1141. /// <param name="stationNameStr">工站全称</param>
  1142. private void S1将SN发给ICT标机(int plcNo, string stationNameStr)
  1143. {
  1144. Stopwatch stopwatch1 = new Stopwatch();
  1145. Stopwatch stopwatch2 = new Stopwatch();
  1146. try
  1147. {
  1148. stopwatch1.Start();
  1149. string a1ProductSN_ICT = (string)s1PLCData["a1ProductSN_ICT"]; // 产品SN(载具SN)
  1150. a1ProductSN_ICT = a1ProductSN_ICT.Replace("\0", "");
  1151. string a1PartNo1_ICT = (string)s1PLCData["a1PartNo1_ICT"]; // 物料码1(穴位1)
  1152. a1PartNo1_ICT = a1PartNo1_ICT.Replace("\0", "");
  1153. string a1PartNo2_ICT = (string)s1PLCData["a1PartNo2_ICT"]; // 物料码2(穴位2)
  1154. a1PartNo2_ICT = a1PartNo2_ICT.Replace("\0", "");
  1155. // ZS 将SN发给ICT标机(串口)
  1156. short a1MES_FLAG_ICT = 1;
  1157. stopwatch2.Start();
  1158. // MES_Flag
  1159. //Funs[plcNo].WriteMultipleRegisters<short>(2182, a1MES_FLAG_ICT); // 上位机发送1代表OK;2代表失败;4代表上位机报警;
  1160. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  1161. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  1162. writeToPLC_Flag.Adress = 2182;
  1163. writeToPLC_Flag.Value = a1MES_FLAG_ICT;
  1164. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  1165. stopwatch2.Stop();
  1166. }
  1167. catch (Exception ex)
  1168. {
  1169. string str = ex.StackTrace;
  1170. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1171. stopwatch2.Start();
  1172. // MES_Flag
  1173. //Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  1174. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  1175. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  1176. writeToPLC_Flag.Adress = 2182;
  1177. writeToPLC_Flag.Value = (short)4;
  1178. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  1179. stopwatch2.Stop();
  1180. }
  1181. stopwatch1.Stop();
  1182. AddMessage(LogType.Info, stationNameStr + "_将SN发给ICT标机;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1183. }
  1184. /// <summary>
  1185. /// [S1] Tray盘上料装备(板测)- 节拍接口
  1186. /// </summary>
  1187. /// <param name="plcNo">PLC编号</param>
  1188. /// <param name="stationNameStr">工站全称</param>
  1189. private void S1节拍接口(int plcNo, string stationNameStr)
  1190. {
  1191. Stopwatch stopwatch1 = new Stopwatch();
  1192. Stopwatch stopwatch2 = new Stopwatch();
  1193. string resultStr = string.Empty;
  1194. try
  1195. {
  1196. stopwatch1.Start();
  1197. string oEEType = ((int)s1PLCData["a1OEEType"]).ToString(); // 节拍类型(plc写入)
  1198. string a1OEEPartNo = (string)s1PLCData["a1OEEPartNo"]; // 物料码
  1199. a1OEEPartNo = a1OEEPartNo.Replace("\0", "");
  1200. string a1OEEVehicleCode = (string)s1PLCData["a1OEEVehicleCode"]; // 载具SN
  1201. a1OEEVehicleCode = a1OEEVehicleCode.Replace("\0", "");
  1202. string a1OEEPartNum = ((int)s1PLCData["a1OEEPartNum"]).ToString(); // 穴位号
  1203. a1OEEPartNum = a1OEEPartNum.Replace("\0", "");
  1204. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  1205. if (!actionBool)
  1206. {
  1207. stopwatch2.Start();
  1208. // MES_Flag
  1209. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  1210. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  1211. writeToPLC_Flag1.Name = "a1OEEMES_FLAG";
  1212. writeToPLC_Flag1.Adress = 2254;
  1213. writeToPLC_Flag1.Value = (short)1;
  1214. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag1);
  1215. stopwatch2.Stop();
  1216. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1217. return;
  1218. }
  1219. if (string.IsNullOrEmpty(a1OEEPartNo) && string.IsNullOrEmpty(a1OEEVehicleCode))
  1220. {
  1221. stopwatch2.Start();
  1222. // MES_Flag
  1223. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  1224. WriteToPLC_Flag writeToPLC_Flag2 = new WriteToPLC_Flag(); // MES_Flag
  1225. writeToPLC_Flag2.Name = "a1OEEMES_FLAG";
  1226. writeToPLC_Flag2.Adress = 2254;
  1227. writeToPLC_Flag2.Value = (short)1;
  1228. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag2);
  1229. stopwatch2.Stop();
  1230. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1231. return;
  1232. }
  1233. else if (string.IsNullOrEmpty(a1OEEPartNo) && !string.IsNullOrEmpty(a1OEEVehicleCode))
  1234. { // 查产品SN
  1235. a1OEEPartNo = "Test"; // ZS
  1236. }
  1237. short a1OEEMES_FLAG = 0;
  1238. // 上传OEE
  1239. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a1OEEPartNo, a1OEEVehicleCode);
  1240. a1OEEMES_FLAG = result.Item1;
  1241. resultStr = result.Item2;
  1242. stopwatch2.Start();
  1243. // MES_Flag
  1244. //Funs[plcNo].WriteMultipleRegisters<short>(2254, a1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  1245. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  1246. writeToPLC_Flag.Name = "a1OEEMES_FLAG";
  1247. writeToPLC_Flag.Adress = 2254;
  1248. writeToPLC_Flag.Value = a1OEEMES_FLAG;
  1249. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
  1250. stopwatch2.Stop();
  1251. }
  1252. catch (Exception ex)
  1253. {
  1254. string str = ex.StackTrace;
  1255. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1256. // MES_Flag
  1257. stopwatch2.Start();
  1258. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  1259. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  1260. writeToPLC_Flag.Name = "a1OEEMES_FLAG";
  1261. writeToPLC_Flag.Adress = 2254;
  1262. writeToPLC_Flag.Value = (short)4;
  1263. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
  1264. stopwatch2.Stop();
  1265. }
  1266. stopwatch1.Stop();
  1267. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1268. }
  1269. /// <summary>
  1270. /// [S1] Tray盘上料装备(板测)- AGV上料叫agv
  1271. /// </summary>
  1272. /// <param name="plcNo">PLC编号</param>
  1273. /// <param name="stationNameStr">工站全称</param>
  1274. private void S1AGV上料叫agv(int plcNo, string stationNameStr)
  1275. {
  1276. Stopwatch stopwatch1 = new Stopwatch();
  1277. Stopwatch stopwatch2 = new Stopwatch();
  1278. try
  1279. {
  1280. stopwatch1.Start();
  1281. // ZS 呼叫AGV
  1282. short a1AGVUpCall = 2;
  1283. stopwatch2.Start();
  1284. // a1AGVUpCall
  1285. //Funs[plcNo].WriteMultipleRegisters<short>(2307, a1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  1286. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  1287. writeToPLC_Flag.Name = "a1AGVUpCall";
  1288. writeToPLC_Flag.Adress = 2307;
  1289. writeToPLC_Flag.Value = a1AGVUpCall;
  1290. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  1291. stopwatch2.Stop();
  1292. }
  1293. catch (Exception ex)
  1294. {
  1295. string str = ex.StackTrace;
  1296. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1297. // a1AGVUpCall
  1298. stopwatch2.Start();
  1299. //Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  1300. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  1301. writeToPLC_Flag.Name = "a1AGVUpCall";
  1302. writeToPLC_Flag.Adress = 2307;
  1303. writeToPLC_Flag.Value = (short)4;
  1304. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  1305. stopwatch2.Stop();
  1306. }
  1307. stopwatch1.Stop();
  1308. AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1309. }
  1310. /// <summary>
  1311. /// [S1] Tray盘上料装备(板测)- AGV上料完成
  1312. /// </summary>
  1313. /// <param name="plcNo">PLC编号</param>
  1314. /// <param name="stationNameStr">工站全称</param>
  1315. private void S1AGV上料完成(int plcNo, string stationNameStr)
  1316. {
  1317. Stopwatch stopwatch1 = new Stopwatch();
  1318. Stopwatch stopwatch2 = new Stopwatch();
  1319. try
  1320. {
  1321. stopwatch1.Start();
  1322. // ZS AGV上料完成,让小车离开
  1323. short a1AGVUpEnd = 2;
  1324. stopwatch2.Start();
  1325. // a1AGVUpEnd
  1326. //Funs[plcNo].WriteMultipleRegisters<short>(2309, a1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  1327. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  1328. writeToPLC_Flag.Name = "a1AGVUpEnd";
  1329. writeToPLC_Flag.Adress = 2309;
  1330. writeToPLC_Flag.Value = a1AGVUpEnd;
  1331. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  1332. stopwatch2.Stop();
  1333. }
  1334. catch (Exception ex)
  1335. {
  1336. string str = ex.StackTrace;
  1337. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1338. // a1AGVUpEnd
  1339. stopwatch2.Start();
  1340. //Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  1341. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  1342. writeToPLC_Flag.Name = "a1AGVUpEnd";
  1343. writeToPLC_Flag.Adress = 2309;
  1344. writeToPLC_Flag.Value = (short)4;
  1345. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  1346. stopwatch2.Stop();
  1347. }
  1348. stopwatch1.Stop();
  1349. AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1350. }
  1351. /// <summary>
  1352. /// [S1] Tray盘上料装备(板测)- AGV下料叫agv
  1353. /// </summary>
  1354. /// <param name="plcNo">PLC编号</param>
  1355. /// <param name="stationNameStr">工站全称</param>
  1356. private void S1AGV下料叫agv(int plcNo, string stationNameStr)
  1357. {
  1358. Stopwatch stopwatch1 = new Stopwatch();
  1359. Stopwatch stopwatch2 = new Stopwatch();
  1360. try
  1361. {
  1362. stopwatch1.Start();
  1363. // ZS 呼叫AGV
  1364. short a1AGVDownCall = 2;
  1365. stopwatch2.Start();
  1366. // a1AGVDownCall
  1367. //Funs[plcNo].WriteMultipleRegisters<short>(2320, a1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  1368. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  1369. writeToPLC_Flag.Name = "a1AGVDownCall";
  1370. writeToPLC_Flag.Adress = 2320;
  1371. writeToPLC_Flag.Value = a1AGVDownCall;
  1372. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  1373. stopwatch2.Stop();
  1374. }
  1375. catch (Exception ex)
  1376. {
  1377. string str = ex.StackTrace;
  1378. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1379. // a1AGVDownCall
  1380. stopwatch2.Start();
  1381. //Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  1382. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  1383. writeToPLC_Flag.Name = "a1AGVDownCall";
  1384. writeToPLC_Flag.Adress = 2320;
  1385. writeToPLC_Flag.Value = (short)4;
  1386. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  1387. stopwatch2.Stop();
  1388. }
  1389. stopwatch1.Stop();
  1390. AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1391. }
  1392. /// <summary>
  1393. /// [S1] Tray盘上料装备(板测)- AGV下料完成
  1394. /// </summary>
  1395. /// <param name="plcNo">PLC编号</param>
  1396. /// <param name="stationNameStr">工站全称</param>
  1397. private void S1AGV下料完成(int plcNo, string stationNameStr)
  1398. {
  1399. Stopwatch stopwatch1 = new Stopwatch();
  1400. Stopwatch stopwatch2 = new Stopwatch();
  1401. try
  1402. {
  1403. stopwatch1.Start();
  1404. // ZS AGV上料完成,让小车离开
  1405. short a1AGVDownEnd = 2;
  1406. stopwatch2.Start();
  1407. // a1AGVDownEnd
  1408. //Funs[plcNo].WriteMultipleRegisters<short>(2322, a1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  1409. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  1410. writeToPLC_Flag.Name = "a1AGVDownEnd";
  1411. writeToPLC_Flag.Adress = 2322;
  1412. writeToPLC_Flag.Value = a1AGVDownEnd;
  1413. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  1414. stopwatch2.Stop();
  1415. }
  1416. catch (Exception ex)
  1417. {
  1418. string str = ex.StackTrace;
  1419. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1420. // a1AGVDownEnd
  1421. stopwatch2.Start();
  1422. //Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  1423. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  1424. writeToPLC_Flag.Name = "a1AGVDownEnd";
  1425. writeToPLC_Flag.Adress = 2322;
  1426. writeToPLC_Flag.Value = (short)4;
  1427. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  1428. stopwatch2.Stop();
  1429. }
  1430. stopwatch1.Stop();
  1431. AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1432. }
  1433. #endregion [S1] Tray盘上料装备(板测)
  1434. #endregion PLC1 张超凡
  1435. #region PLC2 贲流
  1436. #region [S2] 上盖板上料装备
  1437. /// <summary>
  1438. /// S2工位的数据- 触发信号上次的值
  1439. /// </summary>
  1440. private Dictionary<string, object> s2PLCSignal_Old = new Dictionary<string, object>();
  1441. /// <summary>
  1442. /// S2工位的数据(含触发信号)
  1443. /// </summary>
  1444. private Dictionary<string, object> s2PLCData = new Dictionary<string, object>();
  1445. /// <summary>
  1446. /// S2工位的数据- 回写点位
  1447. /// </summary>
  1448. private Dictionary<string, WriteToPLC_Flag> s2PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  1449. /// <summary>
  1450. /// [S2] FCT(板测)
  1451. /// </summary>
  1452. /// <param name="plcNo">PLC编号</param>
  1453. private void ReadStation_S2(int plcNo)
  1454. {
  1455. string stationCode = "[S2]";
  1456. string stationName = "上盖板上料装备";
  1457. string stationNameStr = stationCode + stationName;
  1458. string tagBaseName = "g_OP20_MES"; //标签变量名称
  1459. string tagMesCommName = "mesCommToPC"; //标签变量名称
  1460. string tagAgvCommName = "agvCommFrmPC";
  1461. string tagBarsetName = "BarcodeSet";
  1462. OP20_MesData_t stPLC_MesData; //PLC的MES数据
  1463. (int, string) result;
  1464. bool ProgressState = true;
  1465. while (true)
  1466. {
  1467. try
  1468. {
  1469. if (!GlobalContext._IsCon_Funs2)
  1470. {
  1471. UpdatePLCMonitor(1, plcNo, 0);
  1472. continue;
  1473. }
  1474. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  1475. {
  1476. Stopwatch stopwatch1 = new Stopwatch();
  1477. Stopwatch stopwatch2 = new Stopwatch();
  1478. stopwatch1.Start();
  1479. stopwatch2.Start();
  1480. #region 一次性读取所有数据
  1481. // 一次性读取所有数据
  1482. result = Funs[plcNo].Read_SingleTag<OP20_MesData_t>(tagBaseName, 1, out stPLC_MesData); //读取单个结构体数据
  1483. if (result.Item1 != 0)
  1484. {
  1485. //richTextBox1.AppendText("\n" + strRet);
  1486. }
  1487. else
  1488. {
  1489. //richTextBox1.AppendText("\n" + "读取成功");
  1490. }
  1491. #endregion 一次性读取所有数据
  1492. stopwatch2.Stop();
  1493. #region 进站
  1494. try
  1495. {
  1496. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation && ProgressState == true)
  1497. {
  1498. ProgressState = false;
  1499. Task.Run(() => S2进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  1500. }
  1501. }
  1502. catch (Exception ex)
  1503. {
  1504. ProgressState = false;
  1505. string str = ex.StackTrace;
  1506. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1507. }
  1508. #endregion 进站
  1509. #region 出站
  1510. try
  1511. {
  1512. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation && ProgressState == true)
  1513. {
  1514. ProgressState = false;
  1515. Task.Run(() => S2出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  1516. }
  1517. }
  1518. catch (Exception ex)
  1519. {
  1520. string str = ex.StackTrace;
  1521. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1522. }
  1523. #endregion 进站
  1524. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1525. stopwatch1.Stop();
  1526. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  1527. OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  1528. }
  1529. else
  1530. {
  1531. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1532. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1533. Funs[plcNo].Connect();
  1534. }
  1535. }
  1536. catch (Exception ex)
  1537. {
  1538. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1539. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1540. //Funs[plcNo].ReConnect();
  1541. }
  1542. Thread.Sleep(IntervalReadPLC);
  1543. }
  1544. }
  1545. /// <summary>
  1546. /// [S2] 上盖板上料装备
  1547. /// </summary>
  1548. /// <param name="plcNo">PLC编号</param>
  1549. /// <param name="stationNameStr">工站全称</param>
  1550. private void S2进站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName,string tagBarsetName, out bool ProgressState)
  1551. {
  1552. Stopwatch stopwatch1 = new Stopwatch();
  1553. Stopwatch stopwatch2 = new Stopwatch();
  1554. ProgressState = true;
  1555. try
  1556. {
  1557. stopwatch1.Start();
  1558. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  1559. string MachineId = GlobalContext.S1_MachineId; // 装备ID(可配置)
  1560. string StationId = GlobalContext.S1_StationId; // 工位ID(可配置)
  1561. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  1562. strCarrierBarcode = strCarrierBarcode.Replace("\0", "");
  1563. //载具码验证产品码 错误码111
  1564. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  1565. if (string.IsNullOrEmpty(strProductBarcode))
  1566. {
  1567. AddMessage_Station(stationNameStr, LogType.Error, $"PLC S2 上盖板上料装备未能成功绑定载具信息");
  1568. }
  1569. if (!string.IsNullOrEmpty(strProductBarcode) && !string.IsNullOrEmpty(sn) && strProductBarcode!=sn)
  1570. {
  1571. AddMessage_Station(stationNameStr, LogType.Error, $"PLC S2 上盖板上料装备PLC返回产品码与载具绑定物料码不同");
  1572. }
  1573. // 产品SN(物料码)校验
  1574. List <TestItem> item = new List<TestItem>();
  1575. stopwatch2.Start();
  1576. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  1577. stopwatch2.Stop();
  1578. //指令执行结果 1:OK 110:失败
  1579. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  1580. if (!string.IsNullOrEmpty(strProductBarcode) && !string.IsNullOrEmpty(sn) && strProductBarcode != sn)
  1581. {
  1582. mesResultFrmWeb = 111;
  1583. }
  1584. //进站结果写入PLC
  1585. CommandFromPLC resultToPlC = new CommandFromPLC();
  1586. resultToPlC.cmd = 0;
  1587. resultToPlC.cmdParam = 0; //指令参数
  1588. resultToPlC.cmdResult = mesResultFrmWeb;
  1589. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1590. if (string.IsNullOrEmpty(sn) && !string.IsNullOrEmpty(strProductBarcode))
  1591. {
  1592. BarcodeSet_t BarcodeToPlc= new BarcodeSet_t();
  1593. BarcodeToPlc.strCarrierBarcode = strCarrierBarcode;
  1594. BarcodeToPlc.strProductBarcode = sn;
  1595. Funs[plcNo].Write_SingleTag<BarcodeSet_t>(tagBarsetName, 1, BarcodeToPlc);
  1596. }
  1597. }
  1598. catch (Exception ex)
  1599. {
  1600. string str = ex.StackTrace;
  1601. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1602. CommandFromPLC resultToPlC = new CommandFromPLC();
  1603. resultToPlC.cmd = 0;
  1604. resultToPlC.cmdParam = 0; //指令参数
  1605. resultToPlC.cmdResult = 110;
  1606. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1607. }
  1608. stopwatch1.Stop();
  1609. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1610. }
  1611. /// <summary>
  1612. /// [S2] 上盖板上料装备 - 出站接口
  1613. /// </summary>
  1614. private void S2出站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName,string stationCode,string stationName, out bool ProgressState)
  1615. {
  1616. ProgressState = true;
  1617. Stopwatch stopwatch1 = new Stopwatch();
  1618. Stopwatch stopwatch2 = new Stopwatch();
  1619. try
  1620. {
  1621. stopwatch1.Start();
  1622. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  1623. string processItem = stationName; // 测试项目
  1624. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  1625. string supplierCode = ""; // 供应商代码
  1626. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  1627. string batch_num = GlobalContext.BatchNumber; // 批次号
  1628. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  1629. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  1630. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1631. string MachineId = GlobalContext.S1_MachineId; // 装备id(可配置) // ZS
  1632. string StationId = GlobalContext.S1_StationId; // ⼯位ID(可配置) // ZS
  1633. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  1634. bool pass = a1Result == 1;
  1635. List<TestItem> items = new List<TestItem>();
  1636. items.Add(new TestItem()
  1637. {
  1638. Parameter_name = "载具码",
  1639. Parameter_value = CarrierBarcode,
  1640. Parameter_unit = ""
  1641. });
  1642. items.Add(new TestItem()
  1643. {
  1644. Parameter_name = "产品码",
  1645. Parameter_value = mtltmrk,
  1646. Parameter_unit = ""
  1647. });
  1648. //保存PLC返回MES数据到本地
  1649. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  1650. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId);
  1651. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  1652. stopwatch2.Start();
  1653. //进站结果写入PLC
  1654. CommandFromPLC resultToPlC = new CommandFromPLC();
  1655. resultToPlC.cmd = 0;
  1656. resultToPlC.cmdParam = 0; //指令参数
  1657. resultToPlC.cmdResult = mesResultFrmWeb;
  1658. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1659. stopwatch2.Stop();
  1660. WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-Write" + (result1 == 1 ? "成功!" : "失败!"));
  1661. }
  1662. catch (Exception ex)
  1663. {
  1664. stopwatch2.Start();
  1665. CommandFromPLC resultToPlC = new CommandFromPLC();
  1666. resultToPlC.cmd = 0;
  1667. resultToPlC.cmdParam = 0; //指令参数
  1668. resultToPlC.cmdResult = 110;
  1669. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1670. stopwatch2.Stop();
  1671. string str = ex.StackTrace;
  1672. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{stationNameStr}]上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1673. }
  1674. stopwatch1.Stop();
  1675. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1676. }
  1677. /// <summary>
  1678. /// [S2] FCT(板测)- 节拍接口
  1679. /// </summary>
  1680. /// <param name="plcNo">PLC编号</param>
  1681. /// <param name="stationNameStr">工站全称</param>
  1682. private void S2节拍接口(int plcNo, string stationNameStr)
  1683. {
  1684. Stopwatch stopwatch1 = new Stopwatch();
  1685. Stopwatch stopwatch2 = new Stopwatch();
  1686. string resultStr = string.Empty;
  1687. try
  1688. {
  1689. stopwatch1.Start();
  1690. string oEEType = ((int)s2PLCData["b1OEEType"]).ToString(); // 节拍类型(plc写入)
  1691. string b1OEEProductSN = (string)s2PLCData["b1OEEProductSN"]; // 载具SN
  1692. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  1693. if (!actionBool)
  1694. {
  1695. stopwatch2.Start();
  1696. // MES_Flag
  1697. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  1698. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  1699. writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
  1700. writeToPLC_Flag1.Adress = 2203;
  1701. writeToPLC_Flag1.Value = (short)4;
  1702. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
  1703. stopwatch2.Stop();
  1704. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1705. return;
  1706. }
  1707. string b1OEEPartNo = string.Empty; // 物料码
  1708. if (string.IsNullOrEmpty(b1OEEProductSN))
  1709. {
  1710. stopwatch2.Start();
  1711. // MES_Flag
  1712. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  1713. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  1714. writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
  1715. writeToPLC_Flag1.Adress = 2203;
  1716. writeToPLC_Flag1.Value = (short)1;
  1717. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
  1718. stopwatch2.Stop();
  1719. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1720. return;
  1721. }
  1722. else
  1723. { // 查产品SN
  1724. b1OEEPartNo = "Test"; // ZS
  1725. }
  1726. short b1OEEMES_FLAG = 0;
  1727. // 上传OEE
  1728. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, b1OEEPartNo, b1OEEProductSN);
  1729. b1OEEMES_FLAG = result.Item1;
  1730. resultStr = result.Item2;
  1731. stopwatch2.Start();
  1732. // MES_Flag
  1733. //Funs[plcNo].WriteMultipleRegisters<short>(2203, b1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  1734. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  1735. writeToPLC_Flag.Name = "b1OEEMES_FLAG";
  1736. writeToPLC_Flag.Adress = 2203;
  1737. writeToPLC_Flag.Value = b1OEEMES_FLAG;
  1738. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
  1739. stopwatch2.Stop();
  1740. }
  1741. catch (Exception ex)
  1742. {
  1743. string str = ex.StackTrace;
  1744. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1745. // MES_Flag
  1746. stopwatch2.Start();
  1747. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  1748. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  1749. writeToPLC_Flag.Name = "b1OEEMES_FLAG";
  1750. writeToPLC_Flag.Adress = 2203;
  1751. writeToPLC_Flag.Value = (short)4;
  1752. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
  1753. stopwatch2.Stop();
  1754. }
  1755. stopwatch1.Stop();
  1756. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1757. }
  1758. #endregion [S2] FCT(板测)
  1759. #endregion PLC2 李晓奇
  1760. #region PLC3 刘永村
  1761. #region [S3] 值板机
  1762. /// <summary>
  1763. /// S3工位的数据- 触发信号上次的值
  1764. /// </summary>
  1765. private Dictionary<string, object> s3PLCSignal_Old = new Dictionary<string, object>();
  1766. /// <summary>
  1767. /// S3工位的数据(含触发信号)
  1768. /// </summary>
  1769. private Dictionary<string, object> s3PLCData = new Dictionary<string, object>();
  1770. /// <summary>
  1771. /// S3工位的数据- 回写点位
  1772. /// </summary>
  1773. private Dictionary<string, WriteToPLC_Flag> s3PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  1774. /// <summary>
  1775. /// [S3] 值板机
  1776. /// </summary>
  1777. /// <param name="plcNo">PLC编号</param>
  1778. private void ReadStation_S3(int plcNo)
  1779. {
  1780. string stationCode = "[S3]";
  1781. string stationName = "点散热胶装备";
  1782. string stationNameStr = stationCode + stationName;
  1783. string tagBaseName = "g_OP30_MES"; //标签变量名称
  1784. string tagMesCommName = "mesCommToPC"; //标签变量名称
  1785. string tagAgvCommName = "agvCommFrmPC";
  1786. string tagBarsetName = "BarcodeSet";
  1787. OP30_MesData_t stPLC_MesData; //PLC的MES数据
  1788. (int, string) result;
  1789. #region 创建字典
  1790. // 触发信号字典 赋值
  1791. s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  1792. s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  1793. s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  1794. s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  1795. s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  1796. // PLC数据字典 赋值
  1797. s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  1798. s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  1799. s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  1800. s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  1801. s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  1802. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  1803. s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  1804. s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  1805. s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  1806. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  1807. s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  1808. s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  1809. s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  1810. s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  1811. s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  1812. s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  1813. //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  1814. s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  1815. s3PLCData.Add("c1Result", 0); // 产品结果
  1816. s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  1817. s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  1818. s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  1819. s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  1820. #endregion 创建字典
  1821. while (true)
  1822. {
  1823. try
  1824. {
  1825. if (!GlobalContext._IsCon_Funs2)
  1826. {
  1827. UpdatePLCMonitor(1, plcNo, 0);
  1828. continue;
  1829. }
  1830. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  1831. {
  1832. Stopwatch stopwatch1 = new Stopwatch();
  1833. Stopwatch stopwatch2 = new Stopwatch();
  1834. stopwatch1.Start();
  1835. stopwatch2.Start();
  1836. #region 一次性读取所有数据
  1837. // 一次性读取所有数据
  1838. result = Funs[plcNo].Read_SingleTag<OP30_MesData_t>(tagBaseName, 1, out stPLC_MesData); //读取单个结构体数据
  1839. if (result.Item1 != 0)
  1840. {
  1841. //richTextBox1.AppendText("\n" + strRet);
  1842. }
  1843. else
  1844. {
  1845. //richTextBox1.AppendText("\n" + "读取成功");
  1846. }
  1847. #endregion 一次性读取所有数据
  1848. stopwatch2.Stop();
  1849. #region 左边进站
  1850. try
  1851. {
  1852. //if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation && !string.IsNullOrEmpty(stPLC_MesData.iotData.Left.work_type.ToString()))
  1853. //{
  1854. // Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName));
  1855. // //进站
  1856. //}
  1857. }
  1858. catch (Exception ex)
  1859. {
  1860. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  1861. string str = ex.StackTrace;
  1862. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1863. }
  1864. #endregion 进站
  1865. #region 左边出站
  1866. try
  1867. {
  1868. //if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  1869. //{
  1870. // Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, "Left"));
  1871. //}
  1872. }
  1873. catch (Exception ex)
  1874. {
  1875. string str = ex.StackTrace;
  1876. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1877. }
  1878. #endregion 出站
  1879. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1880. stopwatch1.Stop();
  1881. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  1882. OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  1883. }
  1884. else
  1885. {
  1886. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1887. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1888. Funs[plcNo].Connect();
  1889. }
  1890. }
  1891. catch (Exception ex)
  1892. {
  1893. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1894. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1895. //Funs[plcNo].ReConnect();
  1896. }
  1897. Thread.Sleep(IntervalReadPLC);
  1898. }
  1899. }
  1900. /// <summary>
  1901. /// [S3] 点散热胶装备
  1902. /// </summary>
  1903. /// <param name="plcNo">PLC编号</param>
  1904. /// <param name="stationNameStr">工站全称</param>
  1905. private void S3进站(int plcNo, string stationNameStr, OP30_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName)
  1906. {
  1907. Stopwatch stopwatch1 = new Stopwatch();
  1908. Stopwatch stopwatch2 = new Stopwatch();
  1909. try
  1910. {
  1911. stopwatch1.Start();
  1912. string sn = "";//(string)stPLC_MesDataBarcodeSet.strProductBarcode; // 产品SN(物料码)
  1913. sn = sn.Replace("\0", "");
  1914. string strCarrierBarcode = "";//(string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  1915. strCarrierBarcode = strCarrierBarcode.Replace("\0", "");
  1916. //载具码验证产品码
  1917. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  1918. if (string.IsNullOrEmpty(strProductBarcode))
  1919. {
  1920. AddMessage_Station(stationNameStr, LogType.Error, $"PLC S3 点散热胶装备未能成功绑定载具信息");
  1921. }
  1922. if (!string.IsNullOrEmpty(strProductBarcode) && !string.IsNullOrEmpty(sn) && strProductBarcode != sn)
  1923. {
  1924. AddMessage_Station(stationNameStr, LogType.Error, $"PLC S3 点散热胶装备未能成功绑定载具信息");
  1925. }
  1926. // 产品SN(物料码)校验
  1927. List<TestItem> item = new List<TestItem>();
  1928. stopwatch2.Start();
  1929. int result = 0;
  1930. //int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item);
  1931. stopwatch2.Stop();
  1932. //指令执行结果 1:OK 110:失败
  1933. byte cmdToPC = (byte)(result == 1 ? 1 : 110);
  1934. //进站结果写入PLC
  1935. if (string.IsNullOrEmpty(sn))
  1936. {
  1937. BarcodeSet_t BarcodeToPlc = new BarcodeSet_t();
  1938. BarcodeToPlc.strCarrierBarcode = strCarrierBarcode;
  1939. BarcodeToPlc.strProductBarcode = sn;
  1940. Funs[plcNo].Write_SingleTag<BarcodeSet_t>(tagBarsetName, 1, BarcodeToPlc);
  1941. }
  1942. }
  1943. catch (Exception ex)
  1944. {
  1945. string str = ex.StackTrace;
  1946. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1947. }
  1948. stopwatch1.Stop();
  1949. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1950. }
  1951. /// <summary>
  1952. /// [S3] 点散热胶装备 - 出站接口
  1953. /// </summary>
  1954. private void S3出站(int plcNo, string stationNameStr, OP30_MesData_t stPLC_MesData, string tagMesCommName,string direction)
  1955. {
  1956. Stopwatch stopwatch1 = new Stopwatch();
  1957. Stopwatch stopwatch2 = new Stopwatch();
  1958. try
  1959. {
  1960. stopwatch1.Start();
  1961. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  1962. string batch_num = GlobalContext.BatchNumber; // 批次号
  1963. string mtltmrk = GlobalContext.Mtltmrk; // 产品条码; // 产品型号
  1964. mtltmrk = mtltmrk.Replace("\0", "");
  1965. string CarrierBarcode = "";//(string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1966. // 产品结果
  1967. int a1Result = 0;
  1968. //if (direction=="Left")
  1969. //{
  1970. // a1Result=(int)stPLC_MesData.iotData.Left.testStatus;
  1971. //}
  1972. //if (direction == "Right")
  1973. //{
  1974. // a1Result = (int)stPLC_MesData.iotData.Left.testStatus;
  1975. //}
  1976. bool pass = a1Result == 1;
  1977. List<TestItem> items = new List<TestItem>();
  1978. items.Add(new TestItem()
  1979. {
  1980. Parameter_name = "载具码",
  1981. Parameter_value = CarrierBarcode,
  1982. Parameter_unit = ""
  1983. });
  1984. items.Add(new TestItem()
  1985. {
  1986. Parameter_name = "产品码",
  1987. Parameter_value = mtltmrk,
  1988. Parameter_unit = ""
  1989. });
  1990. //保存PLC返回MES数据到本地
  1991. int result1 = 0;
  1992. //int result1 = SwitctProcessData(stationNameStr, items, "", ""
  1993. // , workorder_code, batch_num, mtltmrk, "", "", "", pass, CarrierBarcode, "1");
  1994. byte cmdToPC = (byte)(result1 == 1 ? 1 : 110);
  1995. stopwatch2.Start();
  1996. //进站结果写入PLC
  1997. stopwatch2.Stop();
  1998. WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-Write" + (result1 == 1 ? "成功!" : "失败!"));
  1999. }
  2000. catch (Exception ex)
  2001. {
  2002. stopwatch2.Start();
  2003. stopwatch2.Stop();
  2004. string str = ex.StackTrace;
  2005. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{stationNameStr}]上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2006. }
  2007. stopwatch1.Stop();
  2008. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2009. }
  2010. //// 上次采集到的SN
  2011. //private string sn_值板机 = string.Empty;
  2012. /// <summary>
  2013. /// [S3] 值板机 - 出站接口
  2014. /// </summary>
  2015. /// <param name="plcNo">PLC编号</param>
  2016. private void S3出站接口(int plcNo, string stationCode, string stationName)
  2017. {
  2018. Stopwatch stopwatch1 = new Stopwatch();
  2019. Stopwatch stopwatch2 = new Stopwatch();
  2020. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2021. string stationNameStr = stationCode + stationName;
  2022. string processItem = stationName; // 测试项目
  2023. try
  2024. {
  2025. stopwatch1.Start();
  2026. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2027. string batch_num = GlobalContext.BatchNumber; // 批次号
  2028. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2029. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2030. string supplierCode = ""; // 供应商代码
  2031. string sn = (string)s3PLCData["c1ProductSN"]; // 产品SN(一穴载具SN)
  2032. sn = sn.Replace("\0", "");
  2033. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 二穴载具SN(产品取自哪个二穴载具)
  2034. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  2035. int c1VehicleCavity = (int)s3PLCData["c1VehicleCavity"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  2036. int c1Result = (int)s3PLCData["c1Result"]; // 产品结果
  2037. bool pass = c1Result == 1;
  2038. //
  2039. string productSN = string.Empty;
  2040. // 是否是两个穴位交换
  2041. List<TestItem> items = new List<TestItem>();
  2042. items.Add(new TestItem()
  2043. {
  2044. Parameter_name = "产品结果",
  2045. Parameter_value = c1Result == 1 ? "OK" : "NG",
  2046. Parameter_unit = ""
  2047. });
  2048. int result1 = 0;
  2049. //int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2050. // , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, productSN, pass, sn, "1");
  2051. short result = result1 == 1 ? (short)1 : (short)2;
  2052. stopwatch2.Start();
  2053. // MES_Flag 为MES报错
  2054. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  2055. //Funs[plcNo].WriteMultipleRegisters<short>(2150, result); // 4代表上位机报警
  2056. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  2057. writeToPLC_Flag.Name = "c1MES_FLAG";
  2058. writeToPLC_Flag.Adress = 2150;
  2059. writeToPLC_Flag.Value = result;
  2060. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  2061. stopwatch2.Stop();
  2062. WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  2063. }
  2064. catch (Exception ex)
  2065. {
  2066. stopwatch2.Start();
  2067. // MES_Flag 为4上位机报错
  2068. //Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)4); // 4代表上位机报警
  2069. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  2070. writeToPLC_Flag.Name = "c1MES_FLAG";
  2071. writeToPLC_Flag.Adress = 2150;
  2072. writeToPLC_Flag.Value = (short)4;
  2073. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  2074. stopwatch2.Stop();
  2075. string str = ex.StackTrace;
  2076. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2077. }
  2078. stopwatch1.Stop();
  2079. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2080. }
  2081. /// <summary>
  2082. /// [S3] 值板机- 节拍接口
  2083. /// </summary>
  2084. /// <param name="plcNo">PLC编号</param>
  2085. /// <param name="stationNameStr">工站全称</param>
  2086. private void S3节拍接口(int plcNo, string stationNameStr)
  2087. {
  2088. Stopwatch stopwatch1 = new Stopwatch();
  2089. Stopwatch stopwatch2 = new Stopwatch();
  2090. string resultStr = string.Empty;
  2091. try
  2092. {
  2093. stopwatch1.Start();
  2094. string oEEType = ((int)s3PLCData["c1OEEType"]).ToString(); // 节拍类型(plc写入)
  2095. string c1OEEProductSN = (string)s3PLCData["c1OEEProductSN"]; // 载具SN
  2096. c1OEEProductSN = c1OEEProductSN.Replace("\0", "");
  2097. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  2098. if (!actionBool)
  2099. {
  2100. stopwatch2.Start();
  2101. // MES_Flag
  2102. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  2103. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  2104. writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
  2105. writeToPLC_Flag1.Adress = 2204;
  2106. writeToPLC_Flag1.Value = (short)4;
  2107. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
  2108. stopwatch2.Stop();
  2109. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2110. return;
  2111. }
  2112. string c1OEEPartNo = string.Empty; // 物料码
  2113. if (string.IsNullOrEmpty(c1OEEProductSN))
  2114. {
  2115. stopwatch2.Start();
  2116. // MES_Flag
  2117. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  2118. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  2119. writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
  2120. writeToPLC_Flag1.Adress = 2204;
  2121. writeToPLC_Flag1.Value = (short)1;
  2122. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
  2123. stopwatch2.Stop();
  2124. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2125. return;
  2126. }
  2127. else
  2128. { // 查产品SN
  2129. c1OEEPartNo = "Test"; // ZS
  2130. }
  2131. short c1OEEMES_FLAG = 0;
  2132. // 上传OEE
  2133. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, c1OEEPartNo, c1OEEProductSN);
  2134. c1OEEMES_FLAG = result.Item1;
  2135. resultStr = result.Item2;
  2136. stopwatch2.Start();
  2137. // MES_Flag
  2138. //Funs[plcNo].WriteMultipleRegisters<short>(2204, c1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  2139. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  2140. writeToPLC_Flag.Name = "c1OEEMES_FLAG";
  2141. writeToPLC_Flag.Adress = 2204;
  2142. writeToPLC_Flag.Value = c1OEEMES_FLAG;
  2143. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
  2144. stopwatch2.Stop();
  2145. }
  2146. catch (Exception ex)
  2147. {
  2148. string str = ex.StackTrace;
  2149. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2150. // MES_Flag
  2151. stopwatch2.Start();
  2152. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  2153. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  2154. writeToPLC_Flag.Name = "c1OEEMES_FLAG";
  2155. writeToPLC_Flag.Adress = 2204;
  2156. writeToPLC_Flag.Value = (short)4;
  2157. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
  2158. stopwatch2.Stop();
  2159. }
  2160. stopwatch1.Stop();
  2161. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2162. }
  2163. #endregion [S3] 值板机
  2164. #endregion PLC3 刘永村
  2165. /// <summary>
  2166. /// [S4] 点胶检测设备
  2167. /// </summary>
  2168. /// <param name="plcNo">PLC编号</param>
  2169. private void ReadStation_S4(int plcNo)
  2170. {
  2171. string stationCode = "[S4]";
  2172. string stationName = "点胶检测设备";
  2173. string stationNameStr = stationCode + stationName;
  2174. string tagBaseName = "g_OP40_MES"; //标签变量名称
  2175. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2176. string tagAgvCommName = "agvCommFrmPC";
  2177. string tagBarsetName = "BarcodeSet";
  2178. OP40_MesData_t stPLC_MesData; //PLC的MES数据
  2179. (int, string) result;
  2180. bool ProgressState = true;
  2181. #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  2182. // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  2183. s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  2184. s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  2185. s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2186. s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  2187. s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2188. s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  2189. s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  2190. s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  2191. s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  2192. // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  2193. s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  2194. s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
  2195. s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
  2196. s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  2197. s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
  2198. s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
  2199. s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2200. s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
  2201. s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
  2202. s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
  2203. s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
  2204. s1PLCData.Add("a1Result", 0); // 产品结果
  2205. s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  2206. s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
  2207. s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
  2208. s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
  2209. s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
  2210. s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2211. s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
  2212. s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  2213. s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  2214. s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
  2215. s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  2216. s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  2217. s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
  2218. s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
  2219. s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  2220. s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
  2221. s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
  2222. #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  2223. while (true)
  2224. {
  2225. try
  2226. {
  2227. if (!GlobalContext._IsCon_Funs1)
  2228. {
  2229. UpdatePLCMonitor(1, plcNo, 0);
  2230. continue;
  2231. }
  2232. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  2233. {
  2234. Stopwatch stopwatch1 = new Stopwatch();
  2235. Stopwatch stopwatch2 = new Stopwatch();
  2236. stopwatch1.Start();
  2237. stopwatch2.Start();
  2238. #region 一次性读取所有数据
  2239. // 一次性读取所有数据
  2240. result = Funs[plcNo].Read_SingleTag<OP40_MesData_t>(tagBaseName, 1, out stPLC_MesData); //读取单个结构体数据
  2241. if (result.Item1 != 0)
  2242. {
  2243. //richTextBox1.AppendText("\n" + strRet);
  2244. }
  2245. else
  2246. {
  2247. //richTextBox1.AppendText("\n" + "读取成功");
  2248. }
  2249. #endregion 一次性读取所有数据
  2250. stopwatch2.Stop();
  2251. #region 进站
  2252. try
  2253. {
  2254. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation && ProgressState == true)
  2255. {
  2256. ProgressState = false;
  2257. Task.Run(() => S4进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, out ProgressState));
  2258. }
  2259. }
  2260. catch (Exception ex)
  2261. {
  2262. ProgressState = false;
  2263. string str = ex.StackTrace;
  2264. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2265. }
  2266. #endregion 进站
  2267. #region 出站
  2268. try
  2269. {
  2270. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation && ProgressState == true)
  2271. {
  2272. ProgressState = false;
  2273. Task.Run(() => S4出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2274. }
  2275. }
  2276. catch (Exception ex)
  2277. {
  2278. string str = ex.StackTrace;
  2279. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2280. }
  2281. #endregion 进站
  2282. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2283. stopwatch1.Stop();
  2284. OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2285. }
  2286. else
  2287. {
  2288. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2289. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2290. Funs[plcNo].Connect(); // 重连
  2291. }
  2292. }
  2293. catch (Exception ex)
  2294. {
  2295. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2296. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2297. }
  2298. Thread.Sleep(IntervalReadPLC);
  2299. }
  2300. }
  2301. /// <summary>
  2302. /// [S4] 点胶检测设备 - 进站
  2303. /// </summary>
  2304. /// <param name="plcNo">PLC编号</param>
  2305. /// <param name="stationNameStr">工站全称</param>
  2306. /// <param name="stPLC_MesData"></param>
  2307. /// <param name="tagMesCommName"></param>
  2308. private void S4进站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, out bool ProgressState)
  2309. {
  2310. int nRet = 0;
  2311. string strRet = "";
  2312. Stopwatch stopwatch1 = new Stopwatch();
  2313. Stopwatch stopwatch2 = new Stopwatch();
  2314. ProgressState = true;
  2315. try
  2316. {
  2317. stopwatch1.Start();
  2318. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2319. string MachineId = GlobalContext.S4_MachineId; // 装备ID(可配置)
  2320. string StationId = GlobalContext.S4_StationId; // 工位ID(可配置)
  2321. // 产品SN(物料码)校验
  2322. List<TestItem> item = new List<TestItem>();
  2323. stopwatch2.Start();
  2324. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2325. stopwatch2.Stop();
  2326. //指令执行结果 1:OK 110:失败
  2327. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2328. //进站结果写入PLC
  2329. CommandFromPLC resultToPlC = new CommandFromPLC();
  2330. resultToPlC.cmd = 0;
  2331. resultToPlC.cmdParam = 0; //指令参数
  2332. resultToPlC.cmdResult = mesResultFrmWeb;
  2333. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2334. }
  2335. catch (Exception ex)
  2336. {
  2337. string str = ex.StackTrace;
  2338. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2339. CommandFromPLC resultToPlC = new CommandFromPLC();
  2340. resultToPlC.cmd = 0;
  2341. resultToPlC.cmdParam = 0; //指令参数
  2342. resultToPlC.cmdResult = 110;
  2343. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2344. }
  2345. stopwatch1.Stop();
  2346. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2347. }
  2348. /// <summary>
  2349. /// [S4] 点胶检测设备 - 出站接口
  2350. /// </summary>
  2351. private void S4出站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2352. {
  2353. ProgressState = true;
  2354. Stopwatch stopwatch1 = new Stopwatch();
  2355. Stopwatch stopwatch2 = new Stopwatch();
  2356. try
  2357. {
  2358. stopwatch1.Start();
  2359. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2360. string processItem = stationName; // 测试项目
  2361. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2362. string supplierCode = ""; // 供应商代码
  2363. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2364. string batch_num = GlobalContext.BatchNumber; // 批次号
  2365. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2366. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2367. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2368. string MachineId = GlobalContext.S4_MachineId; // 装备id(可配置) // ZS
  2369. string StationId = GlobalContext.S4_StationId; // ⼯位ID(可配置) // ZS
  2370. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2371. bool pass = a1Result == 1;
  2372. List<TestItem> items = new List<TestItem>();
  2373. items.Add(new TestItem()
  2374. {
  2375. Parameter_name = "载具码",
  2376. Parameter_value = CarrierBarcode,
  2377. Parameter_unit = ""
  2378. });
  2379. items.Add(new TestItem()
  2380. {
  2381. Parameter_name = "产品码",
  2382. Parameter_value = mtltmrk,
  2383. Parameter_unit = ""
  2384. });
  2385. ResponseMessage responseMessage = InsertOp40Data("", stPLC_MesData.mesData.fGlue_Areas[0], stPLC_MesData.mesData.fGlue_Heights[0],"");
  2386. if (!responseMessage.result)
  2387. {
  2388. AddMessage_Station(stationNameStr, LogType.Error, "OP40记录插入出错!");
  2389. }
  2390. //绑定PLC返回MES数据到本地
  2391. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2392. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId);
  2393. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2394. stopwatch2.Start();
  2395. //进站结果写入PLC
  2396. CommandFromPLC resultToPlC = new CommandFromPLC();
  2397. resultToPlC.cmd = 0;
  2398. resultToPlC.cmdParam = 0; //指令参数
  2399. resultToPlC.cmdResult = mesResultFrmWeb;
  2400. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2401. stopwatch2.Stop();
  2402. WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-Write" + (result1 == 1 ? "成功!" : "失败!"));
  2403. }
  2404. catch (Exception ex)
  2405. {
  2406. stopwatch2.Start();
  2407. CommandFromPLC resultToPlC = new CommandFromPLC();
  2408. resultToPlC.cmd = 0;
  2409. resultToPlC.cmdParam = 0; //指令参数
  2410. resultToPlC.cmdResult = 110;
  2411. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2412. stopwatch2.Stop();
  2413. string str = ex.StackTrace;
  2414. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{stationNameStr}]上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2415. }
  2416. stopwatch1.Stop();
  2417. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2418. }
  2419. /// <summary>
  2420. /// [S5] 点胶检测设备
  2421. /// </summary>
  2422. /// <param name="plcNo">PLC编号</param>
  2423. private void ReadStation_S5(int plcNo)
  2424. {
  2425. string stationCode = "[S5]";
  2426. string stationName = "点胶检测设备";
  2427. string stationNameStr = stationCode + stationName;
  2428. string tagBaseName = "g_OP50_MES"; //标签变量名称
  2429. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2430. string tagAgvCommName = "agvCommFrmPC";
  2431. string tagBarsetName = "BarcodeSet";
  2432. OP50_MesData_t stPLC_MesData; //PLC的MES数据
  2433. (int, string) result;
  2434. bool ProgressState = true;
  2435. #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  2436. // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  2437. s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  2438. s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  2439. s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2440. s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  2441. s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2442. s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  2443. s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  2444. s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  2445. s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  2446. // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  2447. s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  2448. s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
  2449. s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
  2450. s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  2451. s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
  2452. s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
  2453. s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2454. s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
  2455. s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
  2456. s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
  2457. s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
  2458. s1PLCData.Add("a1Result", 0); // 产品结果
  2459. s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  2460. s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
  2461. s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
  2462. s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
  2463. s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
  2464. s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2465. s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
  2466. s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  2467. s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  2468. s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
  2469. s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  2470. s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  2471. s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
  2472. s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
  2473. s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  2474. s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
  2475. s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
  2476. #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  2477. while (true)
  2478. {
  2479. try
  2480. {
  2481. if (!GlobalContext._IsCon_Funs1)
  2482. {
  2483. UpdatePLCMonitor(1, plcNo, 0);
  2484. continue;
  2485. }
  2486. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  2487. {
  2488. Stopwatch stopwatch1 = new Stopwatch();
  2489. Stopwatch stopwatch2 = new Stopwatch();
  2490. stopwatch1.Start();
  2491. stopwatch2.Start();
  2492. #region 一次性读取所有数据
  2493. // 一次性读取所有数据
  2494. result = Funs[plcNo].Read_SingleTag<OP50_MesData_t>(tagBaseName, 1, out stPLC_MesData); //读取单个结构体数据
  2495. if (result.Item1 != 0)
  2496. {
  2497. //richTextBox1.AppendText("\n" + strRet);
  2498. }
  2499. else
  2500. {
  2501. //richTextBox1.AppendText("\n" + "读取成功");
  2502. }
  2503. #endregion 一次性读取所有数据
  2504. stopwatch2.Stop();
  2505. #region 进站
  2506. try
  2507. {
  2508. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation && ProgressState == true)
  2509. {
  2510. ProgressState = false;
  2511. Task.Run(() => S5进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, out ProgressState));
  2512. }
  2513. }
  2514. catch (Exception ex)
  2515. {
  2516. ProgressState = false;
  2517. string str = ex.StackTrace;
  2518. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2519. }
  2520. #endregion 进站
  2521. #region 出站
  2522. try
  2523. {
  2524. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation && ProgressState == true)
  2525. {
  2526. ProgressState = false;
  2527. Task.Run(() => S5出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2528. }
  2529. }
  2530. catch (Exception ex)
  2531. {
  2532. string str = ex.StackTrace;
  2533. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2534. }
  2535. #endregion 进站
  2536. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2537. stopwatch1.Stop();
  2538. OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2539. }
  2540. else
  2541. {
  2542. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2543. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2544. Funs[plcNo].Connect(); // 重连
  2545. }
  2546. }
  2547. catch (Exception ex)
  2548. {
  2549. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2550. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2551. }
  2552. Thread.Sleep(IntervalReadPLC);
  2553. }
  2554. }
  2555. /// <summary>
  2556. /// [S5] 点胶检测设备 - 进站
  2557. /// </summary>
  2558. /// <param name="plcNo">PLC编号</param>
  2559. /// <param name="stationNameStr">工站全称</param>
  2560. /// <param name="stPLC_MesData"></param>
  2561. /// <param name="tagMesCommName"></param>
  2562. private void S5进站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, out bool ProgressState)
  2563. {
  2564. int nRet = 0;
  2565. string strRet = "";
  2566. Stopwatch stopwatch1 = new Stopwatch();
  2567. Stopwatch stopwatch2 = new Stopwatch();
  2568. ProgressState = true;
  2569. try
  2570. {
  2571. stopwatch1.Start();
  2572. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2573. string MachineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  2574. string StationId = GlobalContext.S5_StationId; // 工位ID(可配置)
  2575. // 产品SN(物料码)校验
  2576. List<TestItem> item = new List<TestItem>();
  2577. stopwatch2.Start();
  2578. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2579. stopwatch2.Stop();
  2580. //指令执行结果 1:OK 110:失败
  2581. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2582. //进站结果写入PLC
  2583. CommandFromPLC resultToPlC = new CommandFromPLC();
  2584. resultToPlC.cmd = 0;
  2585. resultToPlC.cmdParam = 0; //指令参数
  2586. resultToPlC.cmdResult = mesResultFrmWeb;
  2587. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2588. }
  2589. catch (Exception ex)
  2590. {
  2591. string str = ex.StackTrace;
  2592. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2593. CommandFromPLC resultToPlC = new CommandFromPLC();
  2594. resultToPlC.cmd = 0;
  2595. resultToPlC.cmdParam = 0; //指令参数
  2596. resultToPlC.cmdResult = 110;
  2597. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2598. }
  2599. stopwatch1.Stop();
  2600. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2601. }
  2602. /// <summary>
  2603. /// [S5] 点胶检测设备 - 出站接口
  2604. /// </summary>
  2605. private void S5出站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2606. {
  2607. ProgressState = true;
  2608. Stopwatch stopwatch1 = new Stopwatch();
  2609. Stopwatch stopwatch2 = new Stopwatch();
  2610. try
  2611. {
  2612. stopwatch1.Start();
  2613. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2614. string processItem = stationName; // 测试项目
  2615. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2616. string supplierCode = ""; // 供应商代码
  2617. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2618. string batch_num = GlobalContext.BatchNumber; // 批次号
  2619. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2620. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2621. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2622. string MachineId = GlobalContext.S5_MachineId; // 装备id(可配置) // ZS
  2623. string StationId = GlobalContext.S5_StationId; // ⼯位ID(可配置) // ZS
  2624. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2625. bool pass = a1Result == 1;
  2626. List<TestItem> items = new List<TestItem>();
  2627. items.Add(new TestItem()
  2628. {
  2629. Parameter_name = "载具码",
  2630. Parameter_value = CarrierBarcode,
  2631. Parameter_unit = ""
  2632. });
  2633. items.Add(new TestItem()
  2634. {
  2635. Parameter_name = "产品码",
  2636. Parameter_value = mtltmrk,
  2637. Parameter_unit = ""
  2638. });
  2639. ResponseMessage responseMessage = InsertOp50Data(CarrierBarcode,sn, stPLC_MesData.BarcodeSet.strPartBarcode, stPLC_MesData.mesData.nIsAddPCBAsmOK,"", stPLC_MesData.mesData.nHaveAddPCB,stPLC_MesData.mesData.fForceAddPCB);
  2640. if (!responseMessage.result)
  2641. {
  2642. AddMessage_Station(stationNameStr, LogType.Error, "OP50记录插入出错!");
  2643. }
  2644. //绑定PLC返回MES数据到本地
  2645. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2646. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId);
  2647. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2648. stopwatch2.Start();
  2649. //进站结果写入PLC
  2650. CommandFromPLC resultToPlC = new CommandFromPLC();
  2651. resultToPlC.cmd = 0;
  2652. resultToPlC.cmdParam = 0; //指令参数
  2653. resultToPlC.cmdResult = mesResultFrmWeb;
  2654. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2655. stopwatch2.Stop();
  2656. WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-Write" + (result1 == 1 ? "成功!" : "失败!"));
  2657. }
  2658. catch (Exception ex)
  2659. {
  2660. stopwatch2.Start();
  2661. CommandFromPLC resultToPlC = new CommandFromPLC();
  2662. resultToPlC.cmd = 0;
  2663. resultToPlC.cmdParam = 0; //指令参数
  2664. resultToPlC.cmdResult = 110;
  2665. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2666. stopwatch2.Stop();
  2667. string str = ex.StackTrace;
  2668. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{stationNameStr}]上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2669. }
  2670. stopwatch1.Stop();
  2671. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2672. }
  2673. #region PLC4 刘果段
  2674. #region [S4] 取放桁架
  2675. /// <summary>
  2676. /// S4工位的数据- 触发信号上次的值
  2677. /// </summary>
  2678. private Dictionary<string, object> s4PLCSignal_Old = new Dictionary<string, object>();
  2679. /// <summary>
  2680. /// S4工位的数据(含触发信号)
  2681. /// </summary>
  2682. private Dictionary<string, object> s4PLCData = new Dictionary<string, object>();
  2683. /// <summary>
  2684. /// S4工位的数据- 回写点位
  2685. /// </summary>
  2686. private Dictionary<string, WriteToPLC_Flag> s4PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  2687. /// <summary>
  2688. /// [S4] 取放桁架
  2689. /// </summary>
  2690. /// <param name="plcNo">PLC编号</param>
  2691. private void ReadStation_S4(int plcNo)
  2692. {
  2693. // [S1] Tray盘上料装备
  2694. // [S2] FCT
  2695. // [S3] 值板机
  2696. // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  2697. // [S5] Tray盘下料装备
  2698. /// 上位机心跳
  2699. /// 获取设备报警数据与状态信息
  2700. string stationCode = "[S4_1]";
  2701. string stationName = "载具下线装备";
  2702. string stationNameStr = stationCode + stationName;
  2703. string stationCode5 = "[S4_5]";
  2704. string stationName5 = "载具上线装备";
  2705. string stationNameStr5 = stationCode5 + stationName5;
  2706. #region 创建字典
  2707. // 触发信号字典 赋值
  2708. s4PLCSignal_Old.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  2709. s4PLCSignal_Old.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  2710. s4PLCSignal_Old.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2711. s4PLCSignal_Old.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2712. s4PLCSignal_Old.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  2713. s4PLCSignal_Old.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  2714. s4PLCSignal_Old.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  2715. s4PLCSignal_Old.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  2716. s4PLCSignal_Old.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  2717. s4PLCSignal_Old.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  2718. s4PLCSignal_Old.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2719. // PLC数据字典 赋值
  2720. // 载具下线装备(弹夹上线)
  2721. s4PLCData.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  2722. s4PLCData.Add("d1BulletclipCode", ""); // 扫到的码
  2723. s4PLCData.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  2724. s4PLCData.Add("d1VehicleCode", ""); // 扫到的码
  2725. s4PLCData.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2726. s4PLCData.Add("d1MES_FLAG", 0); // MES_FLAG
  2727. s4PLCData.Add("d1ProductSN", ""); // 产品SN(弹夹码)
  2728. s4PLCData.Add("d1VehicleCode1", ""); // 载具1码(弹夹穴位1)
  2729. s4PLCData.Add("d1VehicleCode2", ""); // 载具2码(弹夹穴位2)
  2730. s4PLCData.Add("d1VehicleCode3", ""); // 载具3码(弹夹穴位3)
  2731. s4PLCData.Add("d1VehicleCode4", ""); // 载具4码(弹夹穴位4)
  2732. s4PLCData.Add("d1VehicleCode5", ""); // 载具5码(弹夹穴位5)
  2733. s4PLCData.Add("d1VehicleCode6", ""); // 载具6码(弹夹穴位6)
  2734. s4PLCData.Add("d1VehicleCode7", ""); // 载具7码(弹夹穴位7)
  2735. s4PLCData.Add("d1VehicleCode8", ""); // 载具8码(弹夹穴位8)
  2736. s4PLCData.Add("d1VehicleCode9", ""); // 载具9码(弹夹穴位9)
  2737. s4PLCData.Add("d1VehicleCode10", ""); // 载具10码(弹夹穴位10)
  2738. s4PLCData.Add("d1Result", 0); // 产品结果
  2739. s4PLCData.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2740. s4PLCData.Add("d1OEEMES_FLAG", 0); // MES_FLAG
  2741. s4PLCData.Add("d1OEEProductSN", "");// 产品SN(载具SN)
  2742. s4PLCData.Add("d1OEEType", 0); // 节拍类型(plc写入)
  2743. s4PLCData.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  2744. s4PLCData.Add("d2BulletclipStates", 0); // 弹夹状态
  2745. s4PLCData.Add("d2BulletclipCode", ""); // 扫到的码
  2746. // 真空标机(提升机)
  2747. s4PLCData.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  2748. s4PLCData.Add("d3MES_FLAG", 0); // MES_FLAG
  2749. s4PLCData.Add("d3Type", 0); // 进站还是出站
  2750. s4PLCData.Add("d3ProductSN", ""); // 产品SN(弹夹码)
  2751. s4PLCData.Add("d3Result", 0); // 产品结果
  2752. s4PLCData.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  2753. s4PLCData.Add("d4MES_FLAG", 0); // MES_FLAG
  2754. s4PLCData.Add("d4Type", 0); // 进站还是出站
  2755. s4PLCData.Add("d4ProductSN", ""); // 产品SN(弹夹码)
  2756. s4PLCData.Add("d4Result", 0); // 产品结果
  2757. // 载具上线装备(弹夹下线)
  2758. s4PLCData.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  2759. s4PLCData.Add("d5BulletclipCode", ""); // 扫到的码
  2760. s4PLCData.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  2761. s4PLCData.Add("d5VehicleCode", ""); // 扫到的码
  2762. s4PLCData.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  2763. s4PLCData.Add("d5MES_FLAG", 0); // MES_FLAG
  2764. s4PLCData.Add("d5ProductSN", ""); // 产品SN(弹夹码)
  2765. s4PLCData.Add("d5VehicleCode1", ""); // 载具1码(弹夹穴位1)
  2766. s4PLCData.Add("d5VehicleCode2", ""); // 载具2码(弹夹穴位2)
  2767. s4PLCData.Add("d5VehicleCode3", ""); // 载具3码(弹夹穴位3)
  2768. s4PLCData.Add("d5VehicleCode4", ""); // 载具4码(弹夹穴位4)
  2769. s4PLCData.Add("d5VehicleCode5", ""); // 载具5码(弹夹穴位5)
  2770. s4PLCData.Add("d5VehicleCode6", ""); // 载具6码(弹夹穴位6)
  2771. s4PLCData.Add("d5VehicleCode7", ""); // 载具7码(弹夹穴位7)
  2772. s4PLCData.Add("d5VehicleCode8", ""); // 载具8码(弹夹穴位8)
  2773. s4PLCData.Add("d5VehicleCode9", ""); // 载具9码(弹夹穴位9)
  2774. s4PLCData.Add("d5VehicleCode10", ""); // 载具10码(弹夹穴位10)
  2775. s4PLCData.Add("d5Result", 0); // 产品结果
  2776. s4PLCData.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2777. s4PLCData.Add("d5OEEMES_FLAG", 0); // MES_FLAG
  2778. s4PLCData.Add("d5OEEProductSN", "");// 产品SN(载具SN)
  2779. s4PLCData.Add("d5OEEType", 0); // 节拍类型(plc写入)
  2780. #endregion 创建字典
  2781. while (true)
  2782. {
  2783. try
  2784. {
  2785. if (!GlobalContext._IsCon_Funs4)
  2786. {
  2787. UpdatePLCMonitor(1, plcNo, 0);
  2788. continue;
  2789. }
  2790. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  2791. {
  2792. Stopwatch stopwatch1 = new Stopwatch();
  2793. Stopwatch stopwatch2 = new Stopwatch();
  2794. stopwatch1.Start();
  2795. stopwatch2.Start();
  2796. /*
  2797. #region 一次性读取所有数据
  2798. // 载具下线装备(弹夹上线)
  2799. int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  2800. int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  2801. int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  2802. int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 100);
  2803. int[] data5 = Funs[plcNo].ReadHoldingRegisters(2400, 100);
  2804. int[] data6 = Funs[plcNo].ReadHoldingRegisters(2500, 100);
  2805. int[] data7 = Funs[plcNo].ReadHoldingRegisters(2600, 100);
  2806. int[] data8 = Funs[plcNo].ReadHoldingRegisters(2700, 100);
  2807. int[] data9 = Funs[plcNo].ReadHoldingRegisters(2800, 100);
  2808. int[] data10 = Funs[plcNo].ReadHoldingRegisters(2900, 56);
  2809. int[] datas = data1.Concat(data2).ToArray();
  2810. datas = datas.Concat(data3).ToArray();
  2811. datas = datas.Concat(data4).ToArray();
  2812. datas = datas.Concat(data5).ToArray();
  2813. datas = datas.Concat(data6).ToArray();
  2814. datas = datas.Concat(data7).ToArray();
  2815. datas = datas.Concat(data8).ToArray();
  2816. datas = datas.Concat(data9).ToArray();
  2817. datas = datas.Concat(data10).ToArray();
  2818. // 载具下线装备(弹夹上线)
  2819. s4PLCData["d1BulletclipScanCode"] = datas[2]; // 扫码信号 弹夹扫码
  2820. int[] d1BulletclipCodeData = datas.Skip(3).Take(20).ToArray();
  2821. s4PLCData["d1BulletclipCode"] = ModbusClient.ConvertRegistersToString(d1BulletclipCodeData, 0, 40);
  2822. s4PLCData["d1VehicleScanCode"] = datas[33]; // 扫码信号 载具扫码
  2823. int[] d1VehicleCodeData = datas.Skip(34).Take(20).ToArray();
  2824. s4PLCData["d1VehicleCode"] = ModbusClient.ConvertRegistersToString(d1VehicleCodeData, 0, 40);
  2825. s4PLCData["d1PLC_FLAG"] = datas[64]; // PLC_FLAG 出站接口
  2826. s4PLCData["d1MES_FLAG"] = datas[65];
  2827. int[] d1ProductSNData = datas.Skip(66).Take(20).ToArray();
  2828. s4PLCData["d1ProductSN"] = ModbusClient.ConvertRegistersToString(d1ProductSNData, 0, 40); // 产品SN(物料码)
  2829. int[] d1VehicleCode1Data = datas.Skip(86).Take(20).ToArray();
  2830. s4PLCData["d1VehicleCode1"] = ModbusClient.ConvertRegistersToString(d1VehicleCode1Data, 0, 40);
  2831. int[] d1VehicleCode2Data = datas.Skip(106).Take(20).ToArray();
  2832. s4PLCData["d1VehicleCode2"] = ModbusClient.ConvertRegistersToString(d1VehicleCode2Data, 0, 40);
  2833. int[] d1VehicleCode3Data = datas.Skip(126).Take(20).ToArray();
  2834. s4PLCData["d1VehicleCode3"] = ModbusClient.ConvertRegistersToString(d1VehicleCode3Data, 0, 40);
  2835. int[] d1VehicleCode4Data = datas.Skip(146).Take(20).ToArray();
  2836. s4PLCData["d1VehicleCode4"] = ModbusClient.ConvertRegistersToString(d1VehicleCode4Data, 0, 40);
  2837. int[] d1VehicleCode5Data = datas.Skip(166).Take(20).ToArray();
  2838. s4PLCData["d1VehicleCode5"] = ModbusClient.ConvertRegistersToString(d1VehicleCode5Data, 0, 40);
  2839. int[] d1VehicleCode6Data = datas.Skip(186).Take(20).ToArray();
  2840. s4PLCData["d1VehicleCode6"] = ModbusClient.ConvertRegistersToString(d1VehicleCode6Data, 0, 40);
  2841. int[] d1VehicleCode7Data = datas.Skip(206).Take(20).ToArray();
  2842. s4PLCData["d1VehicleCode7"] = ModbusClient.ConvertRegistersToString(d1VehicleCode7Data, 0, 40);
  2843. int[] d1VehicleCode8Data = datas.Skip(226).Take(20).ToArray();
  2844. s4PLCData["d1VehicleCode8"] = ModbusClient.ConvertRegistersToString(d1VehicleCode8Data, 0, 40);
  2845. int[] d1VehicleCode9Data = datas.Skip(246).Take(20).ToArray();
  2846. s4PLCData["d1VehicleCode9"] = ModbusClient.ConvertRegistersToString(d1VehicleCode9Data, 0, 40);
  2847. int[] d1VehicleCode10Data = datas.Skip(266).Take(20).ToArray();
  2848. s4PLCData["d1VehicleCode10"] = ModbusClient.ConvertRegistersToString(d1VehicleCode10Data, 0, 40);
  2849. int[] d1VehicleCode11Data = datas.Skip(286).Take(20).ToArray();
  2850. s4PLCData["d1VehicleCode11"] = ModbusClient.ConvertRegistersToString(d1VehicleCode11Data, 0, 40);
  2851. int[] d1VehicleCode12Data = datas.Skip(306).Take(20).ToArray();
  2852. s4PLCData["d1VehicleCode12"] = ModbusClient.ConvertRegistersToString(d1VehicleCode12Data, 0, 40);
  2853. int[] d1VehicleCode13Data = datas.Skip(326).Take(20).ToArray();
  2854. s4PLCData["d1VehicleCode13"] = ModbusClient.ConvertRegistersToString(d1VehicleCode13Data, 0, 40);
  2855. int[] d1VehicleCode14Data = datas.Skip(346).Take(20).ToArray();
  2856. s4PLCData["d1VehicleCode14"] = ModbusClient.ConvertRegistersToString(d1VehicleCode14Data, 0, 40);
  2857. int[] d1VehicleCode15Data = datas.Skip(366).Take(20).ToArray();
  2858. s4PLCData["d1VehicleCode15"] = ModbusClient.ConvertRegistersToString(d1VehicleCode15Data, 0, 40);
  2859. s4PLCData["d1Result"] = datas[386];
  2860. s4PLCData["d1OEEPLC_FLAG"] = datas[397]; // PLC_FLAG 节拍接口
  2861. s4PLCData["d1OEEMES_FLAG"] = datas[398];
  2862. int[] d1OEEProductSNData = datas.Skip(399).Take(20).ToArray();
  2863. s4PLCData["d1OEEProductSN"] = ModbusClient.ConvertRegistersToString(d1OEEProductSNData, 0, 40);
  2864. s4PLCData["d1OEEType"] = datas[419];
  2865. // 桁架(查询标机中弹夹的状态)
  2866. s4PLCData["d2BulletclipScanCode"] = datas[430];
  2867. s4PLCData["d2BulletclipStates"] = datas[431];
  2868. int[] d2BulletclipCodeData = datas.Skip(432).Take(20).ToArray();
  2869. s4PLCData["d2BulletclipCode"] = ModbusClient.ConvertRegistersToString(d2BulletclipCodeData, 0, 40);
  2870. // 真空标机
  2871. s4PLCData["d3PLC_FLAG"] = datas[462]; // 真空标机1 出站接口
  2872. s4PLCData["d3MES_FLAG"] = datas[463];
  2873. int[] d3ProductSNData = datas.Skip(464).Take(20).ToArray();
  2874. s4PLCData["d3ProductSN"] = ModbusClient.ConvertRegistersToString(d3ProductSNData, 0, 40);
  2875. s4PLCData["d3Result"] = datas[484];
  2876. s4PLCData["d3Type"] = datas[485];
  2877. s4PLCData["d4PLC_FLAG"] = datas[495]; // 真空标机2 出站接口
  2878. s4PLCData["d4MES_FLAG"] = datas[496];
  2879. int[] d4ProductSNData = datas.Skip(497).Take(20).ToArray();
  2880. s4PLCData["d4ProductSN"] = ModbusClient.ConvertRegistersToString(d4ProductSNData, 0, 40);
  2881. s4PLCData["d4Result"] = datas[517];
  2882. s4PLCData["d4Type"] = datas[518];
  2883. // 载具上线装备(弹夹下线)
  2884. s4PLCData["d5BulletclipScanCode"] = datas[528]; // 扫码信号 弹夹扫码
  2885. int[] d5BulletclipCodeData = datas.Skip(529).Take(20).ToArray();
  2886. s4PLCData["d5BulletclipCode"] = ModbusClient.ConvertRegistersToString(d5BulletclipCodeData, 0, 40);
  2887. s4PLCData["d5VehicleScanCode"] = datas[559]; // 扫码信号 载具扫码
  2888. int[] d5VehicleCodeData = datas.Skip(560).Take(20).ToArray();
  2889. s4PLCData["d5VehicleCode"] = ModbusClient.ConvertRegistersToString(d5VehicleCodeData, 0, 40);
  2890. s4PLCData["d5PLC_FLAG"] = datas[590]; // PLC_FLAG 出站接口
  2891. s4PLCData["d5MES_FLAG"] = datas[591];
  2892. int[] d5ProductSNData = datas.Skip(592).Take(20).ToArray();
  2893. s4PLCData["d5ProductSN"] = ModbusClient.ConvertRegistersToString(d5ProductSNData, 0, 40); // 产品SN(物料码)
  2894. int[] d5VehicleCode1Data = datas.Skip(612).Take(20).ToArray();
  2895. s4PLCData["d5VehicleCode1"] = ModbusClient.ConvertRegistersToString(d5VehicleCode1Data, 0, 40);
  2896. int[] d5VehicleCode2Data = datas.Skip(632).Take(20).ToArray();
  2897. s4PLCData["d5VehicleCode2"] = ModbusClient.ConvertRegistersToString(d5VehicleCode2Data, 0, 40);
  2898. int[] d5VehicleCode3Data = datas.Skip(652).Take(20).ToArray();
  2899. s4PLCData["d5VehicleCode3"] = ModbusClient.ConvertRegistersToString(d5VehicleCode3Data, 0, 40);
  2900. int[] d5VehicleCode4Data = datas.Skip(672).Take(20).ToArray();
  2901. s4PLCData["d5VehicleCode4"] = ModbusClient.ConvertRegistersToString(d5VehicleCode4Data, 0, 40);
  2902. int[] d5VehicleCode5Data = datas.Skip(692).Take(20).ToArray();
  2903. s4PLCData["d5VehicleCode5"] = ModbusClient.ConvertRegistersToString(d5VehicleCode5Data, 0, 40);
  2904. int[] d5VehicleCode6Data = datas.Skip(712).Take(20).ToArray();
  2905. s4PLCData["d5VehicleCode6"] = ModbusClient.ConvertRegistersToString(d5VehicleCode6Data, 0, 40);
  2906. int[] d5VehicleCode7Data = datas.Skip(732).Take(20).ToArray();
  2907. s4PLCData["d5VehicleCode7"] = ModbusClient.ConvertRegistersToString(d5VehicleCode7Data, 0, 40);
  2908. int[] d5VehicleCode8Data = datas.Skip(752).Take(20).ToArray();
  2909. s4PLCData["d5VehicleCode8"] = ModbusClient.ConvertRegistersToString(d5VehicleCode8Data, 0, 40);
  2910. int[] d5VehicleCode9Data = datas.Skip(772).Take(20).ToArray();
  2911. s4PLCData["d5VehicleCode9"] = ModbusClient.ConvertRegistersToString(d5VehicleCode9Data, 0, 40);
  2912. int[] d5VehicleCode10Data = datas.Skip(792).Take(20).ToArray();
  2913. s4PLCData["d5VehicleCode10"] = ModbusClient.ConvertRegistersToString(d5VehicleCode10Data, 0, 40);
  2914. int[] d5VehicleCode11Data = datas.Skip(812).Take(20).ToArray();
  2915. s4PLCData["d5VehicleCode11"] = ModbusClient.ConvertRegistersToString(d5VehicleCode11Data, 0, 40);
  2916. int[] d5VehicleCode12Data = datas.Skip(832).Take(20).ToArray();
  2917. s4PLCData["d5VehicleCode12"] = ModbusClient.ConvertRegistersToString(d5VehicleCode12Data, 0, 40);
  2918. int[] d5VehicleCode13Data = datas.Skip(852).Take(20).ToArray();
  2919. s4PLCData["d5VehicleCode13"] = ModbusClient.ConvertRegistersToString(d5VehicleCode13Data, 0, 40);
  2920. int[] d5VehicleCode14Data = datas.Skip(872).Take(20).ToArray();
  2921. s4PLCData["d5VehicleCode14"] = ModbusClient.ConvertRegistersToString(d5VehicleCode14Data, 0, 40);
  2922. int[] d5VehicleCode15Data = datas.Skip(892).Take(20).ToArray();
  2923. s4PLCData["d5VehicleCode15"] = ModbusClient.ConvertRegistersToString(d5VehicleCode15Data, 0, 40);
  2924. s4PLCData["d5Result"] = datas[912];
  2925. s4PLCData["d5OEEPLC_FLAG"] = datas[923]; // PLC_FLAG 节拍接口
  2926. s4PLCData["d5OEEMES_FLAG"] = datas[924];
  2927. int[] d5OEEProductSNData = datas.Skip(925).Take(20).ToArray();
  2928. s4PLCData["d5OEEProductSN"] = ModbusClient.ConvertRegistersToString(d5OEEProductSNData, 0, 40);
  2929. s4PLCData["d5OEEType"] = datas[945];
  2930. #endregion 一次性读取所有数据
  2931. stopwatch2.Stop();
  2932. #region 回写操作,写后清空flag
  2933. PLCWriteData(Funs[plcNo], ref s4PLCData, ref s4PLCWriteData);
  2934. #endregion 回写操作,写后清空flag
  2935. */
  2936. // N801A-S4_1 弹夹扫码
  2937. #region N801A-S4_1 弹夹扫码
  2938. try
  2939. {
  2940. int d1BulletclipScanCode = (int)s4PLCData["d1BulletclipScanCode"];
  2941. int d1BulletclipScanCodeOld = (int)s4PLCSignal_Old["d1BulletclipScanCode"];
  2942. if (d1BulletclipScanCode != d1BulletclipScanCodeOld)
  2943. {
  2944. if (d1BulletclipScanCode == 1) // 0->1
  2945. Task.Run(() => S4_1弹夹扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  2946. s4PLCSignal_Old["d1BulletclipScanCode"] = s4PLCData["d1BulletclipScanCode"];
  2947. }
  2948. }
  2949. catch (Exception ex)
  2950. {
  2951. //Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  2952. string str = ex.StackTrace;
  2953. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2954. }
  2955. #endregion N801A-S4_1 弹夹扫码
  2956. // N801A-S4_1 载具扫码
  2957. #region N801A-S4_1 载具扫码
  2958. try
  2959. {
  2960. int d1VehicleScanCode = (int)s4PLCData["d1VehicleScanCode"];
  2961. int d1VehicleScanCodeOld = (int)s4PLCSignal_Old["d1VehicleScanCode"];
  2962. if (d1VehicleScanCode != d1VehicleScanCodeOld)
  2963. {
  2964. if (d1VehicleScanCode == 1) // 0->1
  2965. Task.Run(() => S4_1载具扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  2966. s4PLCSignal_Old["d1VehicleScanCode"] = s4PLCData["d1VehicleScanCode"];
  2967. }
  2968. }
  2969. catch (Exception ex)
  2970. {
  2971. //Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  2972. string str = ex.StackTrace;
  2973. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2974. }
  2975. #endregion N801A-S4_1 载具扫码
  2976. // N801A-S4_1 出站接口
  2977. #region N801A-S4_1 出站接口
  2978. try
  2979. {
  2980. int d1PLC_FLAG = (int)s4PLCData["d1PLC_FLAG"];
  2981. int d1MES_FLAG = (int)s4PLCData["d1MES_FLAG"];
  2982. int d1PLC_FLAGOld = (int)s4PLCSignal_Old["d1PLC_FLAG"];
  2983. if (d1PLC_FLAG != d1PLC_FLAGOld)
  2984. {
  2985. if (d1PLC_FLAG == 1 && d1MES_FLAG == 0) // 0->1
  2986. Task.Run(() => S4_1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  2987. //else if (d1PLC_FLAG == 0 && d1MES_FLAG != 0)
  2988. //Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)0);
  2989. s4PLCSignal_Old["d1PLC_FLAG"] = s4PLCData["d1PLC_FLAG"];
  2990. }
  2991. }
  2992. catch (Exception ex)
  2993. {
  2994. //Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)6); // 6代表上位机报警
  2995. string str = ex.StackTrace;
  2996. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2997. }
  2998. #endregion N801A-S4_1 出站接口
  2999. // N801A-S4_1 节拍接口
  3000. #region N801A-S4_1 节拍接口
  3001. try
  3002. {
  3003. int d1OEEPLC_FLAG = (int)s4PLCData["d1OEEPLC_FLAG"];
  3004. int d1OEEMES_FLAG = (int)s4PLCData["d1OEEMES_FLAG"];
  3005. int d1OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d1OEEPLC_FLAG"];
  3006. if (d1OEEPLC_FLAG != d1OEEPLC_FLAGOld)
  3007. {
  3008. if (d1OEEPLC_FLAG == 1 && d1OEEMES_FLAG == 0) // 0->1
  3009. Task.Run(() => S4_1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  3010. //else if (d1OEEPLC_FLAG == 0 && d1OEEMES_FLAG != 0)
  3011. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)0);
  3012. s4PLCSignal_Old["d1OEEPLC_FLAG"] = s4PLCData["d1OEEPLC_FLAG"];
  3013. }
  3014. }
  3015. catch (Exception ex)
  3016. {
  3017. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  3018. string str = ex.StackTrace;
  3019. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3020. }
  3021. #endregion N801A-S4_1 节拍接口
  3022. // N801A-S4_2 桁架(查询标机中弹夹的状态) 数据
  3023. #region N801A-S4_2 桁架(查询标机中弹夹的状态)
  3024. try
  3025. {
  3026. int d2BulletclipScanCode = (int)s4PLCData["d2BulletclipScanCode"];
  3027. int d2BulletclipScanCodeOld = (int)s4PLCSignal_Old["d2BulletclipScanCode"];
  3028. if (d2BulletclipScanCode != d2BulletclipScanCodeOld)
  3029. {
  3030. if (d2BulletclipScanCode == 1) // 0->1
  3031. Task.Run(() => S4_2桁架(plcNo, stationNameStr)); // MreTasks[1].Set();
  3032. s4PLCSignal_Old["d2BulletclipScanCode"] = s4PLCData["d2BulletclipScanCode"];
  3033. }
  3034. }
  3035. catch (Exception ex)
  3036. {
  3037. //Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  3038. string str = ex.StackTrace;
  3039. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 桁架出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3040. }
  3041. #endregion N801A-S4_2 桁架(查询标机中弹夹的状态)
  3042. // N801A-S4_3 真空标机1 数据
  3043. #region N801A-S4_3 真空标机1
  3044. try
  3045. {
  3046. int d3PLC_FLAG = (int)s4PLCData["d3PLC_FLAG"];
  3047. int d3MES_FLAG = (int)s4PLCData["d3MES_FLAG"];
  3048. int d3PLC_FLAGOld = (int)s4PLCSignal_Old["d3PLC_FLAG"];
  3049. if (d3PLC_FLAG != d3PLC_FLAGOld)
  3050. {
  3051. if (d3PLC_FLAG == 1 && d3MES_FLAG == 0) // 0->1
  3052. {
  3053. int stationType = (int)s4PLCData["d3Type"];
  3054. if (stationType == 1)
  3055. {
  3056. // S4_3进站接口
  3057. Task.Run(() => S4_3进站接口(plcNo, stationNameStr)); // MreTasks[3].Set();
  3058. }
  3059. else if (stationType == 2)
  3060. {
  3061. // S4_3出站接口
  3062. Task.Run(() => S4_3出站接口(plcNo, stationNameStr)); // MreTasks[3].Set();
  3063. }
  3064. }
  3065. //else if (d3PLC_FLAG == 0 && d3MES_FLAG != 0)
  3066. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)0);
  3067. s4PLCSignal_Old["d3PLC_FLAG"] = s4PLCData["d3PLC_FLAG"];
  3068. }
  3069. }
  3070. catch (Exception ex)
  3071. {
  3072. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  3073. string str = ex.StackTrace;
  3074. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3075. }
  3076. #endregion N801A-S4_3 真空标机1
  3077. // N801A-S4_4 真空标机2 数据
  3078. #region N801A-S4_4 真空标机2
  3079. try
  3080. {
  3081. int d4PLC_FLAG = (int)s4PLCData["d4PLC_FLAG"];
  3082. int d4MES_FLAG = (int)s4PLCData["d4MES_FLAG"];
  3083. int d4PLC_FLAGOld = (int)s4PLCSignal_Old["d4PLC_FLAG"];
  3084. if (d4PLC_FLAG != d4PLC_FLAGOld)
  3085. {
  3086. if (d4PLC_FLAG == 1 && d4MES_FLAG == 0) // 0->1
  3087. {
  3088. int stationType = (int)s4PLCData["d4Type"];
  3089. if (stationType == 1)
  3090. {
  3091. // S4_4进站接口
  3092. Task.Run(() => S4_4进站接口(plcNo, stationNameStr)); // MreTasks[3].Set();
  3093. }
  3094. else if (stationType == 2)
  3095. {
  3096. // S4_4出站接口
  3097. Task.Run(() => S4_4出站接口(plcNo, stationNameStr)); // MreTasks[3].Set();
  3098. }
  3099. }
  3100. //else if (d4PLC_FLAG == 0 && d4MES_FLAG != 0)
  3101. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)0);
  3102. s4PLCSignal_Old["d4PLC_FLAG"] = s4PLCData["d4PLC_FLAG"];
  3103. }
  3104. }
  3105. catch (Exception ex)
  3106. {
  3107. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  3108. string str = ex.StackTrace;
  3109. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3110. }
  3111. #endregion N801A-S4_4 真空标机2
  3112. // N801A-S4_5 弹夹扫码 数据
  3113. #region N801A-S4_5 弹夹扫码
  3114. try
  3115. {
  3116. int d5BulletclipScanCode = (int)s4PLCData["d5BulletclipScanCode"];
  3117. int d5BulletclipScanCodeOld = (int)s4PLCSignal_Old["d5BulletclipScanCode"];
  3118. if (d5BulletclipScanCode != d5BulletclipScanCodeOld)
  3119. {
  3120. if (d5BulletclipScanCode == 1) // 0->1
  3121. Task.Run(() => S4_5弹夹扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  3122. s4PLCSignal_Old["d5BulletclipScanCode"] = s4PLCData["d5BulletclipScanCode"];
  3123. }
  3124. }
  3125. catch (Exception ex)
  3126. {
  3127. //Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  3128. string str = ex.StackTrace;
  3129. AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3130. }
  3131. #endregion N801A-S4_5 弹夹扫码
  3132. // N801A-S4_5 载具扫码 数据
  3133. #region N801A-S4_5 载具扫码
  3134. try
  3135. {
  3136. int d5VehicleScanCode = (int)s4PLCData["d5VehicleScanCode"];
  3137. int d5VehicleScanCodeOld = (int)s4PLCSignal_Old["d5VehicleScanCode"];
  3138. if (d5VehicleScanCode != d5VehicleScanCodeOld)
  3139. {
  3140. if (d5VehicleScanCode == 1) // 0->1
  3141. Task.Run(() => S4_5载具扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  3142. s4PLCSignal_Old["d5VehicleScanCode"] = s4PLCData["d5VehicleScanCode"];
  3143. }
  3144. }
  3145. catch (Exception ex)
  3146. {
  3147. //Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  3148. string str = ex.StackTrace;
  3149. AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3150. }
  3151. #endregion N801A-S4_5 载具扫码
  3152. // N801A-S4_5 出站接口(扫完所有码后立即上传) 数据
  3153. #region N801A-S4_5 出站接口
  3154. try
  3155. {
  3156. int d5PLC_FLAG = (int)s4PLCData["d5PLC_FLAG"];
  3157. int d5MES_FLAG = (int)s4PLCData["d5MES_FLAG"];
  3158. int d5PLC_FLAGOld = (int)s4PLCSignal_Old["d5PLC_FLAG"];
  3159. if (d5PLC_FLAG != d5PLC_FLAGOld)
  3160. {
  3161. if (d5PLC_FLAG == 1 && d5MES_FLAG == 0) // 0->1
  3162. Task.Run(() => S4_5出站接口(plcNo, stationCode5, stationName5)); // MreTasks[3].Set();
  3163. //else if (d5PLC_FLAG == 0 && d5MES_FLAG != 0)
  3164. //Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)0);
  3165. s4PLCSignal_Old["d5PLC_FLAG"] = s4PLCData["d5PLC_FLAG"];
  3166. }
  3167. }
  3168. catch (Exception ex)
  3169. {
  3170. //Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)6); // 6代表上位机报警
  3171. string str = ex.StackTrace;
  3172. AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3173. }
  3174. #endregion N801A-S4_5 出站接口
  3175. // N801A-S4_5 节拍接口 数据
  3176. #region N801A-S4_5 节拍接口
  3177. try
  3178. {
  3179. int d5OEEPLC_FLAG = (int)s4PLCData["d5OEEPLC_FLAG"];
  3180. int d5OEEMES_FLAG = (int)s4PLCData["d5OEEMES_FLAG"];
  3181. int d5OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d5OEEPLC_FLAG"];
  3182. if (d5OEEPLC_FLAG != d5OEEPLC_FLAGOld)
  3183. {
  3184. if (d5OEEPLC_FLAG == 1 && d5OEEMES_FLAG == 0) // 0->1
  3185. Task.Run(() => S4_5节拍接口(plcNo, stationNameStr5)); // MreTasks[4].Set();
  3186. //else if (d5OEEPLC_FLAG == 0 && d5OEEMES_FLAG != 0)
  3187. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)0);
  3188. s4PLCSignal_Old["d5OEEPLC_FLAG"] = s4PLCData["d5OEEPLC_FLAG"];
  3189. }
  3190. }
  3191. catch (Exception ex)
  3192. {
  3193. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  3194. string str = ex.StackTrace;
  3195. AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3196. }
  3197. #endregion N801A-S4_5 节拍接口
  3198. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3199. stopwatch1.Stop();
  3200. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  3201. OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3202. }
  3203. else
  3204. {
  3205. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3206. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3207. Funs[plcNo].Connect();
  3208. }
  3209. }
  3210. catch (Exception ex)
  3211. {
  3212. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3213. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3214. //Funs[plcNo].ReConnect();
  3215. }
  3216. Thread.Sleep(IntervalReadPLC);
  3217. }
  3218. }
  3219. /// <summary>
  3220. /// [S4] 取放桁架 - S4_1弹夹扫码
  3221. /// </summary>
  3222. /// <param name="plcNo">PLC编号</param>
  3223. /// <param name="stationNameStr">工站全称</param>
  3224. private void S4_1弹夹扫码(int plcNo, string stationNameStr)
  3225. {
  3226. Stopwatch stopwatch1 = new Stopwatch();
  3227. Stopwatch stopwatch2 = new Stopwatch();
  3228. try
  3229. {
  3230. stopwatch1.Start();
  3231. // ZS 弹夹扫码
  3232. string d1BulletclipCode = " "; // 扫到的码
  3233. short d1BulletclipScanCode = 2;
  3234. stopwatch2.Start();
  3235. //Funs[plcNo].WriteMultipleRegisters<string>(2003, d1BulletclipCode, 20);
  3236. //// MES_Flag
  3237. //Funs[plcNo].WriteMultipleRegisters<short>(2002, d1BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  3238. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  3239. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  3240. writeToPLC_Flag.Adress = 2002;
  3241. writeToPLC_Flag.Value = d1BulletclipScanCode;
  3242. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  3243. {
  3244. Name = "d1BulletclipCode",
  3245. Adress = 2003,
  3246. ValueType = PLCValueType.String,
  3247. ValueTypeStrLength = 20,
  3248. Value = d1BulletclipCode
  3249. });
  3250. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  3251. stopwatch2.Stop();
  3252. }
  3253. catch (Exception ex)
  3254. {
  3255. string str = ex.StackTrace;
  3256. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3257. stopwatch2.Start();
  3258. //Funs[plcNo].WriteMultipleRegisters<string>(2003, " ", 20);
  3259. //// MES_Flag
  3260. //Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  3261. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  3262. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  3263. writeToPLC_Flag.Adress = 2002;
  3264. writeToPLC_Flag.Value = (short)6;
  3265. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  3266. {
  3267. Name = "d1BulletclipCode",
  3268. Adress = 2003,
  3269. ValueType = PLCValueType.String,
  3270. ValueTypeStrLength = 20,
  3271. Value = " "
  3272. });
  3273. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  3274. stopwatch2.Stop();
  3275. }
  3276. stopwatch1.Stop();
  3277. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3278. }
  3279. /// <summary>
  3280. /// [S4] 取放桁架 - S4_1载具扫码
  3281. /// </summary>
  3282. /// <param name="plcNo">PLC编号</param>
  3283. /// <param name="stationNameStr">工站全称</param>
  3284. private void S4_1载具扫码(int plcNo, string stationNameStr)
  3285. {
  3286. Stopwatch stopwatch1 = new Stopwatch();
  3287. Stopwatch stopwatch2 = new Stopwatch();
  3288. try
  3289. {
  3290. stopwatch1.Start();
  3291. // ZS 载具扫码
  3292. string d1VehicleCode = " "; // 扫到的码
  3293. // 查产品SN
  3294. string partNo = " ";
  3295. short d1VehicleScanCode = 2;
  3296. #region 进站
  3297. if (!string.IsNullOrEmpty(d1VehicleCode))
  3298. {
  3299. List<TestItem> item = new List<TestItem>();
  3300. item.Add(new TestItem()
  3301. {
  3302. Parameter_name = "载具码",
  3303. Parameter_value = d1VehicleCode,
  3304. });
  3305. item.Add(new TestItem()
  3306. {
  3307. Parameter_name = "载具穴号",
  3308. Parameter_value = "1",
  3309. });
  3310. stopwatch2.Start();
  3311. int result = 0;
  3312. //int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item);
  3313. stopwatch2.Stop();
  3314. d1VehicleScanCode = (short)result == 1 ? d1VehicleScanCode : (short)result;
  3315. }
  3316. #endregion 进站
  3317. //Funs[plcNo].WriteMultipleRegisters<string>(2034, d1VehicleCode, 20);
  3318. //// MES_Flag
  3319. //Funs[plcNo].WriteMultipleRegisters<short>(2033, d1VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  3320. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  3321. writeToPLC_Flag.Name = "d1VehicleScanCode";
  3322. writeToPLC_Flag.Adress = 2033;
  3323. writeToPLC_Flag.Value = d1VehicleScanCode;
  3324. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  3325. {
  3326. Name = "d1VehicleCode",
  3327. Adress = 2034,
  3328. ValueType = PLCValueType.String,
  3329. ValueTypeStrLength = 20,
  3330. Value = d1VehicleCode
  3331. });
  3332. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  3333. }
  3334. catch (Exception ex)
  3335. {
  3336. string str = ex.StackTrace;
  3337. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3338. stopwatch2.Start();
  3339. //Funs[plcNo].WriteMultipleRegisters<string>(2034, " ", 20);
  3340. //// MES_Flag
  3341. //Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  3342. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  3343. writeToPLC_Flag.Name = "d1VehicleScanCode";
  3344. writeToPLC_Flag.Adress = 2033;
  3345. writeToPLC_Flag.Value = (short)6; // 6代表上位机报警
  3346. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  3347. {
  3348. Name = "d1VehicleCode",
  3349. Adress = 2034,
  3350. ValueType = PLCValueType.String,
  3351. ValueTypeStrLength = 20,
  3352. Value = " "
  3353. });
  3354. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  3355. stopwatch2.Stop();
  3356. }
  3357. stopwatch1.Stop();
  3358. AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3359. }
  3360. // 上次采集到的SN
  3361. //private string sn_S4_1出站接口 = string.Empty;
  3362. /// <summary>
  3363. /// [S4] 取放桁架 - S4_1出站接口
  3364. /// </summary>
  3365. private void S4_1出站接口(int plcNo, string stationCode, string stationName)
  3366. {
  3367. Stopwatch stopwatch1 = new Stopwatch();
  3368. Stopwatch stopwatch2 = new Stopwatch();
  3369. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3370. string stationNameStr = stationCode + stationName;
  3371. string processItem = stationName; // 测试项目
  3372. try
  3373. {
  3374. stopwatch1.Start();
  3375. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3376. string batch_num = GlobalContext.BatchNumber; // 批次号
  3377. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3378. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3379. string supplierCode = ""; // 供应商代码
  3380. string sn = (string)s4PLCData["d1ProductSN"]; // 产品SN(弹夹码)
  3381. sn = sn.Replace("\0", "");
  3382. string d1VehicleCode1 = (string)s4PLCData["d1VehicleCode1"]; // 载具1码(弹夹穴位1)
  3383. string d1VehicleCode2 = (string)s4PLCData["d1VehicleCode2"]; // 载具2码(弹夹穴位2)
  3384. string d1VehicleCode3 = (string)s4PLCData["d1VehicleCode3"]; // 载具3码(弹夹穴位3)
  3385. string d1VehicleCode4 = (string)s4PLCData["d1VehicleCode4"]; // 载具4码(弹夹穴位4)
  3386. string d1VehicleCode5 = (string)s4PLCData["d1VehicleCode5"]; // 载具5码(弹夹穴位5)
  3387. string d1VehicleCode6 = (string)s4PLCData["d1VehicleCode6"]; // 载具6码(弹夹穴位6)
  3388. string d1VehicleCode7 = (string)s4PLCData["d1VehicleCode7"]; // 载具7码(弹夹穴位7)
  3389. string d1VehicleCode8 = (string)s4PLCData["d1VehicleCode8"]; // 载具8码(弹夹穴位8)
  3390. string d1VehicleCode9 = (string)s4PLCData["d1VehicleCode9"]; // 载具9码(弹夹穴位9)
  3391. string d1VehicleCode10 = (string)s4PLCData["d1VehicleCode10"]; // 载具10码(弹夹穴位10)
  3392. string d1VehicleCode11 = (string)s4PLCData["d1VehicleCode11"]; // 载具11码(弹夹穴位11)
  3393. string d1VehicleCode12 = (string)s4PLCData["d1VehicleCode12"]; // 载具12码(弹夹穴位12)
  3394. string d1VehicleCode13 = (string)s4PLCData["d1VehicleCode13"]; // 载具13码(弹夹穴位13)
  3395. string d1VehicleCode14 = (string)s4PLCData["d1VehicleCode14"]; // 载具14码(弹夹穴位14)
  3396. string d1VehicleCode15 = (string)s4PLCData["d1VehicleCode15"]; // 载具15码(弹夹穴位15)
  3397. int d1Result = (int)s4PLCData["d1Result"]; // 产品结果
  3398. bool pass = d1Result == 1;
  3399. List<TestItem> items1 = new List<TestItem>();
  3400. items1.Add(new TestItem()
  3401. {
  3402. Parameter_name = "产品结果",
  3403. Parameter_value = d1Result == 1 ? "OK" : "NG",
  3404. Parameter_unit = ""
  3405. });
  3406. int result1 = 0;
  3407. //int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  3408. //, workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, d1VehicleCode1, "1");
  3409. //int result = result1 == 1 ? 1 : (GlobalContext.IsSendProcessData ? 4 : 1);
  3410. short result = result1 == 1 ? (short)1 : (short)3;
  3411. stopwatch2.Start();
  3412. // MES_Flag 为4MES报错
  3413. //Funs[plcNo].WriteMultipleRegisters<short>(2065, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  3414. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  3415. writeToPLC_Flag.Name = "d1MES_FLAG";
  3416. writeToPLC_Flag.Adress = 2065;
  3417. writeToPLC_Flag.Value = result;
  3418. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  3419. stopwatch2.Stop();
  3420. WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  3421. }
  3422. catch (Exception ex)
  3423. {
  3424. stopwatch2.Start();
  3425. // MES_Flag 为4上位机报错
  3426. //Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)4); // 4代表上位机报警
  3427. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  3428. writeToPLC_Flag.Name = "d1MES_FLAG";
  3429. writeToPLC_Flag.Adress = 2065;
  3430. writeToPLC_Flag.Value = (short)4;
  3431. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  3432. stopwatch2.Stop();
  3433. string str = ex.StackTrace;
  3434. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3435. }
  3436. stopwatch1.Stop();
  3437. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3438. }
  3439. /// <summary>
  3440. /// [S4] 取放桁架 - S4_1节拍接口
  3441. /// </summary>
  3442. /// <param name="plcNo">PLC编号</param>
  3443. /// <param name="stationNameStr">工站全称</param>
  3444. private void S4_1节拍接口(int plcNo, string stationNameStr)
  3445. {
  3446. Stopwatch stopwatch1 = new Stopwatch();
  3447. Stopwatch stopwatch2 = new Stopwatch();
  3448. string resultStr = string.Empty;
  3449. try
  3450. {
  3451. stopwatch1.Start();
  3452. string oEEType = ((int)s4PLCData["d1OEEType"]).ToString(); // 节拍类型(plc写入)
  3453. string d1OEEProductSN = (string)s4PLCData["d1OEEProductSN"]; // 载具SN
  3454. d1OEEProductSN = d1OEEProductSN.Replace("\0", "");
  3455. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  3456. if (!actionBool)
  3457. {
  3458. stopwatch2.Start();
  3459. // MES_Flag
  3460. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  3461. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  3462. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  3463. writeToPLC_Flag1.Adress = 2398;
  3464. writeToPLC_Flag1.Value = (short)4;
  3465. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  3466. stopwatch2.Stop();
  3467. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3468. return;
  3469. }
  3470. string d1OEEPartNo = string.Empty; // 物料码
  3471. if (string.IsNullOrEmpty(d1OEEProductSN))
  3472. {
  3473. stopwatch2.Start();
  3474. // MES_Flag
  3475. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  3476. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  3477. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  3478. writeToPLC_Flag1.Adress = 2398;
  3479. writeToPLC_Flag1.Value = (short)1;
  3480. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  3481. stopwatch2.Stop();
  3482. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3483. return;
  3484. }
  3485. else
  3486. { // 查产品SN
  3487. d1OEEPartNo = "Test"; // ZS
  3488. }
  3489. short d1OEEMES_FLAG = 0;
  3490. // 上传OEE
  3491. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d1OEEPartNo, d1OEEProductSN);
  3492. d1OEEMES_FLAG = result.Item1;
  3493. resultStr = result.Item2;
  3494. stopwatch2.Start();
  3495. // MES_Flag
  3496. //Funs[plcNo].WriteMultipleRegisters<short>(2398, d1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  3497. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  3498. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  3499. writeToPLC_Flag.Adress = 2398;
  3500. writeToPLC_Flag.Value = d1OEEMES_FLAG;
  3501. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  3502. stopwatch2.Stop();
  3503. }
  3504. catch (Exception ex)
  3505. {
  3506. string str = ex.StackTrace;
  3507. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3508. // MES_Flag
  3509. stopwatch2.Start();
  3510. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  3511. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  3512. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  3513. writeToPLC_Flag.Adress = 2398;
  3514. writeToPLC_Flag.Value = (short)4;
  3515. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  3516. stopwatch2.Stop();
  3517. }
  3518. stopwatch1.Stop();
  3519. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3520. }
  3521. /// <summary>
  3522. /// [S4] 取放桁架 - S4_2桁架
  3523. /// </summary>
  3524. /// <param name="plcNo">PLC编号</param>
  3525. /// <param name="stationNameStr">工站全称</param>
  3526. private void S4_2桁架(int plcNo, string stationNameStr)
  3527. {
  3528. Stopwatch stopwatch1 = new Stopwatch();
  3529. Stopwatch stopwatch2 = new Stopwatch();
  3530. try
  3531. {
  3532. stopwatch1.Start();
  3533. // ZS 弹夹扫码
  3534. string d2BulletclipCode = " "; // 扫到的码
  3535. short d2BulletclipStates = 1; // 弹夹状态(上位机写入)
  3536. short d2BulletclipScanCode = 2;
  3537. stopwatch2.Start();
  3538. //Funs[plcNo].WriteMultipleRegisters<string>(2432, d2BulletclipCode, 20); // 扫到的码
  3539. //Funs[plcNo].WriteMultipleRegisters<short>(2431, d2BulletclipStates); // 弹夹状态(上位机写入)
  3540. //// MES_Flag
  3541. //Funs[plcNo].WriteMultipleRegisters<short>(2430, d2BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  3542. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  3543. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  3544. writeToPLC_Flag.Adress = 2430;
  3545. writeToPLC_Flag.Value = d2BulletclipScanCode;
  3546. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  3547. {
  3548. Name = "d2BulletclipCode",
  3549. Adress = 2432,
  3550. ValueType = PLCValueType.String,
  3551. ValueTypeStrLength = 20,
  3552. Value = d2BulletclipCode
  3553. });
  3554. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  3555. {
  3556. Name = "d2BulletclipStates",
  3557. Adress = 2431,
  3558. ValueType = PLCValueType.Short,
  3559. Value = d2BulletclipStates
  3560. });
  3561. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  3562. stopwatch2.Stop();
  3563. }
  3564. catch (Exception ex)
  3565. {
  3566. string str = ex.StackTrace;
  3567. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3568. stopwatch2.Start();
  3569. //Funs[plcNo].WriteMultipleRegisters<string>(2432, " ", 20);
  3570. //Funs[plcNo].WriteMultipleRegisters<short>(2431, (short)0);
  3571. // MES_Flag
  3572. //Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  3573. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  3574. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  3575. writeToPLC_Flag.Adress = 2430;
  3576. writeToPLC_Flag.Value = (short)6;
  3577. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  3578. {
  3579. Name = "d2BulletclipCode",
  3580. Adress = 2432,
  3581. ValueType = PLCValueType.String,
  3582. ValueTypeStrLength = 20,
  3583. Value = " "
  3584. });
  3585. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  3586. {
  3587. Name = "d2BulletclipStates",
  3588. Adress = 2431,
  3589. ValueType = PLCValueType.Short,
  3590. Value = (short)0
  3591. });
  3592. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  3593. stopwatch2.Stop();
  3594. }
  3595. stopwatch1.Stop();
  3596. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3597. }
  3598. // 上次采集到的SN
  3599. //private string sn_S4_3进站接口 = string.Empty;
  3600. /// <summary>
  3601. /// [S4] 取放桁架 - S4_3进站接口(提升机1)
  3602. /// </summary>
  3603. private void S4_3进站接口(int plcNo, string stationNameStr)
  3604. {
  3605. Stopwatch stopwatch1 = new Stopwatch();
  3606. Stopwatch stopwatch2 = new Stopwatch();
  3607. try
  3608. {
  3609. stopwatch1.Start();
  3610. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  3611. sn = sn.Replace("\0", "");
  3612. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  3613. // ZS 查询15个载具码与15个产品SN
  3614. List<string> vehicleCodes = new string[15].ToList();
  3615. List<string> portNos = new string[15].ToList();
  3616. // 调用MES进站(最多15个)
  3617. stopwatch2.Start();
  3618. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  3619. for (int i = 0; i < vehicleCodes.Count; i++)
  3620. {
  3621. // 循环进站
  3622. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  3623. {
  3624. // 产品SN(物料码)校验
  3625. string portNo = portNos[i];
  3626. List<TestItem> item = new List<TestItem>();
  3627. item.Add(new TestItem()
  3628. {
  3629. Parameter_name = "弹夹码",
  3630. Parameter_value = sn,
  3631. });
  3632. item.Add(new TestItem()
  3633. {
  3634. Parameter_name = "弹夹穴位",
  3635. Parameter_value = (i + 1).ToString(),
  3636. });
  3637. item.Add(new TestItem()
  3638. {
  3639. Parameter_name = "载具码",
  3640. Parameter_value = vehicleCodes[i],
  3641. });
  3642. item.Add(new TestItem()
  3643. {
  3644. Parameter_name = "载具穴号",
  3645. Parameter_value = "1",
  3646. });
  3647. results[i] = 0;//SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item);
  3648. }
  3649. }
  3650. stopwatch2.Stop();
  3651. short result = 0;
  3652. bool haveMesWarn = results.Contains(5);
  3653. bool havePCWarn = results.Contains(6);
  3654. if (haveMesWarn)
  3655. result = 2; // 5->2
  3656. else if (havePCWarn)
  3657. result = 6; // 6->4
  3658. else
  3659. result = 1;
  3660. // MES_Flag 为4MES报错
  3661. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  3662. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  3663. writeToPLC_Flag.Name = "d3MES_FLAG";
  3664. writeToPLC_Flag.Adress = 2463;
  3665. writeToPLC_Flag.Value = result;
  3666. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  3667. WritePLCLog(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  3668. }
  3669. catch (Exception ex)
  3670. {
  3671. stopwatch2.Stop();
  3672. // MES_Flag 为4上位机报错
  3673. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  3674. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  3675. writeToPLC_Flag.Name = "d3MES_FLAG";
  3676. writeToPLC_Flag.Adress = 2463;
  3677. writeToPLC_Flag.Value = (short)4;
  3678. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  3679. string str = ex.StackTrace;
  3680. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3681. }
  3682. stopwatch1.Stop();
  3683. AddMessage(LogType.Info, stationNameStr + "_S4_3进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3684. }
  3685. // 上次采集到的SN
  3686. //private string sn_S4_3出站接口 = string.Empty;
  3687. /// <summary>
  3688. /// [S4] 取放桁架 - S4_3出站接口(提升机1)
  3689. /// </summary>
  3690. private void S4_3出站接口(int plcNo, string stationNameStr)
  3691. {
  3692. Stopwatch stopwatch1 = new Stopwatch();
  3693. Stopwatch stopwatch2 = new Stopwatch();
  3694. try
  3695. {
  3696. stopwatch1.Start();
  3697. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3698. string batch_num = GlobalContext.BatchNumber; // 批次号
  3699. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3700. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3701. string supplierCode = ""; // 供应商代码
  3702. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  3703. sn = sn.Replace("\0", "");
  3704. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  3705. bool isPass = d3Result == 1; // 产品结果 bool
  3706. // ZS 查询15个载具码与15个产品SN
  3707. List<string> vehicleCodes = new string[15].ToList();
  3708. List<string> portNos = new string[15].ToList();
  3709. // 调用MES出站
  3710. stopwatch2.Start();
  3711. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  3712. for (int i = 0; i < vehicleCodes.Count; i++)
  3713. {
  3714. // 循环出站
  3715. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  3716. {
  3717. string portNo = portNos[i];
  3718. List<TestItem> items1 = new List<TestItem>();
  3719. items1.Add(new TestItem()
  3720. {
  3721. Parameter_name = "弹夹码",
  3722. Parameter_value = sn,
  3723. });
  3724. items1.Add(new TestItem()
  3725. {
  3726. Parameter_name = "弹夹穴位",
  3727. Parameter_value = (i + 1).ToString(),
  3728. });
  3729. items1.Add(new TestItem()
  3730. {
  3731. Parameter_name = "载具码",
  3732. Parameter_value = vehicleCodes[i],
  3733. });
  3734. items1.Add(new TestItem()
  3735. {
  3736. Parameter_name = "载具穴号",
  3737. Parameter_value = "1",
  3738. });
  3739. items1.Add(new TestItem()
  3740. {
  3741. Parameter_name = "产品结果",
  3742. Parameter_value = isPass ? "OK" : "NG",
  3743. });
  3744. int mesResult = 0;
  3745. //int mesResult = SwitctProcessData(stationNameStr, items1, "", ""
  3746. // , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, portNo, isPass, vehicleCodes[i], "1");
  3747. results[i] = mesResult == 1 ? 1 : 2;
  3748. }
  3749. }
  3750. stopwatch2.Stop();
  3751. short result = 0;
  3752. bool haveMesWarn = results.Contains(2);
  3753. bool havePCWarn = results.Contains(3);
  3754. if (haveMesWarn)
  3755. result = 2; // 2->2
  3756. else if (havePCWarn)
  3757. result = 4; // 3->4
  3758. else
  3759. result = 1;
  3760. // MES_Flag 为4MES报错
  3761. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  3762. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  3763. writeToPLC_Flag.Name = "d3MES_FLAG";
  3764. writeToPLC_Flag.Adress = 2463;
  3765. writeToPLC_Flag.Value = result;
  3766. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  3767. WritePLCLog(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  3768. }
  3769. catch (Exception ex)
  3770. {
  3771. stopwatch2.Stop();
  3772. // MES_Flag 为4上位机报错
  3773. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  3774. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  3775. writeToPLC_Flag.Name = "d3MES_FLAG";
  3776. writeToPLC_Flag.Adress = 2463;
  3777. writeToPLC_Flag.Value = (short)4;
  3778. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  3779. string str = ex.StackTrace;
  3780. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3781. }
  3782. stopwatch1.Stop();
  3783. AddMessage(LogType.Info, stationNameStr + "_S4_3出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3784. }
  3785. // 上次采集到的SN
  3786. //private string sn_S4_4进站接口 = string.Empty;
  3787. /// <summary>
  3788. /// [S4] 取放桁架 - S4_4进站接口(提升机2)
  3789. /// </summary>
  3790. private void S4_4进站接口(int plcNo, string stationNameStr)
  3791. {
  3792. Stopwatch stopwatch1 = new Stopwatch();
  3793. Stopwatch stopwatch2 = new Stopwatch();
  3794. try
  3795. {
  3796. stopwatch1.Start();
  3797. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  3798. sn = sn.Replace("\0", "");
  3799. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  3800. // ZS 查询15个载具码与15个产品SN
  3801. List<string> vehicleCodes = new string[15].ToList();
  3802. List<string> portNos = new string[15].ToList();
  3803. // 调用MES进站(最多15个)
  3804. stopwatch2.Start();
  3805. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  3806. for (int i = 0; i < vehicleCodes.Count; i++)
  3807. {
  3808. // 循环进站
  3809. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  3810. {
  3811. // 产品SN(物料码)校验
  3812. string portNo = portNos[i];
  3813. List<TestItem> item = new List<TestItem>();
  3814. item.Add(new TestItem()
  3815. {
  3816. Parameter_name = "弹夹码",
  3817. Parameter_value = sn,
  3818. });
  3819. item.Add(new TestItem()
  3820. {
  3821. Parameter_name = "弹夹穴位",
  3822. Parameter_value = (i + 1).ToString(),
  3823. });
  3824. item.Add(new TestItem()
  3825. {
  3826. Parameter_name = "载具码",
  3827. Parameter_value = vehicleCodes[i],
  3828. });
  3829. item.Add(new TestItem()
  3830. {
  3831. Parameter_name = "载具穴号",
  3832. Parameter_value = "1",
  3833. });
  3834. results[i] = 0;// SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item);
  3835. }
  3836. }
  3837. stopwatch2.Stop();
  3838. short result = 0;
  3839. bool haveMesWarn = results.Contains(5);
  3840. bool havePCWarn = results.Contains(6);
  3841. if (haveMesWarn)
  3842. result = 2; // 5->2
  3843. else if (havePCWarn)
  3844. result = 6; // 6->4
  3845. else
  3846. result = 1;
  3847. // MES_Flag 为4MES报错
  3848. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  3849. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  3850. writeToPLC_Flag.Name = "d4MES_FLAG";
  3851. writeToPLC_Flag.Adress = 2496;
  3852. writeToPLC_Flag.Value = result;
  3853. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  3854. WritePLCLog(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  3855. }
  3856. catch (Exception ex)
  3857. {
  3858. stopwatch2.Stop();
  3859. // MES_Flag 为4上位机报错
  3860. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  3861. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  3862. writeToPLC_Flag.Name = "d4MES_FLAG";
  3863. writeToPLC_Flag.Adress = 2496;
  3864. writeToPLC_Flag.Value = (short)4;
  3865. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  3866. string str = ex.StackTrace;
  3867. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3868. }
  3869. stopwatch1.Stop();
  3870. AddMessage(LogType.Info, stationNameStr + "_S4_4进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3871. }
  3872. // 上次采集到的SN
  3873. //private string sn_S4_4出站接口 = string.Empty;
  3874. /// <summary>
  3875. /// [S4] 取放桁架 - S4_4出站接口(提升机2)
  3876. /// </summary>
  3877. private void S4_4出站接口(int plcNo, string stationNameStr)
  3878. {
  3879. Stopwatch stopwatch1 = new Stopwatch();
  3880. Stopwatch stopwatch2 = new Stopwatch();
  3881. try
  3882. {
  3883. stopwatch1.Start();
  3884. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3885. string batch_num = GlobalContext.BatchNumber; // 批次号
  3886. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3887. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3888. string supplierCode = ""; // 供应商代码
  3889. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  3890. sn = sn.Replace("\0", "");
  3891. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  3892. bool isPass = d4Result == 1; // 产品结果 bool
  3893. // ZS 查询15个载具码与15个产品SN
  3894. List<string> vehicleCodes = new string[15].ToList();
  3895. List<string> portNos = new string[15].ToList();
  3896. // 调用MES出站
  3897. stopwatch2.Start();
  3898. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  3899. for (int i = 0; i < vehicleCodes.Count; i++)
  3900. {
  3901. // 循环出站
  3902. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  3903. {
  3904. string portNo = portNos[i];
  3905. List<TestItem> items1 = new List<TestItem>();
  3906. items1.Add(new TestItem()
  3907. {
  3908. Parameter_name = "弹夹码",
  3909. Parameter_value = sn,
  3910. });
  3911. items1.Add(new TestItem()
  3912. {
  3913. Parameter_name = "弹夹穴位",
  3914. Parameter_value = (i + 1).ToString(),
  3915. });
  3916. items1.Add(new TestItem()
  3917. {
  3918. Parameter_name = "载具码",
  3919. Parameter_value = vehicleCodes[i],
  3920. });
  3921. items1.Add(new TestItem()
  3922. {
  3923. Parameter_name = "载具穴号",
  3924. Parameter_value = "1",
  3925. });
  3926. items1.Add(new TestItem()
  3927. {
  3928. Parameter_name = "产品结果",
  3929. Parameter_value = isPass ? "OK" : "NG",
  3930. });
  3931. int mesResult = 0;
  3932. //int mesResult = SwitctProcessData(stationNameStr, items1, "", ""
  3933. // , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, portNo, isPass, vehicleCodes[i], "1");
  3934. results[i] = mesResult == 1 ? 1 : 2;
  3935. }
  3936. }
  3937. stopwatch2.Stop();
  3938. short result = 0;
  3939. bool haveMesWarn = results.Contains(2);
  3940. bool havePCWarn = results.Contains(3);
  3941. if (haveMesWarn)
  3942. result = 2; // 2->2
  3943. else if (havePCWarn)
  3944. result = 4; // 3->4
  3945. else
  3946. result = 1;
  3947. // MES_Flag 为4MES报错
  3948. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  3949. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  3950. writeToPLC_Flag.Name = "d4MES_FLAG";
  3951. writeToPLC_Flag.Adress = 2496;
  3952. writeToPLC_Flag.Value = result;
  3953. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  3954. WritePLCLog(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  3955. }
  3956. catch (Exception ex)
  3957. {
  3958. stopwatch2.Stop();
  3959. // MES_Flag 为4上位机报错
  3960. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  3961. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  3962. writeToPLC_Flag.Name = "d4MES_FLAG";
  3963. writeToPLC_Flag.Adress = 2496;
  3964. writeToPLC_Flag.Value = (short)4;
  3965. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  3966. string str = ex.StackTrace;
  3967. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3968. }
  3969. stopwatch1.Stop();
  3970. AddMessage(LogType.Info, stationNameStr + "_S4_4出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3971. }
  3972. /// <summary>
  3973. /// [S4] 取放桁架 - S4_5弹夹扫码
  3974. /// </summary>
  3975. /// <param name="plcNo">PLC编号</param>
  3976. /// <param name="stationNameStr">工站全称</param>
  3977. private void S4_5弹夹扫码(int plcNo, string stationNameStr)
  3978. {
  3979. Stopwatch stopwatch1 = new Stopwatch();
  3980. Stopwatch stopwatch2 = new Stopwatch();
  3981. try
  3982. {
  3983. stopwatch1.Start();
  3984. // ZS 弹夹扫码
  3985. string d5BulletclipCode = " "; // 扫到的码
  3986. short d5BulletclipScanCode = 2;
  3987. stopwatch2.Start();
  3988. //Funs[plcNo].WriteMultipleRegisters<string>(2529, d5BulletclipCode, 20);
  3989. //// MES_Flag
  3990. //Funs[plcNo].WriteMultipleRegisters<short>(2528, d5BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  3991. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  3992. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  3993. writeToPLC_Flag.Adress = 2528;
  3994. writeToPLC_Flag.Value = d5BulletclipScanCode;
  3995. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  3996. {
  3997. Name = "d5BulletclipCode",
  3998. Adress = 2529,
  3999. ValueType = PLCValueType.String,
  4000. ValueTypeStrLength = 20,
  4001. Value = d5BulletclipCode
  4002. });
  4003. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  4004. stopwatch2.Stop();
  4005. }
  4006. catch (Exception ex)
  4007. {
  4008. string str = ex.StackTrace;
  4009. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4010. stopwatch2.Start();
  4011. //Funs[plcNo].WriteMultipleRegisters<string>(2529, " ", 20);
  4012. //// MES_Flag
  4013. //Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  4014. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4015. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  4016. writeToPLC_Flag.Adress = 2528;
  4017. writeToPLC_Flag.Value = (short)6;
  4018. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  4019. {
  4020. Name = "d5BulletclipCode",
  4021. Adress = 2529,
  4022. ValueType = PLCValueType.String,
  4023. ValueTypeStrLength = 20,
  4024. Value = " "
  4025. });
  4026. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  4027. stopwatch2.Stop();
  4028. }
  4029. stopwatch1.Stop();
  4030. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4031. }
  4032. /// <summary>
  4033. /// [S4] 取放桁架 - S4_5载具扫码
  4034. /// </summary>
  4035. /// <param name="plcNo">PLC编号</param>
  4036. /// <param name="stationNameStr">工站全称</param>
  4037. private void S4_5载具扫码(int plcNo, string stationNameStr)
  4038. {
  4039. Stopwatch stopwatch1 = new Stopwatch();
  4040. Stopwatch stopwatch2 = new Stopwatch();
  4041. try
  4042. {
  4043. stopwatch1.Start();
  4044. // ZS 载具扫码
  4045. string d5VehicleCode = " "; // 扫到的码
  4046. // 查产品SN
  4047. string partNo = " ";
  4048. short d5VehicleScanCode = 2;
  4049. #region 进站
  4050. if (!string.IsNullOrEmpty(d5VehicleCode))
  4051. {
  4052. List<TestItem> item = new List<TestItem>();
  4053. item.Add(new TestItem()
  4054. {
  4055. Parameter_name = "载具码",
  4056. Parameter_value = d5VehicleCode,
  4057. });
  4058. item.Add(new TestItem()
  4059. {
  4060. Parameter_name = "载具穴号",
  4061. Parameter_value = "1",
  4062. });
  4063. stopwatch2.Start();
  4064. int result = 0;//SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item);
  4065. stopwatch2.Stop();
  4066. d5VehicleScanCode = (short)result == 1 ? d5VehicleScanCode : (short)result;
  4067. }
  4068. #endregion 进站
  4069. //Funs[plcNo].WriteMultipleRegisters<string>(2560, d5VehicleCode, 20);
  4070. //// MES_Flag
  4071. //Funs[plcNo].WriteMultipleRegisters<short>(2559, d5VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  4072. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4073. writeToPLC_Flag.Name = "d5VehicleScanCode";
  4074. writeToPLC_Flag.Adress = 2559;
  4075. writeToPLC_Flag.Value = d5VehicleScanCode;
  4076. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  4077. {
  4078. Name = "d5VehicleCode",
  4079. Adress = 2560,
  4080. ValueType = PLCValueType.String,
  4081. ValueTypeStrLength = 20,
  4082. Value = d5VehicleCode
  4083. });
  4084. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  4085. }
  4086. catch (Exception ex)
  4087. {
  4088. string str = ex.StackTrace;
  4089. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4090. stopwatch2.Start();
  4091. //Funs[plcNo].WriteMultipleRegisters<string>(2560, " ", 20);
  4092. //// MES_Flag
  4093. //Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  4094. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4095. writeToPLC_Flag.Name = "d5VehicleScanCode";
  4096. writeToPLC_Flag.Adress = 2559;
  4097. writeToPLC_Flag.Value = (short)6;
  4098. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  4099. {
  4100. Name = "d5VehicleCode",
  4101. Adress = 2560,
  4102. ValueType = PLCValueType.String,
  4103. ValueTypeStrLength = 20,
  4104. Value = " "
  4105. });
  4106. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  4107. stopwatch2.Stop();
  4108. }
  4109. stopwatch1.Stop();
  4110. AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4111. }
  4112. // 上次采集到的SN
  4113. //private string sn_S4_5出站接口 = string.Empty;
  4114. /// <summary>
  4115. /// [S4] 取放桁架 - S4_5出站接口
  4116. /// </summary>
  4117. private void S4_5出站接口(int plcNo, string stationCode, string stationName)
  4118. {
  4119. Stopwatch stopwatch1 = new Stopwatch();
  4120. Stopwatch stopwatch2 = new Stopwatch();
  4121. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4122. string stationNameStr = stationCode + stationName;
  4123. string processItem = stationName; // 测试项目
  4124. try
  4125. {
  4126. stopwatch1.Start();
  4127. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4128. string batch_num = GlobalContext.BatchNumber; // 批次号
  4129. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4130. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4131. string supplierCode = ""; // 供应商代码
  4132. string sn = (string)s4PLCData["d5ProductSN"]; // 产品SN(弹夹码)
  4133. sn = sn.Replace("\0", "");
  4134. string d5VehicleCode1 = (string)s4PLCData["d5VehicleCode1"]; // 载具1码(弹夹穴位1)
  4135. string d5VehicleCode2 = (string)s4PLCData["d5VehicleCode2"]; // 载具2码(弹夹穴位2)
  4136. string d5VehicleCode3 = (string)s4PLCData["d5VehicleCode3"]; // 载具3码(弹夹穴位3)
  4137. string d5VehicleCode4 = (string)s4PLCData["d5VehicleCode4"]; // 载具4码(弹夹穴位4)
  4138. string d5VehicleCode5 = (string)s4PLCData["d5VehicleCode5"]; // 载具5码(弹夹穴位5)
  4139. string d5VehicleCode6 = (string)s4PLCData["d5VehicleCode6"]; // 载具6码(弹夹穴位6)
  4140. string d5VehicleCode7 = (string)s4PLCData["d5VehicleCode7"]; // 载具7码(弹夹穴位7)
  4141. string d5VehicleCode8 = (string)s4PLCData["d5VehicleCode8"]; // 载具8码(弹夹穴位8)
  4142. string d5VehicleCode9 = (string)s4PLCData["d5VehicleCode9"]; // 载具9码(弹夹穴位9)
  4143. string d5VehicleCode10 = (string)s4PLCData["d5VehicleCode10"]; // 载具10码(弹夹穴位10)
  4144. string d5VehicleCode11 = (string)s4PLCData["d5VehicleCode11"]; // 载具11码(弹夹穴位11)
  4145. string d5VehicleCode12 = (string)s4PLCData["d5VehicleCode12"]; // 载具12码(弹夹穴位12)
  4146. string d5VehicleCode13 = (string)s4PLCData["d5VehicleCode13"]; // 载具13码(弹夹穴位13)
  4147. string d5VehicleCode14 = (string)s4PLCData["d5VehicleCode14"]; // 载具14码(弹夹穴位14)
  4148. string d5VehicleCode15 = (string)s4PLCData["d5VehicleCode15"]; // 载具15码(弹夹穴位15)
  4149. int d5Result = (int)s4PLCData["d5Result"]; // 产品结果
  4150. bool pass = d5Result == 1;
  4151. List<TestItem> items1 = new List<TestItem>();
  4152. items1.Add(new TestItem()
  4153. {
  4154. Parameter_name = "产品结果",
  4155. Parameter_value = d5Result == 1 ? "OK" : "NG",
  4156. Parameter_unit = ""
  4157. });
  4158. int result1 = 0;
  4159. //int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  4160. // , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, d5VehicleCode1, "1");
  4161. //int result = result1 == 1 ? 1 : (GlobalContext.IsSendProcessData ? 4 : 1);
  4162. short result = result1 == 1 ? (short)1 : (short)3;
  4163. stopwatch2.Start();
  4164. // MES_Flag 为4MES报错
  4165. //Funs[plcNo].WriteMultipleRegisters<short>(2591, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4166. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4167. writeToPLC_Flag.Name = "d5MES_FLAG";
  4168. writeToPLC_Flag.Adress = 2591;
  4169. writeToPLC_Flag.Value = result;
  4170. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  4171. stopwatch2.Stop();
  4172. WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  4173. }
  4174. catch (Exception ex)
  4175. {
  4176. stopwatch2.Start();
  4177. // MES_Flag 为4上位机报错
  4178. //Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)4); // 4代表上位机报警
  4179. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4180. writeToPLC_Flag.Name = "d5MES_FLAG";
  4181. writeToPLC_Flag.Adress = 2591;
  4182. writeToPLC_Flag.Value = (short)4;
  4183. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  4184. stopwatch2.Stop();
  4185. string str = ex.StackTrace;
  4186. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4187. }
  4188. stopwatch1.Stop();
  4189. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4190. }
  4191. /// <summary>
  4192. /// [S4] 取放桁架 - S4_5节拍接口
  4193. /// </summary>
  4194. /// <param name="plcNo">PLC编号</param>
  4195. /// <param name="stationNameStr">工站全称</param>
  4196. private void S4_5节拍接口(int plcNo, string stationNameStr)
  4197. {
  4198. Stopwatch stopwatch1 = new Stopwatch();
  4199. Stopwatch stopwatch2 = new Stopwatch();
  4200. string resultStr = string.Empty;
  4201. try
  4202. {
  4203. stopwatch1.Start();
  4204. string oEEType = ((int)s4PLCData["d5OEEType"]).ToString(); // 节拍类型(plc写入)
  4205. string d5OEEProductSN = (string)s4PLCData["d5OEEProductSN"]; // 载具SN
  4206. d5OEEProductSN = d5OEEProductSN.Replace("\0", "");
  4207. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  4208. if (!actionBool)
  4209. {
  4210. stopwatch2.Start();
  4211. // MES_Flag
  4212. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 上位机;发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警
  4213. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  4214. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  4215. writeToPLC_Flag1.Adress = 2924;
  4216. writeToPLC_Flag1.Value = (short)4;
  4217. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  4218. stopwatch2.Stop();
  4219. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4220. return;
  4221. }
  4222. string d5OEEPartNo = string.Empty; // 物料码
  4223. if (string.IsNullOrEmpty(d5OEEProductSN))
  4224. {
  4225. stopwatch2.Start();
  4226. // MES_Flag
  4227. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4228. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  4229. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  4230. writeToPLC_Flag1.Adress = 2924;
  4231. writeToPLC_Flag1.Value = (short)1;
  4232. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  4233. stopwatch2.Stop();
  4234. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4235. return;
  4236. }
  4237. else
  4238. { // 查产品SN
  4239. d5OEEPartNo = "Test"; // ZS
  4240. }
  4241. short d5OEEMES_FLAG = 0;
  4242. // 上传OEE
  4243. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d5OEEPartNo, d5OEEProductSN);
  4244. d5OEEMES_FLAG = result.Item1;
  4245. resultStr = result.Item2;
  4246. stopwatch2.Start();
  4247. // MES_Flag
  4248. //Funs[plcNo].WriteMultipleRegisters<short>(2924, d5OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4249. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4250. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  4251. writeToPLC_Flag.Adress = 2924;
  4252. writeToPLC_Flag.Value = d5OEEMES_FLAG;
  4253. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  4254. stopwatch2.Stop();
  4255. }
  4256. catch (Exception ex)
  4257. {
  4258. string str = ex.StackTrace;
  4259. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4260. // MES_Flag
  4261. stopwatch2.Start();
  4262. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  4263. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4264. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  4265. writeToPLC_Flag.Adress = 2924;
  4266. writeToPLC_Flag.Value = (short)4;
  4267. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  4268. stopwatch2.Stop();
  4269. }
  4270. stopwatch1.Stop();
  4271. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4272. }
  4273. #endregion [S4] 取放桁架
  4274. #endregion PLC4 刘果段
  4275. #region PLC5 张超凡
  4276. #region [S5] Tray盘下料装备
  4277. /// <summary>
  4278. /// S5工位的数据- 触发信号上次的值
  4279. /// </summary>
  4280. private Dictionary<string, object> s5PLCSignal_Old = new Dictionary<string, object>();
  4281. /// <summary>
  4282. /// S5工位的数据(含触发信号)
  4283. /// </summary>
  4284. private Dictionary<string, object> s5PLCData = new Dictionary<string, object>();
  4285. /// <summary>
  4286. /// S5工位的数据- 回写点位
  4287. /// </summary>
  4288. private Dictionary<string, WriteToPLC_Flag> s5PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  4289. /// <summary>
  4290. /// [S5] Tray盘下料装备
  4291. /// </summary>
  4292. /// <param name="plcNo">PLC编号</param>
  4293. private void ReadStation_S5(int plcNo)
  4294. {
  4295. // [S1] Tray盘上料装备
  4296. // [S2] FCT
  4297. // [S3] 值板机
  4298. // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  4299. // [S5] Tray盘下料装备
  4300. /// 上位机心跳
  4301. /// 获取设备报警数据与状态信息
  4302. string stationCode = "[S5]";
  4303. string stationName = "Tray盘下料装备";
  4304. string stationNameStr = stationCode + stationName;
  4305. #region 创建字典
  4306. // 触发信号字典 赋值
  4307. s5PLCSignal_Old.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  4308. s5PLCSignal_Old.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  4309. s5PLCSignal_Old.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4310. s5PLCSignal_Old.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  4311. s5PLCSignal_Old.Add("e1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  4312. s5PLCSignal_Old.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  4313. s5PLCSignal_Old.Add("e1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  4314. // PLC数据字典 赋值
  4315. s5PLCData.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  4316. s5PLCData.Add("e1MES_FLAG_Check", 0); // MES_FLAG
  4317. s5PLCData.Add("e1ProductSN_Check", ""); //
  4318. s5PLCData.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  4319. s5PLCData.Add("e1MES_FLAG", 0); // MES_FLAG
  4320. s5PLCData.Add("e1ProductSN", ""); // 产品SN
  4321. s5PLCData.Add("e1PartNo", ""); // 物料码
  4322. s5PLCData.Add("e1Result", 0); // 产品结果
  4323. s5PLCData.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4324. s5PLCData.Add("e1OEEMES_FLAG", 0); // MES_FLAG
  4325. s5PLCData.Add("e1OEEProductSN", "");// 产品SN(载具SN)
  4326. s5PLCData.Add("e1OEEType", 0); // 节拍类型(plc写入)
  4327. s5PLCData.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  4328. s5PLCData.Add("e1AGVUpStart", 0); // AGV上料开始信号
  4329. s5PLCData.Add("e1AGVUpEnd", 0); // AGV上料完成信号
  4330. s5PLCData.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  4331. s5PLCData.Add("e1AGVDownStart", 0); // AGV下料开始信号
  4332. s5PLCData.Add("e1AGVDownEnd", 0); // AGV下料完成信号
  4333. #endregion 创建字典
  4334. while (true)
  4335. {
  4336. try
  4337. {
  4338. if (!GlobalContext._IsCon_Funs5)
  4339. {
  4340. UpdatePLCMonitor(1, plcNo, 0);
  4341. continue;
  4342. }
  4343. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  4344. {
  4345. Stopwatch stopwatch1 = new Stopwatch();
  4346. Stopwatch stopwatch2 = new Stopwatch();
  4347. stopwatch1.Start();
  4348. /*
  4349. stopwatch2.Start();
  4350. #region 一次性读取所有数据
  4351. int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  4352. int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 46);
  4353. int[] datas = data1.Concat(data2).ToArray();
  4354. s5PLCData["e1PLC_FLAG_Check"] = datas[2]; // 进站校验
  4355. s5PLCData["e1MES_FLAG_Check"] = datas[3];
  4356. int[] e1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  4357. s5PLCData["e1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(e1ProductSN_CheckData, 0, 40);
  4358. s5PLCData["e1PLC_FLAG"] = datas[34]; // 出站接口
  4359. s5PLCData["e1MES_FLAG"] = datas[35];
  4360. int[] e1ProductSNData = datas.Skip(36).Take(20).ToArray();
  4361. s5PLCData["e1ProductSN"] = ModbusClient.ConvertRegistersToString(e1ProductSNData, 0, 40);
  4362. int[] e1PartNoData = datas.Skip(56).Take(20).ToArray();
  4363. s5PLCData["e1PartNo"] = ModbusClient.ConvertRegistersToString(e1PartNoData, 0, 40);
  4364. s5PLCData["e1Result"] = datas[76];
  4365. s5PLCData["e1OEEPLC_FLAG"] = datas[87]; // 节拍接口
  4366. s5PLCData["e1OEEMES_FLAG"] = datas[88];
  4367. int[] e1OEEProductSNData = datas.Skip(89).Take(20).ToArray();
  4368. s5PLCData["e1OEEProductSN"] = ModbusClient.ConvertRegistersToString(e1OEEProductSNData, 0, 40);
  4369. s5PLCData["e1OEEType"] = datas[109];
  4370. s5PLCData["e1AGVUpCall"] = datas[120]; // AGV上料
  4371. s5PLCData["e1AGVUpStart"] = datas[121];
  4372. s5PLCData["e1AGVUpEnd"] = datas[122];
  4373. s5PLCData["e1AGVDownCall"] = datas[133]; // AGV下料
  4374. s5PLCData["e1AGVDownStart"] = datas[134];
  4375. s5PLCData["e1AGVDownEnd"] = datas[135];
  4376. #endregion 一次性读取所有数据
  4377. stopwatch2.Stop();
  4378. #region 回写操作,写后清空flag
  4379. PLCWriteData(Funs[plcNo], ref s5PLCData, ref s5PLCWriteData);
  4380. #endregion 回写操作,写后清空flag
  4381. #region 进站校验
  4382. try
  4383. {
  4384. int e1PLC_FLAG_Check = (int)s5PLCData["e1PLC_FLAG_Check"];
  4385. int e1MES_FLAG_Check = (int)s5PLCData["e1MES_FLAG_Check"];
  4386. int e1PLC_FLAG_CheckOld = (int)s5PLCSignal_Old["e1PLC_FLAG_Check"];
  4387. if (e1PLC_FLAG_Check != e1PLC_FLAG_CheckOld)
  4388. {
  4389. if (e1PLC_FLAG_Check == 1 && e1MES_FLAG_Check == 0) // 0->1
  4390. Task.Run(() => S5进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  4391. else if (e1PLC_FLAG_Check == 0 && e1MES_FLAG_Check != 0)
  4392. Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  4393. s5PLCSignal_Old["e1PLC_FLAG_Check"] = s5PLCData["e1PLC_FLAG_Check"];
  4394. }
  4395. }
  4396. catch (Exception ex)
  4397. {
  4398. Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  4399. string str = ex.StackTrace;
  4400. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4401. }
  4402. #endregion 进站校验
  4403. */
  4404. #region 出站接口
  4405. try
  4406. {
  4407. int e1PLC_FLAG = (int)s5PLCData["e1PLC_FLAG"];
  4408. int e1MES_FLAG = (int)s5PLCData["e1MES_FLAG"];
  4409. int e1PLC_FLAGOld = (int)s5PLCSignal_Old["e1PLC_FLAG"];
  4410. if (e1PLC_FLAG != e1PLC_FLAGOld)
  4411. {
  4412. if (e1PLC_FLAG == 1 && e1MES_FLAG == 0) // 0->1
  4413. Task.Run(() => S5出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  4414. //else if (e1PLC_FLAG == 0 && e1MES_FLAG != 0)
  4415. //Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)0);
  4416. s5PLCSignal_Old["e1PLC_FLAG"] = s5PLCData["e1PLC_FLAG"];
  4417. }
  4418. }
  4419. catch (Exception ex)
  4420. {
  4421. //Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)6); // 6代表上位机报警
  4422. string str = ex.StackTrace;
  4423. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4424. }
  4425. #endregion 出站接口
  4426. #region 节拍接口
  4427. try
  4428. {
  4429. int e1OEEPLC_FLAG = (int)s5PLCData["e1OEEPLC_FLAG"];
  4430. int e1OEEMES_FLAG = (int)s5PLCData["e1OEEMES_FLAG"];
  4431. int e1OEEPLC_FLAGOld = (int)s5PLCSignal_Old["e1OEEPLC_FLAG"];
  4432. if (e1OEEPLC_FLAG != e1OEEPLC_FLAGOld)
  4433. {
  4434. if (e1OEEPLC_FLAG == 1 && e1OEEMES_FLAG == 0) // 0->1
  4435. Task.Run(() => S5节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  4436. //else if (e1OEEPLC_FLAG == 0 && e1OEEMES_FLAG != 0)
  4437. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)0);
  4438. s5PLCSignal_Old["e1OEEPLC_FLAG"] = s5PLCData["e1OEEPLC_FLAG"];
  4439. }
  4440. }
  4441. catch (Exception ex)
  4442. {
  4443. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  4444. string str = ex.StackTrace;
  4445. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4446. }
  4447. #endregion 节拍接口
  4448. #region AGV上料
  4449. // AGV上料叫AGV信号
  4450. try
  4451. {
  4452. int e1AGVUpCall = (int)s5PLCData["e1AGVUpCall"];
  4453. int e1AGVUpCallOld = (int)s5PLCSignal_Old["e1AGVUpCall"];
  4454. if (e1AGVUpCall != e1AGVUpCallOld)
  4455. {
  4456. if (e1AGVUpCall == 1) // 0->1
  4457. Task.Run(() => S5AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  4458. s5PLCSignal_Old["e1AGVUpCall"] = s5PLCData["e1AGVUpCall"];
  4459. }
  4460. }
  4461. catch (Exception ex)
  4462. {
  4463. //Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  4464. string str = ex.StackTrace;
  4465. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4466. }
  4467. // AGV上料完成信号
  4468. try
  4469. {
  4470. int e1AGVUpEnd = (int)s5PLCData["e1AGVUpEnd"];
  4471. int e1AGVUpEndOld = (int)s5PLCSignal_Old["e1AGVUpEnd"];
  4472. if (e1AGVUpEnd != e1AGVUpEndOld)
  4473. {
  4474. if (e1AGVUpEnd == 1) // 0->1
  4475. Task.Run(() => S5AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  4476. s5PLCSignal_Old["e1AGVUpEnd"] = s5PLCData["e1AGVUpEnd"];
  4477. }
  4478. }
  4479. catch (Exception ex)
  4480. {
  4481. //Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  4482. string str = ex.StackTrace;
  4483. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4484. }
  4485. #endregion AGV上料
  4486. #region AGV下料
  4487. // AGV下料叫agv信号
  4488. try
  4489. {
  4490. int e1AGVDownCall = (int)s5PLCData["e1AGVDownCall"];
  4491. int e1AGVDownCallOld = (int)s5PLCSignal_Old["e1AGVDownCall"];
  4492. if (e1AGVDownCall != e1AGVDownCallOld)
  4493. {
  4494. if (e1AGVDownCall == 1) // 0->1
  4495. Task.Run(() => S5AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  4496. s5PLCSignal_Old["e1AGVDownCall"] = s5PLCData["e1AGVDownCall"];
  4497. }
  4498. }
  4499. catch (Exception ex)
  4500. {
  4501. //Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  4502. string str = ex.StackTrace;
  4503. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4504. }
  4505. // AGV下料完成信号
  4506. try
  4507. {
  4508. int e1AGVDownEnd = (int)s5PLCData["e1AGVDownEnd"];
  4509. int e1AGVDownEndOld = (int)s5PLCSignal_Old["e1AGVDownEnd"];
  4510. if (e1AGVDownEnd != e1AGVDownEndOld)
  4511. {
  4512. if (e1AGVDownEnd == 1) // 0->1
  4513. Task.Run(() => S5AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  4514. s5PLCSignal_Old["e1AGVDownEnd"] = s5PLCData["e1AGVDownEnd"];
  4515. }
  4516. }
  4517. catch (Exception ex)
  4518. {
  4519. // Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  4520. string str = ex.StackTrace;
  4521. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4522. }
  4523. #endregion AGV下料
  4524. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4525. stopwatch1.Stop();
  4526. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  4527. OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4528. }
  4529. else
  4530. {
  4531. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4532. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4533. Funs[plcNo].Connect();
  4534. }
  4535. }
  4536. catch (Exception ex)
  4537. {
  4538. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4539. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4540. //Funs[plcNo].ReConnect();
  4541. }
  4542. Thread.Sleep(IntervalReadPLC);
  4543. }
  4544. }
  4545. /// <summary>
  4546. /// [S5] Tray盘下料装备 - 进站校验
  4547. /// </summary>
  4548. /// <param name="plcNo">PLC编号</param>
  4549. /// <param name="stationNameStr">工站全称</param>
  4550. private void S5进站校验(int plcNo, string stationNameStr)
  4551. {
  4552. Stopwatch stopwatch1 = new Stopwatch();
  4553. Stopwatch stopwatch2 = new Stopwatch();
  4554. try
  4555. {
  4556. stopwatch1.Start();
  4557. string sn = (string)s5PLCData["e1ProductSN_Check"]; // 产品SN(载具码)
  4558. sn = sn.Replace("\0", "");
  4559. // 获取产品SN By 载具码
  4560. string partNo = string.Empty;
  4561. // 产品SN(物料码)校验
  4562. List<TestItem> item = new List<TestItem>();
  4563. item.Add(new TestItem()
  4564. {
  4565. Parameter_name = "载具码",
  4566. Parameter_value = sn,
  4567. });
  4568. item.Add(new TestItem()
  4569. {
  4570. Parameter_name = "载具穴号",
  4571. Parameter_value = "1",
  4572. });
  4573. stopwatch2.Start();
  4574. int result = 0;
  4575. //int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item);
  4576. stopwatch2.Stop();
  4577. short e1MES_FLAG_Check = (short)result;
  4578. // MES_Flag
  4579. //Funs[plcNo].WriteMultipleRegisters<short>(2003, e1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  4580. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4581. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  4582. writeToPLC_Flag.Adress = 2003;
  4583. writeToPLC_Flag.Value = e1MES_FLAG_Check;
  4584. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  4585. }
  4586. catch (Exception ex)
  4587. {
  4588. string str = ex.StackTrace;
  4589. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4590. // MES_Flag
  4591. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  4592. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4593. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  4594. writeToPLC_Flag.Adress = 2003;
  4595. writeToPLC_Flag.Value = (short)6;
  4596. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  4597. }
  4598. stopwatch1.Stop();
  4599. AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4600. }
  4601. /// <summary>
  4602. /// [S5] Tray盘下料装备 - 出站接口
  4603. /// </summary>
  4604. /// <param name="plcNo"></param>
  4605. /// <param name="stationCode"></param>
  4606. /// <param name="stationName"></param>
  4607. private void S5出站接口(int plcNo, string stationCode, string stationName)
  4608. {
  4609. Stopwatch stopwatch1 = new Stopwatch();
  4610. Stopwatch stopwatch2 = new Stopwatch();
  4611. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4612. string stationNameStr = stationCode + stationName;
  4613. string processItem = stationName; // 测试项目
  4614. try
  4615. {
  4616. stopwatch1.Start();
  4617. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4618. string batch_num = GlobalContext.BatchNumber; // 批次号
  4619. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4620. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4621. string supplierCode = ""; // 供应商代码
  4622. string sn = (string)s5PLCData["e1ProductSN"]; // 产品SN(载具SN码)
  4623. sn = sn.Replace("\0", "");
  4624. //string partNo = (string)s5PLCData["e1PartNo"]; // 物料码
  4625. //partNo = partNo.Replace("\0", "");
  4626. string partNo = string.Empty;
  4627. int e1Result = (int)s5PLCData["e1Result"]; // 产品结果
  4628. bool pass = e1Result == 1;
  4629. List<TestItem> items = new List<TestItem>();
  4630. items.Add(new TestItem()
  4631. {
  4632. Parameter_name = "载具码",
  4633. Parameter_value = sn,
  4634. Parameter_unit = ""
  4635. });
  4636. items.Add(new TestItem()
  4637. {
  4638. Parameter_name = "产品码",
  4639. Parameter_value = partNo,
  4640. Parameter_unit = ""
  4641. });
  4642. int result1 = 0;
  4643. //int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4644. //, workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, partNo, pass, sn, "1");
  4645. //int result = result1 == 1 ? 1 : (GlobalContext.IsSendProcessData ? 4 : 1);
  4646. short result = result1 == 1 ? (short)1 : (short)3;
  4647. stopwatch2.Start();
  4648. // MES_Flag 为MES报错
  4649. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4650. //Funs[plcNo].WriteMultipleRegisters<short>(2035, result); // 4代表上位机报警
  4651. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4652. writeToPLC_Flag.Name = "e1MES_FLAG";
  4653. writeToPLC_Flag.Adress = 2035;
  4654. writeToPLC_Flag.Value = result;
  4655. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  4656. stopwatch2.Stop();
  4657. WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  4658. }
  4659. catch (Exception ex)
  4660. {
  4661. stopwatch2.Start();
  4662. // MES_Flag 为4上位机报错
  4663. //Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)4); // 4代表上位机报警
  4664. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4665. writeToPLC_Flag.Name = "e1MES_FLAG";
  4666. writeToPLC_Flag.Adress = 2035;
  4667. writeToPLC_Flag.Value = (short)4;
  4668. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  4669. stopwatch2.Stop();
  4670. string str = ex.StackTrace;
  4671. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4672. }
  4673. stopwatch1.Stop();
  4674. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4675. }
  4676. /// <summary>
  4677. /// [S5] Tray盘下料装备 - 节拍接口
  4678. /// </summary>
  4679. /// <param name="plcNo">PLC编号</param>
  4680. /// <param name="stationNameStr">工站全称</param>
  4681. private void S5节拍接口(int plcNo, string stationNameStr)
  4682. {
  4683. Stopwatch stopwatch1 = new Stopwatch();
  4684. Stopwatch stopwatch2 = new Stopwatch();
  4685. string resultStr = string.Empty;
  4686. try
  4687. {
  4688. stopwatch1.Start();
  4689. string oEEType = ((int)s5PLCData["e1OEEType"]).ToString(); // 节拍类型(plc写入)
  4690. string e1OEEProductSN = (string)s5PLCData["e1OEEProductSN"]; // 载具SN
  4691. e1OEEProductSN = e1OEEProductSN.Replace("\0", "");
  4692. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  4693. if (!actionBool)
  4694. {
  4695. stopwatch2.Start();
  4696. // MES_Flag
  4697. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4698. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  4699. writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  4700. writeToPLC_Flag1.Adress = 2088;
  4701. writeToPLC_Flag1.Value = (short)4;
  4702. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  4703. stopwatch2.Stop();
  4704. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4705. return;
  4706. }
  4707. string e1OEEPartNo = string.Empty; // 物料码
  4708. if (string.IsNullOrEmpty(e1OEEProductSN))
  4709. {
  4710. stopwatch2.Start();
  4711. // MES_Flag
  4712. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4713. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  4714. writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  4715. writeToPLC_Flag1.Adress = 2088;
  4716. writeToPLC_Flag1.Value = (short)1;
  4717. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  4718. stopwatch2.Stop();
  4719. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4720. return;
  4721. }
  4722. else
  4723. { // 查产品SN
  4724. e1OEEPartNo = "Test"; // ZS
  4725. }
  4726. short e1OEEMES_FLAG = 0;
  4727. // 上传OEE
  4728. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, e1OEEPartNo, e1OEEProductSN);
  4729. e1OEEMES_FLAG = result.Item1;
  4730. resultStr = result.Item2;
  4731. stopwatch2.Start();
  4732. // MES_Flag
  4733. //Funs[plcNo].WriteMultipleRegisters<short>(2088, e1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4734. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4735. writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  4736. writeToPLC_Flag.Adress = 2088;
  4737. writeToPLC_Flag.Value = e1OEEMES_FLAG;
  4738. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  4739. stopwatch2.Stop();
  4740. }
  4741. catch (Exception ex)
  4742. {
  4743. string str = ex.StackTrace;
  4744. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4745. // MES_Flag
  4746. stopwatch2.Start();
  4747. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  4748. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4749. writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  4750. writeToPLC_Flag.Adress = 2088;
  4751. writeToPLC_Flag.Value = (short)4;
  4752. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  4753. stopwatch2.Stop();
  4754. }
  4755. stopwatch1.Stop();
  4756. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4757. }
  4758. /// <summary>
  4759. /// [S5] Tray盘下料装备 - AGV上料叫agv
  4760. /// </summary>
  4761. /// <param name="plcNo">PLC编号</param>
  4762. /// <param name="stationNameStr">工站全称</param>
  4763. private void S5AGV上料叫agv(int plcNo, string stationNameStr)
  4764. {
  4765. Stopwatch stopwatch1 = new Stopwatch();
  4766. Stopwatch stopwatch2 = new Stopwatch();
  4767. try
  4768. {
  4769. stopwatch1.Start();
  4770. // ZS 呼叫AGV
  4771. short e1AGVUpCall = 2;
  4772. stopwatch2.Start();
  4773. // e1AGVUpCall
  4774. //Funs[plcNo].WriteMultipleRegisters<short>(2120, e1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  4775. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4776. writeToPLC_Flag.Name = "e1AGVUpCall";
  4777. writeToPLC_Flag.Adress = 2120;
  4778. writeToPLC_Flag.Value = e1AGVUpCall;
  4779. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  4780. stopwatch2.Stop();
  4781. }
  4782. catch (Exception ex)
  4783. {
  4784. string str = ex.StackTrace;
  4785. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4786. // e1AGVUpCall
  4787. stopwatch2.Start();
  4788. //Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  4789. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4790. writeToPLC_Flag.Name = "e1AGVUpCall";
  4791. writeToPLC_Flag.Adress = 2120;
  4792. writeToPLC_Flag.Value = (short)4;
  4793. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  4794. stopwatch2.Stop();
  4795. }
  4796. stopwatch1.Stop();
  4797. AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4798. }
  4799. /// <summary>
  4800. /// [S5] Tray盘下料装备 - AGV上料完成
  4801. /// </summary>
  4802. /// <param name="plcNo">PLC编号</param>
  4803. /// <param name="stationNameStr">工站全称</param>
  4804. private void S5AGV上料完成(int plcNo, string stationNameStr)
  4805. {
  4806. Stopwatch stopwatch1 = new Stopwatch();
  4807. Stopwatch stopwatch2 = new Stopwatch();
  4808. try
  4809. {
  4810. stopwatch1.Start();
  4811. // ZS AGV上料完成,让小车离开
  4812. short e1AGVUpEnd = 2;
  4813. stopwatch2.Start();
  4814. // e1AGVUpEnd
  4815. //Funs[plcNo].WriteMultipleRegisters<short>(2122, e1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  4816. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4817. writeToPLC_Flag.Name = "e1AGVUpEnd";
  4818. writeToPLC_Flag.Adress = 2122;
  4819. writeToPLC_Flag.Value = e1AGVUpEnd;
  4820. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  4821. stopwatch2.Stop();
  4822. }
  4823. catch (Exception ex)
  4824. {
  4825. string str = ex.StackTrace;
  4826. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4827. // e1AGVUpEnd
  4828. stopwatch2.Start();
  4829. //Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  4830. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4831. writeToPLC_Flag.Name = "e1AGVUpEnd";
  4832. writeToPLC_Flag.Adress = 2122;
  4833. writeToPLC_Flag.Value = (short)4;
  4834. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  4835. stopwatch2.Stop();
  4836. }
  4837. stopwatch1.Stop();
  4838. AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4839. }
  4840. /// <summary>
  4841. /// [S5] Tray盘下料装备 - AGV下料叫agv
  4842. /// </summary>
  4843. /// <param name="plcNo">PLC编号</param>
  4844. /// <param name="stationNameStr">工站全称</param>
  4845. private void S5AGV下料叫agv(int plcNo, string stationNameStr)
  4846. {
  4847. Stopwatch stopwatch1 = new Stopwatch();
  4848. Stopwatch stopwatch2 = new Stopwatch();
  4849. try
  4850. {
  4851. stopwatch1.Start();
  4852. // ZS 呼叫AGV
  4853. short e1AGVDownCall = 2;
  4854. stopwatch2.Start();
  4855. // e1AGVDownCall
  4856. //Funs[plcNo].WriteMultipleRegisters<short>(2133, e1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  4857. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4858. writeToPLC_Flag.Name = "e1AGVDownCall";
  4859. writeToPLC_Flag.Adress = 2133;
  4860. writeToPLC_Flag.Value = e1AGVDownCall;
  4861. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  4862. stopwatch2.Stop();
  4863. }
  4864. catch (Exception ex)
  4865. {
  4866. string str = ex.StackTrace;
  4867. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4868. // e1AGVDownCall
  4869. stopwatch2.Start();
  4870. //Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  4871. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4872. writeToPLC_Flag.Name = "e1AGVDownCall";
  4873. writeToPLC_Flag.Adress = 2133;
  4874. writeToPLC_Flag.Value = (short)4;
  4875. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  4876. stopwatch2.Stop();
  4877. }
  4878. stopwatch1.Stop();
  4879. AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4880. }
  4881. /// <summary>
  4882. /// [S5] Tray盘下料装备 - AGV下料完成
  4883. /// </summary>
  4884. /// <param name="plcNo">PLC编号</param>
  4885. /// <param name="stationNameStr">工站全称</param>
  4886. private void S5AGV下料完成(int plcNo, string stationNameStr)
  4887. {
  4888. Stopwatch stopwatch1 = new Stopwatch();
  4889. Stopwatch stopwatch2 = new Stopwatch();
  4890. try
  4891. {
  4892. stopwatch1.Start();
  4893. // ZS AGV上料完成,让小车离开
  4894. short e1AGVDownEnd = 2;
  4895. stopwatch2.Start();
  4896. // e1AGVDownEnd
  4897. //Funs[plcNo].WriteMultipleRegisters<short>(2135, e1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  4898. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4899. writeToPLC_Flag.Name = "e1AGVDownEnd";
  4900. writeToPLC_Flag.Adress = 2135;
  4901. writeToPLC_Flag.Value = e1AGVDownEnd;
  4902. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  4903. stopwatch2.Stop();
  4904. }
  4905. catch (Exception ex)
  4906. {
  4907. string str = ex.StackTrace;
  4908. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4909. // e1AGVDownEnd
  4910. stopwatch2.Start();
  4911. //Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  4912. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4913. writeToPLC_Flag.Name = "e1AGVDownEnd";
  4914. writeToPLC_Flag.Adress = 2135;
  4915. writeToPLC_Flag.Value = (short)4;
  4916. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  4917. stopwatch2.Stop();
  4918. }
  4919. stopwatch1.Stop();
  4920. AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4921. }
  4922. #endregion [S5] Tray盘下料装备
  4923. #endregion PLC5 张超凡
  4924. /// <summary>
  4925. /// [S6] 顶盖装配设备
  4926. /// </summary>
  4927. /// <param name="plcNo">PLC编号</param>
  4928. private void ReadStation_S6(int plcNo)
  4929. {
  4930. string stationCode = "[S6]";
  4931. string stationName = "顶盖装配设备";
  4932. string stationNameStr = stationCode + stationName;
  4933. string tagBaseName = "g_OP60_MES"; //标签变量名称
  4934. string tagMesCommName = "mesCommToPC"; //标签变量名称
  4935. string tagAgvCommName = "agvCommFrmPC";
  4936. string tagBarsetName = "BarcodeSet";
  4937. OP60_MesData_t stPLC_MesData; //PLC的MES数据
  4938. (int, string) result;
  4939. bool ProgressState = true;
  4940. #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4941. // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4942. s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  4943. s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  4944. s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  4945. s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  4946. s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4947. s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  4948. s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  4949. s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  4950. s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  4951. // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4952. s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  4953. s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
  4954. s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
  4955. s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  4956. s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
  4957. s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
  4958. s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  4959. s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
  4960. s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
  4961. s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
  4962. s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
  4963. s1PLCData.Add("a1Result", 0); // 产品结果
  4964. s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  4965. s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
  4966. s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
  4967. s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
  4968. s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
  4969. s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4970. s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
  4971. s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  4972. s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  4973. s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
  4974. s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  4975. s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  4976. s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
  4977. s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
  4978. s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  4979. s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
  4980. s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
  4981. #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4982. while (true)
  4983. {
  4984. try
  4985. {
  4986. if (!GlobalContext._IsCon_Funs1)
  4987. {
  4988. UpdatePLCMonitor(1, plcNo, 0);
  4989. continue;
  4990. }
  4991. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  4992. {
  4993. Stopwatch stopwatch1 = new Stopwatch();
  4994. Stopwatch stopwatch2 = new Stopwatch();
  4995. stopwatch1.Start();
  4996. stopwatch2.Start();
  4997. #region 一次性读取所有数据
  4998. // 一次性读取所有数据
  4999. result = Funs[plcNo].Read_SingleTag<OP60_MesData_t>(tagBaseName, 1, out stPLC_MesData); //读取单个结构体数据
  5000. if (result.Item1 != 0)
  5001. {
  5002. //richTextBox1.AppendText("\n" + strRet);
  5003. }
  5004. else
  5005. {
  5006. //richTextBox1.AppendText("\n" + "读取成功");
  5007. }
  5008. #endregion 一次性读取所有数据
  5009. stopwatch2.Stop();
  5010. #region 进站
  5011. try
  5012. {
  5013. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation && ProgressState == true)
  5014. {
  5015. ProgressState = false;
  5016. Task.Run(() => S6进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, out ProgressState));
  5017. }
  5018. }
  5019. catch (Exception ex)
  5020. {
  5021. ProgressState = false;
  5022. string str = ex.StackTrace;
  5023. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5024. }
  5025. #endregion 进站
  5026. #region 出站
  5027. try
  5028. {
  5029. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation && ProgressState == true)
  5030. {
  5031. ProgressState = false;
  5032. Task.Run(() => S6出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  5033. }
  5034. }
  5035. catch (Exception ex)
  5036. {
  5037. string str = ex.StackTrace;
  5038. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5039. }
  5040. #endregion 进站
  5041. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5042. stopwatch1.Stop();
  5043. OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5044. }
  5045. else
  5046. {
  5047. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5048. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5049. Funs[plcNo].Connect(); // 重连
  5050. }
  5051. }
  5052. catch (Exception ex)
  5053. {
  5054. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5055. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5056. }
  5057. Thread.Sleep(IntervalReadPLC);
  5058. }
  5059. }
  5060. /// <summary>
  5061. /// [S6] 顶盖装配设备 - 进站
  5062. /// </summary>
  5063. /// <param name="plcNo">PLC编号</param>
  5064. /// <param name="stationNameStr">工站全称</param>
  5065. /// <param name="stPLC_MesData"></param>
  5066. /// <param name="tagMesCommName"></param>
  5067. private void S6进站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, out bool ProgressState)
  5068. {
  5069. int nRet = 0;
  5070. string strRet = "";
  5071. Stopwatch stopwatch1 = new Stopwatch();
  5072. Stopwatch stopwatch2 = new Stopwatch();
  5073. ProgressState = true;
  5074. try
  5075. {
  5076. stopwatch1.Start();
  5077. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  5078. string MachineId = GlobalContext.S6_MachineId; // 装备ID(可配置)
  5079. string StationId = GlobalContext.S6_StationId; // 工位ID(可配置)
  5080. // 产品SN(物料码)校验
  5081. List<TestItem> item = new List<TestItem>();
  5082. stopwatch2.Start();
  5083. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  5084. stopwatch2.Stop();
  5085. //指令执行结果 1:OK 110:失败
  5086. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  5087. //进站结果写入PLC
  5088. CommandFromPLC resultToPlC = new CommandFromPLC();
  5089. resultToPlC.cmd = 0;
  5090. resultToPlC.cmdParam = 0; //指令参数
  5091. resultToPlC.cmdResult = mesResultFrmWeb;
  5092. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5093. }
  5094. catch (Exception ex)
  5095. {
  5096. string str = ex.StackTrace;
  5097. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5098. CommandFromPLC resultToPlC = new CommandFromPLC();
  5099. resultToPlC.cmd = 0;
  5100. resultToPlC.cmdParam = 0; //指令参数
  5101. resultToPlC.cmdResult = 110;
  5102. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5103. }
  5104. stopwatch1.Stop();
  5105. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5106. }
  5107. /// <summary>
  5108. /// [S6] 顶盖装配设备 - 出站接口
  5109. /// </summary>
  5110. private void S6出站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  5111. {
  5112. ProgressState = true;
  5113. Stopwatch stopwatch1 = new Stopwatch();
  5114. Stopwatch stopwatch2 = new Stopwatch();
  5115. try
  5116. {
  5117. stopwatch1.Start();
  5118. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5119. string processItem = stationName; // 测试项目
  5120. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5121. string supplierCode = ""; // 供应商代码
  5122. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5123. string batch_num = GlobalContext.BatchNumber; // 批次号
  5124. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5125. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  5126. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  5127. string MachineId = GlobalContext.S6_MachineId; // 装备id(可配置) // ZS
  5128. string StationId = GlobalContext.S6_StationId; // ⼯位ID(可配置) // ZS
  5129. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5130. bool pass = a1Result == 1;
  5131. List<TestItem> items = new List<TestItem>();
  5132. items.Add(new TestItem()
  5133. {
  5134. Parameter_name = "载具码",
  5135. Parameter_value = CarrierBarcode,
  5136. Parameter_unit = ""
  5137. });
  5138. items.Add(new TestItem()
  5139. {
  5140. Parameter_name = "产品码",
  5141. Parameter_value = mtltmrk,
  5142. Parameter_unit = ""
  5143. });
  5144. ResponseMessage responseMessage = InsertOp60Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsTopCoverAsmOK, "", stPLC_MesData.mesData.nHaveTopCover, stPLC_MesData.mesData.fForceTopCover);
  5145. if (!responseMessage.result)
  5146. {
  5147. AddMessage_Station(stationNameStr,LogType.Error, "OP60记录插入出错!");
  5148. }
  5149. //绑定PLC返回MES数据到本地
  5150. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  5151. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId);
  5152. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  5153. stopwatch2.Start();
  5154. //进站结果写入PLC
  5155. CommandFromPLC resultToPlC = new CommandFromPLC();
  5156. resultToPlC.cmd = 0;
  5157. resultToPlC.cmdParam = 0; //指令参数
  5158. resultToPlC.cmdResult = mesResultFrmWeb;
  5159. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5160. stopwatch2.Stop();
  5161. WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-Write" + (result1 == 1 ? "成功!" : "失败!"));
  5162. }
  5163. catch (Exception ex)
  5164. {
  5165. stopwatch2.Start();
  5166. CommandFromPLC resultToPlC = new CommandFromPLC();
  5167. resultToPlC.cmd = 0;
  5168. resultToPlC.cmdParam = 0; //指令参数
  5169. resultToPlC.cmdResult = 110;
  5170. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5171. stopwatch2.Stop();
  5172. string str = ex.StackTrace;
  5173. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{stationNameStr}]上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5174. }
  5175. stopwatch1.Stop();
  5176. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5177. }
  5178. /// <summary>
  5179. /// [S7] 锁螺丝设备
  5180. /// </summary>
  5181. /// <param name="plcNo">PLC编号</param>
  5182. private void ReadStation_S7(int plcNo)
  5183. {
  5184. string stationCode = "[S7]";
  5185. string stationName = "锁螺丝设备";
  5186. string stationNameStr = stationCode + stationName;
  5187. string tagBaseName = "g_OP70_MES"; //标签变量名称
  5188. string tagMesCommName = "mesCommToPC"; //标签变量名称
  5189. string tagAgvCommName = "agvCommFrmPC";
  5190. string tagBarsetName = "BarcodeSet";
  5191. OP70_MesData_t stPLC_MesData; //PLC的MES数据
  5192. (int, string) result;
  5193. bool ProgressState = true;
  5194. #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  5195. // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  5196. s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  5197. s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  5198. s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5199. s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  5200. s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5201. s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  5202. s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  5203. s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  5204. s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  5205. // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  5206. s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  5207. s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
  5208. s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
  5209. s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  5210. s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
  5211. s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
  5212. s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5213. s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
  5214. s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
  5215. s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
  5216. s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
  5217. s1PLCData.Add("a1Result", 0); // 产品结果
  5218. s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  5219. s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
  5220. s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
  5221. s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
  5222. s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
  5223. s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5224. s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
  5225. s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  5226. s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  5227. s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
  5228. s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  5229. s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  5230. s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
  5231. s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
  5232. s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  5233. s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
  5234. s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
  5235. #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  5236. while (true)
  5237. {
  5238. try
  5239. {
  5240. if (!GlobalContext._IsCon_Funs1)
  5241. {
  5242. UpdatePLCMonitor(1, plcNo, 0);
  5243. continue;
  5244. }
  5245. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  5246. {
  5247. Stopwatch stopwatch1 = new Stopwatch();
  5248. Stopwatch stopwatch2 = new Stopwatch();
  5249. stopwatch1.Start();
  5250. stopwatch2.Start();
  5251. #region 一次性读取所有数据
  5252. // 一次性读取所有数据
  5253. result = Funs[plcNo].Read_SingleTag<OP70_MesData_t>(tagBaseName, 1, out stPLC_MesData); //读取单个结构体数据
  5254. if (result.Item1 != 0)
  5255. {
  5256. //richTextBox1.AppendText("\n" + strRet);
  5257. }
  5258. else
  5259. {
  5260. //richTextBox1.AppendText("\n" + "读取成功");
  5261. }
  5262. #endregion 一次性读取所有数据
  5263. stopwatch2.Stop();
  5264. #region 左边进站
  5265. try
  5266. {
  5267. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation && ProgressState == true)
  5268. {
  5269. ProgressState = false;
  5270. Task.Run(() => S7左边进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, out ProgressState));
  5271. }
  5272. }
  5273. catch (Exception ex)
  5274. {
  5275. ProgressState = false;
  5276. string str = ex.StackTrace;
  5277. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5278. }
  5279. #endregion 左边进站
  5280. #region 左边出站
  5281. try
  5282. {
  5283. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation && ProgressState == true)
  5284. {
  5285. ProgressState = false;
  5286. Task.Run(() => S7左边出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  5287. }
  5288. }
  5289. catch (Exception ex)
  5290. {
  5291. string str = ex.StackTrace;
  5292. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5293. }
  5294. #endregion 左边出站
  5295. #region 右边进站
  5296. try
  5297. {
  5298. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation && ProgressState == true)
  5299. {
  5300. ProgressState = false;
  5301. Task.Run(() => S7右边进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, out ProgressState));
  5302. }
  5303. }
  5304. catch (Exception ex)
  5305. {
  5306. ProgressState = false;
  5307. string str = ex.StackTrace;
  5308. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5309. }
  5310. #endregion 右边进站
  5311. #region 右边出站
  5312. try
  5313. {
  5314. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation && ProgressState == true)
  5315. {
  5316. ProgressState = false;
  5317. Task.Run(() => S7右边出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  5318. }
  5319. }
  5320. catch (Exception ex)
  5321. {
  5322. string str = ex.StackTrace;
  5323. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5324. }
  5325. #endregion 右边出站
  5326. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5327. stopwatch1.Stop();
  5328. OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5329. }
  5330. else
  5331. {
  5332. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5333. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5334. Funs[plcNo].Connect(); // 重连
  5335. }
  5336. }
  5337. catch (Exception ex)
  5338. {
  5339. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5340. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5341. }
  5342. Thread.Sleep(IntervalReadPLC);
  5343. }
  5344. }
  5345. /// <summary>
  5346. /// [S7] 锁螺丝设备 - 左边进站
  5347. /// </summary>
  5348. /// <param name="plcNo">PLC编号</param>
  5349. /// <param name="stationNameStr">工站全称</param>
  5350. /// <param name="stPLC_MesData"></param>
  5351. /// <param name="tagMesCommName"></param>
  5352. private void S7左边进站(int plcNo, string stationNameStr, OP70_MesData_t stPLC_MesData, string tagMesCommName, out bool ProgressState)
  5353. {
  5354. int nRet = 0;
  5355. string strRet = "";
  5356. Stopwatch stopwatch1 = new Stopwatch();
  5357. Stopwatch stopwatch2 = new Stopwatch();
  5358. ProgressState = true;
  5359. try
  5360. {
  5361. stopwatch1.Start();
  5362. string sn = (string)stPLC_MesData.Left.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  5363. string MachineId = GlobalContext.S7_MachineId; // 装备ID(可配置)
  5364. string StationId = GlobalContext.S7_StationId; // 工位ID(可配置)
  5365. // 产品SN(物料码)校验
  5366. List<TestItem> item = new List<TestItem>();
  5367. stopwatch2.Start();
  5368. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  5369. stopwatch2.Stop();
  5370. //指令执行结果 1:OK 110:失败
  5371. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  5372. //进站结果写入PLC
  5373. CommandFromPLC resultToPlC = new CommandFromPLC();
  5374. resultToPlC.cmd = 0;
  5375. resultToPlC.cmdParam = 0; //指令参数
  5376. resultToPlC.cmdResult = mesResultFrmWeb;
  5377. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5378. }
  5379. catch (Exception ex)
  5380. {
  5381. string str = ex.StackTrace;
  5382. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5383. CommandFromPLC resultToPlC = new CommandFromPLC();
  5384. resultToPlC.cmd = 0;
  5385. resultToPlC.cmdParam = 0; //指令参数
  5386. resultToPlC.cmdResult = 110;
  5387. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5388. }
  5389. stopwatch1.Stop();
  5390. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5391. }
  5392. /// <summary>
  5393. /// [S7] 锁螺丝设备 - 左边出站接口
  5394. /// </summary>
  5395. private void S7左边出站(int plcNo, string stationNameStr, OP70_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  5396. {
  5397. ProgressState = true;
  5398. Stopwatch stopwatch1 = new Stopwatch();
  5399. Stopwatch stopwatch2 = new Stopwatch();
  5400. try
  5401. {
  5402. stopwatch1.Start();
  5403. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5404. string processItem = stationName; // 测试项目
  5405. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5406. string supplierCode = ""; // 供应商代码
  5407. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5408. string batch_num = GlobalContext.BatchNumber; // 批次号
  5409. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5410. string sn = (string)stPLC_MesData.Left.BarcodeSet.strProductBarcode; // 产品条码;
  5411. string CarrierBarcode = (string)stPLC_MesData.Left.BarcodeSet.strCarrierBarcode; // 载具条码;
  5412. string MachineId = GlobalContext.S7_MachineId; // 装备id(可配置) // ZS
  5413. string StationId = GlobalContext.S7_StationId; // ⼯位ID(可配置) // ZS
  5414. int a1Result = (int)stPLC_MesData.Left.iotData.testStatus; // 产品结果
  5415. bool pass = a1Result == 1;
  5416. List<TestItem> items = new List<TestItem>();
  5417. items.Add(new TestItem()
  5418. {
  5419. Parameter_name = "载具码",
  5420. Parameter_value = CarrierBarcode,
  5421. Parameter_unit = ""
  5422. });
  5423. items.Add(new TestItem()
  5424. {
  5425. Parameter_name = "产品码",
  5426. Parameter_value = mtltmrk,
  5427. Parameter_unit = ""
  5428. });
  5429. ResponseMessage responseMessage = InsertOp701Data(CarrierBarcode, sn, "", 0, 1, stPLC_MesData.Left.mesData.fScrewTimes[0], stPLC_MesData.Left.mesData.nScrewOrders[0].ToString(), stPLC_MesData.Left.mesData.nScrewResults[0].ToString());
  5430. if (!responseMessage.result)
  5431. {
  5432. AddMessage_Station(stationNameStr, LogType.Error, "OP701记录插入出错!");
  5433. }
  5434. //绑定PLC返回MES数据到本地
  5435. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  5436. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId);
  5437. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  5438. stopwatch2.Start();
  5439. //进站结果写入PLC
  5440. CommandFromPLC resultToPlC = new CommandFromPLC();
  5441. resultToPlC.cmd = 0;
  5442. resultToPlC.cmdParam = 0; //指令参数
  5443. resultToPlC.cmdResult = mesResultFrmWeb;
  5444. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5445. stopwatch2.Stop();
  5446. WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-Write" + (result1 == 1 ? "成功!" : "失败!"));
  5447. }
  5448. catch (Exception ex)
  5449. {
  5450. stopwatch2.Start();
  5451. CommandFromPLC resultToPlC = new CommandFromPLC();
  5452. resultToPlC.cmd = 0;
  5453. resultToPlC.cmdParam = 0; //指令参数
  5454. resultToPlC.cmdResult = 110;
  5455. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5456. stopwatch2.Stop();
  5457. string str = ex.StackTrace;
  5458. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{stationNameStr}]上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5459. }
  5460. stopwatch1.Stop();
  5461. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5462. }
  5463. /// <summary>
  5464. /// [S7] 锁螺丝设备 - 右边进站
  5465. /// </summary>
  5466. /// <param name="plcNo">PLC编号</param>
  5467. /// <param name="stationNameStr">工站全称</param>
  5468. /// <param name="stPLC_MesData"></param>
  5469. /// <param name="tagMesCommName"></param>
  5470. private void S7右边进站(int plcNo, string stationNameStr, OP70_MesData_t stPLC_MesData, string tagMesCommName, out bool ProgressState)
  5471. {
  5472. int nRet = 0;
  5473. string strRet = "";
  5474. Stopwatch stopwatch1 = new Stopwatch();
  5475. Stopwatch stopwatch2 = new Stopwatch();
  5476. ProgressState = true;
  5477. try
  5478. {
  5479. stopwatch1.Start();
  5480. string sn = (string)stPLC_MesData.Right.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  5481. string MachineId = GlobalContext.S7_MachineId; // 装备ID(可配置)
  5482. string StationId = GlobalContext.S7_StationId; // 工位ID(可配置)
  5483. // 产品SN(物料码)校验
  5484. List<TestItem> item = new List<TestItem>();
  5485. stopwatch2.Start();
  5486. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  5487. stopwatch2.Stop();
  5488. //指令执行结果 1:OK 110:失败
  5489. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  5490. //进站结果写入PLC
  5491. CommandFromPLC resultToPlC = new CommandFromPLC();
  5492. resultToPlC.cmd = 0;
  5493. resultToPlC.cmdParam = 0; //指令参数
  5494. resultToPlC.cmdResult = mesResultFrmWeb;
  5495. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5496. }
  5497. catch (Exception ex)
  5498. {
  5499. string str = ex.StackTrace;
  5500. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5501. CommandFromPLC resultToPlC = new CommandFromPLC();
  5502. resultToPlC.cmd = 0;
  5503. resultToPlC.cmdParam = 0; //指令参数
  5504. resultToPlC.cmdResult = 110;
  5505. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5506. }
  5507. stopwatch1.Stop();
  5508. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5509. }
  5510. /// <summary>
  5511. /// [S7] 锁螺丝设备 - 右边出站接口
  5512. /// </summary>
  5513. private void S7右边出站(int plcNo, string stationNameStr, OP70_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  5514. {
  5515. ProgressState = true;
  5516. Stopwatch stopwatch1 = new Stopwatch();
  5517. Stopwatch stopwatch2 = new Stopwatch();
  5518. try
  5519. {
  5520. stopwatch1.Start();
  5521. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5522. string processItem = stationName; // 测试项目
  5523. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5524. string supplierCode = ""; // 供应商代码
  5525. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5526. string batch_num = GlobalContext.BatchNumber; // 批次号
  5527. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5528. string sn = (string)stPLC_MesData.Right.BarcodeSet.strProductBarcode; // 产品条码;
  5529. string CarrierBarcode = (string)stPLC_MesData.Right.BarcodeSet.strCarrierBarcode; // 载具条码;
  5530. string MachineId = GlobalContext.S7_MachineId; // 装备id(可配置) // ZS
  5531. string StationId = GlobalContext.S7_StationId; // ⼯位ID(可配置) // ZS
  5532. int a1Result = (int)stPLC_MesData.Right.iotData.testStatus; // 产品结果
  5533. bool pass = a1Result == 1;
  5534. List<TestItem> items = new List<TestItem>();
  5535. items.Add(new TestItem()
  5536. {
  5537. Parameter_name = "载具码",
  5538. Parameter_value = CarrierBarcode,
  5539. Parameter_unit = ""
  5540. });
  5541. items.Add(new TestItem()
  5542. {
  5543. Parameter_name = "产品码",
  5544. Parameter_value = mtltmrk,
  5545. Parameter_unit = ""
  5546. });
  5547. ResponseMessage responseMessage = InsertOp702Data(CarrierBarcode,sn,"", 0,1, stPLC_MesData.Right.mesData.fScrewTimes[0], stPLC_MesData.Right.mesData.nScrewOrders[0].ToString(), stPLC_MesData.Right.mesData.nScrewResults[0].ToString());
  5548. if (!responseMessage.result)
  5549. {
  5550. AddMessage_Station(stationNameStr, LogType.Error, "OP702记录插入出错!");
  5551. }
  5552. //绑定PLC返回MES数据到本地
  5553. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  5554. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId);
  5555. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  5556. stopwatch2.Start();
  5557. //进站结果写入PLC
  5558. CommandFromPLC resultToPlC = new CommandFromPLC();
  5559. resultToPlC.cmd = 0;
  5560. resultToPlC.cmdParam = 0; //指令参数
  5561. resultToPlC.cmdResult = mesResultFrmWeb;
  5562. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5563. stopwatch2.Stop();
  5564. WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-Write" + (result1 == 1 ? "成功!" : "失败!"));
  5565. }
  5566. catch (Exception ex)
  5567. {
  5568. stopwatch2.Start();
  5569. CommandFromPLC resultToPlC = new CommandFromPLC();
  5570. resultToPlC.cmd = 0;
  5571. resultToPlC.cmdParam = 0; //指令参数
  5572. resultToPlC.cmdResult = 110;
  5573. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5574. stopwatch2.Stop();
  5575. string str = ex.StackTrace;
  5576. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{stationNameStr}]上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5577. }
  5578. stopwatch1.Stop();
  5579. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5580. }
  5581. /// <summary>
  5582. /// [S8] 3D螺丝高度检测设备
  5583. /// </summary>
  5584. /// <param name="plcNo">PLC编号</param>
  5585. private void ReadStation_S8(int plcNo)
  5586. {
  5587. string stationCode = "[S8]";
  5588. string stationName = "3D螺丝高度检测设备";
  5589. string stationNameStr = stationCode + stationName;
  5590. string tagBaseName = "g_OP80_MES"; //标签变量名称
  5591. string tagMesCommName = "mesCommToPC"; //标签变量名称
  5592. string tagAgvCommName = "agvCommFrmPC";
  5593. string tagBarsetName = "BarcodeSet";
  5594. OP80_MesData_t stPLC_MesData; //PLC的MES数据
  5595. (int, string) result;
  5596. bool ProgressState = true;
  5597. #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  5598. // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  5599. s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  5600. s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  5601. s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5602. s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  5603. s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5604. s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  5605. s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  5606. s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  5607. s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  5608. // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  5609. s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  5610. s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
  5611. s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
  5612. s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  5613. s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
  5614. s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
  5615. s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5616. s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
  5617. s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
  5618. s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
  5619. s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
  5620. s1PLCData.Add("a1Result", 0); // 产品结果
  5621. s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  5622. s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
  5623. s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
  5624. s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
  5625. s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
  5626. s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5627. s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
  5628. s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  5629. s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  5630. s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
  5631. s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  5632. s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  5633. s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
  5634. s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
  5635. s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  5636. s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
  5637. s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
  5638. #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  5639. while (true)
  5640. {
  5641. try
  5642. {
  5643. if (!GlobalContext._IsCon_Funs1)
  5644. {
  5645. UpdatePLCMonitor(1, plcNo, 0);
  5646. continue;
  5647. }
  5648. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  5649. {
  5650. Stopwatch stopwatch1 = new Stopwatch();
  5651. Stopwatch stopwatch2 = new Stopwatch();
  5652. stopwatch1.Start();
  5653. stopwatch2.Start();
  5654. #region 一次性读取所有数据
  5655. // 一次性读取所有数据
  5656. result = Funs[plcNo].Read_SingleTag<OP80_MesData_t>(tagBaseName, 1, out stPLC_MesData); //读取单个结构体数据
  5657. if (result.Item1 != 0)
  5658. {
  5659. //richTextBox1.AppendText("\n" + strRet);
  5660. }
  5661. else
  5662. {
  5663. //richTextBox1.AppendText("\n" + "读取成功");
  5664. }
  5665. #endregion 一次性读取所有数据
  5666. stopwatch2.Stop();
  5667. #region 进站
  5668. try
  5669. {
  5670. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation && ProgressState == true)
  5671. {
  5672. ProgressState = false;
  5673. Task.Run(() => S8进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, out ProgressState));
  5674. }
  5675. }
  5676. catch (Exception ex)
  5677. {
  5678. ProgressState = false;
  5679. string str = ex.StackTrace;
  5680. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5681. }
  5682. #endregion 进站
  5683. #region 出站
  5684. try
  5685. {
  5686. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation && ProgressState == true)
  5687. {
  5688. ProgressState = false;
  5689. Task.Run(() => S8出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  5690. }
  5691. }
  5692. catch (Exception ex)
  5693. {
  5694. string str = ex.StackTrace;
  5695. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5696. }
  5697. #endregion 进站
  5698. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5699. stopwatch1.Stop();
  5700. OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5701. }
  5702. else
  5703. {
  5704. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5705. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5706. Funs[plcNo].Connect(); // 重连
  5707. }
  5708. }
  5709. catch (Exception ex)
  5710. {
  5711. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5712. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5713. }
  5714. Thread.Sleep(IntervalReadPLC);
  5715. }
  5716. }
  5717. /// <summary>
  5718. /// [S8] 3D螺丝高度检测设备 - 进站
  5719. /// </summary>
  5720. /// <param name="plcNo">PLC编号</param>
  5721. /// <param name="stationNameStr">工站全称</param>
  5722. /// <param name="stPLC_MesData"></param>
  5723. /// <param name="tagMesCommName"></param>
  5724. private void S8进站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, out bool ProgressState)
  5725. {
  5726. int nRet = 0;
  5727. string strRet = "";
  5728. Stopwatch stopwatch1 = new Stopwatch();
  5729. Stopwatch stopwatch2 = new Stopwatch();
  5730. ProgressState = true;
  5731. try
  5732. {
  5733. stopwatch1.Start();
  5734. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  5735. string MachineId = GlobalContext.S8_MachineId; // 装备ID(可配置)
  5736. string StationId = GlobalContext.S8_StationId; // 工位ID(可配置)
  5737. // 产品SN(物料码)校验
  5738. List<TestItem> item = new List<TestItem>();
  5739. stopwatch2.Start();
  5740. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  5741. stopwatch2.Stop();
  5742. //指令执行结果 1:OK 110:失败
  5743. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  5744. //进站结果写入PLC
  5745. CommandFromPLC resultToPlC = new CommandFromPLC();
  5746. resultToPlC.cmd = 0;
  5747. resultToPlC.cmdParam = 0; //指令参数
  5748. resultToPlC.cmdResult = mesResultFrmWeb;
  5749. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5750. }
  5751. catch (Exception ex)
  5752. {
  5753. string str = ex.StackTrace;
  5754. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5755. CommandFromPLC resultToPlC = new CommandFromPLC();
  5756. resultToPlC.cmd = 0;
  5757. resultToPlC.cmdParam = 0; //指令参数
  5758. resultToPlC.cmdResult = 110;
  5759. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5760. }
  5761. stopwatch1.Stop();
  5762. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5763. }
  5764. /// <summary>
  5765. /// [S8] 3D螺丝高度检测设备 - 出站接口
  5766. /// </summary>
  5767. private void S8出站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  5768. {
  5769. ProgressState = true;
  5770. Stopwatch stopwatch1 = new Stopwatch();
  5771. Stopwatch stopwatch2 = new Stopwatch();
  5772. try
  5773. {
  5774. stopwatch1.Start();
  5775. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5776. string processItem = stationName; // 测试项目
  5777. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5778. string supplierCode = ""; // 供应商代码
  5779. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5780. string batch_num = GlobalContext.BatchNumber; // 批次号
  5781. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5782. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  5783. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  5784. string MachineId = GlobalContext.S8_MachineId; // 装备id(可配置) // ZS
  5785. string StationId = GlobalContext.S8_StationId; // ⼯位ID(可配置) // ZS
  5786. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5787. bool pass = a1Result == 1;
  5788. List<TestItem> items = new List<TestItem>();
  5789. items.Add(new TestItem()
  5790. {
  5791. Parameter_name = "载具码",
  5792. Parameter_value = CarrierBarcode,
  5793. Parameter_unit = ""
  5794. });
  5795. items.Add(new TestItem()
  5796. {
  5797. Parameter_name = "产品码",
  5798. Parameter_value = mtltmrk,
  5799. Parameter_unit = ""
  5800. });
  5801. //绑定PLC返回MES数据到本地
  5802. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  5803. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId);
  5804. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  5805. stopwatch2.Start();
  5806. //进站结果写入PLC
  5807. CommandFromPLC resultToPlC = new CommandFromPLC();
  5808. resultToPlC.cmd = 0;
  5809. resultToPlC.cmdParam = 0; //指令参数
  5810. resultToPlC.cmdResult = mesResultFrmWeb;
  5811. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5812. stopwatch2.Stop();
  5813. WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-Write" + (result1 == 1 ? "成功!" : "失败!"));
  5814. }
  5815. catch (Exception ex)
  5816. {
  5817. stopwatch2.Start();
  5818. CommandFromPLC resultToPlC = new CommandFromPLC();
  5819. resultToPlC.cmd = 0;
  5820. resultToPlC.cmdParam = 0; //指令参数
  5821. resultToPlC.cmdResult = 110;
  5822. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5823. stopwatch2.Stop();
  5824. string str = ex.StackTrace;
  5825. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{stationNameStr}]上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5826. }
  5827. stopwatch1.Stop();
  5828. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5829. }
  5830. /// <summary>
  5831. /// [S9] 下料设备
  5832. /// </summary>
  5833. /// <param name="plcNo">PLC编号</param>
  5834. private void ReadStation_S9(int plcNo)
  5835. {
  5836. string stationCode = "[S9]";
  5837. string stationName = "下料设备";
  5838. string stationNameStr = stationCode + stationName;
  5839. string tagBaseName = "g_OP90_MES"; //标签变量名称
  5840. string tagMesCommName = "mesCommToPC"; //标签变量名称
  5841. string tagAgvCommName = "agvCommFrmPC";
  5842. string tagBarsetName = "BarcodeSet";
  5843. OP90_MesData_t stPLC_MesData; //PLC的MES数据
  5844. (int, string) result;
  5845. bool ProgressState = true;
  5846. #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  5847. // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  5848. s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  5849. s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  5850. s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5851. s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  5852. s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5853. s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  5854. s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  5855. s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  5856. s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  5857. // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  5858. s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  5859. s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
  5860. s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
  5861. s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  5862. s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
  5863. s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
  5864. s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5865. s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
  5866. s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
  5867. s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
  5868. s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
  5869. s1PLCData.Add("a1Result", 0); // 产品结果
  5870. s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  5871. s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
  5872. s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
  5873. s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
  5874. s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
  5875. s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5876. s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
  5877. s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  5878. s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  5879. s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
  5880. s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  5881. s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  5882. s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
  5883. s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
  5884. s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  5885. s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
  5886. s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
  5887. #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  5888. while (true)
  5889. {
  5890. try
  5891. {
  5892. if (!GlobalContext._IsCon_Funs1)
  5893. {
  5894. UpdatePLCMonitor(1, plcNo, 0);
  5895. continue;
  5896. }
  5897. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  5898. {
  5899. Stopwatch stopwatch1 = new Stopwatch();
  5900. Stopwatch stopwatch2 = new Stopwatch();
  5901. stopwatch1.Start();
  5902. stopwatch2.Start();
  5903. #region 一次性读取所有数据
  5904. // 一次性读取所有数据
  5905. result = Funs[plcNo].Read_SingleTag<OP90_MesData_t>(tagBaseName, 1, out stPLC_MesData); //读取单个结构体数据
  5906. if (result.Item1 != 0)
  5907. {
  5908. //richTextBox1.AppendText("\n" + strRet);
  5909. }
  5910. else
  5911. {
  5912. //richTextBox1.AppendText("\n" + "读取成功");
  5913. }
  5914. #endregion 一次性读取所有数据
  5915. stopwatch2.Stop();
  5916. #region 进站
  5917. try
  5918. {
  5919. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation && ProgressState == true)
  5920. {
  5921. ProgressState = false;
  5922. Task.Run(() => S9进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, out ProgressState));
  5923. }
  5924. }
  5925. catch (Exception ex)
  5926. {
  5927. ProgressState = false;
  5928. string str = ex.StackTrace;
  5929. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5930. }
  5931. #endregion 进站
  5932. #region 出站
  5933. try
  5934. {
  5935. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation && ProgressState == true)
  5936. {
  5937. ProgressState = false;
  5938. Task.Run(() => S9出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  5939. }
  5940. }
  5941. catch (Exception ex)
  5942. {
  5943. string str = ex.StackTrace;
  5944. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5945. }
  5946. #endregion 进站
  5947. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5948. stopwatch1.Stop();
  5949. OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5950. }
  5951. else
  5952. {
  5953. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5954. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5955. Funs[plcNo].Connect(); // 重连
  5956. }
  5957. }
  5958. catch (Exception ex)
  5959. {
  5960. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5961. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5962. }
  5963. Thread.Sleep(IntervalReadPLC);
  5964. }
  5965. }
  5966. /// <summary>
  5967. /// [S9] 下料设备 - 进站
  5968. /// </summary>
  5969. /// <param name="plcNo">PLC编号</param>
  5970. /// <param name="stationNameStr">工站全称</param>
  5971. /// <param name="stPLC_MesData"></param>
  5972. /// <param name="tagMesCommName"></param>
  5973. private void S9进站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, out bool ProgressState)
  5974. {
  5975. int nRet = 0;
  5976. string strRet = "";
  5977. Stopwatch stopwatch1 = new Stopwatch();
  5978. Stopwatch stopwatch2 = new Stopwatch();
  5979. ProgressState = true;
  5980. try
  5981. {
  5982. stopwatch1.Start();
  5983. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  5984. string MachineId = GlobalContext.S9_MachineId; // 装备ID(可配置)
  5985. string StationId = GlobalContext.S9_StationId; // 工位ID(可配置)
  5986. // 产品SN(物料码)校验
  5987. List<TestItem> item = new List<TestItem>();
  5988. stopwatch2.Start();
  5989. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  5990. stopwatch2.Stop();
  5991. //指令执行结果 1:OK 110:失败
  5992. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  5993. //进站结果写入PLC
  5994. CommandFromPLC resultToPlC = new CommandFromPLC();
  5995. resultToPlC.cmd = 0;
  5996. resultToPlC.cmdParam = 0; //指令参数
  5997. resultToPlC.cmdResult = mesResultFrmWeb;
  5998. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5999. }
  6000. catch (Exception ex)
  6001. {
  6002. string str = ex.StackTrace;
  6003. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6004. CommandFromPLC resultToPlC = new CommandFromPLC();
  6005. resultToPlC.cmd = 0;
  6006. resultToPlC.cmdParam = 0; //指令参数
  6007. resultToPlC.cmdResult = 110;
  6008. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6009. }
  6010. stopwatch1.Stop();
  6011. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6012. }
  6013. /// <summary>
  6014. /// [S9] 下料设备 - 出站接口
  6015. /// </summary>
  6016. private void S9出站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  6017. {
  6018. ProgressState = true;
  6019. Stopwatch stopwatch1 = new Stopwatch();
  6020. Stopwatch stopwatch2 = new Stopwatch();
  6021. try
  6022. {
  6023. stopwatch1.Start();
  6024. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6025. string processItem = stationName; // 测试项目
  6026. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6027. string supplierCode = ""; // 供应商代码
  6028. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6029. string batch_num = GlobalContext.BatchNumber; // 批次号
  6030. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6031. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  6032. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  6033. string MachineId = GlobalContext.S9_MachineId; // 装备id(可配置) // ZS
  6034. string StationId = GlobalContext.S9_StationId; // ⼯位ID(可配置) // ZS
  6035. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  6036. bool pass = a1Result == 1;
  6037. List<TestItem> items = new List<TestItem>();
  6038. items.Add(new TestItem()
  6039. {
  6040. Parameter_name = "载具码",
  6041. Parameter_value = CarrierBarcode,
  6042. Parameter_unit = ""
  6043. });
  6044. items.Add(new TestItem()
  6045. {
  6046. Parameter_name = "产品码",
  6047. Parameter_value = mtltmrk,
  6048. Parameter_unit = ""
  6049. });
  6050. //绑定PLC返回MES数据到本地
  6051. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  6052. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId);
  6053. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  6054. stopwatch2.Start();
  6055. //进站结果写入PLC
  6056. CommandFromPLC resultToPlC = new CommandFromPLC();
  6057. resultToPlC.cmd = 0;
  6058. resultToPlC.cmdParam = 0; //指令参数
  6059. resultToPlC.cmdResult = mesResultFrmWeb;
  6060. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6061. stopwatch2.Stop();
  6062. WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-Write" + (result1 == 1 ? "成功!" : "失败!"));
  6063. }
  6064. catch (Exception ex)
  6065. {
  6066. stopwatch2.Start();
  6067. CommandFromPLC resultToPlC = new CommandFromPLC();
  6068. resultToPlC.cmd = 0;
  6069. resultToPlC.cmdParam = 0; //指令参数
  6070. resultToPlC.cmdResult = 110;
  6071. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6072. stopwatch2.Stop();
  6073. string str = ex.StackTrace;
  6074. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{stationNameStr}]上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6075. }
  6076. stopwatch1.Stop();
  6077. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6078. }
  6079. #region 缓存读取到的PLC数据 与 需要写入的PLC数据
  6080. /// <summary>
  6081. /// PLC读取到的数据 -添加数据
  6082. /// </summary>
  6083. public static void SxPLCData_Add(ref Dictionary<string, object> sxPlcData, string newKey, object newValue)
  6084. {
  6085. if (sxPlcData.ContainsKey(newKey))
  6086. sxPlcData[newKey] = newValue;
  6087. else
  6088. sxPlcData.Add(newKey, newValue);
  6089. }
  6090. /// <summary>
  6091. /// PLC需要写入的数据 -添加数据
  6092. /// </summary>
  6093. public static void SxPLCWriteData_Add(ref Dictionary<string, WriteToPLC_Flag> sxPLCWriteData, string newKey, WriteToPLC_Flag newValue)
  6094. {
  6095. if (sxPLCWriteData.ContainsKey(newKey))
  6096. sxPLCWriteData[newKey] = newValue;
  6097. else
  6098. sxPLCWriteData.Add(newKey, newValue);
  6099. }
  6100. /// <summary>
  6101. /// PLC回写操作,写后清空flag
  6102. /// </summary>
  6103. /// <param name="modbusClient">modbus对象</param>
  6104. /// <param name="pLCReadDatas">读取到的数据字典</param>
  6105. /// <param name="pLCWriteDatas">需要写入的数据</param>
  6106. public static void PLCWriteData(ModbusClientHelper modbusClient, ref Dictionary<string, object> pLCReadDatas, ref Dictionary<string, WriteToPLC_Flag> pLCWriteDataDic)
  6107. {
  6108. if (pLCWriteDataDic != null && pLCWriteDataDic.Count > 0)
  6109. {
  6110. List<WriteToPLC_Flag> pLCWriteDatas = pLCWriteDataDic.Values.ToList();
  6111. for (int i = 0; i < pLCWriteDatas.Count; i++)
  6112. {
  6113. string mesFlagName = pLCWriteDatas[i].Name;
  6114. int mesFlagAdress = pLCWriteDatas[i].Adress;
  6115. short mesFlagValue = (short)pLCWriteDatas[i].Value; // short
  6116. if (mesFlagValue != 0) // 不为0则证明需要写入结果信息
  6117. {
  6118. // 先回写数据
  6119. List<WriteToPLC_Data> writeToPLCDatas = pLCWriteDatas[i].WriteToPLCDatas;
  6120. for (int j = 0; j < writeToPLCDatas.Count; j++)
  6121. {
  6122. int mesDataAdress = writeToPLCDatas[j].Adress;
  6123. PLCValueType mesDataType = writeToPLCDatas[j].ValueType;
  6124. switch (mesDataType)
  6125. {
  6126. case PLCValueType.Short:
  6127. short mesDataValueShort = (short)writeToPLCDatas[j].Value;
  6128. modbusClient.WriteMultipleRegisters<short>(mesDataAdress, mesDataValueShort);
  6129. break;
  6130. case PLCValueType.String:
  6131. string mesDataValueStr = (string)writeToPLCDatas[j].Value;
  6132. int mesDataValueStrLength = writeToPLCDatas[j].ValueTypeStrLength;
  6133. modbusClient.WriteMultipleRegisters<string>(mesDataAdress, mesDataValueStr, mesDataValueStrLength);
  6134. break;
  6135. }
  6136. }
  6137. // 再回写信号
  6138. modbusClient.WriteMultipleRegisters<short>(mesFlagAdress, mesFlagValue);
  6139. // 存储读取数据的字典
  6140. pLCReadDatas[mesFlagName] = (int)mesFlagValue;
  6141. // 存储写入数据的字典 - 清空写入值
  6142. pLCWriteDatas[i].Value = (short)0;
  6143. pLCWriteDataDic[mesFlagName] = pLCWriteDatas[i];
  6144. }
  6145. }
  6146. }
  6147. }
  6148. /// <summary>
  6149. /// 提交点检数据到MES - 取数据库中缓存的 点检数据
  6150. /// </summary>
  6151. /// <param name="no">3</param>
  6152. /// <param name="stationCode">设备编号</param>
  6153. /// <param name="stationNameStr">设备名称</param>
  6154. /// <param name="plcOrder">车间订单号</param>
  6155. private void SubmitOneCheckDataToMESByDB(int plcNo, int stationCode, string stationNameStr, string plcOrder)
  6156. {
  6157. try
  6158. {
  6159. /// [S2]FCT (2-上传点检数据;102-清空该工单该工单的所有点检项缓存)
  6160. /// [S3]值板机 (3-上传点检数据;103-清空该工单该工单的所有点检项缓存)
  6161. /// [S4]取放桁架 (4-上传点检数据;104-清空该工单该工单的所有点检项缓存)
  6162. /// [S6]CCD检测 (6-上传点检数据;106-清空该工单该工单的所有点检项缓存)
  6163. int result1 = 0;
  6164. switch (stationCode)
  6165. {
  6166. case 2:
  6167. case 3:
  6168. case 4:
  6169. case 6:
  6170. result1 = SubmitToMESByDB(stationCode.ToString(), stationNameStr, plcOrder);
  6171. break;
  6172. case 102:
  6173. result1 = ClearOneCheckDataByDB("2", stationNameStr, plcOrder);
  6174. break;
  6175. case 103:
  6176. result1 = ClearOneCheckDataByDB("3", stationNameStr, plcOrder);
  6177. break;
  6178. case 104:
  6179. result1 = ClearOneCheckDataByDB("4", stationNameStr, plcOrder);
  6180. break;
  6181. case 106:
  6182. result1 = ClearOneCheckDataByDB("6", stationNameStr, plcOrder);
  6183. break;
  6184. default:
  6185. // MES_Flag 为“6未找到正确设备编号”
  6186. //Funs[plcNo].WriteMultipleRegisters<int>(2406, 6);
  6187. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!未找到需要点检的正确设备编号");
  6188. return;
  6189. }
  6190. short result = result1 == 1 ? (short)1 : (short)2;
  6191. //Funs[plcNo].WriteMultipleRegisters<int>(2406, result); // MES_Flag 为4MES报错
  6192. WritePLCLog(LogType.Debug, $"PLC{plcNo}_PLC通知MES上传点检数据运行完毕!-Write" + (result == 1 ? "成功!" : "失败!"));
  6193. }
  6194. catch (Exception ex)
  6195. {
  6196. // MES_Flag 为2上位机报错
  6197. //Funs[plcNo].WriteMultipleRegisters<int>(2406, 2);
  6198. string str = ex.StackTrace;
  6199. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6200. }
  6201. }
  6202. #endregion 缓存读取到的PLC数据 与 需要写入的PLC数据
  6203. #region 日志
  6204. #region 各工位定制日志(同步至PLC交互页面)
  6205. /// <summary>
  6206. /// 添加日志
  6207. /// </summary>
  6208. /// <param name="stationNameStr">工站名称</param>
  6209. /// <param name="logType">日志类型</param>
  6210. /// <param name="message">日志内容</param>
  6211. /// <param name="snNumber">产品数字SN</param>
  6212. public void AddMessage_Station(string stationNameStr, LogType logType, string message, string snNumber = "")
  6213. {
  6214. if (!(stationNameStr.Equals("获取设备报警数据与状态信息")
  6215. && (message.Contains("更新整线运行数据完毕") || message.Contains("更新整线报警数据完毕"))
  6216. ))
  6217. {
  6218. AddMessage(logType, message); // 首页展示+日志记录
  6219. }
  6220. PLCDBFormMessage plcMessage = new PLCDBFormMessage()
  6221. {
  6222. StationName = stationNameStr,
  6223. SnNumber = snNumber,
  6224. Message = message,
  6225. CreateTime = DateTime.Now
  6226. };
  6227. // PLC交互页展示
  6228. Task.Run(() =>
  6229. {
  6230. try
  6231. {
  6232. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  6233. {
  6234. Form_Main.formPLCDB.UpdateMessage(plcMessage);
  6235. }
  6236. }
  6237. catch { }
  6238. });
  6239. }
  6240. #endregion 各工位定制日志(同步至PLC交互页面)
  6241. /// <summary>
  6242. /// 添加日志
  6243. /// </summary>
  6244. /// <param name="logType">日志类型</param>
  6245. /// <param name="message">日志内容</param>
  6246. public void AddMessage(LogType logType, string message)
  6247. {
  6248. OnMessage(logType, message);
  6249. string date = DateTime.Now.ToString("yyyy/MM/dd");
  6250. string time = DateTime.Now.ToString("HH:mm:ss:fff");
  6251. string msgShow = time + "--> " + message + "\r\n";
  6252. this.BeginInvoke(new Action(() =>
  6253. {
  6254. systemLog.Rows.Insert(0, date, time, message);
  6255. if (systemLog.Rows.Count >= 100)
  6256. systemLog.Rows.RemoveAt(systemLog.Rows.Count - 1);
  6257. }));
  6258. }
  6259. /// <summary>
  6260. /// 添加日志-保存
  6261. /// </summary>
  6262. /// <param name="logType">日志类型</param>
  6263. /// <param name="message">日志内容</param>
  6264. private void OnMessage(LogType logType, string msg)
  6265. {
  6266. MessageEvent?.Invoke(logType, msg);
  6267. }
  6268. /// <summary>
  6269. /// 保存PLC日志
  6270. /// </summary>
  6271. /// <param name="logType"></param>
  6272. /// <param name="logValue"></param>
  6273. private void WritePLCLog(LogType logType, string logValue)
  6274. {
  6275. switch ((int)logType)
  6276. {
  6277. case 0:
  6278. _PLCLogNet.WriteDebug(logValue);
  6279. break;
  6280. case 1:
  6281. _PLCLogNet.WriteInfo(logValue);
  6282. break;
  6283. case 2:
  6284. _PLCLogNet.WriteWarn(logValue);
  6285. break;
  6286. case 3:
  6287. _PLCLogNet.WriteError(logValue);
  6288. break;
  6289. default:
  6290. _PLCLogNet.WriteFatal(logValue);
  6291. break;
  6292. }
  6293. }
  6294. #endregion 日志
  6295. #region 保存数据
  6296. /// <summary>
  6297. /// 调用进站接口并保存进站数据
  6298. /// </summary>
  6299. /// <param name="stationNameStr">工站信息</param>
  6300. /// <param name="workorder_code">工单号</param>
  6301. /// <param name="mtltmrk">型号(物料号)</param>
  6302. /// <param name="sn">产品SN</param>
  6303. /// <param name="items">进站数据</param>
  6304. /// <returns>1成功;5MES报警;6上位机报警</returns>
  6305. public int SaveStationInData(string stationNameStr, string workorder_code, string mtltmrk, string sn, List<TestItem> items,string MachineId,string StationId)
  6306. {
  6307. int result = 0;
  6308. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  6309. inRequest_Body.machineId = MachineId; // 装备ID(可配置)
  6310. inRequest_Body.stationId = StationId; // ⼯位ID(可配置)
  6311. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  6312. inRequest_Body.clientTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  6313. inRequest_Body.unitSn = sn; // 产品SN
  6314. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;非必填
  6315. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;非必填
  6316. string json_Body = JsonConvert.SerializeObject(inRequest_Body);
  6317. StationIn stationIn = new StationIn()
  6318. {
  6319. Workorder_code = workorder_code, // 车间订单号
  6320. Mtltmrk = mtltmrk, // 产品型号(物料号)
  6321. Sn = sn, // SN
  6322. StationIn_body = json_Body, // 进站接口Json数据 - Body
  6323. Parameter_values = items, // 进站数据
  6324. Write_user = inRequest_Body.userId, // 员工Id
  6325. Test_time = inRequest_Body.clientTime // 进站时间
  6326. };
  6327. // 本地数据
  6328. string sql = stationIn.ToStringInsert(0);
  6329. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  6330. result = ret == "成功" ? 1 : 6;
  6331. AddMessage_Station(stationNameStr, LogType.Info, string.Concat(stationNameStr, "_保存本地进站数据---" + ret));
  6332. //await Task.Delay(200);
  6333. // 上传MES
  6334. if (GlobalContext.IsSendStationIn)
  6335. {
  6336. try
  6337. {
  6338. XmMES_StationInResponse response = new XmMES_StationInResponse();
  6339. string mesRet = string.Empty;
  6340. int i = 0;
  6341. while (i < 2) // 1009会多次尝试上传
  6342. {
  6343. response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  6344. if (response != null && response.header.code == "200")
  6345. break;
  6346. else if (!mesRet.Contains("1009")) // 1009是未知错误
  6347. i++;
  6348. i++;
  6349. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  6350. // 记录失败原因
  6351. OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + json_Body);
  6352. }
  6353. AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + "_上传进站数据到MES服务器---" + mesRet);
  6354. if (response?.header?.code == "200")
  6355. {
  6356. string sql_Upd = stationIn.ToStringUpdateStatusByID(1);
  6357. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  6358. result = ret_Upd == "成功" ? 1 : 6;
  6359. AddMessage_Station(stationNameStr, LogType.Info, $"更新【进站数据 id {stationIn.GUID}】上传状态---" + ret_Upd);
  6360. }
  6361. else
  6362. {
  6363. result = 5;
  6364. OnMessage(LogType.Error, "上传进站数据到MES服务器---失败!接口报错信息:" + mesRet + "参数:" + json_Body);
  6365. }
  6366. }
  6367. catch (Exception ex)
  6368. {
  6369. result = 6;
  6370. string str = ex.StackTrace;
  6371. AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传进站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6372. }
  6373. }
  6374. return result;
  6375. }
  6376. /// <summary>
  6377. /// 选择如何记录出站数据
  6378. /// </summary>
  6379. /// <param name="items">出站数据</param>
  6380. /// <param name="equipmentCode">设备编号</param>
  6381. /// <param name="processItem">测试项目</param>
  6382. /// <param name="workorder_code">车间订单号</param>
  6383. /// <param name="batch_num">批次号</param>
  6384. /// <param name="mtltmrk">型号</param>
  6385. /// <param name="proDate">日期</param>
  6386. /// <param name="supplierCode">供应商代码</param>
  6387. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  6388. /// <returns>上传成功时返回1;失败返回0</returns>
  6389. private int SwitctProcessData(string stationNameStr, List<TestItem> items, string equipmentCode, string processItem,
  6390. string workorder_code, string batch_num, string mtltmrk, string proDate,
  6391. string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string MachineId, string StationId)
  6392. {
  6393. return SaveProcessDataByDB(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num, mtltmrk,
  6394. proDate, supplierCode, sn, pass, vehicleSn, vehicleSlot, MachineId, StationId);
  6395. }
  6396. /// <summary>
  6397. /// 添加出站数据(提交到MES+本地保存到数据库)
  6398. /// </summary>
  6399. /// <param name="items">出站数据</param>
  6400. /// <param name="equipmentCode">设备编号</param>
  6401. /// <param name="processItem">测试项目</param>
  6402. /// <param name="workorder_code">车间订单号</param>
  6403. /// <param name="batch_num">批次号</param>
  6404. /// <param name="mtltmrk">型号</param>
  6405. /// <param name="proDate">日期</param>
  6406. /// <param name="supplierCode">供应商代码</param>
  6407. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  6408. /// <returns>上传成功时返回1;失败返回0</returns>
  6409. public int SaveProcessDataByDB(string stationNameStr, List<TestItem> items, string equipmentCode,
  6410. string processItem, string workorder_code, string batch_num, string mtltmrk,
  6411. string proDate, string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot,string machineId,string stationId)
  6412. {
  6413. int upload = 0;
  6414. int result = 0;
  6415. ProcessData processData = new ProcessData()
  6416. {
  6417. Equipment_code = equipmentCode,
  6418. Workorder_code = workorder_code,
  6419. Batch_number = batch_num,
  6420. Sn = sn, // SN
  6421. Testitem = processItem,
  6422. Parameter_values = items,
  6423. Write_user = GlobalContext.CurrentUser,
  6424. Test_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  6425. };
  6426. // 本地数据
  6427. string sql = processData.ToStringInsert(upload);
  6428. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  6429. AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地出站数据---" + ret));
  6430. // 上传MES
  6431. if (GlobalContext.IsSendProcessData)
  6432. {
  6433. try
  6434. {
  6435. string id = processData.ID.Copy();
  6436. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  6437. outRequest_Body.machineId = machineId; // 装备id(可配置) // ZS
  6438. outRequest_Body.stationId = stationId; // ⼯位ID(可配置) // ZS
  6439. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  6440. outRequest_Body.clientTime = processData.Test_time; // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  6441. outRequest_Body.unitSn = sn; // 产品SN
  6442. outRequest_Body.state = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL
  6443. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID;非必填
  6444. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id;非必填
  6445. outRequest_Body.unitData.vehicleData.Add(
  6446. new XmMES_StationOutRequest_Body.XmStationOut_VehicleData()
  6447. {
  6448. vehicleSn = vehicleSn,
  6449. vehicleType = string.Empty,
  6450. slot = vehicleSlot
  6451. }); // 设备数据 - 载具信息
  6452. string jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  6453. if (GlobalContext.IsSendProcessData)
  6454. {
  6455. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  6456. string mesRet = string.Empty;
  6457. int i = 0;
  6458. while (i < 2) // 1009会多次尝试上传
  6459. {
  6460. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  6461. if (response != null && response.header.code == "200")
  6462. break;
  6463. else if (!mesRet.Contains("1009")) // 1009是未知错误
  6464. i++;
  6465. i++;
  6466. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  6467. // 记录失败原因
  6468. OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + jsonstr1);
  6469. }
  6470. AddMessage_Station(stationNameStr, LogType.Info, "[" + processItem + "]上传出站数据到MES服务器---" + mesRet);
  6471. if (response?.header?.code == "200")
  6472. {
  6473. string sql_Upd = ProcessData.ToStringUpdateStatusByID(1, id);
  6474. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  6475. result = 1;
  6476. AddMessage_Station(stationNameStr, LogType.Info, $"更新【出站数据 id {id}】上传状态---" + ret_Upd);
  6477. }
  6478. else
  6479. {
  6480. OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!接口报错信息:" + mesRet + "参数:" + jsonstr1);
  6481. }
  6482. }
  6483. }
  6484. catch (Exception ex)
  6485. {
  6486. string str = ex.StackTrace;
  6487. AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传出站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6488. }
  6489. }
  6490. return result;
  6491. }
  6492. /// <summary>
  6493. /// 选择如何记录点检数据
  6494. /// </summary>
  6495. /// <param name="names"></param>
  6496. /// <param name="contents"></param>
  6497. /// <param name="results"></param>
  6498. /// <param name="equipmentCode"></param>
  6499. /// <param name="stationNameStr"></param>
  6500. private int SwitctOneCheckData(OneCheckData oneCheckData, string equipmentCode, string stationNameStr)
  6501. {
  6502. //if (DataSwitch == 1)
  6503. //{
  6504. return SaveOneCheckDataByDB(oneCheckData, equipmentCode, stationNameStr);
  6505. //}
  6506. //else // 废弃
  6507. //{
  6508. // SaveOneCheckData(names, contents, results, equipmentCode, stationNameStr);
  6509. //}
  6510. }
  6511. /// <summary>
  6512. /// 添加点检数据ByDB(本地保存;不提交到MES)
  6513. /// </summary>
  6514. /// <param name="oneCheckData">点检数据</param>
  6515. /// <param name="equipmentCode">设备编号</param>
  6516. /// <param name="stationNameStr">工站名称</param>
  6517. public int SaveOneCheckDataByDB(OneCheckData oneCheckData, string equipmentCode, string stationNameStr)
  6518. {
  6519. int upload = 0;
  6520. //本地数据保存
  6521. string sql = oneCheckData.ToStringInsert(upload);
  6522. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  6523. AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地点检数据---", ret));
  6524. //Task.Run(() => // 上传mes-异步
  6525. //{
  6526. // //上传mes
  6527. // string jsonstr = JsonConvert.SerializeObject(oneCheckData);
  6528. // if (GlobalContext.IsSendCheckOneData)
  6529. // {
  6530. // string url = @"HTTP://" + GlobalContext.ServerHost + ":" + GlobalContext.ServerPort + @"/api/ProductionLine/OneCheckData";
  6531. // string mesRet = HttpUitls.SubmitDataToMES(url, jsonstr);
  6532. // AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]上传点检数据到MES---", mesRet));
  6533. // if (mesRet == "成功")
  6534. // {
  6535. // // 更新上传状态
  6536. // string sql_Upd = OneCheckData.ToStringUpdateStatusByID(1, oneCheckData.ID);
  6537. // string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  6538. // AddMessage_Station(stationNameStr, LogType.Info, $"更新【点检数据 id {oneCheckData.ID}】上传状态---" + ret_Upd);
  6539. // }
  6540. // }
  6541. //});
  6542. return ret == "成功" ? 1 : 0;
  6543. }
  6544. /// <summary>
  6545. /// 提交点检数据到MES
  6546. /// </summary>
  6547. /// <param name="procedure_code">工序编号 = 设备编号</param>
  6548. /// <param name="plcOrder">车间订单号</param>
  6549. /// <returns></returns>
  6550. public int SubmitToMESByDB(string procedure_code, string stationNameStr, string plcOrder)
  6551. {
  6552. // 获取今天的点检数据
  6553. string querySQL_Today = new OneCheckData().ToQuerySQL_Today(procedure_code, plcOrder);
  6554. DataSet ds = SQLHelper_New.Query(querySQL_Today, null);
  6555. if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  6556. {
  6557. // 拼接所有点检数据
  6558. OneCheckData oneCheckDatas_MES = new OneCheckData()
  6559. {
  6560. ID = ds.Tables[0].Rows[0][0].ToString(),
  6561. Line_code = ds.Tables[0].Rows[0][1].ToString(),
  6562. Line_name = ds.Tables[0].Rows[0][2].ToString(),
  6563. Equipment_code = ds.Tables[0].Rows[0][3].ToString(),
  6564. Equipment_name = ds.Tables[0].Rows[0][4].ToString(),
  6565. Workorder_code = ds.Tables[0].Rows[0][5].ToString(),
  6566. Procedure_code = ds.Tables[0].Rows[0][6].ToString(),
  6567. Procedure_name = ds.Tables[0].Rows[0][7].ToString(),
  6568. Onecheck_empcode = ds.Tables[0].Rows[0][8].ToString(),
  6569. Onecheck_empname = ds.Tables[0].Rows[0][9].ToString(),
  6570. Onecheck_time = ds.Tables[0].Rows[0][10].ToString()
  6571. };
  6572. List<string> upd_Ids = new List<string>();
  6573. foreach (DataRow row in ds.Tables[0].Rows)
  6574. {
  6575. var obj1 = row["Oneckeck_values"];
  6576. if (obj1 != null)
  6577. {
  6578. upd_Ids.Add(row["ID"].ToString());
  6579. List<OneCheckItem> item = JsonConvert.DeserializeObject<List<OneCheckItem>>(obj1.ToString());
  6580. oneCheckDatas_MES.Oneckeck_values.AddRange(item);
  6581. }
  6582. }
  6583. //上传mes
  6584. string jsonstr = JsonConvert.SerializeObject(oneCheckDatas_MES);
  6585. if (GlobalContext.IsSendCheckOneData)
  6586. {
  6587. string url = @"HTTP://" + GlobalContext.ServerHost + ":" + @"/api/ProductionLine/OneCheckData";
  6588. string mesRet = HttpUitls.SubmitDataToMES(url, jsonstr);
  6589. AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[", stationNameStr, "]PLC通知上传点检数据到MES到---", mesRet));
  6590. if (mesRet == "成功")
  6591. {
  6592. // 更新上传状态
  6593. string sql_Upd = OneCheckData.ToStringUpdateStatusByIDs(1, upd_Ids);
  6594. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  6595. AddMessage_Station(stationNameStr, LogType.Info, $"更新【点检数据 id [{string.Join("','", upd_Ids)}]】上传状态---" + ret_Upd);
  6596. // 保存最新一条点检数据 到文件中
  6597. StandardLibrary.IniFile.INIWriteValue(GlobalContext.CheckOneDataPath, "S" + procedure_code, "WorkOrderCode", GlobalContext.WorkOrderCode);
  6598. StandardLibrary.IniFile.INIWriteValue(GlobalContext.CheckOneDataPath, "S" + procedure_code, "Oneckeck_values", JsonConvert.SerializeObject(oneCheckDatas_MES.Oneckeck_values));
  6599. return ret_Upd == "成功" ? 1 : 0;
  6600. }
  6601. }
  6602. }
  6603. //else
  6604. //{
  6605. // AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[", stationNameStr, "]PLC通知上传点检数据到MES---失败!今天还未点检。"));
  6606. //}
  6607. return 0;
  6608. }
  6609. /// <summary>
  6610. /// 添加点检数据ByDB(本地保存 + 提交到MES)
  6611. /// </summary>
  6612. /// <param name="oneCheckData">点检数据</param>
  6613. /// <param name="equipmentCode">设备编号</param>
  6614. /// <param name="stationNameStr">工站名称</param>
  6615. /// <returns></returns>
  6616. public int SaveOneCheckDataByDBAndSubmit(OneCheckData oneCheckData, string equipmentCode, string stationNameStr)
  6617. {
  6618. int upload = 0;
  6619. //本地数据保存
  6620. string sql = oneCheckData.ToStringInsert(upload);
  6621. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  6622. AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地点检数据---", ret));
  6623. Task.Run(() => // 上传mes-异步
  6624. {
  6625. //上传mes
  6626. string jsonstr = JsonConvert.SerializeObject(oneCheckData);
  6627. string jsonItems = JsonConvert.SerializeObject(oneCheckData.Oneckeck_values);
  6628. if (GlobalContext.IsSendCheckOneData)
  6629. {
  6630. string url = @"HTTP://" + GlobalContext.ServerHost + ":" + @"/api/ProductionLine/OneCheckData";
  6631. string mesRet = HttpUitls.SubmitDataToMES(url, jsonstr);
  6632. AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]上传点检数据到MES---", mesRet));
  6633. if (mesRet == "成功")
  6634. {
  6635. // 更新上传状态
  6636. string sql_Upd = OneCheckData.ToStringUpdateStatusByID(1, oneCheckData.ID);
  6637. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  6638. AddMessage_Station(stationNameStr, LogType.Info, $"更新【点检数据 id {oneCheckData.ID}】上传状态---" + ret_Upd);
  6639. // 保存最新一条点检数据 到文件中
  6640. StandardLibrary.IniFile.INIWriteValue(GlobalContext.CheckOneDataPath, equipmentCode, "WorkOrderCode", GlobalContext.WorkOrderCode);
  6641. StandardLibrary.IniFile.INIWriteValue(GlobalContext.CheckOneDataPath, equipmentCode, "Oneckeck_values", jsonItems);
  6642. }
  6643. }
  6644. });
  6645. return ret == "成功" ? 1 : 0;
  6646. }
  6647. /// <summary>
  6648. /// 清空 点检数据 By 工序号、订单号
  6649. /// </summary>
  6650. /// <param name="procedure_code">工序号</param>
  6651. /// <param name="stationNameStr">工站号</param>
  6652. /// <param name="plcOrder">订单号</param>
  6653. /// <returns></returns>
  6654. /// <exception cref="NotImplementedException"></exception>
  6655. private int ClearOneCheckDataByDB(string procedure_code, string stationNameStr, string plcOrder)
  6656. {
  6657. // 清空
  6658. string sql_Det = OneCheckData.ToDeteleByProcedurecodeAndPlcOrder(procedure_code, plcOrder);
  6659. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Det, null);
  6660. AddMessage_Station(stationNameStr, LogType.Info, $"清空【工位编号{procedure_code}】【车间订单{plcOrder}】的点检项缓存 ---" + ret_Upd);
  6661. return ret_Upd == "成功" ? 1 : 2;
  6662. }
  6663. /// <summary>
  6664. /// 生产过程中,自动判断 是否 使用上次的点检数据
  6665. /// 在工单加工第一个产品时触发该方法
  6666. /// 如果工单是上次的点检工单则直接返回成功,工单不是上次的点检工单则使用上个工单的点检数据,上传点检信息
  6667. /// </summary>
  6668. /// <param name="stationNameStr"></param>
  6669. /// <param name="equipmentCode">设备编号</param>
  6670. /// <param name="accno">工序编号</param>
  6671. /// <param name="processItem">点检数据</param>
  6672. /// <returns></returns>
  6673. private int SwitctOneCheckData_First(string stationNameStr, string equipmentCode, string accno, string processItem)
  6674. {
  6675. string WorkOrderCode = StandardLibrary.IniFile.INIGetStringValue(GlobalContext.CheckOneDataPath, equipmentCode, "WorkOrderCode", string.Empty);
  6676. //如果当前工单和记录中的工单是一致,表示这个工单是需要点检的,跳过
  6677. //如果当前工单和记录中的工单是不一致,表示这个工单和上个工单是同型号的,可以使用上个工单的点检数据
  6678. if (GlobalContext.WorkOrderCode == WorkOrderCode)
  6679. {
  6680. return 1;
  6681. }
  6682. //点检数据
  6683. string Oneckeck_values = StandardLibrary.IniFile.INIGetStringValue(GlobalContext.CheckOneDataPath, equipmentCode, "Oneckeck_values", string.Empty);
  6684. List<OneCheckItem> items = new List<OneCheckItem>();
  6685. try
  6686. {
  6687. items = JsonConvert.DeserializeObject<List<OneCheckItem>>(Oneckeck_values);
  6688. }
  6689. catch (Exception ex)
  6690. {
  6691. return 0;
  6692. }
  6693. // 拼接所有点检数据
  6694. OneCheckData oneCheckDatas_MES = new OneCheckData()
  6695. {
  6696. ID = Guid.NewGuid().ToString(),
  6697. Line_code = GlobalContext.LineCode,
  6698. Line_name = GlobalContext.LineName,
  6699. Equipment_code = equipmentCode,
  6700. Equipment_name = equipmentCode,
  6701. Workorder_code = GlobalContext.WorkOrderCode,
  6702. Procedure_code = accno,
  6703. Procedure_name = processItem,
  6704. Onecheck_empcode = "",
  6705. Onecheck_empname = "",
  6706. Onecheck_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"),
  6707. Oneckeck_values = items
  6708. };
  6709. // 本地保存 + 提交到MES
  6710. return SaveOneCheckDataByDBAndSubmit(oneCheckDatas_MES, equipmentCode, stationNameStr);
  6711. }
  6712. /// <summary>
  6713. /// 添加报警数据ByDB(提交到MES+本地保存)
  6714. /// </summary>
  6715. /// <param name="alarmData">数据</param>
  6716. /// <param name="isUpd">更新而不是新增</param>
  6717. public void SaveAlarmDataByDB(string stationNameStr, AlarmData alarmData, bool isUpd)
  6718. {
  6719. if (isUpd)
  6720. {
  6721. string sql = alarmData.ToStringUpdate();
  6722. SQLHelper_New.ExecuteSQL(sql, null);
  6723. AddMessage_Station(stationNameStr, LogType.Info, "消除报警[" + alarmData.LineName + "-" + alarmData.AlarmDesc + "]完毕!");
  6724. }
  6725. else
  6726. {
  6727. string sql = alarmData.ToStringInsert();
  6728. SQLHelper_New.ExecuteSQL(sql, null);
  6729. AddMessage_Station(stationNameStr, LogType.Info, "发生了报警[" + alarmData.LineName + "-" + alarmData.AlarmDesc + "]!");
  6730. }
  6731. }
  6732. /// <summary>
  6733. /// 上传节拍数据
  6734. /// </summary>
  6735. /// <returns></returns>
  6736. public (short, string) SaveOEEData(int plcNo, string stationNameStr, XiaomiDeviceOEE deviceOEE, string oEEPartNo, string oEEProductSN)
  6737. {
  6738. // 上传OEE
  6739. if (GlobalContext.IsMqttStationInputBegin)
  6740. {
  6741. Task.Run(() =>
  6742. {
  6743. try
  6744. {
  6745. StationInputBeginRequest oee = new StationInputBeginRequest();
  6746. oee.action = deviceOEE.ToString(); // 节拍动作(XiaomiDeviceOEE)
  6747. oee.beat_tm = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 节拍发⽣时间
  6748. oee.action_subject = oEEPartNo; // 该动作操作的⽬标对象(SN)
  6749. oee.action_subject_parent = oEEProductSN; // ⼤板SN/载具SN
  6750. oee.action_location = "ZS"; // ZS 该动作的位置信息(⼯位、槽位),如:F06-GSTPLA11_01-SLOT-01
  6751. oee.action_material = string.Empty; // 该动作的物料信息
  6752. oee.extra = string.Empty; // 额外信息
  6753. oee.class_level_1 = string.Empty; // 分类层级1
  6754. oee.class_level_2 = string.Empty; // 分类层级2
  6755. oee.class_level_3 = string.Empty; // 分类层级3
  6756. int result = XiaomiMqttClient_Extend.Write_StationInputBegin(oee);
  6757. string msg = $"[{result}]";
  6758. bool errCodeParse = Enum.TryParse(result.ToString(), out XiaomiMqttResponse_ErrCode errCode);
  6759. msg += errCodeParse ? errCode.ToString() : "ERR_UNKOWN";
  6760. AddMessage(LogType.Info, stationNameStr + $"_异步上传节拍接口;接口结果:-- {msg}");
  6761. }
  6762. catch (Exception ex)
  6763. {
  6764. string str = ex.StackTrace;
  6765. AddMessage(LogType.Error, $"PLC{plcNo}_{stationNameStr} 异步上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6766. }
  6767. });
  6768. return ((short)1, "异步上传中!");
  6769. }
  6770. else
  6771. return ((short)1, "未启用上传!");
  6772. }
  6773. /// <summary>
  6774. /// 回调方法- With DataId
  6775. /// </summary>
  6776. /// <param name="id"></param>
  6777. /// <param name="v"></param>
  6778. /// <param name="dataId"></param>
  6779. public void CallbackWithDataId(string id, string msg, string dataId)
  6780. {
  6781. //_MqttLogNet.WriteInfo("-------CallbackWithDataId-------");
  6782. //byte[] buffer1 = Encoding.Default.GetBytes(v);
  6783. //byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);
  6784. //string strBuffer = Encoding.Default.GetString(buffer2, 0, buffer2.Length);
  6785. //Console.WriteLine("{0} -> {1} {2}", id, strBuffer, dataId);
  6786. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  6787. _MqttLogNet.WriteInfo($"{datetime}-> [消息ID:{id}][事件ID:{dataId}]{msg}");
  6788. }
  6789. #endregion 保存数据
  6790. #region UI刷新
  6791. /// <summary>
  6792. /// 更新商品信息的UI + 下发产品信息(SN)
  6793. /// </summary>
  6794. private void UpdateProductInfo()
  6795. {
  6796. currentBN.Text = GlobalContext.BatchNumber; // 批次号
  6797. currentWC.Text = GlobalContext.WorkOrderCode; // 订单号
  6798. currentMtltmrk.Text = GlobalContext.Mtltmrk; // 产品型号
  6799. txt_CurSupplierCode.Text = ""; // 供应商代号
  6800. // 下传给1号机,判断下plc对象数量
  6801. //if (Funs.Count > 1)
  6802. //{
  6803. // DownLoadProductInfo(1);
  6804. //}
  6805. }
  6806. /// <summary>
  6807. /// 更新PLC连接状态的UI
  6808. /// </summary>
  6809. /// <param name="no">PLC编号</param>
  6810. /// <param name="status">状态</param>
  6811. private void UpdatePLCMonitor(int imgNo, int plcNo, int status)
  6812. {
  6813. if (this != null && !this.IsDisposed)
  6814. {
  6815. switch (imgNo)
  6816. {
  6817. case 1:
  6818. this.BeginInvoke(new Action(() =>
  6819. {
  6820. pictureBox1.Image = imageListState.Images[status];
  6821. }));
  6822. break;
  6823. case 2:
  6824. this.BeginInvoke(new Action(() =>
  6825. {
  6826. pictureBox2.Image = imageListState.Images[status];
  6827. }));
  6828. break;
  6829. case 3:
  6830. this.BeginInvoke(new Action(() =>
  6831. {
  6832. pictureBox3.Image = imageListState.Images[status];
  6833. }));
  6834. break;
  6835. case 4:
  6836. this.BeginInvoke(new Action(() =>
  6837. {
  6838. pictureBox4.Image = imageListState.Images[status];
  6839. }));
  6840. break;
  6841. case 5:
  6842. this.BeginInvoke(new Action(() =>
  6843. {
  6844. pictureBox5.Image = imageListState.Images[status];
  6845. }));
  6846. break;
  6847. case 6:
  6848. this.BeginInvoke(new Action(() =>
  6849. {
  6850. pictureBox6.Image = imageListState.Images[status];
  6851. }));
  6852. break;
  6853. case 7:
  6854. this.BeginInvoke(new Action(() =>
  6855. {
  6856. pictureBox7.Image = imageListState.Images[status];
  6857. }));
  6858. break;
  6859. case 8:
  6860. this.BeginInvoke(new Action(() =>
  6861. {
  6862. pictureBox8.Image = imageListState.Images[status];
  6863. }));
  6864. break;
  6865. case 9:
  6866. this.BeginInvoke(new Action(() =>
  6867. {
  6868. pictureBox9.Image = imageListState.Images[status];
  6869. }));
  6870. break;
  6871. default:
  6872. break;
  6873. }
  6874. }
  6875. Task.Run(() => // 更新PLC交互页的指示灯
  6876. {
  6877. try
  6878. {
  6879. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  6880. {
  6881. Form_Main.formPLCDB.UpdatePLCFunMonitor(plcNo, status);
  6882. }
  6883. }
  6884. catch { }
  6885. });
  6886. }
  6887. #endregion UI刷新
  6888. /// <summary>
  6889. /// 实例化报警字典
  6890. /// </summary>
  6891. private void InitalDicAlarm()
  6892. {
  6893. #region 第一个工站(这里未区分工位,所以下面出现的‘工位代码’使用‘线别代码’代替)
  6894. List<Alarm> keyValues1 = new List<Alarm>
  6895. {
  6896. #region 第一组报警(电机)
  6897. new Alarm { 报警类型 = "电机故障", 报警详情 = "料盘搬运_Y轴电机故障" ,关联的PLC地址 = 5100 },
  6898. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_X轴电机故障" ,关联的PLC地址 = 5101 },
  6899. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_Z轴电机故障" ,关联的PLC地址 = 5102 },
  6900. new Alarm { 报警类型 = "电机故障", 报警详情 = "载具搬运_X轴电机故障" ,关联的PLC地址 = 5103 },
  6901. new Alarm { 报警类型 = "电机故障", 报警详情 = "镭射_X轴电机故障" ,关联的PLC地址 = 5104 },
  6902. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_X轴电机故障" ,关联的PLC地址 = 5105 },
  6903. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_Z轴电机故障" ,关联的PLC地址 = 5106 },
  6904. new Alarm { 报警类型 = "电机故障", 报警详情 = "下相机_X轴电机故障" ,关联的PLC地址 = 5107 },
  6905. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_Y轴电机故障" ,关联的PLC地址 = 5108 },
  6906. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_X轴电机故障" ,关联的PLC地址 = 5109 },
  6907. #endregion 第一组报警(电机)
  6908. #region 第二组报警(气缸)
  6909. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料进退气缸故障" ,关联的PLC地址 = 5200 },
  6910. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料升降气缸故障" ,关联的PLC地址 = 5201 },
  6911. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓顶升气缸故障" ,关联的PLC地址 = 5202 },
  6912. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体取料夹爪气缸故障" ,关联的PLC地址 = 5203 },
  6913. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料仓顶升气缸故障" ,关联的PLC地址 = 5204 },
  6914. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料平移气缸故障" ,关联的PLC地址 = 5205 },
  6915. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料升降气缸故障" ,关联的PLC地址 = 5206 },
  6916. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料夹爪气缸故障" ,关联的PLC地址 = 5207 },
  6917. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料旋转气缸故障" ,关联的PLC地址 = 5208 },
  6918. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装平移气缸故障" ,关联的PLC地址 = 5209 },
  6919. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装升降气缸故障" ,关联的PLC地址 = 5210 },
  6920. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装夹爪气缸故障" ,关联的PLC地址 = 5211 },
  6921. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装撑开气缸故障" ,关联的PLC地址 = 5212 },
  6922. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸1故障" ,关联的PLC地址 = 5213 },
  6923. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸2故障" ,关联的PLC地址 = 5214 },
  6924. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具下料移载气缸故障" ,关联的PLC地址 = 5215 },
  6925. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具侧推气缸故障" ,关联的PLC地址 = 5216 },
  6926. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具回流气缸故障" ,关联的PLC地址 = 5217 },
  6927. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2压料气缸故障" ,关联的PLC地址 = 5218 },
  6928. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2电测气缸故障" ,关联的PLC地址 = 5219 },
  6929. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2气密气缸故障" ,关联的PLC地址 = 5220 },
  6930. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3下压气缸故障" ,关联的PLC地址 = 5221 },
  6931. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3上顶气缸故障" ,关联的PLC地址 = 5222 },
  6932. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位5相机升降气缸故障" ,关联的PLC地址 = 5223 },
  6933. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组升降气缸故障" ,关联的PLC地址 = 5224 },
  6934. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸1故障" ,关联的PLC地址 = 5225 },
  6935. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸2故障" ,关联的PLC地址 = 5226 },
  6936. new Alarm { 报警类型 = "气缸故障", 报警详情 = "机械手夹爪气缸故障" ,关联的PLC地址 = 5227 },
  6937. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位4:镭射压料气缸故障" ,关联的PLC地址 = 5228 },
  6938. #endregion 第二组报警(气缸)
  6939. #region 第三组报警(其他故障)
  6940. new Alarm { 报警类型 = "其他故障", 报警详情 = "上料处缺料报警" ,关联的PLC地址 = 5300 },
  6941. new Alarm { 报警类型 = "其他故障", 报警详情 = "震盘缺料报警" ,关联的PLC地址 = 5301 },
  6942. new Alarm { 报警类型 = "其他故障", 报警详情 = "成品仓料满报警" ,关联的PLC地址 = 5302 },
  6943. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照超时报警" ,关联的PLC地址 = 5303 },
  6944. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照NG报警" ,关联的PLC地址 = 5304 },
  6945. new Alarm { 报警类型 = "其他故障", 报警详情 = "玻璃门打开报警" ,关联的PLC地址 = 5305 },
  6946. #endregion 第三组报警(其他故障)
  6947. };
  6948. DicAlarms_Cur.Add(GlobalContext.LineCode, keyValues1); // 这里使用线体代替工位
  6949. #endregion 第一个工站(这里使用线体代替工位)
  6950. # region 第二个工站-原来的写法(废弃)
  6951. //keyValues = new Dictionary<int, AlarmData[]>();
  6952. ////1
  6953. //dicAlarmName = new Dictionary<int, Alarm>();
  6954. //dicAlarmName.Add(0, new Alarm { Name = "M01衬套组模组X电机报警" });
  6955. //dicAlarmName.Add(1, new Alarm { Name = "M02衬套组模组Y电机报警" });
  6956. //dicAlarmName.Add(2, new Alarm { Name = "M03衬套组模组Z电机报警" });
  6957. //dicAlarmName.Add(3, new Alarm { Name = "M04衬套组模组U电机报警" });
  6958. //dicAlarmName.Add(4, new Alarm { Name = "M05外流线皮带电机报警" });
  6959. //alarmDatas = new AlarmData[dicAlarmName.Count];
  6960. //for (int i = 0; i < dicAlarmName.Count; i++)
  6961. //{
  6962. // alarmDatas[i] = new AlarmData();
  6963. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  6964. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  6965. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  6966. // alarmDatas[i].AlarmType = 1;
  6967. //}
  6968. //keyValues.Add(1, alarmDatas);
  6969. ////2
  6970. //dicAlarmName = new Dictionary<int, Alarm>();
  6971. //dicAlarmName.Add(0, new Alarm { Name = "C01定位气缸故障" });
  6972. //dicAlarmName.Add(1, new Alarm { Name = "C02左推料气缸故障" });
  6973. //dicAlarmName.Add(2, new Alarm { Name = "C03右推料气缸故障" });
  6974. //dicAlarmName.Add(3, new Alarm { Name = "C04左压料气缸故障" });
  6975. //dicAlarmName.Add(4, new Alarm { Name = "C05右压料气缸故障" });
  6976. //dicAlarmName.Add(5, new Alarm { Name = "C06切料气缸故障" });
  6977. //dicAlarmName.Add(6, new Alarm { Name = "C07左入料吹气气缸故障" });
  6978. //dicAlarmName.Add(7, new Alarm { Name = "C08右入料吹气气缸故障" });
  6979. //alarmDatas = new AlarmData[dicAlarmName.Count];
  6980. //for (int i = 0; i < dicAlarmName.Count; i++)
  6981. //{
  6982. // alarmDatas[i] = new AlarmData();
  6983. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  6984. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  6985. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  6986. // alarmDatas[i].AlarmType = 2;
  6987. //}
  6988. //keyValues.Add(2, alarmDatas);
  6989. ////3
  6990. //dicAlarmName = new Dictionary<int, Alarm>();
  6991. //dicAlarmName.Add(0, new Alarm { Name = "安全门报警" });
  6992. //dicAlarmName.Add(1, new Alarm { Name = "联机通信故障" });
  6993. //dicAlarmName.Add(2, new Alarm { Name = "连续NG报警" });
  6994. //dicAlarmName.Add(3, new Alarm { Name = "合格率低于设定值报警" });
  6995. //alarmDatas = new AlarmData[dicAlarmName.Count];
  6996. //for (int i = 0; i < dicAlarmName.Count; i++)
  6997. //{
  6998. // alarmDatas[i] = new AlarmData();
  6999. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-3";
  7000. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  7001. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  7002. // alarmDatas[i].AlarmType = 3;
  7003. //}
  7004. //keyValues.Add(3, alarmDatas);
  7005. //DicAlarms.Add(2, keyValues);
  7006. #endregion 第二个工站-原来的写法(废弃)
  7007. }
  7008. private void groupBox3_Enter(object sender, EventArgs e)
  7009. {
  7010. }
  7011. }
  7012. }