mainForm.cs 413 KB

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