mainForm.cs 358 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Diagnostics.Eventing.Reader;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.IO.Ports;
  9. using System.Linq;
  10. using System.Reflection;
  11. using System.Runtime.InteropServices;
  12. using System.Runtime.InteropServices.ComTypes;
  13. using System.Text;
  14. using System.Text.RegularExpressions;
  15. using System.Threading;
  16. using System.Web;
  17. using System.Windows.Forms;
  18. using System.Xml.Linq;
  19. namespace Welling_Motor_Debug_Tool
  20. {
  21. public partial class mainForm : Form
  22. {
  23. #region 变量定义
  24. //版本号
  25. public static string Version = "2.1.7";
  26. //串口实例
  27. Serial_Process mySerialProcess = new Serial_Process();
  28. string PortNumSave = "";
  29. string PortBaudrateSave = "";
  30. //本地信息定义
  31. LocalInfo localInfo = new LocalInfo();
  32. //FTP实例
  33. ftp myFtp = new ftp();
  34. //MC运行信息超时计数
  35. bool MC_RunInfo_Refresh = false;
  36. ushort MC_RunInfo_Refresh_Cnt = 0;
  37. //MC调试信息超时计数
  38. bool MC_DebugInfo_Refresh = false;
  39. ushort MC_DebugInfo_Refresh_Cnt = 0;
  40. //MC故障码超时计数
  41. bool MC_ErrorCode_Refresh = false;
  42. ushort MC_ErrorCode_Refresh_Cnt = 0;
  43. //配置参数实例
  44. Params myParams = new Params();
  45. //记录文件名称
  46. string RunInfoSaveFilename = "";
  47. //BMS运行信息超时计数
  48. bool BMS_RunInfo_Refresh = false;
  49. ushort BMS_RunInfo_Refresh_Cnt = 0;
  50. //生产模式关机指令反馈状态
  51. bool PowerOffAckStatus = false;
  52. //登录窗口
  53. public static Login EnterForm1 = new Login();
  54. //生产配置文件信息
  55. ArrayList array_CfgInfo = new ArrayList();
  56. //写入参数返回标志和计数
  57. public bool WriteACK = false;
  58. public ushort WriteCnt = 0;
  59. public ushort ACK_WaitCnt = 0;
  60. //写入参数返回提示标志
  61. public bool ACK_DisFlag = true;
  62. //Boot版本信息
  63. public string BootInfo = "";
  64. //接收指令临时缓存,转string
  65. public string CmdRevStrTemp = "";
  66. //计时器,用于统计运行时间
  67. public Stopwatch stopwatch = new Stopwatch();
  68. //力矩传感器检验参数窗口
  69. public static TorqueParams TorqueParamsForm = new TorqueParams();
  70. //参数生成窗口
  71. public static GenerateParams GenerateParamsForm = new GenerateParams();
  72. //版本信息窗口
  73. public static Version VersionForm = new Version();
  74. //本机硬件信息
  75. public string Local_HdInformation = "";
  76. #endregion
  77. #region 故障日志结构体定义
  78. //故障日志记录信息 60 bytes,1K空间可以保存最近16条故障记录
  79. [StructLayout(LayoutKind.Sequential)]
  80. public struct MC_ErrorLogSaveInfo_Struct_t
  81. {
  82. public UInt16 Error_Index; //故障列表索引 2 bytes, 地址偏移 0
  83. public UInt16 NotesInfo1; //备注信息1,地址偏移 2
  84. public UInt16 NotesInfo2; //备注信息2,地址偏移 4
  85. public UInt16 NotesInfo3; //备注信息3,地址偏移 6
  86. public UInt32 ErrorCode; //故障码 4 bytes, 地址偏移 8
  87. public UInt32 RunTime; //运行时间 4bytes, 地址偏移 12
  88. //电机运行信息,占用空间32bytes
  89. [StructLayout(LayoutKind.Sequential)]
  90. public struct MC_RunInfo_Struct_t
  91. {
  92. public ushort BikeSpeed; //车速 0.1km/h,地址偏移0
  93. public ushort MotorSpeed; //输出转速 1rpm,地址偏移2
  94. public ushort Power; //电功率 1W,地址偏移4
  95. public ushort BusVoltage; //母线电压 1mV,地址偏移6
  96. public ushort BusCurrent; //母线电流 1mA,地址偏移8
  97. public byte Cadence; //踏频 1rpm,地址偏移10
  98. public byte Torque; //踩踏力矩 1Nm,地址偏移11
  99. public byte CadenceDir; //踩踏方向 0-正,1-反,2-停止,地址偏移12
  100. public byte GearSt; //助力档位,地址偏移13
  101. public byte LightSwitch; //灯开关 0xF0-关,0xF1-开,地址偏移14
  102. public byte SOC; //剩余电量 1%,地址偏移15
  103. public ushort RemainDistance; //续航里程 1km,地址偏移16
  104. public ushort Torque_AD; //力矩寄存器,地址偏移18
  105. public byte PowerPerKm; //平均功耗 0.01Ah/km ,地址偏移20
  106. public byte T_PCB; //PCB温度 +40℃,地址偏移21
  107. public byte T_Coil; //绕组温度 +40℃,地址偏移22
  108. public byte T_MCU; //MCU温度 +40℃,地址偏移23
  109. public ushort Ride_Km; //开机后骑行里程 0.1km, 地址偏移24
  110. public ushort Ride_Time; //开机后骑行时间 1s,地址偏移26
  111. public UInt32 RS; //预留 4bytes
  112. };
  113. [MarshalAs(UnmanagedType.Struct)]
  114. public MC_RunInfo_Struct_t RunInfo; //运行信息 32bytes, 地址偏移 16
  115. //控制变量
  116. public Int16 IqCurrent; //Pu, 地址偏移 48
  117. public Int16 IqVoltage; //Pu, 地址偏移 50
  118. public Int16 IdCurrent; //Pu, 地址偏移 52
  119. public Int16 IdVoltage; //Pu, 地址偏移 54
  120. //状态机
  121. public UInt16 FSM; //高到低依次表示系统状态机、二层状态机、电机状态机、助力状态机, 地址偏移 56
  122. //预留
  123. public UInt16 RS1;
  124. public UInt16 RS2;
  125. public UInt16 RS3;
  126. };
  127. #endregion
  128. #region 屏幕缩放比例获取
  129. public class PrimaryScreen
  130. {
  131. #region Win32 API
  132. [DllImport("user32.dll")]
  133. static extern IntPtr GetDC(IntPtr ptr);
  134. [DllImport("gdi32.dll")]
  135. static extern int GetDeviceCaps(
  136. IntPtr hdc, // handle to DC
  137. int nIndex // index of capability
  138. );
  139. [DllImport("user32.dll", EntryPoint = "ReleaseDC")]
  140. static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDc);
  141. #endregion
  142. #region DeviceCaps常量
  143. const int HORZRES = 8;
  144. const int VERTRES = 10;
  145. const int LOGPIXELSX = 88;
  146. const int LOGPIXELSY = 90;
  147. const int DESKTOPVERTRES = 117;
  148. const int DESKTOPHORZRES = 118;
  149. #endregion
  150. #region 属性
  151. /// <summary>
  152. /// 获取屏幕分辨率当前物理大小
  153. /// </summary>
  154. public static Size WorkingArea
  155. {
  156. get
  157. {
  158. IntPtr hdc = GetDC(IntPtr.Zero);
  159. Size size = new Size();
  160. size.Width = GetDeviceCaps(hdc, HORZRES);
  161. size.Height = GetDeviceCaps(hdc, VERTRES);
  162. ReleaseDC(IntPtr.Zero, hdc);
  163. return size;
  164. }
  165. }
  166. /// <summary>
  167. /// 当前系统DPI_X 大小 一般为96
  168. /// </summary>
  169. public static int DpiX
  170. {
  171. get
  172. {
  173. IntPtr hdc = GetDC(IntPtr.Zero);
  174. int DpiX = GetDeviceCaps(hdc, LOGPIXELSX);
  175. ReleaseDC(IntPtr.Zero, hdc);
  176. return DpiX;
  177. }
  178. }
  179. /// <summary>
  180. /// 当前系统DPI_Y 大小 一般为96
  181. /// </summary>
  182. public static int DpiY
  183. {
  184. get
  185. {
  186. IntPtr hdc = GetDC(IntPtr.Zero);
  187. int DpiX = GetDeviceCaps(hdc, LOGPIXELSY);
  188. ReleaseDC(IntPtr.Zero, hdc);
  189. return DpiX;
  190. }
  191. }
  192. /// <summary>
  193. /// 获取真实设置的桌面分辨率大小
  194. /// </summary>
  195. public static Size DESKTOP
  196. {
  197. get
  198. {
  199. IntPtr hdc = GetDC(IntPtr.Zero);
  200. Size size = new Size();
  201. size.Width = GetDeviceCaps(hdc, DESKTOPHORZRES);
  202. size.Height = GetDeviceCaps(hdc, DESKTOPVERTRES);
  203. ReleaseDC(IntPtr.Zero, hdc);
  204. return size;
  205. }
  206. }
  207. /// <summary>
  208. /// 获取宽度缩放百分比
  209. /// </summary>
  210. public static float ScaleX
  211. {
  212. get
  213. {
  214. IntPtr hdc = GetDC(IntPtr.Zero);
  215. int t = GetDeviceCaps(hdc, DESKTOPHORZRES);
  216. int d = GetDeviceCaps(hdc, HORZRES);
  217. float ScaleX = (float)GetDeviceCaps(hdc, DESKTOPHORZRES) / (float)GetDeviceCaps(hdc, HORZRES);
  218. ReleaseDC(IntPtr.Zero, hdc);
  219. return ScaleX;
  220. }
  221. }
  222. /// <summary>
  223. /// 获取高度缩放百分比
  224. /// </summary>
  225. public static float ScaleY
  226. {
  227. get
  228. {
  229. IntPtr hdc = GetDC(IntPtr.Zero);
  230. float ScaleY = (float)(float)GetDeviceCaps(hdc, DESKTOPVERTRES) / (float)GetDeviceCaps(hdc, VERTRES);
  231. ReleaseDC(IntPtr.Zero, hdc);
  232. return ScaleY;
  233. }
  234. }
  235. #endregion
  236. }
  237. #endregion
  238. public mainForm()
  239. {
  240. InitializeComponent();
  241. System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
  242. stopwatch.Start();
  243. //端口初始化
  244. mySerialProcess.Init();
  245. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  246. //检查备忘录文件
  247. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.NoteFileName))
  248. {
  249. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.NoteFileName, "");
  250. }
  251. //检查文件夹
  252. if (!Directory.Exists(localInfo.LocalPath))
  253. {
  254. Directory.CreateDirectory(localInfo.LocalPath);
  255. }
  256. if (!Directory.Exists(localInfo.LocalDataPath))
  257. {
  258. Directory.CreateDirectory(localInfo.LocalDataPath);
  259. }
  260. if (!Directory.Exists(localInfo.ToolsPath))
  261. {
  262. Directory.CreateDirectory(localInfo.ToolsPath);
  263. }
  264. if (!Directory.Exists(localInfo.LocalPath + localInfo.CfgPathName))
  265. {
  266. Directory.CreateDirectory(localInfo.LocalPath + localInfo.CfgPathName);
  267. }
  268. //检查配置文件
  269. if (File.Exists(localInfo.LocalPath + localInfo.ConfigFileName)) //存在配置文件,导入配置信息
  270. {
  271. //打开文件
  272. StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.ConfigFileName);
  273. string sLine = "";
  274. ArrayList array_CfgInfo = new ArrayList();
  275. array_CfgInfo.Clear();
  276. while (sLine != null)
  277. {
  278. sLine = objReader.ReadLine();
  279. array_CfgInfo.Add(sLine);
  280. }
  281. objReader.Close();
  282. //解析配置文件
  283. try
  284. {
  285. //Port Set
  286. PortNumSave = array_CfgInfo[1].ToString().Split(':')[1];
  287. PortBaudrateSave = array_CfgInfo[2].ToString().Split(':')[1];
  288. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.IndexOf(PortNumSave);
  289. toolStripComboBox_Baudrate.SelectedIndex = toolStripComboBox_Baudrate.Items.IndexOf(PortBaudrateSave);
  290. 连接开机ToolStripMenuItem.Checked = (array_CfgInfo[3].ToString().Split(':')[1] == "True");
  291. 断开关机ToolStripMenuItem.Checked = (array_CfgInfo[4].ToString().Split(':')[1] == "True");
  292. 识别通讯盒ToolStripMenuItem.Checked = (array_CfgInfo[5].ToString().Split(':')[1] == "True");
  293. //Option
  294. 写入存储ToolStripMenuItem.Checked = (array_CfgInfo[8].ToString().Split(':')[1] == "True");
  295. 允许ToolStripMenuItem.Checked = (array_CfgInfo[9].ToString().Split(':')[1] == "True");
  296. 不允许ToolStripMenuItem.Checked = (array_CfgInfo[9].ToString().Split(':')[1] == "False");
  297. if (array_CfgInfo[9].ToString().Split(':')[1] == "False")
  298. {
  299. checkBox_OffLineFacMode.Checked = false;
  300. checkBox_OffLineFacMode.Enabled = false;
  301. checkBox_OffLineCheckMode.Checked = false;
  302. checkBox_OffLineCheckMode.Enabled = false;
  303. }
  304. else
  305. {
  306. checkBox_OffLineFacMode.Checked = true;
  307. checkBox_OffLineFacMode.Enabled = true;
  308. checkBox_OffLineCheckMode.Checked = true;
  309. checkBox_OffLineCheckMode.Enabled = true;
  310. }
  311. //Server Set
  312. toolStripTextBox_ServerIP.Text = array_CfgInfo[12].ToString().Split(':')[1];
  313. toolStripTextBox_ServerPort.Text = array_CfgInfo[13].ToString().Split(':')[1];
  314. toolStripTextBox_ServerUser.Text = array_CfgInfo[14].ToString().Split(':')[1];
  315. toolStripTextBox_ServerPasswd.Text = array_CfgInfo[15].ToString().Split(':')[1];
  316. toolStripTextBox_ServerPath.Text = array_CfgInfo[16].ToString().Split(':')[1];
  317. //MacInfo
  318. toolStripTextBox_MAC.Text = array_CfgInfo[19].ToString().Split(':')[1];
  319. toolStripTextBoxMACAddr.Text = array_CfgInfo[20].ToString().Split(':')[1];
  320. toolStripTextBox_MACDate.Text = DateTime.Now.ToString("yyyyMMdd");
  321. toolStripTextBox_MACPD.Text = array_CfgInfo[22].ToString().Split(':')[1];
  322. //Log Address
  323. textBox_LogAddrBegin.Text = array_CfgInfo[25].ToString().Split(':')[1];
  324. textBox_LogAddrEnd.Text = array_CfgInfo[26].ToString().Split(':')[1];
  325. //电机类型
  326. 中置电机ToolStripMenuItem.Checked = (array_CfgInfo[29].ToString().Split(':')[1] == "True");
  327. 轮毂电机ToolStripMenuItem.Checked = !中置电机ToolStripMenuItem.Checked;
  328. //检测阈值
  329. toolStripTextBox_ThVol.Text = array_CfgInfo[33].ToString().Split(':')[1];
  330. toolStripTextBox_ThCur.Text = array_CfgInfo[34].ToString().Split(':')[1];
  331. toolStripTextBox_ThSpeed.Text = array_CfgInfo[35].ToString().Split(':')[1];
  332. toolStripTextBox_ThTor.Text = array_CfgInfo[36].ToString().Split(':')[1];
  333. toolStripTextBox_ThCad.Text = array_CfgInfo[37].ToString().Split(':')[1];
  334. toolStripTextBox_ThBikeSpeed.Text = array_CfgInfo[38].ToString().Split(':')[1];
  335. toolStripTextBox_ThT_PCB.Text = array_CfgInfo[39].ToString().Split(':')[1];
  336. toolStripTextBox_ThT_MCU.Text = array_CfgInfo[40].ToString().Split(':')[1];
  337. toolStripTextBox_ThT_Motor.Text = array_CfgInfo[41].ToString().Split(':')[1];
  338. }
  339. catch (System.Exception)
  340. {
  341. timer_1s.Enabled = false;
  342. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  343. timer_1s.Enabled = true;
  344. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  345. }
  346. }
  347. else //不存在配置文件,生成文件写入默认值
  348. {
  349. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  350. }
  351. //获取本机信息,读取时间较长,优先从本地文件获取
  352. do
  353. {
  354. try
  355. {
  356. //本地文件为空,读取信息保存
  357. if (!File.Exists(localInfo.LocalPath + localInfo.PC_InfoFileName))
  358. {
  359. Local_HdInformation = "";
  360. Local_HdInformation += "计算机名称: " + System.Environment.UserName + "\r\n";
  361. Local_HdInformation += "IP地址: " + PC_Information.GetIpAddress() + "\r\n";
  362. Local_HdInformation += "系统ID: " + PC_Information.GetSystemID() + "\r\n";
  363. Local_HdInformation += "操作系统类型: " + PC_Information.GetSystemType() + "\r\n";
  364. Local_HdInformation += "主板型号: " + PC_Information.GetBoardType() + "\r\n";
  365. Local_HdInformation += "主板厂商: " + PC_Information.GetBoardManufacturer() + "\r\n";
  366. Local_HdInformation += "主板ID: " + PC_Information.GetBIOSSerialNumber() + "\r\n";
  367. Local_HdInformation += "CPU型号: " + PC_Information.GetCpuName() + "\r\n";
  368. Local_HdInformation += "CPU厂商: " + PC_Information.GetCpuManufacturer() + "\r\n";
  369. Local_HdInformation += "CPU ID: " + PC_Information.GetCPUSerialNumber() + "\r\n";
  370. Local_HdInformation += "内存容量: " + PC_Information.GetPhysicalMemory() + " GB" + "\r\n";
  371. Local_HdInformation += "硬盘容量: " + PC_Information.GetDiskCapacity() + "\r\n";
  372. Local_HdInformation += "MAC ID: " + PC_Information.GetNetCardMACAddress().Replace(":", "-") + "\r\n";
  373. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.PC_InfoFileName, Local_HdInformation);
  374. }
  375. //从本地读取,计算机名和IP地址重新读
  376. else
  377. {
  378. Local_HdInformation = "";
  379. string[] fileInfo = File.ReadAllLines(localInfo.LocalPath + localInfo.PC_InfoFileName, Encoding.UTF8);
  380. fileInfo[0] = "计算机名称: " + System.Environment.UserName;
  381. fileInfo[1] = "IP地址: " + PC_Information.GetIpAddress();
  382. for (int i = 0; i < fileInfo.Length; i++)
  383. Local_HdInformation += fileInfo[i] + "\r\n";
  384. File.Delete(localInfo.LocalPath + localInfo.PC_InfoFileName);
  385. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.PC_InfoFileName, Local_HdInformation);
  386. }
  387. }
  388. catch(Exception)
  389. {
  390. }
  391. } while (false);
  392. //系统登录
  393. do
  394. {
  395. EnterForm1.ShowDialog();
  396. try
  397. {
  398. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  399. {
  400. if (EnterForm1.comboBox_User.Text.Contains("量产"))
  401. {
  402. //隐藏设置项
  403. 其它配置项ToolStripMenuItem.Visible = false;
  404. 写入存储ToolStripMenuItem.Visible = false;
  405. 离线使用ToolStripMenuItem.Visible = false;
  406. 服务器配置ToolStripMenuItem.Visible = false;
  407. 判断阈值ToolStripMenuItem.Visible = false;
  408. 力矩传感器检验ToolStripMenuItem.Visible = false;
  409. //显示生产信息
  410. 生产信息ToolStripMenuItem.Visible = true;
  411. //显示电机类型,但不可编辑
  412. 电机类型ToolStripMenuItem.Visible = true;
  413. 中置电机ToolStripMenuItem.Enabled = false;
  414. 轮毂电机ToolStripMenuItem.Enabled = false;
  415. //隐藏研发调试界面
  416. tabPage_MotorParam.Parent = null;
  417. tabPage_BikeParam.Parent = null;
  418. tabPage_ControlParam.Parent = null;
  419. tabPage_SensorParam.Parent = null;
  420. tabPage_AssistParam.Parent = null;
  421. tabPage_DebugParam.Parent = null;
  422. tabPage_RecordInfo.Parent = null;
  423. tabPage_OtherInfo.Parent = null;
  424. tabPage_OBC.Parent = null;
  425. tabPage_RAMorFLASH.Parent = null;
  426. tabPage_FactoryMode.Parent = null;
  427. tabPage_DebugInfo.Parent = null;
  428. //显示运行信息
  429. tabPage_RunInfo.Parent = tabControl2;
  430. //根据电机类型修改生产信息和电机类型
  431. if (EnterForm1.comboBox_User.Text.Contains("中置"))
  432. {
  433. 中置电机ToolStripMenuItem.Checked = true;
  434. 轮毂电机ToolStripMenuItem.Checked = false;
  435. toolStripTextBox_MACPD.Text = "MM_MC1";
  436. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  437. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  438. }
  439. else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
  440. {
  441. 中置电机ToolStripMenuItem.Checked = false;
  442. 轮毂电机ToolStripMenuItem.Checked = true;
  443. toolStripTextBox_MACPD.Text = "GF_250_1";
  444. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  445. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  446. }
  447. //显示对应生产测试界面
  448. if (EnterForm1.comboBox_User.Text.Contains("写入"))
  449. {
  450. tabPage_ProductMode_Write.Parent = tabControl1;
  451. tabPage_ProductMode_Write.Select();
  452. tabPage_ProductMode_Read.Parent = null;
  453. }
  454. else if (EnterForm1.comboBox_User.Text.Contains("检验"))
  455. {
  456. tabPage_ProductMode_Read.Parent = tabControl1;
  457. tabPage_ProductMode_Read.Select();
  458. tabPage_ProductMode_Write.Parent = null;
  459. }
  460. //应答指令不提示
  461. ACK_DisFlag = false;
  462. //退出登录
  463. break;
  464. }
  465. else if (EnterForm1.comboBox_User.Text == "工程参数配置")
  466. {
  467. //隐藏工作台内容,新建窗口完成配置
  468. groupBox1.Visible = false;
  469. groupBox3.Visible = false;
  470. tabControl2.Visible = false;
  471. //隐藏提示信息
  472. label_StarInfo.Visible = false;
  473. //打开参数配置框
  474. GenerateParamsForm.ShowDialog();
  475. System.Environment.Exit(0);
  476. //退出登录
  477. break;
  478. }
  479. else if (EnterForm1.comboBox_User.Text.Contains("样机"))
  480. {
  481. //隐藏量产界面
  482. tabPage_ProductMode_Read.Parent = null;
  483. tabPage_ProductMode_Write.Parent = null;
  484. //隐藏配置项
  485. 其它配置项ToolStripMenuItem.Visible = false;
  486. 离线使用ToolStripMenuItem.Visible = false;
  487. 服务器配置ToolStripMenuItem.Visible = false;
  488. 判断阈值ToolStripMenuItem.Visible = false;
  489. 力矩传感器检验ToolStripMenuItem.Visible = false;
  490. //显示生产信息
  491. 生产信息ToolStripMenuItem.Visible = true;
  492. //显示电机类型,但不可编辑
  493. 电机类型ToolStripMenuItem.Visible = true;
  494. 中置电机ToolStripMenuItem.Enabled = true;
  495. 轮毂电机ToolStripMenuItem.Enabled = true;
  496. if (EnterForm1.comboBox_User.Text.Contains("中置"))
  497. {
  498. 中置电机ToolStripMenuItem.Checked = true;
  499. 轮毂电机ToolStripMenuItem.Checked = false;
  500. toolStripTextBox_MACPD.Text = "MM_MC1";
  501. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  502. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  503. }
  504. else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
  505. {
  506. 中置电机ToolStripMenuItem.Checked = false;
  507. 轮毂电机ToolStripMenuItem.Checked = true;
  508. toolStripTextBox_MACPD.Text = "GF_250_1";
  509. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  510. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  511. }
  512. //退出登录
  513. break;
  514. }
  515. else if (EnterForm1.comboBox_User.Text == "FCT治具测试")
  516. {
  517. //隐藏设置项
  518. 其它配置项ToolStripMenuItem.Visible = false;
  519. 写入存储ToolStripMenuItem.Visible = false;
  520. 离线使用ToolStripMenuItem.Visible = false;
  521. 服务器配置ToolStripMenuItem.Visible = false;
  522. 判断阈值ToolStripMenuItem.Visible = false;
  523. 力矩传感器检验ToolStripMenuItem.Visible = false;
  524. //显示生产信息
  525. 生产信息ToolStripMenuItem.Visible = true;
  526. //显示电机类型,但不可编辑
  527. 电机类型ToolStripMenuItem.Visible = true;
  528. 中置电机ToolStripMenuItem.Enabled = true;
  529. 轮毂电机ToolStripMenuItem.Enabled = true;
  530. //隐藏研发调试界面
  531. tabPage_MotorParam.Parent = null;
  532. tabPage_BikeParam.Parent = null;
  533. tabPage_ControlParam.Parent = null;
  534. tabPage_SensorParam.Parent = null;
  535. tabPage_AssistParam.Parent = null;
  536. tabPage_DebugParam.Parent = null;
  537. tabPage_RecordInfo.Parent = null;
  538. tabPage_OtherInfo.Parent = null;
  539. tabPage_OBC.Parent = null;
  540. tabPage_RAMorFLASH.Parent = null;
  541. tabPage_FactoryMode.Parent = null;
  542. tabPage_DebugInfo.Parent = null;
  543. //显示运行信息
  544. tabPage_RunInfo.Parent = tabControl2;
  545. //根据电机类型修改生产信息和电机类型
  546. if (EnterForm1.comboBox_User.Text.Contains("中置"))
  547. {
  548. 中置电机ToolStripMenuItem.Checked = true;
  549. 轮毂电机ToolStripMenuItem.Checked = false;
  550. toolStripTextBox_MACPD.Text = "MM_MC1";
  551. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  552. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  553. }
  554. else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
  555. {
  556. 中置电机ToolStripMenuItem.Checked = false;
  557. 轮毂电机ToolStripMenuItem.Checked = true;
  558. toolStripTextBox_MACPD.Text = "GF_250_1";
  559. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  560. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  561. }
  562. //显示量产测试界面
  563. tabPage_ProductMode_Write.Parent = tabControl1;
  564. tabPage_ProductMode_Write.Select();
  565. tabPage_ProductMode_Read.Parent = null;
  566. //允许离线使用
  567. 允许ToolStripMenuItem.Checked = true;
  568. 不允许ToolStripMenuItem.Checked = false;
  569. checkBox_OffLineFacMode.Checked = true;
  570. checkBox_OffLineFacMode.Enabled = true;
  571. checkBox_OffLineCheckMode.Checked = true;
  572. checkBox_OffLineCheckMode.Enabled = true;
  573. //应答指令不提示
  574. ACK_DisFlag = false;
  575. //退出登录
  576. break;
  577. }
  578. else if (EnterForm1.comboBox_User.Text == "研发调试")
  579. {
  580. //隐藏量产界面
  581. tabPage_ProductMode_Read.Parent = null;
  582. tabPage_ProductMode_Write.Parent = null;
  583. 判断阈值ToolStripMenuItem.Visible = false;
  584. 力矩传感器检验ToolStripMenuItem.Visible = false;
  585. 服务器配置ToolStripMenuItem.Visible = false;
  586. //退出登录
  587. break;
  588. }
  589. else if (EnterForm1.comboBox_User.Text == "管理员")
  590. {
  591. //不隐藏任何界面
  592. //...
  593. //退出登录
  594. break;
  595. }
  596. else
  597. {
  598. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  599. //重新登录
  600. continue;
  601. }
  602. }
  603. else
  604. {
  605. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  606. //重新登录
  607. continue;
  608. }
  609. }
  610. catch (Exception)
  611. {
  612. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  613. System.Environment.Exit(0);
  614. }
  615. } while (true);
  616. //端口自动连接
  617. if ((PortNumSave != string.Empty) && (PortBaudrateSave != string.Empty)) //有数值时采用上次使用的值
  618. {
  619. try
  620. {
  621. PortConnect();
  622. }
  623. catch (System.Exception)
  624. {
  625. timer_1s.Enabled = false;
  626. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  627. timer_1s.Enabled = true;
  628. }
  629. }
  630. //配置网络FTP服务器
  631. myFtp.FtpOption(toolStripTextBox_ServerIP.Text, toolStripTextBox_ServerPort.Text, toolStripTextBox_ServerUser.Text, toolStripTextBox_ServerPasswd.Text, "admin", "ttium_admin");
  632. //创建线程,定时检测网络连接状态
  633. Thread th = new Thread(NetworkCheck);
  634. th.IsBackground = true;
  635. th.Start();
  636. }
  637. /// <summary>
  638. /// 检查网络状态线程
  639. /// </summary>
  640. private void NetworkCheck()
  641. {
  642. //允许离线使用,直接退出
  643. if (允许ToolStripMenuItem.Checked == true) //允许离线使用
  644. {
  645. timer_1s.Enabled = false;
  646. MessageBoxTimeOut.Show("离线使用,不检测网络状态!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  647. timer_1s.Enabled = true;
  648. return;
  649. }
  650. //不允许离线使用,实时监测网络状态
  651. else
  652. {
  653. //初始化第一次连接FTP服务器
  654. bool Result = myFtp.CheckFtp();
  655. if (Result == true)//服务器连接成功
  656. {
  657. myFtp.IsNetConnected = true;
  658. //上传登录日志
  659. do
  660. {
  661. //日志文件名
  662. string date = DateTime.Now.ToString("yyyy-MM-dd_HHmmss_fff");
  663. string fileName = date;
  664. //日志内容
  665. string fileInfo = Local_HdInformation;
  666. //保存本地
  667. if (!Directory.Exists(localInfo.LocalLogPath))
  668. Directory.CreateDirectory(localInfo.LocalLogPath);
  669. System.IO.File.WriteAllText(localInfo.LocalLogPath + fileName, fileInfo);
  670. //上传服务器
  671. myFtp.UploadFile(localInfo.LocalLogPath + fileName, "/Tools/Welling_Motor_Debug_Tool/log");
  672. } while (false);
  673. }
  674. else//服务器连接失败
  675. {
  676. myFtp.IsNetConnected = false;
  677. if ((EnterForm1.comboBox_User.Text != "管理员") && (EnterForm1.comboBox_User.Text != "FCT治具测试"))
  678. {
  679. timer_1s.Enabled = false;
  680. MessageBoxTimeOut.Show("网络断开,将自动关闭!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  681. timer_1s.Enabled = true;
  682. this.Close();
  683. }
  684. }
  685. //创建定时器,定时10s检查网络
  686. System.Timers.Timer timer_CheckNet = new System.Timers.Timer();
  687. timer_CheckNet.Enabled = true;
  688. timer_CheckNet.Interval = 10000;
  689. timer_CheckNet.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_CheckNet_Tick);
  690. timer_CheckNet.Start();
  691. while (true)
  692. {
  693. Thread.Sleep(1);
  694. if (myFtp.IsNetConnected == false)
  695. {
  696. label_Server_ComStatus.Text = "网络已断开";
  697. label_ServerStatus.BackColor = Color.Red;
  698. }
  699. else
  700. {
  701. label_Server_ComStatus.Text = "网络已连接";
  702. label_ServerStatus.BackColor = Color.Green;
  703. }
  704. }
  705. }
  706. }
  707. /// <summary>
  708. /// 线程中定时任务,检查网络状态
  709. /// </summary>
  710. /// <param name="sender"></param>
  711. /// <param name="e"></param>
  712. private void timer_CheckNet_Tick(object sender, EventArgs e)
  713. {
  714. //连接FTP服务器
  715. bool Result = myFtp.CheckFtp();
  716. if (Result == true)//服务器连接成功
  717. {
  718. myFtp.IsNetConnected = true;
  719. //允许使用
  720. groupBox1.Enabled = true;
  721. groupBox3.Enabled = true;
  722. tabControl2.Enabled = true;
  723. }
  724. else//服务器连接失败
  725. {
  726. myFtp.IsNetConnected = false;
  727. if ((EnterForm1.comboBox_User.Text != "管理员") && (EnterForm1.comboBox_User.Text != "FCT治具测试"))
  728. {
  729. timer_1s.Enabled = false;
  730. MessageBoxTimeOut.Show("网络断开, 请检查网络!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Warning); //提示框自动3s关闭
  731. timer_1s.Enabled = true;
  732. //禁止使用
  733. groupBox1.Enabled = false;
  734. groupBox3.Enabled = false;
  735. tabControl2.Enabled = false;
  736. }
  737. }
  738. }
  739. #region 非独占性延时函数
  740. public static void Delay_ms(int milliSecond)
  741. {
  742. int start = Environment.TickCount;
  743. while (Math.Abs(Environment.TickCount - start) < milliSecond)//毫秒
  744. {
  745. Application.DoEvents();
  746. }
  747. }
  748. #endregion
  749. private void MainForm_Load(object sender, System.EventArgs e)
  750. {
  751. //页面初始化
  752. label_BuildTime.Text = "编译时间:" + System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString("yyyy-MM-dd HH:mm:ss");
  753. label_Computername.Text = "用户名:" + System.Environment.UserName;
  754. this.Text += Version;
  755. //下拉控件初始值设定
  756. comboBox_WorkMode.SelectedIndex = 0;
  757. comboBox_GearSt.SelectedIndex = 0;
  758. comboBox_LightSwitch.SelectedIndex = 1;
  759. comboBox_OBC_SetGearST.SelectedIndex = 0;
  760. comboBox_OBC_LightSw.SelectedIndex = 1;
  761. comboBox_AssistTorque.SelectedIndex = 0;
  762. comboBox_AssistCadence.SelectedIndex = 0;
  763. //combobox事件定义
  764. this.comboBox_WorkMode.SelectedIndexChanged += new System.EventHandler(this.comboBox_WorkMode_SelectedIndexChanged);
  765. this.comboBox_GearSt.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  766. this.comboBox_LightSwitch.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  767. this.comboBox_OBC_SetGearST.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  768. this.comboBox_OBC_LightSw.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  769. //创建线程,定时解析数据
  770. Thread th = new Thread(Task_SerialProcess);
  771. th.IsBackground = true;
  772. th.Start();
  773. }
  774. #region 结构体与字节流相互转换
  775. public static class MyConverter
  776. {
  777. /// <summary>
  778. /// 由结构体转换为byte数组
  779. /// </summary>
  780. public static byte[] StructureToByte<T>(T structure)
  781. {
  782. int size = Marshal.SizeOf(typeof(T));
  783. byte[] buffer = new byte[size];
  784. IntPtr bufferIntPtr = Marshal.AllocHGlobal(size);
  785. try
  786. {
  787. Marshal.StructureToPtr(structure, bufferIntPtr, true);
  788. Marshal.Copy(bufferIntPtr, buffer, 0, size);
  789. }
  790. finally
  791. {
  792. Marshal.FreeHGlobal(bufferIntPtr);
  793. }
  794. return buffer;
  795. }
  796. /// <summary>
  797. /// 由byte数组转换为结构体
  798. /// </summary>
  799. public static T ByteToStructure<T>(byte[] dataBuffer, ushort StarIndex)
  800. {
  801. object structure = null;
  802. int size = Marshal.SizeOf(typeof(T));
  803. IntPtr allocIntPtr = Marshal.AllocHGlobal(size);
  804. try
  805. {
  806. Marshal.Copy(dataBuffer, StarIndex, allocIntPtr, size);
  807. structure = Marshal.PtrToStructure(allocIntPtr, typeof(T));
  808. }
  809. finally
  810. {
  811. Marshal.FreeHGlobal(allocIntPtr);
  812. }
  813. return (T)structure;
  814. }
  815. }
  816. #endregion
  817. #region 故障日志解析显示
  818. private void ErrorLogDisplay(MC_ErrorLogSaveInfo_Struct_t Log1, MC_ErrorLogSaveInfo_Struct_t Log2)
  819. {
  820. string SaveData = "";
  821. //Log1
  822. if (Log1.Error_Index != 0xFFFF)
  823. {
  824. SaveData += "故障序号:" + Convert.ToString(Log1.Error_Index) + ", ";
  825. SaveData += "备注1:" + Convert.ToString(Log1.NotesInfo1) + ", ";
  826. SaveData += "备注2:" + Convert.ToString(Log1.NotesInfo2) + ", ";
  827. SaveData += "备注3:" + Convert.ToString(Log1.NotesInfo3) + ", ";
  828. SaveData += "故障码:" + "0x" + Convert.ToString(Log1.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  829. SaveData += "运行时间:" + Convert.ToString(Log1.RunTime) + "min" + ", ";
  830. SaveData += "车速:" + ((float)Log1.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  831. SaveData += "电机转速:" + Convert.ToString(Log1.RunInfo.MotorSpeed) + "rpm" + ", ";
  832. SaveData += "功率:" + Convert.ToString(Log1.RunInfo.Power * 2) + "w" + ", ";
  833. SaveData += "电压:" + Convert.ToString(Log1.RunInfo.BusVoltage) + "mV" + ", ";
  834. SaveData += "电流:" + Convert.ToString(Log1.RunInfo.BusCurrent) + "mA" + ", ";
  835. SaveData += "踏频:" + Convert.ToString(Log1.RunInfo.Cadence) + "rpm" + ", ";
  836. SaveData += "力矩:" + Convert.ToString(Log1.RunInfo.Torque) + "N.m" + ", ";
  837. SaveData += "方向:" + ((Log1.RunInfo.CadenceDir == 0) ? "正" : ((Log1.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  838. SaveData += "档位:" + "0x" + Convert.ToString(Log1.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  839. SaveData += "灯开关:" + ((Log1.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  840. SaveData += "电量:" + Convert.ToString(Log1.RunInfo.SOC) + "%" + ", ";
  841. if ((Log1.RunInfo.RemainDistance == 0xEEEE) || (Log1.RunInfo.RemainDistance == 0xFFFF))
  842. {
  843. SaveData += "续航:" + "---km" + ", ";
  844. }
  845. else
  846. {
  847. SaveData += "续航:" + Convert.ToString(Log1.RunInfo.RemainDistance) + "km" + ", ";
  848. }
  849. SaveData += "力矩AD:" + Convert.ToString(Log1.RunInfo.Torque_AD) + ", ";
  850. SaveData += "功耗:" + Convert.ToString(Log1.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  851. SaveData += "PCB温度:" + Convert.ToString((int)(Log1.RunInfo.T_PCB - 40)) + "℃" + ", ";
  852. SaveData += "绕组温度:" + Convert.ToString((int)(Log1.RunInfo.T_Coil - 40)) + "℃" + ", ";
  853. SaveData += "MCU温度:" + Convert.ToString((int)(Log1.RunInfo.T_MCU - 40)) + "℃" + ", ";
  854. SaveData += "单次里程:" + Convert.ToString((float)Log1.RunInfo.Ride_Km / 10f) + "km" + ", ";
  855. SaveData += "单次时间:" + Convert.ToString(Log1.RunInfo.Ride_Time) + "s" + ", ";
  856. SaveData += "q轴电流:" + Convert.ToString(Log1.IqCurrent) + ", ";
  857. SaveData += "q轴电压:" + Convert.ToString(Log1.IqVoltage) + ", ";
  858. SaveData += "d轴电流:" + Convert.ToString(Log1.IdCurrent) + ", ";
  859. SaveData += "d轴电压:" + Convert.ToString(Log1.IdVoltage) + ", ";
  860. SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
  861. SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
  862. SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
  863. SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
  864. SaveData += "\r\n\r\n";
  865. richTextBox_Record.AppendText(SaveData);
  866. SaveData = "";
  867. }
  868. //Log2
  869. if (Log2.Error_Index != 0xFFFF)
  870. {
  871. SaveData += "故障序号:" + Convert.ToString(Log2.Error_Index) + ", ";
  872. SaveData += "备注1:" + Convert.ToString(Log2.NotesInfo1) + ", ";
  873. SaveData += "备注2:" + Convert.ToString(Log2.NotesInfo2) + ", ";
  874. SaveData += "备注3:" + Convert.ToString(Log2.NotesInfo3) + ", ";
  875. SaveData += "故障码:" + "0x" + Convert.ToString(Log2.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  876. SaveData += "运行时间:" + Convert.ToString(Log2.RunTime) + "min" + ", ";
  877. SaveData += "车速:" + ((float)Log2.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  878. SaveData += "电机转速:" + Convert.ToString(Log2.RunInfo.MotorSpeed) + "rpm" + ", ";
  879. SaveData += "功率:" + Convert.ToString(Log2.RunInfo.Power * 2) + "w" + ", ";
  880. SaveData += "电压:" + Convert.ToString(Log2.RunInfo.BusVoltage) + "mV" + ", ";
  881. SaveData += "电流:" + Convert.ToString(Log2.RunInfo.BusCurrent) + "mA" + ", ";
  882. SaveData += "踏频:" + Convert.ToString(Log2.RunInfo.Cadence) + "rpm" + ", ";
  883. SaveData += "力矩:" + Convert.ToString(Log2.RunInfo.Torque) + "N.m" + ", ";
  884. SaveData += "方向:" + ((Log2.RunInfo.CadenceDir == 0) ? "正" : ((Log2.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  885. SaveData += "档位:" + "0x" + Convert.ToString(Log2.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  886. SaveData += "灯开关:" + ((Log2.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  887. SaveData += "电量:" + Convert.ToString(Log2.RunInfo.SOC) + "%" + ", ";
  888. if ((Log2.RunInfo.RemainDistance == 0xEEEE) || (Log2.RunInfo.RemainDistance == 0xFFFF))
  889. {
  890. SaveData += "续航:" + "---km" + ", ";
  891. }
  892. else
  893. {
  894. SaveData += "续航:" + Convert.ToString(Log2.RunInfo.RemainDistance) + "km" + ", ";
  895. }
  896. SaveData += "力矩AD:" + Convert.ToString(Log2.RunInfo.Torque_AD) + ", ";
  897. SaveData += "功耗:" + Convert.ToString(Log2.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  898. SaveData += "PCB温度:" + Convert.ToString((int)(Log2.RunInfo.T_PCB - 40)) + "DegreeC" + ", ";
  899. SaveData += "绕组温度:" + Convert.ToString((int)(Log2.RunInfo.T_Coil - 40)) + "DegreeC" + ", ";
  900. SaveData += "MCU温度:" + Convert.ToString((int)(Log2.RunInfo.T_MCU - 40)) + "DegreeC" + ", ";
  901. SaveData += "单次里程:" + Convert.ToString((float)Log2.RunInfo.Ride_Km / 10f) + "km" + ", ";
  902. SaveData += "单次时间:" + Convert.ToString(Log2.RunInfo.Ride_Time) + "s" + ", ";
  903. SaveData += "q轴电流:" + Convert.ToString(Log2.IqCurrent) + ", ";
  904. SaveData += "q轴电压:" + Convert.ToString(Log2.IqVoltage) + ", ";
  905. SaveData += "d轴电流:" + Convert.ToString(Log2.IdCurrent) + ", ";
  906. SaveData += "d轴电压:" + Convert.ToString(Log2.IdVoltage) + ", ";
  907. SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
  908. SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
  909. SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
  910. SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
  911. SaveData += "\r\n\r\n";
  912. richTextBox_Record.AppendText(SaveData);
  913. SaveData = "";
  914. }
  915. }
  916. #endregion
  917. #region 串口数据解析线程
  918. /// <summary>
  919. /// 串口数据解析线程
  920. /// </summary>
  921. private void Task_SerialProcess()
  922. {
  923. //创建定时器,定时读取串口数据
  924. System.Timers.Timer timer_ReadSerial = new System.Timers.Timer();
  925. timer_ReadSerial.Enabled = true;
  926. timer_ReadSerial.Interval = 20;
  927. timer_ReadSerial.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_ReadSerial_Tick);
  928. timer_ReadSerial.Start();
  929. while (true)
  930. {
  931. Thread.Sleep(1);
  932. };
  933. }
  934. /// <summary>
  935. /// 串口解析定时器
  936. /// </summary>
  937. /// <param name="sender"></param>
  938. /// <param name="e"></param>
  939. private void timer_ReadSerial_Tick(object sender, EventArgs e)
  940. {
  941. //串口解析
  942. Serial_process(mySerialProcess.buffer);
  943. }
  944. #endregion
  945. #region 数据解析
  946. public void Serial_process(List<byte> buffer)
  947. {
  948. byte DataNum = 0; //记录每条命令数据段的长度
  949. ushort PackageID, Cmd;
  950. byte[] Data = new byte[1024];
  951. try
  952. {
  953. while (buffer.Count >= 13)//当buffer中的数据的个数大于等于4个时,即每一帧的数据长度所在位(第4位)出现时
  954. {
  955. if (buffer[0] == 0x55 && buffer[1] == 0xAA)//判断帧头
  956. {
  957. PackageID = (ushort)(buffer[2] * 256 + buffer[3]);
  958. if ((PackageID == 0x0710) || (PackageID == 0x0715) || (PackageID == 0x07FF) || (PackageID == 0x0720) || (PackageID == 0x0713))
  959. {
  960. int CmdLen = buffer[5];
  961. if (buffer.Count < CmdLen + 11) break;//如果接收到的数据没有达到一帧数据的指定长度, 则执行下次循环
  962. while (CmdLen > 0) //读取命令段
  963. {
  964. Cmd = (ushort)(buffer[6] * 256 + buffer[7]);
  965. DataNum = (byte)(buffer[7]);//命令字的第二个字节的表示数据位的长度
  966. if (DataNum <= (CmdLen - 2))
  967. {
  968. for (int i = 0; i < DataNum; i++)
  969. {
  970. Data[i] = buffer[i + 8];
  971. }
  972. buffer.RemoveRange(0, CmdLen + 11);
  973. DataCmdProcess(PackageID, Cmd, Data);//对于不同的命令段,做不同的处理
  974. DataRevToString(Cmd, Data);//指令数据转为字符串
  975. }
  976. }
  977. }
  978. else
  979. {
  980. buffer.RemoveAt(0);//ID不对
  981. }
  982. }
  983. else
  984. {
  985. buffer.RemoveAt(0);//帧头不对,删除帧头高字节
  986. }
  987. }
  988. }
  989. catch (Exception)
  990. {
  991. }
  992. }
  993. private void DataCmdProcess(ushort ID, ushort CmdTemp, byte[] Data)
  994. {
  995. int DataTemp;
  996. ushort uData16;
  997. unchecked
  998. {
  999. this.Invoke((EventHandler)(delegate { label_RecCount.Text = Convert.ToString(Convert.ToInt32(label_RecCount.Text) + 1); }));
  1000. }
  1001. #region 解析发送给CDL的指令
  1002. if (ID == 0x7FF)
  1003. {
  1004. switch (CmdTemp)
  1005. {
  1006. case 0x1100://
  1007. {
  1008. unchecked
  1009. {
  1010. this.Invoke((EventHandler)(delegate
  1011. {
  1012. //CDL连接成功
  1013. mySerialProcess.CDL_Online_Flag = true;
  1014. MessageBoxTimeOut.Show("连接成功!", "提示", 500);
  1015. groupBox1.Visible = true;
  1016. groupBox3.Visible = true;
  1017. tabControl2.Visible = true;
  1018. label_StarInfo.Visible = false;
  1019. }));
  1020. }
  1021. break;
  1022. }
  1023. default: break;
  1024. }
  1025. }
  1026. #endregion
  1027. #region 解析电机的命令
  1028. else if ((ID == 0x715) || (ID == 0x710))
  1029. {
  1030. switch (CmdTemp)
  1031. {
  1032. case 0x1020://电机运行信息
  1033. {
  1034. unchecked
  1035. {
  1036. this.Invoke((EventHandler)(delegate
  1037. {
  1038. MC_RunInfo_Refresh = true;
  1039. //车速
  1040. DataTemp = (int)(Data[1] * 256 + Data[0]);
  1041. textBox_RunInfo_BikeSpeed.Text = ((float)DataTemp / 10f).ToString("0.0") + " km/h";
  1042. //输出转速
  1043. DataTemp = (ushort)(Data[3] * 256 + Data[2]);
  1044. textBox_RunInfo_MotorSpeed.Text = Convert.ToString(DataTemp) + " rpm";
  1045. Class_MotorSpeed.String = textBox_RunInfo_MotorSpeed.Text;
  1046. Class_MotorSpeed.Data = DataTemp;
  1047. //电功率
  1048. DataTemp = (ushort)(Data[5] * 256 + Data[4]);
  1049. textBox_RunInfo_Power.Text = Convert.ToString(DataTemp) + " W";
  1050. //母线电压
  1051. DataTemp = (ushort)(Data[7] * 256 + Data[6]);
  1052. textBox_RunInfo_Vol.Text = Convert.ToString(DataTemp) + " mV";
  1053. //textBox_RunInfo_Vol.Text = (DataTemp / 1000f).ToString("0.0") + " V";
  1054. //母线电流
  1055. DataTemp = (short)(Data[9] * 256 + Data[8]);
  1056. textBox_RunInfo_Current.Text = Convert.ToString(DataTemp) + " mA";
  1057. //textBox_RunInfo_Current.Text = (DataTemp / 1000f).ToString("0.0") + " A";
  1058. Class_CurrentData.String = textBox_RunInfo_Current.Text;
  1059. Class_CurrentData.Data = DataTemp;
  1060. //踏频
  1061. DataTemp = (ushort)(Data[10]);
  1062. textBox_RunInfo_Cadence.Text = Convert.ToString(DataTemp) + " rpm";
  1063. Class_CadenceData.String = textBox_RunInfo_Cadence.Text;
  1064. Class_CadenceData.Data = DataTemp;
  1065. //踩踏力矩
  1066. DataTemp = (ushort)(Data[11]);
  1067. textBox_RunInfo_Torque.Text = Convert.ToString(DataTemp) + " N.m";
  1068. Class_TorqueData.String = textBox_RunInfo_Torque.Text;
  1069. Class_TorqueData.Data = DataTemp;
  1070. //踩踏方向
  1071. DataTemp = (ushort)(Data[12]);
  1072. if (DataTemp == 0)
  1073. {
  1074. textBox_RunInfo_Dir.Text = "正向";
  1075. }
  1076. else if (DataTemp == 1)
  1077. {
  1078. textBox_RunInfo_Dir.Text = "反向";
  1079. }
  1080. else if (DataTemp == 2)
  1081. {
  1082. textBox_RunInfo_Dir.Text = "停止";
  1083. }
  1084. //助力档位
  1085. DataTemp = (ushort)(Data[13]);
  1086. if (DataTemp == 0x33)
  1087. {
  1088. textBox_RunInfo_GearSt.Text = "SMART";
  1089. //comboBox_GearSt.SelectedIndex = 5;
  1090. //comboBox_OBC_SetGearST.SelectedIndex = 5;
  1091. }
  1092. else if (DataTemp == 0x22)
  1093. {
  1094. textBox_RunInfo_GearSt.Text = "WALK";
  1095. //comboBox_GearSt.SelectedIndex = 6;
  1096. //comboBox_OBC_SetGearST.SelectedIndex = 6;
  1097. }
  1098. else
  1099. {
  1100. string[] Gears = new string[5] { "OFF", "ECO", "NORM", "SPORT", "TURBO" };
  1101. textBox_RunInfo_GearSt.Text = Gears[DataTemp];
  1102. //comboBox_GearSt.SelectedIndex = DataTemp;
  1103. //comboBox_OBC_SetGearST.SelectedIndex = DataTemp;
  1104. }
  1105. //大灯状态
  1106. DataTemp = (ushort)(Data[14]);
  1107. if (DataTemp == 0xF0)
  1108. {
  1109. textBox_RunInfo_LightSwitch.Text = "OFF";
  1110. //comboBox_LightSwitch.SelectedIndex = 1;
  1111. //comboBox_OBC_LightSw.SelectedIndex = 1;
  1112. }
  1113. else if (DataTemp == 0xF1)
  1114. {
  1115. textBox_RunInfo_LightSwitch.Text = "ON";
  1116. //comboBox_LightSwitch.SelectedIndex = 0;
  1117. //comboBox_OBC_LightSw.SelectedIndex = 0;
  1118. }
  1119. //剩余电量
  1120. DataTemp = (ushort)(Data[15]);
  1121. textBox_RunInfo_SOC.Text = Convert.ToString(DataTemp) + " %";
  1122. //剩余续航里程
  1123. DataTemp = (ushort)(Data[17] * 256 + Data[16]);
  1124. if ((DataTemp == 0xEEEE) || (DataTemp == 0xFFFF))
  1125. {
  1126. textBox_RunInfo_Range.Text = "---";
  1127. }
  1128. else
  1129. {
  1130. textBox_RunInfo_Range.Text = Convert.ToString(DataTemp) + " km";
  1131. }
  1132. //预留(显示力矩Reg),空2bytes
  1133. DataTemp = (ushort)(Data[19] * 256 + Data[18]);
  1134. textBox_TorqueReg.Text = Convert.ToString(DataTemp);
  1135. //平均功耗
  1136. DataTemp = (ushort)(Data[20]);
  1137. textBox_RunInfo_AvgPower.Text = Convert.ToString(DataTemp * 10) + " mAh/km";
  1138. //PCB温度
  1139. DataTemp = (ushort)(Data[21]);
  1140. textBox_RunInfo_T_PCB.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1141. Class_MotorTemp.String = textBox_RunInfo_T_PCB.Text;
  1142. Class_MotorTemp.Data = DataTemp - 40;
  1143. //绕组温度
  1144. DataTemp = (ushort)(Data[22]);
  1145. textBox_RunInfo_T_Coil.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1146. //MCU温度
  1147. DataTemp = (ushort)(Data[23]);
  1148. textBox_RunInfo_T_MCU.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1149. //单次里程
  1150. DataTemp = (ushort)(Data[25] * 256 + Data[24]);
  1151. textBox_RunInfo_Trip.Text = ((float)DataTemp / 10f).ToString("0.0") + " km";
  1152. //单次时间
  1153. DataTemp = (ushort)(Data[27] * 256 + Data[26]);
  1154. textBox_RunInfo_Trip_Time.Text = Convert.ToString(DataTemp) + " s";
  1155. //数据保存
  1156. RunInfoAutoSave();
  1157. }));
  1158. }
  1159. break;
  1160. }
  1161. case 0x1104://故障码
  1162. {
  1163. unchecked
  1164. {
  1165. this.Invoke((EventHandler)(delegate
  1166. {
  1167. MC_ErrorCode_Refresh = true;
  1168. textBox_ErrorCode.Text =
  1169. Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() +
  1170. Convert.ToString(Data[2], 16).PadLeft(2, '0').ToUpper() +
  1171. Convert.ToString(Data[1], 16).PadLeft(2, '0').ToUpper() +
  1172. Convert.ToString(Data[0], 16).PadLeft(2, '0').ToUpper() +
  1173. "H";
  1174. }));
  1175. }
  1176. break;
  1177. }
  1178. case 0xA903://反馈指令
  1179. {
  1180. unchecked
  1181. {
  1182. this.Invoke((EventHandler)(delegate
  1183. {
  1184. if (ACK_DisFlag == true)
  1185. {
  1186. timer_1s.Enabled = false;
  1187. MessageBoxTimeOut.Show("OK", "反馈指令", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  1188. timer_1s.Enabled = true;
  1189. //关机反馈
  1190. PowerOffAckStatus = true;
  1191. }
  1192. //应答标志置位
  1193. WriteACK = true;
  1194. WriteCnt++;
  1195. }));
  1196. }
  1197. break;
  1198. }
  1199. case 0xB226://马达参数
  1200. {
  1201. unchecked
  1202. {
  1203. this.Invoke((EventHandler)(delegate
  1204. {
  1205. richTextBox_MotorParam.Clear();
  1206. for (int i = 0; i < myParams.MotorParma.Count; i++)
  1207. {
  1208. if (i == 6)
  1209. richTextBox_MotorParam.AppendText(myParams.MotorParma[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1210. else
  1211. richTextBox_MotorParam.AppendText(myParams.MotorParma[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1212. }
  1213. richTextBox_MotorParam.Text = richTextBox_MotorParam.Text.Substring(0, richTextBox_MotorParam.Text.Length - 2);
  1214. }));
  1215. }
  1216. break;
  1217. }
  1218. case 0xB31A://整车信息
  1219. {
  1220. unchecked
  1221. {
  1222. this.Invoke((EventHandler)(delegate
  1223. {
  1224. richTextBox_BikeParam.Clear();
  1225. for (int i = 0; i < myParams.BikeParma.Count; i++)
  1226. {
  1227. if (i == 9)
  1228. richTextBox_BikeParam.AppendText(myParams.BikeParma[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1229. else
  1230. richTextBox_BikeParam.AppendText(myParams.BikeParma[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1231. //更新前后灯参数
  1232. if (i == 8)
  1233. {
  1234. comboBox_TailLightMode.SelectedIndex = ((Data[2 * i + 1] >> 4) & 0x0F) - 1;
  1235. comboBox_TailLightVol.SelectedIndex = ((Data[2 * i + 1] & 0x0F) == 6) ? 0 : 1;
  1236. comboBox_FrontLightVol.SelectedIndex = ((Data[2 * i] & 0x0F) == 6) ? 0 : 1;
  1237. }
  1238. //更新开关机参数
  1239. else if (i == 11)
  1240. {
  1241. textBox_PowerOnDelay.Text = Convert.ToString((Data[2 * i + 1] >> 4) & 0x0F);
  1242. textBox_PowerOffDelay.Text = Convert.ToString(Data[2 * i + 1] & 0x0F);
  1243. textBox_AutoPowerOff.Text = Convert.ToString(Data[2 * i]);
  1244. }
  1245. }
  1246. richTextBox_BikeParam.Text = richTextBox_BikeParam.Text.Substring(0, richTextBox_BikeParam.Text.Length - 2);
  1247. }));
  1248. }
  1249. break;
  1250. }
  1251. case 0xB420://控制器参数
  1252. {
  1253. unchecked
  1254. {
  1255. this.Invoke((EventHandler)(delegate
  1256. {
  1257. richTextBox_ControlParam.Clear();
  1258. for (int i = 0; i < myParams.ControlParma.Count; i++)
  1259. {
  1260. richTextBox_ControlParam.AppendText(myParams.ControlParma[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1261. }
  1262. richTextBox_ControlParam.Text = richTextBox_ControlParam.Text.Substring(0, richTextBox_ControlParam.Text.Length - 2);
  1263. }));
  1264. }
  1265. break;
  1266. }
  1267. case 0xB528://传感器参数
  1268. {
  1269. unchecked
  1270. {
  1271. this.Invoke((EventHandler)(delegate
  1272. {
  1273. richTextBox_SensorParam.Clear();
  1274. for (int i = 0; i < myParams.SensorParam.Count; i++)
  1275. {
  1276. richTextBox_SensorParam.AppendText(myParams.SensorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1277. }
  1278. richTextBox_SensorParam.Text = richTextBox_SensorParam.Text.Substring(0, richTextBox_SensorParam.Text.Length - 2);
  1279. //更新生产模式页面传感器零点和标定值
  1280. textBox_FacModeSensorADC0.Text = (Data[1] * 256 + Data[0]).ToString();
  1281. textBox_FacModeSensorADC1.Text = (Data[15] * 256 + Data[14]).ToString();
  1282. textBox_FacModeSensorADC2.Text = (Data[19] * 256 + Data[18]).ToString();
  1283. textBox_FacModeSensorADC3.Text = (Data[23] * 256 + Data[22]).ToString();
  1284. textBox_FacModeSensorADC4.Text = (Data[27] * 256 + Data[26]).ToString();
  1285. }));
  1286. }
  1287. break;
  1288. }
  1289. case 0xB64C://助力参数
  1290. {
  1291. unchecked
  1292. {
  1293. this.Invoke((EventHandler)(delegate
  1294. {
  1295. richTextBox_AssistParam.Clear();
  1296. int index_1 = myParams.AssistParam.IndexOf("转矩曲线.a");
  1297. int index_2 = myParams.AssistParam.IndexOf("踏频曲线.d");
  1298. int index_3 = myParams.AssistParam.IndexOf("踏频助力加速限制");
  1299. int index_4 = myParams.AssistParam.IndexOf("踏频助力电流步进");
  1300. for (int i = 0; i < myParams.AssistParam.Count; i++)
  1301. {
  1302. if (i < index_1) //数据占用2bytes
  1303. {
  1304. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1305. }
  1306. else if (i <= index_2) //数据占用4bytes
  1307. {
  1308. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((long)((Data[4 * i - 5] << 24) + (Data[4 * i - 6] << 16) + (Data[4 * i - 7] << 8) + Data[4 * i - 8])) + ", ");
  1309. }
  1310. else if (i < index_3) //数据占用2bytes,无符号
  1311. {
  1312. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1313. }
  1314. else if (i <= index_4) //数据占用2bytes,有符号
  1315. {
  1316. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1317. }
  1318. else //数据占用2bytes,无符号
  1319. {
  1320. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1321. }
  1322. }
  1323. richTextBox_AssistParam.Text = richTextBox_AssistParam.Text.Substring(0, richTextBox_AssistParam.Text.Length - 2);
  1324. }));
  1325. }
  1326. break;
  1327. }
  1328. case 0xB74C://历史记录
  1329. {
  1330. unchecked
  1331. {
  1332. this.Invoke((EventHandler)(delegate
  1333. {
  1334. richTextBox_Record.Clear();
  1335. for (int i = 0; i < myParams.Record.Count; i++)
  1336. {
  1337. richTextBox_Record.AppendText(myParams.Record[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  1338. }
  1339. richTextBox_Record.Text = richTextBox_Record.Text.Substring(0, richTextBox_Record.Text.Length - 2);
  1340. }));
  1341. }
  1342. break;
  1343. }
  1344. case 0xB83A://调试参数
  1345. {
  1346. unchecked
  1347. {
  1348. this.Invoke((EventHandler)(delegate
  1349. {
  1350. richTextBox_DebugParam.Clear();
  1351. for (int i = 0; i < myParams.DebugParam.Count; i++)
  1352. {
  1353. richTextBox_DebugParam.AppendText(myParams.DebugParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1354. }
  1355. richTextBox_DebugParam.Text = richTextBox_DebugParam.Text.Substring(0, richTextBox_DebugParam.Text.Length - 2);
  1356. }));
  1357. }
  1358. break;
  1359. }
  1360. case 0xB904://存储标志
  1361. {
  1362. unchecked
  1363. {
  1364. this.Invoke((EventHandler)(delegate
  1365. {
  1366. ushort Flag = 0;
  1367. Flag = (ushort)(Data[1] * 256 + Data[0]);//EEPROM存储标志
  1368. if (Flag == 0)
  1369. {
  1370. radioButton_EE_SaveNo.Checked = true;
  1371. radioButton_EE_SaveYes.Checked = false;
  1372. }
  1373. else
  1374. {
  1375. radioButton_EE_SaveNo.Checked = false;
  1376. radioButton_EE_SaveYes.Checked = true;
  1377. }
  1378. Flag = (ushort)(Data[3] * 256 + Data[2]);//SIP偏移校准存储标志
  1379. if (Flag == 0)
  1380. {
  1381. radioButton_SIP_SaveNo.Checked = true;
  1382. radioButton_SIP_SaveYes.Checked = false;
  1383. }
  1384. else
  1385. {
  1386. radioButton_SIP_SaveNo.Checked = false;
  1387. radioButton_SIP_SaveYes.Checked = true;
  1388. }
  1389. }));
  1390. }
  1391. break;
  1392. }
  1393. case 0x1240://电机版本信息
  1394. {
  1395. unchecked
  1396. {
  1397. this.Invoke((EventHandler)(delegate
  1398. {
  1399. //电机型号
  1400. textBox_Model.Text = "";
  1401. textBox_OBC_ReadModel.Text = "";
  1402. textBox_FacModeName.Text = "";
  1403. for (ushort i = 0; i < 16; i++)
  1404. {
  1405. if (Data[i] == 0x2E)
  1406. {
  1407. break;
  1408. }
  1409. textBox_Model.Text += ((char)Data[i]).ToString();
  1410. textBox_OBC_ReadModel.Text += ((char)Data[i]).ToString();
  1411. textBox_FacModeName.Text += ((char)Data[i]).ToString();
  1412. }
  1413. Class_Motor_Ver.Mode = textBox_Model.Text;
  1414. //电机SN
  1415. textBox_SN.Text = "";
  1416. textBox_OBC_ReadSN.Text = "";
  1417. textBox_FacModeNum.Text = "";
  1418. for (ushort i = 0; i < 16; i++)
  1419. {
  1420. if (Data[16 + i] == 0x2E)
  1421. {
  1422. break;
  1423. }
  1424. textBox_SN.Text += ((char)Data[16 + i]).ToString();
  1425. textBox_OBC_ReadSN.Text += ((char)Data[16 + i]).ToString();
  1426. textBox_FacModeNum.Text += ((char)Data[16 + i]).ToString();
  1427. }
  1428. Class_Motor_Ver.SN = textBox_SN.Text;
  1429. //电机HW
  1430. textBox_HW.Text = "";
  1431. textBox_OBC_ReadHW.Text = "";
  1432. textBox_FacModeHW.Text = "";
  1433. for (ushort i = 0; i < 8; i++)//前8位:硬件板号
  1434. {
  1435. if (Data[32 + i] == 0x2E)
  1436. {
  1437. break;
  1438. }
  1439. else if (Data[32 + i] == 'r')
  1440. {
  1441. Data[32 + i] = (byte)'.';
  1442. break;
  1443. }
  1444. string strTemp = "";
  1445. strTemp = ((char)Data[32 + i]).ToString();
  1446. textBox_HW.Text += strTemp;
  1447. textBox_OBC_ReadHW.Text += strTemp;
  1448. textBox_FacModeHW.Text += strTemp;
  1449. }
  1450. for (ushort i = 0; i < 4; i++)//9-12位:单片机型号
  1451. {
  1452. if (Data[40 + i] == 0x2E)
  1453. {
  1454. break;
  1455. }
  1456. else if (Data[40 + i] == 'r')
  1457. {
  1458. Data[40 + i] = (byte)'.';
  1459. break;
  1460. }
  1461. string strTemp = "";
  1462. strTemp = ((char)Data[40 + i]).ToString();
  1463. textBox_HW.Text += strTemp;
  1464. textBox_OBC_ReadHW.Text += strTemp;
  1465. textBox_FacModeHW.Text += strTemp;
  1466. }
  1467. for (ushort i = 0; i < 4; i++)//13-16位:单片机ID
  1468. {
  1469. string strTemp = "";
  1470. strTemp = Convert.ToString(Data[44 + i], 16).PadLeft(2, '0').ToUpper();
  1471. textBox_HW.Text += strTemp;
  1472. textBox_OBC_ReadHW.Text += strTemp;
  1473. textBox_FacModeHW.Text += strTemp;
  1474. }
  1475. Class_Motor_Ver.HW = textBox_HW.Text;
  1476. //电机FW
  1477. textBox_FW.Text = "";
  1478. textBox_OBC_ReadFW.Text = "";
  1479. textBox_FacModeFW.Text = "";
  1480. for (ushort i = 0; i < 16; i++)
  1481. {
  1482. if ((Data[48 + i] == 0x2E) || (Data[48 + i] == 0x00) || (Data[48 + i] == (char)' '))
  1483. {
  1484. break;
  1485. }
  1486. if (Data[48 + i] == 'r')
  1487. {
  1488. Data[48 + i] = (byte)'.';
  1489. }
  1490. textBox_FW.Text += ((char)Data[48 + i]).ToString();
  1491. textBox_OBC_ReadFW.Text += ((char)Data[48 + i]).ToString();
  1492. textBox_FacModeFW.Text += ((char)Data[48 + i]).ToString();
  1493. }
  1494. Class_Motor_Ver.FW = textBox_FW.Text;
  1495. }));
  1496. }
  1497. break;
  1498. }
  1499. case 0xA610://自定义1
  1500. {
  1501. unchecked
  1502. {
  1503. this.Invoke((EventHandler)(delegate
  1504. {
  1505. textBox_User1.Text = "";
  1506. for (ushort i = 0; i < 16; i++)
  1507. {
  1508. if (Data[i] == 0x2E)
  1509. {
  1510. break;
  1511. }
  1512. textBox_User1.Text += ((char)Data[i]).ToString();
  1513. }
  1514. }));
  1515. }
  1516. break;
  1517. }
  1518. case 0xA710://自定义2
  1519. {
  1520. unchecked
  1521. {
  1522. this.Invoke((EventHandler)(delegate
  1523. {
  1524. textBox_User2.Text = "";
  1525. for (ushort i = 0; i < 16; i++)
  1526. {
  1527. if (Data[i] == 0x2E)
  1528. {
  1529. break;
  1530. }
  1531. textBox_User2.Text += ((char)Data[i]).ToString();
  1532. }
  1533. }));
  1534. }
  1535. break;
  1536. }
  1537. case 0xA810://自定义1
  1538. {
  1539. unchecked
  1540. {
  1541. this.Invoke((EventHandler)(delegate
  1542. {
  1543. textBox_User3.Text = "";
  1544. for (ushort i = 0; i < 16; i++)
  1545. {
  1546. if (Data[i] == 0x2E)
  1547. {
  1548. break;
  1549. }
  1550. textBox_User3.Text += ((char)Data[i]).ToString();
  1551. }
  1552. }));
  1553. }
  1554. break;
  1555. }
  1556. case 0xA520://生产信息
  1557. {
  1558. unchecked
  1559. {
  1560. this.Invoke((EventHandler)(delegate
  1561. {
  1562. //生产商
  1563. textBox_MAC.Text = "";
  1564. for (ushort i = 0; i < 8; i++)
  1565. {
  1566. if (Data[i] == 0x2E)
  1567. {
  1568. break;
  1569. }
  1570. textBox_MAC.Text += ((char)Data[i]).ToString();
  1571. }
  1572. //生产地
  1573. textBox_MACAdd.Text = "";
  1574. for (ushort i = 0; i < 8; i++)
  1575. {
  1576. if (Data[8 + i] == 0x2E)
  1577. {
  1578. break;
  1579. }
  1580. textBox_MACAdd.Text += ((char)Data[8 + i]).ToString();
  1581. }
  1582. //生产日期
  1583. textBox_MACDate.Text = "";
  1584. for (ushort i = 0; i < 8; i++)
  1585. {
  1586. if (Data[16 + i] == 0x2E)
  1587. {
  1588. break;
  1589. }
  1590. textBox_MACDate.Text += ((char)Data[16 + i]).ToString();
  1591. }
  1592. //品牌信息
  1593. textBox_PP.Text = "";
  1594. for (ushort i = 0; i < 8; i++)
  1595. {
  1596. if (Data[24 + i] == 0x2E)
  1597. {
  1598. break;
  1599. }
  1600. textBox_PP.Text += ((char)Data[24 + i]).ToString();
  1601. }
  1602. }));
  1603. }
  1604. break;
  1605. }
  1606. case 0xA408://密钥
  1607. {
  1608. unchecked
  1609. {
  1610. this.Invoke((EventHandler)(delegate
  1611. {
  1612. textBox_Key.Text = "";
  1613. for (ushort i = 0; i < 8; i++)
  1614. {
  1615. textBox_Key.Text += ((char)Data[i]).ToString();
  1616. }
  1617. }));
  1618. }
  1619. break;
  1620. }
  1621. case 0xAB09://存储器数据
  1622. case 0xAB0A:
  1623. case 0xAB0B:
  1624. case 0xAB0C:
  1625. {
  1626. unchecked
  1627. {
  1628. this.Invoke((EventHandler)(delegate
  1629. {
  1630. long ByteNum = 0;
  1631. ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
  1632. if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
  1633. {
  1634. for (int i = 0; i < ByteNum; i++)
  1635. {
  1636. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  1637. }
  1638. }
  1639. else //根据设置自动转换10进制显示
  1640. {
  1641. if (checkBox_ReadRanFlash_ChangeFormat.Checked == true) //10进制显示
  1642. {
  1643. switch (ByteNum)
  1644. {
  1645. case 1:
  1646. {
  1647. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8]) + ", ");
  1648. break;
  1649. }
  1650. case 2:
  1651. {
  1652. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8)) + ", ");
  1653. break;
  1654. }
  1655. case 3:
  1656. {
  1657. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16)) + ", ");
  1658. break;
  1659. }
  1660. case 4:
  1661. {
  1662. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24)) + ", ");
  1663. break;
  1664. }
  1665. default:
  1666. {
  1667. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  1668. break;
  1669. }
  1670. }
  1671. }
  1672. else //16进制显示
  1673. {
  1674. switch (ByteNum)
  1675. {
  1676. case 1:
  1677. {
  1678. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8], 16).PadLeft(2, '0').ToUpper() + ", ");
  1679. break;
  1680. }
  1681. case 2:
  1682. {
  1683. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8), 16).PadLeft(4, '0').ToUpper() + ", ");
  1684. break;
  1685. }
  1686. case 3:
  1687. {
  1688. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16), 16).PadLeft(6, '0').ToUpper() + ", ");
  1689. break;
  1690. }
  1691. case 4:
  1692. {
  1693. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24), 16).PadLeft(8, '0').ToUpper() + ", ");
  1694. break;
  1695. }
  1696. default:
  1697. {
  1698. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  1699. break;
  1700. }
  1701. }
  1702. }
  1703. }
  1704. }));
  1705. }
  1706. break;
  1707. }
  1708. case 0xAB88://故障日志
  1709. {
  1710. unchecked
  1711. {
  1712. this.Invoke((EventHandler)(delegate
  1713. {
  1714. //电机存储的故障日志,一包128字节包含2条故障日志
  1715. var ErrorLogSaveInfo1 = new MC_ErrorLogSaveInfo_Struct_t();
  1716. var ErrorLogSaveInfo2 = new MC_ErrorLogSaveInfo_Struct_t();
  1717. ErrorLogSaveInfo1 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 8);
  1718. ErrorLogSaveInfo2 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 72);
  1719. //数据显示
  1720. ErrorLogDisplay(ErrorLogSaveInfo1, ErrorLogSaveInfo2);
  1721. }));
  1722. }
  1723. break;
  1724. }
  1725. case 0x1401://在线检测结果
  1726. {
  1727. unchecked
  1728. {
  1729. this.Invoke((EventHandler)(delegate
  1730. {
  1731. textBox_Online.Text = Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() + "H";
  1732. }));
  1733. }
  1734. break;
  1735. }
  1736. case 0x1510://骑行历史信息
  1737. {
  1738. unchecked
  1739. {
  1740. this.Invoke((EventHandler)(delegate
  1741. {
  1742. long DataTemp32;
  1743. //ODO里程
  1744. DataTemp32 = (long)((Data[3] << 24) + (Data[2] << 16) + (Data[1] << 8) + Data[0]);
  1745. textBox_OBC_ODO_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  1746. //ODO时间
  1747. DataTemp32 = (long)((Data[7] << 24) + (Data[6] << 16) + (Data[5] << 8) + Data[4]);
  1748. if (DataTemp32 >= 60 * 100000)
  1749. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  1750. else
  1751. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  1752. //TRIP里程
  1753. DataTemp32 = (long)((Data[11] << 24) + (Data[10] << 16) + (Data[9] << 8) + Data[8]);
  1754. textBox_OBC_TRIP_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  1755. //TRIP时间
  1756. DataTemp32 = (long)((Data[15] << 24) + (Data[14] << 16) + (Data[13] << 8) + Data[12]);
  1757. if (DataTemp32 >= 60 * 100000)
  1758. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  1759. else
  1760. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  1761. }));
  1762. }
  1763. break;
  1764. }
  1765. case 0x1720://客户信息
  1766. {
  1767. unchecked
  1768. {
  1769. this.Invoke((EventHandler)(delegate
  1770. {
  1771. //软件标识
  1772. textBox_SP.Text = "";
  1773. textBox_OBC_ReadSP.Text = "";
  1774. textBox_FacModeSP.Text = "";
  1775. for (ushort i = 0; i < 23; i++)
  1776. {
  1777. if (Data[i] == 'r')
  1778. {
  1779. Data[i] = (byte)'.';
  1780. }
  1781. textBox_SP.Text += ((char)Data[i]).ToString();
  1782. textBox_OBC_ReadSP.Text += ((char)Data[i]).ToString();
  1783. textBox_FacModeSP.Text += ((char)Data[i]).ToString();
  1784. }
  1785. //Git提交版本信息
  1786. textBox_FacModeGit.Text = "";
  1787. for (ushort i = 0; i < 9; i++)
  1788. {
  1789. textBox_SP.Text += ((char)Data[23 + i]).ToString();
  1790. textBox_FacModeGit.Text += ((char)Data[23 + i]).ToString();
  1791. }
  1792. Class_Motor_Ver.Special = textBox_SP.Text;
  1793. }));
  1794. }
  1795. break;
  1796. }
  1797. case 0xBA20: //调试信息
  1798. {
  1799. unchecked
  1800. {
  1801. this.Invoke((EventHandler)(delegate
  1802. {
  1803. MC_DebugInfo_Refresh = true;
  1804. //系统状态机
  1805. DataTemp = (short)(Data[0]);
  1806. textBox_DebugInfo_SysFun.Text = Convert.ToString(DataTemp);
  1807. //二层状态机
  1808. DataTemp = (short)(Data[1]);
  1809. textBox_DebugInfo_SecondFun.Text = Convert.ToString(DataTemp);
  1810. //电机状态机
  1811. DataTemp = (short)(Data[2]);
  1812. textBox_DebugInfo_MotorFun.Text = Convert.ToString(DataTemp);
  1813. //助力状态机
  1814. DataTemp = (short)(Data[3]);
  1815. textBox_DebugInfo_AssistFun.Text = Convert.ToString(DataTemp);
  1816. //IdRef
  1817. DataTemp = (short)(Data[5] * 256 + Data[4]);
  1818. textBox_DebugInfo_IdRef.Text = Convert.ToString(DataTemp);
  1819. //IqRef
  1820. DataTemp = (short)(Data[7] * 256 + Data[6]);
  1821. textBox_DebugInfo_IqRef.Text = Convert.ToString(DataTemp);
  1822. //UdRef
  1823. DataTemp = (short)(Data[9] * 256 + Data[8]);
  1824. textBox_DebugInfo_UdRef.Text = Convert.ToString(DataTemp);
  1825. //UqRef
  1826. DataTemp = (short)(Data[11] * 256 + Data[10]);
  1827. textBox_DebugInfo_UqRef.Text = Convert.ToString(DataTemp);
  1828. //瞬时力矩
  1829. DataTemp = (short)(Data[13] * 256 + Data[12]);
  1830. textBox_DebugInfo_TorquePu.Text = Convert.ToString(DataTemp);
  1831. //时间滤波力矩
  1832. DataTemp = (short)(Data[15] * 256 + Data[14]);
  1833. textBox_DebugInfo_TorqueFil.Text = Convert.ToString(DataTemp);
  1834. //踏频滤波力矩
  1835. DataTemp = (short)(Data[17] * 256 + Data[16]);
  1836. textBox_DebugInfo_TorqueCadence.Text = Convert.ToString(DataTemp);
  1837. //IdFdb
  1838. DataTemp = (short)(Data[19] * 256 + Data[18]);
  1839. textBox_DebugInfo_IdFdb.Text = Convert.ToString(DataTemp);
  1840. //IqFdb
  1841. DataTemp = (short)(Data[21] * 256 + Data[20]);
  1842. textBox_DebugInfo_IqFdb.Text = Convert.ToString(DataTemp);
  1843. //助力输出
  1844. DataTemp = (short)(Data[23] * 256 + Data[22]);
  1845. textBox_DebugInfo_AssistOut.Text = Convert.ToString(DataTemp);
  1846. //数据保存
  1847. RunInfoAutoSave();
  1848. }));
  1849. }
  1850. break;
  1851. }
  1852. case 0xBC20: //内阻校正信息
  1853. {
  1854. unchecked
  1855. {
  1856. this.Invoke((EventHandler)(delegate
  1857. {
  1858. //内阻1
  1859. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  1860. textBox_MOS_R1.Text = Convert.ToString(uData16);
  1861. //内阻2
  1862. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  1863. textBox_MOS_R2.Text = Convert.ToString(uData16);
  1864. //内阻3
  1865. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  1866. textBox_MOS_R3.Text = Convert.ToString(uData16);
  1867. //K1
  1868. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  1869. textBox_MOS_K1.Text = Convert.ToString(uData16);
  1870. //K2
  1871. uData16 = (ushort)(Data[9] * 256 + Data[8]);
  1872. textBox_MOS_K2.Text = Convert.ToString(uData16);
  1873. //K3
  1874. uData16 = (ushort)(Data[11] * 256 + Data[10]);
  1875. textBox_MOS_K3.Text = Convert.ToString(uData16);
  1876. //K4
  1877. uData16 = (ushort)(Data[13] * 256 + Data[12]);
  1878. textBox_MOS_K4.Text = Convert.ToString(uData16);
  1879. //K5
  1880. uData16 = (ushort)(Data[15] * 256 + Data[14]);
  1881. textBox_MOS_K5.Text = Convert.ToString(uData16);
  1882. }));
  1883. }
  1884. break;
  1885. }
  1886. case 0xC109: //Boot版本信息
  1887. {
  1888. BootInfo = "";
  1889. for (ushort i = 0; i < 9; i++)
  1890. {
  1891. BootInfo += ((char)Data[i]).ToString();
  1892. }
  1893. break;
  1894. }
  1895. default:
  1896. {
  1897. break;
  1898. }
  1899. }
  1900. }
  1901. #endregion
  1902. #region 解析BMS广播的命令
  1903. else if (ID == 0x720)
  1904. {
  1905. switch (CmdTemp)
  1906. {
  1907. case 0x1010://BMS运行信息
  1908. {
  1909. unchecked
  1910. {
  1911. this.Invoke((EventHandler)(delegate
  1912. {
  1913. BMS_RunInfo_Refresh = true;
  1914. richTextBox_OBC_BMS_RunInfo.Clear();
  1915. //电压
  1916. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  1917. richTextBox_OBC_BMS_RunInfo.AppendText("电压:" + Convert.ToString(uData16) + " mV" + "\r\n");
  1918. //电流
  1919. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  1920. richTextBox_OBC_BMS_RunInfo.AppendText("电流:" + Convert.ToString(uData16) + " mA" + "\r\n");
  1921. //剩余容量
  1922. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  1923. richTextBox_OBC_BMS_RunInfo.AppendText("剩余容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  1924. //满充容量
  1925. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  1926. richTextBox_OBC_BMS_RunInfo.AppendText("满充容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  1927. //电芯温度
  1928. richTextBox_OBC_BMS_RunInfo.AppendText("电芯温度:" + Convert.ToString((int)(Data[8] - 40) + " ℃" + "\r\n"));
  1929. //剩余电量
  1930. richTextBox_OBC_BMS_RunInfo.AppendText("剩余电量:" + Convert.ToString(Data[9]) + " %" + "\r\n");
  1931. //电池状态
  1932. richTextBox_OBC_BMS_RunInfo.AppendText("电池状态:" + Convert.ToString(Data[10], 16).PadLeft(2, '0').ToUpper() + " H" + "\r\n");
  1933. //SOH
  1934. richTextBox_OBC_BMS_RunInfo.AppendText("电池寿命:" + Convert.ToString(Data[11]) + " %" + "\r\n");
  1935. //循环次数
  1936. richTextBox_OBC_BMS_RunInfo.AppendText("循环次数:" + Convert.ToString((ushort)(Data[13] * 256 + Data[12])) + " 次");
  1937. }));
  1938. }
  1939. break;
  1940. }
  1941. default: break;
  1942. }
  1943. }
  1944. #endregion
  1945. #region 解析电机发送OBC的命令
  1946. else if (ID == 0x713)
  1947. {
  1948. switch (CmdTemp)
  1949. {
  1950. case 0x5408://电机用户参数
  1951. {
  1952. unchecked
  1953. {
  1954. this.Invoke((EventHandler)(delegate
  1955. {
  1956. richTextBox_OBC_ReadUserInfo.Clear();
  1957. //默认周长
  1958. richTextBox_OBC_ReadUserInfo.AppendText("默认周长:" + Convert.ToString((int)Data[0]) + " cm" + "\r\n");
  1959. //启动模式
  1960. richTextBox_OBC_ReadUserInfo.AppendText("启动模式:" + ((Data[1] == 0x01) ? "柔和" : (Data[1] == 0x02) ? "正常" : (Data[1] == 0x03) ? "强劲" : "无效") + "\r\n");
  1961. comboBox_OBC_StartMode.SelectedIndex = Data[1] - 1;
  1962. //限速
  1963. richTextBox_OBC_ReadUserInfo.AppendText("限速:" + Convert.ToString(Data[2]) + " km/h" + "\r\n");
  1964. //周长微调
  1965. numericUpDown_OBC_WheelAdj.Value = (int)(Data[3] > 128 ? (Data[3] - 256) : Data[3]);
  1966. richTextBox_OBC_ReadUserInfo.AppendText("周长微调:" + Convert.ToString(numericUpDown_OBC_WheelAdj.Value) + " cm" + "\r\n");
  1967. //助力方案
  1968. richTextBox_OBC_ReadUserInfo.AppendText("助力方案:" + Convert.ToString(Data[4]) + "\r\n");
  1969. comboBox_OBC_AssistFunc.SelectedIndex = Data[4] - 1;
  1970. //关机时间
  1971. richTextBox_OBC_ReadUserInfo.AppendText("关机时间:" + Convert.ToString(Data[5]) + " min" + "\r\n");
  1972. numericUpDown_OBC_OffTime.Value = (int)Data[5];
  1973. }));
  1974. }
  1975. break;
  1976. }
  1977. case 0x5303://电机应答反馈
  1978. {
  1979. unchecked
  1980. {
  1981. this.Invoke((EventHandler)(delegate
  1982. {
  1983. timer_1s.Enabled = false;
  1984. MessageBoxTimeOut.Show("OK", "反馈指令", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  1985. timer_1s.Enabled = true;
  1986. }));
  1987. }
  1988. break;
  1989. }
  1990. default: break;
  1991. }
  1992. }
  1993. #endregion
  1994. }
  1995. private void DataRevToString(ushort CmdTemp, byte[] Data)
  1996. {
  1997. CmdRevStrTemp = "";
  1998. CmdRevStrTemp += Convert.ToString(CmdTemp >> 8, 16).PadLeft(2, '0').ToUpper() + " ";
  1999. CmdRevStrTemp += Convert.ToString(CmdTemp & 0xFF, 16).PadLeft(2, '0').ToUpper() + " ";
  2000. ushort len = (ushort)(CmdTemp & 0x00FF);
  2001. for (int i = 0; i < len ; i++)
  2002. {
  2003. CmdRevStrTemp += Convert.ToString(Data[i], 16).PadLeft(2, '0').ToUpper() + " ";
  2004. }
  2005. }
  2006. #endregion
  2007. /// <summary>
  2008. /// 端口连接或断开
  2009. /// </summary>
  2010. private void PortConnect()
  2011. {
  2012. bool result = false;
  2013. if (连接ToolStripMenuItem.Text == "连接")
  2014. {
  2015. result = mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, 连接开机ToolStripMenuItem.Checked, 识别通讯盒ToolStripMenuItem.Checked);
  2016. if (result)
  2017. {
  2018. toolStripComboBox_ComNum.Enabled = false;
  2019. toolStripComboBox_Baudrate.Enabled = false;
  2020. 刷新ToolStripMenuItem.Enabled = false;
  2021. 连接ToolStripMenuItem.Text = "断开";
  2022. 连接ToolStripMenuItem.Checked = true;
  2023. label_COM_Sta.Text = toolStripComboBox_ComNum.Text + "已连接," + toolStripComboBox_Baudrate.Text;
  2024. label_PortStatus.BackColor = Color.Green;
  2025. }
  2026. }
  2027. else if (连接ToolStripMenuItem.Text == "断开")
  2028. {
  2029. checkBox_OBC_StartSetGearSt.Checked = false;
  2030. checkBox_OBC_StartReadBMS.Checked = false;
  2031. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2032. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  2033. toolStripComboBox_ComNum.Enabled = true;
  2034. toolStripComboBox_Baudrate.Enabled = true;
  2035. 刷新ToolStripMenuItem.Enabled = true;
  2036. 连接ToolStripMenuItem.Text = "连接";
  2037. 连接ToolStripMenuItem.Checked = false;
  2038. label_COM_Sta.Text = "连接状态:未连接";
  2039. label_PortStatus.BackColor = Color.Red;
  2040. }
  2041. }
  2042. /// <summary>
  2043. /// 端口连接事件
  2044. /// </summary>
  2045. /// <param name="sender"></param>
  2046. /// <param name="e"></param>
  2047. private void 连接ToolStripMenuItem_Click(object sender, System.EventArgs e)
  2048. {
  2049. PortConnect();
  2050. }
  2051. /// <summary>
  2052. /// 端口号刷新事件
  2053. /// </summary>
  2054. /// <param name="sender"></param>
  2055. /// <param name="e"></param>
  2056. private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
  2057. {
  2058. toolStripComboBox_ComNum.Items.Clear();
  2059. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  2060. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
  2061. }
  2062. /// <summary>
  2063. /// 转速调节事件
  2064. /// </summary>
  2065. /// <param name="sender"></param>
  2066. /// <param name="e"></param>
  2067. private void numericUpDown_SpeedAdj_ValueChanged(object sender, EventArgs e)
  2068. {
  2069. //生产模式转速设置值更新
  2070. trackBar_FacModeMotorSpeedAdj.Value = (int)numericUpDown_SpeedAdj.Value;
  2071. label_FacModeMotorSpeedSet.Text = trackBar_FacModeMotorSpeedAdj.Value.ToString() + "%";
  2072. //设置转速百分比
  2073. var Data = new byte[1];
  2074. Data[0] = (byte)numericUpDown_SpeedAdj.Value;
  2075. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  2076. }
  2077. /// <summary>
  2078. /// 存储标志修改事件
  2079. /// </summary>
  2080. /// <param name="sender"></param>
  2081. /// <param name="e"></param>
  2082. private void 写入存储ToolStripMenuItem_Click(object sender, EventArgs e)
  2083. {
  2084. 写入存储ToolStripMenuItem.Checked = !写入存储ToolStripMenuItem.Checked;
  2085. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  2086. }
  2087. /// <summary>
  2088. /// 1s定时器
  2089. /// </summary>
  2090. /// <param name="sender"></param>
  2091. /// <param name="e"></param>
  2092. private void timer_1s_Tick(object sender, EventArgs e)
  2093. {
  2094. //时间更新
  2095. label_SystemTime.Text = "系统时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2096. //MC_Runinfo超时清除
  2097. if (MC_RunInfo_Refresh == false)
  2098. {
  2099. MC_RunInfo_Refresh_Cnt++;
  2100. if (MC_RunInfo_Refresh_Cnt > 10)//5s
  2101. {
  2102. MC_RunInfo_Clear();
  2103. MC_RunInfo_Refresh_Cnt = 0;
  2104. }
  2105. }
  2106. else
  2107. {
  2108. MC_RunInfo_Refresh_Cnt = 0;
  2109. }
  2110. MC_RunInfo_Refresh = false;
  2111. //MC_Debuginfo超时清除
  2112. if (MC_DebugInfo_Refresh == false)
  2113. {
  2114. MC_DebugInfo_Refresh_Cnt++;
  2115. if (MC_DebugInfo_Refresh_Cnt > 10)//5s
  2116. {
  2117. MC_DebugInfo_Clear();
  2118. MC_DebugInfo_Refresh_Cnt = 0;
  2119. }
  2120. }
  2121. else
  2122. {
  2123. MC_DebugInfo_Refresh_Cnt = 0;
  2124. }
  2125. MC_DebugInfo_Refresh = false;
  2126. //BMS_RunInfo超时清除
  2127. if (BMS_RunInfo_Refresh == false)
  2128. {
  2129. BMS_RunInfo_Refresh_Cnt++;
  2130. if (BMS_RunInfo_Refresh_Cnt > 10)//5s
  2131. {
  2132. richTextBox_OBC_BMS_RunInfo.Clear();
  2133. BMS_RunInfo_Refresh_Cnt = 0;
  2134. }
  2135. }
  2136. else
  2137. {
  2138. BMS_RunInfo_Refresh_Cnt = 0;
  2139. }
  2140. BMS_RunInfo_Refresh = false;
  2141. //故障码超时清除
  2142. if (MC_ErrorCode_Refresh == false)
  2143. {
  2144. MC_ErrorCode_Refresh_Cnt++;
  2145. if (MC_ErrorCode_Refresh_Cnt > 10)//5s
  2146. {
  2147. textBox_ErrorCode.Text = "---";
  2148. MC_ErrorCode_Refresh_Cnt = 0;
  2149. }
  2150. }
  2151. else
  2152. {
  2153. MC_ErrorCode_Refresh_Cnt = 0;
  2154. }
  2155. MC_ErrorCode_Refresh = false;
  2156. //CDL连接超时
  2157. if (识别通讯盒ToolStripMenuItem.Checked)
  2158. {
  2159. if (mySerialProcess.CDL_Online_Flag == false)
  2160. {
  2161. mySerialProcess.CDL_OnlineCheck_Cnt++;
  2162. if (mySerialProcess.CDL_OnlineCheck_Cnt > 1)//1s
  2163. {
  2164. timer_1s.Enabled = false;
  2165. MessageBox.Show("连接失败!", "提示");
  2166. timer_1s.Enabled = true;
  2167. //关闭串口
  2168. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  2169. toolStripComboBox_ComNum.Enabled = true;
  2170. toolStripComboBox_Baudrate.Enabled = true;
  2171. 刷新ToolStripMenuItem.Enabled = true;
  2172. 连接ToolStripMenuItem.Text = "连接";
  2173. 连接ToolStripMenuItem.Checked = false;
  2174. label_COM_Sta.Text = "连接状态:未连接";
  2175. label_PortStatus.BackColor = Color.Red;
  2176. }
  2177. }
  2178. }
  2179. //OBC定时发送设置档位
  2180. if (checkBox_OBC_StartSetGearSt.Checked == true)
  2181. {
  2182. var CtrlCode = new byte[2];
  2183. if (comboBox_OBC_SetGearST.SelectedIndex == 5)//档位
  2184. CtrlCode[0] = 0x33;
  2185. else if (comboBox_OBC_SetGearST.SelectedIndex == 6)//档位
  2186. CtrlCode[0] = 0x22;
  2187. else
  2188. CtrlCode[0] = (byte)comboBox_OBC_SetGearST.SelectedIndex;
  2189. if (comboBox_OBC_LightSw.SelectedIndex == 0)//车灯
  2190. CtrlCode[1] = 0xF1;
  2191. else
  2192. CtrlCode[1] = 0xF0;
  2193. if (!mySerialProcess.SendCmdWithoutNotice((ushort)0x731, (byte)0x0C, (ushort)0x3002, CtrlCode))
  2194. {
  2195. checkBox_OBC_StartSetGearSt.Checked = false;
  2196. }
  2197. }
  2198. //OBC定时发送查询电池
  2199. if (checkBox_OBC_StartReadBMS.Checked == true)
  2200. {
  2201. if (!mySerialProcess.SendCmd((ushort)0x732, (byte)0x11, (ushort)0x5000, null))
  2202. {
  2203. checkBox_OBC_StartReadBMS.Checked = false;
  2204. }
  2205. }
  2206. //定时读取存储器
  2207. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  2208. {
  2209. var Address = new byte[4];
  2210. UInt32 Address_Begin;
  2211. UInt32 Addres_End;
  2212. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  2213. richTextBox_RamFlasgData.Clear();
  2214. do
  2215. {
  2216. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  2217. {
  2218. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2219. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2220. continue;
  2221. }
  2222. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  2223. {
  2224. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2225. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2226. continue;
  2227. }
  2228. else
  2229. {
  2230. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  2231. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2232. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  2233. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2234. if (Addres_End < Address_Begin)
  2235. {
  2236. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2237. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2238. continue;
  2239. }
  2240. else
  2241. {
  2242. var SendByte = new byte[8];
  2243. SendByte[0] = (byte)(Address_Begin >> 24);
  2244. SendByte[1] = (byte)(Address_Begin >> 16);
  2245. SendByte[2] = (byte)(Address_Begin >> 8);
  2246. SendByte[3] = (byte)(Address_Begin);
  2247. SendByte[4] = (byte)(Addres_End >> 24);
  2248. SendByte[5] = (byte)(Addres_End >> 16);
  2249. SendByte[6] = (byte)(Addres_End >> 8);
  2250. SendByte[7] = (byte)(Addres_End);
  2251. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte))
  2252. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2253. }
  2254. }
  2255. } while (false);
  2256. }
  2257. //写入参数等待计时
  2258. ACK_WaitCnt++;
  2259. }
  2260. /// <summary>
  2261. /// 运行信息清除
  2262. /// </summary>
  2263. private void MC_RunInfo_Clear()
  2264. {
  2265. foreach (Control c in tabPage_RunInfo.Controls)
  2266. {
  2267. if ((c is TextBox))
  2268. {
  2269. if (c.Name != textBox_ErrorCode.ToString())
  2270. c.Text = "---";
  2271. }
  2272. }
  2273. }
  2274. /// <summary>
  2275. /// 调试信息清除
  2276. /// </summary>
  2277. private void MC_DebugInfo_Clear()
  2278. {
  2279. foreach (Control c in tabPage_DebugInfo.Controls)
  2280. {
  2281. if ((c is TextBox))
  2282. {
  2283. if (c.Name != textBox_ErrorCode.ToString())
  2284. c.Text = "---";
  2285. }
  2286. }
  2287. }
  2288. /// <summary>
  2289. /// 读取马达参数
  2290. /// </summary>
  2291. /// <param name="sender"></param>
  2292. /// <param name="e"></param>
  2293. private void button_Read_MotorParam_Click(object sender, EventArgs e)
  2294. {
  2295. richTextBox_MotorParam.Clear();
  2296. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null);
  2297. }
  2298. /// <summary>
  2299. /// 写入马达参数
  2300. /// </summary>
  2301. /// <param name="sender"></param>
  2302. /// <param name="e"></param>
  2303. private void button_Write_Click(object sender, EventArgs e)
  2304. {
  2305. var ConfigParam = new byte[40];
  2306. for (int i = 0; i < 40; i++)
  2307. ConfigParam[i] = 0;
  2308. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2309. short wDataTemp = 0;
  2310. ushort DataTemp = 0;
  2311. string[] strDataTemp = richTextBox_MotorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2312. try
  2313. {
  2314. for (int i = 0; i < strDataTemp.Length; i++)
  2315. {
  2316. if (i == 6)
  2317. {
  2318. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  2319. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  2320. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  2321. }
  2322. else
  2323. {
  2324. DataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2325. ConfigParam[2 * i + 2] = (byte)DataTemp;
  2326. ConfigParam[2 * i + 3] = (byte)(DataTemp >> 8);
  2327. }
  2328. }
  2329. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B28, ConfigParam);
  2330. }
  2331. catch (Exception)
  2332. {
  2333. timer_1s.Enabled = false;
  2334. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2335. timer_1s.Enabled = true;
  2336. }
  2337. }
  2338. /// <summary>
  2339. /// 读取整车信息
  2340. /// </summary>
  2341. /// <param name="sender"></param>
  2342. /// <param name="e"></param>
  2343. private void button_ReadBikeParam_Click(object sender, EventArgs e)
  2344. {
  2345. richTextBox_BikeParam.Clear();
  2346. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null);
  2347. }
  2348. /// <summary>
  2349. /// 写入整车信息
  2350. /// </summary>
  2351. /// <param name="sender"></param>
  2352. /// <param name="e"></param>
  2353. private void button_WriteBikeParam_Click(object sender, EventArgs e)
  2354. {
  2355. var ConfigParam = new byte[28];
  2356. for (int i = 0; i < 28; i++)
  2357. ConfigParam[i] = 0;
  2358. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2359. string[] strDataTemp = richTextBox_BikeParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2360. try
  2361. {
  2362. for (int i = 0; i < strDataTemp.Length; i++)
  2363. {
  2364. short wDataTemp = 0;
  2365. //前后灯参数修改
  2366. if (i == 8)
  2367. {
  2368. wDataTemp |= (short)((comboBox_TailLightMode.SelectedIndex + 1) << 12); //Bit15~Bit12:尾灯模式
  2369. wDataTemp |= (short)((comboBox_TailLightVol.SelectedIndex == 0 ? 6 : 12) << 8); //Bit11~Bit8:尾灯电压
  2370. wDataTemp |= (short)(comboBox_FrontLightVol.SelectedIndex == 0 ? 6 : 12); //Bit7~Bit0:前灯电压
  2371. }
  2372. //开关机参数
  2373. else if (i == 11)
  2374. {
  2375. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOnDelay.Text) << 12);
  2376. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOffDelay.Text) << 8);
  2377. wDataTemp |= (short)(Convert.ToInt16(textBox_AutoPowerOff.Text));
  2378. }
  2379. else
  2380. {
  2381. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  2382. }
  2383. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  2384. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  2385. }
  2386. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D1C, ConfigParam);
  2387. }
  2388. catch (Exception)
  2389. {
  2390. timer_1s.Enabled = false;
  2391. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2392. timer_1s.Enabled = true;
  2393. }
  2394. }
  2395. /// <summary>
  2396. /// 读取控制器参数
  2397. /// </summary>
  2398. /// <param name="sender"></param>
  2399. /// <param name="e"></param>
  2400. private void button_ReadControlParam_Click(object sender, EventArgs e)
  2401. {
  2402. richTextBox_ControlParam.Clear();
  2403. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
  2404. }
  2405. /// <summary>
  2406. /// 写入控制器参数
  2407. /// </summary>
  2408. /// <param name="sender"></param>
  2409. /// <param name="e"></param>
  2410. private void button_WriteControlParam_Click(object sender, EventArgs e)
  2411. {
  2412. var ConfigParam = new byte[34];
  2413. for (int i = 0; i < 34; i++)
  2414. ConfigParam[i] = 0;
  2415. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2416. ushort uwDataTemp = 0;
  2417. string[] strDataTemp = richTextBox_ControlParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2418. try
  2419. {
  2420. for (int i = 0; i < strDataTemp.Length; i++)
  2421. {
  2422. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2423. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2424. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2425. }
  2426. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3F22, ConfigParam);
  2427. }
  2428. catch (Exception)
  2429. {
  2430. timer_1s.Enabled = false;
  2431. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2432. timer_1s.Enabled = true;
  2433. }
  2434. }
  2435. /// <summary>
  2436. /// 读取助力参数
  2437. /// </summary>
  2438. /// <param name="sender"></param>
  2439. /// <param name="e"></param>
  2440. private void button_ReadAssistParam_Click(object sender, EventArgs e)
  2441. {
  2442. var ConfigParam = new byte[4];
  2443. int AssistNum = 0;
  2444. try
  2445. {
  2446. AssistNum = Convert.ToInt32(comboBox_AssistTorque.Text);
  2447. ConfigParam[0] = (byte)(AssistNum & 0xFF);
  2448. ConfigParam[1] = (byte)(AssistNum >> 8);
  2449. AssistNum = Convert.ToInt32(comboBox_AssistCadence.Text);
  2450. ConfigParam[2] = (byte)(AssistNum & 0xFF);
  2451. ConfigParam[3] = (byte)(AssistNum >> 8);
  2452. richTextBox_AssistParam.Clear();
  2453. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam);
  2454. }
  2455. catch (Exception)
  2456. {
  2457. timer_1s.Enabled = false;
  2458. MessageBox.Show("请选择助力参数编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2459. timer_1s.Enabled = true;
  2460. }
  2461. }
  2462. /// <summary>
  2463. /// 写入助力参数
  2464. /// </summary>
  2465. /// <param name="sender"></param>
  2466. /// <param name="e"></param>
  2467. private void button_WriteAssistParam_Click(object sender, EventArgs e)
  2468. {
  2469. var ConfigParam = new byte[80];
  2470. for (int i = 0; i < 80; i++)
  2471. ConfigParam[i] = 0;
  2472. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2473. long lDataTemp = 0;
  2474. string[] strDataTemp = richTextBox_AssistParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2475. int index_1 = 0, index_2 = 0;
  2476. try
  2477. {
  2478. for (int i = 0; i < strDataTemp.Length; i++)
  2479. {
  2480. if (strDataTemp[i].Split('=')[0] == "转矩曲线.a")
  2481. {
  2482. index_1 = i;
  2483. break;
  2484. }
  2485. }
  2486. for (int i = 0; i < strDataTemp.Length; i++)
  2487. {
  2488. if (strDataTemp[i].Split('=')[0] == "踏频曲线.d")
  2489. {
  2490. index_2 = i;
  2491. break;
  2492. }
  2493. }
  2494. for (int i = 0; i < strDataTemp.Length; i++)
  2495. {
  2496. lDataTemp = Convert.ToInt32(strDataTemp[i].Split('=')[1]);
  2497. if (i < index_1)
  2498. {
  2499. ConfigParam[2 * i + 4] = (byte)lDataTemp;
  2500. ConfigParam[2 * i + 5] = (byte)(lDataTemp >> 8);
  2501. }
  2502. else if (i <= index_2)
  2503. {
  2504. ConfigParam[4 * i - 4] = (byte)lDataTemp;
  2505. ConfigParam[4 * i - 3] = (byte)(lDataTemp >> 8);
  2506. ConfigParam[4 * i - 2] = (byte)(lDataTemp >> 16);
  2507. ConfigParam[4 * i - 1] = (byte)(lDataTemp >> 24);
  2508. }
  2509. else
  2510. {
  2511. ConfigParam[2 * i + 20] = (byte)lDataTemp;
  2512. ConfigParam[2 * i + 21] = (byte)(lDataTemp >> 8);
  2513. }
  2514. }
  2515. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4450, ConfigParam);
  2516. }
  2517. catch (Exception)
  2518. {
  2519. timer_1s.Enabled = false;
  2520. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2521. timer_1s.Enabled = true;
  2522. }
  2523. }
  2524. /// <summary>
  2525. /// 读取调试参数
  2526. /// </summary>
  2527. /// <param name="sender"></param>
  2528. /// <param name="e"></param>
  2529. private void button_ReadDebugParam_Click(object sender, EventArgs e)
  2530. {
  2531. richTextBox_DebugParam.Clear();
  2532. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  2533. }
  2534. /// <summary>
  2535. /// 写入调试参数
  2536. /// </summary>
  2537. /// <param name="sender"></param>
  2538. /// <param name="e"></param>
  2539. private void button_WriteDebugParam_Click(object sender, EventArgs e)
  2540. {
  2541. var ConfigParam = new byte[60];
  2542. for (int i = 0; i < 60; i++)
  2543. ConfigParam[i] = 0;
  2544. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2545. ushort uwDataTemp = 0;
  2546. string[] strDataTemp = richTextBox_DebugParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2547. try
  2548. {
  2549. for (int i = 0; i < strDataTemp.Length; i++)
  2550. {
  2551. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2552. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2553. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2554. }
  2555. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam);
  2556. }
  2557. catch (Exception)
  2558. {
  2559. timer_1s.Enabled = false;
  2560. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2561. timer_1s.Enabled = true;
  2562. }
  2563. }
  2564. /// <summary>
  2565. /// 读取历史
  2566. /// </summary>
  2567. /// <param name="sender"></param>
  2568. /// <param name="e"></param>
  2569. private void button_ReadRecord_Click(object sender, EventArgs e)
  2570. {
  2571. richTextBox_Record.Clear();
  2572. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null);
  2573. }
  2574. /// <summary>
  2575. /// 读取传感器参数
  2576. /// </summary>
  2577. /// <param name="sender"></param>
  2578. /// <param name="e"></param>
  2579. private void button_ReadSensorParam_Click(object sender, EventArgs e)
  2580. {
  2581. richTextBox_SensorParam.Clear();
  2582. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  2583. }
  2584. /// <summary>
  2585. /// 写入力矩传感器标定值
  2586. /// </summary>
  2587. /// <param name="sender"></param>
  2588. /// <param name="e"></param>
  2589. private void button_Write_Cal_Click(object sender, EventArgs e)
  2590. {
  2591. var ConfigParam = new byte[4];
  2592. for (int i = 0; i < 4; i++)
  2593. ConfigParam[i] = 0;
  2594. ushort uwDataTemp = 0;
  2595. try
  2596. {
  2597. uwDataTemp = Convert.ToUInt16(comboBox_TorqueSet.Text);//负载序号
  2598. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  2599. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  2600. uwDataTemp = (ushort)(decimal.Parse(textBox_Load.Text) * 10); ;//负载值0.1Nm
  2601. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  2602. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  2603. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  2604. }
  2605. catch (Exception)
  2606. {
  2607. timer_1s.Enabled = false;
  2608. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2609. timer_1s.Enabled = true;
  2610. }
  2611. }
  2612. /// <summary>
  2613. /// 写入传感器参数
  2614. /// </summary>
  2615. /// <param name="sender"></param>
  2616. /// <param name="e"></param>
  2617. private void button_WriteSensorParam_Click(object sender, EventArgs e)
  2618. {
  2619. var ConfigParam = new byte[14];
  2620. for (int i = 0; i < 14; i++)
  2621. ConfigParam[i] = 0;
  2622. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2623. ushort uwDataTemp = 0;
  2624. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  2625. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2626. int index = 0;
  2627. try
  2628. {
  2629. for (int i = 0; i < strDataTemp.Length; i++)
  2630. {
  2631. if (strDataTemp[i].Split('=')[0] == "力矩传感器踏频脉冲数")
  2632. {
  2633. index = i;
  2634. break;
  2635. }
  2636. }
  2637. for (int i = 0; i < (strDataTemp.Length - index); i++)
  2638. {
  2639. uwDataTemp = Convert.ToUInt16(strDataTemp[i + index].Split('=')[1]);
  2640. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2641. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2642. }
  2643. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x420E, ConfigParam);
  2644. }
  2645. catch (Exception)
  2646. {
  2647. timer_1s.Enabled = false;
  2648. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2649. timer_1s.Enabled = true;
  2650. }
  2651. }
  2652. /// <summary>
  2653. /// 写入型号
  2654. /// </summary>
  2655. /// <param name="sender"></param>
  2656. /// <param name="e"></param>
  2657. private void button_WriteModel_Click(object sender, EventArgs e)
  2658. {
  2659. string Mode = textBox_Model.Text;
  2660. var ModeArray = new byte[16];
  2661. for (ushort i = 0; i < Mode.Length; i++)
  2662. {
  2663. ModeArray[i] = (byte)Mode[i];
  2664. }
  2665. if (Mode.Length < 16)
  2666. {
  2667. ModeArray[Mode.Length] = (byte)'.';
  2668. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  2669. {
  2670. ModeArray[Mode.Length + 1 + i] = 0x20;
  2671. }
  2672. }
  2673. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  2674. }
  2675. /// <summary>
  2676. /// 写入SN
  2677. /// </summary>
  2678. /// <param name="sender"></param>
  2679. /// <param name="e"></param>
  2680. private void button_WriteSN_Click(object sender, EventArgs e)
  2681. {
  2682. string SN = textBox_SN.Text;
  2683. var SNArray = new byte[16];
  2684. for (ushort i = 0; i < SN.Length; i++)
  2685. {
  2686. SNArray[i] = (byte)SN[i];
  2687. }
  2688. if (SN.Length < 16)
  2689. {
  2690. SNArray[SN.Length] = (byte)'.';
  2691. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  2692. {
  2693. SNArray[SN.Length + 1 + i] = 0x20;
  2694. }
  2695. }
  2696. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  2697. }
  2698. /// <summary>
  2699. /// 查询版本信息
  2700. /// </summary>
  2701. /// <param name="sender"></param>
  2702. /// <param name="e"></param>
  2703. private void button_ReadVersion_Click(object sender, EventArgs e)
  2704. {
  2705. textBox_Model.Text = "---";
  2706. textBox_SN.Text = "---";
  2707. textBox_HW.Text = "---";
  2708. textBox_FW.Text = "---";
  2709. textBox_SP.Text = "---";
  2710. textBox_OBC_ReadModel.Text = "---";
  2711. textBox_OBC_ReadSN.Text = "---";
  2712. textBox_OBC_ReadHW.Text = "---";
  2713. textBox_OBC_ReadFW.Text = "---";
  2714. textBox_OBC_ReadSP.Text = "---";
  2715. textBox_FacModeName.Text = "---";
  2716. textBox_FacModeNum.Text = "---";
  2717. textBox_FacModeHW.Text = "---";
  2718. textBox_FacModeFW.Text = "---";
  2719. textBox_FacModeSP.Text = "---";
  2720. Class_Motor_Ver.Mode = "---";
  2721. Class_Motor_Ver.SN = "---";
  2722. Class_Motor_Ver.HW = "---";
  2723. Class_Motor_Ver.FW = "---";
  2724. Class_Motor_Ver.Special = "---";
  2725. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  2726. }
  2727. /// <summary>
  2728. /// 查询自定义1
  2729. /// </summary>
  2730. /// <param name="sender"></param>
  2731. /// <param name="e"></param>
  2732. private void button_ReadUser1_Click(object sender, EventArgs e)
  2733. {
  2734. textBox_User1.Text = "---";
  2735. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null);
  2736. }
  2737. /// <summary>
  2738. /// 查询自定义2
  2739. /// </summary>
  2740. /// <param name="sender"></param>
  2741. /// <param name="e"></param>
  2742. private void button_ReadUser2_Click(object sender, EventArgs e)
  2743. {
  2744. textBox_User2.Text = "---";
  2745. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null);
  2746. }
  2747. /// <summary>
  2748. /// 查询自定义3
  2749. /// </summary>
  2750. /// <param name="sender"></param>
  2751. /// <param name="e"></param>
  2752. private void button_ReadUser3_Click(object sender, EventArgs e)
  2753. {
  2754. textBox_User3.Text = "---";
  2755. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null);
  2756. }
  2757. /// <summary>
  2758. /// 写入自定义字符串1
  2759. /// </summary>
  2760. /// <param name="sender"></param>
  2761. /// <param name="e"></param>
  2762. private void button_WriteUser1_Click(object sender, EventArgs e)
  2763. {
  2764. string User = textBox_User1.Text;
  2765. var UserArray = new byte[16];
  2766. for (ushort i = 0; i < User.Length; i++)
  2767. {
  2768. UserArray[i] = (byte)User[i];
  2769. }
  2770. if (User.Length < 16)
  2771. {
  2772. UserArray[User.Length] = (byte)'.';
  2773. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  2774. {
  2775. UserArray[User.Length + 1 + i] = 0x20;
  2776. }
  2777. }
  2778. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1410, UserArray);
  2779. }
  2780. /// <summary>
  2781. /// 写入自定义字符串2
  2782. /// </summary>
  2783. /// <param name="sender"></param>
  2784. /// <param name="e"></param>
  2785. private void button_WriteUser2_Click(object sender, EventArgs e)
  2786. {
  2787. string User = textBox_User2.Text;
  2788. var UserArray = new byte[16];
  2789. for (ushort i = 0; i < User.Length; i++)
  2790. {
  2791. UserArray[i] = (byte)User[i];
  2792. }
  2793. if (User.Length < 16)
  2794. {
  2795. UserArray[User.Length] = (byte)'.';
  2796. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  2797. {
  2798. UserArray[User.Length + 1 + i] = 0x20;
  2799. }
  2800. }
  2801. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1610, UserArray);
  2802. }
  2803. /// <summary>
  2804. /// 写入自定义字符串3
  2805. /// </summary>
  2806. /// <param name="sender"></param>
  2807. /// <param name="e"></param>
  2808. private void button_WriteUser3_Click(object sender, EventArgs e)
  2809. {
  2810. string User = textBox_User3.Text;
  2811. var UserArray = new byte[16];
  2812. for (ushort i = 0; i < User.Length; i++)
  2813. {
  2814. UserArray[i] = (byte)User[i];
  2815. }
  2816. if (User.Length < 16)
  2817. {
  2818. UserArray[User.Length] = (byte)'.';
  2819. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  2820. {
  2821. UserArray[User.Length + 1 + i] = 0x20;
  2822. }
  2823. }
  2824. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1810, UserArray);
  2825. }
  2826. /// <summary>
  2827. /// 查询生产信息
  2828. /// </summary>
  2829. /// <param name="sender"></param>
  2830. /// <param name="e"></param>
  2831. private void button_ReadMAC_Click(object sender, EventArgs e)
  2832. {
  2833. textBox_MAC.Text = "---";
  2834. textBox_MACAdd.Text = "---";
  2835. textBox_MACDate.Text = "---";
  2836. textBox_PP.Text = "---";
  2837. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null);
  2838. }
  2839. /// <summary>
  2840. /// 写入生产信息
  2841. /// </summary>
  2842. /// <param name="sender"></param>
  2843. /// <param name="e"></param>
  2844. private void button_WriteMac_Click(object sender, EventArgs e)
  2845. {
  2846. var MACArray = new byte[32];
  2847. //填入生产商
  2848. for (ushort i = 0; i < textBox_MAC.Text.Length; i++)
  2849. {
  2850. MACArray[i] = (byte)textBox_MAC.Text[i];
  2851. }
  2852. if (textBox_MAC.Text.Length < 8)
  2853. {
  2854. MACArray[textBox_MAC.Text.Length] = (byte)'.';
  2855. for (ushort i = 0; i < 8 - textBox_MAC.Text.Length - 1; i++)
  2856. {
  2857. MACArray[textBox_MAC.Text.Length + 1 + i] = 0x20;
  2858. }
  2859. }
  2860. //填入生产地
  2861. for (ushort i = 0; i < textBox_MACAdd.Text.Length; i++)
  2862. {
  2863. MACArray[8 + i] = (byte)textBox_MACAdd.Text[i];
  2864. }
  2865. if (textBox_MACAdd.Text.Length < 8)
  2866. {
  2867. MACArray[textBox_MACAdd.Text.Length + 8] = (byte)'.';
  2868. for (ushort i = 0; i < 8 - textBox_MACAdd.Text.Length - 1; i++)
  2869. {
  2870. MACArray[textBox_MACAdd.Text.Length + 1 + i + 8] = 0x20;
  2871. }
  2872. }
  2873. //填入生产日期
  2874. for (ushort i = 0; i < textBox_MACDate.Text.Length; i++)
  2875. {
  2876. MACArray[16 + i] = (byte)textBox_MACDate.Text[i];
  2877. }
  2878. if (textBox_MACDate.Text.Length < 8)
  2879. {
  2880. MACArray[textBox_MACDate.Text.Length + 16] = (byte)'.';
  2881. for (ushort i = 0; i < 8 - textBox_MACDate.Text.Length - 1; i++)
  2882. {
  2883. MACArray[textBox_MACDate.Text.Length + 1 + i + 16] = 0x20;
  2884. }
  2885. }
  2886. //填入品牌
  2887. for (ushort i = 0; i < textBox_PP.Text.Length; i++)
  2888. {
  2889. MACArray[24 + i] = (byte)textBox_PP.Text[i];
  2890. }
  2891. if (textBox_PP.Text.Length < 8)
  2892. {
  2893. MACArray[textBox_PP.Text.Length + 24] = (byte)'.';
  2894. for (ushort i = 0; i < 8 - textBox_PP.Text.Length - 1; i++)
  2895. {
  2896. MACArray[textBox_PP.Text.Length + 1 + i + 24] = 0x20;
  2897. }
  2898. }
  2899. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  2900. }
  2901. /// <summary>
  2902. /// 查询密钥
  2903. /// </summary>
  2904. /// <param name="sender"></param>
  2905. /// <param name="e"></param>
  2906. private void button_ReadKey_Click(object sender, EventArgs e)
  2907. {
  2908. textBox_Key.Text = "---";
  2909. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null);
  2910. }
  2911. /// <summary>
  2912. /// 写入校验密钥
  2913. /// </summary>
  2914. /// <param name="sender"></param>
  2915. /// <param name="e"></param>
  2916. private void button_WriteKey_Click(object sender, EventArgs e)
  2917. {
  2918. string Key = textBox_Key.Text;
  2919. var KeyArray = new byte[8];
  2920. if (Key.Length != 8)
  2921. {
  2922. timer_1s.Enabled = false;
  2923. MessageBox.Show("请检查字符长度是否为8", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2924. timer_1s.Enabled = true;
  2925. return;
  2926. }
  2927. for (ushort i = 0; i < Key.Length; i++)
  2928. {
  2929. KeyArray[i] = (byte)Key[i];
  2930. }
  2931. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1108, KeyArray);
  2932. }
  2933. /// <summary>
  2934. /// 查询在线检测结果
  2935. /// </summary>
  2936. /// <param name="sender"></param>
  2937. /// <param name="e"></param>
  2938. private void button_ReadOnLine_Click(object sender, EventArgs e)
  2939. {
  2940. textBox_Online.Text = "---";
  2941. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2100, null);
  2942. }
  2943. /// <summary>
  2944. /// 系统清除
  2945. /// </summary>
  2946. /// <param name="sender"></param>
  2947. /// <param name="e"></param>
  2948. private void button_SystemClear_Click(object sender, EventArgs e)
  2949. {
  2950. var Code = new byte[5];
  2951. Code[0] = (byte)'C';
  2952. Code[1] = (byte)'L';
  2953. Code[2] = (byte)'E';
  2954. Code[3] = (byte)'A';
  2955. Code[4] = (byte)'R';
  2956. timer_1s.Enabled = false;
  2957. if (MessageBox.Show("系统清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2958. {
  2959. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2960. {
  2961. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2962. {
  2963. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  2964. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  2965. }
  2966. }
  2967. }
  2968. timer_1s.Enabled = true;
  2969. }
  2970. /// <summary>
  2971. /// 参数还原
  2972. /// </summary>
  2973. /// <param name="sender"></param>
  2974. /// <param name="e"></param>
  2975. private void button_Recovery_Click(object sender, EventArgs e)
  2976. {
  2977. var Code = new byte[8];
  2978. Code[0] = (byte)'R';
  2979. Code[1] = (byte)'E';
  2980. Code[2] = (byte)'C';
  2981. Code[3] = (byte)'O';
  2982. Code[4] = (byte)'V';
  2983. Code[5] = (byte)'E';
  2984. Code[6] = (byte)'R';
  2985. Code[7] = (byte)'Y';
  2986. timer_1s.Enabled = false;
  2987. if (MessageBox.Show("参数还原后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2988. {
  2989. if (MessageBox.Show("请再次确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2990. {
  2991. if (MessageBox.Show("请最后确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2992. {
  2993. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2708, Code);
  2994. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  2995. }
  2996. }
  2997. }
  2998. timer_1s.Enabled = true;
  2999. }
  3000. /// <summary>
  3001. /// 系统复位
  3002. /// </summary>
  3003. /// <param name="sender"></param>
  3004. /// <param name="e"></param>
  3005. private void button_Reset_Click(object sender, EventArgs e)
  3006. {
  3007. var Code_Off = new byte[5];
  3008. var Code_Reset = new byte[5];
  3009. Code_Off[0] = (byte)'O';
  3010. Code_Off[1] = (byte)'F';
  3011. Code_Off[2] = (byte)'F';
  3012. Code_Off[3] = (byte)'.';
  3013. Code_Off[4] = (byte)'.';
  3014. Code_Reset[0] = (byte)'R';
  3015. Code_Reset[1] = (byte)'E';
  3016. Code_Reset[2] = (byte)'S';
  3017. Code_Reset[3] = (byte)'E';
  3018. Code_Reset[4] = (byte)'T';
  3019. timer_1s.Enabled = false;
  3020. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3021. {
  3022. timer_1s.Enabled = true;
  3023. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  3024. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  3025. PowerOffAckStatus = false;
  3026. Delay_ms(250);
  3027. int TryCnt = 3;
  3028. while ((TryCnt--) >= 0)
  3029. {
  3030. if (!PowerOffAckStatus)
  3031. {
  3032. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  3033. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  3034. PowerOffAckStatus = false;
  3035. Delay_ms(250);
  3036. }
  3037. else break;
  3038. }
  3039. if (PowerOffAckStatus)
  3040. {
  3041. timer_1s.Enabled = false;
  3042. MessageBoxTimeOut.Show("已关机!", "提示", 3000, MessageBoxButtons.OK, MessageBoxIcon.None);
  3043. timer_1s.Enabled = true;
  3044. }
  3045. else
  3046. {
  3047. timer_1s.Enabled = false;
  3048. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3049. timer_1s.Enabled = true;
  3050. }
  3051. }
  3052. timer_1s.Enabled = true;
  3053. }
  3054. /// <summary>
  3055. /// 记录清除
  3056. /// </summary>
  3057. /// <param name="sender"></param>
  3058. /// <param name="e"></param>
  3059. private void button_ClearLog_Click(object sender, EventArgs e)
  3060. {
  3061. var Code = new byte[9];
  3062. Code[0] = (byte)'L';
  3063. Code[1] = (byte)'O';
  3064. Code[2] = (byte)'G';
  3065. Code[3] = (byte)' ';
  3066. Code[4] = (byte)'C';
  3067. Code[5] = (byte)'L';
  3068. Code[6] = (byte)'E';
  3069. Code[7] = (byte)'A';
  3070. Code[8] = (byte)'R';
  3071. timer_1s.Enabled = false;
  3072. if (MessageBox.Show("历史记录信息清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3073. {
  3074. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3075. {
  3076. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3077. {
  3078. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3909, Code);
  3079. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3080. }
  3081. }
  3082. }
  3083. timer_1s.Enabled = true;
  3084. }
  3085. /// <summary>
  3086. /// 打开系统计算器
  3087. /// </summary>
  3088. /// <param name="sender"></param>
  3089. /// <param name="e"></param>
  3090. private void 计算器ToolStripMenuItem_Click(object sender, EventArgs e)
  3091. {
  3092. System.Diagnostics.Process.Start("calc.exe");
  3093. }
  3094. /// <summary>
  3095. ///故障转换和显示
  3096. /// </summary>
  3097. List<string> ErrorInfo = new List<string>{ "过流保护", "低压保护", "过压保护", "堵转保护","过热保护","速度传感器故障","力矩传感器故障","霍尔故障",
  3098. "马达缺相","NTC故障","BMS校验失败","","OBC校验失败","MCU故障","踏频传感器故障","指拨故障","MOS短路","电压异常","","","","","","","","","","","","",
  3099. "",""};
  3100. private string ErrorInfoDisplay(UInt32 Code)
  3101. {
  3102. string Result = "";
  3103. if (Code == 0)
  3104. {
  3105. Result = "无故障";
  3106. }
  3107. else
  3108. {
  3109. for (int i = 0; i < 32; i++)
  3110. {
  3111. if ((Code & 0x01) == 0x01)
  3112. {
  3113. Result += ErrorInfo[i] + " ";
  3114. }
  3115. Code >>= 1;
  3116. }
  3117. }
  3118. return Result;
  3119. }
  3120. /// <summary>
  3121. /// 鼠标滑过故障码显示具体内容
  3122. /// </summary>
  3123. /// <param name="sender"></param>
  3124. /// <param name="e"></param>
  3125. private void textBox_ErrorCode_MouseHover(object sender, EventArgs e)
  3126. {
  3127. // 创建the ToolTip
  3128. ToolTip toolTip1 = new ToolTip();
  3129. // 设置显示样式
  3130. toolTip1.AutoPopDelay = 30000;//提示信息的可见时间
  3131. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  3132. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  3133. toolTip1.ShowAlways = true;//是否显示提示框
  3134. // 设置伴随的对象.
  3135. string ErrorCode = this.textBox_ErrorCode.Text;
  3136. UInt32 Code = ErrorCode.Contains("H") ? Convert.ToUInt32(ErrorCode.Split('H')[0], 16) : 0;
  3137. toolTip1.SetToolTip(this.textBox_ErrorCode, ErrorInfoDisplay(Code));//设置故障内容显示
  3138. }
  3139. /// <summary>
  3140. /// 数据记录
  3141. /// </summary>
  3142. private void RunInfoAutoSave()
  3143. {
  3144. if (运行信息记录ToolStripMenuItem.Checked == true)
  3145. {
  3146. if (RunInfoSaveFilename == string.Empty)
  3147. {
  3148. return;
  3149. }
  3150. string SaveData = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff").Replace(" ", "_") + " --> ";
  3151. foreach (Control c in tabPage_RunInfo.Controls)
  3152. {
  3153. if (c is TextBox)
  3154. {
  3155. SaveData += c.Text + " , ";
  3156. }
  3157. }
  3158. foreach (Control c in tabPage_DebugInfo.Controls)
  3159. {
  3160. if (c is TextBox)
  3161. {
  3162. SaveData += c.Text + " , ";
  3163. }
  3164. }
  3165. SaveData += "\r\n";
  3166. System.IO.File.AppendAllText(RunInfoSaveFilename, SaveData);//sb.ToString());
  3167. }
  3168. }
  3169. /// <summary>
  3170. /// 打开或关闭数据记录
  3171. /// </summary>
  3172. /// <param name="sender"></param>
  3173. /// <param name="e"></param>
  3174. private void 记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  3175. {
  3176. if (运行信息记录ToolStripMenuItem.Checked == false)
  3177. {
  3178. if (mySerialProcess.mySerial.IsOpen == true)
  3179. {
  3180. RunInfoSaveFilename = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_运行信息" + ".txt";
  3181. System.IO.File.AppendAllText(RunInfoSaveFilename, "时间 --> 车速 , 转速 , 踏频 , 力矩Reg , 力矩 , 踩踏方向 , 电压 , 电流 , 功率 , 电量 , " +
  3182. "PCB温度 , 绕组温度 , MOS温度 , 挡位 , 灯开关 , 续航 , 平均功耗 , 单次里程 , 单次时间 , 故障码 , " +
  3183. "系统状态机 , 二层状态机 , 电机状态机 , 助力状态机 , D轴电流给定 , Q轴电流给定 , D轴电压给定 , Q轴电压给定 , 瞬时力矩 , 时间滤波力矩 , 踏频滤波力矩 , D轴电流反馈 , Q轴电流反馈 , 助力函数输出" + "\r\n");
  3184. timer_1s.Enabled = false;
  3185. MessageBoxTimeOut.Show("开始记录", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  3186. timer_1s.Enabled = true;
  3187. 运行信息记录ToolStripMenuItem.Checked = true;
  3188. }
  3189. else
  3190. {
  3191. timer_1s.Enabled = false;
  3192. MessageBox.Show("请连接电机", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3193. timer_1s.Enabled = true;
  3194. }
  3195. }
  3196. else
  3197. {
  3198. 运行信息记录ToolStripMenuItem.Checked = false;
  3199. timer_1s.Enabled = false;
  3200. MessageBoxTimeOut.Show("停止记录", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  3201. timer_1s.Enabled = true;
  3202. }
  3203. }
  3204. /// <summary>
  3205. /// 仪表启动控制档位开关事件
  3206. /// </summary>
  3207. /// <param name="sender"></param>
  3208. /// <param name="e"></param>
  3209. private void checkBox_OBC_StartSetGearSt_CheckedChanged(object sender, EventArgs e)
  3210. {
  3211. if (checkBox_OBC_StartSetGearSt.Checked == true)
  3212. {
  3213. //检查串口是否打开
  3214. if (!mySerialProcess.mySerial.IsOpen)
  3215. {
  3216. timer_1s.Enabled = false;
  3217. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3218. timer_1s.Enabled = true;
  3219. checkBox_OBC_StartSetGearSt.Checked = false;
  3220. return;
  3221. }
  3222. //检查是否选择档位和打开车灯
  3223. if ((comboBox_OBC_SetGearST.SelectedIndex == -1) || (comboBox_OBC_LightSw.SelectedIndex == -1))
  3224. {
  3225. timer_1s.Enabled = false;
  3226. MessageBox.Show("请检查档位设置和大灯开关!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3227. timer_1s.Enabled = true;
  3228. checkBox_OBC_StartSetGearSt.Checked = false;
  3229. return;
  3230. }
  3231. }
  3232. }
  3233. /// <summary>
  3234. /// OBC查询电机用户参数
  3235. /// </summary>
  3236. /// <param name="sender"></param>
  3237. /// <param name="e"></param>
  3238. private void button_OBC_ReadUserInfo_Click(object sender, EventArgs e)
  3239. {
  3240. richTextBox_OBC_ReadUserInfo.Clear();
  3241. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3300, null);
  3242. }
  3243. /// <summary>
  3244. /// OBC设置电机用户参数
  3245. /// </summary>
  3246. /// <param name="sender"></param>
  3247. /// <param name="e"></param>
  3248. private void button_OBC_WriteUserInfo_Click(object sender, EventArgs e)
  3249. {
  3250. var UserInfoCode = new byte[8];
  3251. for (int i = 0; i < UserInfoCode.Length; i++)
  3252. UserInfoCode[i] = 0;
  3253. if (comboBox_OBC_StartMode.SelectedIndex == -1)//检查数据有效性
  3254. {
  3255. timer_1s.Enabled = false;
  3256. MessageBox.Show("请选择启动模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3257. timer_1s.Enabled = true;
  3258. return;
  3259. }
  3260. if (comboBox_OBC_AssistFunc.SelectedIndex == -1)//检查数据有效性
  3261. {
  3262. timer_1s.Enabled = false;
  3263. MessageBox.Show("请选择助力方案!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3264. timer_1s.Enabled = true;
  3265. return;
  3266. }
  3267. UserInfoCode[0] = (byte)(int)numericUpDown_OBC_WheelAdj.Value;
  3268. UserInfoCode[1] = (byte)(comboBox_OBC_StartMode.SelectedIndex + 1);
  3269. UserInfoCode[2] = (byte)(comboBox_OBC_AssistFunc.SelectedIndex + 1);
  3270. UserInfoCode[3] = (byte)(uint)numericUpDown_OBC_OffTime.Value;
  3271. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3408, UserInfoCode);
  3272. }
  3273. /// <summary>
  3274. /// OBC查询电机版本信息
  3275. /// </summary>
  3276. /// <param name="sender"></param>
  3277. /// <param name="e"></param>
  3278. private void button_OBC_ReadVerInfo_Click(object sender, EventArgs e)
  3279. {
  3280. textBox_Model.Text = "---";
  3281. textBox_SN.Text = "---";
  3282. textBox_HW.Text = "---";
  3283. textBox_FW.Text = "---";
  3284. textBox_SP.Text = "---";
  3285. textBox_OBC_ReadModel.Text = "---";
  3286. textBox_OBC_ReadSN.Text = "---";
  3287. textBox_OBC_ReadHW.Text = "---";
  3288. textBox_OBC_ReadFW.Text = "---";
  3289. textBox_OBC_ReadSP.Text = "---";
  3290. textBox_FacModeName.Text = "---";
  3291. textBox_FacModeNum.Text = "---";
  3292. textBox_FacModeHW.Text = "---";
  3293. textBox_FacModeFW.Text = "---";
  3294. textBox_FacModeSP.Text = "---";
  3295. Class_Motor_Ver.Mode = "---";
  3296. Class_Motor_Ver.SN = "---";
  3297. Class_Motor_Ver.HW = "---";
  3298. Class_Motor_Ver.FW = "---";
  3299. Class_Motor_Ver.Special = "---";
  3300. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  3301. }
  3302. /// <summary>
  3303. /// OBC读取骑行历史
  3304. /// </summary>
  3305. /// <param name="sender"></param>
  3306. /// <param name="e"></param>
  3307. private void button_OBC_ReadRideInfo_Click(object sender, EventArgs e)
  3308. {
  3309. textBox_OBC_TRIP_KM.Text = "";
  3310. textBox_OBC_TRIP_TIME.Text = "";
  3311. textBox_OBC_ODO_KM.Text = "";
  3312. textBox_OBC_ODO_TIME.Text = "";
  3313. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3500, null);
  3314. }
  3315. /// <summary>
  3316. /// OBC清除TRIP里程
  3317. /// </summary>
  3318. /// <param name="sender"></param>
  3319. /// <param name="e"></param>
  3320. private void button_OBC_ClearTrip_Click(object sender, EventArgs e)
  3321. {
  3322. var Code = new byte[5];
  3323. Code[0] = (byte)'C';
  3324. Code[1] = (byte)'L';
  3325. Code[2] = (byte)'E';
  3326. Code[3] = (byte)'A';
  3327. Code[4] = (byte)'R';
  3328. timer_1s.Enabled = false;
  3329. if (MessageBox.Show("TRIP清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3330. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3605, Code);
  3331. timer_1s.Enabled = true;
  3332. }
  3333. private void checkBox_OBC_StartReadBMS_CheckedChanged(object sender, EventArgs e)
  3334. {
  3335. if (checkBox_OBC_StartReadBMS.Checked == true)
  3336. {
  3337. //检查串口是否打开
  3338. if (!mySerialProcess.mySerial.IsOpen)
  3339. {
  3340. timer_1s.Enabled = false;
  3341. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3342. timer_1s.Enabled = true;
  3343. checkBox_OBC_StartReadBMS.Checked = false;
  3344. return;
  3345. }
  3346. }
  3347. }
  3348. /// <summary>
  3349. /// 写入力矩传感器参数
  3350. /// </summary>
  3351. /// <param name="sender"></param>
  3352. /// <param name="e"></param>
  3353. private void button_WriteTqSensorParam_Click(object sender, EventArgs e)
  3354. {
  3355. var ConfigParam = new byte[46];
  3356. for (int i = 0; i < 14; i++)
  3357. ConfigParam[i] = 0;
  3358. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  3359. ushort uwDataTemp = 0;
  3360. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  3361. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  3362. int index = 0;
  3363. try
  3364. {
  3365. for (int i = 0; i < strDataTemp.Length; i++)
  3366. {
  3367. if (strDataTemp[i].Split('=')[0] == "第四阶段转矩点采集值")
  3368. {
  3369. index = i;
  3370. break;
  3371. }
  3372. }
  3373. for (int i = 0; i < (index + 1); i++)
  3374. {
  3375. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  3376. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3377. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3378. }
  3379. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x472E, ConfigParam);
  3380. }
  3381. catch (Exception)
  3382. {
  3383. timer_1s.Enabled = false;
  3384. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3385. timer_1s.Enabled = true;
  3386. }
  3387. }
  3388. /// <summary>
  3389. /// 查询存储标志
  3390. /// </summary>
  3391. /// <param name="sender"></param>
  3392. /// <param name="e"></param>
  3393. private void button_ReadSaveFlag_Click(object sender, EventArgs e)
  3394. {
  3395. radioButton_EE_SaveYes.Checked = false;
  3396. radioButton_EE_SaveNo.Checked = false;
  3397. radioButton_SIP_SaveYes.Checked = false;
  3398. radioButton_SIP_SaveNo.Checked = false;
  3399. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null);
  3400. }
  3401. /// <summary>
  3402. /// 写入存储标志
  3403. /// </summary>
  3404. /// <param name="sender"></param>
  3405. /// <param name="e"></param>
  3406. private void button_WriteSaveFlag_Click(object sender, EventArgs e)
  3407. {
  3408. var SaveFlag = new byte[6];
  3409. for (int i = 0; i < 6; i++)
  3410. SaveFlag[i] = 0;
  3411. if ((radioButton_EE_SaveYes.Checked == false) && (radioButton_EE_SaveNo.Checked == false))
  3412. {
  3413. timer_1s.Enabled = false;
  3414. MessageBox.Show("请选择EEPROM存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3415. timer_1s.Enabled = true;
  3416. return;
  3417. }
  3418. if ((radioButton_SIP_SaveYes.Checked == false) && (radioButton_SIP_SaveNo.Checked == false))
  3419. {
  3420. timer_1s.Enabled = false;
  3421. MessageBox.Show("请选择SIP校验存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3422. timer_1s.Enabled = true;
  3423. return;
  3424. }
  3425. SaveFlag[0] = (byte)((checkBox_SaveYes.Checked) ? 0x01 : 0x00);
  3426. SaveFlag[2] = (byte)(radioButton_EE_SaveYes.Checked ? 0x01 : 0x00);
  3427. SaveFlag[3] = 0;
  3428. SaveFlag[4] = (byte)(radioButton_SIP_SaveYes.Checked ? 0x01 : 0x00);
  3429. SaveFlag[5] = 0;
  3430. timer_1s.Enabled = false;
  3431. if (MessageBox.Show("确认修改存储标志?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3432. {
  3433. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4906, SaveFlag);
  3434. }
  3435. timer_1s.Enabled = true;
  3436. }
  3437. /// <summary>
  3438. /// 读取指定地址数据
  3439. /// </summary>
  3440. /// <param name="sender"></param>
  3441. /// <param name="e"></param>
  3442. private void button_ReadRamFlash_Click(object sender, EventArgs e)
  3443. {
  3444. var Address = new byte[4];
  3445. UInt32 Address_Begin;
  3446. UInt32 Addres_End;
  3447. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  3448. richTextBox_RamFlasgData.Clear();
  3449. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  3450. {
  3451. timer_1s.Enabled = false;
  3452. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3453. timer_1s.Enabled = true;
  3454. return;
  3455. }
  3456. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  3457. {
  3458. timer_1s.Enabled = false;
  3459. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3460. timer_1s.Enabled = true;
  3461. return;
  3462. }
  3463. else
  3464. {
  3465. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  3466. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  3467. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  3468. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  3469. if (Addres_End < Address_Begin)
  3470. {
  3471. timer_1s.Enabled = false;
  3472. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3473. timer_1s.Enabled = true;
  3474. return;
  3475. }
  3476. else
  3477. {
  3478. var SendByte = new byte[8];
  3479. SendByte[0] = (byte)(Address_Begin >> 24);
  3480. SendByte[1] = (byte)(Address_Begin >> 16);
  3481. SendByte[2] = (byte)(Address_Begin >> 8);
  3482. SendByte[3] = (byte)(Address_Begin);
  3483. SendByte[4] = (byte)(Addres_End >> 24);
  3484. SendByte[5] = (byte)(Addres_End >> 16);
  3485. SendByte[6] = (byte)(Addres_End >> 8);
  3486. SendByte[7] = (byte)(Addres_End);
  3487. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  3488. }
  3489. }
  3490. }
  3491. /// <summary>
  3492. /// 工作模式选择
  3493. /// </summary>
  3494. /// <param name="sender"></param>
  3495. /// <param name="e"></param>
  3496. private void comboBox_WorkMode_SelectedIndexChanged(object sender, EventArgs e)
  3497. {
  3498. var RunMode = new byte[1];
  3499. if (comboBox_WorkMode.Text == "配置模式")
  3500. RunMode[0] = 0x01;
  3501. else if (comboBox_WorkMode.Text == "调试模式")
  3502. RunMode[0] = 0x02;
  3503. else
  3504. RunMode[0] = 0x00;
  3505. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  3506. }
  3507. /// <summary>
  3508. /// 助力档位选择
  3509. /// </summary>
  3510. /// <param name="sender"></param>
  3511. /// <param name="e"></param>
  3512. private void comboBox_GearSt_SelectedIndexChanged(object sender, EventArgs e)
  3513. {
  3514. var CtrlCode = new byte[2];
  3515. if (comboBox_GearSt.SelectedIndex == 5)//档位
  3516. CtrlCode[0] = 0x33;
  3517. else if (comboBox_GearSt.SelectedIndex == 6)//档位
  3518. CtrlCode[0] = 0x22;
  3519. else
  3520. CtrlCode[0] = (byte)comboBox_GearSt.SelectedIndex;
  3521. if (comboBox_LightSwitch.SelectedIndex == 0)//车灯
  3522. CtrlCode[1] = 0xF1;
  3523. else
  3524. CtrlCode[1] = 0xF0;
  3525. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
  3526. comboBox_OBC_SetGearST.SelectedIndex = comboBox_GearSt.SelectedIndex;
  3527. comboBox_OBC_LightSw.SelectedIndex = comboBox_LightSwitch.SelectedIndex;
  3528. }
  3529. /// <summary>
  3530. /// 仪表档位选择
  3531. /// </summary>
  3532. /// <param name="sender"></param>
  3533. /// <param name="e"></param>
  3534. private void comboBox_OBC_SetGearST_SelectedIndexChanged(object sender, EventArgs e)
  3535. {
  3536. comboBox_GearSt.SelectedIndex = comboBox_OBC_SetGearST.SelectedIndex;
  3537. comboBox_LightSwitch.SelectedIndex = comboBox_OBC_LightSw.SelectedIndex;
  3538. }
  3539. /// <summary>
  3540. /// 生产模式初始化
  3541. /// </summary>
  3542. /// <param name="sender"></param>
  3543. /// <param name="e"></param>
  3544. private void button_FacModeInit_Click(object sender, EventArgs e)
  3545. {
  3546. var Code = new byte[5];
  3547. Code[0] = (byte)'C';
  3548. Code[1] = (byte)'L';
  3549. Code[2] = (byte)'E';
  3550. Code[3] = (byte)'A';
  3551. Code[4] = (byte)'R';
  3552. timer_1s.Enabled = false;
  3553. if (MessageBox.Show("电机即将初始化!", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3554. {
  3555. if (MessageBox.Show("请再次确认", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3556. {
  3557. timer_1s.Enabled = true;
  3558. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  3559. PowerOffAckStatus = false;
  3560. Delay_ms(250);
  3561. int TryCnt = 3;
  3562. while ((TryCnt--) >= 0)
  3563. {
  3564. if (!PowerOffAckStatus)
  3565. {
  3566. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  3567. PowerOffAckStatus = false;
  3568. Delay_ms(250);
  3569. }
  3570. else break;
  3571. }
  3572. if (PowerOffAckStatus)
  3573. {
  3574. timer_1s.Enabled = false;
  3575. MessageBox.Show("系统已关机,请保持无负载重新开机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  3576. timer_1s.Enabled = true;
  3577. }
  3578. else
  3579. {
  3580. timer_1s.Enabled = false;
  3581. MessageBox.Show("初始化失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3582. timer_1s.Enabled = true;
  3583. }
  3584. timer_1s.Enabled = true;
  3585. }
  3586. }
  3587. timer_1s.Enabled = true;
  3588. //清除历史测试记录
  3589. textBox_FacModeSensorADC0.Text = "";
  3590. textBox_FacModeSensorADC1.Text = "";
  3591. textBox_FacModeSensorADC2.Text = "";
  3592. textBox_FacModeSensorADC3.Text = "";
  3593. textBox_FacModeSensorADC4.Text = "";
  3594. LightSwitchStatus = false;
  3595. MotorRunStatus = false;
  3596. trackBar_FacModeMotorSpeedAdj.Value = 5;
  3597. textBox_FacModeName.Text = "";
  3598. textBox_FacModeNum.Text = "";
  3599. textBox_FacModeHW.Text = "";
  3600. textBox_FacModeFW.Text = "";
  3601. }
  3602. /// <summary>
  3603. /// 生产模式读取传感器参数
  3604. /// </summary>
  3605. /// <param name="sender"></param>
  3606. /// <param name="e"></param>
  3607. private void button_FacModeSensorRead_Click(object sender, EventArgs e)
  3608. {
  3609. richTextBox_SensorParam.Clear();
  3610. textBox_FacModeSensorADC0.Text = "";
  3611. textBox_FacModeSensorADC1.Text = "";
  3612. textBox_FacModeSensorADC2.Text = "";
  3613. textBox_FacModeSensorADC3.Text = "";
  3614. textBox_FacModeSensorADC4.Text = "";
  3615. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3616. }
  3617. /// <summary>
  3618. /// 生产模式传感器标定1
  3619. /// </summary>
  3620. /// <param name="sender"></param>
  3621. /// <param name="e"></param>
  3622. private void buttonFacModeSet1_Click(object sender, EventArgs e)
  3623. {
  3624. var ConfigParam = new byte[4];
  3625. for (int i = 0; i < 4; i++)
  3626. ConfigParam[i] = 0;
  3627. ushort uwDataTemp = 0;
  3628. try
  3629. {
  3630. uwDataTemp = 1;//负载序号
  3631. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  3632. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  3633. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal1.Text) * 10); ;//负载值0.1Nm
  3634. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  3635. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  3636. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  3637. Delay_ms(200);
  3638. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3639. }
  3640. catch (Exception)
  3641. {
  3642. timer_1s.Enabled = false;
  3643. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3644. timer_1s.Enabled = true;
  3645. }
  3646. }
  3647. /// <summary>
  3648. /// 生产模式传感器标定2
  3649. /// </summary>
  3650. /// <param name="sender"></param>
  3651. /// <param name="e"></param>
  3652. private void buttonFacModeSet2_Click(object sender, EventArgs e)
  3653. {
  3654. var ConfigParam = new byte[4];
  3655. for (int i = 0; i < 4; i++)
  3656. ConfigParam[i] = 0;
  3657. ushort uwDataTemp = 0;
  3658. try
  3659. {
  3660. uwDataTemp = 2;//负载序号
  3661. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  3662. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  3663. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal2.Text) * 10); ;//负载值0.1Nm
  3664. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  3665. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  3666. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  3667. Delay_ms(200);
  3668. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3669. }
  3670. catch (Exception)
  3671. {
  3672. timer_1s.Enabled = false;
  3673. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3674. timer_1s.Enabled = true;
  3675. }
  3676. }
  3677. /// <summary>
  3678. /// 生产模式传感器标定3
  3679. /// </summary>
  3680. /// <param name="sender"></param>
  3681. /// <param name="e"></param>
  3682. private void buttonFacModeSet3_Click(object sender, EventArgs e)
  3683. {
  3684. var ConfigParam = new byte[4];
  3685. for (int i = 0; i < 4; i++)
  3686. ConfigParam[i] = 0;
  3687. ushort uwDataTemp = 0;
  3688. try
  3689. {
  3690. uwDataTemp = 3;//负载序号
  3691. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  3692. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  3693. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal3.Text) * 10); ;//负载值0.1Nm
  3694. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  3695. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  3696. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  3697. Delay_ms(200);
  3698. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3699. }
  3700. catch (Exception)
  3701. {
  3702. timer_1s.Enabled = false;
  3703. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3704. timer_1s.Enabled = true;
  3705. }
  3706. }
  3707. /// <summary>
  3708. /// 生产模式传感器标定3
  3709. /// </summary>
  3710. /// <param name="sender"></param>
  3711. /// <param name="e"></param>
  3712. private void buttonFacModeSet4_Click(object sender, EventArgs e)
  3713. {
  3714. var ConfigParam = new byte[4];
  3715. for (int i = 0; i < 4; i++)
  3716. ConfigParam[i] = 0;
  3717. ushort uwDataTemp = 0;
  3718. try
  3719. {
  3720. uwDataTemp = 4;//负载序号
  3721. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  3722. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  3723. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal4.Text) * 10); ;//负载值0.1Nm
  3724. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  3725. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  3726. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  3727. Delay_ms(200);
  3728. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3729. }
  3730. catch (Exception)
  3731. {
  3732. timer_1s.Enabled = false;
  3733. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3734. timer_1s.Enabled = true;
  3735. }
  3736. }
  3737. /// <summary>
  3738. /// 生产模式开关灯
  3739. /// </summary>
  3740. /// <param name="sender"></param>
  3741. /// <param name="e"></param>
  3742. bool LightSwitchStatus = false;
  3743. private void button_FacModeLightSW_Click(object sender, EventArgs e)
  3744. {
  3745. var CtrlCode = new byte[2];
  3746. CtrlCode[0] = 0x00;
  3747. if (LightSwitchStatus)
  3748. {
  3749. CtrlCode[1] = 0xF0;
  3750. button_FacModeLightSW.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(128)))));
  3751. }
  3752. else
  3753. {
  3754. CtrlCode[1] = 0xF1;
  3755. button_FacModeLightSW.BackColor = Color.Yellow;
  3756. }
  3757. if (mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode))
  3758. {
  3759. LightSwitchStatus = !LightSwitchStatus;
  3760. comboBox_LightSwitch.SelectedIndex = LightSwitchStatus ? 0 : 1;
  3761. comboBox_OBC_LightSw.SelectedIndex = LightSwitchStatus ? 0 : 1;
  3762. }
  3763. }
  3764. /// <summary>
  3765. /// 生产模式电机控制
  3766. /// </summary>
  3767. /// <param name="sender"></param>
  3768. /// <param name="e"></param>
  3769. bool MotorRunStatus = false;
  3770. private void button_FacModeMotorRun_Click(object sender, EventArgs e)
  3771. {
  3772. string DebugDefaultInfo = "";
  3773. //获取调试信息
  3774. if (richTextBox_DebugParam.Text == string.Empty)
  3775. {
  3776. richTextBox_DebugParam.Clear();
  3777. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  3778. }
  3779. Delay_ms(200);
  3780. DebugDefaultInfo = richTextBox_DebugParam.Text;
  3781. //获取参数
  3782. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  3783. if (strDataTemp.Length != 29)
  3784. {
  3785. timer_1s.Enabled = false;
  3786. MessageBox.Show("数据格式不正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3787. timer_1s.Enabled = true;
  3788. return;
  3789. }
  3790. //设置参数
  3791. var ConfigParam = new byte[60];
  3792. for (int i = 0; i < 60; i++)
  3793. ConfigParam[i] = 0;
  3794. ConfigParam[0] = 0x00;
  3795. ushort uwDataTemp = 0;
  3796. if (!MotorRunStatus) //停止状态
  3797. {
  3798. //设置速度环
  3799. strDataTemp[0] = "整体运行模式=3";
  3800. //发送数据
  3801. try
  3802. {
  3803. for (int i = 0; i < strDataTemp.Length; i++)
  3804. {
  3805. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  3806. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3807. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3808. }
  3809. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  3810. return;
  3811. }
  3812. catch (Exception)
  3813. {
  3814. timer_1s.Enabled = false;
  3815. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3816. timer_1s.Enabled = true;
  3817. }
  3818. Delay_ms(200);
  3819. //设置转速百分比100%
  3820. trackBar_FacModeMotorSpeedAdj.Value = 100;
  3821. MotorRunStatus = !MotorRunStatus;
  3822. button_FacModeMotorRun.BackColor = Color.Yellow;
  3823. Delay_ms(200);
  3824. //电机进入配置模式
  3825. var RunMode = new byte[1];
  3826. RunMode[0] = 0x01;
  3827. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  3828. }
  3829. else //运转状态
  3830. {
  3831. //设置转速百分比0%
  3832. trackBar_FacModeMotorSpeedAdj.Value = 0;
  3833. MotorRunStatus = !MotorRunStatus;
  3834. button_FacModeMotorRun.BackColor = Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
  3835. Delay_ms(200);
  3836. //还原为原始值
  3837. strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  3838. try
  3839. {
  3840. for (int i = 0; i < strDataTemp.Length; i++)
  3841. {
  3842. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  3843. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3844. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3845. }
  3846. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  3847. return;
  3848. }
  3849. catch (Exception)
  3850. {
  3851. timer_1s.Enabled = false;
  3852. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3853. timer_1s.Enabled = true;
  3854. }
  3855. Delay_ms(200);
  3856. //电机退出配置模式
  3857. var RunMode = new byte[1];
  3858. RunMode[0] = 0x00;
  3859. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  3860. }
  3861. }
  3862. /// <summary>
  3863. /// 生产模式转速调节
  3864. /// </summary>
  3865. /// <param name="sender"></param>
  3866. /// <param name="e"></param>
  3867. private void trackBar_FacModeMotorSpeedAdj_ValueChanged(object sender, EventArgs e)
  3868. {
  3869. //转速百分比更新
  3870. label_FacModeMotorSpeedSet.Text = trackBar_FacModeMotorSpeedAdj.Value.ToString() + "%";
  3871. numericUpDown_SpeedAdj.Value = trackBar_FacModeMotorSpeedAdj.Value;
  3872. }
  3873. /// <summary>
  3874. /// 生产模式写入型号
  3875. /// </summary>
  3876. /// <param name="sender"></param>
  3877. /// <param name="e"></param>
  3878. private void button_FacModeSetName_Click(object sender, EventArgs e)
  3879. {
  3880. string Mode = textBox_FacModeName.Text;
  3881. var ModeArray = new byte[16];
  3882. for (ushort i = 0; i < Mode.Length; i++)
  3883. {
  3884. ModeArray[i] = (byte)Mode[i];
  3885. }
  3886. if (Mode.Length < 16)
  3887. {
  3888. ModeArray[Mode.Length] = (byte)'.';
  3889. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  3890. {
  3891. ModeArray[Mode.Length + 1 + i] = 0x20;
  3892. }
  3893. }
  3894. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  3895. }
  3896. /// <summary>
  3897. /// 生产模式写入SN
  3898. /// </summary>
  3899. /// <param name="sender"></param>
  3900. /// <param name="e"></param>
  3901. private void Button_FacModeSetNum_Click(object sender, EventArgs e)
  3902. {
  3903. string SN = textBox_FacModeNum.Text;
  3904. var SNArray = new byte[16];
  3905. for (ushort i = 0; i < SN.Length; i++)
  3906. {
  3907. SNArray[i] = (byte)SN[i];
  3908. }
  3909. if (SN.Length < 16)
  3910. {
  3911. SNArray[SN.Length] = (byte)'.';
  3912. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  3913. {
  3914. SNArray[SN.Length + 1 + i] = 0x20;
  3915. }
  3916. }
  3917. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  3918. }
  3919. /// <summary>
  3920. /// 生产模式读取版本信息
  3921. /// </summary>
  3922. /// <param name="sender"></param>
  3923. /// <param name="e"></param>
  3924. private void Button_FacModeReadVer_Click_1(object sender, EventArgs e)
  3925. {
  3926. textBox_Model.Text = "---";
  3927. textBox_SN.Text = "---";
  3928. textBox_HW.Text = "---";
  3929. textBox_FW.Text = "---";
  3930. textBox_SP.Text = "---";
  3931. textBox_OBC_ReadModel.Text = "---";
  3932. textBox_OBC_ReadSN.Text = "---";
  3933. textBox_OBC_ReadHW.Text = "---";
  3934. textBox_OBC_ReadFW.Text = "---";
  3935. textBox_OBC_ReadSP.Text = "---";
  3936. textBox_FacModeName.Text = "---";
  3937. textBox_FacModeNum.Text = "---";
  3938. textBox_FacModeHW.Text = "---";
  3939. textBox_FacModeFW.Text = "---";
  3940. textBox_FacModeSP.Text = "---";
  3941. textBox_FacModeGit.Text = "---";
  3942. Class_Motor_Ver.Mode = "---";
  3943. Class_Motor_Ver.SN = "---";
  3944. Class_Motor_Ver.HW = "---";
  3945. Class_Motor_Ver.FW = "---";
  3946. Class_Motor_Ver.Special = "---";
  3947. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  3948. }
  3949. /// <summary>
  3950. /// 生产模式写入生产信息
  3951. /// </summary>
  3952. /// <param name="sender"></param>
  3953. /// <param name="e"></param>
  3954. private void Button_FacModeSetMacDate_Click(object sender, EventArgs e)
  3955. {
  3956. var MACArray = new byte[32];
  3957. string MacDefaultInfo = "";
  3958. string MacAddDefaultInfo = "";
  3959. string MacDateDefaultInfo = DateTime.Now.ToString("yyyyMMdd");
  3960. string MacPPDefaultInfo = "";
  3961. do
  3962. {
  3963. //填入生产商
  3964. if (toolStripTextBox_MAC.Text == string.Empty)
  3965. {
  3966. break;
  3967. }
  3968. MacDefaultInfo = toolStripTextBox_MAC.Text;
  3969. for (ushort i = 0; i < MacDefaultInfo.Length; i++)
  3970. {
  3971. MACArray[i] = (byte)MacDefaultInfo[i];
  3972. }
  3973. if (MacDefaultInfo.Length < 8)
  3974. {
  3975. MACArray[MacDefaultInfo.Length] = (byte)'.';
  3976. for (ushort i = 0; i < 8 - MacDefaultInfo.Length - 1; i++)
  3977. {
  3978. MACArray[MacDefaultInfo.Length + 1 + i] = 0x20;
  3979. }
  3980. }
  3981. //填入生产地
  3982. if (toolStripTextBoxMACAddr.Text == string.Empty)
  3983. {
  3984. break;
  3985. }
  3986. MacAddDefaultInfo = toolStripTextBoxMACAddr.Text;
  3987. for (ushort i = 0; i < MacAddDefaultInfo.Length; i++)
  3988. {
  3989. MACArray[8 + i] = (byte)MacAddDefaultInfo[i];
  3990. }
  3991. if (MacAddDefaultInfo.Length < 8)
  3992. {
  3993. MACArray[MacAddDefaultInfo.Length + 8] = (byte)'.';
  3994. for (ushort i = 0; i < 8 - MacAddDefaultInfo.Length - 1; i++)
  3995. {
  3996. MACArray[MacAddDefaultInfo.Length + 1 + i + 8] = 0x20;
  3997. }
  3998. }
  3999. //填入生产日期
  4000. if (toolStripTextBox_MACDate.Text == string.Empty)
  4001. {
  4002. break;
  4003. }
  4004. MacDateDefaultInfo = toolStripTextBox_MACDate.Text;
  4005. for (ushort i = 0; i < MacDateDefaultInfo.Length; i++)
  4006. {
  4007. MACArray[16 + i] = (byte)MacDateDefaultInfo[i];
  4008. }
  4009. if (MacDateDefaultInfo.Length < 8)
  4010. {
  4011. MACArray[MacDateDefaultInfo.Length + 16] = (byte)'.';
  4012. for (ushort i = 0; i < 8 - MacDateDefaultInfo.Length - 1; i++)
  4013. {
  4014. MACArray[MacDateDefaultInfo.Length + 1 + i + 16] = 0x20;
  4015. }
  4016. }
  4017. //填入产品标识
  4018. if (toolStripTextBox_MACPD.Text == string.Empty)
  4019. {
  4020. break;
  4021. }
  4022. MacPPDefaultInfo = toolStripTextBox_MACPD.Text;
  4023. for (ushort i = 0; i < MacPPDefaultInfo.Length; i++)
  4024. {
  4025. MACArray[24 + i] = (byte)MacPPDefaultInfo[i];
  4026. }
  4027. if (MacPPDefaultInfo.Length < 8)
  4028. {
  4029. MACArray[MacPPDefaultInfo.Length + 24] = (byte)'.';
  4030. for (ushort i = 0; i < 8 - MacPPDefaultInfo.Length - 1; i++)
  4031. {
  4032. MACArray[MacPPDefaultInfo.Length + 1 + i + 24] = 0x20;
  4033. }
  4034. }
  4035. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  4036. return;
  4037. } while (false);
  4038. timer_1s.Enabled = false;
  4039. MessageBox.Show("生产信息配置不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4040. timer_1s.Enabled = true;
  4041. }
  4042. /// <summary>
  4043. /// 生产模式保存测试页面
  4044. /// </summary>
  4045. /// <param name="sender"></param>
  4046. /// <param name="e"></param>
  4047. private void Button_FacModeSaveResult_Click(object sender, EventArgs e)
  4048. {
  4049. Button_FacModeSaveResult.Text = "存储中…";
  4050. string[] AssistParams = new string[15];
  4051. do
  4052. {
  4053. //读取一次马达参数
  4054. richTextBox_MotorParam.Clear();
  4055. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break; ;
  4056. Delay_ms(100);
  4057. //读取一次整车参数
  4058. richTextBox_BikeParam.Clear();
  4059. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  4060. Delay_ms(100);
  4061. //读取一次控制参数
  4062. richTextBox_ControlParam.Clear();
  4063. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  4064. Delay_ms(100);
  4065. //查询传感器
  4066. richTextBox_SensorParam.Clear();
  4067. textBox_FacModeSensorADC0.Text = "";
  4068. textBox_FacModeSensorADC1.Text = "";
  4069. textBox_FacModeSensorADC2.Text = "";
  4070. textBox_FacModeSensorADC3.Text = "";
  4071. textBox_FacModeSensorADC4.Text = "";
  4072. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  4073. Delay_ms(100);
  4074. //读取15次助力参数
  4075. for (int i = 1; i <= 15; i++)
  4076. {
  4077. var ConfigParam = new byte[4];
  4078. richTextBox_AssistParam.Clear();
  4079. ConfigParam[0] = (byte)(i & 0xFF);
  4080. ConfigParam[1] = (byte)(i >> 8);
  4081. ConfigParam[2] = (byte)(((i >= 5) ? 5 : i) & 0xFF);
  4082. ConfigParam[3] = (byte)(((i >= 5) ? 5 : i) >> 8);
  4083. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  4084. Delay_ms(200);
  4085. AssistParams[i - 1] = richTextBox_AssistParam.Text + "\r\n";
  4086. }
  4087. //读取一次调试信息
  4088. richTextBox_DebugParam.Clear();
  4089. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  4090. Delay_ms(100);
  4091. //读取一次历史信息
  4092. richTextBox_Record.Clear();
  4093. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  4094. Delay_ms(100);
  4095. //读取一次电机运行信息
  4096. var CtrlCode = new byte[2];
  4097. CtrlCode[0] = 0x00;
  4098. CtrlCode[1] = 0xF0;
  4099. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode)) break;
  4100. Delay_ms(100);
  4101. //读取一次版本信息
  4102. textBox_Model.Text = "---";
  4103. textBox_SN.Text = "---";
  4104. textBox_HW.Text = "---";
  4105. textBox_FW.Text = "---";
  4106. textBox_OBC_ReadModel.Text = "---";
  4107. textBox_OBC_ReadSN.Text = "---";
  4108. textBox_OBC_ReadHW.Text = "---";
  4109. textBox_OBC_ReadFW.Text = "---";
  4110. textBox_FacModeName.Text = "---";
  4111. textBox_FacModeNum.Text = "---";
  4112. textBox_FacModeHW.Text = "---";
  4113. textBox_FacModeFW.Text = "---";
  4114. Class_Motor_Ver.Mode = "---";
  4115. Class_Motor_Ver.SN = "---";
  4116. Class_Motor_Ver.HW = "---";
  4117. Class_Motor_Ver.FW = "---";
  4118. Class_Motor_Ver.Special = "---";
  4119. if (!mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null)) break;
  4120. Delay_ms(100);
  4121. //读取一次生产信息
  4122. textBox_MAC.Text = "";
  4123. textBox_MACAdd.Text = "";
  4124. textBox_MACDate.Text = "";
  4125. textBox_PP.Text = "";
  4126. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  4127. Delay_ms(100);
  4128. //读取一次自定义信息
  4129. textBox_User1.Text = "---";
  4130. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  4131. Delay_ms(100);
  4132. textBox_User2.Text = "---";
  4133. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  4134. Delay_ms(100);
  4135. textBox_User3.Text = "---";
  4136. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  4137. Delay_ms(100);
  4138. //读取一次密钥
  4139. textBox_Key.Text = "---";
  4140. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  4141. Delay_ms(100);
  4142. //读取一次存储标志
  4143. radioButton_EE_SaveYes.Checked = false;
  4144. radioButton_EE_SaveNo.Checked = false;
  4145. radioButton_SIP_SaveYes.Checked = false;
  4146. radioButton_SIP_SaveNo.Checked = false;
  4147. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  4148. Delay_ms(100);
  4149. //读取一次MOS内阻校准参数
  4150. foreach (Control c in groupBox21.Controls)
  4151. {
  4152. if (c is TextBox)
  4153. c.Text = "";
  4154. }
  4155. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  4156. Delay_ms(100);
  4157. //提示检查
  4158. #if false
  4159. timer_1s.Enabled = false;
  4160. if (MessageBox.Show("请检查信息是否完整!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  4161. {
  4162. MessageBox.Show("请检查参数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4163. timer_1s.Enabled = true;
  4164. return;
  4165. }
  4166. timer_1s.Enabled = true;
  4167. Delay_ms(200);
  4168. #endif
  4169. //判断数据是否有效
  4170. if ((textBox_FacModeName.Text == "---") || (textBox_FacModeNum.Text == "---"))
  4171. {
  4172. MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4173. break;
  4174. }
  4175. if ((textBox_FacModeName.Text == string.Empty) || (textBox_FacModeNum.Text == string.Empty))
  4176. {
  4177. MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4178. break;
  4179. }
  4180. //设置文件存储路径
  4181. string Save_Path = localInfo.LocalPath + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
  4182. string PD_PathName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_"); ;
  4183. Save_Path += PD_PathName;
  4184. if (!Directory.Exists(Save_Path))
  4185. Directory.CreateDirectory(Save_Path);
  4186. //保存页面
  4187. string PIC_SaveFileName = "";
  4188. Double scaleX = PrimaryScreen.ScaleX;
  4189. Double scaleY = PrimaryScreen.ScaleY;
  4190. //保存页面
  4191. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  4192. Graphics g = Graphics.FromImage(bit);
  4193. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  4194. PIC_SaveFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_测试页面" + ".png";
  4195. bit.Save(PIC_SaveFileName);
  4196. //保存数据
  4197. string DataFileName = "";
  4198. string FileInfo = "";
  4199. DataFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_记录数据" + ".txt";
  4200. FileInfo += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  4201. FileInfo += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  4202. FileInfo += "\r\n";
  4203. FileInfo += "[电机信息]\r\n";
  4204. FileInfo += "电机型号: " + textBox_FacModeName.Text + "\r\n";
  4205. FileInfo += "电机编号: " + textBox_FacModeNum.Text + "\r\n";
  4206. FileInfo += "硬件版本: " + textBox_HW.Text + "\r\n";
  4207. FileInfo += "软件版本: " + textBox_FW.Text + "\r\n";
  4208. FileInfo += "软件标识: " + textBox_SP.Text + "\r\n";
  4209. FileInfo += "Git信息: " + textBox_FacModeGit.Text + "\r\n";
  4210. FileInfo += "\r\n";
  4211. FileInfo += "[马达参数]\r\n";
  4212. FileInfo += richTextBox_MotorParam.Text + "\r\n";
  4213. FileInfo += "\r\n";
  4214. FileInfo += "[整车参数]\r\n";
  4215. FileInfo += richTextBox_BikeParam.Text + "\r\n";
  4216. FileInfo += "\r\n";
  4217. FileInfo += "[控制参数]\r\n";
  4218. FileInfo += richTextBox_ControlParam.Text + "\r\n";
  4219. FileInfo += "\r\n";
  4220. FileInfo += "[传感器参数]\r\n";
  4221. FileInfo += richTextBox_SensorParam.Text + "\r\n";
  4222. FileInfo += "\r\n";
  4223. FileInfo += "[助力参数]\r\n";
  4224. for(int i=0;i<15;i++)
  4225. {
  4226. FileInfo += AssistParams[i] + "\r\n";
  4227. }
  4228. FileInfo += "[调试参数]\r\n";
  4229. FileInfo += richTextBox_DebugParam.Text + "\r\n";
  4230. FileInfo += "\r\n";
  4231. FileInfo += "[历史信息]\r\n";
  4232. FileInfo += richTextBox_Record.Text + "\r\n";
  4233. FileInfo += "\r\n";
  4234. FileInfo += "[MOS内阻校准参数]\r\n";
  4235. FileInfo += textBox_MOS_K1.Text + ", ";
  4236. FileInfo += textBox_MOS_K2.Text + ", ";
  4237. FileInfo += textBox_MOS_K3.Text + ", ";
  4238. FileInfo += textBox_MOS_K4.Text + ", ";
  4239. FileInfo += textBox_MOS_K5.Text + ", ";
  4240. FileInfo += textBox_MOS_R1.Text + ", ";
  4241. FileInfo += textBox_MOS_R2.Text + ", ";
  4242. FileInfo += textBox_MOS_R3.Text + "\r\n";
  4243. FileInfo += "\r\n";
  4244. FileInfo += "[生产信息]\r\n";
  4245. FileInfo += "生产商: " + textBox_MAC.Text + "\r\n";
  4246. FileInfo += "生产地: " + textBox_MACAdd.Text + "\r\n";
  4247. FileInfo += "生产日期: " + textBox_MACDate.Text + "\r\n";
  4248. FileInfo += "产品标识: " + textBox_PP.Text + "\r\n";
  4249. FileInfo += "\r\n";
  4250. FileInfo += "[自定义信息]\r\n";
  4251. FileInfo += "自定义1: " + textBox_User1.Text + "\r\n";
  4252. FileInfo += "自定义2: " + textBox_User2.Text + "\r\n";
  4253. FileInfo += "自定义3: " + textBox_User3.Text + "\r\n";
  4254. FileInfo += "\r\n";
  4255. FileInfo += "[校验密钥]\r\n";
  4256. FileInfo += textBox_Key.Text + "\r\n";
  4257. FileInfo += "\r\n";
  4258. FileInfo += "[存储标志]\r\n";
  4259. FileInfo += "EEPROM: " + ((radioButton_EE_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  4260. FileInfo += "SIP: " + ((radioButton_SIP_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  4261. FileInfo += "\r\n";
  4262. FileInfo += Local_HdInformation;
  4263. System.IO.File.WriteAllText(DataFileName, FileInfo);
  4264. Delay_ms(1000);
  4265. timer_1s.Enabled = false;
  4266. MessageBox.Show("存储完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  4267. timer_1s.Enabled = true;
  4268. //数据上传
  4269. if (myFtp.IsNetConnected == true)
  4270. {
  4271. string DataNow = DateTime.Now.ToString("yyyy-MM-dd");
  4272. //检查路径
  4273. if (myFtp.DirectoryExist("\\", toolStripTextBox_ServerPath.Text) == false)
  4274. {
  4275. myFtp.MakeDir(toolStripTextBox_ServerPath.Text);
  4276. }
  4277. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text, "Samples") == false)
  4278. {
  4279. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples");
  4280. }
  4281. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples", DataNow) == false)
  4282. {
  4283. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow);
  4284. }
  4285. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow, PD_PathName) == false)
  4286. {
  4287. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4288. }
  4289. //上传文件
  4290. bool result1 = myFtp.UploadFile(PIC_SaveFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4291. bool result2 = myFtp.UploadFile(DataFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4292. if ((result1 & result2) == true)
  4293. {
  4294. timer_1s.Enabled = false;
  4295. MessageBoxTimeOut.Show("数据已上传!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  4296. timer_1s.Enabled = true;
  4297. }
  4298. else
  4299. {
  4300. timer_1s.Enabled = false;
  4301. MessageBox.Show("数据上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4302. timer_1s.Enabled = true;
  4303. }
  4304. }
  4305. else
  4306. {
  4307. timer_1s.Enabled = false;
  4308. MessageBox.Show("服务器断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4309. timer_1s.Enabled = true;
  4310. }
  4311. Button_FacModeSaveResult.Text = "保存数据";
  4312. return;
  4313. } while (false);
  4314. timer_1s.Enabled = false;
  4315. MessageBox.Show("保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4316. timer_1s.Enabled = true;
  4317. Button_FacModeSaveResult.Text = "保存数据";
  4318. }
  4319. /// <summary>
  4320. /// 工具箱页面保存
  4321. /// </summary>
  4322. /// <param name="sender"></param>
  4323. /// <param name="e"></param>
  4324. private void 页面保存ToolStripMenuItem_Click(object sender, EventArgs e)
  4325. {
  4326. Double scaleX = PrimaryScreen.ScaleX;
  4327. Double scaleY = PrimaryScreen.ScaleY;
  4328. //保存页面
  4329. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  4330. Graphics g = Graphics.FromImage(bit);
  4331. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  4332. SaveFileDialog sf = new SaveFileDialog();
  4333. sf.Title = "页面保存";
  4334. sf.FileName = "MotorInfo_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".png";
  4335. sf.Filter = "图片|*.png";
  4336. timer_1s.Enabled = false;
  4337. if (sf.ShowDialog() == DialogResult.OK)
  4338. {
  4339. bit.Save(sf.FileName);//默认保存格式为PNG,保存成jpg格式质量不是很好
  4340. }
  4341. timer_1s.Enabled = true;
  4342. }
  4343. /// <summary>
  4344. /// 生产模式关机
  4345. /// </summary>
  4346. /// <param name="sender"></param>
  4347. /// <param name="e"></param>
  4348. private void Button_FacModePowerOff_Click(object sender, EventArgs e)
  4349. {
  4350. var Code_Off = new byte[5];
  4351. var Code_Reset = new byte[5];
  4352. Code_Off[0] = (byte)'O';
  4353. Code_Off[1] = (byte)'F';
  4354. Code_Off[2] = (byte)'F';
  4355. Code_Off[3] = (byte)'.';
  4356. Code_Off[4] = (byte)'.';
  4357. Code_Reset[0] = (byte)'R';
  4358. Code_Reset[1] = (byte)'E';
  4359. Code_Reset[2] = (byte)'S';
  4360. Code_Reset[3] = (byte)'E';
  4361. Code_Reset[4] = (byte)'T';
  4362. timer_1s.Enabled = false;
  4363. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  4364. {
  4365. timer_1s.Enabled = true;
  4366. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  4367. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  4368. PowerOffAckStatus = false;
  4369. Delay_ms(250);
  4370. int TryCnt = 3;
  4371. while ((TryCnt--) >= 0)
  4372. {
  4373. if (!PowerOffAckStatus)
  4374. {
  4375. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  4376. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  4377. PowerOffAckStatus = false;
  4378. Delay_ms(250);
  4379. }
  4380. else break;
  4381. }
  4382. if (PowerOffAckStatus)
  4383. {
  4384. timer_1s.Enabled = false;
  4385. MessageBox.Show("已关机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  4386. timer_1s.Enabled = true;
  4387. }
  4388. else
  4389. {
  4390. timer_1s.Enabled = false;
  4391. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4392. timer_1s.Enabled = true;
  4393. }
  4394. }
  4395. timer_1s.Enabled = true;
  4396. }
  4397. //仪表电源键按下
  4398. private void button_OBC_ButtonPower_Click(object sender, EventArgs e)
  4399. {
  4400. var Code = new byte[2];
  4401. Code[0] = 0;
  4402. Code[1] = 0b00100000;
  4403. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4404. }
  4405. /// <summary>
  4406. /// 仪表加键按下
  4407. /// </summary>
  4408. /// <param name="sender"></param>
  4409. /// <param name="e"></param>
  4410. private void button_OBC_ButtonAcc_Click(object sender, EventArgs e)
  4411. {
  4412. var Code = new byte[2];
  4413. Code[0] = 0;
  4414. Code[1] = 0b00010000;
  4415. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4416. }
  4417. /// <summary>
  4418. /// 仪表减键按下
  4419. /// </summary>
  4420. /// <param name="sender"></param>
  4421. /// <param name="e"></param>
  4422. private void button_OBC_ButtonDec_Click(object sender, EventArgs e)
  4423. {
  4424. var Code = new byte[2];
  4425. Code[0] = 0;
  4426. Code[1] = 0b00001000;
  4427. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4428. }
  4429. /// <summary>
  4430. /// 仪表Walk键按下
  4431. /// </summary>
  4432. /// <param name="sender"></param>
  4433. /// <param name="e"></param>
  4434. private void button_OBC_ButtonWalk_Click(object sender, EventArgs e)
  4435. {
  4436. var Code = new byte[2];
  4437. Code[0] = 0;
  4438. Code[1] = 0b00000100;
  4439. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4440. }
  4441. /// <summary>
  4442. /// 仪表Light键按下
  4443. /// </summary>
  4444. /// <param name="sender"></param>
  4445. /// <param name="e"></param>
  4446. private void button_OBC_ButtonLight_Click(object sender, EventArgs e)
  4447. {
  4448. var Code = new byte[2];
  4449. Code[0] = 0;
  4450. Code[1] = 0b00000010;
  4451. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4452. }
  4453. /// <summary>
  4454. /// 仪表Set键按下
  4455. /// </summary>
  4456. /// <param name="sender"></param>
  4457. /// <param name="e"></param>
  4458. private void button_OBC_ButtonSet_Click(object sender, EventArgs e)
  4459. {
  4460. var Code = new byte[2];
  4461. Code[0] = 0;
  4462. Code[1] = 0b00000001;
  4463. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4464. }
  4465. /// <summary>
  4466. /// 导出电机故障日志
  4467. /// </summary>
  4468. /// <param name="sender"></param>
  4469. /// <param name="e"></param>
  4470. private void button_ExportLog_Click(object sender, EventArgs e)
  4471. {
  4472. var Address = new byte[4];
  4473. UInt32 Address_Begin;
  4474. UInt32 Addres_End;
  4475. string textBox_Address_Begin = textBox_LogAddrBegin.Text;
  4476. string textBox_Address_End = textBox_LogAddrEnd.Text;
  4477. richTextBox_Record.Clear();
  4478. textBox_LogAddrBegin.ReadOnly = true;
  4479. textBox_LogAddrEnd.ReadOnly = true;
  4480. if (!mySerialProcess.mySerial.IsOpen)
  4481. {
  4482. timer_1s.Enabled = false;
  4483. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4484. timer_1s.Enabled = true;
  4485. return;
  4486. }
  4487. if ((textBox_Address_Begin == string.Empty) || (textBox_Address_End == string.Empty))
  4488. {
  4489. timer_1s.Enabled = false;
  4490. MessageBox.Show("请输入日志存储起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4491. timer_1s.Enabled = true;
  4492. return;
  4493. }
  4494. else
  4495. {
  4496. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin, false);
  4497. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  4498. Address = mySerialProcess.HexStringToBytes(textBox_Address_End, false);
  4499. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  4500. if (Addres_End <= Address_Begin)
  4501. {
  4502. timer_1s.Enabled = false;
  4503. MessageBox.Show("结束地址应大于起始地址!", "提示");
  4504. timer_1s.Enabled = true;
  4505. return;
  4506. }
  4507. else if (((Addres_End - Address_Begin + 1) % 128) != 0) //
  4508. {
  4509. timer_1s.Enabled = false;
  4510. MessageBox.Show("(结束地址 - 起始地址 + 1)应为128整数倍!", "提示");
  4511. timer_1s.Enabled = true;
  4512. return;
  4513. }
  4514. else
  4515. {
  4516. UInt32 ReadCount = 0;
  4517. button_ExportLog.Text = "导出中...";
  4518. button_ExportLog.Enabled = false;
  4519. ReadCount = (Addres_End - Address_Begin + 1) / 128;
  4520. for (ushort i = 0; i < ReadCount; i++)
  4521. {
  4522. var SendByte = new byte[8];
  4523. UInt32 Address_Temp_Begin;
  4524. UInt32 Address_Temp_End;
  4525. Address_Temp_Begin = Address_Begin + 128 * (UInt32)i;
  4526. SendByte[0] = (byte)(Address_Temp_Begin >> 24);
  4527. SendByte[1] = (byte)(Address_Temp_Begin >> 16);
  4528. SendByte[2] = (byte)(Address_Temp_Begin >> 8);
  4529. SendByte[3] = (byte)(Address_Temp_Begin);
  4530. Address_Temp_End = Address_Temp_Begin + 127;
  4531. SendByte[4] = (byte)(Address_Temp_End >> 24);
  4532. SendByte[5] = (byte)(Address_Temp_End >> 16);
  4533. SendByte[6] = (byte)(Address_Temp_End >> 8);
  4534. SendByte[7] = (byte)(Address_Temp_End);
  4535. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  4536. Delay_ms(200);//Thread.Sleep(200);
  4537. }
  4538. button_ExportLog.Text = "导出日志";
  4539. button_ExportLog.Enabled = true;
  4540. }
  4541. }
  4542. }
  4543. /// <summary>
  4544. /// 保存日志信息
  4545. /// </summary>
  4546. /// <param name="sender"></param>
  4547. /// <param name="e"></param>
  4548. private void button_SaveRecordInfo_Click(object sender, EventArgs e)
  4549. {
  4550. string SaveInfo = "";
  4551. if (richTextBox_Record.Text == string.Empty)
  4552. {
  4553. timer_1s.Enabled = false;
  4554. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  4555. timer_1s.Enabled = true;
  4556. return;
  4557. }
  4558. //获取保存信息
  4559. SaveInfo += "读取时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  4560. SaveInfo += "电机型号:" + textBox_FacModeName.Text + "\r\n";
  4561. SaveInfo += "电机SN:" + textBox_FacModeNum.Text + "\r\n";
  4562. SaveInfo += "硬件版本:" + textBox_FacModeHW.Text + "\r\n";
  4563. SaveInfo += "软件版本:" + textBox_FacModeFW.Text + "\r\n";
  4564. SaveInfo += "\r\n";
  4565. SaveInfo += richTextBox_Record.Text;
  4566. //设置保存路径和文件名
  4567. SaveFileDialog sf = new SaveFileDialog();
  4568. sf.Title = "数据保存";
  4569. sf.FileName = "MotorLog_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".ttlog";
  4570. sf.FileName.Replace(" ", "");
  4571. sf.Filter = "日志|*.ttlog";
  4572. if (sf.ShowDialog() == DialogResult.OK)
  4573. {
  4574. System.IO.File.AppendAllText(sf.FileName, SaveInfo);
  4575. }
  4576. }
  4577. /// <summary>
  4578. /// 双击修改日志起始地址
  4579. /// </summary>
  4580. /// <param name="sender"></param>
  4581. /// <param name="e"></param>
  4582. private void label_LogAddrBegin_DoubleClick_1(object sender, EventArgs e)
  4583. {
  4584. textBox_LogAddrBegin.ReadOnly = false;
  4585. }
  4586. /// <summary>
  4587. /// 双击修改日志结束地址
  4588. /// </summary>
  4589. /// <param name="sender"></param>
  4590. /// <param name="e"></param>
  4591. private void label88_DoubleClick(object sender, EventArgs e)
  4592. {
  4593. textBox_LogAddrEnd.ReadOnly = false;
  4594. }
  4595. /// <summary>
  4596. /// 存储器自动读取选择
  4597. /// </summary>
  4598. /// <param name="sender"></param>
  4599. /// <param name="e"></param>
  4600. private void checkBox_ReadRanFlash_AutoSW_CheckedChanged(object sender, EventArgs e)
  4601. {
  4602. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  4603. {
  4604. //检查串口是否打开
  4605. if (!mySerialProcess.mySerial.IsOpen)
  4606. {
  4607. timer_1s.Enabled = false;
  4608. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4609. timer_1s.Enabled = true;
  4610. checkBox_ReadRanFlash_AutoSW.Checked = false;
  4611. return;
  4612. }
  4613. }
  4614. }
  4615. /// <summary>
  4616. /// 系统开机按钮
  4617. /// </summary>
  4618. /// <param name="sender"></param>
  4619. /// <param name="e"></param>
  4620. private void 开机ToolStripMenuItem_Click(object sender, EventArgs e)
  4621. {
  4622. byte[] Data = new byte[1];
  4623. Data[0] = 0xF1;
  4624. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  4625. }
  4626. /// <summary>
  4627. /// 系统关机按钮
  4628. /// </summary>
  4629. /// <param name="sender"></param>
  4630. /// <param name="e"></param>
  4631. private void 关机ToolStripMenuItem_Click(object sender, EventArgs e)
  4632. {
  4633. byte[] Data = new byte[1];
  4634. Data[0] = 0xF0;
  4635. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  4636. }
  4637. /// <summary>
  4638. /// 连接开机选择
  4639. /// </summary>
  4640. /// <param name="sender"></param>
  4641. /// <param name="e"></param>
  4642. private void 连接开机ToolStripMenuItem_Click(object sender, EventArgs e)
  4643. {
  4644. //输入用户名
  4645. EnterForm1.ShowDialog();
  4646. try
  4647. {
  4648. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  4649. {
  4650. if (EnterForm1.comboBox_User.Text == "管理员")
  4651. {
  4652. 连接开机ToolStripMenuItem.Checked = !连接开机ToolStripMenuItem.Checked;
  4653. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  4654. }
  4655. else
  4656. {
  4657. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4658. }
  4659. }
  4660. else
  4661. {
  4662. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4663. }
  4664. }
  4665. catch (Exception)
  4666. {
  4667. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4668. }
  4669. }
  4670. /// <summary>
  4671. /// 断开关机选择
  4672. /// </summary>
  4673. /// <param name="sender"></param>
  4674. /// <param name="e"></param>
  4675. private void 断开关机ToolStripMenuItem_Click(object sender, EventArgs e)
  4676. {
  4677. //输入用户名
  4678. EnterForm1.ShowDialog();
  4679. try
  4680. {
  4681. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  4682. {
  4683. if (EnterForm1.comboBox_User.Text == "管理员")
  4684. {
  4685. 断开关机ToolStripMenuItem.Checked = !断开关机ToolStripMenuItem.Checked;
  4686. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  4687. }
  4688. else
  4689. {
  4690. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4691. }
  4692. }
  4693. else
  4694. {
  4695. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4696. }
  4697. }
  4698. catch (Exception)
  4699. {
  4700. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4701. }
  4702. }
  4703. /// <summary>
  4704. /// 识别通讯盒选择
  4705. /// </summary>
  4706. /// <param name="sender"></param>
  4707. /// <param name="e"></param>
  4708. private void 识别通讯盒ToolStripMenuItem_Click(object sender, EventArgs e)
  4709. {
  4710. //输入用户名
  4711. EnterForm1.ShowDialog();
  4712. try
  4713. {
  4714. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  4715. {
  4716. if (EnterForm1.comboBox_User.Text == "管理员")
  4717. {
  4718. 识别通讯盒ToolStripMenuItem.Checked = !识别通讯盒ToolStripMenuItem.Checked;
  4719. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  4720. }
  4721. else
  4722. {
  4723. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4724. }
  4725. }
  4726. else
  4727. {
  4728. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4729. }
  4730. }
  4731. catch (Exception)
  4732. {
  4733. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4734. }
  4735. }
  4736. /// <summary>
  4737. /// 将配置信息导出为cfg文件
  4738. /// </summary>
  4739. private void ConfigFileSave(bool DeleteFlag, string FileName)
  4740. {
  4741. if (DeleteFlag)
  4742. {
  4743. if (File.Exists(FileName))
  4744. File.Delete(FileName);
  4745. }
  4746. string CfgFileInfo = "";
  4747. CfgFileInfo += "[PortSet]" + "\r\n";
  4748. CfgFileInfo += "PortNum:" + toolStripComboBox_ComNum.Text + "\r\n";
  4749. CfgFileInfo += "PortBaudrate:" + toolStripComboBox_Baudrate.Text + "\r\n";
  4750. CfgFileInfo += "AutoOn:" + 连接开机ToolStripMenuItem.Checked.ToString() + "\r\n";
  4751. CfgFileInfo += "AutoOff:" + 断开关机ToolStripMenuItem.Checked.ToString() + "\r\n";
  4752. CfgFileInfo += "CheckCDL:" + 识别通讯盒ToolStripMenuItem.Checked.ToString() + "\r\n";
  4753. CfgFileInfo += "\r\n";
  4754. CfgFileInfo += "[Option]" + "\r\n";
  4755. CfgFileInfo += "SaveWhenWrite:" + 写入存储ToolStripMenuItem.Checked.ToString() + "\r\n";
  4756. CfgFileInfo += "OfflineEnable:" + 允许ToolStripMenuItem.Checked + "\r\n";
  4757. CfgFileInfo += "\r\n";
  4758. CfgFileInfo += "[ServerSet]" + "\r\n";
  4759. CfgFileInfo += "IPAddress:" + toolStripTextBox_ServerIP.Text + "\r\n";
  4760. CfgFileInfo += "Port:" + toolStripTextBox_ServerPort.Text + "\r\n";
  4761. CfgFileInfo += "User:" + toolStripTextBox_ServerUser.Text + "\r\n";
  4762. CfgFileInfo += "Password:" + toolStripTextBox_ServerPasswd.Text + "\r\n";
  4763. CfgFileInfo += "PathName:" + toolStripTextBox_ServerPath.Text + "\r\n";
  4764. CfgFileInfo += "\r\n";
  4765. CfgFileInfo += "[MacInfo]" + "\r\n";
  4766. CfgFileInfo += "MacName:" + toolStripTextBox_MAC.Text + "\r\n";
  4767. CfgFileInfo += "MacAddress:" + toolStripTextBoxMACAddr.Text + "\r\n";
  4768. CfgFileInfo += "MacDate:" + toolStripTextBox_MACDate.Text + "\r\n";
  4769. CfgFileInfo += "MacPdInfo:" + toolStripTextBox_MACPD.Text + "\r\n";
  4770. CfgFileInfo += "\r\n";
  4771. CfgFileInfo += "[LogAddress]" + "\r\n";
  4772. CfgFileInfo += "BeginAddress:" + textBox_LogAddrBegin.Text + "\r\n";
  4773. CfgFileInfo += "EndAddress:" + textBox_LogAddrEnd.Text + "\r\n";
  4774. CfgFileInfo += "\r\n";
  4775. CfgFileInfo += "[MotorType]" + "\r\n";
  4776. CfgFileInfo += "MidMotor:" + 中置电机ToolStripMenuItem.Checked.ToString() + "\r\n";
  4777. CfgFileInfo += "HubMotor:" + 轮毂电机ToolStripMenuItem.Checked.ToString() + "\r\n";
  4778. CfgFileInfo += "\r\n";
  4779. CfgFileInfo += "[CheckValue]" + "\r\n";
  4780. CfgFileInfo += "Voltage:" + toolStripTextBox_ThVol.Text + "\r\n";
  4781. CfgFileInfo += "Current:" + toolStripTextBox_ThCur.Text + "\r\n";
  4782. CfgFileInfo += "MotorSpeed:" + toolStripTextBox_ThSpeed.Text + "\r\n";
  4783. CfgFileInfo += "Torque:" + toolStripTextBox_ThTor.Text + "\r\n";
  4784. CfgFileInfo += "Cadence:" + toolStripTextBox_ThCad.Text + "\r\n";
  4785. CfgFileInfo += "BikeSpeed:" + toolStripTextBox_ThBikeSpeed.Text + "\r\n";
  4786. CfgFileInfo += "T_PCB:" + toolStripTextBox_ThT_PCB.Text + "\r\n";
  4787. CfgFileInfo += "T_MCU:" + toolStripTextBox_ThT_MCU.Text + "\r\n";
  4788. CfgFileInfo += "T_Motor:" + toolStripTextBox_ThT_Motor.Text + "\r\n";
  4789. System.IO.File.WriteAllText(FileName, CfgFileInfo);
  4790. }
  4791. /// <summary>
  4792. /// 配置状态更新,点击时保存
  4793. /// </summary>
  4794. private void ConfigFileSave_Click(object sender, EventArgs e)
  4795. {
  4796. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  4797. }
  4798. /// <summary>
  4799. /// 文本框修改结束,回车保存
  4800. /// </summary>
  4801. /// <param name="sender"></param>
  4802. /// <param name="e"></param>
  4803. private void ConfigFileSave_KeyDown(object sender, KeyEventArgs e)
  4804. {
  4805. if (e.KeyCode == Keys.Enter)
  4806. {
  4807. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  4808. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  4809. }
  4810. }
  4811. /// <summary>
  4812. /// 允许离线使用
  4813. /// </summary>
  4814. /// <param name="sender"></param>
  4815. /// <param name="e"></param>
  4816. private void 允许ToolStripMenuItem_Click(object sender, EventArgs e)
  4817. {
  4818. //输入用户名
  4819. EnterForm1.ShowDialog();
  4820. try
  4821. {
  4822. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  4823. {
  4824. if (EnterForm1.comboBox_User.Text == "管理员")
  4825. {
  4826. 允许ToolStripMenuItem.Checked = true;
  4827. 不允许ToolStripMenuItem.Checked = false;
  4828. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  4829. }
  4830. else
  4831. {
  4832. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4833. 允许ToolStripMenuItem.Checked = false;
  4834. 不允许ToolStripMenuItem.Checked = true;
  4835. }
  4836. }
  4837. else
  4838. {
  4839. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4840. 允许ToolStripMenuItem.Checked = false;
  4841. 不允许ToolStripMenuItem.Checked = true;
  4842. }
  4843. }
  4844. catch (Exception)
  4845. {
  4846. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4847. 允许ToolStripMenuItem.Checked = false;
  4848. 不允许ToolStripMenuItem.Checked = true;
  4849. }
  4850. }
  4851. /// <summary>
  4852. /// 不允许离线使用
  4853. /// </summary>
  4854. /// <param name="sender"></param>
  4855. /// <param name="e"></param>
  4856. private void 不允许ToolStripMenuItem_Click(object sender, EventArgs e)
  4857. {
  4858. 允许ToolStripMenuItem.Checked = false;
  4859. 不允许ToolStripMenuItem.Checked = true;
  4860. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  4861. }
  4862. /// <summary>
  4863. /// 弹出扫码按钮
  4864. /// </summary>
  4865. /// <param name="sender"></param>
  4866. /// <param name="e"></param>
  4867. private void button_ScanCode_Click(object sender, EventArgs e)
  4868. {
  4869. Scan scan_form = new Scan();
  4870. scan_form.ShowDialog();
  4871. do
  4872. {
  4873. if (scan_form.textBox_Scan.Text == string.Empty)
  4874. {
  4875. timer_1s.Enabled = false;
  4876. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4877. timer_1s.Enabled = true;
  4878. break;
  4879. }
  4880. string ScanInfo = scan_form.textBox_Scan.Text.Replace(" ", "");
  4881. string regexInfo = "";
  4882. string[] InfoList = { "" };
  4883. try
  4884. {
  4885. if (中置电机ToolStripMenuItem.Checked == true)
  4886. {
  4887. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  4888. InfoList = Regex.Split(ScanInfo, regexInfo, RegexOptions.IgnoreCase);
  4889. }
  4890. else if (轮毂电机ToolStripMenuItem.Checked == true)
  4891. {
  4892. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  4893. string Model = InfoList[0];
  4894. string Spec = InfoList[1];
  4895. string Sn = InfoList[2];
  4896. InfoList[0] = Model.Replace("-", "").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  4897. InfoList[1] = Sn;
  4898. }
  4899. }
  4900. catch (Exception)
  4901. {
  4902. MessageBox.Show("格式错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4903. return;
  4904. }
  4905. if (InfoList.Length >= 2)
  4906. {
  4907. //写入型号
  4908. textBox_FacModeName.Text = InfoList[0];
  4909. string Mode = textBox_FacModeName.Text;
  4910. var ModeArray = new byte[16];
  4911. for (ushort i = 0; i < Mode.Length; i++)
  4912. {
  4913. ModeArray[i] = (byte)Mode[i];
  4914. }
  4915. if (Mode.Length < 16)
  4916. {
  4917. ModeArray[Mode.Length] = (byte)'.';
  4918. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  4919. {
  4920. ModeArray[Mode.Length + 1 + i] = 0x20;
  4921. }
  4922. }
  4923. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  4924. //写入SN
  4925. textBox_FacModeNum.Text = InfoList[1];
  4926. string SN = textBox_FacModeNum.Text;
  4927. var SNArray = new byte[16];
  4928. for (ushort i = 0; i < SN.Length; i++)
  4929. {
  4930. SNArray[i] = (byte)SN[i];
  4931. }
  4932. if (SN.Length < 16)
  4933. {
  4934. SNArray[SN.Length] = (byte)'.';
  4935. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  4936. {
  4937. SNArray[SN.Length + 1 + i] = 0x20;
  4938. }
  4939. }
  4940. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  4941. }
  4942. else
  4943. {
  4944. timer_1s.Enabled = false;
  4945. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4946. timer_1s.Enabled = true;
  4947. break;
  4948. }
  4949. } while (false);
  4950. scan_form.Dispose();
  4951. }
  4952. private void 服务器配置ToolStripMenuItem_Click(object sender, EventArgs e)
  4953. {
  4954. //输入用户名
  4955. EnterForm1.ShowDialog();
  4956. try
  4957. {
  4958. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  4959. {
  4960. if (EnterForm1.comboBox_User.Text == "管理员")
  4961. {
  4962. IP地址ToolStripMenuItem.Visible = true;
  4963. 端口ToolStripMenuItem.Visible = true;
  4964. 用户名ToolStripMenuItem.Visible = true;
  4965. 密码ToolStripMenuItem.Visible = true;
  4966. 存储路径ToolStripMenuItem.Visible = true;
  4967. }
  4968. else
  4969. {
  4970. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4971. IP地址ToolStripMenuItem.Visible = false;
  4972. 端口ToolStripMenuItem.Visible = false;
  4973. 用户名ToolStripMenuItem.Visible = false;
  4974. 密码ToolStripMenuItem.Visible = false;
  4975. 存储路径ToolStripMenuItem.Visible = false;
  4976. }
  4977. }
  4978. else
  4979. {
  4980. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4981. IP地址ToolStripMenuItem.Visible = false;
  4982. 端口ToolStripMenuItem.Visible = false;
  4983. 用户名ToolStripMenuItem.Visible = false;
  4984. 密码ToolStripMenuItem.Visible = false;
  4985. 存储路径ToolStripMenuItem.Visible = false;
  4986. }
  4987. }
  4988. catch (Exception)
  4989. {
  4990. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4991. IP地址ToolStripMenuItem.Visible = false;
  4992. 端口ToolStripMenuItem.Visible = false;
  4993. 用户名ToolStripMenuItem.Visible = false;
  4994. 密码ToolStripMenuItem.Visible = false;
  4995. 存储路径ToolStripMenuItem.Visible = false;
  4996. }
  4997. }
  4998. private void 生产信息ToolStripMenuItem_Click(object sender, EventArgs e)
  4999. {
  5000. //输入用户名
  5001. EnterForm1.ShowDialog();
  5002. try
  5003. {
  5004. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5005. {
  5006. if (EnterForm1.comboBox_User.Text == "管理员")
  5007. {
  5008. 生产商ToolStripMenuItem.Visible = true;
  5009. 生产地ToolStripMenuItem.Visible = true;
  5010. 生产日期ToolStripMenuItem.Visible = true;
  5011. 产品标识ToolStripMenuItem.Visible = true;
  5012. }
  5013. else
  5014. {
  5015. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5016. 生产商ToolStripMenuItem.Visible = false;
  5017. 生产地ToolStripMenuItem.Visible = false;
  5018. 生产日期ToolStripMenuItem.Visible = false;
  5019. 产品标识ToolStripMenuItem.Visible = false;
  5020. }
  5021. }
  5022. else
  5023. {
  5024. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5025. 生产商ToolStripMenuItem.Visible = false;
  5026. 生产地ToolStripMenuItem.Visible = false;
  5027. 生产日期ToolStripMenuItem.Visible = false;
  5028. 产品标识ToolStripMenuItem.Visible = false;
  5029. }
  5030. }
  5031. catch (Exception)
  5032. {
  5033. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5034. 生产商ToolStripMenuItem.Visible = false;
  5035. 生产地ToolStripMenuItem.Visible = false;
  5036. 生产日期ToolStripMenuItem.Visible = false;
  5037. 产品标识ToolStripMenuItem.Visible = false;
  5038. }
  5039. }
  5040. /// <summary>
  5041. /// 切换电机类型
  5042. /// </summary>
  5043. /// <param name="sender"></param>
  5044. /// <param name="e"></param>
  5045. private void 中置电机ToolStripMenuItem_Click(object sender, EventArgs e)
  5046. {
  5047. 中置电机ToolStripMenuItem.Checked = true;
  5048. 轮毂电机ToolStripMenuItem.Checked = false;
  5049. toolStripTextBox_MACPD.Text = "MM_MC1";
  5050. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  5051. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5052. }
  5053. /// <summary>
  5054. /// 切换电机类型
  5055. /// </summary>
  5056. /// <param name="sender"></param>
  5057. /// <param name="e"></param>
  5058. private void 轮毂电机ToolStripMenuItem_Click(object sender, EventArgs e)
  5059. {
  5060. 中置电机ToolStripMenuItem.Checked = false;
  5061. 轮毂电机ToolStripMenuItem.Checked = true;
  5062. toolStripTextBox_MACPD.Text = "GF_250_1";
  5063. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  5064. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5065. }
  5066. /// <summary>
  5067. /// 获取配置文件日期
  5068. /// </summary>
  5069. /// <param name="DisAll"></param>
  5070. private void GetDateList(bool DisAll)
  5071. {
  5072. string[] DateList = { "" };
  5073. //从服务器更新日期列表
  5074. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  5075. {
  5076. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
  5077. }
  5078. //从本地更新日期列表
  5079. else
  5080. {
  5081. DateList = Directory.GetDirectories(localInfo.LocalPath + "\\" + localInfo.CfgPathName);
  5082. }
  5083. comboBox_FacModeCfgDate.Items.Clear();
  5084. comboBox_CheckModeCfgDate.Items.Clear();
  5085. //日期列表加载
  5086. if (DisAll == true)
  5087. {
  5088. comboBox_FacModeCfgDate.Items.Add("显示近期");
  5089. comboBox_CheckModeCfgDate.Items.Add("显示近期");
  5090. comboBox_FacModeCfgDate.Items.Add("---");
  5091. comboBox_CheckModeCfgDate.Items.Add("---");
  5092. foreach (var file in DateList)
  5093. {
  5094. comboBox_FacModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5095. comboBox_CheckModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5096. }
  5097. }
  5098. else
  5099. {
  5100. if (DateList.Length > 10)
  5101. {
  5102. comboBox_FacModeCfgDate.Items.Add("显示全部");
  5103. comboBox_CheckModeCfgDate.Items.Add("显示全部");
  5104. comboBox_FacModeCfgDate.Items.Add("---");
  5105. comboBox_CheckModeCfgDate.Items.Add("---");
  5106. }
  5107. for (int i = (DateList.Length > 10) ? (DateList.Length - 10) : 0; i < DateList.Length; i++)//显示最近10个日期
  5108. {
  5109. comboBox_FacModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  5110. comboBox_CheckModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  5111. }
  5112. }
  5113. }
  5114. /// <summary>
  5115. /// 获取配置文件列表
  5116. /// </summary>
  5117. /// <param name="date"></param>
  5118. private void GetFileListFrom(string date)
  5119. {
  5120. string[] FileList = { "" };
  5121. //从服务器更新文件列表
  5122. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  5123. {
  5124. FileList = myFtp.GetFileNameList(toolStripTextBox_ServerPath.Text + "/cfg/" + date);
  5125. }
  5126. else
  5127. {
  5128. FileList = Directory.GetFiles(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + date);
  5129. }
  5130. comboBox_CheckModeCfgFile.Items.Clear();
  5131. comboBox_FacModeCfgFile.Items.Clear();
  5132. foreach (var file in FileList)
  5133. {
  5134. if (file.Contains(".ttcfg"))
  5135. {
  5136. comboBox_CheckModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5137. comboBox_FacModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5138. }
  5139. }
  5140. }
  5141. /// <summary>
  5142. /// 检验模式选择文件日期
  5143. /// </summary>
  5144. /// <param name="sender"></param>
  5145. /// <param name="e"></param>
  5146. private void comboBox_CheckModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  5147. {
  5148. if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示全部")
  5149. {
  5150. GetDateList(true);
  5151. }
  5152. else if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示近期")
  5153. {
  5154. GetDateList(false);
  5155. }
  5156. else
  5157. {
  5158. comboBox_CheckModeCfgFile.Text = "";
  5159. GetFileListFrom(comboBox_CheckModeCfgDate.SelectedItem.ToString());
  5160. }
  5161. }
  5162. /// <summary>
  5163. /// 配置模式选择文件日期
  5164. /// </summary>
  5165. /// <param name="sender"></param>
  5166. /// <param name="e"></param>
  5167. private void comboBox_FacModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  5168. {
  5169. if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示全部")
  5170. {
  5171. GetDateList(true);
  5172. }
  5173. else if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示近期")
  5174. {
  5175. GetDateList(false);
  5176. }
  5177. else
  5178. {
  5179. comboBox_FacModeCfgFile.Text = "";
  5180. GetFileListFrom(comboBox_FacModeCfgDate.SelectedItem.ToString());
  5181. }
  5182. }
  5183. /// <summary>
  5184. /// 选中量产模式
  5185. /// </summary>
  5186. /// <param name="sender"></param>
  5187. /// <param name="e"></param>
  5188. private void tabControl1_Selected(object sender, TabControlEventArgs e)
  5189. {
  5190. //更新生产配置文件目录
  5191. GetDateList(false);
  5192. }
  5193. /// <summary>
  5194. /// 量产测试结束
  5195. /// </summary>
  5196. /// <param name=""></param>
  5197. private void FacMode_Stop(bool OK_Flag)
  5198. {
  5199. //打开开始按钮
  5200. button__FacMode_Start.Enabled = true;
  5201. //系统关机
  5202. var Code = new byte[32];//发送的指令数据
  5203. Code[0] = 0xF0;
  5204. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5205. //关闭串口
  5206. mySerialProcess.SerialClose(false);
  5207. //路径设置
  5208. string LocalSavePath = "";
  5209. string ServerSavePath = "";
  5210. if (OK_Flag)
  5211. {
  5212. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "OK\\";
  5213. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/OK/";
  5214. }
  5215. else
  5216. {
  5217. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "FAIL\\";
  5218. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/FAIL/";
  5219. }
  5220. if (Directory.Exists(LocalSavePath) == false)
  5221. {
  5222. Directory.CreateDirectory(LocalSavePath);
  5223. }
  5224. //保存和上传
  5225. string LogSavePath = "";
  5226. string LogSaveFileName = "";
  5227. string ProductInfo = textBox_FacModeScan.Text;
  5228. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  5229. if (Directory.Exists(LogSavePath) == false)
  5230. {
  5231. Directory.CreateDirectory(LogSavePath);
  5232. }
  5233. //测试页面
  5234. Double scaleX = PrimaryScreen.ScaleX;
  5235. Double scaleY = PrimaryScreen.ScaleY;
  5236. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  5237. Graphics g = Graphics.FromImage(bit);
  5238. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  5239. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  5240. bit.Save(LogSaveFileName);
  5241. //上传测试页面到服务器
  5242. if (myFtp.IsNetConnected == true)
  5243. {
  5244. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  5245. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  5246. {
  5247. myFtp.MakeDir(ServerSavePath + DateNow);
  5248. }
  5249. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  5250. {
  5251. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  5252. }
  5253. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  5254. if (result == true)
  5255. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  5256. }
  5257. else
  5258. {
  5259. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  5260. }
  5261. //测试记录
  5262. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  5263. string file_str = "";
  5264. file_str += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  5265. file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  5266. file_str += "检验记录:\r\n" + richTextBox_FacModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  5267. file_str += "检验结果:\r\n" + label_FacModeResult.Text + "\r\n\r\n";
  5268. file_str += Local_HdInformation;
  5269. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  5270. //上传测试记录到服务器
  5271. if (myFtp.IsNetConnected == true)
  5272. {
  5273. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  5274. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  5275. {
  5276. myFtp.MakeDir(ServerSavePath + DateNow);
  5277. }
  5278. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  5279. {
  5280. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  5281. }
  5282. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  5283. if (result == true)
  5284. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  5285. }
  5286. else
  5287. {
  5288. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  5289. }
  5290. //扫码框清空
  5291. textBox_FacModeScan.Text = "";
  5292. }
  5293. /// <summary>
  5294. /// 量产测试开始
  5295. /// </summary>
  5296. /// <param name="sender"></param>
  5297. /// <param name="e"></param>
  5298. private void button__FacMode_Start_Click(object sender, EventArgs e)
  5299. {
  5300. //关闭测试项目编辑
  5301. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  5302. foreach (Control c in groupBox2.Controls)
  5303. {
  5304. if (c is CheckBox)
  5305. c.Enabled = false;
  5306. }
  5307. WriteLockStatus = true;
  5308. //检查配置文件
  5309. if (comboBox_FacModeCfgFile.Text == "")
  5310. {
  5311. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5312. return;
  5313. }
  5314. //开始测试
  5315. TestStart();
  5316. }
  5317. /// <summary>
  5318. /// 测试子函数
  5319. /// </summary>
  5320. private void TestStart()
  5321. {
  5322. //初始化标签
  5323. FacModelLabelInit();
  5324. richTextBox_FacModeLog.Clear();
  5325. //按钮禁止操作
  5326. button__FacMode_Start.Enabled = false;
  5327. //记录配置文件
  5328. richTextBox_FacModeLog.AppendText("配置文件:" + comboBox_FacModeCfgDate.Text + " / " + comboBox_FacModeCfgFile.Text + "\r\n");
  5329. //检查打标信息格式
  5330. label_FacModeStatus.Text = "检查扫码信息";
  5331. Delay_ms(500);
  5332. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  5333. if (textBox_FacModeScan.Text == string.Empty)
  5334. {
  5335. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5336. return;
  5337. }
  5338. try
  5339. {
  5340. if (中置电机ToolStripMenuItem.Checked == true)
  5341. {
  5342. if (textBox_FacModeScan.Text.Split(' ').Length != 7)
  5343. {
  5344. label_FacModeStatus.Text = "存在故障!";
  5345. label_FacModeResult.BackColor = Color.Red;
  5346. label_FacModeResult.Text = "标签格式错误";
  5347. button__FacMode_Start.Enabled = true;
  5348. return;
  5349. }
  5350. }
  5351. else if (轮毂电机ToolStripMenuItem.Checked == true)
  5352. {
  5353. if (textBox_FacModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  5354. {
  5355. label_FacModeStatus.Text = "存在故障!";
  5356. label_FacModeResult.BackColor = Color.Red;
  5357. label_FacModeResult.Text = "标签格式错误";
  5358. button__FacMode_Start.Enabled = true;
  5359. return;
  5360. }
  5361. }
  5362. }
  5363. catch (System.Exception)
  5364. {
  5365. label_FacModeStatus.Text = "存在故障!";
  5366. label_FacModeResult.BackColor = Color.Red;
  5367. label_FacModeResult.Text = "标签格式错误";
  5368. button__FacMode_Start.Enabled = true;
  5369. return;
  5370. }
  5371. //打开串口
  5372. mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false);
  5373. if (!mySerialProcess.mySerial.IsOpen)
  5374. {
  5375. MessageBox.Show("请检查串口连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5376. return;
  5377. }
  5378. //流水号计数
  5379. //...
  5380. //创建线程,执行测试任务
  5381. Thread th = new Thread(FacModeTest_Task);
  5382. th.Start();
  5383. }
  5384. /// <summary>
  5385. /// 执行一次测试任务
  5386. /// </summary>
  5387. private void FacModeTest_Task()
  5388. {
  5389. //开始测试
  5390. richTextBox_FacModeLog.AppendText("产品标签:" + textBox_FacModeScan.Text + "\r\n");
  5391. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  5392. //变量定义
  5393. var Code = new byte[255];//发送的指令数据
  5394. label_FacModeStatus.Text = "开始测试";
  5395. Delay_ms(500);
  5396. label_FacModeStatus.Text = "系统开机";
  5397. //系统开机,确保测试前先关机,发送关机指令再发送开机指令
  5398. BootInfo = "";
  5399. Code[0] = 0xF0;
  5400. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5401. Delay_ms(1500);
  5402. Code[0] = 0xF1;
  5403. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5404. ACK_WaitCnt = 0;
  5405. while (ACK_WaitCnt <= 2); //1s
  5406. //检查BOOT版本
  5407. if (BootInfo != string.Empty)
  5408. {
  5409. label_FacModeBootVer.BackColor = Color.Green;
  5410. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  5411. Delay_ms(500);
  5412. }
  5413. else
  5414. {
  5415. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
  5416. label_FacModeStatus.Text = "存在故障!";
  5417. label_FacModeResult.BackColor = Color.Red;
  5418. label_FacModeResult.Text = "测试异常";
  5419. Delay_ms(500);
  5420. //存储异常并上传
  5421. FacMode_Stop(false);
  5422. return;
  5423. }
  5424. //系统清除
  5425. if (checkBox_FacModeSysClear.Checked)
  5426. {
  5427. do
  5428. {
  5429. //发送系统清除指令
  5430. label_FacModeStatus.Text = "系统清除";
  5431. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除" + "\r\n");
  5432. Code[0] = (byte)'C';
  5433. Code[1] = (byte)'L';
  5434. Code[2] = (byte)'E';
  5435. Code[3] = (byte)'A';
  5436. Code[4] = (byte)'R';
  5437. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  5438. WriteACK = false;
  5439. WriteCnt = 0;
  5440. ACK_WaitCnt = 0;
  5441. while (ACK_WaitCnt <= 6); //3s
  5442. //等待系统清除完成指令
  5443. if (WriteACK == true)
  5444. {
  5445. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  5446. label_FacModeSysClear.BackColor = Color.Green;
  5447. }
  5448. else
  5449. {
  5450. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除失败" + "\r\n");
  5451. label_FacModeStatus.Text = "存在故障!";
  5452. label_FacModeResult.BackColor = Color.Red;
  5453. label_FacModeResult.Text = "测试异常";
  5454. Delay_ms(500);
  5455. //存储异常并上传
  5456. FacMode_Stop(false);
  5457. return;
  5458. }
  5459. //系统重新开机
  5460. label_FacModeStatus.Text = "重新开机";
  5461. BootInfo = "";
  5462. Code[0] = 0xF1;
  5463. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5464. ACK_WaitCnt = 0;
  5465. while (ACK_WaitCnt <= 4); //2s
  5466. //获取Boot版本信息
  5467. if (BootInfo != string.Empty)
  5468. {
  5469. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机成功" + "\r\n");
  5470. }
  5471. else
  5472. {
  5473. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机失败" + "\r\n");
  5474. label_FacModeStatus.Text = "存在故障!";
  5475. label_FacModeResult.BackColor = Color.Red;
  5476. label_FacModeResult.Text = "测试异常";
  5477. Delay_ms(500);
  5478. //存储异常并上传
  5479. FacMode_Stop(false);
  5480. return;
  5481. }
  5482. } while (false);
  5483. }
  5484. else
  5485. {
  5486. label_FacModeSysClear.BackColor = Color.Yellow;
  5487. label_FacModeStatus.Text = "跳过系统清除!";
  5488. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过系统清除" + "\r\n");
  5489. Delay_ms(500);
  5490. }
  5491. //检查是否有故障
  5492. if (textBox_ErrorCode.Text.Contains("H"))
  5493. {
  5494. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "故障码:" + textBox_ErrorCode.Text + "\r\n");
  5495. label_FacModeStatus.Text = "电机存在故障!";
  5496. label_FacModeResult.BackColor = Color.Red;
  5497. label_FacModeResult.Text = "测试异常";
  5498. Delay_ms(500);
  5499. //存储异常并上传
  5500. FacMode_Stop(false);
  5501. return;
  5502. }
  5503. //参数写入
  5504. if (checkBox_FacModeCfgWrite.Checked)
  5505. {
  5506. label_FacModeStatus.Text = "参数写入";
  5507. //写入产品型号和SN
  5508. do
  5509. {
  5510. //根据扫码信息获取型号和SN
  5511. string ScanInfo = textBox_FacModeScan.Text;
  5512. string regexInfo = "";
  5513. string[] InfoList = { "" };
  5514. try
  5515. {
  5516. if (中置电机ToolStripMenuItem.Checked == true)
  5517. {
  5518. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  5519. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  5520. }
  5521. else if (轮毂电机ToolStripMenuItem.Checked == true)
  5522. {
  5523. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  5524. string Model = InfoList[0];
  5525. string Spec = InfoList[1];
  5526. string Sn = InfoList[2];
  5527. InfoList[0] = Model.Replace("-", "").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  5528. InfoList[1] = Sn;
  5529. }
  5530. }
  5531. catch
  5532. {
  5533. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  5534. label_FacModeStatus.Text = "存在故障!";
  5535. label_FacModeResult.BackColor = Color.Red;
  5536. label_FacModeResult.Text = "标签格式错误";
  5537. Delay_ms(500);
  5538. //存储异常并上传
  5539. FacMode_Stop(false);
  5540. return;
  5541. }
  5542. if (InfoList.Length >= 2)
  5543. {
  5544. //检查配置文件是否与打标信息一致
  5545. //...
  5546. //写入型号
  5547. label_FacModeStatus.Text = "写入型号";
  5548. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号" + "\r\n");
  5549. textBox_FacModeName.Text = InfoList[0];
  5550. string Mode = textBox_FacModeName.Text;
  5551. var ModeArray = new byte[16];
  5552. for (ushort i = 0; i < Mode.Length; i++)
  5553. {
  5554. ModeArray[i] = (byte)Mode[i];
  5555. }
  5556. if (Mode.Length < 16)
  5557. {
  5558. ModeArray[Mode.Length] = (byte)'.';
  5559. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  5560. {
  5561. ModeArray[Mode.Length + 1 + i] = 0x20;
  5562. }
  5563. }
  5564. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  5565. WriteACK = false;
  5566. WriteCnt = 0;
  5567. ACK_WaitCnt = 0;
  5568. while (ACK_WaitCnt <= 2); //1s
  5569. if (WriteACK == true)
  5570. {
  5571. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  5572. }
  5573. else
  5574. {
  5575. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入失败" + "\r\n");
  5576. label_FacModeStatus.Text = "存在故障!";
  5577. label_FacModeResult.BackColor = Color.Red;
  5578. label_FacModeResult.Text = "测试异常";
  5579. Delay_ms(500);
  5580. //存储异常并上传
  5581. FacMode_Stop(false);
  5582. return;
  5583. }
  5584. //写入SN
  5585. label_FacModeStatus.Text = "写入SN";
  5586. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN" + "\r\n");
  5587. textBox_FacModeNum.Text = InfoList[1];
  5588. string SN = textBox_FacModeNum.Text;
  5589. var SNArray = new byte[16];
  5590. for (ushort i = 0; i < SN.Length; i++)
  5591. {
  5592. SNArray[i] = (byte)SN[i];
  5593. }
  5594. if (SN.Length < 16)
  5595. {
  5596. SNArray[SN.Length] = (byte)'.';
  5597. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  5598. {
  5599. SNArray[SN.Length + 1 + i] = 0x20;
  5600. }
  5601. }
  5602. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  5603. WriteACK = false;
  5604. WriteCnt = 0;
  5605. ACK_WaitCnt = 0;
  5606. while (ACK_WaitCnt <= 2); //1s
  5607. if (WriteACK == true)
  5608. {
  5609. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  5610. }
  5611. else
  5612. {
  5613. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入失败" + "\r\n");
  5614. label_FacModeStatus.Text = "存在故障!";
  5615. label_FacModeResult.BackColor = Color.Red;
  5616. label_FacModeResult.Text = "测试异常";
  5617. Delay_ms(500);
  5618. //存储异常并上传
  5619. FacMode_Stop(false);
  5620. return;
  5621. }
  5622. }
  5623. else
  5624. {
  5625. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5626. return;
  5627. }
  5628. } while (false);
  5629. //写入配置文件
  5630. do
  5631. {
  5632. label_FacModeStatus.Text = "写入配置文件";
  5633. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  5634. //配置文件
  5635. List<byte[]> CmdList = new List<byte[]>();
  5636. //从服务器下载文件
  5637. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  5638. {
  5639. string SelectFile = "";
  5640. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "/" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  5641. if (File.Exists(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  5642. {
  5643. File.Delete(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  5644. }
  5645. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  5646. //打开文件
  5647. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  5648. CmdList.Clear();
  5649. while (streamReader.Peek() != -1)
  5650. {
  5651. string fileLineInfo = streamReader.ReadLine();
  5652. if (fileLineInfo.IndexOf("[") != -1)
  5653. {
  5654. continue;
  5655. }
  5656. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  5657. }
  5658. streamReader.Close();
  5659. }
  5660. //加载本地文件
  5661. else
  5662. {
  5663. string SelectFile = "";
  5664. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  5665. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  5666. CmdList.Clear();
  5667. while (streamReader.Peek() != -1)
  5668. {
  5669. string fileLineInfo = streamReader.ReadLine();
  5670. if (fileLineInfo.IndexOf("[") != -1)
  5671. {
  5672. continue;
  5673. }
  5674. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  5675. }
  5676. streamReader.Close();
  5677. }
  5678. int CmdNum = CmdList.Count(); //指令个数
  5679. Delay_ms(500);
  5680. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "开始写入" + "\r\n");
  5681. Delay_ms(500);
  5682. //开始写入
  5683. WriteCnt = 0;
  5684. for (int i = 0; i < CmdList.Count; i++)
  5685. {
  5686. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  5687. Thread.Sleep(200);
  5688. }
  5689. //判断写入是否完整
  5690. if (CmdNum == WriteCnt)
  5691. {
  5692. label_FacMode_CfgWrite.BackColor = Color.Green;
  5693. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入成功" + "\r\n");
  5694. Delay_ms(500);
  5695. }
  5696. else
  5697. {
  5698. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入失败" + "\r\n");
  5699. label_FacModeStatus.Text = "存在故障!";
  5700. label_FacModeResult.BackColor = Color.Red;
  5701. label_FacModeResult.Text = "测试异常";
  5702. Delay_ms(500);
  5703. //存储异常并上传
  5704. FacMode_Stop(false);
  5705. return;
  5706. }
  5707. } while (false);
  5708. }
  5709. else
  5710. {
  5711. label_FacMode_CfgWrite.BackColor = Color.Yellow;
  5712. label_FacModeStatus.Text = "跳过参数写入!";
  5713. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数写入" + "\r\n");
  5714. Delay_ms(500);
  5715. }
  5716. //BMS通讯
  5717. if (checkBox_FacModeBMS.Checked)
  5718. {
  5719. if (label_FacModeBMS.BackColor == Color.Red)
  5720. {
  5721. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "BMS通讯异常" + "\r\n");
  5722. label_FacModeStatus.Text = "存在故障!";
  5723. label_FacModeResult.BackColor = Color.Red;
  5724. label_FacModeResult.Text = "测试异常";
  5725. Delay_ms(500);
  5726. //存储异常并上传
  5727. FacMode_Stop(false);
  5728. return;
  5729. }
  5730. }
  5731. else
  5732. {
  5733. label_FacModeBMS.BackColor = Color.Yellow;
  5734. label_FacModeStatus.Text = "跳过BMS通讯检测!";
  5735. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过BMS通讯检测" + "\r\n");
  5736. Delay_ms(500);
  5737. }
  5738. //基础功能检测
  5739. if (checkBox_FacBaseFucTest.Checked)
  5740. {
  5741. label_FacModeStatus.Text = "基础功能检测";
  5742. //发送指令进入配置模式
  5743. do
  5744. {
  5745. Code[0] = 0x01;
  5746. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  5747. WriteACK = false;
  5748. WriteCnt = 0;
  5749. ACK_WaitCnt = 0;
  5750. while (ACK_WaitCnt <= 2); //1s
  5751. if (textBox_RunInfo_Vol.Text != "---")
  5752. {
  5753. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  5754. }
  5755. else
  5756. {
  5757. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  5758. label_FacModeStatus.Text = "存在故障!";
  5759. label_FacModeResult.BackColor = Color.Red;
  5760. label_FacModeResult.Text = "测试异常";
  5761. Delay_ms(500);
  5762. //存储异常并上传
  5763. FacMode_Stop(false);
  5764. return;
  5765. }
  5766. } while (false);
  5767. //发送指令启动电机
  5768. do
  5769. {
  5770. //发送指令读取调试信息
  5771. richTextBox_DebugParam.Clear();
  5772. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  5773. WriteACK = false;
  5774. WriteCnt = 0;
  5775. ACK_WaitCnt = 0;
  5776. while (ACK_WaitCnt <= 2); //1s
  5777. //获取调试信息
  5778. string DebugDefaultInfo = "";
  5779. if (richTextBox_DebugParam.Text == string.Empty)
  5780. {
  5781. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
  5782. label_FacModeStatus.Text = "存在故障!";
  5783. label_FacModeResult.BackColor = Color.Red;
  5784. label_FacModeResult.Text = "测试异常";
  5785. Delay_ms(500);
  5786. //存储异常并上传
  5787. FacMode_Stop(false);
  5788. return;
  5789. }
  5790. else
  5791. {
  5792. DebugDefaultInfo = richTextBox_DebugParam.Text;
  5793. }
  5794. //设置模式
  5795. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  5796. strDataTemp[0] = "整体运行模式=3";
  5797. //发送数据
  5798. Code[0] = 0;
  5799. Code[1] = 0;
  5800. for (int i = 0; i < strDataTemp.Length; i++)
  5801. {
  5802. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  5803. Code[2 * i + 2] = (byte)uwDataTemp;
  5804. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  5805. }
  5806. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  5807. label_FacModeStatus.Text = "启动电机";
  5808. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "启动电机" + "\r\n");
  5809. //设置转速100%
  5810. var Data = new byte[1];
  5811. Data[0] = (byte)100;
  5812. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  5813. Delay_ms(3000);
  5814. } while (false);
  5815. //判断车速
  5816. if ((Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) <= Convert.ToDouble( toolStripTextBox_ThBikeSpeed.Text.Split(',')[1])) &&
  5817. (Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThBikeSpeed.Text.Split(',')[0])))
  5818. {
  5819. label_FacModeSpeed.BackColor = Color.Green;
  5820. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器正常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
  5821. }
  5822. else
  5823. {
  5824. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器异常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
  5825. label_FacModeStatus.Text = "存在故障!";
  5826. label_FacModeResult.BackColor = Color.Red;
  5827. label_FacModeResult.Text = "测试异常";
  5828. Delay_ms(500);
  5829. //存储异常并上传
  5830. FacMode_Stop(false);
  5831. return;
  5832. }
  5833. //判断电压
  5834. if ((Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[1])) &&
  5835. (Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[0])))
  5836. {
  5837. label_FacModeVolTest.BackColor = Color.Green;
  5838. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量正常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
  5839. }
  5840. else
  5841. {
  5842. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量异常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
  5843. label_FacModeStatus.Text = "存在故障!";
  5844. label_FacModeResult.BackColor = Color.Red;
  5845. label_FacModeResult.Text = "测试异常";
  5846. Delay_ms(500);
  5847. //存储异常并上传
  5848. FacMode_Stop(false);
  5849. return;
  5850. }
  5851. //判断电流
  5852. if ((Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[1])) &&
  5853. (Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[0])))
  5854. {
  5855. label_FacModeCurrentTest.BackColor = Color.Green;
  5856. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量正常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  5857. }
  5858. else
  5859. {
  5860. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量异常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  5861. label_FacModeStatus.Text = "存在故障!";
  5862. label_FacModeResult.BackColor = Color.Red;
  5863. label_FacModeResult.Text = "测试异常";
  5864. Delay_ms(500);
  5865. //存储异常并上传
  5866. FacMode_Stop(false);
  5867. return;
  5868. }
  5869. //判断温度
  5870. if ((Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[1])) &&
  5871. (Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[0])) &&
  5872. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[1])) &&
  5873. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[0])) &&
  5874. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[1])) &&
  5875. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[0])))
  5876. {
  5877. label_FacModeNTC.BackColor = Color.Green;
  5878. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "温度传感器正常" + " " + textBox_RunInfo_T_PCB.Text + " " + textBox_RunInfo_T_MCU.Text + " " + textBox_RunInfo_T_Coil.Text + "\r\n");
  5879. }
  5880. else
  5881. {
  5882. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "温度传感器异常" + " " + textBox_RunInfo_T_PCB.Text + " " + textBox_RunInfo_T_MCU.Text + " " + textBox_RunInfo_T_Coil.Text + "\r\n");
  5883. label_FacModeStatus.Text = "存在故障!";
  5884. label_FacModeResult.BackColor = Color.Red;
  5885. label_FacModeResult.Text = "测试异常";
  5886. Delay_ms(500);
  5887. //存储异常并上传
  5888. FacMode_Stop(false);
  5889. return;
  5890. }
  5891. //判断转速
  5892. if ((Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[1])) &&
  5893. (Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[0])))
  5894. {
  5895. label_FacModeMotorSpeed.BackColor = Color.Green;
  5896. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速正常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
  5897. }
  5898. else
  5899. {
  5900. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速异常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
  5901. label_FacModeStatus.Text = "存在故障!";
  5902. label_FacModeResult.BackColor = Color.Red;
  5903. label_FacModeResult.Text = "测试异常";
  5904. Delay_ms(500);
  5905. //存储异常并上传
  5906. FacMode_Stop(false);
  5907. return;
  5908. }
  5909. //发送指令停止电机
  5910. do
  5911. {
  5912. //设置转速0%
  5913. var Data = new byte[1];
  5914. Data[0] = (byte)0;
  5915. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  5916. //获取调试信息
  5917. string DebugDefaultInfo = "";
  5918. if (richTextBox_DebugParam.Text == string.Empty)
  5919. {
  5920. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
  5921. label_FacModeStatus.Text = "存在故障!";
  5922. label_FacModeResult.BackColor = Color.Red;
  5923. label_FacModeResult.Text = "测试异常";
  5924. Delay_ms(500);
  5925. //存储异常并上传
  5926. FacMode_Stop(false);
  5927. return;
  5928. }
  5929. else
  5930. {
  5931. DebugDefaultInfo = richTextBox_DebugParam.Text;
  5932. }
  5933. //设置模式
  5934. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  5935. //发送数据
  5936. Code[0] = 0;
  5937. Code[1] = 0;
  5938. for (int i = 0; i < strDataTemp.Length; i++)
  5939. {
  5940. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  5941. Code[2 * i + 2] = (byte)uwDataTemp;
  5942. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  5943. }
  5944. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  5945. label_FacModeStatus.Text = "停止电机";
  5946. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "停止电机" + "\r\n");
  5947. Delay_ms(2000);
  5948. } while (false);
  5949. }
  5950. else
  5951. {
  5952. label_FacModeSpeed.BackColor = Color.Yellow;
  5953. label_FacModeVolTest.BackColor = Color.Yellow;
  5954. label_FacModeCurrentTest.BackColor = Color.Yellow;
  5955. label_FacModeNTC.BackColor = Color.Yellow;
  5956. label_FacModeMotorSpeed.BackColor = Color.Yellow;
  5957. label_FacModeStatus.Text = "跳过基础功能检测!";
  5958. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过基础功能检测" + "\r\n");
  5959. Delay_ms(500);
  5960. }
  5961. //力矩检测
  5962. if (checkBox_FacTor.Checked)
  5963. {
  5964. label_FacModeStatus.Text = "力矩传感器检测!";
  5965. //发送指令进入配置模式
  5966. do
  5967. {
  5968. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  5969. {
  5970. break;
  5971. }
  5972. Code[0] = 0x01;
  5973. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  5974. WriteACK = false;
  5975. WriteCnt = 0;
  5976. ACK_WaitCnt = 0;
  5977. while (ACK_WaitCnt <= 2) ; //1s
  5978. if (textBox_RunInfo_Vol.Text != "---")
  5979. {
  5980. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  5981. Delay_ms(500);
  5982. }
  5983. else
  5984. {
  5985. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  5986. label_FacModeStatus.Text = "存在故障!";
  5987. label_FacModeResult.BackColor = Color.Red;
  5988. label_FacModeResult.Text = "测试异常";
  5989. Delay_ms(500);
  5990. //存储异常并上传
  5991. FacMode_Stop(false);
  5992. return;
  5993. }
  5994. } while (false);
  5995. ushort Max = 0, Torque = 0;
  5996. //提示输入力矩信号
  5997. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟力矩信号输入" + "\r\n");
  5998. ACK_WaitCnt = 0;
  5999. while (ACK_WaitCnt <= 20) //10s
  6000. {
  6001. //获取力矩值
  6002. Torque = (ushort)Convert.ToInt16(textBox_RunInfo_Torque.Text.Split(' ')[0]);
  6003. if (Torque > Max)
  6004. Max = Torque;
  6005. if ((Max <= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[1])) &&
  6006. (Max >= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[0])) &&
  6007. (ACK_WaitCnt >= 6))
  6008. {
  6009. label_FacModeTq.BackColor = Color.Green;
  6010. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器正常" + " " + textBox_RunInfo_Torque.Text + "\r\n");
  6011. break;
  6012. }
  6013. }
  6014. if (ACK_WaitCnt >= 20)
  6015. {
  6016. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器异常" + "\r\n");
  6017. label_FacModeStatus.Text = "存在故障!";
  6018. label_FacModeResult.BackColor = Color.Red;
  6019. label_FacModeResult.Text = "测试异常";
  6020. Delay_ms(500);
  6021. //存储异常并上传
  6022. FacMode_Stop(false);
  6023. return;
  6024. }
  6025. }
  6026. else
  6027. {
  6028. label_FacModeTq.BackColor = Color.Yellow;
  6029. label_FacModeCad.BackColor = Color.Yellow;
  6030. label_FacModeStatus.Text = "跳过力矩检测!";
  6031. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过力矩检测" + "\r\n");
  6032. Delay_ms(500);
  6033. }
  6034. //踏频检测
  6035. if (checkBox_FacCad.Checked)
  6036. {
  6037. label_FacModeStatus.Text = "踏频传感器检测!";
  6038. //发送指令进入配置模式
  6039. do
  6040. {
  6041. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  6042. {
  6043. break;
  6044. }
  6045. Code[0] = 0x01;
  6046. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6047. WriteACK = false;
  6048. WriteCnt = 0;
  6049. ACK_WaitCnt = 0;
  6050. while (ACK_WaitCnt <= 2) ; //1s
  6051. if (textBox_RunInfo_Vol.Text != "---")
  6052. {
  6053. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6054. Delay_ms(500);
  6055. }
  6056. else
  6057. {
  6058. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  6059. label_FacModeStatus.Text = "存在故障!";
  6060. label_FacModeResult.BackColor = Color.Red;
  6061. label_FacModeResult.Text = "测试异常";
  6062. Delay_ms(500);
  6063. //存储异常并上传
  6064. FacMode_Stop(false);
  6065. return;
  6066. }
  6067. } while (false);
  6068. ushort Max = 0, Cadence = 0;
  6069. //提示输入踏频信号
  6070. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟踏频信号输入" + "\r\n");
  6071. ACK_WaitCnt = 0;
  6072. while (ACK_WaitCnt <= 20) //10s
  6073. {
  6074. //获取踏频
  6075. Cadence = (ushort)Convert.ToInt16(textBox_RunInfo_Cadence.Text.Split(' ')[0]);
  6076. if (Cadence > Max)
  6077. Max = Cadence;
  6078. if ((Max <= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[1])) &&
  6079. (Max >= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[0])) &&
  6080. (ACK_WaitCnt >= 6))
  6081. {
  6082. label_FacModeCad.BackColor = Color.Green;
  6083. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器正常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  6084. break;
  6085. }
  6086. }
  6087. if (ACK_WaitCnt >= 20)
  6088. {
  6089. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器异常" + "\r\n");
  6090. label_FacModeStatus.Text = "存在故障!";
  6091. label_FacModeResult.BackColor = Color.Red;
  6092. label_FacModeResult.Text = "测试异常";
  6093. Delay_ms(500);
  6094. //存储异常并上传
  6095. FacMode_Stop(false);
  6096. return;
  6097. }
  6098. }
  6099. else
  6100. {
  6101. label_FacModeTq.BackColor = Color.Yellow;
  6102. label_FacModeCad.BackColor = Color.Yellow;
  6103. label_FacModeStatus.Text = "跳过踏频检测!";
  6104. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过踏频检测" + "\r\n");
  6105. Delay_ms(500);
  6106. }
  6107. //转把检测
  6108. if (checkBox_FacThrrotleTest.Checked)
  6109. {
  6110. label_FacModeStatus.Text = "转把检测";
  6111. //发送指令进入配置模式
  6112. do
  6113. {
  6114. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  6115. {
  6116. break;
  6117. }
  6118. Code[0] = 0x01;
  6119. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6120. WriteACK = false;
  6121. WriteCnt = 0;
  6122. ACK_WaitCnt = 0;
  6123. while (ACK_WaitCnt <= 2) ; //1s
  6124. if (textBox_RunInfo_Vol.Text != "---")
  6125. {
  6126. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6127. Delay_ms(500);
  6128. }
  6129. else
  6130. {
  6131. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  6132. label_FacModeStatus.Text = "存在故障!";
  6133. label_FacModeResult.BackColor = Color.Red;
  6134. label_FacModeResult.Text = "测试异常";
  6135. Delay_ms(500);
  6136. //存储异常并上传
  6137. FacMode_Stop(false);
  6138. return;
  6139. }
  6140. } while (false);
  6141. //进入TURBO档
  6142. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把检测,发送指令进入TURBO" + "\r\n");
  6143. Code[0] = 0x04;
  6144. Code[1] = 0xF0;
  6145. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6146. WriteACK = false;
  6147. WriteCnt = 0;
  6148. ACK_WaitCnt = 0;
  6149. while (ACK_WaitCnt <= 2) ; //1s
  6150. if (textBox_RunInfo_GearSt.Text != "TURBO")
  6151. {
  6152. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO异常" + "\r\n");
  6153. label_FacModeStatus.Text = "存在故障!";
  6154. label_FacModeResult.BackColor = Color.Red;
  6155. label_FacModeResult.Text = "测试异常";
  6156. Delay_ms(500);
  6157. //存储异常并上传
  6158. FacMode_Stop(false);
  6159. return;
  6160. }
  6161. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO,10s内转动转把" + "\r\n");
  6162. ACK_WaitCnt = 0;
  6163. while (ACK_WaitCnt <= 20)
  6164. {
  6165. if ((Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) > 500) && (ACK_WaitCnt >= 10))
  6166. {
  6167. label_FacModeGas.BackColor = Color.Green;
  6168. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能正常,松开转把" + "\r\n");
  6169. break;
  6170. }
  6171. }
  6172. if (ACK_WaitCnt >= 20) //转把超时
  6173. {
  6174. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能异常,松开转把" + "\r\n");
  6175. label_FacModeStatus.Text = "存在故障!";
  6176. label_FacModeResult.BackColor = Color.Red;
  6177. label_FacModeResult.Text = "测试异常";
  6178. Delay_ms(500);
  6179. //存储异常并上传
  6180. FacMode_Stop(false);
  6181. return;
  6182. }
  6183. }
  6184. else
  6185. {
  6186. label_FacModeGas.BackColor = Color.Yellow;
  6187. label_FacModeStatus.Text = "跳过转把检测!";
  6188. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过转把检测" + "\r\n");
  6189. Delay_ms(500);
  6190. }
  6191. //刹车检测
  6192. if (checkBox_FacBreakTest.Checked)
  6193. {
  6194. label_FacModeStatus.Text = "刹把检测";
  6195. //发送指令进入配置模式
  6196. do
  6197. {
  6198. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  6199. {
  6200. break;
  6201. }
  6202. Code[0] = 0x01;
  6203. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6204. WriteACK = false;
  6205. WriteCnt = 0;
  6206. ACK_WaitCnt = 0;
  6207. while (ACK_WaitCnt <= 2) ; //1s
  6208. if (textBox_RunInfo_Vol.Text != "---")
  6209. {
  6210. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6211. Delay_ms(500);
  6212. }
  6213. else
  6214. {
  6215. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  6216. label_FacModeStatus.Text = "存在故障!";
  6217. label_FacModeResult.BackColor = Color.Red;
  6218. label_FacModeResult.Text = "测试异常";
  6219. Delay_ms(500);
  6220. //存储异常并上传
  6221. FacMode_Stop(false);
  6222. return;
  6223. }
  6224. } while (false);
  6225. //启动电机进入WALK模式
  6226. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把检测,进入WALK" + "\r\n");
  6227. Code[0] = 0x22;
  6228. Code[1] = 0xF0;
  6229. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6230. WriteACK = false;
  6231. WriteCnt = 0;
  6232. ACK_WaitCnt = 0;
  6233. while (ACK_WaitCnt <= 2) ; //1s
  6234. if (textBox_RunInfo_GearSt.Text != "WALK")
  6235. {
  6236. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
  6237. label_FacModeStatus.Text = "存在故障!";
  6238. label_FacModeResult.BackColor = Color.Red;
  6239. label_FacModeResult.Text = "测试异常";
  6240. Delay_ms(500);
  6241. //存储异常并上传
  6242. FacMode_Stop(false);
  6243. return;
  6244. }
  6245. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,10s内操作剎把" + "\r\n");
  6246. ACK_WaitCnt = 0;
  6247. while (ACK_WaitCnt <= 20)
  6248. {
  6249. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 100)
  6250. {
  6251. label_FacModeBreak.BackColor = Color.Green;
  6252. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把功能正常,松开剎把" + "\r\n");
  6253. break;
  6254. }
  6255. }
  6256. if (ACK_WaitCnt >= 20) //剎把超时
  6257. {
  6258. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把功能异常,松开剎把" + "\r\n");
  6259. label_FacModeStatus.Text = "存在故障!";
  6260. label_FacModeResult.BackColor = Color.Red;
  6261. label_FacModeResult.Text = "测试异常";
  6262. Delay_ms(500);
  6263. //存储异常并上传
  6264. FacMode_Stop(false);
  6265. return;
  6266. }
  6267. //停止电机
  6268. Code[0] = 0x00;
  6269. Code[1] = 0xF0;
  6270. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6271. WriteACK = false;
  6272. WriteCnt = 0;
  6273. ACK_WaitCnt = 0;
  6274. while (ACK_WaitCnt <= 2) ; //1s
  6275. if (textBox_RunInfo_GearSt.Text != "OFF")
  6276. {
  6277. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
  6278. label_FacModeStatus.Text = "存在故障!";
  6279. label_FacModeResult.BackColor = Color.Red;
  6280. label_FacModeResult.Text = "测试异常";
  6281. Delay_ms(500);
  6282. //存储异常并上传
  6283. FacMode_Stop(false);
  6284. return;
  6285. }
  6286. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK" + "\r\n");
  6287. Delay_ms(500);
  6288. }
  6289. else
  6290. {
  6291. label_FacModeBreak.BackColor = Color.Yellow;
  6292. label_FacModeStatus.Text = "跳过刹车检测!";
  6293. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过刹车检测" + "\r\n");
  6294. Delay_ms(500);
  6295. }
  6296. //前后灯检测
  6297. if (checkBox_FacLightTest.Checked)
  6298. {
  6299. //前后灯检测
  6300. label_FacModeStatus.Text = "前后灯检测";
  6301. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开灯指令" + "\r\n");
  6302. //发送指令打开车灯
  6303. Code[0] = 0x00;
  6304. Code[1] = 0xF1;
  6305. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6306. WriteACK = false;
  6307. WriteCnt = 0;
  6308. ACK_WaitCnt = 0;
  6309. while (ACK_WaitCnt <= 2) ; //1s
  6310. if (textBox_RunInfo_LightSwitch.Text != "ON")
  6311. {
  6312. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令发送异常" + "\r\n");
  6313. label_FacModeStatus.Text = "存在故障!";
  6314. label_FacModeResult.BackColor = Color.Red;
  6315. label_FacModeResult.Text = "测试异常";
  6316. Delay_ms(500);
  6317. //存储异常并上传
  6318. FacMode_Stop(false);
  6319. return;
  6320. }
  6321. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已打开前后灯" + "\r\n");
  6322. Delay_ms(500);
  6323. //提示检查灯压是否正确
  6324. if (MessageBox.Show("前后灯是否正常?", "前后灯判断", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  6325. {
  6326. label_FacModeLightF.BackColor = Color.Green;
  6327. label_FacModeLightB.BackColor = Color.Green;
  6328. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯正常" + "\r\n");
  6329. Delay_ms(500);
  6330. }
  6331. else
  6332. {
  6333. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯异常" + "\r\n");
  6334. label_FacModeStatus.Text = "存在故障!";
  6335. label_FacModeResult.BackColor = Color.Red;
  6336. label_FacModeResult.Text = "测试异常";
  6337. Delay_ms(500);
  6338. //存储异常并上传
  6339. FacMode_Stop(false);
  6340. return;
  6341. }
  6342. //发送指令关闭车灯
  6343. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关灯指令" + "\r\n");
  6344. Code[0] = 0x00;
  6345. Code[1] = 0xF0;
  6346. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6347. WriteACK = false;
  6348. WriteCnt = 0;
  6349. ACK_WaitCnt = 0;
  6350. while (ACK_WaitCnt <= 2) ; //1s
  6351. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  6352. {
  6353. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令发送异常" + "\r\n");
  6354. label_FacModeStatus.Text = "存在故障!";
  6355. label_FacModeResult.BackColor = Color.Red;
  6356. label_FacModeResult.Text = "测试异常";
  6357. Delay_ms(500);
  6358. //存储异常并上传
  6359. FacMode_Stop(false);
  6360. return;
  6361. }
  6362. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已关闭前后灯" + "\r\n");
  6363. Delay_ms(500);
  6364. }
  6365. else
  6366. {
  6367. label_FacModeLightF.BackColor = Color.Yellow;
  6368. label_FacModeLightB.BackColor = Color.Yellow;
  6369. label_FacModeStatus.Text = "跳过前后灯检测!";
  6370. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过前后灯检测" + "\r\n");
  6371. Delay_ms(500);
  6372. }
  6373. //软件版本检测
  6374. do
  6375. {
  6376. label_FacModeStatus.Text = "软件版本确认";
  6377. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  6378. //发送指令读取版本
  6379. Class_Motor_Ver.Mode = "---";
  6380. Class_Motor_Ver.SN = "---";
  6381. Class_Motor_Ver.HW = "---";
  6382. Class_Motor_Ver.FW = "---";
  6383. Class_Motor_Ver.Special = "---";
  6384. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  6385. ACK_WaitCnt = 0;
  6386. while (ACK_WaitCnt <= 2) ; //1s
  6387. if (Class_Motor_Ver.Mode == "---")
  6388. {
  6389. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息失败" + "\r\n");
  6390. label_FacModeStatus.Text = "存在故障!";
  6391. label_FacModeResult.BackColor = Color.Red;
  6392. label_FacModeResult.Text = "测试异常";
  6393. Delay_ms(500);
  6394. //存储异常并上传
  6395. FacMode_Stop(false);
  6396. return;
  6397. }
  6398. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  6399. richTextBox_FacModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  6400. richTextBox_FacModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  6401. richTextBox_FacModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  6402. richTextBox_FacModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  6403. richTextBox_FacModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  6404. //判断版本是否正确
  6405. string VerCheck = comboBox_FacModeCfgFile.Text.Split('_')[3] + "_" + comboBox_FacModeCfgFile.Text.Split('_')[4];
  6406. string VerRead = "";
  6407. try
  6408. {
  6409. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  6410. }
  6411. catch (System.Exception)
  6412. {
  6413. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  6414. label_FacModeStatus.Text = "存在故障!";
  6415. label_FacModeResult.BackColor = Color.Red;
  6416. label_FacModeResult.Text = "测试异常";
  6417. Delay_ms(500);
  6418. //存储异常并上传
  6419. FacMode_Stop(false);
  6420. return;
  6421. }
  6422. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  6423. {
  6424. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
  6425. label_FacModeStatus.Text = "存在故障!";
  6426. label_FacModeResult.BackColor = Color.Red;
  6427. label_FacModeResult.Text = "测试异常";
  6428. Delay_ms(500);
  6429. //存储异常并上传
  6430. FacMode_Stop(false);
  6431. return;
  6432. }
  6433. label_FacModeFWVersion.BackColor = Color.Green;
  6434. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  6435. Delay_ms(500);
  6436. } while (false);
  6437. //测试合格
  6438. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  6439. label_FacModeStatus.Text = "测试结束!";
  6440. label_FacModeResult.BackColor = Color.Green;
  6441. label_FacModeResult.Text = "测试合格";
  6442. Delay_ms(500);
  6443. //存储并上传
  6444. FacMode_Stop(true);
  6445. return;
  6446. }
  6447. private void FacModelLabelInit()
  6448. {
  6449. //测试状态标签
  6450. label_FacModeResult.BackColor = Color.Yellow;
  6451. label_FacModeResult.Text = "测试中";
  6452. //测试过程标签
  6453. label_FacModeStatus.Text = "测试就绪";
  6454. //测试结果标签
  6455. foreach (Control c in groupBox28.Controls)
  6456. {
  6457. if (c is Label)
  6458. {
  6459. if (c.Text == string.Empty)
  6460. c.BackColor = Color.Red;
  6461. }
  6462. }
  6463. }
  6464. private void comboBox_CheckModeCfgDate_Click(object sender, EventArgs e)
  6465. {
  6466. //更新生产配置文件目录
  6467. GetDateList(false);
  6468. }
  6469. private void comboBox_FacModeCfgDate_Click(object sender, EventArgs e)
  6470. {
  6471. //更新生产配置文件目录
  6472. GetDateList(false);
  6473. }
  6474. private void richTextBox_FacModeLog_TextChanged(object sender, EventArgs e)
  6475. {
  6476. richTextBox_FacModeLog.SelectionStart = richTextBox_FacModeLog.Text.Length;
  6477. richTextBox_FacModeLog.ScrollToCaret();
  6478. }
  6479. /// <summary>
  6480. /// 参数检验测试停止
  6481. /// </summary>
  6482. /// <param name="OK_Flag"></param>
  6483. private void CheckMode_Stop(bool OK_Flag)
  6484. {
  6485. //打开开始按钮
  6486. button_CheckModeStart.Enabled = true;
  6487. //系统关机
  6488. var Code = new byte[32];//发送的指令数据
  6489. Code[0] = 0xF0;
  6490. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6491. //关闭串口
  6492. mySerialProcess.SerialClose(false);
  6493. //路径设置
  6494. string LocalSavePath = "";
  6495. string ServerSavePath = "";
  6496. if (OK_Flag)
  6497. {
  6498. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "OK\\";
  6499. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/OK/";
  6500. }
  6501. else
  6502. {
  6503. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "FAIL\\";
  6504. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/FAIL/";
  6505. }
  6506. if (Directory.Exists(LocalSavePath) == false)
  6507. {
  6508. Directory.CreateDirectory(LocalSavePath);
  6509. }
  6510. //保存和上传
  6511. string LogSavePath = "";
  6512. string LogSaveFileName = "";
  6513. string ProductInfo = textBox_CheckModeScan.Text;
  6514. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  6515. if (Directory.Exists(LogSavePath) == false)
  6516. {
  6517. Directory.CreateDirectory(LogSavePath);
  6518. }
  6519. //测试页面
  6520. Double scaleX = PrimaryScreen.ScaleX;
  6521. Double scaleY = PrimaryScreen.ScaleY;
  6522. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  6523. Graphics g = Graphics.FromImage(bit);
  6524. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  6525. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  6526. bit.Save(LogSaveFileName);
  6527. //上传测试页面到服务器
  6528. if (myFtp.IsNetConnected == true)
  6529. {
  6530. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  6531. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  6532. {
  6533. myFtp.MakeDir(ServerSavePath + DateNow);
  6534. }
  6535. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  6536. {
  6537. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  6538. }
  6539. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  6540. if (result == true)
  6541. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  6542. }
  6543. //测试记录
  6544. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  6545. string file_str = "";
  6546. file_str += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  6547. file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  6548. file_str += "检验记录:\r\n" + richTextBox_CheckModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  6549. file_str += "检验结果:\r\n" + label_CheckModeResult.Text + "\r\n\r\n";
  6550. file_str += Local_HdInformation;
  6551. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  6552. //上传测试记录到服务器
  6553. if (myFtp.IsNetConnected == true)
  6554. {
  6555. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  6556. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  6557. {
  6558. myFtp.MakeDir(ServerSavePath + DateNow);
  6559. }
  6560. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  6561. {
  6562. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  6563. }
  6564. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  6565. if (result == true)
  6566. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  6567. }
  6568. //扫码框清空
  6569. textBox_CheckModeScan.Text = "";
  6570. }
  6571. /// <summary>
  6572. /// 参数检验开始
  6573. /// </summary>
  6574. /// <param name="sender"></param>
  6575. /// <param name="e"></param>
  6576. private void button_CheckModeStart_Click(object sender, EventArgs e)
  6577. {
  6578. //测试项目关闭编辑
  6579. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  6580. foreach (Control c in groupBox29.Controls)
  6581. {
  6582. if (c is CheckBox)
  6583. c.Enabled = false;
  6584. }
  6585. ReadLockStatus = true;
  6586. //检查配置文件
  6587. if (comboBox_CheckModeCfgFile.Text == "")
  6588. {
  6589. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6590. return;
  6591. }
  6592. //开始测试
  6593. CheckTestStart();
  6594. }
  6595. /// <summary>
  6596. /// 参数检验测试子函数
  6597. /// </summary>
  6598. private void CheckTestStart()
  6599. {
  6600. //初始化标签
  6601. CheckModeLabelInit();
  6602. richTextBox_CheckModeLog.Clear();
  6603. //按钮禁止操作
  6604. button_CheckModeStart.Enabled = false;
  6605. //记录配置文件
  6606. richTextBox_CheckModeLog.AppendText("配置文件:" + comboBox_CheckModeCfgDate.Text + " / " + comboBox_CheckModeCfgFile.Text + "\r\n");
  6607. //检查打标信息
  6608. label_CheckModeStatus.Text = "检查扫码信息";
  6609. Delay_ms(500);
  6610. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  6611. if (textBox_CheckModeScan.Text == string.Empty)
  6612. {
  6613. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6614. return;
  6615. }
  6616. try
  6617. {
  6618. if (中置电机ToolStripMenuItem.Checked == true)
  6619. {
  6620. if (textBox_CheckModeScan.Text.Split(' ').Length != 7)
  6621. {
  6622. label_CheckModeStatus.Text = "存在故障!";
  6623. label_CheckModeResult.BackColor = Color.Red;
  6624. label_CheckModeResult.Text = "标签格式错误";
  6625. button_CheckModeStart.Enabled = true;
  6626. return;
  6627. }
  6628. }
  6629. else if (轮毂电机ToolStripMenuItem.Checked == true)
  6630. {
  6631. if (textBox_CheckModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  6632. {
  6633. label_CheckModeStatus.Text = "存在故障!";
  6634. label_CheckModeResult.BackColor = Color.Red;
  6635. label_CheckModeResult.Text = "标签格式错误";
  6636. button_CheckModeStart.Enabled = true;
  6637. return;
  6638. }
  6639. }
  6640. }
  6641. catch (System.Exception)
  6642. {
  6643. label_CheckModeStatus.Text = "存在故障!";
  6644. label_CheckModeResult.BackColor = Color.Red;
  6645. label_CheckModeResult.Text = "标签格式错误";
  6646. button_CheckModeStart.Enabled = true;
  6647. return;
  6648. }
  6649. //打开串口
  6650. mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false);
  6651. if (!mySerialProcess.mySerial.IsOpen)
  6652. {
  6653. MessageBox.Show("请检查串口连接!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6654. return;
  6655. }
  6656. //流水号计数
  6657. //...
  6658. //创建线程,执行测试任务
  6659. Thread th = new Thread(CheckModeTest_Task);
  6660. th.Start();
  6661. }
  6662. /// <summary>
  6663. /// 执行一次测试任务
  6664. /// </summary>
  6665. private void CheckModeTest_Task()
  6666. {
  6667. //开始测试
  6668. richTextBox_CheckModeLog.AppendText("产品标签:" + textBox_CheckModeScan.Text + "\r\n");
  6669. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  6670. //变量定义
  6671. var Code = new byte[255];//发送的指令数据
  6672. ushort DataTemp;
  6673. short DataTemp_Int16;
  6674. string ResultPathName = "";
  6675. label_CheckModeStatus.Text = "开始测试";
  6676. Delay_ms(500);
  6677. label_CheckModeStatus.Text = "系统开机";
  6678. //系统开机,确保测试前先关机,发送关机指令再发送开机指令
  6679. BootInfo = "";
  6680. Code[0] = 0xF0;
  6681. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6682. Delay_ms(1500);
  6683. Code[0] = 0xF1;
  6684. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6685. ACK_WaitCnt = 0;
  6686. while (ACK_WaitCnt <= 2) ; //1s
  6687. //检查BOOT版本
  6688. if (BootInfo != string.Empty)
  6689. {
  6690. label_CheckModeBoot.BackColor = Color.Green;
  6691. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  6692. Delay_ms(500);
  6693. }
  6694. else
  6695. {
  6696. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
  6697. label_CheckModeStatus.Text = "存在故障!";
  6698. label_CheckModeResult.BackColor = Color.Red;
  6699. label_CheckModeResult.Text = "测试异常";
  6700. Delay_ms(500);
  6701. //存储异常并上传
  6702. CheckMode_Stop(false);
  6703. return;
  6704. }
  6705. //发送指令读取版本信息
  6706. do
  6707. {
  6708. label_CheckModeStatus.Text = "读取版本信息";
  6709. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  6710. //发送指令读取版本
  6711. Class_Motor_Ver.Mode = "---";
  6712. Class_Motor_Ver.SN = "---";
  6713. Class_Motor_Ver.HW = "---";
  6714. Class_Motor_Ver.FW = "---";
  6715. Class_Motor_Ver.Special = "---";
  6716. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  6717. ACK_WaitCnt = 0;
  6718. while (ACK_WaitCnt <= 2) ; //1s
  6719. if (Class_Motor_Ver.Mode == "---")
  6720. {
  6721. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取失败" + "\r\n");
  6722. label_CheckModeStatus.Text = "存在故障!";
  6723. label_CheckModeResult.BackColor = Color.Red;
  6724. label_CheckModeResult.Text = "测试异常";
  6725. Delay_ms(500);
  6726. //存储异常并上传
  6727. CheckMode_Stop(false);
  6728. return;
  6729. }
  6730. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  6731. Delay_ms(500);
  6732. } while (false);
  6733. //软件版本检查
  6734. if (checkBox_CheckModeFWVer.Checked)
  6735. {
  6736. richTextBox_CheckModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  6737. richTextBox_CheckModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  6738. richTextBox_CheckModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  6739. richTextBox_CheckModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  6740. richTextBox_CheckModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  6741. //判断版本是否正确
  6742. string VerCheck = comboBox_CheckModeCfgFile.Text.Split('_')[3] + "_" + comboBox_CheckModeCfgFile.Text.Split('_')[4];
  6743. string VerRead = "";
  6744. try
  6745. {
  6746. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  6747. }
  6748. catch (System.Exception)
  6749. {
  6750. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  6751. label_CheckModeStatus.Text = "存在故障!";
  6752. label_CheckModeResult.BackColor = Color.Red;
  6753. label_CheckModeResult.Text = "测试异常";
  6754. Delay_ms(500);
  6755. //存储异常并上传
  6756. CheckMode_Stop(false);
  6757. return;
  6758. }
  6759. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  6760. {
  6761. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
  6762. label_CheckModeStatus.Text = "存在故障!";
  6763. label_CheckModeResult.BackColor = Color.Red;
  6764. label_CheckModeResult.Text = "测试异常";
  6765. Delay_ms(500);
  6766. //存储异常并上传
  6767. CheckMode_Stop(false);
  6768. return;
  6769. }
  6770. label_CheckModeFWVer.BackColor = Color.Green;
  6771. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  6772. Delay_ms(500);
  6773. }
  6774. else
  6775. {
  6776. label_CheckModeFWVer.BackColor = Color.Yellow;
  6777. label_CheckModeStatus.Text = "跳过软件版本查询";
  6778. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过软件版本查询" + "\r\n");
  6779. Delay_ms(500);
  6780. }
  6781. //打标信息核对
  6782. if (checkBox_CheckModeSN.Checked)
  6783. {
  6784. label_CheckModeStatus.Text = "核对打标信息";
  6785. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "核对打标信息" + "\r\n");
  6786. //根据扫码信息获取型号和SN
  6787. string ScanInfo = textBox_CheckModeScan.Text;
  6788. string regexInfo = "";
  6789. string[] InfoList = { "" };
  6790. try
  6791. {
  6792. if (中置电机ToolStripMenuItem.Checked == true)
  6793. {
  6794. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  6795. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  6796. }
  6797. else if (轮毂电机ToolStripMenuItem.Checked == true)
  6798. {
  6799. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  6800. string Model = InfoList[0];
  6801. string Spec = InfoList[1];
  6802. string Sn = InfoList[2];
  6803. InfoList[0] = Model.Replace("-", "").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  6804. InfoList[1] = Sn;
  6805. }
  6806. }
  6807. catch
  6808. {
  6809. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  6810. label_FacModeStatus.Text = "存在故障!";
  6811. label_FacModeResult.BackColor = Color.Red;
  6812. label_FacModeResult.Text = "标签格式错误";
  6813. Delay_ms(500);
  6814. //存储异常并上传
  6815. CheckMode_Stop(false);
  6816. return;
  6817. }
  6818. //核对型号
  6819. if (string.Equals(InfoList[0], Class_Motor_Ver.Mode) == false) //型号错误,直接结束
  6820. {
  6821. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号不一致" + "\r\n");
  6822. label_CheckModeStatus.Text = "存在故障!";
  6823. label_CheckModeResult.BackColor = Color.Red;
  6824. label_CheckModeResult.Text = "测试异常";
  6825. Delay_ms(500);
  6826. //存储异常并上传
  6827. CheckMode_Stop(false);
  6828. return;
  6829. }
  6830. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号一致" + "\r\n");
  6831. Delay_ms(500);
  6832. //核对SN
  6833. if (string.Equals(InfoList[1], Class_Motor_Ver.SN) == false) //型号错误,直接结束
  6834. {
  6835. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN不一致" + "\r\n");
  6836. label_CheckModeStatus.Text = "存在故障!";
  6837. label_CheckModeResult.BackColor = Color.Red;
  6838. label_CheckModeResult.Text = "测试异常";
  6839. Delay_ms(500);
  6840. //存储异常并上传
  6841. CheckMode_Stop(false);
  6842. return;
  6843. }
  6844. label_CheckModeSN.BackColor = Color.Green;
  6845. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN一致" + "\r\n");
  6846. Delay_ms(500);
  6847. }
  6848. else
  6849. {
  6850. label_CheckModeSN.BackColor = Color.Yellow;
  6851. label_CheckModeStatus.Text = "跳过打标信息确认";
  6852. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过打标信息确认" + "\r\n");
  6853. Delay_ms(500);
  6854. }
  6855. //参数检验
  6856. if (checkBox_CheckModeCfg.Checked)
  6857. {
  6858. //读取配置文件信息
  6859. label_CheckModeStatus.Text = "参数检查";
  6860. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  6861. //配置文件
  6862. List<byte[]> CmdList = new List<byte[]>();
  6863. Dictionary<string, string> ConfigCmd = new Dictionary<string, string>();//配置文件格式
  6864. //从服务器下载文件
  6865. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  6866. {
  6867. string SelectFile = "";
  6868. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "/" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  6869. if (File.Exists(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  6870. {
  6871. File.Delete(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  6872. }
  6873. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  6874. //打开文件
  6875. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  6876. ConfigCmd.Clear();
  6877. while (streamReader.Peek() != -1)
  6878. {
  6879. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  6880. if (fileLineInfo.Contains("["))
  6881. {
  6882. if (fileLineInfo.Contains("助力参数"))
  6883. {
  6884. fileLineInfo = streamReader.ReadLine();
  6885. }
  6886. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  6887. }
  6888. }
  6889. streamReader.Close();
  6890. }
  6891. //从本地加载文件
  6892. else
  6893. {
  6894. string SelectFile = "";
  6895. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  6896. //打开文件
  6897. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  6898. ConfigCmd.Clear();
  6899. while (streamReader.Peek() != -1)
  6900. {
  6901. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  6902. if (fileLineInfo.Contains("["))
  6903. {
  6904. if (fileLineInfo.Contains("助力参数"))
  6905. {
  6906. fileLineInfo = streamReader.ReadLine();
  6907. }
  6908. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  6909. }
  6910. }
  6911. streamReader.Close();
  6912. }
  6913. int CmdNum = ConfigCmd.Count(); //指令个数
  6914. Delay_ms(500);
  6915. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "\r\n");
  6916. Delay_ms(500);
  6917. //逐条读取比较
  6918. try
  6919. {
  6920. foreach (string key in ConfigCmd.Keys)
  6921. {
  6922. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令:" + "\r\n");
  6923. CmdRevStrTemp = "";
  6924. if (key.Contains("曲线"))
  6925. {
  6926. byte LineNum = 0;
  6927. var code = new byte[4];
  6928. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  6929. if (LineNum <= 5)
  6930. {
  6931. code[0] = (byte)(LineNum & 0xFF);
  6932. code[1] = (byte)((LineNum >> 8) & 0xFF);
  6933. code[2] = (byte)(LineNum & 0xFF);
  6934. code[3] = (byte)((LineNum >> 8) & 0xFF);
  6935. }
  6936. else
  6937. {
  6938. code[0] = (byte)(LineNum & 0xFF);
  6939. code[1] = (byte)((LineNum >> 8) & 0xFF);
  6940. code[2] = (byte)(5 & 0xFF);
  6941. code[3] = (byte)((5 >> 8) & 0xFF);
  6942. }
  6943. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  6944. }
  6945. else
  6946. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  6947. Delay_ms(500);
  6948. if (CmdRevStrTemp == string.Empty)
  6949. {
  6950. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "指令读取失败" + "\r\n");
  6951. label_CheckModeStatus.Text = "存在故障!";
  6952. label_CheckModeResult.BackColor = Color.Red;
  6953. label_CheckModeResult.Text = "测试异常";
  6954. Delay_ms(500);
  6955. //存储异常并上传
  6956. CheckMode_Stop(false);
  6957. return;
  6958. }
  6959. //比较当前指令,读取的配置文件和返回数据比较
  6960. string ParamWrite = ConfigCmd[key].Substring(24, ConfigCmd[key].Length - 40).Trim();
  6961. string ParamRead = "";
  6962. if (string.Compare(key, "[其它传感器参数]") == 0)
  6963. ParamRead = CmdRevStrTemp.Substring(90, CmdRevStrTemp.Length - 90).Trim(); //该指令包含力矩参数
  6964. else
  6965. ParamRead = CmdRevStrTemp.Substring(6, CmdRevStrTemp.Length - 6).Trim();
  6966. if (ParamWrite.Contains(ParamRead))
  6967. {
  6968. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "一致" + "\r\n");
  6969. continue;
  6970. }
  6971. else
  6972. {
  6973. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "不一致" + "\r\n");
  6974. label_CheckModeStatus.Text = "存在故障!";
  6975. label_CheckModeResult.BackColor = Color.Red;
  6976. label_CheckModeResult.Text = "测试异常";
  6977. Delay_ms(500);
  6978. //存储异常并上传
  6979. CheckMode_Stop(false);
  6980. return;
  6981. }
  6982. }
  6983. }
  6984. catch (System.Exception)
  6985. {
  6986. timer_1s.Enabled = false;
  6987. MessageBox.Show("参数检验失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6988. timer_1s.Enabled = true;
  6989. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  6990. }
  6991. }
  6992. else
  6993. {
  6994. label_CheckModeCfg.BackColor = Color.Yellow;
  6995. label_CheckModeStatus.Text = "跳过参数检验";
  6996. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数检验" + "\r\n");
  6997. Delay_ms(500);
  6998. }
  6999. label_CheckModeCfg.BackColor = Color.Green;
  7000. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数检验正确" + "\r\n");
  7001. Delay_ms(500);
  7002. //读取力矩传感器
  7003. do
  7004. {
  7005. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据" + "\r\n");
  7006. //发送指令读取力矩传感器标定数据
  7007. CmdRevStrTemp = "";
  7008. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  7009. ACK_WaitCnt = 0;
  7010. while (ACK_WaitCnt <= 2) ; //1s
  7011. if (CmdRevStrTemp == "---")
  7012. {
  7013. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取失败" + "\r\n");
  7014. label_CheckModeStatus.Text = "存在故障!";
  7015. label_CheckModeResult.BackColor = Color.Red;
  7016. label_CheckModeResult.Text = "测试异常";
  7017. Delay_ms(500);
  7018. //存储异常并上传
  7019. CheckMode_Stop(false);
  7020. return;
  7021. }
  7022. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取成功" + "\r\n");
  7023. //取力矩传感器数据
  7024. ushort ZeroInit, Zero1, Zero2, Zero3, ZeroNew;
  7025. ushort MaxTorque;
  7026. ushort K1_T, K1, K2_T, K2, K3_T, K3, K4_T, K4;
  7027. byte[] DataArray = mySerialProcess.HexStringToBytes(CmdRevStrTemp, true);
  7028. ZeroInit = (ushort)((DataArray[3] << 8) + DataArray[2]);
  7029. Zero1 = (ushort)((DataArray[5] << 8) + DataArray[4]);
  7030. Zero2 = (ushort)((DataArray[7] << 8) + DataArray[6]);
  7031. Zero3 = (ushort)((DataArray[9] << 8) + DataArray[8]);
  7032. ZeroNew = (ushort)((DataArray[11] << 8) + DataArray[10]);
  7033. MaxTorque = (ushort)((DataArray[13] << 8) + DataArray[12]);
  7034. K1_T = (ushort)((DataArray[15] << 8) + DataArray[14]);
  7035. K1 = (ushort)((DataArray[17] << 8) + DataArray[16]);
  7036. K2_T = (ushort)((DataArray[19] << 8) + DataArray[18]);
  7037. K2 = (ushort)((DataArray[21] << 8) + DataArray[20]);
  7038. K3_T = (ushort)((DataArray[23] << 8) + DataArray[22]);
  7039. K3 = (ushort)((DataArray[25] << 8) + DataArray[24]);
  7040. K4_T = (ushort)((DataArray[27] << 8) + DataArray[26]);
  7041. K4 = (ushort)((DataArray[29] << 8) + DataArray[28]);
  7042. richTextBox_CheckModeLog.AppendText("力矩传感器零点: " + ZeroInit.ToString() + "," + Zero1.ToString() + "," +
  7043. Zero2.ToString() + "," + Zero3.ToString() + "," + ZeroNew.ToString() + "\r\n");
  7044. richTextBox_CheckModeLog.AppendText("最大力矩: " + MaxTorque.ToString() + "\r\n");
  7045. richTextBox_CheckModeLog.AppendText("力矩传感器标定: " + "[" + K1_T.ToString() + "," + K1.ToString() + "]" + "," +
  7046. "[" + K2_T.ToString() + "," + K2.ToString() + "]" + "," + "[" + K3_T.ToString() + "," + K3.ToString() + "]" + "," +
  7047. "[" + K4_T.ToString() + "," + K4.ToString() + "]" + "\r\n");
  7048. //传感器标定检验
  7049. if (checkBox_CheckModeTorque.Checked)
  7050. {
  7051. richTextBox_CheckModeLog.AppendText("力矩零点范围: " + TorqueParamsForm.Zero.Min.ToString() + " - " + TorqueParamsForm.Zero.Max.ToString() + "\r\n");
  7052. richTextBox_CheckModeLog.AppendText("K1范围: " + TorqueParamsForm.K1.T.ToString() + "," + TorqueParamsForm.K1.Min.ToString() + " - " + TorqueParamsForm.K1.Max.ToString() + "\r\n");
  7053. richTextBox_CheckModeLog.AppendText("K2范围: " + TorqueParamsForm.K2.T.ToString() + "," + TorqueParamsForm.K2.Min.ToString() + " - " + TorqueParamsForm.K2.Max.ToString() + "\r\n");
  7054. richTextBox_CheckModeLog.AppendText("K3范围: " + TorqueParamsForm.K3.T.ToString() + "," + TorqueParamsForm.K3.Min.ToString() + " - " + TorqueParamsForm.K3.Max.ToString() + "\r\n");
  7055. richTextBox_CheckModeLog.AppendText("K4范围: " + TorqueParamsForm.K4.T.ToString() + "," + TorqueParamsForm.K4.Min.ToString() + " - " + TorqueParamsForm.K4.Max.ToString() + "\r\n");
  7056. //与设置值比较
  7057. if ((ZeroInit <= TorqueParamsForm.Zero.Max) && (ZeroInit >= TorqueParamsForm.Zero.Min)
  7058. && (K1_T == TorqueParamsForm.K1.T) && (K1 <= TorqueParamsForm.K1.Max) && (K1 >= TorqueParamsForm.K1.Min)
  7059. && (K2_T == TorqueParamsForm.K2.T) && (K2 <= TorqueParamsForm.K2.Max) && (K2 >= TorqueParamsForm.K2.Min)
  7060. && (K3_T == TorqueParamsForm.K3.T) && (K3 <= TorqueParamsForm.K3.Max) && (K3 >= TorqueParamsForm.K3.Min)
  7061. && (K4_T == TorqueParamsForm.K4.T) && (K4 <= TorqueParamsForm.K4.Max) && (K4 >= TorqueParamsForm.K4.Min)
  7062. )
  7063. {
  7064. label_CheckModeTorque.BackColor = Color.Green;
  7065. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定正常" + "\r\n");
  7066. Delay_ms(500);
  7067. }
  7068. else
  7069. {
  7070. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定超范围" + "\r\n");
  7071. label_CheckModeStatus.Text = "存在故障!";
  7072. label_CheckModeResult.BackColor = Color.Red;
  7073. label_CheckModeResult.Text = "测试异常";
  7074. Delay_ms(500);
  7075. //存储异常并上传
  7076. CheckMode_Stop(false);
  7077. return;
  7078. }
  7079. }
  7080. else
  7081. {
  7082. label_CheckModeFWVer.BackColor = Color.Yellow;
  7083. label_CheckModeStatus.Text = "跳过传感器标定检验";
  7084. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过传感器标定检验" + "\r\n");
  7085. Delay_ms(500);
  7086. }
  7087. } while (false);
  7088. //测试合格
  7089. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  7090. label_CheckModeStatus.Text = "测试结束!";
  7091. label_CheckModeResult.BackColor = Color.Green;
  7092. label_CheckModeResult.Text = "测试合格";
  7093. Delay_ms(500);
  7094. //存储并上传
  7095. CheckMode_Stop(true);
  7096. return;
  7097. }
  7098. private void CheckModeLabelInit()
  7099. {
  7100. //测试状态标签
  7101. label_CheckModeResult.BackColor = Color.Yellow;
  7102. label_CheckModeResult.Text = "测试中";
  7103. //测试过程标签
  7104. label_CheckModeStatus.Text = "测试就绪";
  7105. //测试结果标签
  7106. foreach (Control c in groupBox31.Controls)
  7107. {
  7108. if (c is Label)
  7109. {
  7110. if (c.Text == string.Empty)
  7111. c.BackColor = Color.Red;
  7112. }
  7113. }
  7114. }
  7115. private void 调试记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  7116. {
  7117. System.Diagnostics.Process.Start("explorer.exe", Directory.GetCurrentDirectory());
  7118. }
  7119. private void 生产记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  7120. {
  7121. System.Diagnostics.Process.Start("explorer.exe", localInfo.LocalDataPath);
  7122. }
  7123. private void 累计运行时间ToolStripMenuItem_MouseHover(object sender, EventArgs e)
  7124. {
  7125. UInt32 Time = (UInt32)stopwatch.ElapsedMilliseconds / 1000;
  7126. UInt32 hour = Time / 3600;
  7127. UInt32 min = (Time % 3600) / 60;
  7128. UInt32 s = (Time % 60);
  7129. toolStripMenuItem_RunTime.Text = hour.ToString() + ":" + min.ToString("00") + ":" + s.ToString("00");
  7130. }
  7131. private void richTextBox_CheckModeLog_TextChanged(object sender, EventArgs e)
  7132. {
  7133. richTextBox_CheckModeLog.SelectionStart = richTextBox_CheckModeLog.Text.Length;
  7134. richTextBox_CheckModeLog.ScrollToCaret();
  7135. }
  7136. private void 力矩传感器检验ToolStripMenuItem_Click(object sender, EventArgs e)
  7137. {
  7138. EnterForm1.ShowDialog();
  7139. try
  7140. {
  7141. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  7142. {
  7143. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  7144. {
  7145. TorqueParamsForm.ShowDialog();
  7146. }
  7147. else
  7148. {
  7149. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7150. }
  7151. }
  7152. else
  7153. {
  7154. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7155. }
  7156. }
  7157. catch (Exception)
  7158. {
  7159. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7160. }
  7161. }
  7162. private void textBox_CheckModeScan_KeyUp(object sender, KeyEventArgs e)
  7163. {
  7164. if (e.KeyCode == Keys.Enter)
  7165. CheckTestStart();
  7166. }
  7167. private void textBox_FacModeScan_KeyUp(object sender, KeyEventArgs e)
  7168. {
  7169. if (e.KeyCode == Keys.Enter)
  7170. TestStart();
  7171. }
  7172. private void button_SpeedDec10_Click(object sender, EventArgs e)
  7173. {
  7174. if (numericUpDown_SpeedAdj.Value <= 10)
  7175. numericUpDown_SpeedAdj.Value = 0;
  7176. else
  7177. numericUpDown_SpeedAdj.Value -= 10;
  7178. }
  7179. private void button_SpeedAdd10_Click(object sender, EventArgs e)
  7180. {
  7181. if (numericUpDown_SpeedAdj.Value >= 90)
  7182. numericUpDown_SpeedAdj.Value = 100;
  7183. else
  7184. numericUpDown_SpeedAdj.Value += 10;
  7185. }
  7186. private void button_SpeedDec1_Click(object sender, EventArgs e)
  7187. {
  7188. if (numericUpDown_SpeedAdj.Value <= 1)
  7189. numericUpDown_SpeedAdj.Value = 0;
  7190. else
  7191. numericUpDown_SpeedAdj.Value -= 1;
  7192. }
  7193. private void button_SpeedAdd1_Click(object sender, EventArgs e)
  7194. {
  7195. if(numericUpDown_SpeedAdj.Value >= 99)
  7196. numericUpDown_SpeedAdj.Value = 100;
  7197. else
  7198. numericUpDown_SpeedAdj.Value += 1;
  7199. }
  7200. bool WriteLockStatus = true;
  7201. private void pictureBox_WriteLock_Click(object sender, EventArgs e)
  7202. {
  7203. if (WriteLockStatus == true)
  7204. {
  7205. EnterForm1.ShowDialog();
  7206. try
  7207. {
  7208. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  7209. {
  7210. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  7211. {
  7212. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  7213. foreach (Control c in groupBox2.Controls)
  7214. {
  7215. if (c is CheckBox)
  7216. c.Enabled = true;
  7217. }
  7218. WriteLockStatus = !WriteLockStatus;
  7219. }
  7220. else
  7221. {
  7222. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7223. }
  7224. }
  7225. else
  7226. {
  7227. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7228. }
  7229. }
  7230. catch (Exception)
  7231. {
  7232. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7233. }
  7234. }
  7235. else
  7236. {
  7237. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  7238. foreach (Control c in groupBox2.Controls)
  7239. {
  7240. if (c is CheckBox)
  7241. c.Enabled = false;
  7242. }
  7243. WriteLockStatus = !WriteLockStatus;
  7244. }
  7245. }
  7246. bool ReadLockStatus = true;
  7247. private void pictureBox_ReadLock_Click(object sender, EventArgs e)
  7248. {
  7249. if (ReadLockStatus == true)
  7250. {
  7251. EnterForm1.ShowDialog();
  7252. try
  7253. {
  7254. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  7255. {
  7256. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  7257. {
  7258. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  7259. foreach (Control c in groupBox29.Controls)
  7260. {
  7261. if (c is CheckBox)
  7262. c.Enabled = true;
  7263. }
  7264. ReadLockStatus = !ReadLockStatus;
  7265. }
  7266. else
  7267. {
  7268. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7269. }
  7270. }
  7271. else
  7272. {
  7273. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7274. }
  7275. }
  7276. catch (Exception)
  7277. {
  7278. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7279. }
  7280. }
  7281. else
  7282. {
  7283. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  7284. foreach (Control c in groupBox29.Controls)
  7285. {
  7286. if (c is CheckBox)
  7287. c.Enabled = false;
  7288. }
  7289. ReadLockStatus = !ReadLockStatus;
  7290. }
  7291. }
  7292. private void 屏幕键盘ToolStripMenuItem_Click(object sender, EventArgs e)
  7293. {
  7294. System.Diagnostics.Process.Start("osk.exe");
  7295. }
  7296. private void checkBox_OffLineCheckMode_CheckedChanged(object sender, EventArgs e)
  7297. {
  7298. comboBox_CheckModeCfgDate.SelectedIndex = -1;
  7299. comboBox_CheckModeCfgFile.SelectedIndex = -1;
  7300. checkBox_OffLineFacMode.Checked = checkBox_OffLineCheckMode.Checked;
  7301. }
  7302. private void checkBox_OffLineFacMode_CheckedChanged(object sender, EventArgs e)
  7303. {
  7304. comboBox_FacModeCfgDate.SelectedIndex = -1;
  7305. comboBox_FacModeCfgFile.SelectedIndex = -1;
  7306. checkBox_OffLineCheckMode.Checked = checkBox_OffLineFacMode.Checked;
  7307. }
  7308. private void 版本ToolStripMenuItem_Click(object sender, EventArgs e)
  7309. {
  7310. VersionForm.ShowDialog();
  7311. }
  7312. private void button_MOS_Cal_Click(object sender, EventArgs e)
  7313. {
  7314. textBox_MOS_R1.Text = "";
  7315. textBox_MOS_R2.Text = "";
  7316. textBox_MOS_R3.Text = "";
  7317. try
  7318. {
  7319. var Code = new byte[18];
  7320. for (int i = 0; i < 18; i++)
  7321. Code[i] = 0;
  7322. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  7323. ushort uwDataTemp = 0;
  7324. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  7325. Code[2] = (byte)(uwDataTemp & 0xFF);
  7326. Code[3] = (byte)(uwDataTemp >> 8);
  7327. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  7328. Code[4] = (byte)(uwDataTemp & 0xFF);
  7329. Code[5] = (byte)(uwDataTemp >> 8);
  7330. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  7331. Code[6] = (byte)(uwDataTemp & 0xFF);
  7332. Code[7] = (byte)(uwDataTemp >> 8);
  7333. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  7334. Code[8] = (byte)(uwDataTemp & 0xFF);
  7335. Code[9] = (byte)(uwDataTemp >> 8);
  7336. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  7337. Code[10] = (byte)(uwDataTemp & 0xFF);
  7338. Code[11] = (byte)(uwDataTemp >> 8);
  7339. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  7340. }
  7341. catch (Exception)
  7342. {
  7343. MessageBox.Show("系数填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7344. }
  7345. }
  7346. private void button_MOS_Read_Click(object sender, EventArgs e)
  7347. {
  7348. foreach (Control c in groupBox21.Controls)
  7349. {
  7350. if (c is TextBox)
  7351. c.Text = "";
  7352. }
  7353. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  7354. }
  7355. private void button_MOS_Write_Click(object sender, EventArgs e)
  7356. {
  7357. try
  7358. {
  7359. var Code = new byte[34];
  7360. for (int i = 0; i < 34; i++)
  7361. Code[i] = 0;
  7362. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  7363. ushort uwDataTemp = 0;
  7364. uwDataTemp = Convert.ToUInt16(textBox_MOS_R1.Text);
  7365. Code[2] = (byte)(uwDataTemp & 0xFF);
  7366. Code[3] = (byte)(uwDataTemp >> 8);
  7367. uwDataTemp = Convert.ToUInt16(textBox_MOS_R2.Text);
  7368. Code[4] = (byte)(uwDataTemp & 0xFF);
  7369. Code[5] = (byte)(uwDataTemp >> 8);
  7370. uwDataTemp = Convert.ToUInt16(textBox_MOS_R3.Text);
  7371. Code[6] = (byte)(uwDataTemp & 0xFF);
  7372. Code[7] = (byte)(uwDataTemp >> 8);
  7373. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  7374. Code[8] = (byte)(uwDataTemp & 0xFF);
  7375. Code[9] = (byte)(uwDataTemp >> 8);
  7376. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  7377. Code[10] = (byte)(uwDataTemp & 0xFF);
  7378. Code[11] = (byte)(uwDataTemp >> 8);
  7379. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  7380. Code[12] = (byte)(uwDataTemp & 0xFF);
  7381. Code[13] = (byte)(uwDataTemp >> 8);
  7382. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  7383. Code[14] = (byte)(uwDataTemp & 0xFF);
  7384. Code[15] = (byte)(uwDataTemp >> 8);
  7385. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  7386. Code[16] = (byte)(uwDataTemp & 0xFF);
  7387. Code[17] = (byte)(uwDataTemp >> 8);
  7388. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4C22, Code);
  7389. }
  7390. catch (Exception)
  7391. {
  7392. MessageBox.Show("数据填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7393. }
  7394. }
  7395. /// <summary>
  7396. /// 测试模式点击文本框自动全选
  7397. /// </summary>
  7398. /// <param name="sender"></param>
  7399. /// <param name="e"></param>
  7400. private void textBox_FacModeScan_MouseClick(object sender, MouseEventArgs e)
  7401. {
  7402. textBox_FacModeScan.SelectAll();
  7403. }
  7404. /// <summary>
  7405. /// 检验模式点击文本框自动全选
  7406. /// </summary>
  7407. /// <param name="sender"></param>
  7408. /// <param name="e"></param>
  7409. private void textBox_CheckModeScan_MouseClick(object sender, MouseEventArgs e)
  7410. {
  7411. textBox_CheckModeScan.SelectAll();
  7412. }
  7413. /// <summary>
  7414. /// 鼠标放置显示连接服务器信息
  7415. /// </summary>
  7416. /// <param name="sender"></param>
  7417. /// <param name="e"></param>
  7418. private void label_ServerStatus_MouseHover(object sender, EventArgs e)
  7419. {
  7420. // 创建the ToolTip
  7421. ToolTip toolTip1 = new ToolTip();
  7422. // 设置显示样式
  7423. toolTip1.AutoPopDelay = 30000;//提示信息的可见时间
  7424. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  7425. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  7426. toolTip1.ShowAlways = true;//是否显示提示框
  7427. if (myFtp.IsNetConnected)
  7428. {
  7429. toolTip1.SetToolTip(this.label_ServerStatus, "IP: " + toolStripTextBox_ServerIP.Text);//设置故障内容显示
  7430. }
  7431. else
  7432. {
  7433. toolTip1.SetToolTip(this.label_ServerStatus, "网络断开");//设置故障内容显示
  7434. }
  7435. }
  7436. /// <summary>
  7437. /// UART协议类型修改
  7438. /// </summary>
  7439. /// <param name="sender"></param>
  7440. /// <param name="e"></param>
  7441. private void 协议类型ToolStripMenuItem_SelectedIndexChanged(object sender, EventArgs e)
  7442. {
  7443. var Code = new byte[2];
  7444. Code[0] = (byte)协议类型ToolStripMenuItem.SelectedIndex;
  7445. Code[1] = 0x00;
  7446. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  7447. }
  7448. /// <summary>
  7449. /// 显示本机信息
  7450. /// </summary>
  7451. /// <param name="sender"></param>
  7452. /// <param name="e"></param>
  7453. private void 本机信息ToolStripMenuItem_Click(object sender, EventArgs e)
  7454. {
  7455. MessageBox.Show(Local_HdInformation, "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
  7456. }
  7457. }
  7458. }