mainForm.cs 340 KB

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