123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145 |
- using NPOI.POIFS.Crypt.Dsig;
- using NPOI.SS.Formula.Functions;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Diagnostics.Eventing.Reader;
- using System.Drawing;
- using System.Globalization;
- using System.IO;
- using System.IO.Ports;
- using System.Linq;
- using System.Reflection;
- using System.Runtime.InteropServices;
- using System.Runtime.InteropServices.ComTypes;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading;
- using System.Web;
- using System.Windows.Forms;
- using System.Xml.Linq;
- using static NPOI.POIFS.Crypt.CryptoFunctions;
- namespace Welling_Motor_Debug_Tool
- {
- public partial class mainForm : Form
- {
- #region 变量定义
- //版本号
- public static string Version = "2.5.3";
- //串口实例
- Serial_Process mySerialProcess = new Serial_Process();
- string PortNumSave = "";
- string PortBaudrateSave = "";
- //本地信息定义
- LocalInfo localInfo = new LocalInfo();
- //FTP实例
- ftp myFtp = new ftp();
- public string ServerIP = "";
- public string ServerPort = "";
- public string ServerUser = "";
- public string ServerPassWd = "";
- public bool OfflineFlag = false;
- //MC运行信息超时计数
- bool MC_RunInfo_Refresh = false;
- ushort MC_RunInfo_Refresh_Cnt = 0;
- //MC调试信息超时计数
- bool MC_DebugInfo_Refresh = false;
- ushort MC_DebugInfo_Refresh_Cnt = 0;
- //MC故障码超时计数
- bool MC_ErrorCode_Refresh = false;
- ushort MC_ErrorCode_Refresh_Cnt = 0;
- //配置参数实例
- Params myParams = new Params();
- //记录文件名称
- string RunInfoSaveFilename = "";
- //BMS运行信息超时计数
- bool BMS_RunInfo_Refresh = false;
- ushort BMS_RunInfo_Refresh_Cnt = 0;
- //生产模式关机指令反馈状态
- bool PowerOffAckStatus = false;
- //登录窗口
- public static Login EnterForm1 = new Login();
- //生产配置文件信息
- ArrayList array_CfgInfo = new ArrayList();
- //写入参数返回标志和计数
- public bool WriteACK = false;
- public ushort ACK_WaitCnt = 0;
- //写入参数返回提示标志
- public bool ACK_DisFlag = true;
- //Boot版本信息
- public string BootInfo = "";
- //接收指令临时缓存,转string
- public string CmdRevStrTemp = "";
- //计时器,用于统计运行时间
- public Stopwatch stopwatch = new Stopwatch();
- //力矩传感器检验参数窗口
- public static TorqueParams TorqueParamsForm = new TorqueParams();
- //参数生成窗口
- public static GenerateParams GenerateParamsForm = new GenerateParams();
- //版本信息窗口
- public static Version VersionForm = new Version();
- //本机硬件信息
- public string Local_HdInformation = "";
- //指令窗口显示
- public bool DebugWindowIsOpen = false, DebugDataDisplayEnable = false;
- //位置传感器数据记录
- string[] AngledataRecord = new string[42];
- //服务器设置窗口
- public static ServerSelect ServerCfgForm1 = new ServerSelect();
- #endregion
- #region 故障日志结构体定义
- //故障日志记录信息 60 bytes,1K空间可以保存最近16条故障记录
- [StructLayout(LayoutKind.Sequential)]
- public struct MC_ErrorLogSaveInfo_Struct_t
- {
- public UInt16 Error_Index; //故障列表索引 2 bytes, 地址偏移 0
- public UInt16 NotesInfo1; //备注信息1,地址偏移 2
- public UInt16 NotesInfo2; //备注信息2,地址偏移 4
- public UInt16 NotesInfo3; //备注信息3,地址偏移 6
- public UInt32 ErrorCode; //故障码 4 bytes, 地址偏移 8
- public UInt32 RunTime; //运行时间 4bytes, 地址偏移 12
- //电机运行信息,占用空间32bytes
- [StructLayout(LayoutKind.Sequential)]
- public struct MC_RunInfo_Struct_t
- {
- public ushort BikeSpeed; //车速 0.1km/h,地址偏移0
- public ushort MotorSpeed; //输出转速 1rpm,地址偏移2
- public ushort Power; //电功率 1W,地址偏移4
- public ushort BusVoltage; //母线电压 1mV,地址偏移6
- public ushort BusCurrent; //母线电流 1mA,地址偏移8
- public byte Cadence; //踏频 1rpm,地址偏移10
- public byte Torque; //踩踏力矩 1Nm,地址偏移11
- public byte CadenceDir; //踩踏方向 0-正,1-反,2-停止,地址偏移12
- public byte GearSt; //助力档位,地址偏移13
- public byte LightSwitch; //灯开关 0xF0-关,0xF1-开,地址偏移14
- public byte SOC; //剩余电量 1%,地址偏移15
- public ushort RemainDistance; //续航里程 1km,地址偏移16
- public ushort Torque_AD; //力矩寄存器,地址偏移18
- public byte PowerPerKm; //平均功耗 0.01Ah/km ,地址偏移20
- public byte T_PCB; //PCB温度 +40℃,地址偏移21
- public byte T_Coil; //绕组温度 +40℃,地址偏移22
- public byte T_MCU; //MCU温度 +40℃,地址偏移23
- public ushort Ride_Km; //开机后骑行里程 0.1km, 地址偏移24
- public ushort Ride_Time; //开机后骑行时间 1s,地址偏移26
- public UInt32 RS; //预留 4bytes
- };
- [MarshalAs(UnmanagedType.Struct)]
- public MC_RunInfo_Struct_t RunInfo; //运行信息 32bytes, 地址偏移 16
- //控制变量
- public Int16 IqCurrent; //Pu, 地址偏移 48
- public Int16 IqVoltage; //Pu, 地址偏移 50
- public Int16 IdCurrent; //Pu, 地址偏移 52
- public Int16 IdVoltage; //Pu, 地址偏移 54
- //状态机
- public UInt16 FSM; //高到低依次表示系统状态机、二层状态机、电机状态机、助力状态机, 地址偏移 56
- //预留
- public UInt16 RS1;
- public UInt16 RS2;
- public UInt16 RS3;
- };
- #endregion
- #region 屏幕缩放比例获取
- public class PrimaryScreen
- {
- #region Win32 API
- [DllImport("user32.dll")]
- static extern IntPtr GetDC(IntPtr ptr);
- [DllImport("gdi32.dll")]
- static extern int GetDeviceCaps(
- IntPtr hdc, // handle to DC
- int nIndex // index of capability
- );
- [DllImport("user32.dll", EntryPoint = "ReleaseDC")]
- static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDc);
- #endregion
- #region DeviceCaps常量
- const int HORZRES = 8;
- const int VERTRES = 10;
- const int LOGPIXELSX = 88;
- const int LOGPIXELSY = 90;
- const int DESKTOPVERTRES = 117;
- const int DESKTOPHORZRES = 118;
- #endregion
- #region 属性
- /// <summary>
- /// 获取屏幕分辨率当前物理大小
- /// </summary>
- public static Size WorkingArea
- {
- get
- {
- IntPtr hdc = GetDC(IntPtr.Zero);
- Size size = new Size();
- size.Width = GetDeviceCaps(hdc, HORZRES);
- size.Height = GetDeviceCaps(hdc, VERTRES);
- ReleaseDC(IntPtr.Zero, hdc);
- return size;
- }
- }
- /// <summary>
- /// 当前系统DPI_X 大小 一般为96
- /// </summary>
- public static int DpiX
- {
- get
- {
- IntPtr hdc = GetDC(IntPtr.Zero);
- int DpiX = GetDeviceCaps(hdc, LOGPIXELSX);
- ReleaseDC(IntPtr.Zero, hdc);
- return DpiX;
- }
- }
- /// <summary>
- /// 当前系统DPI_Y 大小 一般为96
- /// </summary>
- public static int DpiY
- {
- get
- {
- IntPtr hdc = GetDC(IntPtr.Zero);
- int DpiX = GetDeviceCaps(hdc, LOGPIXELSY);
- ReleaseDC(IntPtr.Zero, hdc);
- return DpiX;
- }
- }
- /// <summary>
- /// 获取真实设置的桌面分辨率大小
- /// </summary>
- public static Size DESKTOP
- {
- get
- {
- IntPtr hdc = GetDC(IntPtr.Zero);
- Size size = new Size();
- size.Width = GetDeviceCaps(hdc, DESKTOPHORZRES);
- size.Height = GetDeviceCaps(hdc, DESKTOPVERTRES);
- ReleaseDC(IntPtr.Zero, hdc);
- return size;
- }
- }
- /// <summary>
- /// 获取宽度缩放百分比
- /// </summary>
- public static float ScaleX
- {
- get
- {
- IntPtr hdc = GetDC(IntPtr.Zero);
- int t = GetDeviceCaps(hdc, DESKTOPHORZRES);
- int d = GetDeviceCaps(hdc, HORZRES);
- float ScaleX = (float)GetDeviceCaps(hdc, DESKTOPHORZRES) / (float)GetDeviceCaps(hdc, HORZRES);
- ReleaseDC(IntPtr.Zero, hdc);
- return ScaleX;
- }
- }
- /// <summary>
- /// 获取高度缩放百分比
- /// </summary>
- public static float ScaleY
- {
- get
- {
- IntPtr hdc = GetDC(IntPtr.Zero);
- float ScaleY = (float)(float)GetDeviceCaps(hdc, DESKTOPVERTRES) / (float)GetDeviceCaps(hdc, VERTRES);
- ReleaseDC(IntPtr.Zero, hdc);
- return ScaleY;
- }
- }
- #endregion
- }
- #endregion
- public static mainForm mainform1 = null;
- public mainForm()
- {
- InitializeComponent();
- mainform1 = this;
- System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
- stopwatch.Start();
- //端口初始化
- mySerialProcess.Init();
- toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
-
- //检查文件夹
- if (!Directory.Exists(localInfo.LocalPath))
- {
- Directory.CreateDirectory(localInfo.LocalPath);
- }
- if (!Directory.Exists(localInfo.LocalDataPath))
- {
- Directory.CreateDirectory(localInfo.LocalDataPath);
- }
- if (!Directory.Exists(localInfo.ToolsPath))
- {
- Directory.CreateDirectory(localInfo.ToolsPath);
- }
- if (!Directory.Exists(localInfo.LocalPath + localInfo.CfgPathName))
- {
- Directory.CreateDirectory(localInfo.LocalPath + localInfo.CfgPathName);
- }
- //检查备忘录文件
- if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.NoteFileName))
- {
- System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.NoteFileName, "");
- }
- //检验流水号记录文件
- if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.SerialNumFileName1))
- {
- System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, "0");
- }
- if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.SerialNumFileName2))
- {
- System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, "0");
- }
- //服务器初始化
- do
- {
- //检查是否存在配置文件
- if (File.Exists(localInfo.LocalPath + localInfo.ServerCfgFileName)) //存在配置文件从文件选择
- {
- //解密
- string sLine = aes.DecryptFromFile(localInfo.LocalPath + localInfo.ServerCfgFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
- string[] array_CfgInfo = sLine.Split(',');
- //解析配置文件
- ServerIP = array_CfgInfo[0].ToString();
- ServerPort = array_CfgInfo[1].ToString();
- ServerUser = array_CfgInfo[2].ToString();
- ServerPassWd = array_CfgInfo[3].ToString();
- if (array_CfgInfo[4].ToString() == "True")
- {
- OfflineFlag = true;
- checkBox_OffLineFacMode.Checked = true;
- checkBox_OffLineCheckMode.Checked = true;
- }
- }
- else //不存在配置文件由用户选择
- {
- ServerCfgForm1.ShowDialog();
- switch (ServerCfgForm1.comboBox_Server.SelectedIndex)
- {
- case 0: //武汉园区
- case 1: //顺德工厂
- {
- ServerIP = "10.177.130.30";
- ServerPort = "15021";
- ServerUser = "factory_test";
- ServerPassWd = "ttium";
- OfflineFlag = false;
- checkBox_OffLineFacMode.Checked = false;
- checkBox_OffLineCheckMode.Checked = false;
- break;
- }
- case 2: //威灵园区
- case 3: //越南工厂
- case 4: //公司外部
- {
- ServerIP = "8.134.109.44";
- ServerPort = "21";
- ServerUser = "ttium";
- ServerPassWd = "ttium123";
- OfflineFlag = false;
- checkBox_OffLineFacMode.Checked = false;
- checkBox_OffLineCheckMode.Checked = false;
- break;
- }
- case 5: //离线使用
- {
- //输入管理员密码
- Scan scan_form = new Scan();
- scan_form.label1.Text = "请输入管理员密码";
- scan_form.textBox_Scan.UseSystemPasswordChar = true;
- scan_form.ShowDialog();
- if (scan_form.textBox_Scan.Text == "ttium.123")
- {
- //检查许可
- if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.OffLineUseKeyFileName)) //未许可
- {
- if (MessageBox.Show("无离线授权,请导入许可文件!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
- {
- Licences myLicences = new Licences();
- myLicences.ShowDialog();
- //从许可文件读取内容
- string str_lic = aes.DecryptFromFile(myLicences.textBox_LicencePath.Text, "2D820F88F60A39D5", "3687C5216B19D16B");
- string PC_Code = PC_Information.GetCPUSerialNumber();
- if (PC_Code == str_lic) //授权码正确
- {
- aes.EncryptToFile(PC_Code, localInfo.LocalPath + localInfo.OffLineUseKeyFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
- string strInfo = "";
- strInfo = "0;" + DateTime.Now.ToString("yyyyMMdd");
- aes.EncryptToFile(strInfo, localInfo.LocalPath + localInfo.OfflineUseLogFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
- }
- else //授权码错误
- {
- MessageBox.Show("许可文件无效,请联系管理员!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- System.Environment.Exit(0);
- }
- }
- else
- {
- System.Environment.Exit(0);
- }
- }
- else //已授权
- {
- string str_Key = aes.DecryptFromFile(localInfo.LocalPath + localInfo.OffLineUseKeyFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
- //判断授权是否正确
- if (PC_Information.GetCPUSerialNumber() == str_Key) //授权正确
- {
- //检查离线使用记录文件
- if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.OfflineUseLogFileName))
- {
- MessageBox.Show("许可文件内容缺失,请联系管理员!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- File.Delete(localInfo.LocalPath + localInfo.OffLineUseKeyFileName);//缺少离线使用记录文件时,自动删除许可文件,下次打开重新导入许可
- System.Environment.Exit(0);
- }
- //获取离线使用记录并更新
- string UseLog = aes.DecryptFromFile(localInfo.LocalPath + localInfo.OfflineUseLogFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
- UInt32 UseTimes = Convert.ToUInt32(UseLog.Split(';')[0]);
- UseTimes++;
- string str = UseTimes.ToString() + ";" + UseLog.Split(';')[1];
- aes.EncryptToFile(str, localInfo.LocalPath + localInfo.OfflineUseLogFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
- //判断授权期限
- DateTime DataOrigin = new DateTime();
- DateTime.TryParseExact(UseLog.Split(';')[1], "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None, out DataOrigin);
- DateTime DataEnd = DataOrigin.AddDays(90);
- DateTime NowDate = DateTime.Now.Date;
- if ((NowDate > DataEnd) || (UseTimes > 1000)) //第一次打开软件90天内,或1000次内
- {
- MessageBox.Show("离线授权过期,请联系管理员!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- File.Delete(localInfo.LocalPath + localInfo.OffLineUseKeyFileName);//许可过期或超出使用次数,自动删除许可文件和使用记录,下次打开重新导入许可
- File.Delete(localInfo.LocalPath + localInfo.OfflineUseLogFileName);//许可过期或超出使用次数,自动删除许可文件和使用记录,下次打开重新导入许可
- System.Environment.Exit(0);
- }
- }
- else
- {
- MessageBox.Show("离线授权错误,请联系管理员!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- File.Delete(localInfo.LocalPath + localInfo.OffLineUseKeyFileName);//许可文件不匹配,自动删除许可文件和使用记录,下次打开重新导入许可
- File.Delete(localInfo.LocalPath + localInfo.OfflineUseLogFileName);//许可文件不匹配,自动删除许可文件和使用记录,下次打开重新导入许可
- System.Environment.Exit(0);
- }
- }
- OfflineFlag = true;
- checkBox_OffLineFacMode.Checked = true;
- checkBox_OffLineCheckMode.Checked = true;
- }
- else
- {
- MessageBox.Show("密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- System.Environment.Exit(0);
- }
- break;
- }
- default: //无效
- {
- System.Environment.Exit(0);
- break;
- }
- }
- //保存网络配置文件
- if (ServerCfgForm1.checkBox_NoticeSw.Checked)
- {
- string str = ServerIP + "," + ServerPort + "," + ServerUser + "," + ServerPassWd + "," + (OfflineFlag == true).ToString();
- //加密保存
- aes.EncryptToFile(str, localInfo.LocalPath + localInfo.ServerCfgFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
- }
- }
- } while (false);
- //检查配置文件
- if (File.Exists(localInfo.LocalPath + localInfo.ConfigFileName)) //存在配置文件,导入配置信息
- {
- //打开文件
- StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.ConfigFileName);
- string sLine = "";
- ArrayList array_CfgInfo = new ArrayList();
- array_CfgInfo.Clear();
- while (sLine != null)
- {
- sLine = objReader.ReadLine();
- array_CfgInfo.Add(sLine);
- }
- objReader.Close();
- //解析配置文件
- try
- {
- int index = -1;
- //Port Set
- index = Array.IndexOf(array_CfgInfo.ToArray(), "[PortSet]");
- PortNumSave = array_CfgInfo[index + 1].ToString().Split(':')[1];
- PortBaudrateSave = array_CfgInfo[index + 2].ToString().Split(':')[1];
- toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.IndexOf(PortNumSave);
- toolStripComboBox_Baudrate.SelectedIndex = toolStripComboBox_Baudrate.Items.IndexOf(PortBaudrateSave);
- 连接开机ToolStripMenuItem.Checked = (array_CfgInfo[index + 3].ToString().Split(':')[1] == "True");
- 断开关机ToolStripMenuItem.Checked = (array_CfgInfo[index + 4].ToString().Split(':')[1] == "True");
- 识别通讯盒ToolStripMenuItem.Checked = (array_CfgInfo[index + 5].ToString().Split(':')[1] == "True");
- //Option
- index = Array.IndexOf(array_CfgInfo.ToArray(), "[Option]");
- 写入存储ToolStripMenuItem.Checked = (array_CfgInfo[index + 1].ToString().Split(':')[1] == "True");
- //Server Set
- index = Array.IndexOf(array_CfgInfo.ToArray(), "[ServerSet]");
- toolStripTextBox_ServerPath.Text = array_CfgInfo[index + 1].ToString().Split(':')[1];
- //MacInfo
- index = Array.IndexOf(array_CfgInfo.ToArray(), "[MacInfo]");
- toolStripTextBox_MAC.Text = array_CfgInfo[index + 1].ToString().Split(':')[1];
- toolStripTextBoxMACAddr.Text = array_CfgInfo[index + 2].ToString().Split(':')[1];
- toolStripTextBox_MACDate.Text = DateTime.Now.ToString("yyyyMMdd");
- toolStripTextBox_MACPD.Text = array_CfgInfo[index + 4].ToString().Split(':')[1];
- //Log Address
- index = Array.IndexOf(array_CfgInfo.ToArray(), "[LogAddress]");
- textBox_LogAddrBegin.Text = array_CfgInfo[index + 1].ToString().Split(':')[1];
- textBox_LogAddrEnd.Text = array_CfgInfo[index + 2].ToString().Split(':')[1];
- //电机类型
- index = Array.IndexOf(array_CfgInfo.ToArray(), "[MotorType]");
- 中置电机MIGIC_ToolStripMenuItem.Checked = (array_CfgInfo[index + 1].ToString().Split(':')[1] == "True");
- 中置电机VP_ToolStripMenuItem.Checked = (array_CfgInfo[index + 2].ToString().Split(':')[1] == "True");
- 轮毂电机ToolStripMenuItem.Checked = (array_CfgInfo[index + 3].ToString().Split(':')[1] == "True");
- //检测阈值
- index = Array.IndexOf(array_CfgInfo.ToArray(), "[CheckValue]");
- toolStripTextBox_ThVol.Text = array_CfgInfo[index + 1].ToString().Split(':')[1];
- toolStripTextBox_ThCur.Text = array_CfgInfo[index + 2].ToString().Split(':')[1];
- toolStripTextBox_ThSpeed.Text = array_CfgInfo[index + 3].ToString().Split(':')[1];
- toolStripTextBox_ThTor.Text = array_CfgInfo[index + 4].ToString().Split(':')[1];
- toolStripTextBox_ThCad.Text = array_CfgInfo[index + 5].ToString().Split(':')[1];
- toolStripTextBox_ThBikeSpeed.Text = array_CfgInfo[index + 6].ToString().Split(':')[1];
- toolStripTextBox_ThT_PCB.Text = array_CfgInfo[index + 7].ToString().Split(':')[1];
- toolStripTextBox_ThT_MCU.Text = array_CfgInfo[index + 8].ToString().Split(':')[1];
- toolStripTextBox_ThT_Motor.Text = array_CfgInfo[index + 9].ToString().Split(':')[1];
- //MOS内阻校准系数
- index = Array.IndexOf(array_CfgInfo.ToArray(), "[MosCalK]");
- toolStripTextBox_MosCalK.Text = array_CfgInfo[index + 1].ToString().Split(':')[1];
- toolStripTextBox_MOS1.Text= array_CfgInfo[index + 2].ToString().Split(':')[1];
- toolStripTextBox_MOS2.Text = array_CfgInfo[index + 3].ToString().Split(':')[1];
- toolStripTextBox_MOS3.Text = array_CfgInfo[index + 4].ToString().Split(':')[1];
- //通信协议类型
- index = Array.IndexOf(array_CfgInfo.ToArray(), "[ProtocolType]");
- cANToolStripMenuItem.Checked = (array_CfgInfo[index + 1].ToString().Split(':')[1] == "True");
- uARTToolStripMenuItem.Checked = (array_CfgInfo[index + 2].ToString().Split(':')[1] == "True");
- //自动更新开关
- index = Array.IndexOf(array_CfgInfo.ToArray(), "[AutoUpdate]");
- 打开ToolStripMenuItem.Checked = (array_CfgInfo[index + 1].ToString().Split(':')[1] == "True");
- 关闭ToolStripMenuItem.Checked = !打开ToolStripMenuItem.Checked;
- //位置校准偏差
- index = Array.IndexOf(array_CfgInfo.ToArray(), "[AngleCal]");
- textBox_AngleDiffTh.Text = array_CfgInfo[index + 1].ToString().Split(':')[1];
- toolStripTextBox_AngleAvgMax.Text = textBox_AngleDiffTh.Text;
- textBox_AngleZeroTh.Text = array_CfgInfo[index + 2].ToString().Split(':')[1];
- toolStripTextBox_AngleZeroMax.Text = textBox_AngleZeroTh.Text;
- }
- catch (System.Exception)
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_500ms.Enabled = true;
- ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- }
- else //不存在配置文件,生成文件写入默认值
- {
- ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- //解析本地流水号记录
- do
- {
- //测试模式
- label_FacModeSerial.Text = File.ReadAllText(localInfo.LocalPath + localInfo.SerialNumFileName1);
- //检验模式
- label_CheckModeSerial.Text = File.ReadAllText(localInfo.LocalPath + localInfo.SerialNumFileName2);
- } while (false);
- //获取本机信息,读取时间较长,优先从本地文件获取
- do
- {
- try
- {
- //本地文件为空,读取信息保存
- if (!File.Exists(localInfo.LocalPath + localInfo.PC_InfoFileName))
- {
- Local_HdInformation = "";
- Local_HdInformation += "计算机名称: " + System.Environment.UserName + "\r\n";
- Local_HdInformation += "IP地址: " + PC_Information.GetIpAddress() + "\r\n";
- Local_HdInformation += "系统ID: " + PC_Information.GetSystemID() + "\r\n";
- Local_HdInformation += "操作系统类型: " + PC_Information.GetSystemType() + "\r\n";
- Local_HdInformation += "主板型号: " + PC_Information.GetBoardType() + "\r\n";
- Local_HdInformation += "主板厂商: " + PC_Information.GetBoardManufacturer() + "\r\n";
- Local_HdInformation += "主板ID: " + PC_Information.GetBIOSSerialNumber() + "\r\n";
- Local_HdInformation += "CPU型号: " + PC_Information.GetCpuName() + "\r\n";
- Local_HdInformation += "CPU厂商: " + PC_Information.GetCpuManufacturer() + "\r\n";
- Local_HdInformation += "CPU ID: " + PC_Information.GetCPUSerialNumber() + "\r\n";
- Local_HdInformation += "内存容量: " + PC_Information.GetPhysicalMemory() + " GB" + "\r\n";
- Local_HdInformation += "MAC ID: " + PC_Information.GetNetCardMACAddress().Replace(":", "-") + "\r\n";
- System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.PC_InfoFileName, Local_HdInformation);
- }
- //从本地读取,计算机名和IP地址重新读
- else
- {
- Local_HdInformation = "";
- string[] fileInfo = File.ReadAllLines(localInfo.LocalPath + localInfo.PC_InfoFileName, Encoding.UTF8);
- fileInfo[0] = "计算机名称: " + System.Environment.UserName;
- fileInfo[1] = "IP地址: " + PC_Information.GetIpAddress();
- for (int i = 0; i < fileInfo.Length; i++)
- Local_HdInformation += fileInfo[i] + "\r\n";
- File.Delete(localInfo.LocalPath + localInfo.PC_InfoFileName);
- System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.PC_InfoFileName, Local_HdInformation);
- }
-
- }
- catch(Exception)
- {
-
- }
- } while (false);
- //系统登录
- do
- {
- EnterForm1.ShowDialog();
- try
- {
- if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
- {
- if (EnterForm1.comboBox_User.Text.Contains("量产"))
- {
- //隐藏设置项
- 其它配置项ToolStripMenuItem.Visible = false;
- 写入存储ToolStripMenuItem.Visible = false;
- 服务器配置ToolStripMenuItem.Visible = false;
- 判断阈值ToolStripMenuItem.Visible = false;
- mOS内阻校准系数ToolStripMenuItem.Visible = false;
- mOS内阻范围ToolStripMenuItem.Visible = false;
- 力矩传感器检验ToolStripMenuItem.Visible = false;
- 位置校准偏差范围ToolStripMenuItem.Visible = false;
- //显示生产信息
- 生产信息ToolStripMenuItem.Visible = true;
- //显示电机类型,但不可编辑
- 电机类型ToolStripMenuItem.Visible = true;
- 中置电机MIGIC_ToolStripMenuItem.Enabled = false;
- 中置电机VP_ToolStripMenuItem.Enabled = false;
- 轮毂电机ToolStripMenuItem.Enabled = false;
- if (uARTToolStripMenuItem.Checked)
- UART协议ToolStripMenuItem.Visible = true;
- //隐藏研发调试界面
- tabPage_MotorParam.Parent = null;
- tabPage_BikeParam.Parent = null;
- tabPage_BikeParam2.Parent = null;
- tabPage_ControlParam.Parent = null;
- tabPage_SensorParam.Parent = null;
- tabPage_AssistParam.Parent = null;
- tabPage_UsrRideParam.Parent = null;
- tabPage_DebugParam.Parent = null;
- tabPage_RecordInfo.Parent = null;
- tabPage_OtherInfo.Parent = null;
- tabPage_OBC.Parent = null;
- tabPage_RAMorFLASH.Parent = null;
- tabPage_FactoryMode.Parent = null;
- tabPage_DebugInfo.Parent = null;
- tabPage_AngleCal.Parent = null;
- tabPage_FuncSet.Parent = null;
- //显示运行信息
- tabPage_RunInfo.Parent = tabControl2;
- //根据电机类型修改生产信息和电机类型
- if (EnterForm1.comboBox_User.Text.Contains("中置MIGIC"))
- {
- 中置电机MIGIC_ToolStripMenuItem.Checked = true;
- 中置电机VP_ToolStripMenuItem.Checked = false;
- 轮毂电机ToolStripMenuItem.Checked = false;
- toolStripTextBox_MACPD.Text = "MM_MC1";
- toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
- ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- else if (EnterForm1.comboBox_User.Text.Contains("中置VP"))
- {
- 中置电机MIGIC_ToolStripMenuItem.Checked = false;
- 中置电机VP_ToolStripMenuItem.Checked = true;
- 轮毂电机ToolStripMenuItem.Checked = false;
- toolStripTextBox_MACPD.Text = "MM_MV1";
- toolStripTextBox_ServerPath.Text = "MC_VP_TEST";
- ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
- {
- 中置电机MIGIC_ToolStripMenuItem.Checked = false;
- 中置电机VP_ToolStripMenuItem.Checked = false;
- 轮毂电机ToolStripMenuItem.Checked = true;
- toolStripTextBox_MACPD.Text = "GF_250_1";
- toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
- ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- //显示对应生产测试界面
- if (EnterForm1.comboBox_User.Text.Contains("写入"))
- {
- tabPage_ProductMode_Write.Parent = tabControl1;
- tabPage_ProductMode_Write.Select();
- tabPage_ProductMode_Read.Parent = null;
- }
- else if (EnterForm1.comboBox_User.Text.Contains("检验"))
- {
- tabPage_ProductMode_Read.Parent = tabControl1;
- tabPage_ProductMode_Read.Select();
- tabPage_ProductMode_Write.Parent = null;
- }
- //应答指令不提示
- ACK_DisFlag = false;
- //退出登录
- break;
- }
- else if (EnterForm1.comboBox_User.Text == "工程参数配置")
- {
- //隐藏工作台内容,新建窗口完成配置
- groupBox1.Visible = false;
- groupBox3.Visible = false;
- tabControl2.Visible = false;
- //隐藏提示信息
- label_StarInfo.Visible = false;
- //打开参数配置框
- GenerateParamsForm.ShowDialog();
- System.Environment.Exit(0);
- //退出登录
- break;
- }
- else if (EnterForm1.comboBox_User.Text.Contains("样机"))
- {
- //隐藏量产界面
- tabPage_ProductMode_Read.Parent = null;
- tabPage_ProductMode_Write.Parent = null;
- //隐藏配置项
- 其它配置项ToolStripMenuItem.Visible = false;
- 服务器配置ToolStripMenuItem.Visible = false;
- 判断阈值ToolStripMenuItem.Visible = false;
- 力矩传感器检验ToolStripMenuItem.Visible = false;
- mOS内阻校准系数ToolStripMenuItem.Visible = false;
- mOS内阻范围ToolStripMenuItem.Visible = false;
- 位置校准偏差范围ToolStripMenuItem.Visible = false;
- //显示生产信息
- 生产信息ToolStripMenuItem.Visible = true;
- //显示电机类型
- 电机类型ToolStripMenuItem.Visible = true;
- 中置电机MIGIC_ToolStripMenuItem.Enabled = true;
- 中置电机VP_ToolStripMenuItem.Enabled=true;
- 轮毂电机ToolStripMenuItem.Enabled = true;
- if (uARTToolStripMenuItem.Checked)
- UART协议ToolStripMenuItem.Visible = true;
- if (EnterForm1.comboBox_User.Text.Contains("中置MIGIC"))
- {
- 中置电机MIGIC_ToolStripMenuItem.Checked = true;
- 中置电机VP_ToolStripMenuItem.Checked = false;
- 轮毂电机ToolStripMenuItem.Checked = false;
- toolStripTextBox_MACPD.Text = "MM_MC1";
- toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
- ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- else if (EnterForm1.comboBox_User.Text.Contains("中置VP"))
- {
- 中置电机MIGIC_ToolStripMenuItem.Checked = false;
- 中置电机VP_ToolStripMenuItem.Checked = true;
- 轮毂电机ToolStripMenuItem.Checked = false;
- toolStripTextBox_MACPD.Text = "MM_MV1";
- toolStripTextBox_ServerPath.Text = "MC_VP_TEST";
- ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
- {
- 中置电机MIGIC_ToolStripMenuItem.Checked = false;
- 中置电机VP_ToolStripMenuItem.Checked = false;
- 轮毂电机ToolStripMenuItem.Checked = true;
- toolStripTextBox_MACPD.Text = "GF_250_1";
- toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
- ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- //退出登录
- break;
- }
- else if (EnterForm1.comboBox_User.Text == "FCT治具测试")
- {
- //隐藏设置项
- 其它配置项ToolStripMenuItem.Visible = false;
- 写入存储ToolStripMenuItem.Visible = false;
- 服务器配置ToolStripMenuItem.Visible = false;
- 判断阈值ToolStripMenuItem.Visible = false;
- mOS内阻校准系数ToolStripMenuItem.Visible = false;
- mOS内阻范围ToolStripMenuItem.Visible = false;
- 力矩传感器检验ToolStripMenuItem.Visible = false;
- 位置校准偏差范围ToolStripMenuItem.Visible = false;
- //显示生产信息
- 生产信息ToolStripMenuItem.Visible = true;
- //显示电机类型,但不可编辑
- 电机类型ToolStripMenuItem.Visible = false;
- 中置电机MIGIC_ToolStripMenuItem.Enabled = false;
- 中置电机VP_ToolStripMenuItem.Enabled = false;
- 轮毂电机ToolStripMenuItem.Enabled = false;
- if (uARTToolStripMenuItem.Checked)
- UART协议ToolStripMenuItem.Visible = true;
- //隐藏研发调试界面
- tabPage_MotorParam.Parent = null;
- tabPage_BikeParam.Parent = null;
- tabPage_BikeParam2.Parent = null;
- tabPage_ControlParam.Parent = null;
- tabPage_SensorParam.Parent = null;
- tabPage_AssistParam.Parent = null;
- tabPage_UsrRideParam.Parent = null;
- tabPage_DebugParam.Parent = null;
- tabPage_RecordInfo.Parent = null;
- tabPage_OtherInfo.Parent = null;
- tabPage_OBC.Parent = null;
- tabPage_RAMorFLASH.Parent = null;
- tabPage_FactoryMode.Parent = null;
- tabPage_DebugInfo.Parent = null;
- tabPage_AngleCal.Parent = null;
- tabPage_FuncSet.Parent = null;
- //显示运行信息
- tabPage_RunInfo.Parent = tabControl2;
- //目前仅轮毂使用
- 中置电机MIGIC_ToolStripMenuItem.Checked = false;
- 中置电机VP_ToolStripMenuItem.Checked = false;
- 轮毂电机ToolStripMenuItem.Checked = true;
- toolStripTextBox_MACPD.Text = "GF_250_1";
- toolStripTextBox_ServerPath.Text = "HUB_Control_FCT";
- ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
- //显示量产测试界面
- tabPage_ProductMode_Write.Parent = tabControl1;
- tabPage_ProductMode_Write.Select();
- tabPage_ProductMode_Read.Parent = null;
- checkBox_OffLineFacMode.Checked = false;
- checkBox_OffLineFacMode.Enabled = true;
- checkBox_OffLineCheckMode.Checked = false;
- checkBox_OffLineCheckMode.Enabled = true;
- //应答指令不提示
- ACK_DisFlag = false;
- //退出登录
- break;
- }
- else if (EnterForm1.comboBox_User.Text == "研发调试")
- {
- //隐藏量产界面
- tabPage_ProductMode_Read.Parent = null;
- tabPage_ProductMode_Write.Parent = null;
- 服务器配置ToolStripMenuItem.Visible = false;
- if (uARTToolStripMenuItem.Checked)
- UART协议ToolStripMenuItem.Visible = true;
- //退出登录
- break;
- }
- else if (EnterForm1.comboBox_User.Text == "管理员")
- {
- //不隐藏任何界面
- //...
- //退出登录
- break;
- }
- else
- {
- MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- //重新登录
- continue;
- }
- }
- else
- {
- MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- //重新登录
- continue;
- }
- }
- catch (Exception)
- {
- System.Environment.Exit(0);
- }
- } while (true);
- //配置网络FTP服务器
- myFtp.FtpOption(ServerIP, ServerPort, ServerUser, ServerPassWd, "admin", "ttium_admin");
- //创建线程,定时检测网络连接状态
- Thread th = new Thread(NetworkCheck);
- th.IsBackground = true;
- th.Start();
- //允许跨线程访问
- Control.CheckForIllegalCrossThreadCalls = false;
- }
- /// <summary>
- /// 检查网络状态线程
- /// </summary>
- private void NetworkCheck()
- {
- //允许离线使用,直接退出
- if (OfflineFlag == true) //允许离线使用
- {
- MessageBoxTimeOut.Show("离线使用,不检测网络状态!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- //不允许离线使用,实时监测网络状态
- else
- {
- //初始化第一次连接FTP服务器
- bool Result = myFtp.CheckFtp();
- if (Result == true)//服务器连接成功
- {
- myFtp.IsNetConnected = true;
- //上传登录日志
- do
- {
- //日志文件名
- string date = DateTime.Now.ToString("yyyy-MM-dd_HHmmss_fff");
- string fileName = date;
- //日志内容
- string fileInfo = Local_HdInformation;
- //保存本地
- if (!Directory.Exists(localInfo.LocalLogPath))
- Directory.CreateDirectory(localInfo.LocalLogPath);
- System.IO.File.WriteAllText(localInfo.LocalLogPath + fileName, fileInfo);
- //上传服务器
- myFtp.UploadFile(localInfo.LocalLogPath + fileName, "/Tools/Welling_Motor_Debug_Tool/log");
-
- } while (false);
- }
- else//服务器连接失败
- {
- myFtp.IsNetConnected = false;
- if (EnterForm1.comboBox_User.Text != "管理员")
- {
- MessageBoxTimeOut.Show("网络断开,将自动关闭!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- this.Close();
- }
- }
- //创建定时器,定时30s检查网络
- System.Timers.Timer timer_CheckNet = new System.Timers.Timer();
- timer_CheckNet.Enabled = true;
- timer_CheckNet.Interval = 30000;
- timer_CheckNet.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_CheckNet_Tick);
- timer_CheckNet.Start();
- while (true)
- {
- Thread.Sleep(1);
- if (myFtp.IsNetConnected == false)
- {
- label_Server_ComStatus.Text = "网络已断开";
- label_ServerStatus.BackColor = Color.Red;
- }
- else
- {
- label_Server_ComStatus.Text = "网络已连接";
- label_ServerStatus.BackColor = Color.Green;
- }
- }
- }
- }
- /// <summary>
- /// 线程中定时任务,检查网络状态
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void timer_CheckNet_Tick(object sender, EventArgs e)
- {
- //连接FTP服务器
- bool Result = myFtp.CheckFtp();
- if (Result == true)//服务器连接成功
- {
- myFtp.IsNetConnected = true;
- //允许使用
- groupBox1.Enabled = true;
- groupBox3.Enabled = true;
- tabControl2.Enabled = true;
- }
- else//服务器连接失败
- {
- myFtp.IsNetConnected = false;
- if (EnterForm1.comboBox_User.Text != "管理员")
- {
- MessageBoxTimeOut.Show("网络断开, 请检查网络!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Warning); //提示框自动3s关闭
- //禁止使用
- groupBox1.Enabled = false;
- groupBox3.Enabled = false;
- tabControl2.Enabled = false;
-
- }
- }
- }
- #region 非独占性延时函数
- public static void Delay_ms(int milliSecond)
- {
- int start = Environment.TickCount;
- while (Math.Abs(Environment.TickCount - start) < milliSecond)//毫秒
- {
- Application.DoEvents();
- }
- }
- #endregion
- private void MainForm_Load(object sender, System.EventArgs e)
- {
- timer_500ms.Start();
- //页面初始化
- label_BuildTime.Text = "编译时间:" + System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString("yyyy-MM-dd HH:mm:ss");
- label_Computername.Text = System.Environment.UserName;
- label_UserName.Text = EnterForm1.comboBox_User.Text;
-
- //位置校准表格初始化
- for (int i = 0; i < 7; i++)
- {
- int index = dataGridView_AngleCal.Rows.Add();
- dataGridView_AngleCal.Rows[index].Cells[0].Value = i + 1;
- }
- dataGridView_AngleCal.AllowUserToAddRows = false;
- //拓展功能表格初始化
- for (int i = 0; i < 8; i++)
- {
- int index = dataGridView_FunSet.Rows.Add();
- dataGridView_FunSet.Rows[index].Cells[0].Value = "#" + (i + 1).ToString();
- }
- dataGridView_FunSet.AllowUserToAddRows = false;
- //窗体显示版本
- this.Text += Version;
- //检查版本,自动更新
- do
- {
- if ((打开ToolStripMenuItem.Checked == false) || OfflineFlag == true)//关闭自动更新或离线时
- {
- break;
- }
- //检查网络状态
- if (myFtp.CheckFtp() == false)
- {
- MessageBoxTimeOut.Show("网络断开,自动更新失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
- break;
- }
- else
- {
- //检查本地文件删除
- if (System.IO.File.Exists(localInfo.LocalPath + "\\Version"))
- System.IO.File.Delete(localInfo.LocalPath + "\\Version");
- //读取最新版本号
- myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/Version", localInfo.LocalPath);
- StreamReader objReader = new StreamReader(localInfo.LocalPath + "\\Version");
- string sLine = "";
- ArrayList arrText = new ArrayList();//创建一个动态数组
- while (sLine != null)
- {
- sLine = objReader.ReadLine();
- arrText.Add(sLine);
- }
- objReader.Close();
- System.IO.File.Delete(localInfo.LocalPath + "\\Version");
- //检查是否有最新版本
- string[] VerOld = mainForm.Version.Trim().Split('.');
- string[] VerNew = arrText[0].ToString().Trim().Split('.');
- int VerOld_int = Convert.ToInt32(VerOld[0]) * 10000 + Convert.ToInt32(VerOld[1].PadLeft(2, '0')) * 100 + Convert.ToInt32(VerOld[2].PadLeft(2, '0'));
- int VerNew_int = Convert.ToInt32(VerNew[0]) * 10000 + Convert.ToInt32(VerNew[1].PadLeft(2, '0')) * 100 + Convert.ToInt32(VerNew[2].PadLeft(2, '0'));
- if (VerNew_int <= VerOld_int)
- {
- //版本已是最新,跳出
- break;
- }
- //确认下载最新版本
- if (MessageBox.Show("是否更新新版本?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- string SavePath = Directory.GetCurrentDirectory();
- string[] FileList = myFtp.GetFileNameList("/Tools/Welling_Motor_Debug_Tool");
- foreach (string file in FileList)
- {
- if (file.Contains(".exe"))
- {
- myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/" + file, SavePath);
- MessageBox.Show("新版本下载完成,请手动删除旧版本!\r\n最新版本:" + file, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- System.Environment.Exit(0);
- }
- }
- }
- }
- } while (false);
- //下拉控件初始值设定
- comboBox_WorkMode.SelectedIndex = 0;
- comboBox_GearSt.SelectedIndex = 0;
- comboBox_LightSwitch.SelectedIndex = 1;
- comboBox_OBC_SetGearST.SelectedIndex = 0;
- comboBox_OBC_LightSw.SelectedIndex = 1;
- comboBox_AssistTorque.SelectedIndex = 0;
- comboBox_AssistCadence.SelectedIndex = 0;
- //combobox事件定义
- this.comboBox_WorkMode.SelectedIndexChanged += new System.EventHandler(this.comboBox_WorkMode_SelectedIndexChanged);
- this.comboBox_GearSt.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
- this.comboBox_LightSwitch.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
- this.comboBox_OBC_SetGearST.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
- this.comboBox_OBC_LightSw.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
- //端口自动连接
- if ((PortNumSave != string.Empty) && (PortBaudrateSave != string.Empty)) //有数值时采用上次使用的值
- {
- try
- {
- PortConnect();
- }
- catch (System.Exception)
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_500ms.Enabled = true;
- }
- }
- //不识别联动装置盒自动打开界面
- #if true
- groupBox1.Visible = true;
- groupBox3.Visible = true;
- tabControl2.Visible = true;
- label_StarInfo.Visible = false;
- #endif
- //创建线程,定时解析数据
- Thread th = new Thread(Task_SerialProcess);
- th.IsBackground = true;
- th.Start();
- }
- #region 结构体与字节流相互转换
- public static class MyConverter
- {
- /// <summary>
- /// 由结构体转换为byte数组
- /// </summary>
- public static byte[] StructureToByte<T>(T structure)
- {
- int size = Marshal.SizeOf(typeof(T));
- byte[] buffer = new byte[size];
- IntPtr bufferIntPtr = Marshal.AllocHGlobal(size);
- try
- {
- Marshal.StructureToPtr(structure, bufferIntPtr, true);
- Marshal.Copy(bufferIntPtr, buffer, 0, size);
- }
- finally
- {
- Marshal.FreeHGlobal(bufferIntPtr);
- }
- return buffer;
- }
- /// <summary>
- /// 由byte数组转换为结构体
- /// </summary>
- public static T ByteToStructure<T>(byte[] dataBuffer, ushort StarIndex)
- {
- object structure = null;
- int size = Marshal.SizeOf(typeof(T));
- IntPtr allocIntPtr = Marshal.AllocHGlobal(size);
- try
- {
- Marshal.Copy(dataBuffer, StarIndex, allocIntPtr, size);
- structure = Marshal.PtrToStructure(allocIntPtr, typeof(T));
- }
- finally
- {
- Marshal.FreeHGlobal(allocIntPtr);
- }
- return (T)structure;
- }
- }
- #endregion
- #region 故障日志解析显示
- private void ErrorLogDisplay(MC_ErrorLogSaveInfo_Struct_t Log1, MC_ErrorLogSaveInfo_Struct_t Log2)
- {
- string SaveData = "";
- //Log1
- if (Log1.Error_Index != 0xFFFF)
- {
- SaveData += "故障序号:" + Convert.ToString(Log1.Error_Index) + ", ";
- SaveData += "备注1:" + Convert.ToString(Log1.NotesInfo1) + ", ";
- SaveData += "备注2:" + Convert.ToString(Log1.NotesInfo2) + ", ";
- SaveData += "备注3:" + Convert.ToString(Log1.NotesInfo3) + ", ";
- SaveData += "故障码:" + "0x" + Convert.ToString(Log1.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
- SaveData += "运行时间:" + Convert.ToString(Log1.RunTime) + "min" + ", ";
- SaveData += "车速:" + ((float)Log1.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
- SaveData += "电机转速:" + Convert.ToString(Log1.RunInfo.MotorSpeed) + "rpm" + ", ";
- SaveData += "功率:" + Convert.ToString(Log1.RunInfo.Power * 2) + "w" + ", ";
- SaveData += "电压:" + Convert.ToString(Log1.RunInfo.BusVoltage) + "mV" + ", ";
- SaveData += "电流:" + Convert.ToString(Log1.RunInfo.BusCurrent) + "mA" + ", ";
- SaveData += "踏频:" + Convert.ToString(Log1.RunInfo.Cadence) + "rpm" + ", ";
- SaveData += "力矩:" + Convert.ToString(Log1.RunInfo.Torque) + "N.m" + ", ";
- SaveData += "方向:" + ((Log1.RunInfo.CadenceDir == 0) ? "正" : ((Log1.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
- SaveData += "档位:" + "0x" + Convert.ToString(Log1.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
- SaveData += "灯开关:" + ((Log1.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
- SaveData += "电量:" + Convert.ToString(Log1.RunInfo.SOC) + "%" + ", ";
- if ((Log1.RunInfo.RemainDistance == 0xEEEE) || (Log1.RunInfo.RemainDistance == 0xFFFF))
- {
- SaveData += "续航:" + "---km" + ", ";
- }
- else
- {
- SaveData += "续航:" + Convert.ToString(Log1.RunInfo.RemainDistance) + "km" + ", ";
- }
- SaveData += "力矩AD:" + Convert.ToString(Log1.RunInfo.Torque_AD) + ", ";
- SaveData += "功耗:" + Convert.ToString(Log1.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
- SaveData += "PCB温度:" + Convert.ToString((int)(Log1.RunInfo.T_PCB - 40)) + "℃" + ", ";
- SaveData += "绕组温度:" + Convert.ToString((int)(Log1.RunInfo.T_Coil - 40)) + "℃" + ", ";
- SaveData += "MCU温度:" + Convert.ToString((int)(Log1.RunInfo.T_MCU - 40)) + "℃" + ", ";
- SaveData += "单次里程:" + Convert.ToString((float)Log1.RunInfo.Ride_Km / 10f) + "km" + ", ";
- SaveData += "单次时间:" + Convert.ToString(Log1.RunInfo.Ride_Time) + "s" + ", ";
- SaveData += "q轴电流:" + Convert.ToString(Log1.IqCurrent) + ", ";
- SaveData += "q轴电压:" + Convert.ToString(Log1.IqVoltage) + ", ";
- SaveData += "d轴电流:" + Convert.ToString(Log1.IdCurrent) + ", ";
- SaveData += "d轴电压:" + Convert.ToString(Log1.IdVoltage) + ", ";
- SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
- SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
- SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
- SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
- SaveData += "\r\n\r\n";
- richTextBox_Record.AppendText(SaveData);
- SaveData = "";
- }
- //Log2
- if (Log2.Error_Index != 0xFFFF)
- {
- SaveData += "故障序号:" + Convert.ToString(Log2.Error_Index) + ", ";
- SaveData += "备注1:" + Convert.ToString(Log2.NotesInfo1) + ", ";
- SaveData += "备注2:" + Convert.ToString(Log2.NotesInfo2) + ", ";
- SaveData += "备注3:" + Convert.ToString(Log2.NotesInfo3) + ", ";
- SaveData += "故障码:" + "0x" + Convert.ToString(Log2.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
- SaveData += "运行时间:" + Convert.ToString(Log2.RunTime) + "min" + ", ";
- SaveData += "车速:" + ((float)Log2.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
- SaveData += "电机转速:" + Convert.ToString(Log2.RunInfo.MotorSpeed) + "rpm" + ", ";
- SaveData += "功率:" + Convert.ToString(Log2.RunInfo.Power * 2) + "w" + ", ";
- SaveData += "电压:" + Convert.ToString(Log2.RunInfo.BusVoltage) + "mV" + ", ";
- SaveData += "电流:" + Convert.ToString(Log2.RunInfo.BusCurrent) + "mA" + ", ";
- SaveData += "踏频:" + Convert.ToString(Log2.RunInfo.Cadence) + "rpm" + ", ";
- SaveData += "力矩:" + Convert.ToString(Log2.RunInfo.Torque) + "N.m" + ", ";
- SaveData += "方向:" + ((Log2.RunInfo.CadenceDir == 0) ? "正" : ((Log2.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
- SaveData += "档位:" + "0x" + Convert.ToString(Log2.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
- SaveData += "灯开关:" + ((Log2.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
- SaveData += "电量:" + Convert.ToString(Log2.RunInfo.SOC) + "%" + ", ";
- if ((Log2.RunInfo.RemainDistance == 0xEEEE) || (Log2.RunInfo.RemainDistance == 0xFFFF))
- {
- SaveData += "续航:" + "---km" + ", ";
- }
- else
- {
- SaveData += "续航:" + Convert.ToString(Log2.RunInfo.RemainDistance) + "km" + ", ";
- }
- SaveData += "力矩AD:" + Convert.ToString(Log2.RunInfo.Torque_AD) + ", ";
- SaveData += "功耗:" + Convert.ToString(Log2.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
- SaveData += "PCB温度:" + Convert.ToString((int)(Log2.RunInfo.T_PCB - 40)) + "DegreeC" + ", ";
- SaveData += "绕组温度:" + Convert.ToString((int)(Log2.RunInfo.T_Coil - 40)) + "DegreeC" + ", ";
- SaveData += "MCU温度:" + Convert.ToString((int)(Log2.RunInfo.T_MCU - 40)) + "DegreeC" + ", ";
- SaveData += "单次里程:" + Convert.ToString((float)Log2.RunInfo.Ride_Km / 10f) + "km" + ", ";
- SaveData += "单次时间:" + Convert.ToString(Log2.RunInfo.Ride_Time) + "s" + ", ";
- SaveData += "q轴电流:" + Convert.ToString(Log2.IqCurrent) + ", ";
- SaveData += "q轴电压:" + Convert.ToString(Log2.IqVoltage) + ", ";
- SaveData += "d轴电流:" + Convert.ToString(Log2.IdCurrent) + ", ";
- SaveData += "d轴电压:" + Convert.ToString(Log2.IdVoltage) + ", ";
- SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
- SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
- SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
- SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
- SaveData += "\r\n\r\n";
- richTextBox_Record.AppendText(SaveData);
- SaveData = "";
- }
- }
- #endregion
- #region 串口数据解析线程
- /// <summary>
- /// 串口数据解析线程
- /// </summary>
- private void Task_SerialProcess()
- {
- //创建定时器,定时读取串口数据
- System.Timers.Timer timer_ReadSerial = new System.Timers.Timer();
- timer_ReadSerial.Enabled = true;
- timer_ReadSerial.Interval = 20;
- timer_ReadSerial.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_ReadSerial_Tick);
- timer_ReadSerial.Start();
- while (true)
- {
- Thread.Sleep(1);
- };
- }
- /// <summary>
- /// 串口解析定时器
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void timer_ReadSerial_Tick(object sender, EventArgs e)
- {
- //串口解析
- Serial_process(mySerialProcess.buffer);
- }
- #endregion
- #region 数据解析
- public void Serial_process(List<byte> buffer)
- {
- byte DataNum = 0; //记录每条命令数据段的长度
- ushort PackageID, Cmd;
- byte[] Data = new byte[1024];
- try
- {
- while (buffer.Count >= 13)//当buffer中的数据的个数大于等于4个时,即每一帧的数据长度所在位(第4位)出现时
- {
- if (buffer[0] == 0x55 && buffer[1] == 0xAA)//判断帧头
- {
- PackageID = (ushort)(buffer[2] * 256 + buffer[3]);
- if ((PackageID == 0x0710) || (PackageID == 0x0715) || (PackageID == 0x07FF) || (PackageID == 0x0720) || (PackageID == 0x0713))
- {
- int CmdLen = buffer[5];
- if (buffer.Count < CmdLen + 11) break;//如果接收到的数据没有达到一帧数据的指定长度, 则执行下次循环
- while (CmdLen > 0) //读取命令段
- {
- Cmd = (ushort)(buffer[6] * 256 + buffer[7]);
- DataNum = (byte)(buffer[7]);//命令字的第二个字节的表示数据位的长度
- if (DataNum <= (CmdLen - 2))
- {
- for (int i = 0; i < DataNum; i++)
- {
- Data[i] = buffer[i + 8];
- }
- // 串口接收的数据 显示在子窗口
- if (this.DebugWindowIsOpen && this.DebugDataDisplayEnable)
- {
- string strTemp = String.Empty;
- strTemp += System.DateTimeOffset.Now.ToString("HH:mm:ss.fff") + " <-- ";
- for (int i = 0; i < CmdLen + 11; i++)
- {
- strTemp += (buffer[i].ToString("X2") + " ");
- }
- strTemp += "\n";
- DebugForm.debug1.richTextBox_DebugRev.Text += strTemp;
- }
- buffer.RemoveRange(0, CmdLen + 11);
- DataCmdProcess(PackageID, Cmd, Data);//对于不同的命令段,做不同的处理
- DataRevToString(Cmd, Data);//指令数据转为字符串
- }
- }
- }
- else
- {
- buffer.RemoveAt(0);//ID不对
- }
- }
- else
- {
- buffer.RemoveAt(0);//帧头不对,删除帧头高字节
- }
- }
- }
- catch (Exception)
- {
-
- }
- }
- private void DataCmdProcess(ushort ID, ushort CmdTemp, byte[] Data)
- {
- int DataTemp;
- ushort uData16;
- unchecked
- {
- this.Invoke((EventHandler)(delegate { label_RecCount.Text = Convert.ToString(Convert.ToInt32(label_RecCount.Text) + 1); }));
- }
- #region 解析发送给CDL的指令
- if (ID == 0x7FF)
- {
- switch (CmdTemp)
- {
- case 0x1100://
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- //CDL连接成功
- mySerialProcess.CDL_Online_Flag = true;
- MessageBoxTimeOut.Show("连接成功!", "提示", 500);
- groupBox1.Visible = true;
- groupBox3.Visible = true;
- tabControl2.Visible = true;
- label_StarInfo.Visible = false;
- }));
- }
- break;
- }
- default: break;
- }
- }
- #endregion
- #region 解析电机的命令
- else if ((ID == 0x715) || (ID == 0x710))
- {
- switch (CmdTemp)
- {
- case 0x1020://电机运行信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- MC_RunInfo_Refresh = true;
- //车速
- DataTemp = (int)(Data[1] * 256 + Data[0]);
- textBox_RunInfo_BikeSpeed.Text = ((float)DataTemp / 10f).ToString("0.0") + " km/h";
- //输出转速
- DataTemp = (ushort)(Data[3] * 256 + Data[2]);
- textBox_RunInfo_MotorSpeed.Text = Convert.ToString(DataTemp) + " rpm";
- Class_MotorSpeed.String = textBox_RunInfo_MotorSpeed.Text;
- Class_MotorSpeed.Data = DataTemp;
- //电功率
- DataTemp = (ushort)(Data[5] * 256 + Data[4]);
- textBox_RunInfo_Power.Text = Convert.ToString(DataTemp) + " W";
- //母线电压
- DataTemp = (ushort)(Data[7] * 256 + Data[6]);
- textBox_RunInfo_Vol.Text = Convert.ToString(DataTemp) + " mV";
- //textBox_RunInfo_Vol.Text = (DataTemp / 1000f).ToString("0.0") + " V";
- //母线电流
- DataTemp = (short)(Data[9] * 256 + Data[8]);
- textBox_RunInfo_Current.Text = Convert.ToString(DataTemp) + " mA";
- //textBox_RunInfo_Current.Text = (DataTemp / 1000f).ToString("0.0") + " A";
- Class_CurrentData.String = textBox_RunInfo_Current.Text;
- Class_CurrentData.Data = DataTemp;
- //踏频
- DataTemp = (ushort)(Data[10]);
- textBox_RunInfo_Cadence.Text = Convert.ToString(DataTemp) + " rpm";
- Class_CadenceData.String = textBox_RunInfo_Cadence.Text;
- Class_CadenceData.Data = DataTemp;
- //踩踏力矩
- DataTemp = (ushort)(Data[11]);
- textBox_RunInfo_Torque.Text = Convert.ToString(DataTemp) + " N.m";
- Class_TorqueData.String = textBox_RunInfo_Torque.Text;
- Class_TorqueData.Data = DataTemp;
- //踩踏方向
- DataTemp = (ushort)(Data[12]);
- if (DataTemp == 0)
- {
- textBox_RunInfo_Dir.Text = "正向";
- }
- else if (DataTemp == 1)
- {
- textBox_RunInfo_Dir.Text = "反向";
- }
- else if (DataTemp == 2)
- {
- textBox_RunInfo_Dir.Text = "停止";
- }
- //助力档位
- DataTemp = (ushort)(Data[13]);
- if (DataTemp == 0x33)
- {
- textBox_RunInfo_GearSt.Text = "SMART";
- //comboBox_GearSt.SelectedIndex = 5;
- //comboBox_OBC_SetGearST.SelectedIndex = 5;
- }
- else if (DataTemp == 0x22)
- {
- textBox_RunInfo_GearSt.Text = "WALK";
- //comboBox_GearSt.SelectedIndex = 6;
- //comboBox_OBC_SetGearST.SelectedIndex = 6;
- }
- else
- {
- string[] Gears = new string[5] { "OFF", "ECO", "NORM", "SPORT", "TURBO" };
- textBox_RunInfo_GearSt.Text = Gears[DataTemp];
- //comboBox_GearSt.SelectedIndex = DataTemp;
- //comboBox_OBC_SetGearST.SelectedIndex = DataTemp;
- }
- //大灯状态
- DataTemp = (ushort)(Data[14]);
- if (DataTemp == 0xF0)
- {
- textBox_RunInfo_LightSwitch.Text = "OFF";
- //comboBox_LightSwitch.SelectedIndex = 1;
- //comboBox_OBC_LightSw.SelectedIndex = 1;
- }
- else if (DataTemp == 0xF1)
- {
- textBox_RunInfo_LightSwitch.Text = "ON";
- //comboBox_LightSwitch.SelectedIndex = 0;
- //comboBox_OBC_LightSw.SelectedIndex = 0;
- }
- //剩余电量
- DataTemp = (ushort)(Data[15]);
- textBox_RunInfo_SOC.Text = Convert.ToString(DataTemp) + " %";
- //剩余续航里程
- DataTemp = (ushort)(Data[17] * 256 + Data[16]);
- if ((DataTemp == 0xEEEE) || (DataTemp == 0xFFFF))
- {
- textBox_RunInfo_Range.Text = "---";
- }
- else
- {
- textBox_RunInfo_Range.Text = Convert.ToString(DataTemp) + " km";
- }
- //预留(显示力矩Reg),空2bytes
- DataTemp = (ushort)(Data[19] * 256 + Data[18]);
- textBox_TorqueReg.Text = Convert.ToString(DataTemp);
- //平均功耗
- DataTemp = (ushort)(Data[20]);
- textBox_RunInfo_AvgPower.Text = Convert.ToString(DataTemp * 10) + " mAh/km";
- //PCB温度
- DataTemp = (ushort)(Data[21]);
- textBox_RunInfo_T_PCB.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
- Class_MotorTemp.String = textBox_RunInfo_T_PCB.Text;
- Class_MotorTemp.Data = DataTemp - 40;
- //绕组温度
- DataTemp = (ushort)(Data[22]);
- textBox_RunInfo_T_Coil.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
- //MCU温度
- DataTemp = (ushort)(Data[23]);
- textBox_RunInfo_T_MCU.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
- //单次里程
- DataTemp = (ushort)(Data[25] * 256 + Data[24]);
- textBox_RunInfo_Trip.Text = ((float)DataTemp / 10f).ToString("0.0") + " km";
- //单次时间
- DataTemp = (ushort)(Data[27] * 256 + Data[26]);
- textBox_RunInfo_Trip_Time.Text = Convert.ToString(DataTemp) + " s";
- //RSV1
- DataTemp = (ushort)(Data[28]);
- textBox_RunInfo_RSV1.Text = Convert.ToString(DataTemp);
- //RSV2
- DataTemp = (ushort)(Data[29]);
- textBox_RunInfo_RSV2.Text = Convert.ToString(DataTemp);
- //RSV3
- DataTemp = (ushort)(Data[30]);
- textBox_RunInfo_RSV3.Text = Convert.ToString(DataTemp);
- //GearBox
- DataTemp = (ushort)(Data[31]);
- textBox_RunInfo_GearBox.Text = Convert.ToString(DataTemp);
- //数据保存
- RunInfoAutoSave();
- }));
- }
- break;
- }
- case 0x1104://故障码
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- MC_ErrorCode_Refresh = true;
- textBox_ErrorCode.Text =
- Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() +
- Convert.ToString(Data[2], 16).PadLeft(2, '0').ToUpper() +
- Convert.ToString(Data[1], 16).PadLeft(2, '0').ToUpper() +
- Convert.ToString(Data[0], 16).PadLeft(2, '0').ToUpper() +
- "H";
- }));
- }
- break;
- }
- case 0xA903://反馈指令
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- if (ACK_DisFlag == true)
- {
- MessageBoxTimeOut.Show("OK", "反馈指令", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
- //关机反馈
- PowerOffAckStatus = true;
- }
- //应答标志置位
- WriteACK = true;
- }));
- }
- break;
- }
- case 0xB226://马达参数
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_MotorParam.Clear();
- for (int i = 0; i < myParams.MotorParam.Count; i++)
- {
- if (i == 6)
- richTextBox_MotorParam.AppendText(myParams.MotorParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
- else
- richTextBox_MotorParam.AppendText(myParams.MotorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
- }
- richTextBox_MotorParam.Text = richTextBox_MotorParam.Text.Substring(0, richTextBox_MotorParam.Text.Length - 2);
- }));
- }
- break;
- }
- case 0xB31A://整车信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_BikeParam.Clear();
- for (int i = 0; i < myParams.BikeParam.Count; i++)
- {
- if (i == 9)
- richTextBox_BikeParam.AppendText(myParams.BikeParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
- else
- richTextBox_BikeParam.AppendText(myParams.BikeParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
- //更新前后灯参数
- if (i == 8)
- {
- comboBox_TailLightMode.SelectedIndex = ((Data[2 * i + 1] >> 4) & 0x0F) - 1;
- comboBox_TailLightVol.SelectedIndex = ((Data[2 * i + 1] & 0x0F) == 6) ? 0 : 1;
- comboBox_FrontLightVol.SelectedIndex = ((Data[2 * i] & 0x0F) == 6) ? 0 : 1;
- }
- //更新开关机参数
- else if (i == 11)
- {
- textBox_PowerOnDelay.Text = Convert.ToString((Data[2 * i + 1] >> 4) & 0x0F);
- textBox_PowerOffDelay.Text = Convert.ToString(Data[2 * i + 1] & 0x0F);
- textBox_AutoPowerOff.Text = Convert.ToString(Data[2 * i]);
- }
- }
- richTextBox_BikeParam.Text = richTextBox_BikeParam.Text.Substring(0, richTextBox_BikeParam.Text.Length - 2);
- }));
- }
- break;
- }
- case 0xB420://控制器参数
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_ControlParam.Clear();
- for (int i = 0; i < myParams.ControlParam.Count; i++)
- {
- richTextBox_ControlParam.AppendText(myParams.ControlParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
- //转把定速巡航
- if (i == 13)
- {
- comboBox_Bike_CCS.SelectedIndex = ((Data[2 * i]) == 0xAA) ? 1 : 2;
- }
- }
- richTextBox_ControlParam.Text = richTextBox_ControlParam.Text.Substring(0, richTextBox_ControlParam.Text.Length - 2);
- }));
- }
- break;
- }
- case 0xB528://传感器参数
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_SensorParam.Clear();
- for (int i = 0; i < myParams.SensorParam.Count; i++)
- {
- richTextBox_SensorParam.AppendText(myParams.SensorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
- }
- richTextBox_SensorParam.Text = richTextBox_SensorParam.Text.Substring(0, richTextBox_SensorParam.Text.Length - 2);
- //更新生产模式页面传感器零点和标定值
- textBox_FacModeSensorADC0.Text = (Data[9] * 256 + Data[8]).ToString();
- textBox_FacModeSensorADC1.Text = (Data[15] * 256 + Data[14]).ToString();
- textBox_FacModeSensorADC2.Text = (Data[19] * 256 + Data[18]).ToString();
- textBox_FacModeSensorADC3.Text = (Data[23] * 256 + Data[22]).ToString();
- textBox_FacModeSensorADC4.Text = (Data[27] * 256 + Data[26]).ToString();
- WriteACK = true;
- }));
- }
- break;
- }
- case 0xB64C://助力参数
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_AssistParam.Clear();
- int index_1 = myParams.AssistParam.IndexOf("转矩曲线.a");
- int index_2 = myParams.AssistParam.IndexOf("踏频曲线.d");
- int index_3 = myParams.AssistParam.IndexOf("踏频助力加速限制");
- int index_4 = myParams.AssistParam.IndexOf("踏频助力电流步进");
- for (int i = 0; i < myParams.AssistParam.Count; i++)
- {
- if (i < index_1) //数据占用2bytes
- {
- richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
- }
- else if (i <= index_2) //数据占用4bytes
- {
- 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])) + ", ");
- }
- else if (i < index_3) //数据占用2bytes,无符号
- {
- richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
- }
- else if (i <= index_4) //数据占用2bytes,有符号
- {
- richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
- }
- else //数据占用2bytes,无符号
- {
- richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
- }
- }
- richTextBox_AssistParam.Text = richTextBox_AssistParam.Text.Substring(0, richTextBox_AssistParam.Text.Length - 2);
- }));
- }
- break;
- }
- case 0xB74C://历史记录
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_Record.Clear();
- for (int i = 0; i < myParams.Record.Count; i++)
- {
- richTextBox_Record.AppendText(myParams.Record[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
- }
- richTextBox_Record.Text = richTextBox_Record.Text.Substring(0, richTextBox_Record.Text.Length - 2);
- }));
- }
- break;
- }
- case 0xB83A://调试参数
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_DebugParam.Clear();
- for (int i = 0; i < myParams.DebugParam.Count; i++)
- {
- richTextBox_DebugParam.AppendText(myParams.DebugParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
- }
- richTextBox_DebugParam.Text = richTextBox_DebugParam.Text.Substring(0, richTextBox_DebugParam.Text.Length - 2);
- }));
- }
- break;
- }
- case 0xB904://存储标志
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- ushort Flag = 0;
- Flag = (ushort)(Data[1] * 256 + Data[0]);//EEPROM存储标志
- if (Flag == 0)
- {
- radioButton_EE_SaveNo.Checked = true;
- radioButton_EE_SaveYes.Checked = false;
- }
- else
- {
- radioButton_EE_SaveNo.Checked = false;
- radioButton_EE_SaveYes.Checked = true;
- }
- Flag = (ushort)(Data[3] * 256 + Data[2]);//SIP偏移校准存储标志
- if (Flag == 0)
- {
- radioButton_SIP_SaveNo.Checked = true;
- radioButton_SIP_SaveYes.Checked = false;
- }
- else
- {
- radioButton_SIP_SaveNo.Checked = false;
- radioButton_SIP_SaveYes.Checked = true;
- }
- }));
- }
- break;
- }
- case 0x1240://电机版本信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- //电机型号
- textBox_Model.Text = "";
- textBox_OBC_ReadModel.Text = "";
- textBox_FacModeName.Text = "";
- for (ushort i = 0; i < 16; i++)
- {
- if (Data[i] == 0x2E)
- {
- break;
- }
- textBox_Model.Text += ((char)Data[i]).ToString();
- textBox_OBC_ReadModel.Text += ((char)Data[i]).ToString();
- textBox_FacModeName.Text += ((char)Data[i]).ToString();
- }
- Class_Motor_Ver.Mode = textBox_Model.Text;
- //电机SN
- textBox_SN.Text = "";
- textBox_OBC_ReadSN.Text = "";
- textBox_FacModeNum.Text = "";
- for (ushort i = 0; i < 16; i++)
- {
- if (Data[16 + i] == 0x2E)
- {
- break;
- }
- textBox_SN.Text += ((char)Data[16 + i]).ToString();
- textBox_OBC_ReadSN.Text += ((char)Data[16 + i]).ToString();
- textBox_FacModeNum.Text += ((char)Data[16 + i]).ToString();
- }
- Class_Motor_Ver.SN = textBox_SN.Text;
- //电机HW
- textBox_HW.Text = "";
- textBox_OBC_ReadHW.Text = "";
- textBox_FacModeHW.Text = "";
- for (ushort i = 0; i < 8; i++)//前8位:硬件板号
- {
- if (Data[32 + i] == 0x2E)
- {
- break;
- }
- else if (Data[32 + i] == 'r')
- {
- Data[32 + i] = (byte)'.';
- break;
- }
- string strTemp = "";
- strTemp = ((char)Data[32 + i]).ToString();
- textBox_HW.Text += strTemp;
- textBox_OBC_ReadHW.Text += strTemp;
- textBox_FacModeHW.Text += strTemp;
- }
- for (ushort i = 0; i < 4; i++)//9-12位:单片机型号
- {
- if (Data[40 + i] == 0x2E)
- {
- break;
- }
- else if (Data[40 + i] == 'r')
- {
- Data[40 + i] = (byte)'.';
- break;
- }
- string strTemp = "";
- strTemp = ((char)Data[40 + i]).ToString();
- textBox_HW.Text += strTemp;
- textBox_OBC_ReadHW.Text += strTemp;
- textBox_FacModeHW.Text += strTemp;
- }
- for (ushort i = 0; i < 4; i++)//13-16位:单片机ID
- {
- string strTemp = "";
- strTemp = Convert.ToString(Data[44 + i], 16).PadLeft(2, '0').ToUpper();
- textBox_HW.Text += strTemp;
- textBox_OBC_ReadHW.Text += strTemp;
- textBox_FacModeHW.Text += strTemp;
- }
- Class_Motor_Ver.HW = textBox_HW.Text;
- //电机FW
- textBox_FW.Text = "";
- textBox_OBC_ReadFW.Text = "";
- textBox_FacModeFW.Text = "";
- for (ushort i = 0; i < 16; i++)
- {
- if ((Data[48 + i] == 0x2E) || (Data[48 + i] == 0x00) || (Data[48 + i] == (char)' '))
- {
- break;
- }
- if (Data[48 + i] == 'r')
- {
- Data[48 + i] = (byte)'.';
- }
- textBox_FW.Text += ((char)Data[48 + i]).ToString();
- textBox_OBC_ReadFW.Text += ((char)Data[48 + i]).ToString();
- textBox_FacModeFW.Text += ((char)Data[48 + i]).ToString();
- }
- Class_Motor_Ver.FW = textBox_FW.Text;
- }));
- }
- break;
- }
- case 0xA610://自定义1
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- textBox_User1.Text = "";
- for (ushort i = 0; i < 16; i++)
- {
- if (Data[i] == 0x2E)
- {
- break;
- }
- textBox_User1.Text += ((char)Data[i]).ToString();
- }
- }));
- }
- break;
- }
- case 0xA710://自定义2
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- textBox_User2.Text = "";
- for (ushort i = 0; i < 16; i++)
- {
- if (Data[i] == 0x2E)
- {
- break;
- }
- textBox_User2.Text += ((char)Data[i]).ToString();
- }
- }));
- }
- break;
- }
- case 0xA810://自定义1
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- textBox_User3.Text = "";
- for (ushort i = 0; i < 16; i++)
- {
- if (Data[i] == 0x2E)
- {
- break;
- }
- textBox_User3.Text += ((char)Data[i]).ToString();
- }
- }));
- }
- break;
- }
- case 0xA520://生产信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- //生产商
- textBox_MAC.Text = "";
- for (ushort i = 0; i < 8; i++)
- {
- if (Data[i] == 0x2E)
- {
- break;
- }
- textBox_MAC.Text += ((char)Data[i]).ToString();
- }
- //生产地
- textBox_MACAdd.Text = "";
- for (ushort i = 0; i < 8; i++)
- {
- if (Data[8 + i] == 0x2E)
- {
- break;
- }
- textBox_MACAdd.Text += ((char)Data[8 + i]).ToString();
- }
- //生产日期
- textBox_MACDate.Text = "";
- for (ushort i = 0; i < 8; i++)
- {
- if (Data[16 + i] == 0x2E)
- {
- break;
- }
- textBox_MACDate.Text += ((char)Data[16 + i]).ToString();
- }
- //品牌信息
- textBox_PP.Text = "";
- for (ushort i = 0; i < 8; i++)
- {
- if (Data[24 + i] == 0x2E)
- {
- break;
- }
- textBox_PP.Text += ((char)Data[24 + i]).ToString();
- }
- }));
- }
- break;
- }
- case 0xA408://密钥
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- textBox_Key.Text = "";
- for (ushort i = 0; i < 8; i++)
- {
- textBox_Key.Text += ((char)Data[i]).ToString();
- }
- }));
- }
- break;
- }
- case 0xAB09://存储器数据
- case 0xAB0A:
- case 0xAB0B:
- case 0xAB0C:
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- long ByteNum = 0;
- ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
- if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
- {
- for (int i = 0; i < ByteNum; i++)
- {
- richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
- }
- }
- else //根据设置自动转换10进制显示
- {
- if (checkBox_ReadRanFlash_ChangeFormat.Checked == true) //10进制显示
- {
- switch (ByteNum)
- {
- case 1:
- {
- richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8]) + ", ");
- break;
- }
- case 2:
- {
- richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8)) + ", ");
- break;
- }
- case 3:
- {
- richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16)) + ", ");
- break;
- }
- case 4:
- {
- richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24)) + ", ");
- break;
- }
- default:
- {
- richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
- break;
- }
- }
- }
- else //16进制显示
- {
- switch (ByteNum)
- {
- case 1:
- {
- richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8], 16).PadLeft(2, '0').ToUpper() + ", ");
- break;
- }
- case 2:
- {
- richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8), 16).PadLeft(4, '0').ToUpper() + ", ");
- break;
- }
- case 3:
- {
- richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16), 16).PadLeft(6, '0').ToUpper() + ", ");
- break;
- }
- case 4:
- {
- richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24), 16).PadLeft(8, '0').ToUpper() + ", ");
- break;
- }
- default:
- {
- richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
- break;
- }
- }
- }
- }
- }));
- }
- break;
- }
- case 0xAB88://故障日志
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- //电机存储的故障日志,一包128字节包含2条故障日志
- var ErrorLogSaveInfo1 = new MC_ErrorLogSaveInfo_Struct_t();
- var ErrorLogSaveInfo2 = new MC_ErrorLogSaveInfo_Struct_t();
- ErrorLogSaveInfo1 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 8);
- ErrorLogSaveInfo2 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 72);
- //数据显示
- ErrorLogDisplay(ErrorLogSaveInfo1, ErrorLogSaveInfo2);
- }));
- }
- break;
- }
- case 0x1401://在线检测结果
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- textBox_Online.Text = Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() + "H";
- }));
- }
- break;
- }
- case 0x1510://骑行历史信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- long DataTemp32;
- //ODO里程
- DataTemp32 = (long)((Data[3] << 24) + (Data[2] << 16) + (Data[1] << 8) + Data[0]);
- textBox_OBC_ODO_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
- textBox_ODO_KM.Text = DataTemp32.ToString();
- //ODO时间
- DataTemp32 = (long)((Data[7] << 24) + (Data[6] << 16) + (Data[5] << 8) + Data[4]);
- if (DataTemp32 >= 60 * 100000)
- textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
- else
- textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
- textBox_ODO_TIME.Text = DataTemp32.ToString();
- //TRIP里程
- DataTemp32 = (long)((Data[11] << 24) + (Data[10] << 16) + (Data[9] << 8) + Data[8]);
- textBox_OBC_TRIP_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
- textBox_TRIP_KM.Text = DataTemp32.ToString();
- //TRIP时间
- DataTemp32 = (long)((Data[15] << 24) + (Data[14] << 16) + (Data[13] << 8) + Data[12]);
- if (DataTemp32 >= 60 * 100000)
- textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
- else
- textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
- textBox_TRIP_TIME.Text = DataTemp32.ToString();
- }));
- }
- break;
- }
- case 0x1720://客户信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- //软件标识
- textBox_SP.Text = "";
- textBox_OBC_ReadSP.Text = "";
- textBox_FacModeSP.Text = "";
- for (ushort i = 0; i < 23; i++)
- {
- if (Data[i] == 'r')
- {
- Data[i] = (byte)'.';
- }
- textBox_SP.Text += ((char)Data[i]).ToString();
- textBox_OBC_ReadSP.Text += ((char)Data[i]).ToString();
- textBox_FacModeSP.Text += ((char)Data[i]).ToString();
- }
- //Git提交版本信息
- textBox_FacModeGit.Text = "";
- for (ushort i = 0; i < 9; i++)
- {
- textBox_SP.Text += ((char)Data[23 + i]).ToString();
- textBox_FacModeGit.Text += ((char)Data[23 + i]).ToString();
- }
- Class_Motor_Ver.Special = textBox_SP.Text;
- }));
- }
- break;
- }
- case 0xBA20: //调试信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- MC_DebugInfo_Refresh = true;
- //系统状态机
- DataTemp = (short)(Data[0]);
- textBox_DebugInfo_SysFun.Text = Convert.ToString(DataTemp);
- //二层状态机
- DataTemp = (short)(Data[1]);
- textBox_DebugInfo_SecondFun.Text = Convert.ToString(DataTemp);
- //电机状态机
- DataTemp = (short)(Data[2]);
- textBox_DebugInfo_MotorFun.Text = Convert.ToString(DataTemp);
- //助力状态机
- DataTemp = (short)(Data[3]);
- textBox_DebugInfo_AssistFun.Text = Convert.ToString(DataTemp);
- //IdRef
- DataTemp = (short)(Data[5] * 256 + Data[4]);
- textBox_DebugInfo_IdRef.Text = Convert.ToString(DataTemp);
- //IqRef
- DataTemp = (short)(Data[7] * 256 + Data[6]);
- textBox_DebugInfo_IqRef.Text = Convert.ToString(DataTemp);
- //UdRef
- DataTemp = (short)(Data[9] * 256 + Data[8]);
- textBox_DebugInfo_UdRef.Text = Convert.ToString(DataTemp);
- //UqRef
- DataTemp = (short)(Data[11] * 256 + Data[10]);
- textBox_DebugInfo_UqRef.Text = Convert.ToString(DataTemp);
- //瞬时力矩
- DataTemp = (short)(Data[13] * 256 + Data[12]);
- textBox_DebugInfo_TorquePu.Text = Convert.ToString(DataTemp);
- //时间滤波力矩
- DataTemp = (short)(Data[15] * 256 + Data[14]);
- textBox_DebugInfo_TorqueFil.Text = Convert.ToString(DataTemp);
- //踏频滤波力矩
- DataTemp = (short)(Data[17] * 256 + Data[16]);
- textBox_DebugInfo_TorqueCadence.Text = Convert.ToString(DataTemp);
- //IdFdb
- DataTemp = (short)(Data[19] * 256 + Data[18]);
- textBox_DebugInfo_IdFdb.Text = Convert.ToString(DataTemp);
- //IqFdb
- DataTemp = (short)(Data[21] * 256 + Data[20]);
- textBox_DebugInfo_IqFdb.Text = Convert.ToString(DataTemp);
- //助力输出
- DataTemp = (short)(Data[23] * 256 + Data[22]);
- textBox_DebugInfo_AssistOut.Text = Convert.ToString(DataTemp);
- //转把百分比
- DataTemp = (short)(Data[25] * 256 + Data[24]);
- textBox_DebugInfo_ThrottlePer.Text = Convert.ToString(DataTemp);
- //数据保存
- RunInfoAutoSave();
- }));
- }
- break;
- }
- case 0xBB20: //产品标签信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- //产品标签
- textBox_TagInfo.Text = "";
- for (ushort i = 0; i < 32; i++)
- {
- textBox_TagInfo.Text += ((char)Data[i]).ToString();
- }
- }));
- }
- break;
- }
- case 0xBC20: //内阻校正信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- //内阻1
- uData16 = (ushort)(Data[1] * 256 + Data[0]);
- textBox_MOS_R1.Text = Convert.ToString(uData16);
- //内阻2
- uData16 = (ushort)(Data[3] * 256 + Data[2]);
- textBox_MOS_R2.Text = Convert.ToString(uData16);
- //内阻3
- uData16 = (ushort)(Data[5] * 256 + Data[4]);
- textBox_MOS_R3.Text = Convert.ToString(uData16);
- //K1
- uData16 = (ushort)(Data[7] * 256 + Data[6]);
- textBox_MOS_K1.Text = Convert.ToString(uData16);
- //K2
- uData16 = (ushort)(Data[9] * 256 + Data[8]);
- textBox_MOS_K2.Text = Convert.ToString(uData16);
- //K3
- uData16 = (ushort)(Data[11] * 256 + Data[10]);
- textBox_MOS_K3.Text = Convert.ToString(uData16);
- //K4
- uData16 = (ushort)(Data[13] * 256 + Data[12]);
- textBox_MOS_K4.Text = Convert.ToString(uData16);
- //K5
- uData16 = (ushort)(Data[15] * 256 + Data[14]);
- textBox_MOS_K5.Text = Convert.ToString(uData16);
- }));
- }
- break;
- }
- case 0xBD20: //整车信息2
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_BikeParam2.Clear();
- for (int i = 0; i < myParams.BikeParam2.Count; i++)
- {
- richTextBox_BikeParam2.AppendText(myParams.BikeParam2[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
- }
- richTextBox_BikeParam2.Text = richTextBox_BikeParam2.Text.Substring(0, richTextBox_BikeParam2.Text.Length - 2);
- }));
- }
- break;
- }
- case 0xBE20: //用户骑行参数
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_UsrRidesParam.Clear();
- for (int i = 0; i < myParams.UsrRideParam.Count; i++)
- {
- richTextBox_UsrRidesParam.AppendText(myParams.UsrRideParam[i] + "=" + Convert.ToString(Data[i]) + ", ");
- }
- richTextBox_UsrRidesParam.Text = richTextBox_UsrRidesParam.Text.Substring(0, richTextBox_UsrRidesParam.Text.Length - 2);
- }));
- }
- break;
- }
- case 0xBF58: //位置传感器校准值
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- string[] str1 = new string[42];
- double[] error1 = new double[42];
- //更新校准数据
- for (int i = 0; i < 42; i++)
- {
- double data1 = (Data[4 + i * 2] + (Data[4 + i * 2 + 1] << 8)) / 32767.0 * 360;
- error1[i] = data1 - (60 * (i % 6) + 60);
- if (error1[i] < -180)
- {
- error1[i] = error1[i] + 360;
- }
- str1[i] = data1.ToString("F2");
- AngledataRecord[i] = str1[i];
- }
- for (int i = 0; i < 7; i++)
- for (int j = 0; j < 6; j++)
- {
- dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = str1[6 * i + j];
- }
- //计算偏差最小值、最大值和平均值
- //Array.ConvertAll(error1, Math.Abs);
- textBox_AngleDiffMin.Text = error1.Min().ToString("F2");
- textBox_AngleDiffMax.Text = error1.Max().ToString("F2");
- textBox_AngleDiffAvg.Text = error1.Average().ToString("F2");
- //计算零点偏差
- double tmp1 = ((Int16)(Data[0] + (Data[1] << 8))) / 32767.0 * 360;
- textBox_AngleZeroInit.Text = tmp1.ToString("F2");
- double tmp2 = ((Int16)(Data[2] + (Data[3] << 8))) / 32767.0 * 360;
- textBox_AngleZeroCur.Text = tmp2.ToString("F2");
- double tmp3 = (tmp2 - tmp1);
- textBox_AngleZeroDiff.Text = tmp3.ToString("F2");
- }));
- }
- break;
- }
- case 0xC008: //故障日志地址
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- uint Addr_Begin = 0, Addr_End = 0;
- Addr_Begin = (uint)((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]);
- Addr_End = (uint)((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]);
- textBox_LogAddrBegin.Text = Convert.ToString(Addr_Begin, 16).PadLeft(8, '0').ToUpper();
- textBox_LogAddrEnd.Text = Convert.ToString(Addr_End, 16).PadLeft(8, '0').ToUpper();
- }));
- }
- break;
- }
- case 0xC109: //Boot版本信息
- {
- BootInfo = "";
- for (ushort i = 0; i < 9; i++)
- {
- BootInfo += ((char)Data[i]).ToString();
- }
- break;
- }
- case 0xC142: //功能配置表
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- //块编号
- ushort Num = (ushort)(Data[1] * 256 + Data[0]);
- comboBox_FunSet_BlockNum.SelectedIndex = Num - 1;
- //显示数据
- for (int i = 0; i < 64; i++)
- {
- dataGridView_FunSet.Rows[i / 8].Cells[i % 8 + 1].Value = Data[i + 2].ToString();
- }
- }));
- }
- break;
- }
- case 0xC220: //定制编号
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- //定制编号
- textBox_UserNum.Text = "";
- for (ushort i = 0; i < 32; i++)
- {
- textBox_UserNum.Text += ((char)Data[i]).ToString();
- }
- }));
- }
- break;
- }
- default:
- {
- break;
- }
- }
- //存储器导出数据显示
- if ((CmdTemp & 0xFF00) == 0xAB00)
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- long ByteNum = 0;
- ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
- if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
- {
- for (int i = 0; i < ByteNum; i++)
- {
- richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
- }
- }
- }));
- }
- }
- }
- #endregion
- #region 解析BMS广播的命令
- else if (ID == 0x720)
- {
- switch (CmdTemp)
- {
- case 0x1010://BMS运行信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- BMS_RunInfo_Refresh = true;
- richTextBox_OBC_BMS_RunInfo.Clear();
- //电压
- uData16 = (ushort)(Data[1] * 256 + Data[0]);
- richTextBox_OBC_BMS_RunInfo.AppendText("电压:" + Convert.ToString(uData16) + " mV" + "\r\n");
- //电流
- uData16 = (ushort)(Data[3] * 256 + Data[2]);
- richTextBox_OBC_BMS_RunInfo.AppendText("电流:" + Convert.ToString(uData16) + " mA" + "\r\n");
- //剩余容量
- uData16 = (ushort)(Data[5] * 256 + Data[4]);
- richTextBox_OBC_BMS_RunInfo.AppendText("剩余容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
- //满充容量
- uData16 = (ushort)(Data[7] * 256 + Data[6]);
- richTextBox_OBC_BMS_RunInfo.AppendText("满充容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
- //电芯温度
- richTextBox_OBC_BMS_RunInfo.AppendText("电芯温度:" + Convert.ToString((int)(Data[8] - 40) + " ℃" + "\r\n"));
- //剩余电量
- richTextBox_OBC_BMS_RunInfo.AppendText("剩余电量:" + Convert.ToString(Data[9]) + " %" + "\r\n");
- //电池状态
- richTextBox_OBC_BMS_RunInfo.AppendText("电池状态:" + Convert.ToString(Data[10], 16).PadLeft(2, '0').ToUpper() + " H" + "\r\n");
- //SOH
- richTextBox_OBC_BMS_RunInfo.AppendText("电池寿命:" + Convert.ToString(Data[11]) + " %" + "\r\n");
- //循环次数
- richTextBox_OBC_BMS_RunInfo.AppendText("循环次数:" + Convert.ToString((ushort)(Data[13] * 256 + Data[12])) + " 次");
- }));
- }
- break;
- }
- default: break;
- }
- }
- #endregion
- #region 解析电机发送OBC的命令
- else if (ID == 0x713)
- {
- switch (CmdTemp)
- {
- case 0x5408://电机用户参数
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_OBC_ReadUserInfo.Clear();
- //默认周长
- richTextBox_OBC_ReadUserInfo.AppendText("默认周长:" + Convert.ToString((int)Data[0]) + " cm" + "\r\n");
- //启动模式
- richTextBox_OBC_ReadUserInfo.AppendText("启动模式:" + ((Data[1] == 0x01) ? "柔和" : (Data[1] == 0x02) ? "正常" : (Data[1] == 0x03) ? "强劲" : "无效") + "\r\n");
- comboBox_OBC_StartMode.SelectedIndex = Data[1] - 1;
- //限速
- richTextBox_OBC_ReadUserInfo.AppendText("限速:" + Convert.ToString(Data[2]) + " km/h" + "\r\n");
- //周长微调
- numericUpDown_OBC_WheelAdj.Value = (int)(Data[3] > 128 ? (Data[3] - 256) : Data[3]);
- richTextBox_OBC_ReadUserInfo.AppendText("周长微调:" + Convert.ToString(numericUpDown_OBC_WheelAdj.Value) + " cm" + "\r\n");
- //助力方案
- richTextBox_OBC_ReadUserInfo.AppendText("助力方案:" + Convert.ToString(Data[4]) + "\r\n");
- comboBox_OBC_AssistFunc.SelectedIndex = Data[4] - 1;
- //关机时间
- richTextBox_OBC_ReadUserInfo.AppendText("关机时间:" + Convert.ToString(Data[5]) + " min" + "\r\n");
- numericUpDown_OBC_OffTime.Value = (int)Data[5];
- //限速微调
- numericUpDown_OBC_SpeedLimitAdj.Value = (int)(Data[6] > 128 ? (Data[6] - 256) : Data[6]);
- richTextBox_OBC_ReadUserInfo.AppendText("限速微调:" + Convert.ToString(numericUpDown_OBC_SpeedLimitAdj.Value) + " km/h" + "\r\n");
- //定速巡航
- comboBox_OBC_BikeCCS.SelectedIndex = (Data[7] == 0xAA) ? 1 : 2;
- richTextBox_OBC_ReadUserInfo.AppendText("转把巡航:" + comboBox_OBC_BikeCCS.Text + "\r\n");
- }));
- }
- break;
- }
- case 0x5303://电机应答反馈
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- MessageBoxTimeOut.Show("OK", "反馈指令", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
- }));
- }
- break;
- }
- case 0x5620: //用户骑行参数
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_UsrRidesParam.Clear();
- for (int i = 0; i < myParams.UsrRideParam.Count; i++)
- {
- richTextBox_UsrRidesParam.AppendText(myParams.UsrRideParam[i] + "=" + Convert.ToString(Data[i]) + ", ");
- }
- richTextBox_UsrRidesParam.Text = richTextBox_UsrRidesParam.Text.Substring(0, richTextBox_UsrRidesParam.Text.Length - 2);
- }));
- }
- break;
- }
- default: break;
- }
- }
- #endregion
- }
- private void DataRevToString(ushort CmdTemp, byte[] Data)
- {
- CmdRevStrTemp = "";
- CmdRevStrTemp += Convert.ToString(CmdTemp >> 8, 16).PadLeft(2, '0').ToUpper() + " ";
- CmdRevStrTemp += Convert.ToString(CmdTemp & 0xFF, 16).PadLeft(2, '0').ToUpper() + " ";
- ushort len = (ushort)(CmdTemp & 0x00FF);
- for (int i = 0; i < len ; i++)
- {
- CmdRevStrTemp += Convert.ToString(Data[i], 16).PadLeft(2, '0').ToUpper() + " ";
- }
- }
- #endregion
- /// <summary>
- /// 端口连接或断开
- /// </summary>
- private void PortConnect()
- {
- bool result = false;
- if (连接ToolStripMenuItem.Text == "连接")
- {
- result = mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, 连接开机ToolStripMenuItem.Checked, 识别通讯盒ToolStripMenuItem.Checked);
- if (result)
- {
- toolStripComboBox_ComNum.Enabled = false;
- toolStripComboBox_Baudrate.Enabled = false;
- 刷新ToolStripMenuItem.Enabled = false;
- 连接ToolStripMenuItem.Text = "断开";
- 连接ToolStripMenuItem.Checked = true;
- label_COM_Sta.Text = toolStripComboBox_ComNum.Text + "已连接," + toolStripComboBox_Baudrate.Text;
- label_PortStatus.BackColor = Color.Green;
- }
- }
- else if (连接ToolStripMenuItem.Text == "断开")
- {
- checkBox_OBC_StartSetGearSt.Checked = false;
- checkBox_OBC_StartReadBMS.Checked = false;
- checkBox_ReadRanFlash_AutoSW.Checked = false;
- mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
- toolStripComboBox_ComNum.Enabled = true;
- toolStripComboBox_Baudrate.Enabled = true;
- 刷新ToolStripMenuItem.Enabled = true;
- 连接ToolStripMenuItem.Text = "连接";
- 连接ToolStripMenuItem.Checked = false;
- label_COM_Sta.Text = "连接状态:未连接";
- label_PortStatus.BackColor = Color.Red;
- }
- }
- /// <summary>
- /// 端口连接事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 连接ToolStripMenuItem_Click(object sender, System.EventArgs e)
- {
- PortConnect();
- }
- /// <summary>
- /// 端口号刷新事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- toolStripComboBox_ComNum.Items.Clear();
- toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
- toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
- }
- /// <summary>
- /// 存储标志修改事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 写入存储ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- if (写入存储ToolStripMenuItem.Checked)
- {
- EnterForm1.ShowDialog();
- try
- {
- if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
- {
- if (EnterForm1.comboBox_User.Text == "工程参数配置")
- {
- 写入存储ToolStripMenuItem.Checked = false;
- ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- else
- {
- MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else
- {
- MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- catch (Exception)
- {
- MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else
- {
- 写入存储ToolStripMenuItem.Checked = true;
- ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
- }
-
- }
- /// <summary>
- /// 1s定时器
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void timer_1s_Tick(object sender, EventArgs e)
- {
- //时间更新
- label_SystemTime.Text = "系统时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
- //MC_Runinfo超时清除
- if (MC_RunInfo_Refresh == false)
- {
- MC_RunInfo_Refresh_Cnt++;
- if (MC_RunInfo_Refresh_Cnt > 10)//5s
- {
- MC_RunInfo_Clear();
- MC_RunInfo_Refresh_Cnt = 0;
- }
- }
- else
- {
- MC_RunInfo_Refresh_Cnt = 0;
- }
- MC_RunInfo_Refresh = false;
- //MC_Debuginfo超时清除
- if (MC_DebugInfo_Refresh == false)
- {
- MC_DebugInfo_Refresh_Cnt++;
- if (MC_DebugInfo_Refresh_Cnt > 10)//5s
- {
- MC_DebugInfo_Clear();
- MC_DebugInfo_Refresh_Cnt = 0;
- }
- }
- else
- {
- MC_DebugInfo_Refresh_Cnt = 0;
- }
- MC_DebugInfo_Refresh = false;
- //BMS_RunInfo超时清除
- if (BMS_RunInfo_Refresh == false)
- {
- BMS_RunInfo_Refresh_Cnt++;
- if (BMS_RunInfo_Refresh_Cnt > 10)//5s
- {
- richTextBox_OBC_BMS_RunInfo.Clear();
- BMS_RunInfo_Refresh_Cnt = 0;
- }
- }
- else
- {
- BMS_RunInfo_Refresh_Cnt = 0;
- }
- BMS_RunInfo_Refresh = false;
- //故障码超时清除
- if (MC_ErrorCode_Refresh == false)
- {
- MC_ErrorCode_Refresh_Cnt++;
- if (MC_ErrorCode_Refresh_Cnt > 10)//5s
- {
- textBox_ErrorCode.Text = "---";
- MC_ErrorCode_Refresh_Cnt = 0;
- }
- }
- else
- {
- MC_ErrorCode_Refresh_Cnt = 0;
- }
- MC_ErrorCode_Refresh = false;
- //CDL连接超时
- if (识别通讯盒ToolStripMenuItem.Checked)
- {
- if (mySerialProcess.CDL_Online_Flag == false)
- {
- mySerialProcess.CDL_OnlineCheck_Cnt++;
- if (mySerialProcess.CDL_OnlineCheck_Cnt > 1)//1s
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("连接失败!", "提示");
- timer_500ms.Enabled = true;
- //关闭串口
- mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
- toolStripComboBox_ComNum.Enabled = true;
- toolStripComboBox_Baudrate.Enabled = true;
- 刷新ToolStripMenuItem.Enabled = true;
- 连接ToolStripMenuItem.Text = "连接";
- 连接ToolStripMenuItem.Checked = false;
- label_COM_Sta.Text = "连接状态:未连接";
- label_PortStatus.BackColor = Color.Red;
- }
- }
- }
- //OBC定时发送设置档位
- if (checkBox_OBC_StartSetGearSt.Checked == true)
- {
- var CtrlCode = new byte[2];
- if (comboBox_OBC_SetGearST.SelectedIndex == 5)//档位
- CtrlCode[0] = 0x33;
- else if (comboBox_OBC_SetGearST.SelectedIndex == 6)//档位
- CtrlCode[0] = 0x22;
- else
- CtrlCode[0] = (byte)comboBox_OBC_SetGearST.SelectedIndex;
- if (comboBox_OBC_LightSw.SelectedIndex == 0)//车灯
- CtrlCode[1] = 0xF1;
- else
- CtrlCode[1] = 0xF0;
- if (!mySerialProcess.SendCmdWithoutNotice((ushort)0x731, (byte)0x0C, (ushort)0x3002, CtrlCode))
- {
- checkBox_OBC_StartSetGearSt.Checked = false;
- }
- }
- //OBC定时发送查询电池
- if (checkBox_OBC_StartReadBMS.Checked == true)
- {
- if (!mySerialProcess.SendCmd((ushort)0x732, (byte)0x11, (ushort)0x5000, null))
- {
- checkBox_OBC_StartReadBMS.Checked = false;
- }
- }
- //定时读取存储器
- if (checkBox_ReadRanFlash_AutoSW.Checked == true)
- {
- var Address = new byte[4];
- UInt32 Address_Begin;
- UInt32 Addres_End;
- if (checkBox_ReadRanFlash_AutoClear.Checked == true)
- richTextBox_RamFlasgData.Clear();
- do
- {
- if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
- {
- checkBox_ReadRanFlash_AutoSW.Checked = false;
- MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- continue;
- }
- else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
- {
- checkBox_ReadRanFlash_AutoSW.Checked = false;
- MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- continue;
- }
- else
- {
- Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
- Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
- Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
- Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
- if (Addres_End < Address_Begin)
- {
- checkBox_ReadRanFlash_AutoSW.Checked = false;
- MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- continue;
- }
- else
- {
- var SendByte = new byte[8];
- SendByte[0] = (byte)(Address_Begin >> 24);
- SendByte[1] = (byte)(Address_Begin >> 16);
- SendByte[2] = (byte)(Address_Begin >> 8);
- SendByte[3] = (byte)(Address_Begin);
- SendByte[4] = (byte)(Addres_End >> 24);
- SendByte[5] = (byte)(Addres_End >> 16);
- SendByte[6] = (byte)(Addres_End >> 8);
- SendByte[7] = (byte)(Addres_End);
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte))
- checkBox_ReadRanFlash_AutoSW.Checked = false;
- }
- }
- } while (false);
- }
- //写入参数等待计时
- ACK_WaitCnt++;
- }
- /// <summary>
- /// 运行信息清除
- /// </summary>
- private void MC_RunInfo_Clear()
- {
- foreach (Control c in tabPage_RunInfo.Controls)
- {
- if ((c is TextBox))
- {
- if (c.Name != textBox_ErrorCode.ToString())
- c.Text = "---";
- }
- }
- }
- /// <summary>
- /// 调试信息清除
- /// </summary>
- private void MC_DebugInfo_Clear()
- {
- foreach (Control c in tabPage_DebugInfo.Controls)
- {
- if ((c is TextBox))
- {
- if (c.Name != textBox_ErrorCode.ToString())
- c.Text = "---";
- }
- }
- }
- /// <summary>
- /// 读取马达参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_Read_MotorParam_Click(object sender, EventArgs e)
- {
- richTextBox_MotorParam.Clear();
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null);
- }
- /// <summary>
- /// 写入马达参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_Write_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[40];
- for (int i = 0; i < 40; i++)
- ConfigParam[i] = 0;
- ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
- short wDataTemp = 0;
- ushort DataTemp = 0;
- string[] strDataTemp = richTextBox_MotorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- if (i == 6)
- {
- wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
- ConfigParam[2 * i + 2] = (byte)wDataTemp;
- ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
- }
- else
- {
- DataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
- ConfigParam[2 * i + 2] = (byte)DataTemp;
- ConfigParam[2 * i + 3] = (byte)(DataTemp >> 8);
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B28, ConfigParam);
- }
- catch (Exception)
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_500ms.Enabled = true;
- }
- }
- /// <summary>
- /// 读取整车信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadBikeParam_Click(object sender, EventArgs e)
- {
- richTextBox_BikeParam.Clear();
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null);
- }
- /// <summary>
- /// 写入整车信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteBikeParam_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[28];
- for (int i = 0; i < 28; i++)
- ConfigParam[i] = 0;
- ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
- string[] strDataTemp = richTextBox_BikeParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- short wDataTemp = 0;
- //前后灯参数修改
- if (i == 8)
- {
- wDataTemp |= (short)((comboBox_TailLightMode.SelectedIndex + 1) << 12); //Bit15~Bit12:尾灯模式
- wDataTemp |= (short)((comboBox_TailLightVol.SelectedIndex == 0 ? 6 : 12) << 8); //Bit11~Bit8:尾灯电压
- wDataTemp |= (short)(comboBox_FrontLightVol.SelectedIndex == 0 ? 6 : 12); //Bit7~Bit0:前灯电压
- }
- //开关机参数
- else if (i == 11)
- {
- wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOnDelay.Text) << 12);
- wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOffDelay.Text) << 8);
- wDataTemp |= (short)(Convert.ToInt16(textBox_AutoPowerOff.Text));
- }
- else
- {
- wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
- }
- ConfigParam[2 * i + 2] = (byte)wDataTemp;
- ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D1C, ConfigParam);
- }
- catch (Exception)
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_500ms.Enabled = true;
- }
- }
- /// <summary>
- /// 读取控制器参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadControlParam_Click(object sender, EventArgs e)
- {
- richTextBox_ControlParam.Clear();
- comboBox_Bike_CCS.SelectedIndex = 0;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
- }
- /// <summary>
- /// 写入控制器参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteControlParam_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[34];
- for (int i = 0; i < 34; i++)
- ConfigParam[i] = 0;
- ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
- ushort uwDataTemp = 0;
- string[] strDataTemp = richTextBox_ControlParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- if (i == 13)
- {
- uwDataTemp = (comboBox_Bike_CCS.SelectedIndex == 1) ? (ushort)0x00AA : (ushort)0x0000;
- }
- else
- {
- uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
- }
-
- ConfigParam[2 * i + 2] = (byte)uwDataTemp;
- ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3F22, ConfigParam);
- }
- catch (Exception)
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_500ms.Enabled = true;
- }
- }
- /// <summary>
- /// 读取助力参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadAssistParam_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[4];
- int AssistNum = 0;
- try
- {
- AssistNum = Convert.ToInt32(comboBox_AssistTorque.Text);
- ConfigParam[0] = (byte)(AssistNum & 0xFF);
- ConfigParam[1] = (byte)(AssistNum >> 8);
- AssistNum = Convert.ToInt32(comboBox_AssistCadence.Text);
- ConfigParam[2] = (byte)(AssistNum & 0xFF);
- ConfigParam[3] = (byte)(AssistNum >> 8);
- richTextBox_AssistParam.Clear();
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam);
- }
- catch (Exception)
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("请选择助力参数编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_500ms.Enabled = true;
- }
- }
- /// <summary>
- /// 写入助力参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteAssistParam_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[80];
- for (int i = 0; i < 80; i++)
- ConfigParam[i] = 0;
- ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
- long lDataTemp = 0;
- string[] strDataTemp = richTextBox_AssistParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
- int index_1 = 0, index_2 = 0;
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- if (strDataTemp[i].Split('=')[0] == "转矩曲线.a")
- {
- index_1 = i;
- break;
- }
- }
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- if (strDataTemp[i].Split('=')[0] == "踏频曲线.d")
- {
- index_2 = i;
- break;
- }
- }
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- lDataTemp = Convert.ToInt32(strDataTemp[i].Split('=')[1]);
- if (i < index_1)
- {
- ConfigParam[2 * i + 4] = (byte)lDataTemp;
- ConfigParam[2 * i + 5] = (byte)(lDataTemp >> 8);
- }
- else if (i <= index_2)
- {
- ConfigParam[4 * i - 4] = (byte)lDataTemp;
- ConfigParam[4 * i - 3] = (byte)(lDataTemp >> 8);
- ConfigParam[4 * i - 2] = (byte)(lDataTemp >> 16);
- ConfigParam[4 * i - 1] = (byte)(lDataTemp >> 24);
- }
- else
- {
- ConfigParam[2 * i + 20] = (byte)lDataTemp;
- ConfigParam[2 * i + 21] = (byte)(lDataTemp >> 8);
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4450, ConfigParam);
- }
- catch (Exception)
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_500ms.Enabled = true;
- }
- }
- /// <summary>
- /// 读取调试参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadDebugParam_Click(object sender, EventArgs e)
- {
- richTextBox_DebugParam.Clear();
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
- }
- /// <summary>
- /// 写入调试参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteDebugParam_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[60];
- for (int i = 0; i < 60; i++)
- ConfigParam[i] = 0;
- ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
- ushort uwDataTemp = 0;
- string[] strDataTemp = richTextBox_DebugParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
- ConfigParam[2 * i + 2] = (byte)uwDataTemp;
- ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam);
- }
- catch (Exception)
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_500ms.Enabled = true;
- }
- }
- /// <summary>
- /// 读取历史
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadRecord_Click(object sender, EventArgs e)
- {
- richTextBox_Record.Clear();
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null);
- }
- /// <summary>
- /// 读取传感器参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadSensorParam_Click(object sender, EventArgs e)
- {
- richTextBox_SensorParam.Clear();
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
- }
- /// <summary>
- /// 写入力矩传感器标定值
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_Write_Cal_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[4];
- for (int i = 0; i < 4; i++)
- ConfigParam[i] = 0;
- ushort uwDataTemp = 0;
- try
- {
- uwDataTemp = Convert.ToUInt16(comboBox_TorqueSet.Text);//负载序号
- ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
- ConfigParam[1] = (byte)(uwDataTemp >> 8);
- uwDataTemp = (ushort)(decimal.Parse(textBox_Load.Text) * 10); ;//负载值0.1Nm
- ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
- ConfigParam[3] = (byte)(uwDataTemp >> 8);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
- }
- catch (Exception)
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_500ms.Enabled = true;
- }
- }
- /// <summary>
- /// 写入传感器参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteSensorParam_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[14];
- for (int i = 0; i < 14; i++)
- ConfigParam[i] = 0;
- ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
- ushort uwDataTemp = 0;
- //力矩传感器参数只写入前面14项与力矩传感器相关的参数
- string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
- int index = 0;
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- if (strDataTemp[i].Split('=')[0] == "力矩传感器踏频脉冲数")
- {
- index = i;
- break;
- }
- }
- for (int i = 0; i < (strDataTemp.Length - index); i++)
- {
- uwDataTemp = Convert.ToUInt16(strDataTemp[i + index].Split('=')[1]);
- ConfigParam[2 * i + 2] = (byte)uwDataTemp;
- ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x420E, ConfigParam);
- }
- catch (Exception)
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_500ms.Enabled = true;
- }
- }
- /// <summary>
- /// 写入型号
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteModel_Click(object sender, EventArgs e)
- {
- string Mode = textBox_Model.Text;
- var ModeArray = new byte[16];
- for (ushort i = 0; i < Mode.Length; i++)
- {
- ModeArray[i] = (byte)Mode[i];
- }
- if (Mode.Length < 16)
- {
- ModeArray[Mode.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
- {
- ModeArray[Mode.Length + 1 + i] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
- }
- /// <summary>
- /// 写入SN
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteSN_Click(object sender, EventArgs e)
- {
- string SN = textBox_SN.Text;
- var SNArray = new byte[16];
- for (ushort i = 0; i < SN.Length; i++)
- {
- SNArray[i] = (byte)SN[i];
- }
- if (SN.Length < 16)
- {
- SNArray[SN.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - SN.Length - 1; i++)
- {
- SNArray[SN.Length + 1 + i] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
- }
- /// <summary>
- /// 查询版本信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadVersion_Click(object sender, EventArgs e)
- {
- textBox_Model.Text = "---";
- textBox_SN.Text = "---";
- textBox_HW.Text = "---";
- textBox_FW.Text = "---";
- textBox_SP.Text = "---";
- textBox_OBC_ReadModel.Text = "---";
- textBox_OBC_ReadSN.Text = "---";
- textBox_OBC_ReadHW.Text = "---";
- textBox_OBC_ReadFW.Text = "---";
- textBox_OBC_ReadSP.Text = "---";
- textBox_FacModeName.Text = "---";
- textBox_FacModeNum.Text = "---";
- textBox_FacModeHW.Text = "---";
- textBox_FacModeFW.Text = "---";
- textBox_FacModeSP.Text = "---";
- Class_Motor_Ver.Mode = "---";
- Class_Motor_Ver.SN = "---";
- Class_Motor_Ver.HW = "---";
- Class_Motor_Ver.FW = "---";
- Class_Motor_Ver.Special = "---";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
- }
- /// <summary>
- /// 查询自定义1
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadUser1_Click(object sender, EventArgs e)
- {
- textBox_User1.Text = "---";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null);
- }
- /// <summary>
- /// 查询自定义2
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadUser2_Click(object sender, EventArgs e)
- {
- textBox_User2.Text = "---";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null);
- }
- /// <summary>
- /// 查询自定义3
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadUser3_Click(object sender, EventArgs e)
- {
- textBox_User3.Text = "---";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null);
- }
- /// <summary>
- /// 写入自定义字符串1
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteUser1_Click(object sender, EventArgs e)
- {
- string User = textBox_User1.Text;
- var UserArray = new byte[16];
- for (ushort i = 0; i < User.Length; i++)
- {
- UserArray[i] = (byte)User[i];
- }
- if (User.Length < 16)
- {
- UserArray[User.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - User.Length - 1; i++)
- {
- UserArray[User.Length + 1 + i] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1410, UserArray);
- }
- /// <summary>
- /// 写入自定义字符串2
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteUser2_Click(object sender, EventArgs e)
- {
- string User = textBox_User2.Text;
- var UserArray = new byte[16];
- for (ushort i = 0; i < User.Length; i++)
- {
- UserArray[i] = (byte)User[i];
- }
- if (User.Length < 16)
- {
- UserArray[User.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - User.Length - 1; i++)
- {
- UserArray[User.Length + 1 + i] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1610, UserArray);
- }
- /// <summary>
- /// 写入自定义字符串3
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteUser3_Click(object sender, EventArgs e)
- {
- string User = textBox_User3.Text;
- var UserArray = new byte[16];
- for (ushort i = 0; i < User.Length; i++)
- {
- UserArray[i] = (byte)User[i];
- }
- if (User.Length < 16)
- {
- UserArray[User.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - User.Length - 1; i++)
- {
- UserArray[User.Length + 1 + i] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1810, UserArray);
- }
- /// <summary>
- /// 查询生产信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadMAC_Click(object sender, EventArgs e)
- {
- textBox_MAC.Text = "---";
- textBox_MACAdd.Text = "---";
- textBox_MACDate.Text = "---";
- textBox_PP.Text = "---";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null);
- }
- /// <summary>
- /// 写入生产信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteMac_Click(object sender, EventArgs e)
- {
- var MACArray = new byte[32];
- //填入生产商
- for (ushort i = 0; i < textBox_MAC.Text.Length; i++)
- {
- MACArray[i] = (byte)textBox_MAC.Text[i];
- }
- if (textBox_MAC.Text.Length < 8)
- {
- MACArray[textBox_MAC.Text.Length] = (byte)'.';
- for (ushort i = 0; i < 8 - textBox_MAC.Text.Length - 1; i++)
- {
- MACArray[textBox_MAC.Text.Length + 1 + i] = 0x20;
- }
- }
- //填入生产地
- for (ushort i = 0; i < textBox_MACAdd.Text.Length; i++)
- {
- MACArray[8 + i] = (byte)textBox_MACAdd.Text[i];
- }
- if (textBox_MACAdd.Text.Length < 8)
- {
- MACArray[textBox_MACAdd.Text.Length + 8] = (byte)'.';
- for (ushort i = 0; i < 8 - textBox_MACAdd.Text.Length - 1; i++)
- {
- MACArray[textBox_MACAdd.Text.Length + 1 + i + 8] = 0x20;
- }
- }
- //填入生产日期
- for (ushort i = 0; i < textBox_MACDate.Text.Length; i++)
- {
- MACArray[16 + i] = (byte)textBox_MACDate.Text[i];
- }
- if (textBox_MACDate.Text.Length < 8)
- {
- MACArray[textBox_MACDate.Text.Length + 16] = (byte)'.';
- for (ushort i = 0; i < 8 - textBox_MACDate.Text.Length - 1; i++)
- {
- MACArray[textBox_MACDate.Text.Length + 1 + i + 16] = 0x20;
- }
- }
- //填入品牌
- for (ushort i = 0; i < textBox_PP.Text.Length; i++)
- {
- MACArray[24 + i] = (byte)textBox_PP.Text[i];
- }
- if (textBox_PP.Text.Length < 8)
- {
- MACArray[textBox_PP.Text.Length + 24] = (byte)'.';
- for (ushort i = 0; i < 8 - textBox_PP.Text.Length - 1; i++)
- {
- MACArray[textBox_PP.Text.Length + 1 + i + 24] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
- }
- /// <summary>
- /// 查询密钥
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadKey_Click(object sender, EventArgs e)
- {
- textBox_Key.Text = "---";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null);
- }
- /// <summary>
- /// 写入校验密钥
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteKey_Click(object sender, EventArgs e)
- {
- string Key = textBox_Key.Text;
- var KeyArray = new byte[8];
- if (Key.Length != 8)
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("请检查字符长度是否为8", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_500ms.Enabled = true;
- return;
- }
- for (ushort i = 0; i < Key.Length; i++)
- {
- KeyArray[i] = (byte)Key[i];
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1108, KeyArray);
- }
- /// <summary>
- /// 查询在线检测结果
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadOnLine_Click(object sender, EventArgs e)
- {
- textBox_Online.Text = "---";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2100, null);
- }
- /// <summary>
- /// 系统清除
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_SystemClear_Click(object sender, EventArgs e)
- {
- var Code = new byte[5];
- Code[0] = (byte)'C';
- Code[1] = (byte)'L';
- Code[2] = (byte)'E';
- Code[3] = (byte)'A';
- Code[4] = (byte)'R';
- timer_500ms.Enabled = false;
- if (MessageBox.Show("系统清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
- MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- }
- timer_500ms.Enabled = true;
- }
- /// <summary>
- /// 参数还原
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_Recovery_Click(object sender, EventArgs e)
- {
- var Code = new byte[8];
- Code[0] = (byte)'R';
- Code[1] = (byte)'E';
- Code[2] = (byte)'C';
- Code[3] = (byte)'O';
- Code[4] = (byte)'V';
- Code[5] = (byte)'E';
- Code[6] = (byte)'R';
- Code[7] = (byte)'Y';
- timer_500ms.Enabled = false;
- if (MessageBox.Show("参数还原后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- if (MessageBox.Show("请再次确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- if (MessageBox.Show("请最后确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2708, Code);
- MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- }
- timer_500ms.Enabled = true;
- }
- /// <summary>
- /// 系统复位
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_Reset_Click(object sender, EventArgs e)
- {
- var Code_Off = new byte[5];
- var Code_Reset = new byte[5];
- Code_Off[0] = (byte)'O';
- Code_Off[1] = (byte)'F';
- Code_Off[2] = (byte)'F';
- Code_Off[3] = (byte)'.';
- Code_Off[4] = (byte)'.';
- Code_Reset[0] = (byte)'R';
- Code_Reset[1] = (byte)'E';
- Code_Reset[2] = (byte)'S';
- Code_Reset[3] = (byte)'E';
- Code_Reset[4] = (byte)'T';
- timer_500ms.Enabled = false;
- if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- timer_500ms.Enabled = true;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
- PowerOffAckStatus = false;
- Delay_ms(250);
- int TryCnt = 3;
- while ((TryCnt--) >= 0)
- {
- if (!PowerOffAckStatus)
- {
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
- PowerOffAckStatus = false;
- Delay_ms(250);
- }
- else break;
- }
- if (PowerOffAckStatus)
- {
- MessageBoxTimeOut.Show("已关机!", "提示", 3000, MessageBoxButtons.OK, MessageBoxIcon.None);
- }
- else
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_500ms.Enabled = true;
- }
- }
- timer_500ms.Enabled = true;
- }
- /// <summary>
- /// 记录清除
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ClearLog_Click(object sender, EventArgs e)
- {
- var Code = new byte[9];
- Code[0] = (byte)'L';
- Code[1] = (byte)'O';
- Code[2] = (byte)'G';
- Code[3] = (byte)' ';
- Code[4] = (byte)'C';
- Code[5] = (byte)'L';
- Code[6] = (byte)'E';
- Code[7] = (byte)'A';
- Code[8] = (byte)'R';
- timer_500ms.Enabled = false;
- if (MessageBox.Show("历史记录信息清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3909, Code);
- MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- }
- timer_500ms.Enabled = true;
- }
- /// <summary>
- /// 打开系统计算器
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 计算器ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- System.Diagnostics.Process.Start("calc.exe");
- }
- /// <summary>
- ///故障转换和显示
- /// </summary>
- List<string> ErrorInfo = new List<string>{ "过流保护", "低压保护", "过压保护", "堵转保护","过热保护","速度传感器故障","力矩传感器故障","霍尔故障",
- "马达缺相","NTC故障","BMS校验失败","","OBC校验失败","MCU故障","踏频传感器故障","指拨故障","MOS短路","电压异常","","","","","","","","","","","","",
- "",""};
- private string ErrorInfoDisplay(UInt32 Code)
- {
- string Result = "";
- if (Code == 0)
- {
- Result = "无故障";
- }
- else
- {
- for (int i = 0; i < 32; i++)
- {
- if ((Code & 0x01) == 0x01)
- {
- Result += ErrorInfo[i] + " ";
- }
- Code >>= 1;
- }
- }
- return Result;
- }
- /// <summary>
- /// 鼠标滑过故障码显示具体内容
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void textBox_ErrorCode_MouseHover(object sender, EventArgs e)
- {
- // 创建the ToolTip
- ToolTip toolTip1 = new ToolTip();
- // 设置显示样式
- toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
- toolTip1.InitialDelay = 50;//事件触发多久后出现提示
- toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
- toolTip1.ShowAlways = true;//是否显示提示框
- // 设置伴随的对象.
- string ErrorCode = this.textBox_ErrorCode.Text;
- UInt32 Code = ErrorCode.Contains("H") ? Convert.ToUInt32(ErrorCode.Split('H')[0], 16) : 0;
- toolTip1.SetToolTip(this.textBox_ErrorCode, ErrorInfoDisplay(Code));//设置故障内容显示
- }
- /// <summary>
- /// 数据记录
- /// </summary>
- private void RunInfoAutoSave()
- {
- if (运行信息记录ToolStripMenuItem.Checked == true)
- {
- if (RunInfoSaveFilename == string.Empty)
- {
- return;
- }
- string SaveData = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff").Replace(" ", "_") + " --> ";
- foreach (Control c in tabPage_RunInfo.Controls)
- {
- if (c is TextBox)
- {
- SaveData += c.Text + " , ";
- }
- }
- foreach (Control c in tabPage_DebugInfo.Controls)
- {
- if (c is TextBox)
- {
- SaveData += c.Text + " , ";
- }
- }
- SaveData += "\r\n";
- System.IO.File.AppendAllText(RunInfoSaveFilename, SaveData);//sb.ToString());
- }
- }
- /// <summary>
- /// 打开或关闭数据记录
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- if (运行信息记录ToolStripMenuItem.Checked == false)
- {
- if (mySerialProcess.mySerial.IsOpen == true)
- {
- RunInfoSaveFilename = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_运行信息" + ".txt";
- System.IO.File.AppendAllText(RunInfoSaveFilename, "时间 --> 车速 , 转速 , 踏频 , 力矩Reg , 力矩 , 踩踏方向 , 电压 , 电流 , 功率 , 电量 , " +
- "PCB温度 , 绕组温度 , MOS温度 , 挡位 , 灯开关 , 续航 , 平均功耗 , 单次里程 , 单次时间 , 故障码 , " +
- "系统状态机 , 二层状态机 , 电机状态机 , 助力状态机 , D轴电流给定 , Q轴电流给定 , D轴电压给定 , Q轴电压给定 , 瞬时力矩 , 时间滤波力矩 , 踏频滤波力矩 , D轴电流反馈 , Q轴电流反馈 , 助力函数输出" + "\r\n");
- MessageBoxTimeOut.Show("开始记录", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
- 运行信息记录ToolStripMenuItem.Checked = true;
- }
- else
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("请连接电机", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- timer_500ms.Enabled = true;
- }
- }
- else
- {
- 运行信息记录ToolStripMenuItem.Checked = false;
- MessageBoxTimeOut.Show("停止记录", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- /// <summary>
- /// 仪表启动控制档位开关事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void checkBox_OBC_StartSetGearSt_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_OBC_StartSetGearSt.Checked == true)
- {
- //检查串口是否打开
- if (!mySerialProcess.mySerial.IsOpen)
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_500ms.Enabled = true;
- checkBox_OBC_StartSetGearSt.Checked = false;
- return;
- }
- //检查是否选择档位和打开车灯
- if ((comboBox_OBC_SetGearST.SelectedIndex == -1) || (comboBox_OBC_LightSw.SelectedIndex == -1))
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("请检查档位设置和大灯开关!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_500ms.Enabled = true;
- checkBox_OBC_StartSetGearSt.Checked = false;
- return;
- }
- }
- }
- /// <summary>
- /// OBC查询电机用户参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_ReadUserInfo_Click(object sender, EventArgs e)
- {
- richTextBox_OBC_ReadUserInfo.Clear();
- comboBox_OBC_BikeCCS.SelectedIndex = 0;
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3300, null);
- }
- /// <summary>
- /// OBC设置电机用户参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_WriteUserInfo_Click(object sender, EventArgs e)
- {
- var UserInfoCode = new byte[8];
- for (int i = 0; i < UserInfoCode.Length; i++)
- UserInfoCode[i] = 0;
- if (comboBox_OBC_StartMode.SelectedIndex == -1)//检查数据有效性
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("请选择启动模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_500ms.Enabled = true;
- return;
- }
- if (comboBox_OBC_AssistFunc.SelectedIndex == -1)//检查数据有效性
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("请选择助力方案!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_500ms.Enabled = true;
- return;
- }
- //周长微调
- UserInfoCode[0] = (byte)(int)numericUpDown_OBC_WheelAdj.Value;
- //启动模式
- UserInfoCode[1] = (byte)(comboBox_OBC_StartMode.SelectedIndex + 1);
- //助力方案
- UserInfoCode[2] = (byte)(comboBox_OBC_AssistFunc.SelectedIndex + 1);
- //自动关机时间
- UserInfoCode[3] = (byte)(uint)numericUpDown_OBC_OffTime.Value;
- //限速微调
- UserInfoCode[4] = (byte)(int)numericUpDown_OBC_SpeedLimitAdj.Value;
- //定速巡航开关
- UserInfoCode[5] = (byte)((comboBox_OBC_BikeCCS.SelectedIndex == 1) ? 0xAA : 0x00);
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3408, UserInfoCode);
- }
- /// <summary>
- /// OBC查询电机版本信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_ReadVerInfo_Click(object sender, EventArgs e)
- {
- textBox_Model.Text = "---";
- textBox_SN.Text = "---";
- textBox_HW.Text = "---";
- textBox_FW.Text = "---";
- textBox_SP.Text = "---";
- textBox_OBC_ReadModel.Text = "---";
- textBox_OBC_ReadSN.Text = "---";
- textBox_OBC_ReadHW.Text = "---";
- textBox_OBC_ReadFW.Text = "---";
- textBox_OBC_ReadSP.Text = "---";
- textBox_FacModeName.Text = "---";
- textBox_FacModeNum.Text = "---";
- textBox_FacModeHW.Text = "---";
- textBox_FacModeFW.Text = "---";
- textBox_FacModeSP.Text = "---";
- Class_Motor_Ver.Mode = "---";
- Class_Motor_Ver.SN = "---";
- Class_Motor_Ver.HW = "---";
- Class_Motor_Ver.FW = "---";
- Class_Motor_Ver.Special = "---";
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
- }
- /// <summary>
- /// OBC读取骑行历史
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_ReadRideInfo_Click(object sender, EventArgs e)
- {
- textBox_OBC_TRIP_KM.Text = "";
- textBox_OBC_TRIP_TIME.Text = "";
- textBox_OBC_ODO_KM.Text = "";
- textBox_OBC_ODO_TIME.Text = "";
- textBox_ODO_KM.Text = "---";
- textBox_ODO_TIME.Text = "---";
- textBox_TRIP_KM.Text = "---";
- textBox_TRIP_TIME.Text = "---";
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3500, null);
- }
- /// <summary>
- /// OBC清除TRIP里程
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_ClearTrip_Click(object sender, EventArgs e)
- {
- var Code = new byte[5];
- Code[0] = (byte)'C';
- Code[1] = (byte)'L';
- Code[2] = (byte)'E';
- Code[3] = (byte)'A';
- Code[4] = (byte)'R';
- timer_500ms.Enabled = false;
- if (MessageBox.Show("TRIP清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3605, Code);
- timer_500ms.Enabled = true;
- }
- private void checkBox_OBC_StartReadBMS_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_OBC_StartReadBMS.Checked == true)
- {
- //检查串口是否打开
- if (!mySerialProcess.mySerial.IsOpen)
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_500ms.Enabled = true;
- checkBox_OBC_StartReadBMS.Checked = false;
- return;
- }
- }
- }
- /// <summary>
- /// 写入力矩传感器参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteTqSensorParam_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[46];
- for (int i = 0; i < 14; i++)
- ConfigParam[i] = 0;
- ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
- ushort uwDataTemp = 0;
- //力矩传感器参数只写入前面14项与力矩传感器相关的参数
- string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
- int index = 0;
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- if (strDataTemp[i].Split('=')[0] == "第四阶段转矩点采集值")
- {
- index = i;
- break;
- }
- }
- for (int i = 0; i < (index + 1); i++)
- {
- uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
- ConfigParam[2 * i + 2] = (byte)uwDataTemp;
- ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x472E, ConfigParam);
- }
- catch (Exception)
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_500ms.Enabled = true;
- }
- }
- /// <summary>
- /// 查询存储标志
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadSaveFlag_Click(object sender, EventArgs e)
- {
- radioButton_EE_SaveYes.Checked = false;
- radioButton_EE_SaveNo.Checked = false;
- radioButton_SIP_SaveYes.Checked = false;
- radioButton_SIP_SaveNo.Checked = false;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null);
- }
- /// <summary>
- /// 写入存储标志
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteSaveFlag_Click(object sender, EventArgs e)
- {
- var SaveFlag = new byte[6];
- for (int i = 0; i < 6; i++)
- SaveFlag[i] = 0;
- if ((radioButton_EE_SaveYes.Checked == false) && (radioButton_EE_SaveNo.Checked == false))
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("请选择EEPROM存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_500ms.Enabled = true;
- return;
- }
- if ((radioButton_SIP_SaveYes.Checked == false) && (radioButton_SIP_SaveNo.Checked == false))
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("请选择SIP校验存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_500ms.Enabled = true;
- return;
- }
- SaveFlag[0] = (byte)((checkBox_SaveYes.Checked) ? 0x01 : 0x00);
- SaveFlag[2] = (byte)(radioButton_EE_SaveYes.Checked ? 0x01 : 0x00);
- SaveFlag[3] = 0;
- SaveFlag[4] = (byte)(radioButton_SIP_SaveYes.Checked ? 0x01 : 0x00);
- SaveFlag[5] = 0;
- timer_500ms.Enabled = false;
- if (MessageBox.Show("确认修改存储标志?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4906, SaveFlag);
- }
- timer_500ms.Enabled = true;
- }
- /// <summary>
- /// 读取指定地址数据
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadRamFlash_Click(object sender, EventArgs e)
- {
- var Address = new byte[4];
- UInt32 Address_Begin;
- UInt32 Addres_End;
- if (checkBox_ReadRanFlash_AutoClear.Checked == true)
- richTextBox_RamFlasgData.Clear();
- if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_500ms.Enabled = true;
- return;
- }
- else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_500ms.Enabled = true;
- return;
- }
- else
- {
- Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
- Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
- Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
- Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
- if (Addres_End < Address_Begin)
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_500ms.Enabled = true;
- return;
- }
- else
- {
- var SendByte = new byte[8];
- SendByte[0] = (byte)(Address_Begin >> 24);
- SendByte[1] = (byte)(Address_Begin >> 16);
- SendByte[2] = (byte)(Address_Begin >> 8);
- SendByte[3] = (byte)(Address_Begin);
- SendByte[4] = (byte)(Addres_End >> 24);
- SendByte[5] = (byte)(Addres_End >> 16);
- SendByte[6] = (byte)(Addres_End >> 8);
- SendByte[7] = (byte)(Addres_End);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
- }
- }
- }
- /// <summary>
- /// 工作模式选择
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void comboBox_WorkMode_SelectedIndexChanged(object sender, EventArgs e)
- {
- var RunMode = new byte[1];
- if (comboBox_WorkMode.Text == "配置模式")
- RunMode[0] = 0x01;
- else if (comboBox_WorkMode.Text == "调试模式")
- RunMode[0] = 0x02;
- else
- RunMode[0] = 0x00;
- mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
- }
- /// <summary>
- /// 助力档位选择
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void comboBox_GearSt_SelectedIndexChanged(object sender, EventArgs e)
- {
- var CtrlCode = new byte[2];
- if (comboBox_GearSt.SelectedIndex == 5)//档位
- CtrlCode[0] = 0x33;
- else if (comboBox_GearSt.SelectedIndex == 6)//档位
- CtrlCode[0] = 0x22;
- else
- CtrlCode[0] = (byte)comboBox_GearSt.SelectedIndex;
- if (comboBox_LightSwitch.SelectedIndex == 0)//车灯
- CtrlCode[1] = 0xF1;
- else
- CtrlCode[1] = 0xF0;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
- comboBox_OBC_SetGearST.SelectedIndex = comboBox_GearSt.SelectedIndex;
- comboBox_OBC_LightSw.SelectedIndex = comboBox_LightSwitch.SelectedIndex;
- Delay_ms(500);
- //设置百分比
- do
- {
- var PercentCode = new byte[1];
- if (comboBox_GearSt.SelectedIndex == 0) //Off
- {
- PercentCode[0] = 0;
- textBox_MotorSpeedPercent.Text = "0";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, PercentCode);
- }
- else if (comboBox_GearSt.SelectedIndex == 6) //Walk
- {
- if (comboBox_WorkMode.SelectedIndex != 0)
- {
- PercentCode[0] = 100;
- textBox_MotorSpeedPercent.Text = "100";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, PercentCode);
- }
- }
- } while (false);
- }
- /// <summary>
- /// 仪表档位选择
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void comboBox_OBC_SetGearST_SelectedIndexChanged(object sender, EventArgs e)
- {
- comboBox_GearSt.SelectedIndex = comboBox_OBC_SetGearST.SelectedIndex;
- comboBox_LightSwitch.SelectedIndex = comboBox_OBC_LightSw.SelectedIndex;
- }
- /// <summary>
- /// 生产模式初始化
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_FacModeInit_Click(object sender, EventArgs e)
- {
- var Code = new byte[5];
- Code[0] = (byte)'C';
- Code[1] = (byte)'L';
- Code[2] = (byte)'E';
- Code[3] = (byte)'A';
- Code[4] = (byte)'R';
- timer_500ms.Enabled = false;
- if (MessageBox.Show("电机即将初始化!", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- if (MessageBox.Show("请再次确认", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- timer_500ms.Enabled = true;
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
- PowerOffAckStatus = false;
- Delay_ms(250);
- int TryCnt = 3;
- while ((TryCnt--) >= 0)
- {
- if (!PowerOffAckStatus)
- {
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
- PowerOffAckStatus = false;
- Delay_ms(250);
- }
- else break;
- }
- if (PowerOffAckStatus)
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("系统已关机,请保持无负载重新开机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
- timer_500ms.Enabled = true;
- }
- else
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("初始化失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_500ms.Enabled = true;
- }
- timer_500ms.Enabled = true;
- }
- }
- timer_500ms.Enabled = true;
- //清除历史测试记录
- textBox_FacModeSensorADC0.Text = "";
- textBox_FacModeSensorADC1.Text = "";
- textBox_FacModeSensorADC2.Text = "";
- textBox_FacModeSensorADC3.Text = "";
- textBox_FacModeSensorADC4.Text = "";
- LightSwitchStatus = false;
- MotorRunStatus = false;
- textBox_MotorSpeedPercent.Text = "5";
- textBox_FacModeName.Text = "";
- textBox_FacModeNum.Text = "";
- textBox_FacModeHW.Text = "";
- textBox_FacModeFW.Text = "";
- }
- /// <summary>
- /// 生产模式读取传感器参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_FacModeSensorRead_Click(object sender, EventArgs e)
- {
- richTextBox_SensorParam.Clear();
- textBox_FacModeSensorADC0.Text = "";
- textBox_FacModeSensorADC1.Text = "";
- textBox_FacModeSensorADC2.Text = "";
- textBox_FacModeSensorADC3.Text = "";
- textBox_FacModeSensorADC4.Text = "";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
- //零点判断
- label1_TorqueCal0.BackColor = Color.Red;
- WriteACK = false;
- ACK_WaitCnt = 0;
- Delay_ms(200);
- if (WriteACK == true) //力矩读取正常
- {
- WriteACK = false;
- //获取零点
- ushort ZeroNew;
- ZeroNew = (ushort)Convert.ToUInt16(textBox_FacModeSensorADC0.Text);
- //比较零点
- if ((ZeroNew <= TorqueParamsForm.Zero.Max) && (ZeroNew >= TorqueParamsForm.Zero.Min))
- {
- label1_TorqueCal0.BackColor = Color.Green;
- }
- else
- {
- MessageBoxTimeOut.Show("力矩传感器零点超范围!\r\n" + "最新零点:" + ZeroNew.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else //力矩读取不正常
- {
- MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- /// <summary>
- /// 生产模式传感器标定1
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void buttonFacModeSet1_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[4];
- for (int i = 0; i < 4; i++)
- ConfigParam[i] = 0;
- ushort uwDataTemp = 0;
- try
- {
- uwDataTemp = 1;//负载序号
- ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
- ConfigParam[1] = (byte)(uwDataTemp >> 8);
- uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal1.Text) * 10); ;//负载值0.1Nm
- ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
- ConfigParam[3] = (byte)(uwDataTemp >> 8);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
- Delay_ms(2000);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
- //标定1判断
- label1_TorqueCal1.BackColor = Color.Red;
- WriteACK = false;
- ACK_WaitCnt = 0;
- Delay_ms(200);
- if (WriteACK == true) //力矩读取正常
- {
- WriteACK = false;
- //获取标定1
- ushort K1_T, K1;
- K1_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal1.Text) * 10);
- K1 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC1.Text));
- //比较标定1
- if ((K1_T == TorqueParamsForm.K1.T) && (K1 <= TorqueParamsForm.K1.Max) && (K1 >= TorqueParamsForm.K1.Min))
- {
- label1_TorqueCal1.BackColor = Color.Green;
- }
- else
- {
- MessageBoxTimeOut.Show("力矩传感器标定1超范围!\r\n" + "加载扭矩:" + K1_T.ToString() + "\r\n标定值:" + K1.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else //力矩读取不正常
- {
- MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- catch (Exception)
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_500ms.Enabled = true;
- }
- }
- /// <summary>
- /// 生产模式传感器标定2
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void buttonFacModeSet2_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[4];
- for (int i = 0; i < 4; i++)
- ConfigParam[i] = 0;
- ushort uwDataTemp = 0;
- try
- {
- uwDataTemp = 2;//负载序号
- ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
- ConfigParam[1] = (byte)(uwDataTemp >> 8);
- uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal2.Text) * 10); ;//负载值0.1Nm
- ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
- ConfigParam[3] = (byte)(uwDataTemp >> 8);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
- Delay_ms(2000);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
- //标定2判断
- label1_TorqueCal2.BackColor = Color.Red;
- WriteACK = false;
- ACK_WaitCnt = 0;
- Delay_ms(200);
- if (WriteACK == true) //力矩读取正常
- {
- WriteACK = false;
- //获取标定2
- ushort K2_T, K2;
- K2_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal2.Text) * 10);
- K2 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC2.Text));
- //比较标定1
- if ((K2_T == TorqueParamsForm.K2.T) && (K2 <= TorqueParamsForm.K2.Max) && (K2 >= TorqueParamsForm.K2.Min))
- {
- label1_TorqueCal2.BackColor = Color.Green;
- }
- else
- {
- MessageBoxTimeOut.Show("力矩传感器标定2超范围!\r\n" + "加载扭矩:" + K2_T.ToString() + "\r\n标定值:" + K2.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else //力矩读取不正常
- {
- MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- catch (Exception)
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_500ms.Enabled = true;
- }
- }
- /// <summary>
- /// 生产模式传感器标定3
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void buttonFacModeSet3_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[4];
- for (int i = 0; i < 4; i++)
- ConfigParam[i] = 0;
- ushort uwDataTemp = 0;
- try
- {
- uwDataTemp = 3;//负载序号
- ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
- ConfigParam[1] = (byte)(uwDataTemp >> 8);
- uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal3.Text) * 10); ;//负载值0.1Nm
- ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
- ConfigParam[3] = (byte)(uwDataTemp >> 8);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
- Delay_ms(2000);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
- //标定3判断
- label1_TorqueCal3.BackColor = Color.Red;
- WriteACK = false;
- ACK_WaitCnt = 0;
- Delay_ms(200);
- if (WriteACK == true) //力矩读取正常
- {
- WriteACK = false;
- //获取标定3
- ushort K3_T, K3;
- K3_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal3.Text) * 10);
- K3 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC3.Text));
- //比较标定1
- if ((K3_T == TorqueParamsForm.K3.T) && (K3 <= TorqueParamsForm.K3.Max) && (K3 >= TorqueParamsForm.K3.Min))
- {
- label1_TorqueCal3.BackColor = Color.Green;
- }
- else
- {
- MessageBoxTimeOut.Show("力矩传感器标定3超范围!\r\n" + "加载扭矩:" + K3_T.ToString() + "\r\n标定值:" + K3.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else //力矩读取不正常
- {
- MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- catch (Exception)
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_500ms.Enabled = true;
- }
- }
- /// <summary>
- /// 生产模式传感器标定4
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void buttonFacModeSet4_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[4];
- for (int i = 0; i < 4; i++)
- ConfigParam[i] = 0;
- ushort uwDataTemp = 0;
- try
- {
- WriteACK = false;
- uwDataTemp = 4;//负载序号
- ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
- ConfigParam[1] = (byte)(uwDataTemp >> 8);
- uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal4.Text) * 10); ;//负载值0.1Nm
- ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
- ConfigParam[3] = (byte)(uwDataTemp >> 8);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
- Delay_ms(2000);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
- //标定4判断
- label1_TorqueCal4.BackColor = Color.Red;
- WriteACK = false;
- ACK_WaitCnt = 0;
- Delay_ms(200);
- if (WriteACK == true) //力矩读取正常
- {
- //获取标定4
- ushort K4_T, K4;
- K4_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal4.Text) * 10);
- K4 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC4.Text));
- //比较标定1
- if ((K4_T == TorqueParamsForm.K4.T) && (K4 <= TorqueParamsForm.K4.Max) && (K4 >= TorqueParamsForm.K4.Min))
- {
- label1_TorqueCal4.BackColor = Color.Green;
- }
- else
- {
- MessageBoxTimeOut.Show("力矩传感器标定4超范围!\r\n" + "加载扭矩:" + K4_T.ToString() + "\r\n标定值:" + K4.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else //力矩读取不正常
- {
- MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- catch (Exception)
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_500ms.Enabled = true;
- }
- }
- /// <summary>
- /// 生产模式开关灯
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- bool LightSwitchStatus = false;
- private void button_FacModeLightSW_Click(object sender, EventArgs e)
- {
- var CtrlCode = new byte[2];
- CtrlCode[0] = 0x00;
- if (LightSwitchStatus)
- {
- CtrlCode[1] = 0xF0;
- button_FacModeLightSW.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(128)))));
- }
- else
- {
- CtrlCode[1] = 0xF1;
- button_FacModeLightSW.BackColor = Color.Yellow;
- }
- if (mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode))
- {
- LightSwitchStatus = !LightSwitchStatus;
- comboBox_LightSwitch.SelectedIndex = LightSwitchStatus ? 0 : 1;
- comboBox_OBC_LightSw.SelectedIndex = LightSwitchStatus ? 0 : 1;
- }
- }
- /// <summary>
- /// 生产模式电机控制
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- bool MotorRunStatus = false;
- private void button_FacModeMotorRun_Click(object sender, EventArgs e)
- {
- string DebugDefaultInfo = "";
- //获取调试信息
- if (richTextBox_DebugParam.Text == string.Empty)
- {
- richTextBox_DebugParam.Clear();
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
- }
- Delay_ms(200);
- DebugDefaultInfo = richTextBox_DebugParam.Text;
- //获取参数
- string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
- if (strDataTemp.Length != 29)
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("数据格式不正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_500ms.Enabled = true;
- return;
- }
- //设置参数
- var ConfigParam = new byte[60];
- for (int i = 0; i < 60; i++)
- ConfigParam[i] = 0;
- ConfigParam[0] = 0x00;
- ushort uwDataTemp = 0;
- if (!MotorRunStatus) //停止状态
- {
- //设置速度环
- strDataTemp[0] = "整体运行模式=3";
- //发送数据
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
- ConfigParam[2 * i + 2] = (byte)uwDataTemp;
- ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
- }
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
- return;
- }
- catch (Exception)
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_500ms.Enabled = true;
- }
- Delay_ms(200);
- //设置转速百分比100%
- textBox_MotorSpeedPercent.Text = "100";
- ConfigParam[0] = (byte)100;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, ConfigParam);
- MotorRunStatus = !MotorRunStatus;
- button_FacModeMotorRun.BackColor = Color.Yellow;
- Delay_ms(200);
- //电机进入配置模式
- var RunMode = new byte[1];
- RunMode[0] = 0x01;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
- }
- else //运转状态
- {
- //设置转速百分比0%
- textBox_MotorSpeedPercent.Text = "0";
- ConfigParam[0] = (byte)0;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, ConfigParam);
- MotorRunStatus = !MotorRunStatus;
- button_FacModeMotorRun.BackColor = Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
- Delay_ms(200);
- //还原为原始值
- strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
- ConfigParam[2 * i + 2] = (byte)uwDataTemp;
- ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
- }
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
- return;
- }
- catch (Exception)
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_500ms.Enabled = true;
- }
- Delay_ms(200);
- //电机退出配置模式
- var RunMode = new byte[1];
- RunMode[0] = 0x00;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
- }
- }
- /// <summary>
- /// 生产模式写入型号
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_FacModeSetName_Click(object sender, EventArgs e)
- {
- string Mode = textBox_FacModeName.Text;
- var ModeArray = new byte[16];
- for (ushort i = 0; i < Mode.Length; i++)
- {
- ModeArray[i] = (byte)Mode[i];
- }
- if (Mode.Length < 16)
- {
- ModeArray[Mode.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
- {
- ModeArray[Mode.Length + 1 + i] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
- }
- /// <summary>
- /// 生产模式写入SN
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Button_FacModeSetNum_Click(object sender, EventArgs e)
- {
- string SN = textBox_FacModeNum.Text;
- var SNArray = new byte[16];
- for (ushort i = 0; i < SN.Length; i++)
- {
- SNArray[i] = (byte)SN[i];
- }
- if (SN.Length < 16)
- {
- SNArray[SN.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - SN.Length - 1; i++)
- {
- SNArray[SN.Length + 1 + i] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
- }
- /// <summary>
- /// 生产模式读取版本信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Button_FacModeReadVer_Click_1(object sender, EventArgs e)
- {
- textBox_Model.Text = "---";
- textBox_SN.Text = "---";
- textBox_HW.Text = "---";
- textBox_FW.Text = "---";
- textBox_SP.Text = "---";
- textBox_OBC_ReadModel.Text = "---";
- textBox_OBC_ReadSN.Text = "---";
- textBox_OBC_ReadHW.Text = "---";
- textBox_OBC_ReadFW.Text = "---";
- textBox_OBC_ReadSP.Text = "---";
- textBox_FacModeName.Text = "---";
- textBox_FacModeNum.Text = "---";
- textBox_FacModeHW.Text = "---";
- textBox_FacModeFW.Text = "---";
- textBox_FacModeSP.Text = "---";
- textBox_FacModeGit.Text = "---";
- Class_Motor_Ver.Mode = "---";
- Class_Motor_Ver.SN = "---";
- Class_Motor_Ver.HW = "---";
- Class_Motor_Ver.FW = "---";
- Class_Motor_Ver.Special = "---";
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
- }
- /// <summary>
- /// 生产模式写入生产信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Button_FacModeSetMacDate_Click(object sender, EventArgs e)
- {
- var MACArray = new byte[32];
- string MacDefaultInfo = "";
- string MacAddDefaultInfo = "";
- string MacDateDefaultInfo = DateTime.Now.ToString("yyyyMMdd");
- string MacPPDefaultInfo = "";
- do
- {
- //填入生产商
- if (toolStripTextBox_MAC.Text == string.Empty)
- {
- break;
- }
- MacDefaultInfo = toolStripTextBox_MAC.Text;
- for (ushort i = 0; i < MacDefaultInfo.Length; i++)
- {
- MACArray[i] = (byte)MacDefaultInfo[i];
- }
- if (MacDefaultInfo.Length < 8)
- {
- MACArray[MacDefaultInfo.Length] = (byte)'.';
- for (ushort i = 0; i < 8 - MacDefaultInfo.Length - 1; i++)
- {
- MACArray[MacDefaultInfo.Length + 1 + i] = 0x20;
- }
- }
- //填入生产地
- if (toolStripTextBoxMACAddr.Text == string.Empty)
- {
- break;
- }
- MacAddDefaultInfo = toolStripTextBoxMACAddr.Text;
- for (ushort i = 0; i < MacAddDefaultInfo.Length; i++)
- {
- MACArray[8 + i] = (byte)MacAddDefaultInfo[i];
- }
- if (MacAddDefaultInfo.Length < 8)
- {
- MACArray[MacAddDefaultInfo.Length + 8] = (byte)'.';
- for (ushort i = 0; i < 8 - MacAddDefaultInfo.Length - 1; i++)
- {
- MACArray[MacAddDefaultInfo.Length + 1 + i + 8] = 0x20;
- }
- }
- //填入生产日期
- if (toolStripTextBox_MACDate.Text == string.Empty)
- {
- break;
- }
- MacDateDefaultInfo = toolStripTextBox_MACDate.Text;
- for (ushort i = 0; i < MacDateDefaultInfo.Length; i++)
- {
- MACArray[16 + i] = (byte)MacDateDefaultInfo[i];
- }
- if (MacDateDefaultInfo.Length < 8)
- {
- MACArray[MacDateDefaultInfo.Length + 16] = (byte)'.';
- for (ushort i = 0; i < 8 - MacDateDefaultInfo.Length - 1; i++)
- {
- MACArray[MacDateDefaultInfo.Length + 1 + i + 16] = 0x20;
- }
- }
- //填入产品标识
- if (toolStripTextBox_MACPD.Text == string.Empty)
- {
- break;
- }
- MacPPDefaultInfo = toolStripTextBox_MACPD.Text;
- for (ushort i = 0; i < MacPPDefaultInfo.Length; i++)
- {
- MACArray[24 + i] = (byte)MacPPDefaultInfo[i];
- }
- if (MacPPDefaultInfo.Length < 8)
- {
- MACArray[MacPPDefaultInfo.Length + 24] = (byte)'.';
- for (ushort i = 0; i < 8 - MacPPDefaultInfo.Length - 1; i++)
- {
- MACArray[MacPPDefaultInfo.Length + 1 + i + 24] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
- return;
- } while (false);
- timer_500ms.Enabled = false;
- MessageBox.Show("生产信息配置不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_500ms.Enabled = true;
- }
- /// <summary>
- /// 生产模式保存测试页面
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Button_FacModeSaveResult_Click(object sender, EventArgs e)
- {
- Button_FacModeSaveResult.Text = "存储中…";
- string[] AssistParams = new string[15];
- do
- {
- //读取一次马达参数
- richTextBox_MotorParam.Clear();
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break; ;
- Delay_ms(100);
- //读取一次整车参数
- richTextBox_BikeParam.Clear();
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
- Delay_ms(100);
- //读取一次整车参数2
- richTextBox_BikeParam2.Clear();
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null)) break;
- Delay_ms(100);
- //读取一次控制参数
- richTextBox_ControlParam.Clear();
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
- Delay_ms(100);
- //查询传感器
- richTextBox_SensorParam.Clear();
- textBox_FacModeSensorADC0.Text = "";
- textBox_FacModeSensorADC1.Text = "";
- textBox_FacModeSensorADC2.Text = "";
- textBox_FacModeSensorADC3.Text = "";
- textBox_FacModeSensorADC4.Text = "";
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
- Delay_ms(100);
- //读取15次助力参数
- for (int i = 1; i <= 15; i++)
- {
- var ConfigParam = new byte[4];
- richTextBox_AssistParam.Clear();
- ConfigParam[0] = (byte)(i & 0xFF);
- ConfigParam[1] = (byte)(i >> 8);
- ConfigParam[2] = (byte)(((i >= 5) ? 5 : i) & 0xFF);
- ConfigParam[3] = (byte)(((i >= 5) ? 5 : i) >> 8);
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
- Delay_ms(200);
- AssistParams[i - 1] = richTextBox_AssistParam.Text + "\r\n";
- }
- //读取一次用户骑行参数
- richTextBox_UsrRidesParam.Clear();
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
- Delay_ms(100);
- //读取一次调试信息
- richTextBox_DebugParam.Clear();
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
- Delay_ms(100);
- //读取一次历史信息
- richTextBox_Record.Clear();
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
- Delay_ms(100);
- //读取一次电机运行信息
- var CtrlCode = new byte[2];
- CtrlCode[0] = 0x00;
- CtrlCode[1] = 0xF0;
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode)) break;
- Delay_ms(100);
- //读取一次版本信息
- textBox_Model.Text = "---";
- textBox_SN.Text = "---";
- textBox_HW.Text = "---";
- textBox_FW.Text = "---";
- textBox_OBC_ReadModel.Text = "---";
- textBox_OBC_ReadSN.Text = "---";
- textBox_OBC_ReadHW.Text = "---";
- textBox_OBC_ReadFW.Text = "---";
- textBox_FacModeName.Text = "---";
- textBox_FacModeNum.Text = "---";
- textBox_FacModeHW.Text = "---";
- textBox_FacModeFW.Text = "---";
- Class_Motor_Ver.Mode = "---";
- Class_Motor_Ver.SN = "---";
- Class_Motor_Ver.HW = "---";
- Class_Motor_Ver.FW = "---";
- Class_Motor_Ver.Special = "---";
- if (!mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null)) break;
- Delay_ms(100);
- //读取一次生产信息
- textBox_MAC.Text = "";
- textBox_MACAdd.Text = "";
- textBox_MACDate.Text = "";
- textBox_PP.Text = "";
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
- Delay_ms(100);
- //读取一次自定义信息
- textBox_User1.Text = "---";
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
- Delay_ms(100);
- textBox_User2.Text = "---";
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
- Delay_ms(100);
- textBox_User3.Text = "---";
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
- Delay_ms(100);
- //读取一次密钥
- textBox_Key.Text = "---";
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
- Delay_ms(100);
- //读取一次存储标志
- radioButton_EE_SaveYes.Checked = false;
- radioButton_EE_SaveNo.Checked = false;
- radioButton_SIP_SaveYes.Checked = false;
- radioButton_SIP_SaveNo.Checked = false;
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
- Delay_ms(100);
- //读取一次MOS内阻校准参数
- foreach (Control c in groupBox21.Controls)
- {
- if (c is TextBox)
- c.Text = "";
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
- Delay_ms(100);
- //提示检查
- #if false
- timer_1s.Enabled = false;
- if (MessageBox.Show("请检查信息是否完整!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
- {
- MessageBox.Show("请检查参数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- return;
- }
- timer_1s.Enabled = true;
- Delay_ms(200);
- #endif
- //判断数据是否有效
- if ((textBox_FacModeName.Text == "---") || (textBox_FacModeNum.Text == "---"))
- {
- MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- break;
- }
- if ((textBox_FacModeName.Text == string.Empty) || (textBox_FacModeNum.Text == string.Empty))
- {
- MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- break;
- }
- //设置文件存储路径
- string Save_Path = localInfo.LocalPath + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
- string PD_PathName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_"); ;
- Save_Path += PD_PathName;
- if (!Directory.Exists(Save_Path))
- Directory.CreateDirectory(Save_Path);
- //保存页面
- string PIC_SaveFileName = "";
- Double scaleX = PrimaryScreen.ScaleX;
- Double scaleY = PrimaryScreen.ScaleY;
- //保存页面
- Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
- Graphics g = Graphics.FromImage(bit);
- g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
- PIC_SaveFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_测试页面" + ".png";
- bit.Save(PIC_SaveFileName);
- //保存数据
- string DataFileName = "";
- string FileInfo = "";
- DataFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_记录数据" + ".txt";
- FileInfo += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
- FileInfo += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
- FileInfo += "\r\n";
- FileInfo += "[电机信息]\r\n";
- FileInfo += "电机型号: " + textBox_FacModeName.Text + "\r\n";
- FileInfo += "电机编号: " + textBox_FacModeNum.Text + "\r\n";
- FileInfo += "硬件版本: " + textBox_HW.Text + "\r\n";
- FileInfo += "软件版本: " + textBox_FW.Text + "\r\n";
- FileInfo += "软件标识: " + textBox_SP.Text + "\r\n";
- FileInfo += "Git信息: " + textBox_FacModeGit.Text + "\r\n";
- FileInfo += "\r\n";
- FileInfo += "[马达参数]\r\n";
- FileInfo += richTextBox_MotorParam.Text + "\r\n";
- FileInfo += "\r\n";
- FileInfo += "[整车参数]\r\n";
- FileInfo += richTextBox_BikeParam.Text + "\r\n";
- FileInfo += "\r\n";
- FileInfo += "[控制参数]\r\n";
- FileInfo += richTextBox_ControlParam.Text + "\r\n";
- FileInfo += "\r\n";
- FileInfo += "[传感器参数]\r\n";
- FileInfo += richTextBox_SensorParam.Text + "\r\n";
- FileInfo += "\r\n";
- FileInfo += "[助力参数]\r\n";
- for(int i=0;i<15;i++)
- {
- FileInfo += AssistParams[i] + "\r\n";
- }
- FileInfo += "[调试参数]\r\n";
- FileInfo += richTextBox_DebugParam.Text + "\r\n";
- FileInfo += "\r\n";
- FileInfo += "[历史信息]\r\n";
- FileInfo += richTextBox_Record.Text + "\r\n";
- FileInfo += "\r\n";
- FileInfo += "[MOS内阻校准参数]\r\n";
- FileInfo += textBox_MOS_K1.Text + ", ";
- FileInfo += textBox_MOS_K2.Text + ", ";
- FileInfo += textBox_MOS_K3.Text + ", ";
- FileInfo += textBox_MOS_K4.Text + ", ";
- FileInfo += textBox_MOS_K5.Text + ", ";
- FileInfo += textBox_MOS_R1.Text + ", ";
- FileInfo += textBox_MOS_R2.Text + ", ";
- FileInfo += textBox_MOS_R3.Text + "\r\n";
- FileInfo += "\r\n";
- FileInfo += "[整车参数2]\r\n";
- FileInfo += richTextBox_BikeParam2.Text + "\r\n";
- FileInfo += "\r\n";
- FileInfo += "[用户骑行参数]\r\n";
- FileInfo += richTextBox_UsrRidesParam.Text + "\r\n";
- FileInfo += "\r\n";
- FileInfo += "[生产信息]\r\n";
- FileInfo += "生产商: " + textBox_MAC.Text + "\r\n";
- FileInfo += "生产地: " + textBox_MACAdd.Text + "\r\n";
- FileInfo += "生产日期: " + textBox_MACDate.Text + "\r\n";
- FileInfo += "产品标识: " + textBox_PP.Text + "\r\n";
- FileInfo += "\r\n";
- FileInfo += "[自定义信息]\r\n";
- FileInfo += "自定义1: " + textBox_User1.Text + "\r\n";
- FileInfo += "自定义2: " + textBox_User2.Text + "\r\n";
- FileInfo += "自定义3: " + textBox_User3.Text + "\r\n";
- FileInfo += "\r\n";
- FileInfo += "[校验密钥]\r\n";
- FileInfo += textBox_Key.Text + "\r\n";
- FileInfo += "\r\n";
- FileInfo += "[存储标志]\r\n";
- FileInfo += "EEPROM: " + ((radioButton_EE_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
- FileInfo += "SIP: " + ((radioButton_SIP_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
- FileInfo += "\r\n";
- FileInfo += Local_HdInformation;
- FileInfo += "\r\n";
- FileInfo += "文件格式: V2.0\r\n";
- System.IO.File.WriteAllText(DataFileName, FileInfo);
- Delay_ms(1000);
- timer_500ms.Enabled = false;
- MessageBox.Show("存储完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- timer_500ms.Enabled = true;
- //数据上传
- if (myFtp.IsNetConnected == true)
- {
- string DataNow = DateTime.Now.ToString("yyyy-MM-dd");
- //检查路径
- if (myFtp.DirectoryExist("\\", toolStripTextBox_ServerPath.Text) == false)
- {
- myFtp.MakeDir(toolStripTextBox_ServerPath.Text);
- }
- if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text, "Samples") == false)
- {
- myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples");
- }
- if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples", DataNow) == false)
- {
- myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow);
- }
- if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow, PD_PathName) == false)
- {
- myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
- }
- //上传文件
- bool result1 = myFtp.UploadFile(PIC_SaveFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
- bool result2 = myFtp.UploadFile(DataFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
- if ((result1 & result2) == true)
- {
- MessageBoxTimeOut.Show("数据已上传!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- else
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("数据上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_500ms.Enabled = true;
- }
- }
- else
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("服务器断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_500ms.Enabled = true;
- }
- Button_FacModeSaveResult.Text = "保存数据";
- return;
- } while (false);
- timer_500ms.Enabled = false;
- MessageBox.Show("保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_500ms.Enabled = true;
- Button_FacModeSaveResult.Text = "保存数据";
- }
- /// <summary>
- /// 工具箱页面保存
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 页面保存ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- Double scaleX = PrimaryScreen.ScaleX;
- Double scaleY = PrimaryScreen.ScaleY;
- //保存页面
- Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
- Graphics g = Graphics.FromImage(bit);
- g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
- SaveFileDialog sf = new SaveFileDialog();
- sf.Title = "页面保存";
- sf.FileName = "MotorInfo_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".png";
- sf.Filter = "图片|*.png";
- timer_500ms.Enabled = false;
- if (sf.ShowDialog() == DialogResult.OK)
- {
- bit.Save(sf.FileName);//默认保存格式为PNG,保存成jpg格式质量不是很好
- }
- timer_500ms.Enabled = true;
- }
- /// <summary>
- /// 生产模式关机
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Button_FacModePowerOff_Click(object sender, EventArgs e)
- {
- var Code_Off = new byte[5];
- var Code_Reset = new byte[5];
- Code_Off[0] = (byte)'O';
- Code_Off[1] = (byte)'F';
- Code_Off[2] = (byte)'F';
- Code_Off[3] = (byte)'.';
- Code_Off[4] = (byte)'.';
- Code_Reset[0] = (byte)'R';
- Code_Reset[1] = (byte)'E';
- Code_Reset[2] = (byte)'S';
- Code_Reset[3] = (byte)'E';
- Code_Reset[4] = (byte)'T';
- timer_500ms.Enabled = false;
- if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- timer_500ms.Enabled = true;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
- PowerOffAckStatus = false;
- Delay_ms(250);
- int TryCnt = 3;
- while ((TryCnt--) >= 0)
- {
- if (!PowerOffAckStatus)
- {
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
- PowerOffAckStatus = false;
- Delay_ms(250);
- }
- else break;
- }
- if (PowerOffAckStatus)
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("已关机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
- timer_500ms.Enabled = true;
- }
- else
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_500ms.Enabled = true;
- }
- }
- timer_500ms.Enabled = true;
- }
- //仪表电源键按下
- private void button_OBC_ButtonPower_Click(object sender, EventArgs e)
- {
- var Code = new byte[2];
- Code[0] = 0;
- Code[1] = 0b00100000;
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
- }
- /// <summary>
- /// 仪表加键按下
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_ButtonAcc_Click(object sender, EventArgs e)
- {
- var Code = new byte[2];
- Code[0] = 0;
- Code[1] = 0b00010000;
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
- }
- /// <summary>
- /// 仪表减键按下
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_ButtonDec_Click(object sender, EventArgs e)
- {
- var Code = new byte[2];
- Code[0] = 0;
- Code[1] = 0b00001000;
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
- }
- /// <summary>
- /// 仪表Walk键按下
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_ButtonWalk_Click(object sender, EventArgs e)
- {
- var Code = new byte[2];
- Code[0] = 0;
- Code[1] = 0b00000100;
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
- }
- /// <summary>
- /// 仪表Light键按下
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_ButtonLight_Click(object sender, EventArgs e)
- {
- var Code = new byte[2];
- Code[0] = 0;
- Code[1] = 0b00000010;
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
- }
- /// <summary>
- /// 仪表Set键按下
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_ButtonSet_Click(object sender, EventArgs e)
- {
- var Code = new byte[2];
- Code[0] = 0;
- Code[1] = 0b00000001;
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
- }
- /// <summary>
- /// 导出电机故障日志
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ExportLog_Click(object sender, EventArgs e)
- {
- var Address = new byte[4];
- UInt32 Address_Begin;
- UInt32 Addres_End;
- string textBox_Address_Begin = textBox_LogAddrBegin.Text;
- string textBox_Address_End = textBox_LogAddrEnd.Text;
- richTextBox_Record.Clear();
- textBox_LogAddrBegin.ReadOnly = true;
- textBox_LogAddrEnd.ReadOnly = true;
- if (!mySerialProcess.mySerial.IsOpen)
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_500ms.Enabled = true;
- return;
- }
- if ((textBox_Address_Begin == string.Empty) || (textBox_Address_End == string.Empty))
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("请输入日志存储起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_500ms.Enabled = true;
- return;
- }
- else
- {
- Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin, false);
- Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
- Address = mySerialProcess.HexStringToBytes(textBox_Address_End, false);
- Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
- if (Addres_End <= Address_Begin)
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("结束地址应大于起始地址!", "提示");
- timer_500ms.Enabled = true;
- return;
- }
- else if (((Addres_End - Address_Begin + 1) % 128) != 0) //
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("(结束地址 - 起始地址 + 1)应为128整数倍!", "提示");
- timer_500ms.Enabled = true;
- return;
- }
- else
- {
- UInt32 ReadCount = 0;
- button_ExportLog.Text = "导出中...";
- button_ExportLog.Enabled = false;
- ReadCount = (Addres_End - Address_Begin + 1) / 128;
- for (ushort i = 0; i < ReadCount; i++)
- {
- var SendByte = new byte[8];
- UInt32 Address_Temp_Begin;
- UInt32 Address_Temp_End;
- Address_Temp_Begin = Address_Begin + 128 * (UInt32)i;
- SendByte[0] = (byte)(Address_Temp_Begin >> 24);
- SendByte[1] = (byte)(Address_Temp_Begin >> 16);
- SendByte[2] = (byte)(Address_Temp_Begin >> 8);
- SendByte[3] = (byte)(Address_Temp_Begin);
- Address_Temp_End = Address_Temp_Begin + 127;
- SendByte[4] = (byte)(Address_Temp_End >> 24);
- SendByte[5] = (byte)(Address_Temp_End >> 16);
- SendByte[6] = (byte)(Address_Temp_End >> 8);
- SendByte[7] = (byte)(Address_Temp_End);
- mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
- Delay_ms(200);//Thread.Sleep(200);
- }
- button_ExportLog.Text = "导出日志";
- button_ExportLog.Enabled = true;
- }
- }
- }
- /// <summary>
- /// 保存日志信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_SaveRecordInfo_Click(object sender, EventArgs e)
- {
- string SaveInfo = "";
- if (richTextBox_Record.Text == string.Empty)
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- timer_500ms.Enabled = true;
- return;
- }
- //获取保存信息
- SaveInfo += "读取时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
- SaveInfo += "电机型号:" + textBox_FacModeName.Text + "\r\n";
- SaveInfo += "电机SN:" + textBox_FacModeNum.Text + "\r\n";
- SaveInfo += "硬件版本:" + textBox_FacModeHW.Text + "\r\n";
- SaveInfo += "软件版本:" + textBox_FacModeFW.Text + "\r\n";
- SaveInfo += "\r\n";
- SaveInfo += richTextBox_Record.Text;
- //设置保存路径和文件名
- SaveFileDialog sf = new SaveFileDialog();
- sf.Title = "数据保存";
- sf.FileName = "MotorLog_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".ttlog";
- sf.FileName.Replace(" ", "");
- sf.Filter = "日志|*.ttlog";
- if (sf.ShowDialog() == DialogResult.OK)
- {
- System.IO.File.AppendAllText(sf.FileName, SaveInfo);
- }
- }
- /// <summary>
- /// 双击修改日志起始地址
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void label_LogAddrBegin_DoubleClick_1(object sender, EventArgs e)
- {
- textBox_LogAddrBegin.ReadOnly = false;
- }
- /// <summary>
- /// 双击修改日志结束地址
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void label88_DoubleClick(object sender, EventArgs e)
- {
- textBox_LogAddrEnd.ReadOnly = false;
- }
- /// <summary>
- /// 存储器自动读取选择
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void checkBox_ReadRanFlash_AutoSW_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_ReadRanFlash_AutoSW.Checked == true)
- {
- //检查串口是否打开
- if (!mySerialProcess.mySerial.IsOpen)
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_500ms.Enabled = true;
- checkBox_ReadRanFlash_AutoSW.Checked = false;
- return;
- }
- }
- }
- /// <summary>
- /// 系统开机按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 开机ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- byte[] Data = new byte[1];
- Data[0] = 0xF1;
- mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
- }
- /// <summary>
- /// 系统关机按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 关机ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- byte[] Data = new byte[1];
- Data[0] = 0xF0;
- mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
- }
- /// <summary>
- /// 连接开机选择
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 连接开机ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- //输入用户名
- EnterForm1.ShowDialog();
- try
- {
- if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
- {
- if (EnterForm1.comboBox_User.Text == "管理员")
- {
- 连接开机ToolStripMenuItem.Checked = !连接开机ToolStripMenuItem.Checked;
- ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- else
- {
- MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else
- {
- MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- catch (Exception)
- {
- MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- /// <summary>
- /// 断开关机选择
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 断开关机ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- //输入用户名
- EnterForm1.ShowDialog();
- try
- {
- if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
- {
- if (EnterForm1.comboBox_User.Text == "管理员")
- {
- 断开关机ToolStripMenuItem.Checked = !断开关机ToolStripMenuItem.Checked;
- ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- else
- {
- MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else
- {
- MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- catch (Exception)
- {
- MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- /// <summary>
- /// 识别通讯盒选择
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 识别通讯盒ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- //输入用户名
- EnterForm1.ShowDialog();
- try
- {
- if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
- {
- if (EnterForm1.comboBox_User.Text == "管理员")
- {
- 识别通讯盒ToolStripMenuItem.Checked = !识别通讯盒ToolStripMenuItem.Checked;
- ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- else
- {
- MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else
- {
- MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- catch (Exception)
- {
- MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- /// <summary>
- /// 将配置信息导出为cfg文件
- /// </summary>
- private void ConfigFileSave(bool DeleteFlag, string FileName)
- {
- if (DeleteFlag)
- {
- if (File.Exists(FileName))
- File.Delete(FileName);
- }
- string CfgFileInfo = "";
- CfgFileInfo += "[PortSet]" + "\r\n";
- CfgFileInfo += "PortNum:" + toolStripComboBox_ComNum.Text + "\r\n";
- CfgFileInfo += "PortBaudrate:" + "115200" + "\r\n";
- CfgFileInfo += "AutoOn:" + 连接开机ToolStripMenuItem.Checked.ToString() + "\r\n";
- CfgFileInfo += "AutoOff:" + 断开关机ToolStripMenuItem.Checked.ToString() + "\r\n";
- CfgFileInfo += "CheckCDL:" + 识别通讯盒ToolStripMenuItem.Checked.ToString() + "\r\n";
- CfgFileInfo += "\r\n";
- CfgFileInfo += "[Option]" + "\r\n";
- CfgFileInfo += "SaveWhenWrite:" + 写入存储ToolStripMenuItem.Checked.ToString() + "\r\n";
- CfgFileInfo += "\r\n";
- CfgFileInfo += "[ServerSet]" + "\r\n";
- CfgFileInfo += "PathName:" + toolStripTextBox_ServerPath.Text + "\r\n";
- CfgFileInfo += "\r\n";
- CfgFileInfo += "[MacInfo]" + "\r\n";
- CfgFileInfo += "MacName:" + toolStripTextBox_MAC.Text + "\r\n";
- CfgFileInfo += "MacAddress:" + toolStripTextBoxMACAddr.Text + "\r\n";
- CfgFileInfo += "MacDate:" + toolStripTextBox_MACDate.Text + "\r\n";
- CfgFileInfo += "MacPdInfo:" + toolStripTextBox_MACPD.Text + "\r\n";
- CfgFileInfo += "\r\n";
- CfgFileInfo += "[LogAddress]" + "\r\n";
- CfgFileInfo += "BeginAddress:" + textBox_LogAddrBegin.Text + "\r\n";
- CfgFileInfo += "EndAddress:" + textBox_LogAddrEnd.Text + "\r\n";
- CfgFileInfo += "\r\n";
- CfgFileInfo += "[MotorType]" + "\r\n";
- CfgFileInfo += "MidMotor1:" + 中置电机MIGIC_ToolStripMenuItem.Checked.ToString() + "\r\n";
- CfgFileInfo += "MidMotor2:" + 中置电机VP_ToolStripMenuItem.Checked.ToString() + "\r\n";
- CfgFileInfo += "HubMotor:" + 轮毂电机ToolStripMenuItem.Checked.ToString() + "\r\n";
- CfgFileInfo += "\r\n";
- CfgFileInfo += "[CheckValue]" + "\r\n";
- CfgFileInfo += "Voltage:" + toolStripTextBox_ThVol.Text + "\r\n";
- CfgFileInfo += "Current:" + toolStripTextBox_ThCur.Text + "\r\n";
- CfgFileInfo += "MotorSpeed:" + toolStripTextBox_ThSpeed.Text + "\r\n";
- CfgFileInfo += "Torque:" + toolStripTextBox_ThTor.Text + "\r\n";
- CfgFileInfo += "Cadence:" + toolStripTextBox_ThCad.Text + "\r\n";
- CfgFileInfo += "BikeSpeed:" + toolStripTextBox_ThBikeSpeed.Text + "\r\n";
- CfgFileInfo += "T_PCB:" + toolStripTextBox_ThT_PCB.Text + "\r\n";
- CfgFileInfo += "T_MCU:" + toolStripTextBox_ThT_MCU.Text + "\r\n";
- CfgFileInfo += "T_Motor:" + toolStripTextBox_ThT_Motor.Text + "\r\n";
- CfgFileInfo += "\r\n";
- CfgFileInfo += "[MosCalK]" + "\r\n";
- CfgFileInfo += "K1-K5:" + toolStripTextBox_MosCalK.Text + "\r\n";
- CfgFileInfo += "MOS1:" + toolStripTextBox_MOS1.Text + "\r\n";
- CfgFileInfo += "MOS2:" + toolStripTextBox_MOS2.Text + "\r\n";
- CfgFileInfo += "MOS3:" + toolStripTextBox_MOS3.Text + "\r\n";
- CfgFileInfo += "\r\n";
- CfgFileInfo += "[ProtocolType]" + "\r\n";
- CfgFileInfo += "CAN:" + cANToolStripMenuItem.Checked.ToString() + "\r\n";
- CfgFileInfo += "UART:" + uARTToolStripMenuItem.Checked.ToString() + "\r\n";
- CfgFileInfo += "\r\n";
- CfgFileInfo += "[AutoUpdate]" + "\r\n";
- CfgFileInfo += "AutoUpdate:" + 打开ToolStripMenuItem.Checked.ToString() + "\r\n";
- CfgFileInfo += "\r\n";
- CfgFileInfo += "[AngleCal]" + "\r\n";
- CfgFileInfo += "MaxDiffLimit:" + textBox_AngleDiffTh.Text + "\r\n";
- CfgFileInfo += "ZeroDiffLimit:" + textBox_AngleZeroTh.Text + "\r\n";
- System.IO.File.WriteAllText(FileName, CfgFileInfo);
- }
- /// <summary>
- /// 配置状态更新,点击时保存
- /// </summary>
- private void ConfigFileSave_Click(object sender, EventArgs e)
- {
- ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- /// <summary>
- /// 文本框修改结束,回车保存
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ConfigFileSave_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
- MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
- }
- }
- /// <summary>
- /// 弹出扫码按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ScanCode_Click(object sender, EventArgs e)
- {
- Scan scan_form = new Scan();
- scan_form.ShowDialog();
- do
- {
- if (scan_form.textBox_Scan.Text == string.Empty)
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_500ms.Enabled = true;
- break;
- }
- string ScanInfo = scan_form.textBox_Scan.Text;
- string regexInfo = "";
- string[] InfoList = { "" };
- try
- {
- if (中置电机MIGIC_ToolStripMenuItem.Checked == true)
- {
- regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
- InfoList = Regex.Split(ScanInfo, regexInfo, RegexOptions.IgnoreCase);
- }
- else if (中置电机VP_ToolStripMenuItem.Checked == true)
- {
- Regex regex = new Regex(@"^M[12][0-9](0?[1-9]|1[0-2])((0?[1-9])|((1|2)[0-9])|30|31)[A-Z]\d{4}[A-Z][A-Z]?$");
- if (ScanInfo.Contains(" "))
- {
- InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
- string Mode = InfoList[0];
- string Sn = InfoList[1];
- if (regex.IsMatch(Sn) == false)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN格式错误" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "标签格式错误";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- }
- else
- {
- MessageBox.Show("SN格式错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return;
- }
- }
- else if (轮毂电机ToolStripMenuItem.Checked == true)
- {
- if (!ScanInfo.Contains("/")) //老编码规则
- {
- InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
- string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
- string Spec = InfoList[1];
- string Sn = InfoList[2];
- InfoList[0] = Model.Substring(2, 12) + Spec.Substring(Spec.Length - 4);
- InfoList[1] = Sn;
- }
- else //新编码规则
- {
- Dictionary<string, string> Dic_Ver = new Dictionary<string, string>
- {
- { "01", "A" },
- { "02", "B" },
- { "03", "C" },
- { "04", "D" },
- { "05", "E" },
- { "06", "F" },
- { "07", "G" },
- { "08", "H" },
- { "09", "I" }
- };
- Dictionary<string, string> Dic_Vol = new Dictionary<string, string>
- {
- { "24V", "A" },
- { "36V", "B" },
- { "42V", "C" },
- { "48V", "D" },
- { "52V", "E" },
- { "60V", "F" }
- };
- InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
- string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
- string Spec = InfoList[1].Replace("-", "").Replace("/", "");
- string Sn = InfoList[2];
- InfoList[0] = Model[2] + Dic_Ver[Model.Substring(3, 2)] + Model[5] + Dic_Ver[Model.Substring(6, 2)] + Model[9];
- InfoList[0] += Dic_Vol[Spec.Substring(0, 3)] + Spec.Substring(3, 3) + Spec.Substring(13, 4) + Spec.Substring(Spec.Length - 4, 3);
- InfoList[1] = Sn;
- }
- }
- }
- catch (Exception)
- {
- MessageBox.Show("格式错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return;
- }
- if (InfoList.Length >= 2)
- {
- //写入型号
- textBox_FacModeName.Text = InfoList[0];
- string Mode = textBox_FacModeName.Text;
- var ModeArray = new byte[16];
- for (ushort i = 0; i < Mode.Length; i++)
- {
- ModeArray[i] = (byte)Mode[i];
- }
- if (Mode.Length < 16)
- {
- ModeArray[Mode.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
- {
- ModeArray[Mode.Length + 1 + i] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
- //写入SN
- textBox_FacModeNum.Text = InfoList[1];
- string SN = textBox_FacModeNum.Text;
- var SNArray = new byte[16];
- for (ushort i = 0; i < SN.Length; i++)
- {
- SNArray[i] = (byte)SN[i];
- }
- if (SN.Length < 16)
- {
- SNArray[SN.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - SN.Length - 1; i++)
- {
- SNArray[SN.Length + 1 + i] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
- }
- else
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_500ms.Enabled = true;
- break;
- }
- } while (false);
- scan_form.Dispose();
- }
- /// <summary>
- /// 切换电机类型
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 中置电机ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- 中置电机MIGIC_ToolStripMenuItem.Checked = true;
- 中置电机VP_ToolStripMenuItem.Checked = false;
- 轮毂电机ToolStripMenuItem.Checked = false;
- toolStripTextBox_MACPD.Text = "MM_MC1";
- toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
- ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- private void 中置电机小牙盘ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- 中置电机MIGIC_ToolStripMenuItem.Checked = false;
- 中置电机VP_ToolStripMenuItem.Checked = true;
- 轮毂电机ToolStripMenuItem.Checked = false;
- toolStripTextBox_MACPD.Text = "MM_MV1";
- toolStripTextBox_ServerPath.Text = "MC_VP_TEST";
- ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- /// <summary>
- /// 切换电机类型
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 轮毂电机ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- 中置电机MIGIC_ToolStripMenuItem.Checked = false;
- 中置电机VP_ToolStripMenuItem.Checked = false;
- 轮毂电机ToolStripMenuItem.Checked = true;
- toolStripTextBox_MACPD.Text = "GF_250_1";
- toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
- ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- /// <summary>
- /// 获取配置文件日期
- /// </summary>
- /// <param name="DisAll"></param>
- private void GetDateList(bool DisAll)
- {
- string[] DateList = { "" };
- //从服务器更新日期列表
- if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
- {
- DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
- }
- //从本地更新日期列表
- else
- {
- DateList = Directory.GetDirectories(localInfo.LocalPath + "\\" + localInfo.CfgPathName);
- }
-
- comboBox_FacModeCfgDate.Items.Clear();
- comboBox_CheckModeCfgDate.Items.Clear();
- //日期列表加载
- if (DisAll == true)
- {
- comboBox_FacModeCfgDate.Items.Add("显示近期");
- comboBox_CheckModeCfgDate.Items.Add("显示近期");
- comboBox_FacModeCfgDate.Items.Add("---");
- comboBox_CheckModeCfgDate.Items.Add("---");
- foreach (var file in DateList)
- {
- comboBox_FacModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
- comboBox_CheckModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
- }
- }
- else
- {
- if (DateList.Length > 10)
- {
- comboBox_FacModeCfgDate.Items.Add("显示全部");
- comboBox_CheckModeCfgDate.Items.Add("显示全部");
- comboBox_FacModeCfgDate.Items.Add("---");
- comboBox_CheckModeCfgDate.Items.Add("---");
- }
- for (int i = (DateList.Length > 10) ? (DateList.Length - 10) : 0; i < DateList.Length; i++)//显示最近10个日期
- {
- comboBox_FacModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
- comboBox_CheckModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
- }
- }
- }
- /// <summary>
- /// 获取配置文件列表
- /// </summary>
- /// <param name="date"></param>
- private void GetFileListFrom(string date)
- {
- string[] FileList = { "" };
- //从服务器更新文件列表
- if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
- {
- FileList = myFtp.GetFileNameList(toolStripTextBox_ServerPath.Text + "/cfg/" + date);
- }
- else
- {
- FileList = Directory.GetFiles(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + date);
- }
- comboBox_CheckModeCfgFile.Items.Clear();
- comboBox_FacModeCfgFile.Items.Clear();
- foreach (var file in FileList)
- {
- if (file.Contains(".ttcfg"))
- {
- comboBox_CheckModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
- comboBox_FacModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
- }
- }
- }
- /// <summary>
- /// 检验模式选择文件日期
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void comboBox_CheckModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
- {
- if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示全部")
- {
- GetDateList(true);
- }
- else if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示近期")
- {
- GetDateList(false);
- }
- else
- {
- comboBox_CheckModeCfgFile.Text = "";
- GetFileListFrom(comboBox_CheckModeCfgDate.SelectedItem.ToString());
- }
- }
- /// <summary>
- /// 配置模式选择文件日期
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void comboBox_FacModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
- {
- if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示全部")
- {
- GetDateList(true);
- }
- else if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示近期")
- {
- GetDateList(false);
- }
- else
- {
- comboBox_FacModeCfgFile.Text = "";
- GetFileListFrom(comboBox_FacModeCfgDate.SelectedItem.ToString());
- }
- }
- /// <summary>
- /// 选中量产模式
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void tabControl1_Selected(object sender, TabControlEventArgs e)
- {
- //更新生产配置文件目录
- GetDateList(false);
- }
- /// <summary>
- /// 量产测试结束
- /// </summary>
- /// <param name=""></param>
- private void FacMode_Stop(bool OK_Flag)
- {
- //打开开始按钮
- button__FacMode_Start.Enabled = true;
- //系统关机
- var Code = new byte[32];//发送的指令数据
- Code[0] = 0xF0;
- mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
- //关闭串口
- //mySerialProcess.SerialClose(false);
- //路径设置
- string LocalSavePath = "";
- string ServerSavePath = "";
- if (OK_Flag)
- {
- LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "OK\\";
- ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/OK/";
- }
- else
- {
- LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "FAIL\\";
- ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/FAIL/";
- }
- if (Directory.Exists(LocalSavePath) == false)
- {
- Directory.CreateDirectory(LocalSavePath);
- }
- //保存和上传
- string LogSavePath = "";
- string LogSaveFileName = "";
- string ProductInfo = textBox_FacModeScan.Text.Replace(" ", "_").Replace("/", "-");
- LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
- if (Directory.Exists(LogSavePath) == false)
- {
- Directory.CreateDirectory(LogSavePath);
- }
- //测试页面
- Double scaleX = PrimaryScreen.ScaleX;
- Double scaleY = PrimaryScreen.ScaleY;
- Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
- Graphics g = Graphics.FromImage(bit);
- g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
- LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
- bit.Save(LogSaveFileName);
- //上传测试页面到服务器
- if (myFtp.IsNetConnected == true)
- {
- string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
- if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
- {
- myFtp.MakeDir(ServerSavePath + DateNow);
- }
- if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
- {
- myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
- }
- bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
- if (result == true)
- richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
- }
- else
- {
- richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
- }
- //测试记录
- LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
- string file_str = "";
- file_str += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
- file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
- file_str += "检验记录:\r\n" + richTextBox_FacModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
- file_str += "检验结果:\r\n" + label_FacModeResult.Text + "\r\n\r\n";
- file_str += Local_HdInformation;
- System.IO.File.WriteAllText(LogSaveFileName, file_str);
- //上传测试记录到服务器
- if (myFtp.IsNetConnected == true)
- {
- string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
- if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
- {
- myFtp.MakeDir(ServerSavePath + DateNow);
- }
- if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
- {
- myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
- }
- bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
- if (result == true)
- richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
- }
- else
- {
- richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
- }
- //扫码框清空
- textBox_FacModeScan.Text = "";
- }
- /// <summary>
- /// 量产测试开始
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button__FacMode_Start_Click(object sender, EventArgs e)
- {
- //关闭测试项目编辑
- pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
- foreach (Control c in groupBox2.Controls)
- {
- if (c is CheckBox)
- c.Enabled = false;
- }
- WriteLockStatus = true;
-
- //检查配置文件
- if (comboBox_FacModeCfgFile.Text == "")
- {
- MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- //开始测试
- TestStart();
- }
- /// <summary>
- /// 测试子函数
- /// </summary>
- private void TestStart()
- {
- //初始化标签
- FacModelLabelInit();
- richTextBox_FacModeLog.Clear();
- //按钮禁止操作
- button__FacMode_Start.Enabled = false;
- //记录配置文件
- richTextBox_FacModeLog.AppendText("配置文件:" + comboBox_FacModeCfgDate.Text + " / " + comboBox_FacModeCfgFile.Text + "\r\n");
- //检查打标信息格式
- label_FacModeStatus.Text = "检查扫码信息";
- Delay_ms(500);
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
- if (textBox_FacModeScan.Text == string.Empty)
- {
- MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- button__FacMode_Start.Enabled = true;
- return;
- }
- try
- {
- if (中置电机MIGIC_ToolStripMenuItem.Checked == true)
- {
- if (textBox_FacModeScan.Text.Split(' ').Length != 7)
- {
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "标签格式错误";
- button__FacMode_Start.Enabled = true;
- return;
- }
- }
- else if (中置电机VP_ToolStripMenuItem.Checked == true)
- {
- if (textBox_FacModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 2)
- {
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "标签格式错误";
- button__FacMode_Start.Enabled = true;
- return;
- }
- }
- else if (轮毂电机ToolStripMenuItem.Checked == true)
- {
- if (textBox_FacModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
- {
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "标签格式错误";
- button__FacMode_Start.Enabled = true;
- return;
- }
- }
- }
- catch (System.Exception)
- {
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "标签格式错误";
- button__FacMode_Start.Enabled = true;
- return;
- }
- //打开串口
- mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false);
- if (!mySerialProcess.mySerial.IsOpen)
- {
- MessageBox.Show("请检查串口连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- //按钮禁止操作
- button__FacMode_Start.Enabled = true;
- return;
- }
- //流水号计数
- int serial = Convert.ToInt32(label_FacModeSerial.Text);
- serial += 1;
- label_FacModeSerial.Text = serial.ToString();
- File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, serial.ToString());
- //创建线程,执行测试任务
- Thread th = new Thread(FacModeTest_Task);
- th.Start();
- }
- /// <summary>
- /// 执行一次测试任务
- /// </summary>
- private void FacModeTest_Task()
- {
- //开始测试
- richTextBox_FacModeLog.AppendText("产品标签:" + textBox_FacModeScan.Text + "\r\n");
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
- //变量定义
- var Code = new byte[255];//发送的指令数据
-
- label_FacModeStatus.Text = "开始测试";
- Delay_ms(500);
- label_FacModeStatus.Text = "系统开机";
-
- //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
- if (uARTToolStripMenuItem.Checked)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送复位指令,切换联动装置盒波特率" + "\r\n");
- Code[0] = (byte)'R';
- Code[1] = (byte)'E';
- Code[2] = (byte)'S';
- Code[3] = (byte)'E';
- Code[4] = (byte)'T';
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
- Delay_ms(500);
- }
- //发送开机指令
- //确保测试前先关机,发送关机指令再发送开机指令
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
- Code[0] = 0xF0;
- mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
- Delay_ms(1500);
- BootInfo = "";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
- Code[0] = 0xF1;
- mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
- ACK_WaitCnt = 0;
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
- while (ACK_WaitCnt <= 20); //10s,等待开机成功,联动装置盒控制器接口波特率需等待5s接口自动切换为9600
-
- //检查BOOT版本
- if (BootInfo != string.Empty)
- {
- label_FacModeBootVer.BackColor = Color.Green;
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
- Delay_ms(500);
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- //系统清除
- if (checkBox_FacModeSysClear.Checked)
- {
- do
- {
- #if false
- if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
- {
- Code[0] = 0x00;//5S协议
- Code[1] = 0x00;
- mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
- Delay_ms(500);
- mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
- Delay_ms(500);
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
- }
- #endif
- //发送系统清除指令
- label_FacModeStatus.Text = "系统清除";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除" + "\r\n");
- Code[0] = (byte)'C';
- Code[1] = (byte)'L';
- Code[2] = (byte)'E';
- Code[3] = (byte)'A';
- Code[4] = (byte)'R';
-
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
- WriteACK = false;
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 6); //3s
- //等待系统清除完成指令
- if (WriteACK == true)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
- label_FacModeSysClear.BackColor = Color.Green;
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除,重发第1次" + "\r\n");
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 6) ; //3s
- //等待系统清除完成指令
- if (WriteACK == true)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
- label_FacModeSysClear.BackColor = Color.Green;
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除,重发第2次" + "\r\n");
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 6) ; //3s
- //等待系统清除完成指令
- if (WriteACK == true)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
- label_FacModeSysClear.BackColor = Color.Green;
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除失败" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- }
- }
-
- //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
- if (uARTToolStripMenuItem.Checked)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送复位指令,切换联动装置盒波特率" + "\r\n");
- Code[0] = (byte)'R';
- Code[1] = (byte)'E';
- Code[2] = (byte)'S';
- Code[3] = (byte)'E';
- Code[4] = (byte)'T';
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
- Delay_ms(500);
- }
- //系统清除后需重新开机
- label_FacModeStatus.Text = "重新开机";
- //确保测试前先关机,发送关机指令再发送开机指令
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新发送关机指令" + "\r\n");
- Code[0] = 0xF0;
- mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
- Delay_ms(3000);
- BootInfo = "";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新发送开机指令" + "\r\n");
- Code[0] = 0xF1;
- mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
- ACK_WaitCnt = 0;
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
- while (ACK_WaitCnt <= 20);
- //获取Boot版本信息
- if (BootInfo != string.Empty)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机成功" + "\r\n");
- Delay_ms(500);
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机失败" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- } while (false);
- }
- else
- {
- label_FacModeSysClear.BackColor = Color.Yellow;
- label_FacModeStatus.Text = "跳过系统清除!";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过系统清除" + "\r\n");
- Delay_ms(500);
- }
- #if false
- if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
- {
- Code[0] = 0x00;//5S协议
- Code[1] = 0x00;
- mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
- Delay_ms(500);
- mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
- Delay_ms(500);
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
- }
- #endif
- //检查是否有故障
- if (textBox_ErrorCode.Text.Contains("H"))
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "故障码:" + textBox_ErrorCode.Text + "\r\n");
- label_FacModeStatus.Text = "电机存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- //MOS内阻校准
- if (checkBox_FacMode_MosCal.Checked)
- {
- label_FacModeStatus.Text = "MOS内阻校准";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始MOS内阻校准" + "\r\n");
- Delay_ms(500);
- //提示进行负载切换
- if (MessageBox.Show("电阻负载切换完成,开始校准?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "取消MOS内阻校准" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- //确认后发送校准指令
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令" + "\r\n");
- string[] K = toolStripTextBox_MosCalK.Text.Split(',');
- Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
- ushort uwDataTemp = 0;
- uwDataTemp = Convert.ToUInt16(K[0]);
- Code[2] = (byte)(uwDataTemp & 0xFF);
- Code[3] = (byte)(uwDataTemp >> 8);
- uwDataTemp = Convert.ToUInt16(K[1]);
- Code[4] = (byte)(uwDataTemp & 0xFF);
- Code[5] = (byte)(uwDataTemp >> 8);
- uwDataTemp = Convert.ToUInt16(K[2]);
- Code[6] = (byte)(uwDataTemp & 0xFF);
- Code[7] = (byte)(uwDataTemp >> 8);
- uwDataTemp = Convert.ToUInt16(K[3]);
- Code[8] = (byte)(uwDataTemp & 0xFF);
- Code[9] = (byte)(uwDataTemp >> 8);
- uwDataTemp = Convert.ToUInt16(K[4]);
- Code[10] = (byte)(uwDataTemp & 0xFF);
- Code[11] = (byte)(uwDataTemp >> 8);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
- WriteACK = false;
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 6) ; //3s
- if (WriteACK == true)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令,第1次重发" + "\r\n");
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 6) ; //3s
- if (WriteACK == true)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令,第2次重发" + "\r\n");
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 6) ; //3s
- if (WriteACK == true)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准异常" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- }
- }
- #if false
- //因控制器复位需发送指令重新进入5S协议
- if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
- {
- Code[0] = 0x00;//5S协议
- Code[1] = 0x00;
- mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
- Delay_ms(500);
- mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
- Delay_ms(500);
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
- }
- #endif
- //读取显示校准返回数据
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果" + "\r\n");
- foreach (Control c in groupBox21.Controls)
- {
- if (c is TextBox)
- c.Text = "";
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果,第1次重发" + "\r\n");
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果,第2次重发" + "\r\n");
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果异常" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- }
- }
- else
- {
- 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");
- }
- //与校准返回数据对比
- string[] MOS_R1_Th = toolStripTextBox_MOS1.Text.Split(',');
- string[] MOS_R2_Th = toolStripTextBox_MOS2.Text.Split(',');
- string[] MOS_R3_Th = toolStripTextBox_MOS3.Text.Split(',');
- 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])) &&
- (Convert.ToUInt16(textBox_MOS_R2.Text) >= Convert.ToUInt16(MOS_R2_Th[0])) && (Convert.ToUInt16(textBox_MOS_R2.Text) <= Convert.ToUInt16(MOS_R2_Th[1])) &&
- (Convert.ToUInt16(textBox_MOS_R3.Text) >= Convert.ToUInt16(MOS_R3_Th[0])) && (Convert.ToUInt16(textBox_MOS_R3.Text) <= Convert.ToUInt16(MOS_R3_Th[1]))
- )
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准合格" + "\r\n");
- label_FacModeMosCal.BackColor = Color.Green;
- //提示切换负载
- MessageBox.Show("请将负载切换回电机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准超范围" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- //提示切换负载
- MessageBox.Show("请将负载切换回电机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- }
- else
- {
- label_FacModeMosCal.BackColor = Color.Yellow;
- label_FacModeStatus.Text = "跳过MOS内阻校准!";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过MOS内阻校准" + "\r\n");
- Delay_ms(500);
- }
- //位置校准
- if (checkBox_FacMode_AngleCal.Checked)
- {
- //校准前进行一次开关机保存初始化数据
- label_FacModeStatus.Text = "位置校准";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始位置校准" + "\r\n");
- //确保测试前先关机,发送关机指令再发送开机指令
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
- Code[0] = 0xF0;
- mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
- Delay_ms(1500);
- BootInfo = "";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
- Code[0] = 0xF1;
- mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
- ACK_WaitCnt = 0;
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
- while (ACK_WaitCnt <= 10) ; //5s
- //获取Boot版本信息
- if (BootInfo != string.Empty)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机成功" + "\r\n");
- Delay_ms(500);
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机失败" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- //发送位置校准指令
- for (int i = 0; i < 7; i++)
- for (int j = 0; j < 6; j++)
- {
- dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = "";
- }
- foreach (Control cr in tabPage_AngleCal.Controls)
- {
- if (cr is TextBox)
- {
- if ((cr != textBox_AngleDiffTh) && (cr != textBox_AngleZeroTh))
- cr.Text = "";
- }
- }
- Code[0] = 0;
- Code[1] = 0;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x0C, (ushort)0x5002, Code);
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准中,请等待" + "\r\n");
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 50) ; //25s
- //读取位置校准数据
- if (textBox_AngleDiffAvg.Text == string.Empty)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准失败" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准数据:" + "\r\n");
- for (int i = 0; i < 7; i++)
- {
- richTextBox_FacModeLog.AppendText("电周期" + (i + 1).ToString()+":");
- for (int j = 0; j < 6; j++)
- {
- richTextBox_FacModeLog.AppendText(dataGridView_AngleCal.Rows[i].Cells[j + 1].Value.ToString() + ", ");
- }
- richTextBox_FacModeLog.AppendText("\r\n");
- Delay_ms(200);
- }
- richTextBox_FacModeLog.AppendText("最小偏差:" + textBox_AngleDiffMin.Text+ ", " + "\r\n");
- richTextBox_FacModeLog.AppendText("最大偏差:" + textBox_AngleDiffMax.Text + ", " + "\r\n");
- richTextBox_FacModeLog.AppendText("平均偏差:" + textBox_AngleDiffAvg.Text + ", " + "\r\n");
- richTextBox_FacModeLog.AppendText("历史零点:" + textBox_AngleZeroInit.Text + ", " + "\r\n");
- richTextBox_FacModeLog.AppendText("当前零点:" + textBox_AngleZeroCur.Text + ", " + "\r\n");
- richTextBox_FacModeLog.AppendText("零点偏差:" + textBox_AngleZeroDiff.Text + ", " + "\r\n");
- //比较位置偏差
- if ((Math.Abs(Convert.ToDouble(textBox_AngleDiffMin.Text)) > Convert.ToDouble(textBox_AngleDiffTh.Text)) ||
- (Math.Abs(Convert.ToDouble(textBox_AngleDiffMax.Text)) > Convert.ToDouble(textBox_AngleDiffTh.Text)) ||
- (Math.Abs(Convert.ToDouble(textBox_AngleDiffAvg.Text)) > Convert.ToDouble(textBox_AngleZeroTh.Text))
- )
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差过大,无法校准" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- //写入校准偏差值
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差满足要求,写入校准数据" + "\r\n");
- double data1 = Convert.ToDouble(textBox_AngleZeroInit.Text) - Convert.ToDouble(textBox_AngleDiffAvg.Text);
- if (data1 > 360)
- {
- data1 -= 360;
- }
- else if (data1 < -360)
- {
- data1 += 360;
- }
- Int16 data2 = (Int16)(data1 * 32768 / 360);
- Code[0] = 0x01;
- Code[1] = 0x00;
- Code[2] = (byte)(data2);
- Code[3] = (byte)(data2 >> 8);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
- WriteACK = false;
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (WriteACK == true)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入位置偏差,第1次重发" + "\r\n");
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
- WriteACK = false;
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (WriteACK == true)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入位置偏差,第2次重发" + "\r\n");
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
- WriteACK = false;
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (WriteACK == true)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入失败" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- }
- }
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准正常,位置偏差值:" + textBox_AngleDiffAvg.Text + "\r\n");
- label_FacModeAngleCal.BackColor = Color.Green;
- }
- else
- {
- label_FacModeAngleCal.BackColor = Color.Yellow;
- label_FacModeStatus.Text = "跳过位置校准!";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过位置校准" + "\r\n");
- Delay_ms(500);
- }
- //参数写入
- if (checkBox_FacModeCfgWrite.Checked)
- {
- label_FacModeStatus.Text = "参数写入";
- //写入产品型号和SN
- do
- {
- //根据扫码信息获取型号和SN
- string ScanInfo = textBox_FacModeScan.Text;
- string regexInfo = "";
- string[] InfoList = { "" };
- try
- {
- if (中置电机MIGIC_ToolStripMenuItem.Checked == true)
- {
- regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
- InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
- }
- else if (中置电机VP_ToolStripMenuItem.Checked == true)
- {
- Regex regex = new Regex(@"^M[12][0-9](0?[1-9]|1[0-2])((0?[1-9])|((1|2)[0-9])|30|31)[A-Z]\d{4}[A-Z][A-Z]?$");
- if (ScanInfo.Contains(" "))
- {
- InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
- string Mode = InfoList[0];
- string Sn = InfoList[1];
- if (regex.IsMatch(Sn) == false)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN格式错误" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "标签格式错误";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "标签格式错误";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- }
- else if (轮毂电机ToolStripMenuItem.Checked == true)
- {
- if (!ScanInfo.Contains("/")) //老编码规则
- {
- InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
- string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
- string Spec = InfoList[1];
- string Sn = InfoList[2];
- InfoList[0] = Model.Substring(2, 12) + Spec.Substring(Spec.Length - 4);
- InfoList[1] = Sn;
- }
- else //新编码规则
- {
- Dictionary<string, string> Dic_Ver = new Dictionary<string, string>
- {
- { "01", "A" },
- { "02", "B" },
- { "03", "C" },
- { "04", "D" },
- { "05", "E" },
- { "06", "F" },
- { "07", "G" },
- { "08", "H" },
- { "09", "I" }
- };
- Dictionary<string, string> Dic_Vol = new Dictionary<string, string>
- {
- { "24V", "A" },
- { "36V", "B" },
- { "42V", "C" },
- { "48V", "D" },
- { "52V", "E" },
- { "60V", "F" }
- };
- InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
- string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
- string Spec = InfoList[1].Replace("-", "").Replace("/", "");
- string Sn = InfoList[2];
- InfoList[0] = Model[2] + Dic_Ver[Model.Substring(3, 2)] + Model[5] + Dic_Ver[Model.Substring(6, 2)] + Model[9];
- InfoList[0] += Dic_Vol[Spec.Substring(0, 3)] + Spec.Substring(3, 3) + Spec.Substring(13, 4) + Spec.Substring(Spec.Length - 4, 3);
- InfoList[1] = Sn;
- }
- }
- }
- catch
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "标签格式错误";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
-
- if (InfoList.Length >= 2)
- {
- //检查配置文件是否与打标信息一致
- //...
- //写入型号
- label_FacModeStatus.Text = "写入型号";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号" + "\r\n");
- textBox_FacModeName.Text = InfoList[0];
- string Mode = textBox_FacModeName.Text;
- var ModeArray = new byte[16];
- for (ushort i = 0; i < Mode.Length; i++)
- {
- ModeArray[i] = (byte)Mode[i];
- }
- if (Mode.Length < 16)
- {
- ModeArray[Mode.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
- {
- ModeArray[Mode.Length + 1 + i] = 0x20;
- }
- }
-
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
- WriteACK = false;
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2); //1s
- if (WriteACK == true)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号,第1次重发" + "\r\n");
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (WriteACK == true)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号,第2次重发" + "\r\n");
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (WriteACK == true)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入失败" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- }
- }
- //写入SN
- label_FacModeStatus.Text = "写入SN";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN" + "\r\n");
- textBox_FacModeNum.Text = InfoList[1];
- string SN = textBox_FacModeNum.Text;
- var SNArray = new byte[16];
- for (ushort i = 0; i < SN.Length; i++)
- {
- SNArray[i] = (byte)SN[i];
- }
- if (SN.Length < 16)
- {
- SNArray[SN.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - SN.Length - 1; i++)
- {
- SNArray[SN.Length + 1 + i] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
- WriteACK = false;
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2); //1s
- if (WriteACK == true)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN,第1次重发" + "\r\n");
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (WriteACK == true)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN,第2次重发" + "\r\n");
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (WriteACK == true)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入失败" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- }
- }
- }
- else
- {
- MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- } while (false);
- //写入配置文件
- do
- {
- label_FacModeStatus.Text = "写入配置文件";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
- //配置文件
- List<byte[]> CmdList = new List<byte[]>();
- //从服务器下载文件
- if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
- {
- string SelectFile = "";
- SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "/" + comboBox_FacModeCfgFile.SelectedItem.ToString();
- if (File.Exists(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
- {
- File.Delete(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
- }
- myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
- //打开文件
- StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
- CmdList.Clear();
- while (streamReader.Peek() != -1)
- {
- string fileLineInfo = streamReader.ReadLine();
- if (fileLineInfo.IndexOf("[") != -1)
- {
- continue;
- }
- CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
- }
- streamReader.Close();
- }
- //加载本地文件
- else
- {
- string SelectFile = "";
- SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_FacModeCfgFile.SelectedItem.ToString();
- StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
- CmdList.Clear();
- while (streamReader.Peek() != -1)
- {
- string fileLineInfo = streamReader.ReadLine();
- if (fileLineInfo.IndexOf("[") != -1)
- {
- continue;
- }
- CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
- }
- streamReader.Close();
- }
-
- int CmdNum = CmdList.Count(); //指令个数
- Delay_ms(500);
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "开始写入" + "\r\n");
- Delay_ms(500);
- //开始写入
- for (int i = 0; i < CmdList.Count; i++)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令" + "\r\n");
- mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
- WriteACK = false;
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (WriteACK == true)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令,第1次重发" + "\r\n");
- mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
- WriteACK = false;
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (WriteACK == true)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令,第2次重发" + "\r\n");
- mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
- WriteACK = false;
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (WriteACK == true)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入失败," + "共" + CmdNum.ToString() + "条指令," + "写入成功" + i.ToString() + "条" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- }
- }
- }
- //写入完成
- label_FacMode_CfgWrite.BackColor = Color.Green;
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入成功" + "\r\n");
- Delay_ms(500);
- } while (false);
- }
- else
- {
- label_FacMode_CfgWrite.BackColor = Color.Yellow;
- label_FacModeStatus.Text = "跳过参数写入!";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数写入" + "\r\n");
- Delay_ms(500);
- }
- //BMS通讯
- if (checkBox_FacModeBMS.Checked)
- {
- if (label_FacModeBMS.BackColor == Color.Red)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "BMS通讯异常" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- }
- else
- {
- label_FacModeBMS.BackColor = Color.Yellow;
- label_FacModeStatus.Text = "跳过BMS通讯检测!";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过BMS通讯检测" + "\r\n");
- Delay_ms(500);
- }
- //基础功能检测
- if (checkBox_FacBaseFucTest.Checked)
- {
- label_FacModeStatus.Text = "基础功能检测";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始基础功能检测" + "\r\n");
- //确认负载位置
- if (checkBox_FacMode_MosCal.Checked)
- {
- if (MessageBox.Show("请再次确认负载是否切换回电机?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "负载已切换为电机,继续测试" + "\r\n");
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试取消" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- }
- //发送指令进入配置模式
- do
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
- Code[0] = 0x01;
- mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
- WriteACK = false;
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2); //1s
- if (textBox_RunInfo_Vol.Text != "---")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
- mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (textBox_RunInfo_Vol.Text != "---")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
- mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (textBox_RunInfo_Vol.Text != "---")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- }
- }
- } while (false);
- //发送指令启动电机
- do
- {
- #if false //通过运行模式3启动电机
- //发送指令读取调试信息
- richTextBox_DebugParam.Clear();
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
- WriteACK = false;
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2); //1s
- //获取调试信息
- string DebugDefaultInfo = "";
- if (richTextBox_DebugParam.Text == string.Empty)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- else
- {
- DebugDefaultInfo = richTextBox_DebugParam.Text;
- }
- //设置模式
- string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
- strDataTemp[0] = "整体运行模式=3";
- //发送数据
- Code[0] = 0;
- Code[1] = 0;
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
- Code[2 * i + 2] = (byte)uwDataTemp;
- Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
- label_FacModeStatus.Text = "启动电机";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "启动电机" + "\r\n");
- #else //通过Walk模式启动电机
- //设置转速100%
- var Data = new byte[1];
- Data[0] = (byte)100;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
- Delay_ms(500);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
- Delay_ms(500);
- //启动电机进入WALK模式
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "基础功能检测,进入WALK" + "\r\n");
- Code[0] = 0x22;
- Code[1] = 0xF0;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
- WriteACK = false;
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第1次重发" + "\r\n");
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第2次重发" + "\r\n");
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- }
- }
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入WALK,开始检测" + "\r\n");
- #endif
- Delay_ms(5000);
- } while (false);
- //判断车速
- if ((Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) <= Convert.ToDouble( toolStripTextBox_ThBikeSpeed.Text.Split(',')[1])) &&
- (Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThBikeSpeed.Text.Split(',')[0])))
- {
- label_FacModeSpeed.BackColor = Color.Green;
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器正常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器异常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- //判断电压
- if ((Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[1])) &&
- (Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[0])))
- {
- label_FacModeVolTest.BackColor = Color.Green;
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量正常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量异常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- //判断电流
- if ((Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[1])) &&
- (Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[0])))
- {
- label_FacModeCurrentTest.BackColor = Color.Green;
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量正常" + " " + textBox_RunInfo_Current.Text + "\r\n");
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量异常" + " " + textBox_RunInfo_Current.Text + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- //判断温度
- if ((Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[1])) &&
- (Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[0])) &&
- (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[1])) &&
- (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[0])) &&
- (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[1])) &&
- (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[0])))
- {
- label_FacModeNTC.BackColor = Color.Green;
- 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");
- }
- else
- {
- 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");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- //判断转速
- if ((Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[1])) &&
- (Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[0])))
- {
- label_FacModeMotorSpeed.BackColor = Color.Green;
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速正常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速异常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- //中置判断踏频
- if ((中置电机MIGIC_ToolStripMenuItem.Checked == true) || (中置电机VP_ToolStripMenuItem.Checked == true))
- {
- if ((Convert.ToDouble(textBox_RunInfo_Cadence.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[1])) &&
- (Convert.ToDouble(textBox_RunInfo_Cadence.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[0])))
- {
- label_FacModeCad.BackColor = Color.Green;
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器正常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器异常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- }
- //发送指令停止电机
- do
- {
- //设置转速0%
- var Data = new byte[1];
- Data[0] = (byte)0;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
- Delay_ms(500);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
- Delay_ms(500);
- #if false //通过修改调试模式停止电机
- //获取调试信息
- string DebugDefaultInfo = "";
- if (richTextBox_DebugParam.Text == string.Empty)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- else
- {
- DebugDefaultInfo = richTextBox_DebugParam.Text;
- }
- //设置模式
- string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
- //发送数据
- Code[0] = 0;
- Code[1] = 0;
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
- Code[2 * i + 2] = (byte)uwDataTemp;
- Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
- label_FacModeStatus.Text = "停止电机";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "停止电机" + "\r\n");
- #else //通过调整档位停止电机
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK" + "\r\n");
- Code[0] = 0x00;
- Code[1] = 0xF0;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
- WriteACK = false;
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (textBox_RunInfo_GearSt.Text != "OFF")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK,第1次重发" + "\r\n");
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (textBox_RunInfo_GearSt.Text != "OFF")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK,第2次重发" + "\r\n");
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (textBox_RunInfo_GearSt.Text != "OFF")
- {
-
- }
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- }
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已退出WALK,基础功能检测完成" + "\r\n");
- #endif
- Delay_ms(2000);
- } while (false);
- }
- else
- {
- label_FacModeSpeed.BackColor = Color.Yellow;
- label_FacModeVolTest.BackColor = Color.Yellow;
- label_FacModeCurrentTest.BackColor = Color.Yellow;
- label_FacModeNTC.BackColor = Color.Yellow;
- label_FacModeMotorSpeed.BackColor = Color.Yellow;
- label_FacModeStatus.Text = "跳过基础功能检测!";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过基础功能检测" + "\r\n");
- Delay_ms(500);
- }
- //力矩检测
- if (checkBox_FacTor.Checked)
- {
- label_FacModeStatus.Text = "力矩传感器检测!";
- //发送指令进入配置模式
- do
- {
- if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
- {
- break;
- }
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
- Code[0] = 0x01;
- mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
- WriteACK = false;
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (textBox_RunInfo_Vol.Text != "---")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
- Delay_ms(500);
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
- mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (textBox_RunInfo_Vol.Text != "---")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
- Delay_ms(500);
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
- mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (textBox_RunInfo_Vol.Text != "---")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
- Delay_ms(500);
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- }
- }
- } while (false);
- ushort Max = 0, Torque = 0;
- //提示输入力矩信号
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟力矩信号输入" + "\r\n");
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 20) //10s
- {
- //获取力矩值
- Torque = (ushort)Convert.ToInt16(textBox_RunInfo_Torque.Text.Split(' ')[0]);
- if (Torque > Max)
- Max = Torque;
- if ((Max <= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[1])) &&
- (Max >= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[0])) &&
- (ACK_WaitCnt >= 6))
- {
- label_FacModeTq.BackColor = Color.Green;
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器正常" + " " + textBox_RunInfo_Torque.Text + "\r\n");
- break;
- }
- }
- if (ACK_WaitCnt >= 20)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器异常" + " " + textBox_RunInfo_Torque.Text + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- }
- else
- {
- label_FacModeTq.BackColor = Color.Yellow;
- label_FacModeStatus.Text = "跳过力矩检测!";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过力矩检测" + "\r\n");
- Delay_ms(500);
- }
- //踏频检测
- if (checkBox_FacCad.Checked)
- {
- label_FacModeStatus.Text = "踏频传感器检测!";
- //发送指令进入配置模式
- do
- {
- if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
- {
- break;
- }
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
- Code[0] = 0x01;
- mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
- WriteACK = false;
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (textBox_RunInfo_Vol.Text != "---")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
- Delay_ms(500);
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
- mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (textBox_RunInfo_Vol.Text != "---")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
- Delay_ms(500);
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
- mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (textBox_RunInfo_Vol.Text != "---")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
- Delay_ms(500);
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- }
- }
- } while (false);
- ushort Max = 0, Cadence = 0;
- //提示输入踏频信号
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟踏频信号输入" + "\r\n");
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 20) //10s
- {
- //获取踏频
- Cadence = (ushort)Convert.ToInt16(textBox_RunInfo_Cadence.Text.Split(' ')[0]);
- if (Cadence > Max)
- Max = Cadence;
- if ((Max <= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[1])) &&
- (Max >= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[0])) &&
- (ACK_WaitCnt >= 6)) //3s内有踏频值达到阈值
- {
- label_FacModeCad.BackColor = Color.Green;
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器正常" + " " + Max.ToString() + " rpm" + "\r\n");
- break;
- }
- }
- if (ACK_WaitCnt >= 20)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器异常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- }
- else
- {
- label_FacModeCad.BackColor = Color.Yellow;
- label_FacModeStatus.Text = "跳过踏频检测!";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过踏频检测" + "\r\n");
- Delay_ms(500);
- }
- //转把检测
- if (checkBox_FacThrrotleTest.Checked)
- {
- label_FacModeStatus.Text = "转把检测";
- //发送指令进入配置模式
- do
- {
- if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
- {
- break;
- }
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
- Code[0] = 0x01;
- mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
- WriteACK = false;
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (textBox_RunInfo_Vol.Text != "---")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
- Delay_ms(500);
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
- mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (textBox_RunInfo_Vol.Text != "---")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
- Delay_ms(500);
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
- mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (textBox_RunInfo_Vol.Text != "---")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
- Delay_ms(500);
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- }
- }
- } while (false);
- //进入TURBO档
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把检测,发送指令进入TURBO" + "\r\n");
- Code[0] = 0x04;
- Code[1] = 0xF0;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
- WriteACK = false;
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (textBox_RunInfo_GearSt.Text != "TURBO")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO,第1次重发" + "\r\n");
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (textBox_RunInfo_GearSt.Text != "TURBO")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO,第2次重发" + "\r\n");
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (textBox_RunInfo_GearSt.Text != "TURBO")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO异常" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- }
- }
- //进入TURBO后,如果电机直接启动,认为转把电压异常
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把自检,请松开转把" + "\r\n");
- Delay_ms(3000);
- if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) > 500)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把电压异常" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把自检正常" + "\r\n");
- Delay_ms(500);
- //提示转动转把
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入TURBO,10s内转动转把" + "\r\n");
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 20)
- {
- if ((Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) > 500) && (ACK_WaitCnt >= 10)) //5s
- {
- label_FacModeGas.BackColor = Color.Green;
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能正常,电机转速:" + textBox_RunInfo_MotorSpeed.Text + ",请松开转把" + "\r\n");
- break;
- }
- }
- if (ACK_WaitCnt >= 20) //转把超时
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能异常,请松开转把" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- }
- else
- {
- label_FacModeGas.BackColor = Color.Yellow;
- label_FacModeStatus.Text = "跳过转把检测!";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过转把检测" + "\r\n");
- Delay_ms(500);
- }
- //刹车检测
- if (checkBox_FacBreakTest.Checked)
- {
- label_FacModeStatus.Text = "刹把检测";
- //发送指令进入配置模式
- do
- {
- if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
- {
- break;
- }
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
- Code[0] = 0x01;
- mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
- WriteACK = false;
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (textBox_RunInfo_Vol.Text != "---")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
- Delay_ms(500);
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
- mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (textBox_RunInfo_Vol.Text != "---")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
- Delay_ms(500);
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
- mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (textBox_RunInfo_Vol.Text != "---")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
- Delay_ms(500);
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- }
- }
- } while (false);
- //测试前先确定电机已停止
- UInt16 WaitTime = 20;
- do
- {
- WaitTime--;
- if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 100)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机停止,开始进行剎把检测,进入WALK" + "\r\n");
- break;
- }
- if (WaitTime == 0)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机无法停止,剎把检测异常" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- Delay_ms(500);
- } while (true);
- //设置转速100%
- var Data = new byte[1];
- Data[0] = (byte)100;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
- Delay_ms(500);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
- Delay_ms(500);
- //启动电机进入WALK模式
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把检测,进入WALK" + "\r\n");
- Code[0] = 0x22;
- Code[1] = 0xF0;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
- WriteACK = false;
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 500))
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第1次重发" + "\r\n");
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 500))
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第2次重发" + "\r\n");
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 500))
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- }
- }
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,10s内操作剎把" + "\r\n");
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 20)
- {
- if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 100)
- {
- label_FacModeBreak.BackColor = Color.Green;
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把功能正常,松开剎把" + "\r\n");
- break;
- }
- }
- if (ACK_WaitCnt >= 20) //剎把超时
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速:" + textBox_RunInfo_MotorSpeed.Text + "," + "剎把功能异常,松开剎把" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- //停止电机
- Code[0] = 0x00;
- Code[1] = 0xF0;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
- WriteACK = false;
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (textBox_RunInfo_GearSt.Text != "OFF")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK,第1次重发" + "\r\n");
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (textBox_RunInfo_GearSt.Text != "OFF")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK,第2次重发" + "\r\n");
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (textBox_RunInfo_GearSt.Text != "OFF")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- }
- }
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK" + "\r\n");
- Delay_ms(500);
- }
- else
- {
- label_FacModeBreak.BackColor = Color.Yellow;
- label_FacModeStatus.Text = "跳过刹车检测!";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过刹车检测" + "\r\n");
- Delay_ms(500);
- }
- //前后灯检测
- if (checkBox_FacLightTest.Checked)
- {
- //前后灯检测
- label_FacModeStatus.Text = "前后灯检测";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开灯指令" + "\r\n");
- //发送指令打开车灯
- Code[0] = 0x00;
- Code[1] = 0xF1;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
- WriteACK = false;
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (textBox_RunInfo_LightSwitch.Text != "ON")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令,第1次重发" + "\r\n");
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2); //1s
- if (textBox_RunInfo_LightSwitch.Text != "ON")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令,第2次重发" + "\r\n");
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (textBox_RunInfo_LightSwitch.Text != "ON")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令发送异常" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- }
- }
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已打开前后灯" + "\r\n");
- Delay_ms(500);
- //提示检查灯压是否正确
- if (MessageBox.Show("前后灯是否正常开启?", "前后灯判断", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯开启正常" + "\r\n");
- Delay_ms(500);
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯开启异常" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- //发送指令关闭车灯
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关灯指令" + "\r\n");
- Code[0] = 0x00;
- Code[1] = 0xF0;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
- WriteACK = false;
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (textBox_RunInfo_LightSwitch.Text != "OFF")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令,第1次重发" + "\r\n");
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (textBox_RunInfo_LightSwitch.Text != "OFF")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令,第2次重发" + "\r\n");
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (textBox_RunInfo_LightSwitch.Text != "OFF")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令发送异常" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- }
- }
- //提示检查灯压是否关闭
- if (MessageBox.Show("前后灯是否正常关闭?", "前后灯判断", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- label_FacModeLightF.BackColor = Color.Green;
- label_FacModeLightB.BackColor = Color.Green;
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯关闭正常" + "\r\n");
- Delay_ms(500);
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯关闭异常" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已关闭前后灯" + "\r\n");
- }
- else
- {
- label_FacModeLightF.BackColor = Color.Yellow;
- label_FacModeLightB.BackColor = Color.Yellow;
- label_FacModeStatus.Text = "跳过前后灯检测!";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过前后灯检测" + "\r\n");
- Delay_ms(500);
- }
- //软件版本检测
- do
- {
- label_FacModeStatus.Text = "软件版本确认";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
- //发送指令读取版本
- Class_Motor_Ver.Mode = "---";
- Class_Motor_Ver.SN = "---";
- Class_Motor_Ver.HW = "---";
- Class_Motor_Ver.FW = "---";
- Class_Motor_Ver.Special = "---";
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (Class_Motor_Ver.Mode == "---")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第1次重发" + "\r\n");
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (Class_Motor_Ver.Mode == "---")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第2次重发" + "\r\n");
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (Class_Motor_Ver.Mode == "---")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息失败" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- }
- }
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
- richTextBox_FacModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
- richTextBox_FacModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
- richTextBox_FacModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
- richTextBox_FacModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
- richTextBox_FacModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
- //判断版本是否正确
- string VerCheck = comboBox_FacModeCfgFile.Text.Split('_')[3] + "_" + comboBox_FacModeCfgFile.Text.Split('_')[4];
- string VerRead = "";
- try
- {
- VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
- }
- catch (System.Exception)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- label_FacModeFWVersion.BackColor = Color.Green;
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
- Delay_ms(500);
- } while (false);
- //测试合格
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
- label_FacModeStatus.Text = "测试结束!";
- label_FacModeResult.BackColor = Color.Green;
- label_FacModeResult.Text = "测试合格";
- Delay_ms(500);
- //存储并上传
- FacMode_Stop(true);
- return;
- }
- private void FacModelLabelInit()
- {
- //测试状态标签
- label_FacModeResult.BackColor = Color.Yellow;
- label_FacModeResult.Text = "测试中";
- //测试过程标签
- label_FacModeStatus.Text = "测试就绪";
- //测试结果标签
- foreach (Control c in groupBox28.Controls)
- {
- if (c is Label)
- {
- if (c.Text == string.Empty)
- c.BackColor = Color.Red;
- }
- }
- }
- private void comboBox_CheckModeCfgDate_Click(object sender, EventArgs e)
- {
- //更新生产配置文件目录
- GetDateList(false);
- }
- private void comboBox_FacModeCfgDate_Click(object sender, EventArgs e)
- {
- //更新生产配置文件目录
- GetDateList(false);
- }
- private void richTextBox_FacModeLog_TextChanged(object sender, EventArgs e)
- {
- richTextBox_FacModeLog.SelectionStart = richTextBox_FacModeLog.Text.Length;
- richTextBox_FacModeLog.ScrollToCaret();
- }
- /// <summary>
- /// 参数检验测试停止
- /// </summary>
- /// <param name="OK_Flag"></param>
- private void CheckMode_Stop(bool OK_Flag)
- {
- //打开开始按钮
- button_CheckModeStart.Enabled = true;
- //导出电机参数
- string Params = "";
- do
- {
- if (!OK_Flag)
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试异常,停止导出" + "\r\n");
- break;
- }
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "导出电机存储参数" + "\r\n");
- //读取一次马达参数
- richTextBox_MotorParam.Clear();
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break; ;
- Delay_ms(100);
- Params += "[马达参数]" + "\r\n" + richTextBox_MotorParam.Text + "\r\n";
- Params += "\r\n";
- //读取一次整车参数
- richTextBox_BikeParam.Clear();
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
- Delay_ms(100);
- Params += "[整车参数]" + "\r\n" + richTextBox_BikeParam.Text + "\r\n";
- Params += "\r\n";
- //读取一次控制参数
- richTextBox_ControlParam.Clear();
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
- Delay_ms(100);
- Params += "[控制参数]" + "\r\n" + richTextBox_ControlParam.Text + "\r\n";
- Params += "\r\n";
- //查询传感器
- richTextBox_SensorParam.Clear();
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
- Delay_ms(100);
- Params += "[传感器参数]" + "\r\n" + richTextBox_SensorParam.Text + "\r\n";
- Params += "\r\n";
- //读取15次助力参数
- Params += "[助力参数]" + "\r\n";
- for (int i = 1; i <= 15; i++)
- {
- var ConfigParam = new byte[4];
- richTextBox_AssistParam.Clear();
- ConfigParam[0] = (byte)(i & 0xFF);
- ConfigParam[1] = (byte)(i >> 8);
- ConfigParam[2] = (byte)(((i >= 5) ? 5 : i) & 0xFF);
- ConfigParam[3] = (byte)(((i >= 5) ? 5 : i) >> 8);
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
- Delay_ms(200);
- Params += richTextBox_AssistParam.Text + "\r\n";
- Params += "\r\n";
- }
-
- //读取一次调试信息
- richTextBox_DebugParam.Clear();
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
- Delay_ms(100);
- Params += "[调试参数]" + "\r\n" + richTextBox_DebugParam.Text + "\r\n";
- Params += "\r\n";
- //读取一次历史信息
- richTextBox_Record.Clear();
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
- Delay_ms(100);
- Params += "[历史信息]" + "\r\n" + richTextBox_Record.Text + "\r\n";
- Params += "\r\n";
- //读取一次MOS内阻校准参数
- foreach (Control c in groupBox21.Controls)
- {
- if (c is TextBox)
- c.Text = "";
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
- Delay_ms(100);
- Params += "[MOS内阻校准参数]" + "\r\n";
- Params += textBox_MOS_K1.Text + ", " + textBox_MOS_K2.Text + ", " + textBox_MOS_K3.Text + ", " + textBox_MOS_K4.Text + ", "
- + textBox_MOS_K5.Text + ", " + textBox_MOS_R1.Text + ", " + textBox_MOS_R2.Text + ", " + textBox_MOS_R3.Text + ", " + "\r\n";
- Params += "\r\n";
- //读取一次整车参数2
- richTextBox_BikeParam2.Clear();
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null)) break;
- Delay_ms(100);
- Params += "[整车参数2]" + "\r\n" + richTextBox_BikeParam2.Text + "\r\n";
- Params += "\r\n";
- //读取一次用户骑行参数
- richTextBox_UsrRidesParam.Clear();
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
- Delay_ms(100);
- Params += "[用户骑行参数]" + "\r\n" + richTextBox_UsrRidesParam.Text + "\r\n";
- Params += "\r\n";
- //读取一次生产信息
- textBox_MAC.Text = "";
- textBox_MACAdd.Text = "";
- textBox_MACDate.Text = "";
- textBox_PP.Text = "";
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
- Delay_ms(100);
- Params += "[生产信息]" + "\r\n";
- Params += "生产商: " + textBox_MAC.Text + "\r\n";
- Params += "生产地: " + textBox_MACAdd.Text + "\r\n";
- Params += "生产日期: " + textBox_MACDate.Text + "\r\n";
- Params += "产品标识: " + textBox_PP.Text + "\r\n";
- Params += "\r\n";
- //读取一次自定义信息
- textBox_User1.Text = "---";
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
- Delay_ms(100);
- textBox_User2.Text = "---";
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
- Delay_ms(100);
- textBox_User3.Text = "---";
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
- Delay_ms(100);
- Params += "[自定义信息]" + "\r\n";
- Params += "自定义1: " + textBox_User1.Text + "\r\n";
- Params += "自定义2: " + textBox_User2.Text + "\r\n";
- Params += "自定义3: " + textBox_User3.Text + "\r\n";
- Params += "\r\n";
- //读取一次密钥
- textBox_Key.Text = "---";
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
- Delay_ms(100);
- Params += "[校验密钥]" + "\r\n" + textBox_Key.Text + "\r\n";
- Params += "\r\n";
- //读取一次存储标志
- radioButton_EE_SaveYes.Checked = false;
- radioButton_EE_SaveNo.Checked = false;
- radioButton_SIP_SaveYes.Checked = false;
- radioButton_SIP_SaveNo.Checked = false;
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
- Delay_ms(100);
- Params += "[存储标志]" + "\r\n";
- Params += "EEPROM: " + ((radioButton_EE_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
- Params += "SIP: " + ((radioButton_SIP_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
- Params += "\r\n";
- } while (false);
- //系统关机
- var Code = new byte[32];//发送的指令数据
- Code[0] = 0xF0;
- mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
- //关闭串口
- //mySerialProcess.SerialClose(false);
- //路径设置
- string LocalSavePath = "";
- string ServerSavePath = "";
- if (OK_Flag)
- {
- LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "OK\\";
- ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/OK/";
- }
- else
- {
- LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "FAIL\\";
- ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/FAIL/";
- }
- if (Directory.Exists(LocalSavePath) == false)
- {
- Directory.CreateDirectory(LocalSavePath);
- }
- //保存和上传
- string LogSavePath = "";
- string LogSaveFileName = "";
- string ProductInfo = textBox_CheckModeScan.Text.Replace(" ", "_").Replace("/", "-"); ;
- LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
- if (Directory.Exists(LogSavePath) == false)
- {
- Directory.CreateDirectory(LogSavePath);
- }
- //测试页面
- Double scaleX = PrimaryScreen.ScaleX;
- Double scaleY = PrimaryScreen.ScaleY;
- Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
- Graphics g = Graphics.FromImage(bit);
- g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
- LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
- bit.Save(LogSaveFileName);
- //上传测试页面到服务器
- if (myFtp.IsNetConnected == true)
- {
- string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
- if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
- {
- myFtp.MakeDir(ServerSavePath + DateNow);
- }
- if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
- {
- myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
- }
- bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
- if (result == true)
- richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
- }
- //测试记录
- LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
- string file_str = "";
- file_str += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
- file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
- file_str += "检验记录:\r\n" + richTextBox_CheckModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
- file_str += "检验结果:\r\n" + label_CheckModeResult.Text + "\r\n\r\n";
- file_str += Local_HdInformation;
- file_str += "\r\n电机存储参数:\r\n" + Params + "\r\n";
- System.IO.File.WriteAllText(LogSaveFileName, file_str);
- //上传测试记录到服务器
- if (myFtp.IsNetConnected == true)
- {
- string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
- if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
- {
- myFtp.MakeDir(ServerSavePath + DateNow);
- }
- if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
- {
- myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
- }
- bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
- if (result == true)
- richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
- }
- //扫码框清空
- textBox_CheckModeScan.Text = "";
- }
- /// <summary>
- /// 参数检验开始
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_CheckModeStart_Click(object sender, EventArgs e)
- {
- //测试项目关闭编辑
- pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
- foreach (Control c in groupBox29.Controls)
- {
- if (c is CheckBox)
- c.Enabled = false;
- }
- ReadLockStatus = true;
-
- //检查配置文件
- if (comboBox_CheckModeCfgFile.Text == "")
- {
- MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- //开始测试
- CheckTestStart();
- }
- /// <summary>
- /// 参数检验测试子函数
- /// </summary>
- private void CheckTestStart()
- {
- //初始化标签
- CheckModeLabelInit();
- richTextBox_CheckModeLog.Clear();
- //按钮禁止操作
- button_CheckModeStart.Enabled = false;
- //记录配置文件
- richTextBox_CheckModeLog.AppendText("配置文件:" + comboBox_CheckModeCfgDate.Text + " / " + comboBox_CheckModeCfgFile.Text + "\r\n");
- //检查打标信息
- label_CheckModeStatus.Text = "检查扫码信息";
- Delay_ms(500);
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
- if (textBox_CheckModeScan.Text == string.Empty)
- {
- MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- button__FacMode_Start.Enabled = false;
- return;
- }
- try
- {
- if (中置电机MIGIC_ToolStripMenuItem.Checked == true)
- {
- if (textBox_CheckModeScan.Text.Split(' ').Length != 7)
- {
- label_CheckModeStatus.Text = "存在故障!";
- label_CheckModeResult.BackColor = Color.Red;
- label_CheckModeResult.Text = "标签格式错误";
- button_CheckModeStart.Enabled = true;
- return;
- }
- }
- else if (中置电机VP_ToolStripMenuItem.Checked == true)
- {
- if (textBox_CheckModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 2)
- {
- label_CheckModeStatus.Text = "存在故障!";
- label_CheckModeResult.BackColor = Color.Red;
- label_CheckModeResult.Text = "标签格式错误";
- button_CheckModeStart.Enabled = true;
- return;
- }
- }
- else if (轮毂电机ToolStripMenuItem.Checked == true)
- {
- if (textBox_CheckModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
- {
- label_CheckModeStatus.Text = "存在故障!";
- label_CheckModeResult.BackColor = Color.Red;
- label_CheckModeResult.Text = "标签格式错误";
- button_CheckModeStart.Enabled = true;
- return;
- }
- }
- }
- catch (System.Exception)
- {
- label_CheckModeStatus.Text = "存在故障!";
- label_CheckModeResult.BackColor = Color.Red;
- label_CheckModeResult.Text = "标签格式错误";
- button_CheckModeStart.Enabled = true;
- return;
- }
- //打开串口
- mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false);
- if (!mySerialProcess.mySerial.IsOpen)
- {
- MessageBox.Show("请检查串口连接!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- button__FacMode_Start.Enabled = false;
- return;
- }
- //流水号计数
- int serial = Convert.ToInt32(label_CheckModeSerial.Text);
- serial += 1;
- label_CheckModeSerial.Text = serial.ToString();
- File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, serial.ToString());
- //创建线程,执行测试任务
- Thread th = new Thread(CheckModeTest_Task);
- th.Start();
- }
- /// <summary>
- /// 执行一次测试任务
- /// </summary>
- private void CheckModeTest_Task()
- {
- //开始测试
- richTextBox_CheckModeLog.AppendText("产品标签:" + textBox_CheckModeScan.Text + "\r\n");
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
- //变量定义
- var Code = new byte[255];//发送的指令数据
- label_CheckModeStatus.Text = "开始测试";
- Delay_ms(500);
- label_CheckModeStatus.Text = "系统开机";
- //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
- if (uARTToolStripMenuItem.Checked)
- {
- Code[0] = (byte)'R';
- Code[1] = (byte)'E';
- Code[2] = (byte)'S';
- Code[3] = (byte)'E';
- Code[4] = (byte)'T';
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
- Delay_ms(500);
- }
- //系统开机,确保测试前先关机,发送关机指令再发送开机指令
- //确保测试前先关机,发送关机指令再发送开机指令
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
- Code[0] = 0xF0;
- mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
- Delay_ms(1500);
- BootInfo = "";
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
- Code[0] = 0xF1;
- mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
- ACK_WaitCnt = 0;
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
- while (ACK_WaitCnt <= 20);
- //检查BOOT版本
- if (BootInfo != string.Empty)
- {
- label_CheckModeBoot.BackColor = Color.Green;
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
- Delay_ms(500);
- }
- else
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
- label_CheckModeStatus.Text = "存在故障!";
- label_CheckModeResult.BackColor = Color.Red;
- label_CheckModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- CheckMode_Stop(false);
- return;
- }
- #if false
- if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
- {
- Code[0] = 0x00;//5S协议
- Code[1] = 0x00;
- mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
- Delay_ms(500);
- mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
- Delay_ms(500);
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
- }
- #endif
- //发送指令读取版本信息
- do
- {
- label_CheckModeStatus.Text = "读取版本信息";
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
- //发送指令读取版本
- Class_Motor_Ver.Mode = "---";
- Class_Motor_Ver.SN = "---";
- Class_Motor_Ver.HW = "---";
- Class_Motor_Ver.FW = "---";
- Class_Motor_Ver.Special = "---";
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (Class_Motor_Ver.Mode == "---")
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第1次重发" + "\r\n");
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (Class_Motor_Ver.Mode == "---")
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第2次重发" + "\r\n");
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (Class_Motor_Ver.Mode == "---")
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取失败" + "\r\n");
- label_CheckModeStatus.Text = "存在故障!";
- label_CheckModeResult.BackColor = Color.Red;
- label_CheckModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- CheckMode_Stop(false);
- return;
- }
- }
- }
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
- richTextBox_CheckModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
- richTextBox_CheckModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
- richTextBox_CheckModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
- richTextBox_CheckModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
- richTextBox_CheckModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
- Delay_ms(500);
- } while (false);
- //软件版本检查
- if (checkBox_CheckModeFWVer.Checked)
- {
- //判断版本是否正确
- string VerCheck = comboBox_CheckModeCfgFile.Text.Split('_')[3] + "_" + comboBox_CheckModeCfgFile.Text.Split('_')[4];
- string VerRead = "";
- try
- {
- VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
- }
- catch (System.Exception)
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
- label_CheckModeStatus.Text = "存在故障!";
- label_CheckModeResult.BackColor = Color.Red;
- label_CheckModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- CheckMode_Stop(false);
- return;
- }
- if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
- label_CheckModeStatus.Text = "存在故障!";
- label_CheckModeResult.BackColor = Color.Red;
- label_CheckModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- CheckMode_Stop(false);
- return;
- }
- label_CheckModeFWVer.BackColor = Color.Green;
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
- Delay_ms(500);
- }
- else
- {
- label_CheckModeFWVer.BackColor = Color.Yellow;
- label_CheckModeStatus.Text = "跳过软件版本查询";
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过软件版本查询" + "\r\n");
- Delay_ms(500);
- }
- //打标信息核对
- if (checkBox_CheckModeSN.Checked)
- {
- label_CheckModeStatus.Text = "核对打标信息";
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "核对打标信息" + "\r\n");
- //根据扫码信息获取型号和SN
- string ScanInfo = textBox_CheckModeScan.Text;
- string regexInfo = "";
- string[] InfoList = { "" };
- try
- {
- if (中置电机MIGIC_ToolStripMenuItem.Checked == true)
- {
- regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
- InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
- }
- else if (中置电机VP_ToolStripMenuItem.Checked == true)
- {
- Regex regex = new Regex(@"^M[12][0-9](0?[1-9]|1[0-2])((0?[1-9])|((1|2)[0-9])|30|31)[A-Z]\d{4}[A-Z][A-Z]?$");
- if (ScanInfo.Contains(" "))
- {
- InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
- string Mode = InfoList[0];
- string Sn = InfoList[1];
- if (regex.IsMatch(Sn) == false)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN格式错误" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "标签格式错误";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "标签格式错误";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- }
- else if (轮毂电机ToolStripMenuItem.Checked == true)
- {
- if (!ScanInfo.Contains("/")) //老编码规则
- {
- InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
- string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
- string Spec = InfoList[1];
- string Sn = InfoList[2];
- InfoList[0] = Model.Substring(2, 12) + Spec.Substring(Spec.Length - 4);
- InfoList[1] = Sn;
- }
- else //新编码规则
- {
- Dictionary<string, string> Dic_Ver = new Dictionary<string, string>
- {
- { "01", "A" },
- { "02", "B" },
- { "03", "C" },
- { "04", "D" },
- { "05", "E" },
- { "06", "F" },
- { "07", "G" },
- { "08", "H" },
- { "09", "I" }
- };
- Dictionary<string, string> Dic_Vol = new Dictionary<string, string>
- {
- { "24V", "A" },
- { "36V", "B" },
- { "42V", "C" },
- { "48V", "D" },
- { "52V", "E" },
- { "60V", "F" }
- };
- InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
- string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
- string Spec = InfoList[1].Replace("-", "").Replace("/", "");
- string Sn = InfoList[2];
- InfoList[0] = Model[2] + Dic_Ver[Model.Substring(3, 2)] + Model[5] + Dic_Ver[Model.Substring(6, 2)] + Model[9];
- InfoList[0] += Dic_Vol[Spec.Substring(0, 3)] + Spec.Substring(3, 3) + Spec.Substring(13, 4) + Spec.Substring(Spec.Length - 4, 3);
- InfoList[1] = Sn;
- }
- }
- }
- catch
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "标签格式错误";
- Delay_ms(500);
- //存储异常并上传
- CheckMode_Stop(false);
- return;
- }
- //核对型号
- if (string.Equals(InfoList[0], Class_Motor_Ver.Mode) == false) //型号错误,直接结束
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号不一致" + "\r\n");
- label_CheckModeStatus.Text = "存在故障!";
- label_CheckModeResult.BackColor = Color.Red;
- label_CheckModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- CheckMode_Stop(false);
- return;
- }
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号一致" + "\r\n");
- Delay_ms(500);
- //核对SN
- if (string.Equals(InfoList[1], Class_Motor_Ver.SN) == false) //型号错误,直接结束
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN不一致" + "\r\n");
- label_CheckModeStatus.Text = "存在故障!";
- label_CheckModeResult.BackColor = Color.Red;
- label_CheckModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- CheckMode_Stop(false);
- return;
- }
- label_CheckModeSN.BackColor = Color.Green;
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN一致" + "\r\n");
- Delay_ms(500);
- }
- else
- {
- label_CheckModeSN.BackColor = Color.Yellow;
- label_CheckModeStatus.Text = "跳过打标信息确认";
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过打标信息确认" + "\r\n");
- Delay_ms(500);
- }
- //参数检验
- if (checkBox_CheckModeCfg.Checked)
- {
- //读取配置文件信息
- label_CheckModeStatus.Text = "参数检查";
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
- //配置文件
- List<byte[]> CmdList = new List<byte[]>();
- Dictionary<string, string> ConfigCmd = new Dictionary<string, string>();//配置文件格式
- //从服务器下载文件
- if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
- {
- string SelectFile = "";
- SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "/" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
- if (File.Exists(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
- {
- File.Delete(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
- }
- myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
- //打开文件
- StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
- ConfigCmd.Clear();
- while (streamReader.Peek() != -1)
- {
- string fileLineInfo = streamReader.ReadLine(); //读指令名称
- if (fileLineInfo.Contains("["))
- {
- if (fileLineInfo.Contains("助力参数"))
- {
- fileLineInfo = streamReader.ReadLine();
- }
- ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
- }
- }
- streamReader.Close();
- }
- //从本地加载文件
- else
- {
- string SelectFile = "";
- SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
- //打开文件
- StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
- ConfigCmd.Clear();
- while (streamReader.Peek() != -1)
- {
- string fileLineInfo = streamReader.ReadLine(); //读指令名称
- if (fileLineInfo.Contains("["))
- {
- if (fileLineInfo.Contains("助力参数"))
- {
- fileLineInfo = streamReader.ReadLine();
- }
- ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
- }
- }
- streamReader.Close();
- }
-
- int CmdNum = ConfigCmd.Count(); //指令个数
- Delay_ms(500);
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "\r\n");
- Delay_ms(500);
- //逐条读取比较
- try
- {
- foreach (string key in ConfigCmd.Keys)
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令:" + "\r\n");
- CmdRevStrTemp = "";
- if (key.Contains("曲线"))
- {
- byte LineNum = 0;
- var code = new byte[4];
- LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
- if (LineNum <= 5)
- {
- code[0] = (byte)(LineNum & 0xFF);
- code[1] = (byte)((LineNum >> 8) & 0xFF);
- code[2] = (byte)(LineNum & 0xFF);
- code[3] = (byte)((LineNum >> 8) & 0xFF);
- }
- else
- {
- code[0] = (byte)(LineNum & 0xFF);
- code[1] = (byte)((LineNum >> 8) & 0xFF);
- code[2] = (byte)(5 & 0xFF);
- code[3] = (byte)((5 >> 8) & 0xFF);
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
- }
- else
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
- Delay_ms(500);
- if (CmdRevStrTemp == string.Empty)
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令,第1次重发" + "\r\n");
- if (key.Contains("曲线"))
- {
- byte LineNum = 0;
- var code = new byte[4];
- LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
- if (LineNum <= 5)
- {
- code[0] = (byte)(LineNum & 0xFF);
- code[1] = (byte)((LineNum >> 8) & 0xFF);
- code[2] = (byte)(LineNum & 0xFF);
- code[3] = (byte)((LineNum >> 8) & 0xFF);
- }
- else
- {
- code[0] = (byte)(LineNum & 0xFF);
- code[1] = (byte)((LineNum >> 8) & 0xFF);
- code[2] = (byte)(5 & 0xFF);
- code[3] = (byte)((5 >> 8) & 0xFF);
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
- }
- else
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
- Delay_ms(500);
- if (CmdRevStrTemp == string.Empty)
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令,第2次重发" + "\r\n");
- if (key.Contains("曲线"))
- {
- byte LineNum = 0;
- var code = new byte[4];
- LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
- if (LineNum <= 5)
- {
- code[0] = (byte)(LineNum & 0xFF);
- code[1] = (byte)((LineNum >> 8) & 0xFF);
- code[2] = (byte)(LineNum & 0xFF);
- code[3] = (byte)((LineNum >> 8) & 0xFF);
- }
- else
- {
- code[0] = (byte)(LineNum & 0xFF);
- code[1] = (byte)((LineNum >> 8) & 0xFF);
- code[2] = (byte)(5 & 0xFF);
- code[3] = (byte)((5 >> 8) & 0xFF);
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
- }
- else
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
- Delay_ms(500);
- if (CmdRevStrTemp == string.Empty)
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "指令读取失败" + "\r\n");
- label_CheckModeStatus.Text = "存在故障!";
- label_CheckModeResult.BackColor = Color.Red;
- label_CheckModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- CheckMode_Stop(false);
- return;
- }
- }
- }
- //比较当前指令,读取的配置文件和返回数据比较
- string ParamWrite = ConfigCmd[key].Substring(24, ConfigCmd[key].Length - 40).Trim();
- string ParamRead = "";
- ushort CmdGet = Convert.ToUInt16(CmdRevStrTemp.Substring(0, 6).Trim().Replace(" ", ""), 16);//接收到指令的命令字
- ushort CmdRev = myParams.ConfigCheckRevCmd[key];//接收指令设计值
- if (CmdGet != CmdRev)
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "接收指令不正确" + "\r\n");
- richTextBox_CheckModeLog.AppendText("接收指令:" + "0x" + CmdGet.ToString("X2") + "\r\n");
- richTextBox_CheckModeLog.AppendText("正确指令应为:" + "0x" + CmdRev.ToString("X2") + "\r\n");
- label_CheckModeStatus.Text = "存在故障!";
- label_CheckModeResult.BackColor = Color.Red;
- label_CheckModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- CheckMode_Stop(false);
- return;
- }
- if (string.Compare(key, "[其它传感器参数]") == 0)
- ParamRead = CmdRevStrTemp.Substring(90, CmdRevStrTemp.Length - 90).Trim(); //去掉命令字、力矩传感器标定参数
- else if (string.Compare(key, "[力矩传感器参数]") == 0)
- ParamRead = CmdRevStrTemp.Substring(6, CmdRevStrTemp.Length - 6 - 36).Trim(); //去掉命令字、其它传感器参数
- else if (string.Compare(key, "[控制参数]") == 0)
- ParamRead = CmdRevStrTemp.Substring(18, CmdRevStrTemp.Length - 18).Trim(); //去掉命令字、位置零点
- else
- ParamRead = CmdRevStrTemp.Substring(6, CmdRevStrTemp.Length - 6).Trim(); //去掉命令字
- if (ParamWrite.Contains(ParamRead))
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "一致" + "\r\n");
- continue;
- }
- else
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "不一致" + "\r\n");
- richTextBox_CheckModeLog.AppendText("写入参数:" + ParamWrite + "\r\n");
- richTextBox_CheckModeLog.AppendText("读出参数:" + ParamRead + "\r\n");
- label_CheckModeStatus.Text = "存在故障!";
- label_CheckModeResult.BackColor = Color.Red;
- label_CheckModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- CheckMode_Stop(false);
- return;
- }
- }
- }
- catch (System.Exception)
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数检验失败" + "\r\n");
- label_CheckModeStatus.Text = "存在故障!";
- label_CheckModeResult.BackColor = Color.Red;
- label_CheckModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- CheckMode_Stop(false);
- return;
- }
- label_CheckModeCfg.BackColor = Color.Green;
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数检验正确" + "\r\n");
- Delay_ms(500);
- }
- else
- {
- label_CheckModeCfg.BackColor = Color.Yellow;
- label_CheckModeStatus.Text = "跳过参数检验";
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数检验" + "\r\n");
- Delay_ms(500);
- }
-
- //读取力矩传感器
- do
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据" + "\r\n");
- //发送指令读取力矩传感器标定数据
- CmdRevStrTemp = "";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (CmdRevStrTemp == string.Empty)
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据,第1次重发" + "\r\n");
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (CmdRevStrTemp == string.Empty)
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据,第2次重发" + "\r\n");
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (CmdRevStrTemp == string.Empty)
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取失败" + "\r\n");
- label_CheckModeStatus.Text = "存在故障!";
- label_CheckModeResult.BackColor = Color.Red;
- label_CheckModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- CheckMode_Stop(false);
- return;
- }
- }
- }
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取成功" + "\r\n");
- //取力矩传感器数据
- ushort ZeroInit, Zero1, Zero2, Zero3, ZeroNew;
- ushort MaxTorque;
- ushort K1_T, K1, K2_T, K2, K3_T, K3, K4_T, K4;
- byte[] DataArray = mySerialProcess.HexStringToBytes(CmdRevStrTemp, true);
- ushort Cmd = (ushort)((DataArray[0] << 8) + DataArray[1]);
- if (Cmd != 0xB528)
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器参数错误,CMD: 0x" + Convert.ToString(Cmd, 16).PadLeft(2, '0').ToUpper() + "\r\n");
- label_CheckModeStatus.Text = "存在故障!";
- label_CheckModeResult.BackColor = Color.Red;
- label_CheckModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- CheckMode_Stop(false);
- return;
- }
- ZeroInit = (ushort)((DataArray[3] << 8) + DataArray[2]);
- Zero1 = (ushort)((DataArray[5] << 8) + DataArray[4]);
- Zero2 = (ushort)((DataArray[7] << 8) + DataArray[6]);
- Zero3 = (ushort)((DataArray[9] << 8) + DataArray[8]);
- ZeroNew = (ushort)((DataArray[11] << 8) + DataArray[10]);
- MaxTorque = (ushort)((DataArray[13] << 8) + DataArray[12]);
- K1_T = (ushort)((DataArray[15] << 8) + DataArray[14]);
- K1 = (ushort)((DataArray[17] << 8) + DataArray[16]);
- K2_T = (ushort)((DataArray[19] << 8) + DataArray[18]);
- K2 = (ushort)((DataArray[21] << 8) + DataArray[20]);
- K3_T = (ushort)((DataArray[23] << 8) + DataArray[22]);
- K3 = (ushort)((DataArray[25] << 8) + DataArray[24]);
- K4_T = (ushort)((DataArray[27] << 8) + DataArray[26]);
- K4 = (ushort)((DataArray[29] << 8) + DataArray[28]);
- richTextBox_CheckModeLog.AppendText("力矩传感器零点: " + ZeroInit.ToString() + "," + Zero1.ToString() + "," +
- Zero2.ToString() + "," + Zero3.ToString() + "," + ZeroNew.ToString() + "\r\n");
- richTextBox_CheckModeLog.AppendText("最大力矩: " + MaxTorque.ToString() + "\r\n");
- richTextBox_CheckModeLog.AppendText("力矩传感器标定: " + "[" + K1_T.ToString() + "," + K1.ToString() + "]" + "," +
- "[" + K2_T.ToString() + "," + K2.ToString() + "]" + "," + "[" + K3_T.ToString() + "," + K3.ToString() + "]" + "," +
- "[" + K4_T.ToString() + "," + K4.ToString() + "]" + "\r\n");
- //传感器标定检验
- if (checkBox_CheckModeTorque.Checked)
- {
- richTextBox_CheckModeLog.AppendText("力矩零点范围: " + TorqueParamsForm.Zero.Min.ToString() + " - " + TorqueParamsForm.Zero.Max.ToString() + "\r\n");
- richTextBox_CheckModeLog.AppendText("K1范围: " + TorqueParamsForm.K1.T.ToString() + "," + TorqueParamsForm.K1.Min.ToString() + " - " + TorqueParamsForm.K1.Max.ToString() + "\r\n");
- richTextBox_CheckModeLog.AppendText("K2范围: " + TorqueParamsForm.K2.T.ToString() + "," + TorqueParamsForm.K2.Min.ToString() + " - " + TorqueParamsForm.K2.Max.ToString() + "\r\n");
- richTextBox_CheckModeLog.AppendText("K3范围: " + TorqueParamsForm.K3.T.ToString() + "," + TorqueParamsForm.K3.Min.ToString() + " - " + TorqueParamsForm.K3.Max.ToString() + "\r\n");
- richTextBox_CheckModeLog.AppendText("K4范围: " + TorqueParamsForm.K4.T.ToString() + "," + TorqueParamsForm.K4.Min.ToString() + " - " + TorqueParamsForm.K4.Max.ToString() + "\r\n");
- //与设置值比较
- if ((ZeroInit <= TorqueParamsForm.Zero.Max) && (ZeroInit >= TorqueParamsForm.Zero.Min)
- && (K1_T == TorqueParamsForm.K1.T) && (K1 <= TorqueParamsForm.K1.Max) && (K1 >= TorqueParamsForm.K1.Min)
- && (K2_T == TorqueParamsForm.K2.T) && (K2 <= TorqueParamsForm.K2.Max) && (K2 >= TorqueParamsForm.K2.Min)
- && (K3_T == TorqueParamsForm.K3.T) && (K3 <= TorqueParamsForm.K3.Max) && (K3 >= TorqueParamsForm.K3.Min)
- && (K4_T == TorqueParamsForm.K4.T) && (K4 <= TorqueParamsForm.K4.Max) && (K4 >= TorqueParamsForm.K4.Min)
- )
- {
- label_CheckModeTorque.BackColor = Color.Green;
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定正常" + "\r\n");
- Delay_ms(500);
- }
- else
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定超范围" + "\r\n");
- label_CheckModeStatus.Text = "存在故障!";
- label_CheckModeResult.BackColor = Color.Red;
- label_CheckModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- CheckMode_Stop(false);
- return;
- }
- }
- else
- {
- label_CheckModeTorque.BackColor = Color.Yellow;
- label_CheckModeStatus.Text = "跳过传感器标定检验";
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过传感器标定检验" + "\r\n");
- Delay_ms(500);
- }
- } while (false);
- //读取MOS内阻校准参数
- do
- {
- if (checkBox_CheckModeMos.Checked)
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据" + "\r\n");
- //读取显示校准返回数据
- foreach (Control c in groupBox21.Controls)
- {
- if (c is TextBox)
- c.Text = "";
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据,第1次重发" + "\r\n");
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据,第2次重发" + "\r\n");
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果异常" + "\r\n");
- label_CheckModeStatus.Text = "存在故障!";
- label_CheckModeResult.BackColor = Color.Red;
- label_CheckModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- CheckMode_Stop(false);
- return;
- }
- }
- }
- else
- {
- 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");
- }
- //与校准返回数据对比
- string[] MOS_R1_Th = toolStripTextBox_MOS1.Text.Split(',');
- string[] MOS_R2_Th = toolStripTextBox_MOS2.Text.Split(',');
- string[] MOS_R3_Th = toolStripTextBox_MOS3.Text.Split(',');
- 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])) &&
- (Convert.ToUInt16(textBox_MOS_R2.Text) >= Convert.ToUInt16(MOS_R2_Th[0])) && (Convert.ToUInt16(textBox_MOS_R2.Text) <= Convert.ToUInt16(MOS_R2_Th[1])) &&
- (Convert.ToUInt16(textBox_MOS_R3.Text) >= Convert.ToUInt16(MOS_R3_Th[0])) && (Convert.ToUInt16(textBox_MOS_R3.Text) <= Convert.ToUInt16(MOS_R3_Th[1]))
- )
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准合格" + "\r\n");
- label_CheckModeMos.BackColor = Color.Green;
- }
- else
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准超范围" + "\r\n");
- label_CheckModeStatus.Text = "存在故障!";
- label_CheckModeResult.BackColor = Color.Red;
- label_CheckModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- CheckMode_Stop(false);
- return;
- }
- }
- else
- {
- label_CheckModeMos.BackColor = Color.Yellow;
- label_CheckModeStatus.Text = "跳过MOS内阻校准检验";
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过MOS内阻校准检验" + "\r\n");
- Delay_ms(500);
- }
- } while (false);
- //读取位置校准参数
- do
- {
- if (checkBox_CheckModeAngle.Checked)
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取位置校准数据" + "\r\n");
- //发送指令读取位置
- CmdRevStrTemp = "";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (CmdRevStrTemp == string.Empty)
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取位置校准数据,第1次重发" + "\r\n");
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x3E00, null);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (CmdRevStrTemp == string.Empty)
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取位置校准数据,第2次重发" + "\r\n");
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x3E00, null);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (CmdRevStrTemp == string.Empty)
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准数据读取失败" + "\r\n");
- label_CheckModeStatus.Text = "存在故障!";
- label_CheckModeResult.BackColor = Color.Red;
- label_CheckModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- CheckMode_Stop(false);
- return;
- }
- }
- }
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准数据读取成功" + "\r\n");
- //取零点数据
- UInt16 AngleZero_Init = 0, AngleZero_Cur = 0;
- byte[] DataArray = mySerialProcess.HexStringToBytes(CmdRevStrTemp, true);
- ushort Cmd = (ushort)((DataArray[0] << 8) + DataArray[1]);
- if (Cmd != 0xB420)
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置传感器参数错误,CMD: 0x" + Convert.ToString(Cmd, 16).PadLeft(2, '0').ToUpper() + "\r\n");
- label_CheckModeStatus.Text = "存在故障!";
- label_CheckModeResult.BackColor = Color.Red;
- label_CheckModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- CheckMode_Stop(false);
- return;
- }
- AngleZero_Init = (ushort)((DataArray[3] << 8) + DataArray[2]);
- AngleZero_Cur = (ushort)((DataArray[5] << 8) + DataArray[4]);
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置出厂零点: " + AngleZero_Init.ToString() + ",位置当前零点: " + AngleZero_Cur.ToString() + "\r\n");
- int AngleZeroDiff = Math.Abs(AngleZero_Cur - AngleZero_Init);
- int AngleZeroTH = Convert.ToInt32(textBox_AngleZeroTh.Text);
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置零点校准值: " + AngleZeroDiff.ToString() + ",判断阈值: " + AngleZeroTH.ToString() + "\r\n");
- //判断
- if (AngleZeroDiff <= AngleZeroTH)
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置传感器校准合格" + "\r\n");
- label_CheckModeAngle.BackColor = Color.Green;
- }
- else
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置传感器校准超范围" + "\r\n");
- label_CheckModeStatus.Text = "存在故障!";
- label_CheckModeResult.BackColor = Color.Red;
- label_CheckModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- CheckMode_Stop(false);
- return;
- }
- }
- else
- {
- label_CheckModeAngle.BackColor = Color.Yellow;
- label_CheckModeStatus.Text = "跳过位置传感器校准检验";
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过位置传感器校准检验" + "\r\n");
- Delay_ms(500);
- }
- } while (false);
- //测试合格
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
- label_CheckModeStatus.Text = "测试结束!";
- label_CheckModeResult.BackColor = Color.Green;
- label_CheckModeResult.Text = "测试合格";
- Delay_ms(500);
- //存储并上传
- CheckMode_Stop(true);
- return;
- }
- private void CheckModeLabelInit()
- {
- //测试状态标签
- label_CheckModeResult.BackColor = Color.Yellow;
- label_CheckModeResult.Text = "测试中";
- //测试过程标签
- label_CheckModeStatus.Text = "测试就绪";
- //测试结果标签
- foreach (Control c in groupBox31.Controls)
- {
- if (c is Label)
- {
- if (c.Text == string.Empty)
- c.BackColor = Color.Red;
- }
- }
- }
- private void 调试记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- System.Diagnostics.Process.Start("explorer.exe", Directory.GetCurrentDirectory());
- }
- private void 生产记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- System.Diagnostics.Process.Start("explorer.exe", localInfo.LocalDataPath);
- }
- private void 累计运行时间ToolStripMenuItem_MouseHover(object sender, EventArgs e)
- {
- UInt32 Time = (UInt32)stopwatch.ElapsedMilliseconds / 1000;
- UInt32 hour = Time / 3600;
- UInt32 min = (Time % 3600) / 60;
- UInt32 s = (Time % 60);
- toolStripMenuItem_RunTime.Text = hour.ToString() + ":" + min.ToString("00") + ":" + s.ToString("00");
- }
- private void richTextBox_CheckModeLog_TextChanged(object sender, EventArgs e)
- {
- richTextBox_CheckModeLog.SelectionStart = richTextBox_CheckModeLog.Text.Length;
- richTextBox_CheckModeLog.ScrollToCaret();
- }
- private void 力矩传感器检验ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- TorqueParamsForm.ShowDialog();
- }
- private void textBox_CheckModeScan_KeyUp(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- CheckTestStart();
- }
- private void textBox_FacModeScan_KeyUp(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- TestStart();
- }
- private void button_SpeedDec10_Click(object sender, EventArgs e)
- {
- short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
- if (Percent <= 10)
- Percent = 0;
- else
- Percent -= 10;
- //生产模式转速设置值更新
- textBox_MotorSpeedPercent.Text = Percent.ToString();
- //设置转速百分比
- var Data = new byte[1];
- Data[0] = (byte)Percent;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
- }
- private void button_SpeedAdd10_Click(object sender, EventArgs e)
- {
- short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
- if (Percent >= 90)
- Percent = 100;
- else
- Percent += 10;
- //生产模式转速设置值更新
- textBox_MotorSpeedPercent.Text = Percent.ToString();
- //设置转速百分比
- var Data = new byte[1];
- Data[0] = (byte)Percent;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
- }
- private void button_SpeedDec1_Click(object sender, EventArgs e)
- {
- short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
- if (Percent <= 1)
- Percent = 0;
- else
- Percent -= 1;
- //生产模式转速设置值更新
- textBox_MotorSpeedPercent.Text = Percent.ToString();
- //设置转速百分比
- var Data = new byte[1];
- Data[0] = (byte)Percent;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
- }
- private void button_SpeedAdd1_Click(object sender, EventArgs e)
- {
- short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
- if (Percent >= 99)
- Percent = 100;
- else
- Percent += 1;
- //生产模式转速设置值更新
- textBox_MotorSpeedPercent.Text = Percent.ToString();
- //设置转速百分比
- var Data = new byte[1];
- Data[0] = (byte)Percent;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
- }
- bool WriteLockStatus = true;
- private void pictureBox_WriteLock_Click(object sender, EventArgs e)
- {
- if (WriteLockStatus == true)
- {
- EnterForm1.ShowDialog();
- try
- {
- if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
- {
- if (EnterForm1.comboBox_User.Text == "工程参数配置")
- {
- pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
- foreach (Control c in groupBox2.Controls)
- {
- if (c is CheckBox)
- c.Enabled = true;
- }
- WriteLockStatus = !WriteLockStatus;
- }
- else
- {
- MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else
- {
- MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- catch (Exception)
- {
- MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else
- {
- pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
- foreach (Control c in groupBox2.Controls)
- {
- if (c is CheckBox)
- c.Enabled = false;
- }
- WriteLockStatus = !WriteLockStatus;
- }
-
- }
- bool ReadLockStatus = true;
- private void pictureBox_ReadLock_Click(object sender, EventArgs e)
- {
- if (ReadLockStatus == true)
- {
- EnterForm1.ShowDialog();
- try
- {
- if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
- {
- if (EnterForm1.comboBox_User.Text == "工程参数配置")
- {
- pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
- foreach (Control c in groupBox29.Controls)
- {
- if (c is CheckBox)
- c.Enabled = true;
- }
- ReadLockStatus = !ReadLockStatus;
- }
- else
- {
- MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else
- {
- MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- catch (Exception)
- {
- MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else
- {
- pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
- foreach (Control c in groupBox29.Controls)
- {
- if (c is CheckBox)
- c.Enabled = false;
- }
- ReadLockStatus = !ReadLockStatus;
- }
- }
- private void 屏幕键盘ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- System.Diagnostics.Process.Start("osk.exe");
- }
- private void checkBox_OffLineCheckMode_CheckedChanged(object sender, EventArgs e)
- {
- comboBox_CheckModeCfgDate.SelectedIndex = -1;
- comboBox_CheckModeCfgFile.SelectedIndex = -1;
- checkBox_OffLineFacMode.Checked = checkBox_OffLineCheckMode.Checked;
- }
- private void checkBox_OffLineFacMode_CheckedChanged(object sender, EventArgs e)
- {
- comboBox_FacModeCfgDate.SelectedIndex = -1;
- comboBox_FacModeCfgFile.SelectedIndex = -1;
- checkBox_OffLineCheckMode.Checked = checkBox_OffLineFacMode.Checked;
- }
- private void 版本ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- VersionForm.ShowDialog();
- }
- private void button_MOS_Cal_Click(object sender, EventArgs e)
- {
- textBox_MOS_R1.Text = "";
- textBox_MOS_R2.Text = "";
- textBox_MOS_R3.Text = "";
- try
- {
- var Code = new byte[18];
- for (int i = 0; i < 18; i++)
- Code[i] = 0;
- Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
- ushort uwDataTemp = 0;
- uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
- Code[2] = (byte)(uwDataTemp & 0xFF);
- Code[3] = (byte)(uwDataTemp >> 8);
- uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
- Code[4] = (byte)(uwDataTemp & 0xFF);
- Code[5] = (byte)(uwDataTemp >> 8);
- uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
- Code[6] = (byte)(uwDataTemp & 0xFF);
- Code[7] = (byte)(uwDataTemp >> 8);
- uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
- Code[8] = (byte)(uwDataTemp & 0xFF);
- Code[9] = (byte)(uwDataTemp >> 8);
- uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
- Code[10] = (byte)(uwDataTemp & 0xFF);
- Code[11] = (byte)(uwDataTemp >> 8);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
- }
- catch (Exception)
- {
- MessageBox.Show("系数填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- private void button_MOS_Read_Click(object sender, EventArgs e)
- {
- foreach (Control c in groupBox21.Controls)
- {
- if (c is TextBox)
- c.Text = "";
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
- }
- private void button_MOS_Write_Click(object sender, EventArgs e)
- {
- try
- {
- var Code = new byte[34];
- for (int i = 0; i < 34; i++)
- Code[i] = 0;
- Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
- ushort uwDataTemp = 0;
- uwDataTemp = Convert.ToUInt16(textBox_MOS_R1.Text);
- Code[2] = (byte)(uwDataTemp & 0xFF);
- Code[3] = (byte)(uwDataTemp >> 8);
- uwDataTemp = Convert.ToUInt16(textBox_MOS_R2.Text);
- Code[4] = (byte)(uwDataTemp & 0xFF);
- Code[5] = (byte)(uwDataTemp >> 8);
- uwDataTemp = Convert.ToUInt16(textBox_MOS_R3.Text);
- Code[6] = (byte)(uwDataTemp & 0xFF);
- Code[7] = (byte)(uwDataTemp >> 8);
- uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
- Code[8] = (byte)(uwDataTemp & 0xFF);
- Code[9] = (byte)(uwDataTemp >> 8);
- uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
- Code[10] = (byte)(uwDataTemp & 0xFF);
- Code[11] = (byte)(uwDataTemp >> 8);
- uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
- Code[12] = (byte)(uwDataTemp & 0xFF);
- Code[13] = (byte)(uwDataTemp >> 8);
- uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
- Code[14] = (byte)(uwDataTemp & 0xFF);
- Code[15] = (byte)(uwDataTemp >> 8);
- uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
- Code[16] = (byte)(uwDataTemp & 0xFF);
- Code[17] = (byte)(uwDataTemp >> 8);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4C22, Code);
- }
- catch (Exception)
- {
- MessageBox.Show("数据填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- /// <summary>
- /// 测试模式点击文本框自动全选
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void textBox_FacModeScan_MouseClick(object sender, MouseEventArgs e)
- {
- textBox_FacModeScan.SelectAll();
- }
- /// <summary>
- /// 检验模式点击文本框自动全选
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void textBox_CheckModeScan_MouseClick(object sender, MouseEventArgs e)
- {
- textBox_CheckModeScan.SelectAll();
- }
- /// <summary>
- /// 鼠标放置显示连接服务器信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void label_ServerStatus_MouseHover(object sender, EventArgs e)
- {
- // 创建the ToolTip
- ToolTip toolTip1 = new ToolTip();
- // 设置显示样式
- toolTip1.AutoPopDelay = 30000;//提示信息的可见时间
- toolTip1.InitialDelay = 50;//事件触发多久后出现提示
- toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
- toolTip1.ShowAlways = true;//是否显示提示框
-
- if (myFtp.IsNetConnected)
- {
- toolTip1.SetToolTip(this.label_ServerStatus, "IP: " + ServerIP);//设置故障内容显示
- }
- else
- {
- toolTip1.SetToolTip(this.label_ServerStatus, "网络断开");//设置故障内容显示
- }
- }
- /// <summary>
- /// UART协议类型修改
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 协议类型ToolStripMenuItem_SelectedIndexChanged(object sender, EventArgs e)
- {
- var Code = new byte[2];
- Code[0] = (byte)协议类型ToolStripMenuItem.SelectedIndex;
- Code[1] = 0x00;
- mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
- }
- /// <summary>
- /// 显示本机信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 本机信息ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- MessageBox.Show(Local_HdInformation, "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- /// <summary>
- /// 量产模式删除当前选中文件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void label112_DoubleClick(object sender, EventArgs e)
- {
- if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- EnterForm1.ShowDialog();
- try
- {
- if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
- {
- if (EnterForm1.comboBox_User.Text.Contains("工程"))
- {
- try
- {
- myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + comboBox_FacModeCfgFile.Text);
- myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_FacModeCfgFile.Text) + ".src");
- myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_FacModeCfgFile.Text) + ".png");
- MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- catch (Exception)
- {
- MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else
- {
- MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
- catch (Exception)
- {
- MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
- /// <summary>
- /// 检验模式删除当前选中文件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void label138_DoubleClick(object sender, EventArgs e)
- {
- if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- EnterForm1.ShowDialog();
- try
- {
- if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
- {
- if (EnterForm1.comboBox_User.Text.Contains("工程"))
- {
- try
- {
- myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + comboBox_CheckModeCfgFile.Text);
- myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_CheckModeCfgFile.Text) + ".src");
- myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_CheckModeCfgFile.Text) + ".png");
- MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- catch (Exception)
- {
- MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else
- {
- MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
- catch (Exception)
- {
- MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
- /// <summary>
- /// 读取整车信息2
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadBikeParam2_Click(object sender, EventArgs e)
- {
- richTextBox_BikeParam2.Clear();
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null);
- }
- /// <summary>
- /// 写入整车信息2
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteBikeParam2_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[34];
- for (int i = 0; i < 34; i++)
- ConfigParam[i] = 0;
- ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
- string[] strDataTemp = richTextBox_BikeParam2.Text.Split(new string[] { ", " }, StringSplitOptions.None);
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- short wDataTemp = 0;
- wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
- wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
- ConfigParam[2 * i + 2] = (byte)wDataTemp;
- ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4D22, ConfigParam);
- }
- catch (Exception)
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_500ms.Enabled = true;
- }
- }
- /// <summary>
- /// 读取用户骑行参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadUsrRideParam_Click(object sender, EventArgs e)
- {
- richTextBox_UsrRidesParam.Clear();
- if (checkBox_UserRideParam_OBC.Checked)
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x4300, null);
- else
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
- }
- /// <summary>
- /// 写入用户骑行参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteUsrRidetParam_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[34];
- for (int i = 0; i < 34; i++)
- ConfigParam[i] = 0;
- if (checkBox_UserRideParam_OBC.Checked)
- {
- ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
- string[] strDataTemp = richTextBox_UsrRidesParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- ConfigParam[i + 2] = Convert.ToByte(strDataTemp[i].Split('=')[1]);
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4B22, ConfigParam);
- }
- catch (Exception)
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_500ms.Enabled = true;
- }
- }
- else
- {
- string[] strDataTemp = richTextBox_UsrRidesParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- ConfigParam[i] = Convert.ToByte(strDataTemp[i].Split('=')[1]);
- }
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x4420, ConfigParam);
- }
- catch (Exception)
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_500ms.Enabled = true;
- }
- }
-
- }
- /// <summary>
- /// 读取产品标签
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadTag_Click(object sender, EventArgs e)
- {
- textBox_TagInfo.Text = "---";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4E00, null);
- }
- /// <summary>
- /// 写入产品标签
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteTag_Click(object sender, EventArgs e)
- {
- string User = textBox_TagInfo.Text;
- var UserArray = new byte[32];
- for (ushort i = 0; i < User.Length; i++)
- {
- UserArray[i] = (byte)User[i];
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D20, UserArray);
- }
- /// <summary>
- /// 上位机读取骑行历史
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadRideLog_Click(object sender, EventArgs e)
- {
- textBox_ODO_KM.Text = "---";
- textBox_ODO_TIME.Text = "---";
- textBox_TRIP_KM.Text = "---";
- textBox_TRIP_TIME.Text = "---";
- textBox_OBC_TRIP_KM.Text = "";
- textBox_OBC_TRIP_TIME.Text = "";
- textBox_OBC_ODO_KM.Text = "";
- textBox_OBC_ODO_TIME.Text = "";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2E00, null);
- }
- /// <summary>
- /// 上位机写入骑行历史
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteRideLog_Click(object sender, EventArgs e)
- {
- UInt32 Data;
- var UserArray = new byte[16];
- try
- {
- Data = Convert.ToUInt32(textBox_ODO_KM.Text);
- UserArray[0] = (byte)(Data & 0xFF);
- UserArray[1] = (byte)(Data >> 8);
- UserArray[2] = (byte)(Data >> 16);
- UserArray[3] = (byte)(Data >> 24);
- Data = Convert.ToUInt32(textBox_ODO_TIME.Text);
- UserArray[4] = (byte)(Data & 0xFF);
- UserArray[5] = (byte)(Data >> 8);
- UserArray[6] = (byte)(Data >> 16);
- UserArray[7] = (byte)(Data >> 24);
- Data = Convert.ToUInt32(textBox_TRIP_KM.Text);
- UserArray[8] = (byte)(Data & 0xFF);
- UserArray[9] = (byte)(Data >> 8);
- UserArray[10] = (byte)(Data >> 16);
- UserArray[11] = (byte)(Data >> 24);
- Data = Convert.ToUInt32(textBox_TRIP_TIME.Text);
- UserArray[12] = (byte)(Data & 0xFF);
- UserArray[13] = (byte)(Data >> 8);
- UserArray[14] = (byte)(Data >> 16);
- UserArray[15] = (byte)(Data >> 24);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B10, UserArray);
- }
- catch (Exception ex)
- {
- MessageBox.Show("数据格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- /// <summary>
- /// 获取删除配置文件日期列表
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void toolStripTextBox_DelCfgFile_Click(object sender, EventArgs e)
- {
- string[] DateList = { "" };
- //网络断开时直接退出
- if (!myFtp.IsNetConnected)
- return;
- //从服务器更新日期列表
- DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
- toolStripTextBox_DelCfgFile.Items.Clear();
- //日期列表加载,显示最近30条
- if (DateList.Length > 30)
- {
- toolStripTextBox_DelCfgFile.Items.Add("支持最近30条");
- toolStripTextBox_DelCfgFile.Items.Add("-----");
- }
- for (int i = (DateList.Length > 30) ? (DateList.Length - 30) : 0; i < DateList.Length; i++)//显示最近30个日期
- {
- toolStripTextBox_DelCfgFile.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
- }
- }
- /// <summary>
- /// 删除指定配置文件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void toolStripTextBox_DelCfgFile_SelectedIndexChanged(object sender, EventArgs e)
- {
- //提示输入文件名
- Scan scan_form = new Scan();
- scan_form.ShowDialog();
- do
- {
- if (scan_form.textBox_Scan.Text == string.Empty)
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_500ms.Enabled = true;
- break;
- }
- string DelFile = scan_form.textBox_Scan.Text;
- if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- EnterForm1.ShowDialog();
- try
- {
- if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
- {
- if (EnterForm1.comboBox_User.Text.Contains("工程"))
- {
- try
- {
- if (DelFile.Contains("."))
- DelFile = Path.GetFileNameWithoutExtension(DelFile);
- myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".ttcfg");
- myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".src");
- myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".png");
- MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- catch (Exception)
- {
- MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else
- {
- MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
- catch (Exception)
- {
- MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- } while (false);
- }
- /// <summary>
- /// 获取删除样机测试记录日期列表
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void toolStripTextBox_DelLogFile_Click(object sender, EventArgs e)
- {
- string[] DateList = { "" };
- //网络断开时直接退出
- if (!myFtp.IsNetConnected)
- return;
- //从服务器更新日期列表
- DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName);
- toolStripTextBox_DelLogFile.Items.Clear();
- //日期列表加载,显示最近30天
- if (DateList.Length > 30)
- {
- toolStripTextBox_DelLogFile.Items.Add("支持最近30条");
- toolStripTextBox_DelLogFile.Items.Add("-----");
- }
- for (int i = (DateList.Length > 30) ? (DateList.Length - 30) : 0; i < DateList.Length; i++)//显示最近30个日期
- {
- toolStripTextBox_DelLogFile.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
- }
- }
- /// <summary>
- /// 删除指定的样机测试记录
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void toolStripTextBox_DelLogFile_SelectedIndexChanged(object sender, EventArgs e)
- {
- //提示输入文件名
- Scan scan_form = new Scan();
- scan_form.ShowDialog();
- do
- {
- if (scan_form.textBox_Scan.Text == string.Empty)
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_500ms.Enabled = true;
- break;
- }
- string DelFile = scan_form.textBox_Scan.Text;
- if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- EnterForm1.ShowDialog();
- try
- {
- if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
- {
- if (EnterForm1.comboBox_User.Text.Contains("工程"))
- {
- try
- {
- //删除指定目录下面所有文件和文件夹
- myFtp.DelDirectoryWithAll(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName + "\\" + toolStripTextBox_DelLogFile.Text + "\\" + DelFile);
- myFtp.RemoveDirectory(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName + "\\" + toolStripTextBox_DelLogFile.Text + "\\" + DelFile);
- MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- catch (Exception)
- {
- MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else
- {
- MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
- catch (Exception)
- {
- MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- } while (false);
- }
- /// <summary>
- /// CAN协议选择
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void cANToolStripMenuItem_Click(object sender, EventArgs e)
- {
- cANToolStripMenuItem.Checked= true;
- uARTToolStripMenuItem.Checked = false;
- UART协议ToolStripMenuItem.Visible = false;
- ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- /// <summary>
- /// UART协议选择
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void uARTToolStripMenuItem_Click(object sender, EventArgs e)
- {
- cANToolStripMenuItem.Checked = false;
- uARTToolStripMenuItem.Checked = true;
- UART协议ToolStripMenuItem.Visible = true;
- ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- /// <summary>
- /// 清除流水号
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void label131_DoubleClick(object sender, EventArgs e)
- {
- if (MessageBox.Show("确认清零流水号?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- label_FacModeSerial.Text = "0";
- File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, label_FacModeSerial.Text);
- }
- }
- /// <summary>
- /// 清除流水号
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void label135_DoubleClick(object sender, EventArgs e)
- {
- if (MessageBox.Show("确认清零流水号?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- label_CheckModeSerial.Text = "0";
- File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, label_CheckModeSerial.Text);
- }
- }
- /// <summary>
- /// 打开自动更新
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- 打开ToolStripMenuItem.Checked = true;
- 关闭ToolStripMenuItem.Checked = false;
- ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- /// <summary>
- /// 关闭自动更新
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 关闭ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- 打开ToolStripMenuItem.Checked = false;
- 关闭ToolStripMenuItem.Checked = true;
- ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- /// <summary>
- /// 显示完整配置文件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void comboBox_FacModeCfgFile_MouseHover_1(object sender, EventArgs e)
- {
- // 创建the ToolTip
- ToolTip toolTip1 = new ToolTip();
- // 设置显示样式
- toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
- toolTip1.InitialDelay = 50;//事件触发多久后出现提示
- toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
- toolTip1.ShowAlways = true;//是否显示提示框
- // 设置伴随的对象.
- toolTip1.SetToolTip(this.comboBox_FacModeCfgFile, comboBox_FacModeCfgFile.Text);//设置故障内容显示
- }
- /// <summary>
- /// 显示完整配置文件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void comboBox_CheckModeCfgFile_MouseHover_1(object sender, EventArgs e)
- {
- // 创建the ToolTip
- ToolTip toolTip1 = new ToolTip();
- // 设置显示样式
- toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
- toolTip1.InitialDelay = 50;//事件触发多久后出现提示
- toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
- toolTip1.ShowAlways = true;//是否显示提示框
- // 设置伴随的对象.
- toolTip1.SetToolTip(this.comboBox_CheckModeCfgFile, comboBox_CheckModeCfgFile.Text);//设置故障内容显示
- }
- /// <summary>
- /// 手动发送指令
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 发送指令ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- //提示
- Scan scan_form = new Scan();
- scan_form.label1.Text = "按照16进制填写,相邻字节用空格隔开,依次填写ID、Mode、Cmd、Data\r\n例如:07 31 16 22 05 01 02 03 04 05";
- scan_form.ShowDialog();
-
- //发送写入的指令,填写ID、类型、命令字、数据
- do
- {
- if (scan_form.textBox_Scan.Text == string.Empty)
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_500ms.Enabled = true;
- break;
- }
- //输入文本转换为字节流
- var InputData = new byte[256];
- InputData = mySerialProcess.HexStringToBytes(scan_form.textBox_Scan.Text, true);
- //ID
- ushort ID;
- ID = (ushort)((InputData[0] << 8) + InputData[1]);
- //Mode
- byte Mode;
- Mode = InputData[2];
- //Cmd
- ushort Cmd;
- Cmd = (ushort)((InputData[3] << 8) + InputData[4]);
- //Data
- var Data = new byte[Cmd & 0x00FF];
- for (int i = 0; i < (Cmd & 0x00FF); i++)
- Data[i] = InputData[5 + i];
- //发送数据
- mySerialProcess.SendCmdWithoutNotice(ID, Mode, Cmd, Data);
- } while (false);
- }
- /// <summary>
- /// 启动位置传感器校准
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_AngleCalStart_Click(object sender, EventArgs e)
- {
- for (int i = 0; i < 7; i++)
- for (int j = 0; j < 6; j++)
- {
- dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = "";
- }
- foreach (Control cr in tabPage_AngleCal.Controls)
- {
- if (cr is TextBox)
- {
- if ((cr != textBox_AngleDiffTh) && (cr != textBox_AngleZeroTh))
- cr.Text = "";
- }
- }
- var Data = new byte[2];
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x0C, (ushort)0x5002, Data);
- }
- /// <summary>
- /// 导出位置传感器校准数据
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_AngleExportData_Click(object sender, EventArgs e)
- {
- //读出产品信息
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
- Delay_ms(200);
- SaveFileDialog sfd = new SaveFileDialog
- {
- FileName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + "位置传感器角度数据_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt",
- Filter = "文本文档(*.txt)|*.txt",
- Title = "Save"
- };
- if (sfd.ShowDialog() != DialogResult.OK)
- {
- return;
- }
- string filepath = sfd.FileName;
- FileStream fs = new FileStream(filepath, FileMode.OpenOrCreate);
- using (StreamWriter sw = new StreamWriter(fs))
- {
- sw.Write("标准值 ");
- sw.Write("60.00 ");
- sw.Write("120.00 ");
- sw.Write("180.00 ");
- sw.Write("240.00 ");
- sw.Write("300.00 ");
- sw.Write("360.00 ");
- for (int i = 0; i < 42; i++)
- {
- if ((i % 6 == 0))
- {
- sw.Write("\r\n" + "采集值" + (i / 6 + 1).ToString() + " ");
- }
- sw.Write(AngledataRecord[i] + " ");
- }
- sw.Write("\r\n" + "历史零点位置 " + textBox_AngleZeroInit.Text);
- sw.Write("\r\n" + "当前零点位置 " + textBox_AngleZeroCur.Text);
- sw.Write("\r\n" + "零点误差 " + textBox_AngleZeroDiff.Text);
- sw.Write("\r\n" + "最小偏差值 " + textBox_AngleDiffMin.Text);
- sw.Write("\r\n" + "最大偏差值 " + textBox_AngleDiffMax.Text);
- sw.Write("\r\n" + "平均偏差值 " + textBox_AngleDiffAvg.Text);
- sw.Flush();
- }
- fs.Close();
- }
- /// <summary>
- /// 写入校准数据
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_AngleWrite_Click(object sender, EventArgs e)
- {
- if ((textBox_AngleDiffAvg.Text == "") || (textBox_AngleZeroInit.Text == ""))
- {
- timer_500ms.Enabled = false;
- MessageBox.Show("请先启动校准,以确认校准数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_500ms.Enabled = true;
- return;
- }
- timer_500ms.Enabled = false;
- string str1 = "确认校准数据,历史零点: " + textBox_AngleZeroInit.Text + ", 偏差平均值: " + textBox_AngleDiffAvg.Text;
- if (MessageBox.Show(str1, "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- var SaveFlag = new byte[4];
- for (int i = 0; i < 4; i++)
- SaveFlag[i] = 0;
- SaveFlag[0] = (byte)(1);
- double data1 = Convert.ToDouble(textBox_AngleZeroInit.Text) - Convert.ToDouble(textBox_AngleDiffAvg.Text);
- if (data1 > 360)
- {
- data1 -= 360;
- }
- else if (data1 < -360)
- {
- data1 += 360;
- }
- Int16 data2 = (Int16)(data1 * 32768 / 360);
- SaveFlag[2] = (byte)(data2);
- SaveFlag[3] = (byte)(data2 >> 8);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, SaveFlag);
- timer_500ms.Enabled = true;
- }
- else
- {
- timer_500ms.Enabled = true;
- MessageBoxTimeOut.Show("写入取消", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- /// <summary>
- /// 存储允许偏差
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void textBox_AngleDiffTh_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
- MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
- }
- }
- /// <summary>
- /// 存储零点允许偏差
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void textBox_AngleZeroTh_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
- MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
- }
- }
- /// <summary>
- /// 删除服务器配置文件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 重置ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- if (MessageBox.Show("重置后软件自动关闭,确认重置?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- if(File.Exists(localInfo.LocalPath + localInfo.ServerCfgFileName))
- File.Delete(localInfo.LocalPath + localInfo.ServerCfgFileName);
- if(File.Exists(localInfo.LocalPath + localInfo.ConfigFileName))
- File.Delete(localInfo.LocalPath + localInfo.ConfigFileName);
- System.Environment.Exit(0);
- }
- }
- /// <summary>
- /// 按下Enter保存数据
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void toolStripTextBox_AngleAvgMax_KeyDown(object sender, KeyEventArgs e)
- {
- textBox_AngleDiffTh.Text = toolStripTextBox_AngleAvgMax.Text;
- if (e.KeyCode == Keys.Enter)
- {
- ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
- MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
- }
- }
- /// <summary>
- /// 按下Enter保存数据
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void toolStripTextBox_AngleZeroMax_KeyDown(object sender, KeyEventArgs e)
- {
- textBox_AngleZeroTh.Text = toolStripTextBox_AngleZeroMax.Text;
- if (e.KeyCode == Keys.Enter)
- {
- ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
- MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
- }
- }
- private void 帮助ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- //检查本地文件
- if (!File.Exists(localInfo.LocalPath + localInfo.HelpFilename))
- {
- if (!OfflineFlag)
- myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/help/" + localInfo.HelpFilename, localInfo.LocalPath);
- else
- {
- MessageBoxTimeOut.Show("未找到帮助文件!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- }
- //调用本地浏览器打开帮助文件
- System.Diagnostics.Process.Start("explorer", localInfo.LocalPath + localInfo.HelpFilename);
- }
- /// <summary>
- /// 读取故障日志地址
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadLogAddr_Click(object sender, EventArgs e)
- {
- textBox_LogAddrBegin.Text = "";
- textBox_LogAddrEnd.Text = "";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x5200, null);
- }
- /// <summary>
- /// 写入硬件版本
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteHW_Click(object sender, EventArgs e)
- {
- string HW = textBox_HW.Text;
- var HWArray = new byte[16];
- for (ushort i = 0; i < HW.Length; i++)
- {
- HWArray[i] = (byte)HW[i];
- }
- if (HW.Length < 16)
- {
- HWArray[HW.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - HW.Length - 1; i++)
- {
- HWArray[HW.Length + 1 + i] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5310, HWArray);
- }
- /// <summary>
- /// 生产模式写入HW
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Button_FacModeSetHW_Click(object sender, EventArgs e)
- {
- string HW = textBox_FacModeHW.Text;
- var HWArray = new byte[16];
- for (ushort i = 0; i < HW.Length; i++)
- {
- HWArray[i] = (byte)HW[i];
- }
- if (HW.Length < 16)
- {
- HWArray[HW.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - HW.Length - 1; i++)
- {
- HWArray[HW.Length + 1 + i] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5310, HWArray);
- }
- /// <summary>
- /// 读取定制编号
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadUserNum_Click(object sender, EventArgs e)
- {
- textBox_UserNum.Text = "---";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x5600, null);
- }
- /// <summary>
- /// 写入定制编号
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteUserNum_Click(object sender, EventArgs e)
- {
- string User = textBox_UserNum.Text;
- var UserArray = new byte[32];
- for (ushort i = 0; i < User.Length; i++)
- {
- UserArray[i] = (byte)User[i];
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5720, UserArray);
- }
- /// <summary>
- /// 读取指定块拓展功能
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_FunSet_Read_Click(object sender, EventArgs e)
- {
- if (comboBox_FunSet_BlockNum.SelectedIndex < 0)
- {
- MessageBox.Show("请选择块编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- else
- {
- //清空当前内容
- for (int i = 0; i < 8; i++)
- for (int j = 0; j < 8; j++)
- {
- dataGridView_FunSet.Rows[i].Cells[j + 1].Value = "";
- }
- //发送读取指令
- ushort Num = (ushort)(comboBox_FunSet_BlockNum.SelectedIndex + 1);
- var Code = new byte[2];
- Code[0] = (byte)(Num & 0xFF);
- Code[1] = (byte)(Num >> 8);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x5402, Code);
- }
- }
- /// <summary>
- /// 写入指定块或指定单元参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_FunSet_Write_Click(object sender, EventArgs e)
- {
- if (radioButton_WriteByBlock.Checked == true)
- {
- if (comboBox_FunSet_BlockNum.SelectedIndex < 0)
- MessageBox.Show("请选择块编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- else
- {
- //开始按块写入
- ushort Num = (ushort)(comboBox_FunSet_BlockNum.SelectedIndex + 1);
- var Code = new byte[66];
- Code[0] = (byte)(Num & 0xFF);
- Code[1] = (byte)(Num >> 8);
- for (int i = 0; i < 8; i++)
- for (int j = 0; j < 8; j++)
- {
- try
- {
- byte Data = Convert.ToByte(dataGridView_FunSet.Rows[i].Cells[j + 1].Value);
- Code[i * 8 + j + 2] = (byte)(Data & 0xFF);
- }
- catch (Exception)
- {
- MessageBox.Show("数据格式错误或超范围!\r\n" + "单元编号:" + (i + 1).ToString() + "\r\n" + "参数:" + (j + 1).ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- }
- if (MessageBox.Show("请核对块编号!\r\n" + "块编号:" + (Num).ToString(), "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5542, Code);
- else
- MessageBoxTimeOut.Show("取消写入", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- else if (radioButton_WriteByUnit.Checked == true)
- {
- if (comboBox_FunSet_BlockNum.SelectedIndex < 0)
- MessageBox.Show("请选择块编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- else
- {
- if (comboBox_FunSet_UnitNum.SelectedIndex < 0)
- MessageBox.Show("请选择单元编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- else
- {
- //开始按单元写入
- ushort Num1 = (ushort)(comboBox_FunSet_BlockNum.SelectedIndex + 1);
- ushort Num2 = (ushort)(comboBox_FunSet_UnitNum.SelectedIndex + 1);
- var Code = new byte[12];
- Code[0] = (byte)(Num1 & 0xFF);
- Code[1] = (byte)(Num1 >> 8);
- Code[2] = (byte)(Num2 & 0xFF);
- Code[3] = (byte)(Num2 >> 8);
- for (int i = 0; i < 8; i++)
- {
- try
- {
- byte Data = Convert.ToByte(dataGridView_FunSet.Rows[Num2 - 1].Cells[i + 1].Value);
- Code[i + 4] = (byte)(Data & 0xFF);
- }
- catch (Exception)
- {
- MessageBox.Show("数据格式错误或超范围!\r\n" + "单元编号:" + Num2.ToString() + "\r\n" + "参数:" + (i + 1).ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- }
- if (MessageBox.Show("请核对块编号和单元编号!\r\n" + "块编号:" + Num1.ToString() + "\r\n" + "单元编号:" + Num2.ToString(), "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x550C, Code);
- else
- MessageBoxTimeOut.Show("取消写入", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- }
- else
- {
- MessageBox.Show("请选择写入方式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
- /// <summary>
- /// 按块写入时隐藏单元编号
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void radioButton_WriteByUnit_CheckedChanged(object sender, EventArgs e)
- {
- if (radioButton_WriteByUnit.Checked == true)
- {
- label159.Visible = true;
- comboBox_FunSet_UnitNum.Visible = true;
- }
- else
- {
- label159.Visible = false;
- comboBox_FunSet_UnitNum.Visible = false;
- }
- }
- /// <summary>
- /// 打开或关闭指令窗口
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 指令调试ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- if (指令调试ToolStripMenuItem.Checked == false)
- {
- if (DebugForm.debug1 == null || DebugForm.debug1.IsDisposed)
- {
- DebugForm.debug1 = new DebugForm();
- DebugForm.debug1.Show();
- this.DebugWindowIsOpen = true;
- }
- else
- {
- DebugForm.debug1.Activate();
- this.DebugWindowIsOpen = true;
- }
- 指令调试ToolStripMenuItem.Checked = true;
- }
- else
- {
- if (this.DebugWindowIsOpen == true)
- {
- DebugForm.debug1.Close();
- this.DebugWindowIsOpen = false;
- this.DebugDataDisplayEnable = false;
- }
- 指令调试ToolStripMenuItem.Checked = false;
- }
- }
- }
- }
|