mainForm.cs 342 KB

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