mainForm.cs 337 KB

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