mainForm.cs 514 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875
  1. using NPOI.POIFS.Crypt.Dsig;
  2. using NPOI.SS.Formula.Functions;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.Diagnostics;
  7. using System.Diagnostics.Eventing.Reader;
  8. using System.Drawing;
  9. using System.IO;
  10. using System.IO.Ports;
  11. using System.Linq;
  12. using System.Reflection;
  13. using System.Runtime.InteropServices;
  14. using System.Runtime.InteropServices.ComTypes;
  15. using System.Text;
  16. using System.Text.RegularExpressions;
  17. using System.Threading;
  18. using System.Web;
  19. using System.Windows.Forms;
  20. using System.Xml.Linq;
  21. namespace Welling_Motor_Debug_Tool
  22. {
  23. public partial class mainForm : Form
  24. {
  25. #region 变量定义
  26. //版本号
  27. public static string Version = "2.5.1";
  28. //串口实例
  29. Serial_Process mySerialProcess = new Serial_Process();
  30. string PortNumSave = "";
  31. string PortBaudrateSave = "";
  32. //本地信息定义
  33. LocalInfo localInfo = new LocalInfo();
  34. //FTP实例
  35. ftp myFtp = new ftp();
  36. public string ServerIP = "";
  37. public string ServerPort = "";
  38. public string ServerUser = "";
  39. public string ServerPassWd = "";
  40. public bool OfflineFlag = false;
  41. //MC运行信息超时计数
  42. bool MC_RunInfo_Refresh = false;
  43. ushort MC_RunInfo_Refresh_Cnt = 0;
  44. //MC调试信息超时计数
  45. bool MC_DebugInfo_Refresh = false;
  46. ushort MC_DebugInfo_Refresh_Cnt = 0;
  47. //MC故障码超时计数
  48. bool MC_ErrorCode_Refresh = false;
  49. ushort MC_ErrorCode_Refresh_Cnt = 0;
  50. //配置参数实例
  51. Params myParams = new Params();
  52. //记录文件名称
  53. string RunInfoSaveFilename = "";
  54. //BMS运行信息超时计数
  55. bool BMS_RunInfo_Refresh = false;
  56. ushort BMS_RunInfo_Refresh_Cnt = 0;
  57. //生产模式关机指令反馈状态
  58. bool PowerOffAckStatus = false;
  59. //登录窗口
  60. public static Login EnterForm1 = new Login();
  61. //生产配置文件信息
  62. ArrayList array_CfgInfo = new ArrayList();
  63. //写入参数返回标志和计数
  64. public bool WriteACK = false;
  65. public ushort ACK_WaitCnt = 0;
  66. //写入参数返回提示标志
  67. public bool ACK_DisFlag = true;
  68. //Boot版本信息
  69. public string BootInfo = "";
  70. //接收指令临时缓存,转string
  71. public string CmdRevStrTemp = "";
  72. //计时器,用于统计运行时间
  73. public Stopwatch stopwatch = new Stopwatch();
  74. //力矩传感器检验参数窗口
  75. public static TorqueParams TorqueParamsForm = new TorqueParams();
  76. //参数生成窗口
  77. public static GenerateParams GenerateParamsForm = new GenerateParams();
  78. //版本信息窗口
  79. public static Version VersionForm = new Version();
  80. //本机硬件信息
  81. public string Local_HdInformation = "";
  82. //指令窗口显示
  83. public bool DebugWindowIsOpen = false, DebugDataDisplayEnable = false;
  84. //位置传感器数据记录
  85. string[] AngledataRecord = new string[42];
  86. //服务器设置窗口
  87. public static ServerSelect ServerCfgForm1 = new ServerSelect();
  88. #endregion
  89. #region 故障日志结构体定义
  90. //故障日志记录信息 60 bytes,1K空间可以保存最近16条故障记录
  91. [StructLayout(LayoutKind.Sequential)]
  92. public struct MC_ErrorLogSaveInfo_Struct_t
  93. {
  94. public UInt16 Error_Index; //故障列表索引 2 bytes, 地址偏移 0
  95. public UInt16 NotesInfo1; //备注信息1,地址偏移 2
  96. public UInt16 NotesInfo2; //备注信息2,地址偏移 4
  97. public UInt16 NotesInfo3; //备注信息3,地址偏移 6
  98. public UInt32 ErrorCode; //故障码 4 bytes, 地址偏移 8
  99. public UInt32 RunTime; //运行时间 4bytes, 地址偏移 12
  100. //电机运行信息,占用空间32bytes
  101. [StructLayout(LayoutKind.Sequential)]
  102. public struct MC_RunInfo_Struct_t
  103. {
  104. public ushort BikeSpeed; //车速 0.1km/h,地址偏移0
  105. public ushort MotorSpeed; //输出转速 1rpm,地址偏移2
  106. public ushort Power; //电功率 1W,地址偏移4
  107. public ushort BusVoltage; //母线电压 1mV,地址偏移6
  108. public ushort BusCurrent; //母线电流 1mA,地址偏移8
  109. public byte Cadence; //踏频 1rpm,地址偏移10
  110. public byte Torque; //踩踏力矩 1Nm,地址偏移11
  111. public byte CadenceDir; //踩踏方向 0-正,1-反,2-停止,地址偏移12
  112. public byte GearSt; //助力档位,地址偏移13
  113. public byte LightSwitch; //灯开关 0xF0-关,0xF1-开,地址偏移14
  114. public byte SOC; //剩余电量 1%,地址偏移15
  115. public ushort RemainDistance; //续航里程 1km,地址偏移16
  116. public ushort Torque_AD; //力矩寄存器,地址偏移18
  117. public byte PowerPerKm; //平均功耗 0.01Ah/km ,地址偏移20
  118. public byte T_PCB; //PCB温度 +40℃,地址偏移21
  119. public byte T_Coil; //绕组温度 +40℃,地址偏移22
  120. public byte T_MCU; //MCU温度 +40℃,地址偏移23
  121. public ushort Ride_Km; //开机后骑行里程 0.1km, 地址偏移24
  122. public ushort Ride_Time; //开机后骑行时间 1s,地址偏移26
  123. public UInt32 RS; //预留 4bytes
  124. };
  125. [MarshalAs(UnmanagedType.Struct)]
  126. public MC_RunInfo_Struct_t RunInfo; //运行信息 32bytes, 地址偏移 16
  127. //控制变量
  128. public Int16 IqCurrent; //Pu, 地址偏移 48
  129. public Int16 IqVoltage; //Pu, 地址偏移 50
  130. public Int16 IdCurrent; //Pu, 地址偏移 52
  131. public Int16 IdVoltage; //Pu, 地址偏移 54
  132. //状态机
  133. public UInt16 FSM; //高到低依次表示系统状态机、二层状态机、电机状态机、助力状态机, 地址偏移 56
  134. //预留
  135. public UInt16 RS1;
  136. public UInt16 RS2;
  137. public UInt16 RS3;
  138. };
  139. #endregion
  140. #region 屏幕缩放比例获取
  141. public class PrimaryScreen
  142. {
  143. #region Win32 API
  144. [DllImport("user32.dll")]
  145. static extern IntPtr GetDC(IntPtr ptr);
  146. [DllImport("gdi32.dll")]
  147. static extern int GetDeviceCaps(
  148. IntPtr hdc, // handle to DC
  149. int nIndex // index of capability
  150. );
  151. [DllImport("user32.dll", EntryPoint = "ReleaseDC")]
  152. static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDc);
  153. #endregion
  154. #region DeviceCaps常量
  155. const int HORZRES = 8;
  156. const int VERTRES = 10;
  157. const int LOGPIXELSX = 88;
  158. const int LOGPIXELSY = 90;
  159. const int DESKTOPVERTRES = 117;
  160. const int DESKTOPHORZRES = 118;
  161. #endregion
  162. #region 属性
  163. /// <summary>
  164. /// 获取屏幕分辨率当前物理大小
  165. /// </summary>
  166. public static Size WorkingArea
  167. {
  168. get
  169. {
  170. IntPtr hdc = GetDC(IntPtr.Zero);
  171. Size size = new Size();
  172. size.Width = GetDeviceCaps(hdc, HORZRES);
  173. size.Height = GetDeviceCaps(hdc, VERTRES);
  174. ReleaseDC(IntPtr.Zero, hdc);
  175. return size;
  176. }
  177. }
  178. /// <summary>
  179. /// 当前系统DPI_X 大小 一般为96
  180. /// </summary>
  181. public static int DpiX
  182. {
  183. get
  184. {
  185. IntPtr hdc = GetDC(IntPtr.Zero);
  186. int DpiX = GetDeviceCaps(hdc, LOGPIXELSX);
  187. ReleaseDC(IntPtr.Zero, hdc);
  188. return DpiX;
  189. }
  190. }
  191. /// <summary>
  192. /// 当前系统DPI_Y 大小 一般为96
  193. /// </summary>
  194. public static int DpiY
  195. {
  196. get
  197. {
  198. IntPtr hdc = GetDC(IntPtr.Zero);
  199. int DpiX = GetDeviceCaps(hdc, LOGPIXELSY);
  200. ReleaseDC(IntPtr.Zero, hdc);
  201. return DpiX;
  202. }
  203. }
  204. /// <summary>
  205. /// 获取真实设置的桌面分辨率大小
  206. /// </summary>
  207. public static Size DESKTOP
  208. {
  209. get
  210. {
  211. IntPtr hdc = GetDC(IntPtr.Zero);
  212. Size size = new Size();
  213. size.Width = GetDeviceCaps(hdc, DESKTOPHORZRES);
  214. size.Height = GetDeviceCaps(hdc, DESKTOPVERTRES);
  215. ReleaseDC(IntPtr.Zero, hdc);
  216. return size;
  217. }
  218. }
  219. /// <summary>
  220. /// 获取宽度缩放百分比
  221. /// </summary>
  222. public static float ScaleX
  223. {
  224. get
  225. {
  226. IntPtr hdc = GetDC(IntPtr.Zero);
  227. int t = GetDeviceCaps(hdc, DESKTOPHORZRES);
  228. int d = GetDeviceCaps(hdc, HORZRES);
  229. float ScaleX = (float)GetDeviceCaps(hdc, DESKTOPHORZRES) / (float)GetDeviceCaps(hdc, HORZRES);
  230. ReleaseDC(IntPtr.Zero, hdc);
  231. return ScaleX;
  232. }
  233. }
  234. /// <summary>
  235. /// 获取高度缩放百分比
  236. /// </summary>
  237. public static float ScaleY
  238. {
  239. get
  240. {
  241. IntPtr hdc = GetDC(IntPtr.Zero);
  242. float ScaleY = (float)(float)GetDeviceCaps(hdc, DESKTOPVERTRES) / (float)GetDeviceCaps(hdc, VERTRES);
  243. ReleaseDC(IntPtr.Zero, hdc);
  244. return ScaleY;
  245. }
  246. }
  247. #endregion
  248. }
  249. #endregion
  250. public static mainForm mainform1 = null;
  251. public mainForm()
  252. {
  253. InitializeComponent();
  254. mainform1 = this;
  255. System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
  256. stopwatch.Start();
  257. //端口初始化
  258. mySerialProcess.Init();
  259. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  260. //检查备忘录文件
  261. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.NoteFileName))
  262. {
  263. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.NoteFileName, "");
  264. }
  265. //检验流水号记录文件
  266. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.SerialNumFileName1))
  267. {
  268. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, "0");
  269. }
  270. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.SerialNumFileName2))
  271. {
  272. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, "0");
  273. }
  274. //检查文件夹
  275. if (!Directory.Exists(localInfo.LocalPath))
  276. {
  277. Directory.CreateDirectory(localInfo.LocalPath);
  278. }
  279. if (!Directory.Exists(localInfo.LocalDataPath))
  280. {
  281. Directory.CreateDirectory(localInfo.LocalDataPath);
  282. }
  283. if (!Directory.Exists(localInfo.ToolsPath))
  284. {
  285. Directory.CreateDirectory(localInfo.ToolsPath);
  286. }
  287. if (!Directory.Exists(localInfo.LocalPath + localInfo.CfgPathName))
  288. {
  289. Directory.CreateDirectory(localInfo.LocalPath + localInfo.CfgPathName);
  290. }
  291. //服务器初始化
  292. do
  293. {
  294. //检查是否存在配置文件
  295. if (File.Exists(localInfo.LocalPath + localInfo.ServerCfgFileName)) //存在配置文件从文件选择
  296. {
  297. //解密
  298. string sLine = aes.DecryptFromFile(localInfo.LocalPath + localInfo.ServerCfgFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  299. string[] array_CfgInfo = sLine.Split(',');
  300. //解析配置文件
  301. ServerIP = array_CfgInfo[0].ToString();
  302. ServerPort = array_CfgInfo[1].ToString();
  303. ServerUser = array_CfgInfo[2].ToString();
  304. ServerPassWd = array_CfgInfo[3].ToString();
  305. if (array_CfgInfo[4].ToString() == "True")
  306. {
  307. OfflineFlag = true;
  308. checkBox_OffLineFacMode.Checked = true;
  309. checkBox_OffLineCheckMode.Checked = true;
  310. }
  311. }
  312. else //不存在配置文件由用户选择
  313. {
  314. ServerCfgForm1.ShowDialog();
  315. switch (ServerCfgForm1.comboBox_Server.SelectedIndex)
  316. {
  317. case 0: //武汉园区
  318. case 1: //顺德工厂
  319. {
  320. ServerIP = "10.177.130.30";
  321. ServerPort = "15021";
  322. ServerUser = "factory_test";
  323. ServerPassWd = "ttium";
  324. OfflineFlag = false;
  325. checkBox_OffLineFacMode.Checked = false;
  326. checkBox_OffLineCheckMode.Checked = false;
  327. break;
  328. }
  329. case 2: //威灵园区
  330. case 3: //越南工厂
  331. case 4: //公司外部
  332. {
  333. ServerIP = "8.134.109.44";
  334. ServerPort = "21";
  335. ServerUser = "ttium";
  336. ServerPassWd = "ttium123";
  337. OfflineFlag = false;
  338. checkBox_OffLineFacMode.Checked = false;
  339. checkBox_OffLineCheckMode.Checked = false;
  340. break;
  341. }
  342. case 5: //离线使用
  343. {
  344. //输入管理员密码
  345. Scan scan_form = new Scan();
  346. scan_form.label1.Text = "请输入管理员密码";
  347. scan_form.textBox_Scan.UseSystemPasswordChar = true;
  348. scan_form.ShowDialog();
  349. if (scan_form.textBox_Scan.Text == "ttium.123")
  350. {
  351. OfflineFlag = true;
  352. checkBox_OffLineFacMode.Checked = true;
  353. checkBox_OffLineCheckMode.Checked = true;
  354. }
  355. else
  356. {
  357. MessageBox.Show("密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  358. System.Environment.Exit(0);
  359. }
  360. break;
  361. }
  362. default: //无效
  363. {
  364. System.Environment.Exit(0);
  365. break;
  366. }
  367. }
  368. //保存网络配置文件
  369. if (ServerCfgForm1.checkBox_NoticeSw.Checked)
  370. {
  371. string str = ServerIP + "," + ServerPort + "," + ServerUser + "," + ServerPassWd + "," + (OfflineFlag == true).ToString();
  372. //加密保存
  373. aes.EncryptToFile(str, localInfo.LocalPath + localInfo.ServerCfgFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  374. }
  375. }
  376. } while (false);
  377. //检查配置文件
  378. if (File.Exists(localInfo.LocalPath + localInfo.ConfigFileName)) //存在配置文件,导入配置信息
  379. {
  380. //打开文件
  381. StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.ConfigFileName);
  382. string sLine = "";
  383. ArrayList array_CfgInfo = new ArrayList();
  384. array_CfgInfo.Clear();
  385. while (sLine != null)
  386. {
  387. sLine = objReader.ReadLine();
  388. array_CfgInfo.Add(sLine);
  389. }
  390. objReader.Close();
  391. //解析配置文件
  392. try
  393. {
  394. //Port Set
  395. PortNumSave = array_CfgInfo[1].ToString().Split(':')[1];
  396. PortBaudrateSave = array_CfgInfo[2].ToString().Split(':')[1];
  397. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.IndexOf(PortNumSave);
  398. toolStripComboBox_Baudrate.SelectedIndex = toolStripComboBox_Baudrate.Items.IndexOf(PortBaudrateSave);
  399. 连接开机ToolStripMenuItem.Checked = (array_CfgInfo[3].ToString().Split(':')[1] == "True");
  400. 断开关机ToolStripMenuItem.Checked = (array_CfgInfo[4].ToString().Split(':')[1] == "True");
  401. 识别通讯盒ToolStripMenuItem.Checked = (array_CfgInfo[5].ToString().Split(':')[1] == "True");
  402. //Option
  403. 写入存储ToolStripMenuItem.Checked = (array_CfgInfo[8].ToString().Split(':')[1] == "True");
  404. //Server Set
  405. toolStripTextBox_ServerPath.Text = array_CfgInfo[11].ToString().Split(':')[1];
  406. //MacInfo
  407. toolStripTextBox_MAC.Text = array_CfgInfo[14].ToString().Split(':')[1];
  408. toolStripTextBoxMACAddr.Text = array_CfgInfo[15].ToString().Split(':')[1];
  409. toolStripTextBox_MACDate.Text = DateTime.Now.ToString("yyyyMMdd");
  410. toolStripTextBox_MACPD.Text = array_CfgInfo[17].ToString().Split(':')[1];
  411. //Log Address
  412. textBox_LogAddrBegin.Text = array_CfgInfo[20].ToString().Split(':')[1];
  413. textBox_LogAddrEnd.Text = array_CfgInfo[21].ToString().Split(':')[1];
  414. //电机类型
  415. 中置电机ToolStripMenuItem.Checked = (array_CfgInfo[24].ToString().Split(':')[1] == "True");
  416. 轮毂电机ToolStripMenuItem.Checked = !中置电机ToolStripMenuItem.Checked;
  417. //检测阈值
  418. toolStripTextBox_ThVol.Text = array_CfgInfo[28].ToString().Split(':')[1];
  419. toolStripTextBox_ThCur.Text = array_CfgInfo[29].ToString().Split(':')[1];
  420. toolStripTextBox_ThSpeed.Text = array_CfgInfo[30].ToString().Split(':')[1];
  421. toolStripTextBox_ThTor.Text = array_CfgInfo[31].ToString().Split(':')[1];
  422. toolStripTextBox_ThCad.Text = array_CfgInfo[32].ToString().Split(':')[1];
  423. toolStripTextBox_ThBikeSpeed.Text = array_CfgInfo[33].ToString().Split(':')[1];
  424. toolStripTextBox_ThT_PCB.Text = array_CfgInfo[34].ToString().Split(':')[1];
  425. toolStripTextBox_ThT_MCU.Text = array_CfgInfo[35].ToString().Split(':')[1];
  426. toolStripTextBox_ThT_Motor.Text = array_CfgInfo[36].ToString().Split(':')[1];
  427. //MOS内阻校准系数
  428. toolStripTextBox_MosCalK.Text = array_CfgInfo[39].ToString().Split(':')[1];
  429. toolStripTextBox_MOS1.Text= array_CfgInfo[40].ToString().Split(':')[1];
  430. toolStripTextBox_MOS2.Text = array_CfgInfo[41].ToString().Split(':')[1];
  431. toolStripTextBox_MOS3.Text = array_CfgInfo[42].ToString().Split(':')[1];
  432. //通信协议类型
  433. cANToolStripMenuItem.Checked = (array_CfgInfo[45].ToString().Split(':')[1] == "True");
  434. uARTToolStripMenuItem.Checked = !cANToolStripMenuItem.Checked;
  435. //自动更新开关
  436. 打开ToolStripMenuItem.Checked = (array_CfgInfo[49].ToString().Split(':')[1] == "True");
  437. 关闭ToolStripMenuItem.Checked = !打开ToolStripMenuItem.Checked;
  438. //位置校准偏差
  439. textBox_AngleDiffTh.Text = array_CfgInfo[52].ToString().Split(':')[1];
  440. toolStripTextBox_AngleAvgMax.Text = textBox_AngleDiffTh.Text;
  441. textBox_AngleZeroTh.Text = array_CfgInfo[53].ToString().Split(':')[1];
  442. toolStripTextBox_AngleZeroMax.Text = textBox_AngleZeroTh.Text;
  443. }
  444. catch (System.Exception)
  445. {
  446. timer_500ms.Enabled = false;
  447. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  448. timer_500ms.Enabled = true;
  449. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  450. }
  451. }
  452. else //不存在配置文件,生成文件写入默认值
  453. {
  454. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  455. }
  456. //解析本地流水号记录
  457. do
  458. {
  459. //测试模式
  460. label_FacModeSerial.Text = File.ReadAllText(localInfo.LocalPath + localInfo.SerialNumFileName1);
  461. //检验模式
  462. label_CheckModeSerial.Text = File.ReadAllText(localInfo.LocalPath + localInfo.SerialNumFileName2);
  463. } while (false);
  464. //获取本机信息,读取时间较长,优先从本地文件获取
  465. do
  466. {
  467. try
  468. {
  469. //本地文件为空,读取信息保存
  470. if (!File.Exists(localInfo.LocalPath + localInfo.PC_InfoFileName))
  471. {
  472. Local_HdInformation = "";
  473. Local_HdInformation += "计算机名称: " + System.Environment.UserName + "\r\n";
  474. Local_HdInformation += "IP地址: " + PC_Information.GetIpAddress() + "\r\n";
  475. Local_HdInformation += "系统ID: " + PC_Information.GetSystemID() + "\r\n";
  476. Local_HdInformation += "操作系统类型: " + PC_Information.GetSystemType() + "\r\n";
  477. Local_HdInformation += "主板型号: " + PC_Information.GetBoardType() + "\r\n";
  478. Local_HdInformation += "主板厂商: " + PC_Information.GetBoardManufacturer() + "\r\n";
  479. Local_HdInformation += "主板ID: " + PC_Information.GetBIOSSerialNumber() + "\r\n";
  480. Local_HdInformation += "CPU型号: " + PC_Information.GetCpuName() + "\r\n";
  481. Local_HdInformation += "CPU厂商: " + PC_Information.GetCpuManufacturer() + "\r\n";
  482. Local_HdInformation += "CPU ID: " + PC_Information.GetCPUSerialNumber() + "\r\n";
  483. Local_HdInformation += "内存容量: " + PC_Information.GetPhysicalMemory() + " GB" + "\r\n";
  484. Local_HdInformation += "MAC ID: " + PC_Information.GetNetCardMACAddress().Replace(":", "-") + "\r\n";
  485. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.PC_InfoFileName, Local_HdInformation);
  486. }
  487. //从本地读取,计算机名和IP地址重新读
  488. else
  489. {
  490. Local_HdInformation = "";
  491. string[] fileInfo = File.ReadAllLines(localInfo.LocalPath + localInfo.PC_InfoFileName, Encoding.UTF8);
  492. fileInfo[0] = "计算机名称: " + System.Environment.UserName;
  493. fileInfo[1] = "IP地址: " + PC_Information.GetIpAddress();
  494. for (int i = 0; i < fileInfo.Length; i++)
  495. Local_HdInformation += fileInfo[i] + "\r\n";
  496. File.Delete(localInfo.LocalPath + localInfo.PC_InfoFileName);
  497. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.PC_InfoFileName, Local_HdInformation);
  498. }
  499. }
  500. catch(Exception)
  501. {
  502. }
  503. } while (false);
  504. //系统登录
  505. do
  506. {
  507. EnterForm1.ShowDialog();
  508. try
  509. {
  510. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  511. {
  512. if (EnterForm1.comboBox_User.Text.Contains("量产"))
  513. {
  514. //隐藏设置项
  515. 其它配置项ToolStripMenuItem.Visible = false;
  516. 写入存储ToolStripMenuItem.Visible = false;
  517. 服务器配置ToolStripMenuItem.Visible = false;
  518. 判断阈值ToolStripMenuItem.Visible = false;
  519. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  520. mOS内阻范围ToolStripMenuItem.Visible = false;
  521. 力矩传感器检验ToolStripMenuItem.Visible = false;
  522. 位置校准偏差范围ToolStripMenuItem.Visible = false;
  523. //显示生产信息
  524. 生产信息ToolStripMenuItem.Visible = true;
  525. //显示电机类型,但不可编辑
  526. 电机类型ToolStripMenuItem.Visible = true;
  527. 中置电机ToolStripMenuItem.Enabled = false;
  528. 轮毂电机ToolStripMenuItem.Enabled = false;
  529. if (uARTToolStripMenuItem.Checked)
  530. UART协议ToolStripMenuItem.Visible = true;
  531. //隐藏研发调试界面
  532. tabPage_MotorParam.Parent = null;
  533. tabPage_BikeParam.Parent = null;
  534. tabPage_BikeParam2.Parent = null;
  535. tabPage_ControlParam.Parent = null;
  536. tabPage_SensorParam.Parent = null;
  537. tabPage_AssistParam.Parent = null;
  538. tabPage_UsrRideParam.Parent = null;
  539. tabPage_DebugParam.Parent = null;
  540. tabPage_RecordInfo.Parent = null;
  541. tabPage_OtherInfo.Parent = null;
  542. tabPage_OBC.Parent = null;
  543. tabPage_RAMorFLASH.Parent = null;
  544. tabPage_FactoryMode.Parent = null;
  545. tabPage_DebugInfo.Parent = null;
  546. tabPage_AngleCal.Parent = null;
  547. tabPage_FuncSet.Parent = null;
  548. //显示运行信息
  549. tabPage_RunInfo.Parent = tabControl2;
  550. //根据电机类型修改生产信息和电机类型
  551. if (EnterForm1.comboBox_User.Text.Contains("中置"))
  552. {
  553. 中置电机ToolStripMenuItem.Checked = true;
  554. 轮毂电机ToolStripMenuItem.Checked = false;
  555. toolStripTextBox_MACPD.Text = "MM_MC1";
  556. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  557. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  558. }
  559. else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
  560. {
  561. 中置电机ToolStripMenuItem.Checked = false;
  562. 轮毂电机ToolStripMenuItem.Checked = true;
  563. toolStripTextBox_MACPD.Text = "GF_250_1";
  564. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  565. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  566. }
  567. //显示对应生产测试界面
  568. if (EnterForm1.comboBox_User.Text.Contains("写入"))
  569. {
  570. tabPage_ProductMode_Write.Parent = tabControl1;
  571. tabPage_ProductMode_Write.Select();
  572. tabPage_ProductMode_Read.Parent = null;
  573. }
  574. else if (EnterForm1.comboBox_User.Text.Contains("检验"))
  575. {
  576. tabPage_ProductMode_Read.Parent = tabControl1;
  577. tabPage_ProductMode_Read.Select();
  578. tabPage_ProductMode_Write.Parent = null;
  579. }
  580. //应答指令不提示
  581. ACK_DisFlag = false;
  582. //退出登录
  583. break;
  584. }
  585. else if (EnterForm1.comboBox_User.Text == "工程参数配置")
  586. {
  587. //隐藏工作台内容,新建窗口完成配置
  588. groupBox1.Visible = false;
  589. groupBox3.Visible = false;
  590. tabControl2.Visible = false;
  591. //隐藏提示信息
  592. label_StarInfo.Visible = false;
  593. //打开参数配置框
  594. GenerateParamsForm.ShowDialog();
  595. System.Environment.Exit(0);
  596. //退出登录
  597. break;
  598. }
  599. else if (EnterForm1.comboBox_User.Text.Contains("样机"))
  600. {
  601. //隐藏量产界面
  602. tabPage_ProductMode_Read.Parent = null;
  603. tabPage_ProductMode_Write.Parent = null;
  604. //隐藏配置项
  605. 其它配置项ToolStripMenuItem.Visible = false;
  606. 服务器配置ToolStripMenuItem.Visible = false;
  607. 判断阈值ToolStripMenuItem.Visible = false;
  608. 力矩传感器检验ToolStripMenuItem.Visible = false;
  609. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  610. mOS内阻范围ToolStripMenuItem.Visible = false;
  611. 位置校准偏差范围ToolStripMenuItem.Visible = false;
  612. //显示生产信息
  613. 生产信息ToolStripMenuItem.Visible = true;
  614. //显示电机类型,但不可编辑
  615. 电机类型ToolStripMenuItem.Visible = true;
  616. 中置电机ToolStripMenuItem.Enabled = true;
  617. 轮毂电机ToolStripMenuItem.Enabled = true;
  618. if (uARTToolStripMenuItem.Checked)
  619. UART协议ToolStripMenuItem.Visible = true;
  620. if (EnterForm1.comboBox_User.Text.Contains("中置"))
  621. {
  622. 中置电机ToolStripMenuItem.Checked = true;
  623. 轮毂电机ToolStripMenuItem.Checked = false;
  624. toolStripTextBox_MACPD.Text = "MM_MC1";
  625. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  626. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  627. }
  628. else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
  629. {
  630. 中置电机ToolStripMenuItem.Checked = false;
  631. 轮毂电机ToolStripMenuItem.Checked = true;
  632. toolStripTextBox_MACPD.Text = "GF_250_1";
  633. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  634. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  635. }
  636. //退出登录
  637. break;
  638. }
  639. else if (EnterForm1.comboBox_User.Text == "FCT治具测试")
  640. {
  641. //隐藏设置项
  642. 其它配置项ToolStripMenuItem.Visible = false;
  643. 写入存储ToolStripMenuItem.Visible = false;
  644. 服务器配置ToolStripMenuItem.Visible = false;
  645. 判断阈值ToolStripMenuItem.Visible = false;
  646. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  647. mOS内阻范围ToolStripMenuItem.Visible = false;
  648. 力矩传感器检验ToolStripMenuItem.Visible = false;
  649. 位置校准偏差范围ToolStripMenuItem.Visible = false;
  650. //显示生产信息
  651. 生产信息ToolStripMenuItem.Visible = true;
  652. //显示电机类型,但不可编辑
  653. 电机类型ToolStripMenuItem.Visible = false;
  654. 中置电机ToolStripMenuItem.Enabled = false;
  655. 轮毂电机ToolStripMenuItem.Enabled = false;
  656. if (uARTToolStripMenuItem.Checked)
  657. UART协议ToolStripMenuItem.Visible = true;
  658. //隐藏研发调试界面
  659. tabPage_MotorParam.Parent = null;
  660. tabPage_BikeParam.Parent = null;
  661. tabPage_BikeParam2.Parent = null;
  662. tabPage_ControlParam.Parent = null;
  663. tabPage_SensorParam.Parent = null;
  664. tabPage_AssistParam.Parent = null;
  665. tabPage_UsrRideParam.Parent = null;
  666. tabPage_DebugParam.Parent = null;
  667. tabPage_RecordInfo.Parent = null;
  668. tabPage_OtherInfo.Parent = null;
  669. tabPage_OBC.Parent = null;
  670. tabPage_RAMorFLASH.Parent = null;
  671. tabPage_FactoryMode.Parent = null;
  672. tabPage_DebugInfo.Parent = null;
  673. tabPage_AngleCal.Parent = null;
  674. tabPage_FuncSet.Parent = null;
  675. //显示运行信息
  676. tabPage_RunInfo.Parent = tabControl2;
  677. //目前仅轮毂使用
  678. 中置电机ToolStripMenuItem.Checked = false;
  679. 轮毂电机ToolStripMenuItem.Checked = true;
  680. toolStripTextBox_MACPD.Text = "GF_250_1";
  681. toolStripTextBox_ServerPath.Text = "HUB_Control_FCT";
  682. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  683. //显示量产测试界面
  684. tabPage_ProductMode_Write.Parent = tabControl1;
  685. tabPage_ProductMode_Write.Select();
  686. tabPage_ProductMode_Read.Parent = null;
  687. checkBox_OffLineFacMode.Checked = false;
  688. checkBox_OffLineFacMode.Enabled = true;
  689. checkBox_OffLineCheckMode.Checked = false;
  690. checkBox_OffLineCheckMode.Enabled = true;
  691. //应答指令不提示
  692. ACK_DisFlag = false;
  693. //退出登录
  694. break;
  695. }
  696. else if (EnterForm1.comboBox_User.Text == "研发调试")
  697. {
  698. //隐藏量产界面
  699. tabPage_ProductMode_Read.Parent = null;
  700. tabPage_ProductMode_Write.Parent = null;
  701. 服务器配置ToolStripMenuItem.Visible = false;
  702. if (uARTToolStripMenuItem.Checked)
  703. UART协议ToolStripMenuItem.Visible = true;
  704. //退出登录
  705. break;
  706. }
  707. else if (EnterForm1.comboBox_User.Text == "管理员")
  708. {
  709. //不隐藏任何界面
  710. //...
  711. //退出登录
  712. break;
  713. }
  714. else
  715. {
  716. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  717. //重新登录
  718. continue;
  719. }
  720. }
  721. else
  722. {
  723. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  724. //重新登录
  725. continue;
  726. }
  727. }
  728. catch (Exception)
  729. {
  730. System.Environment.Exit(0);
  731. }
  732. } while (true);
  733. //配置网络FTP服务器
  734. myFtp.FtpOption(ServerIP, ServerPort, ServerUser, ServerPassWd, "admin", "ttium_admin");
  735. //创建线程,定时检测网络连接状态
  736. Thread th = new Thread(NetworkCheck);
  737. th.IsBackground = true;
  738. th.Start();
  739. //允许跨线程访问
  740. Control.CheckForIllegalCrossThreadCalls = false;
  741. }
  742. /// <summary>
  743. /// 检查网络状态线程
  744. /// </summary>
  745. private void NetworkCheck()
  746. {
  747. //允许离线使用,直接退出
  748. if (OfflineFlag == true) //允许离线使用
  749. {
  750. MessageBoxTimeOut.Show("离线使用,不检测网络状态!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  751. return;
  752. }
  753. //不允许离线使用,实时监测网络状态
  754. else
  755. {
  756. //初始化第一次连接FTP服务器
  757. bool Result = myFtp.CheckFtp();
  758. if (Result == true)//服务器连接成功
  759. {
  760. myFtp.IsNetConnected = true;
  761. //上传登录日志
  762. do
  763. {
  764. //日志文件名
  765. string date = DateTime.Now.ToString("yyyy-MM-dd_HHmmss_fff");
  766. string fileName = date;
  767. //日志内容
  768. string fileInfo = Local_HdInformation;
  769. //保存本地
  770. if (!Directory.Exists(localInfo.LocalLogPath))
  771. Directory.CreateDirectory(localInfo.LocalLogPath);
  772. System.IO.File.WriteAllText(localInfo.LocalLogPath + fileName, fileInfo);
  773. //上传服务器
  774. myFtp.UploadFile(localInfo.LocalLogPath + fileName, "/Tools/Welling_Motor_Debug_Tool/log");
  775. } while (false);
  776. }
  777. else//服务器连接失败
  778. {
  779. myFtp.IsNetConnected = false;
  780. if (EnterForm1.comboBox_User.Text != "管理员")
  781. {
  782. MessageBoxTimeOut.Show("网络断开,将自动关闭!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  783. this.Close();
  784. }
  785. }
  786. //创建定时器,定时30s检查网络
  787. System.Timers.Timer timer_CheckNet = new System.Timers.Timer();
  788. timer_CheckNet.Enabled = true;
  789. timer_CheckNet.Interval = 30000;
  790. timer_CheckNet.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_CheckNet_Tick);
  791. timer_CheckNet.Start();
  792. while (true)
  793. {
  794. Thread.Sleep(1);
  795. if (myFtp.IsNetConnected == false)
  796. {
  797. label_Server_ComStatus.Text = "网络已断开";
  798. label_ServerStatus.BackColor = Color.Red;
  799. }
  800. else
  801. {
  802. label_Server_ComStatus.Text = "网络已连接";
  803. label_ServerStatus.BackColor = Color.Green;
  804. }
  805. }
  806. }
  807. }
  808. /// <summary>
  809. /// 线程中定时任务,检查网络状态
  810. /// </summary>
  811. /// <param name="sender"></param>
  812. /// <param name="e"></param>
  813. private void timer_CheckNet_Tick(object sender, EventArgs e)
  814. {
  815. //连接FTP服务器
  816. bool Result = myFtp.CheckFtp();
  817. if (Result == true)//服务器连接成功
  818. {
  819. myFtp.IsNetConnected = true;
  820. //允许使用
  821. groupBox1.Enabled = true;
  822. groupBox3.Enabled = true;
  823. tabControl2.Enabled = true;
  824. }
  825. else//服务器连接失败
  826. {
  827. myFtp.IsNetConnected = false;
  828. if (EnterForm1.comboBox_User.Text != "管理员")
  829. {
  830. MessageBoxTimeOut.Show("网络断开, 请检查网络!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Warning); //提示框自动3s关闭
  831. //禁止使用
  832. groupBox1.Enabled = false;
  833. groupBox3.Enabled = false;
  834. tabControl2.Enabled = false;
  835. }
  836. }
  837. }
  838. #region 非独占性延时函数
  839. public static void Delay_ms(int milliSecond)
  840. {
  841. int start = Environment.TickCount;
  842. while (Math.Abs(Environment.TickCount - start) < milliSecond)//毫秒
  843. {
  844. Application.DoEvents();
  845. }
  846. }
  847. #endregion
  848. private void MainForm_Load(object sender, System.EventArgs e)
  849. {
  850. timer_500ms.Start();
  851. //页面初始化
  852. label_BuildTime.Text = "编译时间:" + System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString("yyyy-MM-dd HH:mm:ss");
  853. label_Computername.Text = System.Environment.UserName;
  854. label_UserName.Text = EnterForm1.comboBox_User.Text;
  855. //位置校准表格初始化
  856. for (int i = 0; i < 7; i++)
  857. {
  858. int index = dataGridView_AngleCal.Rows.Add();
  859. dataGridView_AngleCal.Rows[index].Cells[0].Value = i + 1;
  860. }
  861. dataGridView_AngleCal.AllowUserToAddRows = false;
  862. //拓展功能表格初始化
  863. for (int i = 0; i < 8; i++)
  864. {
  865. int index = dataGridView_FunSet.Rows.Add();
  866. dataGridView_FunSet.Rows[index].Cells[0].Value = "#" + (i + 1).ToString();
  867. }
  868. dataGridView_FunSet.AllowUserToAddRows = false;
  869. //窗体显示版本
  870. this.Text += Version;
  871. //检查版本,自动更新
  872. do
  873. {
  874. if ((打开ToolStripMenuItem.Checked == false) || OfflineFlag == true)//关闭自动更新或离线时
  875. {
  876. break;
  877. }
  878. //检查网络状态
  879. if (myFtp.CheckFtp() == false)
  880. {
  881. MessageBoxTimeOut.Show("网络断开,自动更新失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  882. break;
  883. }
  884. else
  885. {
  886. //检查本地文件删除
  887. if (System.IO.File.Exists(localInfo.LocalPath + "\\Version"))
  888. System.IO.File.Delete(localInfo.LocalPath + "\\Version");
  889. //读取最新版本号
  890. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/Version", localInfo.LocalPath);
  891. StreamReader objReader = new StreamReader(localInfo.LocalPath + "\\Version");
  892. string sLine = "";
  893. ArrayList arrText = new ArrayList();//创建一个动态数组
  894. while (sLine != null)
  895. {
  896. sLine = objReader.ReadLine();
  897. arrText.Add(sLine);
  898. }
  899. objReader.Close();
  900. System.IO.File.Delete(localInfo.LocalPath + "\\Version");
  901. //检查是否有最新版本
  902. string[] VerOld = mainForm.Version.Trim().Split('.');
  903. string[] VerNew = arrText[0].ToString().Trim().Split('.');
  904. int VerOld_int = Convert.ToInt32(VerOld[0]) * 10000 + Convert.ToInt32(VerOld[1].PadLeft(2, '0')) * 100 + Convert.ToInt32(VerOld[2].PadLeft(2, '0'));
  905. int VerNew_int = Convert.ToInt32(VerNew[0]) * 10000 + Convert.ToInt32(VerNew[1].PadLeft(2, '0')) * 100 + Convert.ToInt32(VerNew[2].PadLeft(2, '0'));
  906. if (VerNew_int <= VerOld_int)
  907. {
  908. //版本已是最新,跳出
  909. break;
  910. }
  911. //确认下载最新版本
  912. if (MessageBox.Show("是否更新新版本?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  913. {
  914. string SavePath = Directory.GetCurrentDirectory();
  915. string[] FileList = myFtp.GetFileNameList("/Tools/Welling_Motor_Debug_Tool");
  916. foreach (string file in FileList)
  917. {
  918. if (file.Contains(".exe"))
  919. {
  920. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/" + file, SavePath);
  921. MessageBox.Show("新版本下载完成,请手动删除旧版本!\r\n最新版本:" + file, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  922. System.Environment.Exit(0);
  923. }
  924. }
  925. }
  926. }
  927. } while (false);
  928. //下拉控件初始值设定
  929. comboBox_WorkMode.SelectedIndex = 0;
  930. comboBox_GearSt.SelectedIndex = 0;
  931. comboBox_LightSwitch.SelectedIndex = 1;
  932. comboBox_OBC_SetGearST.SelectedIndex = 0;
  933. comboBox_OBC_LightSw.SelectedIndex = 1;
  934. comboBox_AssistTorque.SelectedIndex = 0;
  935. comboBox_AssistCadence.SelectedIndex = 0;
  936. //combobox事件定义
  937. this.comboBox_WorkMode.SelectedIndexChanged += new System.EventHandler(this.comboBox_WorkMode_SelectedIndexChanged);
  938. this.comboBox_GearSt.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  939. this.comboBox_LightSwitch.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  940. this.comboBox_OBC_SetGearST.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  941. this.comboBox_OBC_LightSw.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  942. //端口自动连接
  943. if ((PortNumSave != string.Empty) && (PortBaudrateSave != string.Empty)) //有数值时采用上次使用的值
  944. {
  945. try
  946. {
  947. PortConnect();
  948. }
  949. catch (System.Exception)
  950. {
  951. timer_500ms.Enabled = false;
  952. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  953. timer_500ms.Enabled = true;
  954. }
  955. }
  956. //不识别联动装置盒自动打开界面
  957. #if true
  958. groupBox1.Visible = true;
  959. groupBox3.Visible = true;
  960. tabControl2.Visible = true;
  961. label_StarInfo.Visible = false;
  962. #endif
  963. //创建线程,定时解析数据
  964. Thread th = new Thread(Task_SerialProcess);
  965. th.IsBackground = true;
  966. th.Start();
  967. }
  968. #region 结构体与字节流相互转换
  969. public static class MyConverter
  970. {
  971. /// <summary>
  972. /// 由结构体转换为byte数组
  973. /// </summary>
  974. public static byte[] StructureToByte<T>(T structure)
  975. {
  976. int size = Marshal.SizeOf(typeof(T));
  977. byte[] buffer = new byte[size];
  978. IntPtr bufferIntPtr = Marshal.AllocHGlobal(size);
  979. try
  980. {
  981. Marshal.StructureToPtr(structure, bufferIntPtr, true);
  982. Marshal.Copy(bufferIntPtr, buffer, 0, size);
  983. }
  984. finally
  985. {
  986. Marshal.FreeHGlobal(bufferIntPtr);
  987. }
  988. return buffer;
  989. }
  990. /// <summary>
  991. /// 由byte数组转换为结构体
  992. /// </summary>
  993. public static T ByteToStructure<T>(byte[] dataBuffer, ushort StarIndex)
  994. {
  995. object structure = null;
  996. int size = Marshal.SizeOf(typeof(T));
  997. IntPtr allocIntPtr = Marshal.AllocHGlobal(size);
  998. try
  999. {
  1000. Marshal.Copy(dataBuffer, StarIndex, allocIntPtr, size);
  1001. structure = Marshal.PtrToStructure(allocIntPtr, typeof(T));
  1002. }
  1003. finally
  1004. {
  1005. Marshal.FreeHGlobal(allocIntPtr);
  1006. }
  1007. return (T)structure;
  1008. }
  1009. }
  1010. #endregion
  1011. #region 故障日志解析显示
  1012. private void ErrorLogDisplay(MC_ErrorLogSaveInfo_Struct_t Log1, MC_ErrorLogSaveInfo_Struct_t Log2)
  1013. {
  1014. string SaveData = "";
  1015. //Log1
  1016. if (Log1.Error_Index != 0xFFFF)
  1017. {
  1018. SaveData += "故障序号:" + Convert.ToString(Log1.Error_Index) + ", ";
  1019. SaveData += "备注1:" + Convert.ToString(Log1.NotesInfo1) + ", ";
  1020. SaveData += "备注2:" + Convert.ToString(Log1.NotesInfo2) + ", ";
  1021. SaveData += "备注3:" + Convert.ToString(Log1.NotesInfo3) + ", ";
  1022. SaveData += "故障码:" + "0x" + Convert.ToString(Log1.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  1023. SaveData += "运行时间:" + Convert.ToString(Log1.RunTime) + "min" + ", ";
  1024. SaveData += "车速:" + ((float)Log1.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  1025. SaveData += "电机转速:" + Convert.ToString(Log1.RunInfo.MotorSpeed) + "rpm" + ", ";
  1026. SaveData += "功率:" + Convert.ToString(Log1.RunInfo.Power * 2) + "w" + ", ";
  1027. SaveData += "电压:" + Convert.ToString(Log1.RunInfo.BusVoltage) + "mV" + ", ";
  1028. SaveData += "电流:" + Convert.ToString(Log1.RunInfo.BusCurrent) + "mA" + ", ";
  1029. SaveData += "踏频:" + Convert.ToString(Log1.RunInfo.Cadence) + "rpm" + ", ";
  1030. SaveData += "力矩:" + Convert.ToString(Log1.RunInfo.Torque) + "N.m" + ", ";
  1031. SaveData += "方向:" + ((Log1.RunInfo.CadenceDir == 0) ? "正" : ((Log1.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  1032. SaveData += "档位:" + "0x" + Convert.ToString(Log1.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  1033. SaveData += "灯开关:" + ((Log1.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  1034. SaveData += "电量:" + Convert.ToString(Log1.RunInfo.SOC) + "%" + ", ";
  1035. if ((Log1.RunInfo.RemainDistance == 0xEEEE) || (Log1.RunInfo.RemainDistance == 0xFFFF))
  1036. {
  1037. SaveData += "续航:" + "---km" + ", ";
  1038. }
  1039. else
  1040. {
  1041. SaveData += "续航:" + Convert.ToString(Log1.RunInfo.RemainDistance) + "km" + ", ";
  1042. }
  1043. SaveData += "力矩AD:" + Convert.ToString(Log1.RunInfo.Torque_AD) + ", ";
  1044. SaveData += "功耗:" + Convert.ToString(Log1.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  1045. SaveData += "PCB温度:" + Convert.ToString((int)(Log1.RunInfo.T_PCB - 40)) + "℃" + ", ";
  1046. SaveData += "绕组温度:" + Convert.ToString((int)(Log1.RunInfo.T_Coil - 40)) + "℃" + ", ";
  1047. SaveData += "MCU温度:" + Convert.ToString((int)(Log1.RunInfo.T_MCU - 40)) + "℃" + ", ";
  1048. SaveData += "单次里程:" + Convert.ToString((float)Log1.RunInfo.Ride_Km / 10f) + "km" + ", ";
  1049. SaveData += "单次时间:" + Convert.ToString(Log1.RunInfo.Ride_Time) + "s" + ", ";
  1050. SaveData += "q轴电流:" + Convert.ToString(Log1.IqCurrent) + ", ";
  1051. SaveData += "q轴电压:" + Convert.ToString(Log1.IqVoltage) + ", ";
  1052. SaveData += "d轴电流:" + Convert.ToString(Log1.IdCurrent) + ", ";
  1053. SaveData += "d轴电压:" + Convert.ToString(Log1.IdVoltage) + ", ";
  1054. SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
  1055. SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
  1056. SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
  1057. SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
  1058. SaveData += "\r\n\r\n";
  1059. richTextBox_Record.AppendText(SaveData);
  1060. SaveData = "";
  1061. }
  1062. //Log2
  1063. if (Log2.Error_Index != 0xFFFF)
  1064. {
  1065. SaveData += "故障序号:" + Convert.ToString(Log2.Error_Index) + ", ";
  1066. SaveData += "备注1:" + Convert.ToString(Log2.NotesInfo1) + ", ";
  1067. SaveData += "备注2:" + Convert.ToString(Log2.NotesInfo2) + ", ";
  1068. SaveData += "备注3:" + Convert.ToString(Log2.NotesInfo3) + ", ";
  1069. SaveData += "故障码:" + "0x" + Convert.ToString(Log2.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  1070. SaveData += "运行时间:" + Convert.ToString(Log2.RunTime) + "min" + ", ";
  1071. SaveData += "车速:" + ((float)Log2.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  1072. SaveData += "电机转速:" + Convert.ToString(Log2.RunInfo.MotorSpeed) + "rpm" + ", ";
  1073. SaveData += "功率:" + Convert.ToString(Log2.RunInfo.Power * 2) + "w" + ", ";
  1074. SaveData += "电压:" + Convert.ToString(Log2.RunInfo.BusVoltage) + "mV" + ", ";
  1075. SaveData += "电流:" + Convert.ToString(Log2.RunInfo.BusCurrent) + "mA" + ", ";
  1076. SaveData += "踏频:" + Convert.ToString(Log2.RunInfo.Cadence) + "rpm" + ", ";
  1077. SaveData += "力矩:" + Convert.ToString(Log2.RunInfo.Torque) + "N.m" + ", ";
  1078. SaveData += "方向:" + ((Log2.RunInfo.CadenceDir == 0) ? "正" : ((Log2.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  1079. SaveData += "档位:" + "0x" + Convert.ToString(Log2.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  1080. SaveData += "灯开关:" + ((Log2.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  1081. SaveData += "电量:" + Convert.ToString(Log2.RunInfo.SOC) + "%" + ", ";
  1082. if ((Log2.RunInfo.RemainDistance == 0xEEEE) || (Log2.RunInfo.RemainDistance == 0xFFFF))
  1083. {
  1084. SaveData += "续航:" + "---km" + ", ";
  1085. }
  1086. else
  1087. {
  1088. SaveData += "续航:" + Convert.ToString(Log2.RunInfo.RemainDistance) + "km" + ", ";
  1089. }
  1090. SaveData += "力矩AD:" + Convert.ToString(Log2.RunInfo.Torque_AD) + ", ";
  1091. SaveData += "功耗:" + Convert.ToString(Log2.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  1092. SaveData += "PCB温度:" + Convert.ToString((int)(Log2.RunInfo.T_PCB - 40)) + "DegreeC" + ", ";
  1093. SaveData += "绕组温度:" + Convert.ToString((int)(Log2.RunInfo.T_Coil - 40)) + "DegreeC" + ", ";
  1094. SaveData += "MCU温度:" + Convert.ToString((int)(Log2.RunInfo.T_MCU - 40)) + "DegreeC" + ", ";
  1095. SaveData += "单次里程:" + Convert.ToString((float)Log2.RunInfo.Ride_Km / 10f) + "km" + ", ";
  1096. SaveData += "单次时间:" + Convert.ToString(Log2.RunInfo.Ride_Time) + "s" + ", ";
  1097. SaveData += "q轴电流:" + Convert.ToString(Log2.IqCurrent) + ", ";
  1098. SaveData += "q轴电压:" + Convert.ToString(Log2.IqVoltage) + ", ";
  1099. SaveData += "d轴电流:" + Convert.ToString(Log2.IdCurrent) + ", ";
  1100. SaveData += "d轴电压:" + Convert.ToString(Log2.IdVoltage) + ", ";
  1101. SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
  1102. SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
  1103. SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
  1104. SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
  1105. SaveData += "\r\n\r\n";
  1106. richTextBox_Record.AppendText(SaveData);
  1107. SaveData = "";
  1108. }
  1109. }
  1110. #endregion
  1111. #region 串口数据解析线程
  1112. /// <summary>
  1113. /// 串口数据解析线程
  1114. /// </summary>
  1115. private void Task_SerialProcess()
  1116. {
  1117. //创建定时器,定时读取串口数据
  1118. System.Timers.Timer timer_ReadSerial = new System.Timers.Timer();
  1119. timer_ReadSerial.Enabled = true;
  1120. timer_ReadSerial.Interval = 20;
  1121. timer_ReadSerial.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_ReadSerial_Tick);
  1122. timer_ReadSerial.Start();
  1123. while (true)
  1124. {
  1125. Thread.Sleep(1);
  1126. };
  1127. }
  1128. /// <summary>
  1129. /// 串口解析定时器
  1130. /// </summary>
  1131. /// <param name="sender"></param>
  1132. /// <param name="e"></param>
  1133. private void timer_ReadSerial_Tick(object sender, EventArgs e)
  1134. {
  1135. //串口解析
  1136. Serial_process(mySerialProcess.buffer);
  1137. }
  1138. #endregion
  1139. #region 数据解析
  1140. public void Serial_process(List<byte> buffer)
  1141. {
  1142. byte DataNum = 0; //记录每条命令数据段的长度
  1143. ushort PackageID, Cmd;
  1144. byte[] Data = new byte[1024];
  1145. try
  1146. {
  1147. while (buffer.Count >= 13)//当buffer中的数据的个数大于等于4个时,即每一帧的数据长度所在位(第4位)出现时
  1148. {
  1149. if (buffer[0] == 0x55 && buffer[1] == 0xAA)//判断帧头
  1150. {
  1151. PackageID = (ushort)(buffer[2] * 256 + buffer[3]);
  1152. if ((PackageID == 0x0710) || (PackageID == 0x0715) || (PackageID == 0x07FF) || (PackageID == 0x0720) || (PackageID == 0x0713))
  1153. {
  1154. int CmdLen = buffer[5];
  1155. if (buffer.Count < CmdLen + 11) break;//如果接收到的数据没有达到一帧数据的指定长度, 则执行下次循环
  1156. while (CmdLen > 0) //读取命令段
  1157. {
  1158. Cmd = (ushort)(buffer[6] * 256 + buffer[7]);
  1159. DataNum = (byte)(buffer[7]);//命令字的第二个字节的表示数据位的长度
  1160. if (DataNum <= (CmdLen - 2))
  1161. {
  1162. for (int i = 0; i < DataNum; i++)
  1163. {
  1164. Data[i] = buffer[i + 8];
  1165. }
  1166. // 串口接收的数据 显示在子窗口
  1167. if (this.DebugWindowIsOpen && this.DebugDataDisplayEnable)
  1168. {
  1169. string strTemp = String.Empty;
  1170. strTemp += System.DateTimeOffset.Now.ToString("HH:mm:ss.fff") + " <-- ";
  1171. for (int i = 0; i < CmdLen + 11; i++)
  1172. {
  1173. strTemp += (buffer[i].ToString("X2") + " ");
  1174. }
  1175. strTemp += "\n";
  1176. DebugForm.debug1.richTextBox_DebugRev.Text += strTemp;
  1177. }
  1178. buffer.RemoveRange(0, CmdLen + 11);
  1179. DataCmdProcess(PackageID, Cmd, Data);//对于不同的命令段,做不同的处理
  1180. DataRevToString(Cmd, Data);//指令数据转为字符串
  1181. }
  1182. }
  1183. }
  1184. else
  1185. {
  1186. buffer.RemoveAt(0);//ID不对
  1187. }
  1188. }
  1189. else
  1190. {
  1191. buffer.RemoveAt(0);//帧头不对,删除帧头高字节
  1192. }
  1193. }
  1194. }
  1195. catch (Exception)
  1196. {
  1197. }
  1198. }
  1199. private void DataCmdProcess(ushort ID, ushort CmdTemp, byte[] Data)
  1200. {
  1201. int DataTemp;
  1202. ushort uData16;
  1203. unchecked
  1204. {
  1205. this.Invoke((EventHandler)(delegate { label_RecCount.Text = Convert.ToString(Convert.ToInt32(label_RecCount.Text) + 1); }));
  1206. }
  1207. #region 解析发送给CDL的指令
  1208. if (ID == 0x7FF)
  1209. {
  1210. switch (CmdTemp)
  1211. {
  1212. case 0x1100://
  1213. {
  1214. unchecked
  1215. {
  1216. this.Invoke((EventHandler)(delegate
  1217. {
  1218. //CDL连接成功
  1219. mySerialProcess.CDL_Online_Flag = true;
  1220. MessageBoxTimeOut.Show("连接成功!", "提示", 500);
  1221. groupBox1.Visible = true;
  1222. groupBox3.Visible = true;
  1223. tabControl2.Visible = true;
  1224. label_StarInfo.Visible = false;
  1225. }));
  1226. }
  1227. break;
  1228. }
  1229. default: break;
  1230. }
  1231. }
  1232. #endregion
  1233. #region 解析电机的命令
  1234. else if ((ID == 0x715) || (ID == 0x710))
  1235. {
  1236. switch (CmdTemp)
  1237. {
  1238. case 0x1020://电机运行信息
  1239. {
  1240. unchecked
  1241. {
  1242. this.Invoke((EventHandler)(delegate
  1243. {
  1244. MC_RunInfo_Refresh = true;
  1245. //车速
  1246. DataTemp = (int)(Data[1] * 256 + Data[0]);
  1247. textBox_RunInfo_BikeSpeed.Text = ((float)DataTemp / 10f).ToString("0.0") + " km/h";
  1248. //输出转速
  1249. DataTemp = (ushort)(Data[3] * 256 + Data[2]);
  1250. textBox_RunInfo_MotorSpeed.Text = Convert.ToString(DataTemp) + " rpm";
  1251. Class_MotorSpeed.String = textBox_RunInfo_MotorSpeed.Text;
  1252. Class_MotorSpeed.Data = DataTemp;
  1253. //电功率
  1254. DataTemp = (ushort)(Data[5] * 256 + Data[4]);
  1255. textBox_RunInfo_Power.Text = Convert.ToString(DataTemp) + " W";
  1256. //母线电压
  1257. DataTemp = (ushort)(Data[7] * 256 + Data[6]);
  1258. textBox_RunInfo_Vol.Text = Convert.ToString(DataTemp) + " mV";
  1259. //textBox_RunInfo_Vol.Text = (DataTemp / 1000f).ToString("0.0") + " V";
  1260. //母线电流
  1261. DataTemp = (short)(Data[9] * 256 + Data[8]);
  1262. textBox_RunInfo_Current.Text = Convert.ToString(DataTemp) + " mA";
  1263. //textBox_RunInfo_Current.Text = (DataTemp / 1000f).ToString("0.0") + " A";
  1264. Class_CurrentData.String = textBox_RunInfo_Current.Text;
  1265. Class_CurrentData.Data = DataTemp;
  1266. //踏频
  1267. DataTemp = (ushort)(Data[10]);
  1268. textBox_RunInfo_Cadence.Text = Convert.ToString(DataTemp) + " rpm";
  1269. Class_CadenceData.String = textBox_RunInfo_Cadence.Text;
  1270. Class_CadenceData.Data = DataTemp;
  1271. //踩踏力矩
  1272. DataTemp = (ushort)(Data[11]);
  1273. textBox_RunInfo_Torque.Text = Convert.ToString(DataTemp) + " N.m";
  1274. Class_TorqueData.String = textBox_RunInfo_Torque.Text;
  1275. Class_TorqueData.Data = DataTemp;
  1276. //踩踏方向
  1277. DataTemp = (ushort)(Data[12]);
  1278. if (DataTemp == 0)
  1279. {
  1280. textBox_RunInfo_Dir.Text = "正向";
  1281. }
  1282. else if (DataTemp == 1)
  1283. {
  1284. textBox_RunInfo_Dir.Text = "反向";
  1285. }
  1286. else if (DataTemp == 2)
  1287. {
  1288. textBox_RunInfo_Dir.Text = "停止";
  1289. }
  1290. //助力档位
  1291. DataTemp = (ushort)(Data[13]);
  1292. if (DataTemp == 0x33)
  1293. {
  1294. textBox_RunInfo_GearSt.Text = "SMART";
  1295. //comboBox_GearSt.SelectedIndex = 5;
  1296. //comboBox_OBC_SetGearST.SelectedIndex = 5;
  1297. }
  1298. else if (DataTemp == 0x22)
  1299. {
  1300. textBox_RunInfo_GearSt.Text = "WALK";
  1301. //comboBox_GearSt.SelectedIndex = 6;
  1302. //comboBox_OBC_SetGearST.SelectedIndex = 6;
  1303. }
  1304. else
  1305. {
  1306. string[] Gears = new string[5] { "OFF", "ECO", "NORM", "SPORT", "TURBO" };
  1307. textBox_RunInfo_GearSt.Text = Gears[DataTemp];
  1308. //comboBox_GearSt.SelectedIndex = DataTemp;
  1309. //comboBox_OBC_SetGearST.SelectedIndex = DataTemp;
  1310. }
  1311. //大灯状态
  1312. DataTemp = (ushort)(Data[14]);
  1313. if (DataTemp == 0xF0)
  1314. {
  1315. textBox_RunInfo_LightSwitch.Text = "OFF";
  1316. //comboBox_LightSwitch.SelectedIndex = 1;
  1317. //comboBox_OBC_LightSw.SelectedIndex = 1;
  1318. }
  1319. else if (DataTemp == 0xF1)
  1320. {
  1321. textBox_RunInfo_LightSwitch.Text = "ON";
  1322. //comboBox_LightSwitch.SelectedIndex = 0;
  1323. //comboBox_OBC_LightSw.SelectedIndex = 0;
  1324. }
  1325. //剩余电量
  1326. DataTemp = (ushort)(Data[15]);
  1327. textBox_RunInfo_SOC.Text = Convert.ToString(DataTemp) + " %";
  1328. //剩余续航里程
  1329. DataTemp = (ushort)(Data[17] * 256 + Data[16]);
  1330. if ((DataTemp == 0xEEEE) || (DataTemp == 0xFFFF))
  1331. {
  1332. textBox_RunInfo_Range.Text = "---";
  1333. }
  1334. else
  1335. {
  1336. textBox_RunInfo_Range.Text = Convert.ToString(DataTemp) + " km";
  1337. }
  1338. //预留(显示力矩Reg),空2bytes
  1339. DataTemp = (ushort)(Data[19] * 256 + Data[18]);
  1340. textBox_TorqueReg.Text = Convert.ToString(DataTemp);
  1341. //平均功耗
  1342. DataTemp = (ushort)(Data[20]);
  1343. textBox_RunInfo_AvgPower.Text = Convert.ToString(DataTemp * 10) + " mAh/km";
  1344. //PCB温度
  1345. DataTemp = (ushort)(Data[21]);
  1346. textBox_RunInfo_T_PCB.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1347. Class_MotorTemp.String = textBox_RunInfo_T_PCB.Text;
  1348. Class_MotorTemp.Data = DataTemp - 40;
  1349. //绕组温度
  1350. DataTemp = (ushort)(Data[22]);
  1351. textBox_RunInfo_T_Coil.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1352. //MCU温度
  1353. DataTemp = (ushort)(Data[23]);
  1354. textBox_RunInfo_T_MCU.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1355. //单次里程
  1356. DataTemp = (ushort)(Data[25] * 256 + Data[24]);
  1357. textBox_RunInfo_Trip.Text = ((float)DataTemp / 10f).ToString("0.0") + " km";
  1358. //单次时间
  1359. DataTemp = (ushort)(Data[27] * 256 + Data[26]);
  1360. textBox_RunInfo_Trip_Time.Text = Convert.ToString(DataTemp) + " s";
  1361. //RSV1
  1362. DataTemp = (ushort)(Data[28]);
  1363. textBox_RunInfo_RSV1.Text = Convert.ToString(DataTemp);
  1364. //RSV2
  1365. DataTemp = (ushort)(Data[29]);
  1366. textBox_RunInfo_RSV2.Text = Convert.ToString(DataTemp);
  1367. //RSV3
  1368. DataTemp = (ushort)(Data[30]);
  1369. textBox_RunInfo_RSV3.Text = Convert.ToString(DataTemp);
  1370. //GearBox
  1371. DataTemp = (ushort)(Data[31]);
  1372. textBox_RunInfo_GearBox.Text = Convert.ToString(DataTemp);
  1373. //数据保存
  1374. RunInfoAutoSave();
  1375. }));
  1376. }
  1377. break;
  1378. }
  1379. case 0x1104://故障码
  1380. {
  1381. unchecked
  1382. {
  1383. this.Invoke((EventHandler)(delegate
  1384. {
  1385. MC_ErrorCode_Refresh = true;
  1386. textBox_ErrorCode.Text =
  1387. Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() +
  1388. Convert.ToString(Data[2], 16).PadLeft(2, '0').ToUpper() +
  1389. Convert.ToString(Data[1], 16).PadLeft(2, '0').ToUpper() +
  1390. Convert.ToString(Data[0], 16).PadLeft(2, '0').ToUpper() +
  1391. "H";
  1392. }));
  1393. }
  1394. break;
  1395. }
  1396. case 0xA903://反馈指令
  1397. {
  1398. unchecked
  1399. {
  1400. this.Invoke((EventHandler)(delegate
  1401. {
  1402. if (ACK_DisFlag == true)
  1403. {
  1404. MessageBoxTimeOut.Show("OK", "反馈指令", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  1405. //关机反馈
  1406. PowerOffAckStatus = true;
  1407. }
  1408. //应答标志置位
  1409. WriteACK = true;
  1410. }));
  1411. }
  1412. break;
  1413. }
  1414. case 0xB226://马达参数
  1415. {
  1416. unchecked
  1417. {
  1418. this.Invoke((EventHandler)(delegate
  1419. {
  1420. richTextBox_MotorParam.Clear();
  1421. for (int i = 0; i < myParams.MotorParam.Count; i++)
  1422. {
  1423. if (i == 6)
  1424. richTextBox_MotorParam.AppendText(myParams.MotorParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1425. else
  1426. richTextBox_MotorParam.AppendText(myParams.MotorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1427. }
  1428. richTextBox_MotorParam.Text = richTextBox_MotorParam.Text.Substring(0, richTextBox_MotorParam.Text.Length - 2);
  1429. }));
  1430. }
  1431. break;
  1432. }
  1433. case 0xB31A://整车信息
  1434. {
  1435. unchecked
  1436. {
  1437. this.Invoke((EventHandler)(delegate
  1438. {
  1439. richTextBox_BikeParam.Clear();
  1440. for (int i = 0; i < myParams.BikeParam.Count; i++)
  1441. {
  1442. if (i == 9)
  1443. richTextBox_BikeParam.AppendText(myParams.BikeParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1444. else
  1445. richTextBox_BikeParam.AppendText(myParams.BikeParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1446. //更新前后灯参数
  1447. if (i == 8)
  1448. {
  1449. comboBox_TailLightMode.SelectedIndex = ((Data[2 * i + 1] >> 4) & 0x0F) - 1;
  1450. comboBox_TailLightVol.SelectedIndex = ((Data[2 * i + 1] & 0x0F) == 6) ? 0 : 1;
  1451. comboBox_FrontLightVol.SelectedIndex = ((Data[2 * i] & 0x0F) == 6) ? 0 : 1;
  1452. }
  1453. //更新开关机参数
  1454. else if (i == 11)
  1455. {
  1456. textBox_PowerOnDelay.Text = Convert.ToString((Data[2 * i + 1] >> 4) & 0x0F);
  1457. textBox_PowerOffDelay.Text = Convert.ToString(Data[2 * i + 1] & 0x0F);
  1458. textBox_AutoPowerOff.Text = Convert.ToString(Data[2 * i]);
  1459. }
  1460. }
  1461. richTextBox_BikeParam.Text = richTextBox_BikeParam.Text.Substring(0, richTextBox_BikeParam.Text.Length - 2);
  1462. }));
  1463. }
  1464. break;
  1465. }
  1466. case 0xB420://控制器参数
  1467. {
  1468. unchecked
  1469. {
  1470. this.Invoke((EventHandler)(delegate
  1471. {
  1472. richTextBox_ControlParam.Clear();
  1473. for (int i = 0; i < myParams.ControlParam.Count; i++)
  1474. {
  1475. richTextBox_ControlParam.AppendText(myParams.ControlParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1476. //转把定速巡航
  1477. if (i == 13)
  1478. {
  1479. comboBox_Bike_CCS.SelectedIndex = ((Data[2 * i]) == 0xAA) ? 1 : 2;
  1480. }
  1481. }
  1482. richTextBox_ControlParam.Text = richTextBox_ControlParam.Text.Substring(0, richTextBox_ControlParam.Text.Length - 2);
  1483. }));
  1484. }
  1485. break;
  1486. }
  1487. case 0xB528://传感器参数
  1488. {
  1489. unchecked
  1490. {
  1491. this.Invoke((EventHandler)(delegate
  1492. {
  1493. richTextBox_SensorParam.Clear();
  1494. for (int i = 0; i < myParams.SensorParam.Count; i++)
  1495. {
  1496. richTextBox_SensorParam.AppendText(myParams.SensorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1497. }
  1498. richTextBox_SensorParam.Text = richTextBox_SensorParam.Text.Substring(0, richTextBox_SensorParam.Text.Length - 2);
  1499. //更新生产模式页面传感器零点和标定值
  1500. textBox_FacModeSensorADC0.Text = (Data[9] * 256 + Data[8]).ToString();
  1501. textBox_FacModeSensorADC1.Text = (Data[15] * 256 + Data[14]).ToString();
  1502. textBox_FacModeSensorADC2.Text = (Data[19] * 256 + Data[18]).ToString();
  1503. textBox_FacModeSensorADC3.Text = (Data[23] * 256 + Data[22]).ToString();
  1504. textBox_FacModeSensorADC4.Text = (Data[27] * 256 + Data[26]).ToString();
  1505. WriteACK = true;
  1506. }));
  1507. }
  1508. break;
  1509. }
  1510. case 0xB64C://助力参数
  1511. {
  1512. unchecked
  1513. {
  1514. this.Invoke((EventHandler)(delegate
  1515. {
  1516. richTextBox_AssistParam.Clear();
  1517. int index_1 = myParams.AssistParam.IndexOf("转矩曲线.a");
  1518. int index_2 = myParams.AssistParam.IndexOf("踏频曲线.d");
  1519. int index_3 = myParams.AssistParam.IndexOf("踏频助力加速限制");
  1520. int index_4 = myParams.AssistParam.IndexOf("踏频助力电流步进");
  1521. for (int i = 0; i < myParams.AssistParam.Count; i++)
  1522. {
  1523. if (i < index_1) //数据占用2bytes
  1524. {
  1525. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1526. }
  1527. else if (i <= index_2) //数据占用4bytes
  1528. {
  1529. 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])) + ", ");
  1530. }
  1531. else if (i < index_3) //数据占用2bytes,无符号
  1532. {
  1533. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1534. }
  1535. else if (i <= index_4) //数据占用2bytes,有符号
  1536. {
  1537. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1538. }
  1539. else //数据占用2bytes,无符号
  1540. {
  1541. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1542. }
  1543. }
  1544. richTextBox_AssistParam.Text = richTextBox_AssistParam.Text.Substring(0, richTextBox_AssistParam.Text.Length - 2);
  1545. }));
  1546. }
  1547. break;
  1548. }
  1549. case 0xB74C://历史记录
  1550. {
  1551. unchecked
  1552. {
  1553. this.Invoke((EventHandler)(delegate
  1554. {
  1555. richTextBox_Record.Clear();
  1556. for (int i = 0; i < myParams.Record.Count; i++)
  1557. {
  1558. richTextBox_Record.AppendText(myParams.Record[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  1559. }
  1560. richTextBox_Record.Text = richTextBox_Record.Text.Substring(0, richTextBox_Record.Text.Length - 2);
  1561. }));
  1562. }
  1563. break;
  1564. }
  1565. case 0xB83A://调试参数
  1566. {
  1567. unchecked
  1568. {
  1569. this.Invoke((EventHandler)(delegate
  1570. {
  1571. richTextBox_DebugParam.Clear();
  1572. for (int i = 0; i < myParams.DebugParam.Count; i++)
  1573. {
  1574. richTextBox_DebugParam.AppendText(myParams.DebugParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1575. }
  1576. richTextBox_DebugParam.Text = richTextBox_DebugParam.Text.Substring(0, richTextBox_DebugParam.Text.Length - 2);
  1577. }));
  1578. }
  1579. break;
  1580. }
  1581. case 0xB904://存储标志
  1582. {
  1583. unchecked
  1584. {
  1585. this.Invoke((EventHandler)(delegate
  1586. {
  1587. ushort Flag = 0;
  1588. Flag = (ushort)(Data[1] * 256 + Data[0]);//EEPROM存储标志
  1589. if (Flag == 0)
  1590. {
  1591. radioButton_EE_SaveNo.Checked = true;
  1592. radioButton_EE_SaveYes.Checked = false;
  1593. }
  1594. else
  1595. {
  1596. radioButton_EE_SaveNo.Checked = false;
  1597. radioButton_EE_SaveYes.Checked = true;
  1598. }
  1599. Flag = (ushort)(Data[3] * 256 + Data[2]);//SIP偏移校准存储标志
  1600. if (Flag == 0)
  1601. {
  1602. radioButton_SIP_SaveNo.Checked = true;
  1603. radioButton_SIP_SaveYes.Checked = false;
  1604. }
  1605. else
  1606. {
  1607. radioButton_SIP_SaveNo.Checked = false;
  1608. radioButton_SIP_SaveYes.Checked = true;
  1609. }
  1610. }));
  1611. }
  1612. break;
  1613. }
  1614. case 0x1240://电机版本信息
  1615. {
  1616. unchecked
  1617. {
  1618. this.Invoke((EventHandler)(delegate
  1619. {
  1620. //电机型号
  1621. textBox_Model.Text = "";
  1622. textBox_OBC_ReadModel.Text = "";
  1623. textBox_FacModeName.Text = "";
  1624. for (ushort i = 0; i < 16; i++)
  1625. {
  1626. if (Data[i] == 0x2E)
  1627. {
  1628. break;
  1629. }
  1630. textBox_Model.Text += ((char)Data[i]).ToString();
  1631. textBox_OBC_ReadModel.Text += ((char)Data[i]).ToString();
  1632. textBox_FacModeName.Text += ((char)Data[i]).ToString();
  1633. }
  1634. Class_Motor_Ver.Mode = textBox_Model.Text;
  1635. //电机SN
  1636. textBox_SN.Text = "";
  1637. textBox_OBC_ReadSN.Text = "";
  1638. textBox_FacModeNum.Text = "";
  1639. for (ushort i = 0; i < 16; i++)
  1640. {
  1641. if (Data[16 + i] == 0x2E)
  1642. {
  1643. break;
  1644. }
  1645. textBox_SN.Text += ((char)Data[16 + i]).ToString();
  1646. textBox_OBC_ReadSN.Text += ((char)Data[16 + i]).ToString();
  1647. textBox_FacModeNum.Text += ((char)Data[16 + i]).ToString();
  1648. }
  1649. Class_Motor_Ver.SN = textBox_SN.Text;
  1650. //电机HW
  1651. textBox_HW.Text = "";
  1652. textBox_OBC_ReadHW.Text = "";
  1653. textBox_FacModeHW.Text = "";
  1654. for (ushort i = 0; i < 8; i++)//前8位:硬件板号
  1655. {
  1656. if (Data[32 + i] == 0x2E)
  1657. {
  1658. break;
  1659. }
  1660. else if (Data[32 + i] == 'r')
  1661. {
  1662. Data[32 + i] = (byte)'.';
  1663. break;
  1664. }
  1665. string strTemp = "";
  1666. strTemp = ((char)Data[32 + i]).ToString();
  1667. textBox_HW.Text += strTemp;
  1668. textBox_OBC_ReadHW.Text += strTemp;
  1669. textBox_FacModeHW.Text += strTemp;
  1670. }
  1671. for (ushort i = 0; i < 4; i++)//9-12位:单片机型号
  1672. {
  1673. if (Data[40 + i] == 0x2E)
  1674. {
  1675. break;
  1676. }
  1677. else if (Data[40 + i] == 'r')
  1678. {
  1679. Data[40 + i] = (byte)'.';
  1680. break;
  1681. }
  1682. string strTemp = "";
  1683. strTemp = ((char)Data[40 + i]).ToString();
  1684. textBox_HW.Text += strTemp;
  1685. textBox_OBC_ReadHW.Text += strTemp;
  1686. textBox_FacModeHW.Text += strTemp;
  1687. }
  1688. for (ushort i = 0; i < 4; i++)//13-16位:单片机ID
  1689. {
  1690. string strTemp = "";
  1691. strTemp = Convert.ToString(Data[44 + i], 16).PadLeft(2, '0').ToUpper();
  1692. textBox_HW.Text += strTemp;
  1693. textBox_OBC_ReadHW.Text += strTemp;
  1694. textBox_FacModeHW.Text += strTemp;
  1695. }
  1696. Class_Motor_Ver.HW = textBox_HW.Text;
  1697. //电机FW
  1698. textBox_FW.Text = "";
  1699. textBox_OBC_ReadFW.Text = "";
  1700. textBox_FacModeFW.Text = "";
  1701. for (ushort i = 0; i < 16; i++)
  1702. {
  1703. if ((Data[48 + i] == 0x2E) || (Data[48 + i] == 0x00) || (Data[48 + i] == (char)' '))
  1704. {
  1705. break;
  1706. }
  1707. if (Data[48 + i] == 'r')
  1708. {
  1709. Data[48 + i] = (byte)'.';
  1710. }
  1711. textBox_FW.Text += ((char)Data[48 + i]).ToString();
  1712. textBox_OBC_ReadFW.Text += ((char)Data[48 + i]).ToString();
  1713. textBox_FacModeFW.Text += ((char)Data[48 + i]).ToString();
  1714. }
  1715. Class_Motor_Ver.FW = textBox_FW.Text;
  1716. }));
  1717. }
  1718. break;
  1719. }
  1720. case 0xA610://自定义1
  1721. {
  1722. unchecked
  1723. {
  1724. this.Invoke((EventHandler)(delegate
  1725. {
  1726. textBox_User1.Text = "";
  1727. for (ushort i = 0; i < 16; i++)
  1728. {
  1729. if (Data[i] == 0x2E)
  1730. {
  1731. break;
  1732. }
  1733. textBox_User1.Text += ((char)Data[i]).ToString();
  1734. }
  1735. }));
  1736. }
  1737. break;
  1738. }
  1739. case 0xA710://自定义2
  1740. {
  1741. unchecked
  1742. {
  1743. this.Invoke((EventHandler)(delegate
  1744. {
  1745. textBox_User2.Text = "";
  1746. for (ushort i = 0; i < 16; i++)
  1747. {
  1748. if (Data[i] == 0x2E)
  1749. {
  1750. break;
  1751. }
  1752. textBox_User2.Text += ((char)Data[i]).ToString();
  1753. }
  1754. }));
  1755. }
  1756. break;
  1757. }
  1758. case 0xA810://自定义1
  1759. {
  1760. unchecked
  1761. {
  1762. this.Invoke((EventHandler)(delegate
  1763. {
  1764. textBox_User3.Text = "";
  1765. for (ushort i = 0; i < 16; i++)
  1766. {
  1767. if (Data[i] == 0x2E)
  1768. {
  1769. break;
  1770. }
  1771. textBox_User3.Text += ((char)Data[i]).ToString();
  1772. }
  1773. }));
  1774. }
  1775. break;
  1776. }
  1777. case 0xA520://生产信息
  1778. {
  1779. unchecked
  1780. {
  1781. this.Invoke((EventHandler)(delegate
  1782. {
  1783. //生产商
  1784. textBox_MAC.Text = "";
  1785. for (ushort i = 0; i < 8; i++)
  1786. {
  1787. if (Data[i] == 0x2E)
  1788. {
  1789. break;
  1790. }
  1791. textBox_MAC.Text += ((char)Data[i]).ToString();
  1792. }
  1793. //生产地
  1794. textBox_MACAdd.Text = "";
  1795. for (ushort i = 0; i < 8; i++)
  1796. {
  1797. if (Data[8 + i] == 0x2E)
  1798. {
  1799. break;
  1800. }
  1801. textBox_MACAdd.Text += ((char)Data[8 + i]).ToString();
  1802. }
  1803. //生产日期
  1804. textBox_MACDate.Text = "";
  1805. for (ushort i = 0; i < 8; i++)
  1806. {
  1807. if (Data[16 + i] == 0x2E)
  1808. {
  1809. break;
  1810. }
  1811. textBox_MACDate.Text += ((char)Data[16 + i]).ToString();
  1812. }
  1813. //品牌信息
  1814. textBox_PP.Text = "";
  1815. for (ushort i = 0; i < 8; i++)
  1816. {
  1817. if (Data[24 + i] == 0x2E)
  1818. {
  1819. break;
  1820. }
  1821. textBox_PP.Text += ((char)Data[24 + i]).ToString();
  1822. }
  1823. }));
  1824. }
  1825. break;
  1826. }
  1827. case 0xA408://密钥
  1828. {
  1829. unchecked
  1830. {
  1831. this.Invoke((EventHandler)(delegate
  1832. {
  1833. textBox_Key.Text = "";
  1834. for (ushort i = 0; i < 8; i++)
  1835. {
  1836. textBox_Key.Text += ((char)Data[i]).ToString();
  1837. }
  1838. }));
  1839. }
  1840. break;
  1841. }
  1842. case 0xAB09://存储器数据
  1843. case 0xAB0A:
  1844. case 0xAB0B:
  1845. case 0xAB0C:
  1846. {
  1847. unchecked
  1848. {
  1849. this.Invoke((EventHandler)(delegate
  1850. {
  1851. long ByteNum = 0;
  1852. ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
  1853. if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
  1854. {
  1855. for (int i = 0; i < ByteNum; i++)
  1856. {
  1857. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  1858. }
  1859. }
  1860. else //根据设置自动转换10进制显示
  1861. {
  1862. if (checkBox_ReadRanFlash_ChangeFormat.Checked == true) //10进制显示
  1863. {
  1864. switch (ByteNum)
  1865. {
  1866. case 1:
  1867. {
  1868. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8]) + ", ");
  1869. break;
  1870. }
  1871. case 2:
  1872. {
  1873. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8)) + ", ");
  1874. break;
  1875. }
  1876. case 3:
  1877. {
  1878. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16)) + ", ");
  1879. break;
  1880. }
  1881. case 4:
  1882. {
  1883. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24)) + ", ");
  1884. break;
  1885. }
  1886. default:
  1887. {
  1888. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  1889. break;
  1890. }
  1891. }
  1892. }
  1893. else //16进制显示
  1894. {
  1895. switch (ByteNum)
  1896. {
  1897. case 1:
  1898. {
  1899. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8], 16).PadLeft(2, '0').ToUpper() + ", ");
  1900. break;
  1901. }
  1902. case 2:
  1903. {
  1904. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8), 16).PadLeft(4, '0').ToUpper() + ", ");
  1905. break;
  1906. }
  1907. case 3:
  1908. {
  1909. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16), 16).PadLeft(6, '0').ToUpper() + ", ");
  1910. break;
  1911. }
  1912. case 4:
  1913. {
  1914. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24), 16).PadLeft(8, '0').ToUpper() + ", ");
  1915. break;
  1916. }
  1917. default:
  1918. {
  1919. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  1920. break;
  1921. }
  1922. }
  1923. }
  1924. }
  1925. }));
  1926. }
  1927. break;
  1928. }
  1929. case 0xAB88://故障日志
  1930. {
  1931. unchecked
  1932. {
  1933. this.Invoke((EventHandler)(delegate
  1934. {
  1935. //电机存储的故障日志,一包128字节包含2条故障日志
  1936. var ErrorLogSaveInfo1 = new MC_ErrorLogSaveInfo_Struct_t();
  1937. var ErrorLogSaveInfo2 = new MC_ErrorLogSaveInfo_Struct_t();
  1938. ErrorLogSaveInfo1 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 8);
  1939. ErrorLogSaveInfo2 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 72);
  1940. //数据显示
  1941. ErrorLogDisplay(ErrorLogSaveInfo1, ErrorLogSaveInfo2);
  1942. }));
  1943. }
  1944. break;
  1945. }
  1946. case 0x1401://在线检测结果
  1947. {
  1948. unchecked
  1949. {
  1950. this.Invoke((EventHandler)(delegate
  1951. {
  1952. textBox_Online.Text = Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() + "H";
  1953. }));
  1954. }
  1955. break;
  1956. }
  1957. case 0x1510://骑行历史信息
  1958. {
  1959. unchecked
  1960. {
  1961. this.Invoke((EventHandler)(delegate
  1962. {
  1963. long DataTemp32;
  1964. //ODO里程
  1965. DataTemp32 = (long)((Data[3] << 24) + (Data[2] << 16) + (Data[1] << 8) + Data[0]);
  1966. textBox_OBC_ODO_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  1967. textBox_ODO_KM.Text = DataTemp32.ToString();
  1968. //ODO时间
  1969. DataTemp32 = (long)((Data[7] << 24) + (Data[6] << 16) + (Data[5] << 8) + Data[4]);
  1970. if (DataTemp32 >= 60 * 100000)
  1971. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  1972. else
  1973. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  1974. textBox_ODO_TIME.Text = DataTemp32.ToString();
  1975. //TRIP里程
  1976. DataTemp32 = (long)((Data[11] << 24) + (Data[10] << 16) + (Data[9] << 8) + Data[8]);
  1977. textBox_OBC_TRIP_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  1978. textBox_TRIP_KM.Text = DataTemp32.ToString();
  1979. //TRIP时间
  1980. DataTemp32 = (long)((Data[15] << 24) + (Data[14] << 16) + (Data[13] << 8) + Data[12]);
  1981. if (DataTemp32 >= 60 * 100000)
  1982. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  1983. else
  1984. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  1985. textBox_TRIP_TIME.Text = DataTemp32.ToString();
  1986. }));
  1987. }
  1988. break;
  1989. }
  1990. case 0x1720://客户信息
  1991. {
  1992. unchecked
  1993. {
  1994. this.Invoke((EventHandler)(delegate
  1995. {
  1996. //软件标识
  1997. textBox_SP.Text = "";
  1998. textBox_OBC_ReadSP.Text = "";
  1999. textBox_FacModeSP.Text = "";
  2000. for (ushort i = 0; i < 23; i++)
  2001. {
  2002. if (Data[i] == 'r')
  2003. {
  2004. Data[i] = (byte)'.';
  2005. }
  2006. textBox_SP.Text += ((char)Data[i]).ToString();
  2007. textBox_OBC_ReadSP.Text += ((char)Data[i]).ToString();
  2008. textBox_FacModeSP.Text += ((char)Data[i]).ToString();
  2009. }
  2010. //Git提交版本信息
  2011. textBox_FacModeGit.Text = "";
  2012. for (ushort i = 0; i < 9; i++)
  2013. {
  2014. textBox_SP.Text += ((char)Data[23 + i]).ToString();
  2015. textBox_FacModeGit.Text += ((char)Data[23 + i]).ToString();
  2016. }
  2017. Class_Motor_Ver.Special = textBox_SP.Text;
  2018. }));
  2019. }
  2020. break;
  2021. }
  2022. case 0xBA20: //调试信息
  2023. {
  2024. unchecked
  2025. {
  2026. this.Invoke((EventHandler)(delegate
  2027. {
  2028. MC_DebugInfo_Refresh = true;
  2029. //系统状态机
  2030. DataTemp = (short)(Data[0]);
  2031. textBox_DebugInfo_SysFun.Text = Convert.ToString(DataTemp);
  2032. //二层状态机
  2033. DataTemp = (short)(Data[1]);
  2034. textBox_DebugInfo_SecondFun.Text = Convert.ToString(DataTemp);
  2035. //电机状态机
  2036. DataTemp = (short)(Data[2]);
  2037. textBox_DebugInfo_MotorFun.Text = Convert.ToString(DataTemp);
  2038. //助力状态机
  2039. DataTemp = (short)(Data[3]);
  2040. textBox_DebugInfo_AssistFun.Text = Convert.ToString(DataTemp);
  2041. //IdRef
  2042. DataTemp = (short)(Data[5] * 256 + Data[4]);
  2043. textBox_DebugInfo_IdRef.Text = Convert.ToString(DataTemp);
  2044. //IqRef
  2045. DataTemp = (short)(Data[7] * 256 + Data[6]);
  2046. textBox_DebugInfo_IqRef.Text = Convert.ToString(DataTemp);
  2047. //UdRef
  2048. DataTemp = (short)(Data[9] * 256 + Data[8]);
  2049. textBox_DebugInfo_UdRef.Text = Convert.ToString(DataTemp);
  2050. //UqRef
  2051. DataTemp = (short)(Data[11] * 256 + Data[10]);
  2052. textBox_DebugInfo_UqRef.Text = Convert.ToString(DataTemp);
  2053. //瞬时力矩
  2054. DataTemp = (short)(Data[13] * 256 + Data[12]);
  2055. textBox_DebugInfo_TorquePu.Text = Convert.ToString(DataTemp);
  2056. //时间滤波力矩
  2057. DataTemp = (short)(Data[15] * 256 + Data[14]);
  2058. textBox_DebugInfo_TorqueFil.Text = Convert.ToString(DataTemp);
  2059. //踏频滤波力矩
  2060. DataTemp = (short)(Data[17] * 256 + Data[16]);
  2061. textBox_DebugInfo_TorqueCadence.Text = Convert.ToString(DataTemp);
  2062. //IdFdb
  2063. DataTemp = (short)(Data[19] * 256 + Data[18]);
  2064. textBox_DebugInfo_IdFdb.Text = Convert.ToString(DataTemp);
  2065. //IqFdb
  2066. DataTemp = (short)(Data[21] * 256 + Data[20]);
  2067. textBox_DebugInfo_IqFdb.Text = Convert.ToString(DataTemp);
  2068. //助力输出
  2069. DataTemp = (short)(Data[23] * 256 + Data[22]);
  2070. textBox_DebugInfo_AssistOut.Text = Convert.ToString(DataTemp);
  2071. //转把百分比
  2072. DataTemp = (short)(Data[25] * 256 + Data[24]);
  2073. textBox_DebugInfo_ThrottlePer.Text = Convert.ToString(DataTemp);
  2074. //数据保存
  2075. RunInfoAutoSave();
  2076. }));
  2077. }
  2078. break;
  2079. }
  2080. case 0xBB20: //产品标签信息
  2081. {
  2082. unchecked
  2083. {
  2084. this.Invoke((EventHandler)(delegate
  2085. {
  2086. //产品标签
  2087. textBox_TagInfo.Text = "";
  2088. for (ushort i = 0; i < 32; i++)
  2089. {
  2090. textBox_TagInfo.Text += ((char)Data[i]).ToString();
  2091. }
  2092. }));
  2093. }
  2094. break;
  2095. }
  2096. case 0xBC20: //内阻校正信息
  2097. {
  2098. unchecked
  2099. {
  2100. this.Invoke((EventHandler)(delegate
  2101. {
  2102. //内阻1
  2103. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  2104. textBox_MOS_R1.Text = Convert.ToString(uData16);
  2105. //内阻2
  2106. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  2107. textBox_MOS_R2.Text = Convert.ToString(uData16);
  2108. //内阻3
  2109. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  2110. textBox_MOS_R3.Text = Convert.ToString(uData16);
  2111. //K1
  2112. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  2113. textBox_MOS_K1.Text = Convert.ToString(uData16);
  2114. //K2
  2115. uData16 = (ushort)(Data[9] * 256 + Data[8]);
  2116. textBox_MOS_K2.Text = Convert.ToString(uData16);
  2117. //K3
  2118. uData16 = (ushort)(Data[11] * 256 + Data[10]);
  2119. textBox_MOS_K3.Text = Convert.ToString(uData16);
  2120. //K4
  2121. uData16 = (ushort)(Data[13] * 256 + Data[12]);
  2122. textBox_MOS_K4.Text = Convert.ToString(uData16);
  2123. //K5
  2124. uData16 = (ushort)(Data[15] * 256 + Data[14]);
  2125. textBox_MOS_K5.Text = Convert.ToString(uData16);
  2126. }));
  2127. }
  2128. break;
  2129. }
  2130. case 0xBD20: //整车信息2
  2131. {
  2132. unchecked
  2133. {
  2134. this.Invoke((EventHandler)(delegate
  2135. {
  2136. richTextBox_BikeParam2.Clear();
  2137. for (int i = 0; i < myParams.BikeParam2.Count; i++)
  2138. {
  2139. richTextBox_BikeParam2.AppendText(myParams.BikeParam2[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  2140. }
  2141. richTextBox_BikeParam2.Text = richTextBox_BikeParam2.Text.Substring(0, richTextBox_BikeParam2.Text.Length - 2);
  2142. }));
  2143. }
  2144. break;
  2145. }
  2146. case 0xBE20: //用户骑行参数
  2147. {
  2148. unchecked
  2149. {
  2150. this.Invoke((EventHandler)(delegate
  2151. {
  2152. richTextBox_UsrRidesParam.Clear();
  2153. for (int i = 0; i < myParams.UsrRideParam.Count; i++)
  2154. {
  2155. richTextBox_UsrRidesParam.AppendText(myParams.UsrRideParam[i] + "=" + Convert.ToString(Data[i]) + ", ");
  2156. }
  2157. richTextBox_UsrRidesParam.Text = richTextBox_UsrRidesParam.Text.Substring(0, richTextBox_UsrRidesParam.Text.Length - 2);
  2158. }));
  2159. }
  2160. break;
  2161. }
  2162. case 0xBF58: //位置传感器校准值
  2163. {
  2164. unchecked
  2165. {
  2166. this.Invoke((EventHandler)(delegate
  2167. {
  2168. string[] str1 = new string[42];
  2169. double[] error1 = new double[42];
  2170. //更新校准数据
  2171. for (int i = 0; i < 42; i++)
  2172. {
  2173. double data1 = (Data[4 + i * 2] + (Data[4 + i * 2 + 1] << 8)) / 32767.0 * 360;
  2174. error1[i] = data1 - (60 * (i % 6) + 60);
  2175. if (error1[i] < -180)
  2176. {
  2177. error1[i] = error1[i] + 360;
  2178. }
  2179. str1[i] = data1.ToString("F2");
  2180. AngledataRecord[i] = str1[i];
  2181. }
  2182. for (int i = 0; i < 7; i++)
  2183. for (int j = 0; j < 6; j++)
  2184. {
  2185. dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = str1[6 * i + j];
  2186. }
  2187. //计算偏差最小值、最大值和平均值
  2188. //Array.ConvertAll(error1, Math.Abs);
  2189. textBox_AngleDiffMin.Text = error1.Min().ToString("F2");
  2190. textBox_AngleDiffMax.Text = error1.Max().ToString("F2");
  2191. textBox_AngleDiffAvg.Text = error1.Average().ToString("F2");
  2192. //计算零点偏差
  2193. double tmp1 = ((Int16)(Data[0] + (Data[1] << 8))) / 32767.0 * 360;
  2194. textBox_AngleZeroInit.Text = tmp1.ToString("F2");
  2195. double tmp2 = ((Int16)(Data[2] + (Data[3] << 8))) / 32767.0 * 360;
  2196. textBox_AngleZeroCur.Text = tmp2.ToString("F2");
  2197. double tmp3 = (tmp2 - tmp1);
  2198. textBox_AngleZeroDiff.Text = tmp3.ToString("F2");
  2199. }));
  2200. }
  2201. break;
  2202. }
  2203. case 0xC008: //故障日志地址
  2204. {
  2205. unchecked
  2206. {
  2207. this.Invoke((EventHandler)(delegate
  2208. {
  2209. uint Addr_Begin = 0, Addr_End = 0;
  2210. Addr_Begin = (uint)((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]);
  2211. Addr_End = (uint)((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]);
  2212. textBox_LogAddrBegin.Text = Convert.ToString(Addr_Begin, 16).PadLeft(8, '0').ToUpper();
  2213. textBox_LogAddrEnd.Text = Convert.ToString(Addr_End, 16).PadLeft(8, '0').ToUpper();
  2214. }));
  2215. }
  2216. break;
  2217. }
  2218. case 0xC109: //Boot版本信息
  2219. {
  2220. BootInfo = "";
  2221. for (ushort i = 0; i < 9; i++)
  2222. {
  2223. BootInfo += ((char)Data[i]).ToString();
  2224. }
  2225. break;
  2226. }
  2227. case 0xC142: //功能配置表
  2228. {
  2229. unchecked
  2230. {
  2231. this.Invoke((EventHandler)(delegate
  2232. {
  2233. //块编号
  2234. ushort Num = (ushort)(Data[1] * 256 + Data[0]);
  2235. comboBox_FunSet_BlockNum.SelectedIndex = Num - 1;
  2236. //显示数据
  2237. for (int i = 0; i < 64; i++)
  2238. {
  2239. dataGridView_FunSet.Rows[i / 8].Cells[i % 8 + 1].Value = Data[i + 2].ToString();
  2240. }
  2241. }));
  2242. }
  2243. break;
  2244. }
  2245. case 0xC220: //定制编号
  2246. {
  2247. unchecked
  2248. {
  2249. this.Invoke((EventHandler)(delegate
  2250. {
  2251. //定制编号
  2252. textBox_UserNum.Text = "";
  2253. for (ushort i = 0; i < 32; i++)
  2254. {
  2255. textBox_UserNum.Text += ((char)Data[i]).ToString();
  2256. }
  2257. }));
  2258. }
  2259. break;
  2260. }
  2261. default:
  2262. {
  2263. break;
  2264. }
  2265. }
  2266. //存储器导出数据显示
  2267. if ((CmdTemp & 0xFF00) == 0xAB00)
  2268. {
  2269. unchecked
  2270. {
  2271. this.Invoke((EventHandler)(delegate
  2272. {
  2273. long ByteNum = 0;
  2274. ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
  2275. if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
  2276. {
  2277. for (int i = 0; i < ByteNum; i++)
  2278. {
  2279. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  2280. }
  2281. }
  2282. }));
  2283. }
  2284. }
  2285. }
  2286. #endregion
  2287. #region 解析BMS广播的命令
  2288. else if (ID == 0x720)
  2289. {
  2290. switch (CmdTemp)
  2291. {
  2292. case 0x1010://BMS运行信息
  2293. {
  2294. unchecked
  2295. {
  2296. this.Invoke((EventHandler)(delegate
  2297. {
  2298. BMS_RunInfo_Refresh = true;
  2299. richTextBox_OBC_BMS_RunInfo.Clear();
  2300. //电压
  2301. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  2302. richTextBox_OBC_BMS_RunInfo.AppendText("电压:" + Convert.ToString(uData16) + " mV" + "\r\n");
  2303. //电流
  2304. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  2305. richTextBox_OBC_BMS_RunInfo.AppendText("电流:" + Convert.ToString(uData16) + " mA" + "\r\n");
  2306. //剩余容量
  2307. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  2308. richTextBox_OBC_BMS_RunInfo.AppendText("剩余容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  2309. //满充容量
  2310. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  2311. richTextBox_OBC_BMS_RunInfo.AppendText("满充容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  2312. //电芯温度
  2313. richTextBox_OBC_BMS_RunInfo.AppendText("电芯温度:" + Convert.ToString((int)(Data[8] - 40) + " ℃" + "\r\n"));
  2314. //剩余电量
  2315. richTextBox_OBC_BMS_RunInfo.AppendText("剩余电量:" + Convert.ToString(Data[9]) + " %" + "\r\n");
  2316. //电池状态
  2317. richTextBox_OBC_BMS_RunInfo.AppendText("电池状态:" + Convert.ToString(Data[10], 16).PadLeft(2, '0').ToUpper() + " H" + "\r\n");
  2318. //SOH
  2319. richTextBox_OBC_BMS_RunInfo.AppendText("电池寿命:" + Convert.ToString(Data[11]) + " %" + "\r\n");
  2320. //循环次数
  2321. richTextBox_OBC_BMS_RunInfo.AppendText("循环次数:" + Convert.ToString((ushort)(Data[13] * 256 + Data[12])) + " 次");
  2322. }));
  2323. }
  2324. break;
  2325. }
  2326. default: break;
  2327. }
  2328. }
  2329. #endregion
  2330. #region 解析电机发送OBC的命令
  2331. else if (ID == 0x713)
  2332. {
  2333. switch (CmdTemp)
  2334. {
  2335. case 0x5408://电机用户参数
  2336. {
  2337. unchecked
  2338. {
  2339. this.Invoke((EventHandler)(delegate
  2340. {
  2341. richTextBox_OBC_ReadUserInfo.Clear();
  2342. //默认周长
  2343. richTextBox_OBC_ReadUserInfo.AppendText("默认周长:" + Convert.ToString((int)Data[0]) + " cm" + "\r\n");
  2344. //启动模式
  2345. richTextBox_OBC_ReadUserInfo.AppendText("启动模式:" + ((Data[1] == 0x01) ? "柔和" : (Data[1] == 0x02) ? "正常" : (Data[1] == 0x03) ? "强劲" : "无效") + "\r\n");
  2346. comboBox_OBC_StartMode.SelectedIndex = Data[1] - 1;
  2347. //限速
  2348. richTextBox_OBC_ReadUserInfo.AppendText("限速:" + Convert.ToString(Data[2]) + " km/h" + "\r\n");
  2349. //周长微调
  2350. numericUpDown_OBC_WheelAdj.Value = (int)(Data[3] > 128 ? (Data[3] - 256) : Data[3]);
  2351. richTextBox_OBC_ReadUserInfo.AppendText("周长微调:" + Convert.ToString(numericUpDown_OBC_WheelAdj.Value) + " cm" + "\r\n");
  2352. //助力方案
  2353. richTextBox_OBC_ReadUserInfo.AppendText("助力方案:" + Convert.ToString(Data[4]) + "\r\n");
  2354. comboBox_OBC_AssistFunc.SelectedIndex = Data[4] - 1;
  2355. //关机时间
  2356. richTextBox_OBC_ReadUserInfo.AppendText("关机时间:" + Convert.ToString(Data[5]) + " min" + "\r\n");
  2357. numericUpDown_OBC_OffTime.Value = (int)Data[5];
  2358. //限速微调
  2359. numericUpDown_OBC_SpeedLimitAdj.Value = (int)(Data[6] > 128 ? (Data[6] - 256) : Data[6]);
  2360. richTextBox_OBC_ReadUserInfo.AppendText("限速微调:" + Convert.ToString(numericUpDown_OBC_SpeedLimitAdj.Value) + " km/h" + "\r\n");
  2361. //定速巡航
  2362. comboBox_OBC_BikeCCS.SelectedIndex = (Data[7] == 0xAA) ? 1 : 2;
  2363. richTextBox_OBC_ReadUserInfo.AppendText("转把巡航:" + comboBox_OBC_BikeCCS.Text + "\r\n");
  2364. }));
  2365. }
  2366. break;
  2367. }
  2368. case 0x5303://电机应答反馈
  2369. {
  2370. unchecked
  2371. {
  2372. this.Invoke((EventHandler)(delegate
  2373. {
  2374. MessageBoxTimeOut.Show("OK", "反馈指令", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  2375. }));
  2376. }
  2377. break;
  2378. }
  2379. case 0x5620: //用户骑行参数
  2380. {
  2381. unchecked
  2382. {
  2383. this.Invoke((EventHandler)(delegate
  2384. {
  2385. richTextBox_UsrRidesParam.Clear();
  2386. for (int i = 0; i < myParams.UsrRideParam.Count; i++)
  2387. {
  2388. richTextBox_UsrRidesParam.AppendText(myParams.UsrRideParam[i] + "=" + Convert.ToString(Data[i]) + ", ");
  2389. }
  2390. richTextBox_UsrRidesParam.Text = richTextBox_UsrRidesParam.Text.Substring(0, richTextBox_UsrRidesParam.Text.Length - 2);
  2391. }));
  2392. }
  2393. break;
  2394. }
  2395. default: break;
  2396. }
  2397. }
  2398. #endregion
  2399. }
  2400. private void DataRevToString(ushort CmdTemp, byte[] Data)
  2401. {
  2402. CmdRevStrTemp = "";
  2403. CmdRevStrTemp += Convert.ToString(CmdTemp >> 8, 16).PadLeft(2, '0').ToUpper() + " ";
  2404. CmdRevStrTemp += Convert.ToString(CmdTemp & 0xFF, 16).PadLeft(2, '0').ToUpper() + " ";
  2405. ushort len = (ushort)(CmdTemp & 0x00FF);
  2406. for (int i = 0; i < len ; i++)
  2407. {
  2408. CmdRevStrTemp += Convert.ToString(Data[i], 16).PadLeft(2, '0').ToUpper() + " ";
  2409. }
  2410. }
  2411. #endregion
  2412. /// <summary>
  2413. /// 端口连接或断开
  2414. /// </summary>
  2415. private void PortConnect()
  2416. {
  2417. bool result = false;
  2418. if (连接ToolStripMenuItem.Text == "连接")
  2419. {
  2420. result = mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, 连接开机ToolStripMenuItem.Checked, 识别通讯盒ToolStripMenuItem.Checked);
  2421. if (result)
  2422. {
  2423. toolStripComboBox_ComNum.Enabled = false;
  2424. toolStripComboBox_Baudrate.Enabled = false;
  2425. 刷新ToolStripMenuItem.Enabled = false;
  2426. 连接ToolStripMenuItem.Text = "断开";
  2427. 连接ToolStripMenuItem.Checked = true;
  2428. label_COM_Sta.Text = toolStripComboBox_ComNum.Text + "已连接," + toolStripComboBox_Baudrate.Text;
  2429. label_PortStatus.BackColor = Color.Green;
  2430. }
  2431. }
  2432. else if (连接ToolStripMenuItem.Text == "断开")
  2433. {
  2434. checkBox_OBC_StartSetGearSt.Checked = false;
  2435. checkBox_OBC_StartReadBMS.Checked = false;
  2436. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2437. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  2438. toolStripComboBox_ComNum.Enabled = true;
  2439. toolStripComboBox_Baudrate.Enabled = true;
  2440. 刷新ToolStripMenuItem.Enabled = true;
  2441. 连接ToolStripMenuItem.Text = "连接";
  2442. 连接ToolStripMenuItem.Checked = false;
  2443. label_COM_Sta.Text = "连接状态:未连接";
  2444. label_PortStatus.BackColor = Color.Red;
  2445. }
  2446. }
  2447. /// <summary>
  2448. /// 端口连接事件
  2449. /// </summary>
  2450. /// <param name="sender"></param>
  2451. /// <param name="e"></param>
  2452. private void 连接ToolStripMenuItem_Click(object sender, System.EventArgs e)
  2453. {
  2454. PortConnect();
  2455. }
  2456. /// <summary>
  2457. /// 端口号刷新事件
  2458. /// </summary>
  2459. /// <param name="sender"></param>
  2460. /// <param name="e"></param>
  2461. private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
  2462. {
  2463. toolStripComboBox_ComNum.Items.Clear();
  2464. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  2465. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
  2466. }
  2467. /// <summary>
  2468. /// 存储标志修改事件
  2469. /// </summary>
  2470. /// <param name="sender"></param>
  2471. /// <param name="e"></param>
  2472. private void 写入存储ToolStripMenuItem_Click(object sender, EventArgs e)
  2473. {
  2474. if (写入存储ToolStripMenuItem.Checked)
  2475. {
  2476. EnterForm1.ShowDialog();
  2477. try
  2478. {
  2479. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  2480. {
  2481. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  2482. {
  2483. 写入存储ToolStripMenuItem.Checked = false;
  2484. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  2485. }
  2486. else
  2487. {
  2488. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2489. }
  2490. }
  2491. else
  2492. {
  2493. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2494. }
  2495. }
  2496. catch (Exception)
  2497. {
  2498. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2499. }
  2500. }
  2501. else
  2502. {
  2503. 写入存储ToolStripMenuItem.Checked = true;
  2504. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  2505. }
  2506. }
  2507. /// <summary>
  2508. /// 1s定时器
  2509. /// </summary>
  2510. /// <param name="sender"></param>
  2511. /// <param name="e"></param>
  2512. private void timer_1s_Tick(object sender, EventArgs e)
  2513. {
  2514. //时间更新
  2515. label_SystemTime.Text = "系统时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2516. //MC_Runinfo超时清除
  2517. if (MC_RunInfo_Refresh == false)
  2518. {
  2519. MC_RunInfo_Refresh_Cnt++;
  2520. if (MC_RunInfo_Refresh_Cnt > 10)//5s
  2521. {
  2522. MC_RunInfo_Clear();
  2523. MC_RunInfo_Refresh_Cnt = 0;
  2524. }
  2525. }
  2526. else
  2527. {
  2528. MC_RunInfo_Refresh_Cnt = 0;
  2529. }
  2530. MC_RunInfo_Refresh = false;
  2531. //MC_Debuginfo超时清除
  2532. if (MC_DebugInfo_Refresh == false)
  2533. {
  2534. MC_DebugInfo_Refresh_Cnt++;
  2535. if (MC_DebugInfo_Refresh_Cnt > 10)//5s
  2536. {
  2537. MC_DebugInfo_Clear();
  2538. MC_DebugInfo_Refresh_Cnt = 0;
  2539. }
  2540. }
  2541. else
  2542. {
  2543. MC_DebugInfo_Refresh_Cnt = 0;
  2544. }
  2545. MC_DebugInfo_Refresh = false;
  2546. //BMS_RunInfo超时清除
  2547. if (BMS_RunInfo_Refresh == false)
  2548. {
  2549. BMS_RunInfo_Refresh_Cnt++;
  2550. if (BMS_RunInfo_Refresh_Cnt > 10)//5s
  2551. {
  2552. richTextBox_OBC_BMS_RunInfo.Clear();
  2553. BMS_RunInfo_Refresh_Cnt = 0;
  2554. }
  2555. }
  2556. else
  2557. {
  2558. BMS_RunInfo_Refresh_Cnt = 0;
  2559. }
  2560. BMS_RunInfo_Refresh = false;
  2561. //故障码超时清除
  2562. if (MC_ErrorCode_Refresh == false)
  2563. {
  2564. MC_ErrorCode_Refresh_Cnt++;
  2565. if (MC_ErrorCode_Refresh_Cnt > 10)//5s
  2566. {
  2567. textBox_ErrorCode.Text = "---";
  2568. MC_ErrorCode_Refresh_Cnt = 0;
  2569. }
  2570. }
  2571. else
  2572. {
  2573. MC_ErrorCode_Refresh_Cnt = 0;
  2574. }
  2575. MC_ErrorCode_Refresh = false;
  2576. //CDL连接超时
  2577. if (识别通讯盒ToolStripMenuItem.Checked)
  2578. {
  2579. if (mySerialProcess.CDL_Online_Flag == false)
  2580. {
  2581. mySerialProcess.CDL_OnlineCheck_Cnt++;
  2582. if (mySerialProcess.CDL_OnlineCheck_Cnt > 1)//1s
  2583. {
  2584. timer_500ms.Enabled = false;
  2585. MessageBox.Show("连接失败!", "提示");
  2586. timer_500ms.Enabled = true;
  2587. //关闭串口
  2588. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  2589. toolStripComboBox_ComNum.Enabled = true;
  2590. toolStripComboBox_Baudrate.Enabled = true;
  2591. 刷新ToolStripMenuItem.Enabled = true;
  2592. 连接ToolStripMenuItem.Text = "连接";
  2593. 连接ToolStripMenuItem.Checked = false;
  2594. label_COM_Sta.Text = "连接状态:未连接";
  2595. label_PortStatus.BackColor = Color.Red;
  2596. }
  2597. }
  2598. }
  2599. //OBC定时发送设置档位
  2600. if (checkBox_OBC_StartSetGearSt.Checked == true)
  2601. {
  2602. var CtrlCode = new byte[2];
  2603. if (comboBox_OBC_SetGearST.SelectedIndex == 5)//档位
  2604. CtrlCode[0] = 0x33;
  2605. else if (comboBox_OBC_SetGearST.SelectedIndex == 6)//档位
  2606. CtrlCode[0] = 0x22;
  2607. else
  2608. CtrlCode[0] = (byte)comboBox_OBC_SetGearST.SelectedIndex;
  2609. if (comboBox_OBC_LightSw.SelectedIndex == 0)//车灯
  2610. CtrlCode[1] = 0xF1;
  2611. else
  2612. CtrlCode[1] = 0xF0;
  2613. if (!mySerialProcess.SendCmdWithoutNotice((ushort)0x731, (byte)0x0C, (ushort)0x3002, CtrlCode))
  2614. {
  2615. checkBox_OBC_StartSetGearSt.Checked = false;
  2616. }
  2617. }
  2618. //OBC定时发送查询电池
  2619. if (checkBox_OBC_StartReadBMS.Checked == true)
  2620. {
  2621. if (!mySerialProcess.SendCmd((ushort)0x732, (byte)0x11, (ushort)0x5000, null))
  2622. {
  2623. checkBox_OBC_StartReadBMS.Checked = false;
  2624. }
  2625. }
  2626. //定时读取存储器
  2627. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  2628. {
  2629. var Address = new byte[4];
  2630. UInt32 Address_Begin;
  2631. UInt32 Addres_End;
  2632. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  2633. richTextBox_RamFlasgData.Clear();
  2634. do
  2635. {
  2636. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  2637. {
  2638. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2639. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2640. continue;
  2641. }
  2642. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  2643. {
  2644. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2645. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2646. continue;
  2647. }
  2648. else
  2649. {
  2650. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  2651. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2652. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  2653. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2654. if (Addres_End < Address_Begin)
  2655. {
  2656. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2657. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2658. continue;
  2659. }
  2660. else
  2661. {
  2662. var SendByte = new byte[8];
  2663. SendByte[0] = (byte)(Address_Begin >> 24);
  2664. SendByte[1] = (byte)(Address_Begin >> 16);
  2665. SendByte[2] = (byte)(Address_Begin >> 8);
  2666. SendByte[3] = (byte)(Address_Begin);
  2667. SendByte[4] = (byte)(Addres_End >> 24);
  2668. SendByte[5] = (byte)(Addres_End >> 16);
  2669. SendByte[6] = (byte)(Addres_End >> 8);
  2670. SendByte[7] = (byte)(Addres_End);
  2671. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte))
  2672. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2673. }
  2674. }
  2675. } while (false);
  2676. }
  2677. //写入参数等待计时
  2678. ACK_WaitCnt++;
  2679. }
  2680. /// <summary>
  2681. /// 运行信息清除
  2682. /// </summary>
  2683. private void MC_RunInfo_Clear()
  2684. {
  2685. foreach (Control c in tabPage_RunInfo.Controls)
  2686. {
  2687. if ((c is TextBox))
  2688. {
  2689. if (c.Name != textBox_ErrorCode.ToString())
  2690. c.Text = "---";
  2691. }
  2692. }
  2693. }
  2694. /// <summary>
  2695. /// 调试信息清除
  2696. /// </summary>
  2697. private void MC_DebugInfo_Clear()
  2698. {
  2699. foreach (Control c in tabPage_DebugInfo.Controls)
  2700. {
  2701. if ((c is TextBox))
  2702. {
  2703. if (c.Name != textBox_ErrorCode.ToString())
  2704. c.Text = "---";
  2705. }
  2706. }
  2707. }
  2708. /// <summary>
  2709. /// 读取马达参数
  2710. /// </summary>
  2711. /// <param name="sender"></param>
  2712. /// <param name="e"></param>
  2713. private void button_Read_MotorParam_Click(object sender, EventArgs e)
  2714. {
  2715. richTextBox_MotorParam.Clear();
  2716. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null);
  2717. }
  2718. /// <summary>
  2719. /// 写入马达参数
  2720. /// </summary>
  2721. /// <param name="sender"></param>
  2722. /// <param name="e"></param>
  2723. private void button_Write_Click(object sender, EventArgs e)
  2724. {
  2725. var ConfigParam = new byte[40];
  2726. for (int i = 0; i < 40; i++)
  2727. ConfigParam[i] = 0;
  2728. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2729. short wDataTemp = 0;
  2730. ushort DataTemp = 0;
  2731. string[] strDataTemp = richTextBox_MotorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2732. try
  2733. {
  2734. for (int i = 0; i < strDataTemp.Length; i++)
  2735. {
  2736. if (i == 6)
  2737. {
  2738. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  2739. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  2740. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  2741. }
  2742. else
  2743. {
  2744. DataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2745. ConfigParam[2 * i + 2] = (byte)DataTemp;
  2746. ConfigParam[2 * i + 3] = (byte)(DataTemp >> 8);
  2747. }
  2748. }
  2749. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B28, ConfigParam);
  2750. }
  2751. catch (Exception)
  2752. {
  2753. timer_500ms.Enabled = false;
  2754. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2755. timer_500ms.Enabled = true;
  2756. }
  2757. }
  2758. /// <summary>
  2759. /// 读取整车信息
  2760. /// </summary>
  2761. /// <param name="sender"></param>
  2762. /// <param name="e"></param>
  2763. private void button_ReadBikeParam_Click(object sender, EventArgs e)
  2764. {
  2765. richTextBox_BikeParam.Clear();
  2766. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null);
  2767. }
  2768. /// <summary>
  2769. /// 写入整车信息
  2770. /// </summary>
  2771. /// <param name="sender"></param>
  2772. /// <param name="e"></param>
  2773. private void button_WriteBikeParam_Click(object sender, EventArgs e)
  2774. {
  2775. var ConfigParam = new byte[28];
  2776. for (int i = 0; i < 28; i++)
  2777. ConfigParam[i] = 0;
  2778. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2779. string[] strDataTemp = richTextBox_BikeParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2780. try
  2781. {
  2782. for (int i = 0; i < strDataTemp.Length; i++)
  2783. {
  2784. short wDataTemp = 0;
  2785. //前后灯参数修改
  2786. if (i == 8)
  2787. {
  2788. wDataTemp |= (short)((comboBox_TailLightMode.SelectedIndex + 1) << 12); //Bit15~Bit12:尾灯模式
  2789. wDataTemp |= (short)((comboBox_TailLightVol.SelectedIndex == 0 ? 6 : 12) << 8); //Bit11~Bit8:尾灯电压
  2790. wDataTemp |= (short)(comboBox_FrontLightVol.SelectedIndex == 0 ? 6 : 12); //Bit7~Bit0:前灯电压
  2791. }
  2792. //开关机参数
  2793. else if (i == 11)
  2794. {
  2795. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOnDelay.Text) << 12);
  2796. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOffDelay.Text) << 8);
  2797. wDataTemp |= (short)(Convert.ToInt16(textBox_AutoPowerOff.Text));
  2798. }
  2799. else
  2800. {
  2801. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  2802. }
  2803. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  2804. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  2805. }
  2806. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D1C, ConfigParam);
  2807. }
  2808. catch (Exception)
  2809. {
  2810. timer_500ms.Enabled = false;
  2811. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2812. timer_500ms.Enabled = true;
  2813. }
  2814. }
  2815. /// <summary>
  2816. /// 读取控制器参数
  2817. /// </summary>
  2818. /// <param name="sender"></param>
  2819. /// <param name="e"></param>
  2820. private void button_ReadControlParam_Click(object sender, EventArgs e)
  2821. {
  2822. richTextBox_ControlParam.Clear();
  2823. comboBox_Bike_CCS.SelectedIndex = 0;
  2824. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
  2825. }
  2826. /// <summary>
  2827. /// 写入控制器参数
  2828. /// </summary>
  2829. /// <param name="sender"></param>
  2830. /// <param name="e"></param>
  2831. private void button_WriteControlParam_Click(object sender, EventArgs e)
  2832. {
  2833. var ConfigParam = new byte[34];
  2834. for (int i = 0; i < 34; i++)
  2835. ConfigParam[i] = 0;
  2836. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2837. ushort uwDataTemp = 0;
  2838. string[] strDataTemp = richTextBox_ControlParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2839. try
  2840. {
  2841. for (int i = 0; i < strDataTemp.Length; i++)
  2842. {
  2843. if (i == 13)
  2844. {
  2845. uwDataTemp = (comboBox_Bike_CCS.SelectedIndex == 1) ? (ushort)0x00AA : (ushort)0x0000;
  2846. }
  2847. else
  2848. {
  2849. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2850. }
  2851. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2852. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2853. }
  2854. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3F22, ConfigParam);
  2855. }
  2856. catch (Exception)
  2857. {
  2858. timer_500ms.Enabled = false;
  2859. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2860. timer_500ms.Enabled = true;
  2861. }
  2862. }
  2863. /// <summary>
  2864. /// 读取助力参数
  2865. /// </summary>
  2866. /// <param name="sender"></param>
  2867. /// <param name="e"></param>
  2868. private void button_ReadAssistParam_Click(object sender, EventArgs e)
  2869. {
  2870. var ConfigParam = new byte[4];
  2871. int AssistNum = 0;
  2872. try
  2873. {
  2874. AssistNum = Convert.ToInt32(comboBox_AssistTorque.Text);
  2875. ConfigParam[0] = (byte)(AssistNum & 0xFF);
  2876. ConfigParam[1] = (byte)(AssistNum >> 8);
  2877. AssistNum = Convert.ToInt32(comboBox_AssistCadence.Text);
  2878. ConfigParam[2] = (byte)(AssistNum & 0xFF);
  2879. ConfigParam[3] = (byte)(AssistNum >> 8);
  2880. richTextBox_AssistParam.Clear();
  2881. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam);
  2882. }
  2883. catch (Exception)
  2884. {
  2885. timer_500ms.Enabled = false;
  2886. MessageBox.Show("请选择助力参数编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2887. timer_500ms.Enabled = true;
  2888. }
  2889. }
  2890. /// <summary>
  2891. /// 写入助力参数
  2892. /// </summary>
  2893. /// <param name="sender"></param>
  2894. /// <param name="e"></param>
  2895. private void button_WriteAssistParam_Click(object sender, EventArgs e)
  2896. {
  2897. var ConfigParam = new byte[80];
  2898. for (int i = 0; i < 80; i++)
  2899. ConfigParam[i] = 0;
  2900. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2901. long lDataTemp = 0;
  2902. string[] strDataTemp = richTextBox_AssistParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2903. int index_1 = 0, index_2 = 0;
  2904. try
  2905. {
  2906. for (int i = 0; i < strDataTemp.Length; i++)
  2907. {
  2908. if (strDataTemp[i].Split('=')[0] == "转矩曲线.a")
  2909. {
  2910. index_1 = i;
  2911. break;
  2912. }
  2913. }
  2914. for (int i = 0; i < strDataTemp.Length; i++)
  2915. {
  2916. if (strDataTemp[i].Split('=')[0] == "踏频曲线.d")
  2917. {
  2918. index_2 = i;
  2919. break;
  2920. }
  2921. }
  2922. for (int i = 0; i < strDataTemp.Length; i++)
  2923. {
  2924. lDataTemp = Convert.ToInt32(strDataTemp[i].Split('=')[1]);
  2925. if (i < index_1)
  2926. {
  2927. ConfigParam[2 * i + 4] = (byte)lDataTemp;
  2928. ConfigParam[2 * i + 5] = (byte)(lDataTemp >> 8);
  2929. }
  2930. else if (i <= index_2)
  2931. {
  2932. ConfigParam[4 * i - 4] = (byte)lDataTemp;
  2933. ConfigParam[4 * i - 3] = (byte)(lDataTemp >> 8);
  2934. ConfigParam[4 * i - 2] = (byte)(lDataTemp >> 16);
  2935. ConfigParam[4 * i - 1] = (byte)(lDataTemp >> 24);
  2936. }
  2937. else
  2938. {
  2939. ConfigParam[2 * i + 20] = (byte)lDataTemp;
  2940. ConfigParam[2 * i + 21] = (byte)(lDataTemp >> 8);
  2941. }
  2942. }
  2943. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4450, ConfigParam);
  2944. }
  2945. catch (Exception)
  2946. {
  2947. timer_500ms.Enabled = false;
  2948. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2949. timer_500ms.Enabled = true;
  2950. }
  2951. }
  2952. /// <summary>
  2953. /// 读取调试参数
  2954. /// </summary>
  2955. /// <param name="sender"></param>
  2956. /// <param name="e"></param>
  2957. private void button_ReadDebugParam_Click(object sender, EventArgs e)
  2958. {
  2959. richTextBox_DebugParam.Clear();
  2960. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  2961. }
  2962. /// <summary>
  2963. /// 写入调试参数
  2964. /// </summary>
  2965. /// <param name="sender"></param>
  2966. /// <param name="e"></param>
  2967. private void button_WriteDebugParam_Click(object sender, EventArgs e)
  2968. {
  2969. var ConfigParam = new byte[60];
  2970. for (int i = 0; i < 60; i++)
  2971. ConfigParam[i] = 0;
  2972. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2973. ushort uwDataTemp = 0;
  2974. string[] strDataTemp = richTextBox_DebugParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2975. try
  2976. {
  2977. for (int i = 0; i < strDataTemp.Length; i++)
  2978. {
  2979. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2980. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2981. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2982. }
  2983. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam);
  2984. }
  2985. catch (Exception)
  2986. {
  2987. timer_500ms.Enabled = false;
  2988. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2989. timer_500ms.Enabled = true;
  2990. }
  2991. }
  2992. /// <summary>
  2993. /// 读取历史
  2994. /// </summary>
  2995. /// <param name="sender"></param>
  2996. /// <param name="e"></param>
  2997. private void button_ReadRecord_Click(object sender, EventArgs e)
  2998. {
  2999. richTextBox_Record.Clear();
  3000. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null);
  3001. }
  3002. /// <summary>
  3003. /// 读取传感器参数
  3004. /// </summary>
  3005. /// <param name="sender"></param>
  3006. /// <param name="e"></param>
  3007. private void button_ReadSensorParam_Click(object sender, EventArgs e)
  3008. {
  3009. richTextBox_SensorParam.Clear();
  3010. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3011. }
  3012. /// <summary>
  3013. /// 写入力矩传感器标定值
  3014. /// </summary>
  3015. /// <param name="sender"></param>
  3016. /// <param name="e"></param>
  3017. private void button_Write_Cal_Click(object sender, EventArgs e)
  3018. {
  3019. var ConfigParam = new byte[4];
  3020. for (int i = 0; i < 4; i++)
  3021. ConfigParam[i] = 0;
  3022. ushort uwDataTemp = 0;
  3023. try
  3024. {
  3025. uwDataTemp = Convert.ToUInt16(comboBox_TorqueSet.Text);//负载序号
  3026. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  3027. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  3028. uwDataTemp = (ushort)(decimal.Parse(textBox_Load.Text) * 10); ;//负载值0.1Nm
  3029. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  3030. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  3031. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  3032. }
  3033. catch (Exception)
  3034. {
  3035. timer_500ms.Enabled = false;
  3036. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3037. timer_500ms.Enabled = true;
  3038. }
  3039. }
  3040. /// <summary>
  3041. /// 写入传感器参数
  3042. /// </summary>
  3043. /// <param name="sender"></param>
  3044. /// <param name="e"></param>
  3045. private void button_WriteSensorParam_Click(object sender, EventArgs e)
  3046. {
  3047. var ConfigParam = new byte[14];
  3048. for (int i = 0; i < 14; i++)
  3049. ConfigParam[i] = 0;
  3050. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  3051. ushort uwDataTemp = 0;
  3052. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  3053. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  3054. int index = 0;
  3055. try
  3056. {
  3057. for (int i = 0; i < strDataTemp.Length; i++)
  3058. {
  3059. if (strDataTemp[i].Split('=')[0] == "力矩传感器踏频脉冲数")
  3060. {
  3061. index = i;
  3062. break;
  3063. }
  3064. }
  3065. for (int i = 0; i < (strDataTemp.Length - index); i++)
  3066. {
  3067. uwDataTemp = Convert.ToUInt16(strDataTemp[i + index].Split('=')[1]);
  3068. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3069. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3070. }
  3071. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x420E, ConfigParam);
  3072. }
  3073. catch (Exception)
  3074. {
  3075. timer_500ms.Enabled = false;
  3076. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3077. timer_500ms.Enabled = true;
  3078. }
  3079. }
  3080. /// <summary>
  3081. /// 写入型号
  3082. /// </summary>
  3083. /// <param name="sender"></param>
  3084. /// <param name="e"></param>
  3085. private void button_WriteModel_Click(object sender, EventArgs e)
  3086. {
  3087. string Mode = textBox_Model.Text;
  3088. var ModeArray = new byte[16];
  3089. for (ushort i = 0; i < Mode.Length; i++)
  3090. {
  3091. ModeArray[i] = (byte)Mode[i];
  3092. }
  3093. if (Mode.Length < 16)
  3094. {
  3095. ModeArray[Mode.Length] = (byte)'.';
  3096. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  3097. {
  3098. ModeArray[Mode.Length + 1 + i] = 0x20;
  3099. }
  3100. }
  3101. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  3102. }
  3103. /// <summary>
  3104. /// 写入SN
  3105. /// </summary>
  3106. /// <param name="sender"></param>
  3107. /// <param name="e"></param>
  3108. private void button_WriteSN_Click(object sender, EventArgs e)
  3109. {
  3110. string SN = textBox_SN.Text;
  3111. var SNArray = new byte[16];
  3112. for (ushort i = 0; i < SN.Length; i++)
  3113. {
  3114. SNArray[i] = (byte)SN[i];
  3115. }
  3116. if (SN.Length < 16)
  3117. {
  3118. SNArray[SN.Length] = (byte)'.';
  3119. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  3120. {
  3121. SNArray[SN.Length + 1 + i] = 0x20;
  3122. }
  3123. }
  3124. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  3125. }
  3126. /// <summary>
  3127. /// 查询版本信息
  3128. /// </summary>
  3129. /// <param name="sender"></param>
  3130. /// <param name="e"></param>
  3131. private void button_ReadVersion_Click(object sender, EventArgs e)
  3132. {
  3133. textBox_Model.Text = "---";
  3134. textBox_SN.Text = "---";
  3135. textBox_HW.Text = "---";
  3136. textBox_FW.Text = "---";
  3137. textBox_SP.Text = "---";
  3138. textBox_OBC_ReadModel.Text = "---";
  3139. textBox_OBC_ReadSN.Text = "---";
  3140. textBox_OBC_ReadHW.Text = "---";
  3141. textBox_OBC_ReadFW.Text = "---";
  3142. textBox_OBC_ReadSP.Text = "---";
  3143. textBox_FacModeName.Text = "---";
  3144. textBox_FacModeNum.Text = "---";
  3145. textBox_FacModeHW.Text = "---";
  3146. textBox_FacModeFW.Text = "---";
  3147. textBox_FacModeSP.Text = "---";
  3148. Class_Motor_Ver.Mode = "---";
  3149. Class_Motor_Ver.SN = "---";
  3150. Class_Motor_Ver.HW = "---";
  3151. Class_Motor_Ver.FW = "---";
  3152. Class_Motor_Ver.Special = "---";
  3153. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  3154. }
  3155. /// <summary>
  3156. /// 查询自定义1
  3157. /// </summary>
  3158. /// <param name="sender"></param>
  3159. /// <param name="e"></param>
  3160. private void button_ReadUser1_Click(object sender, EventArgs e)
  3161. {
  3162. textBox_User1.Text = "---";
  3163. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null);
  3164. }
  3165. /// <summary>
  3166. /// 查询自定义2
  3167. /// </summary>
  3168. /// <param name="sender"></param>
  3169. /// <param name="e"></param>
  3170. private void button_ReadUser2_Click(object sender, EventArgs e)
  3171. {
  3172. textBox_User2.Text = "---";
  3173. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null);
  3174. }
  3175. /// <summary>
  3176. /// 查询自定义3
  3177. /// </summary>
  3178. /// <param name="sender"></param>
  3179. /// <param name="e"></param>
  3180. private void button_ReadUser3_Click(object sender, EventArgs e)
  3181. {
  3182. textBox_User3.Text = "---";
  3183. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null);
  3184. }
  3185. /// <summary>
  3186. /// 写入自定义字符串1
  3187. /// </summary>
  3188. /// <param name="sender"></param>
  3189. /// <param name="e"></param>
  3190. private void button_WriteUser1_Click(object sender, EventArgs e)
  3191. {
  3192. string User = textBox_User1.Text;
  3193. var UserArray = new byte[16];
  3194. for (ushort i = 0; i < User.Length; i++)
  3195. {
  3196. UserArray[i] = (byte)User[i];
  3197. }
  3198. if (User.Length < 16)
  3199. {
  3200. UserArray[User.Length] = (byte)'.';
  3201. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3202. {
  3203. UserArray[User.Length + 1 + i] = 0x20;
  3204. }
  3205. }
  3206. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1410, UserArray);
  3207. }
  3208. /// <summary>
  3209. /// 写入自定义字符串2
  3210. /// </summary>
  3211. /// <param name="sender"></param>
  3212. /// <param name="e"></param>
  3213. private void button_WriteUser2_Click(object sender, EventArgs e)
  3214. {
  3215. string User = textBox_User2.Text;
  3216. var UserArray = new byte[16];
  3217. for (ushort i = 0; i < User.Length; i++)
  3218. {
  3219. UserArray[i] = (byte)User[i];
  3220. }
  3221. if (User.Length < 16)
  3222. {
  3223. UserArray[User.Length] = (byte)'.';
  3224. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3225. {
  3226. UserArray[User.Length + 1 + i] = 0x20;
  3227. }
  3228. }
  3229. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1610, UserArray);
  3230. }
  3231. /// <summary>
  3232. /// 写入自定义字符串3
  3233. /// </summary>
  3234. /// <param name="sender"></param>
  3235. /// <param name="e"></param>
  3236. private void button_WriteUser3_Click(object sender, EventArgs e)
  3237. {
  3238. string User = textBox_User3.Text;
  3239. var UserArray = new byte[16];
  3240. for (ushort i = 0; i < User.Length; i++)
  3241. {
  3242. UserArray[i] = (byte)User[i];
  3243. }
  3244. if (User.Length < 16)
  3245. {
  3246. UserArray[User.Length] = (byte)'.';
  3247. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3248. {
  3249. UserArray[User.Length + 1 + i] = 0x20;
  3250. }
  3251. }
  3252. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1810, UserArray);
  3253. }
  3254. /// <summary>
  3255. /// 查询生产信息
  3256. /// </summary>
  3257. /// <param name="sender"></param>
  3258. /// <param name="e"></param>
  3259. private void button_ReadMAC_Click(object sender, EventArgs e)
  3260. {
  3261. textBox_MAC.Text = "---";
  3262. textBox_MACAdd.Text = "---";
  3263. textBox_MACDate.Text = "---";
  3264. textBox_PP.Text = "---";
  3265. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null);
  3266. }
  3267. /// <summary>
  3268. /// 写入生产信息
  3269. /// </summary>
  3270. /// <param name="sender"></param>
  3271. /// <param name="e"></param>
  3272. private void button_WriteMac_Click(object sender, EventArgs e)
  3273. {
  3274. var MACArray = new byte[32];
  3275. //填入生产商
  3276. for (ushort i = 0; i < textBox_MAC.Text.Length; i++)
  3277. {
  3278. MACArray[i] = (byte)textBox_MAC.Text[i];
  3279. }
  3280. if (textBox_MAC.Text.Length < 8)
  3281. {
  3282. MACArray[textBox_MAC.Text.Length] = (byte)'.';
  3283. for (ushort i = 0; i < 8 - textBox_MAC.Text.Length - 1; i++)
  3284. {
  3285. MACArray[textBox_MAC.Text.Length + 1 + i] = 0x20;
  3286. }
  3287. }
  3288. //填入生产地
  3289. for (ushort i = 0; i < textBox_MACAdd.Text.Length; i++)
  3290. {
  3291. MACArray[8 + i] = (byte)textBox_MACAdd.Text[i];
  3292. }
  3293. if (textBox_MACAdd.Text.Length < 8)
  3294. {
  3295. MACArray[textBox_MACAdd.Text.Length + 8] = (byte)'.';
  3296. for (ushort i = 0; i < 8 - textBox_MACAdd.Text.Length - 1; i++)
  3297. {
  3298. MACArray[textBox_MACAdd.Text.Length + 1 + i + 8] = 0x20;
  3299. }
  3300. }
  3301. //填入生产日期
  3302. for (ushort i = 0; i < textBox_MACDate.Text.Length; i++)
  3303. {
  3304. MACArray[16 + i] = (byte)textBox_MACDate.Text[i];
  3305. }
  3306. if (textBox_MACDate.Text.Length < 8)
  3307. {
  3308. MACArray[textBox_MACDate.Text.Length + 16] = (byte)'.';
  3309. for (ushort i = 0; i < 8 - textBox_MACDate.Text.Length - 1; i++)
  3310. {
  3311. MACArray[textBox_MACDate.Text.Length + 1 + i + 16] = 0x20;
  3312. }
  3313. }
  3314. //填入品牌
  3315. for (ushort i = 0; i < textBox_PP.Text.Length; i++)
  3316. {
  3317. MACArray[24 + i] = (byte)textBox_PP.Text[i];
  3318. }
  3319. if (textBox_PP.Text.Length < 8)
  3320. {
  3321. MACArray[textBox_PP.Text.Length + 24] = (byte)'.';
  3322. for (ushort i = 0; i < 8 - textBox_PP.Text.Length - 1; i++)
  3323. {
  3324. MACArray[textBox_PP.Text.Length + 1 + i + 24] = 0x20;
  3325. }
  3326. }
  3327. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  3328. }
  3329. /// <summary>
  3330. /// 查询密钥
  3331. /// </summary>
  3332. /// <param name="sender"></param>
  3333. /// <param name="e"></param>
  3334. private void button_ReadKey_Click(object sender, EventArgs e)
  3335. {
  3336. textBox_Key.Text = "---";
  3337. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null);
  3338. }
  3339. /// <summary>
  3340. /// 写入校验密钥
  3341. /// </summary>
  3342. /// <param name="sender"></param>
  3343. /// <param name="e"></param>
  3344. private void button_WriteKey_Click(object sender, EventArgs e)
  3345. {
  3346. string Key = textBox_Key.Text;
  3347. var KeyArray = new byte[8];
  3348. if (Key.Length != 8)
  3349. {
  3350. timer_500ms.Enabled = false;
  3351. MessageBox.Show("请检查字符长度是否为8", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3352. timer_500ms.Enabled = true;
  3353. return;
  3354. }
  3355. for (ushort i = 0; i < Key.Length; i++)
  3356. {
  3357. KeyArray[i] = (byte)Key[i];
  3358. }
  3359. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1108, KeyArray);
  3360. }
  3361. /// <summary>
  3362. /// 查询在线检测结果
  3363. /// </summary>
  3364. /// <param name="sender"></param>
  3365. /// <param name="e"></param>
  3366. private void button_ReadOnLine_Click(object sender, EventArgs e)
  3367. {
  3368. textBox_Online.Text = "---";
  3369. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2100, null);
  3370. }
  3371. /// <summary>
  3372. /// 系统清除
  3373. /// </summary>
  3374. /// <param name="sender"></param>
  3375. /// <param name="e"></param>
  3376. private void button_SystemClear_Click(object sender, EventArgs e)
  3377. {
  3378. var Code = new byte[5];
  3379. Code[0] = (byte)'C';
  3380. Code[1] = (byte)'L';
  3381. Code[2] = (byte)'E';
  3382. Code[3] = (byte)'A';
  3383. Code[4] = (byte)'R';
  3384. timer_500ms.Enabled = false;
  3385. if (MessageBox.Show("系统清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3386. {
  3387. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3388. {
  3389. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3390. {
  3391. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  3392. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3393. }
  3394. }
  3395. }
  3396. timer_500ms.Enabled = true;
  3397. }
  3398. /// <summary>
  3399. /// 参数还原
  3400. /// </summary>
  3401. /// <param name="sender"></param>
  3402. /// <param name="e"></param>
  3403. private void button_Recovery_Click(object sender, EventArgs e)
  3404. {
  3405. var Code = new byte[8];
  3406. Code[0] = (byte)'R';
  3407. Code[1] = (byte)'E';
  3408. Code[2] = (byte)'C';
  3409. Code[3] = (byte)'O';
  3410. Code[4] = (byte)'V';
  3411. Code[5] = (byte)'E';
  3412. Code[6] = (byte)'R';
  3413. Code[7] = (byte)'Y';
  3414. timer_500ms.Enabled = false;
  3415. if (MessageBox.Show("参数还原后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3416. {
  3417. if (MessageBox.Show("请再次确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3418. {
  3419. if (MessageBox.Show("请最后确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3420. {
  3421. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2708, Code);
  3422. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3423. }
  3424. }
  3425. }
  3426. timer_500ms.Enabled = true;
  3427. }
  3428. /// <summary>
  3429. /// 系统复位
  3430. /// </summary>
  3431. /// <param name="sender"></param>
  3432. /// <param name="e"></param>
  3433. private void button_Reset_Click(object sender, EventArgs e)
  3434. {
  3435. var Code_Off = new byte[5];
  3436. var Code_Reset = new byte[5];
  3437. Code_Off[0] = (byte)'O';
  3438. Code_Off[1] = (byte)'F';
  3439. Code_Off[2] = (byte)'F';
  3440. Code_Off[3] = (byte)'.';
  3441. Code_Off[4] = (byte)'.';
  3442. Code_Reset[0] = (byte)'R';
  3443. Code_Reset[1] = (byte)'E';
  3444. Code_Reset[2] = (byte)'S';
  3445. Code_Reset[3] = (byte)'E';
  3446. Code_Reset[4] = (byte)'T';
  3447. timer_500ms.Enabled = false;
  3448. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3449. {
  3450. timer_500ms.Enabled = true;
  3451. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  3452. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  3453. PowerOffAckStatus = false;
  3454. Delay_ms(250);
  3455. int TryCnt = 3;
  3456. while ((TryCnt--) >= 0)
  3457. {
  3458. if (!PowerOffAckStatus)
  3459. {
  3460. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  3461. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  3462. PowerOffAckStatus = false;
  3463. Delay_ms(250);
  3464. }
  3465. else break;
  3466. }
  3467. if (PowerOffAckStatus)
  3468. {
  3469. MessageBoxTimeOut.Show("已关机!", "提示", 3000, MessageBoxButtons.OK, MessageBoxIcon.None);
  3470. }
  3471. else
  3472. {
  3473. timer_500ms.Enabled = false;
  3474. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3475. timer_500ms.Enabled = true;
  3476. }
  3477. }
  3478. timer_500ms.Enabled = true;
  3479. }
  3480. /// <summary>
  3481. /// 记录清除
  3482. /// </summary>
  3483. /// <param name="sender"></param>
  3484. /// <param name="e"></param>
  3485. private void button_ClearLog_Click(object sender, EventArgs e)
  3486. {
  3487. var Code = new byte[9];
  3488. Code[0] = (byte)'L';
  3489. Code[1] = (byte)'O';
  3490. Code[2] = (byte)'G';
  3491. Code[3] = (byte)' ';
  3492. Code[4] = (byte)'C';
  3493. Code[5] = (byte)'L';
  3494. Code[6] = (byte)'E';
  3495. Code[7] = (byte)'A';
  3496. Code[8] = (byte)'R';
  3497. timer_500ms.Enabled = false;
  3498. if (MessageBox.Show("历史记录信息清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3499. {
  3500. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3501. {
  3502. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3503. {
  3504. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3909, Code);
  3505. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3506. }
  3507. }
  3508. }
  3509. timer_500ms.Enabled = true;
  3510. }
  3511. /// <summary>
  3512. /// 打开系统计算器
  3513. /// </summary>
  3514. /// <param name="sender"></param>
  3515. /// <param name="e"></param>
  3516. private void 计算器ToolStripMenuItem_Click(object sender, EventArgs e)
  3517. {
  3518. System.Diagnostics.Process.Start("calc.exe");
  3519. }
  3520. /// <summary>
  3521. ///故障转换和显示
  3522. /// </summary>
  3523. List<string> ErrorInfo = new List<string>{ "过流保护", "低压保护", "过压保护", "堵转保护","过热保护","速度传感器故障","力矩传感器故障","霍尔故障",
  3524. "马达缺相","NTC故障","BMS校验失败","","OBC校验失败","MCU故障","踏频传感器故障","指拨故障","MOS短路","电压异常","","","","","","","","","","","","",
  3525. "",""};
  3526. private string ErrorInfoDisplay(UInt32 Code)
  3527. {
  3528. string Result = "";
  3529. if (Code == 0)
  3530. {
  3531. Result = "无故障";
  3532. }
  3533. else
  3534. {
  3535. for (int i = 0; i < 32; i++)
  3536. {
  3537. if ((Code & 0x01) == 0x01)
  3538. {
  3539. Result += ErrorInfo[i] + " ";
  3540. }
  3541. Code >>= 1;
  3542. }
  3543. }
  3544. return Result;
  3545. }
  3546. /// <summary>
  3547. /// 鼠标滑过故障码显示具体内容
  3548. /// </summary>
  3549. /// <param name="sender"></param>
  3550. /// <param name="e"></param>
  3551. private void textBox_ErrorCode_MouseHover(object sender, EventArgs e)
  3552. {
  3553. // 创建the ToolTip
  3554. ToolTip toolTip1 = new ToolTip();
  3555. // 设置显示样式
  3556. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  3557. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  3558. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  3559. toolTip1.ShowAlways = true;//是否显示提示框
  3560. // 设置伴随的对象.
  3561. string ErrorCode = this.textBox_ErrorCode.Text;
  3562. UInt32 Code = ErrorCode.Contains("H") ? Convert.ToUInt32(ErrorCode.Split('H')[0], 16) : 0;
  3563. toolTip1.SetToolTip(this.textBox_ErrorCode, ErrorInfoDisplay(Code));//设置故障内容显示
  3564. }
  3565. /// <summary>
  3566. /// 数据记录
  3567. /// </summary>
  3568. private void RunInfoAutoSave()
  3569. {
  3570. if (运行信息记录ToolStripMenuItem.Checked == true)
  3571. {
  3572. if (RunInfoSaveFilename == string.Empty)
  3573. {
  3574. return;
  3575. }
  3576. string SaveData = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff").Replace(" ", "_") + " --> ";
  3577. foreach (Control c in tabPage_RunInfo.Controls)
  3578. {
  3579. if (c is TextBox)
  3580. {
  3581. SaveData += c.Text + " , ";
  3582. }
  3583. }
  3584. foreach (Control c in tabPage_DebugInfo.Controls)
  3585. {
  3586. if (c is TextBox)
  3587. {
  3588. SaveData += c.Text + " , ";
  3589. }
  3590. }
  3591. SaveData += "\r\n";
  3592. System.IO.File.AppendAllText(RunInfoSaveFilename, SaveData);//sb.ToString());
  3593. }
  3594. }
  3595. /// <summary>
  3596. /// 打开或关闭数据记录
  3597. /// </summary>
  3598. /// <param name="sender"></param>
  3599. /// <param name="e"></param>
  3600. private void 记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  3601. {
  3602. if (运行信息记录ToolStripMenuItem.Checked == false)
  3603. {
  3604. if (mySerialProcess.mySerial.IsOpen == true)
  3605. {
  3606. RunInfoSaveFilename = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_运行信息" + ".txt";
  3607. System.IO.File.AppendAllText(RunInfoSaveFilename, "时间 --> 车速 , 转速 , 踏频 , 力矩Reg , 力矩 , 踩踏方向 , 电压 , 电流 , 功率 , 电量 , " +
  3608. "PCB温度 , 绕组温度 , MOS温度 , 挡位 , 灯开关 , 续航 , 平均功耗 , 单次里程 , 单次时间 , 故障码 , " +
  3609. "系统状态机 , 二层状态机 , 电机状态机 , 助力状态机 , D轴电流给定 , Q轴电流给定 , D轴电压给定 , Q轴电压给定 , 瞬时力矩 , 时间滤波力矩 , 踏频滤波力矩 , D轴电流反馈 , Q轴电流反馈 , 助力函数输出" + "\r\n");
  3610. MessageBoxTimeOut.Show("开始记录", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  3611. 运行信息记录ToolStripMenuItem.Checked = true;
  3612. }
  3613. else
  3614. {
  3615. timer_500ms.Enabled = false;
  3616. MessageBox.Show("请连接电机", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3617. timer_500ms.Enabled = true;
  3618. }
  3619. }
  3620. else
  3621. {
  3622. 运行信息记录ToolStripMenuItem.Checked = false;
  3623. MessageBoxTimeOut.Show("停止记录", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  3624. }
  3625. }
  3626. /// <summary>
  3627. /// 仪表启动控制档位开关事件
  3628. /// </summary>
  3629. /// <param name="sender"></param>
  3630. /// <param name="e"></param>
  3631. private void checkBox_OBC_StartSetGearSt_CheckedChanged(object sender, EventArgs e)
  3632. {
  3633. if (checkBox_OBC_StartSetGearSt.Checked == true)
  3634. {
  3635. //检查串口是否打开
  3636. if (!mySerialProcess.mySerial.IsOpen)
  3637. {
  3638. timer_500ms.Enabled = false;
  3639. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3640. timer_500ms.Enabled = true;
  3641. checkBox_OBC_StartSetGearSt.Checked = false;
  3642. return;
  3643. }
  3644. //检查是否选择档位和打开车灯
  3645. if ((comboBox_OBC_SetGearST.SelectedIndex == -1) || (comboBox_OBC_LightSw.SelectedIndex == -1))
  3646. {
  3647. timer_500ms.Enabled = false;
  3648. MessageBox.Show("请检查档位设置和大灯开关!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3649. timer_500ms.Enabled = true;
  3650. checkBox_OBC_StartSetGearSt.Checked = false;
  3651. return;
  3652. }
  3653. }
  3654. }
  3655. /// <summary>
  3656. /// OBC查询电机用户参数
  3657. /// </summary>
  3658. /// <param name="sender"></param>
  3659. /// <param name="e"></param>
  3660. private void button_OBC_ReadUserInfo_Click(object sender, EventArgs e)
  3661. {
  3662. richTextBox_OBC_ReadUserInfo.Clear();
  3663. comboBox_OBC_BikeCCS.SelectedIndex = 0;
  3664. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3300, null);
  3665. }
  3666. /// <summary>
  3667. /// OBC设置电机用户参数
  3668. /// </summary>
  3669. /// <param name="sender"></param>
  3670. /// <param name="e"></param>
  3671. private void button_OBC_WriteUserInfo_Click(object sender, EventArgs e)
  3672. {
  3673. var UserInfoCode = new byte[8];
  3674. for (int i = 0; i < UserInfoCode.Length; i++)
  3675. UserInfoCode[i] = 0;
  3676. if (comboBox_OBC_StartMode.SelectedIndex == -1)//检查数据有效性
  3677. {
  3678. timer_500ms.Enabled = false;
  3679. MessageBox.Show("请选择启动模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3680. timer_500ms.Enabled = true;
  3681. return;
  3682. }
  3683. if (comboBox_OBC_AssistFunc.SelectedIndex == -1)//检查数据有效性
  3684. {
  3685. timer_500ms.Enabled = false;
  3686. MessageBox.Show("请选择助力方案!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3687. timer_500ms.Enabled = true;
  3688. return;
  3689. }
  3690. //周长微调
  3691. UserInfoCode[0] = (byte)(int)numericUpDown_OBC_WheelAdj.Value;
  3692. //启动模式
  3693. UserInfoCode[1] = (byte)(comboBox_OBC_StartMode.SelectedIndex + 1);
  3694. //助力方案
  3695. UserInfoCode[2] = (byte)(comboBox_OBC_AssistFunc.SelectedIndex + 1);
  3696. //自动关机时间
  3697. UserInfoCode[3] = (byte)(uint)numericUpDown_OBC_OffTime.Value;
  3698. //限速微调
  3699. UserInfoCode[4] = (byte)(int)numericUpDown_OBC_SpeedLimitAdj.Value;
  3700. //定速巡航开关
  3701. UserInfoCode[5] = (byte)((comboBox_OBC_BikeCCS.SelectedIndex == 1) ? 0xAA : 0x00);
  3702. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3408, UserInfoCode);
  3703. }
  3704. /// <summary>
  3705. /// OBC查询电机版本信息
  3706. /// </summary>
  3707. /// <param name="sender"></param>
  3708. /// <param name="e"></param>
  3709. private void button_OBC_ReadVerInfo_Click(object sender, EventArgs e)
  3710. {
  3711. textBox_Model.Text = "---";
  3712. textBox_SN.Text = "---";
  3713. textBox_HW.Text = "---";
  3714. textBox_FW.Text = "---";
  3715. textBox_SP.Text = "---";
  3716. textBox_OBC_ReadModel.Text = "---";
  3717. textBox_OBC_ReadSN.Text = "---";
  3718. textBox_OBC_ReadHW.Text = "---";
  3719. textBox_OBC_ReadFW.Text = "---";
  3720. textBox_OBC_ReadSP.Text = "---";
  3721. textBox_FacModeName.Text = "---";
  3722. textBox_FacModeNum.Text = "---";
  3723. textBox_FacModeHW.Text = "---";
  3724. textBox_FacModeFW.Text = "---";
  3725. textBox_FacModeSP.Text = "---";
  3726. Class_Motor_Ver.Mode = "---";
  3727. Class_Motor_Ver.SN = "---";
  3728. Class_Motor_Ver.HW = "---";
  3729. Class_Motor_Ver.FW = "---";
  3730. Class_Motor_Ver.Special = "---";
  3731. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  3732. }
  3733. /// <summary>
  3734. /// OBC读取骑行历史
  3735. /// </summary>
  3736. /// <param name="sender"></param>
  3737. /// <param name="e"></param>
  3738. private void button_OBC_ReadRideInfo_Click(object sender, EventArgs e)
  3739. {
  3740. textBox_OBC_TRIP_KM.Text = "";
  3741. textBox_OBC_TRIP_TIME.Text = "";
  3742. textBox_OBC_ODO_KM.Text = "";
  3743. textBox_OBC_ODO_TIME.Text = "";
  3744. textBox_ODO_KM.Text = "---";
  3745. textBox_ODO_TIME.Text = "---";
  3746. textBox_TRIP_KM.Text = "---";
  3747. textBox_TRIP_TIME.Text = "---";
  3748. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3500, null);
  3749. }
  3750. /// <summary>
  3751. /// OBC清除TRIP里程
  3752. /// </summary>
  3753. /// <param name="sender"></param>
  3754. /// <param name="e"></param>
  3755. private void button_OBC_ClearTrip_Click(object sender, EventArgs e)
  3756. {
  3757. var Code = new byte[5];
  3758. Code[0] = (byte)'C';
  3759. Code[1] = (byte)'L';
  3760. Code[2] = (byte)'E';
  3761. Code[3] = (byte)'A';
  3762. Code[4] = (byte)'R';
  3763. timer_500ms.Enabled = false;
  3764. if (MessageBox.Show("TRIP清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3765. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3605, Code);
  3766. timer_500ms.Enabled = true;
  3767. }
  3768. private void checkBox_OBC_StartReadBMS_CheckedChanged(object sender, EventArgs e)
  3769. {
  3770. if (checkBox_OBC_StartReadBMS.Checked == true)
  3771. {
  3772. //检查串口是否打开
  3773. if (!mySerialProcess.mySerial.IsOpen)
  3774. {
  3775. timer_500ms.Enabled = false;
  3776. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3777. timer_500ms.Enabled = true;
  3778. checkBox_OBC_StartReadBMS.Checked = false;
  3779. return;
  3780. }
  3781. }
  3782. }
  3783. /// <summary>
  3784. /// 写入力矩传感器参数
  3785. /// </summary>
  3786. /// <param name="sender"></param>
  3787. /// <param name="e"></param>
  3788. private void button_WriteTqSensorParam_Click(object sender, EventArgs e)
  3789. {
  3790. var ConfigParam = new byte[46];
  3791. for (int i = 0; i < 14; i++)
  3792. ConfigParam[i] = 0;
  3793. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  3794. ushort uwDataTemp = 0;
  3795. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  3796. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  3797. int index = 0;
  3798. try
  3799. {
  3800. for (int i = 0; i < strDataTemp.Length; i++)
  3801. {
  3802. if (strDataTemp[i].Split('=')[0] == "第四阶段转矩点采集值")
  3803. {
  3804. index = i;
  3805. break;
  3806. }
  3807. }
  3808. for (int i = 0; i < (index + 1); i++)
  3809. {
  3810. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  3811. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3812. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3813. }
  3814. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x472E, ConfigParam);
  3815. }
  3816. catch (Exception)
  3817. {
  3818. timer_500ms.Enabled = false;
  3819. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3820. timer_500ms.Enabled = true;
  3821. }
  3822. }
  3823. /// <summary>
  3824. /// 查询存储标志
  3825. /// </summary>
  3826. /// <param name="sender"></param>
  3827. /// <param name="e"></param>
  3828. private void button_ReadSaveFlag_Click(object sender, EventArgs e)
  3829. {
  3830. radioButton_EE_SaveYes.Checked = false;
  3831. radioButton_EE_SaveNo.Checked = false;
  3832. radioButton_SIP_SaveYes.Checked = false;
  3833. radioButton_SIP_SaveNo.Checked = false;
  3834. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null);
  3835. }
  3836. /// <summary>
  3837. /// 写入存储标志
  3838. /// </summary>
  3839. /// <param name="sender"></param>
  3840. /// <param name="e"></param>
  3841. private void button_WriteSaveFlag_Click(object sender, EventArgs e)
  3842. {
  3843. var SaveFlag = new byte[6];
  3844. for (int i = 0; i < 6; i++)
  3845. SaveFlag[i] = 0;
  3846. if ((radioButton_EE_SaveYes.Checked == false) && (radioButton_EE_SaveNo.Checked == false))
  3847. {
  3848. timer_500ms.Enabled = false;
  3849. MessageBox.Show("请选择EEPROM存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3850. timer_500ms.Enabled = true;
  3851. return;
  3852. }
  3853. if ((radioButton_SIP_SaveYes.Checked == false) && (radioButton_SIP_SaveNo.Checked == false))
  3854. {
  3855. timer_500ms.Enabled = false;
  3856. MessageBox.Show("请选择SIP校验存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3857. timer_500ms.Enabled = true;
  3858. return;
  3859. }
  3860. SaveFlag[0] = (byte)((checkBox_SaveYes.Checked) ? 0x01 : 0x00);
  3861. SaveFlag[2] = (byte)(radioButton_EE_SaveYes.Checked ? 0x01 : 0x00);
  3862. SaveFlag[3] = 0;
  3863. SaveFlag[4] = (byte)(radioButton_SIP_SaveYes.Checked ? 0x01 : 0x00);
  3864. SaveFlag[5] = 0;
  3865. timer_500ms.Enabled = false;
  3866. if (MessageBox.Show("确认修改存储标志?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3867. {
  3868. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4906, SaveFlag);
  3869. }
  3870. timer_500ms.Enabled = true;
  3871. }
  3872. /// <summary>
  3873. /// 读取指定地址数据
  3874. /// </summary>
  3875. /// <param name="sender"></param>
  3876. /// <param name="e"></param>
  3877. private void button_ReadRamFlash_Click(object sender, EventArgs e)
  3878. {
  3879. var Address = new byte[4];
  3880. UInt32 Address_Begin;
  3881. UInt32 Addres_End;
  3882. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  3883. richTextBox_RamFlasgData.Clear();
  3884. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  3885. {
  3886. timer_500ms.Enabled = false;
  3887. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3888. timer_500ms.Enabled = true;
  3889. return;
  3890. }
  3891. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  3892. {
  3893. timer_500ms.Enabled = false;
  3894. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3895. timer_500ms.Enabled = true;
  3896. return;
  3897. }
  3898. else
  3899. {
  3900. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  3901. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  3902. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  3903. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  3904. if (Addres_End < Address_Begin)
  3905. {
  3906. timer_500ms.Enabled = false;
  3907. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3908. timer_500ms.Enabled = true;
  3909. return;
  3910. }
  3911. else
  3912. {
  3913. var SendByte = new byte[8];
  3914. SendByte[0] = (byte)(Address_Begin >> 24);
  3915. SendByte[1] = (byte)(Address_Begin >> 16);
  3916. SendByte[2] = (byte)(Address_Begin >> 8);
  3917. SendByte[3] = (byte)(Address_Begin);
  3918. SendByte[4] = (byte)(Addres_End >> 24);
  3919. SendByte[5] = (byte)(Addres_End >> 16);
  3920. SendByte[6] = (byte)(Addres_End >> 8);
  3921. SendByte[7] = (byte)(Addres_End);
  3922. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  3923. }
  3924. }
  3925. }
  3926. /// <summary>
  3927. /// 工作模式选择
  3928. /// </summary>
  3929. /// <param name="sender"></param>
  3930. /// <param name="e"></param>
  3931. private void comboBox_WorkMode_SelectedIndexChanged(object sender, EventArgs e)
  3932. {
  3933. var RunMode = new byte[1];
  3934. if (comboBox_WorkMode.Text == "配置模式")
  3935. RunMode[0] = 0x01;
  3936. else if (comboBox_WorkMode.Text == "调试模式")
  3937. RunMode[0] = 0x02;
  3938. else
  3939. RunMode[0] = 0x00;
  3940. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  3941. }
  3942. /// <summary>
  3943. /// 助力档位选择
  3944. /// </summary>
  3945. /// <param name="sender"></param>
  3946. /// <param name="e"></param>
  3947. private void comboBox_GearSt_SelectedIndexChanged(object sender, EventArgs e)
  3948. {
  3949. var CtrlCode = new byte[2];
  3950. if (comboBox_GearSt.SelectedIndex == 5)//档位
  3951. CtrlCode[0] = 0x33;
  3952. else if (comboBox_GearSt.SelectedIndex == 6)//档位
  3953. CtrlCode[0] = 0x22;
  3954. else
  3955. CtrlCode[0] = (byte)comboBox_GearSt.SelectedIndex;
  3956. if (comboBox_LightSwitch.SelectedIndex == 0)//车灯
  3957. CtrlCode[1] = 0xF1;
  3958. else
  3959. CtrlCode[1] = 0xF0;
  3960. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
  3961. comboBox_OBC_SetGearST.SelectedIndex = comboBox_GearSt.SelectedIndex;
  3962. comboBox_OBC_LightSw.SelectedIndex = comboBox_LightSwitch.SelectedIndex;
  3963. Delay_ms(500);
  3964. //设置百分比
  3965. do
  3966. {
  3967. var PercentCode = new byte[1];
  3968. if (comboBox_GearSt.SelectedIndex == 0) //Off
  3969. {
  3970. PercentCode[0] = 0;
  3971. textBox_MotorSpeedPercent.Text = "0";
  3972. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, PercentCode);
  3973. }
  3974. else if (comboBox_GearSt.SelectedIndex == 6) //Walk
  3975. {
  3976. if (comboBox_WorkMode.SelectedIndex != 0)
  3977. {
  3978. PercentCode[0] = 100;
  3979. textBox_MotorSpeedPercent.Text = "100";
  3980. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, PercentCode);
  3981. }
  3982. }
  3983. } while (false);
  3984. }
  3985. /// <summary>
  3986. /// 仪表档位选择
  3987. /// </summary>
  3988. /// <param name="sender"></param>
  3989. /// <param name="e"></param>
  3990. private void comboBox_OBC_SetGearST_SelectedIndexChanged(object sender, EventArgs e)
  3991. {
  3992. comboBox_GearSt.SelectedIndex = comboBox_OBC_SetGearST.SelectedIndex;
  3993. comboBox_LightSwitch.SelectedIndex = comboBox_OBC_LightSw.SelectedIndex;
  3994. }
  3995. /// <summary>
  3996. /// 生产模式初始化
  3997. /// </summary>
  3998. /// <param name="sender"></param>
  3999. /// <param name="e"></param>
  4000. private void button_FacModeInit_Click(object sender, EventArgs e)
  4001. {
  4002. var Code = new byte[5];
  4003. Code[0] = (byte)'C';
  4004. Code[1] = (byte)'L';
  4005. Code[2] = (byte)'E';
  4006. Code[3] = (byte)'A';
  4007. Code[4] = (byte)'R';
  4008. timer_500ms.Enabled = false;
  4009. if (MessageBox.Show("电机即将初始化!", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  4010. {
  4011. if (MessageBox.Show("请再次确认", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  4012. {
  4013. timer_500ms.Enabled = true;
  4014. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  4015. PowerOffAckStatus = false;
  4016. Delay_ms(250);
  4017. int TryCnt = 3;
  4018. while ((TryCnt--) >= 0)
  4019. {
  4020. if (!PowerOffAckStatus)
  4021. {
  4022. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  4023. PowerOffAckStatus = false;
  4024. Delay_ms(250);
  4025. }
  4026. else break;
  4027. }
  4028. if (PowerOffAckStatus)
  4029. {
  4030. timer_500ms.Enabled = false;
  4031. MessageBox.Show("系统已关机,请保持无负载重新开机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  4032. timer_500ms.Enabled = true;
  4033. }
  4034. else
  4035. {
  4036. timer_500ms.Enabled = false;
  4037. MessageBox.Show("初始化失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4038. timer_500ms.Enabled = true;
  4039. }
  4040. timer_500ms.Enabled = true;
  4041. }
  4042. }
  4043. timer_500ms.Enabled = true;
  4044. //清除历史测试记录
  4045. textBox_FacModeSensorADC0.Text = "";
  4046. textBox_FacModeSensorADC1.Text = "";
  4047. textBox_FacModeSensorADC2.Text = "";
  4048. textBox_FacModeSensorADC3.Text = "";
  4049. textBox_FacModeSensorADC4.Text = "";
  4050. LightSwitchStatus = false;
  4051. MotorRunStatus = false;
  4052. textBox_MotorSpeedPercent.Text = "5";
  4053. textBox_FacModeName.Text = "";
  4054. textBox_FacModeNum.Text = "";
  4055. textBox_FacModeHW.Text = "";
  4056. textBox_FacModeFW.Text = "";
  4057. }
  4058. /// <summary>
  4059. /// 生产模式读取传感器参数
  4060. /// </summary>
  4061. /// <param name="sender"></param>
  4062. /// <param name="e"></param>
  4063. private void button_FacModeSensorRead_Click(object sender, EventArgs e)
  4064. {
  4065. richTextBox_SensorParam.Clear();
  4066. textBox_FacModeSensorADC0.Text = "";
  4067. textBox_FacModeSensorADC1.Text = "";
  4068. textBox_FacModeSensorADC2.Text = "";
  4069. textBox_FacModeSensorADC3.Text = "";
  4070. textBox_FacModeSensorADC4.Text = "";
  4071. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4072. //零点判断
  4073. label1_TorqueCal0.BackColor = Color.Red;
  4074. WriteACK = false;
  4075. ACK_WaitCnt = 0;
  4076. Delay_ms(200);
  4077. if (WriteACK == true) //力矩读取正常
  4078. {
  4079. WriteACK = false;
  4080. //获取零点
  4081. ushort ZeroNew;
  4082. ZeroNew = (ushort)Convert.ToUInt16(textBox_FacModeSensorADC0.Text);
  4083. //比较零点
  4084. if ((ZeroNew <= TorqueParamsForm.Zero.Max) && (ZeroNew >= TorqueParamsForm.Zero.Min))
  4085. {
  4086. label1_TorqueCal0.BackColor = Color.Green;
  4087. }
  4088. else
  4089. {
  4090. MessageBoxTimeOut.Show("力矩传感器零点超范围!\r\n" + "最新零点:" + ZeroNew.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4091. }
  4092. }
  4093. else //力矩读取不正常
  4094. {
  4095. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4096. }
  4097. }
  4098. /// <summary>
  4099. /// 生产模式传感器标定1
  4100. /// </summary>
  4101. /// <param name="sender"></param>
  4102. /// <param name="e"></param>
  4103. private void buttonFacModeSet1_Click(object sender, EventArgs e)
  4104. {
  4105. var ConfigParam = new byte[4];
  4106. for (int i = 0; i < 4; i++)
  4107. ConfigParam[i] = 0;
  4108. ushort uwDataTemp = 0;
  4109. try
  4110. {
  4111. uwDataTemp = 1;//负载序号
  4112. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4113. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4114. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal1.Text) * 10); ;//负载值0.1Nm
  4115. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4116. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4117. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4118. Delay_ms(200);
  4119. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4120. //标定1判断
  4121. label1_TorqueCal1.BackColor = Color.Red;
  4122. WriteACK = false;
  4123. ACK_WaitCnt = 0;
  4124. Delay_ms(200);
  4125. if (WriteACK == true) //力矩读取正常
  4126. {
  4127. WriteACK = false;
  4128. //获取标定1
  4129. ushort K1_T, K1;
  4130. K1_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal1.Text) * 10);
  4131. K1 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC1.Text));
  4132. //比较标定1
  4133. if ((K1_T == TorqueParamsForm.K1.T) && (K1 <= TorqueParamsForm.K1.Max) && (K1 >= TorqueParamsForm.K1.Min))
  4134. {
  4135. label1_TorqueCal1.BackColor = Color.Green;
  4136. }
  4137. else
  4138. {
  4139. MessageBoxTimeOut.Show("力矩传感器标定1超范围!\r\n" + "加载扭矩:" + K1_T.ToString() + "\r\n标定值:" + K1.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4140. }
  4141. }
  4142. else //力矩读取不正常
  4143. {
  4144. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4145. }
  4146. }
  4147. catch (Exception)
  4148. {
  4149. timer_500ms.Enabled = false;
  4150. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4151. timer_500ms.Enabled = true;
  4152. }
  4153. }
  4154. /// <summary>
  4155. /// 生产模式传感器标定2
  4156. /// </summary>
  4157. /// <param name="sender"></param>
  4158. /// <param name="e"></param>
  4159. private void buttonFacModeSet2_Click(object sender, EventArgs e)
  4160. {
  4161. var ConfigParam = new byte[4];
  4162. for (int i = 0; i < 4; i++)
  4163. ConfigParam[i] = 0;
  4164. ushort uwDataTemp = 0;
  4165. try
  4166. {
  4167. uwDataTemp = 2;//负载序号
  4168. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4169. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4170. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal2.Text) * 10); ;//负载值0.1Nm
  4171. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4172. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4173. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4174. Delay_ms(200);
  4175. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4176. //标定2判断
  4177. label1_TorqueCal2.BackColor = Color.Red;
  4178. WriteACK = false;
  4179. ACK_WaitCnt = 0;
  4180. Delay_ms(200);
  4181. if (WriteACK == true) //力矩读取正常
  4182. {
  4183. WriteACK = false;
  4184. //获取标定2
  4185. ushort K2_T, K2;
  4186. K2_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal2.Text) * 10);
  4187. K2 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC2.Text));
  4188. //比较标定1
  4189. if ((K2_T == TorqueParamsForm.K2.T) && (K2 <= TorqueParamsForm.K2.Max) && (K2 >= TorqueParamsForm.K2.Min))
  4190. {
  4191. label1_TorqueCal2.BackColor = Color.Green;
  4192. }
  4193. else
  4194. {
  4195. MessageBoxTimeOut.Show("力矩传感器标定2超范围!\r\n" + "加载扭矩:" + K2_T.ToString() + "\r\n标定值:" + K2.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4196. }
  4197. }
  4198. else //力矩读取不正常
  4199. {
  4200. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4201. }
  4202. }
  4203. catch (Exception)
  4204. {
  4205. timer_500ms.Enabled = false;
  4206. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4207. timer_500ms.Enabled = true;
  4208. }
  4209. }
  4210. /// <summary>
  4211. /// 生产模式传感器标定3
  4212. /// </summary>
  4213. /// <param name="sender"></param>
  4214. /// <param name="e"></param>
  4215. private void buttonFacModeSet3_Click(object sender, EventArgs e)
  4216. {
  4217. var ConfigParam = new byte[4];
  4218. for (int i = 0; i < 4; i++)
  4219. ConfigParam[i] = 0;
  4220. ushort uwDataTemp = 0;
  4221. try
  4222. {
  4223. uwDataTemp = 3;//负载序号
  4224. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4225. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4226. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal3.Text) * 10); ;//负载值0.1Nm
  4227. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4228. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4229. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4230. Delay_ms(200);
  4231. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4232. //标定3判断
  4233. label1_TorqueCal3.BackColor = Color.Red;
  4234. WriteACK = false;
  4235. ACK_WaitCnt = 0;
  4236. Delay_ms(200);
  4237. if (WriteACK == true) //力矩读取正常
  4238. {
  4239. WriteACK = false;
  4240. //获取标定3
  4241. ushort K3_T, K3;
  4242. K3_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal3.Text) * 10);
  4243. K3 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC3.Text));
  4244. //比较标定1
  4245. if ((K3_T == TorqueParamsForm.K3.T) && (K3 <= TorqueParamsForm.K3.Max) && (K3 >= TorqueParamsForm.K3.Min))
  4246. {
  4247. label1_TorqueCal3.BackColor = Color.Green;
  4248. }
  4249. else
  4250. {
  4251. MessageBoxTimeOut.Show("力矩传感器标定3超范围!\r\n" + "加载扭矩:" + K3_T.ToString() + "\r\n标定值:" + K3.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4252. }
  4253. }
  4254. else //力矩读取不正常
  4255. {
  4256. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4257. }
  4258. }
  4259. catch (Exception)
  4260. {
  4261. timer_500ms.Enabled = false;
  4262. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4263. timer_500ms.Enabled = true;
  4264. }
  4265. }
  4266. /// <summary>
  4267. /// 生产模式传感器标定4
  4268. /// </summary>
  4269. /// <param name="sender"></param>
  4270. /// <param name="e"></param>
  4271. private void buttonFacModeSet4_Click(object sender, EventArgs e)
  4272. {
  4273. var ConfigParam = new byte[4];
  4274. for (int i = 0; i < 4; i++)
  4275. ConfigParam[i] = 0;
  4276. ushort uwDataTemp = 0;
  4277. try
  4278. {
  4279. WriteACK = false;
  4280. uwDataTemp = 4;//负载序号
  4281. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4282. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4283. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal4.Text) * 10); ;//负载值0.1Nm
  4284. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4285. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4286. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4287. Delay_ms(200);
  4288. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4289. //标定4判断
  4290. label1_TorqueCal4.BackColor = Color.Red;
  4291. WriteACK = false;
  4292. ACK_WaitCnt = 0;
  4293. Delay_ms(200);
  4294. if (WriteACK == true) //力矩读取正常
  4295. {
  4296. //获取标定4
  4297. ushort K4_T, K4;
  4298. K4_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal4.Text) * 10);
  4299. K4 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC4.Text));
  4300. //比较标定1
  4301. if ((K4_T == TorqueParamsForm.K4.T) && (K4 <= TorqueParamsForm.K4.Max) && (K4 >= TorqueParamsForm.K4.Min))
  4302. {
  4303. label1_TorqueCal4.BackColor = Color.Green;
  4304. }
  4305. else
  4306. {
  4307. MessageBoxTimeOut.Show("力矩传感器标定4超范围!\r\n" + "加载扭矩:" + K4_T.ToString() + "\r\n标定值:" + K4.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4308. }
  4309. }
  4310. else //力矩读取不正常
  4311. {
  4312. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4313. }
  4314. }
  4315. catch (Exception)
  4316. {
  4317. timer_500ms.Enabled = false;
  4318. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4319. timer_500ms.Enabled = true;
  4320. }
  4321. }
  4322. /// <summary>
  4323. /// 生产模式开关灯
  4324. /// </summary>
  4325. /// <param name="sender"></param>
  4326. /// <param name="e"></param>
  4327. bool LightSwitchStatus = false;
  4328. private void button_FacModeLightSW_Click(object sender, EventArgs e)
  4329. {
  4330. var CtrlCode = new byte[2];
  4331. CtrlCode[0] = 0x00;
  4332. if (LightSwitchStatus)
  4333. {
  4334. CtrlCode[1] = 0xF0;
  4335. button_FacModeLightSW.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(128)))));
  4336. }
  4337. else
  4338. {
  4339. CtrlCode[1] = 0xF1;
  4340. button_FacModeLightSW.BackColor = Color.Yellow;
  4341. }
  4342. if (mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode))
  4343. {
  4344. LightSwitchStatus = !LightSwitchStatus;
  4345. comboBox_LightSwitch.SelectedIndex = LightSwitchStatus ? 0 : 1;
  4346. comboBox_OBC_LightSw.SelectedIndex = LightSwitchStatus ? 0 : 1;
  4347. }
  4348. }
  4349. /// <summary>
  4350. /// 生产模式电机控制
  4351. /// </summary>
  4352. /// <param name="sender"></param>
  4353. /// <param name="e"></param>
  4354. bool MotorRunStatus = false;
  4355. private void button_FacModeMotorRun_Click(object sender, EventArgs e)
  4356. {
  4357. string DebugDefaultInfo = "";
  4358. //获取调试信息
  4359. if (richTextBox_DebugParam.Text == string.Empty)
  4360. {
  4361. richTextBox_DebugParam.Clear();
  4362. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  4363. }
  4364. Delay_ms(200);
  4365. DebugDefaultInfo = richTextBox_DebugParam.Text;
  4366. //获取参数
  4367. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  4368. if (strDataTemp.Length != 29)
  4369. {
  4370. timer_500ms.Enabled = false;
  4371. MessageBox.Show("数据格式不正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4372. timer_500ms.Enabled = true;
  4373. return;
  4374. }
  4375. //设置参数
  4376. var ConfigParam = new byte[60];
  4377. for (int i = 0; i < 60; i++)
  4378. ConfigParam[i] = 0;
  4379. ConfigParam[0] = 0x00;
  4380. ushort uwDataTemp = 0;
  4381. if (!MotorRunStatus) //停止状态
  4382. {
  4383. //设置速度环
  4384. strDataTemp[0] = "整体运行模式=3";
  4385. //发送数据
  4386. try
  4387. {
  4388. for (int i = 0; i < strDataTemp.Length; i++)
  4389. {
  4390. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  4391. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  4392. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  4393. }
  4394. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  4395. return;
  4396. }
  4397. catch (Exception)
  4398. {
  4399. timer_500ms.Enabled = false;
  4400. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4401. timer_500ms.Enabled = true;
  4402. }
  4403. Delay_ms(200);
  4404. //设置转速百分比100%
  4405. textBox_MotorSpeedPercent.Text = "100";
  4406. ConfigParam[0] = (byte)100;
  4407. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, ConfigParam);
  4408. MotorRunStatus = !MotorRunStatus;
  4409. button_FacModeMotorRun.BackColor = Color.Yellow;
  4410. Delay_ms(200);
  4411. //电机进入配置模式
  4412. var RunMode = new byte[1];
  4413. RunMode[0] = 0x01;
  4414. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  4415. }
  4416. else //运转状态
  4417. {
  4418. //设置转速百分比0%
  4419. textBox_MotorSpeedPercent.Text = "0";
  4420. ConfigParam[0] = (byte)0;
  4421. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, ConfigParam);
  4422. MotorRunStatus = !MotorRunStatus;
  4423. button_FacModeMotorRun.BackColor = Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
  4424. Delay_ms(200);
  4425. //还原为原始值
  4426. strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  4427. try
  4428. {
  4429. for (int i = 0; i < strDataTemp.Length; i++)
  4430. {
  4431. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  4432. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  4433. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  4434. }
  4435. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  4436. return;
  4437. }
  4438. catch (Exception)
  4439. {
  4440. timer_500ms.Enabled = false;
  4441. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4442. timer_500ms.Enabled = true;
  4443. }
  4444. Delay_ms(200);
  4445. //电机退出配置模式
  4446. var RunMode = new byte[1];
  4447. RunMode[0] = 0x00;
  4448. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  4449. }
  4450. }
  4451. /// <summary>
  4452. /// 生产模式写入型号
  4453. /// </summary>
  4454. /// <param name="sender"></param>
  4455. /// <param name="e"></param>
  4456. private void button_FacModeSetName_Click(object sender, EventArgs e)
  4457. {
  4458. string Mode = textBox_FacModeName.Text;
  4459. var ModeArray = new byte[16];
  4460. for (ushort i = 0; i < Mode.Length; i++)
  4461. {
  4462. ModeArray[i] = (byte)Mode[i];
  4463. }
  4464. if (Mode.Length < 16)
  4465. {
  4466. ModeArray[Mode.Length] = (byte)'.';
  4467. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  4468. {
  4469. ModeArray[Mode.Length + 1 + i] = 0x20;
  4470. }
  4471. }
  4472. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  4473. }
  4474. /// <summary>
  4475. /// 生产模式写入SN
  4476. /// </summary>
  4477. /// <param name="sender"></param>
  4478. /// <param name="e"></param>
  4479. private void Button_FacModeSetNum_Click(object sender, EventArgs e)
  4480. {
  4481. string SN = textBox_FacModeNum.Text;
  4482. var SNArray = new byte[16];
  4483. for (ushort i = 0; i < SN.Length; i++)
  4484. {
  4485. SNArray[i] = (byte)SN[i];
  4486. }
  4487. if (SN.Length < 16)
  4488. {
  4489. SNArray[SN.Length] = (byte)'.';
  4490. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  4491. {
  4492. SNArray[SN.Length + 1 + i] = 0x20;
  4493. }
  4494. }
  4495. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  4496. }
  4497. /// <summary>
  4498. /// 生产模式读取版本信息
  4499. /// </summary>
  4500. /// <param name="sender"></param>
  4501. /// <param name="e"></param>
  4502. private void Button_FacModeReadVer_Click_1(object sender, EventArgs e)
  4503. {
  4504. textBox_Model.Text = "---";
  4505. textBox_SN.Text = "---";
  4506. textBox_HW.Text = "---";
  4507. textBox_FW.Text = "---";
  4508. textBox_SP.Text = "---";
  4509. textBox_OBC_ReadModel.Text = "---";
  4510. textBox_OBC_ReadSN.Text = "---";
  4511. textBox_OBC_ReadHW.Text = "---";
  4512. textBox_OBC_ReadFW.Text = "---";
  4513. textBox_OBC_ReadSP.Text = "---";
  4514. textBox_FacModeName.Text = "---";
  4515. textBox_FacModeNum.Text = "---";
  4516. textBox_FacModeHW.Text = "---";
  4517. textBox_FacModeFW.Text = "---";
  4518. textBox_FacModeSP.Text = "---";
  4519. textBox_FacModeGit.Text = "---";
  4520. Class_Motor_Ver.Mode = "---";
  4521. Class_Motor_Ver.SN = "---";
  4522. Class_Motor_Ver.HW = "---";
  4523. Class_Motor_Ver.FW = "---";
  4524. Class_Motor_Ver.Special = "---";
  4525. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  4526. }
  4527. /// <summary>
  4528. /// 生产模式写入生产信息
  4529. /// </summary>
  4530. /// <param name="sender"></param>
  4531. /// <param name="e"></param>
  4532. private void Button_FacModeSetMacDate_Click(object sender, EventArgs e)
  4533. {
  4534. var MACArray = new byte[32];
  4535. string MacDefaultInfo = "";
  4536. string MacAddDefaultInfo = "";
  4537. string MacDateDefaultInfo = DateTime.Now.ToString("yyyyMMdd");
  4538. string MacPPDefaultInfo = "";
  4539. do
  4540. {
  4541. //填入生产商
  4542. if (toolStripTextBox_MAC.Text == string.Empty)
  4543. {
  4544. break;
  4545. }
  4546. MacDefaultInfo = toolStripTextBox_MAC.Text;
  4547. for (ushort i = 0; i < MacDefaultInfo.Length; i++)
  4548. {
  4549. MACArray[i] = (byte)MacDefaultInfo[i];
  4550. }
  4551. if (MacDefaultInfo.Length < 8)
  4552. {
  4553. MACArray[MacDefaultInfo.Length] = (byte)'.';
  4554. for (ushort i = 0; i < 8 - MacDefaultInfo.Length - 1; i++)
  4555. {
  4556. MACArray[MacDefaultInfo.Length + 1 + i] = 0x20;
  4557. }
  4558. }
  4559. //填入生产地
  4560. if (toolStripTextBoxMACAddr.Text == string.Empty)
  4561. {
  4562. break;
  4563. }
  4564. MacAddDefaultInfo = toolStripTextBoxMACAddr.Text;
  4565. for (ushort i = 0; i < MacAddDefaultInfo.Length; i++)
  4566. {
  4567. MACArray[8 + i] = (byte)MacAddDefaultInfo[i];
  4568. }
  4569. if (MacAddDefaultInfo.Length < 8)
  4570. {
  4571. MACArray[MacAddDefaultInfo.Length + 8] = (byte)'.';
  4572. for (ushort i = 0; i < 8 - MacAddDefaultInfo.Length - 1; i++)
  4573. {
  4574. MACArray[MacAddDefaultInfo.Length + 1 + i + 8] = 0x20;
  4575. }
  4576. }
  4577. //填入生产日期
  4578. if (toolStripTextBox_MACDate.Text == string.Empty)
  4579. {
  4580. break;
  4581. }
  4582. MacDateDefaultInfo = toolStripTextBox_MACDate.Text;
  4583. for (ushort i = 0; i < MacDateDefaultInfo.Length; i++)
  4584. {
  4585. MACArray[16 + i] = (byte)MacDateDefaultInfo[i];
  4586. }
  4587. if (MacDateDefaultInfo.Length < 8)
  4588. {
  4589. MACArray[MacDateDefaultInfo.Length + 16] = (byte)'.';
  4590. for (ushort i = 0; i < 8 - MacDateDefaultInfo.Length - 1; i++)
  4591. {
  4592. MACArray[MacDateDefaultInfo.Length + 1 + i + 16] = 0x20;
  4593. }
  4594. }
  4595. //填入产品标识
  4596. if (toolStripTextBox_MACPD.Text == string.Empty)
  4597. {
  4598. break;
  4599. }
  4600. MacPPDefaultInfo = toolStripTextBox_MACPD.Text;
  4601. for (ushort i = 0; i < MacPPDefaultInfo.Length; i++)
  4602. {
  4603. MACArray[24 + i] = (byte)MacPPDefaultInfo[i];
  4604. }
  4605. if (MacPPDefaultInfo.Length < 8)
  4606. {
  4607. MACArray[MacPPDefaultInfo.Length + 24] = (byte)'.';
  4608. for (ushort i = 0; i < 8 - MacPPDefaultInfo.Length - 1; i++)
  4609. {
  4610. MACArray[MacPPDefaultInfo.Length + 1 + i + 24] = 0x20;
  4611. }
  4612. }
  4613. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  4614. return;
  4615. } while (false);
  4616. timer_500ms.Enabled = false;
  4617. MessageBox.Show("生产信息配置不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4618. timer_500ms.Enabled = true;
  4619. }
  4620. /// <summary>
  4621. /// 生产模式保存测试页面
  4622. /// </summary>
  4623. /// <param name="sender"></param>
  4624. /// <param name="e"></param>
  4625. private void Button_FacModeSaveResult_Click(object sender, EventArgs e)
  4626. {
  4627. Button_FacModeSaveResult.Text = "存储中…";
  4628. string[] AssistParams = new string[15];
  4629. do
  4630. {
  4631. //读取一次马达参数
  4632. richTextBox_MotorParam.Clear();
  4633. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break; ;
  4634. Delay_ms(100);
  4635. //读取一次整车参数
  4636. richTextBox_BikeParam.Clear();
  4637. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  4638. Delay_ms(100);
  4639. //读取一次整车参数2
  4640. richTextBox_BikeParam2.Clear();
  4641. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null)) break;
  4642. Delay_ms(100);
  4643. //读取一次控制参数
  4644. richTextBox_ControlParam.Clear();
  4645. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  4646. Delay_ms(100);
  4647. //查询传感器
  4648. richTextBox_SensorParam.Clear();
  4649. textBox_FacModeSensorADC0.Text = "";
  4650. textBox_FacModeSensorADC1.Text = "";
  4651. textBox_FacModeSensorADC2.Text = "";
  4652. textBox_FacModeSensorADC3.Text = "";
  4653. textBox_FacModeSensorADC4.Text = "";
  4654. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  4655. Delay_ms(100);
  4656. //读取15次助力参数
  4657. for (int i = 1; i <= 15; i++)
  4658. {
  4659. var ConfigParam = new byte[4];
  4660. richTextBox_AssistParam.Clear();
  4661. ConfigParam[0] = (byte)(i & 0xFF);
  4662. ConfigParam[1] = (byte)(i >> 8);
  4663. ConfigParam[2] = (byte)(((i >= 5) ? 5 : i) & 0xFF);
  4664. ConfigParam[3] = (byte)(((i >= 5) ? 5 : i) >> 8);
  4665. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  4666. Delay_ms(200);
  4667. AssistParams[i - 1] = richTextBox_AssistParam.Text + "\r\n";
  4668. }
  4669. //读取一次用户骑行参数
  4670. richTextBox_UsrRidesParam.Clear();
  4671. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  4672. Delay_ms(100);
  4673. //读取一次调试信息
  4674. richTextBox_DebugParam.Clear();
  4675. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  4676. Delay_ms(100);
  4677. //读取一次历史信息
  4678. richTextBox_Record.Clear();
  4679. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  4680. Delay_ms(100);
  4681. //读取一次电机运行信息
  4682. var CtrlCode = new byte[2];
  4683. CtrlCode[0] = 0x00;
  4684. CtrlCode[1] = 0xF0;
  4685. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode)) break;
  4686. Delay_ms(100);
  4687. //读取一次版本信息
  4688. textBox_Model.Text = "---";
  4689. textBox_SN.Text = "---";
  4690. textBox_HW.Text = "---";
  4691. textBox_FW.Text = "---";
  4692. textBox_OBC_ReadModel.Text = "---";
  4693. textBox_OBC_ReadSN.Text = "---";
  4694. textBox_OBC_ReadHW.Text = "---";
  4695. textBox_OBC_ReadFW.Text = "---";
  4696. textBox_FacModeName.Text = "---";
  4697. textBox_FacModeNum.Text = "---";
  4698. textBox_FacModeHW.Text = "---";
  4699. textBox_FacModeFW.Text = "---";
  4700. Class_Motor_Ver.Mode = "---";
  4701. Class_Motor_Ver.SN = "---";
  4702. Class_Motor_Ver.HW = "---";
  4703. Class_Motor_Ver.FW = "---";
  4704. Class_Motor_Ver.Special = "---";
  4705. if (!mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null)) break;
  4706. Delay_ms(100);
  4707. //读取一次生产信息
  4708. textBox_MAC.Text = "";
  4709. textBox_MACAdd.Text = "";
  4710. textBox_MACDate.Text = "";
  4711. textBox_PP.Text = "";
  4712. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  4713. Delay_ms(100);
  4714. //读取一次自定义信息
  4715. textBox_User1.Text = "---";
  4716. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  4717. Delay_ms(100);
  4718. textBox_User2.Text = "---";
  4719. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  4720. Delay_ms(100);
  4721. textBox_User3.Text = "---";
  4722. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  4723. Delay_ms(100);
  4724. //读取一次密钥
  4725. textBox_Key.Text = "---";
  4726. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  4727. Delay_ms(100);
  4728. //读取一次存储标志
  4729. radioButton_EE_SaveYes.Checked = false;
  4730. radioButton_EE_SaveNo.Checked = false;
  4731. radioButton_SIP_SaveYes.Checked = false;
  4732. radioButton_SIP_SaveNo.Checked = false;
  4733. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  4734. Delay_ms(100);
  4735. //读取一次MOS内阻校准参数
  4736. foreach (Control c in groupBox21.Controls)
  4737. {
  4738. if (c is TextBox)
  4739. c.Text = "";
  4740. }
  4741. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  4742. Delay_ms(100);
  4743. //提示检查
  4744. #if false
  4745. timer_1s.Enabled = false;
  4746. if (MessageBox.Show("请检查信息是否完整!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  4747. {
  4748. MessageBox.Show("请检查参数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4749. timer_1s.Enabled = true;
  4750. return;
  4751. }
  4752. timer_1s.Enabled = true;
  4753. Delay_ms(200);
  4754. #endif
  4755. //判断数据是否有效
  4756. if ((textBox_FacModeName.Text == "---") || (textBox_FacModeNum.Text == "---"))
  4757. {
  4758. MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4759. break;
  4760. }
  4761. if ((textBox_FacModeName.Text == string.Empty) || (textBox_FacModeNum.Text == string.Empty))
  4762. {
  4763. MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4764. break;
  4765. }
  4766. //设置文件存储路径
  4767. string Save_Path = localInfo.LocalPath + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
  4768. string PD_PathName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_"); ;
  4769. Save_Path += PD_PathName;
  4770. if (!Directory.Exists(Save_Path))
  4771. Directory.CreateDirectory(Save_Path);
  4772. //保存页面
  4773. string PIC_SaveFileName = "";
  4774. Double scaleX = PrimaryScreen.ScaleX;
  4775. Double scaleY = PrimaryScreen.ScaleY;
  4776. //保存页面
  4777. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  4778. Graphics g = Graphics.FromImage(bit);
  4779. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  4780. PIC_SaveFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_测试页面" + ".png";
  4781. bit.Save(PIC_SaveFileName);
  4782. //保存数据
  4783. string DataFileName = "";
  4784. string FileInfo = "";
  4785. DataFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_记录数据" + ".txt";
  4786. FileInfo += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  4787. FileInfo += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  4788. FileInfo += "\r\n";
  4789. FileInfo += "[电机信息]\r\n";
  4790. FileInfo += "电机型号: " + textBox_FacModeName.Text + "\r\n";
  4791. FileInfo += "电机编号: " + textBox_FacModeNum.Text + "\r\n";
  4792. FileInfo += "硬件版本: " + textBox_HW.Text + "\r\n";
  4793. FileInfo += "软件版本: " + textBox_FW.Text + "\r\n";
  4794. FileInfo += "软件标识: " + textBox_SP.Text + "\r\n";
  4795. FileInfo += "Git信息: " + textBox_FacModeGit.Text + "\r\n";
  4796. FileInfo += "\r\n";
  4797. FileInfo += "[马达参数]\r\n";
  4798. FileInfo += richTextBox_MotorParam.Text + "\r\n";
  4799. FileInfo += "\r\n";
  4800. FileInfo += "[整车参数]\r\n";
  4801. FileInfo += richTextBox_BikeParam.Text + "\r\n";
  4802. FileInfo += "\r\n";
  4803. FileInfo += "[控制参数]\r\n";
  4804. FileInfo += richTextBox_ControlParam.Text + "\r\n";
  4805. FileInfo += "\r\n";
  4806. FileInfo += "[传感器参数]\r\n";
  4807. FileInfo += richTextBox_SensorParam.Text + "\r\n";
  4808. FileInfo += "\r\n";
  4809. FileInfo += "[助力参数]\r\n";
  4810. for(int i=0;i<15;i++)
  4811. {
  4812. FileInfo += AssistParams[i] + "\r\n";
  4813. }
  4814. FileInfo += "[调试参数]\r\n";
  4815. FileInfo += richTextBox_DebugParam.Text + "\r\n";
  4816. FileInfo += "\r\n";
  4817. FileInfo += "[历史信息]\r\n";
  4818. FileInfo += richTextBox_Record.Text + "\r\n";
  4819. FileInfo += "\r\n";
  4820. FileInfo += "[MOS内阻校准参数]\r\n";
  4821. FileInfo += textBox_MOS_K1.Text + ", ";
  4822. FileInfo += textBox_MOS_K2.Text + ", ";
  4823. FileInfo += textBox_MOS_K3.Text + ", ";
  4824. FileInfo += textBox_MOS_K4.Text + ", ";
  4825. FileInfo += textBox_MOS_K5.Text + ", ";
  4826. FileInfo += textBox_MOS_R1.Text + ", ";
  4827. FileInfo += textBox_MOS_R2.Text + ", ";
  4828. FileInfo += textBox_MOS_R3.Text + "\r\n";
  4829. FileInfo += "\r\n";
  4830. FileInfo += "[整车参数2]\r\n";
  4831. FileInfo += richTextBox_BikeParam2.Text + "\r\n";
  4832. FileInfo += "\r\n";
  4833. FileInfo += "[用户骑行参数]\r\n";
  4834. FileInfo += richTextBox_UsrRidesParam.Text + "\r\n";
  4835. FileInfo += "\r\n";
  4836. FileInfo += "[生产信息]\r\n";
  4837. FileInfo += "生产商: " + textBox_MAC.Text + "\r\n";
  4838. FileInfo += "生产地: " + textBox_MACAdd.Text + "\r\n";
  4839. FileInfo += "生产日期: " + textBox_MACDate.Text + "\r\n";
  4840. FileInfo += "产品标识: " + textBox_PP.Text + "\r\n";
  4841. FileInfo += "\r\n";
  4842. FileInfo += "[自定义信息]\r\n";
  4843. FileInfo += "自定义1: " + textBox_User1.Text + "\r\n";
  4844. FileInfo += "自定义2: " + textBox_User2.Text + "\r\n";
  4845. FileInfo += "自定义3: " + textBox_User3.Text + "\r\n";
  4846. FileInfo += "\r\n";
  4847. FileInfo += "[校验密钥]\r\n";
  4848. FileInfo += textBox_Key.Text + "\r\n";
  4849. FileInfo += "\r\n";
  4850. FileInfo += "[存储标志]\r\n";
  4851. FileInfo += "EEPROM: " + ((radioButton_EE_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  4852. FileInfo += "SIP: " + ((radioButton_SIP_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  4853. FileInfo += "\r\n";
  4854. FileInfo += Local_HdInformation;
  4855. FileInfo += "\r\n";
  4856. FileInfo += "文件格式: V2.0\r\n";
  4857. System.IO.File.WriteAllText(DataFileName, FileInfo);
  4858. Delay_ms(1000);
  4859. timer_500ms.Enabled = false;
  4860. MessageBox.Show("存储完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  4861. timer_500ms.Enabled = true;
  4862. //数据上传
  4863. if (myFtp.IsNetConnected == true)
  4864. {
  4865. string DataNow = DateTime.Now.ToString("yyyy-MM-dd");
  4866. //检查路径
  4867. if (myFtp.DirectoryExist("\\", toolStripTextBox_ServerPath.Text) == false)
  4868. {
  4869. myFtp.MakeDir(toolStripTextBox_ServerPath.Text);
  4870. }
  4871. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text, "Samples") == false)
  4872. {
  4873. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples");
  4874. }
  4875. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples", DataNow) == false)
  4876. {
  4877. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow);
  4878. }
  4879. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow, PD_PathName) == false)
  4880. {
  4881. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4882. }
  4883. //上传文件
  4884. bool result1 = myFtp.UploadFile(PIC_SaveFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4885. bool result2 = myFtp.UploadFile(DataFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4886. if ((result1 & result2) == true)
  4887. {
  4888. MessageBoxTimeOut.Show("数据已上传!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  4889. }
  4890. else
  4891. {
  4892. timer_500ms.Enabled = false;
  4893. MessageBox.Show("数据上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4894. timer_500ms.Enabled = true;
  4895. }
  4896. }
  4897. else
  4898. {
  4899. timer_500ms.Enabled = false;
  4900. MessageBox.Show("服务器断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4901. timer_500ms.Enabled = true;
  4902. }
  4903. Button_FacModeSaveResult.Text = "保存数据";
  4904. return;
  4905. } while (false);
  4906. timer_500ms.Enabled = false;
  4907. MessageBox.Show("保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4908. timer_500ms.Enabled = true;
  4909. Button_FacModeSaveResult.Text = "保存数据";
  4910. }
  4911. /// <summary>
  4912. /// 工具箱页面保存
  4913. /// </summary>
  4914. /// <param name="sender"></param>
  4915. /// <param name="e"></param>
  4916. private void 页面保存ToolStripMenuItem_Click(object sender, EventArgs e)
  4917. {
  4918. Double scaleX = PrimaryScreen.ScaleX;
  4919. Double scaleY = PrimaryScreen.ScaleY;
  4920. //保存页面
  4921. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  4922. Graphics g = Graphics.FromImage(bit);
  4923. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  4924. SaveFileDialog sf = new SaveFileDialog();
  4925. sf.Title = "页面保存";
  4926. sf.FileName = "MotorInfo_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".png";
  4927. sf.Filter = "图片|*.png";
  4928. timer_500ms.Enabled = false;
  4929. if (sf.ShowDialog() == DialogResult.OK)
  4930. {
  4931. bit.Save(sf.FileName);//默认保存格式为PNG,保存成jpg格式质量不是很好
  4932. }
  4933. timer_500ms.Enabled = true;
  4934. }
  4935. /// <summary>
  4936. /// 生产模式关机
  4937. /// </summary>
  4938. /// <param name="sender"></param>
  4939. /// <param name="e"></param>
  4940. private void Button_FacModePowerOff_Click(object sender, EventArgs e)
  4941. {
  4942. var Code_Off = new byte[5];
  4943. var Code_Reset = new byte[5];
  4944. Code_Off[0] = (byte)'O';
  4945. Code_Off[1] = (byte)'F';
  4946. Code_Off[2] = (byte)'F';
  4947. Code_Off[3] = (byte)'.';
  4948. Code_Off[4] = (byte)'.';
  4949. Code_Reset[0] = (byte)'R';
  4950. Code_Reset[1] = (byte)'E';
  4951. Code_Reset[2] = (byte)'S';
  4952. Code_Reset[3] = (byte)'E';
  4953. Code_Reset[4] = (byte)'T';
  4954. timer_500ms.Enabled = false;
  4955. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  4956. {
  4957. timer_500ms.Enabled = true;
  4958. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  4959. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  4960. PowerOffAckStatus = false;
  4961. Delay_ms(250);
  4962. int TryCnt = 3;
  4963. while ((TryCnt--) >= 0)
  4964. {
  4965. if (!PowerOffAckStatus)
  4966. {
  4967. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  4968. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  4969. PowerOffAckStatus = false;
  4970. Delay_ms(250);
  4971. }
  4972. else break;
  4973. }
  4974. if (PowerOffAckStatus)
  4975. {
  4976. timer_500ms.Enabled = false;
  4977. MessageBox.Show("已关机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  4978. timer_500ms.Enabled = true;
  4979. }
  4980. else
  4981. {
  4982. timer_500ms.Enabled = false;
  4983. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4984. timer_500ms.Enabled = true;
  4985. }
  4986. }
  4987. timer_500ms.Enabled = true;
  4988. }
  4989. //仪表电源键按下
  4990. private void button_OBC_ButtonPower_Click(object sender, EventArgs e)
  4991. {
  4992. var Code = new byte[2];
  4993. Code[0] = 0;
  4994. Code[1] = 0b00100000;
  4995. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4996. }
  4997. /// <summary>
  4998. /// 仪表加键按下
  4999. /// </summary>
  5000. /// <param name="sender"></param>
  5001. /// <param name="e"></param>
  5002. private void button_OBC_ButtonAcc_Click(object sender, EventArgs e)
  5003. {
  5004. var Code = new byte[2];
  5005. Code[0] = 0;
  5006. Code[1] = 0b00010000;
  5007. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5008. }
  5009. /// <summary>
  5010. /// 仪表减键按下
  5011. /// </summary>
  5012. /// <param name="sender"></param>
  5013. /// <param name="e"></param>
  5014. private void button_OBC_ButtonDec_Click(object sender, EventArgs e)
  5015. {
  5016. var Code = new byte[2];
  5017. Code[0] = 0;
  5018. Code[1] = 0b00001000;
  5019. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5020. }
  5021. /// <summary>
  5022. /// 仪表Walk键按下
  5023. /// </summary>
  5024. /// <param name="sender"></param>
  5025. /// <param name="e"></param>
  5026. private void button_OBC_ButtonWalk_Click(object sender, EventArgs e)
  5027. {
  5028. var Code = new byte[2];
  5029. Code[0] = 0;
  5030. Code[1] = 0b00000100;
  5031. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5032. }
  5033. /// <summary>
  5034. /// 仪表Light键按下
  5035. /// </summary>
  5036. /// <param name="sender"></param>
  5037. /// <param name="e"></param>
  5038. private void button_OBC_ButtonLight_Click(object sender, EventArgs e)
  5039. {
  5040. var Code = new byte[2];
  5041. Code[0] = 0;
  5042. Code[1] = 0b00000010;
  5043. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5044. }
  5045. /// <summary>
  5046. /// 仪表Set键按下
  5047. /// </summary>
  5048. /// <param name="sender"></param>
  5049. /// <param name="e"></param>
  5050. private void button_OBC_ButtonSet_Click(object sender, EventArgs e)
  5051. {
  5052. var Code = new byte[2];
  5053. Code[0] = 0;
  5054. Code[1] = 0b00000001;
  5055. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5056. }
  5057. /// <summary>
  5058. /// 导出电机故障日志
  5059. /// </summary>
  5060. /// <param name="sender"></param>
  5061. /// <param name="e"></param>
  5062. private void button_ExportLog_Click(object sender, EventArgs e)
  5063. {
  5064. var Address = new byte[4];
  5065. UInt32 Address_Begin;
  5066. UInt32 Addres_End;
  5067. string textBox_Address_Begin = textBox_LogAddrBegin.Text;
  5068. string textBox_Address_End = textBox_LogAddrEnd.Text;
  5069. richTextBox_Record.Clear();
  5070. textBox_LogAddrBegin.ReadOnly = true;
  5071. textBox_LogAddrEnd.ReadOnly = true;
  5072. if (!mySerialProcess.mySerial.IsOpen)
  5073. {
  5074. timer_500ms.Enabled = false;
  5075. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5076. timer_500ms.Enabled = true;
  5077. return;
  5078. }
  5079. if ((textBox_Address_Begin == string.Empty) || (textBox_Address_End == string.Empty))
  5080. {
  5081. timer_500ms.Enabled = false;
  5082. MessageBox.Show("请输入日志存储起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5083. timer_500ms.Enabled = true;
  5084. return;
  5085. }
  5086. else
  5087. {
  5088. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin, false);
  5089. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  5090. Address = mySerialProcess.HexStringToBytes(textBox_Address_End, false);
  5091. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  5092. if (Addres_End <= Address_Begin)
  5093. {
  5094. timer_500ms.Enabled = false;
  5095. MessageBox.Show("结束地址应大于起始地址!", "提示");
  5096. timer_500ms.Enabled = true;
  5097. return;
  5098. }
  5099. else if (((Addres_End - Address_Begin + 1) % 128) != 0) //
  5100. {
  5101. timer_500ms.Enabled = false;
  5102. MessageBox.Show("(结束地址 - 起始地址 + 1)应为128整数倍!", "提示");
  5103. timer_500ms.Enabled = true;
  5104. return;
  5105. }
  5106. else
  5107. {
  5108. UInt32 ReadCount = 0;
  5109. button_ExportLog.Text = "导出中...";
  5110. button_ExportLog.Enabled = false;
  5111. ReadCount = (Addres_End - Address_Begin + 1) / 128;
  5112. for (ushort i = 0; i < ReadCount; i++)
  5113. {
  5114. var SendByte = new byte[8];
  5115. UInt32 Address_Temp_Begin;
  5116. UInt32 Address_Temp_End;
  5117. Address_Temp_Begin = Address_Begin + 128 * (UInt32)i;
  5118. SendByte[0] = (byte)(Address_Temp_Begin >> 24);
  5119. SendByte[1] = (byte)(Address_Temp_Begin >> 16);
  5120. SendByte[2] = (byte)(Address_Temp_Begin >> 8);
  5121. SendByte[3] = (byte)(Address_Temp_Begin);
  5122. Address_Temp_End = Address_Temp_Begin + 127;
  5123. SendByte[4] = (byte)(Address_Temp_End >> 24);
  5124. SendByte[5] = (byte)(Address_Temp_End >> 16);
  5125. SendByte[6] = (byte)(Address_Temp_End >> 8);
  5126. SendByte[7] = (byte)(Address_Temp_End);
  5127. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  5128. Delay_ms(200);//Thread.Sleep(200);
  5129. }
  5130. button_ExportLog.Text = "导出日志";
  5131. button_ExportLog.Enabled = true;
  5132. }
  5133. }
  5134. }
  5135. /// <summary>
  5136. /// 保存日志信息
  5137. /// </summary>
  5138. /// <param name="sender"></param>
  5139. /// <param name="e"></param>
  5140. private void button_SaveRecordInfo_Click(object sender, EventArgs e)
  5141. {
  5142. string SaveInfo = "";
  5143. if (richTextBox_Record.Text == string.Empty)
  5144. {
  5145. timer_500ms.Enabled = false;
  5146. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  5147. timer_500ms.Enabled = true;
  5148. return;
  5149. }
  5150. //获取保存信息
  5151. SaveInfo += "读取时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  5152. SaveInfo += "电机型号:" + textBox_FacModeName.Text + "\r\n";
  5153. SaveInfo += "电机SN:" + textBox_FacModeNum.Text + "\r\n";
  5154. SaveInfo += "硬件版本:" + textBox_FacModeHW.Text + "\r\n";
  5155. SaveInfo += "软件版本:" + textBox_FacModeFW.Text + "\r\n";
  5156. SaveInfo += "\r\n";
  5157. SaveInfo += richTextBox_Record.Text;
  5158. //设置保存路径和文件名
  5159. SaveFileDialog sf = new SaveFileDialog();
  5160. sf.Title = "数据保存";
  5161. sf.FileName = "MotorLog_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".ttlog";
  5162. sf.FileName.Replace(" ", "");
  5163. sf.Filter = "日志|*.ttlog";
  5164. if (sf.ShowDialog() == DialogResult.OK)
  5165. {
  5166. System.IO.File.AppendAllText(sf.FileName, SaveInfo);
  5167. }
  5168. }
  5169. /// <summary>
  5170. /// 双击修改日志起始地址
  5171. /// </summary>
  5172. /// <param name="sender"></param>
  5173. /// <param name="e"></param>
  5174. private void label_LogAddrBegin_DoubleClick_1(object sender, EventArgs e)
  5175. {
  5176. textBox_LogAddrBegin.ReadOnly = false;
  5177. }
  5178. /// <summary>
  5179. /// 双击修改日志结束地址
  5180. /// </summary>
  5181. /// <param name="sender"></param>
  5182. /// <param name="e"></param>
  5183. private void label88_DoubleClick(object sender, EventArgs e)
  5184. {
  5185. textBox_LogAddrEnd.ReadOnly = false;
  5186. }
  5187. /// <summary>
  5188. /// 存储器自动读取选择
  5189. /// </summary>
  5190. /// <param name="sender"></param>
  5191. /// <param name="e"></param>
  5192. private void checkBox_ReadRanFlash_AutoSW_CheckedChanged(object sender, EventArgs e)
  5193. {
  5194. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  5195. {
  5196. //检查串口是否打开
  5197. if (!mySerialProcess.mySerial.IsOpen)
  5198. {
  5199. timer_500ms.Enabled = false;
  5200. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5201. timer_500ms.Enabled = true;
  5202. checkBox_ReadRanFlash_AutoSW.Checked = false;
  5203. return;
  5204. }
  5205. }
  5206. }
  5207. /// <summary>
  5208. /// 系统开机按钮
  5209. /// </summary>
  5210. /// <param name="sender"></param>
  5211. /// <param name="e"></param>
  5212. private void 开机ToolStripMenuItem_Click(object sender, EventArgs e)
  5213. {
  5214. byte[] Data = new byte[1];
  5215. Data[0] = 0xF1;
  5216. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  5217. }
  5218. /// <summary>
  5219. /// 系统关机按钮
  5220. /// </summary>
  5221. /// <param name="sender"></param>
  5222. /// <param name="e"></param>
  5223. private void 关机ToolStripMenuItem_Click(object sender, EventArgs e)
  5224. {
  5225. byte[] Data = new byte[1];
  5226. Data[0] = 0xF0;
  5227. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  5228. }
  5229. /// <summary>
  5230. /// 连接开机选择
  5231. /// </summary>
  5232. /// <param name="sender"></param>
  5233. /// <param name="e"></param>
  5234. private void 连接开机ToolStripMenuItem_Click(object sender, EventArgs e)
  5235. {
  5236. //输入用户名
  5237. EnterForm1.ShowDialog();
  5238. try
  5239. {
  5240. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5241. {
  5242. if (EnterForm1.comboBox_User.Text == "管理员")
  5243. {
  5244. 连接开机ToolStripMenuItem.Checked = !连接开机ToolStripMenuItem.Checked;
  5245. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5246. }
  5247. else
  5248. {
  5249. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5250. }
  5251. }
  5252. else
  5253. {
  5254. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5255. }
  5256. }
  5257. catch (Exception)
  5258. {
  5259. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5260. }
  5261. }
  5262. /// <summary>
  5263. /// 断开关机选择
  5264. /// </summary>
  5265. /// <param name="sender"></param>
  5266. /// <param name="e"></param>
  5267. private void 断开关机ToolStripMenuItem_Click(object sender, EventArgs e)
  5268. {
  5269. //输入用户名
  5270. EnterForm1.ShowDialog();
  5271. try
  5272. {
  5273. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5274. {
  5275. if (EnterForm1.comboBox_User.Text == "管理员")
  5276. {
  5277. 断开关机ToolStripMenuItem.Checked = !断开关机ToolStripMenuItem.Checked;
  5278. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5279. }
  5280. else
  5281. {
  5282. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5283. }
  5284. }
  5285. else
  5286. {
  5287. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5288. }
  5289. }
  5290. catch (Exception)
  5291. {
  5292. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5293. }
  5294. }
  5295. /// <summary>
  5296. /// 识别通讯盒选择
  5297. /// </summary>
  5298. /// <param name="sender"></param>
  5299. /// <param name="e"></param>
  5300. private void 识别通讯盒ToolStripMenuItem_Click(object sender, EventArgs e)
  5301. {
  5302. //输入用户名
  5303. EnterForm1.ShowDialog();
  5304. try
  5305. {
  5306. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5307. {
  5308. if (EnterForm1.comboBox_User.Text == "管理员")
  5309. {
  5310. 识别通讯盒ToolStripMenuItem.Checked = !识别通讯盒ToolStripMenuItem.Checked;
  5311. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5312. }
  5313. else
  5314. {
  5315. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5316. }
  5317. }
  5318. else
  5319. {
  5320. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5321. }
  5322. }
  5323. catch (Exception)
  5324. {
  5325. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5326. }
  5327. }
  5328. /// <summary>
  5329. /// 将配置信息导出为cfg文件
  5330. /// </summary>
  5331. private void ConfigFileSave(bool DeleteFlag, string FileName)
  5332. {
  5333. if (DeleteFlag)
  5334. {
  5335. if (File.Exists(FileName))
  5336. File.Delete(FileName);
  5337. }
  5338. string CfgFileInfo = "";
  5339. CfgFileInfo += "[PortSet]" + "\r\n";
  5340. CfgFileInfo += "PortNum:" + toolStripComboBox_ComNum.Text + "\r\n";
  5341. CfgFileInfo += "PortBaudrate:" + "115200" + "\r\n";
  5342. CfgFileInfo += "AutoOn:" + 连接开机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5343. CfgFileInfo += "AutoOff:" + 断开关机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5344. CfgFileInfo += "CheckCDL:" + 识别通讯盒ToolStripMenuItem.Checked.ToString() + "\r\n";
  5345. CfgFileInfo += "\r\n";
  5346. CfgFileInfo += "[Option]" + "\r\n";
  5347. CfgFileInfo += "SaveWhenWrite:" + 写入存储ToolStripMenuItem.Checked.ToString() + "\r\n";
  5348. CfgFileInfo += "\r\n";
  5349. CfgFileInfo += "[ServerSet]" + "\r\n";
  5350. CfgFileInfo += "PathName:" + toolStripTextBox_ServerPath.Text + "\r\n";
  5351. CfgFileInfo += "\r\n";
  5352. CfgFileInfo += "[MacInfo]" + "\r\n";
  5353. CfgFileInfo += "MacName:" + toolStripTextBox_MAC.Text + "\r\n";
  5354. CfgFileInfo += "MacAddress:" + toolStripTextBoxMACAddr.Text + "\r\n";
  5355. CfgFileInfo += "MacDate:" + toolStripTextBox_MACDate.Text + "\r\n";
  5356. CfgFileInfo += "MacPdInfo:" + toolStripTextBox_MACPD.Text + "\r\n";
  5357. CfgFileInfo += "\r\n";
  5358. CfgFileInfo += "[LogAddress]" + "\r\n";
  5359. CfgFileInfo += "BeginAddress:" + textBox_LogAddrBegin.Text + "\r\n";
  5360. CfgFileInfo += "EndAddress:" + textBox_LogAddrEnd.Text + "\r\n";
  5361. CfgFileInfo += "\r\n";
  5362. CfgFileInfo += "[MotorType]" + "\r\n";
  5363. CfgFileInfo += "MidMotor:" + 中置电机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5364. CfgFileInfo += "HubMotor:" + 轮毂电机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5365. CfgFileInfo += "\r\n";
  5366. CfgFileInfo += "[CheckValue]" + "\r\n";
  5367. CfgFileInfo += "Voltage:" + toolStripTextBox_ThVol.Text + "\r\n";
  5368. CfgFileInfo += "Current:" + toolStripTextBox_ThCur.Text + "\r\n";
  5369. CfgFileInfo += "MotorSpeed:" + toolStripTextBox_ThSpeed.Text + "\r\n";
  5370. CfgFileInfo += "Torque:" + toolStripTextBox_ThTor.Text + "\r\n";
  5371. CfgFileInfo += "Cadence:" + toolStripTextBox_ThCad.Text + "\r\n";
  5372. CfgFileInfo += "BikeSpeed:" + toolStripTextBox_ThBikeSpeed.Text + "\r\n";
  5373. CfgFileInfo += "T_PCB:" + toolStripTextBox_ThT_PCB.Text + "\r\n";
  5374. CfgFileInfo += "T_MCU:" + toolStripTextBox_ThT_MCU.Text + "\r\n";
  5375. CfgFileInfo += "T_Motor:" + toolStripTextBox_ThT_Motor.Text + "\r\n";
  5376. CfgFileInfo += "\r\n";
  5377. CfgFileInfo += "[MosCalK]" + "\r\n";
  5378. CfgFileInfo += "K1-K5:" + toolStripTextBox_MosCalK.Text + "\r\n";
  5379. CfgFileInfo += "MOS1:" + toolStripTextBox_MOS1.Text + "\r\n";
  5380. CfgFileInfo += "MOS2:" + toolStripTextBox_MOS2.Text + "\r\n";
  5381. CfgFileInfo += "MOS3:" + toolStripTextBox_MOS3.Text + "\r\n";
  5382. CfgFileInfo += "\r\n";
  5383. CfgFileInfo += "[ProtocolType]" + "\r\n";
  5384. CfgFileInfo += "CAN:" + cANToolStripMenuItem.Checked.ToString() + "\r\n";
  5385. CfgFileInfo += "UART:" + uARTToolStripMenuItem.Checked.ToString() + "\r\n";
  5386. CfgFileInfo += "\r\n";
  5387. CfgFileInfo += "[AutoUpdate]" + "\r\n";
  5388. CfgFileInfo += "AutoUpdate:" + 打开ToolStripMenuItem.Checked.ToString() + "\r\n";
  5389. CfgFileInfo += "\r\n";
  5390. CfgFileInfo += "[AngleCal]" + "\r\n";
  5391. CfgFileInfo += "MaxDiffLimit:" + textBox_AngleDiffTh.Text + "\r\n";
  5392. CfgFileInfo += "ZeroDiffLimit:" + textBox_AngleZeroTh.Text + "\r\n";
  5393. System.IO.File.WriteAllText(FileName, CfgFileInfo);
  5394. }
  5395. /// <summary>
  5396. /// 配置状态更新,点击时保存
  5397. /// </summary>
  5398. private void ConfigFileSave_Click(object sender, EventArgs e)
  5399. {
  5400. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5401. }
  5402. /// <summary>
  5403. /// 文本框修改结束,回车保存
  5404. /// </summary>
  5405. /// <param name="sender"></param>
  5406. /// <param name="e"></param>
  5407. private void ConfigFileSave_KeyDown(object sender, KeyEventArgs e)
  5408. {
  5409. if (e.KeyCode == Keys.Enter)
  5410. {
  5411. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5412. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  5413. }
  5414. }
  5415. /// <summary>
  5416. /// 弹出扫码按钮
  5417. /// </summary>
  5418. /// <param name="sender"></param>
  5419. /// <param name="e"></param>
  5420. private void button_ScanCode_Click(object sender, EventArgs e)
  5421. {
  5422. Scan scan_form = new Scan();
  5423. scan_form.ShowDialog();
  5424. do
  5425. {
  5426. if (scan_form.textBox_Scan.Text == string.Empty)
  5427. {
  5428. timer_500ms.Enabled = false;
  5429. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5430. timer_500ms.Enabled = true;
  5431. break;
  5432. }
  5433. string ScanInfo = scan_form.textBox_Scan.Text;
  5434. string regexInfo = "";
  5435. string[] InfoList = { "" };
  5436. try
  5437. {
  5438. if (中置电机ToolStripMenuItem.Checked == true)
  5439. {
  5440. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  5441. InfoList = Regex.Split(ScanInfo, regexInfo, RegexOptions.IgnoreCase);
  5442. }
  5443. else if (轮毂电机ToolStripMenuItem.Checked == true)
  5444. {
  5445. if (!ScanInfo.Contains("/")) //老编码规则
  5446. {
  5447. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  5448. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  5449. string Spec = InfoList[1];
  5450. string Sn = InfoList[2];
  5451. InfoList[0] = Model.Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  5452. InfoList[1] = Sn;
  5453. }
  5454. else //新编码规则
  5455. {
  5456. Dictionary<string, string> Dic_Ver = new Dictionary<string, string>
  5457. {
  5458. { "01", "A" },
  5459. { "02", "B" },
  5460. { "03", "C" },
  5461. { "04", "D" },
  5462. { "05", "E" },
  5463. { "06", "F" },
  5464. { "07", "G" },
  5465. { "08", "H" },
  5466. { "09", "I" }
  5467. };
  5468. Dictionary<string, string> Dic_Vol = new Dictionary<string, string>
  5469. {
  5470. { "24V", "A" },
  5471. { "36V", "B" },
  5472. { "42V", "C" },
  5473. { "48V", "D" },
  5474. { "52V", "E" },
  5475. { "60V", "F" }
  5476. };
  5477. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  5478. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  5479. string Spec = InfoList[1].Replace("-", "").Replace("/","");
  5480. string Sn = InfoList[2];
  5481. InfoList[0] = Model[2] + Dic_Ver[Model.Substring(3, 2)] + Model[5] + Dic_Ver[Model.Substring(6, 2)] + Model[9];
  5482. InfoList[0] += Dic_Vol[Spec.Substring(0, 3)] + Spec.Substring(3, 3) + Spec.Substring(13, 4) + Spec.Substring(Spec.Length - 4, 3);
  5483. InfoList[1] = Sn;
  5484. }
  5485. }
  5486. }
  5487. catch (Exception)
  5488. {
  5489. MessageBox.Show("格式错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5490. return;
  5491. }
  5492. if (InfoList.Length >= 2)
  5493. {
  5494. //写入型号
  5495. textBox_FacModeName.Text = InfoList[0];
  5496. string Mode = textBox_FacModeName.Text;
  5497. var ModeArray = new byte[16];
  5498. for (ushort i = 0; i < Mode.Length; i++)
  5499. {
  5500. ModeArray[i] = (byte)Mode[i];
  5501. }
  5502. if (Mode.Length < 16)
  5503. {
  5504. ModeArray[Mode.Length] = (byte)'.';
  5505. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  5506. {
  5507. ModeArray[Mode.Length + 1 + i] = 0x20;
  5508. }
  5509. }
  5510. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  5511. //写入SN
  5512. textBox_FacModeNum.Text = InfoList[1];
  5513. string SN = textBox_FacModeNum.Text;
  5514. var SNArray = new byte[16];
  5515. for (ushort i = 0; i < SN.Length; i++)
  5516. {
  5517. SNArray[i] = (byte)SN[i];
  5518. }
  5519. if (SN.Length < 16)
  5520. {
  5521. SNArray[SN.Length] = (byte)'.';
  5522. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  5523. {
  5524. SNArray[SN.Length + 1 + i] = 0x20;
  5525. }
  5526. }
  5527. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  5528. }
  5529. else
  5530. {
  5531. timer_500ms.Enabled = false;
  5532. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5533. timer_500ms.Enabled = true;
  5534. break;
  5535. }
  5536. } while (false);
  5537. scan_form.Dispose();
  5538. }
  5539. /// <summary>
  5540. /// 切换电机类型
  5541. /// </summary>
  5542. /// <param name="sender"></param>
  5543. /// <param name="e"></param>
  5544. private void 中置电机ToolStripMenuItem_Click(object sender, EventArgs e)
  5545. {
  5546. 中置电机ToolStripMenuItem.Checked = true;
  5547. 轮毂电机ToolStripMenuItem.Checked = false;
  5548. toolStripTextBox_MACPD.Text = "MM_MC1";
  5549. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  5550. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5551. }
  5552. /// <summary>
  5553. /// 切换电机类型
  5554. /// </summary>
  5555. /// <param name="sender"></param>
  5556. /// <param name="e"></param>
  5557. private void 轮毂电机ToolStripMenuItem_Click(object sender, EventArgs e)
  5558. {
  5559. 中置电机ToolStripMenuItem.Checked = false;
  5560. 轮毂电机ToolStripMenuItem.Checked = true;
  5561. toolStripTextBox_MACPD.Text = "GF_250_1";
  5562. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  5563. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5564. }
  5565. /// <summary>
  5566. /// 获取配置文件日期
  5567. /// </summary>
  5568. /// <param name="DisAll"></param>
  5569. private void GetDateList(bool DisAll)
  5570. {
  5571. string[] DateList = { "" };
  5572. //从服务器更新日期列表
  5573. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  5574. {
  5575. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
  5576. }
  5577. //从本地更新日期列表
  5578. else
  5579. {
  5580. DateList = Directory.GetDirectories(localInfo.LocalPath + "\\" + localInfo.CfgPathName);
  5581. }
  5582. comboBox_FacModeCfgDate.Items.Clear();
  5583. comboBox_CheckModeCfgDate.Items.Clear();
  5584. //日期列表加载
  5585. if (DisAll == true)
  5586. {
  5587. comboBox_FacModeCfgDate.Items.Add("显示近期");
  5588. comboBox_CheckModeCfgDate.Items.Add("显示近期");
  5589. comboBox_FacModeCfgDate.Items.Add("---");
  5590. comboBox_CheckModeCfgDate.Items.Add("---");
  5591. foreach (var file in DateList)
  5592. {
  5593. comboBox_FacModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5594. comboBox_CheckModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5595. }
  5596. }
  5597. else
  5598. {
  5599. if (DateList.Length > 10)
  5600. {
  5601. comboBox_FacModeCfgDate.Items.Add("显示全部");
  5602. comboBox_CheckModeCfgDate.Items.Add("显示全部");
  5603. comboBox_FacModeCfgDate.Items.Add("---");
  5604. comboBox_CheckModeCfgDate.Items.Add("---");
  5605. }
  5606. for (int i = (DateList.Length > 10) ? (DateList.Length - 10) : 0; i < DateList.Length; i++)//显示最近10个日期
  5607. {
  5608. comboBox_FacModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  5609. comboBox_CheckModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  5610. }
  5611. }
  5612. }
  5613. /// <summary>
  5614. /// 获取配置文件列表
  5615. /// </summary>
  5616. /// <param name="date"></param>
  5617. private void GetFileListFrom(string date)
  5618. {
  5619. string[] FileList = { "" };
  5620. //从服务器更新文件列表
  5621. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  5622. {
  5623. FileList = myFtp.GetFileNameList(toolStripTextBox_ServerPath.Text + "/cfg/" + date);
  5624. }
  5625. else
  5626. {
  5627. FileList = Directory.GetFiles(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + date);
  5628. }
  5629. comboBox_CheckModeCfgFile.Items.Clear();
  5630. comboBox_FacModeCfgFile.Items.Clear();
  5631. foreach (var file in FileList)
  5632. {
  5633. if (file.Contains(".ttcfg"))
  5634. {
  5635. comboBox_CheckModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5636. comboBox_FacModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5637. }
  5638. }
  5639. }
  5640. /// <summary>
  5641. /// 检验模式选择文件日期
  5642. /// </summary>
  5643. /// <param name="sender"></param>
  5644. /// <param name="e"></param>
  5645. private void comboBox_CheckModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  5646. {
  5647. if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示全部")
  5648. {
  5649. GetDateList(true);
  5650. }
  5651. else if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示近期")
  5652. {
  5653. GetDateList(false);
  5654. }
  5655. else
  5656. {
  5657. comboBox_CheckModeCfgFile.Text = "";
  5658. GetFileListFrom(comboBox_CheckModeCfgDate.SelectedItem.ToString());
  5659. }
  5660. }
  5661. /// <summary>
  5662. /// 配置模式选择文件日期
  5663. /// </summary>
  5664. /// <param name="sender"></param>
  5665. /// <param name="e"></param>
  5666. private void comboBox_FacModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  5667. {
  5668. if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示全部")
  5669. {
  5670. GetDateList(true);
  5671. }
  5672. else if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示近期")
  5673. {
  5674. GetDateList(false);
  5675. }
  5676. else
  5677. {
  5678. comboBox_FacModeCfgFile.Text = "";
  5679. GetFileListFrom(comboBox_FacModeCfgDate.SelectedItem.ToString());
  5680. }
  5681. }
  5682. /// <summary>
  5683. /// 选中量产模式
  5684. /// </summary>
  5685. /// <param name="sender"></param>
  5686. /// <param name="e"></param>
  5687. private void tabControl1_Selected(object sender, TabControlEventArgs e)
  5688. {
  5689. //更新生产配置文件目录
  5690. GetDateList(false);
  5691. }
  5692. /// <summary>
  5693. /// 量产测试结束
  5694. /// </summary>
  5695. /// <param name=""></param>
  5696. private void FacMode_Stop(bool OK_Flag)
  5697. {
  5698. //打开开始按钮
  5699. button__FacMode_Start.Enabled = true;
  5700. //系统关机
  5701. var Code = new byte[32];//发送的指令数据
  5702. Code[0] = 0xF0;
  5703. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5704. //关闭串口
  5705. //mySerialProcess.SerialClose(false);
  5706. //路径设置
  5707. string LocalSavePath = "";
  5708. string ServerSavePath = "";
  5709. if (OK_Flag)
  5710. {
  5711. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "OK\\";
  5712. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/OK/";
  5713. }
  5714. else
  5715. {
  5716. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "FAIL\\";
  5717. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/FAIL/";
  5718. }
  5719. if (Directory.Exists(LocalSavePath) == false)
  5720. {
  5721. Directory.CreateDirectory(LocalSavePath);
  5722. }
  5723. //保存和上传
  5724. string LogSavePath = "";
  5725. string LogSaveFileName = "";
  5726. string ProductInfo = textBox_FacModeScan.Text.Replace(" ", "_").Replace("/", "-");
  5727. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  5728. if (Directory.Exists(LogSavePath) == false)
  5729. {
  5730. Directory.CreateDirectory(LogSavePath);
  5731. }
  5732. //测试页面
  5733. Double scaleX = PrimaryScreen.ScaleX;
  5734. Double scaleY = PrimaryScreen.ScaleY;
  5735. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  5736. Graphics g = Graphics.FromImage(bit);
  5737. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  5738. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  5739. bit.Save(LogSaveFileName);
  5740. //上传测试页面到服务器
  5741. if (myFtp.IsNetConnected == true)
  5742. {
  5743. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  5744. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  5745. {
  5746. myFtp.MakeDir(ServerSavePath + DateNow);
  5747. }
  5748. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  5749. {
  5750. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  5751. }
  5752. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  5753. if (result == true)
  5754. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  5755. }
  5756. else
  5757. {
  5758. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  5759. }
  5760. //测试记录
  5761. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  5762. string file_str = "";
  5763. file_str += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  5764. file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  5765. file_str += "检验记录:\r\n" + richTextBox_FacModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  5766. file_str += "检验结果:\r\n" + label_FacModeResult.Text + "\r\n\r\n";
  5767. file_str += Local_HdInformation;
  5768. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  5769. //上传测试记录到服务器
  5770. if (myFtp.IsNetConnected == true)
  5771. {
  5772. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  5773. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  5774. {
  5775. myFtp.MakeDir(ServerSavePath + DateNow);
  5776. }
  5777. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  5778. {
  5779. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  5780. }
  5781. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  5782. if (result == true)
  5783. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  5784. }
  5785. else
  5786. {
  5787. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  5788. }
  5789. //扫码框清空
  5790. textBox_FacModeScan.Text = "";
  5791. }
  5792. /// <summary>
  5793. /// 量产测试开始
  5794. /// </summary>
  5795. /// <param name="sender"></param>
  5796. /// <param name="e"></param>
  5797. private void button__FacMode_Start_Click(object sender, EventArgs e)
  5798. {
  5799. //关闭测试项目编辑
  5800. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  5801. foreach (Control c in groupBox2.Controls)
  5802. {
  5803. if (c is CheckBox)
  5804. c.Enabled = false;
  5805. }
  5806. WriteLockStatus = true;
  5807. //检查配置文件
  5808. if (comboBox_FacModeCfgFile.Text == "")
  5809. {
  5810. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5811. return;
  5812. }
  5813. //开始测试
  5814. TestStart();
  5815. }
  5816. /// <summary>
  5817. /// 测试子函数
  5818. /// </summary>
  5819. private void TestStart()
  5820. {
  5821. //初始化标签
  5822. FacModelLabelInit();
  5823. richTextBox_FacModeLog.Clear();
  5824. //按钮禁止操作
  5825. button__FacMode_Start.Enabled = false;
  5826. //记录配置文件
  5827. richTextBox_FacModeLog.AppendText("配置文件:" + comboBox_FacModeCfgDate.Text + " / " + comboBox_FacModeCfgFile.Text + "\r\n");
  5828. //检查打标信息格式
  5829. label_FacModeStatus.Text = "检查扫码信息";
  5830. Delay_ms(500);
  5831. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  5832. if (textBox_FacModeScan.Text == string.Empty)
  5833. {
  5834. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5835. button__FacMode_Start.Enabled = true;
  5836. return;
  5837. }
  5838. try
  5839. {
  5840. if (中置电机ToolStripMenuItem.Checked == true)
  5841. {
  5842. if (textBox_FacModeScan.Text.Split(' ').Length != 7)
  5843. {
  5844. label_FacModeStatus.Text = "存在故障!";
  5845. label_FacModeResult.BackColor = Color.Red;
  5846. label_FacModeResult.Text = "标签格式错误";
  5847. button__FacMode_Start.Enabled = true;
  5848. return;
  5849. }
  5850. }
  5851. else if (轮毂电机ToolStripMenuItem.Checked == true)
  5852. {
  5853. if (textBox_FacModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  5854. {
  5855. label_FacModeStatus.Text = "存在故障!";
  5856. label_FacModeResult.BackColor = Color.Red;
  5857. label_FacModeResult.Text = "标签格式错误";
  5858. button__FacMode_Start.Enabled = true;
  5859. return;
  5860. }
  5861. }
  5862. }
  5863. catch (System.Exception)
  5864. {
  5865. label_FacModeStatus.Text = "存在故障!";
  5866. label_FacModeResult.BackColor = Color.Red;
  5867. label_FacModeResult.Text = "标签格式错误";
  5868. button__FacMode_Start.Enabled = true;
  5869. return;
  5870. }
  5871. //打开串口
  5872. mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false);
  5873. if (!mySerialProcess.mySerial.IsOpen)
  5874. {
  5875. MessageBox.Show("请检查串口连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5876. //按钮禁止操作
  5877. button__FacMode_Start.Enabled = true;
  5878. return;
  5879. }
  5880. //流水号计数
  5881. int serial = Convert.ToInt32(label_FacModeSerial.Text);
  5882. serial += 1;
  5883. label_FacModeSerial.Text = serial.ToString();
  5884. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, serial.ToString());
  5885. //创建线程,执行测试任务
  5886. Thread th = new Thread(FacModeTest_Task);
  5887. th.Start();
  5888. }
  5889. /// <summary>
  5890. /// 执行一次测试任务
  5891. /// </summary>
  5892. private void FacModeTest_Task()
  5893. {
  5894. //开始测试
  5895. richTextBox_FacModeLog.AppendText("产品标签:" + textBox_FacModeScan.Text + "\r\n");
  5896. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  5897. //变量定义
  5898. var Code = new byte[255];//发送的指令数据
  5899. label_FacModeStatus.Text = "开始测试";
  5900. BootInfo = "";
  5901. Delay_ms(500);
  5902. label_FacModeStatus.Text = "系统开机";
  5903. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  5904. if (uARTToolStripMenuItem.Checked)
  5905. {
  5906. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送复位指令,切换联动装置盒波特率" + "\r\n");
  5907. Code[0] = (byte)'R';
  5908. Code[1] = (byte)'E';
  5909. Code[2] = (byte)'S';
  5910. Code[3] = (byte)'E';
  5911. Code[4] = (byte)'T';
  5912. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  5913. Delay_ms(500);
  5914. }
  5915. //发送开机指令
  5916. //确保测试前先关机,发送关机指令再发送开机指令
  5917. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  5918. Code[0] = 0xF0;
  5919. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5920. Delay_ms(1500);
  5921. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  5922. Code[0] = 0xF1;
  5923. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5924. ACK_WaitCnt = 0;
  5925. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  5926. while (ACK_WaitCnt <= 20) ; //10s,等待开机成功,联动装置盒控制器接口波特率需等待5s接口自动切换为9600
  5927. //检查BOOT版本
  5928. if (BootInfo != string.Empty)
  5929. {
  5930. label_FacModeBootVer.BackColor = Color.Green;
  5931. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  5932. Delay_ms(500);
  5933. }
  5934. else
  5935. {
  5936. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
  5937. label_FacModeStatus.Text = "存在故障!";
  5938. label_FacModeResult.BackColor = Color.Red;
  5939. label_FacModeResult.Text = "测试异常";
  5940. Delay_ms(500);
  5941. //存储异常并上传
  5942. FacMode_Stop(false);
  5943. return;
  5944. }
  5945. //系统清除
  5946. if (checkBox_FacModeSysClear.Checked)
  5947. {
  5948. do
  5949. {
  5950. #if false
  5951. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  5952. {
  5953. Code[0] = 0x00;//5S协议
  5954. Code[1] = 0x00;
  5955. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5956. Delay_ms(500);
  5957. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5958. Delay_ms(500);
  5959. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  5960. }
  5961. #endif
  5962. //发送系统清除指令
  5963. label_FacModeStatus.Text = "系统清除";
  5964. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除" + "\r\n");
  5965. Code[0] = (byte)'C';
  5966. Code[1] = (byte)'L';
  5967. Code[2] = (byte)'E';
  5968. Code[3] = (byte)'A';
  5969. Code[4] = (byte)'R';
  5970. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  5971. WriteACK = false;
  5972. ACK_WaitCnt = 0;
  5973. while (ACK_WaitCnt <= 6); //3s
  5974. //等待系统清除完成指令
  5975. if (WriteACK == true)
  5976. {
  5977. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  5978. label_FacModeSysClear.BackColor = Color.Green;
  5979. }
  5980. else
  5981. {
  5982. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除,重发第1次" + "\r\n");
  5983. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  5984. ACK_WaitCnt = 0;
  5985. while (ACK_WaitCnt <= 6) ; //3s
  5986. //等待系统清除完成指令
  5987. if (WriteACK == true)
  5988. {
  5989. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  5990. label_FacModeSysClear.BackColor = Color.Green;
  5991. }
  5992. else
  5993. {
  5994. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除,重发第2次" + "\r\n");
  5995. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  5996. ACK_WaitCnt = 0;
  5997. while (ACK_WaitCnt <= 6) ; //3s
  5998. //等待系统清除完成指令
  5999. if (WriteACK == true)
  6000. {
  6001. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  6002. label_FacModeSysClear.BackColor = Color.Green;
  6003. }
  6004. else
  6005. {
  6006. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除失败" + "\r\n");
  6007. label_FacModeStatus.Text = "存在故障!";
  6008. label_FacModeResult.BackColor = Color.Red;
  6009. label_FacModeResult.Text = "测试异常";
  6010. Delay_ms(500);
  6011. //存储异常并上传
  6012. FacMode_Stop(false);
  6013. return;
  6014. }
  6015. }
  6016. }
  6017. BootInfo = "";
  6018. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  6019. if (uARTToolStripMenuItem.Checked)
  6020. {
  6021. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送复位指令,切换联动装置盒波特率" + "\r\n");
  6022. Code[0] = (byte)'R';
  6023. Code[1] = (byte)'E';
  6024. Code[2] = (byte)'S';
  6025. Code[3] = (byte)'E';
  6026. Code[4] = (byte)'T';
  6027. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  6028. Delay_ms(500);
  6029. }
  6030. //系统清除后需重新开机
  6031. label_FacModeStatus.Text = "重新开机";
  6032. //确保测试前先关机,发送关机指令再发送开机指令
  6033. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新发送关机指令" + "\r\n");
  6034. Code[0] = 0xF0;
  6035. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6036. Delay_ms(1500);
  6037. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新发送开机指令" + "\r\n");
  6038. Code[0] = 0xF1;
  6039. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6040. ACK_WaitCnt = 0;
  6041. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  6042. while (ACK_WaitCnt <= 20); //10s
  6043. //获取Boot版本信息
  6044. if (BootInfo != string.Empty)
  6045. {
  6046. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机成功" + "\r\n");
  6047. Delay_ms(500);
  6048. }
  6049. else
  6050. {
  6051. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机失败" + "\r\n");
  6052. label_FacModeStatus.Text = "存在故障!";
  6053. label_FacModeResult.BackColor = Color.Red;
  6054. label_FacModeResult.Text = "测试异常";
  6055. Delay_ms(500);
  6056. //存储异常并上传
  6057. FacMode_Stop(false);
  6058. return;
  6059. }
  6060. } while (false);
  6061. }
  6062. else
  6063. {
  6064. label_FacModeSysClear.BackColor = Color.Yellow;
  6065. label_FacModeStatus.Text = "跳过系统清除!";
  6066. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过系统清除" + "\r\n");
  6067. Delay_ms(500);
  6068. }
  6069. #if false
  6070. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  6071. {
  6072. Code[0] = 0x00;//5S协议
  6073. Code[1] = 0x00;
  6074. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6075. Delay_ms(500);
  6076. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6077. Delay_ms(500);
  6078. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  6079. }
  6080. #endif
  6081. //检查是否有故障
  6082. if (textBox_ErrorCode.Text.Contains("H"))
  6083. {
  6084. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "故障码:" + textBox_ErrorCode.Text + "\r\n");
  6085. label_FacModeStatus.Text = "电机存在故障!";
  6086. label_FacModeResult.BackColor = Color.Red;
  6087. label_FacModeResult.Text = "测试异常";
  6088. Delay_ms(500);
  6089. //存储异常并上传
  6090. FacMode_Stop(false);
  6091. return;
  6092. }
  6093. //MOS内阻校准
  6094. if (checkBox_FacMode_MosCal.Checked)
  6095. {
  6096. label_FacModeStatus.Text = "MOS内阻校准";
  6097. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始MOS内阻校准" + "\r\n");
  6098. Delay_ms(500);
  6099. //提示进行负载切换
  6100. if (MessageBox.Show("电阻负载切换完成,开始校准?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
  6101. {
  6102. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "取消MOS内阻校准" + "\r\n");
  6103. label_FacModeStatus.Text = "存在故障!";
  6104. label_FacModeResult.BackColor = Color.Red;
  6105. label_FacModeResult.Text = "测试异常";
  6106. Delay_ms(500);
  6107. //存储异常并上传
  6108. FacMode_Stop(false);
  6109. return;
  6110. }
  6111. //确认后发送校准指令
  6112. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令" + "\r\n");
  6113. string[] K = toolStripTextBox_MosCalK.Text.Split(',');
  6114. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  6115. ushort uwDataTemp = 0;
  6116. uwDataTemp = Convert.ToUInt16(K[0]);
  6117. Code[2] = (byte)(uwDataTemp & 0xFF);
  6118. Code[3] = (byte)(uwDataTemp >> 8);
  6119. uwDataTemp = Convert.ToUInt16(K[1]);
  6120. Code[4] = (byte)(uwDataTemp & 0xFF);
  6121. Code[5] = (byte)(uwDataTemp >> 8);
  6122. uwDataTemp = Convert.ToUInt16(K[2]);
  6123. Code[6] = (byte)(uwDataTemp & 0xFF);
  6124. Code[7] = (byte)(uwDataTemp >> 8);
  6125. uwDataTemp = Convert.ToUInt16(K[3]);
  6126. Code[8] = (byte)(uwDataTemp & 0xFF);
  6127. Code[9] = (byte)(uwDataTemp >> 8);
  6128. uwDataTemp = Convert.ToUInt16(K[4]);
  6129. Code[10] = (byte)(uwDataTemp & 0xFF);
  6130. Code[11] = (byte)(uwDataTemp >> 8);
  6131. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  6132. WriteACK = false;
  6133. ACK_WaitCnt = 0;
  6134. while (ACK_WaitCnt <= 6) ; //3s
  6135. if (WriteACK == true)
  6136. {
  6137. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  6138. }
  6139. else
  6140. {
  6141. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令,第1次重发" + "\r\n");
  6142. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  6143. ACK_WaitCnt = 0;
  6144. while (ACK_WaitCnt <= 6) ; //3s
  6145. if (WriteACK == true)
  6146. {
  6147. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  6148. }
  6149. else
  6150. {
  6151. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令,第2次重发" + "\r\n");
  6152. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  6153. ACK_WaitCnt = 0;
  6154. while (ACK_WaitCnt <= 6) ; //3s
  6155. if (WriteACK == true)
  6156. {
  6157. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  6158. }
  6159. else
  6160. {
  6161. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准异常" + "\r\n");
  6162. label_FacModeStatus.Text = "存在故障!";
  6163. label_FacModeResult.BackColor = Color.Red;
  6164. label_FacModeResult.Text = "测试异常";
  6165. Delay_ms(500);
  6166. //存储异常并上传
  6167. FacMode_Stop(false);
  6168. return;
  6169. }
  6170. }
  6171. }
  6172. #if false
  6173. //因控制器复位需发送指令重新进入5S协议
  6174. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  6175. {
  6176. Code[0] = 0x00;//5S协议
  6177. Code[1] = 0x00;
  6178. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6179. Delay_ms(500);
  6180. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6181. Delay_ms(500);
  6182. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  6183. }
  6184. #endif
  6185. //读取显示校准返回数据
  6186. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果" + "\r\n");
  6187. foreach (Control c in groupBox21.Controls)
  6188. {
  6189. if (c is TextBox)
  6190. c.Text = "";
  6191. }
  6192. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  6193. ACK_WaitCnt = 0;
  6194. while (ACK_WaitCnt <= 2) ; //1s
  6195. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  6196. {
  6197. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果,第1次重发" + "\r\n");
  6198. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  6199. ACK_WaitCnt = 0;
  6200. while (ACK_WaitCnt <= 2) ; //1s
  6201. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  6202. {
  6203. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果,第2次重发" + "\r\n");
  6204. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  6205. ACK_WaitCnt = 0;
  6206. while (ACK_WaitCnt <= 2) ; //1s
  6207. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  6208. {
  6209. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果异常" + "\r\n");
  6210. label_FacModeStatus.Text = "存在故障!";
  6211. label_FacModeResult.BackColor = Color.Red;
  6212. label_FacModeResult.Text = "测试异常";
  6213. Delay_ms(500);
  6214. //存储异常并上传
  6215. FacMode_Stop(false);
  6216. return;
  6217. }
  6218. }
  6219. }
  6220. else
  6221. {
  6222. 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");
  6223. }
  6224. //与校准返回数据对比
  6225. string[] MOS_R1_Th = toolStripTextBox_MOS1.Text.Split(',');
  6226. string[] MOS_R2_Th = toolStripTextBox_MOS2.Text.Split(',');
  6227. string[] MOS_R3_Th = toolStripTextBox_MOS3.Text.Split(',');
  6228. 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])) &&
  6229. (Convert.ToUInt16(textBox_MOS_R2.Text) >= Convert.ToUInt16(MOS_R2_Th[0])) && (Convert.ToUInt16(textBox_MOS_R2.Text) <= Convert.ToUInt16(MOS_R2_Th[1])) &&
  6230. (Convert.ToUInt16(textBox_MOS_R3.Text) >= Convert.ToUInt16(MOS_R3_Th[0])) && (Convert.ToUInt16(textBox_MOS_R3.Text) <= Convert.ToUInt16(MOS_R3_Th[1]))
  6231. )
  6232. {
  6233. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准合格" + "\r\n");
  6234. label_FacModeMosCal.BackColor = Color.Green;
  6235. //提示切换负载
  6236. MessageBox.Show("请将负载切换回电机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  6237. }
  6238. else
  6239. {
  6240. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准超范围" + "\r\n");
  6241. label_FacModeStatus.Text = "存在故障!";
  6242. label_FacModeResult.BackColor = Color.Red;
  6243. label_FacModeResult.Text = "测试异常";
  6244. Delay_ms(500);
  6245. //存储异常并上传
  6246. FacMode_Stop(false);
  6247. //提示切换负载
  6248. MessageBox.Show("请将负载切换回电机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  6249. return;
  6250. }
  6251. }
  6252. else
  6253. {
  6254. label_FacModeMosCal.BackColor = Color.Yellow;
  6255. label_FacModeStatus.Text = "跳过MOS内阻校准!";
  6256. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过MOS内阻校准" + "\r\n");
  6257. Delay_ms(500);
  6258. }
  6259. //位置校准
  6260. if (checkBox_FacMode_AngleCal.Checked)
  6261. {
  6262. //校准前进行一次开关机保存初始化数据
  6263. BootInfo = "";
  6264. label_FacModeStatus.Text = "位置校准";
  6265. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始位置校准" + "\r\n");
  6266. //确保测试前先关机,发送关机指令再发送开机指令
  6267. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  6268. Code[0] = 0xF0;
  6269. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6270. Delay_ms(1500);
  6271. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  6272. Code[0] = 0xF1;
  6273. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6274. ACK_WaitCnt = 0;
  6275. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  6276. while (ACK_WaitCnt <= 10) ; //5s
  6277. //获取Boot版本信息
  6278. if (BootInfo != string.Empty)
  6279. {
  6280. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机成功" + "\r\n");
  6281. Delay_ms(500);
  6282. }
  6283. else
  6284. {
  6285. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机失败" + "\r\n");
  6286. label_FacModeStatus.Text = "存在故障!";
  6287. label_FacModeResult.BackColor = Color.Red;
  6288. label_FacModeResult.Text = "测试异常";
  6289. Delay_ms(500);
  6290. //存储异常并上传
  6291. FacMode_Stop(false);
  6292. return;
  6293. }
  6294. //发送位置校准指令
  6295. for (int i = 0; i < 7; i++)
  6296. for (int j = 0; j < 6; j++)
  6297. {
  6298. dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = "";
  6299. }
  6300. foreach (Control cr in tabPage_AngleCal.Controls)
  6301. {
  6302. if (cr is TextBox)
  6303. {
  6304. if ((cr != textBox_AngleDiffTh) && (cr != textBox_AngleZeroTh))
  6305. cr.Text = "";
  6306. }
  6307. }
  6308. Code[0] = 0;
  6309. Code[1] = 0;
  6310. mySerialProcess.SendCmd((ushort)0x751, (byte)0x0C, (ushort)0x5002, Code);
  6311. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准中,请等待" + "\r\n");
  6312. ACK_WaitCnt = 0;
  6313. while (ACK_WaitCnt <= 50) ; //25s
  6314. //读取位置校准数据
  6315. if (textBox_AngleDiffAvg.Text == string.Empty)
  6316. {
  6317. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准失败" + "\r\n");
  6318. label_FacModeStatus.Text = "存在故障!";
  6319. label_FacModeResult.BackColor = Color.Red;
  6320. label_FacModeResult.Text = "测试异常";
  6321. Delay_ms(500);
  6322. //存储异常并上传
  6323. FacMode_Stop(false);
  6324. return;
  6325. }
  6326. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准数据:" + "\r\n");
  6327. for (int i = 0; i < 7; i++)
  6328. {
  6329. richTextBox_FacModeLog.AppendText("电周期" + (i + 1).ToString()+":");
  6330. for (int j = 0; j < 6; j++)
  6331. {
  6332. richTextBox_FacModeLog.AppendText(dataGridView_AngleCal.Rows[i].Cells[j + 1].Value.ToString() + ", ");
  6333. }
  6334. richTextBox_FacModeLog.AppendText("\r\n");
  6335. Delay_ms(200);
  6336. }
  6337. richTextBox_FacModeLog.AppendText("最小偏差:" + textBox_AngleDiffMin.Text+ ", " + "\r\n");
  6338. richTextBox_FacModeLog.AppendText("最大偏差:" + textBox_AngleDiffMax.Text + ", " + "\r\n");
  6339. richTextBox_FacModeLog.AppendText("平均偏差:" + textBox_AngleDiffAvg.Text + ", " + "\r\n");
  6340. richTextBox_FacModeLog.AppendText("历史零点:" + textBox_AngleZeroInit.Text + ", " + "\r\n");
  6341. richTextBox_FacModeLog.AppendText("当前零点:" + textBox_AngleZeroCur.Text + ", " + "\r\n");
  6342. richTextBox_FacModeLog.AppendText("零点偏差:" + textBox_AngleZeroDiff.Text + ", " + "\r\n");
  6343. //比较位置偏差
  6344. if ((Math.Abs(Convert.ToDouble(textBox_AngleDiffMin.Text)) > Convert.ToDouble(textBox_AngleDiffTh.Text)) ||
  6345. (Math.Abs(Convert.ToDouble(textBox_AngleDiffMax.Text)) > Convert.ToDouble(textBox_AngleDiffTh.Text)) ||
  6346. (Math.Abs(Convert.ToDouble(textBox_AngleDiffAvg.Text)) > Convert.ToDouble(textBox_AngleZeroTh.Text))
  6347. )
  6348. {
  6349. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差过大,无法校准" + "\r\n");
  6350. label_FacModeStatus.Text = "存在故障!";
  6351. label_FacModeResult.BackColor = Color.Red;
  6352. label_FacModeResult.Text = "测试异常";
  6353. Delay_ms(500);
  6354. //存储异常并上传
  6355. FacMode_Stop(false);
  6356. return;
  6357. }
  6358. //写入校准偏差值
  6359. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差满足要求,写入校准数据" + "\r\n");
  6360. double data1 = Convert.ToDouble(textBox_AngleZeroInit.Text) - Convert.ToDouble(textBox_AngleDiffAvg.Text);
  6361. if (data1 > 360)
  6362. {
  6363. data1 -= 360;
  6364. }
  6365. else if (data1 < -360)
  6366. {
  6367. data1 += 360;
  6368. }
  6369. Int16 data2 = (Int16)(data1 * 32768 / 360);
  6370. Code[0] = 0x01;
  6371. Code[1] = 0x00;
  6372. Code[2] = (byte)(data2);
  6373. Code[3] = (byte)(data2 >> 8);
  6374. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
  6375. WriteACK = false;
  6376. ACK_WaitCnt = 0;
  6377. while (ACK_WaitCnt <= 2) ; //1s
  6378. if (WriteACK == true)
  6379. {
  6380. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
  6381. }
  6382. else
  6383. {
  6384. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入位置偏差,第1次重发" + "\r\n");
  6385. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
  6386. WriteACK = false;
  6387. ACK_WaitCnt = 0;
  6388. while (ACK_WaitCnt <= 2) ; //1s
  6389. if (WriteACK == true)
  6390. {
  6391. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
  6392. }
  6393. else
  6394. {
  6395. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入位置偏差,第2次重发" + "\r\n");
  6396. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
  6397. WriteACK = false;
  6398. ACK_WaitCnt = 0;
  6399. while (ACK_WaitCnt <= 2) ; //1s
  6400. if (WriteACK == true)
  6401. {
  6402. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
  6403. }
  6404. else
  6405. {
  6406. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入失败" + "\r\n");
  6407. label_FacModeStatus.Text = "存在故障!";
  6408. label_FacModeResult.BackColor = Color.Red;
  6409. label_FacModeResult.Text = "测试异常";
  6410. Delay_ms(500);
  6411. //存储异常并上传
  6412. FacMode_Stop(false);
  6413. return;
  6414. }
  6415. }
  6416. }
  6417. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准正常,位置偏差值:" + textBox_AngleDiffAvg.Text + "\r\n");
  6418. label_FacModeAngleCal.BackColor = Color.Green;
  6419. }
  6420. else
  6421. {
  6422. label_FacModeAngleCal.BackColor = Color.Yellow;
  6423. label_FacModeStatus.Text = "跳过位置校准!";
  6424. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过位置校准" + "\r\n");
  6425. Delay_ms(500);
  6426. }
  6427. //参数写入
  6428. if (checkBox_FacModeCfgWrite.Checked)
  6429. {
  6430. label_FacModeStatus.Text = "参数写入";
  6431. //写入产品型号和SN
  6432. do
  6433. {
  6434. //根据扫码信息获取型号和SN
  6435. string ScanInfo = textBox_FacModeScan.Text;
  6436. string regexInfo = "";
  6437. string[] InfoList = { "" };
  6438. try
  6439. {
  6440. if (中置电机ToolStripMenuItem.Checked == true)
  6441. {
  6442. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  6443. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  6444. }
  6445. else if (轮毂电机ToolStripMenuItem.Checked == true)
  6446. {
  6447. if (!ScanInfo.Contains("/")) //老编码规则
  6448. {
  6449. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  6450. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  6451. string Spec = InfoList[1];
  6452. string Sn = InfoList[2];
  6453. InfoList[0] = Model.Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  6454. InfoList[1] = Sn;
  6455. }
  6456. else //新编码规则
  6457. {
  6458. Dictionary<string, string> Dic_Ver = new Dictionary<string, string>
  6459. {
  6460. { "01", "A" },
  6461. { "02", "B" },
  6462. { "03", "C" },
  6463. { "04", "D" },
  6464. { "05", "E" },
  6465. { "06", "F" },
  6466. { "07", "G" },
  6467. { "08", "H" },
  6468. { "09", "I" }
  6469. };
  6470. Dictionary<string, string> Dic_Vol = new Dictionary<string, string>
  6471. {
  6472. { "24V", "A" },
  6473. { "36V", "B" },
  6474. { "42V", "C" },
  6475. { "48V", "D" },
  6476. { "52V", "E" },
  6477. { "60V", "F" }
  6478. };
  6479. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  6480. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  6481. string Spec = InfoList[1].Replace("-", "").Replace("/", "");
  6482. string Sn = InfoList[2];
  6483. InfoList[0] = Model[2] + Dic_Ver[Model.Substring(3, 2)] + Model[5] + Dic_Ver[Model.Substring(6, 2)] + Model[9];
  6484. InfoList[0] += Dic_Vol[Spec.Substring(0, 3)] + Spec.Substring(3, 3) + Spec.Substring(13, 4) + Spec.Substring(Spec.Length - 4, 3);
  6485. InfoList[1] = Sn;
  6486. }
  6487. }
  6488. }
  6489. catch
  6490. {
  6491. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  6492. label_FacModeStatus.Text = "存在故障!";
  6493. label_FacModeResult.BackColor = Color.Red;
  6494. label_FacModeResult.Text = "标签格式错误";
  6495. Delay_ms(500);
  6496. //存储异常并上传
  6497. FacMode_Stop(false);
  6498. return;
  6499. }
  6500. if (InfoList.Length >= 2)
  6501. {
  6502. //检查配置文件是否与打标信息一致
  6503. //...
  6504. //写入型号
  6505. label_FacModeStatus.Text = "写入型号";
  6506. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号" + "\r\n");
  6507. textBox_FacModeName.Text = InfoList[0];
  6508. string Mode = textBox_FacModeName.Text;
  6509. var ModeArray = new byte[16];
  6510. for (ushort i = 0; i < Mode.Length; i++)
  6511. {
  6512. ModeArray[i] = (byte)Mode[i];
  6513. }
  6514. if (Mode.Length < 16)
  6515. {
  6516. ModeArray[Mode.Length] = (byte)'.';
  6517. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  6518. {
  6519. ModeArray[Mode.Length + 1 + i] = 0x20;
  6520. }
  6521. }
  6522. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6523. WriteACK = false;
  6524. ACK_WaitCnt = 0;
  6525. while (ACK_WaitCnt <= 2); //1s
  6526. if (WriteACK == true)
  6527. {
  6528. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6529. }
  6530. else
  6531. {
  6532. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号,第1次重发" + "\r\n");
  6533. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6534. ACK_WaitCnt = 0;
  6535. while (ACK_WaitCnt <= 2) ; //1s
  6536. if (WriteACK == true)
  6537. {
  6538. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6539. }
  6540. else
  6541. {
  6542. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号,第2次重发" + "\r\n");
  6543. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6544. ACK_WaitCnt = 0;
  6545. while (ACK_WaitCnt <= 2) ; //1s
  6546. if (WriteACK == true)
  6547. {
  6548. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6549. }
  6550. else
  6551. {
  6552. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入失败" + "\r\n");
  6553. label_FacModeStatus.Text = "存在故障!";
  6554. label_FacModeResult.BackColor = Color.Red;
  6555. label_FacModeResult.Text = "测试异常";
  6556. Delay_ms(500);
  6557. //存储异常并上传
  6558. FacMode_Stop(false);
  6559. return;
  6560. }
  6561. }
  6562. }
  6563. //写入SN
  6564. label_FacModeStatus.Text = "写入SN";
  6565. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN" + "\r\n");
  6566. textBox_FacModeNum.Text = InfoList[1];
  6567. string SN = textBox_FacModeNum.Text;
  6568. var SNArray = new byte[16];
  6569. for (ushort i = 0; i < SN.Length; i++)
  6570. {
  6571. SNArray[i] = (byte)SN[i];
  6572. }
  6573. if (SN.Length < 16)
  6574. {
  6575. SNArray[SN.Length] = (byte)'.';
  6576. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  6577. {
  6578. SNArray[SN.Length + 1 + i] = 0x20;
  6579. }
  6580. }
  6581. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6582. WriteACK = false;
  6583. ACK_WaitCnt = 0;
  6584. while (ACK_WaitCnt <= 2); //1s
  6585. if (WriteACK == true)
  6586. {
  6587. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  6588. }
  6589. else
  6590. {
  6591. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN,第1次重发" + "\r\n");
  6592. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6593. ACK_WaitCnt = 0;
  6594. while (ACK_WaitCnt <= 2) ; //1s
  6595. if (WriteACK == true)
  6596. {
  6597. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  6598. }
  6599. else
  6600. {
  6601. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN,第2次重发" + "\r\n");
  6602. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6603. ACK_WaitCnt = 0;
  6604. while (ACK_WaitCnt <= 2) ; //1s
  6605. if (WriteACK == true)
  6606. {
  6607. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  6608. }
  6609. else
  6610. {
  6611. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入失败" + "\r\n");
  6612. label_FacModeStatus.Text = "存在故障!";
  6613. label_FacModeResult.BackColor = Color.Red;
  6614. label_FacModeResult.Text = "测试异常";
  6615. Delay_ms(500);
  6616. //存储异常并上传
  6617. FacMode_Stop(false);
  6618. return;
  6619. }
  6620. }
  6621. }
  6622. }
  6623. else
  6624. {
  6625. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6626. return;
  6627. }
  6628. } while (false);
  6629. //写入配置文件
  6630. do
  6631. {
  6632. label_FacModeStatus.Text = "写入配置文件";
  6633. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  6634. //配置文件
  6635. List<byte[]> CmdList = new List<byte[]>();
  6636. //从服务器下载文件
  6637. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  6638. {
  6639. string SelectFile = "";
  6640. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "/" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  6641. if (File.Exists(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  6642. {
  6643. File.Delete(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  6644. }
  6645. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  6646. //打开文件
  6647. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  6648. CmdList.Clear();
  6649. while (streamReader.Peek() != -1)
  6650. {
  6651. string fileLineInfo = streamReader.ReadLine();
  6652. if (fileLineInfo.IndexOf("[") != -1)
  6653. {
  6654. continue;
  6655. }
  6656. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  6657. }
  6658. streamReader.Close();
  6659. }
  6660. //加载本地文件
  6661. else
  6662. {
  6663. string SelectFile = "";
  6664. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  6665. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  6666. CmdList.Clear();
  6667. while (streamReader.Peek() != -1)
  6668. {
  6669. string fileLineInfo = streamReader.ReadLine();
  6670. if (fileLineInfo.IndexOf("[") != -1)
  6671. {
  6672. continue;
  6673. }
  6674. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  6675. }
  6676. streamReader.Close();
  6677. }
  6678. int CmdNum = CmdList.Count(); //指令个数
  6679. Delay_ms(500);
  6680. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "开始写入" + "\r\n");
  6681. Delay_ms(500);
  6682. //开始写入
  6683. for (int i = 0; i < CmdList.Count; i++)
  6684. {
  6685. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令" + "\r\n");
  6686. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6687. WriteACK = false;
  6688. ACK_WaitCnt = 0;
  6689. while (ACK_WaitCnt <= 2) ; //1s
  6690. if (WriteACK == true)
  6691. {
  6692. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6693. }
  6694. else
  6695. {
  6696. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令,第1次重发" + "\r\n");
  6697. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6698. WriteACK = false;
  6699. ACK_WaitCnt = 0;
  6700. while (ACK_WaitCnt <= 2) ; //1s
  6701. if (WriteACK == true)
  6702. {
  6703. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6704. }
  6705. else
  6706. {
  6707. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令,第2次重发" + "\r\n");
  6708. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6709. WriteACK = false;
  6710. ACK_WaitCnt = 0;
  6711. while (ACK_WaitCnt <= 2) ; //1s
  6712. if (WriteACK == true)
  6713. {
  6714. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6715. }
  6716. else
  6717. {
  6718. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入失败," + "共" + CmdNum.ToString() + "条指令," + "写入成功" + i.ToString() + "条" + "\r\n");
  6719. label_FacModeStatus.Text = "存在故障!";
  6720. label_FacModeResult.BackColor = Color.Red;
  6721. label_FacModeResult.Text = "测试异常";
  6722. Delay_ms(500);
  6723. //存储异常并上传
  6724. FacMode_Stop(false);
  6725. return;
  6726. }
  6727. }
  6728. }
  6729. }
  6730. //写入完成
  6731. label_FacMode_CfgWrite.BackColor = Color.Green;
  6732. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入成功" + "\r\n");
  6733. Delay_ms(500);
  6734. } while (false);
  6735. }
  6736. else
  6737. {
  6738. label_FacMode_CfgWrite.BackColor = Color.Yellow;
  6739. label_FacModeStatus.Text = "跳过参数写入!";
  6740. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数写入" + "\r\n");
  6741. Delay_ms(500);
  6742. }
  6743. //BMS通讯
  6744. if (checkBox_FacModeBMS.Checked)
  6745. {
  6746. if (label_FacModeBMS.BackColor == Color.Red)
  6747. {
  6748. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "BMS通讯异常" + "\r\n");
  6749. label_FacModeStatus.Text = "存在故障!";
  6750. label_FacModeResult.BackColor = Color.Red;
  6751. label_FacModeResult.Text = "测试异常";
  6752. Delay_ms(500);
  6753. //存储异常并上传
  6754. FacMode_Stop(false);
  6755. return;
  6756. }
  6757. }
  6758. else
  6759. {
  6760. label_FacModeBMS.BackColor = Color.Yellow;
  6761. label_FacModeStatus.Text = "跳过BMS通讯检测!";
  6762. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过BMS通讯检测" + "\r\n");
  6763. Delay_ms(500);
  6764. }
  6765. //基础功能检测
  6766. if (checkBox_FacBaseFucTest.Checked)
  6767. {
  6768. label_FacModeStatus.Text = "基础功能检测";
  6769. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始基础功能检测" + "\r\n");
  6770. //确认负载位置
  6771. if (checkBox_FacMode_MosCal.Checked)
  6772. {
  6773. if (MessageBox.Show("请再次确认负载是否切换回电机?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  6774. {
  6775. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "负载已切换为电机,继续测试" + "\r\n");
  6776. }
  6777. else
  6778. {
  6779. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试取消" + "\r\n");
  6780. label_FacModeStatus.Text = "存在故障!";
  6781. label_FacModeResult.BackColor = Color.Red;
  6782. label_FacModeResult.Text = "测试异常";
  6783. Delay_ms(500);
  6784. //存储异常并上传
  6785. FacMode_Stop(false);
  6786. return;
  6787. }
  6788. }
  6789. //发送指令进入配置模式
  6790. do
  6791. {
  6792. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6793. Code[0] = 0x01;
  6794. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6795. WriteACK = false;
  6796. ACK_WaitCnt = 0;
  6797. while (ACK_WaitCnt <= 2); //1s
  6798. if (textBox_RunInfo_Vol.Text != "---")
  6799. {
  6800. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6801. }
  6802. else
  6803. {
  6804. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  6805. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6806. ACK_WaitCnt = 0;
  6807. while (ACK_WaitCnt <= 2) ; //1s
  6808. if (textBox_RunInfo_Vol.Text != "---")
  6809. {
  6810. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6811. }
  6812. else
  6813. {
  6814. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  6815. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6816. ACK_WaitCnt = 0;
  6817. while (ACK_WaitCnt <= 2) ; //1s
  6818. if (textBox_RunInfo_Vol.Text != "---")
  6819. {
  6820. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6821. }
  6822. else
  6823. {
  6824. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  6825. label_FacModeStatus.Text = "存在故障!";
  6826. label_FacModeResult.BackColor = Color.Red;
  6827. label_FacModeResult.Text = "测试异常";
  6828. Delay_ms(500);
  6829. //存储异常并上传
  6830. FacMode_Stop(false);
  6831. return;
  6832. }
  6833. }
  6834. }
  6835. } while (false);
  6836. //发送指令启动电机
  6837. do
  6838. {
  6839. #if false //通过运行模式3启动电机
  6840. //发送指令读取调试信息
  6841. richTextBox_DebugParam.Clear();
  6842. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  6843. WriteACK = false;
  6844. ACK_WaitCnt = 0;
  6845. while (ACK_WaitCnt <= 2); //1s
  6846. //获取调试信息
  6847. string DebugDefaultInfo = "";
  6848. if (richTextBox_DebugParam.Text == string.Empty)
  6849. {
  6850. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
  6851. label_FacModeStatus.Text = "存在故障!";
  6852. label_FacModeResult.BackColor = Color.Red;
  6853. label_FacModeResult.Text = "测试异常";
  6854. Delay_ms(500);
  6855. //存储异常并上传
  6856. FacMode_Stop(false);
  6857. return;
  6858. }
  6859. else
  6860. {
  6861. DebugDefaultInfo = richTextBox_DebugParam.Text;
  6862. }
  6863. //设置模式
  6864. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  6865. strDataTemp[0] = "整体运行模式=3";
  6866. //发送数据
  6867. Code[0] = 0;
  6868. Code[1] = 0;
  6869. for (int i = 0; i < strDataTemp.Length; i++)
  6870. {
  6871. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  6872. Code[2 * i + 2] = (byte)uwDataTemp;
  6873. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  6874. }
  6875. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  6876. label_FacModeStatus.Text = "启动电机";
  6877. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "启动电机" + "\r\n");
  6878. #else //通过Walk模式启动电机
  6879. //设置转速100%
  6880. var Data = new byte[1];
  6881. Data[0] = (byte)100;
  6882. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6883. Delay_ms(500);
  6884. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6885. Delay_ms(500);
  6886. //启动电机进入WALK模式
  6887. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "基础功能检测,进入WALK" + "\r\n");
  6888. Code[0] = 0x22;
  6889. Code[1] = 0xF0;
  6890. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6891. WriteACK = false;
  6892. ACK_WaitCnt = 0;
  6893. while (ACK_WaitCnt <= 2) ; //1s
  6894. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6895. {
  6896. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第1次重发" + "\r\n");
  6897. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6898. ACK_WaitCnt = 0;
  6899. while (ACK_WaitCnt <= 2) ; //1s
  6900. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6901. {
  6902. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第2次重发" + "\r\n");
  6903. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6904. ACK_WaitCnt = 0;
  6905. while (ACK_WaitCnt <= 2) ; //1s
  6906. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6907. {
  6908. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
  6909. label_FacModeStatus.Text = "存在故障!";
  6910. label_FacModeResult.BackColor = Color.Red;
  6911. label_FacModeResult.Text = "测试异常";
  6912. Delay_ms(500);
  6913. //存储异常并上传
  6914. FacMode_Stop(false);
  6915. return;
  6916. }
  6917. }
  6918. }
  6919. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入WALK,开始检测" + "\r\n");
  6920. #endif
  6921. Delay_ms(3000);
  6922. } while (false);
  6923. //判断车速
  6924. if ((Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) <= Convert.ToDouble( toolStripTextBox_ThBikeSpeed.Text.Split(',')[1])) &&
  6925. (Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThBikeSpeed.Text.Split(',')[0])))
  6926. {
  6927. label_FacModeSpeed.BackColor = Color.Green;
  6928. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器正常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
  6929. }
  6930. else
  6931. {
  6932. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器异常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
  6933. label_FacModeStatus.Text = "存在故障!";
  6934. label_FacModeResult.BackColor = Color.Red;
  6935. label_FacModeResult.Text = "测试异常";
  6936. Delay_ms(500);
  6937. //存储异常并上传
  6938. FacMode_Stop(false);
  6939. return;
  6940. }
  6941. //判断电压
  6942. if ((Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[1])) &&
  6943. (Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[0])))
  6944. {
  6945. label_FacModeVolTest.BackColor = Color.Green;
  6946. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量正常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
  6947. }
  6948. else
  6949. {
  6950. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量异常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
  6951. label_FacModeStatus.Text = "存在故障!";
  6952. label_FacModeResult.BackColor = Color.Red;
  6953. label_FacModeResult.Text = "测试异常";
  6954. Delay_ms(500);
  6955. //存储异常并上传
  6956. FacMode_Stop(false);
  6957. return;
  6958. }
  6959. //判断电流
  6960. if ((Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[1])) &&
  6961. (Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[0])))
  6962. {
  6963. label_FacModeCurrentTest.BackColor = Color.Green;
  6964. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量正常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  6965. }
  6966. else
  6967. {
  6968. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量异常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  6969. label_FacModeStatus.Text = "存在故障!";
  6970. label_FacModeResult.BackColor = Color.Red;
  6971. label_FacModeResult.Text = "测试异常";
  6972. Delay_ms(500);
  6973. //存储异常并上传
  6974. FacMode_Stop(false);
  6975. return;
  6976. }
  6977. //判断温度
  6978. if ((Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[1])) &&
  6979. (Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[0])) &&
  6980. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[1])) &&
  6981. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[0])) &&
  6982. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[1])) &&
  6983. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[0])))
  6984. {
  6985. label_FacModeNTC.BackColor = Color.Green;
  6986. 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");
  6987. }
  6988. else
  6989. {
  6990. 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");
  6991. label_FacModeStatus.Text = "存在故障!";
  6992. label_FacModeResult.BackColor = Color.Red;
  6993. label_FacModeResult.Text = "测试异常";
  6994. Delay_ms(500);
  6995. //存储异常并上传
  6996. FacMode_Stop(false);
  6997. return;
  6998. }
  6999. //判断转速
  7000. if ((Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[1])) &&
  7001. (Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[0])))
  7002. {
  7003. label_FacModeMotorSpeed.BackColor = Color.Green;
  7004. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速正常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
  7005. }
  7006. else
  7007. {
  7008. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速异常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
  7009. label_FacModeStatus.Text = "存在故障!";
  7010. label_FacModeResult.BackColor = Color.Red;
  7011. label_FacModeResult.Text = "测试异常";
  7012. Delay_ms(500);
  7013. //存储异常并上传
  7014. FacMode_Stop(false);
  7015. return;
  7016. }
  7017. //发送指令停止电机
  7018. do
  7019. {
  7020. //设置转速0%
  7021. var Data = new byte[1];
  7022. Data[0] = (byte)0;
  7023. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7024. Delay_ms(500);
  7025. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7026. Delay_ms(500);
  7027. #if false //通过修改调试模式停止电机
  7028. //获取调试信息
  7029. string DebugDefaultInfo = "";
  7030. if (richTextBox_DebugParam.Text == string.Empty)
  7031. {
  7032. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
  7033. label_FacModeStatus.Text = "存在故障!";
  7034. label_FacModeResult.BackColor = Color.Red;
  7035. label_FacModeResult.Text = "测试异常";
  7036. Delay_ms(500);
  7037. //存储异常并上传
  7038. FacMode_Stop(false);
  7039. return;
  7040. }
  7041. else
  7042. {
  7043. DebugDefaultInfo = richTextBox_DebugParam.Text;
  7044. }
  7045. //设置模式
  7046. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  7047. //发送数据
  7048. Code[0] = 0;
  7049. Code[1] = 0;
  7050. for (int i = 0; i < strDataTemp.Length; i++)
  7051. {
  7052. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  7053. Code[2 * i + 2] = (byte)uwDataTemp;
  7054. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  7055. }
  7056. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  7057. label_FacModeStatus.Text = "停止电机";
  7058. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "停止电机" + "\r\n");
  7059. #else //通过调整档位停止电机
  7060. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK" + "\r\n");
  7061. Code[0] = 0x00;
  7062. Code[1] = 0xF0;
  7063. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7064. WriteACK = false;
  7065. ACK_WaitCnt = 0;
  7066. while (ACK_WaitCnt <= 2) ; //1s
  7067. if (textBox_RunInfo_GearSt.Text != "OFF")
  7068. {
  7069. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK,第1次重发" + "\r\n");
  7070. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7071. ACK_WaitCnt = 0;
  7072. while (ACK_WaitCnt <= 2) ; //1s
  7073. if (textBox_RunInfo_GearSt.Text != "OFF")
  7074. {
  7075. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK,第2次重发" + "\r\n");
  7076. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7077. ACK_WaitCnt = 0;
  7078. while (ACK_WaitCnt <= 2) ; //1s
  7079. if (textBox_RunInfo_GearSt.Text != "OFF")
  7080. {
  7081. }
  7082. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
  7083. label_FacModeStatus.Text = "存在故障!";
  7084. label_FacModeResult.BackColor = Color.Red;
  7085. label_FacModeResult.Text = "测试异常";
  7086. Delay_ms(500);
  7087. //存储异常并上传
  7088. FacMode_Stop(false);
  7089. return;
  7090. }
  7091. }
  7092. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已退出WALK,基础功能检测完成" + "\r\n");
  7093. #endif
  7094. Delay_ms(2000);
  7095. } while (false);
  7096. }
  7097. else
  7098. {
  7099. label_FacModeSpeed.BackColor = Color.Yellow;
  7100. label_FacModeVolTest.BackColor = Color.Yellow;
  7101. label_FacModeCurrentTest.BackColor = Color.Yellow;
  7102. label_FacModeNTC.BackColor = Color.Yellow;
  7103. label_FacModeMotorSpeed.BackColor = Color.Yellow;
  7104. label_FacModeStatus.Text = "跳过基础功能检测!";
  7105. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过基础功能检测" + "\r\n");
  7106. Delay_ms(500);
  7107. }
  7108. //力矩检测
  7109. if (checkBox_FacTor.Checked)
  7110. {
  7111. label_FacModeStatus.Text = "力矩传感器检测!";
  7112. //发送指令进入配置模式
  7113. do
  7114. {
  7115. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  7116. {
  7117. break;
  7118. }
  7119. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  7120. Code[0] = 0x01;
  7121. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7122. WriteACK = false;
  7123. ACK_WaitCnt = 0;
  7124. while (ACK_WaitCnt <= 2) ; //1s
  7125. if (textBox_RunInfo_Vol.Text != "---")
  7126. {
  7127. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7128. Delay_ms(500);
  7129. }
  7130. else
  7131. {
  7132. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  7133. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7134. ACK_WaitCnt = 0;
  7135. while (ACK_WaitCnt <= 2) ; //1s
  7136. if (textBox_RunInfo_Vol.Text != "---")
  7137. {
  7138. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7139. Delay_ms(500);
  7140. }
  7141. else
  7142. {
  7143. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7144. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7145. ACK_WaitCnt = 0;
  7146. while (ACK_WaitCnt <= 2) ; //1s
  7147. if (textBox_RunInfo_Vol.Text != "---")
  7148. {
  7149. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7150. Delay_ms(500);
  7151. }
  7152. else
  7153. {
  7154. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7155. label_FacModeStatus.Text = "存在故障!";
  7156. label_FacModeResult.BackColor = Color.Red;
  7157. label_FacModeResult.Text = "测试异常";
  7158. Delay_ms(500);
  7159. //存储异常并上传
  7160. FacMode_Stop(false);
  7161. return;
  7162. }
  7163. }
  7164. }
  7165. } while (false);
  7166. ushort Max = 0, Torque = 0;
  7167. //提示输入力矩信号
  7168. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟力矩信号输入" + "\r\n");
  7169. ACK_WaitCnt = 0;
  7170. while (ACK_WaitCnt <= 20) //10s
  7171. {
  7172. //获取力矩值
  7173. Torque = (ushort)Convert.ToInt16(textBox_RunInfo_Torque.Text.Split(' ')[0]);
  7174. if (Torque > Max)
  7175. Max = Torque;
  7176. if ((Max <= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[1])) &&
  7177. (Max >= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[0])) &&
  7178. (ACK_WaitCnt >= 6))
  7179. {
  7180. label_FacModeTq.BackColor = Color.Green;
  7181. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器正常" + " " + textBox_RunInfo_Torque.Text + "\r\n");
  7182. break;
  7183. }
  7184. }
  7185. if (ACK_WaitCnt >= 20)
  7186. {
  7187. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器异常" + " " + textBox_RunInfo_Torque.Text + "\r\n");
  7188. label_FacModeStatus.Text = "存在故障!";
  7189. label_FacModeResult.BackColor = Color.Red;
  7190. label_FacModeResult.Text = "测试异常";
  7191. Delay_ms(500);
  7192. //存储异常并上传
  7193. FacMode_Stop(false);
  7194. return;
  7195. }
  7196. }
  7197. else
  7198. {
  7199. label_FacModeTq.BackColor = Color.Yellow;
  7200. label_FacModeStatus.Text = "跳过力矩检测!";
  7201. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过力矩检测" + "\r\n");
  7202. Delay_ms(500);
  7203. }
  7204. //踏频检测
  7205. if (checkBox_FacCad.Checked)
  7206. {
  7207. label_FacModeStatus.Text = "踏频传感器检测!";
  7208. //发送指令进入配置模式
  7209. do
  7210. {
  7211. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  7212. {
  7213. break;
  7214. }
  7215. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  7216. Code[0] = 0x01;
  7217. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7218. WriteACK = false;
  7219. ACK_WaitCnt = 0;
  7220. while (ACK_WaitCnt <= 2) ; //1s
  7221. if (textBox_RunInfo_Vol.Text != "---")
  7222. {
  7223. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7224. Delay_ms(500);
  7225. }
  7226. else
  7227. {
  7228. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  7229. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7230. ACK_WaitCnt = 0;
  7231. while (ACK_WaitCnt <= 2) ; //1s
  7232. if (textBox_RunInfo_Vol.Text != "---")
  7233. {
  7234. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7235. Delay_ms(500);
  7236. }
  7237. else
  7238. {
  7239. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7240. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7241. ACK_WaitCnt = 0;
  7242. while (ACK_WaitCnt <= 2) ; //1s
  7243. if (textBox_RunInfo_Vol.Text != "---")
  7244. {
  7245. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7246. Delay_ms(500);
  7247. }
  7248. else
  7249. {
  7250. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7251. label_FacModeStatus.Text = "存在故障!";
  7252. label_FacModeResult.BackColor = Color.Red;
  7253. label_FacModeResult.Text = "测试异常";
  7254. Delay_ms(500);
  7255. //存储异常并上传
  7256. FacMode_Stop(false);
  7257. return;
  7258. }
  7259. }
  7260. }
  7261. } while (false);
  7262. ushort Max = 0, Cadence = 0;
  7263. //提示输入踏频信号
  7264. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟踏频信号输入" + "\r\n");
  7265. ACK_WaitCnt = 0;
  7266. while (ACK_WaitCnt <= 20) //10s
  7267. {
  7268. //获取踏频
  7269. Cadence = (ushort)Convert.ToInt16(textBox_RunInfo_Cadence.Text.Split(' ')[0]);
  7270. if (Cadence > Max)
  7271. Max = Cadence;
  7272. if ((Max <= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[1])) &&
  7273. (Max >= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[0])) &&
  7274. (ACK_WaitCnt >= 6))
  7275. {
  7276. label_FacModeCad.BackColor = Color.Green;
  7277. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器正常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  7278. break;
  7279. }
  7280. }
  7281. if (ACK_WaitCnt >= 20)
  7282. {
  7283. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器异常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  7284. label_FacModeStatus.Text = "存在故障!";
  7285. label_FacModeResult.BackColor = Color.Red;
  7286. label_FacModeResult.Text = "测试异常";
  7287. Delay_ms(500);
  7288. //存储异常并上传
  7289. FacMode_Stop(false);
  7290. return;
  7291. }
  7292. }
  7293. else
  7294. {
  7295. label_FacModeCad.BackColor = Color.Yellow;
  7296. label_FacModeStatus.Text = "跳过踏频检测!";
  7297. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过踏频检测" + "\r\n");
  7298. Delay_ms(500);
  7299. }
  7300. //转把检测
  7301. if (checkBox_FacThrrotleTest.Checked)
  7302. {
  7303. label_FacModeStatus.Text = "转把检测";
  7304. //发送指令进入配置模式
  7305. do
  7306. {
  7307. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  7308. {
  7309. break;
  7310. }
  7311. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  7312. Code[0] = 0x01;
  7313. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7314. WriteACK = false;
  7315. ACK_WaitCnt = 0;
  7316. while (ACK_WaitCnt <= 2) ; //1s
  7317. if (textBox_RunInfo_Vol.Text != "---")
  7318. {
  7319. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7320. Delay_ms(500);
  7321. }
  7322. else
  7323. {
  7324. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  7325. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7326. ACK_WaitCnt = 0;
  7327. while (ACK_WaitCnt <= 2) ; //1s
  7328. if (textBox_RunInfo_Vol.Text != "---")
  7329. {
  7330. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7331. Delay_ms(500);
  7332. }
  7333. else
  7334. {
  7335. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7336. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7337. ACK_WaitCnt = 0;
  7338. while (ACK_WaitCnt <= 2) ; //1s
  7339. if (textBox_RunInfo_Vol.Text != "---")
  7340. {
  7341. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7342. Delay_ms(500);
  7343. }
  7344. else
  7345. {
  7346. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7347. label_FacModeStatus.Text = "存在故障!";
  7348. label_FacModeResult.BackColor = Color.Red;
  7349. label_FacModeResult.Text = "测试异常";
  7350. Delay_ms(500);
  7351. //存储异常并上传
  7352. FacMode_Stop(false);
  7353. return;
  7354. }
  7355. }
  7356. }
  7357. } while (false);
  7358. //进入TURBO档
  7359. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把检测,发送指令进入TURBO" + "\r\n");
  7360. Code[0] = 0x04;
  7361. Code[1] = 0xF0;
  7362. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7363. WriteACK = false;
  7364. ACK_WaitCnt = 0;
  7365. while (ACK_WaitCnt <= 2) ; //1s
  7366. if (textBox_RunInfo_GearSt.Text != "TURBO")
  7367. {
  7368. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO,第1次重发" + "\r\n");
  7369. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7370. ACK_WaitCnt = 0;
  7371. while (ACK_WaitCnt <= 2) ; //1s
  7372. if (textBox_RunInfo_GearSt.Text != "TURBO")
  7373. {
  7374. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO,第2次重发" + "\r\n");
  7375. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7376. ACK_WaitCnt = 0;
  7377. while (ACK_WaitCnt <= 2) ; //1s
  7378. if (textBox_RunInfo_GearSt.Text != "TURBO")
  7379. {
  7380. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO异常" + "\r\n");
  7381. label_FacModeStatus.Text = "存在故障!";
  7382. label_FacModeResult.BackColor = Color.Red;
  7383. label_FacModeResult.Text = "测试异常";
  7384. Delay_ms(500);
  7385. //存储异常并上传
  7386. FacMode_Stop(false);
  7387. return;
  7388. }
  7389. }
  7390. }
  7391. //进入TURBO后,如果电机直接启动,认为转把电压异常
  7392. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把自检,请松开转把" + "\r\n");
  7393. Delay_ms(3000);
  7394. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) > 500)
  7395. {
  7396. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把电压异常" + "\r\n");
  7397. label_FacModeStatus.Text = "存在故障!";
  7398. label_FacModeResult.BackColor = Color.Red;
  7399. label_FacModeResult.Text = "测试异常";
  7400. Delay_ms(500);
  7401. //存储异常并上传
  7402. FacMode_Stop(false);
  7403. return;
  7404. }
  7405. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把自检正常" + "\r\n");
  7406. Delay_ms(500);
  7407. //提示转动转把
  7408. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入TURBO,10s内转动转把" + "\r\n");
  7409. ACK_WaitCnt = 0;
  7410. while (ACK_WaitCnt <= 20)
  7411. {
  7412. if ((Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) > 500) && (ACK_WaitCnt >= 10))
  7413. {
  7414. label_FacModeGas.BackColor = Color.Green;
  7415. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能正常,松开转把" + "\r\n");
  7416. break;
  7417. }
  7418. }
  7419. if (ACK_WaitCnt >= 20) //转把超时
  7420. {
  7421. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能异常,松开转把" + "\r\n");
  7422. label_FacModeStatus.Text = "存在故障!";
  7423. label_FacModeResult.BackColor = Color.Red;
  7424. label_FacModeResult.Text = "测试异常";
  7425. Delay_ms(500);
  7426. //存储异常并上传
  7427. FacMode_Stop(false);
  7428. return;
  7429. }
  7430. }
  7431. else
  7432. {
  7433. label_FacModeGas.BackColor = Color.Yellow;
  7434. label_FacModeStatus.Text = "跳过转把检测!";
  7435. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过转把检测" + "\r\n");
  7436. Delay_ms(500);
  7437. }
  7438. //刹车检测
  7439. if (checkBox_FacBreakTest.Checked)
  7440. {
  7441. label_FacModeStatus.Text = "刹把检测";
  7442. //发送指令进入配置模式
  7443. do
  7444. {
  7445. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  7446. {
  7447. break;
  7448. }
  7449. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  7450. Code[0] = 0x01;
  7451. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7452. WriteACK = false;
  7453. ACK_WaitCnt = 0;
  7454. while (ACK_WaitCnt <= 2) ; //1s
  7455. if (textBox_RunInfo_Vol.Text != "---")
  7456. {
  7457. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7458. Delay_ms(500);
  7459. }
  7460. else
  7461. {
  7462. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  7463. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7464. ACK_WaitCnt = 0;
  7465. while (ACK_WaitCnt <= 2) ; //1s
  7466. if (textBox_RunInfo_Vol.Text != "---")
  7467. {
  7468. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7469. Delay_ms(500);
  7470. }
  7471. else
  7472. {
  7473. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7474. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7475. ACK_WaitCnt = 0;
  7476. while (ACK_WaitCnt <= 2) ; //1s
  7477. if (textBox_RunInfo_Vol.Text != "---")
  7478. {
  7479. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7480. Delay_ms(500);
  7481. }
  7482. else
  7483. {
  7484. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7485. label_FacModeStatus.Text = "存在故障!";
  7486. label_FacModeResult.BackColor = Color.Red;
  7487. label_FacModeResult.Text = "测试异常";
  7488. Delay_ms(500);
  7489. //存储异常并上传
  7490. FacMode_Stop(false);
  7491. return;
  7492. }
  7493. }
  7494. }
  7495. } while (false);
  7496. //测试前先确定电机已停止
  7497. UInt16 WaitTime = 10;
  7498. do
  7499. {
  7500. WaitTime--;
  7501. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 100)
  7502. {
  7503. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机停止,开始进行剎把检测,进入WALK" + "\r\n");
  7504. break;
  7505. }
  7506. if (WaitTime == 0)
  7507. {
  7508. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机无法停止,剎把检测异常" + "\r\n");
  7509. label_FacModeStatus.Text = "存在故障!";
  7510. label_FacModeResult.BackColor = Color.Red;
  7511. label_FacModeResult.Text = "测试异常";
  7512. Delay_ms(500);
  7513. //存储异常并上传
  7514. FacMode_Stop(false);
  7515. return;
  7516. }
  7517. Delay_ms(500);
  7518. } while (true);
  7519. //设置转速100%
  7520. var Data = new byte[1];
  7521. Data[0] = (byte)100;
  7522. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7523. Delay_ms(500);
  7524. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7525. Delay_ms(500);
  7526. //启动电机进入WALK模式
  7527. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把检测,进入WALK" + "\r\n");
  7528. Code[0] = 0x22;
  7529. Code[1] = 0xF0;
  7530. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7531. WriteACK = false;
  7532. ACK_WaitCnt = 0;
  7533. while (ACK_WaitCnt <= 2) ; //1s
  7534. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 500))
  7535. {
  7536. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第1次重发" + "\r\n");
  7537. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7538. ACK_WaitCnt = 0;
  7539. while (ACK_WaitCnt <= 2) ; //1s
  7540. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 500))
  7541. {
  7542. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第2次重发" + "\r\n");
  7543. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7544. ACK_WaitCnt = 0;
  7545. while (ACK_WaitCnt <= 2) ; //1s
  7546. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 500))
  7547. {
  7548. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
  7549. label_FacModeStatus.Text = "存在故障!";
  7550. label_FacModeResult.BackColor = Color.Red;
  7551. label_FacModeResult.Text = "测试异常";
  7552. Delay_ms(500);
  7553. //存储异常并上传
  7554. FacMode_Stop(false);
  7555. return;
  7556. }
  7557. }
  7558. }
  7559. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,10s内操作剎把" + "\r\n");
  7560. ACK_WaitCnt = 0;
  7561. while (ACK_WaitCnt <= 20)
  7562. {
  7563. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 100)
  7564. {
  7565. label_FacModeBreak.BackColor = Color.Green;
  7566. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把功能正常,松开剎把" + "\r\n");
  7567. break;
  7568. }
  7569. }
  7570. if (ACK_WaitCnt >= 20) //剎把超时
  7571. {
  7572. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速:" + textBox_RunInfo_MotorSpeed.Text + "," + "剎把功能异常,松开剎把" + "\r\n");
  7573. label_FacModeStatus.Text = "存在故障!";
  7574. label_FacModeResult.BackColor = Color.Red;
  7575. label_FacModeResult.Text = "测试异常";
  7576. Delay_ms(500);
  7577. //存储异常并上传
  7578. FacMode_Stop(false);
  7579. return;
  7580. }
  7581. //停止电机
  7582. Code[0] = 0x00;
  7583. Code[1] = 0xF0;
  7584. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7585. WriteACK = false;
  7586. ACK_WaitCnt = 0;
  7587. while (ACK_WaitCnt <= 2) ; //1s
  7588. if (textBox_RunInfo_GearSt.Text != "OFF")
  7589. {
  7590. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK,第1次重发" + "\r\n");
  7591. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7592. ACK_WaitCnt = 0;
  7593. while (ACK_WaitCnt <= 2) ; //1s
  7594. if (textBox_RunInfo_GearSt.Text != "OFF")
  7595. {
  7596. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK,第2次重发" + "\r\n");
  7597. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7598. ACK_WaitCnt = 0;
  7599. while (ACK_WaitCnt <= 2) ; //1s
  7600. if (textBox_RunInfo_GearSt.Text != "OFF")
  7601. {
  7602. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
  7603. label_FacModeStatus.Text = "存在故障!";
  7604. label_FacModeResult.BackColor = Color.Red;
  7605. label_FacModeResult.Text = "测试异常";
  7606. Delay_ms(500);
  7607. //存储异常并上传
  7608. FacMode_Stop(false);
  7609. return;
  7610. }
  7611. }
  7612. }
  7613. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK" + "\r\n");
  7614. Delay_ms(500);
  7615. }
  7616. else
  7617. {
  7618. label_FacModeBreak.BackColor = Color.Yellow;
  7619. label_FacModeStatus.Text = "跳过刹车检测!";
  7620. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过刹车检测" + "\r\n");
  7621. Delay_ms(500);
  7622. }
  7623. //前后灯检测
  7624. if (checkBox_FacLightTest.Checked)
  7625. {
  7626. //前后灯检测
  7627. label_FacModeStatus.Text = "前后灯检测";
  7628. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开灯指令" + "\r\n");
  7629. //发送指令打开车灯
  7630. Code[0] = 0x00;
  7631. Code[1] = 0xF1;
  7632. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7633. WriteACK = false;
  7634. ACK_WaitCnt = 0;
  7635. while (ACK_WaitCnt <= 2) ; //1s
  7636. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7637. {
  7638. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令,第1次重发" + "\r\n");
  7639. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7640. ACK_WaitCnt = 0;
  7641. while (ACK_WaitCnt <= 2); //1s
  7642. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7643. {
  7644. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令,第2次重发" + "\r\n");
  7645. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7646. ACK_WaitCnt = 0;
  7647. while (ACK_WaitCnt <= 2) ; //1s
  7648. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7649. {
  7650. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令发送异常" + "\r\n");
  7651. label_FacModeStatus.Text = "存在故障!";
  7652. label_FacModeResult.BackColor = Color.Red;
  7653. label_FacModeResult.Text = "测试异常";
  7654. Delay_ms(500);
  7655. //存储异常并上传
  7656. FacMode_Stop(false);
  7657. return;
  7658. }
  7659. }
  7660. }
  7661. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已打开前后灯" + "\r\n");
  7662. Delay_ms(500);
  7663. //提示检查灯压是否正确
  7664. if (MessageBox.Show("前后灯是否正常开启?", "前后灯判断", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  7665. {
  7666. label_FacModeLightF.BackColor = Color.Green;
  7667. label_FacModeLightB.BackColor = Color.Green;
  7668. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯正常" + "\r\n");
  7669. Delay_ms(500);
  7670. }
  7671. else
  7672. {
  7673. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯异常" + "\r\n");
  7674. label_FacModeStatus.Text = "存在故障!";
  7675. label_FacModeResult.BackColor = Color.Red;
  7676. label_FacModeResult.Text = "测试异常";
  7677. Delay_ms(500);
  7678. //存储异常并上传
  7679. FacMode_Stop(false);
  7680. return;
  7681. }
  7682. //发送指令关闭车灯
  7683. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关灯指令" + "\r\n");
  7684. Code[0] = 0x00;
  7685. Code[1] = 0xF0;
  7686. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7687. WriteACK = false;
  7688. ACK_WaitCnt = 0;
  7689. while (ACK_WaitCnt <= 2) ; //1s
  7690. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7691. {
  7692. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令,第1次重发" + "\r\n");
  7693. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7694. ACK_WaitCnt = 0;
  7695. while (ACK_WaitCnt <= 2) ; //1s
  7696. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7697. {
  7698. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令,第2次重发" + "\r\n");
  7699. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7700. ACK_WaitCnt = 0;
  7701. while (ACK_WaitCnt <= 2) ; //1s
  7702. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7703. {
  7704. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令发送异常" + "\r\n");
  7705. label_FacModeStatus.Text = "存在故障!";
  7706. label_FacModeResult.BackColor = Color.Red;
  7707. label_FacModeResult.Text = "测试异常";
  7708. Delay_ms(500);
  7709. //存储异常并上传
  7710. FacMode_Stop(false);
  7711. return;
  7712. }
  7713. }
  7714. }
  7715. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已关闭前后灯" + "\r\n");
  7716. Delay_ms(500);
  7717. }
  7718. else
  7719. {
  7720. label_FacModeLightF.BackColor = Color.Yellow;
  7721. label_FacModeLightB.BackColor = Color.Yellow;
  7722. label_FacModeStatus.Text = "跳过前后灯检测!";
  7723. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过前后灯检测" + "\r\n");
  7724. Delay_ms(500);
  7725. }
  7726. //软件版本检测
  7727. do
  7728. {
  7729. label_FacModeStatus.Text = "软件版本确认";
  7730. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  7731. //发送指令读取版本
  7732. Class_Motor_Ver.Mode = "---";
  7733. Class_Motor_Ver.SN = "---";
  7734. Class_Motor_Ver.HW = "---";
  7735. Class_Motor_Ver.FW = "---";
  7736. Class_Motor_Ver.Special = "---";
  7737. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7738. ACK_WaitCnt = 0;
  7739. while (ACK_WaitCnt <= 2) ; //1s
  7740. if (Class_Motor_Ver.Mode == "---")
  7741. {
  7742. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第1次重发" + "\r\n");
  7743. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7744. ACK_WaitCnt = 0;
  7745. while (ACK_WaitCnt <= 2) ; //1s
  7746. if (Class_Motor_Ver.Mode == "---")
  7747. {
  7748. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第2次重发" + "\r\n");
  7749. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7750. ACK_WaitCnt = 0;
  7751. while (ACK_WaitCnt <= 2) ; //1s
  7752. if (Class_Motor_Ver.Mode == "---")
  7753. {
  7754. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息失败" + "\r\n");
  7755. label_FacModeStatus.Text = "存在故障!";
  7756. label_FacModeResult.BackColor = Color.Red;
  7757. label_FacModeResult.Text = "测试异常";
  7758. Delay_ms(500);
  7759. //存储异常并上传
  7760. FacMode_Stop(false);
  7761. return;
  7762. }
  7763. }
  7764. }
  7765. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  7766. richTextBox_FacModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  7767. richTextBox_FacModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  7768. richTextBox_FacModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  7769. richTextBox_FacModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  7770. richTextBox_FacModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  7771. //判断版本是否正确
  7772. string VerCheck = comboBox_FacModeCfgFile.Text.Split('_')[3] + "_" + comboBox_FacModeCfgFile.Text.Split('_')[4];
  7773. string VerRead = "";
  7774. try
  7775. {
  7776. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  7777. }
  7778. catch (System.Exception)
  7779. {
  7780. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  7781. label_FacModeStatus.Text = "存在故障!";
  7782. label_FacModeResult.BackColor = Color.Red;
  7783. label_FacModeResult.Text = "测试异常";
  7784. Delay_ms(500);
  7785. //存储异常并上传
  7786. FacMode_Stop(false);
  7787. return;
  7788. }
  7789. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  7790. {
  7791. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
  7792. label_FacModeStatus.Text = "存在故障!";
  7793. label_FacModeResult.BackColor = Color.Red;
  7794. label_FacModeResult.Text = "测试异常";
  7795. Delay_ms(500);
  7796. //存储异常并上传
  7797. FacMode_Stop(false);
  7798. return;
  7799. }
  7800. label_FacModeFWVersion.BackColor = Color.Green;
  7801. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  7802. Delay_ms(500);
  7803. } while (false);
  7804. //测试合格
  7805. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  7806. label_FacModeStatus.Text = "测试结束!";
  7807. label_FacModeResult.BackColor = Color.Green;
  7808. label_FacModeResult.Text = "测试合格";
  7809. Delay_ms(500);
  7810. //存储并上传
  7811. FacMode_Stop(true);
  7812. return;
  7813. }
  7814. private void FacModelLabelInit()
  7815. {
  7816. //测试状态标签
  7817. label_FacModeResult.BackColor = Color.Yellow;
  7818. label_FacModeResult.Text = "测试中";
  7819. //测试过程标签
  7820. label_FacModeStatus.Text = "测试就绪";
  7821. //测试结果标签
  7822. foreach (Control c in groupBox28.Controls)
  7823. {
  7824. if (c is Label)
  7825. {
  7826. if (c.Text == string.Empty)
  7827. c.BackColor = Color.Red;
  7828. }
  7829. }
  7830. }
  7831. private void comboBox_CheckModeCfgDate_Click(object sender, EventArgs e)
  7832. {
  7833. //更新生产配置文件目录
  7834. GetDateList(false);
  7835. }
  7836. private void comboBox_FacModeCfgDate_Click(object sender, EventArgs e)
  7837. {
  7838. //更新生产配置文件目录
  7839. GetDateList(false);
  7840. }
  7841. private void richTextBox_FacModeLog_TextChanged(object sender, EventArgs e)
  7842. {
  7843. richTextBox_FacModeLog.SelectionStart = richTextBox_FacModeLog.Text.Length;
  7844. richTextBox_FacModeLog.ScrollToCaret();
  7845. }
  7846. /// <summary>
  7847. /// 参数检验测试停止
  7848. /// </summary>
  7849. /// <param name="OK_Flag"></param>
  7850. private void CheckMode_Stop(bool OK_Flag)
  7851. {
  7852. //打开开始按钮
  7853. button_CheckModeStart.Enabled = true;
  7854. //导出电机参数
  7855. string Params = "";
  7856. do
  7857. {
  7858. if (!OK_Flag)
  7859. {
  7860. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试异常,停止导出" + "\r\n");
  7861. break;
  7862. }
  7863. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "导出电机存储参数" + "\r\n");
  7864. //读取一次马达参数
  7865. richTextBox_MotorParam.Clear();
  7866. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break; ;
  7867. Delay_ms(100);
  7868. Params += "[马达参数]" + "\r\n" + richTextBox_MotorParam.Text + "\r\n";
  7869. Params += "\r\n";
  7870. //读取一次整车参数
  7871. richTextBox_BikeParam.Clear();
  7872. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  7873. Delay_ms(100);
  7874. Params += "[整车参数]" + "\r\n" + richTextBox_BikeParam.Text + "\r\n";
  7875. Params += "\r\n";
  7876. //读取一次控制参数
  7877. richTextBox_ControlParam.Clear();
  7878. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  7879. Delay_ms(100);
  7880. Params += "[控制参数]" + "\r\n" + richTextBox_ControlParam.Text + "\r\n";
  7881. Params += "\r\n";
  7882. //查询传感器
  7883. richTextBox_SensorParam.Clear();
  7884. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  7885. Delay_ms(100);
  7886. Params += "[传感器参数]" + "\r\n" + richTextBox_SensorParam.Text + "\r\n";
  7887. Params += "\r\n";
  7888. //读取15次助力参数
  7889. Params += "[助力参数]" + "\r\n";
  7890. for (int i = 1; i <= 15; i++)
  7891. {
  7892. var ConfigParam = new byte[4];
  7893. richTextBox_AssistParam.Clear();
  7894. ConfigParam[0] = (byte)(i & 0xFF);
  7895. ConfigParam[1] = (byte)(i >> 8);
  7896. ConfigParam[2] = (byte)(((i >= 5) ? 5 : i) & 0xFF);
  7897. ConfigParam[3] = (byte)(((i >= 5) ? 5 : i) >> 8);
  7898. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  7899. Delay_ms(200);
  7900. Params += richTextBox_AssistParam.Text + "\r\n";
  7901. Params += "\r\n";
  7902. }
  7903. //读取一次调试信息
  7904. richTextBox_DebugParam.Clear();
  7905. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  7906. Delay_ms(100);
  7907. Params += "[调试参数]" + "\r\n" + richTextBox_DebugParam.Text + "\r\n";
  7908. Params += "\r\n";
  7909. //读取一次历史信息
  7910. richTextBox_Record.Clear();
  7911. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  7912. Delay_ms(100);
  7913. Params += "[历史信息]" + "\r\n" + richTextBox_Record.Text + "\r\n";
  7914. Params += "\r\n";
  7915. //读取一次MOS内阻校准参数
  7916. foreach (Control c in groupBox21.Controls)
  7917. {
  7918. if (c is TextBox)
  7919. c.Text = "";
  7920. }
  7921. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  7922. Delay_ms(100);
  7923. Params += "[MOS内阻校准参数]" + "\r\n";
  7924. Params += textBox_MOS_K1.Text + ", " + textBox_MOS_K2.Text + ", " + textBox_MOS_K3.Text + ", " + textBox_MOS_K4.Text + ", "
  7925. + textBox_MOS_K5.Text + ", " + textBox_MOS_R1.Text + ", " + textBox_MOS_R2.Text + ", " + textBox_MOS_R3.Text + ", " + "\r\n";
  7926. Params += "\r\n";
  7927. //读取一次整车参数2
  7928. richTextBox_BikeParam2.Clear();
  7929. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null)) break;
  7930. Delay_ms(100);
  7931. Params += "[整车参数2]" + "\r\n" + richTextBox_BikeParam2.Text + "\r\n";
  7932. Params += "\r\n";
  7933. //读取一次用户骑行参数
  7934. richTextBox_UsrRidesParam.Clear();
  7935. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  7936. Delay_ms(100);
  7937. Params += "[用户骑行参数]" + "\r\n" + richTextBox_UsrRidesParam.Text + "\r\n";
  7938. Params += "\r\n";
  7939. //读取一次生产信息
  7940. textBox_MAC.Text = "";
  7941. textBox_MACAdd.Text = "";
  7942. textBox_MACDate.Text = "";
  7943. textBox_PP.Text = "";
  7944. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  7945. Delay_ms(100);
  7946. Params += "[生产信息]" + "\r\n";
  7947. Params += "生产商: " + textBox_MAC.Text + "\r\n";
  7948. Params += "生产地: " + textBox_MACAdd.Text + "\r\n";
  7949. Params += "生产日期: " + textBox_MACDate.Text + "\r\n";
  7950. Params += "产品标识: " + textBox_PP.Text + "\r\n";
  7951. Params += "\r\n";
  7952. //读取一次自定义信息
  7953. textBox_User1.Text = "---";
  7954. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  7955. Delay_ms(100);
  7956. textBox_User2.Text = "---";
  7957. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  7958. Delay_ms(100);
  7959. textBox_User3.Text = "---";
  7960. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  7961. Delay_ms(100);
  7962. Params += "[自定义信息]" + "\r\n";
  7963. Params += "自定义1: " + textBox_User1.Text + "\r\n";
  7964. Params += "自定义2: " + textBox_User2.Text + "\r\n";
  7965. Params += "自定义3: " + textBox_User3.Text + "\r\n";
  7966. Params += "\r\n";
  7967. //读取一次密钥
  7968. textBox_Key.Text = "---";
  7969. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  7970. Delay_ms(100);
  7971. Params += "[校验密钥]" + "\r\n" + textBox_Key.Text + "\r\n";
  7972. Params += "\r\n";
  7973. //读取一次存储标志
  7974. radioButton_EE_SaveYes.Checked = false;
  7975. radioButton_EE_SaveNo.Checked = false;
  7976. radioButton_SIP_SaveYes.Checked = false;
  7977. radioButton_SIP_SaveNo.Checked = false;
  7978. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  7979. Delay_ms(100);
  7980. Params += "[存储标志]" + "\r\n";
  7981. Params += "EEPROM: " + ((radioButton_EE_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  7982. Params += "SIP: " + ((radioButton_SIP_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  7983. Params += "\r\n";
  7984. } while (false);
  7985. //系统关机
  7986. var Code = new byte[32];//发送的指令数据
  7987. Code[0] = 0xF0;
  7988. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  7989. //关闭串口
  7990. //mySerialProcess.SerialClose(false);
  7991. //路径设置
  7992. string LocalSavePath = "";
  7993. string ServerSavePath = "";
  7994. if (OK_Flag)
  7995. {
  7996. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "OK\\";
  7997. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/OK/";
  7998. }
  7999. else
  8000. {
  8001. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "FAIL\\";
  8002. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/FAIL/";
  8003. }
  8004. if (Directory.Exists(LocalSavePath) == false)
  8005. {
  8006. Directory.CreateDirectory(LocalSavePath);
  8007. }
  8008. //保存和上传
  8009. string LogSavePath = "";
  8010. string LogSaveFileName = "";
  8011. string ProductInfo = textBox_CheckModeScan.Text.Replace(" ", "_").Replace("/", "-"); ;
  8012. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  8013. if (Directory.Exists(LogSavePath) == false)
  8014. {
  8015. Directory.CreateDirectory(LogSavePath);
  8016. }
  8017. //测试页面
  8018. Double scaleX = PrimaryScreen.ScaleX;
  8019. Double scaleY = PrimaryScreen.ScaleY;
  8020. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  8021. Graphics g = Graphics.FromImage(bit);
  8022. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  8023. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  8024. bit.Save(LogSaveFileName);
  8025. //上传测试页面到服务器
  8026. if (myFtp.IsNetConnected == true)
  8027. {
  8028. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  8029. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  8030. {
  8031. myFtp.MakeDir(ServerSavePath + DateNow);
  8032. }
  8033. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  8034. {
  8035. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  8036. }
  8037. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  8038. if (result == true)
  8039. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  8040. }
  8041. //测试记录
  8042. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  8043. string file_str = "";
  8044. file_str += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  8045. file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  8046. file_str += "检验记录:\r\n" + richTextBox_CheckModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  8047. file_str += "检验结果:\r\n" + label_CheckModeResult.Text + "\r\n\r\n";
  8048. file_str += Local_HdInformation;
  8049. file_str += "\r\n电机存储参数:\r\n" + Params + "\r\n";
  8050. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  8051. //上传测试记录到服务器
  8052. if (myFtp.IsNetConnected == true)
  8053. {
  8054. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  8055. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  8056. {
  8057. myFtp.MakeDir(ServerSavePath + DateNow);
  8058. }
  8059. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  8060. {
  8061. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  8062. }
  8063. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  8064. if (result == true)
  8065. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  8066. }
  8067. //扫码框清空
  8068. textBox_CheckModeScan.Text = "";
  8069. }
  8070. /// <summary>
  8071. /// 参数检验开始
  8072. /// </summary>
  8073. /// <param name="sender"></param>
  8074. /// <param name="e"></param>
  8075. private void button_CheckModeStart_Click(object sender, EventArgs e)
  8076. {
  8077. //测试项目关闭编辑
  8078. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  8079. foreach (Control c in groupBox29.Controls)
  8080. {
  8081. if (c is CheckBox)
  8082. c.Enabled = false;
  8083. }
  8084. ReadLockStatus = true;
  8085. //检查配置文件
  8086. if (comboBox_CheckModeCfgFile.Text == "")
  8087. {
  8088. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  8089. return;
  8090. }
  8091. //开始测试
  8092. CheckTestStart();
  8093. }
  8094. /// <summary>
  8095. /// 参数检验测试子函数
  8096. /// </summary>
  8097. private void CheckTestStart()
  8098. {
  8099. //初始化标签
  8100. CheckModeLabelInit();
  8101. richTextBox_CheckModeLog.Clear();
  8102. //按钮禁止操作
  8103. button_CheckModeStart.Enabled = false;
  8104. //记录配置文件
  8105. richTextBox_CheckModeLog.AppendText("配置文件:" + comboBox_CheckModeCfgDate.Text + " / " + comboBox_CheckModeCfgFile.Text + "\r\n");
  8106. //检查打标信息
  8107. label_CheckModeStatus.Text = "检查扫码信息";
  8108. Delay_ms(500);
  8109. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  8110. if (textBox_CheckModeScan.Text == string.Empty)
  8111. {
  8112. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  8113. button__FacMode_Start.Enabled = false;
  8114. return;
  8115. }
  8116. try
  8117. {
  8118. if (中置电机ToolStripMenuItem.Checked == true)
  8119. {
  8120. if (textBox_CheckModeScan.Text.Split(' ').Length != 7)
  8121. {
  8122. label_CheckModeStatus.Text = "存在故障!";
  8123. label_CheckModeResult.BackColor = Color.Red;
  8124. label_CheckModeResult.Text = "标签格式错误";
  8125. button_CheckModeStart.Enabled = true;
  8126. return;
  8127. }
  8128. }
  8129. else if (轮毂电机ToolStripMenuItem.Checked == true)
  8130. {
  8131. if (textBox_CheckModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  8132. {
  8133. label_CheckModeStatus.Text = "存在故障!";
  8134. label_CheckModeResult.BackColor = Color.Red;
  8135. label_CheckModeResult.Text = "标签格式错误";
  8136. button_CheckModeStart.Enabled = true;
  8137. return;
  8138. }
  8139. }
  8140. }
  8141. catch (System.Exception)
  8142. {
  8143. label_CheckModeStatus.Text = "存在故障!";
  8144. label_CheckModeResult.BackColor = Color.Red;
  8145. label_CheckModeResult.Text = "标签格式错误";
  8146. button_CheckModeStart.Enabled = true;
  8147. return;
  8148. }
  8149. //打开串口
  8150. mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false);
  8151. if (!mySerialProcess.mySerial.IsOpen)
  8152. {
  8153. MessageBox.Show("请检查串口连接!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  8154. button__FacMode_Start.Enabled = false;
  8155. return;
  8156. }
  8157. //流水号计数
  8158. int serial = Convert.ToInt32(label_CheckModeSerial.Text);
  8159. serial += 1;
  8160. label_CheckModeSerial.Text = serial.ToString();
  8161. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, serial.ToString());
  8162. //创建线程,执行测试任务
  8163. Thread th = new Thread(CheckModeTest_Task);
  8164. th.Start();
  8165. }
  8166. /// <summary>
  8167. /// 执行一次测试任务
  8168. /// </summary>
  8169. private void CheckModeTest_Task()
  8170. {
  8171. //开始测试
  8172. richTextBox_CheckModeLog.AppendText("产品标签:" + textBox_CheckModeScan.Text + "\r\n");
  8173. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  8174. //变量定义
  8175. var Code = new byte[255];//发送的指令数据
  8176. ushort DataTemp;
  8177. short DataTemp_Int16;
  8178. string ResultPathName = "";
  8179. label_CheckModeStatus.Text = "开始测试";
  8180. BootInfo = "";
  8181. Delay_ms(500);
  8182. label_CheckModeStatus.Text = "系统开机";
  8183. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  8184. if (uARTToolStripMenuItem.Checked)
  8185. {
  8186. Code[0] = (byte)'R';
  8187. Code[1] = (byte)'E';
  8188. Code[2] = (byte)'S';
  8189. Code[3] = (byte)'E';
  8190. Code[4] = (byte)'T';
  8191. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  8192. Delay_ms(500);
  8193. }
  8194. //系统开机,确保测试前先关机,发送关机指令再发送开机指令
  8195. //确保测试前先关机,发送关机指令再发送开机指令
  8196. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  8197. Code[0] = 0xF0;
  8198. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  8199. Delay_ms(1500);
  8200. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  8201. Code[0] = 0xF1;
  8202. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  8203. ACK_WaitCnt = 0;
  8204. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  8205. while (ACK_WaitCnt <= 20) ; //10s
  8206. //检查BOOT版本
  8207. if (BootInfo != string.Empty)
  8208. {
  8209. label_CheckModeBoot.BackColor = Color.Green;
  8210. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  8211. Delay_ms(500);
  8212. }
  8213. else
  8214. {
  8215. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
  8216. label_CheckModeStatus.Text = "存在故障!";
  8217. label_CheckModeResult.BackColor = Color.Red;
  8218. label_CheckModeResult.Text = "测试异常";
  8219. Delay_ms(500);
  8220. //存储异常并上传
  8221. CheckMode_Stop(false);
  8222. return;
  8223. }
  8224. #if false
  8225. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  8226. {
  8227. Code[0] = 0x00;//5S协议
  8228. Code[1] = 0x00;
  8229. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  8230. Delay_ms(500);
  8231. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  8232. Delay_ms(500);
  8233. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  8234. }
  8235. #endif
  8236. //发送指令读取版本信息
  8237. do
  8238. {
  8239. label_CheckModeStatus.Text = "读取版本信息";
  8240. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  8241. //发送指令读取版本
  8242. Class_Motor_Ver.Mode = "---";
  8243. Class_Motor_Ver.SN = "---";
  8244. Class_Motor_Ver.HW = "---";
  8245. Class_Motor_Ver.FW = "---";
  8246. Class_Motor_Ver.Special = "---";
  8247. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  8248. ACK_WaitCnt = 0;
  8249. while (ACK_WaitCnt <= 2) ; //1s
  8250. if (Class_Motor_Ver.Mode == "---")
  8251. {
  8252. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第1次重发" + "\r\n");
  8253. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  8254. ACK_WaitCnt = 0;
  8255. while (ACK_WaitCnt <= 2) ; //1s
  8256. if (Class_Motor_Ver.Mode == "---")
  8257. {
  8258. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第2次重发" + "\r\n");
  8259. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  8260. ACK_WaitCnt = 0;
  8261. while (ACK_WaitCnt <= 2) ; //1s
  8262. if (Class_Motor_Ver.Mode == "---")
  8263. {
  8264. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取失败" + "\r\n");
  8265. label_CheckModeStatus.Text = "存在故障!";
  8266. label_CheckModeResult.BackColor = Color.Red;
  8267. label_CheckModeResult.Text = "测试异常";
  8268. Delay_ms(500);
  8269. //存储异常并上传
  8270. CheckMode_Stop(false);
  8271. return;
  8272. }
  8273. }
  8274. }
  8275. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  8276. richTextBox_CheckModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  8277. richTextBox_CheckModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  8278. richTextBox_CheckModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  8279. richTextBox_CheckModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  8280. richTextBox_CheckModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  8281. Delay_ms(500);
  8282. } while (false);
  8283. //软件版本检查
  8284. if (checkBox_CheckModeFWVer.Checked)
  8285. {
  8286. //判断版本是否正确
  8287. string VerCheck = comboBox_CheckModeCfgFile.Text.Split('_')[3] + "_" + comboBox_CheckModeCfgFile.Text.Split('_')[4];
  8288. string VerRead = "";
  8289. try
  8290. {
  8291. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  8292. }
  8293. catch (System.Exception)
  8294. {
  8295. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  8296. label_CheckModeStatus.Text = "存在故障!";
  8297. label_CheckModeResult.BackColor = Color.Red;
  8298. label_CheckModeResult.Text = "测试异常";
  8299. Delay_ms(500);
  8300. //存储异常并上传
  8301. CheckMode_Stop(false);
  8302. return;
  8303. }
  8304. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  8305. {
  8306. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
  8307. label_CheckModeStatus.Text = "存在故障!";
  8308. label_CheckModeResult.BackColor = Color.Red;
  8309. label_CheckModeResult.Text = "测试异常";
  8310. Delay_ms(500);
  8311. //存储异常并上传
  8312. CheckMode_Stop(false);
  8313. return;
  8314. }
  8315. label_CheckModeFWVer.BackColor = Color.Green;
  8316. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  8317. Delay_ms(500);
  8318. }
  8319. else
  8320. {
  8321. label_CheckModeFWVer.BackColor = Color.Yellow;
  8322. label_CheckModeStatus.Text = "跳过软件版本查询";
  8323. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过软件版本查询" + "\r\n");
  8324. Delay_ms(500);
  8325. }
  8326. //打标信息核对
  8327. if (checkBox_CheckModeSN.Checked)
  8328. {
  8329. label_CheckModeStatus.Text = "核对打标信息";
  8330. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "核对打标信息" + "\r\n");
  8331. //根据扫码信息获取型号和SN
  8332. string ScanInfo = textBox_CheckModeScan.Text;
  8333. string regexInfo = "";
  8334. string[] InfoList = { "" };
  8335. try
  8336. {
  8337. if (中置电机ToolStripMenuItem.Checked == true)
  8338. {
  8339. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  8340. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  8341. }
  8342. else if (轮毂电机ToolStripMenuItem.Checked == true)
  8343. {
  8344. if (!ScanInfo.Contains("/")) //老编码规则
  8345. {
  8346. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  8347. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  8348. string Spec = InfoList[1];
  8349. string Sn = InfoList[2];
  8350. InfoList[0] = Model.Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  8351. InfoList[1] = Sn;
  8352. }
  8353. else //新编码规则
  8354. {
  8355. Dictionary<string, string> Dic_Ver = new Dictionary<string, string>
  8356. {
  8357. { "01", "A" },
  8358. { "02", "B" },
  8359. { "03", "C" },
  8360. { "04", "D" },
  8361. { "05", "E" },
  8362. { "06", "F" },
  8363. { "07", "G" },
  8364. { "08", "H" },
  8365. { "09", "I" }
  8366. };
  8367. Dictionary<string, string> Dic_Vol = new Dictionary<string, string>
  8368. {
  8369. { "24V", "A" },
  8370. { "36V", "B" },
  8371. { "42V", "C" },
  8372. { "48V", "D" },
  8373. { "52V", "E" },
  8374. { "60V", "F" }
  8375. };
  8376. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  8377. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  8378. string Spec = InfoList[1].Replace("-", "").Replace("/", "");
  8379. string Sn = InfoList[2];
  8380. InfoList[0] = Model[2] + Dic_Ver[Model.Substring(3, 2)] + Model[5] + Dic_Ver[Model.Substring(6, 2)] + Model[9];
  8381. InfoList[0] += Dic_Vol[Spec.Substring(0, 3)] + Spec.Substring(3, 3) + Spec.Substring(13, 4) + Spec.Substring(Spec.Length - 4, 3);
  8382. InfoList[1] = Sn;
  8383. }
  8384. }
  8385. }
  8386. catch
  8387. {
  8388. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  8389. label_FacModeStatus.Text = "存在故障!";
  8390. label_FacModeResult.BackColor = Color.Red;
  8391. label_FacModeResult.Text = "标签格式错误";
  8392. Delay_ms(500);
  8393. //存储异常并上传
  8394. CheckMode_Stop(false);
  8395. return;
  8396. }
  8397. //核对型号
  8398. if (string.Equals(InfoList[0], Class_Motor_Ver.Mode) == false) //型号错误,直接结束
  8399. {
  8400. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号不一致" + "\r\n");
  8401. label_CheckModeStatus.Text = "存在故障!";
  8402. label_CheckModeResult.BackColor = Color.Red;
  8403. label_CheckModeResult.Text = "测试异常";
  8404. Delay_ms(500);
  8405. //存储异常并上传
  8406. CheckMode_Stop(false);
  8407. return;
  8408. }
  8409. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号一致" + "\r\n");
  8410. Delay_ms(500);
  8411. //核对SN
  8412. if (string.Equals(InfoList[1], Class_Motor_Ver.SN) == false) //型号错误,直接结束
  8413. {
  8414. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN不一致" + "\r\n");
  8415. label_CheckModeStatus.Text = "存在故障!";
  8416. label_CheckModeResult.BackColor = Color.Red;
  8417. label_CheckModeResult.Text = "测试异常";
  8418. Delay_ms(500);
  8419. //存储异常并上传
  8420. CheckMode_Stop(false);
  8421. return;
  8422. }
  8423. label_CheckModeSN.BackColor = Color.Green;
  8424. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN一致" + "\r\n");
  8425. Delay_ms(500);
  8426. }
  8427. else
  8428. {
  8429. label_CheckModeSN.BackColor = Color.Yellow;
  8430. label_CheckModeStatus.Text = "跳过打标信息确认";
  8431. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过打标信息确认" + "\r\n");
  8432. Delay_ms(500);
  8433. }
  8434. //参数检验
  8435. if (checkBox_CheckModeCfg.Checked)
  8436. {
  8437. //读取配置文件信息
  8438. label_CheckModeStatus.Text = "参数检查";
  8439. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  8440. //配置文件
  8441. List<byte[]> CmdList = new List<byte[]>();
  8442. Dictionary<string, string> ConfigCmd = new Dictionary<string, string>();//配置文件格式
  8443. //从服务器下载文件
  8444. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  8445. {
  8446. string SelectFile = "";
  8447. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "/" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  8448. if (File.Exists(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  8449. {
  8450. File.Delete(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  8451. }
  8452. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  8453. //打开文件
  8454. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  8455. ConfigCmd.Clear();
  8456. while (streamReader.Peek() != -1)
  8457. {
  8458. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  8459. if (fileLineInfo.Contains("["))
  8460. {
  8461. if (fileLineInfo.Contains("助力参数"))
  8462. {
  8463. fileLineInfo = streamReader.ReadLine();
  8464. }
  8465. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  8466. }
  8467. }
  8468. streamReader.Close();
  8469. }
  8470. //从本地加载文件
  8471. else
  8472. {
  8473. string SelectFile = "";
  8474. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  8475. //打开文件
  8476. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  8477. ConfigCmd.Clear();
  8478. while (streamReader.Peek() != -1)
  8479. {
  8480. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  8481. if (fileLineInfo.Contains("["))
  8482. {
  8483. if (fileLineInfo.Contains("助力参数"))
  8484. {
  8485. fileLineInfo = streamReader.ReadLine();
  8486. }
  8487. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  8488. }
  8489. }
  8490. streamReader.Close();
  8491. }
  8492. int CmdNum = ConfigCmd.Count(); //指令个数
  8493. Delay_ms(500);
  8494. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "\r\n");
  8495. Delay_ms(500);
  8496. //逐条读取比较
  8497. try
  8498. {
  8499. foreach (string key in ConfigCmd.Keys)
  8500. {
  8501. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令:" + "\r\n");
  8502. CmdRevStrTemp = "";
  8503. if (key.Contains("曲线"))
  8504. {
  8505. byte LineNum = 0;
  8506. var code = new byte[4];
  8507. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  8508. if (LineNum <= 5)
  8509. {
  8510. code[0] = (byte)(LineNum & 0xFF);
  8511. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8512. code[2] = (byte)(LineNum & 0xFF);
  8513. code[3] = (byte)((LineNum >> 8) & 0xFF);
  8514. }
  8515. else
  8516. {
  8517. code[0] = (byte)(LineNum & 0xFF);
  8518. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8519. code[2] = (byte)(5 & 0xFF);
  8520. code[3] = (byte)((5 >> 8) & 0xFF);
  8521. }
  8522. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  8523. }
  8524. else
  8525. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  8526. Delay_ms(500);
  8527. if (CmdRevStrTemp == string.Empty)
  8528. {
  8529. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令,第1次重发" + "\r\n");
  8530. if (key.Contains("曲线"))
  8531. {
  8532. byte LineNum = 0;
  8533. var code = new byte[4];
  8534. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  8535. if (LineNum <= 5)
  8536. {
  8537. code[0] = (byte)(LineNum & 0xFF);
  8538. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8539. code[2] = (byte)(LineNum & 0xFF);
  8540. code[3] = (byte)((LineNum >> 8) & 0xFF);
  8541. }
  8542. else
  8543. {
  8544. code[0] = (byte)(LineNum & 0xFF);
  8545. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8546. code[2] = (byte)(5 & 0xFF);
  8547. code[3] = (byte)((5 >> 8) & 0xFF);
  8548. }
  8549. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  8550. }
  8551. else
  8552. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  8553. Delay_ms(500);
  8554. if (CmdRevStrTemp == string.Empty)
  8555. {
  8556. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令,第2次重发" + "\r\n");
  8557. if (key.Contains("曲线"))
  8558. {
  8559. byte LineNum = 0;
  8560. var code = new byte[4];
  8561. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  8562. if (LineNum <= 5)
  8563. {
  8564. code[0] = (byte)(LineNum & 0xFF);
  8565. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8566. code[2] = (byte)(LineNum & 0xFF);
  8567. code[3] = (byte)((LineNum >> 8) & 0xFF);
  8568. }
  8569. else
  8570. {
  8571. code[0] = (byte)(LineNum & 0xFF);
  8572. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8573. code[2] = (byte)(5 & 0xFF);
  8574. code[3] = (byte)((5 >> 8) & 0xFF);
  8575. }
  8576. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  8577. }
  8578. else
  8579. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  8580. Delay_ms(500);
  8581. if (CmdRevStrTemp == string.Empty)
  8582. {
  8583. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "指令读取失败" + "\r\n");
  8584. label_CheckModeStatus.Text = "存在故障!";
  8585. label_CheckModeResult.BackColor = Color.Red;
  8586. label_CheckModeResult.Text = "测试异常";
  8587. Delay_ms(500);
  8588. //存储异常并上传
  8589. CheckMode_Stop(false);
  8590. return;
  8591. }
  8592. }
  8593. }
  8594. //比较当前指令,读取的配置文件和返回数据比较
  8595. string ParamWrite = ConfigCmd[key].Substring(24, ConfigCmd[key].Length - 40).Trim();
  8596. string ParamRead = "";
  8597. ushort CmdGet = Convert.ToUInt16(CmdRevStrTemp.Substring(0, 6).Trim().Replace(" ", ""), 16);//接收到指令的命令字
  8598. ushort CmdRev = myParams.ConfigCheckRevCmd[key];//接收指令设计值
  8599. if (CmdGet != CmdRev)
  8600. {
  8601. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "接收指令不正确" + "\r\n");
  8602. richTextBox_CheckModeLog.AppendText("接收指令:" + "0x" + CmdGet.ToString("X2") + "\r\n");
  8603. richTextBox_CheckModeLog.AppendText("正确指令应为:" + "0x" + CmdRev.ToString("X2") + "\r\n");
  8604. label_CheckModeStatus.Text = "存在故障!";
  8605. label_CheckModeResult.BackColor = Color.Red;
  8606. label_CheckModeResult.Text = "测试异常";
  8607. Delay_ms(500);
  8608. //存储异常并上传
  8609. CheckMode_Stop(false);
  8610. return;
  8611. }
  8612. if (string.Compare(key, "[其它传感器参数]") == 0)
  8613. ParamRead = CmdRevStrTemp.Substring(90, CmdRevStrTemp.Length - 90).Trim(); //去掉命令字、力矩传感器标定参数
  8614. else if (string.Compare(key, "[力矩传感器参数]") == 0)
  8615. ParamRead = CmdRevStrTemp.Substring(6, CmdRevStrTemp.Length - 6 - 36).Trim(); //去掉命令字、其它传感器参数
  8616. else if (string.Compare(key, "[控制参数]") == 0)
  8617. ParamRead = CmdRevStrTemp.Substring(18, CmdRevStrTemp.Length - 18).Trim(); //去掉命令字、位置零点
  8618. else
  8619. ParamRead = CmdRevStrTemp.Substring(6, CmdRevStrTemp.Length - 6).Trim(); //去掉命令字
  8620. if (ParamWrite.Contains(ParamRead))
  8621. {
  8622. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "一致" + "\r\n");
  8623. continue;
  8624. }
  8625. else
  8626. {
  8627. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "不一致" + "\r\n");
  8628. richTextBox_CheckModeLog.AppendText("写入参数:" + ParamWrite + "\r\n");
  8629. richTextBox_CheckModeLog.AppendText("读出参数:" + ParamRead + "\r\n");
  8630. label_CheckModeStatus.Text = "存在故障!";
  8631. label_CheckModeResult.BackColor = Color.Red;
  8632. label_CheckModeResult.Text = "测试异常";
  8633. Delay_ms(500);
  8634. //存储异常并上传
  8635. CheckMode_Stop(false);
  8636. return;
  8637. }
  8638. }
  8639. }
  8640. catch (System.Exception)
  8641. {
  8642. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数检验失败" + "\r\n");
  8643. label_CheckModeStatus.Text = "存在故障!";
  8644. label_CheckModeResult.BackColor = Color.Red;
  8645. label_CheckModeResult.Text = "测试异常";
  8646. Delay_ms(500);
  8647. //存储异常并上传
  8648. CheckMode_Stop(false);
  8649. return;
  8650. }
  8651. label_CheckModeCfg.BackColor = Color.Green;
  8652. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数检验正确" + "\r\n");
  8653. Delay_ms(500);
  8654. }
  8655. else
  8656. {
  8657. label_CheckModeCfg.BackColor = Color.Yellow;
  8658. label_CheckModeStatus.Text = "跳过参数检验";
  8659. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数检验" + "\r\n");
  8660. Delay_ms(500);
  8661. }
  8662. //读取力矩传感器
  8663. do
  8664. {
  8665. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据" + "\r\n");
  8666. //发送指令读取力矩传感器标定数据
  8667. CmdRevStrTemp = "";
  8668. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  8669. ACK_WaitCnt = 0;
  8670. while (ACK_WaitCnt <= 2) ; //1s
  8671. if (CmdRevStrTemp == string.Empty)
  8672. {
  8673. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据,第1次重发" + "\r\n");
  8674. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  8675. ACK_WaitCnt = 0;
  8676. while (ACK_WaitCnt <= 2) ; //1s
  8677. if (CmdRevStrTemp == string.Empty)
  8678. {
  8679. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据,第2次重发" + "\r\n");
  8680. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  8681. ACK_WaitCnt = 0;
  8682. while (ACK_WaitCnt <= 2) ; //1s
  8683. if (CmdRevStrTemp == string.Empty)
  8684. {
  8685. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取失败" + "\r\n");
  8686. label_CheckModeStatus.Text = "存在故障!";
  8687. label_CheckModeResult.BackColor = Color.Red;
  8688. label_CheckModeResult.Text = "测试异常";
  8689. Delay_ms(500);
  8690. //存储异常并上传
  8691. CheckMode_Stop(false);
  8692. return;
  8693. }
  8694. }
  8695. }
  8696. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取成功" + "\r\n");
  8697. //取力矩传感器数据
  8698. ushort ZeroInit, Zero1, Zero2, Zero3, ZeroNew;
  8699. ushort MaxTorque;
  8700. ushort K1_T, K1, K2_T, K2, K3_T, K3, K4_T, K4;
  8701. byte[] DataArray = mySerialProcess.HexStringToBytes(CmdRevStrTemp, true);
  8702. ushort Cmd = (ushort)((DataArray[0] << 8) + DataArray[1]);
  8703. if (Cmd != 0xB528)
  8704. {
  8705. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器参数错误,CMD: 0x" + Convert.ToString(Cmd, 16).PadLeft(2, '0').ToUpper() + "\r\n");
  8706. label_CheckModeStatus.Text = "存在故障!";
  8707. label_CheckModeResult.BackColor = Color.Red;
  8708. label_CheckModeResult.Text = "测试异常";
  8709. Delay_ms(500);
  8710. //存储异常并上传
  8711. CheckMode_Stop(false);
  8712. return;
  8713. }
  8714. ZeroInit = (ushort)((DataArray[3] << 8) + DataArray[2]);
  8715. Zero1 = (ushort)((DataArray[5] << 8) + DataArray[4]);
  8716. Zero2 = (ushort)((DataArray[7] << 8) + DataArray[6]);
  8717. Zero3 = (ushort)((DataArray[9] << 8) + DataArray[8]);
  8718. ZeroNew = (ushort)((DataArray[11] << 8) + DataArray[10]);
  8719. MaxTorque = (ushort)((DataArray[13] << 8) + DataArray[12]);
  8720. K1_T = (ushort)((DataArray[15] << 8) + DataArray[14]);
  8721. K1 = (ushort)((DataArray[17] << 8) + DataArray[16]);
  8722. K2_T = (ushort)((DataArray[19] << 8) + DataArray[18]);
  8723. K2 = (ushort)((DataArray[21] << 8) + DataArray[20]);
  8724. K3_T = (ushort)((DataArray[23] << 8) + DataArray[22]);
  8725. K3 = (ushort)((DataArray[25] << 8) + DataArray[24]);
  8726. K4_T = (ushort)((DataArray[27] << 8) + DataArray[26]);
  8727. K4 = (ushort)((DataArray[29] << 8) + DataArray[28]);
  8728. richTextBox_CheckModeLog.AppendText("力矩传感器零点: " + ZeroInit.ToString() + "," + Zero1.ToString() + "," +
  8729. Zero2.ToString() + "," + Zero3.ToString() + "," + ZeroNew.ToString() + "\r\n");
  8730. richTextBox_CheckModeLog.AppendText("最大力矩: " + MaxTorque.ToString() + "\r\n");
  8731. richTextBox_CheckModeLog.AppendText("力矩传感器标定: " + "[" + K1_T.ToString() + "," + K1.ToString() + "]" + "," +
  8732. "[" + K2_T.ToString() + "," + K2.ToString() + "]" + "," + "[" + K3_T.ToString() + "," + K3.ToString() + "]" + "," +
  8733. "[" + K4_T.ToString() + "," + K4.ToString() + "]" + "\r\n");
  8734. //传感器标定检验
  8735. if (checkBox_CheckModeTorque.Checked)
  8736. {
  8737. richTextBox_CheckModeLog.AppendText("力矩零点范围: " + TorqueParamsForm.Zero.Min.ToString() + " - " + TorqueParamsForm.Zero.Max.ToString() + "\r\n");
  8738. richTextBox_CheckModeLog.AppendText("K1范围: " + TorqueParamsForm.K1.T.ToString() + "," + TorqueParamsForm.K1.Min.ToString() + " - " + TorqueParamsForm.K1.Max.ToString() + "\r\n");
  8739. richTextBox_CheckModeLog.AppendText("K2范围: " + TorqueParamsForm.K2.T.ToString() + "," + TorqueParamsForm.K2.Min.ToString() + " - " + TorqueParamsForm.K2.Max.ToString() + "\r\n");
  8740. richTextBox_CheckModeLog.AppendText("K3范围: " + TorqueParamsForm.K3.T.ToString() + "," + TorqueParamsForm.K3.Min.ToString() + " - " + TorqueParamsForm.K3.Max.ToString() + "\r\n");
  8741. richTextBox_CheckModeLog.AppendText("K4范围: " + TorqueParamsForm.K4.T.ToString() + "," + TorqueParamsForm.K4.Min.ToString() + " - " + TorqueParamsForm.K4.Max.ToString() + "\r\n");
  8742. //与设置值比较
  8743. if ((ZeroInit <= TorqueParamsForm.Zero.Max) && (ZeroInit >= TorqueParamsForm.Zero.Min)
  8744. && (K1_T == TorqueParamsForm.K1.T) && (K1 <= TorqueParamsForm.K1.Max) && (K1 >= TorqueParamsForm.K1.Min)
  8745. && (K2_T == TorqueParamsForm.K2.T) && (K2 <= TorqueParamsForm.K2.Max) && (K2 >= TorqueParamsForm.K2.Min)
  8746. && (K3_T == TorqueParamsForm.K3.T) && (K3 <= TorqueParamsForm.K3.Max) && (K3 >= TorqueParamsForm.K3.Min)
  8747. && (K4_T == TorqueParamsForm.K4.T) && (K4 <= TorqueParamsForm.K4.Max) && (K4 >= TorqueParamsForm.K4.Min)
  8748. )
  8749. {
  8750. label_CheckModeTorque.BackColor = Color.Green;
  8751. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定正常" + "\r\n");
  8752. Delay_ms(500);
  8753. }
  8754. else
  8755. {
  8756. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定超范围" + "\r\n");
  8757. label_CheckModeStatus.Text = "存在故障!";
  8758. label_CheckModeResult.BackColor = Color.Red;
  8759. label_CheckModeResult.Text = "测试异常";
  8760. Delay_ms(500);
  8761. //存储异常并上传
  8762. CheckMode_Stop(false);
  8763. return;
  8764. }
  8765. }
  8766. else
  8767. {
  8768. label_CheckModeTorque.BackColor = Color.Yellow;
  8769. label_CheckModeStatus.Text = "跳过传感器标定检验";
  8770. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过传感器标定检验" + "\r\n");
  8771. Delay_ms(500);
  8772. }
  8773. } while (false);
  8774. //读取MOS内阻校准参数
  8775. do
  8776. {
  8777. if (checkBox_CheckModeMos.Checked)
  8778. {
  8779. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据" + "\r\n");
  8780. //读取显示校准返回数据
  8781. foreach (Control c in groupBox21.Controls)
  8782. {
  8783. if (c is TextBox)
  8784. c.Text = "";
  8785. }
  8786. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8787. ACK_WaitCnt = 0;
  8788. while (ACK_WaitCnt <= 2) ; //1s
  8789. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  8790. {
  8791. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据,第1次重发" + "\r\n");
  8792. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8793. ACK_WaitCnt = 0;
  8794. while (ACK_WaitCnt <= 2) ; //1s
  8795. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  8796. {
  8797. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据,第2次重发" + "\r\n");
  8798. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8799. ACK_WaitCnt = 0;
  8800. while (ACK_WaitCnt <= 2) ; //1s
  8801. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  8802. {
  8803. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果异常" + "\r\n");
  8804. label_CheckModeStatus.Text = "存在故障!";
  8805. label_CheckModeResult.BackColor = Color.Red;
  8806. label_CheckModeResult.Text = "测试异常";
  8807. Delay_ms(500);
  8808. //存储异常并上传
  8809. CheckMode_Stop(false);
  8810. return;
  8811. }
  8812. }
  8813. }
  8814. else
  8815. {
  8816. 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");
  8817. }
  8818. //与校准返回数据对比
  8819. string[] MOS_R1_Th = toolStripTextBox_MOS1.Text.Split(',');
  8820. string[] MOS_R2_Th = toolStripTextBox_MOS2.Text.Split(',');
  8821. string[] MOS_R3_Th = toolStripTextBox_MOS3.Text.Split(',');
  8822. 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])) &&
  8823. (Convert.ToUInt16(textBox_MOS_R2.Text) >= Convert.ToUInt16(MOS_R2_Th[0])) && (Convert.ToUInt16(textBox_MOS_R2.Text) <= Convert.ToUInt16(MOS_R2_Th[1])) &&
  8824. (Convert.ToUInt16(textBox_MOS_R3.Text) >= Convert.ToUInt16(MOS_R3_Th[0])) && (Convert.ToUInt16(textBox_MOS_R3.Text) <= Convert.ToUInt16(MOS_R3_Th[1]))
  8825. )
  8826. {
  8827. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准合格" + "\r\n");
  8828. label_CheckModeMos.BackColor = Color.Green;
  8829. }
  8830. else
  8831. {
  8832. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准超范围" + "\r\n");
  8833. label_CheckModeStatus.Text = "存在故障!";
  8834. label_CheckModeResult.BackColor = Color.Red;
  8835. label_CheckModeResult.Text = "测试异常";
  8836. Delay_ms(500);
  8837. //存储异常并上传
  8838. CheckMode_Stop(false);
  8839. return;
  8840. }
  8841. }
  8842. else
  8843. {
  8844. label_CheckModeMos.BackColor = Color.Yellow;
  8845. label_CheckModeStatus.Text = "跳过MOS内阻校准检验";
  8846. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过MOS内阻校准检验" + "\r\n");
  8847. Delay_ms(500);
  8848. }
  8849. } while (false);
  8850. //读取位置校准参数
  8851. do
  8852. {
  8853. if (checkBox_CheckModeAngle.Checked)
  8854. {
  8855. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取位置校准数据" + "\r\n");
  8856. //发送指令读取位置
  8857. CmdRevStrTemp = "";
  8858. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
  8859. ACK_WaitCnt = 0;
  8860. while (ACK_WaitCnt <= 2) ; //1s
  8861. if (CmdRevStrTemp == string.Empty)
  8862. {
  8863. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取位置校准数据,第1次重发" + "\r\n");
  8864. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x3E00, null);
  8865. ACK_WaitCnt = 0;
  8866. while (ACK_WaitCnt <= 2) ; //1s
  8867. if (CmdRevStrTemp == string.Empty)
  8868. {
  8869. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取位置校准数据,第2次重发" + "\r\n");
  8870. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x3E00, null);
  8871. ACK_WaitCnt = 0;
  8872. while (ACK_WaitCnt <= 2) ; //1s
  8873. if (CmdRevStrTemp == string.Empty)
  8874. {
  8875. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准数据读取失败" + "\r\n");
  8876. label_CheckModeStatus.Text = "存在故障!";
  8877. label_CheckModeResult.BackColor = Color.Red;
  8878. label_CheckModeResult.Text = "测试异常";
  8879. Delay_ms(500);
  8880. //存储异常并上传
  8881. CheckMode_Stop(false);
  8882. return;
  8883. }
  8884. }
  8885. }
  8886. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准数据读取成功" + "\r\n");
  8887. //取零点数据
  8888. UInt16 AngleZero_Init = 0, AngleZero_Cur = 0;
  8889. byte[] DataArray = mySerialProcess.HexStringToBytes(CmdRevStrTemp, true);
  8890. ushort Cmd = (ushort)((DataArray[0] << 8) + DataArray[1]);
  8891. if (Cmd != 0xB420)
  8892. {
  8893. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置传感器参数错误,CMD: 0x" + Convert.ToString(Cmd, 16).PadLeft(2, '0').ToUpper() + "\r\n");
  8894. label_CheckModeStatus.Text = "存在故障!";
  8895. label_CheckModeResult.BackColor = Color.Red;
  8896. label_CheckModeResult.Text = "测试异常";
  8897. Delay_ms(500);
  8898. //存储异常并上传
  8899. CheckMode_Stop(false);
  8900. return;
  8901. }
  8902. AngleZero_Init = (ushort)((DataArray[3] << 8) + DataArray[2]);
  8903. AngleZero_Cur = (ushort)((DataArray[5] << 8) + DataArray[4]);
  8904. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置出厂零点: " + AngleZero_Init.ToString() + ",位置当前零点: " + AngleZero_Cur.ToString() + "\r\n");
  8905. int AngleZeroDiff = Math.Abs(AngleZero_Cur - AngleZero_Init);
  8906. int AngleZeroTH = Convert.ToInt32(textBox_AngleZeroTh.Text);
  8907. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置零点校准值: " + AngleZeroDiff.ToString() + ",判断阈值: " + AngleZeroTH.ToString() + "\r\n");
  8908. //判断
  8909. if (AngleZeroDiff <= AngleZeroTH)
  8910. {
  8911. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置传感器校准合格" + "\r\n");
  8912. label_CheckModeAngle.BackColor = Color.Green;
  8913. }
  8914. else
  8915. {
  8916. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置传感器校准超范围" + "\r\n");
  8917. label_CheckModeStatus.Text = "存在故障!";
  8918. label_CheckModeResult.BackColor = Color.Red;
  8919. label_CheckModeResult.Text = "测试异常";
  8920. Delay_ms(500);
  8921. //存储异常并上传
  8922. CheckMode_Stop(false);
  8923. return;
  8924. }
  8925. }
  8926. else
  8927. {
  8928. label_CheckModeAngle.BackColor = Color.Yellow;
  8929. label_CheckModeStatus.Text = "跳过位置传感器校准检验";
  8930. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过位置传感器校准检验" + "\r\n");
  8931. Delay_ms(500);
  8932. }
  8933. } while (false);
  8934. //测试合格
  8935. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  8936. label_CheckModeStatus.Text = "测试结束!";
  8937. label_CheckModeResult.BackColor = Color.Green;
  8938. label_CheckModeResult.Text = "测试合格";
  8939. Delay_ms(500);
  8940. //存储并上传
  8941. CheckMode_Stop(true);
  8942. return;
  8943. }
  8944. private void CheckModeLabelInit()
  8945. {
  8946. //测试状态标签
  8947. label_CheckModeResult.BackColor = Color.Yellow;
  8948. label_CheckModeResult.Text = "测试中";
  8949. //测试过程标签
  8950. label_CheckModeStatus.Text = "测试就绪";
  8951. //测试结果标签
  8952. foreach (Control c in groupBox31.Controls)
  8953. {
  8954. if (c is Label)
  8955. {
  8956. if (c.Text == string.Empty)
  8957. c.BackColor = Color.Red;
  8958. }
  8959. }
  8960. }
  8961. private void 调试记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  8962. {
  8963. System.Diagnostics.Process.Start("explorer.exe", Directory.GetCurrentDirectory());
  8964. }
  8965. private void 生产记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  8966. {
  8967. System.Diagnostics.Process.Start("explorer.exe", localInfo.LocalDataPath);
  8968. }
  8969. private void 累计运行时间ToolStripMenuItem_MouseHover(object sender, EventArgs e)
  8970. {
  8971. UInt32 Time = (UInt32)stopwatch.ElapsedMilliseconds / 1000;
  8972. UInt32 hour = Time / 3600;
  8973. UInt32 min = (Time % 3600) / 60;
  8974. UInt32 s = (Time % 60);
  8975. toolStripMenuItem_RunTime.Text = hour.ToString() + ":" + min.ToString("00") + ":" + s.ToString("00");
  8976. }
  8977. private void richTextBox_CheckModeLog_TextChanged(object sender, EventArgs e)
  8978. {
  8979. richTextBox_CheckModeLog.SelectionStart = richTextBox_CheckModeLog.Text.Length;
  8980. richTextBox_CheckModeLog.ScrollToCaret();
  8981. }
  8982. private void 力矩传感器检验ToolStripMenuItem_Click(object sender, EventArgs e)
  8983. {
  8984. TorqueParamsForm.ShowDialog();
  8985. }
  8986. private void textBox_CheckModeScan_KeyUp(object sender, KeyEventArgs e)
  8987. {
  8988. if (e.KeyCode == Keys.Enter)
  8989. CheckTestStart();
  8990. }
  8991. private void textBox_FacModeScan_KeyUp(object sender, KeyEventArgs e)
  8992. {
  8993. if (e.KeyCode == Keys.Enter)
  8994. TestStart();
  8995. }
  8996. private void button_SpeedDec10_Click(object sender, EventArgs e)
  8997. {
  8998. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  8999. if (Percent <= 10)
  9000. Percent = 0;
  9001. else
  9002. Percent -= 10;
  9003. //生产模式转速设置值更新
  9004. textBox_MotorSpeedPercent.Text = Percent.ToString();
  9005. //设置转速百分比
  9006. var Data = new byte[1];
  9007. Data[0] = (byte)Percent;
  9008. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  9009. }
  9010. private void button_SpeedAdd10_Click(object sender, EventArgs e)
  9011. {
  9012. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  9013. if (Percent >= 90)
  9014. Percent = 100;
  9015. else
  9016. Percent += 10;
  9017. //生产模式转速设置值更新
  9018. textBox_MotorSpeedPercent.Text = Percent.ToString();
  9019. //设置转速百分比
  9020. var Data = new byte[1];
  9021. Data[0] = (byte)Percent;
  9022. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  9023. }
  9024. private void button_SpeedDec1_Click(object sender, EventArgs e)
  9025. {
  9026. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  9027. if (Percent <= 1)
  9028. Percent = 0;
  9029. else
  9030. Percent -= 1;
  9031. //生产模式转速设置值更新
  9032. textBox_MotorSpeedPercent.Text = Percent.ToString();
  9033. //设置转速百分比
  9034. var Data = new byte[1];
  9035. Data[0] = (byte)Percent;
  9036. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  9037. }
  9038. private void button_SpeedAdd1_Click(object sender, EventArgs e)
  9039. {
  9040. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  9041. if (Percent >= 99)
  9042. Percent = 100;
  9043. else
  9044. Percent += 1;
  9045. //生产模式转速设置值更新
  9046. textBox_MotorSpeedPercent.Text = Percent.ToString();
  9047. //设置转速百分比
  9048. var Data = new byte[1];
  9049. Data[0] = (byte)Percent;
  9050. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  9051. }
  9052. bool WriteLockStatus = true;
  9053. private void pictureBox_WriteLock_Click(object sender, EventArgs e)
  9054. {
  9055. if (WriteLockStatus == true)
  9056. {
  9057. EnterForm1.ShowDialog();
  9058. try
  9059. {
  9060. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9061. {
  9062. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  9063. {
  9064. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  9065. foreach (Control c in groupBox2.Controls)
  9066. {
  9067. if (c is CheckBox)
  9068. c.Enabled = true;
  9069. }
  9070. WriteLockStatus = !WriteLockStatus;
  9071. }
  9072. else
  9073. {
  9074. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9075. }
  9076. }
  9077. else
  9078. {
  9079. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9080. }
  9081. }
  9082. catch (Exception)
  9083. {
  9084. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9085. }
  9086. }
  9087. else
  9088. {
  9089. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  9090. foreach (Control c in groupBox2.Controls)
  9091. {
  9092. if (c is CheckBox)
  9093. c.Enabled = false;
  9094. }
  9095. WriteLockStatus = !WriteLockStatus;
  9096. }
  9097. }
  9098. bool ReadLockStatus = true;
  9099. private void pictureBox_ReadLock_Click(object sender, EventArgs e)
  9100. {
  9101. if (ReadLockStatus == true)
  9102. {
  9103. EnterForm1.ShowDialog();
  9104. try
  9105. {
  9106. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9107. {
  9108. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  9109. {
  9110. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  9111. foreach (Control c in groupBox29.Controls)
  9112. {
  9113. if (c is CheckBox)
  9114. c.Enabled = true;
  9115. }
  9116. ReadLockStatus = !ReadLockStatus;
  9117. }
  9118. else
  9119. {
  9120. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9121. }
  9122. }
  9123. else
  9124. {
  9125. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9126. }
  9127. }
  9128. catch (Exception)
  9129. {
  9130. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9131. }
  9132. }
  9133. else
  9134. {
  9135. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  9136. foreach (Control c in groupBox29.Controls)
  9137. {
  9138. if (c is CheckBox)
  9139. c.Enabled = false;
  9140. }
  9141. ReadLockStatus = !ReadLockStatus;
  9142. }
  9143. }
  9144. private void 屏幕键盘ToolStripMenuItem_Click(object sender, EventArgs e)
  9145. {
  9146. System.Diagnostics.Process.Start("osk.exe");
  9147. }
  9148. private void checkBox_OffLineCheckMode_CheckedChanged(object sender, EventArgs e)
  9149. {
  9150. comboBox_CheckModeCfgDate.SelectedIndex = -1;
  9151. comboBox_CheckModeCfgFile.SelectedIndex = -1;
  9152. checkBox_OffLineFacMode.Checked = checkBox_OffLineCheckMode.Checked;
  9153. }
  9154. private void checkBox_OffLineFacMode_CheckedChanged(object sender, EventArgs e)
  9155. {
  9156. comboBox_FacModeCfgDate.SelectedIndex = -1;
  9157. comboBox_FacModeCfgFile.SelectedIndex = -1;
  9158. checkBox_OffLineCheckMode.Checked = checkBox_OffLineFacMode.Checked;
  9159. }
  9160. private void 版本ToolStripMenuItem_Click(object sender, EventArgs e)
  9161. {
  9162. VersionForm.ShowDialog();
  9163. }
  9164. private void button_MOS_Cal_Click(object sender, EventArgs e)
  9165. {
  9166. textBox_MOS_R1.Text = "";
  9167. textBox_MOS_R2.Text = "";
  9168. textBox_MOS_R3.Text = "";
  9169. try
  9170. {
  9171. var Code = new byte[18];
  9172. for (int i = 0; i < 18; i++)
  9173. Code[i] = 0;
  9174. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  9175. ushort uwDataTemp = 0;
  9176. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  9177. Code[2] = (byte)(uwDataTemp & 0xFF);
  9178. Code[3] = (byte)(uwDataTemp >> 8);
  9179. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  9180. Code[4] = (byte)(uwDataTemp & 0xFF);
  9181. Code[5] = (byte)(uwDataTemp >> 8);
  9182. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  9183. Code[6] = (byte)(uwDataTemp & 0xFF);
  9184. Code[7] = (byte)(uwDataTemp >> 8);
  9185. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  9186. Code[8] = (byte)(uwDataTemp & 0xFF);
  9187. Code[9] = (byte)(uwDataTemp >> 8);
  9188. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  9189. Code[10] = (byte)(uwDataTemp & 0xFF);
  9190. Code[11] = (byte)(uwDataTemp >> 8);
  9191. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  9192. }
  9193. catch (Exception)
  9194. {
  9195. MessageBox.Show("系数填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9196. }
  9197. }
  9198. private void button_MOS_Read_Click(object sender, EventArgs e)
  9199. {
  9200. foreach (Control c in groupBox21.Controls)
  9201. {
  9202. if (c is TextBox)
  9203. c.Text = "";
  9204. }
  9205. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  9206. }
  9207. private void button_MOS_Write_Click(object sender, EventArgs e)
  9208. {
  9209. try
  9210. {
  9211. var Code = new byte[34];
  9212. for (int i = 0; i < 34; i++)
  9213. Code[i] = 0;
  9214. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  9215. ushort uwDataTemp = 0;
  9216. uwDataTemp = Convert.ToUInt16(textBox_MOS_R1.Text);
  9217. Code[2] = (byte)(uwDataTemp & 0xFF);
  9218. Code[3] = (byte)(uwDataTemp >> 8);
  9219. uwDataTemp = Convert.ToUInt16(textBox_MOS_R2.Text);
  9220. Code[4] = (byte)(uwDataTemp & 0xFF);
  9221. Code[5] = (byte)(uwDataTemp >> 8);
  9222. uwDataTemp = Convert.ToUInt16(textBox_MOS_R3.Text);
  9223. Code[6] = (byte)(uwDataTemp & 0xFF);
  9224. Code[7] = (byte)(uwDataTemp >> 8);
  9225. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  9226. Code[8] = (byte)(uwDataTemp & 0xFF);
  9227. Code[9] = (byte)(uwDataTemp >> 8);
  9228. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  9229. Code[10] = (byte)(uwDataTemp & 0xFF);
  9230. Code[11] = (byte)(uwDataTemp >> 8);
  9231. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  9232. Code[12] = (byte)(uwDataTemp & 0xFF);
  9233. Code[13] = (byte)(uwDataTemp >> 8);
  9234. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  9235. Code[14] = (byte)(uwDataTemp & 0xFF);
  9236. Code[15] = (byte)(uwDataTemp >> 8);
  9237. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  9238. Code[16] = (byte)(uwDataTemp & 0xFF);
  9239. Code[17] = (byte)(uwDataTemp >> 8);
  9240. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4C22, Code);
  9241. }
  9242. catch (Exception)
  9243. {
  9244. MessageBox.Show("数据填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9245. }
  9246. }
  9247. /// <summary>
  9248. /// 测试模式点击文本框自动全选
  9249. /// </summary>
  9250. /// <param name="sender"></param>
  9251. /// <param name="e"></param>
  9252. private void textBox_FacModeScan_MouseClick(object sender, MouseEventArgs e)
  9253. {
  9254. textBox_FacModeScan.SelectAll();
  9255. }
  9256. /// <summary>
  9257. /// 检验模式点击文本框自动全选
  9258. /// </summary>
  9259. /// <param name="sender"></param>
  9260. /// <param name="e"></param>
  9261. private void textBox_CheckModeScan_MouseClick(object sender, MouseEventArgs e)
  9262. {
  9263. textBox_CheckModeScan.SelectAll();
  9264. }
  9265. /// <summary>
  9266. /// 鼠标放置显示连接服务器信息
  9267. /// </summary>
  9268. /// <param name="sender"></param>
  9269. /// <param name="e"></param>
  9270. private void label_ServerStatus_MouseHover(object sender, EventArgs e)
  9271. {
  9272. // 创建the ToolTip
  9273. ToolTip toolTip1 = new ToolTip();
  9274. // 设置显示样式
  9275. toolTip1.AutoPopDelay = 30000;//提示信息的可见时间
  9276. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  9277. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  9278. toolTip1.ShowAlways = true;//是否显示提示框
  9279. if (myFtp.IsNetConnected)
  9280. {
  9281. toolTip1.SetToolTip(this.label_ServerStatus, "IP: " + ServerIP);//设置故障内容显示
  9282. }
  9283. else
  9284. {
  9285. toolTip1.SetToolTip(this.label_ServerStatus, "网络断开");//设置故障内容显示
  9286. }
  9287. }
  9288. /// <summary>
  9289. /// UART协议类型修改
  9290. /// </summary>
  9291. /// <param name="sender"></param>
  9292. /// <param name="e"></param>
  9293. private void 协议类型ToolStripMenuItem_SelectedIndexChanged(object sender, EventArgs e)
  9294. {
  9295. var Code = new byte[2];
  9296. Code[0] = (byte)协议类型ToolStripMenuItem.SelectedIndex;
  9297. Code[1] = 0x00;
  9298. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  9299. }
  9300. /// <summary>
  9301. /// 显示本机信息
  9302. /// </summary>
  9303. /// <param name="sender"></param>
  9304. /// <param name="e"></param>
  9305. private void 本机信息ToolStripMenuItem_Click(object sender, EventArgs e)
  9306. {
  9307. MessageBox.Show(Local_HdInformation, "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
  9308. }
  9309. /// <summary>
  9310. /// 量产模式删除当前选中文件
  9311. /// </summary>
  9312. /// <param name="sender"></param>
  9313. /// <param name="e"></param>
  9314. private void label112_DoubleClick(object sender, EventArgs e)
  9315. {
  9316. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9317. {
  9318. EnterForm1.ShowDialog();
  9319. try
  9320. {
  9321. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9322. {
  9323. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  9324. {
  9325. try
  9326. {
  9327. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + comboBox_FacModeCfgFile.Text);
  9328. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_FacModeCfgFile.Text) + ".src");
  9329. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_FacModeCfgFile.Text) + ".png");
  9330. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9331. }
  9332. catch (Exception)
  9333. {
  9334. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9335. }
  9336. }
  9337. else
  9338. {
  9339. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9340. }
  9341. }
  9342. }
  9343. catch (Exception)
  9344. {
  9345. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9346. }
  9347. }
  9348. }
  9349. /// <summary>
  9350. /// 检验模式删除当前选中文件
  9351. /// </summary>
  9352. /// <param name="sender"></param>
  9353. /// <param name="e"></param>
  9354. private void label138_DoubleClick(object sender, EventArgs e)
  9355. {
  9356. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9357. {
  9358. EnterForm1.ShowDialog();
  9359. try
  9360. {
  9361. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9362. {
  9363. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  9364. {
  9365. try
  9366. {
  9367. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + comboBox_CheckModeCfgFile.Text);
  9368. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_CheckModeCfgFile.Text) + ".src");
  9369. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_CheckModeCfgFile.Text) + ".png");
  9370. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9371. }
  9372. catch (Exception)
  9373. {
  9374. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9375. }
  9376. }
  9377. else
  9378. {
  9379. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9380. }
  9381. }
  9382. }
  9383. catch (Exception)
  9384. {
  9385. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9386. }
  9387. }
  9388. }
  9389. /// <summary>
  9390. /// 读取整车信息2
  9391. /// </summary>
  9392. /// <param name="sender"></param>
  9393. /// <param name="e"></param>
  9394. private void button_ReadBikeParam2_Click(object sender, EventArgs e)
  9395. {
  9396. richTextBox_BikeParam2.Clear();
  9397. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null);
  9398. }
  9399. /// <summary>
  9400. /// 写入整车信息2
  9401. /// </summary>
  9402. /// <param name="sender"></param>
  9403. /// <param name="e"></param>
  9404. private void button_WriteBikeParam2_Click(object sender, EventArgs e)
  9405. {
  9406. var ConfigParam = new byte[34];
  9407. for (int i = 0; i < 34; i++)
  9408. ConfigParam[i] = 0;
  9409. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  9410. string[] strDataTemp = richTextBox_BikeParam2.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  9411. try
  9412. {
  9413. for (int i = 0; i < strDataTemp.Length; i++)
  9414. {
  9415. short wDataTemp = 0;
  9416. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  9417. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  9418. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  9419. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  9420. }
  9421. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4D22, ConfigParam);
  9422. }
  9423. catch (Exception)
  9424. {
  9425. timer_500ms.Enabled = false;
  9426. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9427. timer_500ms.Enabled = true;
  9428. }
  9429. }
  9430. /// <summary>
  9431. /// 读取用户骑行参数
  9432. /// </summary>
  9433. /// <param name="sender"></param>
  9434. /// <param name="e"></param>
  9435. private void button_ReadUsrRideParam_Click(object sender, EventArgs e)
  9436. {
  9437. richTextBox_UsrRidesParam.Clear();
  9438. if (checkBox_UserRideParam_OBC.Checked)
  9439. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x4300, null);
  9440. else
  9441. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  9442. }
  9443. /// <summary>
  9444. /// 写入用户骑行参数
  9445. /// </summary>
  9446. /// <param name="sender"></param>
  9447. /// <param name="e"></param>
  9448. private void button_WriteUsrRidetParam_Click(object sender, EventArgs e)
  9449. {
  9450. var ConfigParam = new byte[34];
  9451. for (int i = 0; i < 34; i++)
  9452. ConfigParam[i] = 0;
  9453. if (checkBox_UserRideParam_OBC.Checked)
  9454. {
  9455. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  9456. string[] strDataTemp = richTextBox_UsrRidesParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  9457. try
  9458. {
  9459. for (int i = 0; i < strDataTemp.Length; i++)
  9460. {
  9461. ConfigParam[i + 2] = Convert.ToByte(strDataTemp[i].Split('=')[1]);
  9462. }
  9463. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4B22, ConfigParam);
  9464. }
  9465. catch (Exception)
  9466. {
  9467. timer_500ms.Enabled = false;
  9468. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9469. timer_500ms.Enabled = true;
  9470. }
  9471. }
  9472. else
  9473. {
  9474. string[] strDataTemp = richTextBox_UsrRidesParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  9475. try
  9476. {
  9477. for (int i = 0; i < strDataTemp.Length; i++)
  9478. {
  9479. ConfigParam[i] = Convert.ToByte(strDataTemp[i].Split('=')[1]);
  9480. }
  9481. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x4420, ConfigParam);
  9482. }
  9483. catch (Exception)
  9484. {
  9485. timer_500ms.Enabled = false;
  9486. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9487. timer_500ms.Enabled = true;
  9488. }
  9489. }
  9490. }
  9491. /// <summary>
  9492. /// 读取产品标签
  9493. /// </summary>
  9494. /// <param name="sender"></param>
  9495. /// <param name="e"></param>
  9496. private void button_ReadTag_Click(object sender, EventArgs e)
  9497. {
  9498. textBox_TagInfo.Text = "---";
  9499. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4E00, null);
  9500. }
  9501. /// <summary>
  9502. /// 写入产品标签
  9503. /// </summary>
  9504. /// <param name="sender"></param>
  9505. /// <param name="e"></param>
  9506. private void button_WriteTag_Click(object sender, EventArgs e)
  9507. {
  9508. string User = textBox_TagInfo.Text;
  9509. var UserArray = new byte[32];
  9510. for (ushort i = 0; i < User.Length; i++)
  9511. {
  9512. UserArray[i] = (byte)User[i];
  9513. }
  9514. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D20, UserArray);
  9515. }
  9516. /// <summary>
  9517. /// 上位机读取骑行历史
  9518. /// </summary>
  9519. /// <param name="sender"></param>
  9520. /// <param name="e"></param>
  9521. private void button_ReadRideLog_Click(object sender, EventArgs e)
  9522. {
  9523. textBox_ODO_KM.Text = "---";
  9524. textBox_ODO_TIME.Text = "---";
  9525. textBox_TRIP_KM.Text = "---";
  9526. textBox_TRIP_TIME.Text = "---";
  9527. textBox_OBC_TRIP_KM.Text = "";
  9528. textBox_OBC_TRIP_TIME.Text = "";
  9529. textBox_OBC_ODO_KM.Text = "";
  9530. textBox_OBC_ODO_TIME.Text = "";
  9531. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2E00, null);
  9532. }
  9533. /// <summary>
  9534. /// 上位机写入骑行历史
  9535. /// </summary>
  9536. /// <param name="sender"></param>
  9537. /// <param name="e"></param>
  9538. private void button_WriteRideLog_Click(object sender, EventArgs e)
  9539. {
  9540. UInt32 Data;
  9541. var UserArray = new byte[16];
  9542. try
  9543. {
  9544. Data = Convert.ToUInt32(textBox_ODO_KM.Text);
  9545. UserArray[0] = (byte)(Data & 0xFF);
  9546. UserArray[1] = (byte)(Data >> 8);
  9547. UserArray[2] = (byte)(Data >> 16);
  9548. UserArray[3] = (byte)(Data >> 24);
  9549. Data = Convert.ToUInt32(textBox_ODO_TIME.Text);
  9550. UserArray[4] = (byte)(Data & 0xFF);
  9551. UserArray[5] = (byte)(Data >> 8);
  9552. UserArray[6] = (byte)(Data >> 16);
  9553. UserArray[7] = (byte)(Data >> 24);
  9554. Data = Convert.ToUInt32(textBox_TRIP_KM.Text);
  9555. UserArray[8] = (byte)(Data & 0xFF);
  9556. UserArray[9] = (byte)(Data >> 8);
  9557. UserArray[10] = (byte)(Data >> 16);
  9558. UserArray[11] = (byte)(Data >> 24);
  9559. Data = Convert.ToUInt32(textBox_TRIP_TIME.Text);
  9560. UserArray[12] = (byte)(Data & 0xFF);
  9561. UserArray[13] = (byte)(Data >> 8);
  9562. UserArray[14] = (byte)(Data >> 16);
  9563. UserArray[15] = (byte)(Data >> 24);
  9564. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B10, UserArray);
  9565. }
  9566. catch (Exception ex)
  9567. {
  9568. MessageBox.Show("数据格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9569. }
  9570. }
  9571. /// <summary>
  9572. /// 获取删除配置文件日期列表
  9573. /// </summary>
  9574. /// <param name="sender"></param>
  9575. /// <param name="e"></param>
  9576. private void toolStripTextBox_DelCfgFile_Click(object sender, EventArgs e)
  9577. {
  9578. string[] DateList = { "" };
  9579. //网络断开时直接退出
  9580. if (!myFtp.IsNetConnected)
  9581. return;
  9582. //从服务器更新日期列表
  9583. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
  9584. toolStripTextBox_DelCfgFile.Items.Clear();
  9585. //日期列表加载,显示最近30条
  9586. if (DateList.Length > 30)
  9587. {
  9588. toolStripTextBox_DelCfgFile.Items.Add("支持最近30条");
  9589. toolStripTextBox_DelCfgFile.Items.Add("-----");
  9590. }
  9591. for (int i = (DateList.Length > 30) ? (DateList.Length - 30) : 0; i < DateList.Length; i++)//显示最近30个日期
  9592. {
  9593. toolStripTextBox_DelCfgFile.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  9594. }
  9595. }
  9596. /// <summary>
  9597. /// 删除指定配置文件
  9598. /// </summary>
  9599. /// <param name="sender"></param>
  9600. /// <param name="e"></param>
  9601. private void toolStripTextBox_DelCfgFile_SelectedIndexChanged(object sender, EventArgs e)
  9602. {
  9603. //提示输入文件名
  9604. Scan scan_form = new Scan();
  9605. scan_form.ShowDialog();
  9606. do
  9607. {
  9608. if (scan_form.textBox_Scan.Text == string.Empty)
  9609. {
  9610. timer_500ms.Enabled = false;
  9611. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9612. timer_500ms.Enabled = true;
  9613. break;
  9614. }
  9615. string DelFile = scan_form.textBox_Scan.Text;
  9616. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9617. {
  9618. EnterForm1.ShowDialog();
  9619. try
  9620. {
  9621. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9622. {
  9623. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  9624. {
  9625. try
  9626. {
  9627. if (DelFile.Contains("."))
  9628. DelFile = Path.GetFileNameWithoutExtension(DelFile);
  9629. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".ttcfg");
  9630. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".src");
  9631. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".png");
  9632. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9633. }
  9634. catch (Exception)
  9635. {
  9636. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9637. }
  9638. }
  9639. else
  9640. {
  9641. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9642. }
  9643. }
  9644. }
  9645. catch (Exception)
  9646. {
  9647. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9648. }
  9649. }
  9650. } while (false);
  9651. }
  9652. /// <summary>
  9653. /// 获取删除样机测试记录日期列表
  9654. /// </summary>
  9655. /// <param name="sender"></param>
  9656. /// <param name="e"></param>
  9657. private void toolStripTextBox_DelLogFile_Click(object sender, EventArgs e)
  9658. {
  9659. string[] DateList = { "" };
  9660. //网络断开时直接退出
  9661. if (!myFtp.IsNetConnected)
  9662. return;
  9663. //从服务器更新日期列表
  9664. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName);
  9665. toolStripTextBox_DelLogFile.Items.Clear();
  9666. //日期列表加载,显示最近30天
  9667. if (DateList.Length > 30)
  9668. {
  9669. toolStripTextBox_DelLogFile.Items.Add("支持最近30条");
  9670. toolStripTextBox_DelLogFile.Items.Add("-----");
  9671. }
  9672. for (int i = (DateList.Length > 30) ? (DateList.Length - 30) : 0; i < DateList.Length; i++)//显示最近30个日期
  9673. {
  9674. toolStripTextBox_DelLogFile.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  9675. }
  9676. }
  9677. /// <summary>
  9678. /// 删除指定的样机测试记录
  9679. /// </summary>
  9680. /// <param name="sender"></param>
  9681. /// <param name="e"></param>
  9682. private void toolStripTextBox_DelLogFile_SelectedIndexChanged(object sender, EventArgs e)
  9683. {
  9684. //提示输入文件名
  9685. Scan scan_form = new Scan();
  9686. scan_form.ShowDialog();
  9687. do
  9688. {
  9689. if (scan_form.textBox_Scan.Text == string.Empty)
  9690. {
  9691. timer_500ms.Enabled = false;
  9692. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9693. timer_500ms.Enabled = true;
  9694. break;
  9695. }
  9696. string DelFile = scan_form.textBox_Scan.Text;
  9697. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9698. {
  9699. EnterForm1.ShowDialog();
  9700. try
  9701. {
  9702. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9703. {
  9704. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  9705. {
  9706. try
  9707. {
  9708. //删除指定目录下面所有文件和文件夹
  9709. myFtp.DelDirectoryWithAll(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName + "\\" + toolStripTextBox_DelLogFile.Text + "\\" + DelFile);
  9710. myFtp.RemoveDirectory(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName + "\\" + toolStripTextBox_DelLogFile.Text + "\\" + DelFile);
  9711. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9712. }
  9713. catch (Exception)
  9714. {
  9715. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9716. }
  9717. }
  9718. else
  9719. {
  9720. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9721. }
  9722. }
  9723. }
  9724. catch (Exception)
  9725. {
  9726. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9727. }
  9728. }
  9729. } while (false);
  9730. }
  9731. /// <summary>
  9732. /// CAN协议选择
  9733. /// </summary>
  9734. /// <param name="sender"></param>
  9735. /// <param name="e"></param>
  9736. private void cANToolStripMenuItem_Click(object sender, EventArgs e)
  9737. {
  9738. cANToolStripMenuItem.Checked= true;
  9739. uARTToolStripMenuItem.Checked = false;
  9740. UART协议ToolStripMenuItem.Visible = false;
  9741. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9742. }
  9743. /// <summary>
  9744. /// UART协议选择
  9745. /// </summary>
  9746. /// <param name="sender"></param>
  9747. /// <param name="e"></param>
  9748. private void uARTToolStripMenuItem_Click(object sender, EventArgs e)
  9749. {
  9750. cANToolStripMenuItem.Checked = false;
  9751. uARTToolStripMenuItem.Checked = true;
  9752. UART协议ToolStripMenuItem.Visible = true;
  9753. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9754. }
  9755. /// <summary>
  9756. /// 清除流水号
  9757. /// </summary>
  9758. /// <param name="sender"></param>
  9759. /// <param name="e"></param>
  9760. private void label131_DoubleClick(object sender, EventArgs e)
  9761. {
  9762. if (MessageBox.Show("确认清零流水号?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9763. {
  9764. label_FacModeSerial.Text = "0";
  9765. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, label_FacModeSerial.Text);
  9766. }
  9767. }
  9768. /// <summary>
  9769. /// 清除流水号
  9770. /// </summary>
  9771. /// <param name="sender"></param>
  9772. /// <param name="e"></param>
  9773. private void label135_DoubleClick(object sender, EventArgs e)
  9774. {
  9775. if (MessageBox.Show("确认清零流水号?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9776. {
  9777. label_CheckModeSerial.Text = "0";
  9778. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, label_CheckModeSerial.Text);
  9779. }
  9780. }
  9781. /// <summary>
  9782. /// 打开自动更新
  9783. /// </summary>
  9784. /// <param name="sender"></param>
  9785. /// <param name="e"></param>
  9786. private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
  9787. {
  9788. 打开ToolStripMenuItem.Checked = true;
  9789. 关闭ToolStripMenuItem.Checked = false;
  9790. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9791. }
  9792. /// <summary>
  9793. /// 关闭自动更新
  9794. /// </summary>
  9795. /// <param name="sender"></param>
  9796. /// <param name="e"></param>
  9797. private void 关闭ToolStripMenuItem_Click(object sender, EventArgs e)
  9798. {
  9799. 打开ToolStripMenuItem.Checked = false;
  9800. 关闭ToolStripMenuItem.Checked = true;
  9801. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9802. }
  9803. /// <summary>
  9804. /// 显示完整配置文件
  9805. /// </summary>
  9806. /// <param name="sender"></param>
  9807. /// <param name="e"></param>
  9808. private void comboBox_FacModeCfgFile_MouseHover_1(object sender, EventArgs e)
  9809. {
  9810. // 创建the ToolTip
  9811. ToolTip toolTip1 = new ToolTip();
  9812. // 设置显示样式
  9813. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  9814. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  9815. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  9816. toolTip1.ShowAlways = true;//是否显示提示框
  9817. // 设置伴随的对象.
  9818. toolTip1.SetToolTip(this.comboBox_FacModeCfgFile, comboBox_FacModeCfgFile.Text);//设置故障内容显示
  9819. }
  9820. /// <summary>
  9821. /// 显示完整配置文件
  9822. /// </summary>
  9823. /// <param name="sender"></param>
  9824. /// <param name="e"></param>
  9825. private void comboBox_CheckModeCfgFile_MouseHover_1(object sender, EventArgs e)
  9826. {
  9827. // 创建the ToolTip
  9828. ToolTip toolTip1 = new ToolTip();
  9829. // 设置显示样式
  9830. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  9831. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  9832. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  9833. toolTip1.ShowAlways = true;//是否显示提示框
  9834. // 设置伴随的对象.
  9835. toolTip1.SetToolTip(this.comboBox_CheckModeCfgFile, comboBox_CheckModeCfgFile.Text);//设置故障内容显示
  9836. }
  9837. /// <summary>
  9838. /// 手动发送指令
  9839. /// </summary>
  9840. /// <param name="sender"></param>
  9841. /// <param name="e"></param>
  9842. private void 发送指令ToolStripMenuItem_Click(object sender, EventArgs e)
  9843. {
  9844. //提示
  9845. Scan scan_form = new Scan();
  9846. scan_form.label1.Text = "按照16进制填写,相邻字节用空格隔开,依次填写ID、Mode、Cmd、Data\r\n例如:07 31 16 22 05 01 02 03 04 05";
  9847. scan_form.ShowDialog();
  9848. //发送写入的指令,填写ID、类型、命令字、数据
  9849. do
  9850. {
  9851. if (scan_form.textBox_Scan.Text == string.Empty)
  9852. {
  9853. timer_500ms.Enabled = false;
  9854. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9855. timer_500ms.Enabled = true;
  9856. break;
  9857. }
  9858. //输入文本转换为字节流
  9859. var InputData = new byte[256];
  9860. InputData = mySerialProcess.HexStringToBytes(scan_form.textBox_Scan.Text, true);
  9861. //ID
  9862. ushort ID;
  9863. ID = (ushort)((InputData[0] << 8) + InputData[1]);
  9864. //Mode
  9865. byte Mode;
  9866. Mode = InputData[2];
  9867. //Cmd
  9868. ushort Cmd;
  9869. Cmd = (ushort)((InputData[3] << 8) + InputData[4]);
  9870. //Data
  9871. var Data = new byte[Cmd & 0x00FF];
  9872. for (int i = 0; i < (Cmd & 0x00FF); i++)
  9873. Data[i] = InputData[5 + i];
  9874. //发送数据
  9875. mySerialProcess.SendCmdWithoutNotice(ID, Mode, Cmd, Data);
  9876. } while (false);
  9877. }
  9878. /// <summary>
  9879. /// 启动位置传感器校准
  9880. /// </summary>
  9881. /// <param name="sender"></param>
  9882. /// <param name="e"></param>
  9883. private void button_AngleCalStart_Click(object sender, EventArgs e)
  9884. {
  9885. for (int i = 0; i < 7; i++)
  9886. for (int j = 0; j < 6; j++)
  9887. {
  9888. dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = "";
  9889. }
  9890. foreach (Control cr in tabPage_AngleCal.Controls)
  9891. {
  9892. if (cr is TextBox)
  9893. {
  9894. if ((cr != textBox_AngleDiffTh) && (cr != textBox_AngleZeroTh))
  9895. cr.Text = "";
  9896. }
  9897. }
  9898. var Data = new byte[2];
  9899. mySerialProcess.SendCmd((ushort)0x751, (byte)0x0C, (ushort)0x5002, Data);
  9900. }
  9901. /// <summary>
  9902. /// 导出位置传感器校准数据
  9903. /// </summary>
  9904. /// <param name="sender"></param>
  9905. /// <param name="e"></param>
  9906. private void button_AngleExportData_Click(object sender, EventArgs e)
  9907. {
  9908. //读出产品信息
  9909. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  9910. Delay_ms(200);
  9911. SaveFileDialog sfd = new SaveFileDialog
  9912. {
  9913. FileName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + "位置传感器角度数据_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt",
  9914. Filter = "文本文档(*.txt)|*.txt",
  9915. Title = "Save"
  9916. };
  9917. if (sfd.ShowDialog() != DialogResult.OK)
  9918. {
  9919. return;
  9920. }
  9921. string filepath = sfd.FileName;
  9922. FileStream fs = new FileStream(filepath, FileMode.OpenOrCreate);
  9923. using (StreamWriter sw = new StreamWriter(fs))
  9924. {
  9925. sw.Write("标准值 ");
  9926. sw.Write("60.00 ");
  9927. sw.Write("120.00 ");
  9928. sw.Write("180.00 ");
  9929. sw.Write("240.00 ");
  9930. sw.Write("300.00 ");
  9931. sw.Write("360.00 ");
  9932. for (int i = 0; i < 42; i++)
  9933. {
  9934. if ((i % 6 == 0))
  9935. {
  9936. sw.Write("\r\n" + "采集值" + (i / 6 + 1).ToString() + " ");
  9937. }
  9938. sw.Write(AngledataRecord[i] + " ");
  9939. }
  9940. sw.Write("\r\n" + "历史零点位置 " + textBox_AngleZeroInit.Text);
  9941. sw.Write("\r\n" + "当前零点位置 " + textBox_AngleZeroCur.Text);
  9942. sw.Write("\r\n" + "零点误差 " + textBox_AngleZeroDiff.Text);
  9943. sw.Write("\r\n" + "最小偏差值 " + textBox_AngleDiffMin.Text);
  9944. sw.Write("\r\n" + "最大偏差值 " + textBox_AngleDiffMax.Text);
  9945. sw.Write("\r\n" + "平均偏差值 " + textBox_AngleDiffAvg.Text);
  9946. sw.Flush();
  9947. }
  9948. fs.Close();
  9949. }
  9950. /// <summary>
  9951. /// 写入校准数据
  9952. /// </summary>
  9953. /// <param name="sender"></param>
  9954. /// <param name="e"></param>
  9955. private void button_AngleWrite_Click(object sender, EventArgs e)
  9956. {
  9957. if ((textBox_AngleDiffAvg.Text == "") || (textBox_AngleZeroInit.Text == ""))
  9958. {
  9959. timer_500ms.Enabled = false;
  9960. MessageBox.Show("请先启动校准,以确认校准数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9961. timer_500ms.Enabled = true;
  9962. return;
  9963. }
  9964. timer_500ms.Enabled = false;
  9965. string str1 = "确认校准数据,历史零点: " + textBox_AngleZeroInit.Text + ", 偏差平均值: " + textBox_AngleDiffAvg.Text;
  9966. if (MessageBox.Show(str1, "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9967. {
  9968. var SaveFlag = new byte[4];
  9969. for (int i = 0; i < 4; i++)
  9970. SaveFlag[i] = 0;
  9971. SaveFlag[0] = (byte)(1);
  9972. double data1 = Convert.ToDouble(textBox_AngleZeroInit.Text) - Convert.ToDouble(textBox_AngleDiffAvg.Text);
  9973. if (data1 > 360)
  9974. {
  9975. data1 -= 360;
  9976. }
  9977. else if (data1 < -360)
  9978. {
  9979. data1 += 360;
  9980. }
  9981. Int16 data2 = (Int16)(data1 * 32768 / 360);
  9982. SaveFlag[2] = (byte)(data2);
  9983. SaveFlag[3] = (byte)(data2 >> 8);
  9984. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, SaveFlag);
  9985. timer_500ms.Enabled = true;
  9986. }
  9987. else
  9988. {
  9989. timer_500ms.Enabled = true;
  9990. MessageBoxTimeOut.Show("写入取消", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9991. }
  9992. }
  9993. /// <summary>
  9994. /// 存储允许偏差
  9995. /// </summary>
  9996. /// <param name="sender"></param>
  9997. /// <param name="e"></param>
  9998. private void textBox_AngleDiffTh_KeyDown(object sender, KeyEventArgs e)
  9999. {
  10000. if (e.KeyCode == Keys.Enter)
  10001. {
  10002. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  10003. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  10004. }
  10005. }
  10006. /// <summary>
  10007. /// 存储零点允许偏差
  10008. /// </summary>
  10009. /// <param name="sender"></param>
  10010. /// <param name="e"></param>
  10011. private void textBox_AngleZeroTh_KeyDown(object sender, KeyEventArgs e)
  10012. {
  10013. if (e.KeyCode == Keys.Enter)
  10014. {
  10015. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  10016. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  10017. }
  10018. }
  10019. /// <summary>
  10020. /// 删除服务器配置文件
  10021. /// </summary>
  10022. /// <param name="sender"></param>
  10023. /// <param name="e"></param>
  10024. private void 重置ToolStripMenuItem_Click(object sender, EventArgs e)
  10025. {
  10026. if (MessageBox.Show("重置后软件自动关闭,确认重置?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  10027. {
  10028. if(File.Exists(localInfo.LocalPath + localInfo.ServerCfgFileName))
  10029. File.Delete(localInfo.LocalPath + localInfo.ServerCfgFileName);
  10030. if(File.Exists(localInfo.LocalPath + localInfo.ConfigFileName))
  10031. File.Delete(localInfo.LocalPath + localInfo.ConfigFileName);
  10032. System.Environment.Exit(0);
  10033. }
  10034. }
  10035. /// <summary>
  10036. /// 按下Enter保存数据
  10037. /// </summary>
  10038. /// <param name="sender"></param>
  10039. /// <param name="e"></param>
  10040. private void toolStripTextBox_AngleAvgMax_KeyDown(object sender, KeyEventArgs e)
  10041. {
  10042. textBox_AngleDiffTh.Text = toolStripTextBox_AngleAvgMax.Text;
  10043. if (e.KeyCode == Keys.Enter)
  10044. {
  10045. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  10046. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  10047. }
  10048. }
  10049. /// <summary>
  10050. /// 按下Enter保存数据
  10051. /// </summary>
  10052. /// <param name="sender"></param>
  10053. /// <param name="e"></param>
  10054. private void toolStripTextBox_AngleZeroMax_KeyDown(object sender, KeyEventArgs e)
  10055. {
  10056. textBox_AngleZeroTh.Text = toolStripTextBox_AngleZeroMax.Text;
  10057. if (e.KeyCode == Keys.Enter)
  10058. {
  10059. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  10060. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  10061. }
  10062. }
  10063. private void 帮助ToolStripMenuItem_Click(object sender, EventArgs e)
  10064. {
  10065. //检查本地文件
  10066. if (!File.Exists(localInfo.LocalPath + localInfo.HelpFilename))
  10067. {
  10068. if (!OfflineFlag)
  10069. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/help/" + localInfo.HelpFilename, localInfo.LocalPath);
  10070. else
  10071. {
  10072. MessageBoxTimeOut.Show("未找到帮助文件!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10073. return;
  10074. }
  10075. }
  10076. //调用本地浏览器打开帮助文件
  10077. System.Diagnostics.Process.Start("explorer", localInfo.LocalPath + localInfo.HelpFilename);
  10078. }
  10079. /// <summary>
  10080. /// 读取故障日志地址
  10081. /// </summary>
  10082. /// <param name="sender"></param>
  10083. /// <param name="e"></param>
  10084. private void button_ReadLogAddr_Click(object sender, EventArgs e)
  10085. {
  10086. textBox_LogAddrBegin.Text = "";
  10087. textBox_LogAddrEnd.Text = "";
  10088. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x5200, null);
  10089. }
  10090. /// <summary>
  10091. /// 写入硬件版本
  10092. /// </summary>
  10093. /// <param name="sender"></param>
  10094. /// <param name="e"></param>
  10095. private void button_WriteHW_Click(object sender, EventArgs e)
  10096. {
  10097. string HW = textBox_HW.Text;
  10098. var HWArray = new byte[16];
  10099. for (ushort i = 0; i < HW.Length; i++)
  10100. {
  10101. HWArray[i] = (byte)HW[i];
  10102. }
  10103. if (HW.Length < 16)
  10104. {
  10105. HWArray[HW.Length] = (byte)'.';
  10106. for (ushort i = 0; i < 16 - HW.Length - 1; i++)
  10107. {
  10108. HWArray[HW.Length + 1 + i] = 0x20;
  10109. }
  10110. }
  10111. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5310, HWArray);
  10112. }
  10113. /// <summary>
  10114. /// 生产模式写入HW
  10115. /// </summary>
  10116. /// <param name="sender"></param>
  10117. /// <param name="e"></param>
  10118. private void Button_FacModeSetHW_Click(object sender, EventArgs e)
  10119. {
  10120. string HW = textBox_FacModeHW.Text;
  10121. var HWArray = new byte[16];
  10122. for (ushort i = 0; i < HW.Length; i++)
  10123. {
  10124. HWArray[i] = (byte)HW[i];
  10125. }
  10126. if (HW.Length < 16)
  10127. {
  10128. HWArray[HW.Length] = (byte)'.';
  10129. for (ushort i = 0; i < 16 - HW.Length - 1; i++)
  10130. {
  10131. HWArray[HW.Length + 1 + i] = 0x20;
  10132. }
  10133. }
  10134. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5310, HWArray);
  10135. }
  10136. /// <summary>
  10137. /// 读取定制编号
  10138. /// </summary>
  10139. /// <param name="sender"></param>
  10140. /// <param name="e"></param>
  10141. private void button_ReadUserNum_Click(object sender, EventArgs e)
  10142. {
  10143. textBox_UserNum.Text = "---";
  10144. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x5600, null);
  10145. }
  10146. /// <summary>
  10147. /// 写入定制编号
  10148. /// </summary>
  10149. /// <param name="sender"></param>
  10150. /// <param name="e"></param>
  10151. private void button_WriteUserNum_Click(object sender, EventArgs e)
  10152. {
  10153. string User = textBox_UserNum.Text;
  10154. var UserArray = new byte[32];
  10155. for (ushort i = 0; i < User.Length; i++)
  10156. {
  10157. UserArray[i] = (byte)User[i];
  10158. }
  10159. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5720, UserArray);
  10160. }
  10161. /// <summary>
  10162. /// 读取指定块拓展功能
  10163. /// </summary>
  10164. /// <param name="sender"></param>
  10165. /// <param name="e"></param>
  10166. private void button_FunSet_Read_Click(object sender, EventArgs e)
  10167. {
  10168. if (comboBox_FunSet_BlockNum.SelectedIndex < 0)
  10169. {
  10170. MessageBox.Show("请选择块编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10171. }
  10172. else
  10173. {
  10174. //清空当前内容
  10175. for (int i = 0; i < 8; i++)
  10176. for (int j = 0; j < 8; j++)
  10177. {
  10178. dataGridView_FunSet.Rows[i].Cells[j + 1].Value = "";
  10179. }
  10180. //发送读取指令
  10181. ushort Num = (ushort)(comboBox_FunSet_BlockNum.SelectedIndex + 1);
  10182. var Code = new byte[2];
  10183. Code[0] = (byte)(Num & 0xFF);
  10184. Code[1] = (byte)(Num >> 8);
  10185. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x5402, Code);
  10186. }
  10187. }
  10188. /// <summary>
  10189. /// 写入指定块或指定单元参数
  10190. /// </summary>
  10191. /// <param name="sender"></param>
  10192. /// <param name="e"></param>
  10193. private void button_FunSet_Write_Click(object sender, EventArgs e)
  10194. {
  10195. if (radioButton_WriteByBlock.Checked == true)
  10196. {
  10197. if (comboBox_FunSet_BlockNum.SelectedIndex < 0)
  10198. MessageBox.Show("请选择块编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10199. else
  10200. {
  10201. //开始按块写入
  10202. ushort Num = (ushort)(comboBox_FunSet_BlockNum.SelectedIndex + 1);
  10203. var Code = new byte[66];
  10204. Code[0] = (byte)(Num & 0xFF);
  10205. Code[1] = (byte)(Num >> 8);
  10206. for (int i = 0; i < 8; i++)
  10207. for (int j = 0; j < 8; j++)
  10208. {
  10209. try
  10210. {
  10211. byte Data = Convert.ToByte(dataGridView_FunSet.Rows[i].Cells[j + 1].Value);
  10212. Code[i * 8 + j + 2] = (byte)(Data & 0xFF);
  10213. }
  10214. catch (Exception)
  10215. {
  10216. MessageBox.Show("数据格式错误或超范围!\r\n" + "单元编号:" + (i + 1).ToString() + "\r\n" + "参数:" + (j + 1).ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10217. return;
  10218. }
  10219. }
  10220. if (MessageBox.Show("请核对块编号!\r\n" + "块编号:" + (Num).ToString(), "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  10221. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5542, Code);
  10222. else
  10223. MessageBoxTimeOut.Show("取消写入", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  10224. }
  10225. }
  10226. else if (radioButton_WriteByUnit.Checked == true)
  10227. {
  10228. if (comboBox_FunSet_BlockNum.SelectedIndex < 0)
  10229. MessageBox.Show("请选择块编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10230. else
  10231. {
  10232. if (comboBox_FunSet_UnitNum.SelectedIndex < 0)
  10233. MessageBox.Show("请选择单元编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10234. else
  10235. {
  10236. //开始按单元写入
  10237. ushort Num1 = (ushort)(comboBox_FunSet_BlockNum.SelectedIndex + 1);
  10238. ushort Num2 = (ushort)(comboBox_FunSet_UnitNum.SelectedIndex + 1);
  10239. var Code = new byte[12];
  10240. Code[0] = (byte)(Num1 & 0xFF);
  10241. Code[1] = (byte)(Num1 >> 8);
  10242. Code[2] = (byte)(Num2 & 0xFF);
  10243. Code[3] = (byte)(Num2 >> 8);
  10244. for (int i = 0; i < 8; i++)
  10245. {
  10246. try
  10247. {
  10248. byte Data = Convert.ToByte(dataGridView_FunSet.Rows[Num2 - 1].Cells[i + 1].Value);
  10249. Code[i + 4] = (byte)(Data & 0xFF);
  10250. }
  10251. catch (Exception)
  10252. {
  10253. MessageBox.Show("数据格式错误或超范围!\r\n" + "单元编号:" + Num2.ToString() + "\r\n" + "参数:" + (i + 1).ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10254. return;
  10255. }
  10256. }
  10257. if (MessageBox.Show("请核对块编号和单元编号!\r\n" + "块编号:" + Num1.ToString() + "\r\n" + "单元编号:" + Num2.ToString(), "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  10258. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x550C, Code);
  10259. else
  10260. MessageBoxTimeOut.Show("取消写入", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  10261. }
  10262. }
  10263. }
  10264. else
  10265. {
  10266. MessageBox.Show("请选择写入方式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10267. }
  10268. }
  10269. /// <summary>
  10270. /// 按块写入时隐藏单元编号
  10271. /// </summary>
  10272. /// <param name="sender"></param>
  10273. /// <param name="e"></param>
  10274. private void radioButton_WriteByUnit_CheckedChanged(object sender, EventArgs e)
  10275. {
  10276. if (radioButton_WriteByUnit.Checked == true)
  10277. {
  10278. label159.Visible = true;
  10279. comboBox_FunSet_UnitNum.Visible = true;
  10280. }
  10281. else
  10282. {
  10283. label159.Visible = false;
  10284. comboBox_FunSet_UnitNum.Visible = false;
  10285. }
  10286. }
  10287. /// <summary>
  10288. /// 打开或关闭指令窗口
  10289. /// </summary>
  10290. /// <param name="sender"></param>
  10291. /// <param name="e"></param>
  10292. private void 指令调试ToolStripMenuItem_Click(object sender, EventArgs e)
  10293. {
  10294. if (指令调试ToolStripMenuItem.Checked == false)
  10295. {
  10296. if (DebugForm.debug1 == null || DebugForm.debug1.IsDisposed)
  10297. {
  10298. DebugForm.debug1 = new DebugForm();
  10299. DebugForm.debug1.Show();
  10300. this.DebugWindowIsOpen = true;
  10301. }
  10302. else
  10303. {
  10304. DebugForm.debug1.Activate();
  10305. this.DebugWindowIsOpen = true;
  10306. }
  10307. 指令调试ToolStripMenuItem.Checked = true;
  10308. }
  10309. else
  10310. {
  10311. if (this.DebugWindowIsOpen == true)
  10312. {
  10313. DebugForm.debug1.Close();
  10314. this.DebugWindowIsOpen = false;
  10315. this.DebugDataDisplayEnable = false;
  10316. }
  10317. 指令调试ToolStripMenuItem.Checked = false;
  10318. }
  10319. }
  10320. }
  10321. }