mainForm.cs 389 KB

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