mainForm.cs 442 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Diagnostics.Eventing.Reader;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.IO.Ports;
  9. using System.Linq;
  10. using System.Reflection;
  11. using System.Runtime.InteropServices;
  12. using System.Runtime.InteropServices.ComTypes;
  13. using System.Text;
  14. using System.Text.RegularExpressions;
  15. using System.Threading;
  16. using System.Web;
  17. using System.Windows.Forms;
  18. using System.Xml.Linq;
  19. namespace Welling_Motor_Debug_Tool
  20. {
  21. public partial class mainForm : Form
  22. {
  23. #region 变量定义
  24. //版本号
  25. public static string Version = "2.2.1";
  26. //串口实例
  27. Serial_Process mySerialProcess = new Serial_Process();
  28. string PortNumSave = "";
  29. string PortBaudrateSave = "";
  30. //本地信息定义
  31. LocalInfo localInfo = new LocalInfo();
  32. //FTP实例
  33. ftp myFtp = new ftp();
  34. //MC运行信息超时计数
  35. bool MC_RunInfo_Refresh = false;
  36. ushort MC_RunInfo_Refresh_Cnt = 0;
  37. //MC调试信息超时计数
  38. bool MC_DebugInfo_Refresh = false;
  39. ushort MC_DebugInfo_Refresh_Cnt = 0;
  40. //MC故障码超时计数
  41. bool MC_ErrorCode_Refresh = false;
  42. ushort MC_ErrorCode_Refresh_Cnt = 0;
  43. //配置参数实例
  44. Params myParams = new Params();
  45. //记录文件名称
  46. string RunInfoSaveFilename = "";
  47. //BMS运行信息超时计数
  48. bool BMS_RunInfo_Refresh = false;
  49. ushort BMS_RunInfo_Refresh_Cnt = 0;
  50. //生产模式关机指令反馈状态
  51. bool PowerOffAckStatus = false;
  52. //登录窗口
  53. public static Login EnterForm1 = new Login();
  54. //生产配置文件信息
  55. ArrayList array_CfgInfo = new ArrayList();
  56. //写入参数返回标志和计数
  57. public bool WriteACK = false;
  58. public ushort WriteCnt = 0;
  59. public ushort ACK_WaitCnt = 0;
  60. //写入参数返回提示标志
  61. public bool ACK_DisFlag = true;
  62. //Boot版本信息
  63. public string BootInfo = "";
  64. //接收指令临时缓存,转string
  65. public string CmdRevStrTemp = "";
  66. //计时器,用于统计运行时间
  67. public Stopwatch stopwatch = new Stopwatch();
  68. //力矩传感器检验参数窗口
  69. public static TorqueParams TorqueParamsForm = new TorqueParams();
  70. //参数生成窗口
  71. public static GenerateParams GenerateParamsForm = new GenerateParams();
  72. //版本信息窗口
  73. public static Version VersionForm = new Version();
  74. //本机硬件信息
  75. public string Local_HdInformation = "";
  76. #endregion
  77. #region 故障日志结构体定义
  78. //故障日志记录信息 60 bytes,1K空间可以保存最近16条故障记录
  79. [StructLayout(LayoutKind.Sequential)]
  80. public struct MC_ErrorLogSaveInfo_Struct_t
  81. {
  82. public UInt16 Error_Index; //故障列表索引 2 bytes, 地址偏移 0
  83. public UInt16 NotesInfo1; //备注信息1,地址偏移 2
  84. public UInt16 NotesInfo2; //备注信息2,地址偏移 4
  85. public UInt16 NotesInfo3; //备注信息3,地址偏移 6
  86. public UInt32 ErrorCode; //故障码 4 bytes, 地址偏移 8
  87. public UInt32 RunTime; //运行时间 4bytes, 地址偏移 12
  88. //电机运行信息,占用空间32bytes
  89. [StructLayout(LayoutKind.Sequential)]
  90. public struct MC_RunInfo_Struct_t
  91. {
  92. public ushort BikeSpeed; //车速 0.1km/h,地址偏移0
  93. public ushort MotorSpeed; //输出转速 1rpm,地址偏移2
  94. public ushort Power; //电功率 1W,地址偏移4
  95. public ushort BusVoltage; //母线电压 1mV,地址偏移6
  96. public ushort BusCurrent; //母线电流 1mA,地址偏移8
  97. public byte Cadence; //踏频 1rpm,地址偏移10
  98. public byte Torque; //踩踏力矩 1Nm,地址偏移11
  99. public byte CadenceDir; //踩踏方向 0-正,1-反,2-停止,地址偏移12
  100. public byte GearSt; //助力档位,地址偏移13
  101. public byte LightSwitch; //灯开关 0xF0-关,0xF1-开,地址偏移14
  102. public byte SOC; //剩余电量 1%,地址偏移15
  103. public ushort RemainDistance; //续航里程 1km,地址偏移16
  104. public ushort Torque_AD; //力矩寄存器,地址偏移18
  105. public byte PowerPerKm; //平均功耗 0.01Ah/km ,地址偏移20
  106. public byte T_PCB; //PCB温度 +40℃,地址偏移21
  107. public byte T_Coil; //绕组温度 +40℃,地址偏移22
  108. public byte T_MCU; //MCU温度 +40℃,地址偏移23
  109. public ushort Ride_Km; //开机后骑行里程 0.1km, 地址偏移24
  110. public ushort Ride_Time; //开机后骑行时间 1s,地址偏移26
  111. public UInt32 RS; //预留 4bytes
  112. };
  113. [MarshalAs(UnmanagedType.Struct)]
  114. public MC_RunInfo_Struct_t RunInfo; //运行信息 32bytes, 地址偏移 16
  115. //控制变量
  116. public Int16 IqCurrent; //Pu, 地址偏移 48
  117. public Int16 IqVoltage; //Pu, 地址偏移 50
  118. public Int16 IdCurrent; //Pu, 地址偏移 52
  119. public Int16 IdVoltage; //Pu, 地址偏移 54
  120. //状态机
  121. public UInt16 FSM; //高到低依次表示系统状态机、二层状态机、电机状态机、助力状态机, 地址偏移 56
  122. //预留
  123. public UInt16 RS1;
  124. public UInt16 RS2;
  125. public UInt16 RS3;
  126. };
  127. #endregion
  128. #region 屏幕缩放比例获取
  129. public class PrimaryScreen
  130. {
  131. #region Win32 API
  132. [DllImport("user32.dll")]
  133. static extern IntPtr GetDC(IntPtr ptr);
  134. [DllImport("gdi32.dll")]
  135. static extern int GetDeviceCaps(
  136. IntPtr hdc, // handle to DC
  137. int nIndex // index of capability
  138. );
  139. [DllImport("user32.dll", EntryPoint = "ReleaseDC")]
  140. static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDc);
  141. #endregion
  142. #region DeviceCaps常量
  143. const int HORZRES = 8;
  144. const int VERTRES = 10;
  145. const int LOGPIXELSX = 88;
  146. const int LOGPIXELSY = 90;
  147. const int DESKTOPVERTRES = 117;
  148. const int DESKTOPHORZRES = 118;
  149. #endregion
  150. #region 属性
  151. /// <summary>
  152. /// 获取屏幕分辨率当前物理大小
  153. /// </summary>
  154. public static Size WorkingArea
  155. {
  156. get
  157. {
  158. IntPtr hdc = GetDC(IntPtr.Zero);
  159. Size size = new Size();
  160. size.Width = GetDeviceCaps(hdc, HORZRES);
  161. size.Height = GetDeviceCaps(hdc, VERTRES);
  162. ReleaseDC(IntPtr.Zero, hdc);
  163. return size;
  164. }
  165. }
  166. /// <summary>
  167. /// 当前系统DPI_X 大小 一般为96
  168. /// </summary>
  169. public static int DpiX
  170. {
  171. get
  172. {
  173. IntPtr hdc = GetDC(IntPtr.Zero);
  174. int DpiX = GetDeviceCaps(hdc, LOGPIXELSX);
  175. ReleaseDC(IntPtr.Zero, hdc);
  176. return DpiX;
  177. }
  178. }
  179. /// <summary>
  180. /// 当前系统DPI_Y 大小 一般为96
  181. /// </summary>
  182. public static int DpiY
  183. {
  184. get
  185. {
  186. IntPtr hdc = GetDC(IntPtr.Zero);
  187. int DpiX = GetDeviceCaps(hdc, LOGPIXELSY);
  188. ReleaseDC(IntPtr.Zero, hdc);
  189. return DpiX;
  190. }
  191. }
  192. /// <summary>
  193. /// 获取真实设置的桌面分辨率大小
  194. /// </summary>
  195. public static Size DESKTOP
  196. {
  197. get
  198. {
  199. IntPtr hdc = GetDC(IntPtr.Zero);
  200. Size size = new Size();
  201. size.Width = GetDeviceCaps(hdc, DESKTOPHORZRES);
  202. size.Height = GetDeviceCaps(hdc, DESKTOPVERTRES);
  203. ReleaseDC(IntPtr.Zero, hdc);
  204. return size;
  205. }
  206. }
  207. /// <summary>
  208. /// 获取宽度缩放百分比
  209. /// </summary>
  210. public static float ScaleX
  211. {
  212. get
  213. {
  214. IntPtr hdc = GetDC(IntPtr.Zero);
  215. int t = GetDeviceCaps(hdc, DESKTOPHORZRES);
  216. int d = GetDeviceCaps(hdc, HORZRES);
  217. float ScaleX = (float)GetDeviceCaps(hdc, DESKTOPHORZRES) / (float)GetDeviceCaps(hdc, HORZRES);
  218. ReleaseDC(IntPtr.Zero, hdc);
  219. return ScaleX;
  220. }
  221. }
  222. /// <summary>
  223. /// 获取高度缩放百分比
  224. /// </summary>
  225. public static float ScaleY
  226. {
  227. get
  228. {
  229. IntPtr hdc = GetDC(IntPtr.Zero);
  230. float ScaleY = (float)(float)GetDeviceCaps(hdc, DESKTOPVERTRES) / (float)GetDeviceCaps(hdc, VERTRES);
  231. ReleaseDC(IntPtr.Zero, hdc);
  232. return ScaleY;
  233. }
  234. }
  235. #endregion
  236. }
  237. #endregion
  238. public mainForm()
  239. {
  240. InitializeComponent();
  241. System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
  242. stopwatch.Start();
  243. //端口初始化
  244. mySerialProcess.Init();
  245. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  246. //检查备忘录文件
  247. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.NoteFileName))
  248. {
  249. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.NoteFileName, "");
  250. }
  251. //检验流水号记录文件
  252. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.SerialNumFileName1))
  253. {
  254. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, "0");
  255. }
  256. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.SerialNumFileName2))
  257. {
  258. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, "0");
  259. }
  260. //检查文件夹
  261. if (!Directory.Exists(localInfo.LocalPath))
  262. {
  263. Directory.CreateDirectory(localInfo.LocalPath);
  264. }
  265. if (!Directory.Exists(localInfo.LocalDataPath))
  266. {
  267. Directory.CreateDirectory(localInfo.LocalDataPath);
  268. }
  269. if (!Directory.Exists(localInfo.ToolsPath))
  270. {
  271. Directory.CreateDirectory(localInfo.ToolsPath);
  272. }
  273. if (!Directory.Exists(localInfo.LocalPath + localInfo.CfgPathName))
  274. {
  275. Directory.CreateDirectory(localInfo.LocalPath + localInfo.CfgPathName);
  276. }
  277. //检查配置文件
  278. if (File.Exists(localInfo.LocalPath + localInfo.ConfigFileName)) //存在配置文件,导入配置信息
  279. {
  280. //打开文件
  281. StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.ConfigFileName);
  282. string sLine = "";
  283. ArrayList array_CfgInfo = new ArrayList();
  284. array_CfgInfo.Clear();
  285. while (sLine != null)
  286. {
  287. sLine = objReader.ReadLine();
  288. array_CfgInfo.Add(sLine);
  289. }
  290. objReader.Close();
  291. //解析配置文件
  292. try
  293. {
  294. //Port Set
  295. PortNumSave = array_CfgInfo[1].ToString().Split(':')[1];
  296. PortBaudrateSave = array_CfgInfo[2].ToString().Split(':')[1];
  297. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.IndexOf(PortNumSave);
  298. toolStripComboBox_Baudrate.SelectedIndex = toolStripComboBox_Baudrate.Items.IndexOf(PortBaudrateSave);
  299. 连接开机ToolStripMenuItem.Checked = (array_CfgInfo[3].ToString().Split(':')[1] == "True");
  300. 断开关机ToolStripMenuItem.Checked = (array_CfgInfo[4].ToString().Split(':')[1] == "True");
  301. 识别通讯盒ToolStripMenuItem.Checked = (array_CfgInfo[5].ToString().Split(':')[1] == "True");
  302. //Option
  303. 写入存储ToolStripMenuItem.Checked = (array_CfgInfo[8].ToString().Split(':')[1] == "True");
  304. 允许ToolStripMenuItem.Checked = (array_CfgInfo[9].ToString().Split(':')[1] == "True");
  305. 不允许ToolStripMenuItem.Checked = (array_CfgInfo[9].ToString().Split(':')[1] == "False");
  306. if (array_CfgInfo[9].ToString().Split(':')[1] == "False")
  307. {
  308. checkBox_OffLineFacMode.Checked = false;
  309. checkBox_OffLineFacMode.Enabled = false;
  310. checkBox_OffLineCheckMode.Checked = false;
  311. checkBox_OffLineCheckMode.Enabled = false;
  312. }
  313. else
  314. {
  315. checkBox_OffLineFacMode.Checked = true;
  316. checkBox_OffLineFacMode.Enabled = true;
  317. checkBox_OffLineCheckMode.Checked = true;
  318. checkBox_OffLineCheckMode.Enabled = true;
  319. }
  320. //Server Set
  321. toolStripTextBox_ServerIP.Text = array_CfgInfo[12].ToString().Split(':')[1];
  322. toolStripTextBox_ServerPort.Text = array_CfgInfo[13].ToString().Split(':')[1];
  323. toolStripTextBox_ServerUser.Text = array_CfgInfo[14].ToString().Split(':')[1];
  324. toolStripTextBox_ServerPasswd.Text = array_CfgInfo[15].ToString().Split(':')[1];
  325. toolStripTextBox_ServerPath.Text = array_CfgInfo[16].ToString().Split(':')[1];
  326. //MacInfo
  327. toolStripTextBox_MAC.Text = array_CfgInfo[19].ToString().Split(':')[1];
  328. toolStripTextBoxMACAddr.Text = array_CfgInfo[20].ToString().Split(':')[1];
  329. toolStripTextBox_MACDate.Text = DateTime.Now.ToString("yyyyMMdd");
  330. toolStripTextBox_MACPD.Text = array_CfgInfo[22].ToString().Split(':')[1];
  331. //Log Address
  332. textBox_LogAddrBegin.Text = array_CfgInfo[25].ToString().Split(':')[1];
  333. textBox_LogAddrEnd.Text = array_CfgInfo[26].ToString().Split(':')[1];
  334. //电机类型
  335. 中置电机ToolStripMenuItem.Checked = (array_CfgInfo[29].ToString().Split(':')[1] == "True");
  336. 轮毂电机ToolStripMenuItem.Checked = !中置电机ToolStripMenuItem.Checked;
  337. //检测阈值
  338. toolStripTextBox_ThVol.Text = array_CfgInfo[33].ToString().Split(':')[1];
  339. toolStripTextBox_ThCur.Text = array_CfgInfo[34].ToString().Split(':')[1];
  340. toolStripTextBox_ThSpeed.Text = array_CfgInfo[35].ToString().Split(':')[1];
  341. toolStripTextBox_ThTor.Text = array_CfgInfo[36].ToString().Split(':')[1];
  342. toolStripTextBox_ThCad.Text = array_CfgInfo[37].ToString().Split(':')[1];
  343. toolStripTextBox_ThBikeSpeed.Text = array_CfgInfo[38].ToString().Split(':')[1];
  344. toolStripTextBox_ThT_PCB.Text = array_CfgInfo[39].ToString().Split(':')[1];
  345. toolStripTextBox_ThT_MCU.Text = array_CfgInfo[40].ToString().Split(':')[1];
  346. toolStripTextBox_ThT_Motor.Text = array_CfgInfo[41].ToString().Split(':')[1];
  347. //MOS内阻校准系数
  348. toolStripTextBox_MosCalK.Text = array_CfgInfo[44].ToString().Split(':')[1];
  349. toolStripTextBox_MOS1.Text= array_CfgInfo[45].ToString().Split(':')[1];
  350. toolStripTextBox_MOS2.Text = array_CfgInfo[46].ToString().Split(':')[1];
  351. toolStripTextBox_MOS3.Text = array_CfgInfo[47].ToString().Split(':')[1];
  352. //通信协议类型
  353. cANToolStripMenuItem.Checked = (array_CfgInfo[50].ToString().Split(':')[1] == "True");
  354. uARTToolStripMenuItem.Checked = !cANToolStripMenuItem.Checked;
  355. //自动更新开关
  356. 打开ToolStripMenuItem.Checked = (array_CfgInfo[54].ToString().Split(':')[1] == "True");
  357. 关闭ToolStripMenuItem.Checked = !打开ToolStripMenuItem.Checked;
  358. }
  359. catch (System.Exception)
  360. {
  361. timer_1s.Enabled = false;
  362. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  363. timer_1s.Enabled = true;
  364. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  365. }
  366. }
  367. else //不存在配置文件,生成文件写入默认值
  368. {
  369. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  370. }
  371. //解析本地流水号记录
  372. do
  373. {
  374. //测试模式
  375. label_FacModeSerial.Text = File.ReadAllText(localInfo.LocalPath + localInfo.SerialNumFileName1);
  376. //检验模式
  377. label_CheckModeSerial.Text = File.ReadAllText(localInfo.LocalPath + localInfo.SerialNumFileName2);
  378. } while (false);
  379. //获取本机信息,读取时间较长,优先从本地文件获取
  380. do
  381. {
  382. try
  383. {
  384. //本地文件为空,读取信息保存
  385. if (!File.Exists(localInfo.LocalPath + localInfo.PC_InfoFileName))
  386. {
  387. Local_HdInformation = "";
  388. Local_HdInformation += "计算机名称: " + System.Environment.UserName + "\r\n";
  389. Local_HdInformation += "IP地址: " + PC_Information.GetIpAddress() + "\r\n";
  390. Local_HdInformation += "系统ID: " + PC_Information.GetSystemID() + "\r\n";
  391. Local_HdInformation += "操作系统类型: " + PC_Information.GetSystemType() + "\r\n";
  392. Local_HdInformation += "主板型号: " + PC_Information.GetBoardType() + "\r\n";
  393. Local_HdInformation += "主板厂商: " + PC_Information.GetBoardManufacturer() + "\r\n";
  394. Local_HdInformation += "主板ID: " + PC_Information.GetBIOSSerialNumber() + "\r\n";
  395. Local_HdInformation += "CPU型号: " + PC_Information.GetCpuName() + "\r\n";
  396. Local_HdInformation += "CPU厂商: " + PC_Information.GetCpuManufacturer() + "\r\n";
  397. Local_HdInformation += "CPU ID: " + PC_Information.GetCPUSerialNumber() + "\r\n";
  398. Local_HdInformation += "内存容量: " + PC_Information.GetPhysicalMemory() + " GB" + "\r\n";
  399. Local_HdInformation += "MAC ID: " + PC_Information.GetNetCardMACAddress().Replace(":", "-") + "\r\n";
  400. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.PC_InfoFileName, Local_HdInformation);
  401. }
  402. //从本地读取,计算机名和IP地址重新读
  403. else
  404. {
  405. Local_HdInformation = "";
  406. string[] fileInfo = File.ReadAllLines(localInfo.LocalPath + localInfo.PC_InfoFileName, Encoding.UTF8);
  407. fileInfo[0] = "计算机名称: " + System.Environment.UserName;
  408. fileInfo[1] = "IP地址: " + PC_Information.GetIpAddress();
  409. for (int i = 0; i < fileInfo.Length; i++)
  410. Local_HdInformation += fileInfo[i] + "\r\n";
  411. File.Delete(localInfo.LocalPath + localInfo.PC_InfoFileName);
  412. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.PC_InfoFileName, Local_HdInformation);
  413. }
  414. }
  415. catch(Exception)
  416. {
  417. }
  418. } while (false);
  419. //系统登录
  420. do
  421. {
  422. EnterForm1.ShowDialog();
  423. try
  424. {
  425. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  426. {
  427. if (EnterForm1.comboBox_User.Text.Contains("量产"))
  428. {
  429. //隐藏设置项
  430. 其它配置项ToolStripMenuItem.Visible = false;
  431. 写入存储ToolStripMenuItem.Visible = false;
  432. 离线使用ToolStripMenuItem.Visible = false;
  433. 服务器配置ToolStripMenuItem.Visible = false;
  434. 判断阈值ToolStripMenuItem.Visible = false;
  435. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  436. mOS内阻范围ToolStripMenuItem.Visible = false;
  437. 力矩传感器检验ToolStripMenuItem.Visible = false;
  438. //显示生产信息
  439. 生产信息ToolStripMenuItem.Visible = true;
  440. //显示电机类型,但不可编辑
  441. 电机类型ToolStripMenuItem.Visible = true;
  442. 中置电机ToolStripMenuItem.Enabled = false;
  443. 轮毂电机ToolStripMenuItem.Enabled = false;
  444. if (uARTToolStripMenuItem.Checked)
  445. UART协议ToolStripMenuItem.Visible = true;
  446. //隐藏研发调试界面
  447. tabPage_MotorParam.Parent = null;
  448. tabPage_BikeParam.Parent = null;
  449. tabPage_BikeParam2.Parent = null;
  450. tabPage_ControlParam.Parent = null;
  451. tabPage_SensorParam.Parent = null;
  452. tabPage_AssistParam.Parent = null;
  453. tabPage_UsrRideParam.Parent = null;
  454. tabPage_DebugParam.Parent = null;
  455. tabPage_RecordInfo.Parent = null;
  456. tabPage_OtherInfo.Parent = null;
  457. tabPage_OBC.Parent = null;
  458. tabPage_RAMorFLASH.Parent = null;
  459. tabPage_FactoryMode.Parent = null;
  460. tabPage_DebugInfo.Parent = null;
  461. //显示运行信息
  462. tabPage_RunInfo.Parent = tabControl2;
  463. //根据电机类型修改生产信息和电机类型
  464. if (EnterForm1.comboBox_User.Text.Contains("中置"))
  465. {
  466. 中置电机ToolStripMenuItem.Checked = true;
  467. 轮毂电机ToolStripMenuItem.Checked = false;
  468. toolStripTextBox_MACPD.Text = "MM_MC1";
  469. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  470. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  471. }
  472. else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
  473. {
  474. 中置电机ToolStripMenuItem.Checked = false;
  475. 轮毂电机ToolStripMenuItem.Checked = true;
  476. toolStripTextBox_MACPD.Text = "GF_250_1";
  477. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  478. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  479. }
  480. //显示对应生产测试界面
  481. if (EnterForm1.comboBox_User.Text.Contains("写入"))
  482. {
  483. tabPage_ProductMode_Write.Parent = tabControl1;
  484. tabPage_ProductMode_Write.Select();
  485. tabPage_ProductMode_Read.Parent = null;
  486. }
  487. else if (EnterForm1.comboBox_User.Text.Contains("检验"))
  488. {
  489. tabPage_ProductMode_Read.Parent = tabControl1;
  490. tabPage_ProductMode_Read.Select();
  491. tabPage_ProductMode_Write.Parent = null;
  492. }
  493. //应答指令不提示
  494. ACK_DisFlag = false;
  495. //退出登录
  496. break;
  497. }
  498. else if (EnterForm1.comboBox_User.Text == "工程参数配置")
  499. {
  500. //隐藏工作台内容,新建窗口完成配置
  501. groupBox1.Visible = false;
  502. groupBox3.Visible = false;
  503. tabControl2.Visible = false;
  504. //隐藏提示信息
  505. label_StarInfo.Visible = false;
  506. //打开参数配置框
  507. GenerateParamsForm.ShowDialog();
  508. System.Environment.Exit(0);
  509. //退出登录
  510. break;
  511. }
  512. else if (EnterForm1.comboBox_User.Text.Contains("样机"))
  513. {
  514. //隐藏量产界面
  515. tabPage_ProductMode_Read.Parent = null;
  516. tabPage_ProductMode_Write.Parent = null;
  517. //隐藏配置项
  518. 其它配置项ToolStripMenuItem.Visible = false;
  519. 离线使用ToolStripMenuItem.Visible = false;
  520. 服务器配置ToolStripMenuItem.Visible = false;
  521. 判断阈值ToolStripMenuItem.Visible = false;
  522. 力矩传感器检验ToolStripMenuItem.Visible = false;
  523. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  524. mOS内阻范围ToolStripMenuItem.Visible = false;
  525. //显示生产信息
  526. 生产信息ToolStripMenuItem.Visible = true;
  527. //显示电机类型,但不可编辑
  528. 电机类型ToolStripMenuItem.Visible = true;
  529. 中置电机ToolStripMenuItem.Enabled = true;
  530. 轮毂电机ToolStripMenuItem.Enabled = true;
  531. if (uARTToolStripMenuItem.Checked)
  532. UART协议ToolStripMenuItem.Visible = true;
  533. if (EnterForm1.comboBox_User.Text.Contains("中置"))
  534. {
  535. 中置电机ToolStripMenuItem.Checked = true;
  536. 轮毂电机ToolStripMenuItem.Checked = false;
  537. toolStripTextBox_MACPD.Text = "MM_MC1";
  538. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  539. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  540. }
  541. else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
  542. {
  543. 中置电机ToolStripMenuItem.Checked = false;
  544. 轮毂电机ToolStripMenuItem.Checked = true;
  545. toolStripTextBox_MACPD.Text = "GF_250_1";
  546. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  547. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  548. }
  549. //退出登录
  550. break;
  551. }
  552. else if (EnterForm1.comboBox_User.Text == "FCT治具测试")
  553. {
  554. //隐藏设置项
  555. 其它配置项ToolStripMenuItem.Visible = false;
  556. 写入存储ToolStripMenuItem.Visible = false;
  557. 离线使用ToolStripMenuItem.Visible = false;
  558. 服务器配置ToolStripMenuItem.Visible = false;
  559. 判断阈值ToolStripMenuItem.Visible = false;
  560. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  561. mOS内阻范围ToolStripMenuItem.Visible = false;
  562. 力矩传感器检验ToolStripMenuItem.Visible = false;
  563. //显示生产信息
  564. 生产信息ToolStripMenuItem.Visible = true;
  565. //显示电机类型,但不可编辑
  566. 电机类型ToolStripMenuItem.Visible = false;
  567. 中置电机ToolStripMenuItem.Enabled = false;
  568. 轮毂电机ToolStripMenuItem.Enabled = false;
  569. if (uARTToolStripMenuItem.Checked)
  570. UART协议ToolStripMenuItem.Visible = true;
  571. //隐藏研发调试界面
  572. tabPage_MotorParam.Parent = null;
  573. tabPage_BikeParam.Parent = null;
  574. tabPage_BikeParam2.Parent = null;
  575. tabPage_ControlParam.Parent = null;
  576. tabPage_SensorParam.Parent = null;
  577. tabPage_AssistParam.Parent = null;
  578. tabPage_UsrRideParam.Parent = null;
  579. tabPage_DebugParam.Parent = null;
  580. tabPage_RecordInfo.Parent = null;
  581. tabPage_OtherInfo.Parent = null;
  582. tabPage_OBC.Parent = null;
  583. tabPage_RAMorFLASH.Parent = null;
  584. tabPage_FactoryMode.Parent = null;
  585. tabPage_DebugInfo.Parent = null;
  586. //显示运行信息
  587. tabPage_RunInfo.Parent = tabControl2;
  588. //目前仅轮毂使用
  589. 中置电机ToolStripMenuItem.Checked = false;
  590. 轮毂电机ToolStripMenuItem.Checked = true;
  591. toolStripTextBox_MACPD.Text = "GF_250_1";
  592. toolStripTextBox_ServerPath.Text = "HUB_Control_FCT";
  593. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  594. //显示量产测试界面
  595. tabPage_ProductMode_Write.Parent = tabControl1;
  596. tabPage_ProductMode_Write.Select();
  597. tabPage_ProductMode_Read.Parent = null;
  598. //允许离线使用
  599. 允许ToolStripMenuItem.Checked = false;
  600. 不允许ToolStripMenuItem.Checked = true;
  601. checkBox_OffLineFacMode.Checked = false;
  602. checkBox_OffLineFacMode.Enabled = true;
  603. checkBox_OffLineCheckMode.Checked = false;
  604. checkBox_OffLineCheckMode.Enabled = true;
  605. //应答指令不提示
  606. ACK_DisFlag = false;
  607. //退出登录
  608. break;
  609. }
  610. else if (EnterForm1.comboBox_User.Text == "研发调试")
  611. {
  612. //隐藏量产界面
  613. tabPage_ProductMode_Read.Parent = null;
  614. tabPage_ProductMode_Write.Parent = null;
  615. 服务器配置ToolStripMenuItem.Visible = false;
  616. if (uARTToolStripMenuItem.Checked)
  617. UART协议ToolStripMenuItem.Visible = true;
  618. //退出登录
  619. break;
  620. }
  621. else if (EnterForm1.comboBox_User.Text == "管理员")
  622. {
  623. //不隐藏任何界面
  624. //...
  625. //退出登录
  626. break;
  627. }
  628. else
  629. {
  630. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  631. //重新登录
  632. continue;
  633. }
  634. }
  635. else
  636. {
  637. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  638. //重新登录
  639. continue;
  640. }
  641. }
  642. catch (Exception)
  643. {
  644. System.Environment.Exit(0);
  645. }
  646. } while (true);
  647. //配置网络FTP服务器
  648. myFtp.FtpOption(toolStripTextBox_ServerIP.Text, toolStripTextBox_ServerPort.Text, toolStripTextBox_ServerUser.Text, toolStripTextBox_ServerPasswd.Text, "admin", "ttium_admin");
  649. //创建线程,定时检测网络连接状态
  650. Thread th = new Thread(NetworkCheck);
  651. th.IsBackground = true;
  652. th.Start();
  653. }
  654. /// <summary>
  655. /// 检查网络状态线程
  656. /// </summary>
  657. private void NetworkCheck()
  658. {
  659. //允许离线使用,直接退出
  660. if (允许ToolStripMenuItem.Checked == true) //允许离线使用
  661. {
  662. timer_1s.Enabled = false;
  663. MessageBoxTimeOut.Show("离线使用,不检测网络状态!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  664. timer_1s.Enabled = true;
  665. return;
  666. }
  667. //不允许离线使用,实时监测网络状态
  668. else
  669. {
  670. //初始化第一次连接FTP服务器
  671. bool Result = myFtp.CheckFtp();
  672. if (Result == true)//服务器连接成功
  673. {
  674. myFtp.IsNetConnected = true;
  675. //上传登录日志
  676. do
  677. {
  678. //日志文件名
  679. string date = DateTime.Now.ToString("yyyy-MM-dd_HHmmss_fff");
  680. string fileName = date;
  681. //日志内容
  682. string fileInfo = Local_HdInformation;
  683. //保存本地
  684. if (!Directory.Exists(localInfo.LocalLogPath))
  685. Directory.CreateDirectory(localInfo.LocalLogPath);
  686. System.IO.File.WriteAllText(localInfo.LocalLogPath + fileName, fileInfo);
  687. //上传服务器
  688. myFtp.UploadFile(localInfo.LocalLogPath + fileName, "/Tools/Welling_Motor_Debug_Tool/log");
  689. } while (false);
  690. }
  691. else//服务器连接失败
  692. {
  693. myFtp.IsNetConnected = false;
  694. if (EnterForm1.comboBox_User.Text != "管理员")
  695. {
  696. timer_1s.Enabled = false;
  697. MessageBoxTimeOut.Show("网络断开,将自动关闭!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  698. timer_1s.Enabled = true;
  699. this.Close();
  700. }
  701. }
  702. //创建定时器,定时10s检查网络
  703. System.Timers.Timer timer_CheckNet = new System.Timers.Timer();
  704. timer_CheckNet.Enabled = true;
  705. timer_CheckNet.Interval = 30000;
  706. timer_CheckNet.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_CheckNet_Tick);
  707. timer_CheckNet.Start();
  708. while (true)
  709. {
  710. Thread.Sleep(1);
  711. if (myFtp.IsNetConnected == false)
  712. {
  713. label_Server_ComStatus.Text = "网络已断开";
  714. label_ServerStatus.BackColor = Color.Red;
  715. }
  716. else
  717. {
  718. label_Server_ComStatus.Text = "网络已连接";
  719. label_ServerStatus.BackColor = Color.Green;
  720. }
  721. }
  722. }
  723. }
  724. /// <summary>
  725. /// 线程中定时任务,检查网络状态
  726. /// </summary>
  727. /// <param name="sender"></param>
  728. /// <param name="e"></param>
  729. private void timer_CheckNet_Tick(object sender, EventArgs e)
  730. {
  731. //连接FTP服务器
  732. bool Result = myFtp.CheckFtp();
  733. if (Result == true)//服务器连接成功
  734. {
  735. myFtp.IsNetConnected = true;
  736. //允许使用
  737. groupBox1.Enabled = true;
  738. groupBox3.Enabled = true;
  739. tabControl2.Enabled = true;
  740. }
  741. else//服务器连接失败
  742. {
  743. myFtp.IsNetConnected = false;
  744. if (EnterForm1.comboBox_User.Text != "管理员")
  745. {
  746. timer_1s.Enabled = false;
  747. MessageBoxTimeOut.Show("网络断开, 请检查网络!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Warning); //提示框自动3s关闭
  748. timer_1s.Enabled = true;
  749. //禁止使用
  750. groupBox1.Enabled = false;
  751. groupBox3.Enabled = false;
  752. tabControl2.Enabled = false;
  753. }
  754. }
  755. }
  756. #region 非独占性延时函数
  757. public static void Delay_ms(int milliSecond)
  758. {
  759. int start = Environment.TickCount;
  760. while (Math.Abs(Environment.TickCount - start) < milliSecond)//毫秒
  761. {
  762. Application.DoEvents();
  763. }
  764. }
  765. #endregion
  766. private void MainForm_Load(object sender, System.EventArgs e)
  767. {
  768. //页面初始化
  769. label_BuildTime.Text = "编译时间:" + System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString("yyyy-MM-dd HH:mm:ss");
  770. label_Computername.Text = System.Environment.UserName;
  771. label_UserName.Text = EnterForm1.comboBox_User.Text;
  772. this.Text += Version;
  773. //检查版本,自动更新
  774. do
  775. {
  776. if (打开ToolStripMenuItem.Checked == false)//关闭自动更新
  777. {
  778. break;
  779. }
  780. //检查网络状态
  781. if (myFtp.CheckFtp() == false)
  782. {
  783. MessageBoxTimeOut.Show("网络断开,自动更新失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  784. break;
  785. }
  786. else
  787. {
  788. //检查本地文件删除
  789. if (System.IO.File.Exists(localInfo.LocalPath + "\\Version"))
  790. System.IO.File.Delete(localInfo.LocalPath + "\\Version");
  791. //读取最新版本号
  792. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/Version", localInfo.LocalPath);
  793. StreamReader objReader = new StreamReader(localInfo.LocalPath + "\\Version");
  794. string sLine = "";
  795. ArrayList arrText = new ArrayList();//创建一个动态数组
  796. while (sLine != null)
  797. {
  798. sLine = objReader.ReadLine();
  799. arrText.Add(sLine);
  800. }
  801. objReader.Close();
  802. System.IO.File.Delete(localInfo.LocalPath + "\\Version");
  803. //检查是否有最新版本
  804. string[] VerOld = mainForm.Version.Trim().Split('.');
  805. string[] VerNew = arrText[0].ToString().Trim().Split('.');
  806. int VerOld_int = Convert.ToInt32(VerOld[0]) * 10000 + Convert.ToInt32(VerOld[1].PadLeft(2, '0')) * 100 + Convert.ToInt32(VerOld[2].PadLeft(2, '0'));
  807. int VerNew_int = Convert.ToInt32(VerNew[0]) * 10000 + Convert.ToInt32(VerNew[1].PadLeft(2, '0')) * 100 + Convert.ToInt32(VerNew[2].PadLeft(2, '0'));
  808. if (VerNew_int <= VerOld_int)
  809. {
  810. //版本已是最新,跳出
  811. break;
  812. }
  813. //确认下载最新版本
  814. if (MessageBox.Show("是否更新新版本?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  815. {
  816. string SavePath = Directory.GetCurrentDirectory();
  817. string[] FileList = myFtp.GetFileNameList("/Tools/Welling_Motor_Debug_Tool");
  818. foreach (string file in FileList)
  819. {
  820. if (file.Contains(".exe"))
  821. {
  822. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/" + file, SavePath);
  823. MessageBox.Show("新版本下载完成,请手动删除旧版本!\r\n最新版本:" + file, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  824. System.Environment.Exit(0);
  825. }
  826. }
  827. }
  828. }
  829. } while (false);
  830. //下拉控件初始值设定
  831. comboBox_WorkMode.SelectedIndex = 0;
  832. comboBox_GearSt.SelectedIndex = 0;
  833. comboBox_LightSwitch.SelectedIndex = 1;
  834. comboBox_OBC_SetGearST.SelectedIndex = 0;
  835. comboBox_OBC_LightSw.SelectedIndex = 1;
  836. comboBox_AssistTorque.SelectedIndex = 0;
  837. comboBox_AssistCadence.SelectedIndex = 0;
  838. //combobox事件定义
  839. this.comboBox_WorkMode.SelectedIndexChanged += new System.EventHandler(this.comboBox_WorkMode_SelectedIndexChanged);
  840. this.comboBox_GearSt.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  841. this.comboBox_LightSwitch.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  842. this.comboBox_OBC_SetGearST.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  843. this.comboBox_OBC_LightSw.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  844. //端口自动连接
  845. if ((PortNumSave != string.Empty) && (PortBaudrateSave != string.Empty)) //有数值时采用上次使用的值
  846. {
  847. try
  848. {
  849. PortConnect();
  850. }
  851. catch (System.Exception)
  852. {
  853. timer_1s.Enabled = false;
  854. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  855. timer_1s.Enabled = true;
  856. }
  857. }
  858. //不识别联动装置盒自动打开界面
  859. #if true
  860. groupBox1.Visible = true;
  861. groupBox3.Visible = true;
  862. tabControl2.Visible = true;
  863. label_StarInfo.Visible = false;
  864. #endif
  865. //创建线程,定时解析数据
  866. Thread th = new Thread(Task_SerialProcess);
  867. th.IsBackground = true;
  868. th.Start();
  869. }
  870. #region 结构体与字节流相互转换
  871. public static class MyConverter
  872. {
  873. /// <summary>
  874. /// 由结构体转换为byte数组
  875. /// </summary>
  876. public static byte[] StructureToByte<T>(T structure)
  877. {
  878. int size = Marshal.SizeOf(typeof(T));
  879. byte[] buffer = new byte[size];
  880. IntPtr bufferIntPtr = Marshal.AllocHGlobal(size);
  881. try
  882. {
  883. Marshal.StructureToPtr(structure, bufferIntPtr, true);
  884. Marshal.Copy(bufferIntPtr, buffer, 0, size);
  885. }
  886. finally
  887. {
  888. Marshal.FreeHGlobal(bufferIntPtr);
  889. }
  890. return buffer;
  891. }
  892. /// <summary>
  893. /// 由byte数组转换为结构体
  894. /// </summary>
  895. public static T ByteToStructure<T>(byte[] dataBuffer, ushort StarIndex)
  896. {
  897. object structure = null;
  898. int size = Marshal.SizeOf(typeof(T));
  899. IntPtr allocIntPtr = Marshal.AllocHGlobal(size);
  900. try
  901. {
  902. Marshal.Copy(dataBuffer, StarIndex, allocIntPtr, size);
  903. structure = Marshal.PtrToStructure(allocIntPtr, typeof(T));
  904. }
  905. finally
  906. {
  907. Marshal.FreeHGlobal(allocIntPtr);
  908. }
  909. return (T)structure;
  910. }
  911. }
  912. #endregion
  913. #region 故障日志解析显示
  914. private void ErrorLogDisplay(MC_ErrorLogSaveInfo_Struct_t Log1, MC_ErrorLogSaveInfo_Struct_t Log2)
  915. {
  916. string SaveData = "";
  917. //Log1
  918. if (Log1.Error_Index != 0xFFFF)
  919. {
  920. SaveData += "故障序号:" + Convert.ToString(Log1.Error_Index) + ", ";
  921. SaveData += "备注1:" + Convert.ToString(Log1.NotesInfo1) + ", ";
  922. SaveData += "备注2:" + Convert.ToString(Log1.NotesInfo2) + ", ";
  923. SaveData += "备注3:" + Convert.ToString(Log1.NotesInfo3) + ", ";
  924. SaveData += "故障码:" + "0x" + Convert.ToString(Log1.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  925. SaveData += "运行时间:" + Convert.ToString(Log1.RunTime) + "min" + ", ";
  926. SaveData += "车速:" + ((float)Log1.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  927. SaveData += "电机转速:" + Convert.ToString(Log1.RunInfo.MotorSpeed) + "rpm" + ", ";
  928. SaveData += "功率:" + Convert.ToString(Log1.RunInfo.Power * 2) + "w" + ", ";
  929. SaveData += "电压:" + Convert.ToString(Log1.RunInfo.BusVoltage) + "mV" + ", ";
  930. SaveData += "电流:" + Convert.ToString(Log1.RunInfo.BusCurrent) + "mA" + ", ";
  931. SaveData += "踏频:" + Convert.ToString(Log1.RunInfo.Cadence) + "rpm" + ", ";
  932. SaveData += "力矩:" + Convert.ToString(Log1.RunInfo.Torque) + "N.m" + ", ";
  933. SaveData += "方向:" + ((Log1.RunInfo.CadenceDir == 0) ? "正" : ((Log1.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  934. SaveData += "档位:" + "0x" + Convert.ToString(Log1.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  935. SaveData += "灯开关:" + ((Log1.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  936. SaveData += "电量:" + Convert.ToString(Log1.RunInfo.SOC) + "%" + ", ";
  937. if ((Log1.RunInfo.RemainDistance == 0xEEEE) || (Log1.RunInfo.RemainDistance == 0xFFFF))
  938. {
  939. SaveData += "续航:" + "---km" + ", ";
  940. }
  941. else
  942. {
  943. SaveData += "续航:" + Convert.ToString(Log1.RunInfo.RemainDistance) + "km" + ", ";
  944. }
  945. SaveData += "力矩AD:" + Convert.ToString(Log1.RunInfo.Torque_AD) + ", ";
  946. SaveData += "功耗:" + Convert.ToString(Log1.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  947. SaveData += "PCB温度:" + Convert.ToString((int)(Log1.RunInfo.T_PCB - 40)) + "℃" + ", ";
  948. SaveData += "绕组温度:" + Convert.ToString((int)(Log1.RunInfo.T_Coil - 40)) + "℃" + ", ";
  949. SaveData += "MCU温度:" + Convert.ToString((int)(Log1.RunInfo.T_MCU - 40)) + "℃" + ", ";
  950. SaveData += "单次里程:" + Convert.ToString((float)Log1.RunInfo.Ride_Km / 10f) + "km" + ", ";
  951. SaveData += "单次时间:" + Convert.ToString(Log1.RunInfo.Ride_Time) + "s" + ", ";
  952. SaveData += "q轴电流:" + Convert.ToString(Log1.IqCurrent) + ", ";
  953. SaveData += "q轴电压:" + Convert.ToString(Log1.IqVoltage) + ", ";
  954. SaveData += "d轴电流:" + Convert.ToString(Log1.IdCurrent) + ", ";
  955. SaveData += "d轴电压:" + Convert.ToString(Log1.IdVoltage) + ", ";
  956. SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
  957. SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
  958. SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
  959. SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
  960. SaveData += "\r\n\r\n";
  961. richTextBox_Record.AppendText(SaveData);
  962. SaveData = "";
  963. }
  964. //Log2
  965. if (Log2.Error_Index != 0xFFFF)
  966. {
  967. SaveData += "故障序号:" + Convert.ToString(Log2.Error_Index) + ", ";
  968. SaveData += "备注1:" + Convert.ToString(Log2.NotesInfo1) + ", ";
  969. SaveData += "备注2:" + Convert.ToString(Log2.NotesInfo2) + ", ";
  970. SaveData += "备注3:" + Convert.ToString(Log2.NotesInfo3) + ", ";
  971. SaveData += "故障码:" + "0x" + Convert.ToString(Log2.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  972. SaveData += "运行时间:" + Convert.ToString(Log2.RunTime) + "min" + ", ";
  973. SaveData += "车速:" + ((float)Log2.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  974. SaveData += "电机转速:" + Convert.ToString(Log2.RunInfo.MotorSpeed) + "rpm" + ", ";
  975. SaveData += "功率:" + Convert.ToString(Log2.RunInfo.Power * 2) + "w" + ", ";
  976. SaveData += "电压:" + Convert.ToString(Log2.RunInfo.BusVoltage) + "mV" + ", ";
  977. SaveData += "电流:" + Convert.ToString(Log2.RunInfo.BusCurrent) + "mA" + ", ";
  978. SaveData += "踏频:" + Convert.ToString(Log2.RunInfo.Cadence) + "rpm" + ", ";
  979. SaveData += "力矩:" + Convert.ToString(Log2.RunInfo.Torque) + "N.m" + ", ";
  980. SaveData += "方向:" + ((Log2.RunInfo.CadenceDir == 0) ? "正" : ((Log2.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  981. SaveData += "档位:" + "0x" + Convert.ToString(Log2.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  982. SaveData += "灯开关:" + ((Log2.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  983. SaveData += "电量:" + Convert.ToString(Log2.RunInfo.SOC) + "%" + ", ";
  984. if ((Log2.RunInfo.RemainDistance == 0xEEEE) || (Log2.RunInfo.RemainDistance == 0xFFFF))
  985. {
  986. SaveData += "续航:" + "---km" + ", ";
  987. }
  988. else
  989. {
  990. SaveData += "续航:" + Convert.ToString(Log2.RunInfo.RemainDistance) + "km" + ", ";
  991. }
  992. SaveData += "力矩AD:" + Convert.ToString(Log2.RunInfo.Torque_AD) + ", ";
  993. SaveData += "功耗:" + Convert.ToString(Log2.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  994. SaveData += "PCB温度:" + Convert.ToString((int)(Log2.RunInfo.T_PCB - 40)) + "DegreeC" + ", ";
  995. SaveData += "绕组温度:" + Convert.ToString((int)(Log2.RunInfo.T_Coil - 40)) + "DegreeC" + ", ";
  996. SaveData += "MCU温度:" + Convert.ToString((int)(Log2.RunInfo.T_MCU - 40)) + "DegreeC" + ", ";
  997. SaveData += "单次里程:" + Convert.ToString((float)Log2.RunInfo.Ride_Km / 10f) + "km" + ", ";
  998. SaveData += "单次时间:" + Convert.ToString(Log2.RunInfo.Ride_Time) + "s" + ", ";
  999. SaveData += "q轴电流:" + Convert.ToString(Log2.IqCurrent) + ", ";
  1000. SaveData += "q轴电压:" + Convert.ToString(Log2.IqVoltage) + ", ";
  1001. SaveData += "d轴电流:" + Convert.ToString(Log2.IdCurrent) + ", ";
  1002. SaveData += "d轴电压:" + Convert.ToString(Log2.IdVoltage) + ", ";
  1003. SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
  1004. SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
  1005. SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
  1006. SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
  1007. SaveData += "\r\n\r\n";
  1008. richTextBox_Record.AppendText(SaveData);
  1009. SaveData = "";
  1010. }
  1011. }
  1012. #endregion
  1013. #region 串口数据解析线程
  1014. /// <summary>
  1015. /// 串口数据解析线程
  1016. /// </summary>
  1017. private void Task_SerialProcess()
  1018. {
  1019. //创建定时器,定时读取串口数据
  1020. System.Timers.Timer timer_ReadSerial = new System.Timers.Timer();
  1021. timer_ReadSerial.Enabled = true;
  1022. timer_ReadSerial.Interval = 20;
  1023. timer_ReadSerial.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_ReadSerial_Tick);
  1024. timer_ReadSerial.Start();
  1025. while (true)
  1026. {
  1027. Thread.Sleep(1);
  1028. };
  1029. }
  1030. /// <summary>
  1031. /// 串口解析定时器
  1032. /// </summary>
  1033. /// <param name="sender"></param>
  1034. /// <param name="e"></param>
  1035. private void timer_ReadSerial_Tick(object sender, EventArgs e)
  1036. {
  1037. //串口解析
  1038. Serial_process(mySerialProcess.buffer);
  1039. }
  1040. #endregion
  1041. #region 数据解析
  1042. public void Serial_process(List<byte> buffer)
  1043. {
  1044. byte DataNum = 0; //记录每条命令数据段的长度
  1045. ushort PackageID, Cmd;
  1046. byte[] Data = new byte[1024];
  1047. try
  1048. {
  1049. while (buffer.Count >= 13)//当buffer中的数据的个数大于等于4个时,即每一帧的数据长度所在位(第4位)出现时
  1050. {
  1051. if (buffer[0] == 0x55 && buffer[1] == 0xAA)//判断帧头
  1052. {
  1053. PackageID = (ushort)(buffer[2] * 256 + buffer[3]);
  1054. if ((PackageID == 0x0710) || (PackageID == 0x0715) || (PackageID == 0x07FF) || (PackageID == 0x0720) || (PackageID == 0x0713))
  1055. {
  1056. int CmdLen = buffer[5];
  1057. if (buffer.Count < CmdLen + 11) break;//如果接收到的数据没有达到一帧数据的指定长度, 则执行下次循环
  1058. while (CmdLen > 0) //读取命令段
  1059. {
  1060. Cmd = (ushort)(buffer[6] * 256 + buffer[7]);
  1061. DataNum = (byte)(buffer[7]);//命令字的第二个字节的表示数据位的长度
  1062. if (DataNum <= (CmdLen - 2))
  1063. {
  1064. for (int i = 0; i < DataNum; i++)
  1065. {
  1066. Data[i] = buffer[i + 8];
  1067. }
  1068. buffer.RemoveRange(0, CmdLen + 11);
  1069. DataCmdProcess(PackageID, Cmd, Data);//对于不同的命令段,做不同的处理
  1070. DataRevToString(Cmd, Data);//指令数据转为字符串
  1071. }
  1072. }
  1073. }
  1074. else
  1075. {
  1076. buffer.RemoveAt(0);//ID不对
  1077. }
  1078. }
  1079. else
  1080. {
  1081. buffer.RemoveAt(0);//帧头不对,删除帧头高字节
  1082. }
  1083. }
  1084. }
  1085. catch (Exception)
  1086. {
  1087. }
  1088. }
  1089. private void DataCmdProcess(ushort ID, ushort CmdTemp, byte[] Data)
  1090. {
  1091. int DataTemp;
  1092. ushort uData16;
  1093. unchecked
  1094. {
  1095. this.Invoke((EventHandler)(delegate { label_RecCount.Text = Convert.ToString(Convert.ToInt32(label_RecCount.Text) + 1); }));
  1096. }
  1097. #region 解析发送给CDL的指令
  1098. if (ID == 0x7FF)
  1099. {
  1100. switch (CmdTemp)
  1101. {
  1102. case 0x1100://
  1103. {
  1104. unchecked
  1105. {
  1106. this.Invoke((EventHandler)(delegate
  1107. {
  1108. //CDL连接成功
  1109. mySerialProcess.CDL_Online_Flag = true;
  1110. MessageBoxTimeOut.Show("连接成功!", "提示", 500);
  1111. groupBox1.Visible = true;
  1112. groupBox3.Visible = true;
  1113. tabControl2.Visible = true;
  1114. label_StarInfo.Visible = false;
  1115. }));
  1116. }
  1117. break;
  1118. }
  1119. default: break;
  1120. }
  1121. }
  1122. #endregion
  1123. #region 解析电机的命令
  1124. else if ((ID == 0x715) || (ID == 0x710))
  1125. {
  1126. switch (CmdTemp)
  1127. {
  1128. case 0x1020://电机运行信息
  1129. {
  1130. unchecked
  1131. {
  1132. this.Invoke((EventHandler)(delegate
  1133. {
  1134. MC_RunInfo_Refresh = true;
  1135. //车速
  1136. DataTemp = (int)(Data[1] * 256 + Data[0]);
  1137. textBox_RunInfo_BikeSpeed.Text = ((float)DataTemp / 10f).ToString("0.0") + " km/h";
  1138. //输出转速
  1139. DataTemp = (ushort)(Data[3] * 256 + Data[2]);
  1140. textBox_RunInfo_MotorSpeed.Text = Convert.ToString(DataTemp) + " rpm";
  1141. Class_MotorSpeed.String = textBox_RunInfo_MotorSpeed.Text;
  1142. Class_MotorSpeed.Data = DataTemp;
  1143. //电功率
  1144. DataTemp = (ushort)(Data[5] * 256 + Data[4]);
  1145. textBox_RunInfo_Power.Text = Convert.ToString(DataTemp) + " W";
  1146. //母线电压
  1147. DataTemp = (ushort)(Data[7] * 256 + Data[6]);
  1148. textBox_RunInfo_Vol.Text = Convert.ToString(DataTemp) + " mV";
  1149. //textBox_RunInfo_Vol.Text = (DataTemp / 1000f).ToString("0.0") + " V";
  1150. //母线电流
  1151. DataTemp = (short)(Data[9] * 256 + Data[8]);
  1152. textBox_RunInfo_Current.Text = Convert.ToString(DataTemp) + " mA";
  1153. //textBox_RunInfo_Current.Text = (DataTemp / 1000f).ToString("0.0") + " A";
  1154. Class_CurrentData.String = textBox_RunInfo_Current.Text;
  1155. Class_CurrentData.Data = DataTemp;
  1156. //踏频
  1157. DataTemp = (ushort)(Data[10]);
  1158. textBox_RunInfo_Cadence.Text = Convert.ToString(DataTemp) + " rpm";
  1159. Class_CadenceData.String = textBox_RunInfo_Cadence.Text;
  1160. Class_CadenceData.Data = DataTemp;
  1161. //踩踏力矩
  1162. DataTemp = (ushort)(Data[11]);
  1163. textBox_RunInfo_Torque.Text = Convert.ToString(DataTemp) + " N.m";
  1164. Class_TorqueData.String = textBox_RunInfo_Torque.Text;
  1165. Class_TorqueData.Data = DataTemp;
  1166. //踩踏方向
  1167. DataTemp = (ushort)(Data[12]);
  1168. if (DataTemp == 0)
  1169. {
  1170. textBox_RunInfo_Dir.Text = "正向";
  1171. }
  1172. else if (DataTemp == 1)
  1173. {
  1174. textBox_RunInfo_Dir.Text = "反向";
  1175. }
  1176. else if (DataTemp == 2)
  1177. {
  1178. textBox_RunInfo_Dir.Text = "停止";
  1179. }
  1180. //助力档位
  1181. DataTemp = (ushort)(Data[13]);
  1182. if (DataTemp == 0x33)
  1183. {
  1184. textBox_RunInfo_GearSt.Text = "SMART";
  1185. //comboBox_GearSt.SelectedIndex = 5;
  1186. //comboBox_OBC_SetGearST.SelectedIndex = 5;
  1187. }
  1188. else if (DataTemp == 0x22)
  1189. {
  1190. textBox_RunInfo_GearSt.Text = "WALK";
  1191. //comboBox_GearSt.SelectedIndex = 6;
  1192. //comboBox_OBC_SetGearST.SelectedIndex = 6;
  1193. }
  1194. else
  1195. {
  1196. string[] Gears = new string[5] { "OFF", "ECO", "NORM", "SPORT", "TURBO" };
  1197. textBox_RunInfo_GearSt.Text = Gears[DataTemp];
  1198. //comboBox_GearSt.SelectedIndex = DataTemp;
  1199. //comboBox_OBC_SetGearST.SelectedIndex = DataTemp;
  1200. }
  1201. //大灯状态
  1202. DataTemp = (ushort)(Data[14]);
  1203. if (DataTemp == 0xF0)
  1204. {
  1205. textBox_RunInfo_LightSwitch.Text = "OFF";
  1206. //comboBox_LightSwitch.SelectedIndex = 1;
  1207. //comboBox_OBC_LightSw.SelectedIndex = 1;
  1208. }
  1209. else if (DataTemp == 0xF1)
  1210. {
  1211. textBox_RunInfo_LightSwitch.Text = "ON";
  1212. //comboBox_LightSwitch.SelectedIndex = 0;
  1213. //comboBox_OBC_LightSw.SelectedIndex = 0;
  1214. }
  1215. //剩余电量
  1216. DataTemp = (ushort)(Data[15]);
  1217. textBox_RunInfo_SOC.Text = Convert.ToString(DataTemp) + " %";
  1218. //剩余续航里程
  1219. DataTemp = (ushort)(Data[17] * 256 + Data[16]);
  1220. if ((DataTemp == 0xEEEE) || (DataTemp == 0xFFFF))
  1221. {
  1222. textBox_RunInfo_Range.Text = "---";
  1223. }
  1224. else
  1225. {
  1226. textBox_RunInfo_Range.Text = Convert.ToString(DataTemp) + " km";
  1227. }
  1228. //预留(显示力矩Reg),空2bytes
  1229. DataTemp = (ushort)(Data[19] * 256 + Data[18]);
  1230. textBox_TorqueReg.Text = Convert.ToString(DataTemp);
  1231. //平均功耗
  1232. DataTemp = (ushort)(Data[20]);
  1233. textBox_RunInfo_AvgPower.Text = Convert.ToString(DataTemp * 10) + " mAh/km";
  1234. //PCB温度
  1235. DataTemp = (ushort)(Data[21]);
  1236. textBox_RunInfo_T_PCB.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1237. Class_MotorTemp.String = textBox_RunInfo_T_PCB.Text;
  1238. Class_MotorTemp.Data = DataTemp - 40;
  1239. //绕组温度
  1240. DataTemp = (ushort)(Data[22]);
  1241. textBox_RunInfo_T_Coil.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1242. //MCU温度
  1243. DataTemp = (ushort)(Data[23]);
  1244. textBox_RunInfo_T_MCU.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1245. //单次里程
  1246. DataTemp = (ushort)(Data[25] * 256 + Data[24]);
  1247. textBox_RunInfo_Trip.Text = ((float)DataTemp / 10f).ToString("0.0") + " km";
  1248. //单次时间
  1249. DataTemp = (ushort)(Data[27] * 256 + Data[26]);
  1250. textBox_RunInfo_Trip_Time.Text = Convert.ToString(DataTemp) + " s";
  1251. //数据保存
  1252. RunInfoAutoSave();
  1253. }));
  1254. }
  1255. break;
  1256. }
  1257. case 0x1104://故障码
  1258. {
  1259. unchecked
  1260. {
  1261. this.Invoke((EventHandler)(delegate
  1262. {
  1263. MC_ErrorCode_Refresh = true;
  1264. textBox_ErrorCode.Text =
  1265. Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() +
  1266. Convert.ToString(Data[2], 16).PadLeft(2, '0').ToUpper() +
  1267. Convert.ToString(Data[1], 16).PadLeft(2, '0').ToUpper() +
  1268. Convert.ToString(Data[0], 16).PadLeft(2, '0').ToUpper() +
  1269. "H";
  1270. }));
  1271. }
  1272. break;
  1273. }
  1274. case 0xA903://反馈指令
  1275. {
  1276. unchecked
  1277. {
  1278. this.Invoke((EventHandler)(delegate
  1279. {
  1280. if (ACK_DisFlag == true)
  1281. {
  1282. timer_1s.Enabled = false;
  1283. MessageBoxTimeOut.Show("OK", "反馈指令", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  1284. timer_1s.Enabled = true;
  1285. //关机反馈
  1286. PowerOffAckStatus = true;
  1287. }
  1288. //应答标志置位
  1289. WriteACK = true;
  1290. WriteCnt++;
  1291. }));
  1292. }
  1293. break;
  1294. }
  1295. case 0xB226://马达参数
  1296. {
  1297. unchecked
  1298. {
  1299. this.Invoke((EventHandler)(delegate
  1300. {
  1301. richTextBox_MotorParam.Clear();
  1302. for (int i = 0; i < myParams.MotorParam.Count; i++)
  1303. {
  1304. if (i == 6)
  1305. richTextBox_MotorParam.AppendText(myParams.MotorParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1306. else
  1307. richTextBox_MotorParam.AppendText(myParams.MotorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1308. }
  1309. richTextBox_MotorParam.Text = richTextBox_MotorParam.Text.Substring(0, richTextBox_MotorParam.Text.Length - 2);
  1310. }));
  1311. }
  1312. break;
  1313. }
  1314. case 0xB31A://整车信息
  1315. {
  1316. unchecked
  1317. {
  1318. this.Invoke((EventHandler)(delegate
  1319. {
  1320. richTextBox_BikeParam.Clear();
  1321. for (int i = 0; i < myParams.BikeParam.Count; i++)
  1322. {
  1323. if (i == 9)
  1324. richTextBox_BikeParam.AppendText(myParams.BikeParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1325. else
  1326. richTextBox_BikeParam.AppendText(myParams.BikeParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1327. //更新前后灯参数
  1328. if (i == 8)
  1329. {
  1330. comboBox_TailLightMode.SelectedIndex = ((Data[2 * i + 1] >> 4) & 0x0F) - 1;
  1331. comboBox_TailLightVol.SelectedIndex = ((Data[2 * i + 1] & 0x0F) == 6) ? 0 : 1;
  1332. comboBox_FrontLightVol.SelectedIndex = ((Data[2 * i] & 0x0F) == 6) ? 0 : 1;
  1333. }
  1334. //更新开关机参数
  1335. else if (i == 11)
  1336. {
  1337. textBox_PowerOnDelay.Text = Convert.ToString((Data[2 * i + 1] >> 4) & 0x0F);
  1338. textBox_PowerOffDelay.Text = Convert.ToString(Data[2 * i + 1] & 0x0F);
  1339. textBox_AutoPowerOff.Text = Convert.ToString(Data[2 * i]);
  1340. }
  1341. }
  1342. richTextBox_BikeParam.Text = richTextBox_BikeParam.Text.Substring(0, richTextBox_BikeParam.Text.Length - 2);
  1343. }));
  1344. }
  1345. break;
  1346. }
  1347. case 0xB420://控制器参数
  1348. {
  1349. unchecked
  1350. {
  1351. this.Invoke((EventHandler)(delegate
  1352. {
  1353. richTextBox_ControlParam.Clear();
  1354. for (int i = 0; i < myParams.ControlParam.Count; i++)
  1355. {
  1356. richTextBox_ControlParam.AppendText(myParams.ControlParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1357. //转把定速巡航
  1358. if (i == 13)
  1359. {
  1360. comboBox_Bike_CCS.SelectedIndex = ((Data[2 * i]) == 0xAA) ? 1 : 2;
  1361. }
  1362. }
  1363. richTextBox_ControlParam.Text = richTextBox_ControlParam.Text.Substring(0, richTextBox_ControlParam.Text.Length - 2);
  1364. }));
  1365. }
  1366. break;
  1367. }
  1368. case 0xB528://传感器参数
  1369. {
  1370. unchecked
  1371. {
  1372. this.Invoke((EventHandler)(delegate
  1373. {
  1374. richTextBox_SensorParam.Clear();
  1375. for (int i = 0; i < myParams.SensorParam.Count; i++)
  1376. {
  1377. richTextBox_SensorParam.AppendText(myParams.SensorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1378. }
  1379. richTextBox_SensorParam.Text = richTextBox_SensorParam.Text.Substring(0, richTextBox_SensorParam.Text.Length - 2);
  1380. //更新生产模式页面传感器零点和标定值
  1381. textBox_FacModeSensorADC0.Text = (Data[1] * 256 + Data[0]).ToString();
  1382. textBox_FacModeSensorADC1.Text = (Data[15] * 256 + Data[14]).ToString();
  1383. textBox_FacModeSensorADC2.Text = (Data[19] * 256 + Data[18]).ToString();
  1384. textBox_FacModeSensorADC3.Text = (Data[23] * 256 + Data[22]).ToString();
  1385. textBox_FacModeSensorADC4.Text = (Data[27] * 256 + Data[26]).ToString();
  1386. }));
  1387. }
  1388. break;
  1389. }
  1390. case 0xB64C://助力参数
  1391. {
  1392. unchecked
  1393. {
  1394. this.Invoke((EventHandler)(delegate
  1395. {
  1396. richTextBox_AssistParam.Clear();
  1397. int index_1 = myParams.AssistParam.IndexOf("转矩曲线.a");
  1398. int index_2 = myParams.AssistParam.IndexOf("踏频曲线.d");
  1399. int index_3 = myParams.AssistParam.IndexOf("踏频助力加速限制");
  1400. int index_4 = myParams.AssistParam.IndexOf("踏频助力电流步进");
  1401. for (int i = 0; i < myParams.AssistParam.Count; i++)
  1402. {
  1403. if (i < index_1) //数据占用2bytes
  1404. {
  1405. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1406. }
  1407. else if (i <= index_2) //数据占用4bytes
  1408. {
  1409. 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])) + ", ");
  1410. }
  1411. else if (i < index_3) //数据占用2bytes,无符号
  1412. {
  1413. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1414. }
  1415. else if (i <= index_4) //数据占用2bytes,有符号
  1416. {
  1417. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1418. }
  1419. else //数据占用2bytes,无符号
  1420. {
  1421. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1422. }
  1423. }
  1424. richTextBox_AssistParam.Text = richTextBox_AssistParam.Text.Substring(0, richTextBox_AssistParam.Text.Length - 2);
  1425. }));
  1426. }
  1427. break;
  1428. }
  1429. case 0xB74C://历史记录
  1430. {
  1431. unchecked
  1432. {
  1433. this.Invoke((EventHandler)(delegate
  1434. {
  1435. richTextBox_Record.Clear();
  1436. for (int i = 0; i < myParams.Record.Count; i++)
  1437. {
  1438. richTextBox_Record.AppendText(myParams.Record[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  1439. }
  1440. richTextBox_Record.Text = richTextBox_Record.Text.Substring(0, richTextBox_Record.Text.Length - 2);
  1441. }));
  1442. }
  1443. break;
  1444. }
  1445. case 0xB83A://调试参数
  1446. {
  1447. unchecked
  1448. {
  1449. this.Invoke((EventHandler)(delegate
  1450. {
  1451. richTextBox_DebugParam.Clear();
  1452. for (int i = 0; i < myParams.DebugParam.Count; i++)
  1453. {
  1454. richTextBox_DebugParam.AppendText(myParams.DebugParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1455. }
  1456. richTextBox_DebugParam.Text = richTextBox_DebugParam.Text.Substring(0, richTextBox_DebugParam.Text.Length - 2);
  1457. }));
  1458. }
  1459. break;
  1460. }
  1461. case 0xB904://存储标志
  1462. {
  1463. unchecked
  1464. {
  1465. this.Invoke((EventHandler)(delegate
  1466. {
  1467. ushort Flag = 0;
  1468. Flag = (ushort)(Data[1] * 256 + Data[0]);//EEPROM存储标志
  1469. if (Flag == 0)
  1470. {
  1471. radioButton_EE_SaveNo.Checked = true;
  1472. radioButton_EE_SaveYes.Checked = false;
  1473. }
  1474. else
  1475. {
  1476. radioButton_EE_SaveNo.Checked = false;
  1477. radioButton_EE_SaveYes.Checked = true;
  1478. }
  1479. Flag = (ushort)(Data[3] * 256 + Data[2]);//SIP偏移校准存储标志
  1480. if (Flag == 0)
  1481. {
  1482. radioButton_SIP_SaveNo.Checked = true;
  1483. radioButton_SIP_SaveYes.Checked = false;
  1484. }
  1485. else
  1486. {
  1487. radioButton_SIP_SaveNo.Checked = false;
  1488. radioButton_SIP_SaveYes.Checked = true;
  1489. }
  1490. }));
  1491. }
  1492. break;
  1493. }
  1494. case 0x1240://电机版本信息
  1495. {
  1496. unchecked
  1497. {
  1498. this.Invoke((EventHandler)(delegate
  1499. {
  1500. //电机型号
  1501. textBox_Model.Text = "";
  1502. textBox_OBC_ReadModel.Text = "";
  1503. textBox_FacModeName.Text = "";
  1504. for (ushort i = 0; i < 16; i++)
  1505. {
  1506. if (Data[i] == 0x2E)
  1507. {
  1508. break;
  1509. }
  1510. textBox_Model.Text += ((char)Data[i]).ToString();
  1511. textBox_OBC_ReadModel.Text += ((char)Data[i]).ToString();
  1512. textBox_FacModeName.Text += ((char)Data[i]).ToString();
  1513. }
  1514. Class_Motor_Ver.Mode = textBox_Model.Text;
  1515. //电机SN
  1516. textBox_SN.Text = "";
  1517. textBox_OBC_ReadSN.Text = "";
  1518. textBox_FacModeNum.Text = "";
  1519. for (ushort i = 0; i < 16; i++)
  1520. {
  1521. if (Data[16 + i] == 0x2E)
  1522. {
  1523. break;
  1524. }
  1525. textBox_SN.Text += ((char)Data[16 + i]).ToString();
  1526. textBox_OBC_ReadSN.Text += ((char)Data[16 + i]).ToString();
  1527. textBox_FacModeNum.Text += ((char)Data[16 + i]).ToString();
  1528. }
  1529. Class_Motor_Ver.SN = textBox_SN.Text;
  1530. //电机HW
  1531. textBox_HW.Text = "";
  1532. textBox_OBC_ReadHW.Text = "";
  1533. textBox_FacModeHW.Text = "";
  1534. for (ushort i = 0; i < 8; i++)//前8位:硬件板号
  1535. {
  1536. if (Data[32 + i] == 0x2E)
  1537. {
  1538. break;
  1539. }
  1540. else if (Data[32 + i] == 'r')
  1541. {
  1542. Data[32 + i] = (byte)'.';
  1543. break;
  1544. }
  1545. string strTemp = "";
  1546. strTemp = ((char)Data[32 + i]).ToString();
  1547. textBox_HW.Text += strTemp;
  1548. textBox_OBC_ReadHW.Text += strTemp;
  1549. textBox_FacModeHW.Text += strTemp;
  1550. }
  1551. for (ushort i = 0; i < 4; i++)//9-12位:单片机型号
  1552. {
  1553. if (Data[40 + i] == 0x2E)
  1554. {
  1555. break;
  1556. }
  1557. else if (Data[40 + i] == 'r')
  1558. {
  1559. Data[40 + i] = (byte)'.';
  1560. break;
  1561. }
  1562. string strTemp = "";
  1563. strTemp = ((char)Data[40 + i]).ToString();
  1564. textBox_HW.Text += strTemp;
  1565. textBox_OBC_ReadHW.Text += strTemp;
  1566. textBox_FacModeHW.Text += strTemp;
  1567. }
  1568. for (ushort i = 0; i < 4; i++)//13-16位:单片机ID
  1569. {
  1570. string strTemp = "";
  1571. strTemp = Convert.ToString(Data[44 + i], 16).PadLeft(2, '0').ToUpper();
  1572. textBox_HW.Text += strTemp;
  1573. textBox_OBC_ReadHW.Text += strTemp;
  1574. textBox_FacModeHW.Text += strTemp;
  1575. }
  1576. Class_Motor_Ver.HW = textBox_HW.Text;
  1577. //电机FW
  1578. textBox_FW.Text = "";
  1579. textBox_OBC_ReadFW.Text = "";
  1580. textBox_FacModeFW.Text = "";
  1581. for (ushort i = 0; i < 16; i++)
  1582. {
  1583. if ((Data[48 + i] == 0x2E) || (Data[48 + i] == 0x00) || (Data[48 + i] == (char)' '))
  1584. {
  1585. break;
  1586. }
  1587. if (Data[48 + i] == 'r')
  1588. {
  1589. Data[48 + i] = (byte)'.';
  1590. }
  1591. textBox_FW.Text += ((char)Data[48 + i]).ToString();
  1592. textBox_OBC_ReadFW.Text += ((char)Data[48 + i]).ToString();
  1593. textBox_FacModeFW.Text += ((char)Data[48 + i]).ToString();
  1594. }
  1595. Class_Motor_Ver.FW = textBox_FW.Text;
  1596. }));
  1597. }
  1598. break;
  1599. }
  1600. case 0xA610://自定义1
  1601. {
  1602. unchecked
  1603. {
  1604. this.Invoke((EventHandler)(delegate
  1605. {
  1606. textBox_User1.Text = "";
  1607. for (ushort i = 0; i < 16; i++)
  1608. {
  1609. if (Data[i] == 0x2E)
  1610. {
  1611. break;
  1612. }
  1613. textBox_User1.Text += ((char)Data[i]).ToString();
  1614. }
  1615. }));
  1616. }
  1617. break;
  1618. }
  1619. case 0xA710://自定义2
  1620. {
  1621. unchecked
  1622. {
  1623. this.Invoke((EventHandler)(delegate
  1624. {
  1625. textBox_User2.Text = "";
  1626. for (ushort i = 0; i < 16; i++)
  1627. {
  1628. if (Data[i] == 0x2E)
  1629. {
  1630. break;
  1631. }
  1632. textBox_User2.Text += ((char)Data[i]).ToString();
  1633. }
  1634. }));
  1635. }
  1636. break;
  1637. }
  1638. case 0xA810://自定义1
  1639. {
  1640. unchecked
  1641. {
  1642. this.Invoke((EventHandler)(delegate
  1643. {
  1644. textBox_User3.Text = "";
  1645. for (ushort i = 0; i < 16; i++)
  1646. {
  1647. if (Data[i] == 0x2E)
  1648. {
  1649. break;
  1650. }
  1651. textBox_User3.Text += ((char)Data[i]).ToString();
  1652. }
  1653. }));
  1654. }
  1655. break;
  1656. }
  1657. case 0xA520://生产信息
  1658. {
  1659. unchecked
  1660. {
  1661. this.Invoke((EventHandler)(delegate
  1662. {
  1663. //生产商
  1664. textBox_MAC.Text = "";
  1665. for (ushort i = 0; i < 8; i++)
  1666. {
  1667. if (Data[i] == 0x2E)
  1668. {
  1669. break;
  1670. }
  1671. textBox_MAC.Text += ((char)Data[i]).ToString();
  1672. }
  1673. //生产地
  1674. textBox_MACAdd.Text = "";
  1675. for (ushort i = 0; i < 8; i++)
  1676. {
  1677. if (Data[8 + i] == 0x2E)
  1678. {
  1679. break;
  1680. }
  1681. textBox_MACAdd.Text += ((char)Data[8 + i]).ToString();
  1682. }
  1683. //生产日期
  1684. textBox_MACDate.Text = "";
  1685. for (ushort i = 0; i < 8; i++)
  1686. {
  1687. if (Data[16 + i] == 0x2E)
  1688. {
  1689. break;
  1690. }
  1691. textBox_MACDate.Text += ((char)Data[16 + i]).ToString();
  1692. }
  1693. //品牌信息
  1694. textBox_PP.Text = "";
  1695. for (ushort i = 0; i < 8; i++)
  1696. {
  1697. if (Data[24 + i] == 0x2E)
  1698. {
  1699. break;
  1700. }
  1701. textBox_PP.Text += ((char)Data[24 + i]).ToString();
  1702. }
  1703. }));
  1704. }
  1705. break;
  1706. }
  1707. case 0xA408://密钥
  1708. {
  1709. unchecked
  1710. {
  1711. this.Invoke((EventHandler)(delegate
  1712. {
  1713. textBox_Key.Text = "";
  1714. for (ushort i = 0; i < 8; i++)
  1715. {
  1716. textBox_Key.Text += ((char)Data[i]).ToString();
  1717. }
  1718. }));
  1719. }
  1720. break;
  1721. }
  1722. case 0xAB09://存储器数据
  1723. case 0xAB0A:
  1724. case 0xAB0B:
  1725. case 0xAB0C:
  1726. {
  1727. unchecked
  1728. {
  1729. this.Invoke((EventHandler)(delegate
  1730. {
  1731. long ByteNum = 0;
  1732. ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
  1733. if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
  1734. {
  1735. for (int i = 0; i < ByteNum; i++)
  1736. {
  1737. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  1738. }
  1739. }
  1740. else //根据设置自动转换10进制显示
  1741. {
  1742. if (checkBox_ReadRanFlash_ChangeFormat.Checked == true) //10进制显示
  1743. {
  1744. switch (ByteNum)
  1745. {
  1746. case 1:
  1747. {
  1748. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8]) + ", ");
  1749. break;
  1750. }
  1751. case 2:
  1752. {
  1753. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8)) + ", ");
  1754. break;
  1755. }
  1756. case 3:
  1757. {
  1758. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16)) + ", ");
  1759. break;
  1760. }
  1761. case 4:
  1762. {
  1763. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24)) + ", ");
  1764. break;
  1765. }
  1766. default:
  1767. {
  1768. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  1769. break;
  1770. }
  1771. }
  1772. }
  1773. else //16进制显示
  1774. {
  1775. switch (ByteNum)
  1776. {
  1777. case 1:
  1778. {
  1779. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8], 16).PadLeft(2, '0').ToUpper() + ", ");
  1780. break;
  1781. }
  1782. case 2:
  1783. {
  1784. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8), 16).PadLeft(4, '0').ToUpper() + ", ");
  1785. break;
  1786. }
  1787. case 3:
  1788. {
  1789. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16), 16).PadLeft(6, '0').ToUpper() + ", ");
  1790. break;
  1791. }
  1792. case 4:
  1793. {
  1794. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24), 16).PadLeft(8, '0').ToUpper() + ", ");
  1795. break;
  1796. }
  1797. default:
  1798. {
  1799. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  1800. break;
  1801. }
  1802. }
  1803. }
  1804. }
  1805. }));
  1806. }
  1807. break;
  1808. }
  1809. case 0xAB88://故障日志
  1810. {
  1811. unchecked
  1812. {
  1813. this.Invoke((EventHandler)(delegate
  1814. {
  1815. //电机存储的故障日志,一包128字节包含2条故障日志
  1816. var ErrorLogSaveInfo1 = new MC_ErrorLogSaveInfo_Struct_t();
  1817. var ErrorLogSaveInfo2 = new MC_ErrorLogSaveInfo_Struct_t();
  1818. ErrorLogSaveInfo1 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 8);
  1819. ErrorLogSaveInfo2 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 72);
  1820. //数据显示
  1821. ErrorLogDisplay(ErrorLogSaveInfo1, ErrorLogSaveInfo2);
  1822. }));
  1823. }
  1824. break;
  1825. }
  1826. case 0x1401://在线检测结果
  1827. {
  1828. unchecked
  1829. {
  1830. this.Invoke((EventHandler)(delegate
  1831. {
  1832. textBox_Online.Text = Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() + "H";
  1833. }));
  1834. }
  1835. break;
  1836. }
  1837. case 0x1510://骑行历史信息
  1838. {
  1839. unchecked
  1840. {
  1841. this.Invoke((EventHandler)(delegate
  1842. {
  1843. long DataTemp32;
  1844. //ODO里程
  1845. DataTemp32 = (long)((Data[3] << 24) + (Data[2] << 16) + (Data[1] << 8) + Data[0]);
  1846. textBox_OBC_ODO_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  1847. textBox_ODO_KM.Text = DataTemp32.ToString();
  1848. //ODO时间
  1849. DataTemp32 = (long)((Data[7] << 24) + (Data[6] << 16) + (Data[5] << 8) + Data[4]);
  1850. if (DataTemp32 >= 60 * 100000)
  1851. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  1852. else
  1853. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  1854. textBox_ODO_TIME.Text = DataTemp32.ToString();
  1855. //TRIP里程
  1856. DataTemp32 = (long)((Data[11] << 24) + (Data[10] << 16) + (Data[9] << 8) + Data[8]);
  1857. textBox_OBC_TRIP_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  1858. textBox_TRIP_KM.Text = DataTemp32.ToString();
  1859. //TRIP时间
  1860. DataTemp32 = (long)((Data[15] << 24) + (Data[14] << 16) + (Data[13] << 8) + Data[12]);
  1861. if (DataTemp32 >= 60 * 100000)
  1862. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  1863. else
  1864. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  1865. textBox_TRIP_TIME.Text = DataTemp32.ToString();
  1866. }));
  1867. }
  1868. break;
  1869. }
  1870. case 0x1720://客户信息
  1871. {
  1872. unchecked
  1873. {
  1874. this.Invoke((EventHandler)(delegate
  1875. {
  1876. //软件标识
  1877. textBox_SP.Text = "";
  1878. textBox_OBC_ReadSP.Text = "";
  1879. textBox_FacModeSP.Text = "";
  1880. for (ushort i = 0; i < 23; i++)
  1881. {
  1882. if (Data[i] == 'r')
  1883. {
  1884. Data[i] = (byte)'.';
  1885. }
  1886. textBox_SP.Text += ((char)Data[i]).ToString();
  1887. textBox_OBC_ReadSP.Text += ((char)Data[i]).ToString();
  1888. textBox_FacModeSP.Text += ((char)Data[i]).ToString();
  1889. }
  1890. //Git提交版本信息
  1891. textBox_FacModeGit.Text = "";
  1892. for (ushort i = 0; i < 9; i++)
  1893. {
  1894. textBox_SP.Text += ((char)Data[23 + i]).ToString();
  1895. textBox_FacModeGit.Text += ((char)Data[23 + i]).ToString();
  1896. }
  1897. Class_Motor_Ver.Special = textBox_SP.Text;
  1898. }));
  1899. }
  1900. break;
  1901. }
  1902. case 0xBA20: //调试信息
  1903. {
  1904. unchecked
  1905. {
  1906. this.Invoke((EventHandler)(delegate
  1907. {
  1908. MC_DebugInfo_Refresh = true;
  1909. //系统状态机
  1910. DataTemp = (short)(Data[0]);
  1911. textBox_DebugInfo_SysFun.Text = Convert.ToString(DataTemp);
  1912. //二层状态机
  1913. DataTemp = (short)(Data[1]);
  1914. textBox_DebugInfo_SecondFun.Text = Convert.ToString(DataTemp);
  1915. //电机状态机
  1916. DataTemp = (short)(Data[2]);
  1917. textBox_DebugInfo_MotorFun.Text = Convert.ToString(DataTemp);
  1918. //助力状态机
  1919. DataTemp = (short)(Data[3]);
  1920. textBox_DebugInfo_AssistFun.Text = Convert.ToString(DataTemp);
  1921. //IdRef
  1922. DataTemp = (short)(Data[5] * 256 + Data[4]);
  1923. textBox_DebugInfo_IdRef.Text = Convert.ToString(DataTemp);
  1924. //IqRef
  1925. DataTemp = (short)(Data[7] * 256 + Data[6]);
  1926. textBox_DebugInfo_IqRef.Text = Convert.ToString(DataTemp);
  1927. //UdRef
  1928. DataTemp = (short)(Data[9] * 256 + Data[8]);
  1929. textBox_DebugInfo_UdRef.Text = Convert.ToString(DataTemp);
  1930. //UqRef
  1931. DataTemp = (short)(Data[11] * 256 + Data[10]);
  1932. textBox_DebugInfo_UqRef.Text = Convert.ToString(DataTemp);
  1933. //瞬时力矩
  1934. DataTemp = (short)(Data[13] * 256 + Data[12]);
  1935. textBox_DebugInfo_TorquePu.Text = Convert.ToString(DataTemp);
  1936. //时间滤波力矩
  1937. DataTemp = (short)(Data[15] * 256 + Data[14]);
  1938. textBox_DebugInfo_TorqueFil.Text = Convert.ToString(DataTemp);
  1939. //踏频滤波力矩
  1940. DataTemp = (short)(Data[17] * 256 + Data[16]);
  1941. textBox_DebugInfo_TorqueCadence.Text = Convert.ToString(DataTemp);
  1942. //IdFdb
  1943. DataTemp = (short)(Data[19] * 256 + Data[18]);
  1944. textBox_DebugInfo_IdFdb.Text = Convert.ToString(DataTemp);
  1945. //IqFdb
  1946. DataTemp = (short)(Data[21] * 256 + Data[20]);
  1947. textBox_DebugInfo_IqFdb.Text = Convert.ToString(DataTemp);
  1948. //助力输出
  1949. DataTemp = (short)(Data[23] * 256 + Data[22]);
  1950. textBox_DebugInfo_AssistOut.Text = Convert.ToString(DataTemp);
  1951. //数据保存
  1952. RunInfoAutoSave();
  1953. }));
  1954. }
  1955. break;
  1956. }
  1957. case 0xBB20: //产品标签信息
  1958. {
  1959. unchecked
  1960. {
  1961. this.Invoke((EventHandler)(delegate
  1962. {
  1963. //产品标签
  1964. textBox_TagInfo.Text = "";
  1965. for (ushort i = 0; i < 32; i++)
  1966. {
  1967. textBox_TagInfo.Text += ((char)Data[i]).ToString();
  1968. }
  1969. }));
  1970. }
  1971. break;
  1972. }
  1973. case 0xBC20: //内阻校正信息
  1974. {
  1975. unchecked
  1976. {
  1977. this.Invoke((EventHandler)(delegate
  1978. {
  1979. //内阻1
  1980. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  1981. textBox_MOS_R1.Text = Convert.ToString(uData16);
  1982. //内阻2
  1983. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  1984. textBox_MOS_R2.Text = Convert.ToString(uData16);
  1985. //内阻3
  1986. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  1987. textBox_MOS_R3.Text = Convert.ToString(uData16);
  1988. //K1
  1989. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  1990. textBox_MOS_K1.Text = Convert.ToString(uData16);
  1991. //K2
  1992. uData16 = (ushort)(Data[9] * 256 + Data[8]);
  1993. textBox_MOS_K2.Text = Convert.ToString(uData16);
  1994. //K3
  1995. uData16 = (ushort)(Data[11] * 256 + Data[10]);
  1996. textBox_MOS_K3.Text = Convert.ToString(uData16);
  1997. //K4
  1998. uData16 = (ushort)(Data[13] * 256 + Data[12]);
  1999. textBox_MOS_K4.Text = Convert.ToString(uData16);
  2000. //K5
  2001. uData16 = (ushort)(Data[15] * 256 + Data[14]);
  2002. textBox_MOS_K5.Text = Convert.ToString(uData16);
  2003. }));
  2004. }
  2005. break;
  2006. }
  2007. case 0xBD20: //整车信息2
  2008. {
  2009. unchecked
  2010. {
  2011. this.Invoke((EventHandler)(delegate
  2012. {
  2013. richTextBox_BikeParam2.Clear();
  2014. for (int i = 0; i < myParams.BikeParam2.Count; i++)
  2015. {
  2016. richTextBox_BikeParam2.AppendText(myParams.BikeParam2[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  2017. }
  2018. richTextBox_BikeParam2.Text = richTextBox_BikeParam2.Text.Substring(0, richTextBox_BikeParam2.Text.Length - 2);
  2019. }));
  2020. }
  2021. break;
  2022. }
  2023. case 0xBE20: //用户骑行参数
  2024. {
  2025. unchecked
  2026. {
  2027. this.Invoke((EventHandler)(delegate
  2028. {
  2029. richTextBox_UsrRidesParam.Clear();
  2030. for (int i = 0; i < myParams.UsrRideParam.Count; i++)
  2031. {
  2032. richTextBox_UsrRidesParam.AppendText(myParams.UsrRideParam[i] + "=" + Convert.ToString(Data[i]) + ", ");
  2033. }
  2034. richTextBox_UsrRidesParam.Text = richTextBox_UsrRidesParam.Text.Substring(0, richTextBox_UsrRidesParam.Text.Length - 2);
  2035. }));
  2036. }
  2037. break;
  2038. }
  2039. case 0xC109: //Boot版本信息
  2040. {
  2041. BootInfo = "";
  2042. for (ushort i = 0; i < 9; i++)
  2043. {
  2044. BootInfo += ((char)Data[i]).ToString();
  2045. }
  2046. break;
  2047. }
  2048. default:
  2049. {
  2050. break;
  2051. }
  2052. }
  2053. }
  2054. #endregion
  2055. #region 解析BMS广播的命令
  2056. else if (ID == 0x720)
  2057. {
  2058. switch (CmdTemp)
  2059. {
  2060. case 0x1010://BMS运行信息
  2061. {
  2062. unchecked
  2063. {
  2064. this.Invoke((EventHandler)(delegate
  2065. {
  2066. BMS_RunInfo_Refresh = true;
  2067. richTextBox_OBC_BMS_RunInfo.Clear();
  2068. //电压
  2069. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  2070. richTextBox_OBC_BMS_RunInfo.AppendText("电压:" + Convert.ToString(uData16) + " mV" + "\r\n");
  2071. //电流
  2072. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  2073. richTextBox_OBC_BMS_RunInfo.AppendText("电流:" + Convert.ToString(uData16) + " mA" + "\r\n");
  2074. //剩余容量
  2075. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  2076. richTextBox_OBC_BMS_RunInfo.AppendText("剩余容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  2077. //满充容量
  2078. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  2079. richTextBox_OBC_BMS_RunInfo.AppendText("满充容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  2080. //电芯温度
  2081. richTextBox_OBC_BMS_RunInfo.AppendText("电芯温度:" + Convert.ToString((int)(Data[8] - 40) + " ℃" + "\r\n"));
  2082. //剩余电量
  2083. richTextBox_OBC_BMS_RunInfo.AppendText("剩余电量:" + Convert.ToString(Data[9]) + " %" + "\r\n");
  2084. //电池状态
  2085. richTextBox_OBC_BMS_RunInfo.AppendText("电池状态:" + Convert.ToString(Data[10], 16).PadLeft(2, '0').ToUpper() + " H" + "\r\n");
  2086. //SOH
  2087. richTextBox_OBC_BMS_RunInfo.AppendText("电池寿命:" + Convert.ToString(Data[11]) + " %" + "\r\n");
  2088. //循环次数
  2089. richTextBox_OBC_BMS_RunInfo.AppendText("循环次数:" + Convert.ToString((ushort)(Data[13] * 256 + Data[12])) + " 次");
  2090. }));
  2091. }
  2092. break;
  2093. }
  2094. default: break;
  2095. }
  2096. }
  2097. #endregion
  2098. #region 解析电机发送OBC的命令
  2099. else if (ID == 0x713)
  2100. {
  2101. switch (CmdTemp)
  2102. {
  2103. case 0x5408://电机用户参数
  2104. {
  2105. unchecked
  2106. {
  2107. this.Invoke((EventHandler)(delegate
  2108. {
  2109. richTextBox_OBC_ReadUserInfo.Clear();
  2110. //默认周长
  2111. richTextBox_OBC_ReadUserInfo.AppendText("默认周长:" + Convert.ToString((int)Data[0]) + " cm" + "\r\n");
  2112. //启动模式
  2113. richTextBox_OBC_ReadUserInfo.AppendText("启动模式:" + ((Data[1] == 0x01) ? "柔和" : (Data[1] == 0x02) ? "正常" : (Data[1] == 0x03) ? "强劲" : "无效") + "\r\n");
  2114. comboBox_OBC_StartMode.SelectedIndex = Data[1] - 1;
  2115. //限速
  2116. richTextBox_OBC_ReadUserInfo.AppendText("限速:" + Convert.ToString(Data[2]) + " km/h" + "\r\n");
  2117. //周长微调
  2118. numericUpDown_OBC_WheelAdj.Value = (int)(Data[3] > 128 ? (Data[3] - 256) : Data[3]);
  2119. richTextBox_OBC_ReadUserInfo.AppendText("周长微调:" + Convert.ToString(numericUpDown_OBC_WheelAdj.Value) + " cm" + "\r\n");
  2120. //助力方案
  2121. richTextBox_OBC_ReadUserInfo.AppendText("助力方案:" + Convert.ToString(Data[4]) + "\r\n");
  2122. comboBox_OBC_AssistFunc.SelectedIndex = Data[4] - 1;
  2123. //关机时间
  2124. richTextBox_OBC_ReadUserInfo.AppendText("关机时间:" + Convert.ToString(Data[5]) + " min" + "\r\n");
  2125. numericUpDown_OBC_OffTime.Value = (int)Data[5];
  2126. //限速微调
  2127. numericUpDown_OBC_SpeedLimitAdj.Value = (int)(Data[6] > 128 ? (Data[6] - 256) : Data[6]);
  2128. richTextBox_OBC_ReadUserInfo.AppendText("限速微调:" + Convert.ToString(numericUpDown_OBC_SpeedLimitAdj.Value) + " km/h" + "\r\n");
  2129. //定速巡航
  2130. comboBox_OBC_BikeCCS.SelectedIndex = (Data[7] == 0xAA) ? 1 : 2;
  2131. richTextBox_OBC_ReadUserInfo.AppendText("转把巡航:" + comboBox_OBC_BikeCCS.Text + "\r\n");
  2132. }));
  2133. }
  2134. break;
  2135. }
  2136. case 0x5303://电机应答反馈
  2137. {
  2138. unchecked
  2139. {
  2140. this.Invoke((EventHandler)(delegate
  2141. {
  2142. timer_1s.Enabled = false;
  2143. MessageBoxTimeOut.Show("OK", "反馈指令", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  2144. timer_1s.Enabled = true;
  2145. }));
  2146. }
  2147. break;
  2148. }
  2149. case 0x5620: //用户骑行参数
  2150. {
  2151. unchecked
  2152. {
  2153. this.Invoke((EventHandler)(delegate
  2154. {
  2155. richTextBox_UsrRidesParam.Clear();
  2156. for (int i = 0; i < myParams.UsrRideParam.Count; i++)
  2157. {
  2158. richTextBox_UsrRidesParam.AppendText(myParams.UsrRideParam[i] + "=" + Convert.ToString(Data[i]) + ", ");
  2159. }
  2160. richTextBox_UsrRidesParam.Text = richTextBox_UsrRidesParam.Text.Substring(0, richTextBox_UsrRidesParam.Text.Length - 2);
  2161. }));
  2162. }
  2163. break;
  2164. }
  2165. default: break;
  2166. }
  2167. }
  2168. #endregion
  2169. }
  2170. private void DataRevToString(ushort CmdTemp, byte[] Data)
  2171. {
  2172. CmdRevStrTemp = "";
  2173. CmdRevStrTemp += Convert.ToString(CmdTemp >> 8, 16).PadLeft(2, '0').ToUpper() + " ";
  2174. CmdRevStrTemp += Convert.ToString(CmdTemp & 0xFF, 16).PadLeft(2, '0').ToUpper() + " ";
  2175. ushort len = (ushort)(CmdTemp & 0x00FF);
  2176. for (int i = 0; i < len ; i++)
  2177. {
  2178. CmdRevStrTemp += Convert.ToString(Data[i], 16).PadLeft(2, '0').ToUpper() + " ";
  2179. }
  2180. }
  2181. #endregion
  2182. /// <summary>
  2183. /// 端口连接或断开
  2184. /// </summary>
  2185. private void PortConnect()
  2186. {
  2187. bool result = false;
  2188. if (连接ToolStripMenuItem.Text == "连接")
  2189. {
  2190. result = mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, 连接开机ToolStripMenuItem.Checked, 识别通讯盒ToolStripMenuItem.Checked);
  2191. if (result)
  2192. {
  2193. toolStripComboBox_ComNum.Enabled = false;
  2194. toolStripComboBox_Baudrate.Enabled = false;
  2195. 刷新ToolStripMenuItem.Enabled = false;
  2196. 连接ToolStripMenuItem.Text = "断开";
  2197. 连接ToolStripMenuItem.Checked = true;
  2198. label_COM_Sta.Text = toolStripComboBox_ComNum.Text + "已连接," + toolStripComboBox_Baudrate.Text;
  2199. label_PortStatus.BackColor = Color.Green;
  2200. }
  2201. }
  2202. else if (连接ToolStripMenuItem.Text == "断开")
  2203. {
  2204. checkBox_OBC_StartSetGearSt.Checked = false;
  2205. checkBox_OBC_StartReadBMS.Checked = false;
  2206. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2207. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  2208. toolStripComboBox_ComNum.Enabled = true;
  2209. toolStripComboBox_Baudrate.Enabled = true;
  2210. 刷新ToolStripMenuItem.Enabled = true;
  2211. 连接ToolStripMenuItem.Text = "连接";
  2212. 连接ToolStripMenuItem.Checked = false;
  2213. label_COM_Sta.Text = "连接状态:未连接";
  2214. label_PortStatus.BackColor = Color.Red;
  2215. }
  2216. }
  2217. /// <summary>
  2218. /// 端口连接事件
  2219. /// </summary>
  2220. /// <param name="sender"></param>
  2221. /// <param name="e"></param>
  2222. private void 连接ToolStripMenuItem_Click(object sender, System.EventArgs e)
  2223. {
  2224. PortConnect();
  2225. }
  2226. /// <summary>
  2227. /// 端口号刷新事件
  2228. /// </summary>
  2229. /// <param name="sender"></param>
  2230. /// <param name="e"></param>
  2231. private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
  2232. {
  2233. toolStripComboBox_ComNum.Items.Clear();
  2234. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  2235. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
  2236. }
  2237. /// <summary>
  2238. /// 转速调节事件
  2239. /// </summary>
  2240. /// <param name="sender"></param>
  2241. /// <param name="e"></param>
  2242. private void numericUpDown_SpeedAdj_ValueChanged(object sender, EventArgs e)
  2243. {
  2244. //生产模式转速设置值更新
  2245. trackBar_FacModeMotorSpeedAdj.Value = (int)numericUpDown_SpeedAdj.Value;
  2246. label_FacModeMotorSpeedSet.Text = trackBar_FacModeMotorSpeedAdj.Value.ToString() + "%";
  2247. //设置转速百分比
  2248. var Data = new byte[1];
  2249. Data[0] = (byte)numericUpDown_SpeedAdj.Value;
  2250. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  2251. }
  2252. /// <summary>
  2253. /// 存储标志修改事件
  2254. /// </summary>
  2255. /// <param name="sender"></param>
  2256. /// <param name="e"></param>
  2257. private void 写入存储ToolStripMenuItem_Click(object sender, EventArgs e)
  2258. {
  2259. if (写入存储ToolStripMenuItem.Checked)
  2260. {
  2261. EnterForm1.ShowDialog();
  2262. try
  2263. {
  2264. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  2265. {
  2266. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  2267. {
  2268. 写入存储ToolStripMenuItem.Checked = false;
  2269. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  2270. }
  2271. else
  2272. {
  2273. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2274. }
  2275. }
  2276. else
  2277. {
  2278. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2279. }
  2280. }
  2281. catch (Exception)
  2282. {
  2283. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2284. }
  2285. }
  2286. else
  2287. {
  2288. 写入存储ToolStripMenuItem.Checked = true;
  2289. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  2290. }
  2291. }
  2292. /// <summary>
  2293. /// 1s定时器
  2294. /// </summary>
  2295. /// <param name="sender"></param>
  2296. /// <param name="e"></param>
  2297. private void timer_1s_Tick(object sender, EventArgs e)
  2298. {
  2299. //时间更新
  2300. label_SystemTime.Text = "系统时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2301. //MC_Runinfo超时清除
  2302. if (MC_RunInfo_Refresh == false)
  2303. {
  2304. MC_RunInfo_Refresh_Cnt++;
  2305. if (MC_RunInfo_Refresh_Cnt > 10)//5s
  2306. {
  2307. MC_RunInfo_Clear();
  2308. MC_RunInfo_Refresh_Cnt = 0;
  2309. }
  2310. }
  2311. else
  2312. {
  2313. MC_RunInfo_Refresh_Cnt = 0;
  2314. }
  2315. MC_RunInfo_Refresh = false;
  2316. //MC_Debuginfo超时清除
  2317. if (MC_DebugInfo_Refresh == false)
  2318. {
  2319. MC_DebugInfo_Refresh_Cnt++;
  2320. if (MC_DebugInfo_Refresh_Cnt > 10)//5s
  2321. {
  2322. MC_DebugInfo_Clear();
  2323. MC_DebugInfo_Refresh_Cnt = 0;
  2324. }
  2325. }
  2326. else
  2327. {
  2328. MC_DebugInfo_Refresh_Cnt = 0;
  2329. }
  2330. MC_DebugInfo_Refresh = false;
  2331. //BMS_RunInfo超时清除
  2332. if (BMS_RunInfo_Refresh == false)
  2333. {
  2334. BMS_RunInfo_Refresh_Cnt++;
  2335. if (BMS_RunInfo_Refresh_Cnt > 10)//5s
  2336. {
  2337. richTextBox_OBC_BMS_RunInfo.Clear();
  2338. BMS_RunInfo_Refresh_Cnt = 0;
  2339. }
  2340. }
  2341. else
  2342. {
  2343. BMS_RunInfo_Refresh_Cnt = 0;
  2344. }
  2345. BMS_RunInfo_Refresh = false;
  2346. //故障码超时清除
  2347. if (MC_ErrorCode_Refresh == false)
  2348. {
  2349. MC_ErrorCode_Refresh_Cnt++;
  2350. if (MC_ErrorCode_Refresh_Cnt > 10)//5s
  2351. {
  2352. textBox_ErrorCode.Text = "---";
  2353. MC_ErrorCode_Refresh_Cnt = 0;
  2354. }
  2355. }
  2356. else
  2357. {
  2358. MC_ErrorCode_Refresh_Cnt = 0;
  2359. }
  2360. MC_ErrorCode_Refresh = false;
  2361. //CDL连接超时
  2362. if (识别通讯盒ToolStripMenuItem.Checked)
  2363. {
  2364. if (mySerialProcess.CDL_Online_Flag == false)
  2365. {
  2366. mySerialProcess.CDL_OnlineCheck_Cnt++;
  2367. if (mySerialProcess.CDL_OnlineCheck_Cnt > 1)//1s
  2368. {
  2369. timer_1s.Enabled = false;
  2370. MessageBox.Show("连接失败!", "提示");
  2371. timer_1s.Enabled = true;
  2372. //关闭串口
  2373. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  2374. toolStripComboBox_ComNum.Enabled = true;
  2375. toolStripComboBox_Baudrate.Enabled = true;
  2376. 刷新ToolStripMenuItem.Enabled = true;
  2377. 连接ToolStripMenuItem.Text = "连接";
  2378. 连接ToolStripMenuItem.Checked = false;
  2379. label_COM_Sta.Text = "连接状态:未连接";
  2380. label_PortStatus.BackColor = Color.Red;
  2381. }
  2382. }
  2383. }
  2384. //OBC定时发送设置档位
  2385. if (checkBox_OBC_StartSetGearSt.Checked == true)
  2386. {
  2387. var CtrlCode = new byte[2];
  2388. if (comboBox_OBC_SetGearST.SelectedIndex == 5)//档位
  2389. CtrlCode[0] = 0x33;
  2390. else if (comboBox_OBC_SetGearST.SelectedIndex == 6)//档位
  2391. CtrlCode[0] = 0x22;
  2392. else
  2393. CtrlCode[0] = (byte)comboBox_OBC_SetGearST.SelectedIndex;
  2394. if (comboBox_OBC_LightSw.SelectedIndex == 0)//车灯
  2395. CtrlCode[1] = 0xF1;
  2396. else
  2397. CtrlCode[1] = 0xF0;
  2398. if (!mySerialProcess.SendCmdWithoutNotice((ushort)0x731, (byte)0x0C, (ushort)0x3002, CtrlCode))
  2399. {
  2400. checkBox_OBC_StartSetGearSt.Checked = false;
  2401. }
  2402. }
  2403. //OBC定时发送查询电池
  2404. if (checkBox_OBC_StartReadBMS.Checked == true)
  2405. {
  2406. if (!mySerialProcess.SendCmd((ushort)0x732, (byte)0x11, (ushort)0x5000, null))
  2407. {
  2408. checkBox_OBC_StartReadBMS.Checked = false;
  2409. }
  2410. }
  2411. //定时读取存储器
  2412. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  2413. {
  2414. var Address = new byte[4];
  2415. UInt32 Address_Begin;
  2416. UInt32 Addres_End;
  2417. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  2418. richTextBox_RamFlasgData.Clear();
  2419. do
  2420. {
  2421. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  2422. {
  2423. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2424. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2425. continue;
  2426. }
  2427. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  2428. {
  2429. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2430. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2431. continue;
  2432. }
  2433. else
  2434. {
  2435. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  2436. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2437. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  2438. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2439. if (Addres_End < Address_Begin)
  2440. {
  2441. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2442. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2443. continue;
  2444. }
  2445. else
  2446. {
  2447. var SendByte = new byte[8];
  2448. SendByte[0] = (byte)(Address_Begin >> 24);
  2449. SendByte[1] = (byte)(Address_Begin >> 16);
  2450. SendByte[2] = (byte)(Address_Begin >> 8);
  2451. SendByte[3] = (byte)(Address_Begin);
  2452. SendByte[4] = (byte)(Addres_End >> 24);
  2453. SendByte[5] = (byte)(Addres_End >> 16);
  2454. SendByte[6] = (byte)(Addres_End >> 8);
  2455. SendByte[7] = (byte)(Addres_End);
  2456. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte))
  2457. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2458. }
  2459. }
  2460. } while (false);
  2461. }
  2462. //写入参数等待计时
  2463. ACK_WaitCnt++;
  2464. }
  2465. /// <summary>
  2466. /// 运行信息清除
  2467. /// </summary>
  2468. private void MC_RunInfo_Clear()
  2469. {
  2470. foreach (Control c in tabPage_RunInfo.Controls)
  2471. {
  2472. if ((c is TextBox))
  2473. {
  2474. if (c.Name != textBox_ErrorCode.ToString())
  2475. c.Text = "---";
  2476. }
  2477. }
  2478. }
  2479. /// <summary>
  2480. /// 调试信息清除
  2481. /// </summary>
  2482. private void MC_DebugInfo_Clear()
  2483. {
  2484. foreach (Control c in tabPage_DebugInfo.Controls)
  2485. {
  2486. if ((c is TextBox))
  2487. {
  2488. if (c.Name != textBox_ErrorCode.ToString())
  2489. c.Text = "---";
  2490. }
  2491. }
  2492. }
  2493. /// <summary>
  2494. /// 读取马达参数
  2495. /// </summary>
  2496. /// <param name="sender"></param>
  2497. /// <param name="e"></param>
  2498. private void button_Read_MotorParam_Click(object sender, EventArgs e)
  2499. {
  2500. richTextBox_MotorParam.Clear();
  2501. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null);
  2502. }
  2503. /// <summary>
  2504. /// 写入马达参数
  2505. /// </summary>
  2506. /// <param name="sender"></param>
  2507. /// <param name="e"></param>
  2508. private void button_Write_Click(object sender, EventArgs e)
  2509. {
  2510. var ConfigParam = new byte[40];
  2511. for (int i = 0; i < 40; i++)
  2512. ConfigParam[i] = 0;
  2513. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2514. short wDataTemp = 0;
  2515. ushort DataTemp = 0;
  2516. string[] strDataTemp = richTextBox_MotorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2517. try
  2518. {
  2519. for (int i = 0; i < strDataTemp.Length; i++)
  2520. {
  2521. if (i == 6)
  2522. {
  2523. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  2524. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  2525. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  2526. }
  2527. else
  2528. {
  2529. DataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2530. ConfigParam[2 * i + 2] = (byte)DataTemp;
  2531. ConfigParam[2 * i + 3] = (byte)(DataTemp >> 8);
  2532. }
  2533. }
  2534. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B28, ConfigParam);
  2535. }
  2536. catch (Exception)
  2537. {
  2538. timer_1s.Enabled = false;
  2539. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2540. timer_1s.Enabled = true;
  2541. }
  2542. }
  2543. /// <summary>
  2544. /// 读取整车信息
  2545. /// </summary>
  2546. /// <param name="sender"></param>
  2547. /// <param name="e"></param>
  2548. private void button_ReadBikeParam_Click(object sender, EventArgs e)
  2549. {
  2550. richTextBox_BikeParam.Clear();
  2551. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null);
  2552. }
  2553. /// <summary>
  2554. /// 写入整车信息
  2555. /// </summary>
  2556. /// <param name="sender"></param>
  2557. /// <param name="e"></param>
  2558. private void button_WriteBikeParam_Click(object sender, EventArgs e)
  2559. {
  2560. var ConfigParam = new byte[28];
  2561. for (int i = 0; i < 28; i++)
  2562. ConfigParam[i] = 0;
  2563. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2564. string[] strDataTemp = richTextBox_BikeParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2565. try
  2566. {
  2567. for (int i = 0; i < strDataTemp.Length; i++)
  2568. {
  2569. short wDataTemp = 0;
  2570. //前后灯参数修改
  2571. if (i == 8)
  2572. {
  2573. wDataTemp |= (short)((comboBox_TailLightMode.SelectedIndex + 1) << 12); //Bit15~Bit12:尾灯模式
  2574. wDataTemp |= (short)((comboBox_TailLightVol.SelectedIndex == 0 ? 6 : 12) << 8); //Bit11~Bit8:尾灯电压
  2575. wDataTemp |= (short)(comboBox_FrontLightVol.SelectedIndex == 0 ? 6 : 12); //Bit7~Bit0:前灯电压
  2576. }
  2577. //开关机参数
  2578. else if (i == 11)
  2579. {
  2580. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOnDelay.Text) << 12);
  2581. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOffDelay.Text) << 8);
  2582. wDataTemp |= (short)(Convert.ToInt16(textBox_AutoPowerOff.Text));
  2583. }
  2584. else
  2585. {
  2586. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  2587. }
  2588. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  2589. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  2590. }
  2591. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D1C, ConfigParam);
  2592. }
  2593. catch (Exception)
  2594. {
  2595. timer_1s.Enabled = false;
  2596. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2597. timer_1s.Enabled = true;
  2598. }
  2599. }
  2600. /// <summary>
  2601. /// 读取控制器参数
  2602. /// </summary>
  2603. /// <param name="sender"></param>
  2604. /// <param name="e"></param>
  2605. private void button_ReadControlParam_Click(object sender, EventArgs e)
  2606. {
  2607. richTextBox_ControlParam.Clear();
  2608. comboBox_Bike_CCS.SelectedIndex = 0;
  2609. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
  2610. }
  2611. /// <summary>
  2612. /// 写入控制器参数
  2613. /// </summary>
  2614. /// <param name="sender"></param>
  2615. /// <param name="e"></param>
  2616. private void button_WriteControlParam_Click(object sender, EventArgs e)
  2617. {
  2618. var ConfigParam = new byte[34];
  2619. for (int i = 0; i < 34; i++)
  2620. ConfigParam[i] = 0;
  2621. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2622. ushort uwDataTemp = 0;
  2623. string[] strDataTemp = richTextBox_ControlParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2624. try
  2625. {
  2626. for (int i = 0; i < strDataTemp.Length; i++)
  2627. {
  2628. if (i == 13)
  2629. {
  2630. uwDataTemp = (comboBox_Bike_CCS.SelectedIndex == 1) ? (ushort)0x00AA : (ushort)0x0000;
  2631. }
  2632. else
  2633. {
  2634. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2635. }
  2636. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2637. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2638. }
  2639. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3F22, ConfigParam);
  2640. }
  2641. catch (Exception)
  2642. {
  2643. timer_1s.Enabled = false;
  2644. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2645. timer_1s.Enabled = true;
  2646. }
  2647. }
  2648. /// <summary>
  2649. /// 读取助力参数
  2650. /// </summary>
  2651. /// <param name="sender"></param>
  2652. /// <param name="e"></param>
  2653. private void button_ReadAssistParam_Click(object sender, EventArgs e)
  2654. {
  2655. var ConfigParam = new byte[4];
  2656. int AssistNum = 0;
  2657. try
  2658. {
  2659. AssistNum = Convert.ToInt32(comboBox_AssistTorque.Text);
  2660. ConfigParam[0] = (byte)(AssistNum & 0xFF);
  2661. ConfigParam[1] = (byte)(AssistNum >> 8);
  2662. AssistNum = Convert.ToInt32(comboBox_AssistCadence.Text);
  2663. ConfigParam[2] = (byte)(AssistNum & 0xFF);
  2664. ConfigParam[3] = (byte)(AssistNum >> 8);
  2665. richTextBox_AssistParam.Clear();
  2666. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam);
  2667. }
  2668. catch (Exception)
  2669. {
  2670. timer_1s.Enabled = false;
  2671. MessageBox.Show("请选择助力参数编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2672. timer_1s.Enabled = true;
  2673. }
  2674. }
  2675. /// <summary>
  2676. /// 写入助力参数
  2677. /// </summary>
  2678. /// <param name="sender"></param>
  2679. /// <param name="e"></param>
  2680. private void button_WriteAssistParam_Click(object sender, EventArgs e)
  2681. {
  2682. var ConfigParam = new byte[80];
  2683. for (int i = 0; i < 80; i++)
  2684. ConfigParam[i] = 0;
  2685. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2686. long lDataTemp = 0;
  2687. string[] strDataTemp = richTextBox_AssistParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2688. int index_1 = 0, index_2 = 0;
  2689. try
  2690. {
  2691. for (int i = 0; i < strDataTemp.Length; i++)
  2692. {
  2693. if (strDataTemp[i].Split('=')[0] == "转矩曲线.a")
  2694. {
  2695. index_1 = i;
  2696. break;
  2697. }
  2698. }
  2699. for (int i = 0; i < strDataTemp.Length; i++)
  2700. {
  2701. if (strDataTemp[i].Split('=')[0] == "踏频曲线.d")
  2702. {
  2703. index_2 = i;
  2704. break;
  2705. }
  2706. }
  2707. for (int i = 0; i < strDataTemp.Length; i++)
  2708. {
  2709. lDataTemp = Convert.ToInt32(strDataTemp[i].Split('=')[1]);
  2710. if (i < index_1)
  2711. {
  2712. ConfigParam[2 * i + 4] = (byte)lDataTemp;
  2713. ConfigParam[2 * i + 5] = (byte)(lDataTemp >> 8);
  2714. }
  2715. else if (i <= index_2)
  2716. {
  2717. ConfigParam[4 * i - 4] = (byte)lDataTemp;
  2718. ConfigParam[4 * i - 3] = (byte)(lDataTemp >> 8);
  2719. ConfigParam[4 * i - 2] = (byte)(lDataTemp >> 16);
  2720. ConfigParam[4 * i - 1] = (byte)(lDataTemp >> 24);
  2721. }
  2722. else
  2723. {
  2724. ConfigParam[2 * i + 20] = (byte)lDataTemp;
  2725. ConfigParam[2 * i + 21] = (byte)(lDataTemp >> 8);
  2726. }
  2727. }
  2728. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4450, ConfigParam);
  2729. }
  2730. catch (Exception)
  2731. {
  2732. timer_1s.Enabled = false;
  2733. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2734. timer_1s.Enabled = true;
  2735. }
  2736. }
  2737. /// <summary>
  2738. /// 读取调试参数
  2739. /// </summary>
  2740. /// <param name="sender"></param>
  2741. /// <param name="e"></param>
  2742. private void button_ReadDebugParam_Click(object sender, EventArgs e)
  2743. {
  2744. richTextBox_DebugParam.Clear();
  2745. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  2746. }
  2747. /// <summary>
  2748. /// 写入调试参数
  2749. /// </summary>
  2750. /// <param name="sender"></param>
  2751. /// <param name="e"></param>
  2752. private void button_WriteDebugParam_Click(object sender, EventArgs e)
  2753. {
  2754. var ConfigParam = new byte[60];
  2755. for (int i = 0; i < 60; i++)
  2756. ConfigParam[i] = 0;
  2757. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2758. ushort uwDataTemp = 0;
  2759. string[] strDataTemp = richTextBox_DebugParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2760. try
  2761. {
  2762. for (int i = 0; i < strDataTemp.Length; i++)
  2763. {
  2764. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2765. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2766. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2767. }
  2768. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam);
  2769. }
  2770. catch (Exception)
  2771. {
  2772. timer_1s.Enabled = false;
  2773. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2774. timer_1s.Enabled = true;
  2775. }
  2776. }
  2777. /// <summary>
  2778. /// 读取历史
  2779. /// </summary>
  2780. /// <param name="sender"></param>
  2781. /// <param name="e"></param>
  2782. private void button_ReadRecord_Click(object sender, EventArgs e)
  2783. {
  2784. richTextBox_Record.Clear();
  2785. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null);
  2786. }
  2787. /// <summary>
  2788. /// 读取传感器参数
  2789. /// </summary>
  2790. /// <param name="sender"></param>
  2791. /// <param name="e"></param>
  2792. private void button_ReadSensorParam_Click(object sender, EventArgs e)
  2793. {
  2794. richTextBox_SensorParam.Clear();
  2795. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  2796. }
  2797. /// <summary>
  2798. /// 写入力矩传感器标定值
  2799. /// </summary>
  2800. /// <param name="sender"></param>
  2801. /// <param name="e"></param>
  2802. private void button_Write_Cal_Click(object sender, EventArgs e)
  2803. {
  2804. var ConfigParam = new byte[4];
  2805. for (int i = 0; i < 4; i++)
  2806. ConfigParam[i] = 0;
  2807. ushort uwDataTemp = 0;
  2808. try
  2809. {
  2810. uwDataTemp = Convert.ToUInt16(comboBox_TorqueSet.Text);//负载序号
  2811. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  2812. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  2813. uwDataTemp = (ushort)(decimal.Parse(textBox_Load.Text) * 10); ;//负载值0.1Nm
  2814. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  2815. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  2816. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  2817. }
  2818. catch (Exception)
  2819. {
  2820. timer_1s.Enabled = false;
  2821. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2822. timer_1s.Enabled = true;
  2823. }
  2824. }
  2825. /// <summary>
  2826. /// 写入传感器参数
  2827. /// </summary>
  2828. /// <param name="sender"></param>
  2829. /// <param name="e"></param>
  2830. private void button_WriteSensorParam_Click(object sender, EventArgs e)
  2831. {
  2832. var ConfigParam = new byte[14];
  2833. for (int i = 0; i < 14; i++)
  2834. ConfigParam[i] = 0;
  2835. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2836. ushort uwDataTemp = 0;
  2837. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  2838. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2839. int index = 0;
  2840. try
  2841. {
  2842. for (int i = 0; i < strDataTemp.Length; i++)
  2843. {
  2844. if (strDataTemp[i].Split('=')[0] == "力矩传感器踏频脉冲数")
  2845. {
  2846. index = i;
  2847. break;
  2848. }
  2849. }
  2850. for (int i = 0; i < (strDataTemp.Length - index); i++)
  2851. {
  2852. uwDataTemp = Convert.ToUInt16(strDataTemp[i + index].Split('=')[1]);
  2853. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2854. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2855. }
  2856. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x420E, ConfigParam);
  2857. }
  2858. catch (Exception)
  2859. {
  2860. timer_1s.Enabled = false;
  2861. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2862. timer_1s.Enabled = true;
  2863. }
  2864. }
  2865. /// <summary>
  2866. /// 写入型号
  2867. /// </summary>
  2868. /// <param name="sender"></param>
  2869. /// <param name="e"></param>
  2870. private void button_WriteModel_Click(object sender, EventArgs e)
  2871. {
  2872. string Mode = textBox_Model.Text;
  2873. var ModeArray = new byte[16];
  2874. for (ushort i = 0; i < Mode.Length; i++)
  2875. {
  2876. ModeArray[i] = (byte)Mode[i];
  2877. }
  2878. if (Mode.Length < 16)
  2879. {
  2880. ModeArray[Mode.Length] = (byte)'.';
  2881. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  2882. {
  2883. ModeArray[Mode.Length + 1 + i] = 0x20;
  2884. }
  2885. }
  2886. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  2887. }
  2888. /// <summary>
  2889. /// 写入SN
  2890. /// </summary>
  2891. /// <param name="sender"></param>
  2892. /// <param name="e"></param>
  2893. private void button_WriteSN_Click(object sender, EventArgs e)
  2894. {
  2895. string SN = textBox_SN.Text;
  2896. var SNArray = new byte[16];
  2897. for (ushort i = 0; i < SN.Length; i++)
  2898. {
  2899. SNArray[i] = (byte)SN[i];
  2900. }
  2901. if (SN.Length < 16)
  2902. {
  2903. SNArray[SN.Length] = (byte)'.';
  2904. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  2905. {
  2906. SNArray[SN.Length + 1 + i] = 0x20;
  2907. }
  2908. }
  2909. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  2910. }
  2911. /// <summary>
  2912. /// 查询版本信息
  2913. /// </summary>
  2914. /// <param name="sender"></param>
  2915. /// <param name="e"></param>
  2916. private void button_ReadVersion_Click(object sender, EventArgs e)
  2917. {
  2918. textBox_Model.Text = "---";
  2919. textBox_SN.Text = "---";
  2920. textBox_HW.Text = "---";
  2921. textBox_FW.Text = "---";
  2922. textBox_SP.Text = "---";
  2923. textBox_OBC_ReadModel.Text = "---";
  2924. textBox_OBC_ReadSN.Text = "---";
  2925. textBox_OBC_ReadHW.Text = "---";
  2926. textBox_OBC_ReadFW.Text = "---";
  2927. textBox_OBC_ReadSP.Text = "---";
  2928. textBox_FacModeName.Text = "---";
  2929. textBox_FacModeNum.Text = "---";
  2930. textBox_FacModeHW.Text = "---";
  2931. textBox_FacModeFW.Text = "---";
  2932. textBox_FacModeSP.Text = "---";
  2933. Class_Motor_Ver.Mode = "---";
  2934. Class_Motor_Ver.SN = "---";
  2935. Class_Motor_Ver.HW = "---";
  2936. Class_Motor_Ver.FW = "---";
  2937. Class_Motor_Ver.Special = "---";
  2938. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  2939. }
  2940. /// <summary>
  2941. /// 查询自定义1
  2942. /// </summary>
  2943. /// <param name="sender"></param>
  2944. /// <param name="e"></param>
  2945. private void button_ReadUser1_Click(object sender, EventArgs e)
  2946. {
  2947. textBox_User1.Text = "---";
  2948. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null);
  2949. }
  2950. /// <summary>
  2951. /// 查询自定义2
  2952. /// </summary>
  2953. /// <param name="sender"></param>
  2954. /// <param name="e"></param>
  2955. private void button_ReadUser2_Click(object sender, EventArgs e)
  2956. {
  2957. textBox_User2.Text = "---";
  2958. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null);
  2959. }
  2960. /// <summary>
  2961. /// 查询自定义3
  2962. /// </summary>
  2963. /// <param name="sender"></param>
  2964. /// <param name="e"></param>
  2965. private void button_ReadUser3_Click(object sender, EventArgs e)
  2966. {
  2967. textBox_User3.Text = "---";
  2968. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null);
  2969. }
  2970. /// <summary>
  2971. /// 写入自定义字符串1
  2972. /// </summary>
  2973. /// <param name="sender"></param>
  2974. /// <param name="e"></param>
  2975. private void button_WriteUser1_Click(object sender, EventArgs e)
  2976. {
  2977. string User = textBox_User1.Text;
  2978. var UserArray = new byte[16];
  2979. for (ushort i = 0; i < User.Length; i++)
  2980. {
  2981. UserArray[i] = (byte)User[i];
  2982. }
  2983. if (User.Length < 16)
  2984. {
  2985. UserArray[User.Length] = (byte)'.';
  2986. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  2987. {
  2988. UserArray[User.Length + 1 + i] = 0x20;
  2989. }
  2990. }
  2991. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1410, UserArray);
  2992. }
  2993. /// <summary>
  2994. /// 写入自定义字符串2
  2995. /// </summary>
  2996. /// <param name="sender"></param>
  2997. /// <param name="e"></param>
  2998. private void button_WriteUser2_Click(object sender, EventArgs e)
  2999. {
  3000. string User = textBox_User2.Text;
  3001. var UserArray = new byte[16];
  3002. for (ushort i = 0; i < User.Length; i++)
  3003. {
  3004. UserArray[i] = (byte)User[i];
  3005. }
  3006. if (User.Length < 16)
  3007. {
  3008. UserArray[User.Length] = (byte)'.';
  3009. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3010. {
  3011. UserArray[User.Length + 1 + i] = 0x20;
  3012. }
  3013. }
  3014. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1610, UserArray);
  3015. }
  3016. /// <summary>
  3017. /// 写入自定义字符串3
  3018. /// </summary>
  3019. /// <param name="sender"></param>
  3020. /// <param name="e"></param>
  3021. private void button_WriteUser3_Click(object sender, EventArgs e)
  3022. {
  3023. string User = textBox_User3.Text;
  3024. var UserArray = new byte[16];
  3025. for (ushort i = 0; i < User.Length; i++)
  3026. {
  3027. UserArray[i] = (byte)User[i];
  3028. }
  3029. if (User.Length < 16)
  3030. {
  3031. UserArray[User.Length] = (byte)'.';
  3032. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3033. {
  3034. UserArray[User.Length + 1 + i] = 0x20;
  3035. }
  3036. }
  3037. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1810, UserArray);
  3038. }
  3039. /// <summary>
  3040. /// 查询生产信息
  3041. /// </summary>
  3042. /// <param name="sender"></param>
  3043. /// <param name="e"></param>
  3044. private void button_ReadMAC_Click(object sender, EventArgs e)
  3045. {
  3046. textBox_MAC.Text = "---";
  3047. textBox_MACAdd.Text = "---";
  3048. textBox_MACDate.Text = "---";
  3049. textBox_PP.Text = "---";
  3050. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null);
  3051. }
  3052. /// <summary>
  3053. /// 写入生产信息
  3054. /// </summary>
  3055. /// <param name="sender"></param>
  3056. /// <param name="e"></param>
  3057. private void button_WriteMac_Click(object sender, EventArgs e)
  3058. {
  3059. var MACArray = new byte[32];
  3060. //填入生产商
  3061. for (ushort i = 0; i < textBox_MAC.Text.Length; i++)
  3062. {
  3063. MACArray[i] = (byte)textBox_MAC.Text[i];
  3064. }
  3065. if (textBox_MAC.Text.Length < 8)
  3066. {
  3067. MACArray[textBox_MAC.Text.Length] = (byte)'.';
  3068. for (ushort i = 0; i < 8 - textBox_MAC.Text.Length - 1; i++)
  3069. {
  3070. MACArray[textBox_MAC.Text.Length + 1 + i] = 0x20;
  3071. }
  3072. }
  3073. //填入生产地
  3074. for (ushort i = 0; i < textBox_MACAdd.Text.Length; i++)
  3075. {
  3076. MACArray[8 + i] = (byte)textBox_MACAdd.Text[i];
  3077. }
  3078. if (textBox_MACAdd.Text.Length < 8)
  3079. {
  3080. MACArray[textBox_MACAdd.Text.Length + 8] = (byte)'.';
  3081. for (ushort i = 0; i < 8 - textBox_MACAdd.Text.Length - 1; i++)
  3082. {
  3083. MACArray[textBox_MACAdd.Text.Length + 1 + i + 8] = 0x20;
  3084. }
  3085. }
  3086. //填入生产日期
  3087. for (ushort i = 0; i < textBox_MACDate.Text.Length; i++)
  3088. {
  3089. MACArray[16 + i] = (byte)textBox_MACDate.Text[i];
  3090. }
  3091. if (textBox_MACDate.Text.Length < 8)
  3092. {
  3093. MACArray[textBox_MACDate.Text.Length + 16] = (byte)'.';
  3094. for (ushort i = 0; i < 8 - textBox_MACDate.Text.Length - 1; i++)
  3095. {
  3096. MACArray[textBox_MACDate.Text.Length + 1 + i + 16] = 0x20;
  3097. }
  3098. }
  3099. //填入品牌
  3100. for (ushort i = 0; i < textBox_PP.Text.Length; i++)
  3101. {
  3102. MACArray[24 + i] = (byte)textBox_PP.Text[i];
  3103. }
  3104. if (textBox_PP.Text.Length < 8)
  3105. {
  3106. MACArray[textBox_PP.Text.Length + 24] = (byte)'.';
  3107. for (ushort i = 0; i < 8 - textBox_PP.Text.Length - 1; i++)
  3108. {
  3109. MACArray[textBox_PP.Text.Length + 1 + i + 24] = 0x20;
  3110. }
  3111. }
  3112. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  3113. }
  3114. /// <summary>
  3115. /// 查询密钥
  3116. /// </summary>
  3117. /// <param name="sender"></param>
  3118. /// <param name="e"></param>
  3119. private void button_ReadKey_Click(object sender, EventArgs e)
  3120. {
  3121. textBox_Key.Text = "---";
  3122. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null);
  3123. }
  3124. /// <summary>
  3125. /// 写入校验密钥
  3126. /// </summary>
  3127. /// <param name="sender"></param>
  3128. /// <param name="e"></param>
  3129. private void button_WriteKey_Click(object sender, EventArgs e)
  3130. {
  3131. string Key = textBox_Key.Text;
  3132. var KeyArray = new byte[8];
  3133. if (Key.Length != 8)
  3134. {
  3135. timer_1s.Enabled = false;
  3136. MessageBox.Show("请检查字符长度是否为8", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3137. timer_1s.Enabled = true;
  3138. return;
  3139. }
  3140. for (ushort i = 0; i < Key.Length; i++)
  3141. {
  3142. KeyArray[i] = (byte)Key[i];
  3143. }
  3144. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1108, KeyArray);
  3145. }
  3146. /// <summary>
  3147. /// 查询在线检测结果
  3148. /// </summary>
  3149. /// <param name="sender"></param>
  3150. /// <param name="e"></param>
  3151. private void button_ReadOnLine_Click(object sender, EventArgs e)
  3152. {
  3153. textBox_Online.Text = "---";
  3154. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2100, null);
  3155. }
  3156. /// <summary>
  3157. /// 系统清除
  3158. /// </summary>
  3159. /// <param name="sender"></param>
  3160. /// <param name="e"></param>
  3161. private void button_SystemClear_Click(object sender, EventArgs e)
  3162. {
  3163. var Code = new byte[5];
  3164. Code[0] = (byte)'C';
  3165. Code[1] = (byte)'L';
  3166. Code[2] = (byte)'E';
  3167. Code[3] = (byte)'A';
  3168. Code[4] = (byte)'R';
  3169. timer_1s.Enabled = false;
  3170. if (MessageBox.Show("系统清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3171. {
  3172. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3173. {
  3174. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3175. {
  3176. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  3177. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3178. }
  3179. }
  3180. }
  3181. timer_1s.Enabled = true;
  3182. }
  3183. /// <summary>
  3184. /// 参数还原
  3185. /// </summary>
  3186. /// <param name="sender"></param>
  3187. /// <param name="e"></param>
  3188. private void button_Recovery_Click(object sender, EventArgs e)
  3189. {
  3190. var Code = new byte[8];
  3191. Code[0] = (byte)'R';
  3192. Code[1] = (byte)'E';
  3193. Code[2] = (byte)'C';
  3194. Code[3] = (byte)'O';
  3195. Code[4] = (byte)'V';
  3196. Code[5] = (byte)'E';
  3197. Code[6] = (byte)'R';
  3198. Code[7] = (byte)'Y';
  3199. timer_1s.Enabled = false;
  3200. if (MessageBox.Show("参数还原后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3201. {
  3202. if (MessageBox.Show("请再次确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3203. {
  3204. if (MessageBox.Show("请最后确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3205. {
  3206. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2708, Code);
  3207. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3208. }
  3209. }
  3210. }
  3211. timer_1s.Enabled = true;
  3212. }
  3213. /// <summary>
  3214. /// 系统复位
  3215. /// </summary>
  3216. /// <param name="sender"></param>
  3217. /// <param name="e"></param>
  3218. private void button_Reset_Click(object sender, EventArgs e)
  3219. {
  3220. var Code_Off = new byte[5];
  3221. var Code_Reset = new byte[5];
  3222. Code_Off[0] = (byte)'O';
  3223. Code_Off[1] = (byte)'F';
  3224. Code_Off[2] = (byte)'F';
  3225. Code_Off[3] = (byte)'.';
  3226. Code_Off[4] = (byte)'.';
  3227. Code_Reset[0] = (byte)'R';
  3228. Code_Reset[1] = (byte)'E';
  3229. Code_Reset[2] = (byte)'S';
  3230. Code_Reset[3] = (byte)'E';
  3231. Code_Reset[4] = (byte)'T';
  3232. timer_1s.Enabled = false;
  3233. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3234. {
  3235. timer_1s.Enabled = true;
  3236. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  3237. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  3238. PowerOffAckStatus = false;
  3239. Delay_ms(250);
  3240. int TryCnt = 3;
  3241. while ((TryCnt--) >= 0)
  3242. {
  3243. if (!PowerOffAckStatus)
  3244. {
  3245. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  3246. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  3247. PowerOffAckStatus = false;
  3248. Delay_ms(250);
  3249. }
  3250. else break;
  3251. }
  3252. if (PowerOffAckStatus)
  3253. {
  3254. timer_1s.Enabled = false;
  3255. MessageBoxTimeOut.Show("已关机!", "提示", 3000, MessageBoxButtons.OK, MessageBoxIcon.None);
  3256. timer_1s.Enabled = true;
  3257. }
  3258. else
  3259. {
  3260. timer_1s.Enabled = false;
  3261. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3262. timer_1s.Enabled = true;
  3263. }
  3264. }
  3265. timer_1s.Enabled = true;
  3266. }
  3267. /// <summary>
  3268. /// 记录清除
  3269. /// </summary>
  3270. /// <param name="sender"></param>
  3271. /// <param name="e"></param>
  3272. private void button_ClearLog_Click(object sender, EventArgs e)
  3273. {
  3274. var Code = new byte[9];
  3275. Code[0] = (byte)'L';
  3276. Code[1] = (byte)'O';
  3277. Code[2] = (byte)'G';
  3278. Code[3] = (byte)' ';
  3279. Code[4] = (byte)'C';
  3280. Code[5] = (byte)'L';
  3281. Code[6] = (byte)'E';
  3282. Code[7] = (byte)'A';
  3283. Code[8] = (byte)'R';
  3284. timer_1s.Enabled = false;
  3285. if (MessageBox.Show("历史记录信息清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3286. {
  3287. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3288. {
  3289. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3290. {
  3291. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3909, Code);
  3292. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3293. }
  3294. }
  3295. }
  3296. timer_1s.Enabled = true;
  3297. }
  3298. /// <summary>
  3299. /// 打开系统计算器
  3300. /// </summary>
  3301. /// <param name="sender"></param>
  3302. /// <param name="e"></param>
  3303. private void 计算器ToolStripMenuItem_Click(object sender, EventArgs e)
  3304. {
  3305. System.Diagnostics.Process.Start("calc.exe");
  3306. }
  3307. /// <summary>
  3308. ///故障转换和显示
  3309. /// </summary>
  3310. List<string> ErrorInfo = new List<string>{ "过流保护", "低压保护", "过压保护", "堵转保护","过热保护","速度传感器故障","力矩传感器故障","霍尔故障",
  3311. "马达缺相","NTC故障","BMS校验失败","","OBC校验失败","MCU故障","踏频传感器故障","指拨故障","MOS短路","电压异常","","","","","","","","","","","","",
  3312. "",""};
  3313. private string ErrorInfoDisplay(UInt32 Code)
  3314. {
  3315. string Result = "";
  3316. if (Code == 0)
  3317. {
  3318. Result = "无故障";
  3319. }
  3320. else
  3321. {
  3322. for (int i = 0; i < 32; i++)
  3323. {
  3324. if ((Code & 0x01) == 0x01)
  3325. {
  3326. Result += ErrorInfo[i] + " ";
  3327. }
  3328. Code >>= 1;
  3329. }
  3330. }
  3331. return Result;
  3332. }
  3333. /// <summary>
  3334. /// 鼠标滑过故障码显示具体内容
  3335. /// </summary>
  3336. /// <param name="sender"></param>
  3337. /// <param name="e"></param>
  3338. private void textBox_ErrorCode_MouseHover(object sender, EventArgs e)
  3339. {
  3340. // 创建the ToolTip
  3341. ToolTip toolTip1 = new ToolTip();
  3342. // 设置显示样式
  3343. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  3344. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  3345. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  3346. toolTip1.ShowAlways = true;//是否显示提示框
  3347. // 设置伴随的对象.
  3348. string ErrorCode = this.textBox_ErrorCode.Text;
  3349. UInt32 Code = ErrorCode.Contains("H") ? Convert.ToUInt32(ErrorCode.Split('H')[0], 16) : 0;
  3350. toolTip1.SetToolTip(this.textBox_ErrorCode, ErrorInfoDisplay(Code));//设置故障内容显示
  3351. }
  3352. /// <summary>
  3353. /// 数据记录
  3354. /// </summary>
  3355. private void RunInfoAutoSave()
  3356. {
  3357. if (运行信息记录ToolStripMenuItem.Checked == true)
  3358. {
  3359. if (RunInfoSaveFilename == string.Empty)
  3360. {
  3361. return;
  3362. }
  3363. string SaveData = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff").Replace(" ", "_") + " --> ";
  3364. foreach (Control c in tabPage_RunInfo.Controls)
  3365. {
  3366. if (c is TextBox)
  3367. {
  3368. SaveData += c.Text + " , ";
  3369. }
  3370. }
  3371. foreach (Control c in tabPage_DebugInfo.Controls)
  3372. {
  3373. if (c is TextBox)
  3374. {
  3375. SaveData += c.Text + " , ";
  3376. }
  3377. }
  3378. SaveData += "\r\n";
  3379. System.IO.File.AppendAllText(RunInfoSaveFilename, SaveData);//sb.ToString());
  3380. }
  3381. }
  3382. /// <summary>
  3383. /// 打开或关闭数据记录
  3384. /// </summary>
  3385. /// <param name="sender"></param>
  3386. /// <param name="e"></param>
  3387. private void 记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  3388. {
  3389. if (运行信息记录ToolStripMenuItem.Checked == false)
  3390. {
  3391. if (mySerialProcess.mySerial.IsOpen == true)
  3392. {
  3393. RunInfoSaveFilename = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_运行信息" + ".txt";
  3394. System.IO.File.AppendAllText(RunInfoSaveFilename, "时间 --> 车速 , 转速 , 踏频 , 力矩Reg , 力矩 , 踩踏方向 , 电压 , 电流 , 功率 , 电量 , " +
  3395. "PCB温度 , 绕组温度 , MOS温度 , 挡位 , 灯开关 , 续航 , 平均功耗 , 单次里程 , 单次时间 , 故障码 , " +
  3396. "系统状态机 , 二层状态机 , 电机状态机 , 助力状态机 , D轴电流给定 , Q轴电流给定 , D轴电压给定 , Q轴电压给定 , 瞬时力矩 , 时间滤波力矩 , 踏频滤波力矩 , D轴电流反馈 , Q轴电流反馈 , 助力函数输出" + "\r\n");
  3397. timer_1s.Enabled = false;
  3398. MessageBoxTimeOut.Show("开始记录", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  3399. timer_1s.Enabled = true;
  3400. 运行信息记录ToolStripMenuItem.Checked = true;
  3401. }
  3402. else
  3403. {
  3404. timer_1s.Enabled = false;
  3405. MessageBox.Show("请连接电机", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3406. timer_1s.Enabled = true;
  3407. }
  3408. }
  3409. else
  3410. {
  3411. 运行信息记录ToolStripMenuItem.Checked = false;
  3412. timer_1s.Enabled = false;
  3413. MessageBoxTimeOut.Show("停止记录", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  3414. timer_1s.Enabled = true;
  3415. }
  3416. }
  3417. /// <summary>
  3418. /// 仪表启动控制档位开关事件
  3419. /// </summary>
  3420. /// <param name="sender"></param>
  3421. /// <param name="e"></param>
  3422. private void checkBox_OBC_StartSetGearSt_CheckedChanged(object sender, EventArgs e)
  3423. {
  3424. if (checkBox_OBC_StartSetGearSt.Checked == true)
  3425. {
  3426. //检查串口是否打开
  3427. if (!mySerialProcess.mySerial.IsOpen)
  3428. {
  3429. timer_1s.Enabled = false;
  3430. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3431. timer_1s.Enabled = true;
  3432. checkBox_OBC_StartSetGearSt.Checked = false;
  3433. return;
  3434. }
  3435. //检查是否选择档位和打开车灯
  3436. if ((comboBox_OBC_SetGearST.SelectedIndex == -1) || (comboBox_OBC_LightSw.SelectedIndex == -1))
  3437. {
  3438. timer_1s.Enabled = false;
  3439. MessageBox.Show("请检查档位设置和大灯开关!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3440. timer_1s.Enabled = true;
  3441. checkBox_OBC_StartSetGearSt.Checked = false;
  3442. return;
  3443. }
  3444. }
  3445. }
  3446. /// <summary>
  3447. /// OBC查询电机用户参数
  3448. /// </summary>
  3449. /// <param name="sender"></param>
  3450. /// <param name="e"></param>
  3451. private void button_OBC_ReadUserInfo_Click(object sender, EventArgs e)
  3452. {
  3453. richTextBox_OBC_ReadUserInfo.Clear();
  3454. comboBox_OBC_BikeCCS.SelectedIndex = 0;
  3455. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3300, null);
  3456. }
  3457. /// <summary>
  3458. /// OBC设置电机用户参数
  3459. /// </summary>
  3460. /// <param name="sender"></param>
  3461. /// <param name="e"></param>
  3462. private void button_OBC_WriteUserInfo_Click(object sender, EventArgs e)
  3463. {
  3464. var UserInfoCode = new byte[8];
  3465. for (int i = 0; i < UserInfoCode.Length; i++)
  3466. UserInfoCode[i] = 0;
  3467. if (comboBox_OBC_StartMode.SelectedIndex == -1)//检查数据有效性
  3468. {
  3469. timer_1s.Enabled = false;
  3470. MessageBox.Show("请选择启动模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3471. timer_1s.Enabled = true;
  3472. return;
  3473. }
  3474. if (comboBox_OBC_AssistFunc.SelectedIndex == -1)//检查数据有效性
  3475. {
  3476. timer_1s.Enabled = false;
  3477. MessageBox.Show("请选择助力方案!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3478. timer_1s.Enabled = true;
  3479. return;
  3480. }
  3481. //周长微调
  3482. UserInfoCode[0] = (byte)(int)numericUpDown_OBC_WheelAdj.Value;
  3483. //启动模式
  3484. UserInfoCode[1] = (byte)(comboBox_OBC_StartMode.SelectedIndex + 1);
  3485. //助力方案
  3486. UserInfoCode[2] = (byte)(comboBox_OBC_AssistFunc.SelectedIndex + 1);
  3487. //自动关机时间
  3488. UserInfoCode[3] = (byte)(uint)numericUpDown_OBC_OffTime.Value;
  3489. //限速微调
  3490. UserInfoCode[4] = (byte)(int)numericUpDown_OBC_SpeedLimitAdj.Value;
  3491. //定速巡航开关
  3492. UserInfoCode[5] = (byte)((comboBox_OBC_BikeCCS.SelectedIndex == 1) ? 0xAA : 0x00);
  3493. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3408, UserInfoCode);
  3494. }
  3495. /// <summary>
  3496. /// OBC查询电机版本信息
  3497. /// </summary>
  3498. /// <param name="sender"></param>
  3499. /// <param name="e"></param>
  3500. private void button_OBC_ReadVerInfo_Click(object sender, EventArgs e)
  3501. {
  3502. textBox_Model.Text = "---";
  3503. textBox_SN.Text = "---";
  3504. textBox_HW.Text = "---";
  3505. textBox_FW.Text = "---";
  3506. textBox_SP.Text = "---";
  3507. textBox_OBC_ReadModel.Text = "---";
  3508. textBox_OBC_ReadSN.Text = "---";
  3509. textBox_OBC_ReadHW.Text = "---";
  3510. textBox_OBC_ReadFW.Text = "---";
  3511. textBox_OBC_ReadSP.Text = "---";
  3512. textBox_FacModeName.Text = "---";
  3513. textBox_FacModeNum.Text = "---";
  3514. textBox_FacModeHW.Text = "---";
  3515. textBox_FacModeFW.Text = "---";
  3516. textBox_FacModeSP.Text = "---";
  3517. Class_Motor_Ver.Mode = "---";
  3518. Class_Motor_Ver.SN = "---";
  3519. Class_Motor_Ver.HW = "---";
  3520. Class_Motor_Ver.FW = "---";
  3521. Class_Motor_Ver.Special = "---";
  3522. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  3523. }
  3524. /// <summary>
  3525. /// OBC读取骑行历史
  3526. /// </summary>
  3527. /// <param name="sender"></param>
  3528. /// <param name="e"></param>
  3529. private void button_OBC_ReadRideInfo_Click(object sender, EventArgs e)
  3530. {
  3531. textBox_OBC_TRIP_KM.Text = "";
  3532. textBox_OBC_TRIP_TIME.Text = "";
  3533. textBox_OBC_ODO_KM.Text = "";
  3534. textBox_OBC_ODO_TIME.Text = "";
  3535. textBox_ODO_KM.Text = "---";
  3536. textBox_ODO_TIME.Text = "---";
  3537. textBox_TRIP_KM.Text = "---";
  3538. textBox_TRIP_TIME.Text = "---";
  3539. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3500, null);
  3540. }
  3541. /// <summary>
  3542. /// OBC清除TRIP里程
  3543. /// </summary>
  3544. /// <param name="sender"></param>
  3545. /// <param name="e"></param>
  3546. private void button_OBC_ClearTrip_Click(object sender, EventArgs e)
  3547. {
  3548. var Code = new byte[5];
  3549. Code[0] = (byte)'C';
  3550. Code[1] = (byte)'L';
  3551. Code[2] = (byte)'E';
  3552. Code[3] = (byte)'A';
  3553. Code[4] = (byte)'R';
  3554. timer_1s.Enabled = false;
  3555. if (MessageBox.Show("TRIP清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3556. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3605, Code);
  3557. timer_1s.Enabled = true;
  3558. }
  3559. private void checkBox_OBC_StartReadBMS_CheckedChanged(object sender, EventArgs e)
  3560. {
  3561. if (checkBox_OBC_StartReadBMS.Checked == true)
  3562. {
  3563. //检查串口是否打开
  3564. if (!mySerialProcess.mySerial.IsOpen)
  3565. {
  3566. timer_1s.Enabled = false;
  3567. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3568. timer_1s.Enabled = true;
  3569. checkBox_OBC_StartReadBMS.Checked = false;
  3570. return;
  3571. }
  3572. }
  3573. }
  3574. /// <summary>
  3575. /// 写入力矩传感器参数
  3576. /// </summary>
  3577. /// <param name="sender"></param>
  3578. /// <param name="e"></param>
  3579. private void button_WriteTqSensorParam_Click(object sender, EventArgs e)
  3580. {
  3581. var ConfigParam = new byte[46];
  3582. for (int i = 0; i < 14; i++)
  3583. ConfigParam[i] = 0;
  3584. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  3585. ushort uwDataTemp = 0;
  3586. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  3587. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  3588. int index = 0;
  3589. try
  3590. {
  3591. for (int i = 0; i < strDataTemp.Length; i++)
  3592. {
  3593. if (strDataTemp[i].Split('=')[0] == "第四阶段转矩点采集值")
  3594. {
  3595. index = i;
  3596. break;
  3597. }
  3598. }
  3599. for (int i = 0; i < (index + 1); i++)
  3600. {
  3601. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  3602. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3603. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3604. }
  3605. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x472E, ConfigParam);
  3606. }
  3607. catch (Exception)
  3608. {
  3609. timer_1s.Enabled = false;
  3610. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3611. timer_1s.Enabled = true;
  3612. }
  3613. }
  3614. /// <summary>
  3615. /// 查询存储标志
  3616. /// </summary>
  3617. /// <param name="sender"></param>
  3618. /// <param name="e"></param>
  3619. private void button_ReadSaveFlag_Click(object sender, EventArgs e)
  3620. {
  3621. radioButton_EE_SaveYes.Checked = false;
  3622. radioButton_EE_SaveNo.Checked = false;
  3623. radioButton_SIP_SaveYes.Checked = false;
  3624. radioButton_SIP_SaveNo.Checked = false;
  3625. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null);
  3626. }
  3627. /// <summary>
  3628. /// 写入存储标志
  3629. /// </summary>
  3630. /// <param name="sender"></param>
  3631. /// <param name="e"></param>
  3632. private void button_WriteSaveFlag_Click(object sender, EventArgs e)
  3633. {
  3634. var SaveFlag = new byte[6];
  3635. for (int i = 0; i < 6; i++)
  3636. SaveFlag[i] = 0;
  3637. if ((radioButton_EE_SaveYes.Checked == false) && (radioButton_EE_SaveNo.Checked == false))
  3638. {
  3639. timer_1s.Enabled = false;
  3640. MessageBox.Show("请选择EEPROM存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3641. timer_1s.Enabled = true;
  3642. return;
  3643. }
  3644. if ((radioButton_SIP_SaveYes.Checked == false) && (radioButton_SIP_SaveNo.Checked == false))
  3645. {
  3646. timer_1s.Enabled = false;
  3647. MessageBox.Show("请选择SIP校验存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3648. timer_1s.Enabled = true;
  3649. return;
  3650. }
  3651. SaveFlag[0] = (byte)((checkBox_SaveYes.Checked) ? 0x01 : 0x00);
  3652. SaveFlag[2] = (byte)(radioButton_EE_SaveYes.Checked ? 0x01 : 0x00);
  3653. SaveFlag[3] = 0;
  3654. SaveFlag[4] = (byte)(radioButton_SIP_SaveYes.Checked ? 0x01 : 0x00);
  3655. SaveFlag[5] = 0;
  3656. timer_1s.Enabled = false;
  3657. if (MessageBox.Show("确认修改存储标志?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3658. {
  3659. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4906, SaveFlag);
  3660. }
  3661. timer_1s.Enabled = true;
  3662. }
  3663. /// <summary>
  3664. /// 读取指定地址数据
  3665. /// </summary>
  3666. /// <param name="sender"></param>
  3667. /// <param name="e"></param>
  3668. private void button_ReadRamFlash_Click(object sender, EventArgs e)
  3669. {
  3670. var Address = new byte[4];
  3671. UInt32 Address_Begin;
  3672. UInt32 Addres_End;
  3673. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  3674. richTextBox_RamFlasgData.Clear();
  3675. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  3676. {
  3677. timer_1s.Enabled = false;
  3678. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3679. timer_1s.Enabled = true;
  3680. return;
  3681. }
  3682. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  3683. {
  3684. timer_1s.Enabled = false;
  3685. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3686. timer_1s.Enabled = true;
  3687. return;
  3688. }
  3689. else
  3690. {
  3691. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  3692. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  3693. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  3694. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  3695. if (Addres_End < Address_Begin)
  3696. {
  3697. timer_1s.Enabled = false;
  3698. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3699. timer_1s.Enabled = true;
  3700. return;
  3701. }
  3702. else
  3703. {
  3704. var SendByte = new byte[8];
  3705. SendByte[0] = (byte)(Address_Begin >> 24);
  3706. SendByte[1] = (byte)(Address_Begin >> 16);
  3707. SendByte[2] = (byte)(Address_Begin >> 8);
  3708. SendByte[3] = (byte)(Address_Begin);
  3709. SendByte[4] = (byte)(Addres_End >> 24);
  3710. SendByte[5] = (byte)(Addres_End >> 16);
  3711. SendByte[6] = (byte)(Addres_End >> 8);
  3712. SendByte[7] = (byte)(Addres_End);
  3713. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  3714. }
  3715. }
  3716. }
  3717. /// <summary>
  3718. /// 工作模式选择
  3719. /// </summary>
  3720. /// <param name="sender"></param>
  3721. /// <param name="e"></param>
  3722. private void comboBox_WorkMode_SelectedIndexChanged(object sender, EventArgs e)
  3723. {
  3724. var RunMode = new byte[1];
  3725. if (comboBox_WorkMode.Text == "配置模式")
  3726. RunMode[0] = 0x01;
  3727. else if (comboBox_WorkMode.Text == "调试模式")
  3728. RunMode[0] = 0x02;
  3729. else
  3730. RunMode[0] = 0x00;
  3731. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  3732. }
  3733. /// <summary>
  3734. /// 助力档位选择
  3735. /// </summary>
  3736. /// <param name="sender"></param>
  3737. /// <param name="e"></param>
  3738. private void comboBox_GearSt_SelectedIndexChanged(object sender, EventArgs e)
  3739. {
  3740. var CtrlCode = new byte[2];
  3741. if (comboBox_GearSt.SelectedIndex == 5)//档位
  3742. CtrlCode[0] = 0x33;
  3743. else if (comboBox_GearSt.SelectedIndex == 6)//档位
  3744. CtrlCode[0] = 0x22;
  3745. else
  3746. CtrlCode[0] = (byte)comboBox_GearSt.SelectedIndex;
  3747. if (comboBox_LightSwitch.SelectedIndex == 0)//车灯
  3748. CtrlCode[1] = 0xF1;
  3749. else
  3750. CtrlCode[1] = 0xF0;
  3751. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
  3752. comboBox_OBC_SetGearST.SelectedIndex = comboBox_GearSt.SelectedIndex;
  3753. comboBox_OBC_LightSw.SelectedIndex = comboBox_LightSwitch.SelectedIndex;
  3754. }
  3755. /// <summary>
  3756. /// 仪表档位选择
  3757. /// </summary>
  3758. /// <param name="sender"></param>
  3759. /// <param name="e"></param>
  3760. private void comboBox_OBC_SetGearST_SelectedIndexChanged(object sender, EventArgs e)
  3761. {
  3762. comboBox_GearSt.SelectedIndex = comboBox_OBC_SetGearST.SelectedIndex;
  3763. comboBox_LightSwitch.SelectedIndex = comboBox_OBC_LightSw.SelectedIndex;
  3764. }
  3765. /// <summary>
  3766. /// 生产模式初始化
  3767. /// </summary>
  3768. /// <param name="sender"></param>
  3769. /// <param name="e"></param>
  3770. private void button_FacModeInit_Click(object sender, EventArgs e)
  3771. {
  3772. var Code = new byte[5];
  3773. Code[0] = (byte)'C';
  3774. Code[1] = (byte)'L';
  3775. Code[2] = (byte)'E';
  3776. Code[3] = (byte)'A';
  3777. Code[4] = (byte)'R';
  3778. timer_1s.Enabled = false;
  3779. if (MessageBox.Show("电机即将初始化!", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3780. {
  3781. if (MessageBox.Show("请再次确认", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3782. {
  3783. timer_1s.Enabled = true;
  3784. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  3785. PowerOffAckStatus = false;
  3786. Delay_ms(250);
  3787. int TryCnt = 3;
  3788. while ((TryCnt--) >= 0)
  3789. {
  3790. if (!PowerOffAckStatus)
  3791. {
  3792. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  3793. PowerOffAckStatus = false;
  3794. Delay_ms(250);
  3795. }
  3796. else break;
  3797. }
  3798. if (PowerOffAckStatus)
  3799. {
  3800. timer_1s.Enabled = false;
  3801. MessageBox.Show("系统已关机,请保持无负载重新开机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  3802. timer_1s.Enabled = true;
  3803. }
  3804. else
  3805. {
  3806. timer_1s.Enabled = false;
  3807. MessageBox.Show("初始化失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3808. timer_1s.Enabled = true;
  3809. }
  3810. timer_1s.Enabled = true;
  3811. }
  3812. }
  3813. timer_1s.Enabled = true;
  3814. //清除历史测试记录
  3815. textBox_FacModeSensorADC0.Text = "";
  3816. textBox_FacModeSensorADC1.Text = "";
  3817. textBox_FacModeSensorADC2.Text = "";
  3818. textBox_FacModeSensorADC3.Text = "";
  3819. textBox_FacModeSensorADC4.Text = "";
  3820. LightSwitchStatus = false;
  3821. MotorRunStatus = false;
  3822. trackBar_FacModeMotorSpeedAdj.Value = 5;
  3823. textBox_FacModeName.Text = "";
  3824. textBox_FacModeNum.Text = "";
  3825. textBox_FacModeHW.Text = "";
  3826. textBox_FacModeFW.Text = "";
  3827. }
  3828. /// <summary>
  3829. /// 生产模式读取传感器参数
  3830. /// </summary>
  3831. /// <param name="sender"></param>
  3832. /// <param name="e"></param>
  3833. private void button_FacModeSensorRead_Click(object sender, EventArgs e)
  3834. {
  3835. richTextBox_SensorParam.Clear();
  3836. textBox_FacModeSensorADC0.Text = "";
  3837. textBox_FacModeSensorADC1.Text = "";
  3838. textBox_FacModeSensorADC2.Text = "";
  3839. textBox_FacModeSensorADC3.Text = "";
  3840. textBox_FacModeSensorADC4.Text = "";
  3841. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3842. }
  3843. /// <summary>
  3844. /// 生产模式传感器标定1
  3845. /// </summary>
  3846. /// <param name="sender"></param>
  3847. /// <param name="e"></param>
  3848. private void buttonFacModeSet1_Click(object sender, EventArgs e)
  3849. {
  3850. var ConfigParam = new byte[4];
  3851. for (int i = 0; i < 4; i++)
  3852. ConfigParam[i] = 0;
  3853. ushort uwDataTemp = 0;
  3854. try
  3855. {
  3856. uwDataTemp = 1;//负载序号
  3857. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  3858. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  3859. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal1.Text) * 10); ;//负载值0.1Nm
  3860. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  3861. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  3862. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  3863. Delay_ms(200);
  3864. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3865. }
  3866. catch (Exception)
  3867. {
  3868. timer_1s.Enabled = false;
  3869. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3870. timer_1s.Enabled = true;
  3871. }
  3872. }
  3873. /// <summary>
  3874. /// 生产模式传感器标定2
  3875. /// </summary>
  3876. /// <param name="sender"></param>
  3877. /// <param name="e"></param>
  3878. private void buttonFacModeSet2_Click(object sender, EventArgs e)
  3879. {
  3880. var ConfigParam = new byte[4];
  3881. for (int i = 0; i < 4; i++)
  3882. ConfigParam[i] = 0;
  3883. ushort uwDataTemp = 0;
  3884. try
  3885. {
  3886. uwDataTemp = 2;//负载序号
  3887. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  3888. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  3889. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal2.Text) * 10); ;//负载值0.1Nm
  3890. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  3891. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  3892. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  3893. Delay_ms(200);
  3894. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3895. }
  3896. catch (Exception)
  3897. {
  3898. timer_1s.Enabled = false;
  3899. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3900. timer_1s.Enabled = true;
  3901. }
  3902. }
  3903. /// <summary>
  3904. /// 生产模式传感器标定3
  3905. /// </summary>
  3906. /// <param name="sender"></param>
  3907. /// <param name="e"></param>
  3908. private void buttonFacModeSet3_Click(object sender, EventArgs e)
  3909. {
  3910. var ConfigParam = new byte[4];
  3911. for (int i = 0; i < 4; i++)
  3912. ConfigParam[i] = 0;
  3913. ushort uwDataTemp = 0;
  3914. try
  3915. {
  3916. uwDataTemp = 3;//负载序号
  3917. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  3918. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  3919. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal3.Text) * 10); ;//负载值0.1Nm
  3920. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  3921. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  3922. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  3923. Delay_ms(200);
  3924. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3925. }
  3926. catch (Exception)
  3927. {
  3928. timer_1s.Enabled = false;
  3929. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3930. timer_1s.Enabled = true;
  3931. }
  3932. }
  3933. /// <summary>
  3934. /// 生产模式传感器标定3
  3935. /// </summary>
  3936. /// <param name="sender"></param>
  3937. /// <param name="e"></param>
  3938. private void buttonFacModeSet4_Click(object sender, EventArgs e)
  3939. {
  3940. var ConfigParam = new byte[4];
  3941. for (int i = 0; i < 4; i++)
  3942. ConfigParam[i] = 0;
  3943. ushort uwDataTemp = 0;
  3944. try
  3945. {
  3946. uwDataTemp = 4;//负载序号
  3947. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  3948. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  3949. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal4.Text) * 10); ;//负载值0.1Nm
  3950. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  3951. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  3952. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  3953. Delay_ms(200);
  3954. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3955. }
  3956. catch (Exception)
  3957. {
  3958. timer_1s.Enabled = false;
  3959. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3960. timer_1s.Enabled = true;
  3961. }
  3962. }
  3963. /// <summary>
  3964. /// 生产模式开关灯
  3965. /// </summary>
  3966. /// <param name="sender"></param>
  3967. /// <param name="e"></param>
  3968. bool LightSwitchStatus = false;
  3969. private void button_FacModeLightSW_Click(object sender, EventArgs e)
  3970. {
  3971. var CtrlCode = new byte[2];
  3972. CtrlCode[0] = 0x00;
  3973. if (LightSwitchStatus)
  3974. {
  3975. CtrlCode[1] = 0xF0;
  3976. button_FacModeLightSW.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(128)))));
  3977. }
  3978. else
  3979. {
  3980. CtrlCode[1] = 0xF1;
  3981. button_FacModeLightSW.BackColor = Color.Yellow;
  3982. }
  3983. if (mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode))
  3984. {
  3985. LightSwitchStatus = !LightSwitchStatus;
  3986. comboBox_LightSwitch.SelectedIndex = LightSwitchStatus ? 0 : 1;
  3987. comboBox_OBC_LightSw.SelectedIndex = LightSwitchStatus ? 0 : 1;
  3988. }
  3989. }
  3990. /// <summary>
  3991. /// 生产模式电机控制
  3992. /// </summary>
  3993. /// <param name="sender"></param>
  3994. /// <param name="e"></param>
  3995. bool MotorRunStatus = false;
  3996. private void button_FacModeMotorRun_Click(object sender, EventArgs e)
  3997. {
  3998. string DebugDefaultInfo = "";
  3999. //获取调试信息
  4000. if (richTextBox_DebugParam.Text == string.Empty)
  4001. {
  4002. richTextBox_DebugParam.Clear();
  4003. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  4004. }
  4005. Delay_ms(200);
  4006. DebugDefaultInfo = richTextBox_DebugParam.Text;
  4007. //获取参数
  4008. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  4009. if (strDataTemp.Length != 29)
  4010. {
  4011. timer_1s.Enabled = false;
  4012. MessageBox.Show("数据格式不正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4013. timer_1s.Enabled = true;
  4014. return;
  4015. }
  4016. //设置参数
  4017. var ConfigParam = new byte[60];
  4018. for (int i = 0; i < 60; i++)
  4019. ConfigParam[i] = 0;
  4020. ConfigParam[0] = 0x00;
  4021. ushort uwDataTemp = 0;
  4022. if (!MotorRunStatus) //停止状态
  4023. {
  4024. //设置速度环
  4025. strDataTemp[0] = "整体运行模式=3";
  4026. //发送数据
  4027. try
  4028. {
  4029. for (int i = 0; i < strDataTemp.Length; i++)
  4030. {
  4031. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  4032. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  4033. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  4034. }
  4035. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  4036. return;
  4037. }
  4038. catch (Exception)
  4039. {
  4040. timer_1s.Enabled = false;
  4041. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4042. timer_1s.Enabled = true;
  4043. }
  4044. Delay_ms(200);
  4045. //设置转速百分比100%
  4046. trackBar_FacModeMotorSpeedAdj.Value = 100;
  4047. MotorRunStatus = !MotorRunStatus;
  4048. button_FacModeMotorRun.BackColor = Color.Yellow;
  4049. Delay_ms(200);
  4050. //电机进入配置模式
  4051. var RunMode = new byte[1];
  4052. RunMode[0] = 0x01;
  4053. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  4054. }
  4055. else //运转状态
  4056. {
  4057. //设置转速百分比0%
  4058. trackBar_FacModeMotorSpeedAdj.Value = 0;
  4059. MotorRunStatus = !MotorRunStatus;
  4060. button_FacModeMotorRun.BackColor = Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
  4061. Delay_ms(200);
  4062. //还原为原始值
  4063. strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  4064. try
  4065. {
  4066. for (int i = 0; i < strDataTemp.Length; i++)
  4067. {
  4068. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  4069. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  4070. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  4071. }
  4072. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  4073. return;
  4074. }
  4075. catch (Exception)
  4076. {
  4077. timer_1s.Enabled = false;
  4078. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4079. timer_1s.Enabled = true;
  4080. }
  4081. Delay_ms(200);
  4082. //电机退出配置模式
  4083. var RunMode = new byte[1];
  4084. RunMode[0] = 0x00;
  4085. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  4086. }
  4087. }
  4088. /// <summary>
  4089. /// 生产模式转速调节
  4090. /// </summary>
  4091. /// <param name="sender"></param>
  4092. /// <param name="e"></param>
  4093. private void trackBar_FacModeMotorSpeedAdj_ValueChanged(object sender, EventArgs e)
  4094. {
  4095. //转速百分比更新
  4096. label_FacModeMotorSpeedSet.Text = trackBar_FacModeMotorSpeedAdj.Value.ToString() + "%";
  4097. numericUpDown_SpeedAdj.Value = trackBar_FacModeMotorSpeedAdj.Value;
  4098. }
  4099. /// <summary>
  4100. /// 生产模式写入型号
  4101. /// </summary>
  4102. /// <param name="sender"></param>
  4103. /// <param name="e"></param>
  4104. private void button_FacModeSetName_Click(object sender, EventArgs e)
  4105. {
  4106. string Mode = textBox_FacModeName.Text;
  4107. var ModeArray = new byte[16];
  4108. for (ushort i = 0; i < Mode.Length; i++)
  4109. {
  4110. ModeArray[i] = (byte)Mode[i];
  4111. }
  4112. if (Mode.Length < 16)
  4113. {
  4114. ModeArray[Mode.Length] = (byte)'.';
  4115. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  4116. {
  4117. ModeArray[Mode.Length + 1 + i] = 0x20;
  4118. }
  4119. }
  4120. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  4121. }
  4122. /// <summary>
  4123. /// 生产模式写入SN
  4124. /// </summary>
  4125. /// <param name="sender"></param>
  4126. /// <param name="e"></param>
  4127. private void Button_FacModeSetNum_Click(object sender, EventArgs e)
  4128. {
  4129. string SN = textBox_FacModeNum.Text;
  4130. var SNArray = new byte[16];
  4131. for (ushort i = 0; i < SN.Length; i++)
  4132. {
  4133. SNArray[i] = (byte)SN[i];
  4134. }
  4135. if (SN.Length < 16)
  4136. {
  4137. SNArray[SN.Length] = (byte)'.';
  4138. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  4139. {
  4140. SNArray[SN.Length + 1 + i] = 0x20;
  4141. }
  4142. }
  4143. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  4144. }
  4145. /// <summary>
  4146. /// 生产模式读取版本信息
  4147. /// </summary>
  4148. /// <param name="sender"></param>
  4149. /// <param name="e"></param>
  4150. private void Button_FacModeReadVer_Click_1(object sender, EventArgs e)
  4151. {
  4152. textBox_Model.Text = "---";
  4153. textBox_SN.Text = "---";
  4154. textBox_HW.Text = "---";
  4155. textBox_FW.Text = "---";
  4156. textBox_SP.Text = "---";
  4157. textBox_OBC_ReadModel.Text = "---";
  4158. textBox_OBC_ReadSN.Text = "---";
  4159. textBox_OBC_ReadHW.Text = "---";
  4160. textBox_OBC_ReadFW.Text = "---";
  4161. textBox_OBC_ReadSP.Text = "---";
  4162. textBox_FacModeName.Text = "---";
  4163. textBox_FacModeNum.Text = "---";
  4164. textBox_FacModeHW.Text = "---";
  4165. textBox_FacModeFW.Text = "---";
  4166. textBox_FacModeSP.Text = "---";
  4167. textBox_FacModeGit.Text = "---";
  4168. Class_Motor_Ver.Mode = "---";
  4169. Class_Motor_Ver.SN = "---";
  4170. Class_Motor_Ver.HW = "---";
  4171. Class_Motor_Ver.FW = "---";
  4172. Class_Motor_Ver.Special = "---";
  4173. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  4174. }
  4175. /// <summary>
  4176. /// 生产模式写入生产信息
  4177. /// </summary>
  4178. /// <param name="sender"></param>
  4179. /// <param name="e"></param>
  4180. private void Button_FacModeSetMacDate_Click(object sender, EventArgs e)
  4181. {
  4182. var MACArray = new byte[32];
  4183. string MacDefaultInfo = "";
  4184. string MacAddDefaultInfo = "";
  4185. string MacDateDefaultInfo = DateTime.Now.ToString("yyyyMMdd");
  4186. string MacPPDefaultInfo = "";
  4187. do
  4188. {
  4189. //填入生产商
  4190. if (toolStripTextBox_MAC.Text == string.Empty)
  4191. {
  4192. break;
  4193. }
  4194. MacDefaultInfo = toolStripTextBox_MAC.Text;
  4195. for (ushort i = 0; i < MacDefaultInfo.Length; i++)
  4196. {
  4197. MACArray[i] = (byte)MacDefaultInfo[i];
  4198. }
  4199. if (MacDefaultInfo.Length < 8)
  4200. {
  4201. MACArray[MacDefaultInfo.Length] = (byte)'.';
  4202. for (ushort i = 0; i < 8 - MacDefaultInfo.Length - 1; i++)
  4203. {
  4204. MACArray[MacDefaultInfo.Length + 1 + i] = 0x20;
  4205. }
  4206. }
  4207. //填入生产地
  4208. if (toolStripTextBoxMACAddr.Text == string.Empty)
  4209. {
  4210. break;
  4211. }
  4212. MacAddDefaultInfo = toolStripTextBoxMACAddr.Text;
  4213. for (ushort i = 0; i < MacAddDefaultInfo.Length; i++)
  4214. {
  4215. MACArray[8 + i] = (byte)MacAddDefaultInfo[i];
  4216. }
  4217. if (MacAddDefaultInfo.Length < 8)
  4218. {
  4219. MACArray[MacAddDefaultInfo.Length + 8] = (byte)'.';
  4220. for (ushort i = 0; i < 8 - MacAddDefaultInfo.Length - 1; i++)
  4221. {
  4222. MACArray[MacAddDefaultInfo.Length + 1 + i + 8] = 0x20;
  4223. }
  4224. }
  4225. //填入生产日期
  4226. if (toolStripTextBox_MACDate.Text == string.Empty)
  4227. {
  4228. break;
  4229. }
  4230. MacDateDefaultInfo = toolStripTextBox_MACDate.Text;
  4231. for (ushort i = 0; i < MacDateDefaultInfo.Length; i++)
  4232. {
  4233. MACArray[16 + i] = (byte)MacDateDefaultInfo[i];
  4234. }
  4235. if (MacDateDefaultInfo.Length < 8)
  4236. {
  4237. MACArray[MacDateDefaultInfo.Length + 16] = (byte)'.';
  4238. for (ushort i = 0; i < 8 - MacDateDefaultInfo.Length - 1; i++)
  4239. {
  4240. MACArray[MacDateDefaultInfo.Length + 1 + i + 16] = 0x20;
  4241. }
  4242. }
  4243. //填入产品标识
  4244. if (toolStripTextBox_MACPD.Text == string.Empty)
  4245. {
  4246. break;
  4247. }
  4248. MacPPDefaultInfo = toolStripTextBox_MACPD.Text;
  4249. for (ushort i = 0; i < MacPPDefaultInfo.Length; i++)
  4250. {
  4251. MACArray[24 + i] = (byte)MacPPDefaultInfo[i];
  4252. }
  4253. if (MacPPDefaultInfo.Length < 8)
  4254. {
  4255. MACArray[MacPPDefaultInfo.Length + 24] = (byte)'.';
  4256. for (ushort i = 0; i < 8 - MacPPDefaultInfo.Length - 1; i++)
  4257. {
  4258. MACArray[MacPPDefaultInfo.Length + 1 + i + 24] = 0x20;
  4259. }
  4260. }
  4261. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  4262. return;
  4263. } while (false);
  4264. timer_1s.Enabled = false;
  4265. MessageBox.Show("生产信息配置不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4266. timer_1s.Enabled = true;
  4267. }
  4268. /// <summary>
  4269. /// 生产模式保存测试页面
  4270. /// </summary>
  4271. /// <param name="sender"></param>
  4272. /// <param name="e"></param>
  4273. private void Button_FacModeSaveResult_Click(object sender, EventArgs e)
  4274. {
  4275. Button_FacModeSaveResult.Text = "存储中…";
  4276. string[] AssistParams = new string[15];
  4277. do
  4278. {
  4279. //读取一次马达参数
  4280. richTextBox_MotorParam.Clear();
  4281. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break; ;
  4282. Delay_ms(100);
  4283. //读取一次整车参数
  4284. richTextBox_BikeParam.Clear();
  4285. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  4286. Delay_ms(100);
  4287. //读取一次控制参数
  4288. richTextBox_ControlParam.Clear();
  4289. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  4290. Delay_ms(100);
  4291. //查询传感器
  4292. richTextBox_SensorParam.Clear();
  4293. textBox_FacModeSensorADC0.Text = "";
  4294. textBox_FacModeSensorADC1.Text = "";
  4295. textBox_FacModeSensorADC2.Text = "";
  4296. textBox_FacModeSensorADC3.Text = "";
  4297. textBox_FacModeSensorADC4.Text = "";
  4298. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  4299. Delay_ms(100);
  4300. //读取15次助力参数
  4301. for (int i = 1; i <= 15; i++)
  4302. {
  4303. var ConfigParam = new byte[4];
  4304. richTextBox_AssistParam.Clear();
  4305. ConfigParam[0] = (byte)(i & 0xFF);
  4306. ConfigParam[1] = (byte)(i >> 8);
  4307. ConfigParam[2] = (byte)(((i >= 5) ? 5 : i) & 0xFF);
  4308. ConfigParam[3] = (byte)(((i >= 5) ? 5 : i) >> 8);
  4309. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  4310. Delay_ms(200);
  4311. AssistParams[i - 1] = richTextBox_AssistParam.Text + "\r\n";
  4312. }
  4313. //读取一次调试信息
  4314. richTextBox_DebugParam.Clear();
  4315. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  4316. Delay_ms(100);
  4317. //读取一次历史信息
  4318. richTextBox_Record.Clear();
  4319. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  4320. Delay_ms(100);
  4321. //读取一次电机运行信息
  4322. var CtrlCode = new byte[2];
  4323. CtrlCode[0] = 0x00;
  4324. CtrlCode[1] = 0xF0;
  4325. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode)) break;
  4326. Delay_ms(100);
  4327. //读取一次版本信息
  4328. textBox_Model.Text = "---";
  4329. textBox_SN.Text = "---";
  4330. textBox_HW.Text = "---";
  4331. textBox_FW.Text = "---";
  4332. textBox_OBC_ReadModel.Text = "---";
  4333. textBox_OBC_ReadSN.Text = "---";
  4334. textBox_OBC_ReadHW.Text = "---";
  4335. textBox_OBC_ReadFW.Text = "---";
  4336. textBox_FacModeName.Text = "---";
  4337. textBox_FacModeNum.Text = "---";
  4338. textBox_FacModeHW.Text = "---";
  4339. textBox_FacModeFW.Text = "---";
  4340. Class_Motor_Ver.Mode = "---";
  4341. Class_Motor_Ver.SN = "---";
  4342. Class_Motor_Ver.HW = "---";
  4343. Class_Motor_Ver.FW = "---";
  4344. Class_Motor_Ver.Special = "---";
  4345. if (!mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null)) break;
  4346. Delay_ms(100);
  4347. //读取一次生产信息
  4348. textBox_MAC.Text = "";
  4349. textBox_MACAdd.Text = "";
  4350. textBox_MACDate.Text = "";
  4351. textBox_PP.Text = "";
  4352. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  4353. Delay_ms(100);
  4354. //读取一次自定义信息
  4355. textBox_User1.Text = "---";
  4356. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  4357. Delay_ms(100);
  4358. textBox_User2.Text = "---";
  4359. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  4360. Delay_ms(100);
  4361. textBox_User3.Text = "---";
  4362. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  4363. Delay_ms(100);
  4364. //读取一次密钥
  4365. textBox_Key.Text = "---";
  4366. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  4367. Delay_ms(100);
  4368. //读取一次存储标志
  4369. radioButton_EE_SaveYes.Checked = false;
  4370. radioButton_EE_SaveNo.Checked = false;
  4371. radioButton_SIP_SaveYes.Checked = false;
  4372. radioButton_SIP_SaveNo.Checked = false;
  4373. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  4374. Delay_ms(100);
  4375. //读取一次MOS内阻校准参数
  4376. foreach (Control c in groupBox21.Controls)
  4377. {
  4378. if (c is TextBox)
  4379. c.Text = "";
  4380. }
  4381. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  4382. Delay_ms(100);
  4383. //提示检查
  4384. #if false
  4385. timer_1s.Enabled = false;
  4386. if (MessageBox.Show("请检查信息是否完整!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  4387. {
  4388. MessageBox.Show("请检查参数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4389. timer_1s.Enabled = true;
  4390. return;
  4391. }
  4392. timer_1s.Enabled = true;
  4393. Delay_ms(200);
  4394. #endif
  4395. //判断数据是否有效
  4396. if ((textBox_FacModeName.Text == "---") || (textBox_FacModeNum.Text == "---"))
  4397. {
  4398. MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4399. break;
  4400. }
  4401. if ((textBox_FacModeName.Text == string.Empty) || (textBox_FacModeNum.Text == string.Empty))
  4402. {
  4403. MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4404. break;
  4405. }
  4406. //设置文件存储路径
  4407. string Save_Path = localInfo.LocalPath + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
  4408. string PD_PathName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_"); ;
  4409. Save_Path += PD_PathName;
  4410. if (!Directory.Exists(Save_Path))
  4411. Directory.CreateDirectory(Save_Path);
  4412. //保存页面
  4413. string PIC_SaveFileName = "";
  4414. Double scaleX = PrimaryScreen.ScaleX;
  4415. Double scaleY = PrimaryScreen.ScaleY;
  4416. //保存页面
  4417. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  4418. Graphics g = Graphics.FromImage(bit);
  4419. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  4420. PIC_SaveFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_测试页面" + ".png";
  4421. bit.Save(PIC_SaveFileName);
  4422. //保存数据
  4423. string DataFileName = "";
  4424. string FileInfo = "";
  4425. DataFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_记录数据" + ".txt";
  4426. FileInfo += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  4427. FileInfo += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  4428. FileInfo += "\r\n";
  4429. FileInfo += "[电机信息]\r\n";
  4430. FileInfo += "电机型号: " + textBox_FacModeName.Text + "\r\n";
  4431. FileInfo += "电机编号: " + textBox_FacModeNum.Text + "\r\n";
  4432. FileInfo += "硬件版本: " + textBox_HW.Text + "\r\n";
  4433. FileInfo += "软件版本: " + textBox_FW.Text + "\r\n";
  4434. FileInfo += "软件标识: " + textBox_SP.Text + "\r\n";
  4435. FileInfo += "Git信息: " + textBox_FacModeGit.Text + "\r\n";
  4436. FileInfo += "\r\n";
  4437. FileInfo += "[马达参数]\r\n";
  4438. FileInfo += richTextBox_MotorParam.Text + "\r\n";
  4439. FileInfo += "\r\n";
  4440. FileInfo += "[整车参数]\r\n";
  4441. FileInfo += richTextBox_BikeParam.Text + "\r\n";
  4442. FileInfo += "\r\n";
  4443. FileInfo += "[控制参数]\r\n";
  4444. FileInfo += richTextBox_ControlParam.Text + "\r\n";
  4445. FileInfo += "\r\n";
  4446. FileInfo += "[传感器参数]\r\n";
  4447. FileInfo += richTextBox_SensorParam.Text + "\r\n";
  4448. FileInfo += "\r\n";
  4449. FileInfo += "[助力参数]\r\n";
  4450. for(int i=0;i<15;i++)
  4451. {
  4452. FileInfo += AssistParams[i] + "\r\n";
  4453. }
  4454. FileInfo += "[调试参数]\r\n";
  4455. FileInfo += richTextBox_DebugParam.Text + "\r\n";
  4456. FileInfo += "\r\n";
  4457. FileInfo += "[历史信息]\r\n";
  4458. FileInfo += richTextBox_Record.Text + "\r\n";
  4459. FileInfo += "\r\n";
  4460. FileInfo += "[MOS内阻校准参数]\r\n";
  4461. FileInfo += textBox_MOS_K1.Text + ", ";
  4462. FileInfo += textBox_MOS_K2.Text + ", ";
  4463. FileInfo += textBox_MOS_K3.Text + ", ";
  4464. FileInfo += textBox_MOS_K4.Text + ", ";
  4465. FileInfo += textBox_MOS_K5.Text + ", ";
  4466. FileInfo += textBox_MOS_R1.Text + ", ";
  4467. FileInfo += textBox_MOS_R2.Text + ", ";
  4468. FileInfo += textBox_MOS_R3.Text + "\r\n";
  4469. FileInfo += "\r\n";
  4470. FileInfo += "[生产信息]\r\n";
  4471. FileInfo += "生产商: " + textBox_MAC.Text + "\r\n";
  4472. FileInfo += "生产地: " + textBox_MACAdd.Text + "\r\n";
  4473. FileInfo += "生产日期: " + textBox_MACDate.Text + "\r\n";
  4474. FileInfo += "产品标识: " + textBox_PP.Text + "\r\n";
  4475. FileInfo += "\r\n";
  4476. FileInfo += "[自定义信息]\r\n";
  4477. FileInfo += "自定义1: " + textBox_User1.Text + "\r\n";
  4478. FileInfo += "自定义2: " + textBox_User2.Text + "\r\n";
  4479. FileInfo += "自定义3: " + textBox_User3.Text + "\r\n";
  4480. FileInfo += "\r\n";
  4481. FileInfo += "[校验密钥]\r\n";
  4482. FileInfo += textBox_Key.Text + "\r\n";
  4483. FileInfo += "\r\n";
  4484. FileInfo += "[存储标志]\r\n";
  4485. FileInfo += "EEPROM: " + ((radioButton_EE_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  4486. FileInfo += "SIP: " + ((radioButton_SIP_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  4487. FileInfo += "\r\n";
  4488. FileInfo += Local_HdInformation;
  4489. System.IO.File.WriteAllText(DataFileName, FileInfo);
  4490. Delay_ms(1000);
  4491. timer_1s.Enabled = false;
  4492. MessageBox.Show("存储完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  4493. timer_1s.Enabled = true;
  4494. //数据上传
  4495. if (myFtp.IsNetConnected == true)
  4496. {
  4497. string DataNow = DateTime.Now.ToString("yyyy-MM-dd");
  4498. //检查路径
  4499. if (myFtp.DirectoryExist("\\", toolStripTextBox_ServerPath.Text) == false)
  4500. {
  4501. myFtp.MakeDir(toolStripTextBox_ServerPath.Text);
  4502. }
  4503. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text, "Samples") == false)
  4504. {
  4505. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples");
  4506. }
  4507. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples", DataNow) == false)
  4508. {
  4509. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow);
  4510. }
  4511. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow, PD_PathName) == false)
  4512. {
  4513. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4514. }
  4515. //上传文件
  4516. bool result1 = myFtp.UploadFile(PIC_SaveFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4517. bool result2 = myFtp.UploadFile(DataFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4518. if ((result1 & result2) == true)
  4519. {
  4520. timer_1s.Enabled = false;
  4521. MessageBoxTimeOut.Show("数据已上传!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  4522. timer_1s.Enabled = true;
  4523. }
  4524. else
  4525. {
  4526. timer_1s.Enabled = false;
  4527. MessageBox.Show("数据上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4528. timer_1s.Enabled = true;
  4529. }
  4530. }
  4531. else
  4532. {
  4533. timer_1s.Enabled = false;
  4534. MessageBox.Show("服务器断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4535. timer_1s.Enabled = true;
  4536. }
  4537. Button_FacModeSaveResult.Text = "保存数据";
  4538. return;
  4539. } while (false);
  4540. timer_1s.Enabled = false;
  4541. MessageBox.Show("保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4542. timer_1s.Enabled = true;
  4543. Button_FacModeSaveResult.Text = "保存数据";
  4544. }
  4545. /// <summary>
  4546. /// 工具箱页面保存
  4547. /// </summary>
  4548. /// <param name="sender"></param>
  4549. /// <param name="e"></param>
  4550. private void 页面保存ToolStripMenuItem_Click(object sender, EventArgs e)
  4551. {
  4552. Double scaleX = PrimaryScreen.ScaleX;
  4553. Double scaleY = PrimaryScreen.ScaleY;
  4554. //保存页面
  4555. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  4556. Graphics g = Graphics.FromImage(bit);
  4557. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  4558. SaveFileDialog sf = new SaveFileDialog();
  4559. sf.Title = "页面保存";
  4560. sf.FileName = "MotorInfo_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".png";
  4561. sf.Filter = "图片|*.png";
  4562. timer_1s.Enabled = false;
  4563. if (sf.ShowDialog() == DialogResult.OK)
  4564. {
  4565. bit.Save(sf.FileName);//默认保存格式为PNG,保存成jpg格式质量不是很好
  4566. }
  4567. timer_1s.Enabled = true;
  4568. }
  4569. /// <summary>
  4570. /// 生产模式关机
  4571. /// </summary>
  4572. /// <param name="sender"></param>
  4573. /// <param name="e"></param>
  4574. private void Button_FacModePowerOff_Click(object sender, EventArgs e)
  4575. {
  4576. var Code_Off = new byte[5];
  4577. var Code_Reset = new byte[5];
  4578. Code_Off[0] = (byte)'O';
  4579. Code_Off[1] = (byte)'F';
  4580. Code_Off[2] = (byte)'F';
  4581. Code_Off[3] = (byte)'.';
  4582. Code_Off[4] = (byte)'.';
  4583. Code_Reset[0] = (byte)'R';
  4584. Code_Reset[1] = (byte)'E';
  4585. Code_Reset[2] = (byte)'S';
  4586. Code_Reset[3] = (byte)'E';
  4587. Code_Reset[4] = (byte)'T';
  4588. timer_1s.Enabled = false;
  4589. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  4590. {
  4591. timer_1s.Enabled = true;
  4592. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  4593. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  4594. PowerOffAckStatus = false;
  4595. Delay_ms(250);
  4596. int TryCnt = 3;
  4597. while ((TryCnt--) >= 0)
  4598. {
  4599. if (!PowerOffAckStatus)
  4600. {
  4601. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  4602. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  4603. PowerOffAckStatus = false;
  4604. Delay_ms(250);
  4605. }
  4606. else break;
  4607. }
  4608. if (PowerOffAckStatus)
  4609. {
  4610. timer_1s.Enabled = false;
  4611. MessageBox.Show("已关机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  4612. timer_1s.Enabled = true;
  4613. }
  4614. else
  4615. {
  4616. timer_1s.Enabled = false;
  4617. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4618. timer_1s.Enabled = true;
  4619. }
  4620. }
  4621. timer_1s.Enabled = true;
  4622. }
  4623. //仪表电源键按下
  4624. private void button_OBC_ButtonPower_Click(object sender, EventArgs e)
  4625. {
  4626. var Code = new byte[2];
  4627. Code[0] = 0;
  4628. Code[1] = 0b00100000;
  4629. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4630. }
  4631. /// <summary>
  4632. /// 仪表加键按下
  4633. /// </summary>
  4634. /// <param name="sender"></param>
  4635. /// <param name="e"></param>
  4636. private void button_OBC_ButtonAcc_Click(object sender, EventArgs e)
  4637. {
  4638. var Code = new byte[2];
  4639. Code[0] = 0;
  4640. Code[1] = 0b00010000;
  4641. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4642. }
  4643. /// <summary>
  4644. /// 仪表减键按下
  4645. /// </summary>
  4646. /// <param name="sender"></param>
  4647. /// <param name="e"></param>
  4648. private void button_OBC_ButtonDec_Click(object sender, EventArgs e)
  4649. {
  4650. var Code = new byte[2];
  4651. Code[0] = 0;
  4652. Code[1] = 0b00001000;
  4653. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4654. }
  4655. /// <summary>
  4656. /// 仪表Walk键按下
  4657. /// </summary>
  4658. /// <param name="sender"></param>
  4659. /// <param name="e"></param>
  4660. private void button_OBC_ButtonWalk_Click(object sender, EventArgs e)
  4661. {
  4662. var Code = new byte[2];
  4663. Code[0] = 0;
  4664. Code[1] = 0b00000100;
  4665. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4666. }
  4667. /// <summary>
  4668. /// 仪表Light键按下
  4669. /// </summary>
  4670. /// <param name="sender"></param>
  4671. /// <param name="e"></param>
  4672. private void button_OBC_ButtonLight_Click(object sender, EventArgs e)
  4673. {
  4674. var Code = new byte[2];
  4675. Code[0] = 0;
  4676. Code[1] = 0b00000010;
  4677. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4678. }
  4679. /// <summary>
  4680. /// 仪表Set键按下
  4681. /// </summary>
  4682. /// <param name="sender"></param>
  4683. /// <param name="e"></param>
  4684. private void button_OBC_ButtonSet_Click(object sender, EventArgs e)
  4685. {
  4686. var Code = new byte[2];
  4687. Code[0] = 0;
  4688. Code[1] = 0b00000001;
  4689. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4690. }
  4691. /// <summary>
  4692. /// 导出电机故障日志
  4693. /// </summary>
  4694. /// <param name="sender"></param>
  4695. /// <param name="e"></param>
  4696. private void button_ExportLog_Click(object sender, EventArgs e)
  4697. {
  4698. var Address = new byte[4];
  4699. UInt32 Address_Begin;
  4700. UInt32 Addres_End;
  4701. string textBox_Address_Begin = textBox_LogAddrBegin.Text;
  4702. string textBox_Address_End = textBox_LogAddrEnd.Text;
  4703. richTextBox_Record.Clear();
  4704. textBox_LogAddrBegin.ReadOnly = true;
  4705. textBox_LogAddrEnd.ReadOnly = true;
  4706. if (!mySerialProcess.mySerial.IsOpen)
  4707. {
  4708. timer_1s.Enabled = false;
  4709. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4710. timer_1s.Enabled = true;
  4711. return;
  4712. }
  4713. if ((textBox_Address_Begin == string.Empty) || (textBox_Address_End == string.Empty))
  4714. {
  4715. timer_1s.Enabled = false;
  4716. MessageBox.Show("请输入日志存储起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4717. timer_1s.Enabled = true;
  4718. return;
  4719. }
  4720. else
  4721. {
  4722. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin, false);
  4723. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  4724. Address = mySerialProcess.HexStringToBytes(textBox_Address_End, false);
  4725. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  4726. if (Addres_End <= Address_Begin)
  4727. {
  4728. timer_1s.Enabled = false;
  4729. MessageBox.Show("结束地址应大于起始地址!", "提示");
  4730. timer_1s.Enabled = true;
  4731. return;
  4732. }
  4733. else if (((Addres_End - Address_Begin + 1) % 128) != 0) //
  4734. {
  4735. timer_1s.Enabled = false;
  4736. MessageBox.Show("(结束地址 - 起始地址 + 1)应为128整数倍!", "提示");
  4737. timer_1s.Enabled = true;
  4738. return;
  4739. }
  4740. else
  4741. {
  4742. UInt32 ReadCount = 0;
  4743. button_ExportLog.Text = "导出中...";
  4744. button_ExportLog.Enabled = false;
  4745. ReadCount = (Addres_End - Address_Begin + 1) / 128;
  4746. for (ushort i = 0; i < ReadCount; i++)
  4747. {
  4748. var SendByte = new byte[8];
  4749. UInt32 Address_Temp_Begin;
  4750. UInt32 Address_Temp_End;
  4751. Address_Temp_Begin = Address_Begin + 128 * (UInt32)i;
  4752. SendByte[0] = (byte)(Address_Temp_Begin >> 24);
  4753. SendByte[1] = (byte)(Address_Temp_Begin >> 16);
  4754. SendByte[2] = (byte)(Address_Temp_Begin >> 8);
  4755. SendByte[3] = (byte)(Address_Temp_Begin);
  4756. Address_Temp_End = Address_Temp_Begin + 127;
  4757. SendByte[4] = (byte)(Address_Temp_End >> 24);
  4758. SendByte[5] = (byte)(Address_Temp_End >> 16);
  4759. SendByte[6] = (byte)(Address_Temp_End >> 8);
  4760. SendByte[7] = (byte)(Address_Temp_End);
  4761. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  4762. Delay_ms(200);//Thread.Sleep(200);
  4763. }
  4764. button_ExportLog.Text = "导出日志";
  4765. button_ExportLog.Enabled = true;
  4766. }
  4767. }
  4768. }
  4769. /// <summary>
  4770. /// 保存日志信息
  4771. /// </summary>
  4772. /// <param name="sender"></param>
  4773. /// <param name="e"></param>
  4774. private void button_SaveRecordInfo_Click(object sender, EventArgs e)
  4775. {
  4776. string SaveInfo = "";
  4777. if (richTextBox_Record.Text == string.Empty)
  4778. {
  4779. timer_1s.Enabled = false;
  4780. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  4781. timer_1s.Enabled = true;
  4782. return;
  4783. }
  4784. //获取保存信息
  4785. SaveInfo += "读取时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  4786. SaveInfo += "电机型号:" + textBox_FacModeName.Text + "\r\n";
  4787. SaveInfo += "电机SN:" + textBox_FacModeNum.Text + "\r\n";
  4788. SaveInfo += "硬件版本:" + textBox_FacModeHW.Text + "\r\n";
  4789. SaveInfo += "软件版本:" + textBox_FacModeFW.Text + "\r\n";
  4790. SaveInfo += "\r\n";
  4791. SaveInfo += richTextBox_Record.Text;
  4792. //设置保存路径和文件名
  4793. SaveFileDialog sf = new SaveFileDialog();
  4794. sf.Title = "数据保存";
  4795. sf.FileName = "MotorLog_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".ttlog";
  4796. sf.FileName.Replace(" ", "");
  4797. sf.Filter = "日志|*.ttlog";
  4798. if (sf.ShowDialog() == DialogResult.OK)
  4799. {
  4800. System.IO.File.AppendAllText(sf.FileName, SaveInfo);
  4801. }
  4802. }
  4803. /// <summary>
  4804. /// 双击修改日志起始地址
  4805. /// </summary>
  4806. /// <param name="sender"></param>
  4807. /// <param name="e"></param>
  4808. private void label_LogAddrBegin_DoubleClick_1(object sender, EventArgs e)
  4809. {
  4810. textBox_LogAddrBegin.ReadOnly = false;
  4811. }
  4812. /// <summary>
  4813. /// 双击修改日志结束地址
  4814. /// </summary>
  4815. /// <param name="sender"></param>
  4816. /// <param name="e"></param>
  4817. private void label88_DoubleClick(object sender, EventArgs e)
  4818. {
  4819. textBox_LogAddrEnd.ReadOnly = false;
  4820. }
  4821. /// <summary>
  4822. /// 存储器自动读取选择
  4823. /// </summary>
  4824. /// <param name="sender"></param>
  4825. /// <param name="e"></param>
  4826. private void checkBox_ReadRanFlash_AutoSW_CheckedChanged(object sender, EventArgs e)
  4827. {
  4828. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  4829. {
  4830. //检查串口是否打开
  4831. if (!mySerialProcess.mySerial.IsOpen)
  4832. {
  4833. timer_1s.Enabled = false;
  4834. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4835. timer_1s.Enabled = true;
  4836. checkBox_ReadRanFlash_AutoSW.Checked = false;
  4837. return;
  4838. }
  4839. }
  4840. }
  4841. /// <summary>
  4842. /// 系统开机按钮
  4843. /// </summary>
  4844. /// <param name="sender"></param>
  4845. /// <param name="e"></param>
  4846. private void 开机ToolStripMenuItem_Click(object sender, EventArgs e)
  4847. {
  4848. byte[] Data = new byte[1];
  4849. Data[0] = 0xF1;
  4850. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  4851. }
  4852. /// <summary>
  4853. /// 系统关机按钮
  4854. /// </summary>
  4855. /// <param name="sender"></param>
  4856. /// <param name="e"></param>
  4857. private void 关机ToolStripMenuItem_Click(object sender, EventArgs e)
  4858. {
  4859. byte[] Data = new byte[1];
  4860. Data[0] = 0xF0;
  4861. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  4862. }
  4863. /// <summary>
  4864. /// 连接开机选择
  4865. /// </summary>
  4866. /// <param name="sender"></param>
  4867. /// <param name="e"></param>
  4868. private void 连接开机ToolStripMenuItem_Click(object sender, EventArgs e)
  4869. {
  4870. //输入用户名
  4871. EnterForm1.ShowDialog();
  4872. try
  4873. {
  4874. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  4875. {
  4876. if (EnterForm1.comboBox_User.Text == "管理员")
  4877. {
  4878. 连接开机ToolStripMenuItem.Checked = !连接开机ToolStripMenuItem.Checked;
  4879. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  4880. }
  4881. else
  4882. {
  4883. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4884. }
  4885. }
  4886. else
  4887. {
  4888. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4889. }
  4890. }
  4891. catch (Exception)
  4892. {
  4893. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4894. }
  4895. }
  4896. /// <summary>
  4897. /// 断开关机选择
  4898. /// </summary>
  4899. /// <param name="sender"></param>
  4900. /// <param name="e"></param>
  4901. private void 断开关机ToolStripMenuItem_Click(object sender, EventArgs e)
  4902. {
  4903. //输入用户名
  4904. EnterForm1.ShowDialog();
  4905. try
  4906. {
  4907. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  4908. {
  4909. if (EnterForm1.comboBox_User.Text == "管理员")
  4910. {
  4911. 断开关机ToolStripMenuItem.Checked = !断开关机ToolStripMenuItem.Checked;
  4912. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  4913. }
  4914. else
  4915. {
  4916. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4917. }
  4918. }
  4919. else
  4920. {
  4921. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4922. }
  4923. }
  4924. catch (Exception)
  4925. {
  4926. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4927. }
  4928. }
  4929. /// <summary>
  4930. /// 识别通讯盒选择
  4931. /// </summary>
  4932. /// <param name="sender"></param>
  4933. /// <param name="e"></param>
  4934. private void 识别通讯盒ToolStripMenuItem_Click(object sender, EventArgs e)
  4935. {
  4936. //输入用户名
  4937. EnterForm1.ShowDialog();
  4938. try
  4939. {
  4940. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  4941. {
  4942. if (EnterForm1.comboBox_User.Text == "管理员")
  4943. {
  4944. 识别通讯盒ToolStripMenuItem.Checked = !识别通讯盒ToolStripMenuItem.Checked;
  4945. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  4946. }
  4947. else
  4948. {
  4949. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4950. }
  4951. }
  4952. else
  4953. {
  4954. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4955. }
  4956. }
  4957. catch (Exception)
  4958. {
  4959. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4960. }
  4961. }
  4962. /// <summary>
  4963. /// 将配置信息导出为cfg文件
  4964. /// </summary>
  4965. private void ConfigFileSave(bool DeleteFlag, string FileName)
  4966. {
  4967. if (DeleteFlag)
  4968. {
  4969. if (File.Exists(FileName))
  4970. File.Delete(FileName);
  4971. }
  4972. string CfgFileInfo = "";
  4973. CfgFileInfo += "[PortSet]" + "\r\n";
  4974. CfgFileInfo += "PortNum:" + toolStripComboBox_ComNum.Text + "\r\n";
  4975. CfgFileInfo += "PortBaudrate:" + "115200" + "\r\n";
  4976. CfgFileInfo += "AutoOn:" + 连接开机ToolStripMenuItem.Checked.ToString() + "\r\n";
  4977. CfgFileInfo += "AutoOff:" + 断开关机ToolStripMenuItem.Checked.ToString() + "\r\n";
  4978. CfgFileInfo += "CheckCDL:" + 识别通讯盒ToolStripMenuItem.Checked.ToString() + "\r\n";
  4979. CfgFileInfo += "\r\n";
  4980. CfgFileInfo += "[Option]" + "\r\n";
  4981. CfgFileInfo += "SaveWhenWrite:" + 写入存储ToolStripMenuItem.Checked.ToString() + "\r\n";
  4982. CfgFileInfo += "OfflineEnable:" + 允许ToolStripMenuItem.Checked + "\r\n";
  4983. CfgFileInfo += "\r\n";
  4984. CfgFileInfo += "[ServerSet]" + "\r\n";
  4985. CfgFileInfo += "IPAddress:" + toolStripTextBox_ServerIP.Text + "\r\n";
  4986. CfgFileInfo += "Port:" + toolStripTextBox_ServerPort.Text + "\r\n";
  4987. CfgFileInfo += "User:" + toolStripTextBox_ServerUser.Text + "\r\n";
  4988. CfgFileInfo += "Password:" + toolStripTextBox_ServerPasswd.Text + "\r\n";
  4989. CfgFileInfo += "PathName:" + toolStripTextBox_ServerPath.Text + "\r\n";
  4990. CfgFileInfo += "\r\n";
  4991. CfgFileInfo += "[MacInfo]" + "\r\n";
  4992. CfgFileInfo += "MacName:" + toolStripTextBox_MAC.Text + "\r\n";
  4993. CfgFileInfo += "MacAddress:" + toolStripTextBoxMACAddr.Text + "\r\n";
  4994. CfgFileInfo += "MacDate:" + toolStripTextBox_MACDate.Text + "\r\n";
  4995. CfgFileInfo += "MacPdInfo:" + toolStripTextBox_MACPD.Text + "\r\n";
  4996. CfgFileInfo += "\r\n";
  4997. CfgFileInfo += "[LogAddress]" + "\r\n";
  4998. CfgFileInfo += "BeginAddress:" + textBox_LogAddrBegin.Text + "\r\n";
  4999. CfgFileInfo += "EndAddress:" + textBox_LogAddrEnd.Text + "\r\n";
  5000. CfgFileInfo += "\r\n";
  5001. CfgFileInfo += "[MotorType]" + "\r\n";
  5002. CfgFileInfo += "MidMotor:" + 中置电机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5003. CfgFileInfo += "HubMotor:" + 轮毂电机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5004. CfgFileInfo += "\r\n";
  5005. CfgFileInfo += "[CheckValue]" + "\r\n";
  5006. CfgFileInfo += "Voltage:" + toolStripTextBox_ThVol.Text + "\r\n";
  5007. CfgFileInfo += "Current:" + toolStripTextBox_ThCur.Text + "\r\n";
  5008. CfgFileInfo += "MotorSpeed:" + toolStripTextBox_ThSpeed.Text + "\r\n";
  5009. CfgFileInfo += "Torque:" + toolStripTextBox_ThTor.Text + "\r\n";
  5010. CfgFileInfo += "Cadence:" + toolStripTextBox_ThCad.Text + "\r\n";
  5011. CfgFileInfo += "BikeSpeed:" + toolStripTextBox_ThBikeSpeed.Text + "\r\n";
  5012. CfgFileInfo += "T_PCB:" + toolStripTextBox_ThT_PCB.Text + "\r\n";
  5013. CfgFileInfo += "T_MCU:" + toolStripTextBox_ThT_MCU.Text + "\r\n";
  5014. CfgFileInfo += "T_Motor:" + toolStripTextBox_ThT_Motor.Text + "\r\n";
  5015. CfgFileInfo += "\r\n";
  5016. CfgFileInfo += "[MosCalK]" + "\r\n";
  5017. CfgFileInfo += "K1-K5:" + toolStripTextBox_MosCalK.Text + "\r\n";
  5018. CfgFileInfo += "MOS1:" + toolStripTextBox_MOS1.Text + "\r\n";
  5019. CfgFileInfo += "MOS2:" + toolStripTextBox_MOS2.Text + "\r\n";
  5020. CfgFileInfo += "MOS3:" + toolStripTextBox_MOS3.Text + "\r\n";
  5021. CfgFileInfo += "\r\n";
  5022. CfgFileInfo += "[ProtocolType]" + "\r\n";
  5023. CfgFileInfo += "CAN:" + cANToolStripMenuItem.Checked.ToString() + "\r\n";
  5024. CfgFileInfo += "UART:" + uARTToolStripMenuItem.Checked.ToString() + "\r\n";
  5025. CfgFileInfo += "\r\n";
  5026. CfgFileInfo += "[AutoUpdate]" + "\r\n";
  5027. CfgFileInfo += "AutoUpdate:" + 打开ToolStripMenuItem.Checked.ToString() + "\r\n";
  5028. System.IO.File.WriteAllText(FileName, CfgFileInfo);
  5029. }
  5030. /// <summary>
  5031. /// 配置状态更新,点击时保存
  5032. /// </summary>
  5033. private void ConfigFileSave_Click(object sender, EventArgs e)
  5034. {
  5035. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5036. }
  5037. /// <summary>
  5038. /// 文本框修改结束,回车保存
  5039. /// </summary>
  5040. /// <param name="sender"></param>
  5041. /// <param name="e"></param>
  5042. private void ConfigFileSave_KeyDown(object sender, KeyEventArgs e)
  5043. {
  5044. if (e.KeyCode == Keys.Enter)
  5045. {
  5046. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5047. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  5048. }
  5049. }
  5050. /// <summary>
  5051. /// 允许离线使用
  5052. /// </summary>
  5053. /// <param name="sender"></param>
  5054. /// <param name="e"></param>
  5055. private void 允许ToolStripMenuItem_Click(object sender, EventArgs e)
  5056. {
  5057. //输入用户名
  5058. EnterForm1.ShowDialog();
  5059. try
  5060. {
  5061. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5062. {
  5063. if (EnterForm1.comboBox_User.Text == "管理员")
  5064. {
  5065. 允许ToolStripMenuItem.Checked = true;
  5066. 不允许ToolStripMenuItem.Checked = false;
  5067. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5068. }
  5069. else
  5070. {
  5071. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5072. 允许ToolStripMenuItem.Checked = false;
  5073. 不允许ToolStripMenuItem.Checked = true;
  5074. }
  5075. }
  5076. else
  5077. {
  5078. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5079. 允许ToolStripMenuItem.Checked = false;
  5080. 不允许ToolStripMenuItem.Checked = true;
  5081. }
  5082. }
  5083. catch (Exception)
  5084. {
  5085. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5086. 允许ToolStripMenuItem.Checked = false;
  5087. 不允许ToolStripMenuItem.Checked = true;
  5088. }
  5089. }
  5090. /// <summary>
  5091. /// 不允许离线使用
  5092. /// </summary>
  5093. /// <param name="sender"></param>
  5094. /// <param name="e"></param>
  5095. private void 不允许ToolStripMenuItem_Click(object sender, EventArgs e)
  5096. {
  5097. 允许ToolStripMenuItem.Checked = false;
  5098. 不允许ToolStripMenuItem.Checked = true;
  5099. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5100. }
  5101. /// <summary>
  5102. /// 弹出扫码按钮
  5103. /// </summary>
  5104. /// <param name="sender"></param>
  5105. /// <param name="e"></param>
  5106. private void button_ScanCode_Click(object sender, EventArgs e)
  5107. {
  5108. Scan scan_form = new Scan();
  5109. scan_form.ShowDialog();
  5110. do
  5111. {
  5112. if (scan_form.textBox_Scan.Text == string.Empty)
  5113. {
  5114. timer_1s.Enabled = false;
  5115. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5116. timer_1s.Enabled = true;
  5117. break;
  5118. }
  5119. string ScanInfo = scan_form.textBox_Scan.Text;
  5120. string regexInfo = "";
  5121. string[] InfoList = { "" };
  5122. try
  5123. {
  5124. if (中置电机ToolStripMenuItem.Checked == true)
  5125. {
  5126. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  5127. InfoList = Regex.Split(ScanInfo, regexInfo, RegexOptions.IgnoreCase);
  5128. }
  5129. else if (轮毂电机ToolStripMenuItem.Checked == true)
  5130. {
  5131. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  5132. string Model = InfoList[0];
  5133. string Spec = InfoList[1];
  5134. string Sn = InfoList[2];
  5135. InfoList[0] = Model.Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  5136. InfoList[1] = Sn;
  5137. }
  5138. }
  5139. catch (Exception)
  5140. {
  5141. MessageBox.Show("格式错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5142. return;
  5143. }
  5144. if (InfoList.Length >= 2)
  5145. {
  5146. //写入型号
  5147. textBox_FacModeName.Text = InfoList[0];
  5148. string Mode = textBox_FacModeName.Text;
  5149. var ModeArray = new byte[16];
  5150. for (ushort i = 0; i < Mode.Length; i++)
  5151. {
  5152. ModeArray[i] = (byte)Mode[i];
  5153. }
  5154. if (Mode.Length < 16)
  5155. {
  5156. ModeArray[Mode.Length] = (byte)'.';
  5157. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  5158. {
  5159. ModeArray[Mode.Length + 1 + i] = 0x20;
  5160. }
  5161. }
  5162. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  5163. //写入SN
  5164. textBox_FacModeNum.Text = InfoList[1];
  5165. string SN = textBox_FacModeNum.Text;
  5166. var SNArray = new byte[16];
  5167. for (ushort i = 0; i < SN.Length; i++)
  5168. {
  5169. SNArray[i] = (byte)SN[i];
  5170. }
  5171. if (SN.Length < 16)
  5172. {
  5173. SNArray[SN.Length] = (byte)'.';
  5174. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  5175. {
  5176. SNArray[SN.Length + 1 + i] = 0x20;
  5177. }
  5178. }
  5179. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  5180. }
  5181. else
  5182. {
  5183. timer_1s.Enabled = false;
  5184. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5185. timer_1s.Enabled = true;
  5186. break;
  5187. }
  5188. } while (false);
  5189. scan_form.Dispose();
  5190. }
  5191. private void 服务器配置ToolStripMenuItem_Click(object sender, EventArgs e)
  5192. {
  5193. //输入用户名
  5194. EnterForm1.ShowDialog();
  5195. try
  5196. {
  5197. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5198. {
  5199. if (EnterForm1.comboBox_User.Text == "管理员")
  5200. {
  5201. IP地址ToolStripMenuItem.Visible = true;
  5202. 端口ToolStripMenuItem.Visible = true;
  5203. 用户名ToolStripMenuItem.Visible = true;
  5204. 密码ToolStripMenuItem.Visible = true;
  5205. 存储路径ToolStripMenuItem.Visible = true;
  5206. }
  5207. else
  5208. {
  5209. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5210. IP地址ToolStripMenuItem.Visible = false;
  5211. 端口ToolStripMenuItem.Visible = false;
  5212. 用户名ToolStripMenuItem.Visible = false;
  5213. 密码ToolStripMenuItem.Visible = false;
  5214. 存储路径ToolStripMenuItem.Visible = false;
  5215. }
  5216. }
  5217. else
  5218. {
  5219. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5220. IP地址ToolStripMenuItem.Visible = false;
  5221. 端口ToolStripMenuItem.Visible = false;
  5222. 用户名ToolStripMenuItem.Visible = false;
  5223. 密码ToolStripMenuItem.Visible = false;
  5224. 存储路径ToolStripMenuItem.Visible = false;
  5225. }
  5226. }
  5227. catch (Exception)
  5228. {
  5229. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5230. IP地址ToolStripMenuItem.Visible = false;
  5231. 端口ToolStripMenuItem.Visible = false;
  5232. 用户名ToolStripMenuItem.Visible = false;
  5233. 密码ToolStripMenuItem.Visible = false;
  5234. 存储路径ToolStripMenuItem.Visible = false;
  5235. }
  5236. }
  5237. private void 生产信息ToolStripMenuItem_Click(object sender, EventArgs e)
  5238. {
  5239. //输入用户名
  5240. EnterForm1.ShowDialog();
  5241. try
  5242. {
  5243. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5244. {
  5245. if (EnterForm1.comboBox_User.Text == "管理员")
  5246. {
  5247. 生产商ToolStripMenuItem.Visible = true;
  5248. 生产地ToolStripMenuItem.Visible = true;
  5249. 生产日期ToolStripMenuItem.Visible = true;
  5250. 产品标识ToolStripMenuItem.Visible = true;
  5251. }
  5252. else
  5253. {
  5254. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5255. 生产商ToolStripMenuItem.Visible = false;
  5256. 生产地ToolStripMenuItem.Visible = false;
  5257. 生产日期ToolStripMenuItem.Visible = false;
  5258. 产品标识ToolStripMenuItem.Visible = false;
  5259. }
  5260. }
  5261. else
  5262. {
  5263. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5264. 生产商ToolStripMenuItem.Visible = false;
  5265. 生产地ToolStripMenuItem.Visible = false;
  5266. 生产日期ToolStripMenuItem.Visible = false;
  5267. 产品标识ToolStripMenuItem.Visible = false;
  5268. }
  5269. }
  5270. catch (Exception)
  5271. {
  5272. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5273. 生产商ToolStripMenuItem.Visible = false;
  5274. 生产地ToolStripMenuItem.Visible = false;
  5275. 生产日期ToolStripMenuItem.Visible = false;
  5276. 产品标识ToolStripMenuItem.Visible = false;
  5277. }
  5278. }
  5279. /// <summary>
  5280. /// 切换电机类型
  5281. /// </summary>
  5282. /// <param name="sender"></param>
  5283. /// <param name="e"></param>
  5284. private void 中置电机ToolStripMenuItem_Click(object sender, EventArgs e)
  5285. {
  5286. 中置电机ToolStripMenuItem.Checked = true;
  5287. 轮毂电机ToolStripMenuItem.Checked = false;
  5288. toolStripTextBox_MACPD.Text = "MM_MC1";
  5289. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  5290. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5291. }
  5292. /// <summary>
  5293. /// 切换电机类型
  5294. /// </summary>
  5295. /// <param name="sender"></param>
  5296. /// <param name="e"></param>
  5297. private void 轮毂电机ToolStripMenuItem_Click(object sender, EventArgs e)
  5298. {
  5299. 中置电机ToolStripMenuItem.Checked = false;
  5300. 轮毂电机ToolStripMenuItem.Checked = true;
  5301. toolStripTextBox_MACPD.Text = "GF_250_1";
  5302. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  5303. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5304. }
  5305. /// <summary>
  5306. /// 获取配置文件日期
  5307. /// </summary>
  5308. /// <param name="DisAll"></param>
  5309. private void GetDateList(bool DisAll)
  5310. {
  5311. string[] DateList = { "" };
  5312. //从服务器更新日期列表
  5313. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  5314. {
  5315. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
  5316. }
  5317. //从本地更新日期列表
  5318. else
  5319. {
  5320. DateList = Directory.GetDirectories(localInfo.LocalPath + "\\" + localInfo.CfgPathName);
  5321. }
  5322. comboBox_FacModeCfgDate.Items.Clear();
  5323. comboBox_CheckModeCfgDate.Items.Clear();
  5324. //日期列表加载
  5325. if (DisAll == true)
  5326. {
  5327. comboBox_FacModeCfgDate.Items.Add("显示近期");
  5328. comboBox_CheckModeCfgDate.Items.Add("显示近期");
  5329. comboBox_FacModeCfgDate.Items.Add("---");
  5330. comboBox_CheckModeCfgDate.Items.Add("---");
  5331. foreach (var file in DateList)
  5332. {
  5333. comboBox_FacModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5334. comboBox_CheckModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5335. }
  5336. }
  5337. else
  5338. {
  5339. if (DateList.Length > 10)
  5340. {
  5341. comboBox_FacModeCfgDate.Items.Add("显示全部");
  5342. comboBox_CheckModeCfgDate.Items.Add("显示全部");
  5343. comboBox_FacModeCfgDate.Items.Add("---");
  5344. comboBox_CheckModeCfgDate.Items.Add("---");
  5345. }
  5346. for (int i = (DateList.Length > 10) ? (DateList.Length - 10) : 0; i < DateList.Length; i++)//显示最近10个日期
  5347. {
  5348. comboBox_FacModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  5349. comboBox_CheckModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  5350. }
  5351. }
  5352. }
  5353. /// <summary>
  5354. /// 获取配置文件列表
  5355. /// </summary>
  5356. /// <param name="date"></param>
  5357. private void GetFileListFrom(string date)
  5358. {
  5359. string[] FileList = { "" };
  5360. //从服务器更新文件列表
  5361. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  5362. {
  5363. FileList = myFtp.GetFileNameList(toolStripTextBox_ServerPath.Text + "/cfg/" + date);
  5364. }
  5365. else
  5366. {
  5367. FileList = Directory.GetFiles(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + date);
  5368. }
  5369. comboBox_CheckModeCfgFile.Items.Clear();
  5370. comboBox_FacModeCfgFile.Items.Clear();
  5371. foreach (var file in FileList)
  5372. {
  5373. if (file.Contains(".ttcfg"))
  5374. {
  5375. comboBox_CheckModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5376. comboBox_FacModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5377. }
  5378. }
  5379. }
  5380. /// <summary>
  5381. /// 检验模式选择文件日期
  5382. /// </summary>
  5383. /// <param name="sender"></param>
  5384. /// <param name="e"></param>
  5385. private void comboBox_CheckModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  5386. {
  5387. if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示全部")
  5388. {
  5389. GetDateList(true);
  5390. }
  5391. else if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示近期")
  5392. {
  5393. GetDateList(false);
  5394. }
  5395. else
  5396. {
  5397. comboBox_CheckModeCfgFile.Text = "";
  5398. GetFileListFrom(comboBox_CheckModeCfgDate.SelectedItem.ToString());
  5399. }
  5400. }
  5401. /// <summary>
  5402. /// 配置模式选择文件日期
  5403. /// </summary>
  5404. /// <param name="sender"></param>
  5405. /// <param name="e"></param>
  5406. private void comboBox_FacModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  5407. {
  5408. if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示全部")
  5409. {
  5410. GetDateList(true);
  5411. }
  5412. else if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示近期")
  5413. {
  5414. GetDateList(false);
  5415. }
  5416. else
  5417. {
  5418. comboBox_FacModeCfgFile.Text = "";
  5419. GetFileListFrom(comboBox_FacModeCfgDate.SelectedItem.ToString());
  5420. }
  5421. }
  5422. /// <summary>
  5423. /// 选中量产模式
  5424. /// </summary>
  5425. /// <param name="sender"></param>
  5426. /// <param name="e"></param>
  5427. private void tabControl1_Selected(object sender, TabControlEventArgs e)
  5428. {
  5429. //更新生产配置文件目录
  5430. GetDateList(false);
  5431. }
  5432. /// <summary>
  5433. /// 量产测试结束
  5434. /// </summary>
  5435. /// <param name=""></param>
  5436. private void FacMode_Stop(bool OK_Flag)
  5437. {
  5438. //打开开始按钮
  5439. button__FacMode_Start.Enabled = true;
  5440. //系统关机
  5441. var Code = new byte[32];//发送的指令数据
  5442. Code[0] = 0xF0;
  5443. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5444. //关闭串口
  5445. //mySerialProcess.SerialClose(false);
  5446. //路径设置
  5447. string LocalSavePath = "";
  5448. string ServerSavePath = "";
  5449. if (OK_Flag)
  5450. {
  5451. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "OK\\";
  5452. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/OK/";
  5453. }
  5454. else
  5455. {
  5456. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "FAIL\\";
  5457. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/FAIL/";
  5458. }
  5459. if (Directory.Exists(LocalSavePath) == false)
  5460. {
  5461. Directory.CreateDirectory(LocalSavePath);
  5462. }
  5463. //保存和上传
  5464. string LogSavePath = "";
  5465. string LogSaveFileName = "";
  5466. string ProductInfo = textBox_FacModeScan.Text;
  5467. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  5468. if (Directory.Exists(LogSavePath) == false)
  5469. {
  5470. Directory.CreateDirectory(LogSavePath);
  5471. }
  5472. //测试页面
  5473. Double scaleX = PrimaryScreen.ScaleX;
  5474. Double scaleY = PrimaryScreen.ScaleY;
  5475. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  5476. Graphics g = Graphics.FromImage(bit);
  5477. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  5478. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  5479. bit.Save(LogSaveFileName);
  5480. //上传测试页面到服务器
  5481. if (myFtp.IsNetConnected == true)
  5482. {
  5483. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  5484. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  5485. {
  5486. myFtp.MakeDir(ServerSavePath + DateNow);
  5487. }
  5488. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  5489. {
  5490. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  5491. }
  5492. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  5493. if (result == true)
  5494. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  5495. }
  5496. else
  5497. {
  5498. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  5499. }
  5500. //测试记录
  5501. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  5502. string file_str = "";
  5503. file_str += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  5504. file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  5505. file_str += "检验记录:\r\n" + richTextBox_FacModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  5506. file_str += "检验结果:\r\n" + label_FacModeResult.Text + "\r\n\r\n";
  5507. file_str += Local_HdInformation;
  5508. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  5509. //上传测试记录到服务器
  5510. if (myFtp.IsNetConnected == true)
  5511. {
  5512. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  5513. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  5514. {
  5515. myFtp.MakeDir(ServerSavePath + DateNow);
  5516. }
  5517. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  5518. {
  5519. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  5520. }
  5521. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  5522. if (result == true)
  5523. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  5524. }
  5525. else
  5526. {
  5527. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  5528. }
  5529. //扫码框清空
  5530. textBox_FacModeScan.Text = "";
  5531. }
  5532. /// <summary>
  5533. /// 量产测试开始
  5534. /// </summary>
  5535. /// <param name="sender"></param>
  5536. /// <param name="e"></param>
  5537. private void button__FacMode_Start_Click(object sender, EventArgs e)
  5538. {
  5539. //关闭测试项目编辑
  5540. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  5541. foreach (Control c in groupBox2.Controls)
  5542. {
  5543. if (c is CheckBox)
  5544. c.Enabled = false;
  5545. }
  5546. WriteLockStatus = true;
  5547. //检查配置文件
  5548. if (comboBox_FacModeCfgFile.Text == "")
  5549. {
  5550. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5551. return;
  5552. }
  5553. //开始测试
  5554. TestStart();
  5555. }
  5556. /// <summary>
  5557. /// 测试子函数
  5558. /// </summary>
  5559. private void TestStart()
  5560. {
  5561. //初始化标签
  5562. FacModelLabelInit();
  5563. richTextBox_FacModeLog.Clear();
  5564. //按钮禁止操作
  5565. button__FacMode_Start.Enabled = false;
  5566. //记录配置文件
  5567. richTextBox_FacModeLog.AppendText("配置文件:" + comboBox_FacModeCfgDate.Text + " / " + comboBox_FacModeCfgFile.Text + "\r\n");
  5568. //检查打标信息格式
  5569. label_FacModeStatus.Text = "检查扫码信息";
  5570. Delay_ms(500);
  5571. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  5572. if (textBox_FacModeScan.Text == string.Empty)
  5573. {
  5574. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5575. button__FacMode_Start.Enabled = true;
  5576. return;
  5577. }
  5578. try
  5579. {
  5580. if (中置电机ToolStripMenuItem.Checked == true)
  5581. {
  5582. if (textBox_FacModeScan.Text.Split(' ').Length != 7)
  5583. {
  5584. label_FacModeStatus.Text = "存在故障!";
  5585. label_FacModeResult.BackColor = Color.Red;
  5586. label_FacModeResult.Text = "标签格式错误";
  5587. button__FacMode_Start.Enabled = true;
  5588. return;
  5589. }
  5590. }
  5591. else if (轮毂电机ToolStripMenuItem.Checked == true)
  5592. {
  5593. if (textBox_FacModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  5594. {
  5595. label_FacModeStatus.Text = "存在故障!";
  5596. label_FacModeResult.BackColor = Color.Red;
  5597. label_FacModeResult.Text = "标签格式错误";
  5598. button__FacMode_Start.Enabled = true;
  5599. return;
  5600. }
  5601. }
  5602. }
  5603. catch (System.Exception)
  5604. {
  5605. label_FacModeStatus.Text = "存在故障!";
  5606. label_FacModeResult.BackColor = Color.Red;
  5607. label_FacModeResult.Text = "标签格式错误";
  5608. button__FacMode_Start.Enabled = true;
  5609. return;
  5610. }
  5611. //打开串口
  5612. mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false);
  5613. if (!mySerialProcess.mySerial.IsOpen)
  5614. {
  5615. MessageBox.Show("请检查串口连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5616. //按钮禁止操作
  5617. button__FacMode_Start.Enabled = true;
  5618. return;
  5619. }
  5620. //流水号计数
  5621. int serial = Convert.ToInt32(label_FacModeSerial.Text);
  5622. serial += 1;
  5623. label_FacModeSerial.Text = serial.ToString();
  5624. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, serial.ToString());
  5625. //创建线程,执行测试任务
  5626. Thread th = new Thread(FacModeTest_Task);
  5627. th.Start();
  5628. }
  5629. /// <summary>
  5630. /// 执行一次测试任务
  5631. /// </summary>
  5632. private void FacModeTest_Task()
  5633. {
  5634. //开始测试
  5635. richTextBox_FacModeLog.AppendText("产品标签:" + textBox_FacModeScan.Text + "\r\n");
  5636. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  5637. //变量定义
  5638. var Code = new byte[255];//发送的指令数据
  5639. label_FacModeStatus.Text = "开始测试";
  5640. BootInfo = "";
  5641. Delay_ms(500);
  5642. label_FacModeStatus.Text = "系统开机";
  5643. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  5644. if (uARTToolStripMenuItem.Checked)
  5645. {
  5646. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送复位指令,切换联动装置盒波特率" + "\r\n");
  5647. Code[0] = (byte)'R';
  5648. Code[1] = (byte)'E';
  5649. Code[2] = (byte)'S';
  5650. Code[3] = (byte)'E';
  5651. Code[4] = (byte)'T';
  5652. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  5653. Delay_ms(500);
  5654. }
  5655. //发送开机指令
  5656. //确保测试前先关机,发送关机指令再发送开机指令
  5657. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  5658. Code[0] = 0xF0;
  5659. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5660. Delay_ms(1500);
  5661. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  5662. Code[0] = 0xF1;
  5663. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5664. ACK_WaitCnt = 0;
  5665. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  5666. while (ACK_WaitCnt <= 20) ; //10s,等待开机成功,联动装置盒控制器接口波特率需等待5s接口自动切换为9600
  5667. //检查BOOT版本
  5668. if (BootInfo != string.Empty)
  5669. {
  5670. label_FacModeBootVer.BackColor = Color.Green;
  5671. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  5672. Delay_ms(500);
  5673. }
  5674. else
  5675. {
  5676. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\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 (checkBox_FacModeSysClear.Checked)
  5687. {
  5688. do
  5689. {
  5690. #if false
  5691. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  5692. {
  5693. Code[0] = 0x00;//5S协议
  5694. Code[1] = 0x00;
  5695. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5696. Delay_ms(500);
  5697. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5698. Delay_ms(500);
  5699. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  5700. }
  5701. #endif
  5702. //发送系统清除指令
  5703. label_FacModeStatus.Text = "系统清除";
  5704. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除" + "\r\n");
  5705. Code[0] = (byte)'C';
  5706. Code[1] = (byte)'L';
  5707. Code[2] = (byte)'E';
  5708. Code[3] = (byte)'A';
  5709. Code[4] = (byte)'R';
  5710. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  5711. WriteACK = false;
  5712. WriteCnt = 0;
  5713. ACK_WaitCnt = 0;
  5714. while (ACK_WaitCnt <= 6); //3s
  5715. //等待系统清除完成指令
  5716. if (WriteACK == true)
  5717. {
  5718. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  5719. label_FacModeSysClear.BackColor = Color.Green;
  5720. }
  5721. else
  5722. {
  5723. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除,重发第1次" + "\r\n");
  5724. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  5725. ACK_WaitCnt = 0;
  5726. while (ACK_WaitCnt <= 6) ; //3s
  5727. //等待系统清除完成指令
  5728. if (WriteACK == true)
  5729. {
  5730. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  5731. label_FacModeSysClear.BackColor = Color.Green;
  5732. }
  5733. else
  5734. {
  5735. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除,重发第2次" + "\r\n");
  5736. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  5737. ACK_WaitCnt = 0;
  5738. while (ACK_WaitCnt <= 6) ; //3s
  5739. //等待系统清除完成指令
  5740. if (WriteACK == true)
  5741. {
  5742. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  5743. label_FacModeSysClear.BackColor = Color.Green;
  5744. }
  5745. else
  5746. {
  5747. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除失败" + "\r\n");
  5748. label_FacModeStatus.Text = "存在故障!";
  5749. label_FacModeResult.BackColor = Color.Red;
  5750. label_FacModeResult.Text = "测试异常";
  5751. Delay_ms(500);
  5752. //存储异常并上传
  5753. FacMode_Stop(false);
  5754. return;
  5755. }
  5756. }
  5757. }
  5758. BootInfo = "";
  5759. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  5760. if (uARTToolStripMenuItem.Checked)
  5761. {
  5762. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送复位指令,切换联动装置盒波特率" + "\r\n");
  5763. Code[0] = (byte)'R';
  5764. Code[1] = (byte)'E';
  5765. Code[2] = (byte)'S';
  5766. Code[3] = (byte)'E';
  5767. Code[4] = (byte)'T';
  5768. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  5769. Delay_ms(500);
  5770. }
  5771. //系统重新开机
  5772. label_FacModeStatus.Text = "重新开机";
  5773. //确保测试前先关机,发送关机指令再发送开机指令
  5774. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新发送开机指令" + "\r\n");
  5775. Code[0] = 0xF0;
  5776. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5777. Delay_ms(1500);
  5778. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新发送关机指令" + "\r\n");
  5779. Code[0] = 0xF1;
  5780. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5781. ACK_WaitCnt = 0;
  5782. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  5783. while (ACK_WaitCnt <= 20); //10s
  5784. //获取Boot版本信息
  5785. if (BootInfo != string.Empty)
  5786. {
  5787. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机成功" + "\r\n");
  5788. Delay_ms(500);
  5789. }
  5790. else
  5791. {
  5792. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机失败" + "\r\n");
  5793. label_FacModeStatus.Text = "存在故障!";
  5794. label_FacModeResult.BackColor = Color.Red;
  5795. label_FacModeResult.Text = "测试异常";
  5796. Delay_ms(500);
  5797. //存储异常并上传
  5798. FacMode_Stop(false);
  5799. return;
  5800. }
  5801. } while (false);
  5802. }
  5803. else
  5804. {
  5805. label_FacModeSysClear.BackColor = Color.Yellow;
  5806. label_FacModeStatus.Text = "跳过系统清除!";
  5807. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过系统清除" + "\r\n");
  5808. Delay_ms(500);
  5809. }
  5810. #if false
  5811. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  5812. {
  5813. Code[0] = 0x00;//5S协议
  5814. Code[1] = 0x00;
  5815. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5816. Delay_ms(500);
  5817. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5818. Delay_ms(500);
  5819. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  5820. }
  5821. #endif
  5822. //检查是否有故障
  5823. if (textBox_ErrorCode.Text.Contains("H"))
  5824. {
  5825. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "故障码:" + textBox_ErrorCode.Text + "\r\n");
  5826. label_FacModeStatus.Text = "电机存在故障!";
  5827. label_FacModeResult.BackColor = Color.Red;
  5828. label_FacModeResult.Text = "测试异常";
  5829. Delay_ms(500);
  5830. //存储异常并上传
  5831. FacMode_Stop(false);
  5832. return;
  5833. }
  5834. //MOS内阻校准
  5835. if (checkBox_FacMode_MosCal.Checked)
  5836. {
  5837. label_FacModeStatus.Text = "MOS内阻校准";
  5838. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始MOS内阻校准" + "\r\n");
  5839. Delay_ms(500);
  5840. //提示进行负载切换
  5841. if (MessageBox.Show("电阻负载切换完成,开始校准?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
  5842. {
  5843. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "取消MOS内阻校准" + "\r\n");
  5844. label_FacModeStatus.Text = "存在故障!";
  5845. label_FacModeResult.BackColor = Color.Red;
  5846. label_FacModeResult.Text = "测试异常";
  5847. Delay_ms(500);
  5848. //存储异常并上传
  5849. FacMode_Stop(false);
  5850. return;
  5851. }
  5852. //确认后发送校准指令
  5853. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令" + "\r\n");
  5854. string[] K = toolStripTextBox_MosCalK.Text.Split(',');
  5855. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  5856. ushort uwDataTemp = 0;
  5857. uwDataTemp = Convert.ToUInt16(K[0]);
  5858. Code[2] = (byte)(uwDataTemp & 0xFF);
  5859. Code[3] = (byte)(uwDataTemp >> 8);
  5860. uwDataTemp = Convert.ToUInt16(K[1]);
  5861. Code[4] = (byte)(uwDataTemp & 0xFF);
  5862. Code[5] = (byte)(uwDataTemp >> 8);
  5863. uwDataTemp = Convert.ToUInt16(K[2]);
  5864. Code[6] = (byte)(uwDataTemp & 0xFF);
  5865. Code[7] = (byte)(uwDataTemp >> 8);
  5866. uwDataTemp = Convert.ToUInt16(K[3]);
  5867. Code[8] = (byte)(uwDataTemp & 0xFF);
  5868. Code[9] = (byte)(uwDataTemp >> 8);
  5869. uwDataTemp = Convert.ToUInt16(K[4]);
  5870. Code[10] = (byte)(uwDataTemp & 0xFF);
  5871. Code[11] = (byte)(uwDataTemp >> 8);
  5872. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  5873. WriteACK = false;
  5874. WriteCnt = 0;
  5875. ACK_WaitCnt = 0;
  5876. while (ACK_WaitCnt <= 6) ; //3s
  5877. if (WriteACK == true)
  5878. {
  5879. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  5880. }
  5881. else
  5882. {
  5883. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令,第1次重发" + "\r\n");
  5884. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  5885. ACK_WaitCnt = 0;
  5886. while (ACK_WaitCnt <= 6) ; //3s
  5887. if (WriteACK == true)
  5888. {
  5889. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  5890. }
  5891. else
  5892. {
  5893. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令,第2次重发" + "\r\n");
  5894. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  5895. ACK_WaitCnt = 0;
  5896. while (ACK_WaitCnt <= 6) ; //3s
  5897. if (WriteACK == true)
  5898. {
  5899. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  5900. }
  5901. else
  5902. {
  5903. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准异常" + "\r\n");
  5904. label_FacModeStatus.Text = "存在故障!";
  5905. label_FacModeResult.BackColor = Color.Red;
  5906. label_FacModeResult.Text = "测试异常";
  5907. Delay_ms(500);
  5908. //存储异常并上传
  5909. FacMode_Stop(false);
  5910. return;
  5911. }
  5912. }
  5913. }
  5914. #if false
  5915. //因控制器复位需发送指令重新进入5S协议
  5916. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  5917. {
  5918. Code[0] = 0x00;//5S协议
  5919. Code[1] = 0x00;
  5920. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5921. Delay_ms(500);
  5922. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5923. Delay_ms(500);
  5924. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  5925. }
  5926. #endif
  5927. //读取显示校准返回数据
  5928. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果" + "\r\n");
  5929. foreach (Control c in groupBox21.Controls)
  5930. {
  5931. if (c is TextBox)
  5932. c.Text = "";
  5933. }
  5934. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  5935. ACK_WaitCnt = 0;
  5936. while (ACK_WaitCnt <= 2) ; //1s
  5937. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  5938. {
  5939. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果,第1次重发" + "\r\n");
  5940. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  5941. ACK_WaitCnt = 0;
  5942. while (ACK_WaitCnt <= 2) ; //1s
  5943. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  5944. {
  5945. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果,第2次重发" + "\r\n");
  5946. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  5947. ACK_WaitCnt = 0;
  5948. while (ACK_WaitCnt <= 2) ; //1s
  5949. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  5950. {
  5951. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果异常" + "\r\n");
  5952. label_FacModeStatus.Text = "存在故障!";
  5953. label_FacModeResult.BackColor = Color.Red;
  5954. label_FacModeResult.Text = "测试异常";
  5955. Delay_ms(500);
  5956. //存储异常并上传
  5957. FacMode_Stop(false);
  5958. return;
  5959. }
  5960. }
  5961. }
  5962. else
  5963. {
  5964. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻:" + textBox_MOS_R1.Text + " " + textBox_MOS_R2.Text + " " + textBox_MOS_R3.Text + "\r\n");
  5965. }
  5966. //与校准返回数据对比
  5967. string[] MOS_R1_Th = toolStripTextBox_MOS1.Text.Split(',');
  5968. string[] MOS_R2_Th = toolStripTextBox_MOS2.Text.Split(',');
  5969. string[] MOS_R3_Th = toolStripTextBox_MOS3.Text.Split(',');
  5970. if ((Convert.ToUInt16(textBox_MOS_R1.Text) >= Convert.ToUInt16(MOS_R1_Th[0])) && (Convert.ToUInt16(textBox_MOS_R1.Text) <= Convert.ToUInt16(MOS_R1_Th[1])) &&
  5971. (Convert.ToUInt16(textBox_MOS_R2.Text) >= Convert.ToUInt16(MOS_R2_Th[0])) && (Convert.ToUInt16(textBox_MOS_R2.Text) <= Convert.ToUInt16(MOS_R2_Th[1])) &&
  5972. (Convert.ToUInt16(textBox_MOS_R3.Text) >= Convert.ToUInt16(MOS_R3_Th[0])) && (Convert.ToUInt16(textBox_MOS_R3.Text) <= Convert.ToUInt16(MOS_R3_Th[1]))
  5973. )
  5974. {
  5975. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准合格" + "\r\n");
  5976. label_FacModeMosCal.BackColor = Color.Green;
  5977. //提示切换负载
  5978. MessageBox.Show("请将负载切换回电机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  5979. }
  5980. else
  5981. {
  5982. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准超范围" + "\r\n");
  5983. label_FacModeStatus.Text = "存在故障!";
  5984. label_FacModeResult.BackColor = Color.Red;
  5985. label_FacModeResult.Text = "测试异常";
  5986. Delay_ms(500);
  5987. //存储异常并上传
  5988. FacMode_Stop(false);
  5989. //提示切换负载
  5990. MessageBox.Show("请将负载切换回电机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  5991. return;
  5992. }
  5993. }
  5994. else
  5995. {
  5996. label_FacModeMosCal.BackColor = Color.Yellow;
  5997. label_FacModeStatus.Text = "跳过MOS内阻校准!";
  5998. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过MOS内阻校准" + "\r\n");
  5999. Delay_ms(500);
  6000. }
  6001. //参数写入
  6002. if (checkBox_FacModeCfgWrite.Checked)
  6003. {
  6004. label_FacModeStatus.Text = "参数写入";
  6005. //写入产品型号和SN
  6006. do
  6007. {
  6008. //根据扫码信息获取型号和SN
  6009. string ScanInfo = textBox_FacModeScan.Text;
  6010. string regexInfo = "";
  6011. string[] InfoList = { "" };
  6012. try
  6013. {
  6014. if (中置电机ToolStripMenuItem.Checked == true)
  6015. {
  6016. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  6017. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  6018. }
  6019. else if (轮毂电机ToolStripMenuItem.Checked == true)
  6020. {
  6021. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  6022. string Model = InfoList[0];
  6023. string Spec = InfoList[1];
  6024. string Sn = InfoList[2];
  6025. InfoList[0] = Model.Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  6026. InfoList[1] = Sn;
  6027. }
  6028. }
  6029. catch
  6030. {
  6031. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  6032. label_FacModeStatus.Text = "存在故障!";
  6033. label_FacModeResult.BackColor = Color.Red;
  6034. label_FacModeResult.Text = "标签格式错误";
  6035. Delay_ms(500);
  6036. //存储异常并上传
  6037. FacMode_Stop(false);
  6038. return;
  6039. }
  6040. if (InfoList.Length >= 2)
  6041. {
  6042. //检查配置文件是否与打标信息一致
  6043. //...
  6044. //写入型号
  6045. label_FacModeStatus.Text = "写入型号";
  6046. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号" + "\r\n");
  6047. textBox_FacModeName.Text = InfoList[0];
  6048. string Mode = textBox_FacModeName.Text;
  6049. var ModeArray = new byte[16];
  6050. for (ushort i = 0; i < Mode.Length; i++)
  6051. {
  6052. ModeArray[i] = (byte)Mode[i];
  6053. }
  6054. if (Mode.Length < 16)
  6055. {
  6056. ModeArray[Mode.Length] = (byte)'.';
  6057. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  6058. {
  6059. ModeArray[Mode.Length + 1 + i] = 0x20;
  6060. }
  6061. }
  6062. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6063. WriteACK = false;
  6064. WriteCnt = 0;
  6065. ACK_WaitCnt = 0;
  6066. while (ACK_WaitCnt <= 2); //1s
  6067. if (WriteACK == true)
  6068. {
  6069. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6070. }
  6071. else
  6072. {
  6073. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号,第1次重发" + "\r\n");
  6074. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6075. ACK_WaitCnt = 0;
  6076. while (ACK_WaitCnt <= 2) ; //1s
  6077. if (WriteACK == true)
  6078. {
  6079. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6080. }
  6081. else
  6082. {
  6083. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号,第2次重发" + "\r\n");
  6084. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6085. ACK_WaitCnt = 0;
  6086. while (ACK_WaitCnt <= 2) ; //1s
  6087. if (WriteACK == true)
  6088. {
  6089. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6090. }
  6091. else
  6092. {
  6093. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入失败" + "\r\n");
  6094. label_FacModeStatus.Text = "存在故障!";
  6095. label_FacModeResult.BackColor = Color.Red;
  6096. label_FacModeResult.Text = "测试异常";
  6097. Delay_ms(500);
  6098. //存储异常并上传
  6099. FacMode_Stop(false);
  6100. return;
  6101. }
  6102. }
  6103. }
  6104. //写入SN
  6105. label_FacModeStatus.Text = "写入SN";
  6106. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN" + "\r\n");
  6107. textBox_FacModeNum.Text = InfoList[1];
  6108. string SN = textBox_FacModeNum.Text;
  6109. var SNArray = new byte[16];
  6110. for (ushort i = 0; i < SN.Length; i++)
  6111. {
  6112. SNArray[i] = (byte)SN[i];
  6113. }
  6114. if (SN.Length < 16)
  6115. {
  6116. SNArray[SN.Length] = (byte)'.';
  6117. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  6118. {
  6119. SNArray[SN.Length + 1 + i] = 0x20;
  6120. }
  6121. }
  6122. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6123. WriteACK = false;
  6124. WriteCnt = 0;
  6125. ACK_WaitCnt = 0;
  6126. while (ACK_WaitCnt <= 2); //1s
  6127. if (WriteACK == true)
  6128. {
  6129. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  6130. }
  6131. else
  6132. {
  6133. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN,第1次重发" + "\r\n");
  6134. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6135. ACK_WaitCnt = 0;
  6136. while (ACK_WaitCnt <= 2) ; //1s
  6137. if (WriteACK == true)
  6138. {
  6139. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  6140. }
  6141. else
  6142. {
  6143. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN,第2次重发" + "\r\n");
  6144. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6145. ACK_WaitCnt = 0;
  6146. while (ACK_WaitCnt <= 2) ; //1s
  6147. if (WriteACK == true)
  6148. {
  6149. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  6150. }
  6151. else
  6152. {
  6153. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入失败" + "\r\n");
  6154. label_FacModeStatus.Text = "存在故障!";
  6155. label_FacModeResult.BackColor = Color.Red;
  6156. label_FacModeResult.Text = "测试异常";
  6157. Delay_ms(500);
  6158. //存储异常并上传
  6159. FacMode_Stop(false);
  6160. return;
  6161. }
  6162. }
  6163. }
  6164. }
  6165. else
  6166. {
  6167. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6168. return;
  6169. }
  6170. } while (false);
  6171. //写入配置文件
  6172. do
  6173. {
  6174. label_FacModeStatus.Text = "写入配置文件";
  6175. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  6176. //配置文件
  6177. List<byte[]> CmdList = new List<byte[]>();
  6178. //从服务器下载文件
  6179. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  6180. {
  6181. string SelectFile = "";
  6182. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "/" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  6183. if (File.Exists(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  6184. {
  6185. File.Delete(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  6186. }
  6187. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  6188. //打开文件
  6189. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  6190. CmdList.Clear();
  6191. while (streamReader.Peek() != -1)
  6192. {
  6193. string fileLineInfo = streamReader.ReadLine();
  6194. if (fileLineInfo.IndexOf("[") != -1)
  6195. {
  6196. continue;
  6197. }
  6198. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  6199. }
  6200. streamReader.Close();
  6201. }
  6202. //加载本地文件
  6203. else
  6204. {
  6205. string SelectFile = "";
  6206. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  6207. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  6208. CmdList.Clear();
  6209. while (streamReader.Peek() != -1)
  6210. {
  6211. string fileLineInfo = streamReader.ReadLine();
  6212. if (fileLineInfo.IndexOf("[") != -1)
  6213. {
  6214. continue;
  6215. }
  6216. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  6217. }
  6218. streamReader.Close();
  6219. }
  6220. int CmdNum = CmdList.Count(); //指令个数
  6221. Delay_ms(500);
  6222. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "开始写入" + "\r\n");
  6223. Delay_ms(500);
  6224. //开始写入
  6225. WriteCnt = 0;
  6226. for (int i = 0; i < CmdList.Count; i++)
  6227. {
  6228. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令" + "\r\n");
  6229. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6230. WriteACK = false;
  6231. ACK_WaitCnt = 0;
  6232. while (ACK_WaitCnt <= 2) ; //1s
  6233. if (WriteACK == true)
  6234. {
  6235. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6236. }
  6237. else
  6238. {
  6239. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令,第1次重发" + "\r\n");
  6240. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6241. WriteACK = false;
  6242. ACK_WaitCnt = 0;
  6243. while (ACK_WaitCnt <= 2) ; //1s
  6244. if (WriteACK == true)
  6245. {
  6246. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6247. }
  6248. else
  6249. {
  6250. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令,第2次重发" + "\r\n");
  6251. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6252. WriteACK = false;
  6253. ACK_WaitCnt = 0;
  6254. while (ACK_WaitCnt <= 2) ; //1s
  6255. if (WriteACK == true)
  6256. {
  6257. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6258. }
  6259. else
  6260. {
  6261. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入失败," + "共" + CmdNum.ToString() + "条指令," + "写入成功" + i.ToString() + "条" + "\r\n");
  6262. label_FacModeStatus.Text = "存在故障!";
  6263. label_FacModeResult.BackColor = Color.Red;
  6264. label_FacModeResult.Text = "测试异常";
  6265. Delay_ms(500);
  6266. //存储异常并上传
  6267. FacMode_Stop(false);
  6268. return;
  6269. }
  6270. }
  6271. }
  6272. }
  6273. //写入完成
  6274. label_FacMode_CfgWrite.BackColor = Color.Green;
  6275. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入成功" + "\r\n");
  6276. Delay_ms(500);
  6277. } while (false);
  6278. }
  6279. else
  6280. {
  6281. label_FacMode_CfgWrite.BackColor = Color.Yellow;
  6282. label_FacModeStatus.Text = "跳过参数写入!";
  6283. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数写入" + "\r\n");
  6284. Delay_ms(500);
  6285. }
  6286. //BMS通讯
  6287. if (checkBox_FacModeBMS.Checked)
  6288. {
  6289. if (label_FacModeBMS.BackColor == Color.Red)
  6290. {
  6291. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "BMS通讯异常" + "\r\n");
  6292. label_FacModeStatus.Text = "存在故障!";
  6293. label_FacModeResult.BackColor = Color.Red;
  6294. label_FacModeResult.Text = "测试异常";
  6295. Delay_ms(500);
  6296. //存储异常并上传
  6297. FacMode_Stop(false);
  6298. return;
  6299. }
  6300. }
  6301. else
  6302. {
  6303. label_FacModeBMS.BackColor = Color.Yellow;
  6304. label_FacModeStatus.Text = "跳过BMS通讯检测!";
  6305. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过BMS通讯检测" + "\r\n");
  6306. Delay_ms(500);
  6307. }
  6308. //基础功能检测
  6309. if (checkBox_FacBaseFucTest.Checked)
  6310. {
  6311. label_FacModeStatus.Text = "基础功能检测";
  6312. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始基础功能检测" + "\r\n");
  6313. //确认负载位置
  6314. if (checkBox_FacMode_MosCal.Checked)
  6315. {
  6316. if (MessageBox.Show("请再次确认负载是否切换回电机?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  6317. {
  6318. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "负载已切换为电机,继续测试" + "\r\n");
  6319. }
  6320. else
  6321. {
  6322. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试取消" + "\r\n");
  6323. label_FacModeStatus.Text = "存在故障!";
  6324. label_FacModeResult.BackColor = Color.Red;
  6325. label_FacModeResult.Text = "测试异常";
  6326. Delay_ms(500);
  6327. //存储异常并上传
  6328. FacMode_Stop(false);
  6329. return;
  6330. }
  6331. }
  6332. //发送指令进入配置模式
  6333. do
  6334. {
  6335. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6336. Code[0] = 0x01;
  6337. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6338. WriteACK = false;
  6339. WriteCnt = 0;
  6340. ACK_WaitCnt = 0;
  6341. while (ACK_WaitCnt <= 2); //1s
  6342. if (textBox_RunInfo_Vol.Text != "---")
  6343. {
  6344. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6345. }
  6346. else
  6347. {
  6348. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  6349. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6350. ACK_WaitCnt = 0;
  6351. while (ACK_WaitCnt <= 2) ; //1s
  6352. if (textBox_RunInfo_Vol.Text != "---")
  6353. {
  6354. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6355. }
  6356. else
  6357. {
  6358. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  6359. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6360. ACK_WaitCnt = 0;
  6361. while (ACK_WaitCnt <= 2) ; //1s
  6362. if (textBox_RunInfo_Vol.Text != "---")
  6363. {
  6364. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6365. }
  6366. else
  6367. {
  6368. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  6369. label_FacModeStatus.Text = "存在故障!";
  6370. label_FacModeResult.BackColor = Color.Red;
  6371. label_FacModeResult.Text = "测试异常";
  6372. Delay_ms(500);
  6373. //存储异常并上传
  6374. FacMode_Stop(false);
  6375. return;
  6376. }
  6377. }
  6378. }
  6379. } while (false);
  6380. //发送指令启动电机
  6381. do
  6382. {
  6383. #if false //通过运行模式3启动电机
  6384. //发送指令读取调试信息
  6385. richTextBox_DebugParam.Clear();
  6386. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  6387. WriteACK = false;
  6388. WriteCnt = 0;
  6389. ACK_WaitCnt = 0;
  6390. while (ACK_WaitCnt <= 2); //1s
  6391. //获取调试信息
  6392. string DebugDefaultInfo = "";
  6393. if (richTextBox_DebugParam.Text == string.Empty)
  6394. {
  6395. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
  6396. label_FacModeStatus.Text = "存在故障!";
  6397. label_FacModeResult.BackColor = Color.Red;
  6398. label_FacModeResult.Text = "测试异常";
  6399. Delay_ms(500);
  6400. //存储异常并上传
  6401. FacMode_Stop(false);
  6402. return;
  6403. }
  6404. else
  6405. {
  6406. DebugDefaultInfo = richTextBox_DebugParam.Text;
  6407. }
  6408. //设置模式
  6409. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  6410. strDataTemp[0] = "整体运行模式=3";
  6411. //发送数据
  6412. Code[0] = 0;
  6413. Code[1] = 0;
  6414. for (int i = 0; i < strDataTemp.Length; i++)
  6415. {
  6416. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  6417. Code[2 * i + 2] = (byte)uwDataTemp;
  6418. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  6419. }
  6420. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  6421. label_FacModeStatus.Text = "启动电机";
  6422. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "启动电机" + "\r\n");
  6423. #else //通过Walk模式启动电机
  6424. //设置转速100%
  6425. var Data = new byte[1];
  6426. Data[0] = (byte)100;
  6427. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6428. Delay_ms(500);
  6429. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6430. Delay_ms(500);
  6431. //启动电机进入WALK模式
  6432. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "基础功能检测,进入WALK" + "\r\n");
  6433. Code[0] = 0x22;
  6434. Code[1] = 0xF0;
  6435. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6436. WriteACK = false;
  6437. WriteCnt = 0;
  6438. ACK_WaitCnt = 0;
  6439. while (ACK_WaitCnt <= 2) ; //1s
  6440. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6441. {
  6442. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第1次重发" + "\r\n");
  6443. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6444. ACK_WaitCnt = 0;
  6445. while (ACK_WaitCnt <= 2) ; //1s
  6446. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6447. {
  6448. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第2次重发" + "\r\n");
  6449. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6450. ACK_WaitCnt = 0;
  6451. while (ACK_WaitCnt <= 2) ; //1s
  6452. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6453. {
  6454. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
  6455. label_FacModeStatus.Text = "存在故障!";
  6456. label_FacModeResult.BackColor = Color.Red;
  6457. label_FacModeResult.Text = "测试异常";
  6458. Delay_ms(500);
  6459. //存储异常并上传
  6460. FacMode_Stop(false);
  6461. return;
  6462. }
  6463. }
  6464. }
  6465. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入WALK,开始检测" + "\r\n");
  6466. #endif
  6467. Delay_ms(3000);
  6468. } while (false);
  6469. //判断车速
  6470. if ((Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) <= Convert.ToDouble( toolStripTextBox_ThBikeSpeed.Text.Split(',')[1])) &&
  6471. (Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThBikeSpeed.Text.Split(',')[0])))
  6472. {
  6473. label_FacModeSpeed.BackColor = Color.Green;
  6474. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器正常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
  6475. }
  6476. else
  6477. {
  6478. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器异常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
  6479. label_FacModeStatus.Text = "存在故障!";
  6480. label_FacModeResult.BackColor = Color.Red;
  6481. label_FacModeResult.Text = "测试异常";
  6482. Delay_ms(500);
  6483. //存储异常并上传
  6484. FacMode_Stop(false);
  6485. return;
  6486. }
  6487. //判断电压
  6488. if ((Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[1])) &&
  6489. (Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[0])))
  6490. {
  6491. label_FacModeVolTest.BackColor = Color.Green;
  6492. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量正常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
  6493. }
  6494. else
  6495. {
  6496. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量异常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
  6497. label_FacModeStatus.Text = "存在故障!";
  6498. label_FacModeResult.BackColor = Color.Red;
  6499. label_FacModeResult.Text = "测试异常";
  6500. Delay_ms(500);
  6501. //存储异常并上传
  6502. FacMode_Stop(false);
  6503. return;
  6504. }
  6505. //判断电流
  6506. if ((Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[1])) &&
  6507. (Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[0])))
  6508. {
  6509. label_FacModeCurrentTest.BackColor = Color.Green;
  6510. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量正常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  6511. }
  6512. else
  6513. {
  6514. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量异常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  6515. label_FacModeStatus.Text = "存在故障!";
  6516. label_FacModeResult.BackColor = Color.Red;
  6517. label_FacModeResult.Text = "测试异常";
  6518. Delay_ms(500);
  6519. //存储异常并上传
  6520. FacMode_Stop(false);
  6521. return;
  6522. }
  6523. //判断温度
  6524. if ((Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[1])) &&
  6525. (Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[0])) &&
  6526. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[1])) &&
  6527. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[0])) &&
  6528. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[1])) &&
  6529. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[0])))
  6530. {
  6531. label_FacModeNTC.BackColor = Color.Green;
  6532. 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");
  6533. }
  6534. else
  6535. {
  6536. 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");
  6537. label_FacModeStatus.Text = "存在故障!";
  6538. label_FacModeResult.BackColor = Color.Red;
  6539. label_FacModeResult.Text = "测试异常";
  6540. Delay_ms(500);
  6541. //存储异常并上传
  6542. FacMode_Stop(false);
  6543. return;
  6544. }
  6545. //判断转速
  6546. if ((Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[1])) &&
  6547. (Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[0])))
  6548. {
  6549. label_FacModeMotorSpeed.BackColor = Color.Green;
  6550. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速正常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
  6551. }
  6552. else
  6553. {
  6554. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速异常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
  6555. label_FacModeStatus.Text = "存在故障!";
  6556. label_FacModeResult.BackColor = Color.Red;
  6557. label_FacModeResult.Text = "测试异常";
  6558. Delay_ms(500);
  6559. //存储异常并上传
  6560. FacMode_Stop(false);
  6561. return;
  6562. }
  6563. //发送指令停止电机
  6564. do
  6565. {
  6566. //设置转速0%
  6567. var Data = new byte[1];
  6568. Data[0] = (byte)0;
  6569. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6570. Delay_ms(500);
  6571. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6572. Delay_ms(500);
  6573. #if false //通过修改调试模式停止电机
  6574. //获取调试信息
  6575. string DebugDefaultInfo = "";
  6576. if (richTextBox_DebugParam.Text == string.Empty)
  6577. {
  6578. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
  6579. label_FacModeStatus.Text = "存在故障!";
  6580. label_FacModeResult.BackColor = Color.Red;
  6581. label_FacModeResult.Text = "测试异常";
  6582. Delay_ms(500);
  6583. //存储异常并上传
  6584. FacMode_Stop(false);
  6585. return;
  6586. }
  6587. else
  6588. {
  6589. DebugDefaultInfo = richTextBox_DebugParam.Text;
  6590. }
  6591. //设置模式
  6592. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  6593. //发送数据
  6594. Code[0] = 0;
  6595. Code[1] = 0;
  6596. for (int i = 0; i < strDataTemp.Length; i++)
  6597. {
  6598. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  6599. Code[2 * i + 2] = (byte)uwDataTemp;
  6600. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  6601. }
  6602. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  6603. label_FacModeStatus.Text = "停止电机";
  6604. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "停止电机" + "\r\n");
  6605. #else //通过调整档位停止电机
  6606. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK" + "\r\n");
  6607. Code[0] = 0x00;
  6608. Code[1] = 0xF0;
  6609. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6610. WriteACK = false;
  6611. WriteCnt = 0;
  6612. ACK_WaitCnt = 0;
  6613. while (ACK_WaitCnt <= 2) ; //1s
  6614. if (textBox_RunInfo_GearSt.Text != "OFF")
  6615. {
  6616. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK,第1次重发" + "\r\n");
  6617. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6618. ACK_WaitCnt = 0;
  6619. while (ACK_WaitCnt <= 2) ; //1s
  6620. if (textBox_RunInfo_GearSt.Text != "OFF")
  6621. {
  6622. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK,第2次重发" + "\r\n");
  6623. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6624. ACK_WaitCnt = 0;
  6625. while (ACK_WaitCnt <= 2) ; //1s
  6626. if (textBox_RunInfo_GearSt.Text != "OFF")
  6627. {
  6628. }
  6629. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
  6630. label_FacModeStatus.Text = "存在故障!";
  6631. label_FacModeResult.BackColor = Color.Red;
  6632. label_FacModeResult.Text = "测试异常";
  6633. Delay_ms(500);
  6634. //存储异常并上传
  6635. FacMode_Stop(false);
  6636. return;
  6637. }
  6638. }
  6639. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已退出WALK,基础功能检测完成" + "\r\n");
  6640. #endif
  6641. Delay_ms(2000);
  6642. } while (false);
  6643. }
  6644. else
  6645. {
  6646. label_FacModeSpeed.BackColor = Color.Yellow;
  6647. label_FacModeVolTest.BackColor = Color.Yellow;
  6648. label_FacModeCurrentTest.BackColor = Color.Yellow;
  6649. label_FacModeNTC.BackColor = Color.Yellow;
  6650. label_FacModeMotorSpeed.BackColor = Color.Yellow;
  6651. label_FacModeStatus.Text = "跳过基础功能检测!";
  6652. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过基础功能检测" + "\r\n");
  6653. Delay_ms(500);
  6654. }
  6655. //力矩检测
  6656. if (checkBox_FacTor.Checked)
  6657. {
  6658. label_FacModeStatus.Text = "力矩传感器检测!";
  6659. //发送指令进入配置模式
  6660. do
  6661. {
  6662. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  6663. {
  6664. break;
  6665. }
  6666. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6667. Code[0] = 0x01;
  6668. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6669. WriteACK = false;
  6670. WriteCnt = 0;
  6671. ACK_WaitCnt = 0;
  6672. while (ACK_WaitCnt <= 2) ; //1s
  6673. if (textBox_RunInfo_Vol.Text != "---")
  6674. {
  6675. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6676. Delay_ms(500);
  6677. }
  6678. else
  6679. {
  6680. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  6681. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6682. ACK_WaitCnt = 0;
  6683. while (ACK_WaitCnt <= 2) ; //1s
  6684. if (textBox_RunInfo_Vol.Text != "---")
  6685. {
  6686. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6687. Delay_ms(500);
  6688. }
  6689. else
  6690. {
  6691. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  6692. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6693. ACK_WaitCnt = 0;
  6694. while (ACK_WaitCnt <= 2) ; //1s
  6695. if (textBox_RunInfo_Vol.Text != "---")
  6696. {
  6697. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6698. Delay_ms(500);
  6699. }
  6700. else
  6701. {
  6702. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  6703. label_FacModeStatus.Text = "存在故障!";
  6704. label_FacModeResult.BackColor = Color.Red;
  6705. label_FacModeResult.Text = "测试异常";
  6706. Delay_ms(500);
  6707. //存储异常并上传
  6708. FacMode_Stop(false);
  6709. return;
  6710. }
  6711. }
  6712. }
  6713. } while (false);
  6714. ushort Max = 0, Torque = 0;
  6715. //提示输入力矩信号
  6716. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟力矩信号输入" + "\r\n");
  6717. ACK_WaitCnt = 0;
  6718. while (ACK_WaitCnt <= 20) //10s
  6719. {
  6720. //获取力矩值
  6721. Torque = (ushort)Convert.ToInt16(textBox_RunInfo_Torque.Text.Split(' ')[0]);
  6722. if (Torque > Max)
  6723. Max = Torque;
  6724. if ((Max <= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[1])) &&
  6725. (Max >= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[0])) &&
  6726. (ACK_WaitCnt >= 6))
  6727. {
  6728. label_FacModeTq.BackColor = Color.Green;
  6729. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器正常" + " " + textBox_RunInfo_Torque.Text + "\r\n");
  6730. break;
  6731. }
  6732. }
  6733. if (ACK_WaitCnt >= 20)
  6734. {
  6735. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器异常" + " " + textBox_RunInfo_Torque.Text + "\r\n");
  6736. label_FacModeStatus.Text = "存在故障!";
  6737. label_FacModeResult.BackColor = Color.Red;
  6738. label_FacModeResult.Text = "测试异常";
  6739. Delay_ms(500);
  6740. //存储异常并上传
  6741. FacMode_Stop(false);
  6742. return;
  6743. }
  6744. }
  6745. else
  6746. {
  6747. label_FacModeTq.BackColor = Color.Yellow;
  6748. label_FacModeStatus.Text = "跳过力矩检测!";
  6749. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过力矩检测" + "\r\n");
  6750. Delay_ms(500);
  6751. }
  6752. //踏频检测
  6753. if (checkBox_FacCad.Checked)
  6754. {
  6755. label_FacModeStatus.Text = "踏频传感器检测!";
  6756. //发送指令进入配置模式
  6757. do
  6758. {
  6759. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  6760. {
  6761. break;
  6762. }
  6763. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6764. Code[0] = 0x01;
  6765. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6766. WriteACK = false;
  6767. WriteCnt = 0;
  6768. ACK_WaitCnt = 0;
  6769. while (ACK_WaitCnt <= 2) ; //1s
  6770. if (textBox_RunInfo_Vol.Text != "---")
  6771. {
  6772. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6773. Delay_ms(500);
  6774. }
  6775. else
  6776. {
  6777. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  6778. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6779. ACK_WaitCnt = 0;
  6780. while (ACK_WaitCnt <= 2) ; //1s
  6781. if (textBox_RunInfo_Vol.Text != "---")
  6782. {
  6783. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6784. Delay_ms(500);
  6785. }
  6786. else
  6787. {
  6788. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  6789. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6790. ACK_WaitCnt = 0;
  6791. while (ACK_WaitCnt <= 2) ; //1s
  6792. if (textBox_RunInfo_Vol.Text != "---")
  6793. {
  6794. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6795. Delay_ms(500);
  6796. }
  6797. else
  6798. {
  6799. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  6800. label_FacModeStatus.Text = "存在故障!";
  6801. label_FacModeResult.BackColor = Color.Red;
  6802. label_FacModeResult.Text = "测试异常";
  6803. Delay_ms(500);
  6804. //存储异常并上传
  6805. FacMode_Stop(false);
  6806. return;
  6807. }
  6808. }
  6809. }
  6810. } while (false);
  6811. ushort Max = 0, Cadence = 0;
  6812. //提示输入踏频信号
  6813. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟踏频信号输入" + "\r\n");
  6814. ACK_WaitCnt = 0;
  6815. while (ACK_WaitCnt <= 20) //10s
  6816. {
  6817. //获取踏频
  6818. Cadence = (ushort)Convert.ToInt16(textBox_RunInfo_Cadence.Text.Split(' ')[0]);
  6819. if (Cadence > Max)
  6820. Max = Cadence;
  6821. if ((Max <= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[1])) &&
  6822. (Max >= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[0])) &&
  6823. (ACK_WaitCnt >= 6))
  6824. {
  6825. label_FacModeCad.BackColor = Color.Green;
  6826. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器正常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  6827. break;
  6828. }
  6829. }
  6830. if (ACK_WaitCnt >= 20)
  6831. {
  6832. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器异常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  6833. label_FacModeStatus.Text = "存在故障!";
  6834. label_FacModeResult.BackColor = Color.Red;
  6835. label_FacModeResult.Text = "测试异常";
  6836. Delay_ms(500);
  6837. //存储异常并上传
  6838. FacMode_Stop(false);
  6839. return;
  6840. }
  6841. }
  6842. else
  6843. {
  6844. label_FacModeCad.BackColor = Color.Yellow;
  6845. label_FacModeStatus.Text = "跳过踏频检测!";
  6846. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过踏频检测" + "\r\n");
  6847. Delay_ms(500);
  6848. }
  6849. //转把检测
  6850. if (checkBox_FacThrrotleTest.Checked)
  6851. {
  6852. label_FacModeStatus.Text = "转把检测";
  6853. //发送指令进入配置模式
  6854. do
  6855. {
  6856. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  6857. {
  6858. break;
  6859. }
  6860. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6861. Code[0] = 0x01;
  6862. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6863. WriteACK = false;
  6864. WriteCnt = 0;
  6865. ACK_WaitCnt = 0;
  6866. while (ACK_WaitCnt <= 2) ; //1s
  6867. if (textBox_RunInfo_Vol.Text != "---")
  6868. {
  6869. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6870. Delay_ms(500);
  6871. }
  6872. else
  6873. {
  6874. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  6875. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6876. ACK_WaitCnt = 0;
  6877. while (ACK_WaitCnt <= 2) ; //1s
  6878. if (textBox_RunInfo_Vol.Text != "---")
  6879. {
  6880. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6881. Delay_ms(500);
  6882. }
  6883. else
  6884. {
  6885. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  6886. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6887. ACK_WaitCnt = 0;
  6888. while (ACK_WaitCnt <= 2) ; //1s
  6889. if (textBox_RunInfo_Vol.Text != "---")
  6890. {
  6891. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6892. Delay_ms(500);
  6893. }
  6894. else
  6895. {
  6896. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  6897. label_FacModeStatus.Text = "存在故障!";
  6898. label_FacModeResult.BackColor = Color.Red;
  6899. label_FacModeResult.Text = "测试异常";
  6900. Delay_ms(500);
  6901. //存储异常并上传
  6902. FacMode_Stop(false);
  6903. return;
  6904. }
  6905. }
  6906. }
  6907. } while (false);
  6908. //进入TURBO档
  6909. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把检测,发送指令进入TURBO" + "\r\n");
  6910. Code[0] = 0x04;
  6911. Code[1] = 0xF0;
  6912. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6913. WriteACK = false;
  6914. WriteCnt = 0;
  6915. ACK_WaitCnt = 0;
  6916. while (ACK_WaitCnt <= 2) ; //1s
  6917. if (textBox_RunInfo_GearSt.Text != "TURBO")
  6918. {
  6919. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO,第1次重发" + "\r\n");
  6920. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6921. ACK_WaitCnt = 0;
  6922. while (ACK_WaitCnt <= 2) ; //1s
  6923. if (textBox_RunInfo_GearSt.Text != "TURBO")
  6924. {
  6925. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO,第2次重发" + "\r\n");
  6926. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6927. ACK_WaitCnt = 0;
  6928. while (ACK_WaitCnt <= 2) ; //1s
  6929. if (textBox_RunInfo_GearSt.Text != "TURBO")
  6930. {
  6931. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO异常" + "\r\n");
  6932. label_FacModeStatus.Text = "存在故障!";
  6933. label_FacModeResult.BackColor = Color.Red;
  6934. label_FacModeResult.Text = "测试异常";
  6935. Delay_ms(500);
  6936. //存储异常并上传
  6937. FacMode_Stop(false);
  6938. return;
  6939. }
  6940. }
  6941. }
  6942. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入TURBO,10s内转动转把" + "\r\n");
  6943. ACK_WaitCnt = 0;
  6944. while (ACK_WaitCnt <= 20)
  6945. {
  6946. if ((Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) > 500) && (ACK_WaitCnt >= 10))
  6947. {
  6948. label_FacModeGas.BackColor = Color.Green;
  6949. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能正常,松开转把" + "\r\n");
  6950. break;
  6951. }
  6952. }
  6953. if (ACK_WaitCnt >= 20) //转把超时
  6954. {
  6955. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能异常,松开转把" + "\r\n");
  6956. label_FacModeStatus.Text = "存在故障!";
  6957. label_FacModeResult.BackColor = Color.Red;
  6958. label_FacModeResult.Text = "测试异常";
  6959. Delay_ms(500);
  6960. //存储异常并上传
  6961. FacMode_Stop(false);
  6962. return;
  6963. }
  6964. }
  6965. else
  6966. {
  6967. label_FacModeGas.BackColor = Color.Yellow;
  6968. label_FacModeStatus.Text = "跳过转把检测!";
  6969. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过转把检测" + "\r\n");
  6970. Delay_ms(500);
  6971. }
  6972. //刹车检测
  6973. if (checkBox_FacBreakTest.Checked)
  6974. {
  6975. label_FacModeStatus.Text = "刹把检测";
  6976. //发送指令进入配置模式
  6977. do
  6978. {
  6979. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  6980. {
  6981. break;
  6982. }
  6983. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6984. Code[0] = 0x01;
  6985. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6986. WriteACK = false;
  6987. WriteCnt = 0;
  6988. ACK_WaitCnt = 0;
  6989. while (ACK_WaitCnt <= 2) ; //1s
  6990. if (textBox_RunInfo_Vol.Text != "---")
  6991. {
  6992. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6993. Delay_ms(500);
  6994. }
  6995. else
  6996. {
  6997. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  6998. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6999. ACK_WaitCnt = 0;
  7000. while (ACK_WaitCnt <= 2) ; //1s
  7001. if (textBox_RunInfo_Vol.Text != "---")
  7002. {
  7003. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7004. Delay_ms(500);
  7005. }
  7006. else
  7007. {
  7008. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7009. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7010. ACK_WaitCnt = 0;
  7011. while (ACK_WaitCnt <= 2) ; //1s
  7012. if (textBox_RunInfo_Vol.Text != "---")
  7013. {
  7014. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7015. Delay_ms(500);
  7016. }
  7017. else
  7018. {
  7019. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7020. label_FacModeStatus.Text = "存在故障!";
  7021. label_FacModeResult.BackColor = Color.Red;
  7022. label_FacModeResult.Text = "测试异常";
  7023. Delay_ms(500);
  7024. //存储异常并上传
  7025. FacMode_Stop(false);
  7026. return;
  7027. }
  7028. }
  7029. }
  7030. } while (false);
  7031. //设置转速100%
  7032. var Data = new byte[1];
  7033. Data[0] = (byte)100;
  7034. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7035. Delay_ms(500);
  7036. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7037. Delay_ms(500);
  7038. //启动电机进入WALK模式
  7039. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把检测,进入WALK" + "\r\n");
  7040. Code[0] = 0x22;
  7041. Code[1] = 0xF0;
  7042. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7043. WriteACK = false;
  7044. WriteCnt = 0;
  7045. ACK_WaitCnt = 0;
  7046. while (ACK_WaitCnt <= 2) ; //1s
  7047. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  7048. {
  7049. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第1次重发" + "\r\n");
  7050. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7051. ACK_WaitCnt = 0;
  7052. while (ACK_WaitCnt <= 2) ; //1s
  7053. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  7054. {
  7055. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第2次重发" + "\r\n");
  7056. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7057. ACK_WaitCnt = 0;
  7058. while (ACK_WaitCnt <= 2) ; //1s
  7059. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  7060. {
  7061. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
  7062. label_FacModeStatus.Text = "存在故障!";
  7063. label_FacModeResult.BackColor = Color.Red;
  7064. label_FacModeResult.Text = "测试异常";
  7065. Delay_ms(500);
  7066. //存储异常并上传
  7067. FacMode_Stop(false);
  7068. return;
  7069. }
  7070. }
  7071. }
  7072. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,10s内操作剎把" + "\r\n");
  7073. ACK_WaitCnt = 0;
  7074. while (ACK_WaitCnt <= 20)
  7075. {
  7076. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 100)
  7077. {
  7078. label_FacModeBreak.BackColor = Color.Green;
  7079. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把功能正常,松开剎把" + "\r\n");
  7080. break;
  7081. }
  7082. }
  7083. if (ACK_WaitCnt >= 20) //剎把超时
  7084. {
  7085. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把功能异常,松开剎把" + "\r\n");
  7086. label_FacModeStatus.Text = "存在故障!";
  7087. label_FacModeResult.BackColor = Color.Red;
  7088. label_FacModeResult.Text = "测试异常";
  7089. Delay_ms(500);
  7090. //存储异常并上传
  7091. FacMode_Stop(false);
  7092. return;
  7093. }
  7094. //停止电机
  7095. Code[0] = 0x00;
  7096. Code[1] = 0xF0;
  7097. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7098. WriteACK = false;
  7099. WriteCnt = 0;
  7100. ACK_WaitCnt = 0;
  7101. while (ACK_WaitCnt <= 2) ; //1s
  7102. if (textBox_RunInfo_GearSt.Text != "OFF")
  7103. {
  7104. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK,第1次重发" + "\r\n");
  7105. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7106. ACK_WaitCnt = 0;
  7107. while (ACK_WaitCnt <= 2) ; //1s
  7108. if (textBox_RunInfo_GearSt.Text != "OFF")
  7109. {
  7110. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK,第2次重发" + "\r\n");
  7111. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7112. ACK_WaitCnt = 0;
  7113. while (ACK_WaitCnt <= 2) ; //1s
  7114. if (textBox_RunInfo_GearSt.Text != "OFF")
  7115. {
  7116. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
  7117. label_FacModeStatus.Text = "存在故障!";
  7118. label_FacModeResult.BackColor = Color.Red;
  7119. label_FacModeResult.Text = "测试异常";
  7120. Delay_ms(500);
  7121. //存储异常并上传
  7122. FacMode_Stop(false);
  7123. return;
  7124. }
  7125. }
  7126. }
  7127. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK" + "\r\n");
  7128. Delay_ms(500);
  7129. }
  7130. else
  7131. {
  7132. label_FacModeBreak.BackColor = Color.Yellow;
  7133. label_FacModeStatus.Text = "跳过刹车检测!";
  7134. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过刹车检测" + "\r\n");
  7135. Delay_ms(500);
  7136. }
  7137. //前后灯检测
  7138. if (checkBox_FacLightTest.Checked)
  7139. {
  7140. //前后灯检测
  7141. label_FacModeStatus.Text = "前后灯检测";
  7142. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开灯指令" + "\r\n");
  7143. //发送指令打开车灯
  7144. Code[0] = 0x00;
  7145. Code[1] = 0xF1;
  7146. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7147. WriteACK = false;
  7148. WriteCnt = 0;
  7149. ACK_WaitCnt = 0;
  7150. while (ACK_WaitCnt <= 2) ; //1s
  7151. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7152. {
  7153. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令,第1次重发" + "\r\n");
  7154. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7155. ACK_WaitCnt = 0;
  7156. while (ACK_WaitCnt <= 2); //1s
  7157. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7158. {
  7159. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令,第2次重发" + "\r\n");
  7160. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7161. ACK_WaitCnt = 0;
  7162. while (ACK_WaitCnt <= 2) ; //1s
  7163. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7164. {
  7165. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令发送异常" + "\r\n");
  7166. label_FacModeStatus.Text = "存在故障!";
  7167. label_FacModeResult.BackColor = Color.Red;
  7168. label_FacModeResult.Text = "测试异常";
  7169. Delay_ms(500);
  7170. //存储异常并上传
  7171. FacMode_Stop(false);
  7172. return;
  7173. }
  7174. }
  7175. }
  7176. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已打开前后灯" + "\r\n");
  7177. Delay_ms(500);
  7178. //提示检查灯压是否正确
  7179. if (MessageBox.Show("前后灯是否正常?", "前后灯判断", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  7180. {
  7181. label_FacModeLightF.BackColor = Color.Green;
  7182. label_FacModeLightB.BackColor = Color.Green;
  7183. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯正常" + "\r\n");
  7184. Delay_ms(500);
  7185. }
  7186. else
  7187. {
  7188. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯异常" + "\r\n");
  7189. label_FacModeStatus.Text = "存在故障!";
  7190. label_FacModeResult.BackColor = Color.Red;
  7191. label_FacModeResult.Text = "测试异常";
  7192. Delay_ms(500);
  7193. //存储异常并上传
  7194. FacMode_Stop(false);
  7195. return;
  7196. }
  7197. //发送指令关闭车灯
  7198. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关灯指令" + "\r\n");
  7199. Code[0] = 0x00;
  7200. Code[1] = 0xF0;
  7201. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7202. WriteACK = false;
  7203. WriteCnt = 0;
  7204. ACK_WaitCnt = 0;
  7205. while (ACK_WaitCnt <= 2) ; //1s
  7206. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7207. {
  7208. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令,第1次重发" + "\r\n");
  7209. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7210. ACK_WaitCnt = 0;
  7211. while (ACK_WaitCnt <= 2) ; //1s
  7212. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7213. {
  7214. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令,第2次重发" + "\r\n");
  7215. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7216. ACK_WaitCnt = 0;
  7217. while (ACK_WaitCnt <= 2) ; //1s
  7218. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7219. {
  7220. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令发送异常" + "\r\n");
  7221. label_FacModeStatus.Text = "存在故障!";
  7222. label_FacModeResult.BackColor = Color.Red;
  7223. label_FacModeResult.Text = "测试异常";
  7224. Delay_ms(500);
  7225. //存储异常并上传
  7226. FacMode_Stop(false);
  7227. return;
  7228. }
  7229. }
  7230. }
  7231. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已关闭前后灯" + "\r\n");
  7232. Delay_ms(500);
  7233. }
  7234. else
  7235. {
  7236. label_FacModeLightF.BackColor = Color.Yellow;
  7237. label_FacModeLightB.BackColor = Color.Yellow;
  7238. label_FacModeStatus.Text = "跳过前后灯检测!";
  7239. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过前后灯检测" + "\r\n");
  7240. Delay_ms(500);
  7241. }
  7242. //软件版本检测
  7243. do
  7244. {
  7245. label_FacModeStatus.Text = "软件版本确认";
  7246. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  7247. //发送指令读取版本
  7248. Class_Motor_Ver.Mode = "---";
  7249. Class_Motor_Ver.SN = "---";
  7250. Class_Motor_Ver.HW = "---";
  7251. Class_Motor_Ver.FW = "---";
  7252. Class_Motor_Ver.Special = "---";
  7253. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7254. ACK_WaitCnt = 0;
  7255. while (ACK_WaitCnt <= 2) ; //1s
  7256. if (Class_Motor_Ver.Mode == "---")
  7257. {
  7258. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第1次重发" + "\r\n");
  7259. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7260. ACK_WaitCnt = 0;
  7261. while (ACK_WaitCnt <= 2) ; //1s
  7262. if (Class_Motor_Ver.Mode == "---")
  7263. {
  7264. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第2次重发" + "\r\n");
  7265. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7266. ACK_WaitCnt = 0;
  7267. while (ACK_WaitCnt <= 2) ; //1s
  7268. if (Class_Motor_Ver.Mode == "---")
  7269. {
  7270. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息失败" + "\r\n");
  7271. label_FacModeStatus.Text = "存在故障!";
  7272. label_FacModeResult.BackColor = Color.Red;
  7273. label_FacModeResult.Text = "测试异常";
  7274. Delay_ms(500);
  7275. //存储异常并上传
  7276. FacMode_Stop(false);
  7277. return;
  7278. }
  7279. }
  7280. }
  7281. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  7282. richTextBox_FacModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  7283. richTextBox_FacModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  7284. richTextBox_FacModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  7285. richTextBox_FacModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  7286. richTextBox_FacModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  7287. //判断版本是否正确
  7288. string VerCheck = comboBox_FacModeCfgFile.Text.Split('_')[3] + "_" + comboBox_FacModeCfgFile.Text.Split('_')[4];
  7289. string VerRead = "";
  7290. try
  7291. {
  7292. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  7293. }
  7294. catch (System.Exception)
  7295. {
  7296. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  7297. label_FacModeStatus.Text = "存在故障!";
  7298. label_FacModeResult.BackColor = Color.Red;
  7299. label_FacModeResult.Text = "测试异常";
  7300. Delay_ms(500);
  7301. //存储异常并上传
  7302. FacMode_Stop(false);
  7303. return;
  7304. }
  7305. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  7306. {
  7307. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
  7308. label_FacModeStatus.Text = "存在故障!";
  7309. label_FacModeResult.BackColor = Color.Red;
  7310. label_FacModeResult.Text = "测试异常";
  7311. Delay_ms(500);
  7312. //存储异常并上传
  7313. FacMode_Stop(false);
  7314. return;
  7315. }
  7316. label_FacModeFWVersion.BackColor = Color.Green;
  7317. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  7318. Delay_ms(500);
  7319. } while (false);
  7320. //测试合格
  7321. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  7322. label_FacModeStatus.Text = "测试结束!";
  7323. label_FacModeResult.BackColor = Color.Green;
  7324. label_FacModeResult.Text = "测试合格";
  7325. Delay_ms(500);
  7326. //存储并上传
  7327. FacMode_Stop(true);
  7328. return;
  7329. }
  7330. private void FacModelLabelInit()
  7331. {
  7332. //测试状态标签
  7333. label_FacModeResult.BackColor = Color.Yellow;
  7334. label_FacModeResult.Text = "测试中";
  7335. //测试过程标签
  7336. label_FacModeStatus.Text = "测试就绪";
  7337. //测试结果标签
  7338. foreach (Control c in groupBox28.Controls)
  7339. {
  7340. if (c is Label)
  7341. {
  7342. if (c.Text == string.Empty)
  7343. c.BackColor = Color.Red;
  7344. }
  7345. }
  7346. }
  7347. private void comboBox_CheckModeCfgDate_Click(object sender, EventArgs e)
  7348. {
  7349. //更新生产配置文件目录
  7350. GetDateList(false);
  7351. }
  7352. private void comboBox_FacModeCfgDate_Click(object sender, EventArgs e)
  7353. {
  7354. //更新生产配置文件目录
  7355. GetDateList(false);
  7356. }
  7357. private void richTextBox_FacModeLog_TextChanged(object sender, EventArgs e)
  7358. {
  7359. richTextBox_FacModeLog.SelectionStart = richTextBox_FacModeLog.Text.Length;
  7360. richTextBox_FacModeLog.ScrollToCaret();
  7361. }
  7362. /// <summary>
  7363. /// 参数检验测试停止
  7364. /// </summary>
  7365. /// <param name="OK_Flag"></param>
  7366. private void CheckMode_Stop(bool OK_Flag)
  7367. {
  7368. //打开开始按钮
  7369. button_CheckModeStart.Enabled = true;
  7370. //系统关机
  7371. var Code = new byte[32];//发送的指令数据
  7372. Code[0] = 0xF0;
  7373. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  7374. //关闭串口
  7375. //mySerialProcess.SerialClose(false);
  7376. //路径设置
  7377. string LocalSavePath = "";
  7378. string ServerSavePath = "";
  7379. if (OK_Flag)
  7380. {
  7381. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "OK\\";
  7382. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/OK/";
  7383. }
  7384. else
  7385. {
  7386. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "FAIL\\";
  7387. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/FAIL/";
  7388. }
  7389. if (Directory.Exists(LocalSavePath) == false)
  7390. {
  7391. Directory.CreateDirectory(LocalSavePath);
  7392. }
  7393. //保存和上传
  7394. string LogSavePath = "";
  7395. string LogSaveFileName = "";
  7396. string ProductInfo = textBox_CheckModeScan.Text;
  7397. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  7398. if (Directory.Exists(LogSavePath) == false)
  7399. {
  7400. Directory.CreateDirectory(LogSavePath);
  7401. }
  7402. //测试页面
  7403. Double scaleX = PrimaryScreen.ScaleX;
  7404. Double scaleY = PrimaryScreen.ScaleY;
  7405. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  7406. Graphics g = Graphics.FromImage(bit);
  7407. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  7408. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  7409. bit.Save(LogSaveFileName);
  7410. //上传测试页面到服务器
  7411. if (myFtp.IsNetConnected == true)
  7412. {
  7413. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  7414. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  7415. {
  7416. myFtp.MakeDir(ServerSavePath + DateNow);
  7417. }
  7418. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  7419. {
  7420. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  7421. }
  7422. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  7423. if (result == true)
  7424. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  7425. }
  7426. //测试记录
  7427. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  7428. string file_str = "";
  7429. file_str += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  7430. file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  7431. file_str += "检验记录:\r\n" + richTextBox_CheckModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  7432. file_str += "检验结果:\r\n" + label_CheckModeResult.Text + "\r\n\r\n";
  7433. file_str += Local_HdInformation;
  7434. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  7435. //上传测试记录到服务器
  7436. if (myFtp.IsNetConnected == true)
  7437. {
  7438. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  7439. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  7440. {
  7441. myFtp.MakeDir(ServerSavePath + DateNow);
  7442. }
  7443. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  7444. {
  7445. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  7446. }
  7447. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  7448. if (result == true)
  7449. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  7450. }
  7451. //扫码框清空
  7452. textBox_CheckModeScan.Text = "";
  7453. }
  7454. /// <summary>
  7455. /// 参数检验开始
  7456. /// </summary>
  7457. /// <param name="sender"></param>
  7458. /// <param name="e"></param>
  7459. private void button_CheckModeStart_Click(object sender, EventArgs e)
  7460. {
  7461. //测试项目关闭编辑
  7462. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  7463. foreach (Control c in groupBox29.Controls)
  7464. {
  7465. if (c is CheckBox)
  7466. c.Enabled = false;
  7467. }
  7468. ReadLockStatus = true;
  7469. //检查配置文件
  7470. if (comboBox_CheckModeCfgFile.Text == "")
  7471. {
  7472. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  7473. return;
  7474. }
  7475. //开始测试
  7476. CheckTestStart();
  7477. }
  7478. /// <summary>
  7479. /// 参数检验测试子函数
  7480. /// </summary>
  7481. private void CheckTestStart()
  7482. {
  7483. //初始化标签
  7484. CheckModeLabelInit();
  7485. richTextBox_CheckModeLog.Clear();
  7486. //按钮禁止操作
  7487. button_CheckModeStart.Enabled = false;
  7488. //记录配置文件
  7489. richTextBox_CheckModeLog.AppendText("配置文件:" + comboBox_CheckModeCfgDate.Text + " / " + comboBox_CheckModeCfgFile.Text + "\r\n");
  7490. //检查打标信息
  7491. label_CheckModeStatus.Text = "检查扫码信息";
  7492. Delay_ms(500);
  7493. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  7494. if (textBox_CheckModeScan.Text == string.Empty)
  7495. {
  7496. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  7497. button__FacMode_Start.Enabled = false;
  7498. return;
  7499. }
  7500. try
  7501. {
  7502. if (中置电机ToolStripMenuItem.Checked == true)
  7503. {
  7504. if (textBox_CheckModeScan.Text.Split(' ').Length != 7)
  7505. {
  7506. label_CheckModeStatus.Text = "存在故障!";
  7507. label_CheckModeResult.BackColor = Color.Red;
  7508. label_CheckModeResult.Text = "标签格式错误";
  7509. button_CheckModeStart.Enabled = true;
  7510. return;
  7511. }
  7512. }
  7513. else if (轮毂电机ToolStripMenuItem.Checked == true)
  7514. {
  7515. if (textBox_CheckModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  7516. {
  7517. label_CheckModeStatus.Text = "存在故障!";
  7518. label_CheckModeResult.BackColor = Color.Red;
  7519. label_CheckModeResult.Text = "标签格式错误";
  7520. button_CheckModeStart.Enabled = true;
  7521. return;
  7522. }
  7523. }
  7524. }
  7525. catch (System.Exception)
  7526. {
  7527. label_CheckModeStatus.Text = "存在故障!";
  7528. label_CheckModeResult.BackColor = Color.Red;
  7529. label_CheckModeResult.Text = "标签格式错误";
  7530. button_CheckModeStart.Enabled = true;
  7531. return;
  7532. }
  7533. //打开串口
  7534. mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false);
  7535. if (!mySerialProcess.mySerial.IsOpen)
  7536. {
  7537. MessageBox.Show("请检查串口连接!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  7538. button__FacMode_Start.Enabled = false;
  7539. return;
  7540. }
  7541. //流水号计数
  7542. int serial = Convert.ToInt32(label_CheckModeSerial.Text);
  7543. serial += 1;
  7544. label_CheckModeSerial.Text = serial.ToString();
  7545. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, serial.ToString());
  7546. //创建线程,执行测试任务
  7547. Thread th = new Thread(CheckModeTest_Task);
  7548. th.Start();
  7549. }
  7550. /// <summary>
  7551. /// 执行一次测试任务
  7552. /// </summary>
  7553. private void CheckModeTest_Task()
  7554. {
  7555. //开始测试
  7556. richTextBox_CheckModeLog.AppendText("产品标签:" + textBox_CheckModeScan.Text + "\r\n");
  7557. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  7558. //变量定义
  7559. var Code = new byte[255];//发送的指令数据
  7560. ushort DataTemp;
  7561. short DataTemp_Int16;
  7562. string ResultPathName = "";
  7563. label_CheckModeStatus.Text = "开始测试";
  7564. Delay_ms(500);
  7565. label_CheckModeStatus.Text = "系统开机";
  7566. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  7567. if (uARTToolStripMenuItem.Checked)
  7568. {
  7569. Code[0] = (byte)'R';
  7570. Code[1] = (byte)'E';
  7571. Code[2] = (byte)'S';
  7572. Code[3] = (byte)'E';
  7573. Code[4] = (byte)'T';
  7574. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  7575. Delay_ms(500);
  7576. }
  7577. //系统开机,确保测试前先关机,发送关机指令再发送开机指令
  7578. BootInfo = "";
  7579. Code[0] = 0xF0;
  7580. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  7581. Delay_ms(1500);
  7582. Code[0] = 0xF1;
  7583. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  7584. ACK_WaitCnt = 0;
  7585. while (ACK_WaitCnt <= 15) ; //7.5s
  7586. //检查BOOT版本
  7587. if (BootInfo != string.Empty)
  7588. {
  7589. label_CheckModeBoot.BackColor = Color.Green;
  7590. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  7591. Delay_ms(500);
  7592. }
  7593. else
  7594. {
  7595. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
  7596. label_CheckModeStatus.Text = "存在故障!";
  7597. label_CheckModeResult.BackColor = Color.Red;
  7598. label_CheckModeResult.Text = "测试异常";
  7599. Delay_ms(500);
  7600. //存储异常并上传
  7601. CheckMode_Stop(false);
  7602. return;
  7603. }
  7604. #if false
  7605. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  7606. {
  7607. Code[0] = 0x00;//5S协议
  7608. Code[1] = 0x00;
  7609. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  7610. Delay_ms(500);
  7611. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  7612. Delay_ms(500);
  7613. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  7614. }
  7615. #endif
  7616. //发送指令读取版本信息
  7617. do
  7618. {
  7619. label_CheckModeStatus.Text = "读取版本信息";
  7620. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  7621. //发送指令读取版本
  7622. Class_Motor_Ver.Mode = "---";
  7623. Class_Motor_Ver.SN = "---";
  7624. Class_Motor_Ver.HW = "---";
  7625. Class_Motor_Ver.FW = "---";
  7626. Class_Motor_Ver.Special = "---";
  7627. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7628. ACK_WaitCnt = 0;
  7629. while (ACK_WaitCnt <= 2) ; //1s
  7630. if (Class_Motor_Ver.Mode == "---")
  7631. {
  7632. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第1次重发" + "\r\n");
  7633. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7634. ACK_WaitCnt = 0;
  7635. while (ACK_WaitCnt <= 2) ; //1s
  7636. if (Class_Motor_Ver.Mode == "---")
  7637. {
  7638. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第2次重发" + "\r\n");
  7639. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7640. ACK_WaitCnt = 0;
  7641. while (ACK_WaitCnt <= 2) ; //1s
  7642. if (Class_Motor_Ver.Mode == "---")
  7643. {
  7644. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取失败" + "\r\n");
  7645. label_CheckModeStatus.Text = "存在故障!";
  7646. label_CheckModeResult.BackColor = Color.Red;
  7647. label_CheckModeResult.Text = "测试异常";
  7648. Delay_ms(500);
  7649. //存储异常并上传
  7650. CheckMode_Stop(false);
  7651. return;
  7652. }
  7653. }
  7654. }
  7655. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  7656. Delay_ms(500);
  7657. } while (false);
  7658. //软件版本检查
  7659. if (checkBox_CheckModeFWVer.Checked)
  7660. {
  7661. richTextBox_CheckModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  7662. richTextBox_CheckModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  7663. richTextBox_CheckModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  7664. richTextBox_CheckModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  7665. richTextBox_CheckModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  7666. //判断版本是否正确
  7667. string VerCheck = comboBox_CheckModeCfgFile.Text.Split('_')[3] + "_" + comboBox_CheckModeCfgFile.Text.Split('_')[4];
  7668. string VerRead = "";
  7669. try
  7670. {
  7671. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  7672. }
  7673. catch (System.Exception)
  7674. {
  7675. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  7676. label_CheckModeStatus.Text = "存在故障!";
  7677. label_CheckModeResult.BackColor = Color.Red;
  7678. label_CheckModeResult.Text = "测试异常";
  7679. Delay_ms(500);
  7680. //存储异常并上传
  7681. CheckMode_Stop(false);
  7682. return;
  7683. }
  7684. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  7685. {
  7686. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
  7687. label_CheckModeStatus.Text = "存在故障!";
  7688. label_CheckModeResult.BackColor = Color.Red;
  7689. label_CheckModeResult.Text = "测试异常";
  7690. Delay_ms(500);
  7691. //存储异常并上传
  7692. CheckMode_Stop(false);
  7693. return;
  7694. }
  7695. label_CheckModeFWVer.BackColor = Color.Green;
  7696. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  7697. Delay_ms(500);
  7698. }
  7699. else
  7700. {
  7701. label_CheckModeFWVer.BackColor = Color.Yellow;
  7702. label_CheckModeStatus.Text = "跳过软件版本查询";
  7703. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过软件版本查询" + "\r\n");
  7704. Delay_ms(500);
  7705. }
  7706. //打标信息核对
  7707. if (checkBox_CheckModeSN.Checked)
  7708. {
  7709. label_CheckModeStatus.Text = "核对打标信息";
  7710. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "核对打标信息" + "\r\n");
  7711. //根据扫码信息获取型号和SN
  7712. string ScanInfo = textBox_CheckModeScan.Text;
  7713. string regexInfo = "";
  7714. string[] InfoList = { "" };
  7715. try
  7716. {
  7717. if (中置电机ToolStripMenuItem.Checked == true)
  7718. {
  7719. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  7720. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  7721. }
  7722. else if (轮毂电机ToolStripMenuItem.Checked == true)
  7723. {
  7724. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  7725. string Model = InfoList[0];
  7726. string Spec = InfoList[1];
  7727. string Sn = InfoList[2];
  7728. InfoList[0] = Model.Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  7729. InfoList[1] = Sn;
  7730. }
  7731. }
  7732. catch
  7733. {
  7734. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  7735. label_FacModeStatus.Text = "存在故障!";
  7736. label_FacModeResult.BackColor = Color.Red;
  7737. label_FacModeResult.Text = "标签格式错误";
  7738. Delay_ms(500);
  7739. //存储异常并上传
  7740. CheckMode_Stop(false);
  7741. return;
  7742. }
  7743. //核对型号
  7744. if (string.Equals(InfoList[0], Class_Motor_Ver.Mode) == false) //型号错误,直接结束
  7745. {
  7746. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号不一致" + "\r\n");
  7747. label_CheckModeStatus.Text = "存在故障!";
  7748. label_CheckModeResult.BackColor = Color.Red;
  7749. label_CheckModeResult.Text = "测试异常";
  7750. Delay_ms(500);
  7751. //存储异常并上传
  7752. CheckMode_Stop(false);
  7753. return;
  7754. }
  7755. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号一致" + "\r\n");
  7756. Delay_ms(500);
  7757. //核对SN
  7758. if (string.Equals(InfoList[1], Class_Motor_Ver.SN) == false) //型号错误,直接结束
  7759. {
  7760. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN不一致" + "\r\n");
  7761. label_CheckModeStatus.Text = "存在故障!";
  7762. label_CheckModeResult.BackColor = Color.Red;
  7763. label_CheckModeResult.Text = "测试异常";
  7764. Delay_ms(500);
  7765. //存储异常并上传
  7766. CheckMode_Stop(false);
  7767. return;
  7768. }
  7769. label_CheckModeSN.BackColor = Color.Green;
  7770. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN一致" + "\r\n");
  7771. Delay_ms(500);
  7772. }
  7773. else
  7774. {
  7775. label_CheckModeSN.BackColor = Color.Yellow;
  7776. label_CheckModeStatus.Text = "跳过打标信息确认";
  7777. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过打标信息确认" + "\r\n");
  7778. Delay_ms(500);
  7779. }
  7780. //参数检验
  7781. if (checkBox_CheckModeCfg.Checked)
  7782. {
  7783. //读取配置文件信息
  7784. label_CheckModeStatus.Text = "参数检查";
  7785. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  7786. //配置文件
  7787. List<byte[]> CmdList = new List<byte[]>();
  7788. Dictionary<string, string> ConfigCmd = new Dictionary<string, string>();//配置文件格式
  7789. //从服务器下载文件
  7790. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  7791. {
  7792. string SelectFile = "";
  7793. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "/" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  7794. if (File.Exists(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  7795. {
  7796. File.Delete(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  7797. }
  7798. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  7799. //打开文件
  7800. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  7801. ConfigCmd.Clear();
  7802. while (streamReader.Peek() != -1)
  7803. {
  7804. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  7805. if (fileLineInfo.Contains("["))
  7806. {
  7807. if (fileLineInfo.Contains("助力参数"))
  7808. {
  7809. fileLineInfo = streamReader.ReadLine();
  7810. }
  7811. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  7812. }
  7813. }
  7814. streamReader.Close();
  7815. }
  7816. //从本地加载文件
  7817. else
  7818. {
  7819. string SelectFile = "";
  7820. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  7821. //打开文件
  7822. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  7823. ConfigCmd.Clear();
  7824. while (streamReader.Peek() != -1)
  7825. {
  7826. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  7827. if (fileLineInfo.Contains("["))
  7828. {
  7829. if (fileLineInfo.Contains("助力参数"))
  7830. {
  7831. fileLineInfo = streamReader.ReadLine();
  7832. }
  7833. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  7834. }
  7835. }
  7836. streamReader.Close();
  7837. }
  7838. int CmdNum = ConfigCmd.Count(); //指令个数
  7839. Delay_ms(500);
  7840. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "\r\n");
  7841. Delay_ms(500);
  7842. //逐条读取比较
  7843. try
  7844. {
  7845. foreach (string key in ConfigCmd.Keys)
  7846. {
  7847. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令:" + "\r\n");
  7848. CmdRevStrTemp = "";
  7849. if (key.Contains("曲线"))
  7850. {
  7851. byte LineNum = 0;
  7852. var code = new byte[4];
  7853. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  7854. if (LineNum <= 5)
  7855. {
  7856. code[0] = (byte)(LineNum & 0xFF);
  7857. code[1] = (byte)((LineNum >> 8) & 0xFF);
  7858. code[2] = (byte)(LineNum & 0xFF);
  7859. code[3] = (byte)((LineNum >> 8) & 0xFF);
  7860. }
  7861. else
  7862. {
  7863. code[0] = (byte)(LineNum & 0xFF);
  7864. code[1] = (byte)((LineNum >> 8) & 0xFF);
  7865. code[2] = (byte)(5 & 0xFF);
  7866. code[3] = (byte)((5 >> 8) & 0xFF);
  7867. }
  7868. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  7869. }
  7870. else
  7871. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  7872. Delay_ms(500);
  7873. if (CmdRevStrTemp == string.Empty)
  7874. {
  7875. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "指令读取失败" + "\r\n");
  7876. label_CheckModeStatus.Text = "存在故障!";
  7877. label_CheckModeResult.BackColor = Color.Red;
  7878. label_CheckModeResult.Text = "测试异常";
  7879. Delay_ms(500);
  7880. //存储异常并上传
  7881. CheckMode_Stop(false);
  7882. return;
  7883. }
  7884. //比较当前指令,读取的配置文件和返回数据比较
  7885. string ParamWrite = ConfigCmd[key].Substring(24, ConfigCmd[key].Length - 40).Trim();
  7886. string ParamRead = "";
  7887. if (string.Compare(key, "[其它传感器参数]") == 0)
  7888. ParamRead = CmdRevStrTemp.Substring(90, CmdRevStrTemp.Length - 90).Trim(); //该指令包含力矩参数
  7889. else
  7890. ParamRead = CmdRevStrTemp.Substring(6, CmdRevStrTemp.Length - 6).Trim();
  7891. if (ParamWrite.Contains(ParamRead))
  7892. {
  7893. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "一致" + "\r\n");
  7894. continue;
  7895. }
  7896. else
  7897. {
  7898. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "不一致" + "\r\n");
  7899. label_CheckModeStatus.Text = "存在故障!";
  7900. label_CheckModeResult.BackColor = Color.Red;
  7901. label_CheckModeResult.Text = "测试异常";
  7902. Delay_ms(500);
  7903. //存储异常并上传
  7904. CheckMode_Stop(false);
  7905. return;
  7906. }
  7907. }
  7908. }
  7909. catch (System.Exception)
  7910. {
  7911. timer_1s.Enabled = false;
  7912. MessageBox.Show("参数检验失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  7913. timer_1s.Enabled = true;
  7914. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  7915. }
  7916. }
  7917. else
  7918. {
  7919. label_CheckModeCfg.BackColor = Color.Yellow;
  7920. label_CheckModeStatus.Text = "跳过参数检验";
  7921. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数检验" + "\r\n");
  7922. Delay_ms(500);
  7923. }
  7924. label_CheckModeCfg.BackColor = Color.Green;
  7925. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数检验正确" + "\r\n");
  7926. Delay_ms(500);
  7927. //读取力矩传感器
  7928. do
  7929. {
  7930. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据" + "\r\n");
  7931. //发送指令读取力矩传感器标定数据
  7932. CmdRevStrTemp = "";
  7933. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  7934. ACK_WaitCnt = 0;
  7935. while (ACK_WaitCnt <= 2) ; //1s
  7936. if (CmdRevStrTemp == "---")
  7937. {
  7938. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取失败" + "\r\n");
  7939. label_CheckModeStatus.Text = "存在故障!";
  7940. label_CheckModeResult.BackColor = Color.Red;
  7941. label_CheckModeResult.Text = "测试异常";
  7942. Delay_ms(500);
  7943. //存储异常并上传
  7944. CheckMode_Stop(false);
  7945. return;
  7946. }
  7947. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取成功" + "\r\n");
  7948. //取力矩传感器数据
  7949. ushort ZeroInit, Zero1, Zero2, Zero3, ZeroNew;
  7950. ushort MaxTorque;
  7951. ushort K1_T, K1, K2_T, K2, K3_T, K3, K4_T, K4;
  7952. byte[] DataArray = mySerialProcess.HexStringToBytes(CmdRevStrTemp, true);
  7953. ZeroInit = (ushort)((DataArray[3] << 8) + DataArray[2]);
  7954. Zero1 = (ushort)((DataArray[5] << 8) + DataArray[4]);
  7955. Zero2 = (ushort)((DataArray[7] << 8) + DataArray[6]);
  7956. Zero3 = (ushort)((DataArray[9] << 8) + DataArray[8]);
  7957. ZeroNew = (ushort)((DataArray[11] << 8) + DataArray[10]);
  7958. MaxTorque = (ushort)((DataArray[13] << 8) + DataArray[12]);
  7959. K1_T = (ushort)((DataArray[15] << 8) + DataArray[14]);
  7960. K1 = (ushort)((DataArray[17] << 8) + DataArray[16]);
  7961. K2_T = (ushort)((DataArray[19] << 8) + DataArray[18]);
  7962. K2 = (ushort)((DataArray[21] << 8) + DataArray[20]);
  7963. K3_T = (ushort)((DataArray[23] << 8) + DataArray[22]);
  7964. K3 = (ushort)((DataArray[25] << 8) + DataArray[24]);
  7965. K4_T = (ushort)((DataArray[27] << 8) + DataArray[26]);
  7966. K4 = (ushort)((DataArray[29] << 8) + DataArray[28]);
  7967. richTextBox_CheckModeLog.AppendText("力矩传感器零点: " + ZeroInit.ToString() + "," + Zero1.ToString() + "," +
  7968. Zero2.ToString() + "," + Zero3.ToString() + "," + ZeroNew.ToString() + "\r\n");
  7969. richTextBox_CheckModeLog.AppendText("最大力矩: " + MaxTorque.ToString() + "\r\n");
  7970. richTextBox_CheckModeLog.AppendText("力矩传感器标定: " + "[" + K1_T.ToString() + "," + K1.ToString() + "]" + "," +
  7971. "[" + K2_T.ToString() + "," + K2.ToString() + "]" + "," + "[" + K3_T.ToString() + "," + K3.ToString() + "]" + "," +
  7972. "[" + K4_T.ToString() + "," + K4.ToString() + "]" + "\r\n");
  7973. //传感器标定检验
  7974. if (checkBox_CheckModeTorque.Checked)
  7975. {
  7976. richTextBox_CheckModeLog.AppendText("力矩零点范围: " + TorqueParamsForm.Zero.Min.ToString() + " - " + TorqueParamsForm.Zero.Max.ToString() + "\r\n");
  7977. richTextBox_CheckModeLog.AppendText("K1范围: " + TorqueParamsForm.K1.T.ToString() + "," + TorqueParamsForm.K1.Min.ToString() + " - " + TorqueParamsForm.K1.Max.ToString() + "\r\n");
  7978. richTextBox_CheckModeLog.AppendText("K2范围: " + TorqueParamsForm.K2.T.ToString() + "," + TorqueParamsForm.K2.Min.ToString() + " - " + TorqueParamsForm.K2.Max.ToString() + "\r\n");
  7979. richTextBox_CheckModeLog.AppendText("K3范围: " + TorqueParamsForm.K3.T.ToString() + "," + TorqueParamsForm.K3.Min.ToString() + " - " + TorqueParamsForm.K3.Max.ToString() + "\r\n");
  7980. richTextBox_CheckModeLog.AppendText("K4范围: " + TorqueParamsForm.K4.T.ToString() + "," + TorqueParamsForm.K4.Min.ToString() + " - " + TorqueParamsForm.K4.Max.ToString() + "\r\n");
  7981. //与设置值比较
  7982. if ((ZeroInit <= TorqueParamsForm.Zero.Max) && (ZeroInit >= TorqueParamsForm.Zero.Min)
  7983. && (K1_T == TorqueParamsForm.K1.T) && (K1 <= TorqueParamsForm.K1.Max) && (K1 >= TorqueParamsForm.K1.Min)
  7984. && (K2_T == TorqueParamsForm.K2.T) && (K2 <= TorqueParamsForm.K2.Max) && (K2 >= TorqueParamsForm.K2.Min)
  7985. && (K3_T == TorqueParamsForm.K3.T) && (K3 <= TorqueParamsForm.K3.Max) && (K3 >= TorqueParamsForm.K3.Min)
  7986. && (K4_T == TorqueParamsForm.K4.T) && (K4 <= TorqueParamsForm.K4.Max) && (K4 >= TorqueParamsForm.K4.Min)
  7987. )
  7988. {
  7989. label_CheckModeTorque.BackColor = Color.Green;
  7990. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定正常" + "\r\n");
  7991. Delay_ms(500);
  7992. }
  7993. else
  7994. {
  7995. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定超范围" + "\r\n");
  7996. label_CheckModeStatus.Text = "存在故障!";
  7997. label_CheckModeResult.BackColor = Color.Red;
  7998. label_CheckModeResult.Text = "测试异常";
  7999. Delay_ms(500);
  8000. //存储异常并上传
  8001. CheckMode_Stop(false);
  8002. return;
  8003. }
  8004. }
  8005. else
  8006. {
  8007. label_CheckModeTorque.BackColor = Color.Yellow;
  8008. label_CheckModeStatus.Text = "跳过传感器标定检验";
  8009. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过传感器标定检验" + "\r\n");
  8010. Delay_ms(500);
  8011. }
  8012. } while (false);
  8013. //读取MOS内阻校准参数
  8014. do
  8015. {
  8016. if (checkBox_CheckModeMos.Checked)
  8017. {
  8018. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据" + "\r\n");
  8019. //读取显示校准返回数据
  8020. foreach (Control c in groupBox21.Controls)
  8021. {
  8022. if (c is TextBox)
  8023. c.Text = "";
  8024. }
  8025. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8026. ACK_WaitCnt = 0;
  8027. while (ACK_WaitCnt <= 2) ; //1s
  8028. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  8029. {
  8030. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果异常" + "\r\n");
  8031. label_CheckModeStatus.Text = "存在故障!";
  8032. label_CheckModeResult.BackColor = Color.Red;
  8033. label_CheckModeResult.Text = "测试异常";
  8034. Delay_ms(500);
  8035. //存储异常并上传
  8036. CheckMode_Stop(false);
  8037. return;
  8038. }
  8039. else
  8040. {
  8041. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻:" + textBox_MOS_R1.Text + " " + textBox_MOS_R2.Text + " " + textBox_MOS_R3.Text + "\r\n");
  8042. }
  8043. //与校准返回数据对比
  8044. string[] MOS_R1_Th = toolStripTextBox_MOS1.Text.Split(',');
  8045. string[] MOS_R2_Th = toolStripTextBox_MOS2.Text.Split(',');
  8046. string[] MOS_R3_Th = toolStripTextBox_MOS3.Text.Split(',');
  8047. if ((Convert.ToUInt16(textBox_MOS_R1.Text) >= Convert.ToUInt16(MOS_R1_Th[0])) && (Convert.ToUInt16(textBox_MOS_R1.Text) <= Convert.ToUInt16(MOS_R1_Th[1])) &&
  8048. (Convert.ToUInt16(textBox_MOS_R2.Text) >= Convert.ToUInt16(MOS_R2_Th[0])) && (Convert.ToUInt16(textBox_MOS_R2.Text) <= Convert.ToUInt16(MOS_R2_Th[1])) &&
  8049. (Convert.ToUInt16(textBox_MOS_R3.Text) >= Convert.ToUInt16(MOS_R3_Th[0])) && (Convert.ToUInt16(textBox_MOS_R3.Text) <= Convert.ToUInt16(MOS_R3_Th[1]))
  8050. )
  8051. {
  8052. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准合格" + "\r\n");
  8053. label_CheckModeMos.BackColor = Color.Green;
  8054. }
  8055. else
  8056. {
  8057. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准超范围" + "\r\n");
  8058. label_CheckModeStatus.Text = "存在故障!";
  8059. label_CheckModeResult.BackColor = Color.Red;
  8060. label_CheckModeResult.Text = "测试异常";
  8061. Delay_ms(500);
  8062. //存储异常并上传
  8063. CheckMode_Stop(false);
  8064. return;
  8065. }
  8066. }
  8067. else
  8068. {
  8069. label_CheckModeMos.BackColor = Color.Yellow;
  8070. label_CheckModeStatus.Text = "跳过MOS内阻校准检验";
  8071. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过MOS内阻校准检验" + "\r\n");
  8072. Delay_ms(500);
  8073. }
  8074. } while (false);
  8075. //测试合格
  8076. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  8077. label_CheckModeStatus.Text = "测试结束!";
  8078. label_CheckModeResult.BackColor = Color.Green;
  8079. label_CheckModeResult.Text = "测试合格";
  8080. Delay_ms(500);
  8081. //存储并上传
  8082. CheckMode_Stop(true);
  8083. return;
  8084. }
  8085. private void CheckModeLabelInit()
  8086. {
  8087. //测试状态标签
  8088. label_CheckModeResult.BackColor = Color.Yellow;
  8089. label_CheckModeResult.Text = "测试中";
  8090. //测试过程标签
  8091. label_CheckModeStatus.Text = "测试就绪";
  8092. //测试结果标签
  8093. foreach (Control c in groupBox31.Controls)
  8094. {
  8095. if (c is Label)
  8096. {
  8097. if (c.Text == string.Empty)
  8098. c.BackColor = Color.Red;
  8099. }
  8100. }
  8101. }
  8102. private void 调试记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  8103. {
  8104. System.Diagnostics.Process.Start("explorer.exe", Directory.GetCurrentDirectory());
  8105. }
  8106. private void 生产记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  8107. {
  8108. System.Diagnostics.Process.Start("explorer.exe", localInfo.LocalDataPath);
  8109. }
  8110. private void 累计运行时间ToolStripMenuItem_MouseHover(object sender, EventArgs e)
  8111. {
  8112. UInt32 Time = (UInt32)stopwatch.ElapsedMilliseconds / 1000;
  8113. UInt32 hour = Time / 3600;
  8114. UInt32 min = (Time % 3600) / 60;
  8115. UInt32 s = (Time % 60);
  8116. toolStripMenuItem_RunTime.Text = hour.ToString() + ":" + min.ToString("00") + ":" + s.ToString("00");
  8117. }
  8118. private void richTextBox_CheckModeLog_TextChanged(object sender, EventArgs e)
  8119. {
  8120. richTextBox_CheckModeLog.SelectionStart = richTextBox_CheckModeLog.Text.Length;
  8121. richTextBox_CheckModeLog.ScrollToCaret();
  8122. }
  8123. private void 力矩传感器检验ToolStripMenuItem_Click(object sender, EventArgs e)
  8124. {
  8125. TorqueParamsForm.ShowDialog();
  8126. }
  8127. private void textBox_CheckModeScan_KeyUp(object sender, KeyEventArgs e)
  8128. {
  8129. if (e.KeyCode == Keys.Enter)
  8130. CheckTestStart();
  8131. }
  8132. private void textBox_FacModeScan_KeyUp(object sender, KeyEventArgs e)
  8133. {
  8134. if (e.KeyCode == Keys.Enter)
  8135. TestStart();
  8136. }
  8137. private void button_SpeedDec10_Click(object sender, EventArgs e)
  8138. {
  8139. if (numericUpDown_SpeedAdj.Value <= 10)
  8140. numericUpDown_SpeedAdj.Value = 0;
  8141. else
  8142. numericUpDown_SpeedAdj.Value -= 10;
  8143. }
  8144. private void button_SpeedAdd10_Click(object sender, EventArgs e)
  8145. {
  8146. if (numericUpDown_SpeedAdj.Value >= 90)
  8147. numericUpDown_SpeedAdj.Value = 100;
  8148. else
  8149. numericUpDown_SpeedAdj.Value += 10;
  8150. }
  8151. private void button_SpeedDec1_Click(object sender, EventArgs e)
  8152. {
  8153. if (numericUpDown_SpeedAdj.Value <= 1)
  8154. numericUpDown_SpeedAdj.Value = 0;
  8155. else
  8156. numericUpDown_SpeedAdj.Value -= 1;
  8157. }
  8158. private void button_SpeedAdd1_Click(object sender, EventArgs e)
  8159. {
  8160. if(numericUpDown_SpeedAdj.Value >= 99)
  8161. numericUpDown_SpeedAdj.Value = 100;
  8162. else
  8163. numericUpDown_SpeedAdj.Value += 1;
  8164. }
  8165. bool WriteLockStatus = true;
  8166. private void pictureBox_WriteLock_Click(object sender, EventArgs e)
  8167. {
  8168. if (WriteLockStatus == true)
  8169. {
  8170. EnterForm1.ShowDialog();
  8171. try
  8172. {
  8173. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  8174. {
  8175. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  8176. {
  8177. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  8178. foreach (Control c in groupBox2.Controls)
  8179. {
  8180. if (c is CheckBox)
  8181. c.Enabled = true;
  8182. }
  8183. WriteLockStatus = !WriteLockStatus;
  8184. }
  8185. else
  8186. {
  8187. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8188. }
  8189. }
  8190. else
  8191. {
  8192. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8193. }
  8194. }
  8195. catch (Exception)
  8196. {
  8197. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8198. }
  8199. }
  8200. else
  8201. {
  8202. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  8203. foreach (Control c in groupBox2.Controls)
  8204. {
  8205. if (c is CheckBox)
  8206. c.Enabled = false;
  8207. }
  8208. WriteLockStatus = !WriteLockStatus;
  8209. }
  8210. }
  8211. bool ReadLockStatus = true;
  8212. private void pictureBox_ReadLock_Click(object sender, EventArgs e)
  8213. {
  8214. if (ReadLockStatus == true)
  8215. {
  8216. EnterForm1.ShowDialog();
  8217. try
  8218. {
  8219. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  8220. {
  8221. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  8222. {
  8223. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  8224. foreach (Control c in groupBox29.Controls)
  8225. {
  8226. if (c is CheckBox)
  8227. c.Enabled = true;
  8228. }
  8229. ReadLockStatus = !ReadLockStatus;
  8230. }
  8231. else
  8232. {
  8233. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8234. }
  8235. }
  8236. else
  8237. {
  8238. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8239. }
  8240. }
  8241. catch (Exception)
  8242. {
  8243. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8244. }
  8245. }
  8246. else
  8247. {
  8248. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  8249. foreach (Control c in groupBox29.Controls)
  8250. {
  8251. if (c is CheckBox)
  8252. c.Enabled = false;
  8253. }
  8254. ReadLockStatus = !ReadLockStatus;
  8255. }
  8256. }
  8257. private void 屏幕键盘ToolStripMenuItem_Click(object sender, EventArgs e)
  8258. {
  8259. System.Diagnostics.Process.Start("osk.exe");
  8260. }
  8261. private void checkBox_OffLineCheckMode_CheckedChanged(object sender, EventArgs e)
  8262. {
  8263. comboBox_CheckModeCfgDate.SelectedIndex = -1;
  8264. comboBox_CheckModeCfgFile.SelectedIndex = -1;
  8265. checkBox_OffLineFacMode.Checked = checkBox_OffLineCheckMode.Checked;
  8266. }
  8267. private void checkBox_OffLineFacMode_CheckedChanged(object sender, EventArgs e)
  8268. {
  8269. comboBox_FacModeCfgDate.SelectedIndex = -1;
  8270. comboBox_FacModeCfgFile.SelectedIndex = -1;
  8271. checkBox_OffLineCheckMode.Checked = checkBox_OffLineFacMode.Checked;
  8272. }
  8273. private void 版本ToolStripMenuItem_Click(object sender, EventArgs e)
  8274. {
  8275. VersionForm.ShowDialog();
  8276. }
  8277. private void button_MOS_Cal_Click(object sender, EventArgs e)
  8278. {
  8279. textBox_MOS_R1.Text = "";
  8280. textBox_MOS_R2.Text = "";
  8281. textBox_MOS_R3.Text = "";
  8282. try
  8283. {
  8284. var Code = new byte[18];
  8285. for (int i = 0; i < 18; i++)
  8286. Code[i] = 0;
  8287. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  8288. ushort uwDataTemp = 0;
  8289. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  8290. Code[2] = (byte)(uwDataTemp & 0xFF);
  8291. Code[3] = (byte)(uwDataTemp >> 8);
  8292. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  8293. Code[4] = (byte)(uwDataTemp & 0xFF);
  8294. Code[5] = (byte)(uwDataTemp >> 8);
  8295. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  8296. Code[6] = (byte)(uwDataTemp & 0xFF);
  8297. Code[7] = (byte)(uwDataTemp >> 8);
  8298. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  8299. Code[8] = (byte)(uwDataTemp & 0xFF);
  8300. Code[9] = (byte)(uwDataTemp >> 8);
  8301. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  8302. Code[10] = (byte)(uwDataTemp & 0xFF);
  8303. Code[11] = (byte)(uwDataTemp >> 8);
  8304. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  8305. }
  8306. catch (Exception)
  8307. {
  8308. MessageBox.Show("系数填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8309. }
  8310. }
  8311. private void button_MOS_Read_Click(object sender, EventArgs e)
  8312. {
  8313. foreach (Control c in groupBox21.Controls)
  8314. {
  8315. if (c is TextBox)
  8316. c.Text = "";
  8317. }
  8318. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8319. }
  8320. private void button_MOS_Write_Click(object sender, EventArgs e)
  8321. {
  8322. try
  8323. {
  8324. var Code = new byte[34];
  8325. for (int i = 0; i < 34; i++)
  8326. Code[i] = 0;
  8327. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  8328. ushort uwDataTemp = 0;
  8329. uwDataTemp = Convert.ToUInt16(textBox_MOS_R1.Text);
  8330. Code[2] = (byte)(uwDataTemp & 0xFF);
  8331. Code[3] = (byte)(uwDataTemp >> 8);
  8332. uwDataTemp = Convert.ToUInt16(textBox_MOS_R2.Text);
  8333. Code[4] = (byte)(uwDataTemp & 0xFF);
  8334. Code[5] = (byte)(uwDataTemp >> 8);
  8335. uwDataTemp = Convert.ToUInt16(textBox_MOS_R3.Text);
  8336. Code[6] = (byte)(uwDataTemp & 0xFF);
  8337. Code[7] = (byte)(uwDataTemp >> 8);
  8338. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  8339. Code[8] = (byte)(uwDataTemp & 0xFF);
  8340. Code[9] = (byte)(uwDataTemp >> 8);
  8341. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  8342. Code[10] = (byte)(uwDataTemp & 0xFF);
  8343. Code[11] = (byte)(uwDataTemp >> 8);
  8344. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  8345. Code[12] = (byte)(uwDataTemp & 0xFF);
  8346. Code[13] = (byte)(uwDataTemp >> 8);
  8347. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  8348. Code[14] = (byte)(uwDataTemp & 0xFF);
  8349. Code[15] = (byte)(uwDataTemp >> 8);
  8350. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  8351. Code[16] = (byte)(uwDataTemp & 0xFF);
  8352. Code[17] = (byte)(uwDataTemp >> 8);
  8353. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4C22, Code);
  8354. }
  8355. catch (Exception)
  8356. {
  8357. MessageBox.Show("数据填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8358. }
  8359. }
  8360. /// <summary>
  8361. /// 测试模式点击文本框自动全选
  8362. /// </summary>
  8363. /// <param name="sender"></param>
  8364. /// <param name="e"></param>
  8365. private void textBox_FacModeScan_MouseClick(object sender, MouseEventArgs e)
  8366. {
  8367. textBox_FacModeScan.SelectAll();
  8368. }
  8369. /// <summary>
  8370. /// 检验模式点击文本框自动全选
  8371. /// </summary>
  8372. /// <param name="sender"></param>
  8373. /// <param name="e"></param>
  8374. private void textBox_CheckModeScan_MouseClick(object sender, MouseEventArgs e)
  8375. {
  8376. textBox_CheckModeScan.SelectAll();
  8377. }
  8378. /// <summary>
  8379. /// 鼠标放置显示连接服务器信息
  8380. /// </summary>
  8381. /// <param name="sender"></param>
  8382. /// <param name="e"></param>
  8383. private void label_ServerStatus_MouseHover(object sender, EventArgs e)
  8384. {
  8385. // 创建the ToolTip
  8386. ToolTip toolTip1 = new ToolTip();
  8387. // 设置显示样式
  8388. toolTip1.AutoPopDelay = 30000;//提示信息的可见时间
  8389. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  8390. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  8391. toolTip1.ShowAlways = true;//是否显示提示框
  8392. if (myFtp.IsNetConnected)
  8393. {
  8394. toolTip1.SetToolTip(this.label_ServerStatus, "IP: " + toolStripTextBox_ServerIP.Text);//设置故障内容显示
  8395. }
  8396. else
  8397. {
  8398. toolTip1.SetToolTip(this.label_ServerStatus, "网络断开");//设置故障内容显示
  8399. }
  8400. }
  8401. /// <summary>
  8402. /// UART协议类型修改
  8403. /// </summary>
  8404. /// <param name="sender"></param>
  8405. /// <param name="e"></param>
  8406. private void 协议类型ToolStripMenuItem_SelectedIndexChanged(object sender, EventArgs e)
  8407. {
  8408. var Code = new byte[2];
  8409. Code[0] = (byte)协议类型ToolStripMenuItem.SelectedIndex;
  8410. Code[1] = 0x00;
  8411. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  8412. }
  8413. /// <summary>
  8414. /// 显示本机信息
  8415. /// </summary>
  8416. /// <param name="sender"></param>
  8417. /// <param name="e"></param>
  8418. private void 本机信息ToolStripMenuItem_Click(object sender, EventArgs e)
  8419. {
  8420. MessageBox.Show(Local_HdInformation, "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
  8421. }
  8422. /// <summary>
  8423. /// 量产模式删除当前选中文件
  8424. /// </summary>
  8425. /// <param name="sender"></param>
  8426. /// <param name="e"></param>
  8427. private void label112_DoubleClick(object sender, EventArgs e)
  8428. {
  8429. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  8430. {
  8431. EnterForm1.ShowDialog();
  8432. try
  8433. {
  8434. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  8435. {
  8436. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  8437. {
  8438. try
  8439. {
  8440. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + comboBox_FacModeCfgFile.Text);
  8441. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_FacModeCfgFile.Text) + ".src");
  8442. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_FacModeCfgFile.Text) + ".png");
  8443. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  8444. }
  8445. catch (Exception)
  8446. {
  8447. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8448. }
  8449. }
  8450. else
  8451. {
  8452. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8453. }
  8454. }
  8455. }
  8456. catch (Exception)
  8457. {
  8458. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8459. }
  8460. }
  8461. }
  8462. /// <summary>
  8463. /// 检验模式删除当前选中文件
  8464. /// </summary>
  8465. /// <param name="sender"></param>
  8466. /// <param name="e"></param>
  8467. private void label138_DoubleClick(object sender, EventArgs e)
  8468. {
  8469. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  8470. {
  8471. EnterForm1.ShowDialog();
  8472. try
  8473. {
  8474. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  8475. {
  8476. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  8477. {
  8478. try
  8479. {
  8480. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + comboBox_CheckModeCfgFile.Text);
  8481. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_CheckModeCfgFile.Text) + ".src");
  8482. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_CheckModeCfgFile.Text) + ".png");
  8483. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  8484. }
  8485. catch (Exception)
  8486. {
  8487. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8488. }
  8489. }
  8490. else
  8491. {
  8492. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8493. }
  8494. }
  8495. }
  8496. catch (Exception)
  8497. {
  8498. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8499. }
  8500. }
  8501. }
  8502. /// <summary>
  8503. /// 读取整车信息2
  8504. /// </summary>
  8505. /// <param name="sender"></param>
  8506. /// <param name="e"></param>
  8507. private void button_ReadBikeParam2_Click(object sender, EventArgs e)
  8508. {
  8509. richTextBox_BikeParam2.Clear();
  8510. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null);
  8511. }
  8512. /// <summary>
  8513. /// 写入整车信息2
  8514. /// </summary>
  8515. /// <param name="sender"></param>
  8516. /// <param name="e"></param>
  8517. private void button_WriteBikeParam2_Click(object sender, EventArgs e)
  8518. {
  8519. var ConfigParam = new byte[34];
  8520. for (int i = 0; i < 34; i++)
  8521. ConfigParam[i] = 0;
  8522. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  8523. string[] strDataTemp = richTextBox_BikeParam2.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  8524. try
  8525. {
  8526. for (int i = 0; i < strDataTemp.Length; i++)
  8527. {
  8528. short wDataTemp = 0;
  8529. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  8530. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  8531. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  8532. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  8533. }
  8534. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4D22, ConfigParam);
  8535. }
  8536. catch (Exception)
  8537. {
  8538. timer_1s.Enabled = false;
  8539. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8540. timer_1s.Enabled = true;
  8541. }
  8542. }
  8543. /// <summary>
  8544. /// 读取用户骑行参数
  8545. /// </summary>
  8546. /// <param name="sender"></param>
  8547. /// <param name="e"></param>
  8548. private void button_ReadUsrRideParam_Click(object sender, EventArgs e)
  8549. {
  8550. richTextBox_UsrRidesParam.Clear();
  8551. if (checkBox_UserRideParam_OBC.Checked)
  8552. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x4300, null);
  8553. else
  8554. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  8555. }
  8556. /// <summary>
  8557. /// 写入用户骑行参数
  8558. /// </summary>
  8559. /// <param name="sender"></param>
  8560. /// <param name="e"></param>
  8561. private void button_WriteUsrRidetParam_Click(object sender, EventArgs e)
  8562. {
  8563. var ConfigParam = new byte[34];
  8564. for (int i = 0; i < 34; i++)
  8565. ConfigParam[i] = 0;
  8566. if (checkBox_UserRideParam_OBC.Checked)
  8567. {
  8568. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  8569. string[] strDataTemp = richTextBox_UsrRidesParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  8570. try
  8571. {
  8572. for (int i = 0; i < strDataTemp.Length; i++)
  8573. {
  8574. ConfigParam[i + 2] = Convert.ToByte(strDataTemp[i].Split('=')[1]);
  8575. }
  8576. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4B22, ConfigParam);
  8577. }
  8578. catch (Exception)
  8579. {
  8580. timer_1s.Enabled = false;
  8581. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8582. timer_1s.Enabled = true;
  8583. }
  8584. }
  8585. else
  8586. {
  8587. string[] strDataTemp = richTextBox_UsrRidesParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  8588. try
  8589. {
  8590. for (int i = 0; i < strDataTemp.Length; i++)
  8591. {
  8592. ConfigParam[i] = Convert.ToByte(strDataTemp[i].Split('=')[1]);
  8593. }
  8594. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x4420, ConfigParam);
  8595. }
  8596. catch (Exception)
  8597. {
  8598. timer_1s.Enabled = false;
  8599. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8600. timer_1s.Enabled = true;
  8601. }
  8602. }
  8603. }
  8604. /// <summary>
  8605. /// 读取产品标签
  8606. /// </summary>
  8607. /// <param name="sender"></param>
  8608. /// <param name="e"></param>
  8609. private void button_ReadTag_Click(object sender, EventArgs e)
  8610. {
  8611. textBox_TagInfo.Text = "---";
  8612. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4E00, null);
  8613. }
  8614. /// <summary>
  8615. /// 写入产品标签
  8616. /// </summary>
  8617. /// <param name="sender"></param>
  8618. /// <param name="e"></param>
  8619. private void button_WriteTag_Click(object sender, EventArgs e)
  8620. {
  8621. string User = textBox_TagInfo.Text;
  8622. var UserArray = new byte[32];
  8623. for (ushort i = 0; i < User.Length; i++)
  8624. {
  8625. UserArray[i] = (byte)User[i];
  8626. }
  8627. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D20, UserArray);
  8628. }
  8629. /// <summary>
  8630. /// 上位机读取骑行历史
  8631. /// </summary>
  8632. /// <param name="sender"></param>
  8633. /// <param name="e"></param>
  8634. private void button_ReadRideLog_Click(object sender, EventArgs e)
  8635. {
  8636. textBox_ODO_KM.Text = "---";
  8637. textBox_ODO_TIME.Text = "---";
  8638. textBox_TRIP_KM.Text = "---";
  8639. textBox_TRIP_TIME.Text = "---";
  8640. textBox_OBC_TRIP_KM.Text = "";
  8641. textBox_OBC_TRIP_TIME.Text = "";
  8642. textBox_OBC_ODO_KM.Text = "";
  8643. textBox_OBC_ODO_TIME.Text = "";
  8644. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2E00, null);
  8645. }
  8646. /// <summary>
  8647. /// 上位机写入骑行历史
  8648. /// </summary>
  8649. /// <param name="sender"></param>
  8650. /// <param name="e"></param>
  8651. private void button_WriteRideLog_Click(object sender, EventArgs e)
  8652. {
  8653. UInt32 Data;
  8654. var UserArray = new byte[16];
  8655. try
  8656. {
  8657. Data = Convert.ToUInt32(textBox_ODO_KM.Text);
  8658. UserArray[0] = (byte)(Data & 0xFF);
  8659. UserArray[1] = (byte)(Data >> 8);
  8660. UserArray[2] = (byte)(Data >> 16);
  8661. UserArray[3] = (byte)(Data >> 24);
  8662. Data = Convert.ToUInt32(textBox_ODO_TIME.Text);
  8663. UserArray[4] = (byte)(Data & 0xFF);
  8664. UserArray[5] = (byte)(Data >> 8);
  8665. UserArray[6] = (byte)(Data >> 16);
  8666. UserArray[7] = (byte)(Data >> 24);
  8667. Data = Convert.ToUInt32(textBox_TRIP_KM.Text);
  8668. UserArray[8] = (byte)(Data & 0xFF);
  8669. UserArray[9] = (byte)(Data >> 8);
  8670. UserArray[10] = (byte)(Data >> 16);
  8671. UserArray[11] = (byte)(Data >> 24);
  8672. Data = Convert.ToUInt32(textBox_TRIP_TIME.Text);
  8673. UserArray[12] = (byte)(Data & 0xFF);
  8674. UserArray[13] = (byte)(Data >> 8);
  8675. UserArray[14] = (byte)(Data >> 16);
  8676. UserArray[15] = (byte)(Data >> 24);
  8677. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B10, UserArray);
  8678. }
  8679. catch (Exception ex)
  8680. {
  8681. MessageBox.Show("数据格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8682. }
  8683. }
  8684. /// <summary>
  8685. /// 获取删除配置文件日期列表
  8686. /// </summary>
  8687. /// <param name="sender"></param>
  8688. /// <param name="e"></param>
  8689. private void toolStripTextBox_DelCfgFile_Click(object sender, EventArgs e)
  8690. {
  8691. string[] DateList = { "" };
  8692. //网络断开时直接退出
  8693. if (!myFtp.IsNetConnected)
  8694. return;
  8695. //从服务器更新日期列表
  8696. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
  8697. toolStripTextBox_DelCfgFile.Items.Clear();
  8698. //日期列表加载,显示最近30条
  8699. if (DateList.Length > 30)
  8700. {
  8701. toolStripTextBox_DelCfgFile.Items.Add("支持最近30条");
  8702. toolStripTextBox_DelCfgFile.Items.Add("-----");
  8703. }
  8704. for (int i = (DateList.Length > 30) ? (DateList.Length - 30) : 0; i < DateList.Length; i++)//显示最近30个日期
  8705. {
  8706. toolStripTextBox_DelCfgFile.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  8707. }
  8708. }
  8709. /// <summary>
  8710. /// 删除指定配置文件
  8711. /// </summary>
  8712. /// <param name="sender"></param>
  8713. /// <param name="e"></param>
  8714. private void toolStripTextBox_DelCfgFile_SelectedIndexChanged(object sender, EventArgs e)
  8715. {
  8716. //提示输入文件名
  8717. Scan scan_form = new Scan();
  8718. scan_form.ShowDialog();
  8719. do
  8720. {
  8721. if (scan_form.textBox_Scan.Text == string.Empty)
  8722. {
  8723. timer_1s.Enabled = false;
  8724. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  8725. timer_1s.Enabled = true;
  8726. break;
  8727. }
  8728. string DelFile = scan_form.textBox_Scan.Text;
  8729. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  8730. {
  8731. EnterForm1.ShowDialog();
  8732. try
  8733. {
  8734. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  8735. {
  8736. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  8737. {
  8738. try
  8739. {
  8740. if (DelFile.Contains("."))
  8741. DelFile = Path.GetFileNameWithoutExtension(DelFile);
  8742. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".ttcfg");
  8743. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".src");
  8744. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".png");
  8745. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  8746. }
  8747. catch (Exception)
  8748. {
  8749. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8750. }
  8751. }
  8752. else
  8753. {
  8754. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8755. }
  8756. }
  8757. }
  8758. catch (Exception)
  8759. {
  8760. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8761. }
  8762. }
  8763. } while (false);
  8764. }
  8765. /// <summary>
  8766. /// 获取删除样机测试记录日期列表
  8767. /// </summary>
  8768. /// <param name="sender"></param>
  8769. /// <param name="e"></param>
  8770. private void toolStripTextBox_DelLogFile_Click(object sender, EventArgs e)
  8771. {
  8772. string[] DateList = { "" };
  8773. //网络断开时直接退出
  8774. if (!myFtp.IsNetConnected)
  8775. return;
  8776. //从服务器更新日期列表
  8777. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName);
  8778. toolStripTextBox_DelLogFile.Items.Clear();
  8779. //日期列表加载,显示最近30天
  8780. if (DateList.Length > 30)
  8781. {
  8782. toolStripTextBox_DelLogFile.Items.Add("支持最近30条");
  8783. toolStripTextBox_DelLogFile.Items.Add("-----");
  8784. }
  8785. for (int i = (DateList.Length > 30) ? (DateList.Length - 30) : 0; i < DateList.Length; i++)//显示最近30个日期
  8786. {
  8787. toolStripTextBox_DelLogFile.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  8788. }
  8789. }
  8790. /// <summary>
  8791. /// 删除指定的样机测试记录
  8792. /// </summary>
  8793. /// <param name="sender"></param>
  8794. /// <param name="e"></param>
  8795. private void toolStripTextBox_DelLogFile_SelectedIndexChanged(object sender, EventArgs e)
  8796. {
  8797. //提示输入文件名
  8798. Scan scan_form = new Scan();
  8799. scan_form.ShowDialog();
  8800. do
  8801. {
  8802. if (scan_form.textBox_Scan.Text == string.Empty)
  8803. {
  8804. timer_1s.Enabled = false;
  8805. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  8806. timer_1s.Enabled = true;
  8807. break;
  8808. }
  8809. string DelFile = scan_form.textBox_Scan.Text;
  8810. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  8811. {
  8812. EnterForm1.ShowDialog();
  8813. try
  8814. {
  8815. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  8816. {
  8817. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  8818. {
  8819. try
  8820. {
  8821. //删除指定目录下面所有文件和文件夹
  8822. myFtp.DelDirectoryWithAll(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName + "\\" + toolStripTextBox_DelLogFile.Text + "\\" + DelFile);
  8823. myFtp.RemoveDirectory(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName + "\\" + toolStripTextBox_DelLogFile.Text + "\\" + DelFile);
  8824. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  8825. }
  8826. catch (Exception)
  8827. {
  8828. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8829. }
  8830. }
  8831. else
  8832. {
  8833. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8834. }
  8835. }
  8836. }
  8837. catch (Exception)
  8838. {
  8839. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8840. }
  8841. }
  8842. } while (false);
  8843. }
  8844. /// <summary>
  8845. /// CAN协议选择
  8846. /// </summary>
  8847. /// <param name="sender"></param>
  8848. /// <param name="e"></param>
  8849. private void cANToolStripMenuItem_Click(object sender, EventArgs e)
  8850. {
  8851. cANToolStripMenuItem.Checked= true;
  8852. uARTToolStripMenuItem.Checked = false;
  8853. UART协议ToolStripMenuItem.Visible = false;
  8854. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  8855. }
  8856. /// <summary>
  8857. /// UART协议选择
  8858. /// </summary>
  8859. /// <param name="sender"></param>
  8860. /// <param name="e"></param>
  8861. private void uARTToolStripMenuItem_Click(object sender, EventArgs e)
  8862. {
  8863. cANToolStripMenuItem.Checked = false;
  8864. uARTToolStripMenuItem.Checked = true;
  8865. UART协议ToolStripMenuItem.Visible = true;
  8866. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  8867. }
  8868. /// <summary>
  8869. /// 清除流水号
  8870. /// </summary>
  8871. /// <param name="sender"></param>
  8872. /// <param name="e"></param>
  8873. private void label131_DoubleClick(object sender, EventArgs e)
  8874. {
  8875. if (MessageBox.Show("确认清零流水号?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  8876. {
  8877. label_FacModeSerial.Text = "0";
  8878. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, label_FacModeSerial.Text);
  8879. }
  8880. }
  8881. /// <summary>
  8882. /// 清除流水号
  8883. /// </summary>
  8884. /// <param name="sender"></param>
  8885. /// <param name="e"></param>
  8886. private void label135_DoubleClick(object sender, EventArgs e)
  8887. {
  8888. if (MessageBox.Show("确认清零流水号?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  8889. {
  8890. label_CheckModeSerial.Text = "0";
  8891. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, label_CheckModeSerial.Text);
  8892. }
  8893. }
  8894. /// <summary>
  8895. /// 打开自动更新
  8896. /// </summary>
  8897. /// <param name="sender"></param>
  8898. /// <param name="e"></param>
  8899. private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
  8900. {
  8901. 打开ToolStripMenuItem.Checked = true;
  8902. 关闭ToolStripMenuItem.Checked = false;
  8903. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  8904. }
  8905. /// <summary>
  8906. /// 关闭自动更新
  8907. /// </summary>
  8908. /// <param name="sender"></param>
  8909. /// <param name="e"></param>
  8910. private void 关闭ToolStripMenuItem_Click(object sender, EventArgs e)
  8911. {
  8912. 打开ToolStripMenuItem.Checked = false;
  8913. 关闭ToolStripMenuItem.Checked = true;
  8914. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  8915. }
  8916. /// <summary>
  8917. /// 显示完整配置文件
  8918. /// </summary>
  8919. /// <param name="sender"></param>
  8920. /// <param name="e"></param>
  8921. private void comboBox_FacModeCfgFile_MouseHover_1(object sender, EventArgs e)
  8922. {
  8923. // 创建the ToolTip
  8924. ToolTip toolTip1 = new ToolTip();
  8925. // 设置显示样式
  8926. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  8927. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  8928. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  8929. toolTip1.ShowAlways = true;//是否显示提示框
  8930. // 设置伴随的对象.
  8931. toolTip1.SetToolTip(this.comboBox_FacModeCfgFile, comboBox_FacModeCfgFile.Text);//设置故障内容显示
  8932. }
  8933. /// <summary>
  8934. /// 显示完整配置文件
  8935. /// </summary>
  8936. /// <param name="sender"></param>
  8937. /// <param name="e"></param>
  8938. private void comboBox_CheckModeCfgFile_MouseHover_1(object sender, EventArgs e)
  8939. {
  8940. // 创建the ToolTip
  8941. ToolTip toolTip1 = new ToolTip();
  8942. // 设置显示样式
  8943. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  8944. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  8945. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  8946. toolTip1.ShowAlways = true;//是否显示提示框
  8947. // 设置伴随的对象.
  8948. toolTip1.SetToolTip(this.comboBox_CheckModeCfgFile, comboBox_CheckModeCfgFile.Text);//设置故障内容显示
  8949. }
  8950. }
  8951. }