1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846 |
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.IO;
- using System.Linq;
- using System.Text;
- using Microsoft.Win32;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using HslCommunication.LogNet;
- using MainForm.FaForm;
- using NPOI.Util;
- using Sunny.UI;
- using MainForm.ClassFile.XiaomiAPI;
- using System.Diagnostics;
- using MainForm.Models;
- using SqlSugar;
- using EasyModbus;
- using ModBusClientSimple.Util;
- using MainForm.ClassFile.XiaomiAPI_MES;
- using static MainForm.ClassFile.XiaomiAPI.XiaomiMqttClient_Extend;
- using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound;
- using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationInbound;
- using EIP_Protocol;
- using DevComponents.DotNetBar.Controls;
- using ICSharpCode.SharpZipLib.Zip;
- using static MainForm.SQLHelper;
- using NPOI.SS.Formula.Functions;
- using MainForm.ClassFile.ProjectClass;
- using HslCommunication.Controls;
- /*
- * 注:本源码对外提供,所以有些地方使用中文命名方法及变量
- */
- namespace MainForm
- {
- /// <summary>
- /// 记录日志的委托
- /// </summary>
- /// <param name="logType">日志类型</param>
- /// <param name="message">日志信息</param>
- public delegate void HomeMessageHandler(LogType logType, string message);
- /// <summary>
- /// 主页窗体
- /// </summary>
- public partial class Form_Home : Form
- {
- #region 常量
- //文本常量
- private const string Head = "开始采集";
- private const string Tail = "采集完成";
- private const string Body = "工位出站数据";
- private const string BodyCheck = "工位点检数据";
- private const string BodyRun = "整线运行数据";
- private const string BodyAlarm = "整线报警数据";
- #endregion 常量
- #region 变量
- /// <summary>
- /// 委托-记录日志的方法
- /// </summary>
- public event HomeMessageHandler MessageEvent;
- /// <summary>
- /// 日志接口
- /// </summary>
- ILogNet _PLCLogNet;
- /// <summary>
- /// 用于记录MQTT日志
- /// </summary>
- ILogNet _MqttLogNet;
- //private int DataSwitch = 1; // 1-SQLServer;2-Excel
- // 定义信号量,index0给MES(true有信号,false无信号;set()让被控线程运行,Reset()让被控线程停止;WaitOne(等待时间)等待线程运行)
- //间隔时间
- private int IntervalReadPLC = 300; //ms 读PLC
- private int IntervalMonitorMES = 1000; //ms MES心跳
- private int IntervalUpHead = 1000; //ms 上位机心跳(给PLC用)
- private int IntervalAlarm = 1000; //ms 数据(报警)查询与设备运行信息
- //定义一个字典,存plc对象(通讯)
- //ModbusClientHelper plc1Alarm; // PLC‘运行数据’与‘报警数据’线程用ModbusTCP
- //Dictionary<int, ModbusClientHelper> Funs = new Dictionary<int, ModbusClientHelper>();
- Inovance_EIP plc1Alarm; // PLC‘运行数据’与‘报警数据’线程用ModbusTCP
- Dictionary<int, Inovance_EIP> Funs = new Dictionary<int, Inovance_EIP>();
- /// <summary>
- /// 上次的设备运行信息
- /// </summary>
- private string lineWorkingData1_OldStr = string.Empty;
- /// <summary>
- /// 设备报警字典-当前结果
- /// Dictionary<工位代码,List<报警信息>>
- /// </summary>
- private Dictionary<string, List<Alarm>> DicAlarms_Cur = new Dictionary<string, List<Alarm>>();
- #endregion 变量
- #region 窗体基础事件
- /// <summary>
- /// 初始化
- /// </summary>
- public Form_Home()
- {
- InitializeComponent();
- CheckForIllegalCrossThreadCalls = false; // 不检查跨线程访问
- _PLCLogNet = new LogNetDateTime(GlobalContext.PlcLogDir, GenerateMode.ByEveryDay); // 按天记录日志
- _MqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryHour); // 按小时记录日志
- GlobalContext.Set += new Action(UpdateProductInfo); // 产品信息变化时更新UI
- }
- /// <summary>
- /// 窗体加载事件
- /// </summary>
- private void Form_Home_Load(object sender, EventArgs e)
- {
- try
- {
- AddMessage(LogType.Info, "开始初始化程序");
- InitalDicAlarm(); // 实例化报警字典
- //组建plc对象字典
- //plc1Alarm = new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort);
- //plc1Alarm = new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine1Address);
- if (GlobalContext.IsUsePLC1)
- Funs.Add(1, new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine1Address)); //OP10 壳体清洁上料装备
- //Funs.Add(1, new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort, 2001)); // Tray盘上料装备(板测)
- if (GlobalContext.IsUsePLC2)
- //Funs.Add(2, new ModbusClientHelper(GlobalContext.Machine2Address, GlobalContext.MachinePort, 2001)); // FCT(板测),
- Funs.Add(2, new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine2Address)); //OP20 顶盖上料设备
- if (GlobalContext.IsUsePLC3)
- Funs.Add(3, new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine3Address)); //OP30 点胶设备
- //Funs.Add(3, new ModbusClientHelper(GlobalContext.Machine3Address, GlobalContext.MachinePort, 2001)); // 值板机,
- if (GlobalContext.IsUsePLC4)
- Funs.Add(4, new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine4Address)); //OP40 3D胶线检测
- //Funs.Add(4, new ModbusClientHelper(GlobalContext.Machine4Address, GlobalContext.MachinePort, 2001)); // 取放桁
- if (GlobalContext.IsUsePLC5)
- Funs.Add(5, new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine5Address)); //OP50 ADD PCB板上料
- //Funs.Add(5, new ModbusClientHelper(GlobalContext.Machine5Address, GlobalContext.MachinePort, 2001)); //Tray盘下料装备
- if (GlobalContext.IsUsePLC6)
- Funs.Add(6, new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine6Address)); //OP60 顶盖装配
- if (GlobalContext.IsUsePLC7)
- Funs.Add(7, new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine7Address)); //OP70 锁螺丝
- if (GlobalContext.IsUsePLC8)
- Funs.Add(8, new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine8Address)); //OP80 3D螺丝高度检测,NG出料站
- if (GlobalContext.IsUsePLC9)
- Funs.Add(9, new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine9Address)); //OP90 下料站
- foreach (Inovance_EIP plcEIP in Funs.Values)
- {
- if (plcEIP != null)
- {
- try
- {
- (int, string) result = plcEIP.Connect();
- }
- catch (Exception ex)
- {
- MessageBox.Show($"PLC[{GlobalContext.Machine1Address}]连接失败!失败信息:" + ex.Message,
- "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
- }
- }
- }
- /*
- //plc1Alarm.Connect();
- foreach (ModbusClientHelper modbusClient in Funs.Values)
- {
- if (modbusClient != null)
- {
- try
- {
- modbusClient.Connect();
- }
- catch (Exception ex)
- {
- MessageBox.Show($"PLC[{modbusClient.IPAddress}:{modbusClient.Port}]连接失败!失败信息:" + ex.Message,
- "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
- }
- }
- }
- */
- // 采集任务
- Task TaskReadAlarm = new Task(ReadAlarmAllPLC); // 线程-获取线体报警数据
- List<Task> TaskReadProcess = new List<Task>(); // 线程-触发点位(PLC)的线程
- //TaskReadProcess.Add(new Task(() => { ReadStation_DownOrderInfo(1); })); // 下发机种
- if (GlobalContext.IsUsePLC1)
- //ReadStation_S1(1);
- TaskReadProcess.Add(new Task(() => { ReadStation_S1(1); })); //OP10 壳体清洁上料装备
- if (GlobalContext.IsUsePLC2)
- TaskReadProcess.Add(new Task(() => { ReadStation_S2(2); })); //OP20 顶盖上料设备
- if (GlobalContext.IsUsePLC3)
- //TaskReadProcess.Add(new Task(() => { ReadStation_S3(3); })); //OP30 点胶设备
- if (GlobalContext.IsUsePLC4)
- TaskReadProcess.Add(new Task(() => { ReadStation_S4(4); })); //OP40 点胶检测设备
- if (GlobalContext.IsUsePLC5)
- TaskReadProcess.Add(new Task(() => { ReadStation_S5(5); })); //OP50 ADD PCB板上料设备
-
- if (GlobalContext.IsUsePLC6)
- TaskReadProcess.Add(new Task(() => { ReadStation_S6(6); })); //OP60 顶盖装配设备
- if (GlobalContext.IsUsePLC7)
- TaskReadProcess.Add(new Task(() => { ReadStation_S7(7); })); //OP70 锁螺丝设备
- if (GlobalContext.IsUsePLC8)
- TaskReadProcess.Add(new Task(() => { ReadStation_S8(8); })); //OP80 3D螺丝高度检测设备
- if (GlobalContext.IsUsePLC9)
- TaskReadProcess.Add(new Task(() => { ReadStation_S9(9); })); //OP90 下料设备
-
-
-
-
- #region 初始化
- try
- {
- // 开启MES(Http)
- //bool mesret = HttpUitls.PingIP(GlobalContext.ServerHost1);
- //if (mesret)
- //{
- // OnMessage(LogType.Info, "MES初始连接正常");
- // pictureBoxMESStatus.Image = imageListState.Images[1];
- // GlobalContext.MESIsConnect = true;
- //}
- //else
- //{
- // OnMessage(LogType.Info, "MES初始连接失败");
- // pictureBoxMESStatus.Image = imageListState.Images[0];
- // GlobalContext.MESIsConnect = false;
- //}
- // 开启IOT(MQTT)
- string addr = GlobalContext.MQTTServerHost;
- int port = GlobalContext.MQTTServerPort;
- //int qmttResult = XiaomiMqttClient_Extend.OpenWithMqttServer(addr, port, GlobalContext.MqttServerPath, GlobalContext.MqttServerName);
- //XiaomiMqttResponse_ErrCode response_ErrCode = (XiaomiMqttResponse_ErrCode)qmttResult;
- //if (response_ErrCode == XiaomiMqttResponse_ErrCode.OK)
- //{
- // AddMessage(LogType.Info, "小米MQTT连接成功!--- OK");
- // pictureBoxMESStatus.Image = imageListState.Images[1];
- // GlobalContext.IOTIsConnect1 = true;
- // XiaomiMqttClient_Extend.SetCallbackWithDataId(CallbackWithDataId);
- //}
- //else
- //{
- // AddMessage(LogType.Info, $"小米MQTT连接失败!--- {response_ErrCode.ToString()}");
- // pictureBoxMESStatus.Image = imageListState.Images[0];
- // GlobalContext.IOTIsConnect1 = false;
- //}
- // 开启AGV HTTP
- //bool mesret = HttpUitls.PingIP(GlobalContext.ServerHost1);
- //if (mesret)
- //{
- // OnMessage(LogType.Info, "MES初始连接正常");
- // pictureBoxMESStatus.Image = imageListState.Images[1];
- // GlobalContext.MESIsConnect = true;
- //}
- //else
- //{
- // OnMessage(LogType.Info, "MES初始连接失败");
- // pictureBoxMESStatus.Image = imageListState.Images[0];
- // GlobalContext.MESIsConnect = false;
- //}
- // 开启AGV MQTT
- // 持续监视MES、IOT、AGV HTTP、AGV MQTT连接状态
- Task.Run(MonitorMESConnect);
- // 查询PLC连接状态
- foreach (int plcNo in Funs.Keys)
- {
- bool connected = Funs[plcNo].IsConnected;
- if (connected)
- {
- string msg = plcNo.ToString() + "工位初始连接成功---" + Funs[plcNo]._plcIPStr;
- AddMessage(LogType.Info, msg);
- UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI
- }
- else
- {
- string msg = plcNo.ToString() + "工位初始连接失败---" + Funs[plcNo]._plcIPStr;
- AddMessage(LogType.Info, msg);
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- }
- }
- // 开启PLC的业务处理线程-监听PLC点位+状态
- foreach (Task task in TaskReadProcess)
- {
- if (task != null)
- task.Start();
- }
- //// 开启“获取线体报警数据”的线程
- //TaskReadAlarm.Start();
- ////下传MES信息给1工位(先判断下plc对象数量)
- //if (Funs.Count > 1)
- // DownLoadProductInfo(1);
- AddMessage(LogType.Info, "程序初始化完成");
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- this.BeginInvoke(new Action(() =>
- {
- AddMessage(LogType.Error, "初始化PLC连接失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }));
- }
- #endregion
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- OnMessage(LogType.Info, "主窗体的首页初始化出错!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
- if (ex.Message != null && ex.Message.Contains("timed out"))
- MessageBox.Show("主窗体的首页初始化出错!异常信息:PLC连接超时!" + ex.Message);
- else
- MessageBox.Show("主窗体的首页初始化出错!异常信息:" + ex.Message);
- }
- }
- /// <summary>
- /// 窗体关闭事件
- /// </summary>
- private void Form_Home_FormClosed(object sender, FormClosedEventArgs e)
- {
- Closed2();
- }
- public void Closed2()
- {
- try
- {
- XiaomiMqttClient_Extend.CloseWithMqttServer(GlobalContext.MqttServerPath, GlobalContext.MqttServerName);
- }
- catch { }
- }
- #endregion 窗体基础事件
- #region 监控MES状态
- /// <summary>
- /// 监控MES连接状态
- /// </summary>
- private void MonitorMESConnect()
- {
- while (true) // 运行被控线程
- {
- bool mesret = XiaomiMqttClient.IsOpen;
- if (mesret)
- {
- pictureBoxMESStatus.Image = imageListState.Images[1];
- GlobalContext.IOTIsConnect1 = true;
- }
- else
- {
- OnMessage(LogType.Info, "MES1连接失败");
- pictureBoxMESStatus.Image = imageListState.Images[0];
- GlobalContext.IOTIsConnect1 = false;
- }
- Thread.Sleep(IntervalMonitorMES);
- }
- }
- #endregion 监控MES连接状态
- #region 采集设备状态、运行数据、报警数据
- /// <summary>
- /// 请求设备状态 5000
- /// </summary>
- /// <param name="no">1</param>
- /// <param name="stationNameStr"></param>
- /// <returns>0:证明未连接到PLC;1,代表设备控制状态处于运行状态;2,代表设备控制状态处于故障状态;3,代表设备控制状态处于缺料状态;4,代表设备控制状态处于待机状态;5,代表设备控制状态处于维修状态;</returns>
- public int GetDeviceStatus(int plcNo, string stationNameStr = "[S0]壳体上料")
- {
- try
- {
- if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
- {
- short result = 0; //Funs[plcNo].ReadHoldingRegisters<short>(5000); // 5000
- return result;
- }
- else
- {
- return 0;
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, "请求设备状态失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- return 0;
- }
- }
- /// <summary>
- /// 检查是否可采集点检数据 - 不取新值
- /// 5000不为1时可点检
- /// </summary>
- /// <returns></returns>
- public bool CheckCanSpotcheck1(int deviceState)
- {
- //return true;
- //D5000 = 1,代表设备控制状态处于运行状态
- //D5000 = 2, 代表设备控制状态处于故障状态
- //D5000 = 3,代表设备控制状态处于缺料状态
- //D5000 = 4, 代表设备控制状态处于待机状态
- //D5000 = 5,代表设备控制状态处于维修状态
- return deviceState != 1;
- }
- /// <summary>
- /// 检查是否可采集产品数据 - 不取新值
- /// </summary>
- /// <returns></returns>
- public bool CheckCanCollData(int deviceState)
- {
- return deviceState == 0; // 点检时该值不为0
- }
- /// <summary>
- /// 获取设备报警数据与获取设备运行信息
- /// </summary>
- private async void ReadAlarmAllPLC()
- {
- // [S1] Tray盘上料装备(板测)
- // [S2] FCT(板测)
- // [S3] 值板机
- // [S4] 取放桁架
- // [S5] Tray盘下料装备
- /// 上位机心跳
- /// 获取设备报警数据与状态信息
- string stationNameStr = "获取设备报警数据与状态信息";
- while (true)
- {
- try
- {
- if (!GlobalContext._IsCon_plc1Alarm)
- {
- UpdatePLCMonitor(1, -2, 0);
- continue;
- }
- if (plc1Alarm.IsConnected) // 检查PLC是否已连接上
- {
- DateTime dtNow = DateTime.Now;
- #region 获取设备运行信息
- try
- {
- LineWorkingData_ThisTime lineWorkingData1 = new LineWorkingData_ThisTime();
- lineWorkingData1.GUID = Guid.NewGuid().ToString();
- lineWorkingData1.LineName = GlobalContext.LineCode;
- //
- /*
- lineWorkingData1.BootTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5500); // 本次开机时间(整线)D5500 h
- lineWorkingData1.NormalTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5502); // 本次开机运行时间(整线)D5502 h
- lineWorkingData1.StandbyTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5504); // 本次开机待机时间(整线)D5504 h
- lineWorkingData1.FaultTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5506); // 本次开机故障时间(整线)D5506 h
- lineWorkingData1.MaterialShortageTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5508); // 本次开机缺料时间(整线)D5508 h
- lineWorkingData1.MaintenanceTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5510); // 本次开机维修时间(整线)D5510 h
- lineWorkingData1.FaultNumber = plc1Alarm.ReadHoldingRegisters<short>(5514); // 本次开机故障停机次数(整线)D5514
- lineWorkingData1.OutputNumber = plc1Alarm.ReadHoldingRegisters<short>(5700); // 本次开机产量(整线) D5700
- lineWorkingData1.QualifiedNumber = plc1Alarm.ReadHoldingRegisters<short>(5704); // 本次开机合格数量(整线) D5704
- lineWorkingData1.QualifiedRate = plc1Alarm.ReadHoldingRegisters<float>(5710); // 本次开机合格率(整线) D5710
- lineWorkingData1.DesignRhythm = plc1Alarm.ReadHoldingRegisters<float>(5714); // 设计节拍(整线) D5714
- lineWorkingData1.RealityRhythm = plc1Alarm.ReadHoldingRegisters<float>(5716); // 本次开机实际节拍(整线) D5716
- */
- lineWorkingData1.CreateTime = DateTime.Now;
- string lineWorkingData1_Str = JsonConvert.SerializeObject(lineWorkingData1);
- // UI展示-展示到设备状态页
- if (string.IsNullOrEmpty(lineWorkingData1_OldStr)) // 软件启动后第一次运行
- {
- // 查询数据库最新一条数据,确定是不是更新
- string qSql = @"SELECT top(1) [GUID]
- ,[LineName]
- ,[BootTimeLong]
- ,[NormalTimeLong]
- ,[StandbyTimeLong]
- ,[FaultTimeLong]
- ,[MaterialShortageTimeLong]
- ,[MaintenanceTimeLong]
- ,[FaultNumber]
- ,[OutputNumber]
- ,[QualifiedNumber]
- ,[QualifiedRate]
- ,[DesignRhythm]
- ,[RealityRhythm]
- ,[CreateTime]
- FROM [LineWorkingData]
- where [CreateTime] > '{0}'
- and [LineName]='{1}'
- order by [CreateTime] desc
- ";
- qSql = string.Format(qSql, DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00", lineWorkingData1.LineName);
- var ds = SQLHelper_New.Query(qSql, null);
- if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
- {
- var dataDBlast = new LineWorkingData_ThisTime();
- dataDBlast.GUID = ds.Tables[0].Rows[0][0].ToString(); // 主键
- dataDBlast.LineName = ds.Tables[0].Rows[0][1].ToString(); // 线体名称
- dataDBlast.BootTimeLong = Convert.ToSingle(ds.Tables[0].Rows[0][2].ToString()); // 本次开机时间(整线)
- dataDBlast.CreateTime = Convert.ToDateTime(ds.Tables[0].Rows[0][14].ToString()); // 创建时间
- if (lineWorkingData1.BootTimeLong > dataDBlast.BootTimeLong) // 需要更新的情况;不需要更新的走后面的插入
- {
- dataDBlast.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
- dataDBlast.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
- dataDBlast.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
- dataDBlast.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
- dataDBlast.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
- dataDBlast.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
- dataDBlast.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
- dataDBlast.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
- dataDBlast.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
- dataDBlast.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
- dataDBlast.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
- dataDBlast.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
- string usql = dataDBlast.ToStringUpdate();
- SQLHelper_New.ExecuteSQL(usql, null);
- lineWorkingData1_OldStr = JsonConvert.SerializeObject(dataDBlast);
- AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
- //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
- }
- }
- else
- {
- // 插入
- SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
- lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
- AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
- //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
- }
- }
- else if (!lineWorkingData1_Str.Equals(lineWorkingData1_OldStr)) // 非“软件启动后第一次运行”
- {
- LineWorkingData_ThisTime lineWorkingData1_Old = string.IsNullOrEmpty(lineWorkingData1_OldStr) ? lineWorkingData1 : JsonConvert.DeserializeObject<LineWorkingData_ThisTime>(lineWorkingData1_OldStr); // 上次的状态信息
- //// 本次开机设备运行情况
- //LineWorkingData1_ThisTime lineWorkingData_UI = JsonConvert.DeserializeObject<LineWorkingData1_ThisTime>(lineWorkingData1_OldStr);
- //Task.Run(() =>
- //{
- // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
- // {
- // Form_Main.formDevAlarm.UpdDeviceStatus_ThisTime(lineWorkingData_UI); // UI更新
- // }
- //});
- // 本日设备运行情况
- // 存数据库(开机时间>上次的开机时间,则更新上次记录;<则作为新数据插入)
- if (lineWorkingData1.BootTimeLong > lineWorkingData1_Old.BootTimeLong)
- {
- // 更新
- lineWorkingData1_Old.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
- lineWorkingData1_Old.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
- lineWorkingData1_Old.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
- lineWorkingData1_Old.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
- lineWorkingData1_Old.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
- lineWorkingData1_Old.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
- lineWorkingData1_Old.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
- lineWorkingData1_Old.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
- lineWorkingData1_Old.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
- lineWorkingData1_Old.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
- lineWorkingData1_Old.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
- lineWorkingData1_Old.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
- SQLHelper_New.ExecuteSQL(lineWorkingData1_Old.ToStringUpdate(), null);
- lineWorkingData1_OldStr = JsonConvert.SerializeObject(lineWorkingData1_Old);
- AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
- //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
- }
- else if (lineWorkingData1.BootTimeLong < lineWorkingData1_Old.BootTimeLong)
- {
- // 插入
- SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
- lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
- AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
- //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
- }
- await Task.Run(() =>
- {
- try
- {
- if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
- {
- Form_Main.formDevAlarm.UpdDeviceStatus_Today(); // UI更新
- }
- }
- catch { }
- });
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取设备运行信息出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 获取设备运行信息
- #region 报警数据
- try
- {
- List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
- bool isNeedUpdUI = false; // 是否需要更新历史报警UI
- // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
- var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.LineCode];
- for (int i = 0; i < dicAlarms_Cur_PLC1.Count; i++) // 读取
- {
- short shortBuf = 0;// plc1Alarm.ReadHoldingRegisters<short>(dicAlarms_Cur_PLC1[i].关联的PLC地址);
- dicAlarms_Cur_PLC1[i].是否报警 = shortBuf != 0;
- if (dicAlarms_Cur_PLC1[i].上次的运行状态 != dicAlarms_Cur_PLC1[i].是否报警)
- {
- isNeedUpdUI = true; // 需要更新历史报警UI信息
- // 记录
- dicAlarms_Cur_PLC1[i].上次的运行状态 = dicAlarms_Cur_PLC1[i].是否报警;
- switch (dicAlarms_Cur_PLC1[i].是否报警)
- {
- case true: // 报警
- dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
- {
- GUID = Guid.NewGuid().ToString(),
- LineName = GlobalContext.LineCode, // 线体
- AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
- AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
- StartTime = dtNow // 开始时间
- };
- // 传输到页面
- deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
- {
- 线体名称 = dicAlarms_Cur_PLC1[i].报警数据.LineName,
- 报警类型 = dicAlarms_Cur_PLC1[i].报警数据.AlarmType,
- 报警内容 = dicAlarms_Cur_PLC1[i].报警数据.AlarmDesc,
- 开始时间 = dtNow
- });
- // 新增到数据库
- var data1 = dicAlarms_Cur_PLC1[i].报警数据;
- SaveAlarmDataByDB(stationNameStr, data1, false);
- AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
- break;
- case false: // 消除报警
- if (dicAlarms_Cur_PLC1[i].报警数据 == null || string.IsNullOrEmpty(dicAlarms_Cur_PLC1[i].报警数据.GUID))
- {
- dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
- {
- GUID = Guid.NewGuid().ToString(),
- LineName = GlobalContext.LineCode, // 线体
- AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
- AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
- StartTime = dtNow, // 开始时间
- EndTime = dtNow, // 开始时间
- PersistTime = 1, // 耗时1s
- };
- // 新增
- var data2 = dicAlarms_Cur_PLC1[i].报警数据;
- SaveAlarmDataByDB(stationNameStr, data2, false);
- AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
- }
- else
- {
- dicAlarms_Cur_PLC1[i].报警数据.EndTime = dtNow; // 开始时间
- dicAlarms_Cur_PLC1[i].报警数据.PersistTime = Convert.ToInt32((dicAlarms_Cur_PLC1[i].报警数据.EndTime
- - dicAlarms_Cur_PLC1[i].报警数据.StartTime).TotalSeconds); // 耗时s
- // 修改
- var data3 = dicAlarms_Cur_PLC1[i].报警数据;
- SaveAlarmDataByDB(stationNameStr, data3, true);
- AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
- }
- break;
- default:
- break;
- }
- }
- }
- DicAlarms_Cur[GlobalContext.LineCode] = dicAlarms_Cur_PLC1;
- // 有新报警则更新
- if (isNeedUpdUI)
- {
- // UI展示 - 展示到设备状态页
- await Task.Run(() =>
- {
- try
- {
- if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
- {
- Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
- if (Form_Main.formDevAlarm.Visible)
- {
- Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
- }
- }
- }
- catch { }
- });
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 报警数据
- UpdatePLCMonitor(1, -2, 1);
- }
- else
- {
- UpdatePLCMonitor(1, -2, 0);
- }
- }
- catch (Exception ex)
- {
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- }
- Thread.Sleep(IntervalAlarm);
- }
- }
- #endregion 轮询PLC
- #region 下发订单信息
- ///// <summary>
- ///// 壳体上料(下发工单)的交互逻辑
- ///// </summary>
- ///// <param name="no"></param>
- ///// <exception cref="NotImplementedException"></exception>
- //private void ReadStation_DownOrderInfo(int plcNo)
- //{
- // // [S1] Tray盘上料装备(板测)
- // // [S2] FCT(板测)
- // // [S3] 值板机
- // // [S4] 取放桁架
- // // [S5] Tray盘下料装备
- // /// 上位机心跳
- // /// 获取设备报警数据与状态信息
- // string stationNameStr = "[S0]壳体上料";
- // while (true)
- // {
- // try
- // {
- // if (!GlobalContext._IsCon_Funs1)
- // {
- // UpdatePLCMonitor(plcNo, 0);
- // continue;
- // }
- // if (Funs[plcNo].isConnected) // 检查PLC是否已连接上
- // {
- // #region 壳体上料(下发工单)
- // try
- // {
- // Funs[plcNo].Read_Int_Tag("500", 1, out short[] iiMes0);
- // Funs[plcNo].Read_Int_Tag("501", 1, out short[] iiPlc0);
- // bool mES_FLAG_1 = iiMes0[0] == 1 ? true : false; // MES_FLAG_1
- // bool pLC_Flag_1 = iiPlc0[0] == 1 ? true : false; // PLC_FLAG_1
- // // 重置数据和信号
- // if (mES_FLAG_1 && pLC_Flag_1) // 1 1
- // {
- // // 清空写给PLC的数据
- // int[] i497 = new int[1] { 0 };
- // Funs[plcNo].Write_DInt_Tag("497", 1, i497); // SN号(数字部分)重置信号
- // // MES_Flag重置为0
- // int[] i500 = new int[1] { 0 };
- // Funs[plcNo].Write_DInt_Tag("500", 1, i500); // MES_FLAG_1
- // }
- // }
- // catch (Exception ex)
- // {
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}下发订单信息运行出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion 壳体上料(下发工单)
- // UpdatePLCMonitor(plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- // }
- // else
- // {
- // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
- // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- //
- // Funs[plcNo].Connect();
- // }
- // }
- // catch (Exception ex)
- // {
- // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- //
- // Funs[plcNo].ReConnect();
- // }
- // Thread.Sleep(IntervalReadPLC);
- // }
- //}
- ///// <summary>
- ///// 下发订单信息到PLC
- ///// </summary>
- ///// <param name="no">PLC编号</param>
- //private void DownLoadProductInfo(int plcNo, string stationNameStr = "[S0]壳体上料")
- //{
- // try
- // {
- // if (!string.IsNullOrEmpty(GlobalContext.Mtltmrk))
- // {
- // Funs[plcNo].Write_String_Tag("568", 1, GlobalContext.Mtltmrk); // 产品型号(mtltmrk)
- // WritePLCLog(LogType.Debug, GlobalContext.Mtltmrk);
- // }
- // Funs[plcNo].Write_DInt_Tag("500", 1, new Int32[1] { 1 }); // MES_FLAG_1
- // }
- // catch (Exception ex)
- // {
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, "下发订单信息到PLC失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- //}
- /// <summary>
- /// 下发清料信号
- /// </summary>
- /// <param name="no">PLC编号</param>
- public bool ClearProducts(int plcNo, string stationNameStr = "[S0]壳体上料")
- {
- try
- {
- //Funs[plcNo].ReadHoldingRegisters<int>(496); //
- AddMessage_Station(stationNameStr, LogType.Info, "下发了清料信号!");
- return true;
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, "下发清料信号失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- return false;
- }
- }
- #endregion 下发订单信息
- #region PLC1 贲流
- #region [S1] 壳体清洁上料装备
- /// <summary>
- /// S1工位的数据- 触发信号上次的值
- /// </summary>
- private Dictionary<string, object> s1PLCSignal_Old = new Dictionary<string, object>();
- /// <summary>
- /// S1工位的数据(含触发信号)
- /// </summary>
- private Dictionary<string, object> s1PLCData = new Dictionary<string, object>();
- /// <summary>
- /// S1工位的数据- 回写点位
- /// </summary>
- private Dictionary<string, WriteToPLC_Flag> s1PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
- ///// <summary>
- ///// 触发信号
- ///// </summary>
- //private ManualResetEvent[] MreTasks;
- /// <summary>
- /// [S1] 壳体清洁上料装备
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- private void ReadStation_S1(int plcNo)
- {
- string stationCode = "[S1]";
- string stationName = "壳体清洁上料";
- string stationNameStr = stationCode + stationName;
- string tagBaseName = "g_OP10_MES"; //标签变量名称
- string tagMesCommName = "mesCommToPC"; //标签变量名称
- string tagAgvCommName = "agvCommFrmPC";
- string tagBarsetName = "BarcodeSet";
-
- OP10_MesData_t stPLC_MesData; //PLC的MES数据
- (int, string) result;
- bool ProgressState = true;
- #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
- // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
- s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
- s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
- s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
- s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
- s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
- s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
- s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
- s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
- // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
- s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
- s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
- s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
- s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
- s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
- s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
- s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
- s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
- s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
- s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
- s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
- s1PLCData.Add("a1Result", 0); // 产品结果
- s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
- s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
- s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
- s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
- s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
- s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
- s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
- s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
- s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
- s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
- s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
- s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
- s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
- s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
- s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
- s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
- #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
- while (true)
- {
- try
- {
- if (!GlobalContext._IsCon_Funs1)
- {
- UpdatePLCMonitor(1, plcNo, 0);
- continue;
- }
- if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- stopwatch1.Start();
- stopwatch2.Start();
- #region 一次性读取所有数据
- // 一次性读取所有数据
- result = Funs[plcNo].Read_SingleTag<OP10_MesData_t>(tagBaseName, 1, out stPLC_MesData); //读取单个结构体数据
- if (result.Item1 != 0)
- {
- //richTextBox1.AppendText("\n" + strRet);
- }
- else
- {
- //richTextBox1.AppendText("\n" + "读取成功");
- }
- #endregion 一次性读取所有数据
- stopwatch2.Stop();
- #region 进站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation && ProgressState == true)
- {
- ProgressState = false;
- Task.Run(() => S1进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName,out ProgressState));
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 进站
- #region 出站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation && ProgressState == true)
- {
- ProgressState = false;
- Task.Run(() => S1出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName,out ProgressState));
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 进站
-
- UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- stopwatch1.Stop();
- OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- }
- else
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- Funs[plcNo].Connect(); // 重连
- }
- }
- catch (Exception ex)
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- }
- Thread.Sleep(IntervalReadPLC);
- }
- }
- /// <summary>
- /// [S1] 壳体清洁上料 - 进站
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- /// <param name="stPLC_MesData"></param>
- /// <param name="tagMesCommName"></param>
- private void S1进站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName,out bool ProgressState)
- {
- int nRet=0;
- string strRet = "";
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- ProgressState = true;
- try
- {
- stopwatch1.Start();
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
- string MachineId = GlobalContext.S1_MachineId; // 装备ID(可配置)
- string StationId = GlobalContext.S1_StationId; // 工位ID(可配置)
- // 产品SN(物料码)校验
- List<TestItem> item = new List<TestItem>();
- stopwatch2.Start();
- int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
- stopwatch2.Stop();
- //指令执行结果 1:OK 110:失败
- byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo,stationNameStr, tagMesCommName,1, resultToPlC);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// 进出站结果写入PLC
- /// </summary>
- public void WriteResultToPlc(int plcNo,string stationNameStr,string strTagName, int nCount, CommandFromPLC resultToPlC)
- {
- int i = 0;
- int nRet = 0;
- string strRet = "";
- while (i < 3) // 最多上传三次
- {
- (nRet, strRet) = Funs[plcNo].Write_SingleTag<CommandFromPLC>(strTagName, nCount, resultToPlC);
- if (nRet == 0) //成功
- {
- break;
- }
- else
- {
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站结果写入PLC出错!错误信息:" + strRet);
- i++;
- }
- }
- }
- /// <summary>
- /// [S1] 壳体清洁上料 - 出站接口
- /// </summary>
- private void S1出站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName,string stationCode,string stationName, out bool ProgressState)
- {
- ProgressState = true;
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string processItem = stationName; // 测试项目
- string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string supplierCode = ""; // 供应商代码
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- string sn=(string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
- string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
- string MachineId = GlobalContext.S1_MachineId; // 装备id(可配置) // ZS
- string StationId = GlobalContext.S1_StationId; // ⼯位ID(可配置) // ZS
- int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
- bool pass = a1Result == 1;
- List<TestItem> items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = CarrierBarcode,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "产品码",
- Parameter_value = mtltmrk,
- Parameter_unit = ""
- });
- //绑定载具和产品
- ResponseMessage message = new ResponseMessage();
- message= SQLHelper.InsertCarrierBind(CarrierBarcode, CarrierBarcode, stationNameStr);
- if (message.result==false)
- {
- AddMessage(LogType.Info, stationNameStr + "_载具码与产品码绑定失败");
- }
- //绑定PLC返回MES数据到本地
- int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
- , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId);
- byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
- stopwatch2.Start();
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-Write" + (result1 == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Start();
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{stationNameStr}]上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- //// 上传点检数据_ [S1] Tray盘上料装备(板测)
- //private void DoOneCheckData_Tray盘上料装备(int plcNo, string stationCode, string stationName)
- //{
- // string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- // string stationNameStr = stationCode + stationName;
- // string processItem = stationName; // 测试项目
- // try
- // {
- // string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- // string accno = "1"; // 工序编号
- // Funs[plcNo].Read_Real_Tag("896", 1, out float[] float0);
- // float travelLimitUp = float0[0]; // 胶圈装配行程设定上限
- // List<OneCheckItem> items = new List<OneCheckItem>()
- // {
- // new OneCheckItem()
- // {
- // Onecheck_name="胶圈装配行程设定上限",
- // Onecheck_content="上限值",
- // Onecheck_result=$"正常|胶圈装配行程设定上限{travelLimitUp} mm"
- // },
- // };
- // OneCheckData oneCheckData = new OneCheckData()
- // {
- // Line_code = GlobalContext.LineCode,
- // Line_name = GlobalContext.LineName,
- // Equipment_code = equipmentCode,
- // Equipment_name = equipmentCode,
- // Workorder_code = workorder_code,
- // Procedure_code = accno,
- // Procedure_name = processItem,
- // Oneckeck_values = items,
- // Onecheck_empcode = "",
- // Onecheck_empname = "",
- // Onecheck_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
- // };
- // int result1 = SaveOneCheckDataByDBAndSubmit(oneCheckData, equipmentCode, processItem);
- // //int result = result1 == 1 ? 1 : (GlobalContext.IsSendCheckOneData ? 4 : 1);
- // short result = result1 == 1 ? (short)1 : (short)2;
- // // MES_Flag 为4MES报错
- // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { result });
- // WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
- // }
- // catch (Exception ex)
- // {
- // // MES_Flag 为2上位机报错
- // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}点检报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- //}
- // ReadStation_S1_2 节拍接口+AGV
- /// <summary>
- /// [S1] Tray盘上料装备(板测)- 将SN发给ICT标机(串口)
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S1将SN发给ICT标机(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- string a1ProductSN_ICT = (string)s1PLCData["a1ProductSN_ICT"]; // 产品SN(载具SN)
- a1ProductSN_ICT = a1ProductSN_ICT.Replace("\0", "");
- string a1PartNo1_ICT = (string)s1PLCData["a1PartNo1_ICT"]; // 物料码1(穴位1)
- a1PartNo1_ICT = a1PartNo1_ICT.Replace("\0", "");
- string a1PartNo2_ICT = (string)s1PLCData["a1PartNo2_ICT"]; // 物料码2(穴位2)
- a1PartNo2_ICT = a1PartNo2_ICT.Replace("\0", "");
- // ZS 将SN发给ICT标机(串口)
- short a1MES_FLAG_ICT = 1;
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2182, a1MES_FLAG_ICT); // 上位机发送1代表OK;2代表失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
- writeToPLC_Flag.Adress = 2182;
- writeToPLC_Flag.Value = a1MES_FLAG_ICT;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
- writeToPLC_Flag.Adress = 2182;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_将SN发给ICT标机;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S1] Tray盘上料装备(板测)- 节拍接口
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S1节拍接口(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string resultStr = string.Empty;
- try
- {
- stopwatch1.Start();
- string oEEType = ((int)s1PLCData["a1OEEType"]).ToString(); // 节拍类型(plc写入)
- string a1OEEPartNo = (string)s1PLCData["a1OEEPartNo"]; // 物料码
- a1OEEPartNo = a1OEEPartNo.Replace("\0", "");
- string a1OEEVehicleCode = (string)s1PLCData["a1OEEVehicleCode"]; // 载具SN
- a1OEEVehicleCode = a1OEEVehicleCode.Replace("\0", "");
- string a1OEEPartNum = ((int)s1PLCData["a1OEEPartNum"]).ToString(); // 穴位号
- a1OEEPartNum = a1OEEPartNum.Replace("\0", "");
- bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
- if (!actionBool)
- {
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "a1OEEMES_FLAG";
- writeToPLC_Flag1.Adress = 2254;
- writeToPLC_Flag1.Value = (short)1;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag1);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- if (string.IsNullOrEmpty(a1OEEPartNo) && string.IsNullOrEmpty(a1OEEVehicleCode))
- {
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag2 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag2.Name = "a1OEEMES_FLAG";
- writeToPLC_Flag2.Adress = 2254;
- writeToPLC_Flag2.Value = (short)1;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag2);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- else if (string.IsNullOrEmpty(a1OEEPartNo) && !string.IsNullOrEmpty(a1OEEVehicleCode))
- { // 查产品SN
- a1OEEPartNo = "Test"; // ZS
- }
- short a1OEEMES_FLAG = 0;
- // 上传OEE
- (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a1OEEPartNo, a1OEEVehicleCode);
- a1OEEMES_FLAG = result.Item1;
- resultStr = result.Item2;
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2254, a1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1OEEMES_FLAG";
- writeToPLC_Flag.Adress = 2254;
- writeToPLC_Flag.Value = a1OEEMES_FLAG;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1OEEMES_FLAG";
- writeToPLC_Flag.Adress = 2254;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S1] Tray盘上料装备(板测)- AGV上料叫agv
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S1AGV上料叫agv(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS 呼叫AGV
- short a1AGVUpCall = 2;
- stopwatch2.Start();
- // a1AGVUpCall
- //Funs[plcNo].WriteMultipleRegisters<short>(2307, a1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1AGVUpCall";
- writeToPLC_Flag.Adress = 2307;
- writeToPLC_Flag.Value = a1AGVUpCall;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // a1AGVUpCall
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1AGVUpCall";
- writeToPLC_Flag.Adress = 2307;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S1] Tray盘上料装备(板测)- AGV上料完成
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S1AGV上料完成(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS AGV上料完成,让小车离开
- short a1AGVUpEnd = 2;
- stopwatch2.Start();
- // a1AGVUpEnd
- //Funs[plcNo].WriteMultipleRegisters<short>(2309, a1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1AGVUpEnd";
- writeToPLC_Flag.Adress = 2309;
- writeToPLC_Flag.Value = a1AGVUpEnd;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // a1AGVUpEnd
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1AGVUpEnd";
- writeToPLC_Flag.Adress = 2309;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S1] Tray盘上料装备(板测)- AGV下料叫agv
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S1AGV下料叫agv(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS 呼叫AGV
- short a1AGVDownCall = 2;
- stopwatch2.Start();
- // a1AGVDownCall
- //Funs[plcNo].WriteMultipleRegisters<short>(2320, a1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1AGVDownCall";
- writeToPLC_Flag.Adress = 2320;
- writeToPLC_Flag.Value = a1AGVDownCall;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // a1AGVDownCall
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1AGVDownCall";
- writeToPLC_Flag.Adress = 2320;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S1] Tray盘上料装备(板测)- AGV下料完成
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S1AGV下料完成(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS AGV上料完成,让小车离开
- short a1AGVDownEnd = 2;
- stopwatch2.Start();
- // a1AGVDownEnd
- //Funs[plcNo].WriteMultipleRegisters<short>(2322, a1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1AGVDownEnd";
- writeToPLC_Flag.Adress = 2322;
- writeToPLC_Flag.Value = a1AGVDownEnd;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // a1AGVDownEnd
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1AGVDownEnd";
- writeToPLC_Flag.Adress = 2322;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- #endregion [S1] Tray盘上料装备(板测)
- #endregion PLC1 张超凡
- #region PLC2 贲流
- #region [S2] 上盖板上料装备
- /// <summary>
- /// S2工位的数据- 触发信号上次的值
- /// </summary>
- private Dictionary<string, object> s2PLCSignal_Old = new Dictionary<string, object>();
- /// <summary>
- /// S2工位的数据(含触发信号)
- /// </summary>
- private Dictionary<string, object> s2PLCData = new Dictionary<string, object>();
- /// <summary>
- /// S2工位的数据- 回写点位
- /// </summary>
- private Dictionary<string, WriteToPLC_Flag> s2PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
- /// <summary>
- /// [S2] FCT(板测)
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- private void ReadStation_S2(int plcNo)
- {
- string stationCode = "[S2]";
- string stationName = "上盖板上料装备";
- string stationNameStr = stationCode + stationName;
- string tagBaseName = "g_OP20_MES"; //标签变量名称
- string tagMesCommName = "mesCommToPC"; //标签变量名称
- string tagAgvCommName = "agvCommFrmPC";
- string tagBarsetName = "BarcodeSet";
- OP20_MesData_t stPLC_MesData; //PLC的MES数据
- (int, string) result;
- bool ProgressState = true;
- while (true)
- {
- try
- {
- if (!GlobalContext._IsCon_Funs2)
- {
- UpdatePLCMonitor(1, plcNo, 0);
- continue;
- }
- if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- stopwatch1.Start();
- stopwatch2.Start();
- #region 一次性读取所有数据
- // 一次性读取所有数据
- result = Funs[plcNo].Read_SingleTag<OP20_MesData_t>(tagBaseName, 1, out stPLC_MesData); //读取单个结构体数据
- if (result.Item1 != 0)
- {
- //richTextBox1.AppendText("\n" + strRet);
- }
- else
- {
- //richTextBox1.AppendText("\n" + "读取成功");
- }
- #endregion 一次性读取所有数据
- stopwatch2.Stop();
- #region 进站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation && ProgressState == true)
- {
- ProgressState = false;
- Task.Run(() => S2进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 进站
- #region 出站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation && ProgressState == true)
- {
- ProgressState = false;
- Task.Run(() => S2出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 进站
- UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- stopwatch1.Stop();
- //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
- OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- }
- else
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- Funs[plcNo].Connect();
- }
- }
- catch (Exception ex)
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- //Funs[plcNo].ReConnect();
- }
- Thread.Sleep(IntervalReadPLC);
- }
- }
- /// <summary>
- /// [S2] 上盖板上料装备
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S2进站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName,string tagBarsetName, out bool ProgressState)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- ProgressState = true;
- try
- {
- stopwatch1.Start();
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
- string MachineId = GlobalContext.S1_MachineId; // 装备ID(可配置)
- string StationId = GlobalContext.S1_StationId; // 工位ID(可配置)
- string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
- strCarrierBarcode = strCarrierBarcode.Replace("\0", "");
- //载具码验证产品码 错误码111
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
- if (string.IsNullOrEmpty(strProductBarcode))
- {
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC S2 上盖板上料装备未能成功绑定载具信息");
- }
- if (!string.IsNullOrEmpty(strProductBarcode) && !string.IsNullOrEmpty(sn) && strProductBarcode!=sn)
- {
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC S2 上盖板上料装备PLC返回产品码与载具绑定物料码不同");
- }
- // 产品SN(物料码)校验
- List <TestItem> item = new List<TestItem>();
- stopwatch2.Start();
- int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
- stopwatch2.Stop();
- //指令执行结果 1:OK 110:失败
- byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
- if (!string.IsNullOrEmpty(strProductBarcode) && !string.IsNullOrEmpty(sn) && strProductBarcode != sn)
- {
- mesResultFrmWeb = 111;
- }
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- if (string.IsNullOrEmpty(sn) && !string.IsNullOrEmpty(strProductBarcode))
- {
- BarcodeSet_t BarcodeToPlc= new BarcodeSet_t();
- BarcodeToPlc.strCarrierBarcode = strCarrierBarcode;
- BarcodeToPlc.strProductBarcode = sn;
- Funs[plcNo].Write_SingleTag<BarcodeSet_t>(tagBarsetName, 1, BarcodeToPlc);
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S2] 上盖板上料装备 - 出站接口
- /// </summary>
- private void S2出站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName,string stationCode,string stationName, out bool ProgressState)
- {
- ProgressState = true;
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string processItem = stationName; // 测试项目
- string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string supplierCode = ""; // 供应商代码
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
- string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
- string MachineId = GlobalContext.S1_MachineId; // 装备id(可配置) // ZS
- string StationId = GlobalContext.S1_StationId; // ⼯位ID(可配置) // ZS
- int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
- bool pass = a1Result == 1;
- List<TestItem> items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = CarrierBarcode,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "产品码",
- Parameter_value = mtltmrk,
- Parameter_unit = ""
- });
- //保存PLC返回MES数据到本地
- int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
- , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId);
- byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
- stopwatch2.Start();
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-Write" + (result1 == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Start();
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{stationNameStr}]上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S2] FCT(板测)- 节拍接口
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S2节拍接口(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string resultStr = string.Empty;
- try
- {
- stopwatch1.Start();
- string oEEType = ((int)s2PLCData["b1OEEType"]).ToString(); // 节拍类型(plc写入)
- string b1OEEProductSN = (string)s2PLCData["b1OEEProductSN"]; // 载具SN
- bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
- if (!actionBool)
- {
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
- writeToPLC_Flag1.Adress = 2203;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- string b1OEEPartNo = string.Empty; // 物料码
- if (string.IsNullOrEmpty(b1OEEProductSN))
- {
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
- writeToPLC_Flag1.Adress = 2203;
- writeToPLC_Flag1.Value = (short)1;
- SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- else
- { // 查产品SN
- b1OEEPartNo = "Test"; // ZS
- }
- short b1OEEMES_FLAG = 0;
- // 上传OEE
- (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, b1OEEPartNo, b1OEEProductSN);
- b1OEEMES_FLAG = result.Item1;
- resultStr = result.Item2;
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2203, b1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "b1OEEMES_FLAG";
- writeToPLC_Flag.Adress = 2203;
- writeToPLC_Flag.Value = b1OEEMES_FLAG;
- SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "b1OEEMES_FLAG";
- writeToPLC_Flag.Adress = 2203;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- #endregion [S2] FCT(板测)
- #endregion PLC2 李晓奇
- #region PLC3 刘永村
- #region [S3] 值板机
- /// <summary>
- /// S3工位的数据- 触发信号上次的值
- /// </summary>
- private Dictionary<string, object> s3PLCSignal_Old = new Dictionary<string, object>();
- /// <summary>
- /// S3工位的数据(含触发信号)
- /// </summary>
- private Dictionary<string, object> s3PLCData = new Dictionary<string, object>();
- /// <summary>
- /// S3工位的数据- 回写点位
- /// </summary>
- private Dictionary<string, WriteToPLC_Flag> s3PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
- /// <summary>
- /// [S3] 值板机
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- private void ReadStation_S3(int plcNo)
- {
- string stationCode = "[S3]";
- string stationName = "点散热胶装备";
- string stationNameStr = stationCode + stationName;
- string tagBaseName = "g_OP30_MES"; //标签变量名称
- string tagMesCommName = "mesCommToPC"; //标签变量名称
- string tagAgvCommName = "agvCommFrmPC";
- string tagBarsetName = "BarcodeSet";
- OP30_MesData_t stPLC_MesData; //PLC的MES数据
- (int, string) result;
- #region 创建字典
- // 触发信号字典 赋值
- s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
- s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
- s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
- s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
- s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- // PLC数据字典 赋值
- s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
- s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
- s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
- s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
- s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
- //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
- s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
- s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
- s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
- //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
- s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
- s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
- s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
- s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
- s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
- s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
- //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
- s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
- s3PLCData.Add("c1Result", 0); // 产品结果
- s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
- s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
- s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
- #endregion 创建字典
- while (true)
- {
- try
- {
- if (!GlobalContext._IsCon_Funs2)
- {
- UpdatePLCMonitor(1, plcNo, 0);
- continue;
- }
- if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- stopwatch1.Start();
- stopwatch2.Start();
- #region 一次性读取所有数据
- // 一次性读取所有数据
- result = Funs[plcNo].Read_SingleTag<OP30_MesData_t>(tagBaseName, 1, out stPLC_MesData); //读取单个结构体数据
- if (result.Item1 != 0)
- {
- //richTextBox1.AppendText("\n" + strRet);
- }
- else
- {
- //richTextBox1.AppendText("\n" + "读取成功");
- }
- #endregion 一次性读取所有数据
- stopwatch2.Stop();
- #region 左边进站
- try
- {
- //if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation && !string.IsNullOrEmpty(stPLC_MesData.iotData.Left.work_type.ToString()))
- //{
- // Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName));
- // //进站
- //}
- }
- catch (Exception ex)
- {
- //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 进站
- #region 左边出站
- try
- {
- //if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
- //{
- // Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, "Left"));
- //}
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 出站
- UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- stopwatch1.Stop();
- //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
- OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- }
- else
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- Funs[plcNo].Connect();
- }
- }
- catch (Exception ex)
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- //Funs[plcNo].ReConnect();
- }
- Thread.Sleep(IntervalReadPLC);
- }
- }
- /// <summary>
- /// [S3] 点散热胶装备
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S3进站(int plcNo, string stationNameStr, OP30_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- string sn = "";//(string)stPLC_MesDataBarcodeSet.strProductBarcode; // 产品SN(物料码)
- sn = sn.Replace("\0", "");
- string strCarrierBarcode = "";//(string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
- strCarrierBarcode = strCarrierBarcode.Replace("\0", "");
- //载具码验证产品码
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
- if (string.IsNullOrEmpty(strProductBarcode))
- {
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC S3 点散热胶装备未能成功绑定载具信息");
- }
- if (!string.IsNullOrEmpty(strProductBarcode) && !string.IsNullOrEmpty(sn) && strProductBarcode != sn)
- {
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC S3 点散热胶装备未能成功绑定载具信息");
- }
- // 产品SN(物料码)校验
- List<TestItem> item = new List<TestItem>();
- stopwatch2.Start();
- int result = 0;
- //int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item);
- stopwatch2.Stop();
- //指令执行结果 1:OK 110:失败
- byte cmdToPC = (byte)(result == 1 ? 1 : 110);
- //进站结果写入PLC
-
- if (string.IsNullOrEmpty(sn))
- {
- BarcodeSet_t BarcodeToPlc = new BarcodeSet_t();
- BarcodeToPlc.strCarrierBarcode = strCarrierBarcode;
- BarcodeToPlc.strProductBarcode = sn;
- Funs[plcNo].Write_SingleTag<BarcodeSet_t>(tagBarsetName, 1, BarcodeToPlc);
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
-
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S3] 点散热胶装备 - 出站接口
- /// </summary>
- private void S3出站(int plcNo, string stationNameStr, OP30_MesData_t stPLC_MesData, string tagMesCommName,string direction)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品条码; // 产品型号
- mtltmrk = mtltmrk.Replace("\0", "");
- string CarrierBarcode = "";//(string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
-
- // 产品结果
- int a1Result = 0;
- //if (direction=="Left")
- //{
- // a1Result=(int)stPLC_MesData.iotData.Left.testStatus;
- //}
- //if (direction == "Right")
- //{
- // a1Result = (int)stPLC_MesData.iotData.Left.testStatus;
- //}
- bool pass = a1Result == 1;
- List<TestItem> items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = CarrierBarcode,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "产品码",
- Parameter_value = mtltmrk,
- Parameter_unit = ""
- });
- //保存PLC返回MES数据到本地
- int result1 = 0;
- //int result1 = SwitctProcessData(stationNameStr, items, "", ""
- // , workorder_code, batch_num, mtltmrk, "", "", "", pass, CarrierBarcode, "1");
- byte cmdToPC = (byte)(result1 == 1 ? 1 : 110);
- stopwatch2.Start();
- //进站结果写入PLC
-
- stopwatch2.Stop();
- WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-Write" + (result1 == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Start();
-
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{stationNameStr}]上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- //// 上次采集到的SN
- //private string sn_值板机 = string.Empty;
- /// <summary>
- /// [S3] 值板机 - 出站接口
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- private void S3出站接口(int plcNo, string stationCode, string stationName)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string stationNameStr = stationCode + stationName;
- string processItem = stationName; // 测试项目
- try
- {
- stopwatch1.Start();
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string supplierCode = ""; // 供应商代码
- string sn = (string)s3PLCData["c1ProductSN"]; // 产品SN(一穴载具SN)
- sn = sn.Replace("\0", "");
- string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 二穴载具SN(产品取自哪个二穴载具)
- c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
- int c1VehicleCavity = (int)s3PLCData["c1VehicleCavity"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
- int c1Result = (int)s3PLCData["c1Result"]; // 产品结果
- bool pass = c1Result == 1;
- //
- string productSN = string.Empty;
- // 是否是两个穴位交换
- List<TestItem> items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "产品结果",
- Parameter_value = c1Result == 1 ? "OK" : "NG",
- Parameter_unit = ""
- });
- int result1 = 0;
- //int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
- // , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, productSN, pass, sn, "1");
- short result = result1 == 1 ? (short)1 : (short)2;
- stopwatch2.Start();
- // MES_Flag 为MES报错
- // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- //Funs[plcNo].WriteMultipleRegisters<short>(2150, result); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "c1MES_FLAG";
- writeToPLC_Flag.Adress = 2150;
- writeToPLC_Flag.Value = result;
- SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Start();
- // MES_Flag 为4上位机报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "c1MES_FLAG";
- writeToPLC_Flag.Adress = 2150;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S3] 值板机- 节拍接口
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S3节拍接口(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string resultStr = string.Empty;
- try
- {
- stopwatch1.Start();
- string oEEType = ((int)s3PLCData["c1OEEType"]).ToString(); // 节拍类型(plc写入)
- string c1OEEProductSN = (string)s3PLCData["c1OEEProductSN"]; // 载具SN
- c1OEEProductSN = c1OEEProductSN.Replace("\0", "");
- bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
- if (!actionBool)
- {
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
- writeToPLC_Flag1.Adress = 2204;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- string c1OEEPartNo = string.Empty; // 物料码
- if (string.IsNullOrEmpty(c1OEEProductSN))
- {
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
- writeToPLC_Flag1.Adress = 2204;
- writeToPLC_Flag1.Value = (short)1;
- SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- else
- { // 查产品SN
- c1OEEPartNo = "Test"; // ZS
- }
- short c1OEEMES_FLAG = 0;
- // 上传OEE
- (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, c1OEEPartNo, c1OEEProductSN);
- c1OEEMES_FLAG = result.Item1;
- resultStr = result.Item2;
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2204, c1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "c1OEEMES_FLAG";
- writeToPLC_Flag.Adress = 2204;
- writeToPLC_Flag.Value = c1OEEMES_FLAG;
- SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "c1OEEMES_FLAG";
- writeToPLC_Flag.Adress = 2204;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- #endregion [S3] 值板机
- #endregion PLC3 刘永村
- /// <summary>
- /// [S4] 点胶检测设备
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- private void ReadStation_S4(int plcNo)
- {
- string stationCode = "[S4]";
- string stationName = "点胶检测设备";
- string stationNameStr = stationCode + stationName;
- string tagBaseName = "g_OP40_MES"; //标签变量名称
- string tagMesCommName = "mesCommToPC"; //标签变量名称
- string tagAgvCommName = "agvCommFrmPC";
- string tagBarsetName = "BarcodeSet";
- OP40_MesData_t stPLC_MesData; //PLC的MES数据
- (int, string) result;
- bool ProgressState = true;
- #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
- // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
- s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
- s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
- s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
- s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
- s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
- s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
- s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
- s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
- // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
- s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
- s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
- s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
- s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
- s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
- s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
- s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
- s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
- s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
- s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
- s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
- s1PLCData.Add("a1Result", 0); // 产品结果
- s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
- s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
- s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
- s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
- s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
- s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
- s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
- s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
- s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
- s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
- s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
- s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
- s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
- s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
- s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
- s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
- #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
- while (true)
- {
- try
- {
- if (!GlobalContext._IsCon_Funs1)
- {
- UpdatePLCMonitor(1, plcNo, 0);
- continue;
- }
- if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- stopwatch1.Start();
- stopwatch2.Start();
- #region 一次性读取所有数据
- // 一次性读取所有数据
- result = Funs[plcNo].Read_SingleTag<OP40_MesData_t>(tagBaseName, 1, out stPLC_MesData); //读取单个结构体数据
- if (result.Item1 != 0)
- {
- //richTextBox1.AppendText("\n" + strRet);
- }
- else
- {
- //richTextBox1.AppendText("\n" + "读取成功");
- }
- #endregion 一次性读取所有数据
- stopwatch2.Stop();
- #region 进站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation && ProgressState == true)
- {
- ProgressState = false;
- Task.Run(() => S4进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, out ProgressState));
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 进站
- #region 出站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation && ProgressState == true)
- {
- ProgressState = false;
- Task.Run(() => S4出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 进站
- UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- stopwatch1.Stop();
- OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- }
- else
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- Funs[plcNo].Connect(); // 重连
- }
- }
- catch (Exception ex)
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- }
- Thread.Sleep(IntervalReadPLC);
- }
- }
- /// <summary>
- /// [S4] 点胶检测设备 - 进站
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- /// <param name="stPLC_MesData"></param>
- /// <param name="tagMesCommName"></param>
- private void S4进站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, out bool ProgressState)
- {
- int nRet = 0;
- string strRet = "";
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- ProgressState = true;
- try
- {
- stopwatch1.Start();
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
- string MachineId = GlobalContext.S4_MachineId; // 装备ID(可配置)
- string StationId = GlobalContext.S4_StationId; // 工位ID(可配置)
- // 产品SN(物料码)校验
- List<TestItem> item = new List<TestItem>();
- stopwatch2.Start();
- int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
- stopwatch2.Stop();
- //指令执行结果 1:OK 110:失败
- byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S4] 点胶检测设备 - 出站接口
- /// </summary>
- private void S4出站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
- {
- ProgressState = true;
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string processItem = stationName; // 测试项目
- string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string supplierCode = ""; // 供应商代码
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
- string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
- string MachineId = GlobalContext.S4_MachineId; // 装备id(可配置) // ZS
- string StationId = GlobalContext.S4_StationId; // ⼯位ID(可配置) // ZS
- int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
- bool pass = a1Result == 1;
- List<TestItem> items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = CarrierBarcode,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "产品码",
- Parameter_value = mtltmrk,
- Parameter_unit = ""
- });
- ResponseMessage responseMessage = InsertOp40Data("", stPLC_MesData.mesData.fGlue_Areas[0], stPLC_MesData.mesData.fGlue_Heights[0],"");
- if (!responseMessage.result)
- {
- AddMessage_Station(stationNameStr, LogType.Error, "OP40记录插入出错!");
- }
- //绑定PLC返回MES数据到本地
- int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
- , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId);
- byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
- stopwatch2.Start();
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-Write" + (result1 == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Start();
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{stationNameStr}]上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S5] 点胶检测设备
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- private void ReadStation_S5(int plcNo)
- {
- string stationCode = "[S5]";
- string stationName = "点胶检测设备";
- string stationNameStr = stationCode + stationName;
- string tagBaseName = "g_OP50_MES"; //标签变量名称
- string tagMesCommName = "mesCommToPC"; //标签变量名称
- string tagAgvCommName = "agvCommFrmPC";
- string tagBarsetName = "BarcodeSet";
- OP50_MesData_t stPLC_MesData; //PLC的MES数据
- (int, string) result;
- bool ProgressState = true;
- #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
- // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
- s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
- s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
- s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
- s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
- s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
- s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
- s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
- s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
- // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
- s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
- s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
- s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
- s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
- s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
- s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
- s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
- s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
- s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
- s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
- s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
- s1PLCData.Add("a1Result", 0); // 产品结果
- s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
- s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
- s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
- s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
- s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
- s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
- s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
- s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
- s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
- s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
- s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
- s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
- s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
- s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
- s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
- s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
- #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
- while (true)
- {
- try
- {
- if (!GlobalContext._IsCon_Funs1)
- {
- UpdatePLCMonitor(1, plcNo, 0);
- continue;
- }
- if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- stopwatch1.Start();
- stopwatch2.Start();
- #region 一次性读取所有数据
- // 一次性读取所有数据
- result = Funs[plcNo].Read_SingleTag<OP50_MesData_t>(tagBaseName, 1, out stPLC_MesData); //读取单个结构体数据
- if (result.Item1 != 0)
- {
- //richTextBox1.AppendText("\n" + strRet);
- }
- else
- {
- //richTextBox1.AppendText("\n" + "读取成功");
- }
- #endregion 一次性读取所有数据
- stopwatch2.Stop();
- #region 进站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation && ProgressState == true)
- {
- ProgressState = false;
- Task.Run(() => S5进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, out ProgressState));
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 进站
- #region 出站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation && ProgressState == true)
- {
- ProgressState = false;
- Task.Run(() => S5出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 进站
- UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- stopwatch1.Stop();
- OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- }
- else
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- Funs[plcNo].Connect(); // 重连
- }
- }
- catch (Exception ex)
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- }
- Thread.Sleep(IntervalReadPLC);
- }
- }
- /// <summary>
- /// [S5] 点胶检测设备 - 进站
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- /// <param name="stPLC_MesData"></param>
- /// <param name="tagMesCommName"></param>
- private void S5进站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, out bool ProgressState)
- {
- int nRet = 0;
- string strRet = "";
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- ProgressState = true;
- try
- {
- stopwatch1.Start();
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
- string MachineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
- string StationId = GlobalContext.S5_StationId; // 工位ID(可配置)
- // 产品SN(物料码)校验
- List<TestItem> item = new List<TestItem>();
- stopwatch2.Start();
- int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
- stopwatch2.Stop();
- //指令执行结果 1:OK 110:失败
- byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S5] 点胶检测设备 - 出站接口
- /// </summary>
- private void S5出站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
- {
- ProgressState = true;
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string processItem = stationName; // 测试项目
- string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string supplierCode = ""; // 供应商代码
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
- string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
- string MachineId = GlobalContext.S5_MachineId; // 装备id(可配置) // ZS
- string StationId = GlobalContext.S5_StationId; // ⼯位ID(可配置) // ZS
- int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
- bool pass = a1Result == 1;
- List<TestItem> items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = CarrierBarcode,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "产品码",
- Parameter_value = mtltmrk,
- Parameter_unit = ""
- });
- ResponseMessage responseMessage = InsertOp50Data(CarrierBarcode,sn, stPLC_MesData.BarcodeSet.strPartBarcode, stPLC_MesData.mesData.nIsAddPCBAsmOK,"", stPLC_MesData.mesData.nHaveAddPCB,stPLC_MesData.mesData.fForceAddPCB);
- if (!responseMessage.result)
- {
- AddMessage_Station(stationNameStr, LogType.Error, "OP50记录插入出错!");
- }
- //绑定PLC返回MES数据到本地
- int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
- , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId);
- byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
- stopwatch2.Start();
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-Write" + (result1 == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Start();
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{stationNameStr}]上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- #region PLC4 刘果段
- #region [S4] 取放桁架
- /// <summary>
- /// S4工位的数据- 触发信号上次的值
- /// </summary>
- private Dictionary<string, object> s4PLCSignal_Old = new Dictionary<string, object>();
- /// <summary>
- /// S4工位的数据(含触发信号)
- /// </summary>
- private Dictionary<string, object> s4PLCData = new Dictionary<string, object>();
- /// <summary>
- /// S4工位的数据- 回写点位
- /// </summary>
- private Dictionary<string, WriteToPLC_Flag> s4PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
- /// <summary>
- /// [S4] 取放桁架
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- private void ReadStation_S4(int plcNo)
- {
- // [S1] Tray盘上料装备
- // [S2] FCT
- // [S3] 值板机
- // [S4_1] 载具下线装备 [S4_5] 载具上线装备
- // [S5] Tray盘下料装备
- /// 上位机心跳
- /// 获取设备报警数据与状态信息
- string stationCode = "[S4_1]";
- string stationName = "载具下线装备";
- string stationNameStr = stationCode + stationName;
- string stationCode5 = "[S4_5]";
- string stationName5 = "载具上线装备";
- string stationNameStr5 = stationCode5 + stationName5;
- #region 创建字典
- // 触发信号字典 赋值
- s4PLCSignal_Old.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
- s4PLCSignal_Old.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
- s4PLCSignal_Old.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
- s4PLCSignal_Old.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- s4PLCSignal_Old.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
- s4PLCSignal_Old.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
- s4PLCSignal_Old.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
- s4PLCSignal_Old.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
- s4PLCSignal_Old.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
- s4PLCSignal_Old.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
- s4PLCSignal_Old.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- // PLC数据字典 赋值
- // 载具下线装备(弹夹上线)
- s4PLCData.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
- s4PLCData.Add("d1BulletclipCode", ""); // 扫到的码
- s4PLCData.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
- s4PLCData.Add("d1VehicleCode", ""); // 扫到的码
- s4PLCData.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
- s4PLCData.Add("d1MES_FLAG", 0); // MES_FLAG
- s4PLCData.Add("d1ProductSN", ""); // 产品SN(弹夹码)
- s4PLCData.Add("d1VehicleCode1", ""); // 载具1码(弹夹穴位1)
- s4PLCData.Add("d1VehicleCode2", ""); // 载具2码(弹夹穴位2)
- s4PLCData.Add("d1VehicleCode3", ""); // 载具3码(弹夹穴位3)
- s4PLCData.Add("d1VehicleCode4", ""); // 载具4码(弹夹穴位4)
- s4PLCData.Add("d1VehicleCode5", ""); // 载具5码(弹夹穴位5)
- s4PLCData.Add("d1VehicleCode6", ""); // 载具6码(弹夹穴位6)
- s4PLCData.Add("d1VehicleCode7", ""); // 载具7码(弹夹穴位7)
- s4PLCData.Add("d1VehicleCode8", ""); // 载具8码(弹夹穴位8)
- s4PLCData.Add("d1VehicleCode9", ""); // 载具9码(弹夹穴位9)
- s4PLCData.Add("d1VehicleCode10", ""); // 载具10码(弹夹穴位10)
- s4PLCData.Add("d1Result", 0); // 产品结果
- s4PLCData.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- s4PLCData.Add("d1OEEMES_FLAG", 0); // MES_FLAG
- s4PLCData.Add("d1OEEProductSN", "");// 产品SN(载具SN)
- s4PLCData.Add("d1OEEType", 0); // 节拍类型(plc写入)
- s4PLCData.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
- s4PLCData.Add("d2BulletclipStates", 0); // 弹夹状态
- s4PLCData.Add("d2BulletclipCode", ""); // 扫到的码
- // 真空标机(提升机)
- s4PLCData.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
- s4PLCData.Add("d3MES_FLAG", 0); // MES_FLAG
- s4PLCData.Add("d3Type", 0); // 进站还是出站
- s4PLCData.Add("d3ProductSN", ""); // 产品SN(弹夹码)
- s4PLCData.Add("d3Result", 0); // 产品结果
- s4PLCData.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
- s4PLCData.Add("d4MES_FLAG", 0); // MES_FLAG
- s4PLCData.Add("d4Type", 0); // 进站还是出站
- s4PLCData.Add("d4ProductSN", ""); // 产品SN(弹夹码)
- s4PLCData.Add("d4Result", 0); // 产品结果
- // 载具上线装备(弹夹下线)
- s4PLCData.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
- s4PLCData.Add("d5BulletclipCode", ""); // 扫到的码
- s4PLCData.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
- s4PLCData.Add("d5VehicleCode", ""); // 扫到的码
- s4PLCData.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
- s4PLCData.Add("d5MES_FLAG", 0); // MES_FLAG
- s4PLCData.Add("d5ProductSN", ""); // 产品SN(弹夹码)
- s4PLCData.Add("d5VehicleCode1", ""); // 载具1码(弹夹穴位1)
- s4PLCData.Add("d5VehicleCode2", ""); // 载具2码(弹夹穴位2)
- s4PLCData.Add("d5VehicleCode3", ""); // 载具3码(弹夹穴位3)
- s4PLCData.Add("d5VehicleCode4", ""); // 载具4码(弹夹穴位4)
- s4PLCData.Add("d5VehicleCode5", ""); // 载具5码(弹夹穴位5)
- s4PLCData.Add("d5VehicleCode6", ""); // 载具6码(弹夹穴位6)
- s4PLCData.Add("d5VehicleCode7", ""); // 载具7码(弹夹穴位7)
- s4PLCData.Add("d5VehicleCode8", ""); // 载具8码(弹夹穴位8)
- s4PLCData.Add("d5VehicleCode9", ""); // 载具9码(弹夹穴位9)
- s4PLCData.Add("d5VehicleCode10", ""); // 载具10码(弹夹穴位10)
- s4PLCData.Add("d5Result", 0); // 产品结果
- s4PLCData.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- s4PLCData.Add("d5OEEMES_FLAG", 0); // MES_FLAG
- s4PLCData.Add("d5OEEProductSN", "");// 产品SN(载具SN)
- s4PLCData.Add("d5OEEType", 0); // 节拍类型(plc写入)
- #endregion 创建字典
- while (true)
- {
- try
- {
- if (!GlobalContext._IsCon_Funs4)
- {
- UpdatePLCMonitor(1, plcNo, 0);
- continue;
- }
- if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- stopwatch1.Start();
- stopwatch2.Start();
- /*
- #region 一次性读取所有数据
- // 载具下线装备(弹夹上线)
- int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
- int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
- int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
- int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 100);
- int[] data5 = Funs[plcNo].ReadHoldingRegisters(2400, 100);
- int[] data6 = Funs[plcNo].ReadHoldingRegisters(2500, 100);
- int[] data7 = Funs[plcNo].ReadHoldingRegisters(2600, 100);
- int[] data8 = Funs[plcNo].ReadHoldingRegisters(2700, 100);
- int[] data9 = Funs[plcNo].ReadHoldingRegisters(2800, 100);
- int[] data10 = Funs[plcNo].ReadHoldingRegisters(2900, 56);
- int[] datas = data1.Concat(data2).ToArray();
- datas = datas.Concat(data3).ToArray();
- datas = datas.Concat(data4).ToArray();
- datas = datas.Concat(data5).ToArray();
- datas = datas.Concat(data6).ToArray();
- datas = datas.Concat(data7).ToArray();
- datas = datas.Concat(data8).ToArray();
- datas = datas.Concat(data9).ToArray();
- datas = datas.Concat(data10).ToArray();
- // 载具下线装备(弹夹上线)
- s4PLCData["d1BulletclipScanCode"] = datas[2]; // 扫码信号 弹夹扫码
- int[] d1BulletclipCodeData = datas.Skip(3).Take(20).ToArray();
- s4PLCData["d1BulletclipCode"] = ModbusClient.ConvertRegistersToString(d1BulletclipCodeData, 0, 40);
- s4PLCData["d1VehicleScanCode"] = datas[33]; // 扫码信号 载具扫码
- int[] d1VehicleCodeData = datas.Skip(34).Take(20).ToArray();
- s4PLCData["d1VehicleCode"] = ModbusClient.ConvertRegistersToString(d1VehicleCodeData, 0, 40);
- s4PLCData["d1PLC_FLAG"] = datas[64]; // PLC_FLAG 出站接口
- s4PLCData["d1MES_FLAG"] = datas[65];
- int[] d1ProductSNData = datas.Skip(66).Take(20).ToArray();
- s4PLCData["d1ProductSN"] = ModbusClient.ConvertRegistersToString(d1ProductSNData, 0, 40); // 产品SN(物料码)
- int[] d1VehicleCode1Data = datas.Skip(86).Take(20).ToArray();
- s4PLCData["d1VehicleCode1"] = ModbusClient.ConvertRegistersToString(d1VehicleCode1Data, 0, 40);
- int[] d1VehicleCode2Data = datas.Skip(106).Take(20).ToArray();
- s4PLCData["d1VehicleCode2"] = ModbusClient.ConvertRegistersToString(d1VehicleCode2Data, 0, 40);
- int[] d1VehicleCode3Data = datas.Skip(126).Take(20).ToArray();
- s4PLCData["d1VehicleCode3"] = ModbusClient.ConvertRegistersToString(d1VehicleCode3Data, 0, 40);
- int[] d1VehicleCode4Data = datas.Skip(146).Take(20).ToArray();
- s4PLCData["d1VehicleCode4"] = ModbusClient.ConvertRegistersToString(d1VehicleCode4Data, 0, 40);
- int[] d1VehicleCode5Data = datas.Skip(166).Take(20).ToArray();
- s4PLCData["d1VehicleCode5"] = ModbusClient.ConvertRegistersToString(d1VehicleCode5Data, 0, 40);
- int[] d1VehicleCode6Data = datas.Skip(186).Take(20).ToArray();
- s4PLCData["d1VehicleCode6"] = ModbusClient.ConvertRegistersToString(d1VehicleCode6Data, 0, 40);
- int[] d1VehicleCode7Data = datas.Skip(206).Take(20).ToArray();
- s4PLCData["d1VehicleCode7"] = ModbusClient.ConvertRegistersToString(d1VehicleCode7Data, 0, 40);
- int[] d1VehicleCode8Data = datas.Skip(226).Take(20).ToArray();
- s4PLCData["d1VehicleCode8"] = ModbusClient.ConvertRegistersToString(d1VehicleCode8Data, 0, 40);
- int[] d1VehicleCode9Data = datas.Skip(246).Take(20).ToArray();
- s4PLCData["d1VehicleCode9"] = ModbusClient.ConvertRegistersToString(d1VehicleCode9Data, 0, 40);
- int[] d1VehicleCode10Data = datas.Skip(266).Take(20).ToArray();
- s4PLCData["d1VehicleCode10"] = ModbusClient.ConvertRegistersToString(d1VehicleCode10Data, 0, 40);
- int[] d1VehicleCode11Data = datas.Skip(286).Take(20).ToArray();
- s4PLCData["d1VehicleCode11"] = ModbusClient.ConvertRegistersToString(d1VehicleCode11Data, 0, 40);
- int[] d1VehicleCode12Data = datas.Skip(306).Take(20).ToArray();
- s4PLCData["d1VehicleCode12"] = ModbusClient.ConvertRegistersToString(d1VehicleCode12Data, 0, 40);
- int[] d1VehicleCode13Data = datas.Skip(326).Take(20).ToArray();
- s4PLCData["d1VehicleCode13"] = ModbusClient.ConvertRegistersToString(d1VehicleCode13Data, 0, 40);
- int[] d1VehicleCode14Data = datas.Skip(346).Take(20).ToArray();
- s4PLCData["d1VehicleCode14"] = ModbusClient.ConvertRegistersToString(d1VehicleCode14Data, 0, 40);
- int[] d1VehicleCode15Data = datas.Skip(366).Take(20).ToArray();
- s4PLCData["d1VehicleCode15"] = ModbusClient.ConvertRegistersToString(d1VehicleCode15Data, 0, 40);
- s4PLCData["d1Result"] = datas[386];
- s4PLCData["d1OEEPLC_FLAG"] = datas[397]; // PLC_FLAG 节拍接口
- s4PLCData["d1OEEMES_FLAG"] = datas[398];
- int[] d1OEEProductSNData = datas.Skip(399).Take(20).ToArray();
- s4PLCData["d1OEEProductSN"] = ModbusClient.ConvertRegistersToString(d1OEEProductSNData, 0, 40);
- s4PLCData["d1OEEType"] = datas[419];
- // 桁架(查询标机中弹夹的状态)
- s4PLCData["d2BulletclipScanCode"] = datas[430];
- s4PLCData["d2BulletclipStates"] = datas[431];
- int[] d2BulletclipCodeData = datas.Skip(432).Take(20).ToArray();
- s4PLCData["d2BulletclipCode"] = ModbusClient.ConvertRegistersToString(d2BulletclipCodeData, 0, 40);
- // 真空标机
- s4PLCData["d3PLC_FLAG"] = datas[462]; // 真空标机1 出站接口
- s4PLCData["d3MES_FLAG"] = datas[463];
- int[] d3ProductSNData = datas.Skip(464).Take(20).ToArray();
- s4PLCData["d3ProductSN"] = ModbusClient.ConvertRegistersToString(d3ProductSNData, 0, 40);
- s4PLCData["d3Result"] = datas[484];
- s4PLCData["d3Type"] = datas[485];
- s4PLCData["d4PLC_FLAG"] = datas[495]; // 真空标机2 出站接口
- s4PLCData["d4MES_FLAG"] = datas[496];
- int[] d4ProductSNData = datas.Skip(497).Take(20).ToArray();
- s4PLCData["d4ProductSN"] = ModbusClient.ConvertRegistersToString(d4ProductSNData, 0, 40);
- s4PLCData["d4Result"] = datas[517];
- s4PLCData["d4Type"] = datas[518];
- // 载具上线装备(弹夹下线)
- s4PLCData["d5BulletclipScanCode"] = datas[528]; // 扫码信号 弹夹扫码
- int[] d5BulletclipCodeData = datas.Skip(529).Take(20).ToArray();
- s4PLCData["d5BulletclipCode"] = ModbusClient.ConvertRegistersToString(d5BulletclipCodeData, 0, 40);
- s4PLCData["d5VehicleScanCode"] = datas[559]; // 扫码信号 载具扫码
- int[] d5VehicleCodeData = datas.Skip(560).Take(20).ToArray();
- s4PLCData["d5VehicleCode"] = ModbusClient.ConvertRegistersToString(d5VehicleCodeData, 0, 40);
- s4PLCData["d5PLC_FLAG"] = datas[590]; // PLC_FLAG 出站接口
- s4PLCData["d5MES_FLAG"] = datas[591];
- int[] d5ProductSNData = datas.Skip(592).Take(20).ToArray();
- s4PLCData["d5ProductSN"] = ModbusClient.ConvertRegistersToString(d5ProductSNData, 0, 40); // 产品SN(物料码)
- int[] d5VehicleCode1Data = datas.Skip(612).Take(20).ToArray();
- s4PLCData["d5VehicleCode1"] = ModbusClient.ConvertRegistersToString(d5VehicleCode1Data, 0, 40);
- int[] d5VehicleCode2Data = datas.Skip(632).Take(20).ToArray();
- s4PLCData["d5VehicleCode2"] = ModbusClient.ConvertRegistersToString(d5VehicleCode2Data, 0, 40);
- int[] d5VehicleCode3Data = datas.Skip(652).Take(20).ToArray();
- s4PLCData["d5VehicleCode3"] = ModbusClient.ConvertRegistersToString(d5VehicleCode3Data, 0, 40);
- int[] d5VehicleCode4Data = datas.Skip(672).Take(20).ToArray();
- s4PLCData["d5VehicleCode4"] = ModbusClient.ConvertRegistersToString(d5VehicleCode4Data, 0, 40);
- int[] d5VehicleCode5Data = datas.Skip(692).Take(20).ToArray();
- s4PLCData["d5VehicleCode5"] = ModbusClient.ConvertRegistersToString(d5VehicleCode5Data, 0, 40);
- int[] d5VehicleCode6Data = datas.Skip(712).Take(20).ToArray();
- s4PLCData["d5VehicleCode6"] = ModbusClient.ConvertRegistersToString(d5VehicleCode6Data, 0, 40);
- int[] d5VehicleCode7Data = datas.Skip(732).Take(20).ToArray();
- s4PLCData["d5VehicleCode7"] = ModbusClient.ConvertRegistersToString(d5VehicleCode7Data, 0, 40);
- int[] d5VehicleCode8Data = datas.Skip(752).Take(20).ToArray();
- s4PLCData["d5VehicleCode8"] = ModbusClient.ConvertRegistersToString(d5VehicleCode8Data, 0, 40);
- int[] d5VehicleCode9Data = datas.Skip(772).Take(20).ToArray();
- s4PLCData["d5VehicleCode9"] = ModbusClient.ConvertRegistersToString(d5VehicleCode9Data, 0, 40);
- int[] d5VehicleCode10Data = datas.Skip(792).Take(20).ToArray();
- s4PLCData["d5VehicleCode10"] = ModbusClient.ConvertRegistersToString(d5VehicleCode10Data, 0, 40);
- int[] d5VehicleCode11Data = datas.Skip(812).Take(20).ToArray();
- s4PLCData["d5VehicleCode11"] = ModbusClient.ConvertRegistersToString(d5VehicleCode11Data, 0, 40);
- int[] d5VehicleCode12Data = datas.Skip(832).Take(20).ToArray();
- s4PLCData["d5VehicleCode12"] = ModbusClient.ConvertRegistersToString(d5VehicleCode12Data, 0, 40);
- int[] d5VehicleCode13Data = datas.Skip(852).Take(20).ToArray();
- s4PLCData["d5VehicleCode13"] = ModbusClient.ConvertRegistersToString(d5VehicleCode13Data, 0, 40);
- int[] d5VehicleCode14Data = datas.Skip(872).Take(20).ToArray();
- s4PLCData["d5VehicleCode14"] = ModbusClient.ConvertRegistersToString(d5VehicleCode14Data, 0, 40);
- int[] d5VehicleCode15Data = datas.Skip(892).Take(20).ToArray();
- s4PLCData["d5VehicleCode15"] = ModbusClient.ConvertRegistersToString(d5VehicleCode15Data, 0, 40);
- s4PLCData["d5Result"] = datas[912];
- s4PLCData["d5OEEPLC_FLAG"] = datas[923]; // PLC_FLAG 节拍接口
- s4PLCData["d5OEEMES_FLAG"] = datas[924];
- int[] d5OEEProductSNData = datas.Skip(925).Take(20).ToArray();
- s4PLCData["d5OEEProductSN"] = ModbusClient.ConvertRegistersToString(d5OEEProductSNData, 0, 40);
- s4PLCData["d5OEEType"] = datas[945];
- #endregion 一次性读取所有数据
- stopwatch2.Stop();
- #region 回写操作,写后清空flag
- PLCWriteData(Funs[plcNo], ref s4PLCData, ref s4PLCWriteData);
- #endregion 回写操作,写后清空flag
- */
- // N801A-S4_1 弹夹扫码
- #region N801A-S4_1 弹夹扫码
- try
- {
- int d1BulletclipScanCode = (int)s4PLCData["d1BulletclipScanCode"];
- int d1BulletclipScanCodeOld = (int)s4PLCSignal_Old["d1BulletclipScanCode"];
- if (d1BulletclipScanCode != d1BulletclipScanCodeOld)
- {
- if (d1BulletclipScanCode == 1) // 0->1
- Task.Run(() => S4_1弹夹扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
- s4PLCSignal_Old["d1BulletclipScanCode"] = s4PLCData["d1BulletclipScanCode"];
- }
- }
- catch (Exception ex)
- {
- //Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion N801A-S4_1 弹夹扫码
- // N801A-S4_1 载具扫码
- #region N801A-S4_1 载具扫码
- try
- {
- int d1VehicleScanCode = (int)s4PLCData["d1VehicleScanCode"];
- int d1VehicleScanCodeOld = (int)s4PLCSignal_Old["d1VehicleScanCode"];
- if (d1VehicleScanCode != d1VehicleScanCodeOld)
- {
- if (d1VehicleScanCode == 1) // 0->1
- Task.Run(() => S4_1载具扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
- s4PLCSignal_Old["d1VehicleScanCode"] = s4PLCData["d1VehicleScanCode"];
- }
- }
- catch (Exception ex)
- {
- //Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion N801A-S4_1 载具扫码
- // N801A-S4_1 出站接口
- #region N801A-S4_1 出站接口
- try
- {
- int d1PLC_FLAG = (int)s4PLCData["d1PLC_FLAG"];
- int d1MES_FLAG = (int)s4PLCData["d1MES_FLAG"];
- int d1PLC_FLAGOld = (int)s4PLCSignal_Old["d1PLC_FLAG"];
- if (d1PLC_FLAG != d1PLC_FLAGOld)
- {
- if (d1PLC_FLAG == 1 && d1MES_FLAG == 0) // 0->1
- Task.Run(() => S4_1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
- //else if (d1PLC_FLAG == 0 && d1MES_FLAG != 0)
- //Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)0);
- s4PLCSignal_Old["d1PLC_FLAG"] = s4PLCData["d1PLC_FLAG"];
- }
- }
- catch (Exception ex)
- {
- //Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)6); // 6代表上位机报警
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion N801A-S4_1 出站接口
- // N801A-S4_1 节拍接口
- #region N801A-S4_1 节拍接口
- try
- {
- int d1OEEPLC_FLAG = (int)s4PLCData["d1OEEPLC_FLAG"];
- int d1OEEMES_FLAG = (int)s4PLCData["d1OEEMES_FLAG"];
- int d1OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d1OEEPLC_FLAG"];
- if (d1OEEPLC_FLAG != d1OEEPLC_FLAGOld)
- {
- if (d1OEEPLC_FLAG == 1 && d1OEEMES_FLAG == 0) // 0->1
- Task.Run(() => S4_1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
- //else if (d1OEEPLC_FLAG == 0 && d1OEEMES_FLAG != 0)
- //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)0);
- s4PLCSignal_Old["d1OEEPLC_FLAG"] = s4PLCData["d1OEEPLC_FLAG"];
- }
- }
- catch (Exception ex)
- {
- //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion N801A-S4_1 节拍接口
- // N801A-S4_2 桁架(查询标机中弹夹的状态) 数据
- #region N801A-S4_2 桁架(查询标机中弹夹的状态)
- try
- {
- int d2BulletclipScanCode = (int)s4PLCData["d2BulletclipScanCode"];
- int d2BulletclipScanCodeOld = (int)s4PLCSignal_Old["d2BulletclipScanCode"];
- if (d2BulletclipScanCode != d2BulletclipScanCodeOld)
- {
- if (d2BulletclipScanCode == 1) // 0->1
- Task.Run(() => S4_2桁架(plcNo, stationNameStr)); // MreTasks[1].Set();
- s4PLCSignal_Old["d2BulletclipScanCode"] = s4PLCData["d2BulletclipScanCode"];
- }
- }
- catch (Exception ex)
- {
- //Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 桁架出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion N801A-S4_2 桁架(查询标机中弹夹的状态)
- // N801A-S4_3 真空标机1 数据
- #region N801A-S4_3 真空标机1
- try
- {
- int d3PLC_FLAG = (int)s4PLCData["d3PLC_FLAG"];
- int d3MES_FLAG = (int)s4PLCData["d3MES_FLAG"];
- int d3PLC_FLAGOld = (int)s4PLCSignal_Old["d3PLC_FLAG"];
- if (d3PLC_FLAG != d3PLC_FLAGOld)
- {
- if (d3PLC_FLAG == 1 && d3MES_FLAG == 0) // 0->1
- {
- int stationType = (int)s4PLCData["d3Type"];
- if (stationType == 1)
- {
- // S4_3进站接口
- Task.Run(() => S4_3进站接口(plcNo, stationNameStr)); // MreTasks[3].Set();
- }
- else if (stationType == 2)
- {
- // S4_3出站接口
- Task.Run(() => S4_3出站接口(plcNo, stationNameStr)); // MreTasks[3].Set();
- }
- }
- //else if (d3PLC_FLAG == 0 && d3MES_FLAG != 0)
- //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)0);
- s4PLCSignal_Old["d3PLC_FLAG"] = s4PLCData["d3PLC_FLAG"];
- }
- }
- catch (Exception ex)
- {
- //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion N801A-S4_3 真空标机1
- // N801A-S4_4 真空标机2 数据
- #region N801A-S4_4 真空标机2
- try
- {
- int d4PLC_FLAG = (int)s4PLCData["d4PLC_FLAG"];
- int d4MES_FLAG = (int)s4PLCData["d4MES_FLAG"];
- int d4PLC_FLAGOld = (int)s4PLCSignal_Old["d4PLC_FLAG"];
- if (d4PLC_FLAG != d4PLC_FLAGOld)
- {
- if (d4PLC_FLAG == 1 && d4MES_FLAG == 0) // 0->1
- {
- int stationType = (int)s4PLCData["d4Type"];
- if (stationType == 1)
- {
- // S4_4进站接口
- Task.Run(() => S4_4进站接口(plcNo, stationNameStr)); // MreTasks[3].Set();
- }
- else if (stationType == 2)
- {
- // S4_4出站接口
- Task.Run(() => S4_4出站接口(plcNo, stationNameStr)); // MreTasks[3].Set();
- }
- }
- //else if (d4PLC_FLAG == 0 && d4MES_FLAG != 0)
- //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)0);
- s4PLCSignal_Old["d4PLC_FLAG"] = s4PLCData["d4PLC_FLAG"];
- }
- }
- catch (Exception ex)
- {
- //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion N801A-S4_4 真空标机2
- // N801A-S4_5 弹夹扫码 数据
- #region N801A-S4_5 弹夹扫码
- try
- {
- int d5BulletclipScanCode = (int)s4PLCData["d5BulletclipScanCode"];
- int d5BulletclipScanCodeOld = (int)s4PLCSignal_Old["d5BulletclipScanCode"];
- if (d5BulletclipScanCode != d5BulletclipScanCodeOld)
- {
- if (d5BulletclipScanCode == 1) // 0->1
- Task.Run(() => S4_5弹夹扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
- s4PLCSignal_Old["d5BulletclipScanCode"] = s4PLCData["d5BulletclipScanCode"];
- }
- }
- catch (Exception ex)
- {
- //Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion N801A-S4_5 弹夹扫码
- // N801A-S4_5 载具扫码 数据
- #region N801A-S4_5 载具扫码
- try
- {
- int d5VehicleScanCode = (int)s4PLCData["d5VehicleScanCode"];
- int d5VehicleScanCodeOld = (int)s4PLCSignal_Old["d5VehicleScanCode"];
- if (d5VehicleScanCode != d5VehicleScanCodeOld)
- {
- if (d5VehicleScanCode == 1) // 0->1
- Task.Run(() => S4_5载具扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
- s4PLCSignal_Old["d5VehicleScanCode"] = s4PLCData["d5VehicleScanCode"];
- }
- }
- catch (Exception ex)
- {
- //Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion N801A-S4_5 载具扫码
- // N801A-S4_5 出站接口(扫完所有码后立即上传) 数据
- #region N801A-S4_5 出站接口
- try
- {
- int d5PLC_FLAG = (int)s4PLCData["d5PLC_FLAG"];
- int d5MES_FLAG = (int)s4PLCData["d5MES_FLAG"];
- int d5PLC_FLAGOld = (int)s4PLCSignal_Old["d5PLC_FLAG"];
- if (d5PLC_FLAG != d5PLC_FLAGOld)
- {
- if (d5PLC_FLAG == 1 && d5MES_FLAG == 0) // 0->1
- Task.Run(() => S4_5出站接口(plcNo, stationCode5, stationName5)); // MreTasks[3].Set();
- //else if (d5PLC_FLAG == 0 && d5MES_FLAG != 0)
- //Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)0);
- s4PLCSignal_Old["d5PLC_FLAG"] = s4PLCData["d5PLC_FLAG"];
- }
- }
- catch (Exception ex)
- {
- //Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)6); // 6代表上位机报警
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion N801A-S4_5 出站接口
- // N801A-S4_5 节拍接口 数据
- #region N801A-S4_5 节拍接口
- try
- {
- int d5OEEPLC_FLAG = (int)s4PLCData["d5OEEPLC_FLAG"];
- int d5OEEMES_FLAG = (int)s4PLCData["d5OEEMES_FLAG"];
- int d5OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d5OEEPLC_FLAG"];
- if (d5OEEPLC_FLAG != d5OEEPLC_FLAGOld)
- {
- if (d5OEEPLC_FLAG == 1 && d5OEEMES_FLAG == 0) // 0->1
- Task.Run(() => S4_5节拍接口(plcNo, stationNameStr5)); // MreTasks[4].Set();
- //else if (d5OEEPLC_FLAG == 0 && d5OEEMES_FLAG != 0)
- //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)0);
- s4PLCSignal_Old["d5OEEPLC_FLAG"] = s4PLCData["d5OEEPLC_FLAG"];
- }
- }
- catch (Exception ex)
- {
- //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion N801A-S4_5 节拍接口
- UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- stopwatch1.Stop();
- //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
- OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- }
- else
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- Funs[plcNo].Connect();
- }
- }
- catch (Exception ex)
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- //Funs[plcNo].ReConnect();
- }
- Thread.Sleep(IntervalReadPLC);
- }
- }
- /// <summary>
- /// [S4] 取放桁架 - S4_1弹夹扫码
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S4_1弹夹扫码(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS 弹夹扫码
- string d1BulletclipCode = " "; // 扫到的码
- short d1BulletclipScanCode = 2;
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<string>(2003, d1BulletclipCode, 20);
- //// MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2002, d1BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d1BulletclipScanCode";
- writeToPLC_Flag.Adress = 2002;
- writeToPLC_Flag.Value = d1BulletclipScanCode;
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
- {
- Name = "d1BulletclipCode",
- Adress = 2003,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = d1BulletclipCode
- });
- SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<string>(2003, " ", 20);
- //// MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d1BulletclipScanCode";
- writeToPLC_Flag.Adress = 2002;
- writeToPLC_Flag.Value = (short)6;
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
- {
- Name = "d1BulletclipCode",
- Adress = 2003,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = " "
- });
- SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S4] 取放桁架 - S4_1载具扫码
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S4_1载具扫码(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS 载具扫码
- string d1VehicleCode = " "; // 扫到的码
- // 查产品SN
- string partNo = " ";
- short d1VehicleScanCode = 2;
- #region 进站
- if (!string.IsNullOrEmpty(d1VehicleCode))
- {
- List<TestItem> item = new List<TestItem>();
- item.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = d1VehicleCode,
- });
- item.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "1",
- });
- stopwatch2.Start();
- int result = 0;
- //int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item);
- stopwatch2.Stop();
- d1VehicleScanCode = (short)result == 1 ? d1VehicleScanCode : (short)result;
- }
- #endregion 进站
- //Funs[plcNo].WriteMultipleRegisters<string>(2034, d1VehicleCode, 20);
- //// MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2033, d1VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d1VehicleScanCode";
- writeToPLC_Flag.Adress = 2033;
- writeToPLC_Flag.Value = d1VehicleScanCode;
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
- {
- Name = "d1VehicleCode",
- Adress = 2034,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = d1VehicleCode
- });
- SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<string>(2034, " ", 20);
- //// MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d1VehicleScanCode";
- writeToPLC_Flag.Adress = 2033;
- writeToPLC_Flag.Value = (short)6; // 6代表上位机报警
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
- {
- Name = "d1VehicleCode",
- Adress = 2034,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = " "
- });
- SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- // 上次采集到的SN
- //private string sn_S4_1出站接口 = string.Empty;
- /// <summary>
- /// [S4] 取放桁架 - S4_1出站接口
- /// </summary>
- private void S4_1出站接口(int plcNo, string stationCode, string stationName)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string stationNameStr = stationCode + stationName;
- string processItem = stationName; // 测试项目
- try
- {
- stopwatch1.Start();
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string supplierCode = ""; // 供应商代码
- string sn = (string)s4PLCData["d1ProductSN"]; // 产品SN(弹夹码)
- sn = sn.Replace("\0", "");
- string d1VehicleCode1 = (string)s4PLCData["d1VehicleCode1"]; // 载具1码(弹夹穴位1)
- string d1VehicleCode2 = (string)s4PLCData["d1VehicleCode2"]; // 载具2码(弹夹穴位2)
- string d1VehicleCode3 = (string)s4PLCData["d1VehicleCode3"]; // 载具3码(弹夹穴位3)
- string d1VehicleCode4 = (string)s4PLCData["d1VehicleCode4"]; // 载具4码(弹夹穴位4)
- string d1VehicleCode5 = (string)s4PLCData["d1VehicleCode5"]; // 载具5码(弹夹穴位5)
- string d1VehicleCode6 = (string)s4PLCData["d1VehicleCode6"]; // 载具6码(弹夹穴位6)
- string d1VehicleCode7 = (string)s4PLCData["d1VehicleCode7"]; // 载具7码(弹夹穴位7)
- string d1VehicleCode8 = (string)s4PLCData["d1VehicleCode8"]; // 载具8码(弹夹穴位8)
- string d1VehicleCode9 = (string)s4PLCData["d1VehicleCode9"]; // 载具9码(弹夹穴位9)
- string d1VehicleCode10 = (string)s4PLCData["d1VehicleCode10"]; // 载具10码(弹夹穴位10)
- string d1VehicleCode11 = (string)s4PLCData["d1VehicleCode11"]; // 载具11码(弹夹穴位11)
- string d1VehicleCode12 = (string)s4PLCData["d1VehicleCode12"]; // 载具12码(弹夹穴位12)
- string d1VehicleCode13 = (string)s4PLCData["d1VehicleCode13"]; // 载具13码(弹夹穴位13)
- string d1VehicleCode14 = (string)s4PLCData["d1VehicleCode14"]; // 载具14码(弹夹穴位14)
- string d1VehicleCode15 = (string)s4PLCData["d1VehicleCode15"]; // 载具15码(弹夹穴位15)
- int d1Result = (int)s4PLCData["d1Result"]; // 产品结果
- bool pass = d1Result == 1;
- List<TestItem> items1 = new List<TestItem>();
- items1.Add(new TestItem()
- {
- Parameter_name = "产品结果",
- Parameter_value = d1Result == 1 ? "OK" : "NG",
- Parameter_unit = ""
- });
- int result1 = 0;
- //int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
- //, workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, d1VehicleCode1, "1");
- //int result = result1 == 1 ? 1 : (GlobalContext.IsSendProcessData ? 4 : 1);
- short result = result1 == 1 ? (short)1 : (short)3;
- stopwatch2.Start();
- // MES_Flag 为4MES报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2065, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d1MES_FLAG";
- writeToPLC_Flag.Adress = 2065;
- writeToPLC_Flag.Value = result;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Start();
- // MES_Flag 为4上位机报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d1MES_FLAG";
- writeToPLC_Flag.Adress = 2065;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S4] 取放桁架 - S4_1节拍接口
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S4_1节拍接口(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string resultStr = string.Empty;
- try
- {
- stopwatch1.Start();
- string oEEType = ((int)s4PLCData["d1OEEType"]).ToString(); // 节拍类型(plc写入)
- string d1OEEProductSN = (string)s4PLCData["d1OEEProductSN"]; // 载具SN
- d1OEEProductSN = d1OEEProductSN.Replace("\0", "");
- bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
- if (!actionBool)
- {
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
- writeToPLC_Flag1.Adress = 2398;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- string d1OEEPartNo = string.Empty; // 物料码
- if (string.IsNullOrEmpty(d1OEEProductSN))
- {
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
- writeToPLC_Flag1.Adress = 2398;
- writeToPLC_Flag1.Value = (short)1;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- else
- { // 查产品SN
- d1OEEPartNo = "Test"; // ZS
- }
- short d1OEEMES_FLAG = 0;
- // 上传OEE
- (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d1OEEPartNo, d1OEEProductSN);
- d1OEEMES_FLAG = result.Item1;
- resultStr = result.Item2;
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2398, d1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d1OEEMES_FLAG";
- writeToPLC_Flag.Adress = 2398;
- writeToPLC_Flag.Value = d1OEEMES_FLAG;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d1OEEMES_FLAG";
- writeToPLC_Flag.Adress = 2398;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S4] 取放桁架 - S4_2桁架
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S4_2桁架(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS 弹夹扫码
- string d2BulletclipCode = " "; // 扫到的码
- short d2BulletclipStates = 1; // 弹夹状态(上位机写入)
- short d2BulletclipScanCode = 2;
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<string>(2432, d2BulletclipCode, 20); // 扫到的码
- //Funs[plcNo].WriteMultipleRegisters<short>(2431, d2BulletclipStates); // 弹夹状态(上位机写入)
- //// MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2430, d2BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d2BulletclipScanCode";
- writeToPLC_Flag.Adress = 2430;
- writeToPLC_Flag.Value = d2BulletclipScanCode;
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
- {
- Name = "d2BulletclipCode",
- Adress = 2432,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = d2BulletclipCode
- });
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
- {
- Name = "d2BulletclipStates",
- Adress = 2431,
- ValueType = PLCValueType.Short,
- Value = d2BulletclipStates
- });
- SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<string>(2432, " ", 20);
- //Funs[plcNo].WriteMultipleRegisters<short>(2431, (short)0);
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d2BulletclipScanCode";
- writeToPLC_Flag.Adress = 2430;
- writeToPLC_Flag.Value = (short)6;
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
- {
- Name = "d2BulletclipCode",
- Adress = 2432,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = " "
- });
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
- {
- Name = "d2BulletclipStates",
- Adress = 2431,
- ValueType = PLCValueType.Short,
- Value = (short)0
- });
- SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- // 上次采集到的SN
- //private string sn_S4_3进站接口 = string.Empty;
- /// <summary>
- /// [S4] 取放桁架 - S4_3进站接口(提升机1)
- /// </summary>
- private void S4_3进站接口(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
- sn = sn.Replace("\0", "");
- int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
- // ZS 查询15个载具码与15个产品SN
- List<string> vehicleCodes = new string[15].ToList();
- List<string> portNos = new string[15].ToList();
- // 调用MES进站(最多15个)
- stopwatch2.Start();
- List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
- for (int i = 0; i < vehicleCodes.Count; i++)
- {
- // 循环进站
- if (!string.IsNullOrEmpty(vehicleCodes[i]))
- {
- // 产品SN(物料码)校验
- string portNo = portNos[i];
- List<TestItem> item = new List<TestItem>();
- item.Add(new TestItem()
- {
- Parameter_name = "弹夹码",
- Parameter_value = sn,
- });
- item.Add(new TestItem()
- {
- Parameter_name = "弹夹穴位",
- Parameter_value = (i + 1).ToString(),
- });
- item.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = vehicleCodes[i],
- });
- item.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "1",
- });
- results[i] = 0;//SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item);
- }
- }
- stopwatch2.Stop();
- short result = 0;
- bool haveMesWarn = results.Contains(5);
- bool havePCWarn = results.Contains(6);
- if (haveMesWarn)
- result = 2; // 5->2
- else if (havePCWarn)
- result = 6; // 6->4
- else
- result = 1;
- // MES_Flag 为4MES报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d3MES_FLAG";
- writeToPLC_Flag.Adress = 2463;
- writeToPLC_Flag.Value = result;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
- WritePLCLog(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Stop();
- // MES_Flag 为4上位机报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d3MES_FLAG";
- writeToPLC_Flag.Adress = 2463;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_S4_3进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- // 上次采集到的SN
- //private string sn_S4_3出站接口 = string.Empty;
- /// <summary>
- /// [S4] 取放桁架 - S4_3出站接口(提升机1)
- /// </summary>
- private void S4_3出站接口(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string supplierCode = ""; // 供应商代码
- string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
- sn = sn.Replace("\0", "");
- int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
- bool isPass = d3Result == 1; // 产品结果 bool
- // ZS 查询15个载具码与15个产品SN
- List<string> vehicleCodes = new string[15].ToList();
- List<string> portNos = new string[15].ToList();
- // 调用MES出站
- stopwatch2.Start();
- List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
- for (int i = 0; i < vehicleCodes.Count; i++)
- {
- // 循环出站
- if (!string.IsNullOrEmpty(vehicleCodes[i]))
- {
- string portNo = portNos[i];
- List<TestItem> items1 = new List<TestItem>();
- items1.Add(new TestItem()
- {
- Parameter_name = "弹夹码",
- Parameter_value = sn,
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "弹夹穴位",
- Parameter_value = (i + 1).ToString(),
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = vehicleCodes[i],
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "1",
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "产品结果",
- Parameter_value = isPass ? "OK" : "NG",
- });
- int mesResult = 0;
- //int mesResult = SwitctProcessData(stationNameStr, items1, "", ""
- // , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, portNo, isPass, vehicleCodes[i], "1");
- results[i] = mesResult == 1 ? 1 : 2;
- }
- }
- stopwatch2.Stop();
- short result = 0;
- bool haveMesWarn = results.Contains(2);
- bool havePCWarn = results.Contains(3);
- if (haveMesWarn)
- result = 2; // 2->2
- else if (havePCWarn)
- result = 4; // 3->4
- else
- result = 1;
- // MES_Flag 为4MES报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d3MES_FLAG";
- writeToPLC_Flag.Adress = 2463;
- writeToPLC_Flag.Value = result;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
- WritePLCLog(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Stop();
- // MES_Flag 为4上位机报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d3MES_FLAG";
- writeToPLC_Flag.Adress = 2463;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_S4_3出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- // 上次采集到的SN
- //private string sn_S4_4进站接口 = string.Empty;
- /// <summary>
- /// [S4] 取放桁架 - S4_4进站接口(提升机2)
- /// </summary>
- private void S4_4进站接口(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
- sn = sn.Replace("\0", "");
- int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
- // ZS 查询15个载具码与15个产品SN
- List<string> vehicleCodes = new string[15].ToList();
- List<string> portNos = new string[15].ToList();
- // 调用MES进站(最多15个)
- stopwatch2.Start();
- List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
- for (int i = 0; i < vehicleCodes.Count; i++)
- {
- // 循环进站
- if (!string.IsNullOrEmpty(vehicleCodes[i]))
- {
- // 产品SN(物料码)校验
- string portNo = portNos[i];
- List<TestItem> item = new List<TestItem>();
- item.Add(new TestItem()
- {
- Parameter_name = "弹夹码",
- Parameter_value = sn,
- });
- item.Add(new TestItem()
- {
- Parameter_name = "弹夹穴位",
- Parameter_value = (i + 1).ToString(),
- });
- item.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = vehicleCodes[i],
- });
- item.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "1",
- });
- results[i] = 0;// SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item);
- }
- }
- stopwatch2.Stop();
- short result = 0;
- bool haveMesWarn = results.Contains(5);
- bool havePCWarn = results.Contains(6);
- if (haveMesWarn)
- result = 2; // 5->2
- else if (havePCWarn)
- result = 6; // 6->4
- else
- result = 1;
- // MES_Flag 为4MES报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d4MES_FLAG";
- writeToPLC_Flag.Adress = 2496;
- writeToPLC_Flag.Value = result;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
- WritePLCLog(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Stop();
- // MES_Flag 为4上位机报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d4MES_FLAG";
- writeToPLC_Flag.Adress = 2496;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_S4_4进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- // 上次采集到的SN
- //private string sn_S4_4出站接口 = string.Empty;
- /// <summary>
- /// [S4] 取放桁架 - S4_4出站接口(提升机2)
- /// </summary>
- private void S4_4出站接口(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string supplierCode = ""; // 供应商代码
- string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
- sn = sn.Replace("\0", "");
- int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
- bool isPass = d4Result == 1; // 产品结果 bool
- // ZS 查询15个载具码与15个产品SN
- List<string> vehicleCodes = new string[15].ToList();
- List<string> portNos = new string[15].ToList();
- // 调用MES出站
- stopwatch2.Start();
- List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
- for (int i = 0; i < vehicleCodes.Count; i++)
- {
- // 循环出站
- if (!string.IsNullOrEmpty(vehicleCodes[i]))
- {
- string portNo = portNos[i];
- List<TestItem> items1 = new List<TestItem>();
- items1.Add(new TestItem()
- {
- Parameter_name = "弹夹码",
- Parameter_value = sn,
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "弹夹穴位",
- Parameter_value = (i + 1).ToString(),
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = vehicleCodes[i],
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "1",
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "产品结果",
- Parameter_value = isPass ? "OK" : "NG",
- });
- int mesResult = 0;
- //int mesResult = SwitctProcessData(stationNameStr, items1, "", ""
- // , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, portNo, isPass, vehicleCodes[i], "1");
-
- results[i] = mesResult == 1 ? 1 : 2;
- }
- }
- stopwatch2.Stop();
- short result = 0;
- bool haveMesWarn = results.Contains(2);
- bool havePCWarn = results.Contains(3);
- if (haveMesWarn)
- result = 2; // 2->2
- else if (havePCWarn)
- result = 4; // 3->4
- else
- result = 1;
- // MES_Flag 为4MES报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d4MES_FLAG";
- writeToPLC_Flag.Adress = 2496;
- writeToPLC_Flag.Value = result;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
- WritePLCLog(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Stop();
- // MES_Flag 为4上位机报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d4MES_FLAG";
- writeToPLC_Flag.Adress = 2496;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_S4_4出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S4] 取放桁架 - S4_5弹夹扫码
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S4_5弹夹扫码(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS 弹夹扫码
- string d5BulletclipCode = " "; // 扫到的码
- short d5BulletclipScanCode = 2;
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<string>(2529, d5BulletclipCode, 20);
- //// MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2528, d5BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d5BulletclipScanCode";
- writeToPLC_Flag.Adress = 2528;
- writeToPLC_Flag.Value = d5BulletclipScanCode;
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
- {
- Name = "d5BulletclipCode",
- Adress = 2529,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = d5BulletclipCode
- });
- SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<string>(2529, " ", 20);
- //// MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d5BulletclipScanCode";
- writeToPLC_Flag.Adress = 2528;
- writeToPLC_Flag.Value = (short)6;
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
- {
- Name = "d5BulletclipCode",
- Adress = 2529,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = " "
- });
- SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S4] 取放桁架 - S4_5载具扫码
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S4_5载具扫码(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS 载具扫码
- string d5VehicleCode = " "; // 扫到的码
- // 查产品SN
- string partNo = " ";
- short d5VehicleScanCode = 2;
- #region 进站
- if (!string.IsNullOrEmpty(d5VehicleCode))
- {
- List<TestItem> item = new List<TestItem>();
- item.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = d5VehicleCode,
- });
- item.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "1",
- });
- stopwatch2.Start();
- int result = 0;//SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item);
- stopwatch2.Stop();
- d5VehicleScanCode = (short)result == 1 ? d5VehicleScanCode : (short)result;
- }
- #endregion 进站
- //Funs[plcNo].WriteMultipleRegisters<string>(2560, d5VehicleCode, 20);
- //// MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2559, d5VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d5VehicleScanCode";
- writeToPLC_Flag.Adress = 2559;
- writeToPLC_Flag.Value = d5VehicleScanCode;
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
- {
- Name = "d5VehicleCode",
- Adress = 2560,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = d5VehicleCode
- });
- SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<string>(2560, " ", 20);
- //// MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d5VehicleScanCode";
- writeToPLC_Flag.Adress = 2559;
- writeToPLC_Flag.Value = (short)6;
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
- {
- Name = "d5VehicleCode",
- Adress = 2560,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = " "
- });
- SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- // 上次采集到的SN
- //private string sn_S4_5出站接口 = string.Empty;
- /// <summary>
- /// [S4] 取放桁架 - S4_5出站接口
- /// </summary>
- private void S4_5出站接口(int plcNo, string stationCode, string stationName)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string stationNameStr = stationCode + stationName;
- string processItem = stationName; // 测试项目
- try
- {
- stopwatch1.Start();
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string supplierCode = ""; // 供应商代码
- string sn = (string)s4PLCData["d5ProductSN"]; // 产品SN(弹夹码)
- sn = sn.Replace("\0", "");
- string d5VehicleCode1 = (string)s4PLCData["d5VehicleCode1"]; // 载具1码(弹夹穴位1)
- string d5VehicleCode2 = (string)s4PLCData["d5VehicleCode2"]; // 载具2码(弹夹穴位2)
- string d5VehicleCode3 = (string)s4PLCData["d5VehicleCode3"]; // 载具3码(弹夹穴位3)
- string d5VehicleCode4 = (string)s4PLCData["d5VehicleCode4"]; // 载具4码(弹夹穴位4)
- string d5VehicleCode5 = (string)s4PLCData["d5VehicleCode5"]; // 载具5码(弹夹穴位5)
- string d5VehicleCode6 = (string)s4PLCData["d5VehicleCode6"]; // 载具6码(弹夹穴位6)
- string d5VehicleCode7 = (string)s4PLCData["d5VehicleCode7"]; // 载具7码(弹夹穴位7)
- string d5VehicleCode8 = (string)s4PLCData["d5VehicleCode8"]; // 载具8码(弹夹穴位8)
- string d5VehicleCode9 = (string)s4PLCData["d5VehicleCode9"]; // 载具9码(弹夹穴位9)
- string d5VehicleCode10 = (string)s4PLCData["d5VehicleCode10"]; // 载具10码(弹夹穴位10)
- string d5VehicleCode11 = (string)s4PLCData["d5VehicleCode11"]; // 载具11码(弹夹穴位11)
- string d5VehicleCode12 = (string)s4PLCData["d5VehicleCode12"]; // 载具12码(弹夹穴位12)
- string d5VehicleCode13 = (string)s4PLCData["d5VehicleCode13"]; // 载具13码(弹夹穴位13)
- string d5VehicleCode14 = (string)s4PLCData["d5VehicleCode14"]; // 载具14码(弹夹穴位14)
- string d5VehicleCode15 = (string)s4PLCData["d5VehicleCode15"]; // 载具15码(弹夹穴位15)
- int d5Result = (int)s4PLCData["d5Result"]; // 产品结果
- bool pass = d5Result == 1;
- List<TestItem> items1 = new List<TestItem>();
- items1.Add(new TestItem()
- {
- Parameter_name = "产品结果",
- Parameter_value = d5Result == 1 ? "OK" : "NG",
- Parameter_unit = ""
- });
- int result1 = 0;
- //int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
- // , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, d5VehicleCode1, "1");
- //int result = result1 == 1 ? 1 : (GlobalContext.IsSendProcessData ? 4 : 1);
- short result = result1 == 1 ? (short)1 : (short)3;
- stopwatch2.Start();
- // MES_Flag 为4MES报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2591, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d5MES_FLAG";
- writeToPLC_Flag.Adress = 2591;
- writeToPLC_Flag.Value = result;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Start();
- // MES_Flag 为4上位机报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d5MES_FLAG";
- writeToPLC_Flag.Adress = 2591;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S4] 取放桁架 - S4_5节拍接口
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S4_5节拍接口(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string resultStr = string.Empty;
- try
- {
- stopwatch1.Start();
- string oEEType = ((int)s4PLCData["d5OEEType"]).ToString(); // 节拍类型(plc写入)
- string d5OEEProductSN = (string)s4PLCData["d5OEEProductSN"]; // 载具SN
- d5OEEProductSN = d5OEEProductSN.Replace("\0", "");
- bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
- if (!actionBool)
- {
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 上位机;发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
- writeToPLC_Flag1.Adress = 2924;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- string d5OEEPartNo = string.Empty; // 物料码
- if (string.IsNullOrEmpty(d5OEEProductSN))
- {
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
- writeToPLC_Flag1.Adress = 2924;
- writeToPLC_Flag1.Value = (short)1;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- else
- { // 查产品SN
- d5OEEPartNo = "Test"; // ZS
- }
- short d5OEEMES_FLAG = 0;
- // 上传OEE
- (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d5OEEPartNo, d5OEEProductSN);
- d5OEEMES_FLAG = result.Item1;
- resultStr = result.Item2;
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2924, d5OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d5OEEMES_FLAG";
- writeToPLC_Flag.Adress = 2924;
- writeToPLC_Flag.Value = d5OEEMES_FLAG;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d5OEEMES_FLAG";
- writeToPLC_Flag.Adress = 2924;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- #endregion [S4] 取放桁架
- #endregion PLC4 刘果段
- #region PLC5 张超凡
- #region [S5] Tray盘下料装备
- /// <summary>
- /// S5工位的数据- 触发信号上次的值
- /// </summary>
- private Dictionary<string, object> s5PLCSignal_Old = new Dictionary<string, object>();
- /// <summary>
- /// S5工位的数据(含触发信号)
- /// </summary>
- private Dictionary<string, object> s5PLCData = new Dictionary<string, object>();
- /// <summary>
- /// S5工位的数据- 回写点位
- /// </summary>
- private Dictionary<string, WriteToPLC_Flag> s5PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
- /// <summary>
- /// [S5] Tray盘下料装备
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- private void ReadStation_S5(int plcNo)
- {
- // [S1] Tray盘上料装备
- // [S2] FCT
- // [S3] 值板机
- // [S4_1] 载具下线装备 [S4_5] 载具上线装备
- // [S5] Tray盘下料装备
- /// 上位机心跳
- /// 获取设备报警数据与状态信息
- string stationCode = "[S5]";
- string stationName = "Tray盘下料装备";
- string stationNameStr = stationCode + stationName;
- #region 创建字典
- // 触发信号字典 赋值
- s5PLCSignal_Old.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
- s5PLCSignal_Old.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
- s5PLCSignal_Old.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- s5PLCSignal_Old.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
- s5PLCSignal_Old.Add("e1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
- s5PLCSignal_Old.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
- s5PLCSignal_Old.Add("e1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
- // PLC数据字典 赋值
- s5PLCData.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
- s5PLCData.Add("e1MES_FLAG_Check", 0); // MES_FLAG
- s5PLCData.Add("e1ProductSN_Check", ""); //
- s5PLCData.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
- s5PLCData.Add("e1MES_FLAG", 0); // MES_FLAG
- s5PLCData.Add("e1ProductSN", ""); // 产品SN
- s5PLCData.Add("e1PartNo", ""); // 物料码
- s5PLCData.Add("e1Result", 0); // 产品结果
- s5PLCData.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- s5PLCData.Add("e1OEEMES_FLAG", 0); // MES_FLAG
- s5PLCData.Add("e1OEEProductSN", "");// 产品SN(载具SN)
- s5PLCData.Add("e1OEEType", 0); // 节拍类型(plc写入)
- s5PLCData.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
- s5PLCData.Add("e1AGVUpStart", 0); // AGV上料开始信号
- s5PLCData.Add("e1AGVUpEnd", 0); // AGV上料完成信号
- s5PLCData.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
- s5PLCData.Add("e1AGVDownStart", 0); // AGV下料开始信号
- s5PLCData.Add("e1AGVDownEnd", 0); // AGV下料完成信号
- #endregion 创建字典
- while (true)
- {
- try
- {
- if (!GlobalContext._IsCon_Funs5)
- {
- UpdatePLCMonitor(1, plcNo, 0);
- continue;
- }
- if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- stopwatch1.Start();
- /*
- stopwatch2.Start();
- #region 一次性读取所有数据
- int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
- int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 46);
- int[] datas = data1.Concat(data2).ToArray();
- s5PLCData["e1PLC_FLAG_Check"] = datas[2]; // 进站校验
- s5PLCData["e1MES_FLAG_Check"] = datas[3];
- int[] e1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
- s5PLCData["e1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(e1ProductSN_CheckData, 0, 40);
- s5PLCData["e1PLC_FLAG"] = datas[34]; // 出站接口
- s5PLCData["e1MES_FLAG"] = datas[35];
- int[] e1ProductSNData = datas.Skip(36).Take(20).ToArray();
- s5PLCData["e1ProductSN"] = ModbusClient.ConvertRegistersToString(e1ProductSNData, 0, 40);
- int[] e1PartNoData = datas.Skip(56).Take(20).ToArray();
- s5PLCData["e1PartNo"] = ModbusClient.ConvertRegistersToString(e1PartNoData, 0, 40);
- s5PLCData["e1Result"] = datas[76];
- s5PLCData["e1OEEPLC_FLAG"] = datas[87]; // 节拍接口
- s5PLCData["e1OEEMES_FLAG"] = datas[88];
- int[] e1OEEProductSNData = datas.Skip(89).Take(20).ToArray();
- s5PLCData["e1OEEProductSN"] = ModbusClient.ConvertRegistersToString(e1OEEProductSNData, 0, 40);
- s5PLCData["e1OEEType"] = datas[109];
- s5PLCData["e1AGVUpCall"] = datas[120]; // AGV上料
- s5PLCData["e1AGVUpStart"] = datas[121];
- s5PLCData["e1AGVUpEnd"] = datas[122];
- s5PLCData["e1AGVDownCall"] = datas[133]; // AGV下料
- s5PLCData["e1AGVDownStart"] = datas[134];
- s5PLCData["e1AGVDownEnd"] = datas[135];
- #endregion 一次性读取所有数据
- stopwatch2.Stop();
- #region 回写操作,写后清空flag
- PLCWriteData(Funs[plcNo], ref s5PLCData, ref s5PLCWriteData);
- #endregion 回写操作,写后清空flag
- #region 进站校验
- try
- {
- int e1PLC_FLAG_Check = (int)s5PLCData["e1PLC_FLAG_Check"];
- int e1MES_FLAG_Check = (int)s5PLCData["e1MES_FLAG_Check"];
- int e1PLC_FLAG_CheckOld = (int)s5PLCSignal_Old["e1PLC_FLAG_Check"];
- if (e1PLC_FLAG_Check != e1PLC_FLAG_CheckOld)
- {
- if (e1PLC_FLAG_Check == 1 && e1MES_FLAG_Check == 0) // 0->1
- Task.Run(() => S5进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
- else if (e1PLC_FLAG_Check == 0 && e1MES_FLAG_Check != 0)
- Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
- s5PLCSignal_Old["e1PLC_FLAG_Check"] = s5PLCData["e1PLC_FLAG_Check"];
- }
- }
- catch (Exception ex)
- {
- Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 进站校验
- */
- #region 出站接口
- try
- {
- int e1PLC_FLAG = (int)s5PLCData["e1PLC_FLAG"];
- int e1MES_FLAG = (int)s5PLCData["e1MES_FLAG"];
- int e1PLC_FLAGOld = (int)s5PLCSignal_Old["e1PLC_FLAG"];
- if (e1PLC_FLAG != e1PLC_FLAGOld)
- {
- if (e1PLC_FLAG == 1 && e1MES_FLAG == 0) // 0->1
- Task.Run(() => S5出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
- //else if (e1PLC_FLAG == 0 && e1MES_FLAG != 0)
- //Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)0);
- s5PLCSignal_Old["e1PLC_FLAG"] = s5PLCData["e1PLC_FLAG"];
- }
- }
- catch (Exception ex)
- {
- //Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)6); // 6代表上位机报警
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 出站接口
- #region 节拍接口
- try
- {
- int e1OEEPLC_FLAG = (int)s5PLCData["e1OEEPLC_FLAG"];
- int e1OEEMES_FLAG = (int)s5PLCData["e1OEEMES_FLAG"];
- int e1OEEPLC_FLAGOld = (int)s5PLCSignal_Old["e1OEEPLC_FLAG"];
- if (e1OEEPLC_FLAG != e1OEEPLC_FLAGOld)
- {
- if (e1OEEPLC_FLAG == 1 && e1OEEMES_FLAG == 0) // 0->1
- Task.Run(() => S5节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
- //else if (e1OEEPLC_FLAG == 0 && e1OEEMES_FLAG != 0)
- //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)0);
- s5PLCSignal_Old["e1OEEPLC_FLAG"] = s5PLCData["e1OEEPLC_FLAG"];
- }
- }
- catch (Exception ex)
- {
- //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 节拍接口
- #region AGV上料
- // AGV上料叫AGV信号
- try
- {
- int e1AGVUpCall = (int)s5PLCData["e1AGVUpCall"];
- int e1AGVUpCallOld = (int)s5PLCSignal_Old["e1AGVUpCall"];
- if (e1AGVUpCall != e1AGVUpCallOld)
- {
- if (e1AGVUpCall == 1) // 0->1
- Task.Run(() => S5AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
- s5PLCSignal_Old["e1AGVUpCall"] = s5PLCData["e1AGVUpCall"];
- }
- }
- catch (Exception ex)
- {
- //Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- // AGV上料完成信号
- try
- {
- int e1AGVUpEnd = (int)s5PLCData["e1AGVUpEnd"];
- int e1AGVUpEndOld = (int)s5PLCSignal_Old["e1AGVUpEnd"];
- if (e1AGVUpEnd != e1AGVUpEndOld)
- {
- if (e1AGVUpEnd == 1) // 0->1
- Task.Run(() => S5AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
- s5PLCSignal_Old["e1AGVUpEnd"] = s5PLCData["e1AGVUpEnd"];
- }
- }
- catch (Exception ex)
- {
- //Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion AGV上料
- #region AGV下料
- // AGV下料叫agv信号
- try
- {
- int e1AGVDownCall = (int)s5PLCData["e1AGVDownCall"];
- int e1AGVDownCallOld = (int)s5PLCSignal_Old["e1AGVDownCall"];
- if (e1AGVDownCall != e1AGVDownCallOld)
- {
- if (e1AGVDownCall == 1) // 0->1
- Task.Run(() => S5AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
- s5PLCSignal_Old["e1AGVDownCall"] = s5PLCData["e1AGVDownCall"];
- }
- }
- catch (Exception ex)
- {
- //Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- // AGV下料完成信号
- try
- {
- int e1AGVDownEnd = (int)s5PLCData["e1AGVDownEnd"];
- int e1AGVDownEndOld = (int)s5PLCSignal_Old["e1AGVDownEnd"];
- if (e1AGVDownEnd != e1AGVDownEndOld)
- {
- if (e1AGVDownEnd == 1) // 0->1
- Task.Run(() => S5AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
- s5PLCSignal_Old["e1AGVDownEnd"] = s5PLCData["e1AGVDownEnd"];
- }
- }
- catch (Exception ex)
- {
- // Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion AGV下料
- UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- stopwatch1.Stop();
- //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
- OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- }
- else
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- Funs[plcNo].Connect();
- }
- }
- catch (Exception ex)
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- //Funs[plcNo].ReConnect();
- }
- Thread.Sleep(IntervalReadPLC);
- }
- }
- /// <summary>
- /// [S5] Tray盘下料装备 - 进站校验
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S5进站校验(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- string sn = (string)s5PLCData["e1ProductSN_Check"]; // 产品SN(载具码)
- sn = sn.Replace("\0", "");
- // 获取产品SN By 载具码
- string partNo = string.Empty;
- // 产品SN(物料码)校验
- List<TestItem> item = new List<TestItem>();
- item.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = sn,
- });
- item.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "1",
- });
- stopwatch2.Start();
- int result = 0;
- //int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item);
- stopwatch2.Stop();
- short e1MES_FLAG_Check = (short)result;
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2003, e1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1MES_FLAG_Check";
- writeToPLC_Flag.Adress = 2003;
- writeToPLC_Flag.Value = e1MES_FLAG_Check;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1MES_FLAG_Check";
- writeToPLC_Flag.Adress = 2003;
- writeToPLC_Flag.Value = (short)6;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S5] Tray盘下料装备 - 出站接口
- /// </summary>
- /// <param name="plcNo"></param>
- /// <param name="stationCode"></param>
- /// <param name="stationName"></param>
- private void S5出站接口(int plcNo, string stationCode, string stationName)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string stationNameStr = stationCode + stationName;
- string processItem = stationName; // 测试项目
- try
- {
- stopwatch1.Start();
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string supplierCode = ""; // 供应商代码
- string sn = (string)s5PLCData["e1ProductSN"]; // 产品SN(载具SN码)
- sn = sn.Replace("\0", "");
- //string partNo = (string)s5PLCData["e1PartNo"]; // 物料码
- //partNo = partNo.Replace("\0", "");
- string partNo = string.Empty;
- int e1Result = (int)s5PLCData["e1Result"]; // 产品结果
- bool pass = e1Result == 1;
- List<TestItem> items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = sn,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "产品码",
- Parameter_value = partNo,
- Parameter_unit = ""
- });
- int result1 = 0;
- //int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
- //, workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, partNo, pass, sn, "1");
- //int result = result1 == 1 ? 1 : (GlobalContext.IsSendProcessData ? 4 : 1);
- short result = result1 == 1 ? (short)1 : (short)3;
- stopwatch2.Start();
- // MES_Flag 为MES报错
- // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- //Funs[plcNo].WriteMultipleRegisters<short>(2035, result); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1MES_FLAG";
- writeToPLC_Flag.Adress = 2035;
- writeToPLC_Flag.Value = result;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Start();
- // MES_Flag 为4上位机报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1MES_FLAG";
- writeToPLC_Flag.Adress = 2035;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S5] Tray盘下料装备 - 节拍接口
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S5节拍接口(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string resultStr = string.Empty;
- try
- {
- stopwatch1.Start();
- string oEEType = ((int)s5PLCData["e1OEEType"]).ToString(); // 节拍类型(plc写入)
- string e1OEEProductSN = (string)s5PLCData["e1OEEProductSN"]; // 载具SN
- e1OEEProductSN = e1OEEProductSN.Replace("\0", "");
- bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
- if (!actionBool)
- {
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
- writeToPLC_Flag1.Adress = 2088;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- string e1OEEPartNo = string.Empty; // 物料码
- if (string.IsNullOrEmpty(e1OEEProductSN))
- {
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
- writeToPLC_Flag1.Adress = 2088;
- writeToPLC_Flag1.Value = (short)1;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- else
- { // 查产品SN
- e1OEEPartNo = "Test"; // ZS
- }
- short e1OEEMES_FLAG = 0;
- // 上传OEE
- (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, e1OEEPartNo, e1OEEProductSN);
- e1OEEMES_FLAG = result.Item1;
- resultStr = result.Item2;
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2088, e1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1OEEMES_FLAG";
- writeToPLC_Flag.Adress = 2088;
- writeToPLC_Flag.Value = e1OEEMES_FLAG;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1OEEMES_FLAG";
- writeToPLC_Flag.Adress = 2088;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S5] Tray盘下料装备 - AGV上料叫agv
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S5AGV上料叫agv(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS 呼叫AGV
- short e1AGVUpCall = 2;
- stopwatch2.Start();
- // e1AGVUpCall
- //Funs[plcNo].WriteMultipleRegisters<short>(2120, e1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1AGVUpCall";
- writeToPLC_Flag.Adress = 2120;
- writeToPLC_Flag.Value = e1AGVUpCall;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // e1AGVUpCall
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1AGVUpCall";
- writeToPLC_Flag.Adress = 2120;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S5] Tray盘下料装备 - AGV上料完成
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S5AGV上料完成(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS AGV上料完成,让小车离开
- short e1AGVUpEnd = 2;
- stopwatch2.Start();
- // e1AGVUpEnd
- //Funs[plcNo].WriteMultipleRegisters<short>(2122, e1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1AGVUpEnd";
- writeToPLC_Flag.Adress = 2122;
- writeToPLC_Flag.Value = e1AGVUpEnd;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // e1AGVUpEnd
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1AGVUpEnd";
- writeToPLC_Flag.Adress = 2122;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S5] Tray盘下料装备 - AGV下料叫agv
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S5AGV下料叫agv(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS 呼叫AGV
- short e1AGVDownCall = 2;
- stopwatch2.Start();
- // e1AGVDownCall
- //Funs[plcNo].WriteMultipleRegisters<short>(2133, e1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1AGVDownCall";
- writeToPLC_Flag.Adress = 2133;
- writeToPLC_Flag.Value = e1AGVDownCall;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // e1AGVDownCall
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1AGVDownCall";
- writeToPLC_Flag.Adress = 2133;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S5] Tray盘下料装备 - AGV下料完成
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S5AGV下料完成(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS AGV上料完成,让小车离开
- short e1AGVDownEnd = 2;
- stopwatch2.Start();
- // e1AGVDownEnd
- //Funs[plcNo].WriteMultipleRegisters<short>(2135, e1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1AGVDownEnd";
- writeToPLC_Flag.Adress = 2135;
- writeToPLC_Flag.Value = e1AGVDownEnd;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // e1AGVDownEnd
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1AGVDownEnd";
- writeToPLC_Flag.Adress = 2135;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- #endregion [S5] Tray盘下料装备
- #endregion PLC5 张超凡
- /// <summary>
- /// [S6] 顶盖装配设备
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- private void ReadStation_S6(int plcNo)
- {
- string stationCode = "[S6]";
- string stationName = "顶盖装配设备";
- string stationNameStr = stationCode + stationName;
- string tagBaseName = "g_OP60_MES"; //标签变量名称
- string tagMesCommName = "mesCommToPC"; //标签变量名称
- string tagAgvCommName = "agvCommFrmPC";
- string tagBarsetName = "BarcodeSet";
- OP60_MesData_t stPLC_MesData; //PLC的MES数据
- (int, string) result;
- bool ProgressState = true;
- #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
- // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
- s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
- s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
- s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
- s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
- s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
- s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
- s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
- s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
- // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
- s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
- s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
- s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
- s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
- s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
- s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
- s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
- s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
- s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
- s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
- s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
- s1PLCData.Add("a1Result", 0); // 产品结果
- s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
- s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
- s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
- s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
- s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
- s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
- s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
- s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
- s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
- s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
- s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
- s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
- s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
- s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
- s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
- s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
- #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
- while (true)
- {
- try
- {
- if (!GlobalContext._IsCon_Funs1)
- {
- UpdatePLCMonitor(1, plcNo, 0);
- continue;
- }
- if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- stopwatch1.Start();
- stopwatch2.Start();
- #region 一次性读取所有数据
- // 一次性读取所有数据
- result = Funs[plcNo].Read_SingleTag<OP60_MesData_t>(tagBaseName, 1, out stPLC_MesData); //读取单个结构体数据
- if (result.Item1 != 0)
- {
- //richTextBox1.AppendText("\n" + strRet);
- }
- else
- {
- //richTextBox1.AppendText("\n" + "读取成功");
- }
- #endregion 一次性读取所有数据
- stopwatch2.Stop();
- #region 进站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation && ProgressState == true)
- {
- ProgressState = false;
- Task.Run(() => S6进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, out ProgressState));
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 进站
- #region 出站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation && ProgressState == true)
- {
- ProgressState = false;
- Task.Run(() => S6出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 进站
- UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- stopwatch1.Stop();
- OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- }
- else
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- Funs[plcNo].Connect(); // 重连
- }
- }
- catch (Exception ex)
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- }
- Thread.Sleep(IntervalReadPLC);
- }
- }
- /// <summary>
- /// [S6] 顶盖装配设备 - 进站
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- /// <param name="stPLC_MesData"></param>
- /// <param name="tagMesCommName"></param>
- private void S6进站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, out bool ProgressState)
- {
- int nRet = 0;
- string strRet = "";
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- ProgressState = true;
- try
- {
- stopwatch1.Start();
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
- string MachineId = GlobalContext.S6_MachineId; // 装备ID(可配置)
- string StationId = GlobalContext.S6_StationId; // 工位ID(可配置)
- // 产品SN(物料码)校验
- List<TestItem> item = new List<TestItem>();
- stopwatch2.Start();
- int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
- stopwatch2.Stop();
- //指令执行结果 1:OK 110:失败
- byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S6] 顶盖装配设备 - 出站接口
- /// </summary>
- private void S6出站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
- {
- ProgressState = true;
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string processItem = stationName; // 测试项目
- string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string supplierCode = ""; // 供应商代码
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
- string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
- string MachineId = GlobalContext.S6_MachineId; // 装备id(可配置) // ZS
- string StationId = GlobalContext.S6_StationId; // ⼯位ID(可配置) // ZS
- int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
- bool pass = a1Result == 1;
- List<TestItem> items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = CarrierBarcode,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "产品码",
- Parameter_value = mtltmrk,
- Parameter_unit = ""
- });
- ResponseMessage responseMessage = InsertOp60Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsTopCoverAsmOK, "", stPLC_MesData.mesData.nHaveTopCover, stPLC_MesData.mesData.fForceTopCover);
- if (!responseMessage.result)
- {
- AddMessage_Station(stationNameStr,LogType.Error, "OP60记录插入出错!");
- }
- //绑定PLC返回MES数据到本地
- int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
- , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId);
- byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
- stopwatch2.Start();
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-Write" + (result1 == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Start();
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{stationNameStr}]上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S7] 锁螺丝设备
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- private void ReadStation_S7(int plcNo)
- {
- string stationCode = "[S7]";
- string stationName = "锁螺丝设备";
- string stationNameStr = stationCode + stationName;
- string tagBaseName = "g_OP70_MES"; //标签变量名称
- string tagMesCommName = "mesCommToPC"; //标签变量名称
- string tagAgvCommName = "agvCommFrmPC";
- string tagBarsetName = "BarcodeSet";
- OP70_MesData_t stPLC_MesData; //PLC的MES数据
- (int, string) result;
- bool ProgressState = true;
- #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
- // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
- s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
- s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
- s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
- s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
- s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
- s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
- s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
- s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
- // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
- s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
- s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
- s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
- s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
- s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
- s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
- s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
- s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
- s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
- s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
- s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
- s1PLCData.Add("a1Result", 0); // 产品结果
- s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
- s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
- s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
- s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
- s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
- s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
- s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
- s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
- s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
- s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
- s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
- s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
- s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
- s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
- s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
- s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
- #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
- while (true)
- {
- try
- {
- if (!GlobalContext._IsCon_Funs1)
- {
- UpdatePLCMonitor(1, plcNo, 0);
- continue;
- }
- if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- stopwatch1.Start();
- stopwatch2.Start();
- #region 一次性读取所有数据
- // 一次性读取所有数据
- result = Funs[plcNo].Read_SingleTag<OP70_MesData_t>(tagBaseName, 1, out stPLC_MesData); //读取单个结构体数据
- if (result.Item1 != 0)
- {
- //richTextBox1.AppendText("\n" + strRet);
- }
- else
- {
- //richTextBox1.AppendText("\n" + "读取成功");
- }
- #endregion 一次性读取所有数据
- stopwatch2.Stop();
- #region 左边进站
- try
- {
- if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation && ProgressState == true)
- {
- ProgressState = false;
- Task.Run(() => S7左边进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, out ProgressState));
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 左边进站
- #region 左边出站
- try
- {
- if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation && ProgressState == true)
- {
- ProgressState = false;
- Task.Run(() => S7左边出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 左边出站
- #region 右边进站
- try
- {
- if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation && ProgressState == true)
- {
- ProgressState = false;
- Task.Run(() => S7右边进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, out ProgressState));
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 右边进站
- #region 右边出站
- try
- {
- if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation && ProgressState == true)
- {
- ProgressState = false;
- Task.Run(() => S7右边出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 右边出站
- UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- stopwatch1.Stop();
- OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- }
- else
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- Funs[plcNo].Connect(); // 重连
- }
- }
- catch (Exception ex)
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- }
- Thread.Sleep(IntervalReadPLC);
- }
- }
- /// <summary>
- /// [S7] 锁螺丝设备 - 左边进站
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- /// <param name="stPLC_MesData"></param>
- /// <param name="tagMesCommName"></param>
- private void S7左边进站(int plcNo, string stationNameStr, OP70_MesData_t stPLC_MesData, string tagMesCommName, out bool ProgressState)
- {
- int nRet = 0;
- string strRet = "";
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- ProgressState = true;
- try
- {
- stopwatch1.Start();
- string sn = (string)stPLC_MesData.Left.BarcodeSet.strProductBarcode; // 产品SN(物料码)
- string MachineId = GlobalContext.S7_MachineId; // 装备ID(可配置)
- string StationId = GlobalContext.S7_StationId; // 工位ID(可配置)
- // 产品SN(物料码)校验
- List<TestItem> item = new List<TestItem>();
- stopwatch2.Start();
- int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
- stopwatch2.Stop();
- //指令执行结果 1:OK 110:失败
- byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S7] 锁螺丝设备 - 左边出站接口
- /// </summary>
- private void S7左边出站(int plcNo, string stationNameStr, OP70_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
- {
- ProgressState = true;
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string processItem = stationName; // 测试项目
- string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string supplierCode = ""; // 供应商代码
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- string sn = (string)stPLC_MesData.Left.BarcodeSet.strProductBarcode; // 产品条码;
- string CarrierBarcode = (string)stPLC_MesData.Left.BarcodeSet.strCarrierBarcode; // 载具条码;
- string MachineId = GlobalContext.S7_MachineId; // 装备id(可配置) // ZS
- string StationId = GlobalContext.S7_StationId; // ⼯位ID(可配置) // ZS
- int a1Result = (int)stPLC_MesData.Left.iotData.testStatus; // 产品结果
- bool pass = a1Result == 1;
- List<TestItem> items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = CarrierBarcode,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "产品码",
- Parameter_value = mtltmrk,
- Parameter_unit = ""
- });
- 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());
- if (!responseMessage.result)
- {
- AddMessage_Station(stationNameStr, LogType.Error, "OP701记录插入出错!");
- }
- //绑定PLC返回MES数据到本地
- int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
- , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId);
- byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
- stopwatch2.Start();
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-Write" + (result1 == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Start();
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{stationNameStr}]上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S7] 锁螺丝设备 - 右边进站
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- /// <param name="stPLC_MesData"></param>
- /// <param name="tagMesCommName"></param>
- private void S7右边进站(int plcNo, string stationNameStr, OP70_MesData_t stPLC_MesData, string tagMesCommName, out bool ProgressState)
- {
- int nRet = 0;
- string strRet = "";
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- ProgressState = true;
- try
- {
- stopwatch1.Start();
- string sn = (string)stPLC_MesData.Right.BarcodeSet.strProductBarcode; // 产品SN(物料码)
- string MachineId = GlobalContext.S7_MachineId; // 装备ID(可配置)
- string StationId = GlobalContext.S7_StationId; // 工位ID(可配置)
- // 产品SN(物料码)校验
- List<TestItem> item = new List<TestItem>();
- stopwatch2.Start();
- int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
- stopwatch2.Stop();
- //指令执行结果 1:OK 110:失败
- byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S7] 锁螺丝设备 - 右边出站接口
- /// </summary>
- private void S7右边出站(int plcNo, string stationNameStr, OP70_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
- {
- ProgressState = true;
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string processItem = stationName; // 测试项目
- string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string supplierCode = ""; // 供应商代码
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- string sn = (string)stPLC_MesData.Right.BarcodeSet.strProductBarcode; // 产品条码;
- string CarrierBarcode = (string)stPLC_MesData.Right.BarcodeSet.strCarrierBarcode; // 载具条码;
- string MachineId = GlobalContext.S7_MachineId; // 装备id(可配置) // ZS
- string StationId = GlobalContext.S7_StationId; // ⼯位ID(可配置) // ZS
- int a1Result = (int)stPLC_MesData.Right.iotData.testStatus; // 产品结果
- bool pass = a1Result == 1;
- List<TestItem> items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = CarrierBarcode,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "产品码",
- Parameter_value = mtltmrk,
- Parameter_unit = ""
- });
- 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());
- if (!responseMessage.result)
- {
- AddMessage_Station(stationNameStr, LogType.Error, "OP702记录插入出错!");
- }
- //绑定PLC返回MES数据到本地
- int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
- , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId);
- byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
- stopwatch2.Start();
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-Write" + (result1 == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Start();
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{stationNameStr}]上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S8] 3D螺丝高度检测设备
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- private void ReadStation_S8(int plcNo)
- {
- string stationCode = "[S8]";
- string stationName = "3D螺丝高度检测设备";
- string stationNameStr = stationCode + stationName;
- string tagBaseName = "g_OP80_MES"; //标签变量名称
- string tagMesCommName = "mesCommToPC"; //标签变量名称
- string tagAgvCommName = "agvCommFrmPC";
- string tagBarsetName = "BarcodeSet";
- OP80_MesData_t stPLC_MesData; //PLC的MES数据
- (int, string) result;
- bool ProgressState = true;
- #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
- // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
- s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
- s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
- s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
- s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
- s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
- s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
- s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
- s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
- // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
- s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
- s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
- s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
- s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
- s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
- s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
- s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
- s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
- s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
- s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
- s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
- s1PLCData.Add("a1Result", 0); // 产品结果
- s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
- s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
- s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
- s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
- s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
- s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
- s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
- s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
- s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
- s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
- s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
- s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
- s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
- s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
- s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
- s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
- #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
- while (true)
- {
- try
- {
- if (!GlobalContext._IsCon_Funs1)
- {
- UpdatePLCMonitor(1, plcNo, 0);
- continue;
- }
- if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- stopwatch1.Start();
- stopwatch2.Start();
- #region 一次性读取所有数据
- // 一次性读取所有数据
- result = Funs[plcNo].Read_SingleTag<OP80_MesData_t>(tagBaseName, 1, out stPLC_MesData); //读取单个结构体数据
- if (result.Item1 != 0)
- {
- //richTextBox1.AppendText("\n" + strRet);
- }
- else
- {
- //richTextBox1.AppendText("\n" + "读取成功");
- }
- #endregion 一次性读取所有数据
- stopwatch2.Stop();
- #region 进站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation && ProgressState == true)
- {
- ProgressState = false;
- Task.Run(() => S8进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, out ProgressState));
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 进站
- #region 出站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation && ProgressState == true)
- {
- ProgressState = false;
- Task.Run(() => S8出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 进站
- UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- stopwatch1.Stop();
- OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- }
- else
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- Funs[plcNo].Connect(); // 重连
- }
- }
- catch (Exception ex)
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- }
- Thread.Sleep(IntervalReadPLC);
- }
- }
- /// <summary>
- /// [S8] 3D螺丝高度检测设备 - 进站
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- /// <param name="stPLC_MesData"></param>
- /// <param name="tagMesCommName"></param>
- private void S8进站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, out bool ProgressState)
- {
- int nRet = 0;
- string strRet = "";
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- ProgressState = true;
- try
- {
- stopwatch1.Start();
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
- string MachineId = GlobalContext.S8_MachineId; // 装备ID(可配置)
- string StationId = GlobalContext.S8_StationId; // 工位ID(可配置)
- // 产品SN(物料码)校验
- List<TestItem> item = new List<TestItem>();
- stopwatch2.Start();
- int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
- stopwatch2.Stop();
- //指令执行结果 1:OK 110:失败
- byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S8] 3D螺丝高度检测设备 - 出站接口
- /// </summary>
- private void S8出站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
- {
- ProgressState = true;
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string processItem = stationName; // 测试项目
- string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string supplierCode = ""; // 供应商代码
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
- string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
- string MachineId = GlobalContext.S8_MachineId; // 装备id(可配置) // ZS
- string StationId = GlobalContext.S8_StationId; // ⼯位ID(可配置) // ZS
- int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
- bool pass = a1Result == 1;
- List<TestItem> items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = CarrierBarcode,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "产品码",
- Parameter_value = mtltmrk,
- Parameter_unit = ""
- });
- //绑定PLC返回MES数据到本地
- int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
- , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId);
- byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
- stopwatch2.Start();
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-Write" + (result1 == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Start();
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{stationNameStr}]上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S9] 下料设备
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- private void ReadStation_S9(int plcNo)
- {
- string stationCode = "[S9]";
- string stationName = "下料设备";
- string stationNameStr = stationCode + stationName;
- string tagBaseName = "g_OP90_MES"; //标签变量名称
- string tagMesCommName = "mesCommToPC"; //标签变量名称
- string tagAgvCommName = "agvCommFrmPC";
- string tagBarsetName = "BarcodeSet";
- OP90_MesData_t stPLC_MesData; //PLC的MES数据
- (int, string) result;
- bool ProgressState = true;
- #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
- // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
- s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
- s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
- s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
- s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
- s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
- s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
- s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
- s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
- // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
- s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
- s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
- s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
- s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
- s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
- s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
- s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
- s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
- s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
- s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
- s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
- s1PLCData.Add("a1Result", 0); // 产品结果
- s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
- s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
- s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
- s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
- s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
- s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
- s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
- s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
- s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
- s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
- s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
- s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
- s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
- s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
- s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
- s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
- #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
- while (true)
- {
- try
- {
- if (!GlobalContext._IsCon_Funs1)
- {
- UpdatePLCMonitor(1, plcNo, 0);
- continue;
- }
- if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- stopwatch1.Start();
- stopwatch2.Start();
- #region 一次性读取所有数据
- // 一次性读取所有数据
- result = Funs[plcNo].Read_SingleTag<OP90_MesData_t>(tagBaseName, 1, out stPLC_MesData); //读取单个结构体数据
- if (result.Item1 != 0)
- {
- //richTextBox1.AppendText("\n" + strRet);
- }
- else
- {
- //richTextBox1.AppendText("\n" + "读取成功");
- }
- #endregion 一次性读取所有数据
- stopwatch2.Stop();
- #region 进站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation && ProgressState == true)
- {
- ProgressState = false;
- Task.Run(() => S9进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, out ProgressState));
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 进站
- #region 出站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation && ProgressState == true)
- {
- ProgressState = false;
- Task.Run(() => S9出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 进站
- UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- stopwatch1.Stop();
- OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- }
- else
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- Funs[plcNo].Connect(); // 重连
- }
- }
- catch (Exception ex)
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- }
- Thread.Sleep(IntervalReadPLC);
- }
- }
- /// <summary>
- /// [S9] 下料设备 - 进站
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- /// <param name="stPLC_MesData"></param>
- /// <param name="tagMesCommName"></param>
- private void S9进站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, out bool ProgressState)
- {
- int nRet = 0;
- string strRet = "";
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- ProgressState = true;
- try
- {
- stopwatch1.Start();
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
- string MachineId = GlobalContext.S9_MachineId; // 装备ID(可配置)
- string StationId = GlobalContext.S9_StationId; // 工位ID(可配置)
- // 产品SN(物料码)校验
- List<TestItem> item = new List<TestItem>();
- stopwatch2.Start();
- int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
- stopwatch2.Stop();
- //指令执行结果 1:OK 110:失败
- byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S9] 下料设备 - 出站接口
- /// </summary>
- private void S9出站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
- {
- ProgressState = true;
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string processItem = stationName; // 测试项目
- string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string supplierCode = ""; // 供应商代码
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
- string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
- string MachineId = GlobalContext.S9_MachineId; // 装备id(可配置) // ZS
- string StationId = GlobalContext.S9_StationId; // ⼯位ID(可配置) // ZS
- int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
- bool pass = a1Result == 1;
- List<TestItem> items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = CarrierBarcode,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "产品码",
- Parameter_value = mtltmrk,
- Parameter_unit = ""
- });
- //绑定PLC返回MES数据到本地
- int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
- , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId);
- byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
- stopwatch2.Start();
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-Write" + (result1 == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Start();
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{stationNameStr}]上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- #region 缓存读取到的PLC数据 与 需要写入的PLC数据
- /// <summary>
- /// PLC读取到的数据 -添加数据
- /// </summary>
- public static void SxPLCData_Add(ref Dictionary<string, object> sxPlcData, string newKey, object newValue)
- {
- if (sxPlcData.ContainsKey(newKey))
- sxPlcData[newKey] = newValue;
- else
- sxPlcData.Add(newKey, newValue);
- }
- /// <summary>
- /// PLC需要写入的数据 -添加数据
- /// </summary>
- public static void SxPLCWriteData_Add(ref Dictionary<string, WriteToPLC_Flag> sxPLCWriteData, string newKey, WriteToPLC_Flag newValue)
- {
- if (sxPLCWriteData.ContainsKey(newKey))
- sxPLCWriteData[newKey] = newValue;
- else
- sxPLCWriteData.Add(newKey, newValue);
- }
- /// <summary>
- /// PLC回写操作,写后清空flag
- /// </summary>
- /// <param name="modbusClient">modbus对象</param>
- /// <param name="pLCReadDatas">读取到的数据字典</param>
- /// <param name="pLCWriteDatas">需要写入的数据</param>
- public static void PLCWriteData(ModbusClientHelper modbusClient, ref Dictionary<string, object> pLCReadDatas, ref Dictionary<string, WriteToPLC_Flag> pLCWriteDataDic)
- {
- if (pLCWriteDataDic != null && pLCWriteDataDic.Count > 0)
- {
- List<WriteToPLC_Flag> pLCWriteDatas = pLCWriteDataDic.Values.ToList();
- for (int i = 0; i < pLCWriteDatas.Count; i++)
- {
- string mesFlagName = pLCWriteDatas[i].Name;
- int mesFlagAdress = pLCWriteDatas[i].Adress;
- short mesFlagValue = (short)pLCWriteDatas[i].Value; // short
- if (mesFlagValue != 0) // 不为0则证明需要写入结果信息
- {
- // 先回写数据
- List<WriteToPLC_Data> writeToPLCDatas = pLCWriteDatas[i].WriteToPLCDatas;
- for (int j = 0; j < writeToPLCDatas.Count; j++)
- {
- int mesDataAdress = writeToPLCDatas[j].Adress;
- PLCValueType mesDataType = writeToPLCDatas[j].ValueType;
- switch (mesDataType)
- {
- case PLCValueType.Short:
- short mesDataValueShort = (short)writeToPLCDatas[j].Value;
- modbusClient.WriteMultipleRegisters<short>(mesDataAdress, mesDataValueShort);
- break;
- case PLCValueType.String:
- string mesDataValueStr = (string)writeToPLCDatas[j].Value;
- int mesDataValueStrLength = writeToPLCDatas[j].ValueTypeStrLength;
- modbusClient.WriteMultipleRegisters<string>(mesDataAdress, mesDataValueStr, mesDataValueStrLength);
- break;
- }
- }
- // 再回写信号
- modbusClient.WriteMultipleRegisters<short>(mesFlagAdress, mesFlagValue);
- // 存储读取数据的字典
- pLCReadDatas[mesFlagName] = (int)mesFlagValue;
- // 存储写入数据的字典 - 清空写入值
- pLCWriteDatas[i].Value = (short)0;
- pLCWriteDataDic[mesFlagName] = pLCWriteDatas[i];
- }
- }
- }
- }
- /// <summary>
- /// 提交点检数据到MES - 取数据库中缓存的 点检数据
- /// </summary>
- /// <param name="no">3</param>
- /// <param name="stationCode">设备编号</param>
- /// <param name="stationNameStr">设备名称</param>
- /// <param name="plcOrder">车间订单号</param>
- private void SubmitOneCheckDataToMESByDB(int plcNo, int stationCode, string stationNameStr, string plcOrder)
- {
- try
- {
- /// [S2]FCT (2-上传点检数据;102-清空该工单该工单的所有点检项缓存)
- /// [S3]值板机 (3-上传点检数据;103-清空该工单该工单的所有点检项缓存)
- /// [S4]取放桁架 (4-上传点检数据;104-清空该工单该工单的所有点检项缓存)
- /// [S6]CCD检测 (6-上传点检数据;106-清空该工单该工单的所有点检项缓存)
- int result1 = 0;
- switch (stationCode)
- {
- case 2:
- case 3:
- case 4:
- case 6:
- result1 = SubmitToMESByDB(stationCode.ToString(), stationNameStr, plcOrder);
- break;
- case 102:
- result1 = ClearOneCheckDataByDB("2", stationNameStr, plcOrder);
- break;
- case 103:
- result1 = ClearOneCheckDataByDB("3", stationNameStr, plcOrder);
- break;
- case 104:
- result1 = ClearOneCheckDataByDB("4", stationNameStr, plcOrder);
- break;
- case 106:
- result1 = ClearOneCheckDataByDB("6", stationNameStr, plcOrder);
- break;
- default:
- // MES_Flag 为“6未找到正确设备编号”
- //Funs[plcNo].WriteMultipleRegisters<int>(2406, 6);
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!未找到需要点检的正确设备编号");
- return;
- }
- short result = result1 == 1 ? (short)1 : (short)2;
- //Funs[plcNo].WriteMultipleRegisters<int>(2406, result); // MES_Flag 为4MES报错
- WritePLCLog(LogType.Debug, $"PLC{plcNo}_PLC通知MES上传点检数据运行完毕!-Write" + (result == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- // MES_Flag 为2上位机报错
- //Funs[plcNo].WriteMultipleRegisters<int>(2406, 2);
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- }
- #endregion 缓存读取到的PLC数据 与 需要写入的PLC数据
- #region 日志
- #region 各工位定制日志(同步至PLC交互页面)
- /// <summary>
- /// 添加日志
- /// </summary>
- /// <param name="stationNameStr">工站名称</param>
- /// <param name="logType">日志类型</param>
- /// <param name="message">日志内容</param>
- /// <param name="snNumber">产品数字SN</param>
- public void AddMessage_Station(string stationNameStr, LogType logType, string message, string snNumber = "")
- {
- if (!(stationNameStr.Equals("获取设备报警数据与状态信息")
- && (message.Contains("更新整线运行数据完毕") || message.Contains("更新整线报警数据完毕"))
- ))
- {
- AddMessage(logType, message); // 首页展示+日志记录
- }
- PLCDBFormMessage plcMessage = new PLCDBFormMessage()
- {
- StationName = stationNameStr,
- SnNumber = snNumber,
- Message = message,
- CreateTime = DateTime.Now
- };
- // PLC交互页展示
- Task.Run(() =>
- {
- try
- {
- if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
- {
- Form_Main.formPLCDB.UpdateMessage(plcMessage);
- }
- }
- catch { }
- });
- }
- #endregion 各工位定制日志(同步至PLC交互页面)
- /// <summary>
- /// 添加日志
- /// </summary>
- /// <param name="logType">日志类型</param>
- /// <param name="message">日志内容</param>
- public void AddMessage(LogType logType, string message)
- {
- OnMessage(logType, message);
- string date = DateTime.Now.ToString("yyyy/MM/dd");
- string time = DateTime.Now.ToString("HH:mm:ss:fff");
- string msgShow = time + "--> " + message + "\r\n";
- this.BeginInvoke(new Action(() =>
- {
- systemLog.Rows.Insert(0, date, time, message);
- if (systemLog.Rows.Count >= 100)
- systemLog.Rows.RemoveAt(systemLog.Rows.Count - 1);
- }));
- }
- /// <summary>
- /// 添加日志-保存
- /// </summary>
- /// <param name="logType">日志类型</param>
- /// <param name="message">日志内容</param>
- private void OnMessage(LogType logType, string msg)
- {
- MessageEvent?.Invoke(logType, msg);
- }
- /// <summary>
- /// 保存PLC日志
- /// </summary>
- /// <param name="logType"></param>
- /// <param name="logValue"></param>
- private void WritePLCLog(LogType logType, string logValue)
- {
- switch ((int)logType)
- {
- case 0:
- _PLCLogNet.WriteDebug(logValue);
- break;
- case 1:
- _PLCLogNet.WriteInfo(logValue);
- break;
- case 2:
- _PLCLogNet.WriteWarn(logValue);
- break;
- case 3:
- _PLCLogNet.WriteError(logValue);
- break;
- default:
- _PLCLogNet.WriteFatal(logValue);
- break;
- }
- }
- #endregion 日志
- #region 保存数据
- /// <summary>
- /// 调用进站接口并保存进站数据
- /// </summary>
- /// <param name="stationNameStr">工站信息</param>
- /// <param name="workorder_code">工单号</param>
- /// <param name="mtltmrk">型号(物料号)</param>
- /// <param name="sn">产品SN</param>
- /// <param name="items">进站数据</param>
- /// <returns>1成功;5MES报警;6上位机报警</returns>
- public int SaveStationInData(string stationNameStr, string workorder_code, string mtltmrk, string sn, List<TestItem> items,string MachineId,string StationId)
- {
- int result = 0;
- XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
- inRequest_Body.machineId = MachineId; // 装备ID(可配置)
- inRequest_Body.stationId = StationId; // ⼯位ID(可配置)
- inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
- inRequest_Body.clientTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
- inRequest_Body.unitSn = sn; // 产品SN
- inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;非必填
- inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;非必填
- string json_Body = JsonConvert.SerializeObject(inRequest_Body);
- StationIn stationIn = new StationIn()
- {
- Workorder_code = workorder_code, // 车间订单号
- Mtltmrk = mtltmrk, // 产品型号(物料号)
- Sn = sn, // SN
- StationIn_body = json_Body, // 进站接口Json数据 - Body
- Parameter_values = items, // 进站数据
- Write_user = inRequest_Body.userId, // 员工Id
- Test_time = inRequest_Body.clientTime // 进站时间
- };
- // 本地数据
- string sql = stationIn.ToStringInsert(0);
- string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
- result = ret == "成功" ? 1 : 6;
- AddMessage_Station(stationNameStr, LogType.Info, string.Concat(stationNameStr, "_保存本地进站数据---" + ret));
- //await Task.Delay(200);
- // 上传MES
- if (GlobalContext.IsSendStationIn)
- {
- try
- {
- XmMES_StationInResponse response = new XmMES_StationInResponse();
- string mesRet = string.Empty;
- int i = 0;
- while (i < 2) // 1009会多次尝试上传
- {
- response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
- if (response != null && response.header.code == "200")
- break;
- else if (!mesRet.Contains("1009")) // 1009是未知错误
- i++;
- i++;
- mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
- // 记录失败原因
- OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + json_Body);
- }
- AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + "_上传进站数据到MES服务器---" + mesRet);
- if (response?.header?.code == "200")
- {
- string sql_Upd = stationIn.ToStringUpdateStatusByID(1);
- string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
- result = ret_Upd == "成功" ? 1 : 6;
- AddMessage_Station(stationNameStr, LogType.Info, $"更新【进站数据 id {stationIn.GUID}】上传状态---" + ret_Upd);
- }
- else
- {
- result = 5;
- OnMessage(LogType.Error, "上传进站数据到MES服务器---失败!接口报错信息:" + mesRet + "参数:" + json_Body);
- }
- }
- catch (Exception ex)
- {
- result = 6;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传进站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- }
- return result;
- }
- /// <summary>
- /// 选择如何记录出站数据
- /// </summary>
- /// <param name="items">出站数据</param>
- /// <param name="equipmentCode">设备编号</param>
- /// <param name="processItem">测试项目</param>
- /// <param name="workorder_code">车间订单号</param>
- /// <param name="batch_num">批次号</param>
- /// <param name="mtltmrk">型号</param>
- /// <param name="proDate">日期</param>
- /// <param name="supplierCode">供应商代码</param>
- /// <param name="sn_Number">产品序列号的 数字序列部分</param>
- /// <returns>上传成功时返回1;失败返回0</returns>
- private int SwitctProcessData(string stationNameStr, List<TestItem> items, string equipmentCode, string processItem,
- string workorder_code, string batch_num, string mtltmrk, string proDate,
- string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string MachineId, string StationId)
- {
- return SaveProcessDataByDB(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num, mtltmrk,
- proDate, supplierCode, sn, pass, vehicleSn, vehicleSlot, MachineId, StationId);
- }
- /// <summary>
- /// 添加出站数据(提交到MES+本地保存到数据库)
- /// </summary>
- /// <param name="items">出站数据</param>
- /// <param name="equipmentCode">设备编号</param>
- /// <param name="processItem">测试项目</param>
- /// <param name="workorder_code">车间订单号</param>
- /// <param name="batch_num">批次号</param>
- /// <param name="mtltmrk">型号</param>
- /// <param name="proDate">日期</param>
- /// <param name="supplierCode">供应商代码</param>
- /// <param name="sn_Number">产品序列号的 数字序列部分</param>
- /// <returns>上传成功时返回1;失败返回0</returns>
- public int SaveProcessDataByDB(string stationNameStr, List<TestItem> items, string equipmentCode,
- string processItem, string workorder_code, string batch_num, string mtltmrk,
- string proDate, string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot,string machineId,string stationId)
- {
- int upload = 0;
- int result = 0;
- ProcessData processData = new ProcessData()
- {
- Equipment_code = equipmentCode,
- Workorder_code = workorder_code,
- Batch_number = batch_num,
- Sn = sn, // SN
- Testitem = processItem,
- Parameter_values = items,
- Write_user = GlobalContext.CurrentUser,
- Test_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
- };
- // 本地数据
- string sql = processData.ToStringInsert(upload);
- string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
- AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地出站数据---" + ret));
-
- // 上传MES
- if (GlobalContext.IsSendProcessData)
- {
- try
- {
- string id = processData.ID.Copy();
- XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
- outRequest_Body.machineId = machineId; // 装备id(可配置) // ZS
- outRequest_Body.stationId = stationId; // ⼯位ID(可配置) // ZS
- outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
- outRequest_Body.clientTime = processData.Test_time; // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
- outRequest_Body.unitSn = sn; // 产品SN
- outRequest_Body.state = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL
- outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID;非必填
- outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id;非必填
- outRequest_Body.unitData.vehicleData.Add(
- new XmMES_StationOutRequest_Body.XmStationOut_VehicleData()
- {
- vehicleSn = vehicleSn,
- vehicleType = string.Empty,
- slot = vehicleSlot
- }); // 设备数据 - 载具信息
- string jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
- if (GlobalContext.IsSendProcessData)
- {
- XmMES_StationOutResponse response = new XmMES_StationOutResponse();
- string mesRet = string.Empty;
- int i = 0;
- while (i < 2) // 1009会多次尝试上传
- {
- response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
- if (response != null && response.header.code == "200")
- break;
- else if (!mesRet.Contains("1009")) // 1009是未知错误
- i++;
- i++;
- mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
- // 记录失败原因
- OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + jsonstr1);
- }
- AddMessage_Station(stationNameStr, LogType.Info, "[" + processItem + "]上传出站数据到MES服务器---" + mesRet);
- if (response?.header?.code == "200")
- {
- string sql_Upd = ProcessData.ToStringUpdateStatusByID(1, id);
- string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
- result = 1;
- AddMessage_Station(stationNameStr, LogType.Info, $"更新【出站数据 id {id}】上传状态---" + ret_Upd);
- }
- else
- {
- OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!接口报错信息:" + mesRet + "参数:" + jsonstr1);
- }
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传出站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- }
- return result;
- }
- /// <summary>
- /// 选择如何记录点检数据
- /// </summary>
- /// <param name="names"></param>
- /// <param name="contents"></param>
- /// <param name="results"></param>
- /// <param name="equipmentCode"></param>
- /// <param name="stationNameStr"></param>
- private int SwitctOneCheckData(OneCheckData oneCheckData, string equipmentCode, string stationNameStr)
- {
- //if (DataSwitch == 1)
- //{
- return SaveOneCheckDataByDB(oneCheckData, equipmentCode, stationNameStr);
- //}
- //else // 废弃
- //{
- // SaveOneCheckData(names, contents, results, equipmentCode, stationNameStr);
- //}
- }
- /// <summary>
- /// 添加点检数据ByDB(本地保存;不提交到MES)
- /// </summary>
- /// <param name="oneCheckData">点检数据</param>
- /// <param name="equipmentCode">设备编号</param>
- /// <param name="stationNameStr">工站名称</param>
- public int SaveOneCheckDataByDB(OneCheckData oneCheckData, string equipmentCode, string stationNameStr)
- {
- int upload = 0;
- //本地数据保存
- string sql = oneCheckData.ToStringInsert(upload);
- string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
- AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地点检数据---", ret));
- //Task.Run(() => // 上传mes-异步
- //{
- // //上传mes
- // string jsonstr = JsonConvert.SerializeObject(oneCheckData);
- // if (GlobalContext.IsSendCheckOneData)
- // {
- // string url = @"HTTP://" + GlobalContext.ServerHost + ":" + GlobalContext.ServerPort + @"/api/ProductionLine/OneCheckData";
- // string mesRet = HttpUitls.SubmitDataToMES(url, jsonstr);
- // AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]上传点检数据到MES---", mesRet));
- // if (mesRet == "成功")
- // {
- // // 更新上传状态
- // string sql_Upd = OneCheckData.ToStringUpdateStatusByID(1, oneCheckData.ID);
- // string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
- // AddMessage_Station(stationNameStr, LogType.Info, $"更新【点检数据 id {oneCheckData.ID}】上传状态---" + ret_Upd);
- // }
- // }
- //});
- return ret == "成功" ? 1 : 0;
- }
- /// <summary>
- /// 提交点检数据到MES
- /// </summary>
- /// <param name="procedure_code">工序编号 = 设备编号</param>
- /// <param name="plcOrder">车间订单号</param>
- /// <returns></returns>
- public int SubmitToMESByDB(string procedure_code, string stationNameStr, string plcOrder)
- {
- // 获取今天的点检数据
- string querySQL_Today = new OneCheckData().ToQuerySQL_Today(procedure_code, plcOrder);
- DataSet ds = SQLHelper_New.Query(querySQL_Today, null);
- if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
- {
- // 拼接所有点检数据
- OneCheckData oneCheckDatas_MES = new OneCheckData()
- {
- ID = ds.Tables[0].Rows[0][0].ToString(),
- Line_code = ds.Tables[0].Rows[0][1].ToString(),
- Line_name = ds.Tables[0].Rows[0][2].ToString(),
- Equipment_code = ds.Tables[0].Rows[0][3].ToString(),
- Equipment_name = ds.Tables[0].Rows[0][4].ToString(),
- Workorder_code = ds.Tables[0].Rows[0][5].ToString(),
- Procedure_code = ds.Tables[0].Rows[0][6].ToString(),
- Procedure_name = ds.Tables[0].Rows[0][7].ToString(),
- Onecheck_empcode = ds.Tables[0].Rows[0][8].ToString(),
- Onecheck_empname = ds.Tables[0].Rows[0][9].ToString(),
- Onecheck_time = ds.Tables[0].Rows[0][10].ToString()
- };
- List<string> upd_Ids = new List<string>();
- foreach (DataRow row in ds.Tables[0].Rows)
- {
- var obj1 = row["Oneckeck_values"];
- if (obj1 != null)
- {
- upd_Ids.Add(row["ID"].ToString());
- List<OneCheckItem> item = JsonConvert.DeserializeObject<List<OneCheckItem>>(obj1.ToString());
- oneCheckDatas_MES.Oneckeck_values.AddRange(item);
- }
- }
- //上传mes
- string jsonstr = JsonConvert.SerializeObject(oneCheckDatas_MES);
- if (GlobalContext.IsSendCheckOneData)
- {
- string url = @"HTTP://" + GlobalContext.ServerHost + ":" + @"/api/ProductionLine/OneCheckData";
- string mesRet = HttpUitls.SubmitDataToMES(url, jsonstr);
- AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[", stationNameStr, "]PLC通知上传点检数据到MES到---", mesRet));
- if (mesRet == "成功")
- {
- // 更新上传状态
- string sql_Upd = OneCheckData.ToStringUpdateStatusByIDs(1, upd_Ids);
- string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
- AddMessage_Station(stationNameStr, LogType.Info, $"更新【点检数据 id [{string.Join("','", upd_Ids)}]】上传状态---" + ret_Upd);
- // 保存最新一条点检数据 到文件中
- StandardLibrary.IniFile.INIWriteValue(GlobalContext.CheckOneDataPath, "S" + procedure_code, "WorkOrderCode", GlobalContext.WorkOrderCode);
- StandardLibrary.IniFile.INIWriteValue(GlobalContext.CheckOneDataPath, "S" + procedure_code, "Oneckeck_values", JsonConvert.SerializeObject(oneCheckDatas_MES.Oneckeck_values));
- return ret_Upd == "成功" ? 1 : 0;
- }
- }
- }
- //else
- //{
- // AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[", stationNameStr, "]PLC通知上传点检数据到MES---失败!今天还未点检。"));
- //}
- return 0;
- }
- /// <summary>
- /// 添加点检数据ByDB(本地保存 + 提交到MES)
- /// </summary>
- /// <param name="oneCheckData">点检数据</param>
- /// <param name="equipmentCode">设备编号</param>
- /// <param name="stationNameStr">工站名称</param>
- /// <returns></returns>
- public int SaveOneCheckDataByDBAndSubmit(OneCheckData oneCheckData, string equipmentCode, string stationNameStr)
- {
- int upload = 0;
- //本地数据保存
- string sql = oneCheckData.ToStringInsert(upload);
- string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
- AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地点检数据---", ret));
- Task.Run(() => // 上传mes-异步
- {
- //上传mes
- string jsonstr = JsonConvert.SerializeObject(oneCheckData);
- string jsonItems = JsonConvert.SerializeObject(oneCheckData.Oneckeck_values);
- if (GlobalContext.IsSendCheckOneData)
- {
- string url = @"HTTP://" + GlobalContext.ServerHost + ":" + @"/api/ProductionLine/OneCheckData";
- string mesRet = HttpUitls.SubmitDataToMES(url, jsonstr);
- AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]上传点检数据到MES---", mesRet));
- if (mesRet == "成功")
- {
- // 更新上传状态
- string sql_Upd = OneCheckData.ToStringUpdateStatusByID(1, oneCheckData.ID);
- string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
- AddMessage_Station(stationNameStr, LogType.Info, $"更新【点检数据 id {oneCheckData.ID}】上传状态---" + ret_Upd);
- // 保存最新一条点检数据 到文件中
- StandardLibrary.IniFile.INIWriteValue(GlobalContext.CheckOneDataPath, equipmentCode, "WorkOrderCode", GlobalContext.WorkOrderCode);
- StandardLibrary.IniFile.INIWriteValue(GlobalContext.CheckOneDataPath, equipmentCode, "Oneckeck_values", jsonItems);
- }
- }
- });
- return ret == "成功" ? 1 : 0;
- }
- /// <summary>
- /// 清空 点检数据 By 工序号、订单号
- /// </summary>
- /// <param name="procedure_code">工序号</param>
- /// <param name="stationNameStr">工站号</param>
- /// <param name="plcOrder">订单号</param>
- /// <returns></returns>
- /// <exception cref="NotImplementedException"></exception>
- private int ClearOneCheckDataByDB(string procedure_code, string stationNameStr, string plcOrder)
- {
- // 清空
- string sql_Det = OneCheckData.ToDeteleByProcedurecodeAndPlcOrder(procedure_code, plcOrder);
- string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Det, null);
- AddMessage_Station(stationNameStr, LogType.Info, $"清空【工位编号{procedure_code}】【车间订单{plcOrder}】的点检项缓存 ---" + ret_Upd);
- return ret_Upd == "成功" ? 1 : 2;
- }
- /// <summary>
- /// 生产过程中,自动判断 是否 使用上次的点检数据
- /// 在工单加工第一个产品时触发该方法
- /// 如果工单是上次的点检工单则直接返回成功,工单不是上次的点检工单则使用上个工单的点检数据,上传点检信息
- /// </summary>
- /// <param name="stationNameStr"></param>
- /// <param name="equipmentCode">设备编号</param>
- /// <param name="accno">工序编号</param>
- /// <param name="processItem">点检数据</param>
- /// <returns></returns>
- private int SwitctOneCheckData_First(string stationNameStr, string equipmentCode, string accno, string processItem)
- {
- string WorkOrderCode = StandardLibrary.IniFile.INIGetStringValue(GlobalContext.CheckOneDataPath, equipmentCode, "WorkOrderCode", string.Empty);
- //如果当前工单和记录中的工单是一致,表示这个工单是需要点检的,跳过
- //如果当前工单和记录中的工单是不一致,表示这个工单和上个工单是同型号的,可以使用上个工单的点检数据
- if (GlobalContext.WorkOrderCode == WorkOrderCode)
- {
- return 1;
- }
- //点检数据
- string Oneckeck_values = StandardLibrary.IniFile.INIGetStringValue(GlobalContext.CheckOneDataPath, equipmentCode, "Oneckeck_values", string.Empty);
- List<OneCheckItem> items = new List<OneCheckItem>();
- try
- {
- items = JsonConvert.DeserializeObject<List<OneCheckItem>>(Oneckeck_values);
- }
- catch (Exception ex)
- {
- return 0;
- }
- // 拼接所有点检数据
- OneCheckData oneCheckDatas_MES = new OneCheckData()
- {
- ID = Guid.NewGuid().ToString(),
- Line_code = GlobalContext.LineCode,
- Line_name = GlobalContext.LineName,
- Equipment_code = equipmentCode,
- Equipment_name = equipmentCode,
- Workorder_code = GlobalContext.WorkOrderCode,
- Procedure_code = accno,
- Procedure_name = processItem,
- Onecheck_empcode = "",
- Onecheck_empname = "",
- Onecheck_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"),
- Oneckeck_values = items
- };
- // 本地保存 + 提交到MES
- return SaveOneCheckDataByDBAndSubmit(oneCheckDatas_MES, equipmentCode, stationNameStr);
- }
- /// <summary>
- /// 添加报警数据ByDB(提交到MES+本地保存)
- /// </summary>
- /// <param name="alarmData">数据</param>
- /// <param name="isUpd">更新而不是新增</param>
- public void SaveAlarmDataByDB(string stationNameStr, AlarmData alarmData, bool isUpd)
- {
- if (isUpd)
- {
- string sql = alarmData.ToStringUpdate();
- SQLHelper_New.ExecuteSQL(sql, null);
- AddMessage_Station(stationNameStr, LogType.Info, "消除报警[" + alarmData.LineName + "-" + alarmData.AlarmDesc + "]完毕!");
- }
- else
- {
- string sql = alarmData.ToStringInsert();
- SQLHelper_New.ExecuteSQL(sql, null);
- AddMessage_Station(stationNameStr, LogType.Info, "发生了报警[" + alarmData.LineName + "-" + alarmData.AlarmDesc + "]!");
- }
- }
- /// <summary>
- /// 上传节拍数据
- /// </summary>
- /// <returns></returns>
- public (short, string) SaveOEEData(int plcNo, string stationNameStr, XiaomiDeviceOEE deviceOEE, string oEEPartNo, string oEEProductSN)
- {
- // 上传OEE
- if (GlobalContext.IsMqttStationInputBegin)
- {
- Task.Run(() =>
- {
- try
- {
- StationInputBeginRequest oee = new StationInputBeginRequest();
- oee.action = deviceOEE.ToString(); // 节拍动作(XiaomiDeviceOEE)
- oee.beat_tm = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 节拍发⽣时间
- oee.action_subject = oEEPartNo; // 该动作操作的⽬标对象(SN)
- oee.action_subject_parent = oEEProductSN; // ⼤板SN/载具SN
- oee.action_location = "ZS"; // ZS 该动作的位置信息(⼯位、槽位),如:F06-GSTPLA11_01-SLOT-01
- oee.action_material = string.Empty; // 该动作的物料信息
- oee.extra = string.Empty; // 额外信息
- oee.class_level_1 = string.Empty; // 分类层级1
- oee.class_level_2 = string.Empty; // 分类层级2
- oee.class_level_3 = string.Empty; // 分类层级3
- int result = XiaomiMqttClient_Extend.Write_StationInputBegin(oee);
- string msg = $"[{result}]";
- bool errCodeParse = Enum.TryParse(result.ToString(), out XiaomiMqttResponse_ErrCode errCode);
- msg += errCodeParse ? errCode.ToString() : "ERR_UNKOWN";
- AddMessage(LogType.Info, stationNameStr + $"_异步上传节拍接口;接口结果:-- {msg}");
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage(LogType.Error, $"PLC{plcNo}_{stationNameStr} 异步上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- });
- return ((short)1, "异步上传中!");
- }
- else
- return ((short)1, "未启用上传!");
- }
- /// <summary>
- /// 回调方法- With DataId
- /// </summary>
- /// <param name="id"></param>
- /// <param name="v"></param>
- /// <param name="dataId"></param>
- public void CallbackWithDataId(string id, string msg, string dataId)
- {
- //_MqttLogNet.WriteInfo("-------CallbackWithDataId-------");
- //byte[] buffer1 = Encoding.Default.GetBytes(v);
- //byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);
- //string strBuffer = Encoding.Default.GetString(buffer2, 0, buffer2.Length);
- //Console.WriteLine("{0} -> {1} {2}", id, strBuffer, dataId);
- string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
- _MqttLogNet.WriteInfo($"{datetime}-> [消息ID:{id}][事件ID:{dataId}]{msg}");
- }
- #endregion 保存数据
- #region UI刷新
- /// <summary>
- /// 更新商品信息的UI + 下发产品信息(SN)
- /// </summary>
- private void UpdateProductInfo()
- {
- currentBN.Text = GlobalContext.BatchNumber; // 批次号
- currentWC.Text = GlobalContext.WorkOrderCode; // 订单号
- currentMtltmrk.Text = GlobalContext.Mtltmrk; // 产品型号
- txt_CurSupplierCode.Text = ""; // 供应商代号
- // 下传给1号机,判断下plc对象数量
- //if (Funs.Count > 1)
- //{
- // DownLoadProductInfo(1);
- //}
- }
- /// <summary>
- /// 更新PLC连接状态的UI
- /// </summary>
- /// <param name="no">PLC编号</param>
- /// <param name="status">状态</param>
- private void UpdatePLCMonitor(int imgNo, int plcNo, int status)
- {
- if (this != null && !this.IsDisposed)
- {
- switch (imgNo)
- {
- case 1:
- this.BeginInvoke(new Action(() =>
- {
- pictureBox1.Image = imageListState.Images[status];
- }));
- break;
- case 2:
- this.BeginInvoke(new Action(() =>
- {
- pictureBox2.Image = imageListState.Images[status];
- }));
- break;
- case 3:
- this.BeginInvoke(new Action(() =>
- {
- pictureBox3.Image = imageListState.Images[status];
- }));
- break;
- case 4:
- this.BeginInvoke(new Action(() =>
- {
- pictureBox4.Image = imageListState.Images[status];
- }));
- break;
- case 5:
- this.BeginInvoke(new Action(() =>
- {
- pictureBox5.Image = imageListState.Images[status];
- }));
- break;
- case 6:
- this.BeginInvoke(new Action(() =>
- {
- pictureBox6.Image = imageListState.Images[status];
- }));
- break;
- case 7:
- this.BeginInvoke(new Action(() =>
- {
- pictureBox7.Image = imageListState.Images[status];
- }));
- break;
- case 8:
- this.BeginInvoke(new Action(() =>
- {
- pictureBox8.Image = imageListState.Images[status];
- }));
- break;
- case 9:
- this.BeginInvoke(new Action(() =>
- {
- pictureBox9.Image = imageListState.Images[status];
- }));
- break;
- default:
- break;
- }
- }
- Task.Run(() => // 更新PLC交互页的指示灯
- {
- try
- {
- if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
- {
- Form_Main.formPLCDB.UpdatePLCFunMonitor(plcNo, status);
- }
- }
- catch { }
- });
- }
- #endregion UI刷新
- /// <summary>
- /// 实例化报警字典
- /// </summary>
- private void InitalDicAlarm()
- {
- #region 第一个工站(这里未区分工位,所以下面出现的‘工位代码’使用‘线别代码’代替)
- List<Alarm> keyValues1 = new List<Alarm>
- {
- #region 第一组报警(电机)
- new Alarm { 报警类型 = "电机故障", 报警详情 = "料盘搬运_Y轴电机故障" ,关联的PLC地址 = 5100 },
- new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_X轴电机故障" ,关联的PLC地址 = 5101 },
- new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_Z轴电机故障" ,关联的PLC地址 = 5102 },
- new Alarm { 报警类型 = "电机故障", 报警详情 = "载具搬运_X轴电机故障" ,关联的PLC地址 = 5103 },
- new Alarm { 报警类型 = "电机故障", 报警详情 = "镭射_X轴电机故障" ,关联的PLC地址 = 5104 },
- new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_X轴电机故障" ,关联的PLC地址 = 5105 },
- new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_Z轴电机故障" ,关联的PLC地址 = 5106 },
- new Alarm { 报警类型 = "电机故障", 报警详情 = "下相机_X轴电机故障" ,关联的PLC地址 = 5107 },
- new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_Y轴电机故障" ,关联的PLC地址 = 5108 },
- new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_X轴电机故障" ,关联的PLC地址 = 5109 },
- #endregion 第一组报警(电机)
- #region 第二组报警(气缸)
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料进退气缸故障" ,关联的PLC地址 = 5200 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料升降气缸故障" ,关联的PLC地址 = 5201 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓顶升气缸故障" ,关联的PLC地址 = 5202 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体取料夹爪气缸故障" ,关联的PLC地址 = 5203 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料仓顶升气缸故障" ,关联的PLC地址 = 5204 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料平移气缸故障" ,关联的PLC地址 = 5205 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料升降气缸故障" ,关联的PLC地址 = 5206 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料夹爪气缸故障" ,关联的PLC地址 = 5207 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料旋转气缸故障" ,关联的PLC地址 = 5208 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装平移气缸故障" ,关联的PLC地址 = 5209 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装升降气缸故障" ,关联的PLC地址 = 5210 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装夹爪气缸故障" ,关联的PLC地址 = 5211 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装撑开气缸故障" ,关联的PLC地址 = 5212 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸1故障" ,关联的PLC地址 = 5213 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸2故障" ,关联的PLC地址 = 5214 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具下料移载气缸故障" ,关联的PLC地址 = 5215 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具侧推气缸故障" ,关联的PLC地址 = 5216 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具回流气缸故障" ,关联的PLC地址 = 5217 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2压料气缸故障" ,关联的PLC地址 = 5218 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2电测气缸故障" ,关联的PLC地址 = 5219 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2气密气缸故障" ,关联的PLC地址 = 5220 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3下压气缸故障" ,关联的PLC地址 = 5221 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3上顶气缸故障" ,关联的PLC地址 = 5222 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位5相机升降气缸故障" ,关联的PLC地址 = 5223 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组升降气缸故障" ,关联的PLC地址 = 5224 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸1故障" ,关联的PLC地址 = 5225 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸2故障" ,关联的PLC地址 = 5226 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "机械手夹爪气缸故障" ,关联的PLC地址 = 5227 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位4:镭射压料气缸故障" ,关联的PLC地址 = 5228 },
- #endregion 第二组报警(气缸)
- #region 第三组报警(其他故障)
- new Alarm { 报警类型 = "其他故障", 报警详情 = "上料处缺料报警" ,关联的PLC地址 = 5300 },
- new Alarm { 报警类型 = "其他故障", 报警详情 = "震盘缺料报警" ,关联的PLC地址 = 5301 },
- new Alarm { 报警类型 = "其他故障", 报警详情 = "成品仓料满报警" ,关联的PLC地址 = 5302 },
- new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照超时报警" ,关联的PLC地址 = 5303 },
- new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照NG报警" ,关联的PLC地址 = 5304 },
- new Alarm { 报警类型 = "其他故障", 报警详情 = "玻璃门打开报警" ,关联的PLC地址 = 5305 },
- #endregion 第三组报警(其他故障)
- };
- DicAlarms_Cur.Add(GlobalContext.LineCode, keyValues1); // 这里使用线体代替工位
- #endregion 第一个工站(这里使用线体代替工位)
- # region 第二个工站-原来的写法(废弃)
- //keyValues = new Dictionary<int, AlarmData[]>();
- ////1
- //dicAlarmName = new Dictionary<int, Alarm>();
- //dicAlarmName.Add(0, new Alarm { Name = "M01衬套组模组X电机报警" });
- //dicAlarmName.Add(1, new Alarm { Name = "M02衬套组模组Y电机报警" });
- //dicAlarmName.Add(2, new Alarm { Name = "M03衬套组模组Z电机报警" });
- //dicAlarmName.Add(3, new Alarm { Name = "M04衬套组模组U电机报警" });
- //dicAlarmName.Add(4, new Alarm { Name = "M05外流线皮带电机报警" });
- //alarmDatas = new AlarmData[dicAlarmName.Count];
- //for (int i = 0; i < dicAlarmName.Count; i++)
- //{
- // alarmDatas[i] = new AlarmData();
- // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
- // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
- // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
- // alarmDatas[i].AlarmType = 1;
- //}
- //keyValues.Add(1, alarmDatas);
- ////2
- //dicAlarmName = new Dictionary<int, Alarm>();
- //dicAlarmName.Add(0, new Alarm { Name = "C01定位气缸故障" });
- //dicAlarmName.Add(1, new Alarm { Name = "C02左推料气缸故障" });
- //dicAlarmName.Add(2, new Alarm { Name = "C03右推料气缸故障" });
- //dicAlarmName.Add(3, new Alarm { Name = "C04左压料气缸故障" });
- //dicAlarmName.Add(4, new Alarm { Name = "C05右压料气缸故障" });
- //dicAlarmName.Add(5, new Alarm { Name = "C06切料气缸故障" });
- //dicAlarmName.Add(6, new Alarm { Name = "C07左入料吹气气缸故障" });
- //dicAlarmName.Add(7, new Alarm { Name = "C08右入料吹气气缸故障" });
- //alarmDatas = new AlarmData[dicAlarmName.Count];
- //for (int i = 0; i < dicAlarmName.Count; i++)
- //{
- // alarmDatas[i] = new AlarmData();
- // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
- // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
- // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
- // alarmDatas[i].AlarmType = 2;
- //}
- //keyValues.Add(2, alarmDatas);
- ////3
- //dicAlarmName = new Dictionary<int, Alarm>();
- //dicAlarmName.Add(0, new Alarm { Name = "安全门报警" });
- //dicAlarmName.Add(1, new Alarm { Name = "联机通信故障" });
- //dicAlarmName.Add(2, new Alarm { Name = "连续NG报警" });
- //dicAlarmName.Add(3, new Alarm { Name = "合格率低于设定值报警" });
- //alarmDatas = new AlarmData[dicAlarmName.Count];
- //for (int i = 0; i < dicAlarmName.Count; i++)
- //{
- // alarmDatas[i] = new AlarmData();
- // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-3";
- // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
- // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
- // alarmDatas[i].AlarmType = 3;
- //}
- //keyValues.Add(3, alarmDatas);
- //DicAlarms.Add(2, keyValues);
- #endregion 第二个工站-原来的写法(废弃)
- }
- private void groupBox3_Enter(object sender, EventArgs e)
- {
- }
- }
- }
|