mainForm.cs 483 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242
  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.4.0";
  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. public string ServerIP = "";
  35. public string ServerPort = "";
  36. public string ServerUser = "";
  37. public string ServerPassWd = "";
  38. public bool OfflineFlag = false;
  39. //MC运行信息超时计数
  40. bool MC_RunInfo_Refresh = false;
  41. ushort MC_RunInfo_Refresh_Cnt = 0;
  42. //MC调试信息超时计数
  43. bool MC_DebugInfo_Refresh = false;
  44. ushort MC_DebugInfo_Refresh_Cnt = 0;
  45. //MC故障码超时计数
  46. bool MC_ErrorCode_Refresh = false;
  47. ushort MC_ErrorCode_Refresh_Cnt = 0;
  48. //配置参数实例
  49. Params myParams = new Params();
  50. //记录文件名称
  51. string RunInfoSaveFilename = "";
  52. //BMS运行信息超时计数
  53. bool BMS_RunInfo_Refresh = false;
  54. ushort BMS_RunInfo_Refresh_Cnt = 0;
  55. //生产模式关机指令反馈状态
  56. bool PowerOffAckStatus = false;
  57. //登录窗口
  58. public static Login EnterForm1 = new Login();
  59. //生产配置文件信息
  60. ArrayList array_CfgInfo = new ArrayList();
  61. //写入参数返回标志和计数
  62. public bool WriteACK = false;
  63. public ushort WriteCnt = 0;
  64. public ushort ACK_WaitCnt = 0;
  65. //写入参数返回提示标志
  66. public bool ACK_DisFlag = true;
  67. //Boot版本信息
  68. public string BootInfo = "";
  69. //接收指令临时缓存,转string
  70. public string CmdRevStrTemp = "";
  71. //计时器,用于统计运行时间
  72. public Stopwatch stopwatch = new Stopwatch();
  73. //力矩传感器检验参数窗口
  74. public static TorqueParams TorqueParamsForm = new TorqueParams();
  75. //参数生成窗口
  76. public static GenerateParams GenerateParamsForm = new GenerateParams();
  77. //版本信息窗口
  78. public static Version VersionForm = new Version();
  79. //本机硬件信息
  80. public string Local_HdInformation = "";
  81. //指令窗口显示
  82. public bool DebugWindowIsOpen = false, DebugDataDisplayEnable = false;
  83. //位置传感器数据记录
  84. string[] AngledataRecord = new string[42];
  85. //服务器设置窗口
  86. public static ServerSelect ServerCfgForm1 = new ServerSelect();
  87. #endregion
  88. #region 故障日志结构体定义
  89. //故障日志记录信息 60 bytes,1K空间可以保存最近16条故障记录
  90. [StructLayout(LayoutKind.Sequential)]
  91. public struct MC_ErrorLogSaveInfo_Struct_t
  92. {
  93. public UInt16 Error_Index; //故障列表索引 2 bytes, 地址偏移 0
  94. public UInt16 NotesInfo1; //备注信息1,地址偏移 2
  95. public UInt16 NotesInfo2; //备注信息2,地址偏移 4
  96. public UInt16 NotesInfo3; //备注信息3,地址偏移 6
  97. public UInt32 ErrorCode; //故障码 4 bytes, 地址偏移 8
  98. public UInt32 RunTime; //运行时间 4bytes, 地址偏移 12
  99. //电机运行信息,占用空间32bytes
  100. [StructLayout(LayoutKind.Sequential)]
  101. public struct MC_RunInfo_Struct_t
  102. {
  103. public ushort BikeSpeed; //车速 0.1km/h,地址偏移0
  104. public ushort MotorSpeed; //输出转速 1rpm,地址偏移2
  105. public ushort Power; //电功率 1W,地址偏移4
  106. public ushort BusVoltage; //母线电压 1mV,地址偏移6
  107. public ushort BusCurrent; //母线电流 1mA,地址偏移8
  108. public byte Cadence; //踏频 1rpm,地址偏移10
  109. public byte Torque; //踩踏力矩 1Nm,地址偏移11
  110. public byte CadenceDir; //踩踏方向 0-正,1-反,2-停止,地址偏移12
  111. public byte GearSt; //助力档位,地址偏移13
  112. public byte LightSwitch; //灯开关 0xF0-关,0xF1-开,地址偏移14
  113. public byte SOC; //剩余电量 1%,地址偏移15
  114. public ushort RemainDistance; //续航里程 1km,地址偏移16
  115. public ushort Torque_AD; //力矩寄存器,地址偏移18
  116. public byte PowerPerKm; //平均功耗 0.01Ah/km ,地址偏移20
  117. public byte T_PCB; //PCB温度 +40℃,地址偏移21
  118. public byte T_Coil; //绕组温度 +40℃,地址偏移22
  119. public byte T_MCU; //MCU温度 +40℃,地址偏移23
  120. public ushort Ride_Km; //开机后骑行里程 0.1km, 地址偏移24
  121. public ushort Ride_Time; //开机后骑行时间 1s,地址偏移26
  122. public UInt32 RS; //预留 4bytes
  123. };
  124. [MarshalAs(UnmanagedType.Struct)]
  125. public MC_RunInfo_Struct_t RunInfo; //运行信息 32bytes, 地址偏移 16
  126. //控制变量
  127. public Int16 IqCurrent; //Pu, 地址偏移 48
  128. public Int16 IqVoltage; //Pu, 地址偏移 50
  129. public Int16 IdCurrent; //Pu, 地址偏移 52
  130. public Int16 IdVoltage; //Pu, 地址偏移 54
  131. //状态机
  132. public UInt16 FSM; //高到低依次表示系统状态机、二层状态机、电机状态机、助力状态机, 地址偏移 56
  133. //预留
  134. public UInt16 RS1;
  135. public UInt16 RS2;
  136. public UInt16 RS3;
  137. };
  138. #endregion
  139. #region 屏幕缩放比例获取
  140. public class PrimaryScreen
  141. {
  142. #region Win32 API
  143. [DllImport("user32.dll")]
  144. static extern IntPtr GetDC(IntPtr ptr);
  145. [DllImport("gdi32.dll")]
  146. static extern int GetDeviceCaps(
  147. IntPtr hdc, // handle to DC
  148. int nIndex // index of capability
  149. );
  150. [DllImport("user32.dll", EntryPoint = "ReleaseDC")]
  151. static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDc);
  152. #endregion
  153. #region DeviceCaps常量
  154. const int HORZRES = 8;
  155. const int VERTRES = 10;
  156. const int LOGPIXELSX = 88;
  157. const int LOGPIXELSY = 90;
  158. const int DESKTOPVERTRES = 117;
  159. const int DESKTOPHORZRES = 118;
  160. #endregion
  161. #region 属性
  162. /// <summary>
  163. /// 获取屏幕分辨率当前物理大小
  164. /// </summary>
  165. public static Size WorkingArea
  166. {
  167. get
  168. {
  169. IntPtr hdc = GetDC(IntPtr.Zero);
  170. Size size = new Size();
  171. size.Width = GetDeviceCaps(hdc, HORZRES);
  172. size.Height = GetDeviceCaps(hdc, VERTRES);
  173. ReleaseDC(IntPtr.Zero, hdc);
  174. return size;
  175. }
  176. }
  177. /// <summary>
  178. /// 当前系统DPI_X 大小 一般为96
  179. /// </summary>
  180. public static int DpiX
  181. {
  182. get
  183. {
  184. IntPtr hdc = GetDC(IntPtr.Zero);
  185. int DpiX = GetDeviceCaps(hdc, LOGPIXELSX);
  186. ReleaseDC(IntPtr.Zero, hdc);
  187. return DpiX;
  188. }
  189. }
  190. /// <summary>
  191. /// 当前系统DPI_Y 大小 一般为96
  192. /// </summary>
  193. public static int DpiY
  194. {
  195. get
  196. {
  197. IntPtr hdc = GetDC(IntPtr.Zero);
  198. int DpiX = GetDeviceCaps(hdc, LOGPIXELSY);
  199. ReleaseDC(IntPtr.Zero, hdc);
  200. return DpiX;
  201. }
  202. }
  203. /// <summary>
  204. /// 获取真实设置的桌面分辨率大小
  205. /// </summary>
  206. public static Size DESKTOP
  207. {
  208. get
  209. {
  210. IntPtr hdc = GetDC(IntPtr.Zero);
  211. Size size = new Size();
  212. size.Width = GetDeviceCaps(hdc, DESKTOPHORZRES);
  213. size.Height = GetDeviceCaps(hdc, DESKTOPVERTRES);
  214. ReleaseDC(IntPtr.Zero, hdc);
  215. return size;
  216. }
  217. }
  218. /// <summary>
  219. /// 获取宽度缩放百分比
  220. /// </summary>
  221. public static float ScaleX
  222. {
  223. get
  224. {
  225. IntPtr hdc = GetDC(IntPtr.Zero);
  226. int t = GetDeviceCaps(hdc, DESKTOPHORZRES);
  227. int d = GetDeviceCaps(hdc, HORZRES);
  228. float ScaleX = (float)GetDeviceCaps(hdc, DESKTOPHORZRES) / (float)GetDeviceCaps(hdc, HORZRES);
  229. ReleaseDC(IntPtr.Zero, hdc);
  230. return ScaleX;
  231. }
  232. }
  233. /// <summary>
  234. /// 获取高度缩放百分比
  235. /// </summary>
  236. public static float ScaleY
  237. {
  238. get
  239. {
  240. IntPtr hdc = GetDC(IntPtr.Zero);
  241. float ScaleY = (float)(float)GetDeviceCaps(hdc, DESKTOPVERTRES) / (float)GetDeviceCaps(hdc, VERTRES);
  242. ReleaseDC(IntPtr.Zero, hdc);
  243. return ScaleY;
  244. }
  245. }
  246. #endregion
  247. }
  248. #endregion
  249. public static mainForm mainform1 = null;
  250. public mainForm()
  251. {
  252. InitializeComponent();
  253. mainform1 = this;
  254. System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
  255. stopwatch.Start();
  256. //端口初始化
  257. mySerialProcess.Init();
  258. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  259. //检查备忘录文件
  260. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.NoteFileName))
  261. {
  262. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.NoteFileName, "");
  263. }
  264. //检验流水号记录文件
  265. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.SerialNumFileName1))
  266. {
  267. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, "0");
  268. }
  269. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.SerialNumFileName2))
  270. {
  271. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, "0");
  272. }
  273. //检查文件夹
  274. if (!Directory.Exists(localInfo.LocalPath))
  275. {
  276. Directory.CreateDirectory(localInfo.LocalPath);
  277. }
  278. if (!Directory.Exists(localInfo.LocalDataPath))
  279. {
  280. Directory.CreateDirectory(localInfo.LocalDataPath);
  281. }
  282. if (!Directory.Exists(localInfo.ToolsPath))
  283. {
  284. Directory.CreateDirectory(localInfo.ToolsPath);
  285. }
  286. if (!Directory.Exists(localInfo.LocalPath + localInfo.CfgPathName))
  287. {
  288. Directory.CreateDirectory(localInfo.LocalPath + localInfo.CfgPathName);
  289. }
  290. //服务器初始化
  291. do
  292. {
  293. //检查是否存在配置文件
  294. if (File.Exists(localInfo.LocalPath + localInfo.ServerCfgFileName)) //存在配置文件从文件选择
  295. {
  296. //打开文件
  297. StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.ServerCfgFileName);
  298. string sLine = "";
  299. ArrayList array_CfgInfo = new ArrayList();
  300. array_CfgInfo.Clear();
  301. while (sLine != null)
  302. {
  303. sLine = objReader.ReadLine();
  304. array_CfgInfo.Add(sLine);
  305. }
  306. objReader.Close();
  307. //解析配置文件
  308. ServerIP = array_CfgInfo[0].ToString();
  309. ServerPort = array_CfgInfo[1].ToString();
  310. ServerUser = array_CfgInfo[2].ToString();
  311. ServerPassWd = array_CfgInfo[3].ToString();
  312. if (array_CfgInfo[4].ToString() == "True")
  313. {
  314. OfflineFlag = true;
  315. checkBox_OffLineFacMode.Checked = true;
  316. checkBox_OffLineCheckMode.Checked = true;
  317. }
  318. }
  319. else //不存在配置文件由用户选择
  320. {
  321. ServerCfgForm1.ShowDialog();
  322. switch (ServerCfgForm1.comboBox_Server.SelectedIndex)
  323. {
  324. case 0: //武汉园区
  325. case 1: //顺德工厂
  326. {
  327. ServerIP = "10.177.130.30";
  328. ServerPort = "15021";
  329. ServerUser = "factory_test";
  330. ServerPassWd = "ttium";
  331. OfflineFlag = false;
  332. checkBox_OffLineFacMode.Checked = false;
  333. checkBox_OffLineCheckMode.Checked = false;
  334. break;
  335. }
  336. case 2: //威灵园区
  337. case 3: //越南工厂
  338. case 4: //公司外部
  339. {
  340. ServerIP = "8.134.109.44";
  341. ServerPort = "21";
  342. ServerUser = "ttium";
  343. ServerPassWd = "ttium123";
  344. OfflineFlag = false;
  345. checkBox_OffLineFacMode.Checked = false;
  346. checkBox_OffLineCheckMode.Checked = false;
  347. break;
  348. }
  349. case 5: //离线使用
  350. {
  351. //输入管理员密码
  352. Scan scan_form = new Scan();
  353. scan_form.label1.Text = "请输入管理员密码";
  354. scan_form.textBox_Scan.UseSystemPasswordChar = true;
  355. scan_form.ShowDialog();
  356. if (scan_form.textBox_Scan.Text == "ttium.123")
  357. {
  358. OfflineFlag = true;
  359. checkBox_OffLineFacMode.Checked = true;
  360. checkBox_OffLineCheckMode.Checked = true;
  361. }
  362. else
  363. {
  364. MessageBox.Show("密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  365. System.Environment.Exit(0);
  366. }
  367. break;
  368. }
  369. default: //无效
  370. {
  371. System.Environment.Exit(0);
  372. break;
  373. }
  374. }
  375. //保存网络配置文件
  376. if (ServerCfgForm1.checkBox_NoticeSw.Checked)
  377. {
  378. string str = ServerIP + "\r\n" + ServerPort + "\r\n" + ServerUser + "\r\n" + ServerPassWd + "\r\n" + (OfflineFlag == true).ToString();
  379. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.ServerCfgFileName, str);
  380. }
  381. }
  382. } while (false);
  383. //检查配置文件
  384. if (File.Exists(localInfo.LocalPath + localInfo.ConfigFileName)) //存在配置文件,导入配置信息
  385. {
  386. //打开文件
  387. StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.ConfigFileName);
  388. string sLine = "";
  389. ArrayList array_CfgInfo = new ArrayList();
  390. array_CfgInfo.Clear();
  391. while (sLine != null)
  392. {
  393. sLine = objReader.ReadLine();
  394. array_CfgInfo.Add(sLine);
  395. }
  396. objReader.Close();
  397. //解析配置文件
  398. try
  399. {
  400. //Port Set
  401. PortNumSave = array_CfgInfo[1].ToString().Split(':')[1];
  402. PortBaudrateSave = array_CfgInfo[2].ToString().Split(':')[1];
  403. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.IndexOf(PortNumSave);
  404. toolStripComboBox_Baudrate.SelectedIndex = toolStripComboBox_Baudrate.Items.IndexOf(PortBaudrateSave);
  405. 连接开机ToolStripMenuItem.Checked = (array_CfgInfo[3].ToString().Split(':')[1] == "True");
  406. 断开关机ToolStripMenuItem.Checked = (array_CfgInfo[4].ToString().Split(':')[1] == "True");
  407. 识别通讯盒ToolStripMenuItem.Checked = (array_CfgInfo[5].ToString().Split(':')[1] == "True");
  408. //Option
  409. 写入存储ToolStripMenuItem.Checked = (array_CfgInfo[8].ToString().Split(':')[1] == "True");
  410. //Server Set
  411. toolStripTextBox_ServerPath.Text = array_CfgInfo[11].ToString().Split(':')[1];
  412. //MacInfo
  413. toolStripTextBox_MAC.Text = array_CfgInfo[14].ToString().Split(':')[1];
  414. toolStripTextBoxMACAddr.Text = array_CfgInfo[15].ToString().Split(':')[1];
  415. toolStripTextBox_MACDate.Text = DateTime.Now.ToString("yyyyMMdd");
  416. toolStripTextBox_MACPD.Text = array_CfgInfo[17].ToString().Split(':')[1];
  417. //Log Address
  418. textBox_LogAddrBegin.Text = array_CfgInfo[20].ToString().Split(':')[1];
  419. textBox_LogAddrEnd.Text = array_CfgInfo[21].ToString().Split(':')[1];
  420. //电机类型
  421. 中置电机ToolStripMenuItem.Checked = (array_CfgInfo[24].ToString().Split(':')[1] == "True");
  422. 轮毂电机ToolStripMenuItem.Checked = !中置电机ToolStripMenuItem.Checked;
  423. //检测阈值
  424. toolStripTextBox_ThVol.Text = array_CfgInfo[28].ToString().Split(':')[1];
  425. toolStripTextBox_ThCur.Text = array_CfgInfo[29].ToString().Split(':')[1];
  426. toolStripTextBox_ThSpeed.Text = array_CfgInfo[30].ToString().Split(':')[1];
  427. toolStripTextBox_ThTor.Text = array_CfgInfo[31].ToString().Split(':')[1];
  428. toolStripTextBox_ThCad.Text = array_CfgInfo[32].ToString().Split(':')[1];
  429. toolStripTextBox_ThBikeSpeed.Text = array_CfgInfo[33].ToString().Split(':')[1];
  430. toolStripTextBox_ThT_PCB.Text = array_CfgInfo[34].ToString().Split(':')[1];
  431. toolStripTextBox_ThT_MCU.Text = array_CfgInfo[35].ToString().Split(':')[1];
  432. toolStripTextBox_ThT_Motor.Text = array_CfgInfo[36].ToString().Split(':')[1];
  433. //MOS内阻校准系数
  434. toolStripTextBox_MosCalK.Text = array_CfgInfo[39].ToString().Split(':')[1];
  435. toolStripTextBox_MOS1.Text= array_CfgInfo[40].ToString().Split(':')[1];
  436. toolStripTextBox_MOS2.Text = array_CfgInfo[41].ToString().Split(':')[1];
  437. toolStripTextBox_MOS3.Text = array_CfgInfo[42].ToString().Split(':')[1];
  438. //通信协议类型
  439. cANToolStripMenuItem.Checked = (array_CfgInfo[45].ToString().Split(':')[1] == "True");
  440. uARTToolStripMenuItem.Checked = !cANToolStripMenuItem.Checked;
  441. //自动更新开关
  442. 打开ToolStripMenuItem.Checked = (array_CfgInfo[49].ToString().Split(':')[1] == "True");
  443. 关闭ToolStripMenuItem.Checked = !打开ToolStripMenuItem.Checked;
  444. //位置校准偏差
  445. textBox_AngleDiffTh.Text = array_CfgInfo[52].ToString().Split(':')[1];
  446. toolStripTextBox_AngleAvgMax.Text = textBox_AngleDiffTh.Text;
  447. textBox_AngleZeroTh.Text = array_CfgInfo[53].ToString().Split(':')[1];
  448. toolStripTextBox_AngleZeroMax.Text = textBox_AngleZeroTh.Text;
  449. }
  450. catch (System.Exception)
  451. {
  452. timer_500ms.Enabled = false;
  453. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  454. timer_500ms.Enabled = true;
  455. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  456. }
  457. }
  458. else //不存在配置文件,生成文件写入默认值
  459. {
  460. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  461. }
  462. //解析本地流水号记录
  463. do
  464. {
  465. //测试模式
  466. label_FacModeSerial.Text = File.ReadAllText(localInfo.LocalPath + localInfo.SerialNumFileName1);
  467. //检验模式
  468. label_CheckModeSerial.Text = File.ReadAllText(localInfo.LocalPath + localInfo.SerialNumFileName2);
  469. } while (false);
  470. //获取本机信息,读取时间较长,优先从本地文件获取
  471. do
  472. {
  473. try
  474. {
  475. //本地文件为空,读取信息保存
  476. if (!File.Exists(localInfo.LocalPath + localInfo.PC_InfoFileName))
  477. {
  478. Local_HdInformation = "";
  479. Local_HdInformation += "计算机名称: " + System.Environment.UserName + "\r\n";
  480. Local_HdInformation += "IP地址: " + PC_Information.GetIpAddress() + "\r\n";
  481. Local_HdInformation += "系统ID: " + PC_Information.GetSystemID() + "\r\n";
  482. Local_HdInformation += "操作系统类型: " + PC_Information.GetSystemType() + "\r\n";
  483. Local_HdInformation += "主板型号: " + PC_Information.GetBoardType() + "\r\n";
  484. Local_HdInformation += "主板厂商: " + PC_Information.GetBoardManufacturer() + "\r\n";
  485. Local_HdInformation += "主板ID: " + PC_Information.GetBIOSSerialNumber() + "\r\n";
  486. Local_HdInformation += "CPU型号: " + PC_Information.GetCpuName() + "\r\n";
  487. Local_HdInformation += "CPU厂商: " + PC_Information.GetCpuManufacturer() + "\r\n";
  488. Local_HdInformation += "CPU ID: " + PC_Information.GetCPUSerialNumber() + "\r\n";
  489. Local_HdInformation += "内存容量: " + PC_Information.GetPhysicalMemory() + " GB" + "\r\n";
  490. Local_HdInformation += "MAC ID: " + PC_Information.GetNetCardMACAddress().Replace(":", "-") + "\r\n";
  491. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.PC_InfoFileName, Local_HdInformation);
  492. }
  493. //从本地读取,计算机名和IP地址重新读
  494. else
  495. {
  496. Local_HdInformation = "";
  497. string[] fileInfo = File.ReadAllLines(localInfo.LocalPath + localInfo.PC_InfoFileName, Encoding.UTF8);
  498. fileInfo[0] = "计算机名称: " + System.Environment.UserName;
  499. fileInfo[1] = "IP地址: " + PC_Information.GetIpAddress();
  500. for (int i = 0; i < fileInfo.Length; i++)
  501. Local_HdInformation += fileInfo[i] + "\r\n";
  502. File.Delete(localInfo.LocalPath + localInfo.PC_InfoFileName);
  503. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.PC_InfoFileName, Local_HdInformation);
  504. }
  505. }
  506. catch(Exception)
  507. {
  508. }
  509. } while (false);
  510. //系统登录
  511. do
  512. {
  513. EnterForm1.ShowDialog();
  514. try
  515. {
  516. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  517. {
  518. if (EnterForm1.comboBox_User.Text.Contains("量产"))
  519. {
  520. //隐藏设置项
  521. 其它配置项ToolStripMenuItem.Visible = false;
  522. 写入存储ToolStripMenuItem.Visible = false;
  523. 服务器配置ToolStripMenuItem.Visible = false;
  524. 判断阈值ToolStripMenuItem.Visible = false;
  525. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  526. mOS内阻范围ToolStripMenuItem.Visible = false;
  527. 力矩传感器检验ToolStripMenuItem.Visible = false;
  528. 位置校准偏差范围ToolStripMenuItem.Visible = false;
  529. //显示生产信息
  530. 生产信息ToolStripMenuItem.Visible = true;
  531. //显示电机类型,但不可编辑
  532. 电机类型ToolStripMenuItem.Visible = true;
  533. 中置电机ToolStripMenuItem.Enabled = false;
  534. 轮毂电机ToolStripMenuItem.Enabled = false;
  535. if (uARTToolStripMenuItem.Checked)
  536. UART协议ToolStripMenuItem.Visible = true;
  537. //隐藏研发调试界面
  538. tabPage_MotorParam.Parent = null;
  539. tabPage_BikeParam.Parent = null;
  540. tabPage_BikeParam2.Parent = null;
  541. tabPage_ControlParam.Parent = null;
  542. tabPage_SensorParam.Parent = null;
  543. tabPage_AssistParam.Parent = null;
  544. tabPage_UsrRideParam.Parent = null;
  545. tabPage_DebugParam.Parent = null;
  546. tabPage_RecordInfo.Parent = null;
  547. tabPage_OtherInfo.Parent = null;
  548. tabPage_OBC.Parent = null;
  549. tabPage_RAMorFLASH.Parent = null;
  550. tabPage_FactoryMode.Parent = null;
  551. tabPage_DebugInfo.Parent = null;
  552. tabPage_AngleCal.Parent = null;
  553. //显示运行信息
  554. tabPage_RunInfo.Parent = tabControl2;
  555. //根据电机类型修改生产信息和电机类型
  556. if (EnterForm1.comboBox_User.Text.Contains("中置"))
  557. {
  558. 中置电机ToolStripMenuItem.Checked = true;
  559. 轮毂电机ToolStripMenuItem.Checked = false;
  560. toolStripTextBox_MACPD.Text = "MM_MC1";
  561. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  562. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  563. }
  564. else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
  565. {
  566. 中置电机ToolStripMenuItem.Checked = false;
  567. 轮毂电机ToolStripMenuItem.Checked = true;
  568. toolStripTextBox_MACPD.Text = "GF_250_1";
  569. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  570. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  571. }
  572. //显示对应生产测试界面
  573. if (EnterForm1.comboBox_User.Text.Contains("写入"))
  574. {
  575. tabPage_ProductMode_Write.Parent = tabControl1;
  576. tabPage_ProductMode_Write.Select();
  577. tabPage_ProductMode_Read.Parent = null;
  578. }
  579. else if (EnterForm1.comboBox_User.Text.Contains("检验"))
  580. {
  581. tabPage_ProductMode_Read.Parent = tabControl1;
  582. tabPage_ProductMode_Read.Select();
  583. tabPage_ProductMode_Write.Parent = null;
  584. }
  585. //应答指令不提示
  586. ACK_DisFlag = false;
  587. //退出登录
  588. break;
  589. }
  590. else if (EnterForm1.comboBox_User.Text == "工程参数配置")
  591. {
  592. //隐藏工作台内容,新建窗口完成配置
  593. groupBox1.Visible = false;
  594. groupBox3.Visible = false;
  595. tabControl2.Visible = false;
  596. //隐藏提示信息
  597. label_StarInfo.Visible = false;
  598. //打开参数配置框
  599. GenerateParamsForm.ShowDialog();
  600. System.Environment.Exit(0);
  601. //退出登录
  602. break;
  603. }
  604. else if (EnterForm1.comboBox_User.Text.Contains("样机"))
  605. {
  606. //隐藏量产界面
  607. tabPage_ProductMode_Read.Parent = null;
  608. tabPage_ProductMode_Write.Parent = null;
  609. //隐藏配置项
  610. 其它配置项ToolStripMenuItem.Visible = false;
  611. 服务器配置ToolStripMenuItem.Visible = false;
  612. 判断阈值ToolStripMenuItem.Visible = false;
  613. 力矩传感器检验ToolStripMenuItem.Visible = false;
  614. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  615. mOS内阻范围ToolStripMenuItem.Visible = false;
  616. 位置校准偏差范围ToolStripMenuItem.Visible = false;
  617. //显示生产信息
  618. 生产信息ToolStripMenuItem.Visible = true;
  619. //显示电机类型,但不可编辑
  620. 电机类型ToolStripMenuItem.Visible = true;
  621. 中置电机ToolStripMenuItem.Enabled = true;
  622. 轮毂电机ToolStripMenuItem.Enabled = true;
  623. if (uARTToolStripMenuItem.Checked)
  624. UART协议ToolStripMenuItem.Visible = true;
  625. if (EnterForm1.comboBox_User.Text.Contains("中置"))
  626. {
  627. 中置电机ToolStripMenuItem.Checked = true;
  628. 轮毂电机ToolStripMenuItem.Checked = false;
  629. toolStripTextBox_MACPD.Text = "MM_MC1";
  630. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  631. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  632. }
  633. else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
  634. {
  635. 中置电机ToolStripMenuItem.Checked = false;
  636. 轮毂电机ToolStripMenuItem.Checked = true;
  637. toolStripTextBox_MACPD.Text = "GF_250_1";
  638. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  639. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  640. }
  641. //退出登录
  642. break;
  643. }
  644. else if (EnterForm1.comboBox_User.Text == "FCT治具测试")
  645. {
  646. //隐藏设置项
  647. 其它配置项ToolStripMenuItem.Visible = false;
  648. 写入存储ToolStripMenuItem.Visible = false;
  649. 服务器配置ToolStripMenuItem.Visible = false;
  650. 判断阈值ToolStripMenuItem.Visible = false;
  651. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  652. mOS内阻范围ToolStripMenuItem.Visible = false;
  653. 力矩传感器检验ToolStripMenuItem.Visible = false;
  654. 位置校准偏差范围ToolStripMenuItem.Visible = false;
  655. //显示生产信息
  656. 生产信息ToolStripMenuItem.Visible = true;
  657. //显示电机类型,但不可编辑
  658. 电机类型ToolStripMenuItem.Visible = false;
  659. 中置电机ToolStripMenuItem.Enabled = false;
  660. 轮毂电机ToolStripMenuItem.Enabled = false;
  661. if (uARTToolStripMenuItem.Checked)
  662. UART协议ToolStripMenuItem.Visible = true;
  663. //隐藏研发调试界面
  664. tabPage_MotorParam.Parent = null;
  665. tabPage_BikeParam.Parent = null;
  666. tabPage_BikeParam2.Parent = null;
  667. tabPage_ControlParam.Parent = null;
  668. tabPage_SensorParam.Parent = null;
  669. tabPage_AssistParam.Parent = null;
  670. tabPage_UsrRideParam.Parent = null;
  671. tabPage_DebugParam.Parent = null;
  672. tabPage_RecordInfo.Parent = null;
  673. tabPage_OtherInfo.Parent = null;
  674. tabPage_OBC.Parent = null;
  675. tabPage_RAMorFLASH.Parent = null;
  676. tabPage_FactoryMode.Parent = null;
  677. tabPage_DebugInfo.Parent = null;
  678. tabPage_AngleCal.Parent = null;
  679. //显示运行信息
  680. tabPage_RunInfo.Parent = tabControl2;
  681. //目前仅轮毂使用
  682. 中置电机ToolStripMenuItem.Checked = false;
  683. 轮毂电机ToolStripMenuItem.Checked = true;
  684. toolStripTextBox_MACPD.Text = "GF_250_1";
  685. toolStripTextBox_ServerPath.Text = "HUB_Control_FCT";
  686. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  687. //显示量产测试界面
  688. tabPage_ProductMode_Write.Parent = tabControl1;
  689. tabPage_ProductMode_Write.Select();
  690. tabPage_ProductMode_Read.Parent = null;
  691. checkBox_OffLineFacMode.Checked = false;
  692. checkBox_OffLineFacMode.Enabled = true;
  693. checkBox_OffLineCheckMode.Checked = false;
  694. checkBox_OffLineCheckMode.Enabled = true;
  695. //应答指令不提示
  696. ACK_DisFlag = false;
  697. //退出登录
  698. break;
  699. }
  700. else if (EnterForm1.comboBox_User.Text == "研发调试")
  701. {
  702. //隐藏量产界面
  703. tabPage_ProductMode_Read.Parent = null;
  704. tabPage_ProductMode_Write.Parent = null;
  705. 服务器配置ToolStripMenuItem.Visible = false;
  706. if (uARTToolStripMenuItem.Checked)
  707. UART协议ToolStripMenuItem.Visible = true;
  708. //退出登录
  709. break;
  710. }
  711. else if (EnterForm1.comboBox_User.Text == "管理员")
  712. {
  713. //不隐藏任何界面
  714. //...
  715. //退出登录
  716. break;
  717. }
  718. else
  719. {
  720. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  721. //重新登录
  722. continue;
  723. }
  724. }
  725. else
  726. {
  727. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  728. //重新登录
  729. continue;
  730. }
  731. }
  732. catch (Exception)
  733. {
  734. System.Environment.Exit(0);
  735. }
  736. } while (true);
  737. //配置网络FTP服务器
  738. myFtp.FtpOption(ServerIP, ServerPort, ServerUser, ServerPassWd, "admin", "ttium_admin");
  739. //创建线程,定时检测网络连接状态
  740. Thread th = new Thread(NetworkCheck);
  741. th.IsBackground = true;
  742. th.Start();
  743. //允许跨线程访问
  744. Control.CheckForIllegalCrossThreadCalls = false;
  745. }
  746. /// <summary>
  747. /// 检查网络状态线程
  748. /// </summary>
  749. private void NetworkCheck()
  750. {
  751. //允许离线使用,直接退出
  752. if (OfflineFlag == true) //允许离线使用
  753. {
  754. timer_500ms.Enabled = false;
  755. MessageBoxTimeOut.Show("离线使用,不检测网络状态!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  756. timer_500ms.Enabled = true;
  757. return;
  758. }
  759. //不允许离线使用,实时监测网络状态
  760. else
  761. {
  762. //初始化第一次连接FTP服务器
  763. bool Result = myFtp.CheckFtp();
  764. if (Result == true)//服务器连接成功
  765. {
  766. myFtp.IsNetConnected = true;
  767. //上传登录日志
  768. do
  769. {
  770. //日志文件名
  771. string date = DateTime.Now.ToString("yyyy-MM-dd_HHmmss_fff");
  772. string fileName = date;
  773. //日志内容
  774. string fileInfo = Local_HdInformation;
  775. //保存本地
  776. if (!Directory.Exists(localInfo.LocalLogPath))
  777. Directory.CreateDirectory(localInfo.LocalLogPath);
  778. System.IO.File.WriteAllText(localInfo.LocalLogPath + fileName, fileInfo);
  779. //上传服务器
  780. myFtp.UploadFile(localInfo.LocalLogPath + fileName, "/Tools/Welling_Motor_Debug_Tool/log");
  781. } while (false);
  782. }
  783. else//服务器连接失败
  784. {
  785. myFtp.IsNetConnected = false;
  786. if (EnterForm1.comboBox_User.Text != "管理员")
  787. {
  788. timer_500ms.Enabled = false;
  789. MessageBoxTimeOut.Show("网络断开,将自动关闭!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  790. timer_500ms.Enabled = true;
  791. this.Close();
  792. }
  793. }
  794. //创建定时器,定时30s检查网络
  795. System.Timers.Timer timer_CheckNet = new System.Timers.Timer();
  796. timer_CheckNet.Enabled = true;
  797. timer_CheckNet.Interval = 30000;
  798. timer_CheckNet.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_CheckNet_Tick);
  799. timer_CheckNet.Start();
  800. while (true)
  801. {
  802. Thread.Sleep(1);
  803. if (myFtp.IsNetConnected == false)
  804. {
  805. label_Server_ComStatus.Text = "网络已断开";
  806. label_ServerStatus.BackColor = Color.Red;
  807. }
  808. else
  809. {
  810. label_Server_ComStatus.Text = "网络已连接";
  811. label_ServerStatus.BackColor = Color.Green;
  812. }
  813. }
  814. }
  815. }
  816. /// <summary>
  817. /// 线程中定时任务,检查网络状态
  818. /// </summary>
  819. /// <param name="sender"></param>
  820. /// <param name="e"></param>
  821. private void timer_CheckNet_Tick(object sender, EventArgs e)
  822. {
  823. //连接FTP服务器
  824. bool Result = myFtp.CheckFtp();
  825. if (Result == true)//服务器连接成功
  826. {
  827. myFtp.IsNetConnected = true;
  828. //允许使用
  829. groupBox1.Enabled = true;
  830. groupBox3.Enabled = true;
  831. tabControl2.Enabled = true;
  832. }
  833. else//服务器连接失败
  834. {
  835. myFtp.IsNetConnected = false;
  836. if (EnterForm1.comboBox_User.Text != "管理员")
  837. {
  838. timer_500ms.Enabled = false;
  839. MessageBoxTimeOut.Show("网络断开, 请检查网络!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Warning); //提示框自动3s关闭
  840. timer_500ms.Enabled = true;
  841. //禁止使用
  842. groupBox1.Enabled = false;
  843. groupBox3.Enabled = false;
  844. tabControl2.Enabled = false;
  845. }
  846. }
  847. }
  848. #region 非独占性延时函数
  849. public static void Delay_ms(int milliSecond)
  850. {
  851. int start = Environment.TickCount;
  852. while (Math.Abs(Environment.TickCount - start) < milliSecond)//毫秒
  853. {
  854. Application.DoEvents();
  855. }
  856. }
  857. #endregion
  858. private void MainForm_Load(object sender, System.EventArgs e)
  859. {
  860. //页面初始化
  861. label_BuildTime.Text = "编译时间:" + System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString("yyyy-MM-dd HH:mm:ss");
  862. label_Computername.Text = System.Environment.UserName;
  863. label_UserName.Text = EnterForm1.comboBox_User.Text;
  864. //位置校准表格初始化
  865. for (int i = 0; i < 7; i++)
  866. {
  867. int index = dataGridView_AngleCal.Rows.Add();
  868. dataGridView_AngleCal.Rows[index].Cells[0].Value = i + 1;
  869. }
  870. dataGridView_AngleCal.AllowUserToAddRows = false;
  871. this.Text += Version;
  872. //检查版本,自动更新
  873. do
  874. {
  875. if ((打开ToolStripMenuItem.Checked == false) || OfflineFlag == true)//关闭自动更新或离线时
  876. {
  877. break;
  878. }
  879. //检查网络状态
  880. if (myFtp.CheckFtp() == false)
  881. {
  882. MessageBoxTimeOut.Show("网络断开,自动更新失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  883. break;
  884. }
  885. else
  886. {
  887. //检查本地文件删除
  888. if (System.IO.File.Exists(localInfo.LocalPath + "\\Version"))
  889. System.IO.File.Delete(localInfo.LocalPath + "\\Version");
  890. //读取最新版本号
  891. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/Version", localInfo.LocalPath);
  892. StreamReader objReader = new StreamReader(localInfo.LocalPath + "\\Version");
  893. string sLine = "";
  894. ArrayList arrText = new ArrayList();//创建一个动态数组
  895. while (sLine != null)
  896. {
  897. sLine = objReader.ReadLine();
  898. arrText.Add(sLine);
  899. }
  900. objReader.Close();
  901. System.IO.File.Delete(localInfo.LocalPath + "\\Version");
  902. //检查是否有最新版本
  903. string[] VerOld = mainForm.Version.Trim().Split('.');
  904. string[] VerNew = arrText[0].ToString().Trim().Split('.');
  905. int VerOld_int = Convert.ToInt32(VerOld[0]) * 10000 + Convert.ToInt32(VerOld[1].PadLeft(2, '0')) * 100 + Convert.ToInt32(VerOld[2].PadLeft(2, '0'));
  906. int VerNew_int = Convert.ToInt32(VerNew[0]) * 10000 + Convert.ToInt32(VerNew[1].PadLeft(2, '0')) * 100 + Convert.ToInt32(VerNew[2].PadLeft(2, '0'));
  907. if (VerNew_int <= VerOld_int)
  908. {
  909. //版本已是最新,跳出
  910. break;
  911. }
  912. //确认下载最新版本
  913. if (MessageBox.Show("是否更新新版本?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  914. {
  915. string SavePath = Directory.GetCurrentDirectory();
  916. string[] FileList = myFtp.GetFileNameList("/Tools/Welling_Motor_Debug_Tool");
  917. foreach (string file in FileList)
  918. {
  919. if (file.Contains(".exe"))
  920. {
  921. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/" + file, SavePath);
  922. MessageBox.Show("新版本下载完成,请手动删除旧版本!\r\n最新版本:" + file, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  923. System.Environment.Exit(0);
  924. }
  925. }
  926. }
  927. }
  928. } while (false);
  929. //下拉控件初始值设定
  930. comboBox_WorkMode.SelectedIndex = 0;
  931. comboBox_GearSt.SelectedIndex = 0;
  932. comboBox_LightSwitch.SelectedIndex = 1;
  933. comboBox_OBC_SetGearST.SelectedIndex = 0;
  934. comboBox_OBC_LightSw.SelectedIndex = 1;
  935. comboBox_AssistTorque.SelectedIndex = 0;
  936. comboBox_AssistCadence.SelectedIndex = 0;
  937. //combobox事件定义
  938. this.comboBox_WorkMode.SelectedIndexChanged += new System.EventHandler(this.comboBox_WorkMode_SelectedIndexChanged);
  939. this.comboBox_GearSt.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  940. this.comboBox_LightSwitch.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  941. this.comboBox_OBC_SetGearST.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  942. this.comboBox_OBC_LightSw.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  943. //端口自动连接
  944. if ((PortNumSave != string.Empty) && (PortBaudrateSave != string.Empty)) //有数值时采用上次使用的值
  945. {
  946. try
  947. {
  948. PortConnect();
  949. }
  950. catch (System.Exception)
  951. {
  952. timer_500ms.Enabled = false;
  953. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  954. timer_500ms.Enabled = true;
  955. }
  956. }
  957. //不识别联动装置盒自动打开界面
  958. #if true
  959. groupBox1.Visible = true;
  960. groupBox3.Visible = true;
  961. tabControl2.Visible = true;
  962. label_StarInfo.Visible = false;
  963. #endif
  964. //创建线程,定时解析数据
  965. Thread th = new Thread(Task_SerialProcess);
  966. th.IsBackground = true;
  967. th.Start();
  968. }
  969. #region 结构体与字节流相互转换
  970. public static class MyConverter
  971. {
  972. /// <summary>
  973. /// 由结构体转换为byte数组
  974. /// </summary>
  975. public static byte[] StructureToByte<T>(T structure)
  976. {
  977. int size = Marshal.SizeOf(typeof(T));
  978. byte[] buffer = new byte[size];
  979. IntPtr bufferIntPtr = Marshal.AllocHGlobal(size);
  980. try
  981. {
  982. Marshal.StructureToPtr(structure, bufferIntPtr, true);
  983. Marshal.Copy(bufferIntPtr, buffer, 0, size);
  984. }
  985. finally
  986. {
  987. Marshal.FreeHGlobal(bufferIntPtr);
  988. }
  989. return buffer;
  990. }
  991. /// <summary>
  992. /// 由byte数组转换为结构体
  993. /// </summary>
  994. public static T ByteToStructure<T>(byte[] dataBuffer, ushort StarIndex)
  995. {
  996. object structure = null;
  997. int size = Marshal.SizeOf(typeof(T));
  998. IntPtr allocIntPtr = Marshal.AllocHGlobal(size);
  999. try
  1000. {
  1001. Marshal.Copy(dataBuffer, StarIndex, allocIntPtr, size);
  1002. structure = Marshal.PtrToStructure(allocIntPtr, typeof(T));
  1003. }
  1004. finally
  1005. {
  1006. Marshal.FreeHGlobal(allocIntPtr);
  1007. }
  1008. return (T)structure;
  1009. }
  1010. }
  1011. #endregion
  1012. #region 故障日志解析显示
  1013. private void ErrorLogDisplay(MC_ErrorLogSaveInfo_Struct_t Log1, MC_ErrorLogSaveInfo_Struct_t Log2)
  1014. {
  1015. string SaveData = "";
  1016. //Log1
  1017. if (Log1.Error_Index != 0xFFFF)
  1018. {
  1019. SaveData += "故障序号:" + Convert.ToString(Log1.Error_Index) + ", ";
  1020. SaveData += "备注1:" + Convert.ToString(Log1.NotesInfo1) + ", ";
  1021. SaveData += "备注2:" + Convert.ToString(Log1.NotesInfo2) + ", ";
  1022. SaveData += "备注3:" + Convert.ToString(Log1.NotesInfo3) + ", ";
  1023. SaveData += "故障码:" + "0x" + Convert.ToString(Log1.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  1024. SaveData += "运行时间:" + Convert.ToString(Log1.RunTime) + "min" + ", ";
  1025. SaveData += "车速:" + ((float)Log1.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  1026. SaveData += "电机转速:" + Convert.ToString(Log1.RunInfo.MotorSpeed) + "rpm" + ", ";
  1027. SaveData += "功率:" + Convert.ToString(Log1.RunInfo.Power * 2) + "w" + ", ";
  1028. SaveData += "电压:" + Convert.ToString(Log1.RunInfo.BusVoltage) + "mV" + ", ";
  1029. SaveData += "电流:" + Convert.ToString(Log1.RunInfo.BusCurrent) + "mA" + ", ";
  1030. SaveData += "踏频:" + Convert.ToString(Log1.RunInfo.Cadence) + "rpm" + ", ";
  1031. SaveData += "力矩:" + Convert.ToString(Log1.RunInfo.Torque) + "N.m" + ", ";
  1032. SaveData += "方向:" + ((Log1.RunInfo.CadenceDir == 0) ? "正" : ((Log1.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  1033. SaveData += "档位:" + "0x" + Convert.ToString(Log1.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  1034. SaveData += "灯开关:" + ((Log1.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  1035. SaveData += "电量:" + Convert.ToString(Log1.RunInfo.SOC) + "%" + ", ";
  1036. if ((Log1.RunInfo.RemainDistance == 0xEEEE) || (Log1.RunInfo.RemainDistance == 0xFFFF))
  1037. {
  1038. SaveData += "续航:" + "---km" + ", ";
  1039. }
  1040. else
  1041. {
  1042. SaveData += "续航:" + Convert.ToString(Log1.RunInfo.RemainDistance) + "km" + ", ";
  1043. }
  1044. SaveData += "力矩AD:" + Convert.ToString(Log1.RunInfo.Torque_AD) + ", ";
  1045. SaveData += "功耗:" + Convert.ToString(Log1.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  1046. SaveData += "PCB温度:" + Convert.ToString((int)(Log1.RunInfo.T_PCB - 40)) + "℃" + ", ";
  1047. SaveData += "绕组温度:" + Convert.ToString((int)(Log1.RunInfo.T_Coil - 40)) + "℃" + ", ";
  1048. SaveData += "MCU温度:" + Convert.ToString((int)(Log1.RunInfo.T_MCU - 40)) + "℃" + ", ";
  1049. SaveData += "单次里程:" + Convert.ToString((float)Log1.RunInfo.Ride_Km / 10f) + "km" + ", ";
  1050. SaveData += "单次时间:" + Convert.ToString(Log1.RunInfo.Ride_Time) + "s" + ", ";
  1051. SaveData += "q轴电流:" + Convert.ToString(Log1.IqCurrent) + ", ";
  1052. SaveData += "q轴电压:" + Convert.ToString(Log1.IqVoltage) + ", ";
  1053. SaveData += "d轴电流:" + Convert.ToString(Log1.IdCurrent) + ", ";
  1054. SaveData += "d轴电压:" + Convert.ToString(Log1.IdVoltage) + ", ";
  1055. SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
  1056. SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
  1057. SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
  1058. SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
  1059. SaveData += "\r\n\r\n";
  1060. richTextBox_Record.AppendText(SaveData);
  1061. SaveData = "";
  1062. }
  1063. //Log2
  1064. if (Log2.Error_Index != 0xFFFF)
  1065. {
  1066. SaveData += "故障序号:" + Convert.ToString(Log2.Error_Index) + ", ";
  1067. SaveData += "备注1:" + Convert.ToString(Log2.NotesInfo1) + ", ";
  1068. SaveData += "备注2:" + Convert.ToString(Log2.NotesInfo2) + ", ";
  1069. SaveData += "备注3:" + Convert.ToString(Log2.NotesInfo3) + ", ";
  1070. SaveData += "故障码:" + "0x" + Convert.ToString(Log2.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  1071. SaveData += "运行时间:" + Convert.ToString(Log2.RunTime) + "min" + ", ";
  1072. SaveData += "车速:" + ((float)Log2.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  1073. SaveData += "电机转速:" + Convert.ToString(Log2.RunInfo.MotorSpeed) + "rpm" + ", ";
  1074. SaveData += "功率:" + Convert.ToString(Log2.RunInfo.Power * 2) + "w" + ", ";
  1075. SaveData += "电压:" + Convert.ToString(Log2.RunInfo.BusVoltage) + "mV" + ", ";
  1076. SaveData += "电流:" + Convert.ToString(Log2.RunInfo.BusCurrent) + "mA" + ", ";
  1077. SaveData += "踏频:" + Convert.ToString(Log2.RunInfo.Cadence) + "rpm" + ", ";
  1078. SaveData += "力矩:" + Convert.ToString(Log2.RunInfo.Torque) + "N.m" + ", ";
  1079. SaveData += "方向:" + ((Log2.RunInfo.CadenceDir == 0) ? "正" : ((Log2.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  1080. SaveData += "档位:" + "0x" + Convert.ToString(Log2.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  1081. SaveData += "灯开关:" + ((Log2.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  1082. SaveData += "电量:" + Convert.ToString(Log2.RunInfo.SOC) + "%" + ", ";
  1083. if ((Log2.RunInfo.RemainDistance == 0xEEEE) || (Log2.RunInfo.RemainDistance == 0xFFFF))
  1084. {
  1085. SaveData += "续航:" + "---km" + ", ";
  1086. }
  1087. else
  1088. {
  1089. SaveData += "续航:" + Convert.ToString(Log2.RunInfo.RemainDistance) + "km" + ", ";
  1090. }
  1091. SaveData += "力矩AD:" + Convert.ToString(Log2.RunInfo.Torque_AD) + ", ";
  1092. SaveData += "功耗:" + Convert.ToString(Log2.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  1093. SaveData += "PCB温度:" + Convert.ToString((int)(Log2.RunInfo.T_PCB - 40)) + "DegreeC" + ", ";
  1094. SaveData += "绕组温度:" + Convert.ToString((int)(Log2.RunInfo.T_Coil - 40)) + "DegreeC" + ", ";
  1095. SaveData += "MCU温度:" + Convert.ToString((int)(Log2.RunInfo.T_MCU - 40)) + "DegreeC" + ", ";
  1096. SaveData += "单次里程:" + Convert.ToString((float)Log2.RunInfo.Ride_Km / 10f) + "km" + ", ";
  1097. SaveData += "单次时间:" + Convert.ToString(Log2.RunInfo.Ride_Time) + "s" + ", ";
  1098. SaveData += "q轴电流:" + Convert.ToString(Log2.IqCurrent) + ", ";
  1099. SaveData += "q轴电压:" + Convert.ToString(Log2.IqVoltage) + ", ";
  1100. SaveData += "d轴电流:" + Convert.ToString(Log2.IdCurrent) + ", ";
  1101. SaveData += "d轴电压:" + Convert.ToString(Log2.IdVoltage) + ", ";
  1102. SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
  1103. SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
  1104. SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
  1105. SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
  1106. SaveData += "\r\n\r\n";
  1107. richTextBox_Record.AppendText(SaveData);
  1108. SaveData = "";
  1109. }
  1110. }
  1111. #endregion
  1112. #region 串口数据解析线程
  1113. /// <summary>
  1114. /// 串口数据解析线程
  1115. /// </summary>
  1116. private void Task_SerialProcess()
  1117. {
  1118. //创建定时器,定时读取串口数据
  1119. System.Timers.Timer timer_ReadSerial = new System.Timers.Timer();
  1120. timer_ReadSerial.Enabled = true;
  1121. timer_ReadSerial.Interval = 20;
  1122. timer_ReadSerial.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_ReadSerial_Tick);
  1123. timer_ReadSerial.Start();
  1124. while (true)
  1125. {
  1126. Thread.Sleep(1);
  1127. };
  1128. }
  1129. /// <summary>
  1130. /// 串口解析定时器
  1131. /// </summary>
  1132. /// <param name="sender"></param>
  1133. /// <param name="e"></param>
  1134. private void timer_ReadSerial_Tick(object sender, EventArgs e)
  1135. {
  1136. //串口解析
  1137. Serial_process(mySerialProcess.buffer);
  1138. }
  1139. #endregion
  1140. #region 数据解析
  1141. public void Serial_process(List<byte> buffer)
  1142. {
  1143. byte DataNum = 0; //记录每条命令数据段的长度
  1144. ushort PackageID, Cmd;
  1145. byte[] Data = new byte[1024];
  1146. try
  1147. {
  1148. while (buffer.Count >= 13)//当buffer中的数据的个数大于等于4个时,即每一帧的数据长度所在位(第4位)出现时
  1149. {
  1150. if (buffer[0] == 0x55 && buffer[1] == 0xAA)//判断帧头
  1151. {
  1152. PackageID = (ushort)(buffer[2] * 256 + buffer[3]);
  1153. if ((PackageID == 0x0710) || (PackageID == 0x0715) || (PackageID == 0x07FF) || (PackageID == 0x0720) || (PackageID == 0x0713))
  1154. {
  1155. int CmdLen = buffer[5];
  1156. if (buffer.Count < CmdLen + 11) break;//如果接收到的数据没有达到一帧数据的指定长度, 则执行下次循环
  1157. while (CmdLen > 0) //读取命令段
  1158. {
  1159. Cmd = (ushort)(buffer[6] * 256 + buffer[7]);
  1160. DataNum = (byte)(buffer[7]);//命令字的第二个字节的表示数据位的长度
  1161. if (DataNum <= (CmdLen - 2))
  1162. {
  1163. for (int i = 0; i < DataNum; i++)
  1164. {
  1165. Data[i] = buffer[i + 8];
  1166. }
  1167. // 串口接收的数据 显示在子窗口
  1168. if (this.DebugWindowIsOpen && this.DebugDataDisplayEnable)
  1169. {
  1170. string strTemp = String.Empty;
  1171. strTemp += System.DateTimeOffset.Now.ToString("HH:mm:ss.fff") + " <-- ";
  1172. for (int i = 0; i < CmdLen + 11; i++)
  1173. {
  1174. strTemp += (buffer[i].ToString("X2") + " ");
  1175. }
  1176. strTemp += "\n";
  1177. DebugForm.debug1.richTextBox_DebugRev.Text += strTemp;
  1178. }
  1179. buffer.RemoveRange(0, CmdLen + 11);
  1180. DataCmdProcess(PackageID, Cmd, Data);//对于不同的命令段,做不同的处理
  1181. DataRevToString(Cmd, Data);//指令数据转为字符串
  1182. }
  1183. }
  1184. }
  1185. else
  1186. {
  1187. buffer.RemoveAt(0);//ID不对
  1188. }
  1189. }
  1190. else
  1191. {
  1192. buffer.RemoveAt(0);//帧头不对,删除帧头高字节
  1193. }
  1194. }
  1195. }
  1196. catch (Exception)
  1197. {
  1198. }
  1199. }
  1200. private void DataCmdProcess(ushort ID, ushort CmdTemp, byte[] Data)
  1201. {
  1202. int DataTemp;
  1203. ushort uData16;
  1204. unchecked
  1205. {
  1206. this.Invoke((EventHandler)(delegate { label_RecCount.Text = Convert.ToString(Convert.ToInt32(label_RecCount.Text) + 1); }));
  1207. }
  1208. #region 解析发送给CDL的指令
  1209. if (ID == 0x7FF)
  1210. {
  1211. switch (CmdTemp)
  1212. {
  1213. case 0x1100://
  1214. {
  1215. unchecked
  1216. {
  1217. this.Invoke((EventHandler)(delegate
  1218. {
  1219. //CDL连接成功
  1220. mySerialProcess.CDL_Online_Flag = true;
  1221. MessageBoxTimeOut.Show("连接成功!", "提示", 500);
  1222. groupBox1.Visible = true;
  1223. groupBox3.Visible = true;
  1224. tabControl2.Visible = true;
  1225. label_StarInfo.Visible = false;
  1226. }));
  1227. }
  1228. break;
  1229. }
  1230. default: break;
  1231. }
  1232. }
  1233. #endregion
  1234. #region 解析电机的命令
  1235. else if ((ID == 0x715) || (ID == 0x710))
  1236. {
  1237. switch (CmdTemp)
  1238. {
  1239. case 0x1020://电机运行信息
  1240. {
  1241. unchecked
  1242. {
  1243. this.Invoke((EventHandler)(delegate
  1244. {
  1245. MC_RunInfo_Refresh = true;
  1246. //车速
  1247. DataTemp = (int)(Data[1] * 256 + Data[0]);
  1248. textBox_RunInfo_BikeSpeed.Text = ((float)DataTemp / 10f).ToString("0.0") + " km/h";
  1249. //输出转速
  1250. DataTemp = (ushort)(Data[3] * 256 + Data[2]);
  1251. textBox_RunInfo_MotorSpeed.Text = Convert.ToString(DataTemp) + " rpm";
  1252. Class_MotorSpeed.String = textBox_RunInfo_MotorSpeed.Text;
  1253. Class_MotorSpeed.Data = DataTemp;
  1254. //电功率
  1255. DataTemp = (ushort)(Data[5] * 256 + Data[4]);
  1256. textBox_RunInfo_Power.Text = Convert.ToString(DataTemp) + " W";
  1257. //母线电压
  1258. DataTemp = (ushort)(Data[7] * 256 + Data[6]);
  1259. textBox_RunInfo_Vol.Text = Convert.ToString(DataTemp) + " mV";
  1260. //textBox_RunInfo_Vol.Text = (DataTemp / 1000f).ToString("0.0") + " V";
  1261. //母线电流
  1262. DataTemp = (short)(Data[9] * 256 + Data[8]);
  1263. textBox_RunInfo_Current.Text = Convert.ToString(DataTemp) + " mA";
  1264. //textBox_RunInfo_Current.Text = (DataTemp / 1000f).ToString("0.0") + " A";
  1265. Class_CurrentData.String = textBox_RunInfo_Current.Text;
  1266. Class_CurrentData.Data = DataTemp;
  1267. //踏频
  1268. DataTemp = (ushort)(Data[10]);
  1269. textBox_RunInfo_Cadence.Text = Convert.ToString(DataTemp) + " rpm";
  1270. Class_CadenceData.String = textBox_RunInfo_Cadence.Text;
  1271. Class_CadenceData.Data = DataTemp;
  1272. //踩踏力矩
  1273. DataTemp = (ushort)(Data[11]);
  1274. textBox_RunInfo_Torque.Text = Convert.ToString(DataTemp) + " N.m";
  1275. Class_TorqueData.String = textBox_RunInfo_Torque.Text;
  1276. Class_TorqueData.Data = DataTemp;
  1277. //踩踏方向
  1278. DataTemp = (ushort)(Data[12]);
  1279. if (DataTemp == 0)
  1280. {
  1281. textBox_RunInfo_Dir.Text = "正向";
  1282. }
  1283. else if (DataTemp == 1)
  1284. {
  1285. textBox_RunInfo_Dir.Text = "反向";
  1286. }
  1287. else if (DataTemp == 2)
  1288. {
  1289. textBox_RunInfo_Dir.Text = "停止";
  1290. }
  1291. //助力档位
  1292. DataTemp = (ushort)(Data[13]);
  1293. if (DataTemp == 0x33)
  1294. {
  1295. textBox_RunInfo_GearSt.Text = "SMART";
  1296. //comboBox_GearSt.SelectedIndex = 5;
  1297. //comboBox_OBC_SetGearST.SelectedIndex = 5;
  1298. }
  1299. else if (DataTemp == 0x22)
  1300. {
  1301. textBox_RunInfo_GearSt.Text = "WALK";
  1302. //comboBox_GearSt.SelectedIndex = 6;
  1303. //comboBox_OBC_SetGearST.SelectedIndex = 6;
  1304. }
  1305. else
  1306. {
  1307. string[] Gears = new string[5] { "OFF", "ECO", "NORM", "SPORT", "TURBO" };
  1308. textBox_RunInfo_GearSt.Text = Gears[DataTemp];
  1309. //comboBox_GearSt.SelectedIndex = DataTemp;
  1310. //comboBox_OBC_SetGearST.SelectedIndex = DataTemp;
  1311. }
  1312. //大灯状态
  1313. DataTemp = (ushort)(Data[14]);
  1314. if (DataTemp == 0xF0)
  1315. {
  1316. textBox_RunInfo_LightSwitch.Text = "OFF";
  1317. //comboBox_LightSwitch.SelectedIndex = 1;
  1318. //comboBox_OBC_LightSw.SelectedIndex = 1;
  1319. }
  1320. else if (DataTemp == 0xF1)
  1321. {
  1322. textBox_RunInfo_LightSwitch.Text = "ON";
  1323. //comboBox_LightSwitch.SelectedIndex = 0;
  1324. //comboBox_OBC_LightSw.SelectedIndex = 0;
  1325. }
  1326. //剩余电量
  1327. DataTemp = (ushort)(Data[15]);
  1328. textBox_RunInfo_SOC.Text = Convert.ToString(DataTemp) + " %";
  1329. //剩余续航里程
  1330. DataTemp = (ushort)(Data[17] * 256 + Data[16]);
  1331. if ((DataTemp == 0xEEEE) || (DataTemp == 0xFFFF))
  1332. {
  1333. textBox_RunInfo_Range.Text = "---";
  1334. }
  1335. else
  1336. {
  1337. textBox_RunInfo_Range.Text = Convert.ToString(DataTemp) + " km";
  1338. }
  1339. //预留(显示力矩Reg),空2bytes
  1340. DataTemp = (ushort)(Data[19] * 256 + Data[18]);
  1341. textBox_TorqueReg.Text = Convert.ToString(DataTemp);
  1342. //平均功耗
  1343. DataTemp = (ushort)(Data[20]);
  1344. textBox_RunInfo_AvgPower.Text = Convert.ToString(DataTemp * 10) + " mAh/km";
  1345. //PCB温度
  1346. DataTemp = (ushort)(Data[21]);
  1347. textBox_RunInfo_T_PCB.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1348. Class_MotorTemp.String = textBox_RunInfo_T_PCB.Text;
  1349. Class_MotorTemp.Data = DataTemp - 40;
  1350. //绕组温度
  1351. DataTemp = (ushort)(Data[22]);
  1352. textBox_RunInfo_T_Coil.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1353. //MCU温度
  1354. DataTemp = (ushort)(Data[23]);
  1355. textBox_RunInfo_T_MCU.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1356. //单次里程
  1357. DataTemp = (ushort)(Data[25] * 256 + Data[24]);
  1358. textBox_RunInfo_Trip.Text = ((float)DataTemp / 10f).ToString("0.0") + " km";
  1359. //单次时间
  1360. DataTemp = (ushort)(Data[27] * 256 + Data[26]);
  1361. textBox_RunInfo_Trip_Time.Text = Convert.ToString(DataTemp) + " s";
  1362. //数据保存
  1363. RunInfoAutoSave();
  1364. }));
  1365. }
  1366. break;
  1367. }
  1368. case 0x1104://故障码
  1369. {
  1370. unchecked
  1371. {
  1372. this.Invoke((EventHandler)(delegate
  1373. {
  1374. MC_ErrorCode_Refresh = true;
  1375. textBox_ErrorCode.Text =
  1376. Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() +
  1377. Convert.ToString(Data[2], 16).PadLeft(2, '0').ToUpper() +
  1378. Convert.ToString(Data[1], 16).PadLeft(2, '0').ToUpper() +
  1379. Convert.ToString(Data[0], 16).PadLeft(2, '0').ToUpper() +
  1380. "H";
  1381. }));
  1382. }
  1383. break;
  1384. }
  1385. case 0xA903://反馈指令
  1386. {
  1387. unchecked
  1388. {
  1389. this.Invoke((EventHandler)(delegate
  1390. {
  1391. if (ACK_DisFlag == true)
  1392. {
  1393. timer_500ms.Enabled = false;
  1394. MessageBoxTimeOut.Show("OK", "反馈指令", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  1395. timer_500ms.Enabled = true;
  1396. //关机反馈
  1397. PowerOffAckStatus = true;
  1398. }
  1399. //应答标志置位
  1400. WriteACK = true;
  1401. WriteCnt++;
  1402. }));
  1403. }
  1404. break;
  1405. }
  1406. case 0xB226://马达参数
  1407. {
  1408. unchecked
  1409. {
  1410. this.Invoke((EventHandler)(delegate
  1411. {
  1412. richTextBox_MotorParam.Clear();
  1413. for (int i = 0; i < myParams.MotorParam.Count; i++)
  1414. {
  1415. if (i == 6)
  1416. richTextBox_MotorParam.AppendText(myParams.MotorParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1417. else
  1418. richTextBox_MotorParam.AppendText(myParams.MotorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1419. }
  1420. richTextBox_MotorParam.Text = richTextBox_MotorParam.Text.Substring(0, richTextBox_MotorParam.Text.Length - 2);
  1421. }));
  1422. }
  1423. break;
  1424. }
  1425. case 0xB31A://整车信息
  1426. {
  1427. unchecked
  1428. {
  1429. this.Invoke((EventHandler)(delegate
  1430. {
  1431. richTextBox_BikeParam.Clear();
  1432. for (int i = 0; i < myParams.BikeParam.Count; i++)
  1433. {
  1434. if (i == 9)
  1435. richTextBox_BikeParam.AppendText(myParams.BikeParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1436. else
  1437. richTextBox_BikeParam.AppendText(myParams.BikeParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1438. //更新前后灯参数
  1439. if (i == 8)
  1440. {
  1441. comboBox_TailLightMode.SelectedIndex = ((Data[2 * i + 1] >> 4) & 0x0F) - 1;
  1442. comboBox_TailLightVol.SelectedIndex = ((Data[2 * i + 1] & 0x0F) == 6) ? 0 : 1;
  1443. comboBox_FrontLightVol.SelectedIndex = ((Data[2 * i] & 0x0F) == 6) ? 0 : 1;
  1444. }
  1445. //更新开关机参数
  1446. else if (i == 11)
  1447. {
  1448. textBox_PowerOnDelay.Text = Convert.ToString((Data[2 * i + 1] >> 4) & 0x0F);
  1449. textBox_PowerOffDelay.Text = Convert.ToString(Data[2 * i + 1] & 0x0F);
  1450. textBox_AutoPowerOff.Text = Convert.ToString(Data[2 * i]);
  1451. }
  1452. }
  1453. richTextBox_BikeParam.Text = richTextBox_BikeParam.Text.Substring(0, richTextBox_BikeParam.Text.Length - 2);
  1454. }));
  1455. }
  1456. break;
  1457. }
  1458. case 0xB420://控制器参数
  1459. {
  1460. unchecked
  1461. {
  1462. this.Invoke((EventHandler)(delegate
  1463. {
  1464. richTextBox_ControlParam.Clear();
  1465. for (int i = 0; i < myParams.ControlParam.Count; i++)
  1466. {
  1467. richTextBox_ControlParam.AppendText(myParams.ControlParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1468. //转把定速巡航
  1469. if (i == 13)
  1470. {
  1471. comboBox_Bike_CCS.SelectedIndex = ((Data[2 * i]) == 0xAA) ? 1 : 2;
  1472. }
  1473. }
  1474. richTextBox_ControlParam.Text = richTextBox_ControlParam.Text.Substring(0, richTextBox_ControlParam.Text.Length - 2);
  1475. }));
  1476. }
  1477. break;
  1478. }
  1479. case 0xB528://传感器参数
  1480. {
  1481. unchecked
  1482. {
  1483. this.Invoke((EventHandler)(delegate
  1484. {
  1485. richTextBox_SensorParam.Clear();
  1486. for (int i = 0; i < myParams.SensorParam.Count; i++)
  1487. {
  1488. richTextBox_SensorParam.AppendText(myParams.SensorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1489. }
  1490. richTextBox_SensorParam.Text = richTextBox_SensorParam.Text.Substring(0, richTextBox_SensorParam.Text.Length - 2);
  1491. //更新生产模式页面传感器零点和标定值
  1492. textBox_FacModeSensorADC0.Text = (Data[1] * 256 + Data[0]).ToString();
  1493. textBox_FacModeSensorADC1.Text = (Data[15] * 256 + Data[14]).ToString();
  1494. textBox_FacModeSensorADC2.Text = (Data[19] * 256 + Data[18]).ToString();
  1495. textBox_FacModeSensorADC3.Text = (Data[23] * 256 + Data[22]).ToString();
  1496. textBox_FacModeSensorADC4.Text = (Data[27] * 256 + Data[26]).ToString();
  1497. }));
  1498. }
  1499. break;
  1500. }
  1501. case 0xB64C://助力参数
  1502. {
  1503. unchecked
  1504. {
  1505. this.Invoke((EventHandler)(delegate
  1506. {
  1507. richTextBox_AssistParam.Clear();
  1508. int index_1 = myParams.AssistParam.IndexOf("转矩曲线.a");
  1509. int index_2 = myParams.AssistParam.IndexOf("踏频曲线.d");
  1510. int index_3 = myParams.AssistParam.IndexOf("踏频助力加速限制");
  1511. int index_4 = myParams.AssistParam.IndexOf("踏频助力电流步进");
  1512. for (int i = 0; i < myParams.AssistParam.Count; i++)
  1513. {
  1514. if (i < index_1) //数据占用2bytes
  1515. {
  1516. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1517. }
  1518. else if (i <= index_2) //数据占用4bytes
  1519. {
  1520. 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])) + ", ");
  1521. }
  1522. else if (i < index_3) //数据占用2bytes,无符号
  1523. {
  1524. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1525. }
  1526. else if (i <= index_4) //数据占用2bytes,有符号
  1527. {
  1528. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1529. }
  1530. else //数据占用2bytes,无符号
  1531. {
  1532. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1533. }
  1534. }
  1535. richTextBox_AssistParam.Text = richTextBox_AssistParam.Text.Substring(0, richTextBox_AssistParam.Text.Length - 2);
  1536. }));
  1537. }
  1538. break;
  1539. }
  1540. case 0xB74C://历史记录
  1541. {
  1542. unchecked
  1543. {
  1544. this.Invoke((EventHandler)(delegate
  1545. {
  1546. richTextBox_Record.Clear();
  1547. for (int i = 0; i < myParams.Record.Count; i++)
  1548. {
  1549. richTextBox_Record.AppendText(myParams.Record[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  1550. }
  1551. richTextBox_Record.Text = richTextBox_Record.Text.Substring(0, richTextBox_Record.Text.Length - 2);
  1552. }));
  1553. }
  1554. break;
  1555. }
  1556. case 0xB83A://调试参数
  1557. {
  1558. unchecked
  1559. {
  1560. this.Invoke((EventHandler)(delegate
  1561. {
  1562. richTextBox_DebugParam.Clear();
  1563. for (int i = 0; i < myParams.DebugParam.Count; i++)
  1564. {
  1565. richTextBox_DebugParam.AppendText(myParams.DebugParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1566. }
  1567. richTextBox_DebugParam.Text = richTextBox_DebugParam.Text.Substring(0, richTextBox_DebugParam.Text.Length - 2);
  1568. }));
  1569. }
  1570. break;
  1571. }
  1572. case 0xB904://存储标志
  1573. {
  1574. unchecked
  1575. {
  1576. this.Invoke((EventHandler)(delegate
  1577. {
  1578. ushort Flag = 0;
  1579. Flag = (ushort)(Data[1] * 256 + Data[0]);//EEPROM存储标志
  1580. if (Flag == 0)
  1581. {
  1582. radioButton_EE_SaveNo.Checked = true;
  1583. radioButton_EE_SaveYes.Checked = false;
  1584. }
  1585. else
  1586. {
  1587. radioButton_EE_SaveNo.Checked = false;
  1588. radioButton_EE_SaveYes.Checked = true;
  1589. }
  1590. Flag = (ushort)(Data[3] * 256 + Data[2]);//SIP偏移校准存储标志
  1591. if (Flag == 0)
  1592. {
  1593. radioButton_SIP_SaveNo.Checked = true;
  1594. radioButton_SIP_SaveYes.Checked = false;
  1595. }
  1596. else
  1597. {
  1598. radioButton_SIP_SaveNo.Checked = false;
  1599. radioButton_SIP_SaveYes.Checked = true;
  1600. }
  1601. }));
  1602. }
  1603. break;
  1604. }
  1605. case 0x1240://电机版本信息
  1606. {
  1607. unchecked
  1608. {
  1609. this.Invoke((EventHandler)(delegate
  1610. {
  1611. //电机型号
  1612. textBox_Model.Text = "";
  1613. textBox_OBC_ReadModel.Text = "";
  1614. textBox_FacModeName.Text = "";
  1615. for (ushort i = 0; i < 16; i++)
  1616. {
  1617. if (Data[i] == 0x2E)
  1618. {
  1619. break;
  1620. }
  1621. textBox_Model.Text += ((char)Data[i]).ToString();
  1622. textBox_OBC_ReadModel.Text += ((char)Data[i]).ToString();
  1623. textBox_FacModeName.Text += ((char)Data[i]).ToString();
  1624. }
  1625. Class_Motor_Ver.Mode = textBox_Model.Text;
  1626. //电机SN
  1627. textBox_SN.Text = "";
  1628. textBox_OBC_ReadSN.Text = "";
  1629. textBox_FacModeNum.Text = "";
  1630. for (ushort i = 0; i < 16; i++)
  1631. {
  1632. if (Data[16 + i] == 0x2E)
  1633. {
  1634. break;
  1635. }
  1636. textBox_SN.Text += ((char)Data[16 + i]).ToString();
  1637. textBox_OBC_ReadSN.Text += ((char)Data[16 + i]).ToString();
  1638. textBox_FacModeNum.Text += ((char)Data[16 + i]).ToString();
  1639. }
  1640. Class_Motor_Ver.SN = textBox_SN.Text;
  1641. //电机HW
  1642. textBox_HW.Text = "";
  1643. textBox_OBC_ReadHW.Text = "";
  1644. textBox_FacModeHW.Text = "";
  1645. for (ushort i = 0; i < 8; i++)//前8位:硬件板号
  1646. {
  1647. if (Data[32 + i] == 0x2E)
  1648. {
  1649. break;
  1650. }
  1651. else if (Data[32 + i] == 'r')
  1652. {
  1653. Data[32 + i] = (byte)'.';
  1654. break;
  1655. }
  1656. string strTemp = "";
  1657. strTemp = ((char)Data[32 + i]).ToString();
  1658. textBox_HW.Text += strTemp;
  1659. textBox_OBC_ReadHW.Text += strTemp;
  1660. textBox_FacModeHW.Text += strTemp;
  1661. }
  1662. for (ushort i = 0; i < 4; i++)//9-12位:单片机型号
  1663. {
  1664. if (Data[40 + i] == 0x2E)
  1665. {
  1666. break;
  1667. }
  1668. else if (Data[40 + i] == 'r')
  1669. {
  1670. Data[40 + i] = (byte)'.';
  1671. break;
  1672. }
  1673. string strTemp = "";
  1674. strTemp = ((char)Data[40 + i]).ToString();
  1675. textBox_HW.Text += strTemp;
  1676. textBox_OBC_ReadHW.Text += strTemp;
  1677. textBox_FacModeHW.Text += strTemp;
  1678. }
  1679. for (ushort i = 0; i < 4; i++)//13-16位:单片机ID
  1680. {
  1681. string strTemp = "";
  1682. strTemp = Convert.ToString(Data[44 + i], 16).PadLeft(2, '0').ToUpper();
  1683. textBox_HW.Text += strTemp;
  1684. textBox_OBC_ReadHW.Text += strTemp;
  1685. textBox_FacModeHW.Text += strTemp;
  1686. }
  1687. Class_Motor_Ver.HW = textBox_HW.Text;
  1688. //电机FW
  1689. textBox_FW.Text = "";
  1690. textBox_OBC_ReadFW.Text = "";
  1691. textBox_FacModeFW.Text = "";
  1692. for (ushort i = 0; i < 16; i++)
  1693. {
  1694. if ((Data[48 + i] == 0x2E) || (Data[48 + i] == 0x00) || (Data[48 + i] == (char)' '))
  1695. {
  1696. break;
  1697. }
  1698. if (Data[48 + i] == 'r')
  1699. {
  1700. Data[48 + i] = (byte)'.';
  1701. }
  1702. textBox_FW.Text += ((char)Data[48 + i]).ToString();
  1703. textBox_OBC_ReadFW.Text += ((char)Data[48 + i]).ToString();
  1704. textBox_FacModeFW.Text += ((char)Data[48 + i]).ToString();
  1705. }
  1706. Class_Motor_Ver.FW = textBox_FW.Text;
  1707. }));
  1708. }
  1709. break;
  1710. }
  1711. case 0xA610://自定义1
  1712. {
  1713. unchecked
  1714. {
  1715. this.Invoke((EventHandler)(delegate
  1716. {
  1717. textBox_User1.Text = "";
  1718. for (ushort i = 0; i < 16; i++)
  1719. {
  1720. if (Data[i] == 0x2E)
  1721. {
  1722. break;
  1723. }
  1724. textBox_User1.Text += ((char)Data[i]).ToString();
  1725. }
  1726. }));
  1727. }
  1728. break;
  1729. }
  1730. case 0xA710://自定义2
  1731. {
  1732. unchecked
  1733. {
  1734. this.Invoke((EventHandler)(delegate
  1735. {
  1736. textBox_User2.Text = "";
  1737. for (ushort i = 0; i < 16; i++)
  1738. {
  1739. if (Data[i] == 0x2E)
  1740. {
  1741. break;
  1742. }
  1743. textBox_User2.Text += ((char)Data[i]).ToString();
  1744. }
  1745. }));
  1746. }
  1747. break;
  1748. }
  1749. case 0xA810://自定义1
  1750. {
  1751. unchecked
  1752. {
  1753. this.Invoke((EventHandler)(delegate
  1754. {
  1755. textBox_User3.Text = "";
  1756. for (ushort i = 0; i < 16; i++)
  1757. {
  1758. if (Data[i] == 0x2E)
  1759. {
  1760. break;
  1761. }
  1762. textBox_User3.Text += ((char)Data[i]).ToString();
  1763. }
  1764. }));
  1765. }
  1766. break;
  1767. }
  1768. case 0xA520://生产信息
  1769. {
  1770. unchecked
  1771. {
  1772. this.Invoke((EventHandler)(delegate
  1773. {
  1774. //生产商
  1775. textBox_MAC.Text = "";
  1776. for (ushort i = 0; i < 8; i++)
  1777. {
  1778. if (Data[i] == 0x2E)
  1779. {
  1780. break;
  1781. }
  1782. textBox_MAC.Text += ((char)Data[i]).ToString();
  1783. }
  1784. //生产地
  1785. textBox_MACAdd.Text = "";
  1786. for (ushort i = 0; i < 8; i++)
  1787. {
  1788. if (Data[8 + i] == 0x2E)
  1789. {
  1790. break;
  1791. }
  1792. textBox_MACAdd.Text += ((char)Data[8 + i]).ToString();
  1793. }
  1794. //生产日期
  1795. textBox_MACDate.Text = "";
  1796. for (ushort i = 0; i < 8; i++)
  1797. {
  1798. if (Data[16 + i] == 0x2E)
  1799. {
  1800. break;
  1801. }
  1802. textBox_MACDate.Text += ((char)Data[16 + i]).ToString();
  1803. }
  1804. //品牌信息
  1805. textBox_PP.Text = "";
  1806. for (ushort i = 0; i < 8; i++)
  1807. {
  1808. if (Data[24 + i] == 0x2E)
  1809. {
  1810. break;
  1811. }
  1812. textBox_PP.Text += ((char)Data[24 + i]).ToString();
  1813. }
  1814. }));
  1815. }
  1816. break;
  1817. }
  1818. case 0xA408://密钥
  1819. {
  1820. unchecked
  1821. {
  1822. this.Invoke((EventHandler)(delegate
  1823. {
  1824. textBox_Key.Text = "";
  1825. for (ushort i = 0; i < 8; i++)
  1826. {
  1827. textBox_Key.Text += ((char)Data[i]).ToString();
  1828. }
  1829. }));
  1830. }
  1831. break;
  1832. }
  1833. case 0xAB09://存储器数据
  1834. case 0xAB0A:
  1835. case 0xAB0B:
  1836. case 0xAB0C:
  1837. {
  1838. unchecked
  1839. {
  1840. this.Invoke((EventHandler)(delegate
  1841. {
  1842. long ByteNum = 0;
  1843. ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
  1844. if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
  1845. {
  1846. for (int i = 0; i < ByteNum; i++)
  1847. {
  1848. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  1849. }
  1850. }
  1851. else //根据设置自动转换10进制显示
  1852. {
  1853. if (checkBox_ReadRanFlash_ChangeFormat.Checked == true) //10进制显示
  1854. {
  1855. switch (ByteNum)
  1856. {
  1857. case 1:
  1858. {
  1859. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8]) + ", ");
  1860. break;
  1861. }
  1862. case 2:
  1863. {
  1864. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8)) + ", ");
  1865. break;
  1866. }
  1867. case 3:
  1868. {
  1869. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16)) + ", ");
  1870. break;
  1871. }
  1872. case 4:
  1873. {
  1874. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24)) + ", ");
  1875. break;
  1876. }
  1877. default:
  1878. {
  1879. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  1880. break;
  1881. }
  1882. }
  1883. }
  1884. else //16进制显示
  1885. {
  1886. switch (ByteNum)
  1887. {
  1888. case 1:
  1889. {
  1890. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8], 16).PadLeft(2, '0').ToUpper() + ", ");
  1891. break;
  1892. }
  1893. case 2:
  1894. {
  1895. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8), 16).PadLeft(4, '0').ToUpper() + ", ");
  1896. break;
  1897. }
  1898. case 3:
  1899. {
  1900. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16), 16).PadLeft(6, '0').ToUpper() + ", ");
  1901. break;
  1902. }
  1903. case 4:
  1904. {
  1905. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24), 16).PadLeft(8, '0').ToUpper() + ", ");
  1906. break;
  1907. }
  1908. default:
  1909. {
  1910. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  1911. break;
  1912. }
  1913. }
  1914. }
  1915. }
  1916. }));
  1917. }
  1918. break;
  1919. }
  1920. case 0xAB88://故障日志
  1921. {
  1922. unchecked
  1923. {
  1924. this.Invoke((EventHandler)(delegate
  1925. {
  1926. //电机存储的故障日志,一包128字节包含2条故障日志
  1927. var ErrorLogSaveInfo1 = new MC_ErrorLogSaveInfo_Struct_t();
  1928. var ErrorLogSaveInfo2 = new MC_ErrorLogSaveInfo_Struct_t();
  1929. ErrorLogSaveInfo1 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 8);
  1930. ErrorLogSaveInfo2 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 72);
  1931. //数据显示
  1932. ErrorLogDisplay(ErrorLogSaveInfo1, ErrorLogSaveInfo2);
  1933. }));
  1934. }
  1935. break;
  1936. }
  1937. case 0x1401://在线检测结果
  1938. {
  1939. unchecked
  1940. {
  1941. this.Invoke((EventHandler)(delegate
  1942. {
  1943. textBox_Online.Text = Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() + "H";
  1944. }));
  1945. }
  1946. break;
  1947. }
  1948. case 0x1510://骑行历史信息
  1949. {
  1950. unchecked
  1951. {
  1952. this.Invoke((EventHandler)(delegate
  1953. {
  1954. long DataTemp32;
  1955. //ODO里程
  1956. DataTemp32 = (long)((Data[3] << 24) + (Data[2] << 16) + (Data[1] << 8) + Data[0]);
  1957. textBox_OBC_ODO_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  1958. textBox_ODO_KM.Text = DataTemp32.ToString();
  1959. //ODO时间
  1960. DataTemp32 = (long)((Data[7] << 24) + (Data[6] << 16) + (Data[5] << 8) + Data[4]);
  1961. if (DataTemp32 >= 60 * 100000)
  1962. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  1963. else
  1964. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  1965. textBox_ODO_TIME.Text = DataTemp32.ToString();
  1966. //TRIP里程
  1967. DataTemp32 = (long)((Data[11] << 24) + (Data[10] << 16) + (Data[9] << 8) + Data[8]);
  1968. textBox_OBC_TRIP_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  1969. textBox_TRIP_KM.Text = DataTemp32.ToString();
  1970. //TRIP时间
  1971. DataTemp32 = (long)((Data[15] << 24) + (Data[14] << 16) + (Data[13] << 8) + Data[12]);
  1972. if (DataTemp32 >= 60 * 100000)
  1973. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  1974. else
  1975. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  1976. textBox_TRIP_TIME.Text = DataTemp32.ToString();
  1977. }));
  1978. }
  1979. break;
  1980. }
  1981. case 0x1720://客户信息
  1982. {
  1983. unchecked
  1984. {
  1985. this.Invoke((EventHandler)(delegate
  1986. {
  1987. //软件标识
  1988. textBox_SP.Text = "";
  1989. textBox_OBC_ReadSP.Text = "";
  1990. textBox_FacModeSP.Text = "";
  1991. for (ushort i = 0; i < 23; i++)
  1992. {
  1993. if (Data[i] == 'r')
  1994. {
  1995. Data[i] = (byte)'.';
  1996. }
  1997. textBox_SP.Text += ((char)Data[i]).ToString();
  1998. textBox_OBC_ReadSP.Text += ((char)Data[i]).ToString();
  1999. textBox_FacModeSP.Text += ((char)Data[i]).ToString();
  2000. }
  2001. //Git提交版本信息
  2002. textBox_FacModeGit.Text = "";
  2003. for (ushort i = 0; i < 9; i++)
  2004. {
  2005. textBox_SP.Text += ((char)Data[23 + i]).ToString();
  2006. textBox_FacModeGit.Text += ((char)Data[23 + i]).ToString();
  2007. }
  2008. Class_Motor_Ver.Special = textBox_SP.Text;
  2009. }));
  2010. }
  2011. break;
  2012. }
  2013. case 0xBA20: //调试信息
  2014. {
  2015. unchecked
  2016. {
  2017. this.Invoke((EventHandler)(delegate
  2018. {
  2019. MC_DebugInfo_Refresh = true;
  2020. //系统状态机
  2021. DataTemp = (short)(Data[0]);
  2022. textBox_DebugInfo_SysFun.Text = Convert.ToString(DataTemp);
  2023. //二层状态机
  2024. DataTemp = (short)(Data[1]);
  2025. textBox_DebugInfo_SecondFun.Text = Convert.ToString(DataTemp);
  2026. //电机状态机
  2027. DataTemp = (short)(Data[2]);
  2028. textBox_DebugInfo_MotorFun.Text = Convert.ToString(DataTemp);
  2029. //助力状态机
  2030. DataTemp = (short)(Data[3]);
  2031. textBox_DebugInfo_AssistFun.Text = Convert.ToString(DataTemp);
  2032. //IdRef
  2033. DataTemp = (short)(Data[5] * 256 + Data[4]);
  2034. textBox_DebugInfo_IdRef.Text = Convert.ToString(DataTemp);
  2035. //IqRef
  2036. DataTemp = (short)(Data[7] * 256 + Data[6]);
  2037. textBox_DebugInfo_IqRef.Text = Convert.ToString(DataTemp);
  2038. //UdRef
  2039. DataTemp = (short)(Data[9] * 256 + Data[8]);
  2040. textBox_DebugInfo_UdRef.Text = Convert.ToString(DataTemp);
  2041. //UqRef
  2042. DataTemp = (short)(Data[11] * 256 + Data[10]);
  2043. textBox_DebugInfo_UqRef.Text = Convert.ToString(DataTemp);
  2044. //瞬时力矩
  2045. DataTemp = (short)(Data[13] * 256 + Data[12]);
  2046. textBox_DebugInfo_TorquePu.Text = Convert.ToString(DataTemp);
  2047. //时间滤波力矩
  2048. DataTemp = (short)(Data[15] * 256 + Data[14]);
  2049. textBox_DebugInfo_TorqueFil.Text = Convert.ToString(DataTemp);
  2050. //踏频滤波力矩
  2051. DataTemp = (short)(Data[17] * 256 + Data[16]);
  2052. textBox_DebugInfo_TorqueCadence.Text = Convert.ToString(DataTemp);
  2053. //IdFdb
  2054. DataTemp = (short)(Data[19] * 256 + Data[18]);
  2055. textBox_DebugInfo_IdFdb.Text = Convert.ToString(DataTemp);
  2056. //IqFdb
  2057. DataTemp = (short)(Data[21] * 256 + Data[20]);
  2058. textBox_DebugInfo_IqFdb.Text = Convert.ToString(DataTemp);
  2059. //助力输出
  2060. DataTemp = (short)(Data[23] * 256 + Data[22]);
  2061. textBox_DebugInfo_AssistOut.Text = Convert.ToString(DataTemp);
  2062. //转把百分比
  2063. DataTemp = (short)(Data[25] * 256 + Data[24]);
  2064. textBox_DebugInfo_ThrottlePer.Text = Convert.ToString(DataTemp);
  2065. //数据保存
  2066. RunInfoAutoSave();
  2067. }));
  2068. }
  2069. break;
  2070. }
  2071. case 0xBB20: //产品标签信息
  2072. {
  2073. unchecked
  2074. {
  2075. this.Invoke((EventHandler)(delegate
  2076. {
  2077. //产品标签
  2078. textBox_TagInfo.Text = "";
  2079. for (ushort i = 0; i < 32; i++)
  2080. {
  2081. textBox_TagInfo.Text += ((char)Data[i]).ToString();
  2082. }
  2083. }));
  2084. }
  2085. break;
  2086. }
  2087. case 0xBC20: //内阻校正信息
  2088. {
  2089. unchecked
  2090. {
  2091. this.Invoke((EventHandler)(delegate
  2092. {
  2093. //内阻1
  2094. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  2095. textBox_MOS_R1.Text = Convert.ToString(uData16);
  2096. //内阻2
  2097. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  2098. textBox_MOS_R2.Text = Convert.ToString(uData16);
  2099. //内阻3
  2100. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  2101. textBox_MOS_R3.Text = Convert.ToString(uData16);
  2102. //K1
  2103. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  2104. textBox_MOS_K1.Text = Convert.ToString(uData16);
  2105. //K2
  2106. uData16 = (ushort)(Data[9] * 256 + Data[8]);
  2107. textBox_MOS_K2.Text = Convert.ToString(uData16);
  2108. //K3
  2109. uData16 = (ushort)(Data[11] * 256 + Data[10]);
  2110. textBox_MOS_K3.Text = Convert.ToString(uData16);
  2111. //K4
  2112. uData16 = (ushort)(Data[13] * 256 + Data[12]);
  2113. textBox_MOS_K4.Text = Convert.ToString(uData16);
  2114. //K5
  2115. uData16 = (ushort)(Data[15] * 256 + Data[14]);
  2116. textBox_MOS_K5.Text = Convert.ToString(uData16);
  2117. }));
  2118. }
  2119. break;
  2120. }
  2121. case 0xBD20: //整车信息2
  2122. {
  2123. unchecked
  2124. {
  2125. this.Invoke((EventHandler)(delegate
  2126. {
  2127. richTextBox_BikeParam2.Clear();
  2128. for (int i = 0; i < myParams.BikeParam2.Count; i++)
  2129. {
  2130. richTextBox_BikeParam2.AppendText(myParams.BikeParam2[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  2131. }
  2132. richTextBox_BikeParam2.Text = richTextBox_BikeParam2.Text.Substring(0, richTextBox_BikeParam2.Text.Length - 2);
  2133. }));
  2134. }
  2135. break;
  2136. }
  2137. case 0xBE20: //用户骑行参数
  2138. {
  2139. unchecked
  2140. {
  2141. this.Invoke((EventHandler)(delegate
  2142. {
  2143. richTextBox_UsrRidesParam.Clear();
  2144. for (int i = 0; i < myParams.UsrRideParam.Count; i++)
  2145. {
  2146. richTextBox_UsrRidesParam.AppendText(myParams.UsrRideParam[i] + "=" + Convert.ToString(Data[i]) + ", ");
  2147. }
  2148. richTextBox_UsrRidesParam.Text = richTextBox_UsrRidesParam.Text.Substring(0, richTextBox_UsrRidesParam.Text.Length - 2);
  2149. }));
  2150. }
  2151. break;
  2152. }
  2153. case 0xBF58:
  2154. {
  2155. unchecked
  2156. {
  2157. this.Invoke((EventHandler)(delegate
  2158. {
  2159. string[] str1 = new string[42];
  2160. double[] error1 = new double[42];
  2161. //更新校准数据
  2162. for (int i = 0; i < 42; i++)
  2163. {
  2164. double data1 = (Data[4 + i * 2] + (Data[4 + i * 2 + 1] << 8)) / 32767.0 * 360;
  2165. error1[i] = data1 - (60 * (i % 6) + 60);
  2166. if (error1[i] < -180)
  2167. {
  2168. error1[i] = error1[i] + 360;
  2169. }
  2170. str1[i] = data1.ToString("F2");
  2171. AngledataRecord[i] = str1[i];
  2172. }
  2173. for (int i = 0; i < 7; i++)
  2174. for (int j = 0; j < 6; j++)
  2175. {
  2176. dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = str1[6 * i + j];
  2177. }
  2178. //计算偏差最小值、最大值和平均值
  2179. //Array.ConvertAll(error1, Math.Abs);
  2180. textBox_AngleDiffMin.Text = error1.Min().ToString("F2");
  2181. textBox_AngleDiffMax.Text = error1.Max().ToString("F2");
  2182. textBox_AngleDiffAvg.Text = error1.Average().ToString("F2");
  2183. //计算零点偏差
  2184. double tmp1 = ((Int16)(Data[0] + (Data[1] << 8))) / 32767.0 * 360;
  2185. textBox_AngleZeroInit.Text = tmp1.ToString("F2");
  2186. double tmp2 = ((Int16)(Data[2] + (Data[3] << 8))) / 32767.0 * 360;
  2187. textBox_AngleZeroCur.Text = tmp2.ToString("F2");
  2188. double tmp3 = (tmp2 - tmp1);
  2189. textBox_AngleZeroDiff.Text = tmp3.ToString("F2");
  2190. }));
  2191. }
  2192. break;
  2193. }
  2194. case 0xC109: //Boot版本信息
  2195. {
  2196. BootInfo = "";
  2197. for (ushort i = 0; i < 9; i++)
  2198. {
  2199. BootInfo += ((char)Data[i]).ToString();
  2200. }
  2201. break;
  2202. }
  2203. default:
  2204. {
  2205. break;
  2206. }
  2207. }
  2208. //存储器导出数据显示
  2209. if ((CmdTemp & 0xFF00) == 0xAB00)
  2210. {
  2211. unchecked
  2212. {
  2213. this.Invoke((EventHandler)(delegate
  2214. {
  2215. long ByteNum = 0;
  2216. ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
  2217. if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
  2218. {
  2219. for (int i = 0; i < ByteNum; i++)
  2220. {
  2221. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  2222. }
  2223. }
  2224. }));
  2225. }
  2226. }
  2227. }
  2228. #endregion
  2229. #region 解析BMS广播的命令
  2230. else if (ID == 0x720)
  2231. {
  2232. switch (CmdTemp)
  2233. {
  2234. case 0x1010://BMS运行信息
  2235. {
  2236. unchecked
  2237. {
  2238. this.Invoke((EventHandler)(delegate
  2239. {
  2240. BMS_RunInfo_Refresh = true;
  2241. richTextBox_OBC_BMS_RunInfo.Clear();
  2242. //电压
  2243. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  2244. richTextBox_OBC_BMS_RunInfo.AppendText("电压:" + Convert.ToString(uData16) + " mV" + "\r\n");
  2245. //电流
  2246. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  2247. richTextBox_OBC_BMS_RunInfo.AppendText("电流:" + Convert.ToString(uData16) + " mA" + "\r\n");
  2248. //剩余容量
  2249. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  2250. richTextBox_OBC_BMS_RunInfo.AppendText("剩余容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  2251. //满充容量
  2252. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  2253. richTextBox_OBC_BMS_RunInfo.AppendText("满充容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  2254. //电芯温度
  2255. richTextBox_OBC_BMS_RunInfo.AppendText("电芯温度:" + Convert.ToString((int)(Data[8] - 40) + " ℃" + "\r\n"));
  2256. //剩余电量
  2257. richTextBox_OBC_BMS_RunInfo.AppendText("剩余电量:" + Convert.ToString(Data[9]) + " %" + "\r\n");
  2258. //电池状态
  2259. richTextBox_OBC_BMS_RunInfo.AppendText("电池状态:" + Convert.ToString(Data[10], 16).PadLeft(2, '0').ToUpper() + " H" + "\r\n");
  2260. //SOH
  2261. richTextBox_OBC_BMS_RunInfo.AppendText("电池寿命:" + Convert.ToString(Data[11]) + " %" + "\r\n");
  2262. //循环次数
  2263. richTextBox_OBC_BMS_RunInfo.AppendText("循环次数:" + Convert.ToString((ushort)(Data[13] * 256 + Data[12])) + " 次");
  2264. }));
  2265. }
  2266. break;
  2267. }
  2268. default: break;
  2269. }
  2270. }
  2271. #endregion
  2272. #region 解析电机发送OBC的命令
  2273. else if (ID == 0x713)
  2274. {
  2275. switch (CmdTemp)
  2276. {
  2277. case 0x5408://电机用户参数
  2278. {
  2279. unchecked
  2280. {
  2281. this.Invoke((EventHandler)(delegate
  2282. {
  2283. richTextBox_OBC_ReadUserInfo.Clear();
  2284. //默认周长
  2285. richTextBox_OBC_ReadUserInfo.AppendText("默认周长:" + Convert.ToString((int)Data[0]) + " cm" + "\r\n");
  2286. //启动模式
  2287. richTextBox_OBC_ReadUserInfo.AppendText("启动模式:" + ((Data[1] == 0x01) ? "柔和" : (Data[1] == 0x02) ? "正常" : (Data[1] == 0x03) ? "强劲" : "无效") + "\r\n");
  2288. comboBox_OBC_StartMode.SelectedIndex = Data[1] - 1;
  2289. //限速
  2290. richTextBox_OBC_ReadUserInfo.AppendText("限速:" + Convert.ToString(Data[2]) + " km/h" + "\r\n");
  2291. //周长微调
  2292. numericUpDown_OBC_WheelAdj.Value = (int)(Data[3] > 128 ? (Data[3] - 256) : Data[3]);
  2293. richTextBox_OBC_ReadUserInfo.AppendText("周长微调:" + Convert.ToString(numericUpDown_OBC_WheelAdj.Value) + " cm" + "\r\n");
  2294. //助力方案
  2295. richTextBox_OBC_ReadUserInfo.AppendText("助力方案:" + Convert.ToString(Data[4]) + "\r\n");
  2296. comboBox_OBC_AssistFunc.SelectedIndex = Data[4] - 1;
  2297. //关机时间
  2298. richTextBox_OBC_ReadUserInfo.AppendText("关机时间:" + Convert.ToString(Data[5]) + " min" + "\r\n");
  2299. numericUpDown_OBC_OffTime.Value = (int)Data[5];
  2300. //限速微调
  2301. numericUpDown_OBC_SpeedLimitAdj.Value = (int)(Data[6] > 128 ? (Data[6] - 256) : Data[6]);
  2302. richTextBox_OBC_ReadUserInfo.AppendText("限速微调:" + Convert.ToString(numericUpDown_OBC_SpeedLimitAdj.Value) + " km/h" + "\r\n");
  2303. //定速巡航
  2304. comboBox_OBC_BikeCCS.SelectedIndex = (Data[7] == 0xAA) ? 1 : 2;
  2305. richTextBox_OBC_ReadUserInfo.AppendText("转把巡航:" + comboBox_OBC_BikeCCS.Text + "\r\n");
  2306. }));
  2307. }
  2308. break;
  2309. }
  2310. case 0x5303://电机应答反馈
  2311. {
  2312. unchecked
  2313. {
  2314. this.Invoke((EventHandler)(delegate
  2315. {
  2316. timer_500ms.Enabled = false;
  2317. MessageBoxTimeOut.Show("OK", "反馈指令", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  2318. timer_500ms.Enabled = true;
  2319. }));
  2320. }
  2321. break;
  2322. }
  2323. case 0x5620: //用户骑行参数
  2324. {
  2325. unchecked
  2326. {
  2327. this.Invoke((EventHandler)(delegate
  2328. {
  2329. richTextBox_UsrRidesParam.Clear();
  2330. for (int i = 0; i < myParams.UsrRideParam.Count; i++)
  2331. {
  2332. richTextBox_UsrRidesParam.AppendText(myParams.UsrRideParam[i] + "=" + Convert.ToString(Data[i]) + ", ");
  2333. }
  2334. richTextBox_UsrRidesParam.Text = richTextBox_UsrRidesParam.Text.Substring(0, richTextBox_UsrRidesParam.Text.Length - 2);
  2335. }));
  2336. }
  2337. break;
  2338. }
  2339. default: break;
  2340. }
  2341. }
  2342. #endregion
  2343. }
  2344. private void DataRevToString(ushort CmdTemp, byte[] Data)
  2345. {
  2346. CmdRevStrTemp = "";
  2347. CmdRevStrTemp += Convert.ToString(CmdTemp >> 8, 16).PadLeft(2, '0').ToUpper() + " ";
  2348. CmdRevStrTemp += Convert.ToString(CmdTemp & 0xFF, 16).PadLeft(2, '0').ToUpper() + " ";
  2349. ushort len = (ushort)(CmdTemp & 0x00FF);
  2350. for (int i = 0; i < len ; i++)
  2351. {
  2352. CmdRevStrTemp += Convert.ToString(Data[i], 16).PadLeft(2, '0').ToUpper() + " ";
  2353. }
  2354. }
  2355. #endregion
  2356. /// <summary>
  2357. /// 端口连接或断开
  2358. /// </summary>
  2359. private void PortConnect()
  2360. {
  2361. bool result = false;
  2362. if (连接ToolStripMenuItem.Text == "连接")
  2363. {
  2364. result = mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, 连接开机ToolStripMenuItem.Checked, 识别通讯盒ToolStripMenuItem.Checked);
  2365. if (result)
  2366. {
  2367. toolStripComboBox_ComNum.Enabled = false;
  2368. toolStripComboBox_Baudrate.Enabled = false;
  2369. 刷新ToolStripMenuItem.Enabled = false;
  2370. 连接ToolStripMenuItem.Text = "断开";
  2371. 连接ToolStripMenuItem.Checked = true;
  2372. label_COM_Sta.Text = toolStripComboBox_ComNum.Text + "已连接," + toolStripComboBox_Baudrate.Text;
  2373. label_PortStatus.BackColor = Color.Green;
  2374. }
  2375. }
  2376. else if (连接ToolStripMenuItem.Text == "断开")
  2377. {
  2378. checkBox_OBC_StartSetGearSt.Checked = false;
  2379. checkBox_OBC_StartReadBMS.Checked = false;
  2380. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2381. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  2382. toolStripComboBox_ComNum.Enabled = true;
  2383. toolStripComboBox_Baudrate.Enabled = true;
  2384. 刷新ToolStripMenuItem.Enabled = true;
  2385. 连接ToolStripMenuItem.Text = "连接";
  2386. 连接ToolStripMenuItem.Checked = false;
  2387. label_COM_Sta.Text = "连接状态:未连接";
  2388. label_PortStatus.BackColor = Color.Red;
  2389. }
  2390. }
  2391. /// <summary>
  2392. /// 端口连接事件
  2393. /// </summary>
  2394. /// <param name="sender"></param>
  2395. /// <param name="e"></param>
  2396. private void 连接ToolStripMenuItem_Click(object sender, System.EventArgs e)
  2397. {
  2398. PortConnect();
  2399. }
  2400. /// <summary>
  2401. /// 端口号刷新事件
  2402. /// </summary>
  2403. /// <param name="sender"></param>
  2404. /// <param name="e"></param>
  2405. private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
  2406. {
  2407. toolStripComboBox_ComNum.Items.Clear();
  2408. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  2409. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
  2410. }
  2411. /// <summary>
  2412. /// 存储标志修改事件
  2413. /// </summary>
  2414. /// <param name="sender"></param>
  2415. /// <param name="e"></param>
  2416. private void 写入存储ToolStripMenuItem_Click(object sender, EventArgs e)
  2417. {
  2418. if (写入存储ToolStripMenuItem.Checked)
  2419. {
  2420. EnterForm1.ShowDialog();
  2421. try
  2422. {
  2423. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  2424. {
  2425. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  2426. {
  2427. 写入存储ToolStripMenuItem.Checked = false;
  2428. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  2429. }
  2430. else
  2431. {
  2432. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2433. }
  2434. }
  2435. else
  2436. {
  2437. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2438. }
  2439. }
  2440. catch (Exception)
  2441. {
  2442. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2443. }
  2444. }
  2445. else
  2446. {
  2447. 写入存储ToolStripMenuItem.Checked = true;
  2448. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  2449. }
  2450. }
  2451. /// <summary>
  2452. /// 1s定时器
  2453. /// </summary>
  2454. /// <param name="sender"></param>
  2455. /// <param name="e"></param>
  2456. private void timer_1s_Tick(object sender, EventArgs e)
  2457. {
  2458. //时间更新
  2459. label_SystemTime.Text = "系统时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2460. //MC_Runinfo超时清除
  2461. if (MC_RunInfo_Refresh == false)
  2462. {
  2463. MC_RunInfo_Refresh_Cnt++;
  2464. if (MC_RunInfo_Refresh_Cnt > 10)//5s
  2465. {
  2466. MC_RunInfo_Clear();
  2467. MC_RunInfo_Refresh_Cnt = 0;
  2468. }
  2469. }
  2470. else
  2471. {
  2472. MC_RunInfo_Refresh_Cnt = 0;
  2473. }
  2474. MC_RunInfo_Refresh = false;
  2475. //MC_Debuginfo超时清除
  2476. if (MC_DebugInfo_Refresh == false)
  2477. {
  2478. MC_DebugInfo_Refresh_Cnt++;
  2479. if (MC_DebugInfo_Refresh_Cnt > 10)//5s
  2480. {
  2481. MC_DebugInfo_Clear();
  2482. MC_DebugInfo_Refresh_Cnt = 0;
  2483. }
  2484. }
  2485. else
  2486. {
  2487. MC_DebugInfo_Refresh_Cnt = 0;
  2488. }
  2489. MC_DebugInfo_Refresh = false;
  2490. //BMS_RunInfo超时清除
  2491. if (BMS_RunInfo_Refresh == false)
  2492. {
  2493. BMS_RunInfo_Refresh_Cnt++;
  2494. if (BMS_RunInfo_Refresh_Cnt > 10)//5s
  2495. {
  2496. richTextBox_OBC_BMS_RunInfo.Clear();
  2497. BMS_RunInfo_Refresh_Cnt = 0;
  2498. }
  2499. }
  2500. else
  2501. {
  2502. BMS_RunInfo_Refresh_Cnt = 0;
  2503. }
  2504. BMS_RunInfo_Refresh = false;
  2505. //故障码超时清除
  2506. if (MC_ErrorCode_Refresh == false)
  2507. {
  2508. MC_ErrorCode_Refresh_Cnt++;
  2509. if (MC_ErrorCode_Refresh_Cnt > 10)//5s
  2510. {
  2511. textBox_ErrorCode.Text = "---";
  2512. MC_ErrorCode_Refresh_Cnt = 0;
  2513. }
  2514. }
  2515. else
  2516. {
  2517. MC_ErrorCode_Refresh_Cnt = 0;
  2518. }
  2519. MC_ErrorCode_Refresh = false;
  2520. //CDL连接超时
  2521. if (识别通讯盒ToolStripMenuItem.Checked)
  2522. {
  2523. if (mySerialProcess.CDL_Online_Flag == false)
  2524. {
  2525. mySerialProcess.CDL_OnlineCheck_Cnt++;
  2526. if (mySerialProcess.CDL_OnlineCheck_Cnt > 1)//1s
  2527. {
  2528. timer_500ms.Enabled = false;
  2529. MessageBox.Show("连接失败!", "提示");
  2530. timer_500ms.Enabled = true;
  2531. //关闭串口
  2532. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  2533. toolStripComboBox_ComNum.Enabled = true;
  2534. toolStripComboBox_Baudrate.Enabled = true;
  2535. 刷新ToolStripMenuItem.Enabled = true;
  2536. 连接ToolStripMenuItem.Text = "连接";
  2537. 连接ToolStripMenuItem.Checked = false;
  2538. label_COM_Sta.Text = "连接状态:未连接";
  2539. label_PortStatus.BackColor = Color.Red;
  2540. }
  2541. }
  2542. }
  2543. //OBC定时发送设置档位
  2544. if (checkBox_OBC_StartSetGearSt.Checked == true)
  2545. {
  2546. var CtrlCode = new byte[2];
  2547. if (comboBox_OBC_SetGearST.SelectedIndex == 5)//档位
  2548. CtrlCode[0] = 0x33;
  2549. else if (comboBox_OBC_SetGearST.SelectedIndex == 6)//档位
  2550. CtrlCode[0] = 0x22;
  2551. else
  2552. CtrlCode[0] = (byte)comboBox_OBC_SetGearST.SelectedIndex;
  2553. if (comboBox_OBC_LightSw.SelectedIndex == 0)//车灯
  2554. CtrlCode[1] = 0xF1;
  2555. else
  2556. CtrlCode[1] = 0xF0;
  2557. if (!mySerialProcess.SendCmdWithoutNotice((ushort)0x731, (byte)0x0C, (ushort)0x3002, CtrlCode))
  2558. {
  2559. checkBox_OBC_StartSetGearSt.Checked = false;
  2560. }
  2561. }
  2562. //OBC定时发送查询电池
  2563. if (checkBox_OBC_StartReadBMS.Checked == true)
  2564. {
  2565. if (!mySerialProcess.SendCmd((ushort)0x732, (byte)0x11, (ushort)0x5000, null))
  2566. {
  2567. checkBox_OBC_StartReadBMS.Checked = false;
  2568. }
  2569. }
  2570. //定时读取存储器
  2571. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  2572. {
  2573. var Address = new byte[4];
  2574. UInt32 Address_Begin;
  2575. UInt32 Addres_End;
  2576. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  2577. richTextBox_RamFlasgData.Clear();
  2578. do
  2579. {
  2580. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  2581. {
  2582. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2583. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2584. continue;
  2585. }
  2586. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  2587. {
  2588. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2589. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2590. continue;
  2591. }
  2592. else
  2593. {
  2594. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  2595. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2596. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  2597. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2598. if (Addres_End < Address_Begin)
  2599. {
  2600. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2601. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2602. continue;
  2603. }
  2604. else
  2605. {
  2606. var SendByte = new byte[8];
  2607. SendByte[0] = (byte)(Address_Begin >> 24);
  2608. SendByte[1] = (byte)(Address_Begin >> 16);
  2609. SendByte[2] = (byte)(Address_Begin >> 8);
  2610. SendByte[3] = (byte)(Address_Begin);
  2611. SendByte[4] = (byte)(Addres_End >> 24);
  2612. SendByte[5] = (byte)(Addres_End >> 16);
  2613. SendByte[6] = (byte)(Addres_End >> 8);
  2614. SendByte[7] = (byte)(Addres_End);
  2615. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte))
  2616. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2617. }
  2618. }
  2619. } while (false);
  2620. }
  2621. //写入参数等待计时
  2622. ACK_WaitCnt++;
  2623. }
  2624. /// <summary>
  2625. /// 运行信息清除
  2626. /// </summary>
  2627. private void MC_RunInfo_Clear()
  2628. {
  2629. foreach (Control c in tabPage_RunInfo.Controls)
  2630. {
  2631. if ((c is TextBox))
  2632. {
  2633. if (c.Name != textBox_ErrorCode.ToString())
  2634. c.Text = "---";
  2635. }
  2636. }
  2637. }
  2638. /// <summary>
  2639. /// 调试信息清除
  2640. /// </summary>
  2641. private void MC_DebugInfo_Clear()
  2642. {
  2643. foreach (Control c in tabPage_DebugInfo.Controls)
  2644. {
  2645. if ((c is TextBox))
  2646. {
  2647. if (c.Name != textBox_ErrorCode.ToString())
  2648. c.Text = "---";
  2649. }
  2650. }
  2651. }
  2652. /// <summary>
  2653. /// 读取马达参数
  2654. /// </summary>
  2655. /// <param name="sender"></param>
  2656. /// <param name="e"></param>
  2657. private void button_Read_MotorParam_Click(object sender, EventArgs e)
  2658. {
  2659. richTextBox_MotorParam.Clear();
  2660. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null);
  2661. }
  2662. /// <summary>
  2663. /// 写入马达参数
  2664. /// </summary>
  2665. /// <param name="sender"></param>
  2666. /// <param name="e"></param>
  2667. private void button_Write_Click(object sender, EventArgs e)
  2668. {
  2669. var ConfigParam = new byte[40];
  2670. for (int i = 0; i < 40; i++)
  2671. ConfigParam[i] = 0;
  2672. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2673. short wDataTemp = 0;
  2674. ushort DataTemp = 0;
  2675. string[] strDataTemp = richTextBox_MotorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2676. try
  2677. {
  2678. for (int i = 0; i < strDataTemp.Length; i++)
  2679. {
  2680. if (i == 6)
  2681. {
  2682. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  2683. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  2684. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  2685. }
  2686. else
  2687. {
  2688. DataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2689. ConfigParam[2 * i + 2] = (byte)DataTemp;
  2690. ConfigParam[2 * i + 3] = (byte)(DataTemp >> 8);
  2691. }
  2692. }
  2693. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B28, ConfigParam);
  2694. }
  2695. catch (Exception)
  2696. {
  2697. timer_500ms.Enabled = false;
  2698. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2699. timer_500ms.Enabled = true;
  2700. }
  2701. }
  2702. /// <summary>
  2703. /// 读取整车信息
  2704. /// </summary>
  2705. /// <param name="sender"></param>
  2706. /// <param name="e"></param>
  2707. private void button_ReadBikeParam_Click(object sender, EventArgs e)
  2708. {
  2709. richTextBox_BikeParam.Clear();
  2710. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null);
  2711. }
  2712. /// <summary>
  2713. /// 写入整车信息
  2714. /// </summary>
  2715. /// <param name="sender"></param>
  2716. /// <param name="e"></param>
  2717. private void button_WriteBikeParam_Click(object sender, EventArgs e)
  2718. {
  2719. var ConfigParam = new byte[28];
  2720. for (int i = 0; i < 28; i++)
  2721. ConfigParam[i] = 0;
  2722. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2723. string[] strDataTemp = richTextBox_BikeParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2724. try
  2725. {
  2726. for (int i = 0; i < strDataTemp.Length; i++)
  2727. {
  2728. short wDataTemp = 0;
  2729. //前后灯参数修改
  2730. if (i == 8)
  2731. {
  2732. wDataTemp |= (short)((comboBox_TailLightMode.SelectedIndex + 1) << 12); //Bit15~Bit12:尾灯模式
  2733. wDataTemp |= (short)((comboBox_TailLightVol.SelectedIndex == 0 ? 6 : 12) << 8); //Bit11~Bit8:尾灯电压
  2734. wDataTemp |= (short)(comboBox_FrontLightVol.SelectedIndex == 0 ? 6 : 12); //Bit7~Bit0:前灯电压
  2735. }
  2736. //开关机参数
  2737. else if (i == 11)
  2738. {
  2739. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOnDelay.Text) << 12);
  2740. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOffDelay.Text) << 8);
  2741. wDataTemp |= (short)(Convert.ToInt16(textBox_AutoPowerOff.Text));
  2742. }
  2743. else
  2744. {
  2745. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  2746. }
  2747. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  2748. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  2749. }
  2750. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D1C, ConfigParam);
  2751. }
  2752. catch (Exception)
  2753. {
  2754. timer_500ms.Enabled = false;
  2755. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2756. timer_500ms.Enabled = true;
  2757. }
  2758. }
  2759. /// <summary>
  2760. /// 读取控制器参数
  2761. /// </summary>
  2762. /// <param name="sender"></param>
  2763. /// <param name="e"></param>
  2764. private void button_ReadControlParam_Click(object sender, EventArgs e)
  2765. {
  2766. richTextBox_ControlParam.Clear();
  2767. comboBox_Bike_CCS.SelectedIndex = 0;
  2768. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
  2769. }
  2770. /// <summary>
  2771. /// 写入控制器参数
  2772. /// </summary>
  2773. /// <param name="sender"></param>
  2774. /// <param name="e"></param>
  2775. private void button_WriteControlParam_Click(object sender, EventArgs e)
  2776. {
  2777. var ConfigParam = new byte[34];
  2778. for (int i = 0; i < 34; i++)
  2779. ConfigParam[i] = 0;
  2780. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2781. ushort uwDataTemp = 0;
  2782. string[] strDataTemp = richTextBox_ControlParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2783. try
  2784. {
  2785. for (int i = 0; i < strDataTemp.Length; i++)
  2786. {
  2787. if (i == 13)
  2788. {
  2789. uwDataTemp = (comboBox_Bike_CCS.SelectedIndex == 1) ? (ushort)0x00AA : (ushort)0x0000;
  2790. }
  2791. else
  2792. {
  2793. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2794. }
  2795. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2796. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2797. }
  2798. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3F22, ConfigParam);
  2799. }
  2800. catch (Exception)
  2801. {
  2802. timer_500ms.Enabled = false;
  2803. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2804. timer_500ms.Enabled = true;
  2805. }
  2806. }
  2807. /// <summary>
  2808. /// 读取助力参数
  2809. /// </summary>
  2810. /// <param name="sender"></param>
  2811. /// <param name="e"></param>
  2812. private void button_ReadAssistParam_Click(object sender, EventArgs e)
  2813. {
  2814. var ConfigParam = new byte[4];
  2815. int AssistNum = 0;
  2816. try
  2817. {
  2818. AssistNum = Convert.ToInt32(comboBox_AssistTorque.Text);
  2819. ConfigParam[0] = (byte)(AssistNum & 0xFF);
  2820. ConfigParam[1] = (byte)(AssistNum >> 8);
  2821. AssistNum = Convert.ToInt32(comboBox_AssistCadence.Text);
  2822. ConfigParam[2] = (byte)(AssistNum & 0xFF);
  2823. ConfigParam[3] = (byte)(AssistNum >> 8);
  2824. richTextBox_AssistParam.Clear();
  2825. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam);
  2826. }
  2827. catch (Exception)
  2828. {
  2829. timer_500ms.Enabled = false;
  2830. MessageBox.Show("请选择助力参数编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2831. timer_500ms.Enabled = true;
  2832. }
  2833. }
  2834. /// <summary>
  2835. /// 写入助力参数
  2836. /// </summary>
  2837. /// <param name="sender"></param>
  2838. /// <param name="e"></param>
  2839. private void button_WriteAssistParam_Click(object sender, EventArgs e)
  2840. {
  2841. var ConfigParam = new byte[80];
  2842. for (int i = 0; i < 80; i++)
  2843. ConfigParam[i] = 0;
  2844. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2845. long lDataTemp = 0;
  2846. string[] strDataTemp = richTextBox_AssistParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2847. int index_1 = 0, index_2 = 0;
  2848. try
  2849. {
  2850. for (int i = 0; i < strDataTemp.Length; i++)
  2851. {
  2852. if (strDataTemp[i].Split('=')[0] == "转矩曲线.a")
  2853. {
  2854. index_1 = i;
  2855. break;
  2856. }
  2857. }
  2858. for (int i = 0; i < strDataTemp.Length; i++)
  2859. {
  2860. if (strDataTemp[i].Split('=')[0] == "踏频曲线.d")
  2861. {
  2862. index_2 = i;
  2863. break;
  2864. }
  2865. }
  2866. for (int i = 0; i < strDataTemp.Length; i++)
  2867. {
  2868. lDataTemp = Convert.ToInt32(strDataTemp[i].Split('=')[1]);
  2869. if (i < index_1)
  2870. {
  2871. ConfigParam[2 * i + 4] = (byte)lDataTemp;
  2872. ConfigParam[2 * i + 5] = (byte)(lDataTemp >> 8);
  2873. }
  2874. else if (i <= index_2)
  2875. {
  2876. ConfigParam[4 * i - 4] = (byte)lDataTemp;
  2877. ConfigParam[4 * i - 3] = (byte)(lDataTemp >> 8);
  2878. ConfigParam[4 * i - 2] = (byte)(lDataTemp >> 16);
  2879. ConfigParam[4 * i - 1] = (byte)(lDataTemp >> 24);
  2880. }
  2881. else
  2882. {
  2883. ConfigParam[2 * i + 20] = (byte)lDataTemp;
  2884. ConfigParam[2 * i + 21] = (byte)(lDataTemp >> 8);
  2885. }
  2886. }
  2887. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4450, ConfigParam);
  2888. }
  2889. catch (Exception)
  2890. {
  2891. timer_500ms.Enabled = false;
  2892. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2893. timer_500ms.Enabled = true;
  2894. }
  2895. }
  2896. /// <summary>
  2897. /// 读取调试参数
  2898. /// </summary>
  2899. /// <param name="sender"></param>
  2900. /// <param name="e"></param>
  2901. private void button_ReadDebugParam_Click(object sender, EventArgs e)
  2902. {
  2903. richTextBox_DebugParam.Clear();
  2904. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  2905. }
  2906. /// <summary>
  2907. /// 写入调试参数
  2908. /// </summary>
  2909. /// <param name="sender"></param>
  2910. /// <param name="e"></param>
  2911. private void button_WriteDebugParam_Click(object sender, EventArgs e)
  2912. {
  2913. var ConfigParam = new byte[60];
  2914. for (int i = 0; i < 60; i++)
  2915. ConfigParam[i] = 0;
  2916. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2917. ushort uwDataTemp = 0;
  2918. string[] strDataTemp = richTextBox_DebugParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2919. try
  2920. {
  2921. for (int i = 0; i < strDataTemp.Length; i++)
  2922. {
  2923. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2924. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2925. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2926. }
  2927. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam);
  2928. }
  2929. catch (Exception)
  2930. {
  2931. timer_500ms.Enabled = false;
  2932. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2933. timer_500ms.Enabled = true;
  2934. }
  2935. }
  2936. /// <summary>
  2937. /// 读取历史
  2938. /// </summary>
  2939. /// <param name="sender"></param>
  2940. /// <param name="e"></param>
  2941. private void button_ReadRecord_Click(object sender, EventArgs e)
  2942. {
  2943. richTextBox_Record.Clear();
  2944. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null);
  2945. }
  2946. /// <summary>
  2947. /// 读取传感器参数
  2948. /// </summary>
  2949. /// <param name="sender"></param>
  2950. /// <param name="e"></param>
  2951. private void button_ReadSensorParam_Click(object sender, EventArgs e)
  2952. {
  2953. richTextBox_SensorParam.Clear();
  2954. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  2955. }
  2956. /// <summary>
  2957. /// 写入力矩传感器标定值
  2958. /// </summary>
  2959. /// <param name="sender"></param>
  2960. /// <param name="e"></param>
  2961. private void button_Write_Cal_Click(object sender, EventArgs e)
  2962. {
  2963. var ConfigParam = new byte[4];
  2964. for (int i = 0; i < 4; i++)
  2965. ConfigParam[i] = 0;
  2966. ushort uwDataTemp = 0;
  2967. try
  2968. {
  2969. uwDataTemp = Convert.ToUInt16(comboBox_TorqueSet.Text);//负载序号
  2970. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  2971. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  2972. uwDataTemp = (ushort)(decimal.Parse(textBox_Load.Text) * 10); ;//负载值0.1Nm
  2973. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  2974. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  2975. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  2976. }
  2977. catch (Exception)
  2978. {
  2979. timer_500ms.Enabled = false;
  2980. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2981. timer_500ms.Enabled = true;
  2982. }
  2983. }
  2984. /// <summary>
  2985. /// 写入传感器参数
  2986. /// </summary>
  2987. /// <param name="sender"></param>
  2988. /// <param name="e"></param>
  2989. private void button_WriteSensorParam_Click(object sender, EventArgs e)
  2990. {
  2991. var ConfigParam = new byte[14];
  2992. for (int i = 0; i < 14; i++)
  2993. ConfigParam[i] = 0;
  2994. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2995. ushort uwDataTemp = 0;
  2996. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  2997. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2998. int index = 0;
  2999. try
  3000. {
  3001. for (int i = 0; i < strDataTemp.Length; i++)
  3002. {
  3003. if (strDataTemp[i].Split('=')[0] == "力矩传感器踏频脉冲数")
  3004. {
  3005. index = i;
  3006. break;
  3007. }
  3008. }
  3009. for (int i = 0; i < (strDataTemp.Length - index); i++)
  3010. {
  3011. uwDataTemp = Convert.ToUInt16(strDataTemp[i + index].Split('=')[1]);
  3012. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3013. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3014. }
  3015. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x420E, ConfigParam);
  3016. }
  3017. catch (Exception)
  3018. {
  3019. timer_500ms.Enabled = false;
  3020. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3021. timer_500ms.Enabled = true;
  3022. }
  3023. }
  3024. /// <summary>
  3025. /// 写入型号
  3026. /// </summary>
  3027. /// <param name="sender"></param>
  3028. /// <param name="e"></param>
  3029. private void button_WriteModel_Click(object sender, EventArgs e)
  3030. {
  3031. string Mode = textBox_Model.Text;
  3032. var ModeArray = new byte[16];
  3033. for (ushort i = 0; i < Mode.Length; i++)
  3034. {
  3035. ModeArray[i] = (byte)Mode[i];
  3036. }
  3037. if (Mode.Length < 16)
  3038. {
  3039. ModeArray[Mode.Length] = (byte)'.';
  3040. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  3041. {
  3042. ModeArray[Mode.Length + 1 + i] = 0x20;
  3043. }
  3044. }
  3045. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  3046. }
  3047. /// <summary>
  3048. /// 写入SN
  3049. /// </summary>
  3050. /// <param name="sender"></param>
  3051. /// <param name="e"></param>
  3052. private void button_WriteSN_Click(object sender, EventArgs e)
  3053. {
  3054. string SN = textBox_SN.Text;
  3055. var SNArray = new byte[16];
  3056. for (ushort i = 0; i < SN.Length; i++)
  3057. {
  3058. SNArray[i] = (byte)SN[i];
  3059. }
  3060. if (SN.Length < 16)
  3061. {
  3062. SNArray[SN.Length] = (byte)'.';
  3063. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  3064. {
  3065. SNArray[SN.Length + 1 + i] = 0x20;
  3066. }
  3067. }
  3068. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  3069. }
  3070. /// <summary>
  3071. /// 查询版本信息
  3072. /// </summary>
  3073. /// <param name="sender"></param>
  3074. /// <param name="e"></param>
  3075. private void button_ReadVersion_Click(object sender, EventArgs e)
  3076. {
  3077. textBox_Model.Text = "---";
  3078. textBox_SN.Text = "---";
  3079. textBox_HW.Text = "---";
  3080. textBox_FW.Text = "---";
  3081. textBox_SP.Text = "---";
  3082. textBox_OBC_ReadModel.Text = "---";
  3083. textBox_OBC_ReadSN.Text = "---";
  3084. textBox_OBC_ReadHW.Text = "---";
  3085. textBox_OBC_ReadFW.Text = "---";
  3086. textBox_OBC_ReadSP.Text = "---";
  3087. textBox_FacModeName.Text = "---";
  3088. textBox_FacModeNum.Text = "---";
  3089. textBox_FacModeHW.Text = "---";
  3090. textBox_FacModeFW.Text = "---";
  3091. textBox_FacModeSP.Text = "---";
  3092. Class_Motor_Ver.Mode = "---";
  3093. Class_Motor_Ver.SN = "---";
  3094. Class_Motor_Ver.HW = "---";
  3095. Class_Motor_Ver.FW = "---";
  3096. Class_Motor_Ver.Special = "---";
  3097. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  3098. }
  3099. /// <summary>
  3100. /// 查询自定义1
  3101. /// </summary>
  3102. /// <param name="sender"></param>
  3103. /// <param name="e"></param>
  3104. private void button_ReadUser1_Click(object sender, EventArgs e)
  3105. {
  3106. textBox_User1.Text = "---";
  3107. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null);
  3108. }
  3109. /// <summary>
  3110. /// 查询自定义2
  3111. /// </summary>
  3112. /// <param name="sender"></param>
  3113. /// <param name="e"></param>
  3114. private void button_ReadUser2_Click(object sender, EventArgs e)
  3115. {
  3116. textBox_User2.Text = "---";
  3117. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null);
  3118. }
  3119. /// <summary>
  3120. /// 查询自定义3
  3121. /// </summary>
  3122. /// <param name="sender"></param>
  3123. /// <param name="e"></param>
  3124. private void button_ReadUser3_Click(object sender, EventArgs e)
  3125. {
  3126. textBox_User3.Text = "---";
  3127. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null);
  3128. }
  3129. /// <summary>
  3130. /// 写入自定义字符串1
  3131. /// </summary>
  3132. /// <param name="sender"></param>
  3133. /// <param name="e"></param>
  3134. private void button_WriteUser1_Click(object sender, EventArgs e)
  3135. {
  3136. string User = textBox_User1.Text;
  3137. var UserArray = new byte[16];
  3138. for (ushort i = 0; i < User.Length; i++)
  3139. {
  3140. UserArray[i] = (byte)User[i];
  3141. }
  3142. if (User.Length < 16)
  3143. {
  3144. UserArray[User.Length] = (byte)'.';
  3145. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3146. {
  3147. UserArray[User.Length + 1 + i] = 0x20;
  3148. }
  3149. }
  3150. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1410, UserArray);
  3151. }
  3152. /// <summary>
  3153. /// 写入自定义字符串2
  3154. /// </summary>
  3155. /// <param name="sender"></param>
  3156. /// <param name="e"></param>
  3157. private void button_WriteUser2_Click(object sender, EventArgs e)
  3158. {
  3159. string User = textBox_User2.Text;
  3160. var UserArray = new byte[16];
  3161. for (ushort i = 0; i < User.Length; i++)
  3162. {
  3163. UserArray[i] = (byte)User[i];
  3164. }
  3165. if (User.Length < 16)
  3166. {
  3167. UserArray[User.Length] = (byte)'.';
  3168. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3169. {
  3170. UserArray[User.Length + 1 + i] = 0x20;
  3171. }
  3172. }
  3173. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1610, UserArray);
  3174. }
  3175. /// <summary>
  3176. /// 写入自定义字符串3
  3177. /// </summary>
  3178. /// <param name="sender"></param>
  3179. /// <param name="e"></param>
  3180. private void button_WriteUser3_Click(object sender, EventArgs e)
  3181. {
  3182. string User = textBox_User3.Text;
  3183. var UserArray = new byte[16];
  3184. for (ushort i = 0; i < User.Length; i++)
  3185. {
  3186. UserArray[i] = (byte)User[i];
  3187. }
  3188. if (User.Length < 16)
  3189. {
  3190. UserArray[User.Length] = (byte)'.';
  3191. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3192. {
  3193. UserArray[User.Length + 1 + i] = 0x20;
  3194. }
  3195. }
  3196. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1810, UserArray);
  3197. }
  3198. /// <summary>
  3199. /// 查询生产信息
  3200. /// </summary>
  3201. /// <param name="sender"></param>
  3202. /// <param name="e"></param>
  3203. private void button_ReadMAC_Click(object sender, EventArgs e)
  3204. {
  3205. textBox_MAC.Text = "---";
  3206. textBox_MACAdd.Text = "---";
  3207. textBox_MACDate.Text = "---";
  3208. textBox_PP.Text = "---";
  3209. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null);
  3210. }
  3211. /// <summary>
  3212. /// 写入生产信息
  3213. /// </summary>
  3214. /// <param name="sender"></param>
  3215. /// <param name="e"></param>
  3216. private void button_WriteMac_Click(object sender, EventArgs e)
  3217. {
  3218. var MACArray = new byte[32];
  3219. //填入生产商
  3220. for (ushort i = 0; i < textBox_MAC.Text.Length; i++)
  3221. {
  3222. MACArray[i] = (byte)textBox_MAC.Text[i];
  3223. }
  3224. if (textBox_MAC.Text.Length < 8)
  3225. {
  3226. MACArray[textBox_MAC.Text.Length] = (byte)'.';
  3227. for (ushort i = 0; i < 8 - textBox_MAC.Text.Length - 1; i++)
  3228. {
  3229. MACArray[textBox_MAC.Text.Length + 1 + i] = 0x20;
  3230. }
  3231. }
  3232. //填入生产地
  3233. for (ushort i = 0; i < textBox_MACAdd.Text.Length; i++)
  3234. {
  3235. MACArray[8 + i] = (byte)textBox_MACAdd.Text[i];
  3236. }
  3237. if (textBox_MACAdd.Text.Length < 8)
  3238. {
  3239. MACArray[textBox_MACAdd.Text.Length + 8] = (byte)'.';
  3240. for (ushort i = 0; i < 8 - textBox_MACAdd.Text.Length - 1; i++)
  3241. {
  3242. MACArray[textBox_MACAdd.Text.Length + 1 + i + 8] = 0x20;
  3243. }
  3244. }
  3245. //填入生产日期
  3246. for (ushort i = 0; i < textBox_MACDate.Text.Length; i++)
  3247. {
  3248. MACArray[16 + i] = (byte)textBox_MACDate.Text[i];
  3249. }
  3250. if (textBox_MACDate.Text.Length < 8)
  3251. {
  3252. MACArray[textBox_MACDate.Text.Length + 16] = (byte)'.';
  3253. for (ushort i = 0; i < 8 - textBox_MACDate.Text.Length - 1; i++)
  3254. {
  3255. MACArray[textBox_MACDate.Text.Length + 1 + i + 16] = 0x20;
  3256. }
  3257. }
  3258. //填入品牌
  3259. for (ushort i = 0; i < textBox_PP.Text.Length; i++)
  3260. {
  3261. MACArray[24 + i] = (byte)textBox_PP.Text[i];
  3262. }
  3263. if (textBox_PP.Text.Length < 8)
  3264. {
  3265. MACArray[textBox_PP.Text.Length + 24] = (byte)'.';
  3266. for (ushort i = 0; i < 8 - textBox_PP.Text.Length - 1; i++)
  3267. {
  3268. MACArray[textBox_PP.Text.Length + 1 + i + 24] = 0x20;
  3269. }
  3270. }
  3271. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  3272. }
  3273. /// <summary>
  3274. /// 查询密钥
  3275. /// </summary>
  3276. /// <param name="sender"></param>
  3277. /// <param name="e"></param>
  3278. private void button_ReadKey_Click(object sender, EventArgs e)
  3279. {
  3280. textBox_Key.Text = "---";
  3281. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null);
  3282. }
  3283. /// <summary>
  3284. /// 写入校验密钥
  3285. /// </summary>
  3286. /// <param name="sender"></param>
  3287. /// <param name="e"></param>
  3288. private void button_WriteKey_Click(object sender, EventArgs e)
  3289. {
  3290. string Key = textBox_Key.Text;
  3291. var KeyArray = new byte[8];
  3292. if (Key.Length != 8)
  3293. {
  3294. timer_500ms.Enabled = false;
  3295. MessageBox.Show("请检查字符长度是否为8", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3296. timer_500ms.Enabled = true;
  3297. return;
  3298. }
  3299. for (ushort i = 0; i < Key.Length; i++)
  3300. {
  3301. KeyArray[i] = (byte)Key[i];
  3302. }
  3303. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1108, KeyArray);
  3304. }
  3305. /// <summary>
  3306. /// 查询在线检测结果
  3307. /// </summary>
  3308. /// <param name="sender"></param>
  3309. /// <param name="e"></param>
  3310. private void button_ReadOnLine_Click(object sender, EventArgs e)
  3311. {
  3312. textBox_Online.Text = "---";
  3313. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2100, null);
  3314. }
  3315. /// <summary>
  3316. /// 系统清除
  3317. /// </summary>
  3318. /// <param name="sender"></param>
  3319. /// <param name="e"></param>
  3320. private void button_SystemClear_Click(object sender, EventArgs e)
  3321. {
  3322. var Code = new byte[5];
  3323. Code[0] = (byte)'C';
  3324. Code[1] = (byte)'L';
  3325. Code[2] = (byte)'E';
  3326. Code[3] = (byte)'A';
  3327. Code[4] = (byte)'R';
  3328. timer_500ms.Enabled = false;
  3329. if (MessageBox.Show("系统清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3330. {
  3331. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3332. {
  3333. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3334. {
  3335. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  3336. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3337. }
  3338. }
  3339. }
  3340. timer_500ms.Enabled = true;
  3341. }
  3342. /// <summary>
  3343. /// 参数还原
  3344. /// </summary>
  3345. /// <param name="sender"></param>
  3346. /// <param name="e"></param>
  3347. private void button_Recovery_Click(object sender, EventArgs e)
  3348. {
  3349. var Code = new byte[8];
  3350. Code[0] = (byte)'R';
  3351. Code[1] = (byte)'E';
  3352. Code[2] = (byte)'C';
  3353. Code[3] = (byte)'O';
  3354. Code[4] = (byte)'V';
  3355. Code[5] = (byte)'E';
  3356. Code[6] = (byte)'R';
  3357. Code[7] = (byte)'Y';
  3358. timer_500ms.Enabled = false;
  3359. if (MessageBox.Show("参数还原后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3360. {
  3361. if (MessageBox.Show("请再次确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3362. {
  3363. if (MessageBox.Show("请最后确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3364. {
  3365. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2708, Code);
  3366. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3367. }
  3368. }
  3369. }
  3370. timer_500ms.Enabled = true;
  3371. }
  3372. /// <summary>
  3373. /// 系统复位
  3374. /// </summary>
  3375. /// <param name="sender"></param>
  3376. /// <param name="e"></param>
  3377. private void button_Reset_Click(object sender, EventArgs e)
  3378. {
  3379. var Code_Off = new byte[5];
  3380. var Code_Reset = new byte[5];
  3381. Code_Off[0] = (byte)'O';
  3382. Code_Off[1] = (byte)'F';
  3383. Code_Off[2] = (byte)'F';
  3384. Code_Off[3] = (byte)'.';
  3385. Code_Off[4] = (byte)'.';
  3386. Code_Reset[0] = (byte)'R';
  3387. Code_Reset[1] = (byte)'E';
  3388. Code_Reset[2] = (byte)'S';
  3389. Code_Reset[3] = (byte)'E';
  3390. Code_Reset[4] = (byte)'T';
  3391. timer_500ms.Enabled = false;
  3392. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3393. {
  3394. timer_500ms.Enabled = true;
  3395. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  3396. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  3397. PowerOffAckStatus = false;
  3398. Delay_ms(250);
  3399. int TryCnt = 3;
  3400. while ((TryCnt--) >= 0)
  3401. {
  3402. if (!PowerOffAckStatus)
  3403. {
  3404. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  3405. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  3406. PowerOffAckStatus = false;
  3407. Delay_ms(250);
  3408. }
  3409. else break;
  3410. }
  3411. if (PowerOffAckStatus)
  3412. {
  3413. timer_500ms.Enabled = false;
  3414. MessageBoxTimeOut.Show("已关机!", "提示", 3000, MessageBoxButtons.OK, MessageBoxIcon.None);
  3415. timer_500ms.Enabled = true;
  3416. }
  3417. else
  3418. {
  3419. timer_500ms.Enabled = false;
  3420. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3421. timer_500ms.Enabled = true;
  3422. }
  3423. }
  3424. timer_500ms.Enabled = true;
  3425. }
  3426. /// <summary>
  3427. /// 记录清除
  3428. /// </summary>
  3429. /// <param name="sender"></param>
  3430. /// <param name="e"></param>
  3431. private void button_ClearLog_Click(object sender, EventArgs e)
  3432. {
  3433. var Code = new byte[9];
  3434. Code[0] = (byte)'L';
  3435. Code[1] = (byte)'O';
  3436. Code[2] = (byte)'G';
  3437. Code[3] = (byte)' ';
  3438. Code[4] = (byte)'C';
  3439. Code[5] = (byte)'L';
  3440. Code[6] = (byte)'E';
  3441. Code[7] = (byte)'A';
  3442. Code[8] = (byte)'R';
  3443. timer_500ms.Enabled = false;
  3444. if (MessageBox.Show("历史记录信息清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3445. {
  3446. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3447. {
  3448. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3449. {
  3450. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3909, Code);
  3451. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3452. }
  3453. }
  3454. }
  3455. timer_500ms.Enabled = true;
  3456. }
  3457. /// <summary>
  3458. /// 打开系统计算器
  3459. /// </summary>
  3460. /// <param name="sender"></param>
  3461. /// <param name="e"></param>
  3462. private void 计算器ToolStripMenuItem_Click(object sender, EventArgs e)
  3463. {
  3464. System.Diagnostics.Process.Start("calc.exe");
  3465. }
  3466. /// <summary>
  3467. ///故障转换和显示
  3468. /// </summary>
  3469. List<string> ErrorInfo = new List<string>{ "过流保护", "低压保护", "过压保护", "堵转保护","过热保护","速度传感器故障","力矩传感器故障","霍尔故障",
  3470. "马达缺相","NTC故障","BMS校验失败","","OBC校验失败","MCU故障","踏频传感器故障","指拨故障","MOS短路","电压异常","","","","","","","","","","","","",
  3471. "",""};
  3472. private string ErrorInfoDisplay(UInt32 Code)
  3473. {
  3474. string Result = "";
  3475. if (Code == 0)
  3476. {
  3477. Result = "无故障";
  3478. }
  3479. else
  3480. {
  3481. for (int i = 0; i < 32; i++)
  3482. {
  3483. if ((Code & 0x01) == 0x01)
  3484. {
  3485. Result += ErrorInfo[i] + " ";
  3486. }
  3487. Code >>= 1;
  3488. }
  3489. }
  3490. return Result;
  3491. }
  3492. /// <summary>
  3493. /// 鼠标滑过故障码显示具体内容
  3494. /// </summary>
  3495. /// <param name="sender"></param>
  3496. /// <param name="e"></param>
  3497. private void textBox_ErrorCode_MouseHover(object sender, EventArgs e)
  3498. {
  3499. // 创建the ToolTip
  3500. ToolTip toolTip1 = new ToolTip();
  3501. // 设置显示样式
  3502. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  3503. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  3504. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  3505. toolTip1.ShowAlways = true;//是否显示提示框
  3506. // 设置伴随的对象.
  3507. string ErrorCode = this.textBox_ErrorCode.Text;
  3508. UInt32 Code = ErrorCode.Contains("H") ? Convert.ToUInt32(ErrorCode.Split('H')[0], 16) : 0;
  3509. toolTip1.SetToolTip(this.textBox_ErrorCode, ErrorInfoDisplay(Code));//设置故障内容显示
  3510. }
  3511. /// <summary>
  3512. /// 数据记录
  3513. /// </summary>
  3514. private void RunInfoAutoSave()
  3515. {
  3516. if (运行信息记录ToolStripMenuItem.Checked == true)
  3517. {
  3518. if (RunInfoSaveFilename == string.Empty)
  3519. {
  3520. return;
  3521. }
  3522. string SaveData = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff").Replace(" ", "_") + " --> ";
  3523. foreach (Control c in tabPage_RunInfo.Controls)
  3524. {
  3525. if (c is TextBox)
  3526. {
  3527. SaveData += c.Text + " , ";
  3528. }
  3529. }
  3530. foreach (Control c in tabPage_DebugInfo.Controls)
  3531. {
  3532. if (c is TextBox)
  3533. {
  3534. SaveData += c.Text + " , ";
  3535. }
  3536. }
  3537. SaveData += "\r\n";
  3538. System.IO.File.AppendAllText(RunInfoSaveFilename, SaveData);//sb.ToString());
  3539. }
  3540. }
  3541. /// <summary>
  3542. /// 打开或关闭数据记录
  3543. /// </summary>
  3544. /// <param name="sender"></param>
  3545. /// <param name="e"></param>
  3546. private void 记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  3547. {
  3548. if (运行信息记录ToolStripMenuItem.Checked == false)
  3549. {
  3550. if (mySerialProcess.mySerial.IsOpen == true)
  3551. {
  3552. RunInfoSaveFilename = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_运行信息" + ".txt";
  3553. System.IO.File.AppendAllText(RunInfoSaveFilename, "时间 --> 车速 , 转速 , 踏频 , 力矩Reg , 力矩 , 踩踏方向 , 电压 , 电流 , 功率 , 电量 , " +
  3554. "PCB温度 , 绕组温度 , MOS温度 , 挡位 , 灯开关 , 续航 , 平均功耗 , 单次里程 , 单次时间 , 故障码 , " +
  3555. "系统状态机 , 二层状态机 , 电机状态机 , 助力状态机 , D轴电流给定 , Q轴电流给定 , D轴电压给定 , Q轴电压给定 , 瞬时力矩 , 时间滤波力矩 , 踏频滤波力矩 , D轴电流反馈 , Q轴电流反馈 , 助力函数输出" + "\r\n");
  3556. timer_500ms.Enabled = false;
  3557. MessageBoxTimeOut.Show("开始记录", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  3558. timer_500ms.Enabled = true;
  3559. 运行信息记录ToolStripMenuItem.Checked = true;
  3560. }
  3561. else
  3562. {
  3563. timer_500ms.Enabled = false;
  3564. MessageBox.Show("请连接电机", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3565. timer_500ms.Enabled = true;
  3566. }
  3567. }
  3568. else
  3569. {
  3570. 运行信息记录ToolStripMenuItem.Checked = false;
  3571. timer_500ms.Enabled = false;
  3572. MessageBoxTimeOut.Show("停止记录", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  3573. timer_500ms.Enabled = true;
  3574. }
  3575. }
  3576. /// <summary>
  3577. /// 仪表启动控制档位开关事件
  3578. /// </summary>
  3579. /// <param name="sender"></param>
  3580. /// <param name="e"></param>
  3581. private void checkBox_OBC_StartSetGearSt_CheckedChanged(object sender, EventArgs e)
  3582. {
  3583. if (checkBox_OBC_StartSetGearSt.Checked == true)
  3584. {
  3585. //检查串口是否打开
  3586. if (!mySerialProcess.mySerial.IsOpen)
  3587. {
  3588. timer_500ms.Enabled = false;
  3589. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3590. timer_500ms.Enabled = true;
  3591. checkBox_OBC_StartSetGearSt.Checked = false;
  3592. return;
  3593. }
  3594. //检查是否选择档位和打开车灯
  3595. if ((comboBox_OBC_SetGearST.SelectedIndex == -1) || (comboBox_OBC_LightSw.SelectedIndex == -1))
  3596. {
  3597. timer_500ms.Enabled = false;
  3598. MessageBox.Show("请检查档位设置和大灯开关!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3599. timer_500ms.Enabled = true;
  3600. checkBox_OBC_StartSetGearSt.Checked = false;
  3601. return;
  3602. }
  3603. }
  3604. }
  3605. /// <summary>
  3606. /// OBC查询电机用户参数
  3607. /// </summary>
  3608. /// <param name="sender"></param>
  3609. /// <param name="e"></param>
  3610. private void button_OBC_ReadUserInfo_Click(object sender, EventArgs e)
  3611. {
  3612. richTextBox_OBC_ReadUserInfo.Clear();
  3613. comboBox_OBC_BikeCCS.SelectedIndex = 0;
  3614. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3300, null);
  3615. }
  3616. /// <summary>
  3617. /// OBC设置电机用户参数
  3618. /// </summary>
  3619. /// <param name="sender"></param>
  3620. /// <param name="e"></param>
  3621. private void button_OBC_WriteUserInfo_Click(object sender, EventArgs e)
  3622. {
  3623. var UserInfoCode = new byte[8];
  3624. for (int i = 0; i < UserInfoCode.Length; i++)
  3625. UserInfoCode[i] = 0;
  3626. if (comboBox_OBC_StartMode.SelectedIndex == -1)//检查数据有效性
  3627. {
  3628. timer_500ms.Enabled = false;
  3629. MessageBox.Show("请选择启动模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3630. timer_500ms.Enabled = true;
  3631. return;
  3632. }
  3633. if (comboBox_OBC_AssistFunc.SelectedIndex == -1)//检查数据有效性
  3634. {
  3635. timer_500ms.Enabled = false;
  3636. MessageBox.Show("请选择助力方案!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3637. timer_500ms.Enabled = true;
  3638. return;
  3639. }
  3640. //周长微调
  3641. UserInfoCode[0] = (byte)(int)numericUpDown_OBC_WheelAdj.Value;
  3642. //启动模式
  3643. UserInfoCode[1] = (byte)(comboBox_OBC_StartMode.SelectedIndex + 1);
  3644. //助力方案
  3645. UserInfoCode[2] = (byte)(comboBox_OBC_AssistFunc.SelectedIndex + 1);
  3646. //自动关机时间
  3647. UserInfoCode[3] = (byte)(uint)numericUpDown_OBC_OffTime.Value;
  3648. //限速微调
  3649. UserInfoCode[4] = (byte)(int)numericUpDown_OBC_SpeedLimitAdj.Value;
  3650. //定速巡航开关
  3651. UserInfoCode[5] = (byte)((comboBox_OBC_BikeCCS.SelectedIndex == 1) ? 0xAA : 0x00);
  3652. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3408, UserInfoCode);
  3653. }
  3654. /// <summary>
  3655. /// OBC查询电机版本信息
  3656. /// </summary>
  3657. /// <param name="sender"></param>
  3658. /// <param name="e"></param>
  3659. private void button_OBC_ReadVerInfo_Click(object sender, EventArgs e)
  3660. {
  3661. textBox_Model.Text = "---";
  3662. textBox_SN.Text = "---";
  3663. textBox_HW.Text = "---";
  3664. textBox_FW.Text = "---";
  3665. textBox_SP.Text = "---";
  3666. textBox_OBC_ReadModel.Text = "---";
  3667. textBox_OBC_ReadSN.Text = "---";
  3668. textBox_OBC_ReadHW.Text = "---";
  3669. textBox_OBC_ReadFW.Text = "---";
  3670. textBox_OBC_ReadSP.Text = "---";
  3671. textBox_FacModeName.Text = "---";
  3672. textBox_FacModeNum.Text = "---";
  3673. textBox_FacModeHW.Text = "---";
  3674. textBox_FacModeFW.Text = "---";
  3675. textBox_FacModeSP.Text = "---";
  3676. Class_Motor_Ver.Mode = "---";
  3677. Class_Motor_Ver.SN = "---";
  3678. Class_Motor_Ver.HW = "---";
  3679. Class_Motor_Ver.FW = "---";
  3680. Class_Motor_Ver.Special = "---";
  3681. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  3682. }
  3683. /// <summary>
  3684. /// OBC读取骑行历史
  3685. /// </summary>
  3686. /// <param name="sender"></param>
  3687. /// <param name="e"></param>
  3688. private void button_OBC_ReadRideInfo_Click(object sender, EventArgs e)
  3689. {
  3690. textBox_OBC_TRIP_KM.Text = "";
  3691. textBox_OBC_TRIP_TIME.Text = "";
  3692. textBox_OBC_ODO_KM.Text = "";
  3693. textBox_OBC_ODO_TIME.Text = "";
  3694. textBox_ODO_KM.Text = "---";
  3695. textBox_ODO_TIME.Text = "---";
  3696. textBox_TRIP_KM.Text = "---";
  3697. textBox_TRIP_TIME.Text = "---";
  3698. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3500, null);
  3699. }
  3700. /// <summary>
  3701. /// OBC清除TRIP里程
  3702. /// </summary>
  3703. /// <param name="sender"></param>
  3704. /// <param name="e"></param>
  3705. private void button_OBC_ClearTrip_Click(object sender, EventArgs e)
  3706. {
  3707. var Code = new byte[5];
  3708. Code[0] = (byte)'C';
  3709. Code[1] = (byte)'L';
  3710. Code[2] = (byte)'E';
  3711. Code[3] = (byte)'A';
  3712. Code[4] = (byte)'R';
  3713. timer_500ms.Enabled = false;
  3714. if (MessageBox.Show("TRIP清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3715. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3605, Code);
  3716. timer_500ms.Enabled = true;
  3717. }
  3718. private void checkBox_OBC_StartReadBMS_CheckedChanged(object sender, EventArgs e)
  3719. {
  3720. if (checkBox_OBC_StartReadBMS.Checked == true)
  3721. {
  3722. //检查串口是否打开
  3723. if (!mySerialProcess.mySerial.IsOpen)
  3724. {
  3725. timer_500ms.Enabled = false;
  3726. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3727. timer_500ms.Enabled = true;
  3728. checkBox_OBC_StartReadBMS.Checked = false;
  3729. return;
  3730. }
  3731. }
  3732. }
  3733. /// <summary>
  3734. /// 写入力矩传感器参数
  3735. /// </summary>
  3736. /// <param name="sender"></param>
  3737. /// <param name="e"></param>
  3738. private void button_WriteTqSensorParam_Click(object sender, EventArgs e)
  3739. {
  3740. var ConfigParam = new byte[46];
  3741. for (int i = 0; i < 14; i++)
  3742. ConfigParam[i] = 0;
  3743. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  3744. ushort uwDataTemp = 0;
  3745. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  3746. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  3747. int index = 0;
  3748. try
  3749. {
  3750. for (int i = 0; i < strDataTemp.Length; i++)
  3751. {
  3752. if (strDataTemp[i].Split('=')[0] == "第四阶段转矩点采集值")
  3753. {
  3754. index = i;
  3755. break;
  3756. }
  3757. }
  3758. for (int i = 0; i < (index + 1); i++)
  3759. {
  3760. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  3761. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3762. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3763. }
  3764. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x472E, ConfigParam);
  3765. }
  3766. catch (Exception)
  3767. {
  3768. timer_500ms.Enabled = false;
  3769. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3770. timer_500ms.Enabled = true;
  3771. }
  3772. }
  3773. /// <summary>
  3774. /// 查询存储标志
  3775. /// </summary>
  3776. /// <param name="sender"></param>
  3777. /// <param name="e"></param>
  3778. private void button_ReadSaveFlag_Click(object sender, EventArgs e)
  3779. {
  3780. radioButton_EE_SaveYes.Checked = false;
  3781. radioButton_EE_SaveNo.Checked = false;
  3782. radioButton_SIP_SaveYes.Checked = false;
  3783. radioButton_SIP_SaveNo.Checked = false;
  3784. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null);
  3785. }
  3786. /// <summary>
  3787. /// 写入存储标志
  3788. /// </summary>
  3789. /// <param name="sender"></param>
  3790. /// <param name="e"></param>
  3791. private void button_WriteSaveFlag_Click(object sender, EventArgs e)
  3792. {
  3793. var SaveFlag = new byte[6];
  3794. for (int i = 0; i < 6; i++)
  3795. SaveFlag[i] = 0;
  3796. if ((radioButton_EE_SaveYes.Checked == false) && (radioButton_EE_SaveNo.Checked == false))
  3797. {
  3798. timer_500ms.Enabled = false;
  3799. MessageBox.Show("请选择EEPROM存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3800. timer_500ms.Enabled = true;
  3801. return;
  3802. }
  3803. if ((radioButton_SIP_SaveYes.Checked == false) && (radioButton_SIP_SaveNo.Checked == false))
  3804. {
  3805. timer_500ms.Enabled = false;
  3806. MessageBox.Show("请选择SIP校验存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3807. timer_500ms.Enabled = true;
  3808. return;
  3809. }
  3810. SaveFlag[0] = (byte)((checkBox_SaveYes.Checked) ? 0x01 : 0x00);
  3811. SaveFlag[2] = (byte)(radioButton_EE_SaveYes.Checked ? 0x01 : 0x00);
  3812. SaveFlag[3] = 0;
  3813. SaveFlag[4] = (byte)(radioButton_SIP_SaveYes.Checked ? 0x01 : 0x00);
  3814. SaveFlag[5] = 0;
  3815. timer_500ms.Enabled = false;
  3816. if (MessageBox.Show("确认修改存储标志?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3817. {
  3818. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4906, SaveFlag);
  3819. }
  3820. timer_500ms.Enabled = true;
  3821. }
  3822. /// <summary>
  3823. /// 读取指定地址数据
  3824. /// </summary>
  3825. /// <param name="sender"></param>
  3826. /// <param name="e"></param>
  3827. private void button_ReadRamFlash_Click(object sender, EventArgs e)
  3828. {
  3829. var Address = new byte[4];
  3830. UInt32 Address_Begin;
  3831. UInt32 Addres_End;
  3832. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  3833. richTextBox_RamFlasgData.Clear();
  3834. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  3835. {
  3836. timer_500ms.Enabled = false;
  3837. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3838. timer_500ms.Enabled = true;
  3839. return;
  3840. }
  3841. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  3842. {
  3843. timer_500ms.Enabled = false;
  3844. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3845. timer_500ms.Enabled = true;
  3846. return;
  3847. }
  3848. else
  3849. {
  3850. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  3851. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  3852. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  3853. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  3854. if (Addres_End < Address_Begin)
  3855. {
  3856. timer_500ms.Enabled = false;
  3857. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3858. timer_500ms.Enabled = true;
  3859. return;
  3860. }
  3861. else
  3862. {
  3863. var SendByte = new byte[8];
  3864. SendByte[0] = (byte)(Address_Begin >> 24);
  3865. SendByte[1] = (byte)(Address_Begin >> 16);
  3866. SendByte[2] = (byte)(Address_Begin >> 8);
  3867. SendByte[3] = (byte)(Address_Begin);
  3868. SendByte[4] = (byte)(Addres_End >> 24);
  3869. SendByte[5] = (byte)(Addres_End >> 16);
  3870. SendByte[6] = (byte)(Addres_End >> 8);
  3871. SendByte[7] = (byte)(Addres_End);
  3872. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  3873. }
  3874. }
  3875. }
  3876. /// <summary>
  3877. /// 工作模式选择
  3878. /// </summary>
  3879. /// <param name="sender"></param>
  3880. /// <param name="e"></param>
  3881. private void comboBox_WorkMode_SelectedIndexChanged(object sender, EventArgs e)
  3882. {
  3883. var RunMode = new byte[1];
  3884. if (comboBox_WorkMode.Text == "配置模式")
  3885. RunMode[0] = 0x01;
  3886. else if (comboBox_WorkMode.Text == "调试模式")
  3887. RunMode[0] = 0x02;
  3888. else
  3889. RunMode[0] = 0x00;
  3890. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  3891. }
  3892. /// <summary>
  3893. /// 助力档位选择
  3894. /// </summary>
  3895. /// <param name="sender"></param>
  3896. /// <param name="e"></param>
  3897. private void comboBox_GearSt_SelectedIndexChanged(object sender, EventArgs e)
  3898. {
  3899. var CtrlCode = new byte[2];
  3900. if (comboBox_GearSt.SelectedIndex == 5)//档位
  3901. CtrlCode[0] = 0x33;
  3902. else if (comboBox_GearSt.SelectedIndex == 6)//档位
  3903. CtrlCode[0] = 0x22;
  3904. else
  3905. CtrlCode[0] = (byte)comboBox_GearSt.SelectedIndex;
  3906. if (comboBox_LightSwitch.SelectedIndex == 0)//车灯
  3907. CtrlCode[1] = 0xF1;
  3908. else
  3909. CtrlCode[1] = 0xF0;
  3910. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
  3911. comboBox_OBC_SetGearST.SelectedIndex = comboBox_GearSt.SelectedIndex;
  3912. comboBox_OBC_LightSw.SelectedIndex = comboBox_LightSwitch.SelectedIndex;
  3913. Delay_ms(500);
  3914. //设置百分比
  3915. do
  3916. {
  3917. var PercentCode = new byte[1];
  3918. if (comboBox_GearSt.SelectedIndex == 0) //Off
  3919. {
  3920. PercentCode[0] = 0;
  3921. textBox_MotorSpeedPercent.Text = "0";
  3922. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, PercentCode);
  3923. }
  3924. else if (comboBox_GearSt.SelectedIndex == 6) //Walk
  3925. {
  3926. if (comboBox_WorkMode.SelectedIndex != 0)
  3927. {
  3928. PercentCode[0] = 100;
  3929. textBox_MotorSpeedPercent.Text = "100";
  3930. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, PercentCode);
  3931. }
  3932. }
  3933. } while (false);
  3934. }
  3935. /// <summary>
  3936. /// 仪表档位选择
  3937. /// </summary>
  3938. /// <param name="sender"></param>
  3939. /// <param name="e"></param>
  3940. private void comboBox_OBC_SetGearST_SelectedIndexChanged(object sender, EventArgs e)
  3941. {
  3942. comboBox_GearSt.SelectedIndex = comboBox_OBC_SetGearST.SelectedIndex;
  3943. comboBox_LightSwitch.SelectedIndex = comboBox_OBC_LightSw.SelectedIndex;
  3944. }
  3945. /// <summary>
  3946. /// 生产模式初始化
  3947. /// </summary>
  3948. /// <param name="sender"></param>
  3949. /// <param name="e"></param>
  3950. private void button_FacModeInit_Click(object sender, EventArgs e)
  3951. {
  3952. var Code = new byte[5];
  3953. Code[0] = (byte)'C';
  3954. Code[1] = (byte)'L';
  3955. Code[2] = (byte)'E';
  3956. Code[3] = (byte)'A';
  3957. Code[4] = (byte)'R';
  3958. timer_500ms.Enabled = false;
  3959. if (MessageBox.Show("电机即将初始化!", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3960. {
  3961. if (MessageBox.Show("请再次确认", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3962. {
  3963. timer_500ms.Enabled = true;
  3964. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  3965. PowerOffAckStatus = false;
  3966. Delay_ms(250);
  3967. int TryCnt = 3;
  3968. while ((TryCnt--) >= 0)
  3969. {
  3970. if (!PowerOffAckStatus)
  3971. {
  3972. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  3973. PowerOffAckStatus = false;
  3974. Delay_ms(250);
  3975. }
  3976. else break;
  3977. }
  3978. if (PowerOffAckStatus)
  3979. {
  3980. timer_500ms.Enabled = false;
  3981. MessageBox.Show("系统已关机,请保持无负载重新开机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  3982. timer_500ms.Enabled = true;
  3983. }
  3984. else
  3985. {
  3986. timer_500ms.Enabled = false;
  3987. MessageBox.Show("初始化失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3988. timer_500ms.Enabled = true;
  3989. }
  3990. timer_500ms.Enabled = true;
  3991. }
  3992. }
  3993. timer_500ms.Enabled = true;
  3994. //清除历史测试记录
  3995. textBox_FacModeSensorADC0.Text = "";
  3996. textBox_FacModeSensorADC1.Text = "";
  3997. textBox_FacModeSensorADC2.Text = "";
  3998. textBox_FacModeSensorADC3.Text = "";
  3999. textBox_FacModeSensorADC4.Text = "";
  4000. LightSwitchStatus = false;
  4001. MotorRunStatus = false;
  4002. textBox_MotorSpeedPercent.Text = "5";
  4003. textBox_FacModeName.Text = "";
  4004. textBox_FacModeNum.Text = "";
  4005. textBox_FacModeHW.Text = "";
  4006. textBox_FacModeFW.Text = "";
  4007. }
  4008. /// <summary>
  4009. /// 生产模式读取传感器参数
  4010. /// </summary>
  4011. /// <param name="sender"></param>
  4012. /// <param name="e"></param>
  4013. private void button_FacModeSensorRead_Click(object sender, EventArgs e)
  4014. {
  4015. richTextBox_SensorParam.Clear();
  4016. textBox_FacModeSensorADC0.Text = "";
  4017. textBox_FacModeSensorADC1.Text = "";
  4018. textBox_FacModeSensorADC2.Text = "";
  4019. textBox_FacModeSensorADC3.Text = "";
  4020. textBox_FacModeSensorADC4.Text = "";
  4021. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4022. }
  4023. /// <summary>
  4024. /// 生产模式传感器标定1
  4025. /// </summary>
  4026. /// <param name="sender"></param>
  4027. /// <param name="e"></param>
  4028. private void buttonFacModeSet1_Click(object sender, EventArgs e)
  4029. {
  4030. var ConfigParam = new byte[4];
  4031. for (int i = 0; i < 4; i++)
  4032. ConfigParam[i] = 0;
  4033. ushort uwDataTemp = 0;
  4034. try
  4035. {
  4036. uwDataTemp = 1;//负载序号
  4037. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4038. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4039. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal1.Text) * 10); ;//负载值0.1Nm
  4040. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4041. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4042. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4043. Delay_ms(200);
  4044. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4045. }
  4046. catch (Exception)
  4047. {
  4048. timer_500ms.Enabled = false;
  4049. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4050. timer_500ms.Enabled = true;
  4051. }
  4052. }
  4053. /// <summary>
  4054. /// 生产模式传感器标定2
  4055. /// </summary>
  4056. /// <param name="sender"></param>
  4057. /// <param name="e"></param>
  4058. private void buttonFacModeSet2_Click(object sender, EventArgs e)
  4059. {
  4060. var ConfigParam = new byte[4];
  4061. for (int i = 0; i < 4; i++)
  4062. ConfigParam[i] = 0;
  4063. ushort uwDataTemp = 0;
  4064. try
  4065. {
  4066. uwDataTemp = 2;//负载序号
  4067. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4068. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4069. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal2.Text) * 10); ;//负载值0.1Nm
  4070. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4071. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4072. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4073. Delay_ms(200);
  4074. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4075. }
  4076. catch (Exception)
  4077. {
  4078. timer_500ms.Enabled = false;
  4079. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4080. timer_500ms.Enabled = true;
  4081. }
  4082. }
  4083. /// <summary>
  4084. /// 生产模式传感器标定3
  4085. /// </summary>
  4086. /// <param name="sender"></param>
  4087. /// <param name="e"></param>
  4088. private void buttonFacModeSet3_Click(object sender, EventArgs e)
  4089. {
  4090. var ConfigParam = new byte[4];
  4091. for (int i = 0; i < 4; i++)
  4092. ConfigParam[i] = 0;
  4093. ushort uwDataTemp = 0;
  4094. try
  4095. {
  4096. uwDataTemp = 3;//负载序号
  4097. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4098. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4099. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal3.Text) * 10); ;//负载值0.1Nm
  4100. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4101. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4102. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4103. Delay_ms(200);
  4104. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4105. }
  4106. catch (Exception)
  4107. {
  4108. timer_500ms.Enabled = false;
  4109. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4110. timer_500ms.Enabled = true;
  4111. }
  4112. }
  4113. /// <summary>
  4114. /// 生产模式传感器标定3
  4115. /// </summary>
  4116. /// <param name="sender"></param>
  4117. /// <param name="e"></param>
  4118. private void buttonFacModeSet4_Click(object sender, EventArgs e)
  4119. {
  4120. var ConfigParam = new byte[4];
  4121. for (int i = 0; i < 4; i++)
  4122. ConfigParam[i] = 0;
  4123. ushort uwDataTemp = 0;
  4124. try
  4125. {
  4126. uwDataTemp = 4;//负载序号
  4127. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4128. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4129. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal4.Text) * 10); ;//负载值0.1Nm
  4130. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4131. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4132. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4133. Delay_ms(200);
  4134. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4135. }
  4136. catch (Exception)
  4137. {
  4138. timer_500ms.Enabled = false;
  4139. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4140. timer_500ms.Enabled = true;
  4141. }
  4142. }
  4143. /// <summary>
  4144. /// 生产模式开关灯
  4145. /// </summary>
  4146. /// <param name="sender"></param>
  4147. /// <param name="e"></param>
  4148. bool LightSwitchStatus = false;
  4149. private void button_FacModeLightSW_Click(object sender, EventArgs e)
  4150. {
  4151. var CtrlCode = new byte[2];
  4152. CtrlCode[0] = 0x00;
  4153. if (LightSwitchStatus)
  4154. {
  4155. CtrlCode[1] = 0xF0;
  4156. button_FacModeLightSW.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(128)))));
  4157. }
  4158. else
  4159. {
  4160. CtrlCode[1] = 0xF1;
  4161. button_FacModeLightSW.BackColor = Color.Yellow;
  4162. }
  4163. if (mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode))
  4164. {
  4165. LightSwitchStatus = !LightSwitchStatus;
  4166. comboBox_LightSwitch.SelectedIndex = LightSwitchStatus ? 0 : 1;
  4167. comboBox_OBC_LightSw.SelectedIndex = LightSwitchStatus ? 0 : 1;
  4168. }
  4169. }
  4170. /// <summary>
  4171. /// 生产模式电机控制
  4172. /// </summary>
  4173. /// <param name="sender"></param>
  4174. /// <param name="e"></param>
  4175. bool MotorRunStatus = false;
  4176. private void button_FacModeMotorRun_Click(object sender, EventArgs e)
  4177. {
  4178. string DebugDefaultInfo = "";
  4179. //获取调试信息
  4180. if (richTextBox_DebugParam.Text == string.Empty)
  4181. {
  4182. richTextBox_DebugParam.Clear();
  4183. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  4184. }
  4185. Delay_ms(200);
  4186. DebugDefaultInfo = richTextBox_DebugParam.Text;
  4187. //获取参数
  4188. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  4189. if (strDataTemp.Length != 29)
  4190. {
  4191. timer_500ms.Enabled = false;
  4192. MessageBox.Show("数据格式不正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4193. timer_500ms.Enabled = true;
  4194. return;
  4195. }
  4196. //设置参数
  4197. var ConfigParam = new byte[60];
  4198. for (int i = 0; i < 60; i++)
  4199. ConfigParam[i] = 0;
  4200. ConfigParam[0] = 0x00;
  4201. ushort uwDataTemp = 0;
  4202. if (!MotorRunStatus) //停止状态
  4203. {
  4204. //设置速度环
  4205. strDataTemp[0] = "整体运行模式=3";
  4206. //发送数据
  4207. try
  4208. {
  4209. for (int i = 0; i < strDataTemp.Length; i++)
  4210. {
  4211. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  4212. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  4213. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  4214. }
  4215. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  4216. return;
  4217. }
  4218. catch (Exception)
  4219. {
  4220. timer_500ms.Enabled = false;
  4221. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4222. timer_500ms.Enabled = true;
  4223. }
  4224. Delay_ms(200);
  4225. //设置转速百分比100%
  4226. textBox_MotorSpeedPercent.Text = "100";
  4227. ConfigParam[0] = (byte)100;
  4228. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, ConfigParam);
  4229. MotorRunStatus = !MotorRunStatus;
  4230. button_FacModeMotorRun.BackColor = Color.Yellow;
  4231. Delay_ms(200);
  4232. //电机进入配置模式
  4233. var RunMode = new byte[1];
  4234. RunMode[0] = 0x01;
  4235. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  4236. }
  4237. else //运转状态
  4238. {
  4239. //设置转速百分比0%
  4240. textBox_MotorSpeedPercent.Text = "0";
  4241. ConfigParam[0] = (byte)0;
  4242. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, ConfigParam);
  4243. MotorRunStatus = !MotorRunStatus;
  4244. button_FacModeMotorRun.BackColor = Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
  4245. Delay_ms(200);
  4246. //还原为原始值
  4247. strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  4248. try
  4249. {
  4250. for (int i = 0; i < strDataTemp.Length; i++)
  4251. {
  4252. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  4253. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  4254. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  4255. }
  4256. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  4257. return;
  4258. }
  4259. catch (Exception)
  4260. {
  4261. timer_500ms.Enabled = false;
  4262. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4263. timer_500ms.Enabled = true;
  4264. }
  4265. Delay_ms(200);
  4266. //电机退出配置模式
  4267. var RunMode = new byte[1];
  4268. RunMode[0] = 0x00;
  4269. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  4270. }
  4271. }
  4272. /// <summary>
  4273. /// 生产模式写入型号
  4274. /// </summary>
  4275. /// <param name="sender"></param>
  4276. /// <param name="e"></param>
  4277. private void button_FacModeSetName_Click(object sender, EventArgs e)
  4278. {
  4279. string Mode = textBox_FacModeName.Text;
  4280. var ModeArray = new byte[16];
  4281. for (ushort i = 0; i < Mode.Length; i++)
  4282. {
  4283. ModeArray[i] = (byte)Mode[i];
  4284. }
  4285. if (Mode.Length < 16)
  4286. {
  4287. ModeArray[Mode.Length] = (byte)'.';
  4288. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  4289. {
  4290. ModeArray[Mode.Length + 1 + i] = 0x20;
  4291. }
  4292. }
  4293. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  4294. }
  4295. /// <summary>
  4296. /// 生产模式写入SN
  4297. /// </summary>
  4298. /// <param name="sender"></param>
  4299. /// <param name="e"></param>
  4300. private void Button_FacModeSetNum_Click(object sender, EventArgs e)
  4301. {
  4302. string SN = textBox_FacModeNum.Text;
  4303. var SNArray = new byte[16];
  4304. for (ushort i = 0; i < SN.Length; i++)
  4305. {
  4306. SNArray[i] = (byte)SN[i];
  4307. }
  4308. if (SN.Length < 16)
  4309. {
  4310. SNArray[SN.Length] = (byte)'.';
  4311. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  4312. {
  4313. SNArray[SN.Length + 1 + i] = 0x20;
  4314. }
  4315. }
  4316. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  4317. }
  4318. /// <summary>
  4319. /// 生产模式读取版本信息
  4320. /// </summary>
  4321. /// <param name="sender"></param>
  4322. /// <param name="e"></param>
  4323. private void Button_FacModeReadVer_Click_1(object sender, EventArgs e)
  4324. {
  4325. textBox_Model.Text = "---";
  4326. textBox_SN.Text = "---";
  4327. textBox_HW.Text = "---";
  4328. textBox_FW.Text = "---";
  4329. textBox_SP.Text = "---";
  4330. textBox_OBC_ReadModel.Text = "---";
  4331. textBox_OBC_ReadSN.Text = "---";
  4332. textBox_OBC_ReadHW.Text = "---";
  4333. textBox_OBC_ReadFW.Text = "---";
  4334. textBox_OBC_ReadSP.Text = "---";
  4335. textBox_FacModeName.Text = "---";
  4336. textBox_FacModeNum.Text = "---";
  4337. textBox_FacModeHW.Text = "---";
  4338. textBox_FacModeFW.Text = "---";
  4339. textBox_FacModeSP.Text = "---";
  4340. textBox_FacModeGit.Text = "---";
  4341. Class_Motor_Ver.Mode = "---";
  4342. Class_Motor_Ver.SN = "---";
  4343. Class_Motor_Ver.HW = "---";
  4344. Class_Motor_Ver.FW = "---";
  4345. Class_Motor_Ver.Special = "---";
  4346. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  4347. }
  4348. /// <summary>
  4349. /// 生产模式写入生产信息
  4350. /// </summary>
  4351. /// <param name="sender"></param>
  4352. /// <param name="e"></param>
  4353. private void Button_FacModeSetMacDate_Click(object sender, EventArgs e)
  4354. {
  4355. var MACArray = new byte[32];
  4356. string MacDefaultInfo = "";
  4357. string MacAddDefaultInfo = "";
  4358. string MacDateDefaultInfo = DateTime.Now.ToString("yyyyMMdd");
  4359. string MacPPDefaultInfo = "";
  4360. do
  4361. {
  4362. //填入生产商
  4363. if (toolStripTextBox_MAC.Text == string.Empty)
  4364. {
  4365. break;
  4366. }
  4367. MacDefaultInfo = toolStripTextBox_MAC.Text;
  4368. for (ushort i = 0; i < MacDefaultInfo.Length; i++)
  4369. {
  4370. MACArray[i] = (byte)MacDefaultInfo[i];
  4371. }
  4372. if (MacDefaultInfo.Length < 8)
  4373. {
  4374. MACArray[MacDefaultInfo.Length] = (byte)'.';
  4375. for (ushort i = 0; i < 8 - MacDefaultInfo.Length - 1; i++)
  4376. {
  4377. MACArray[MacDefaultInfo.Length + 1 + i] = 0x20;
  4378. }
  4379. }
  4380. //填入生产地
  4381. if (toolStripTextBoxMACAddr.Text == string.Empty)
  4382. {
  4383. break;
  4384. }
  4385. MacAddDefaultInfo = toolStripTextBoxMACAddr.Text;
  4386. for (ushort i = 0; i < MacAddDefaultInfo.Length; i++)
  4387. {
  4388. MACArray[8 + i] = (byte)MacAddDefaultInfo[i];
  4389. }
  4390. if (MacAddDefaultInfo.Length < 8)
  4391. {
  4392. MACArray[MacAddDefaultInfo.Length + 8] = (byte)'.';
  4393. for (ushort i = 0; i < 8 - MacAddDefaultInfo.Length - 1; i++)
  4394. {
  4395. MACArray[MacAddDefaultInfo.Length + 1 + i + 8] = 0x20;
  4396. }
  4397. }
  4398. //填入生产日期
  4399. if (toolStripTextBox_MACDate.Text == string.Empty)
  4400. {
  4401. break;
  4402. }
  4403. MacDateDefaultInfo = toolStripTextBox_MACDate.Text;
  4404. for (ushort i = 0; i < MacDateDefaultInfo.Length; i++)
  4405. {
  4406. MACArray[16 + i] = (byte)MacDateDefaultInfo[i];
  4407. }
  4408. if (MacDateDefaultInfo.Length < 8)
  4409. {
  4410. MACArray[MacDateDefaultInfo.Length + 16] = (byte)'.';
  4411. for (ushort i = 0; i < 8 - MacDateDefaultInfo.Length - 1; i++)
  4412. {
  4413. MACArray[MacDateDefaultInfo.Length + 1 + i + 16] = 0x20;
  4414. }
  4415. }
  4416. //填入产品标识
  4417. if (toolStripTextBox_MACPD.Text == string.Empty)
  4418. {
  4419. break;
  4420. }
  4421. MacPPDefaultInfo = toolStripTextBox_MACPD.Text;
  4422. for (ushort i = 0; i < MacPPDefaultInfo.Length; i++)
  4423. {
  4424. MACArray[24 + i] = (byte)MacPPDefaultInfo[i];
  4425. }
  4426. if (MacPPDefaultInfo.Length < 8)
  4427. {
  4428. MACArray[MacPPDefaultInfo.Length + 24] = (byte)'.';
  4429. for (ushort i = 0; i < 8 - MacPPDefaultInfo.Length - 1; i++)
  4430. {
  4431. MACArray[MacPPDefaultInfo.Length + 1 + i + 24] = 0x20;
  4432. }
  4433. }
  4434. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  4435. return;
  4436. } while (false);
  4437. timer_500ms.Enabled = false;
  4438. MessageBox.Show("生产信息配置不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4439. timer_500ms.Enabled = true;
  4440. }
  4441. /// <summary>
  4442. /// 生产模式保存测试页面
  4443. /// </summary>
  4444. /// <param name="sender"></param>
  4445. /// <param name="e"></param>
  4446. private void Button_FacModeSaveResult_Click(object sender, EventArgs e)
  4447. {
  4448. Button_FacModeSaveResult.Text = "存储中…";
  4449. string[] AssistParams = new string[15];
  4450. do
  4451. {
  4452. //读取一次马达参数
  4453. richTextBox_MotorParam.Clear();
  4454. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break; ;
  4455. Delay_ms(100);
  4456. //读取一次整车参数
  4457. richTextBox_BikeParam.Clear();
  4458. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  4459. Delay_ms(100);
  4460. //读取一次整车参数2
  4461. richTextBox_BikeParam2.Clear();
  4462. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null)) break;
  4463. Delay_ms(100);
  4464. //读取一次控制参数
  4465. richTextBox_ControlParam.Clear();
  4466. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  4467. Delay_ms(100);
  4468. //查询传感器
  4469. richTextBox_SensorParam.Clear();
  4470. textBox_FacModeSensorADC0.Text = "";
  4471. textBox_FacModeSensorADC1.Text = "";
  4472. textBox_FacModeSensorADC2.Text = "";
  4473. textBox_FacModeSensorADC3.Text = "";
  4474. textBox_FacModeSensorADC4.Text = "";
  4475. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  4476. Delay_ms(100);
  4477. //读取15次助力参数
  4478. for (int i = 1; i <= 15; i++)
  4479. {
  4480. var ConfigParam = new byte[4];
  4481. richTextBox_AssistParam.Clear();
  4482. ConfigParam[0] = (byte)(i & 0xFF);
  4483. ConfigParam[1] = (byte)(i >> 8);
  4484. ConfigParam[2] = (byte)(((i >= 5) ? 5 : i) & 0xFF);
  4485. ConfigParam[3] = (byte)(((i >= 5) ? 5 : i) >> 8);
  4486. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  4487. Delay_ms(200);
  4488. AssistParams[i - 1] = richTextBox_AssistParam.Text + "\r\n";
  4489. }
  4490. //读取一次用户骑行参数
  4491. richTextBox_UsrRidesParam.Clear();
  4492. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  4493. Delay_ms(100);
  4494. //读取一次调试信息
  4495. richTextBox_DebugParam.Clear();
  4496. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  4497. Delay_ms(100);
  4498. //读取一次历史信息
  4499. richTextBox_Record.Clear();
  4500. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  4501. Delay_ms(100);
  4502. //读取一次电机运行信息
  4503. var CtrlCode = new byte[2];
  4504. CtrlCode[0] = 0x00;
  4505. CtrlCode[1] = 0xF0;
  4506. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode)) break;
  4507. Delay_ms(100);
  4508. //读取一次版本信息
  4509. textBox_Model.Text = "---";
  4510. textBox_SN.Text = "---";
  4511. textBox_HW.Text = "---";
  4512. textBox_FW.Text = "---";
  4513. textBox_OBC_ReadModel.Text = "---";
  4514. textBox_OBC_ReadSN.Text = "---";
  4515. textBox_OBC_ReadHW.Text = "---";
  4516. textBox_OBC_ReadFW.Text = "---";
  4517. textBox_FacModeName.Text = "---";
  4518. textBox_FacModeNum.Text = "---";
  4519. textBox_FacModeHW.Text = "---";
  4520. textBox_FacModeFW.Text = "---";
  4521. Class_Motor_Ver.Mode = "---";
  4522. Class_Motor_Ver.SN = "---";
  4523. Class_Motor_Ver.HW = "---";
  4524. Class_Motor_Ver.FW = "---";
  4525. Class_Motor_Ver.Special = "---";
  4526. if (!mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null)) break;
  4527. Delay_ms(100);
  4528. //读取一次生产信息
  4529. textBox_MAC.Text = "";
  4530. textBox_MACAdd.Text = "";
  4531. textBox_MACDate.Text = "";
  4532. textBox_PP.Text = "";
  4533. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  4534. Delay_ms(100);
  4535. //读取一次自定义信息
  4536. textBox_User1.Text = "---";
  4537. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  4538. Delay_ms(100);
  4539. textBox_User2.Text = "---";
  4540. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  4541. Delay_ms(100);
  4542. textBox_User3.Text = "---";
  4543. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  4544. Delay_ms(100);
  4545. //读取一次密钥
  4546. textBox_Key.Text = "---";
  4547. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  4548. Delay_ms(100);
  4549. //读取一次存储标志
  4550. radioButton_EE_SaveYes.Checked = false;
  4551. radioButton_EE_SaveNo.Checked = false;
  4552. radioButton_SIP_SaveYes.Checked = false;
  4553. radioButton_SIP_SaveNo.Checked = false;
  4554. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  4555. Delay_ms(100);
  4556. //读取一次MOS内阻校准参数
  4557. foreach (Control c in groupBox21.Controls)
  4558. {
  4559. if (c is TextBox)
  4560. c.Text = "";
  4561. }
  4562. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  4563. Delay_ms(100);
  4564. //提示检查
  4565. #if false
  4566. timer_1s.Enabled = false;
  4567. if (MessageBox.Show("请检查信息是否完整!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  4568. {
  4569. MessageBox.Show("请检查参数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4570. timer_1s.Enabled = true;
  4571. return;
  4572. }
  4573. timer_1s.Enabled = true;
  4574. Delay_ms(200);
  4575. #endif
  4576. //判断数据是否有效
  4577. if ((textBox_FacModeName.Text == "---") || (textBox_FacModeNum.Text == "---"))
  4578. {
  4579. MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4580. break;
  4581. }
  4582. if ((textBox_FacModeName.Text == string.Empty) || (textBox_FacModeNum.Text == string.Empty))
  4583. {
  4584. MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4585. break;
  4586. }
  4587. //设置文件存储路径
  4588. string Save_Path = localInfo.LocalPath + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
  4589. string PD_PathName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_"); ;
  4590. Save_Path += PD_PathName;
  4591. if (!Directory.Exists(Save_Path))
  4592. Directory.CreateDirectory(Save_Path);
  4593. //保存页面
  4594. string PIC_SaveFileName = "";
  4595. Double scaleX = PrimaryScreen.ScaleX;
  4596. Double scaleY = PrimaryScreen.ScaleY;
  4597. //保存页面
  4598. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  4599. Graphics g = Graphics.FromImage(bit);
  4600. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  4601. PIC_SaveFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_测试页面" + ".png";
  4602. bit.Save(PIC_SaveFileName);
  4603. //保存数据
  4604. string DataFileName = "";
  4605. string FileInfo = "";
  4606. DataFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_记录数据" + ".txt";
  4607. FileInfo += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  4608. FileInfo += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  4609. FileInfo += "\r\n";
  4610. FileInfo += "[电机信息]\r\n";
  4611. FileInfo += "电机型号: " + textBox_FacModeName.Text + "\r\n";
  4612. FileInfo += "电机编号: " + textBox_FacModeNum.Text + "\r\n";
  4613. FileInfo += "硬件版本: " + textBox_HW.Text + "\r\n";
  4614. FileInfo += "软件版本: " + textBox_FW.Text + "\r\n";
  4615. FileInfo += "软件标识: " + textBox_SP.Text + "\r\n";
  4616. FileInfo += "Git信息: " + textBox_FacModeGit.Text + "\r\n";
  4617. FileInfo += "\r\n";
  4618. FileInfo += "[马达参数]\r\n";
  4619. FileInfo += richTextBox_MotorParam.Text + "\r\n";
  4620. FileInfo += "\r\n";
  4621. FileInfo += "[整车参数]\r\n";
  4622. FileInfo += richTextBox_BikeParam.Text + "\r\n";
  4623. FileInfo += "\r\n";
  4624. FileInfo += "[控制参数]\r\n";
  4625. FileInfo += richTextBox_ControlParam.Text + "\r\n";
  4626. FileInfo += "\r\n";
  4627. FileInfo += "[传感器参数]\r\n";
  4628. FileInfo += richTextBox_SensorParam.Text + "\r\n";
  4629. FileInfo += "\r\n";
  4630. FileInfo += "[助力参数]\r\n";
  4631. for(int i=0;i<15;i++)
  4632. {
  4633. FileInfo += AssistParams[i] + "\r\n";
  4634. }
  4635. FileInfo += "[调试参数]\r\n";
  4636. FileInfo += richTextBox_DebugParam.Text + "\r\n";
  4637. FileInfo += "\r\n";
  4638. FileInfo += "[历史信息]\r\n";
  4639. FileInfo += richTextBox_Record.Text + "\r\n";
  4640. FileInfo += "\r\n";
  4641. FileInfo += "[MOS内阻校准参数]\r\n";
  4642. FileInfo += textBox_MOS_K1.Text + ", ";
  4643. FileInfo += textBox_MOS_K2.Text + ", ";
  4644. FileInfo += textBox_MOS_K3.Text + ", ";
  4645. FileInfo += textBox_MOS_K4.Text + ", ";
  4646. FileInfo += textBox_MOS_K5.Text + ", ";
  4647. FileInfo += textBox_MOS_R1.Text + ", ";
  4648. FileInfo += textBox_MOS_R2.Text + ", ";
  4649. FileInfo += textBox_MOS_R3.Text + "\r\n";
  4650. FileInfo += "\r\n";
  4651. FileInfo += "[整车参数2]\r\n";
  4652. FileInfo += richTextBox_BikeParam2.Text + "\r\n";
  4653. FileInfo += "\r\n";
  4654. FileInfo += "[用户骑行参数]\r\n";
  4655. FileInfo += richTextBox_UsrRidesParam.Text + "\r\n";
  4656. FileInfo += "\r\n";
  4657. FileInfo += "[生产信息]\r\n";
  4658. FileInfo += "生产商: " + textBox_MAC.Text + "\r\n";
  4659. FileInfo += "生产地: " + textBox_MACAdd.Text + "\r\n";
  4660. FileInfo += "生产日期: " + textBox_MACDate.Text + "\r\n";
  4661. FileInfo += "产品标识: " + textBox_PP.Text + "\r\n";
  4662. FileInfo += "\r\n";
  4663. FileInfo += "[自定义信息]\r\n";
  4664. FileInfo += "自定义1: " + textBox_User1.Text + "\r\n";
  4665. FileInfo += "自定义2: " + textBox_User2.Text + "\r\n";
  4666. FileInfo += "自定义3: " + textBox_User3.Text + "\r\n";
  4667. FileInfo += "\r\n";
  4668. FileInfo += "[校验密钥]\r\n";
  4669. FileInfo += textBox_Key.Text + "\r\n";
  4670. FileInfo += "\r\n";
  4671. FileInfo += "[存储标志]\r\n";
  4672. FileInfo += "EEPROM: " + ((radioButton_EE_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  4673. FileInfo += "SIP: " + ((radioButton_SIP_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  4674. FileInfo += "\r\n";
  4675. FileInfo += Local_HdInformation;
  4676. FileInfo += "\r\n";
  4677. FileInfo += "文件格式: V2.0\r\n";
  4678. System.IO.File.WriteAllText(DataFileName, FileInfo);
  4679. Delay_ms(1000);
  4680. timer_500ms.Enabled = false;
  4681. MessageBox.Show("存储完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  4682. timer_500ms.Enabled = true;
  4683. //数据上传
  4684. if (myFtp.IsNetConnected == true)
  4685. {
  4686. string DataNow = DateTime.Now.ToString("yyyy-MM-dd");
  4687. //检查路径
  4688. if (myFtp.DirectoryExist("\\", toolStripTextBox_ServerPath.Text) == false)
  4689. {
  4690. myFtp.MakeDir(toolStripTextBox_ServerPath.Text);
  4691. }
  4692. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text, "Samples") == false)
  4693. {
  4694. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples");
  4695. }
  4696. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples", DataNow) == false)
  4697. {
  4698. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow);
  4699. }
  4700. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow, PD_PathName) == false)
  4701. {
  4702. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4703. }
  4704. //上传文件
  4705. bool result1 = myFtp.UploadFile(PIC_SaveFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4706. bool result2 = myFtp.UploadFile(DataFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4707. if ((result1 & result2) == true)
  4708. {
  4709. timer_500ms.Enabled = false;
  4710. MessageBoxTimeOut.Show("数据已上传!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  4711. timer_500ms.Enabled = true;
  4712. }
  4713. else
  4714. {
  4715. timer_500ms.Enabled = false;
  4716. MessageBox.Show("数据上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4717. timer_500ms.Enabled = true;
  4718. }
  4719. }
  4720. else
  4721. {
  4722. timer_500ms.Enabled = false;
  4723. MessageBox.Show("服务器断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4724. timer_500ms.Enabled = true;
  4725. }
  4726. Button_FacModeSaveResult.Text = "保存数据";
  4727. return;
  4728. } while (false);
  4729. timer_500ms.Enabled = false;
  4730. MessageBox.Show("保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4731. timer_500ms.Enabled = true;
  4732. Button_FacModeSaveResult.Text = "保存数据";
  4733. }
  4734. /// <summary>
  4735. /// 工具箱页面保存
  4736. /// </summary>
  4737. /// <param name="sender"></param>
  4738. /// <param name="e"></param>
  4739. private void 页面保存ToolStripMenuItem_Click(object sender, EventArgs e)
  4740. {
  4741. Double scaleX = PrimaryScreen.ScaleX;
  4742. Double scaleY = PrimaryScreen.ScaleY;
  4743. //保存页面
  4744. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  4745. Graphics g = Graphics.FromImage(bit);
  4746. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  4747. SaveFileDialog sf = new SaveFileDialog();
  4748. sf.Title = "页面保存";
  4749. sf.FileName = "MotorInfo_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".png";
  4750. sf.Filter = "图片|*.png";
  4751. timer_500ms.Enabled = false;
  4752. if (sf.ShowDialog() == DialogResult.OK)
  4753. {
  4754. bit.Save(sf.FileName);//默认保存格式为PNG,保存成jpg格式质量不是很好
  4755. }
  4756. timer_500ms.Enabled = true;
  4757. }
  4758. /// <summary>
  4759. /// 生产模式关机
  4760. /// </summary>
  4761. /// <param name="sender"></param>
  4762. /// <param name="e"></param>
  4763. private void Button_FacModePowerOff_Click(object sender, EventArgs e)
  4764. {
  4765. var Code_Off = new byte[5];
  4766. var Code_Reset = new byte[5];
  4767. Code_Off[0] = (byte)'O';
  4768. Code_Off[1] = (byte)'F';
  4769. Code_Off[2] = (byte)'F';
  4770. Code_Off[3] = (byte)'.';
  4771. Code_Off[4] = (byte)'.';
  4772. Code_Reset[0] = (byte)'R';
  4773. Code_Reset[1] = (byte)'E';
  4774. Code_Reset[2] = (byte)'S';
  4775. Code_Reset[3] = (byte)'E';
  4776. Code_Reset[4] = (byte)'T';
  4777. timer_500ms.Enabled = false;
  4778. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  4779. {
  4780. timer_500ms.Enabled = true;
  4781. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  4782. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  4783. PowerOffAckStatus = false;
  4784. Delay_ms(250);
  4785. int TryCnt = 3;
  4786. while ((TryCnt--) >= 0)
  4787. {
  4788. if (!PowerOffAckStatus)
  4789. {
  4790. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  4791. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  4792. PowerOffAckStatus = false;
  4793. Delay_ms(250);
  4794. }
  4795. else break;
  4796. }
  4797. if (PowerOffAckStatus)
  4798. {
  4799. timer_500ms.Enabled = false;
  4800. MessageBox.Show("已关机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  4801. timer_500ms.Enabled = true;
  4802. }
  4803. else
  4804. {
  4805. timer_500ms.Enabled = false;
  4806. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4807. timer_500ms.Enabled = true;
  4808. }
  4809. }
  4810. timer_500ms.Enabled = true;
  4811. }
  4812. //仪表电源键按下
  4813. private void button_OBC_ButtonPower_Click(object sender, EventArgs e)
  4814. {
  4815. var Code = new byte[2];
  4816. Code[0] = 0;
  4817. Code[1] = 0b00100000;
  4818. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4819. }
  4820. /// <summary>
  4821. /// 仪表加键按下
  4822. /// </summary>
  4823. /// <param name="sender"></param>
  4824. /// <param name="e"></param>
  4825. private void button_OBC_ButtonAcc_Click(object sender, EventArgs e)
  4826. {
  4827. var Code = new byte[2];
  4828. Code[0] = 0;
  4829. Code[1] = 0b00010000;
  4830. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4831. }
  4832. /// <summary>
  4833. /// 仪表减键按下
  4834. /// </summary>
  4835. /// <param name="sender"></param>
  4836. /// <param name="e"></param>
  4837. private void button_OBC_ButtonDec_Click(object sender, EventArgs e)
  4838. {
  4839. var Code = new byte[2];
  4840. Code[0] = 0;
  4841. Code[1] = 0b00001000;
  4842. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4843. }
  4844. /// <summary>
  4845. /// 仪表Walk键按下
  4846. /// </summary>
  4847. /// <param name="sender"></param>
  4848. /// <param name="e"></param>
  4849. private void button_OBC_ButtonWalk_Click(object sender, EventArgs e)
  4850. {
  4851. var Code = new byte[2];
  4852. Code[0] = 0;
  4853. Code[1] = 0b00000100;
  4854. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4855. }
  4856. /// <summary>
  4857. /// 仪表Light键按下
  4858. /// </summary>
  4859. /// <param name="sender"></param>
  4860. /// <param name="e"></param>
  4861. private void button_OBC_ButtonLight_Click(object sender, EventArgs e)
  4862. {
  4863. var Code = new byte[2];
  4864. Code[0] = 0;
  4865. Code[1] = 0b00000010;
  4866. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4867. }
  4868. /// <summary>
  4869. /// 仪表Set键按下
  4870. /// </summary>
  4871. /// <param name="sender"></param>
  4872. /// <param name="e"></param>
  4873. private void button_OBC_ButtonSet_Click(object sender, EventArgs e)
  4874. {
  4875. var Code = new byte[2];
  4876. Code[0] = 0;
  4877. Code[1] = 0b00000001;
  4878. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4879. }
  4880. /// <summary>
  4881. /// 导出电机故障日志
  4882. /// </summary>
  4883. /// <param name="sender"></param>
  4884. /// <param name="e"></param>
  4885. private void button_ExportLog_Click(object sender, EventArgs e)
  4886. {
  4887. var Address = new byte[4];
  4888. UInt32 Address_Begin;
  4889. UInt32 Addres_End;
  4890. string textBox_Address_Begin = textBox_LogAddrBegin.Text;
  4891. string textBox_Address_End = textBox_LogAddrEnd.Text;
  4892. richTextBox_Record.Clear();
  4893. textBox_LogAddrBegin.ReadOnly = true;
  4894. textBox_LogAddrEnd.ReadOnly = true;
  4895. if (!mySerialProcess.mySerial.IsOpen)
  4896. {
  4897. timer_500ms.Enabled = false;
  4898. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4899. timer_500ms.Enabled = true;
  4900. return;
  4901. }
  4902. if ((textBox_Address_Begin == string.Empty) || (textBox_Address_End == string.Empty))
  4903. {
  4904. timer_500ms.Enabled = false;
  4905. MessageBox.Show("请输入日志存储起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4906. timer_500ms.Enabled = true;
  4907. return;
  4908. }
  4909. else
  4910. {
  4911. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin, false);
  4912. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  4913. Address = mySerialProcess.HexStringToBytes(textBox_Address_End, false);
  4914. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  4915. if (Addres_End <= Address_Begin)
  4916. {
  4917. timer_500ms.Enabled = false;
  4918. MessageBox.Show("结束地址应大于起始地址!", "提示");
  4919. timer_500ms.Enabled = true;
  4920. return;
  4921. }
  4922. else if (((Addres_End - Address_Begin + 1) % 128) != 0) //
  4923. {
  4924. timer_500ms.Enabled = false;
  4925. MessageBox.Show("(结束地址 - 起始地址 + 1)应为128整数倍!", "提示");
  4926. timer_500ms.Enabled = true;
  4927. return;
  4928. }
  4929. else
  4930. {
  4931. UInt32 ReadCount = 0;
  4932. button_ExportLog.Text = "导出中...";
  4933. button_ExportLog.Enabled = false;
  4934. ReadCount = (Addres_End - Address_Begin + 1) / 128;
  4935. for (ushort i = 0; i < ReadCount; i++)
  4936. {
  4937. var SendByte = new byte[8];
  4938. UInt32 Address_Temp_Begin;
  4939. UInt32 Address_Temp_End;
  4940. Address_Temp_Begin = Address_Begin + 128 * (UInt32)i;
  4941. SendByte[0] = (byte)(Address_Temp_Begin >> 24);
  4942. SendByte[1] = (byte)(Address_Temp_Begin >> 16);
  4943. SendByte[2] = (byte)(Address_Temp_Begin >> 8);
  4944. SendByte[3] = (byte)(Address_Temp_Begin);
  4945. Address_Temp_End = Address_Temp_Begin + 127;
  4946. SendByte[4] = (byte)(Address_Temp_End >> 24);
  4947. SendByte[5] = (byte)(Address_Temp_End >> 16);
  4948. SendByte[6] = (byte)(Address_Temp_End >> 8);
  4949. SendByte[7] = (byte)(Address_Temp_End);
  4950. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  4951. Delay_ms(200);//Thread.Sleep(200);
  4952. }
  4953. button_ExportLog.Text = "导出日志";
  4954. button_ExportLog.Enabled = true;
  4955. }
  4956. }
  4957. }
  4958. /// <summary>
  4959. /// 保存日志信息
  4960. /// </summary>
  4961. /// <param name="sender"></param>
  4962. /// <param name="e"></param>
  4963. private void button_SaveRecordInfo_Click(object sender, EventArgs e)
  4964. {
  4965. string SaveInfo = "";
  4966. if (richTextBox_Record.Text == string.Empty)
  4967. {
  4968. timer_500ms.Enabled = false;
  4969. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  4970. timer_500ms.Enabled = true;
  4971. return;
  4972. }
  4973. //获取保存信息
  4974. SaveInfo += "读取时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  4975. SaveInfo += "电机型号:" + textBox_FacModeName.Text + "\r\n";
  4976. SaveInfo += "电机SN:" + textBox_FacModeNum.Text + "\r\n";
  4977. SaveInfo += "硬件版本:" + textBox_FacModeHW.Text + "\r\n";
  4978. SaveInfo += "软件版本:" + textBox_FacModeFW.Text + "\r\n";
  4979. SaveInfo += "\r\n";
  4980. SaveInfo += richTextBox_Record.Text;
  4981. //设置保存路径和文件名
  4982. SaveFileDialog sf = new SaveFileDialog();
  4983. sf.Title = "数据保存";
  4984. sf.FileName = "MotorLog_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".ttlog";
  4985. sf.FileName.Replace(" ", "");
  4986. sf.Filter = "日志|*.ttlog";
  4987. if (sf.ShowDialog() == DialogResult.OK)
  4988. {
  4989. System.IO.File.AppendAllText(sf.FileName, SaveInfo);
  4990. }
  4991. }
  4992. /// <summary>
  4993. /// 双击修改日志起始地址
  4994. /// </summary>
  4995. /// <param name="sender"></param>
  4996. /// <param name="e"></param>
  4997. private void label_LogAddrBegin_DoubleClick_1(object sender, EventArgs e)
  4998. {
  4999. textBox_LogAddrBegin.ReadOnly = false;
  5000. }
  5001. /// <summary>
  5002. /// 双击修改日志结束地址
  5003. /// </summary>
  5004. /// <param name="sender"></param>
  5005. /// <param name="e"></param>
  5006. private void label88_DoubleClick(object sender, EventArgs e)
  5007. {
  5008. textBox_LogAddrEnd.ReadOnly = false;
  5009. }
  5010. /// <summary>
  5011. /// 存储器自动读取选择
  5012. /// </summary>
  5013. /// <param name="sender"></param>
  5014. /// <param name="e"></param>
  5015. private void checkBox_ReadRanFlash_AutoSW_CheckedChanged(object sender, EventArgs e)
  5016. {
  5017. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  5018. {
  5019. //检查串口是否打开
  5020. if (!mySerialProcess.mySerial.IsOpen)
  5021. {
  5022. timer_500ms.Enabled = false;
  5023. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5024. timer_500ms.Enabled = true;
  5025. checkBox_ReadRanFlash_AutoSW.Checked = false;
  5026. return;
  5027. }
  5028. }
  5029. }
  5030. /// <summary>
  5031. /// 系统开机按钮
  5032. /// </summary>
  5033. /// <param name="sender"></param>
  5034. /// <param name="e"></param>
  5035. private void 开机ToolStripMenuItem_Click(object sender, EventArgs e)
  5036. {
  5037. byte[] Data = new byte[1];
  5038. Data[0] = 0xF1;
  5039. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  5040. }
  5041. /// <summary>
  5042. /// 系统关机按钮
  5043. /// </summary>
  5044. /// <param name="sender"></param>
  5045. /// <param name="e"></param>
  5046. private void 关机ToolStripMenuItem_Click(object sender, EventArgs e)
  5047. {
  5048. byte[] Data = new byte[1];
  5049. Data[0] = 0xF0;
  5050. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  5051. }
  5052. /// <summary>
  5053. /// 连接开机选择
  5054. /// </summary>
  5055. /// <param name="sender"></param>
  5056. /// <param name="e"></param>
  5057. private void 连接开机ToolStripMenuItem_Click(object sender, EventArgs e)
  5058. {
  5059. //输入用户名
  5060. EnterForm1.ShowDialog();
  5061. try
  5062. {
  5063. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5064. {
  5065. if (EnterForm1.comboBox_User.Text == "管理员")
  5066. {
  5067. 连接开机ToolStripMenuItem.Checked = !连接开机ToolStripMenuItem.Checked;
  5068. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5069. }
  5070. else
  5071. {
  5072. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5073. }
  5074. }
  5075. else
  5076. {
  5077. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5078. }
  5079. }
  5080. catch (Exception)
  5081. {
  5082. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5083. }
  5084. }
  5085. /// <summary>
  5086. /// 断开关机选择
  5087. /// </summary>
  5088. /// <param name="sender"></param>
  5089. /// <param name="e"></param>
  5090. private void 断开关机ToolStripMenuItem_Click(object sender, EventArgs e)
  5091. {
  5092. //输入用户名
  5093. EnterForm1.ShowDialog();
  5094. try
  5095. {
  5096. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5097. {
  5098. if (EnterForm1.comboBox_User.Text == "管理员")
  5099. {
  5100. 断开关机ToolStripMenuItem.Checked = !断开关机ToolStripMenuItem.Checked;
  5101. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5102. }
  5103. else
  5104. {
  5105. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5106. }
  5107. }
  5108. else
  5109. {
  5110. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5111. }
  5112. }
  5113. catch (Exception)
  5114. {
  5115. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5116. }
  5117. }
  5118. /// <summary>
  5119. /// 识别通讯盒选择
  5120. /// </summary>
  5121. /// <param name="sender"></param>
  5122. /// <param name="e"></param>
  5123. private void 识别通讯盒ToolStripMenuItem_Click(object sender, EventArgs e)
  5124. {
  5125. //输入用户名
  5126. EnterForm1.ShowDialog();
  5127. try
  5128. {
  5129. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5130. {
  5131. if (EnterForm1.comboBox_User.Text == "管理员")
  5132. {
  5133. 识别通讯盒ToolStripMenuItem.Checked = !识别通讯盒ToolStripMenuItem.Checked;
  5134. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5135. }
  5136. else
  5137. {
  5138. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5139. }
  5140. }
  5141. else
  5142. {
  5143. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5144. }
  5145. }
  5146. catch (Exception)
  5147. {
  5148. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5149. }
  5150. }
  5151. /// <summary>
  5152. /// 将配置信息导出为cfg文件
  5153. /// </summary>
  5154. private void ConfigFileSave(bool DeleteFlag, string FileName)
  5155. {
  5156. if (DeleteFlag)
  5157. {
  5158. if (File.Exists(FileName))
  5159. File.Delete(FileName);
  5160. }
  5161. string CfgFileInfo = "";
  5162. CfgFileInfo += "[PortSet]" + "\r\n";
  5163. CfgFileInfo += "PortNum:" + toolStripComboBox_ComNum.Text + "\r\n";
  5164. CfgFileInfo += "PortBaudrate:" + "115200" + "\r\n";
  5165. CfgFileInfo += "AutoOn:" + 连接开机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5166. CfgFileInfo += "AutoOff:" + 断开关机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5167. CfgFileInfo += "CheckCDL:" + 识别通讯盒ToolStripMenuItem.Checked.ToString() + "\r\n";
  5168. CfgFileInfo += "\r\n";
  5169. CfgFileInfo += "[Option]" + "\r\n";
  5170. CfgFileInfo += "SaveWhenWrite:" + 写入存储ToolStripMenuItem.Checked.ToString() + "\r\n";
  5171. CfgFileInfo += "\r\n";
  5172. CfgFileInfo += "[ServerSet]" + "\r\n";
  5173. CfgFileInfo += "PathName:" + toolStripTextBox_ServerPath.Text + "\r\n";
  5174. CfgFileInfo += "\r\n";
  5175. CfgFileInfo += "[MacInfo]" + "\r\n";
  5176. CfgFileInfo += "MacName:" + toolStripTextBox_MAC.Text + "\r\n";
  5177. CfgFileInfo += "MacAddress:" + toolStripTextBoxMACAddr.Text + "\r\n";
  5178. CfgFileInfo += "MacDate:" + toolStripTextBox_MACDate.Text + "\r\n";
  5179. CfgFileInfo += "MacPdInfo:" + toolStripTextBox_MACPD.Text + "\r\n";
  5180. CfgFileInfo += "\r\n";
  5181. CfgFileInfo += "[LogAddress]" + "\r\n";
  5182. CfgFileInfo += "BeginAddress:" + textBox_LogAddrBegin.Text + "\r\n";
  5183. CfgFileInfo += "EndAddress:" + textBox_LogAddrEnd.Text + "\r\n";
  5184. CfgFileInfo += "\r\n";
  5185. CfgFileInfo += "[MotorType]" + "\r\n";
  5186. CfgFileInfo += "MidMotor:" + 中置电机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5187. CfgFileInfo += "HubMotor:" + 轮毂电机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5188. CfgFileInfo += "\r\n";
  5189. CfgFileInfo += "[CheckValue]" + "\r\n";
  5190. CfgFileInfo += "Voltage:" + toolStripTextBox_ThVol.Text + "\r\n";
  5191. CfgFileInfo += "Current:" + toolStripTextBox_ThCur.Text + "\r\n";
  5192. CfgFileInfo += "MotorSpeed:" + toolStripTextBox_ThSpeed.Text + "\r\n";
  5193. CfgFileInfo += "Torque:" + toolStripTextBox_ThTor.Text + "\r\n";
  5194. CfgFileInfo += "Cadence:" + toolStripTextBox_ThCad.Text + "\r\n";
  5195. CfgFileInfo += "BikeSpeed:" + toolStripTextBox_ThBikeSpeed.Text + "\r\n";
  5196. CfgFileInfo += "T_PCB:" + toolStripTextBox_ThT_PCB.Text + "\r\n";
  5197. CfgFileInfo += "T_MCU:" + toolStripTextBox_ThT_MCU.Text + "\r\n";
  5198. CfgFileInfo += "T_Motor:" + toolStripTextBox_ThT_Motor.Text + "\r\n";
  5199. CfgFileInfo += "\r\n";
  5200. CfgFileInfo += "[MosCalK]" + "\r\n";
  5201. CfgFileInfo += "K1-K5:" + toolStripTextBox_MosCalK.Text + "\r\n";
  5202. CfgFileInfo += "MOS1:" + toolStripTextBox_MOS1.Text + "\r\n";
  5203. CfgFileInfo += "MOS2:" + toolStripTextBox_MOS2.Text + "\r\n";
  5204. CfgFileInfo += "MOS3:" + toolStripTextBox_MOS3.Text + "\r\n";
  5205. CfgFileInfo += "\r\n";
  5206. CfgFileInfo += "[ProtocolType]" + "\r\n";
  5207. CfgFileInfo += "CAN:" + cANToolStripMenuItem.Checked.ToString() + "\r\n";
  5208. CfgFileInfo += "UART:" + uARTToolStripMenuItem.Checked.ToString() + "\r\n";
  5209. CfgFileInfo += "\r\n";
  5210. CfgFileInfo += "[AutoUpdate]" + "\r\n";
  5211. CfgFileInfo += "AutoUpdate:" + 打开ToolStripMenuItem.Checked.ToString() + "\r\n";
  5212. CfgFileInfo += "\r\n";
  5213. CfgFileInfo += "[AngleCal]" + "\r\n";
  5214. CfgFileInfo += "MaxDiffLimit:" + textBox_AngleDiffTh.Text + "\r\n";
  5215. CfgFileInfo += "ZeroDiffLimit:" + textBox_AngleZeroTh.Text + "\r\n";
  5216. System.IO.File.WriteAllText(FileName, CfgFileInfo);
  5217. }
  5218. /// <summary>
  5219. /// 配置状态更新,点击时保存
  5220. /// </summary>
  5221. private void ConfigFileSave_Click(object sender, EventArgs e)
  5222. {
  5223. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5224. }
  5225. /// <summary>
  5226. /// 文本框修改结束,回车保存
  5227. /// </summary>
  5228. /// <param name="sender"></param>
  5229. /// <param name="e"></param>
  5230. private void ConfigFileSave_KeyDown(object sender, KeyEventArgs e)
  5231. {
  5232. if (e.KeyCode == Keys.Enter)
  5233. {
  5234. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5235. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  5236. }
  5237. }
  5238. /// <summary>
  5239. /// 弹出扫码按钮
  5240. /// </summary>
  5241. /// <param name="sender"></param>
  5242. /// <param name="e"></param>
  5243. private void button_ScanCode_Click(object sender, EventArgs e)
  5244. {
  5245. Scan scan_form = new Scan();
  5246. scan_form.ShowDialog();
  5247. do
  5248. {
  5249. if (scan_form.textBox_Scan.Text == string.Empty)
  5250. {
  5251. timer_500ms.Enabled = false;
  5252. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5253. timer_500ms.Enabled = true;
  5254. break;
  5255. }
  5256. string ScanInfo = scan_form.textBox_Scan.Text;
  5257. string regexInfo = "";
  5258. string[] InfoList = { "" };
  5259. try
  5260. {
  5261. if (中置电机ToolStripMenuItem.Checked == true)
  5262. {
  5263. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  5264. InfoList = Regex.Split(ScanInfo, regexInfo, RegexOptions.IgnoreCase);
  5265. }
  5266. else if (轮毂电机ToolStripMenuItem.Checked == true)
  5267. {
  5268. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  5269. string Model = InfoList[0];
  5270. string Spec = InfoList[1];
  5271. string Sn = InfoList[2];
  5272. InfoList[0] = Model.Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  5273. InfoList[1] = Sn;
  5274. }
  5275. }
  5276. catch (Exception)
  5277. {
  5278. MessageBox.Show("格式错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5279. return;
  5280. }
  5281. if (InfoList.Length >= 2)
  5282. {
  5283. //写入型号
  5284. textBox_FacModeName.Text = InfoList[0];
  5285. string Mode = textBox_FacModeName.Text;
  5286. var ModeArray = new byte[16];
  5287. for (ushort i = 0; i < Mode.Length; i++)
  5288. {
  5289. ModeArray[i] = (byte)Mode[i];
  5290. }
  5291. if (Mode.Length < 16)
  5292. {
  5293. ModeArray[Mode.Length] = (byte)'.';
  5294. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  5295. {
  5296. ModeArray[Mode.Length + 1 + i] = 0x20;
  5297. }
  5298. }
  5299. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  5300. //写入SN
  5301. textBox_FacModeNum.Text = InfoList[1];
  5302. string SN = textBox_FacModeNum.Text;
  5303. var SNArray = new byte[16];
  5304. for (ushort i = 0; i < SN.Length; i++)
  5305. {
  5306. SNArray[i] = (byte)SN[i];
  5307. }
  5308. if (SN.Length < 16)
  5309. {
  5310. SNArray[SN.Length] = (byte)'.';
  5311. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  5312. {
  5313. SNArray[SN.Length + 1 + i] = 0x20;
  5314. }
  5315. }
  5316. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  5317. }
  5318. else
  5319. {
  5320. timer_500ms.Enabled = false;
  5321. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5322. timer_500ms.Enabled = true;
  5323. break;
  5324. }
  5325. } while (false);
  5326. scan_form.Dispose();
  5327. }
  5328. /// <summary>
  5329. /// 切换电机类型
  5330. /// </summary>
  5331. /// <param name="sender"></param>
  5332. /// <param name="e"></param>
  5333. private void 中置电机ToolStripMenuItem_Click(object sender, EventArgs e)
  5334. {
  5335. 中置电机ToolStripMenuItem.Checked = true;
  5336. 轮毂电机ToolStripMenuItem.Checked = false;
  5337. toolStripTextBox_MACPD.Text = "MM_MC1";
  5338. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  5339. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5340. }
  5341. /// <summary>
  5342. /// 切换电机类型
  5343. /// </summary>
  5344. /// <param name="sender"></param>
  5345. /// <param name="e"></param>
  5346. private void 轮毂电机ToolStripMenuItem_Click(object sender, EventArgs e)
  5347. {
  5348. 中置电机ToolStripMenuItem.Checked = false;
  5349. 轮毂电机ToolStripMenuItem.Checked = true;
  5350. toolStripTextBox_MACPD.Text = "GF_250_1";
  5351. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  5352. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5353. }
  5354. /// <summary>
  5355. /// 获取配置文件日期
  5356. /// </summary>
  5357. /// <param name="DisAll"></param>
  5358. private void GetDateList(bool DisAll)
  5359. {
  5360. string[] DateList = { "" };
  5361. //从服务器更新日期列表
  5362. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  5363. {
  5364. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
  5365. }
  5366. //从本地更新日期列表
  5367. else
  5368. {
  5369. DateList = Directory.GetDirectories(localInfo.LocalPath + "\\" + localInfo.CfgPathName);
  5370. }
  5371. comboBox_FacModeCfgDate.Items.Clear();
  5372. comboBox_CheckModeCfgDate.Items.Clear();
  5373. //日期列表加载
  5374. if (DisAll == true)
  5375. {
  5376. comboBox_FacModeCfgDate.Items.Add("显示近期");
  5377. comboBox_CheckModeCfgDate.Items.Add("显示近期");
  5378. comboBox_FacModeCfgDate.Items.Add("---");
  5379. comboBox_CheckModeCfgDate.Items.Add("---");
  5380. foreach (var file in DateList)
  5381. {
  5382. comboBox_FacModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5383. comboBox_CheckModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5384. }
  5385. }
  5386. else
  5387. {
  5388. if (DateList.Length > 10)
  5389. {
  5390. comboBox_FacModeCfgDate.Items.Add("显示全部");
  5391. comboBox_CheckModeCfgDate.Items.Add("显示全部");
  5392. comboBox_FacModeCfgDate.Items.Add("---");
  5393. comboBox_CheckModeCfgDate.Items.Add("---");
  5394. }
  5395. for (int i = (DateList.Length > 10) ? (DateList.Length - 10) : 0; i < DateList.Length; i++)//显示最近10个日期
  5396. {
  5397. comboBox_FacModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  5398. comboBox_CheckModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  5399. }
  5400. }
  5401. }
  5402. /// <summary>
  5403. /// 获取配置文件列表
  5404. /// </summary>
  5405. /// <param name="date"></param>
  5406. private void GetFileListFrom(string date)
  5407. {
  5408. string[] FileList = { "" };
  5409. //从服务器更新文件列表
  5410. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  5411. {
  5412. FileList = myFtp.GetFileNameList(toolStripTextBox_ServerPath.Text + "/cfg/" + date);
  5413. }
  5414. else
  5415. {
  5416. FileList = Directory.GetFiles(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + date);
  5417. }
  5418. comboBox_CheckModeCfgFile.Items.Clear();
  5419. comboBox_FacModeCfgFile.Items.Clear();
  5420. foreach (var file in FileList)
  5421. {
  5422. if (file.Contains(".ttcfg"))
  5423. {
  5424. comboBox_CheckModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5425. comboBox_FacModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5426. }
  5427. }
  5428. }
  5429. /// <summary>
  5430. /// 检验模式选择文件日期
  5431. /// </summary>
  5432. /// <param name="sender"></param>
  5433. /// <param name="e"></param>
  5434. private void comboBox_CheckModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  5435. {
  5436. if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示全部")
  5437. {
  5438. GetDateList(true);
  5439. }
  5440. else if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示近期")
  5441. {
  5442. GetDateList(false);
  5443. }
  5444. else
  5445. {
  5446. comboBox_CheckModeCfgFile.Text = "";
  5447. GetFileListFrom(comboBox_CheckModeCfgDate.SelectedItem.ToString());
  5448. }
  5449. }
  5450. /// <summary>
  5451. /// 配置模式选择文件日期
  5452. /// </summary>
  5453. /// <param name="sender"></param>
  5454. /// <param name="e"></param>
  5455. private void comboBox_FacModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  5456. {
  5457. if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示全部")
  5458. {
  5459. GetDateList(true);
  5460. }
  5461. else if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示近期")
  5462. {
  5463. GetDateList(false);
  5464. }
  5465. else
  5466. {
  5467. comboBox_FacModeCfgFile.Text = "";
  5468. GetFileListFrom(comboBox_FacModeCfgDate.SelectedItem.ToString());
  5469. }
  5470. }
  5471. /// <summary>
  5472. /// 选中量产模式
  5473. /// </summary>
  5474. /// <param name="sender"></param>
  5475. /// <param name="e"></param>
  5476. private void tabControl1_Selected(object sender, TabControlEventArgs e)
  5477. {
  5478. //更新生产配置文件目录
  5479. GetDateList(false);
  5480. }
  5481. /// <summary>
  5482. /// 量产测试结束
  5483. /// </summary>
  5484. /// <param name=""></param>
  5485. private void FacMode_Stop(bool OK_Flag)
  5486. {
  5487. //打开开始按钮
  5488. button__FacMode_Start.Enabled = true;
  5489. //系统关机
  5490. var Code = new byte[32];//发送的指令数据
  5491. Code[0] = 0xF0;
  5492. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5493. //关闭串口
  5494. //mySerialProcess.SerialClose(false);
  5495. //路径设置
  5496. string LocalSavePath = "";
  5497. string ServerSavePath = "";
  5498. if (OK_Flag)
  5499. {
  5500. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "OK\\";
  5501. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/OK/";
  5502. }
  5503. else
  5504. {
  5505. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "FAIL\\";
  5506. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/FAIL/";
  5507. }
  5508. if (Directory.Exists(LocalSavePath) == false)
  5509. {
  5510. Directory.CreateDirectory(LocalSavePath);
  5511. }
  5512. //保存和上传
  5513. string LogSavePath = "";
  5514. string LogSaveFileName = "";
  5515. string ProductInfo = textBox_FacModeScan.Text.Replace(" ", "_");
  5516. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  5517. if (Directory.Exists(LogSavePath) == false)
  5518. {
  5519. Directory.CreateDirectory(LogSavePath);
  5520. }
  5521. //测试页面
  5522. Double scaleX = PrimaryScreen.ScaleX;
  5523. Double scaleY = PrimaryScreen.ScaleY;
  5524. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  5525. Graphics g = Graphics.FromImage(bit);
  5526. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  5527. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  5528. bit.Save(LogSaveFileName);
  5529. //上传测试页面到服务器
  5530. if (myFtp.IsNetConnected == true)
  5531. {
  5532. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  5533. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  5534. {
  5535. myFtp.MakeDir(ServerSavePath + DateNow);
  5536. }
  5537. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  5538. {
  5539. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  5540. }
  5541. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  5542. if (result == true)
  5543. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  5544. }
  5545. else
  5546. {
  5547. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  5548. }
  5549. //测试记录
  5550. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  5551. string file_str = "";
  5552. file_str += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  5553. file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  5554. file_str += "检验记录:\r\n" + richTextBox_FacModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  5555. file_str += "检验结果:\r\n" + label_FacModeResult.Text + "\r\n\r\n";
  5556. file_str += Local_HdInformation;
  5557. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  5558. //上传测试记录到服务器
  5559. if (myFtp.IsNetConnected == true)
  5560. {
  5561. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  5562. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  5563. {
  5564. myFtp.MakeDir(ServerSavePath + DateNow);
  5565. }
  5566. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  5567. {
  5568. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  5569. }
  5570. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  5571. if (result == true)
  5572. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  5573. }
  5574. else
  5575. {
  5576. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  5577. }
  5578. //扫码框清空
  5579. textBox_FacModeScan.Text = "";
  5580. }
  5581. /// <summary>
  5582. /// 量产测试开始
  5583. /// </summary>
  5584. /// <param name="sender"></param>
  5585. /// <param name="e"></param>
  5586. private void button__FacMode_Start_Click(object sender, EventArgs e)
  5587. {
  5588. //关闭测试项目编辑
  5589. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  5590. foreach (Control c in groupBox2.Controls)
  5591. {
  5592. if (c is CheckBox)
  5593. c.Enabled = false;
  5594. }
  5595. WriteLockStatus = true;
  5596. //检查配置文件
  5597. if (comboBox_FacModeCfgFile.Text == "")
  5598. {
  5599. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5600. return;
  5601. }
  5602. //开始测试
  5603. TestStart();
  5604. }
  5605. /// <summary>
  5606. /// 测试子函数
  5607. /// </summary>
  5608. private void TestStart()
  5609. {
  5610. //初始化标签
  5611. FacModelLabelInit();
  5612. richTextBox_FacModeLog.Clear();
  5613. //按钮禁止操作
  5614. button__FacMode_Start.Enabled = false;
  5615. //记录配置文件
  5616. richTextBox_FacModeLog.AppendText("配置文件:" + comboBox_FacModeCfgDate.Text + " / " + comboBox_FacModeCfgFile.Text + "\r\n");
  5617. //检查打标信息格式
  5618. label_FacModeStatus.Text = "检查扫码信息";
  5619. Delay_ms(500);
  5620. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  5621. if (textBox_FacModeScan.Text == string.Empty)
  5622. {
  5623. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5624. button__FacMode_Start.Enabled = true;
  5625. return;
  5626. }
  5627. try
  5628. {
  5629. if (中置电机ToolStripMenuItem.Checked == true)
  5630. {
  5631. if (textBox_FacModeScan.Text.Split(' ').Length != 7)
  5632. {
  5633. label_FacModeStatus.Text = "存在故障!";
  5634. label_FacModeResult.BackColor = Color.Red;
  5635. label_FacModeResult.Text = "标签格式错误";
  5636. button__FacMode_Start.Enabled = true;
  5637. return;
  5638. }
  5639. }
  5640. else if (轮毂电机ToolStripMenuItem.Checked == true)
  5641. {
  5642. if (textBox_FacModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  5643. {
  5644. label_FacModeStatus.Text = "存在故障!";
  5645. label_FacModeResult.BackColor = Color.Red;
  5646. label_FacModeResult.Text = "标签格式错误";
  5647. button__FacMode_Start.Enabled = true;
  5648. return;
  5649. }
  5650. }
  5651. }
  5652. catch (System.Exception)
  5653. {
  5654. label_FacModeStatus.Text = "存在故障!";
  5655. label_FacModeResult.BackColor = Color.Red;
  5656. label_FacModeResult.Text = "标签格式错误";
  5657. button__FacMode_Start.Enabled = true;
  5658. return;
  5659. }
  5660. //打开串口
  5661. mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false);
  5662. if (!mySerialProcess.mySerial.IsOpen)
  5663. {
  5664. MessageBox.Show("请检查串口连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5665. //按钮禁止操作
  5666. button__FacMode_Start.Enabled = true;
  5667. return;
  5668. }
  5669. //流水号计数
  5670. int serial = Convert.ToInt32(label_FacModeSerial.Text);
  5671. serial += 1;
  5672. label_FacModeSerial.Text = serial.ToString();
  5673. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, serial.ToString());
  5674. //创建线程,执行测试任务
  5675. Thread th = new Thread(FacModeTest_Task);
  5676. th.Start();
  5677. }
  5678. /// <summary>
  5679. /// 执行一次测试任务
  5680. /// </summary>
  5681. private void FacModeTest_Task()
  5682. {
  5683. //开始测试
  5684. richTextBox_FacModeLog.AppendText("产品标签:" + textBox_FacModeScan.Text + "\r\n");
  5685. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  5686. //变量定义
  5687. var Code = new byte[255];//发送的指令数据
  5688. label_FacModeStatus.Text = "开始测试";
  5689. BootInfo = "";
  5690. Delay_ms(500);
  5691. label_FacModeStatus.Text = "系统开机";
  5692. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  5693. if (uARTToolStripMenuItem.Checked)
  5694. {
  5695. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送复位指令,切换联动装置盒波特率" + "\r\n");
  5696. Code[0] = (byte)'R';
  5697. Code[1] = (byte)'E';
  5698. Code[2] = (byte)'S';
  5699. Code[3] = (byte)'E';
  5700. Code[4] = (byte)'T';
  5701. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  5702. Delay_ms(500);
  5703. }
  5704. //发送开机指令
  5705. //确保测试前先关机,发送关机指令再发送开机指令
  5706. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  5707. Code[0] = 0xF0;
  5708. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5709. Delay_ms(1500);
  5710. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  5711. Code[0] = 0xF1;
  5712. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5713. ACK_WaitCnt = 0;
  5714. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  5715. while (ACK_WaitCnt <= 20) ; //10s,等待开机成功,联动装置盒控制器接口波特率需等待5s接口自动切换为9600
  5716. //检查BOOT版本
  5717. if (BootInfo != string.Empty)
  5718. {
  5719. label_FacModeBootVer.BackColor = Color.Green;
  5720. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  5721. Delay_ms(500);
  5722. }
  5723. else
  5724. {
  5725. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
  5726. label_FacModeStatus.Text = "存在故障!";
  5727. label_FacModeResult.BackColor = Color.Red;
  5728. label_FacModeResult.Text = "测试异常";
  5729. Delay_ms(500);
  5730. //存储异常并上传
  5731. FacMode_Stop(false);
  5732. return;
  5733. }
  5734. //系统清除
  5735. if (checkBox_FacModeSysClear.Checked)
  5736. {
  5737. do
  5738. {
  5739. #if false
  5740. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  5741. {
  5742. Code[0] = 0x00;//5S协议
  5743. Code[1] = 0x00;
  5744. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5745. Delay_ms(500);
  5746. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5747. Delay_ms(500);
  5748. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  5749. }
  5750. #endif
  5751. //发送系统清除指令
  5752. label_FacModeStatus.Text = "系统清除";
  5753. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除" + "\r\n");
  5754. Code[0] = (byte)'C';
  5755. Code[1] = (byte)'L';
  5756. Code[2] = (byte)'E';
  5757. Code[3] = (byte)'A';
  5758. Code[4] = (byte)'R';
  5759. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  5760. WriteACK = false;
  5761. WriteCnt = 0;
  5762. ACK_WaitCnt = 0;
  5763. while (ACK_WaitCnt <= 6); //3s
  5764. //等待系统清除完成指令
  5765. if (WriteACK == true)
  5766. {
  5767. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  5768. label_FacModeSysClear.BackColor = Color.Green;
  5769. }
  5770. else
  5771. {
  5772. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除,重发第1次" + "\r\n");
  5773. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  5774. ACK_WaitCnt = 0;
  5775. while (ACK_WaitCnt <= 6) ; //3s
  5776. //等待系统清除完成指令
  5777. if (WriteACK == true)
  5778. {
  5779. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  5780. label_FacModeSysClear.BackColor = Color.Green;
  5781. }
  5782. else
  5783. {
  5784. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除,重发第2次" + "\r\n");
  5785. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  5786. ACK_WaitCnt = 0;
  5787. while (ACK_WaitCnt <= 6) ; //3s
  5788. //等待系统清除完成指令
  5789. if (WriteACK == true)
  5790. {
  5791. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  5792. label_FacModeSysClear.BackColor = Color.Green;
  5793. }
  5794. else
  5795. {
  5796. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除失败" + "\r\n");
  5797. label_FacModeStatus.Text = "存在故障!";
  5798. label_FacModeResult.BackColor = Color.Red;
  5799. label_FacModeResult.Text = "测试异常";
  5800. Delay_ms(500);
  5801. //存储异常并上传
  5802. FacMode_Stop(false);
  5803. return;
  5804. }
  5805. }
  5806. }
  5807. BootInfo = "";
  5808. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  5809. if (uARTToolStripMenuItem.Checked)
  5810. {
  5811. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送复位指令,切换联动装置盒波特率" + "\r\n");
  5812. Code[0] = (byte)'R';
  5813. Code[1] = (byte)'E';
  5814. Code[2] = (byte)'S';
  5815. Code[3] = (byte)'E';
  5816. Code[4] = (byte)'T';
  5817. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  5818. Delay_ms(500);
  5819. }
  5820. //系统清除后需重新开机
  5821. label_FacModeStatus.Text = "重新开机";
  5822. //确保测试前先关机,发送关机指令再发送开机指令
  5823. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新发送关机指令" + "\r\n");
  5824. Code[0] = 0xF0;
  5825. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5826. Delay_ms(1500);
  5827. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新发送开机指令" + "\r\n");
  5828. Code[0] = 0xF1;
  5829. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5830. ACK_WaitCnt = 0;
  5831. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  5832. while (ACK_WaitCnt <= 20); //10s
  5833. //获取Boot版本信息
  5834. if (BootInfo != string.Empty)
  5835. {
  5836. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机成功" + "\r\n");
  5837. Delay_ms(500);
  5838. }
  5839. else
  5840. {
  5841. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机失败" + "\r\n");
  5842. label_FacModeStatus.Text = "存在故障!";
  5843. label_FacModeResult.BackColor = Color.Red;
  5844. label_FacModeResult.Text = "测试异常";
  5845. Delay_ms(500);
  5846. //存储异常并上传
  5847. FacMode_Stop(false);
  5848. return;
  5849. }
  5850. } while (false);
  5851. }
  5852. else
  5853. {
  5854. label_FacModeSysClear.BackColor = Color.Yellow;
  5855. label_FacModeStatus.Text = "跳过系统清除!";
  5856. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过系统清除" + "\r\n");
  5857. Delay_ms(500);
  5858. }
  5859. #if false
  5860. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  5861. {
  5862. Code[0] = 0x00;//5S协议
  5863. Code[1] = 0x00;
  5864. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5865. Delay_ms(500);
  5866. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5867. Delay_ms(500);
  5868. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  5869. }
  5870. #endif
  5871. //检查是否有故障
  5872. if (textBox_ErrorCode.Text.Contains("H"))
  5873. {
  5874. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "故障码:" + textBox_ErrorCode.Text + "\r\n");
  5875. label_FacModeStatus.Text = "电机存在故障!";
  5876. label_FacModeResult.BackColor = Color.Red;
  5877. label_FacModeResult.Text = "测试异常";
  5878. Delay_ms(500);
  5879. //存储异常并上传
  5880. FacMode_Stop(false);
  5881. return;
  5882. }
  5883. //MOS内阻校准
  5884. if (checkBox_FacMode_MosCal.Checked)
  5885. {
  5886. label_FacModeStatus.Text = "MOS内阻校准";
  5887. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始MOS内阻校准" + "\r\n");
  5888. Delay_ms(500);
  5889. //提示进行负载切换
  5890. if (MessageBox.Show("电阻负载切换完成,开始校准?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
  5891. {
  5892. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "取消MOS内阻校准" + "\r\n");
  5893. label_FacModeStatus.Text = "存在故障!";
  5894. label_FacModeResult.BackColor = Color.Red;
  5895. label_FacModeResult.Text = "测试异常";
  5896. Delay_ms(500);
  5897. //存储异常并上传
  5898. FacMode_Stop(false);
  5899. return;
  5900. }
  5901. //确认后发送校准指令
  5902. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令" + "\r\n");
  5903. string[] K = toolStripTextBox_MosCalK.Text.Split(',');
  5904. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  5905. ushort uwDataTemp = 0;
  5906. uwDataTemp = Convert.ToUInt16(K[0]);
  5907. Code[2] = (byte)(uwDataTemp & 0xFF);
  5908. Code[3] = (byte)(uwDataTemp >> 8);
  5909. uwDataTemp = Convert.ToUInt16(K[1]);
  5910. Code[4] = (byte)(uwDataTemp & 0xFF);
  5911. Code[5] = (byte)(uwDataTemp >> 8);
  5912. uwDataTemp = Convert.ToUInt16(K[2]);
  5913. Code[6] = (byte)(uwDataTemp & 0xFF);
  5914. Code[7] = (byte)(uwDataTemp >> 8);
  5915. uwDataTemp = Convert.ToUInt16(K[3]);
  5916. Code[8] = (byte)(uwDataTemp & 0xFF);
  5917. Code[9] = (byte)(uwDataTemp >> 8);
  5918. uwDataTemp = Convert.ToUInt16(K[4]);
  5919. Code[10] = (byte)(uwDataTemp & 0xFF);
  5920. Code[11] = (byte)(uwDataTemp >> 8);
  5921. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  5922. WriteACK = false;
  5923. WriteCnt = 0;
  5924. ACK_WaitCnt = 0;
  5925. while (ACK_WaitCnt <= 6) ; //3s
  5926. if (WriteACK == true)
  5927. {
  5928. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  5929. }
  5930. else
  5931. {
  5932. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令,第1次重发" + "\r\n");
  5933. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  5934. ACK_WaitCnt = 0;
  5935. while (ACK_WaitCnt <= 6) ; //3s
  5936. if (WriteACK == true)
  5937. {
  5938. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  5939. }
  5940. else
  5941. {
  5942. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令,第2次重发" + "\r\n");
  5943. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  5944. ACK_WaitCnt = 0;
  5945. while (ACK_WaitCnt <= 6) ; //3s
  5946. if (WriteACK == true)
  5947. {
  5948. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  5949. }
  5950. else
  5951. {
  5952. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准异常" + "\r\n");
  5953. label_FacModeStatus.Text = "存在故障!";
  5954. label_FacModeResult.BackColor = Color.Red;
  5955. label_FacModeResult.Text = "测试异常";
  5956. Delay_ms(500);
  5957. //存储异常并上传
  5958. FacMode_Stop(false);
  5959. return;
  5960. }
  5961. }
  5962. }
  5963. #if false
  5964. //因控制器复位需发送指令重新进入5S协议
  5965. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  5966. {
  5967. Code[0] = 0x00;//5S协议
  5968. Code[1] = 0x00;
  5969. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5970. Delay_ms(500);
  5971. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5972. Delay_ms(500);
  5973. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  5974. }
  5975. #endif
  5976. //读取显示校准返回数据
  5977. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果" + "\r\n");
  5978. foreach (Control c in groupBox21.Controls)
  5979. {
  5980. if (c is TextBox)
  5981. c.Text = "";
  5982. }
  5983. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  5984. ACK_WaitCnt = 0;
  5985. while (ACK_WaitCnt <= 2) ; //1s
  5986. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  5987. {
  5988. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果,第1次重发" + "\r\n");
  5989. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  5990. ACK_WaitCnt = 0;
  5991. while (ACK_WaitCnt <= 2) ; //1s
  5992. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  5993. {
  5994. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果,第2次重发" + "\r\n");
  5995. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  5996. ACK_WaitCnt = 0;
  5997. while (ACK_WaitCnt <= 2) ; //1s
  5998. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  5999. {
  6000. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果异常" + "\r\n");
  6001. label_FacModeStatus.Text = "存在故障!";
  6002. label_FacModeResult.BackColor = Color.Red;
  6003. label_FacModeResult.Text = "测试异常";
  6004. Delay_ms(500);
  6005. //存储异常并上传
  6006. FacMode_Stop(false);
  6007. return;
  6008. }
  6009. }
  6010. }
  6011. else
  6012. {
  6013. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻:" + textBox_MOS_R1.Text + " " + textBox_MOS_R2.Text + " " + textBox_MOS_R3.Text + "\r\n");
  6014. }
  6015. //与校准返回数据对比
  6016. string[] MOS_R1_Th = toolStripTextBox_MOS1.Text.Split(',');
  6017. string[] MOS_R2_Th = toolStripTextBox_MOS2.Text.Split(',');
  6018. string[] MOS_R3_Th = toolStripTextBox_MOS3.Text.Split(',');
  6019. if ((Convert.ToUInt16(textBox_MOS_R1.Text) >= Convert.ToUInt16(MOS_R1_Th[0])) && (Convert.ToUInt16(textBox_MOS_R1.Text) <= Convert.ToUInt16(MOS_R1_Th[1])) &&
  6020. (Convert.ToUInt16(textBox_MOS_R2.Text) >= Convert.ToUInt16(MOS_R2_Th[0])) && (Convert.ToUInt16(textBox_MOS_R2.Text) <= Convert.ToUInt16(MOS_R2_Th[1])) &&
  6021. (Convert.ToUInt16(textBox_MOS_R3.Text) >= Convert.ToUInt16(MOS_R3_Th[0])) && (Convert.ToUInt16(textBox_MOS_R3.Text) <= Convert.ToUInt16(MOS_R3_Th[1]))
  6022. )
  6023. {
  6024. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准合格" + "\r\n");
  6025. label_FacModeMosCal.BackColor = Color.Green;
  6026. //提示切换负载
  6027. MessageBox.Show("请将负载切换回电机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  6028. }
  6029. else
  6030. {
  6031. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准超范围" + "\r\n");
  6032. label_FacModeStatus.Text = "存在故障!";
  6033. label_FacModeResult.BackColor = Color.Red;
  6034. label_FacModeResult.Text = "测试异常";
  6035. Delay_ms(500);
  6036. //存储异常并上传
  6037. FacMode_Stop(false);
  6038. //提示切换负载
  6039. MessageBox.Show("请将负载切换回电机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  6040. return;
  6041. }
  6042. }
  6043. else
  6044. {
  6045. label_FacModeMosCal.BackColor = Color.Yellow;
  6046. label_FacModeStatus.Text = "跳过MOS内阻校准!";
  6047. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过MOS内阻校准" + "\r\n");
  6048. Delay_ms(500);
  6049. }
  6050. //位置校准
  6051. if (checkBox_FacMode_AngleCal.Checked)
  6052. {
  6053. //校准前进行一次开关机保存初始化数据
  6054. BootInfo = "";
  6055. label_FacModeStatus.Text = "位置校准";
  6056. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始位置校准" + "\r\n");
  6057. //确保测试前先关机,发送关机指令再发送开机指令
  6058. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  6059. Code[0] = 0xF0;
  6060. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6061. Delay_ms(1500);
  6062. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  6063. Code[0] = 0xF1;
  6064. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6065. ACK_WaitCnt = 0;
  6066. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  6067. while (ACK_WaitCnt <= 10) ; //5s
  6068. //获取Boot版本信息
  6069. if (BootInfo != string.Empty)
  6070. {
  6071. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机成功" + "\r\n");
  6072. Delay_ms(500);
  6073. }
  6074. else
  6075. {
  6076. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机失败" + "\r\n");
  6077. label_FacModeStatus.Text = "存在故障!";
  6078. label_FacModeResult.BackColor = Color.Red;
  6079. label_FacModeResult.Text = "测试异常";
  6080. Delay_ms(500);
  6081. //存储异常并上传
  6082. FacMode_Stop(false);
  6083. return;
  6084. }
  6085. //发送位置校准指令
  6086. for (int i = 0; i < 7; i++)
  6087. for (int j = 0; j < 6; j++)
  6088. {
  6089. dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = "";
  6090. }
  6091. foreach (Control cr in tabPage_AngleCal.Controls)
  6092. {
  6093. if (cr is TextBox)
  6094. {
  6095. if ((cr != textBox_AngleDiffTh) && (cr != textBox_AngleZeroTh))
  6096. cr.Text = "";
  6097. }
  6098. }
  6099. Code[0] = 0;
  6100. Code[1] = 0;
  6101. mySerialProcess.SendCmd((ushort)0x751, (byte)0x0C, (ushort)0x5002, Code);
  6102. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准中,请等待" + "\r\n");
  6103. ACK_WaitCnt = 0;
  6104. while (ACK_WaitCnt <= 50) ; //25s
  6105. //读取位置校准数据
  6106. if (textBox_AngleDiffAvg.Text == string.Empty)
  6107. {
  6108. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准失败" + "\r\n");
  6109. label_FacModeStatus.Text = "存在故障!";
  6110. label_FacModeResult.BackColor = Color.Red;
  6111. label_FacModeResult.Text = "测试异常";
  6112. Delay_ms(500);
  6113. //存储异常并上传
  6114. FacMode_Stop(false);
  6115. return;
  6116. }
  6117. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准数据:" + "\r\n");
  6118. for (int i = 0; i < 7; i++)
  6119. {
  6120. richTextBox_FacModeLog.AppendText("电周期" + (i + 1).ToString()+":");
  6121. for (int j = 0; j < 6; j++)
  6122. {
  6123. richTextBox_FacModeLog.AppendText(dataGridView_AngleCal.Rows[i].Cells[j + 1].Value.ToString() + ", ");
  6124. }
  6125. richTextBox_FacModeLog.AppendText("\r\n");
  6126. Delay_ms(200);
  6127. }
  6128. richTextBox_FacModeLog.AppendText("最小偏差:" + textBox_AngleDiffMin.Text+ ", " + "\r\n");
  6129. richTextBox_FacModeLog.AppendText("最大偏差:" + textBox_AngleDiffMax.Text + ", " + "\r\n");
  6130. richTextBox_FacModeLog.AppendText("平均偏差:" + textBox_AngleDiffAvg.Text + ", " + "\r\n");
  6131. richTextBox_FacModeLog.AppendText("历史零点:" + textBox_AngleZeroInit.Text + ", " + "\r\n");
  6132. richTextBox_FacModeLog.AppendText("当前零点:" + textBox_AngleZeroCur.Text + ", " + "\r\n");
  6133. richTextBox_FacModeLog.AppendText("零点偏差:" + textBox_AngleZeroDiff.Text + ", " + "\r\n");
  6134. //比较位置偏差
  6135. if ((Math.Abs(Convert.ToDouble(textBox_AngleDiffMin.Text)) > Convert.ToDouble(textBox_AngleDiffTh.Text)) ||
  6136. (Math.Abs(Convert.ToDouble(textBox_AngleDiffMax.Text)) > Convert.ToDouble(textBox_AngleDiffTh.Text)) ||
  6137. (Math.Abs(Convert.ToDouble(textBox_AngleDiffAvg.Text)) > Convert.ToDouble(textBox_AngleZeroTh.Text))
  6138. )
  6139. {
  6140. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差过大,无法校准" + "\r\n");
  6141. label_FacModeStatus.Text = "存在故障!";
  6142. label_FacModeResult.BackColor = Color.Red;
  6143. label_FacModeResult.Text = "测试异常";
  6144. Delay_ms(500);
  6145. //存储异常并上传
  6146. FacMode_Stop(false);
  6147. return;
  6148. }
  6149. //写入校准偏差值
  6150. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差满足要求,写入校准数据" + "\r\n");
  6151. double data1 = Convert.ToDouble(textBox_AngleZeroInit.Text) - Convert.ToDouble(textBox_AngleDiffAvg.Text);
  6152. if (data1 > 360)
  6153. {
  6154. data1 -= 360;
  6155. }
  6156. else if (data1 < -360)
  6157. {
  6158. data1 += 360;
  6159. }
  6160. Int16 data2 = (Int16)(data1 * 32768 / 360);
  6161. Code[0] = 0x01;
  6162. Code[1] = 0x00;
  6163. Code[2] = (byte)(data2);
  6164. Code[3] = (byte)(data2 >> 8);
  6165. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
  6166. WriteACK = false;
  6167. ACK_WaitCnt = 0;
  6168. while (ACK_WaitCnt <= 2) ; //1s
  6169. if (WriteACK == true)
  6170. {
  6171. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
  6172. }
  6173. else
  6174. {
  6175. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入位置偏差,第1次重发" + "\r\n");
  6176. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
  6177. WriteACK = false;
  6178. ACK_WaitCnt = 0;
  6179. while (ACK_WaitCnt <= 2) ; //1s
  6180. if (WriteACK == true)
  6181. {
  6182. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
  6183. }
  6184. else
  6185. {
  6186. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入位置偏差,第2次重发" + "\r\n");
  6187. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
  6188. WriteACK = false;
  6189. ACK_WaitCnt = 0;
  6190. while (ACK_WaitCnt <= 2) ; //1s
  6191. if (WriteACK == true)
  6192. {
  6193. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
  6194. }
  6195. else
  6196. {
  6197. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入失败" + "\r\n");
  6198. label_FacModeStatus.Text = "存在故障!";
  6199. label_FacModeResult.BackColor = Color.Red;
  6200. label_FacModeResult.Text = "测试异常";
  6201. Delay_ms(500);
  6202. //存储异常并上传
  6203. FacMode_Stop(false);
  6204. return;
  6205. }
  6206. }
  6207. }
  6208. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准正常,位置偏差值:" + textBox_AngleDiffAvg.Text + "\r\n");
  6209. label_FacModeAngleCal.BackColor = Color.Green;
  6210. }
  6211. else
  6212. {
  6213. label_FacModeAngleCal.BackColor = Color.Yellow;
  6214. label_FacModeStatus.Text = "跳过位置校准!";
  6215. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过位置校准" + "\r\n");
  6216. Delay_ms(500);
  6217. }
  6218. //参数写入
  6219. if (checkBox_FacModeCfgWrite.Checked)
  6220. {
  6221. label_FacModeStatus.Text = "参数写入";
  6222. //写入产品型号和SN
  6223. do
  6224. {
  6225. //根据扫码信息获取型号和SN
  6226. string ScanInfo = textBox_FacModeScan.Text;
  6227. string regexInfo = "";
  6228. string[] InfoList = { "" };
  6229. try
  6230. {
  6231. if (中置电机ToolStripMenuItem.Checked == true)
  6232. {
  6233. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  6234. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  6235. }
  6236. else if (轮毂电机ToolStripMenuItem.Checked == true)
  6237. {
  6238. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  6239. string Model = InfoList[0];
  6240. string Spec = InfoList[1];
  6241. string Sn = InfoList[2];
  6242. InfoList[0] = Model.Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  6243. InfoList[1] = Sn;
  6244. }
  6245. }
  6246. catch
  6247. {
  6248. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  6249. label_FacModeStatus.Text = "存在故障!";
  6250. label_FacModeResult.BackColor = Color.Red;
  6251. label_FacModeResult.Text = "标签格式错误";
  6252. Delay_ms(500);
  6253. //存储异常并上传
  6254. FacMode_Stop(false);
  6255. return;
  6256. }
  6257. if (InfoList.Length >= 2)
  6258. {
  6259. //检查配置文件是否与打标信息一致
  6260. //...
  6261. //写入型号
  6262. label_FacModeStatus.Text = "写入型号";
  6263. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号" + "\r\n");
  6264. textBox_FacModeName.Text = InfoList[0];
  6265. string Mode = textBox_FacModeName.Text;
  6266. var ModeArray = new byte[16];
  6267. for (ushort i = 0; i < Mode.Length; i++)
  6268. {
  6269. ModeArray[i] = (byte)Mode[i];
  6270. }
  6271. if (Mode.Length < 16)
  6272. {
  6273. ModeArray[Mode.Length] = (byte)'.';
  6274. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  6275. {
  6276. ModeArray[Mode.Length + 1 + i] = 0x20;
  6277. }
  6278. }
  6279. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6280. WriteACK = false;
  6281. WriteCnt = 0;
  6282. ACK_WaitCnt = 0;
  6283. while (ACK_WaitCnt <= 2); //1s
  6284. if (WriteACK == true)
  6285. {
  6286. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6287. }
  6288. else
  6289. {
  6290. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号,第1次重发" + "\r\n");
  6291. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6292. ACK_WaitCnt = 0;
  6293. while (ACK_WaitCnt <= 2) ; //1s
  6294. if (WriteACK == true)
  6295. {
  6296. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6297. }
  6298. else
  6299. {
  6300. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号,第2次重发" + "\r\n");
  6301. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6302. ACK_WaitCnt = 0;
  6303. while (ACK_WaitCnt <= 2) ; //1s
  6304. if (WriteACK == true)
  6305. {
  6306. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6307. }
  6308. else
  6309. {
  6310. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入失败" + "\r\n");
  6311. label_FacModeStatus.Text = "存在故障!";
  6312. label_FacModeResult.BackColor = Color.Red;
  6313. label_FacModeResult.Text = "测试异常";
  6314. Delay_ms(500);
  6315. //存储异常并上传
  6316. FacMode_Stop(false);
  6317. return;
  6318. }
  6319. }
  6320. }
  6321. //写入SN
  6322. label_FacModeStatus.Text = "写入SN";
  6323. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN" + "\r\n");
  6324. textBox_FacModeNum.Text = InfoList[1];
  6325. string SN = textBox_FacModeNum.Text;
  6326. var SNArray = new byte[16];
  6327. for (ushort i = 0; i < SN.Length; i++)
  6328. {
  6329. SNArray[i] = (byte)SN[i];
  6330. }
  6331. if (SN.Length < 16)
  6332. {
  6333. SNArray[SN.Length] = (byte)'.';
  6334. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  6335. {
  6336. SNArray[SN.Length + 1 + i] = 0x20;
  6337. }
  6338. }
  6339. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6340. WriteACK = false;
  6341. WriteCnt = 0;
  6342. ACK_WaitCnt = 0;
  6343. while (ACK_WaitCnt <= 2); //1s
  6344. if (WriteACK == true)
  6345. {
  6346. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  6347. }
  6348. else
  6349. {
  6350. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN,第1次重发" + "\r\n");
  6351. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6352. ACK_WaitCnt = 0;
  6353. while (ACK_WaitCnt <= 2) ; //1s
  6354. if (WriteACK == true)
  6355. {
  6356. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  6357. }
  6358. else
  6359. {
  6360. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN,第2次重发" + "\r\n");
  6361. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6362. ACK_WaitCnt = 0;
  6363. while (ACK_WaitCnt <= 2) ; //1s
  6364. if (WriteACK == true)
  6365. {
  6366. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  6367. }
  6368. else
  6369. {
  6370. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入失败" + "\r\n");
  6371. label_FacModeStatus.Text = "存在故障!";
  6372. label_FacModeResult.BackColor = Color.Red;
  6373. label_FacModeResult.Text = "测试异常";
  6374. Delay_ms(500);
  6375. //存储异常并上传
  6376. FacMode_Stop(false);
  6377. return;
  6378. }
  6379. }
  6380. }
  6381. }
  6382. else
  6383. {
  6384. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6385. return;
  6386. }
  6387. } while (false);
  6388. //写入配置文件
  6389. do
  6390. {
  6391. label_FacModeStatus.Text = "写入配置文件";
  6392. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  6393. //配置文件
  6394. List<byte[]> CmdList = new List<byte[]>();
  6395. //从服务器下载文件
  6396. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  6397. {
  6398. string SelectFile = "";
  6399. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "/" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  6400. if (File.Exists(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  6401. {
  6402. File.Delete(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  6403. }
  6404. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  6405. //打开文件
  6406. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  6407. CmdList.Clear();
  6408. while (streamReader.Peek() != -1)
  6409. {
  6410. string fileLineInfo = streamReader.ReadLine();
  6411. if (fileLineInfo.IndexOf("[") != -1)
  6412. {
  6413. continue;
  6414. }
  6415. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  6416. }
  6417. streamReader.Close();
  6418. }
  6419. //加载本地文件
  6420. else
  6421. {
  6422. string SelectFile = "";
  6423. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  6424. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  6425. CmdList.Clear();
  6426. while (streamReader.Peek() != -1)
  6427. {
  6428. string fileLineInfo = streamReader.ReadLine();
  6429. if (fileLineInfo.IndexOf("[") != -1)
  6430. {
  6431. continue;
  6432. }
  6433. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  6434. }
  6435. streamReader.Close();
  6436. }
  6437. int CmdNum = CmdList.Count(); //指令个数
  6438. Delay_ms(500);
  6439. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "开始写入" + "\r\n");
  6440. Delay_ms(500);
  6441. //开始写入
  6442. WriteCnt = 0;
  6443. for (int i = 0; i < CmdList.Count; i++)
  6444. {
  6445. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令" + "\r\n");
  6446. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6447. WriteACK = false;
  6448. ACK_WaitCnt = 0;
  6449. while (ACK_WaitCnt <= 2) ; //1s
  6450. if (WriteACK == true)
  6451. {
  6452. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6453. }
  6454. else
  6455. {
  6456. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令,第1次重发" + "\r\n");
  6457. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6458. WriteACK = false;
  6459. ACK_WaitCnt = 0;
  6460. while (ACK_WaitCnt <= 2) ; //1s
  6461. if (WriteACK == true)
  6462. {
  6463. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6464. }
  6465. else
  6466. {
  6467. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令,第2次重发" + "\r\n");
  6468. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6469. WriteACK = false;
  6470. ACK_WaitCnt = 0;
  6471. while (ACK_WaitCnt <= 2) ; //1s
  6472. if (WriteACK == true)
  6473. {
  6474. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6475. }
  6476. else
  6477. {
  6478. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入失败," + "共" + CmdNum.ToString() + "条指令," + "写入成功" + i.ToString() + "条" + "\r\n");
  6479. label_FacModeStatus.Text = "存在故障!";
  6480. label_FacModeResult.BackColor = Color.Red;
  6481. label_FacModeResult.Text = "测试异常";
  6482. Delay_ms(500);
  6483. //存储异常并上传
  6484. FacMode_Stop(false);
  6485. return;
  6486. }
  6487. }
  6488. }
  6489. }
  6490. //写入完成
  6491. label_FacMode_CfgWrite.BackColor = Color.Green;
  6492. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入成功" + "\r\n");
  6493. Delay_ms(500);
  6494. } while (false);
  6495. }
  6496. else
  6497. {
  6498. label_FacMode_CfgWrite.BackColor = Color.Yellow;
  6499. label_FacModeStatus.Text = "跳过参数写入!";
  6500. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数写入" + "\r\n");
  6501. Delay_ms(500);
  6502. }
  6503. //BMS通讯
  6504. if (checkBox_FacModeBMS.Checked)
  6505. {
  6506. if (label_FacModeBMS.BackColor == Color.Red)
  6507. {
  6508. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "BMS通讯异常" + "\r\n");
  6509. label_FacModeStatus.Text = "存在故障!";
  6510. label_FacModeResult.BackColor = Color.Red;
  6511. label_FacModeResult.Text = "测试异常";
  6512. Delay_ms(500);
  6513. //存储异常并上传
  6514. FacMode_Stop(false);
  6515. return;
  6516. }
  6517. }
  6518. else
  6519. {
  6520. label_FacModeBMS.BackColor = Color.Yellow;
  6521. label_FacModeStatus.Text = "跳过BMS通讯检测!";
  6522. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过BMS通讯检测" + "\r\n");
  6523. Delay_ms(500);
  6524. }
  6525. //基础功能检测
  6526. if (checkBox_FacBaseFucTest.Checked)
  6527. {
  6528. label_FacModeStatus.Text = "基础功能检测";
  6529. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始基础功能检测" + "\r\n");
  6530. //确认负载位置
  6531. if (checkBox_FacMode_MosCal.Checked)
  6532. {
  6533. if (MessageBox.Show("请再次确认负载是否切换回电机?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  6534. {
  6535. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "负载已切换为电机,继续测试" + "\r\n");
  6536. }
  6537. else
  6538. {
  6539. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试取消" + "\r\n");
  6540. label_FacModeStatus.Text = "存在故障!";
  6541. label_FacModeResult.BackColor = Color.Red;
  6542. label_FacModeResult.Text = "测试异常";
  6543. Delay_ms(500);
  6544. //存储异常并上传
  6545. FacMode_Stop(false);
  6546. return;
  6547. }
  6548. }
  6549. //发送指令进入配置模式
  6550. do
  6551. {
  6552. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6553. Code[0] = 0x01;
  6554. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6555. WriteACK = false;
  6556. WriteCnt = 0;
  6557. ACK_WaitCnt = 0;
  6558. while (ACK_WaitCnt <= 2); //1s
  6559. if (textBox_RunInfo_Vol.Text != "---")
  6560. {
  6561. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6562. }
  6563. else
  6564. {
  6565. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  6566. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6567. ACK_WaitCnt = 0;
  6568. while (ACK_WaitCnt <= 2) ; //1s
  6569. if (textBox_RunInfo_Vol.Text != "---")
  6570. {
  6571. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6572. }
  6573. else
  6574. {
  6575. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  6576. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6577. ACK_WaitCnt = 0;
  6578. while (ACK_WaitCnt <= 2) ; //1s
  6579. if (textBox_RunInfo_Vol.Text != "---")
  6580. {
  6581. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6582. }
  6583. else
  6584. {
  6585. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  6586. label_FacModeStatus.Text = "存在故障!";
  6587. label_FacModeResult.BackColor = Color.Red;
  6588. label_FacModeResult.Text = "测试异常";
  6589. Delay_ms(500);
  6590. //存储异常并上传
  6591. FacMode_Stop(false);
  6592. return;
  6593. }
  6594. }
  6595. }
  6596. } while (false);
  6597. //发送指令启动电机
  6598. do
  6599. {
  6600. #if false //通过运行模式3启动电机
  6601. //发送指令读取调试信息
  6602. richTextBox_DebugParam.Clear();
  6603. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  6604. WriteACK = false;
  6605. WriteCnt = 0;
  6606. ACK_WaitCnt = 0;
  6607. while (ACK_WaitCnt <= 2); //1s
  6608. //获取调试信息
  6609. string DebugDefaultInfo = "";
  6610. if (richTextBox_DebugParam.Text == string.Empty)
  6611. {
  6612. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
  6613. label_FacModeStatus.Text = "存在故障!";
  6614. label_FacModeResult.BackColor = Color.Red;
  6615. label_FacModeResult.Text = "测试异常";
  6616. Delay_ms(500);
  6617. //存储异常并上传
  6618. FacMode_Stop(false);
  6619. return;
  6620. }
  6621. else
  6622. {
  6623. DebugDefaultInfo = richTextBox_DebugParam.Text;
  6624. }
  6625. //设置模式
  6626. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  6627. strDataTemp[0] = "整体运行模式=3";
  6628. //发送数据
  6629. Code[0] = 0;
  6630. Code[1] = 0;
  6631. for (int i = 0; i < strDataTemp.Length; i++)
  6632. {
  6633. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  6634. Code[2 * i + 2] = (byte)uwDataTemp;
  6635. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  6636. }
  6637. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  6638. label_FacModeStatus.Text = "启动电机";
  6639. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "启动电机" + "\r\n");
  6640. #else //通过Walk模式启动电机
  6641. //设置转速100%
  6642. var Data = new byte[1];
  6643. Data[0] = (byte)100;
  6644. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6645. Delay_ms(500);
  6646. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6647. Delay_ms(500);
  6648. //启动电机进入WALK模式
  6649. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "基础功能检测,进入WALK" + "\r\n");
  6650. Code[0] = 0x22;
  6651. Code[1] = 0xF0;
  6652. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6653. WriteACK = false;
  6654. WriteCnt = 0;
  6655. ACK_WaitCnt = 0;
  6656. while (ACK_WaitCnt <= 2) ; //1s
  6657. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6658. {
  6659. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第1次重发" + "\r\n");
  6660. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6661. ACK_WaitCnt = 0;
  6662. while (ACK_WaitCnt <= 2) ; //1s
  6663. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6664. {
  6665. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第2次重发" + "\r\n");
  6666. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6667. ACK_WaitCnt = 0;
  6668. while (ACK_WaitCnt <= 2) ; //1s
  6669. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6670. {
  6671. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
  6672. label_FacModeStatus.Text = "存在故障!";
  6673. label_FacModeResult.BackColor = Color.Red;
  6674. label_FacModeResult.Text = "测试异常";
  6675. Delay_ms(500);
  6676. //存储异常并上传
  6677. FacMode_Stop(false);
  6678. return;
  6679. }
  6680. }
  6681. }
  6682. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入WALK,开始检测" + "\r\n");
  6683. #endif
  6684. Delay_ms(3000);
  6685. } while (false);
  6686. //判断车速
  6687. if ((Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) <= Convert.ToDouble( toolStripTextBox_ThBikeSpeed.Text.Split(',')[1])) &&
  6688. (Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThBikeSpeed.Text.Split(',')[0])))
  6689. {
  6690. label_FacModeSpeed.BackColor = Color.Green;
  6691. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器正常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
  6692. }
  6693. else
  6694. {
  6695. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器异常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
  6696. label_FacModeStatus.Text = "存在故障!";
  6697. label_FacModeResult.BackColor = Color.Red;
  6698. label_FacModeResult.Text = "测试异常";
  6699. Delay_ms(500);
  6700. //存储异常并上传
  6701. FacMode_Stop(false);
  6702. return;
  6703. }
  6704. //判断电压
  6705. if ((Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[1])) &&
  6706. (Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[0])))
  6707. {
  6708. label_FacModeVolTest.BackColor = Color.Green;
  6709. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量正常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
  6710. }
  6711. else
  6712. {
  6713. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量异常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
  6714. label_FacModeStatus.Text = "存在故障!";
  6715. label_FacModeResult.BackColor = Color.Red;
  6716. label_FacModeResult.Text = "测试异常";
  6717. Delay_ms(500);
  6718. //存储异常并上传
  6719. FacMode_Stop(false);
  6720. return;
  6721. }
  6722. //判断电流
  6723. if ((Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[1])) &&
  6724. (Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[0])))
  6725. {
  6726. label_FacModeCurrentTest.BackColor = Color.Green;
  6727. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量正常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  6728. }
  6729. else
  6730. {
  6731. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量异常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  6732. label_FacModeStatus.Text = "存在故障!";
  6733. label_FacModeResult.BackColor = Color.Red;
  6734. label_FacModeResult.Text = "测试异常";
  6735. Delay_ms(500);
  6736. //存储异常并上传
  6737. FacMode_Stop(false);
  6738. return;
  6739. }
  6740. //判断温度
  6741. if ((Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[1])) &&
  6742. (Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[0])) &&
  6743. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[1])) &&
  6744. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[0])) &&
  6745. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[1])) &&
  6746. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[0])))
  6747. {
  6748. label_FacModeNTC.BackColor = Color.Green;
  6749. 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");
  6750. }
  6751. else
  6752. {
  6753. 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");
  6754. label_FacModeStatus.Text = "存在故障!";
  6755. label_FacModeResult.BackColor = Color.Red;
  6756. label_FacModeResult.Text = "测试异常";
  6757. Delay_ms(500);
  6758. //存储异常并上传
  6759. FacMode_Stop(false);
  6760. return;
  6761. }
  6762. //判断转速
  6763. if ((Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[1])) &&
  6764. (Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[0])))
  6765. {
  6766. label_FacModeMotorSpeed.BackColor = Color.Green;
  6767. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速正常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
  6768. }
  6769. else
  6770. {
  6771. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速异常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
  6772. label_FacModeStatus.Text = "存在故障!";
  6773. label_FacModeResult.BackColor = Color.Red;
  6774. label_FacModeResult.Text = "测试异常";
  6775. Delay_ms(500);
  6776. //存储异常并上传
  6777. FacMode_Stop(false);
  6778. return;
  6779. }
  6780. //发送指令停止电机
  6781. do
  6782. {
  6783. //设置转速0%
  6784. var Data = new byte[1];
  6785. Data[0] = (byte)0;
  6786. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6787. Delay_ms(500);
  6788. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6789. Delay_ms(500);
  6790. #if false //通过修改调试模式停止电机
  6791. //获取调试信息
  6792. string DebugDefaultInfo = "";
  6793. if (richTextBox_DebugParam.Text == string.Empty)
  6794. {
  6795. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
  6796. label_FacModeStatus.Text = "存在故障!";
  6797. label_FacModeResult.BackColor = Color.Red;
  6798. label_FacModeResult.Text = "测试异常";
  6799. Delay_ms(500);
  6800. //存储异常并上传
  6801. FacMode_Stop(false);
  6802. return;
  6803. }
  6804. else
  6805. {
  6806. DebugDefaultInfo = richTextBox_DebugParam.Text;
  6807. }
  6808. //设置模式
  6809. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  6810. //发送数据
  6811. Code[0] = 0;
  6812. Code[1] = 0;
  6813. for (int i = 0; i < strDataTemp.Length; i++)
  6814. {
  6815. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  6816. Code[2 * i + 2] = (byte)uwDataTemp;
  6817. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  6818. }
  6819. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  6820. label_FacModeStatus.Text = "停止电机";
  6821. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "停止电机" + "\r\n");
  6822. #else //通过调整档位停止电机
  6823. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK" + "\r\n");
  6824. Code[0] = 0x00;
  6825. Code[1] = 0xF0;
  6826. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6827. WriteACK = false;
  6828. WriteCnt = 0;
  6829. ACK_WaitCnt = 0;
  6830. while (ACK_WaitCnt <= 2) ; //1s
  6831. if (textBox_RunInfo_GearSt.Text != "OFF")
  6832. {
  6833. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK,第1次重发" + "\r\n");
  6834. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6835. ACK_WaitCnt = 0;
  6836. while (ACK_WaitCnt <= 2) ; //1s
  6837. if (textBox_RunInfo_GearSt.Text != "OFF")
  6838. {
  6839. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK,第2次重发" + "\r\n");
  6840. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6841. ACK_WaitCnt = 0;
  6842. while (ACK_WaitCnt <= 2) ; //1s
  6843. if (textBox_RunInfo_GearSt.Text != "OFF")
  6844. {
  6845. }
  6846. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
  6847. label_FacModeStatus.Text = "存在故障!";
  6848. label_FacModeResult.BackColor = Color.Red;
  6849. label_FacModeResult.Text = "测试异常";
  6850. Delay_ms(500);
  6851. //存储异常并上传
  6852. FacMode_Stop(false);
  6853. return;
  6854. }
  6855. }
  6856. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已退出WALK,基础功能检测完成" + "\r\n");
  6857. #endif
  6858. Delay_ms(2000);
  6859. } while (false);
  6860. }
  6861. else
  6862. {
  6863. label_FacModeSpeed.BackColor = Color.Yellow;
  6864. label_FacModeVolTest.BackColor = Color.Yellow;
  6865. label_FacModeCurrentTest.BackColor = Color.Yellow;
  6866. label_FacModeNTC.BackColor = Color.Yellow;
  6867. label_FacModeMotorSpeed.BackColor = Color.Yellow;
  6868. label_FacModeStatus.Text = "跳过基础功能检测!";
  6869. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过基础功能检测" + "\r\n");
  6870. Delay_ms(500);
  6871. }
  6872. //力矩检测
  6873. if (checkBox_FacTor.Checked)
  6874. {
  6875. label_FacModeStatus.Text = "力矩传感器检测!";
  6876. //发送指令进入配置模式
  6877. do
  6878. {
  6879. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  6880. {
  6881. break;
  6882. }
  6883. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6884. Code[0] = 0x01;
  6885. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6886. WriteACK = false;
  6887. WriteCnt = 0;
  6888. ACK_WaitCnt = 0;
  6889. while (ACK_WaitCnt <= 2) ; //1s
  6890. if (textBox_RunInfo_Vol.Text != "---")
  6891. {
  6892. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6893. Delay_ms(500);
  6894. }
  6895. else
  6896. {
  6897. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  6898. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6899. ACK_WaitCnt = 0;
  6900. while (ACK_WaitCnt <= 2) ; //1s
  6901. if (textBox_RunInfo_Vol.Text != "---")
  6902. {
  6903. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6904. Delay_ms(500);
  6905. }
  6906. else
  6907. {
  6908. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  6909. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6910. ACK_WaitCnt = 0;
  6911. while (ACK_WaitCnt <= 2) ; //1s
  6912. if (textBox_RunInfo_Vol.Text != "---")
  6913. {
  6914. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6915. Delay_ms(500);
  6916. }
  6917. else
  6918. {
  6919. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  6920. label_FacModeStatus.Text = "存在故障!";
  6921. label_FacModeResult.BackColor = Color.Red;
  6922. label_FacModeResult.Text = "测试异常";
  6923. Delay_ms(500);
  6924. //存储异常并上传
  6925. FacMode_Stop(false);
  6926. return;
  6927. }
  6928. }
  6929. }
  6930. } while (false);
  6931. ushort Max = 0, Torque = 0;
  6932. //提示输入力矩信号
  6933. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟力矩信号输入" + "\r\n");
  6934. ACK_WaitCnt = 0;
  6935. while (ACK_WaitCnt <= 20) //10s
  6936. {
  6937. //获取力矩值
  6938. Torque = (ushort)Convert.ToInt16(textBox_RunInfo_Torque.Text.Split(' ')[0]);
  6939. if (Torque > Max)
  6940. Max = Torque;
  6941. if ((Max <= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[1])) &&
  6942. (Max >= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[0])) &&
  6943. (ACK_WaitCnt >= 6))
  6944. {
  6945. label_FacModeTq.BackColor = Color.Green;
  6946. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器正常" + " " + textBox_RunInfo_Torque.Text + "\r\n");
  6947. break;
  6948. }
  6949. }
  6950. if (ACK_WaitCnt >= 20)
  6951. {
  6952. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器异常" + " " + textBox_RunInfo_Torque.Text + "\r\n");
  6953. label_FacModeStatus.Text = "存在故障!";
  6954. label_FacModeResult.BackColor = Color.Red;
  6955. label_FacModeResult.Text = "测试异常";
  6956. Delay_ms(500);
  6957. //存储异常并上传
  6958. FacMode_Stop(false);
  6959. return;
  6960. }
  6961. }
  6962. else
  6963. {
  6964. label_FacModeTq.BackColor = Color.Yellow;
  6965. label_FacModeStatus.Text = "跳过力矩检测!";
  6966. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过力矩检测" + "\r\n");
  6967. Delay_ms(500);
  6968. }
  6969. //踏频检测
  6970. if (checkBox_FacCad.Checked)
  6971. {
  6972. label_FacModeStatus.Text = "踏频传感器检测!";
  6973. //发送指令进入配置模式
  6974. do
  6975. {
  6976. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  6977. {
  6978. break;
  6979. }
  6980. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6981. Code[0] = 0x01;
  6982. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6983. WriteACK = false;
  6984. WriteCnt = 0;
  6985. ACK_WaitCnt = 0;
  6986. while (ACK_WaitCnt <= 2) ; //1s
  6987. if (textBox_RunInfo_Vol.Text != "---")
  6988. {
  6989. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6990. Delay_ms(500);
  6991. }
  6992. else
  6993. {
  6994. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  6995. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6996. ACK_WaitCnt = 0;
  6997. while (ACK_WaitCnt <= 2) ; //1s
  6998. if (textBox_RunInfo_Vol.Text != "---")
  6999. {
  7000. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7001. Delay_ms(500);
  7002. }
  7003. else
  7004. {
  7005. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7006. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7007. ACK_WaitCnt = 0;
  7008. while (ACK_WaitCnt <= 2) ; //1s
  7009. if (textBox_RunInfo_Vol.Text != "---")
  7010. {
  7011. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7012. Delay_ms(500);
  7013. }
  7014. else
  7015. {
  7016. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7017. label_FacModeStatus.Text = "存在故障!";
  7018. label_FacModeResult.BackColor = Color.Red;
  7019. label_FacModeResult.Text = "测试异常";
  7020. Delay_ms(500);
  7021. //存储异常并上传
  7022. FacMode_Stop(false);
  7023. return;
  7024. }
  7025. }
  7026. }
  7027. } while (false);
  7028. ushort Max = 0, Cadence = 0;
  7029. //提示输入踏频信号
  7030. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟踏频信号输入" + "\r\n");
  7031. ACK_WaitCnt = 0;
  7032. while (ACK_WaitCnt <= 20) //10s
  7033. {
  7034. //获取踏频
  7035. Cadence = (ushort)Convert.ToInt16(textBox_RunInfo_Cadence.Text.Split(' ')[0]);
  7036. if (Cadence > Max)
  7037. Max = Cadence;
  7038. if ((Max <= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[1])) &&
  7039. (Max >= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[0])) &&
  7040. (ACK_WaitCnt >= 6))
  7041. {
  7042. label_FacModeCad.BackColor = Color.Green;
  7043. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器正常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  7044. break;
  7045. }
  7046. }
  7047. if (ACK_WaitCnt >= 20)
  7048. {
  7049. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器异常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  7050. label_FacModeStatus.Text = "存在故障!";
  7051. label_FacModeResult.BackColor = Color.Red;
  7052. label_FacModeResult.Text = "测试异常";
  7053. Delay_ms(500);
  7054. //存储异常并上传
  7055. FacMode_Stop(false);
  7056. return;
  7057. }
  7058. }
  7059. else
  7060. {
  7061. label_FacModeCad.BackColor = Color.Yellow;
  7062. label_FacModeStatus.Text = "跳过踏频检测!";
  7063. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过踏频检测" + "\r\n");
  7064. Delay_ms(500);
  7065. }
  7066. //转把检测
  7067. if (checkBox_FacThrrotleTest.Checked)
  7068. {
  7069. label_FacModeStatus.Text = "转把检测";
  7070. //发送指令进入配置模式
  7071. do
  7072. {
  7073. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  7074. {
  7075. break;
  7076. }
  7077. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  7078. Code[0] = 0x01;
  7079. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7080. WriteACK = false;
  7081. WriteCnt = 0;
  7082. ACK_WaitCnt = 0;
  7083. while (ACK_WaitCnt <= 2) ; //1s
  7084. if (textBox_RunInfo_Vol.Text != "---")
  7085. {
  7086. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7087. Delay_ms(500);
  7088. }
  7089. else
  7090. {
  7091. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  7092. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7093. ACK_WaitCnt = 0;
  7094. while (ACK_WaitCnt <= 2) ; //1s
  7095. if (textBox_RunInfo_Vol.Text != "---")
  7096. {
  7097. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7098. Delay_ms(500);
  7099. }
  7100. else
  7101. {
  7102. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7103. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7104. ACK_WaitCnt = 0;
  7105. while (ACK_WaitCnt <= 2) ; //1s
  7106. if (textBox_RunInfo_Vol.Text != "---")
  7107. {
  7108. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7109. Delay_ms(500);
  7110. }
  7111. else
  7112. {
  7113. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7114. label_FacModeStatus.Text = "存在故障!";
  7115. label_FacModeResult.BackColor = Color.Red;
  7116. label_FacModeResult.Text = "测试异常";
  7117. Delay_ms(500);
  7118. //存储异常并上传
  7119. FacMode_Stop(false);
  7120. return;
  7121. }
  7122. }
  7123. }
  7124. } while (false);
  7125. //进入TURBO档
  7126. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把检测,发送指令进入TURBO" + "\r\n");
  7127. Code[0] = 0x04;
  7128. Code[1] = 0xF0;
  7129. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7130. WriteACK = false;
  7131. WriteCnt = 0;
  7132. ACK_WaitCnt = 0;
  7133. while (ACK_WaitCnt <= 2) ; //1s
  7134. if (textBox_RunInfo_GearSt.Text != "TURBO")
  7135. {
  7136. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO,第1次重发" + "\r\n");
  7137. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7138. ACK_WaitCnt = 0;
  7139. while (ACK_WaitCnt <= 2) ; //1s
  7140. if (textBox_RunInfo_GearSt.Text != "TURBO")
  7141. {
  7142. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO,第2次重发" + "\r\n");
  7143. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7144. ACK_WaitCnt = 0;
  7145. while (ACK_WaitCnt <= 2) ; //1s
  7146. if (textBox_RunInfo_GearSt.Text != "TURBO")
  7147. {
  7148. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO异常" + "\r\n");
  7149. label_FacModeStatus.Text = "存在故障!";
  7150. label_FacModeResult.BackColor = Color.Red;
  7151. label_FacModeResult.Text = "测试异常";
  7152. Delay_ms(500);
  7153. //存储异常并上传
  7154. FacMode_Stop(false);
  7155. return;
  7156. }
  7157. }
  7158. }
  7159. //进入TURBO后,如果电机直接启动,认为转把电压异常
  7160. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把自检,请松开转把" + "\r\n");
  7161. Delay_ms(3000);
  7162. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) > 500)
  7163. {
  7164. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把电压异常" + "\r\n");
  7165. label_FacModeStatus.Text = "存在故障!";
  7166. label_FacModeResult.BackColor = Color.Red;
  7167. label_FacModeResult.Text = "测试异常";
  7168. Delay_ms(500);
  7169. //存储异常并上传
  7170. FacMode_Stop(false);
  7171. return;
  7172. }
  7173. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把自检正常" + "\r\n");
  7174. Delay_ms(500);
  7175. //提示转动转把
  7176. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入TURBO,10s内转动转把" + "\r\n");
  7177. ACK_WaitCnt = 0;
  7178. while (ACK_WaitCnt <= 20)
  7179. {
  7180. if ((Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) > 500) && (ACK_WaitCnt >= 10))
  7181. {
  7182. label_FacModeGas.BackColor = Color.Green;
  7183. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能正常,松开转把" + "\r\n");
  7184. break;
  7185. }
  7186. }
  7187. if (ACK_WaitCnt >= 20) //转把超时
  7188. {
  7189. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能异常,松开转把" + "\r\n");
  7190. label_FacModeStatus.Text = "存在故障!";
  7191. label_FacModeResult.BackColor = Color.Red;
  7192. label_FacModeResult.Text = "测试异常";
  7193. Delay_ms(500);
  7194. //存储异常并上传
  7195. FacMode_Stop(false);
  7196. return;
  7197. }
  7198. }
  7199. else
  7200. {
  7201. label_FacModeGas.BackColor = Color.Yellow;
  7202. label_FacModeStatus.Text = "跳过转把检测!";
  7203. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过转把检测" + "\r\n");
  7204. Delay_ms(500);
  7205. }
  7206. //刹车检测
  7207. if (checkBox_FacBreakTest.Checked)
  7208. {
  7209. label_FacModeStatus.Text = "刹把检测";
  7210. //发送指令进入配置模式
  7211. do
  7212. {
  7213. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  7214. {
  7215. break;
  7216. }
  7217. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  7218. Code[0] = 0x01;
  7219. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7220. WriteACK = false;
  7221. WriteCnt = 0;
  7222. ACK_WaitCnt = 0;
  7223. while (ACK_WaitCnt <= 2) ; //1s
  7224. if (textBox_RunInfo_Vol.Text != "---")
  7225. {
  7226. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7227. Delay_ms(500);
  7228. }
  7229. else
  7230. {
  7231. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  7232. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7233. ACK_WaitCnt = 0;
  7234. while (ACK_WaitCnt <= 2) ; //1s
  7235. if (textBox_RunInfo_Vol.Text != "---")
  7236. {
  7237. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7238. Delay_ms(500);
  7239. }
  7240. else
  7241. {
  7242. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7243. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7244. ACK_WaitCnt = 0;
  7245. while (ACK_WaitCnt <= 2) ; //1s
  7246. if (textBox_RunInfo_Vol.Text != "---")
  7247. {
  7248. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7249. Delay_ms(500);
  7250. }
  7251. else
  7252. {
  7253. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7254. label_FacModeStatus.Text = "存在故障!";
  7255. label_FacModeResult.BackColor = Color.Red;
  7256. label_FacModeResult.Text = "测试异常";
  7257. Delay_ms(500);
  7258. //存储异常并上传
  7259. FacMode_Stop(false);
  7260. return;
  7261. }
  7262. }
  7263. }
  7264. } while (false);
  7265. //测试前先确定电机已停止
  7266. UInt16 WaitTime = 10;
  7267. do
  7268. {
  7269. WaitTime--;
  7270. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 100)
  7271. {
  7272. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机停止,开始进行剎把检测,进入WALK" + "\r\n");
  7273. break;
  7274. }
  7275. if (WaitTime == 0)
  7276. {
  7277. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机无法停止,剎把检测异常" + "\r\n");
  7278. label_FacModeStatus.Text = "存在故障!";
  7279. label_FacModeResult.BackColor = Color.Red;
  7280. label_FacModeResult.Text = "测试异常";
  7281. Delay_ms(500);
  7282. //存储异常并上传
  7283. FacMode_Stop(false);
  7284. return;
  7285. }
  7286. Delay_ms(500);
  7287. } while (true);
  7288. //设置转速100%
  7289. var Data = new byte[1];
  7290. Data[0] = (byte)100;
  7291. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7292. Delay_ms(500);
  7293. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7294. Delay_ms(500);
  7295. //启动电机进入WALK模式
  7296. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把检测,进入WALK" + "\r\n");
  7297. Code[0] = 0x22;
  7298. Code[1] = 0xF0;
  7299. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7300. WriteACK = false;
  7301. WriteCnt = 0;
  7302. ACK_WaitCnt = 0;
  7303. while (ACK_WaitCnt <= 2) ; //1s
  7304. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 500))
  7305. {
  7306. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第1次重发" + "\r\n");
  7307. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7308. ACK_WaitCnt = 0;
  7309. while (ACK_WaitCnt <= 2) ; //1s
  7310. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 500))
  7311. {
  7312. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第2次重发" + "\r\n");
  7313. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7314. ACK_WaitCnt = 0;
  7315. while (ACK_WaitCnt <= 2) ; //1s
  7316. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 500))
  7317. {
  7318. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
  7319. label_FacModeStatus.Text = "存在故障!";
  7320. label_FacModeResult.BackColor = Color.Red;
  7321. label_FacModeResult.Text = "测试异常";
  7322. Delay_ms(500);
  7323. //存储异常并上传
  7324. FacMode_Stop(false);
  7325. return;
  7326. }
  7327. }
  7328. }
  7329. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,10s内操作剎把" + "\r\n");
  7330. ACK_WaitCnt = 0;
  7331. while (ACK_WaitCnt <= 20)
  7332. {
  7333. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 100)
  7334. {
  7335. label_FacModeBreak.BackColor = Color.Green;
  7336. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把功能正常,松开剎把" + "\r\n");
  7337. break;
  7338. }
  7339. }
  7340. if (ACK_WaitCnt >= 20) //剎把超时
  7341. {
  7342. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速:" + textBox_RunInfo_MotorSpeed.Text + "," + "剎把功能异常,松开剎把" + "\r\n");
  7343. label_FacModeStatus.Text = "存在故障!";
  7344. label_FacModeResult.BackColor = Color.Red;
  7345. label_FacModeResult.Text = "测试异常";
  7346. Delay_ms(500);
  7347. //存储异常并上传
  7348. FacMode_Stop(false);
  7349. return;
  7350. }
  7351. //停止电机
  7352. Code[0] = 0x00;
  7353. Code[1] = 0xF0;
  7354. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7355. WriteACK = false;
  7356. WriteCnt = 0;
  7357. ACK_WaitCnt = 0;
  7358. while (ACK_WaitCnt <= 2) ; //1s
  7359. if (textBox_RunInfo_GearSt.Text != "OFF")
  7360. {
  7361. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK,第1次重发" + "\r\n");
  7362. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7363. ACK_WaitCnt = 0;
  7364. while (ACK_WaitCnt <= 2) ; //1s
  7365. if (textBox_RunInfo_GearSt.Text != "OFF")
  7366. {
  7367. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK,第2次重发" + "\r\n");
  7368. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7369. ACK_WaitCnt = 0;
  7370. while (ACK_WaitCnt <= 2) ; //1s
  7371. if (textBox_RunInfo_GearSt.Text != "OFF")
  7372. {
  7373. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
  7374. label_FacModeStatus.Text = "存在故障!";
  7375. label_FacModeResult.BackColor = Color.Red;
  7376. label_FacModeResult.Text = "测试异常";
  7377. Delay_ms(500);
  7378. //存储异常并上传
  7379. FacMode_Stop(false);
  7380. return;
  7381. }
  7382. }
  7383. }
  7384. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK" + "\r\n");
  7385. Delay_ms(500);
  7386. }
  7387. else
  7388. {
  7389. label_FacModeBreak.BackColor = Color.Yellow;
  7390. label_FacModeStatus.Text = "跳过刹车检测!";
  7391. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过刹车检测" + "\r\n");
  7392. Delay_ms(500);
  7393. }
  7394. //前后灯检测
  7395. if (checkBox_FacLightTest.Checked)
  7396. {
  7397. //前后灯检测
  7398. label_FacModeStatus.Text = "前后灯检测";
  7399. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开灯指令" + "\r\n");
  7400. //发送指令打开车灯
  7401. Code[0] = 0x00;
  7402. Code[1] = 0xF1;
  7403. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7404. WriteACK = false;
  7405. WriteCnt = 0;
  7406. ACK_WaitCnt = 0;
  7407. while (ACK_WaitCnt <= 2) ; //1s
  7408. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7409. {
  7410. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令,第1次重发" + "\r\n");
  7411. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7412. ACK_WaitCnt = 0;
  7413. while (ACK_WaitCnt <= 2); //1s
  7414. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7415. {
  7416. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令,第2次重发" + "\r\n");
  7417. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7418. ACK_WaitCnt = 0;
  7419. while (ACK_WaitCnt <= 2) ; //1s
  7420. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7421. {
  7422. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令发送异常" + "\r\n");
  7423. label_FacModeStatus.Text = "存在故障!";
  7424. label_FacModeResult.BackColor = Color.Red;
  7425. label_FacModeResult.Text = "测试异常";
  7426. Delay_ms(500);
  7427. //存储异常并上传
  7428. FacMode_Stop(false);
  7429. return;
  7430. }
  7431. }
  7432. }
  7433. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已打开前后灯" + "\r\n");
  7434. Delay_ms(500);
  7435. //提示检查灯压是否正确
  7436. if (MessageBox.Show("前后灯是否正常开启?", "前后灯判断", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  7437. {
  7438. label_FacModeLightF.BackColor = Color.Green;
  7439. label_FacModeLightB.BackColor = Color.Green;
  7440. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯正常" + "\r\n");
  7441. Delay_ms(500);
  7442. }
  7443. else
  7444. {
  7445. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯异常" + "\r\n");
  7446. label_FacModeStatus.Text = "存在故障!";
  7447. label_FacModeResult.BackColor = Color.Red;
  7448. label_FacModeResult.Text = "测试异常";
  7449. Delay_ms(500);
  7450. //存储异常并上传
  7451. FacMode_Stop(false);
  7452. return;
  7453. }
  7454. //发送指令关闭车灯
  7455. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关灯指令" + "\r\n");
  7456. Code[0] = 0x00;
  7457. Code[1] = 0xF0;
  7458. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7459. WriteACK = false;
  7460. WriteCnt = 0;
  7461. ACK_WaitCnt = 0;
  7462. while (ACK_WaitCnt <= 2) ; //1s
  7463. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7464. {
  7465. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令,第1次重发" + "\r\n");
  7466. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7467. ACK_WaitCnt = 0;
  7468. while (ACK_WaitCnt <= 2) ; //1s
  7469. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7470. {
  7471. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令,第2次重发" + "\r\n");
  7472. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7473. ACK_WaitCnt = 0;
  7474. while (ACK_WaitCnt <= 2) ; //1s
  7475. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7476. {
  7477. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令发送异常" + "\r\n");
  7478. label_FacModeStatus.Text = "存在故障!";
  7479. label_FacModeResult.BackColor = Color.Red;
  7480. label_FacModeResult.Text = "测试异常";
  7481. Delay_ms(500);
  7482. //存储异常并上传
  7483. FacMode_Stop(false);
  7484. return;
  7485. }
  7486. }
  7487. }
  7488. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已关闭前后灯" + "\r\n");
  7489. Delay_ms(500);
  7490. }
  7491. else
  7492. {
  7493. label_FacModeLightF.BackColor = Color.Yellow;
  7494. label_FacModeLightB.BackColor = Color.Yellow;
  7495. label_FacModeStatus.Text = "跳过前后灯检测!";
  7496. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过前后灯检测" + "\r\n");
  7497. Delay_ms(500);
  7498. }
  7499. //软件版本检测
  7500. do
  7501. {
  7502. label_FacModeStatus.Text = "软件版本确认";
  7503. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  7504. //发送指令读取版本
  7505. Class_Motor_Ver.Mode = "---";
  7506. Class_Motor_Ver.SN = "---";
  7507. Class_Motor_Ver.HW = "---";
  7508. Class_Motor_Ver.FW = "---";
  7509. Class_Motor_Ver.Special = "---";
  7510. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7511. ACK_WaitCnt = 0;
  7512. while (ACK_WaitCnt <= 2) ; //1s
  7513. if (Class_Motor_Ver.Mode == "---")
  7514. {
  7515. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第1次重发" + "\r\n");
  7516. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7517. ACK_WaitCnt = 0;
  7518. while (ACK_WaitCnt <= 2) ; //1s
  7519. if (Class_Motor_Ver.Mode == "---")
  7520. {
  7521. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第2次重发" + "\r\n");
  7522. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7523. ACK_WaitCnt = 0;
  7524. while (ACK_WaitCnt <= 2) ; //1s
  7525. if (Class_Motor_Ver.Mode == "---")
  7526. {
  7527. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息失败" + "\r\n");
  7528. label_FacModeStatus.Text = "存在故障!";
  7529. label_FacModeResult.BackColor = Color.Red;
  7530. label_FacModeResult.Text = "测试异常";
  7531. Delay_ms(500);
  7532. //存储异常并上传
  7533. FacMode_Stop(false);
  7534. return;
  7535. }
  7536. }
  7537. }
  7538. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  7539. richTextBox_FacModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  7540. richTextBox_FacModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  7541. richTextBox_FacModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  7542. richTextBox_FacModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  7543. richTextBox_FacModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  7544. //判断版本是否正确
  7545. string VerCheck = comboBox_FacModeCfgFile.Text.Split('_')[3] + "_" + comboBox_FacModeCfgFile.Text.Split('_')[4];
  7546. string VerRead = "";
  7547. try
  7548. {
  7549. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  7550. }
  7551. catch (System.Exception)
  7552. {
  7553. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  7554. label_FacModeStatus.Text = "存在故障!";
  7555. label_FacModeResult.BackColor = Color.Red;
  7556. label_FacModeResult.Text = "测试异常";
  7557. Delay_ms(500);
  7558. //存储异常并上传
  7559. FacMode_Stop(false);
  7560. return;
  7561. }
  7562. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  7563. {
  7564. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
  7565. label_FacModeStatus.Text = "存在故障!";
  7566. label_FacModeResult.BackColor = Color.Red;
  7567. label_FacModeResult.Text = "测试异常";
  7568. Delay_ms(500);
  7569. //存储异常并上传
  7570. FacMode_Stop(false);
  7571. return;
  7572. }
  7573. label_FacModeFWVersion.BackColor = Color.Green;
  7574. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  7575. Delay_ms(500);
  7576. } while (false);
  7577. //测试合格
  7578. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  7579. label_FacModeStatus.Text = "测试结束!";
  7580. label_FacModeResult.BackColor = Color.Green;
  7581. label_FacModeResult.Text = "测试合格";
  7582. Delay_ms(500);
  7583. //存储并上传
  7584. FacMode_Stop(true);
  7585. return;
  7586. }
  7587. private void FacModelLabelInit()
  7588. {
  7589. //测试状态标签
  7590. label_FacModeResult.BackColor = Color.Yellow;
  7591. label_FacModeResult.Text = "测试中";
  7592. //测试过程标签
  7593. label_FacModeStatus.Text = "测试就绪";
  7594. //测试结果标签
  7595. foreach (Control c in groupBox28.Controls)
  7596. {
  7597. if (c is Label)
  7598. {
  7599. if (c.Text == string.Empty)
  7600. c.BackColor = Color.Red;
  7601. }
  7602. }
  7603. }
  7604. private void comboBox_CheckModeCfgDate_Click(object sender, EventArgs e)
  7605. {
  7606. //更新生产配置文件目录
  7607. GetDateList(false);
  7608. }
  7609. private void comboBox_FacModeCfgDate_Click(object sender, EventArgs e)
  7610. {
  7611. //更新生产配置文件目录
  7612. GetDateList(false);
  7613. }
  7614. private void richTextBox_FacModeLog_TextChanged(object sender, EventArgs e)
  7615. {
  7616. richTextBox_FacModeLog.SelectionStart = richTextBox_FacModeLog.Text.Length;
  7617. richTextBox_FacModeLog.ScrollToCaret();
  7618. }
  7619. /// <summary>
  7620. /// 参数检验测试停止
  7621. /// </summary>
  7622. /// <param name="OK_Flag"></param>
  7623. private void CheckMode_Stop(bool OK_Flag)
  7624. {
  7625. //打开开始按钮
  7626. button_CheckModeStart.Enabled = true;
  7627. //导出电机参数
  7628. string Params = "";
  7629. do
  7630. {
  7631. if (!OK_Flag)
  7632. {
  7633. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试异常,停止导出" + "\r\n");
  7634. break;
  7635. }
  7636. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "导出电机存储参数" + "\r\n");
  7637. //读取一次马达参数
  7638. richTextBox_MotorParam.Clear();
  7639. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break; ;
  7640. Delay_ms(100);
  7641. Params += "[马达参数]" + "\r\n" + richTextBox_MotorParam.Text + "\r\n";
  7642. Params += "\r\n";
  7643. //读取一次整车参数
  7644. richTextBox_BikeParam.Clear();
  7645. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  7646. Delay_ms(100);
  7647. Params += "[整车参数]" + "\r\n" + richTextBox_BikeParam.Text + "\r\n";
  7648. Params += "\r\n";
  7649. //读取一次控制参数
  7650. richTextBox_ControlParam.Clear();
  7651. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  7652. Delay_ms(100);
  7653. Params += "[控制参数]" + "\r\n" + richTextBox_ControlParam.Text + "\r\n";
  7654. Params += "\r\n";
  7655. //查询传感器
  7656. richTextBox_SensorParam.Clear();
  7657. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  7658. Delay_ms(100);
  7659. Params += "[传感器参数]" + "\r\n" + richTextBox_SensorParam.Text + "\r\n";
  7660. Params += "\r\n";
  7661. //读取15次助力参数
  7662. Params += "[助力参数]" + "\r\n";
  7663. for (int i = 1; i <= 15; i++)
  7664. {
  7665. var ConfigParam = new byte[4];
  7666. richTextBox_AssistParam.Clear();
  7667. ConfigParam[0] = (byte)(i & 0xFF);
  7668. ConfigParam[1] = (byte)(i >> 8);
  7669. ConfigParam[2] = (byte)(((i >= 5) ? 5 : i) & 0xFF);
  7670. ConfigParam[3] = (byte)(((i >= 5) ? 5 : i) >> 8);
  7671. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  7672. Delay_ms(200);
  7673. Params += richTextBox_AssistParam.Text + "\r\n";
  7674. Params += "\r\n";
  7675. }
  7676. //读取一次调试信息
  7677. richTextBox_DebugParam.Clear();
  7678. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  7679. Delay_ms(100);
  7680. Params += "[调试参数]" + "\r\n" + richTextBox_DebugParam.Text + "\r\n";
  7681. Params += "\r\n";
  7682. //读取一次历史信息
  7683. richTextBox_Record.Clear();
  7684. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  7685. Delay_ms(100);
  7686. Params += "[历史信息]" + "\r\n" + richTextBox_Record.Text + "\r\n";
  7687. Params += "\r\n";
  7688. //读取一次MOS内阻校准参数
  7689. foreach (Control c in groupBox21.Controls)
  7690. {
  7691. if (c is TextBox)
  7692. c.Text = "";
  7693. }
  7694. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  7695. Delay_ms(100);
  7696. Params += "[MOS内阻校准参数]" + "\r\n";
  7697. Params += textBox_MOS_K1.Text + ", " + textBox_MOS_K2.Text + ", " + textBox_MOS_K3.Text + ", " + textBox_MOS_K4.Text + ", "
  7698. + textBox_MOS_K5.Text + ", " + textBox_MOS_R1.Text + ", " + textBox_MOS_R2.Text + ", " + textBox_MOS_R3.Text + ", " + "\r\n";
  7699. Params += "\r\n";
  7700. //读取一次整车参数2
  7701. richTextBox_BikeParam2.Clear();
  7702. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null)) break;
  7703. Delay_ms(100);
  7704. Params += "[整车参数2]" + "\r\n" + richTextBox_BikeParam2.Text + "\r\n";
  7705. Params += "\r\n";
  7706. //读取一次用户骑行参数
  7707. richTextBox_UsrRidesParam.Clear();
  7708. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  7709. Delay_ms(100);
  7710. Params += "[用户骑行参数]" + "\r\n" + richTextBox_UsrRidesParam.Text + "\r\n";
  7711. Params += "\r\n";
  7712. //读取一次生产信息
  7713. textBox_MAC.Text = "";
  7714. textBox_MACAdd.Text = "";
  7715. textBox_MACDate.Text = "";
  7716. textBox_PP.Text = "";
  7717. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  7718. Delay_ms(100);
  7719. Params += "[生产信息]" + "\r\n";
  7720. Params += "生产商: " + textBox_MAC.Text + "\r\n";
  7721. Params += "生产地: " + textBox_MACAdd.Text + "\r\n";
  7722. Params += "生产日期: " + textBox_MACDate.Text + "\r\n";
  7723. Params += "产品标识: " + textBox_PP.Text + "\r\n";
  7724. Params += "\r\n";
  7725. //读取一次自定义信息
  7726. textBox_User1.Text = "---";
  7727. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  7728. Delay_ms(100);
  7729. textBox_User2.Text = "---";
  7730. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  7731. Delay_ms(100);
  7732. textBox_User3.Text = "---";
  7733. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  7734. Delay_ms(100);
  7735. Params += "[自定义信息]" + "\r\n";
  7736. Params += "自定义1: " + textBox_User1.Text + "\r\n";
  7737. Params += "自定义2: " + textBox_User2.Text + "\r\n";
  7738. Params += "自定义3: " + textBox_User3.Text + "\r\n";
  7739. Params += "\r\n";
  7740. //读取一次密钥
  7741. textBox_Key.Text = "---";
  7742. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  7743. Delay_ms(100);
  7744. Params += "[校验密钥]" + "\r\n" + textBox_Key.Text + "\r\n";
  7745. Params += "\r\n";
  7746. //读取一次存储标志
  7747. radioButton_EE_SaveYes.Checked = false;
  7748. radioButton_EE_SaveNo.Checked = false;
  7749. radioButton_SIP_SaveYes.Checked = false;
  7750. radioButton_SIP_SaveNo.Checked = false;
  7751. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  7752. Delay_ms(100);
  7753. Params += "[存储标志]" + "\r\n";
  7754. Params += "EEPROM: " + ((radioButton_EE_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  7755. Params += "SIP: " + ((radioButton_SIP_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  7756. Params += "\r\n";
  7757. } while (false);
  7758. //系统关机
  7759. var Code = new byte[32];//发送的指令数据
  7760. Code[0] = 0xF0;
  7761. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  7762. //关闭串口
  7763. //mySerialProcess.SerialClose(false);
  7764. //路径设置
  7765. string LocalSavePath = "";
  7766. string ServerSavePath = "";
  7767. if (OK_Flag)
  7768. {
  7769. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "OK\\";
  7770. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/OK/";
  7771. }
  7772. else
  7773. {
  7774. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "FAIL\\";
  7775. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/FAIL/";
  7776. }
  7777. if (Directory.Exists(LocalSavePath) == false)
  7778. {
  7779. Directory.CreateDirectory(LocalSavePath);
  7780. }
  7781. //保存和上传
  7782. string LogSavePath = "";
  7783. string LogSaveFileName = "";
  7784. string ProductInfo = textBox_CheckModeScan.Text.Replace(" ", "_"); ;
  7785. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  7786. if (Directory.Exists(LogSavePath) == false)
  7787. {
  7788. Directory.CreateDirectory(LogSavePath);
  7789. }
  7790. //测试页面
  7791. Double scaleX = PrimaryScreen.ScaleX;
  7792. Double scaleY = PrimaryScreen.ScaleY;
  7793. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  7794. Graphics g = Graphics.FromImage(bit);
  7795. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  7796. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  7797. bit.Save(LogSaveFileName);
  7798. //上传测试页面到服务器
  7799. if (myFtp.IsNetConnected == true)
  7800. {
  7801. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  7802. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  7803. {
  7804. myFtp.MakeDir(ServerSavePath + DateNow);
  7805. }
  7806. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  7807. {
  7808. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  7809. }
  7810. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  7811. if (result == true)
  7812. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  7813. }
  7814. //测试记录
  7815. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  7816. string file_str = "";
  7817. file_str += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  7818. file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  7819. file_str += "检验记录:\r\n" + richTextBox_CheckModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  7820. file_str += "检验结果:\r\n" + label_CheckModeResult.Text + "\r\n\r\n";
  7821. file_str += Local_HdInformation;
  7822. file_str += "\r\n电机存储参数:\r\n" + Params + "\r\n";
  7823. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  7824. //上传测试记录到服务器
  7825. if (myFtp.IsNetConnected == true)
  7826. {
  7827. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  7828. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  7829. {
  7830. myFtp.MakeDir(ServerSavePath + DateNow);
  7831. }
  7832. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  7833. {
  7834. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  7835. }
  7836. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  7837. if (result == true)
  7838. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  7839. }
  7840. //扫码框清空
  7841. textBox_CheckModeScan.Text = "";
  7842. }
  7843. /// <summary>
  7844. /// 参数检验开始
  7845. /// </summary>
  7846. /// <param name="sender"></param>
  7847. /// <param name="e"></param>
  7848. private void button_CheckModeStart_Click(object sender, EventArgs e)
  7849. {
  7850. //测试项目关闭编辑
  7851. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  7852. foreach (Control c in groupBox29.Controls)
  7853. {
  7854. if (c is CheckBox)
  7855. c.Enabled = false;
  7856. }
  7857. ReadLockStatus = true;
  7858. //检查配置文件
  7859. if (comboBox_CheckModeCfgFile.Text == "")
  7860. {
  7861. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  7862. return;
  7863. }
  7864. //开始测试
  7865. CheckTestStart();
  7866. }
  7867. /// <summary>
  7868. /// 参数检验测试子函数
  7869. /// </summary>
  7870. private void CheckTestStart()
  7871. {
  7872. //初始化标签
  7873. CheckModeLabelInit();
  7874. richTextBox_CheckModeLog.Clear();
  7875. //按钮禁止操作
  7876. button_CheckModeStart.Enabled = false;
  7877. //记录配置文件
  7878. richTextBox_CheckModeLog.AppendText("配置文件:" + comboBox_CheckModeCfgDate.Text + " / " + comboBox_CheckModeCfgFile.Text + "\r\n");
  7879. //检查打标信息
  7880. label_CheckModeStatus.Text = "检查扫码信息";
  7881. Delay_ms(500);
  7882. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  7883. if (textBox_CheckModeScan.Text == string.Empty)
  7884. {
  7885. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  7886. button__FacMode_Start.Enabled = false;
  7887. return;
  7888. }
  7889. try
  7890. {
  7891. if (中置电机ToolStripMenuItem.Checked == true)
  7892. {
  7893. if (textBox_CheckModeScan.Text.Split(' ').Length != 7)
  7894. {
  7895. label_CheckModeStatus.Text = "存在故障!";
  7896. label_CheckModeResult.BackColor = Color.Red;
  7897. label_CheckModeResult.Text = "标签格式错误";
  7898. button_CheckModeStart.Enabled = true;
  7899. return;
  7900. }
  7901. }
  7902. else if (轮毂电机ToolStripMenuItem.Checked == true)
  7903. {
  7904. if (textBox_CheckModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  7905. {
  7906. label_CheckModeStatus.Text = "存在故障!";
  7907. label_CheckModeResult.BackColor = Color.Red;
  7908. label_CheckModeResult.Text = "标签格式错误";
  7909. button_CheckModeStart.Enabled = true;
  7910. return;
  7911. }
  7912. }
  7913. }
  7914. catch (System.Exception)
  7915. {
  7916. label_CheckModeStatus.Text = "存在故障!";
  7917. label_CheckModeResult.BackColor = Color.Red;
  7918. label_CheckModeResult.Text = "标签格式错误";
  7919. button_CheckModeStart.Enabled = true;
  7920. return;
  7921. }
  7922. //打开串口
  7923. mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false);
  7924. if (!mySerialProcess.mySerial.IsOpen)
  7925. {
  7926. MessageBox.Show("请检查串口连接!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  7927. button__FacMode_Start.Enabled = false;
  7928. return;
  7929. }
  7930. //流水号计数
  7931. int serial = Convert.ToInt32(label_CheckModeSerial.Text);
  7932. serial += 1;
  7933. label_CheckModeSerial.Text = serial.ToString();
  7934. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, serial.ToString());
  7935. //创建线程,执行测试任务
  7936. Thread th = new Thread(CheckModeTest_Task);
  7937. th.Start();
  7938. }
  7939. /// <summary>
  7940. /// 执行一次测试任务
  7941. /// </summary>
  7942. private void CheckModeTest_Task()
  7943. {
  7944. //开始测试
  7945. richTextBox_CheckModeLog.AppendText("产品标签:" + textBox_CheckModeScan.Text + "\r\n");
  7946. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  7947. //变量定义
  7948. var Code = new byte[255];//发送的指令数据
  7949. ushort DataTemp;
  7950. short DataTemp_Int16;
  7951. string ResultPathName = "";
  7952. label_CheckModeStatus.Text = "开始测试";
  7953. BootInfo = "";
  7954. Delay_ms(500);
  7955. label_CheckModeStatus.Text = "系统开机";
  7956. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  7957. if (uARTToolStripMenuItem.Checked)
  7958. {
  7959. Code[0] = (byte)'R';
  7960. Code[1] = (byte)'E';
  7961. Code[2] = (byte)'S';
  7962. Code[3] = (byte)'E';
  7963. Code[4] = (byte)'T';
  7964. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  7965. Delay_ms(500);
  7966. }
  7967. //系统开机,确保测试前先关机,发送关机指令再发送开机指令
  7968. //确保测试前先关机,发送关机指令再发送开机指令
  7969. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  7970. Code[0] = 0xF0;
  7971. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  7972. Delay_ms(1500);
  7973. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  7974. Code[0] = 0xF1;
  7975. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  7976. ACK_WaitCnt = 0;
  7977. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  7978. while (ACK_WaitCnt <= 20) ; //10s
  7979. //检查BOOT版本
  7980. if (BootInfo != string.Empty)
  7981. {
  7982. label_CheckModeBoot.BackColor = Color.Green;
  7983. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  7984. Delay_ms(500);
  7985. }
  7986. else
  7987. {
  7988. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
  7989. label_CheckModeStatus.Text = "存在故障!";
  7990. label_CheckModeResult.BackColor = Color.Red;
  7991. label_CheckModeResult.Text = "测试异常";
  7992. Delay_ms(500);
  7993. //存储异常并上传
  7994. CheckMode_Stop(false);
  7995. return;
  7996. }
  7997. #if false
  7998. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  7999. {
  8000. Code[0] = 0x00;//5S协议
  8001. Code[1] = 0x00;
  8002. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  8003. Delay_ms(500);
  8004. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  8005. Delay_ms(500);
  8006. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  8007. }
  8008. #endif
  8009. //发送指令读取版本信息
  8010. do
  8011. {
  8012. label_CheckModeStatus.Text = "读取版本信息";
  8013. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  8014. //发送指令读取版本
  8015. Class_Motor_Ver.Mode = "---";
  8016. Class_Motor_Ver.SN = "---";
  8017. Class_Motor_Ver.HW = "---";
  8018. Class_Motor_Ver.FW = "---";
  8019. Class_Motor_Ver.Special = "---";
  8020. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  8021. ACK_WaitCnt = 0;
  8022. while (ACK_WaitCnt <= 2) ; //1s
  8023. if (Class_Motor_Ver.Mode == "---")
  8024. {
  8025. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第1次重发" + "\r\n");
  8026. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  8027. ACK_WaitCnt = 0;
  8028. while (ACK_WaitCnt <= 2) ; //1s
  8029. if (Class_Motor_Ver.Mode == "---")
  8030. {
  8031. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第2次重发" + "\r\n");
  8032. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  8033. ACK_WaitCnt = 0;
  8034. while (ACK_WaitCnt <= 2) ; //1s
  8035. if (Class_Motor_Ver.Mode == "---")
  8036. {
  8037. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取失败" + "\r\n");
  8038. label_CheckModeStatus.Text = "存在故障!";
  8039. label_CheckModeResult.BackColor = Color.Red;
  8040. label_CheckModeResult.Text = "测试异常";
  8041. Delay_ms(500);
  8042. //存储异常并上传
  8043. CheckMode_Stop(false);
  8044. return;
  8045. }
  8046. }
  8047. }
  8048. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  8049. Delay_ms(500);
  8050. } while (false);
  8051. //软件版本检查
  8052. if (checkBox_CheckModeFWVer.Checked)
  8053. {
  8054. richTextBox_CheckModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  8055. richTextBox_CheckModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  8056. richTextBox_CheckModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  8057. richTextBox_CheckModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  8058. richTextBox_CheckModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  8059. //判断版本是否正确
  8060. string VerCheck = comboBox_CheckModeCfgFile.Text.Split('_')[3] + "_" + comboBox_CheckModeCfgFile.Text.Split('_')[4];
  8061. string VerRead = "";
  8062. try
  8063. {
  8064. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  8065. }
  8066. catch (System.Exception)
  8067. {
  8068. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  8069. label_CheckModeStatus.Text = "存在故障!";
  8070. label_CheckModeResult.BackColor = Color.Red;
  8071. label_CheckModeResult.Text = "测试异常";
  8072. Delay_ms(500);
  8073. //存储异常并上传
  8074. CheckMode_Stop(false);
  8075. return;
  8076. }
  8077. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  8078. {
  8079. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
  8080. label_CheckModeStatus.Text = "存在故障!";
  8081. label_CheckModeResult.BackColor = Color.Red;
  8082. label_CheckModeResult.Text = "测试异常";
  8083. Delay_ms(500);
  8084. //存储异常并上传
  8085. CheckMode_Stop(false);
  8086. return;
  8087. }
  8088. label_CheckModeFWVer.BackColor = Color.Green;
  8089. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  8090. Delay_ms(500);
  8091. }
  8092. else
  8093. {
  8094. label_CheckModeFWVer.BackColor = Color.Yellow;
  8095. label_CheckModeStatus.Text = "跳过软件版本查询";
  8096. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过软件版本查询" + "\r\n");
  8097. Delay_ms(500);
  8098. }
  8099. //打标信息核对
  8100. if (checkBox_CheckModeSN.Checked)
  8101. {
  8102. label_CheckModeStatus.Text = "核对打标信息";
  8103. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "核对打标信息" + "\r\n");
  8104. //根据扫码信息获取型号和SN
  8105. string ScanInfo = textBox_CheckModeScan.Text;
  8106. string regexInfo = "";
  8107. string[] InfoList = { "" };
  8108. try
  8109. {
  8110. if (中置电机ToolStripMenuItem.Checked == true)
  8111. {
  8112. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  8113. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  8114. }
  8115. else if (轮毂电机ToolStripMenuItem.Checked == true)
  8116. {
  8117. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  8118. string Model = InfoList[0];
  8119. string Spec = InfoList[1];
  8120. string Sn = InfoList[2];
  8121. InfoList[0] = Model.Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  8122. InfoList[1] = Sn;
  8123. }
  8124. }
  8125. catch
  8126. {
  8127. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  8128. label_FacModeStatus.Text = "存在故障!";
  8129. label_FacModeResult.BackColor = Color.Red;
  8130. label_FacModeResult.Text = "标签格式错误";
  8131. Delay_ms(500);
  8132. //存储异常并上传
  8133. CheckMode_Stop(false);
  8134. return;
  8135. }
  8136. //核对型号
  8137. if (string.Equals(InfoList[0], Class_Motor_Ver.Mode) == false) //型号错误,直接结束
  8138. {
  8139. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号不一致" + "\r\n");
  8140. label_CheckModeStatus.Text = "存在故障!";
  8141. label_CheckModeResult.BackColor = Color.Red;
  8142. label_CheckModeResult.Text = "测试异常";
  8143. Delay_ms(500);
  8144. //存储异常并上传
  8145. CheckMode_Stop(false);
  8146. return;
  8147. }
  8148. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号一致" + "\r\n");
  8149. Delay_ms(500);
  8150. //核对SN
  8151. if (string.Equals(InfoList[1], Class_Motor_Ver.SN) == false) //型号错误,直接结束
  8152. {
  8153. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN不一致" + "\r\n");
  8154. label_CheckModeStatus.Text = "存在故障!";
  8155. label_CheckModeResult.BackColor = Color.Red;
  8156. label_CheckModeResult.Text = "测试异常";
  8157. Delay_ms(500);
  8158. //存储异常并上传
  8159. CheckMode_Stop(false);
  8160. return;
  8161. }
  8162. label_CheckModeSN.BackColor = Color.Green;
  8163. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN一致" + "\r\n");
  8164. Delay_ms(500);
  8165. }
  8166. else
  8167. {
  8168. label_CheckModeSN.BackColor = Color.Yellow;
  8169. label_CheckModeStatus.Text = "跳过打标信息确认";
  8170. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过打标信息确认" + "\r\n");
  8171. Delay_ms(500);
  8172. }
  8173. //参数检验
  8174. if (checkBox_CheckModeCfg.Checked)
  8175. {
  8176. //读取配置文件信息
  8177. label_CheckModeStatus.Text = "参数检查";
  8178. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  8179. //配置文件
  8180. List<byte[]> CmdList = new List<byte[]>();
  8181. Dictionary<string, string> ConfigCmd = new Dictionary<string, string>();//配置文件格式
  8182. //从服务器下载文件
  8183. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  8184. {
  8185. string SelectFile = "";
  8186. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "/" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  8187. if (File.Exists(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  8188. {
  8189. File.Delete(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  8190. }
  8191. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  8192. //打开文件
  8193. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  8194. ConfigCmd.Clear();
  8195. while (streamReader.Peek() != -1)
  8196. {
  8197. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  8198. if (fileLineInfo.Contains("["))
  8199. {
  8200. if (fileLineInfo.Contains("助力参数"))
  8201. {
  8202. fileLineInfo = streamReader.ReadLine();
  8203. }
  8204. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  8205. }
  8206. }
  8207. streamReader.Close();
  8208. }
  8209. //从本地加载文件
  8210. else
  8211. {
  8212. string SelectFile = "";
  8213. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  8214. //打开文件
  8215. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  8216. ConfigCmd.Clear();
  8217. while (streamReader.Peek() != -1)
  8218. {
  8219. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  8220. if (fileLineInfo.Contains("["))
  8221. {
  8222. if (fileLineInfo.Contains("助力参数"))
  8223. {
  8224. fileLineInfo = streamReader.ReadLine();
  8225. }
  8226. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  8227. }
  8228. }
  8229. streamReader.Close();
  8230. }
  8231. int CmdNum = ConfigCmd.Count(); //指令个数
  8232. Delay_ms(500);
  8233. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "\r\n");
  8234. Delay_ms(500);
  8235. //逐条读取比较
  8236. try
  8237. {
  8238. foreach (string key in ConfigCmd.Keys)
  8239. {
  8240. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令:" + "\r\n");
  8241. CmdRevStrTemp = "";
  8242. if (key.Contains("曲线"))
  8243. {
  8244. byte LineNum = 0;
  8245. var code = new byte[4];
  8246. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  8247. if (LineNum <= 5)
  8248. {
  8249. code[0] = (byte)(LineNum & 0xFF);
  8250. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8251. code[2] = (byte)(LineNum & 0xFF);
  8252. code[3] = (byte)((LineNum >> 8) & 0xFF);
  8253. }
  8254. else
  8255. {
  8256. code[0] = (byte)(LineNum & 0xFF);
  8257. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8258. code[2] = (byte)(5 & 0xFF);
  8259. code[3] = (byte)((5 >> 8) & 0xFF);
  8260. }
  8261. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  8262. }
  8263. else
  8264. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  8265. Delay_ms(500);
  8266. if (CmdRevStrTemp == string.Empty)
  8267. {
  8268. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令,第1次重发" + "\r\n");
  8269. if (key.Contains("曲线"))
  8270. {
  8271. byte LineNum = 0;
  8272. var code = new byte[4];
  8273. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  8274. if (LineNum <= 5)
  8275. {
  8276. code[0] = (byte)(LineNum & 0xFF);
  8277. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8278. code[2] = (byte)(LineNum & 0xFF);
  8279. code[3] = (byte)((LineNum >> 8) & 0xFF);
  8280. }
  8281. else
  8282. {
  8283. code[0] = (byte)(LineNum & 0xFF);
  8284. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8285. code[2] = (byte)(5 & 0xFF);
  8286. code[3] = (byte)((5 >> 8) & 0xFF);
  8287. }
  8288. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  8289. }
  8290. else
  8291. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  8292. Delay_ms(500);
  8293. if (CmdRevStrTemp == string.Empty)
  8294. {
  8295. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令,第2次重发" + "\r\n");
  8296. if (key.Contains("曲线"))
  8297. {
  8298. byte LineNum = 0;
  8299. var code = new byte[4];
  8300. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  8301. if (LineNum <= 5)
  8302. {
  8303. code[0] = (byte)(LineNum & 0xFF);
  8304. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8305. code[2] = (byte)(LineNum & 0xFF);
  8306. code[3] = (byte)((LineNum >> 8) & 0xFF);
  8307. }
  8308. else
  8309. {
  8310. code[0] = (byte)(LineNum & 0xFF);
  8311. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8312. code[2] = (byte)(5 & 0xFF);
  8313. code[3] = (byte)((5 >> 8) & 0xFF);
  8314. }
  8315. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  8316. }
  8317. else
  8318. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  8319. Delay_ms(500);
  8320. if (CmdRevStrTemp == string.Empty)
  8321. {
  8322. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "指令读取失败" + "\r\n");
  8323. label_CheckModeStatus.Text = "存在故障!";
  8324. label_CheckModeResult.BackColor = Color.Red;
  8325. label_CheckModeResult.Text = "测试异常";
  8326. Delay_ms(500);
  8327. //存储异常并上传
  8328. CheckMode_Stop(false);
  8329. return;
  8330. }
  8331. }
  8332. }
  8333. //比较当前指令,读取的配置文件和返回数据比较
  8334. string ParamWrite = ConfigCmd[key].Substring(24, ConfigCmd[key].Length - 40).Trim();
  8335. string ParamRead = "";
  8336. if (string.Compare(key, "[其它传感器参数]") == 0)
  8337. ParamRead = CmdRevStrTemp.Substring(90, CmdRevStrTemp.Length - 90).Trim(); //去掉去掉命令字、力矩传感器参数
  8338. else if (string.Compare(key, "[控制参数]") == 0)
  8339. ParamRead = CmdRevStrTemp.Substring(18, CmdRevStrTemp.Length - 18).Trim(); //去掉去掉命令字、位置零点
  8340. else
  8341. ParamRead = CmdRevStrTemp.Substring(6, CmdRevStrTemp.Length - 6).Trim(); //去掉命令字
  8342. if (ParamWrite.Contains(ParamRead))
  8343. {
  8344. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "一致" + "\r\n");
  8345. continue;
  8346. }
  8347. else
  8348. {
  8349. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "不一致" + "\r\n");
  8350. richTextBox_CheckModeLog.AppendText("写入参数:" + ParamWrite + "\r\n");
  8351. richTextBox_CheckModeLog.AppendText("读出参数:" + ParamRead + "\r\n");
  8352. label_CheckModeStatus.Text = "存在故障!";
  8353. label_CheckModeResult.BackColor = Color.Red;
  8354. label_CheckModeResult.Text = "测试异常";
  8355. Delay_ms(500);
  8356. //存储异常并上传
  8357. CheckMode_Stop(false);
  8358. return;
  8359. }
  8360. }
  8361. }
  8362. catch (System.Exception)
  8363. {
  8364. timer_500ms.Enabled = false;
  8365. MessageBox.Show("参数检验失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  8366. timer_500ms.Enabled = true;
  8367. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  8368. }
  8369. }
  8370. else
  8371. {
  8372. label_CheckModeCfg.BackColor = Color.Yellow;
  8373. label_CheckModeStatus.Text = "跳过参数检验";
  8374. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数检验" + "\r\n");
  8375. Delay_ms(500);
  8376. }
  8377. label_CheckModeCfg.BackColor = Color.Green;
  8378. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数检验正确" + "\r\n");
  8379. Delay_ms(500);
  8380. //读取力矩传感器
  8381. do
  8382. {
  8383. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据" + "\r\n");
  8384. //发送指令读取力矩传感器标定数据
  8385. CmdRevStrTemp = "";
  8386. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  8387. ACK_WaitCnt = 0;
  8388. while (ACK_WaitCnt <= 2) ; //1s
  8389. if (CmdRevStrTemp == "---")
  8390. {
  8391. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据,第1次重发" + "\r\n");
  8392. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  8393. ACK_WaitCnt = 0;
  8394. while (ACK_WaitCnt <= 2) ; //1s
  8395. if (CmdRevStrTemp == "---")
  8396. {
  8397. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据,第2次重发" + "\r\n");
  8398. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  8399. ACK_WaitCnt = 0;
  8400. while (ACK_WaitCnt <= 2) ; //1s
  8401. if (CmdRevStrTemp == "---")
  8402. {
  8403. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取失败" + "\r\n");
  8404. label_CheckModeStatus.Text = "存在故障!";
  8405. label_CheckModeResult.BackColor = Color.Red;
  8406. label_CheckModeResult.Text = "测试异常";
  8407. Delay_ms(500);
  8408. //存储异常并上传
  8409. CheckMode_Stop(false);
  8410. return;
  8411. }
  8412. }
  8413. }
  8414. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取成功" + "\r\n");
  8415. //取力矩传感器数据
  8416. ushort ZeroInit, Zero1, Zero2, Zero3, ZeroNew;
  8417. ushort MaxTorque;
  8418. ushort K1_T, K1, K2_T, K2, K3_T, K3, K4_T, K4;
  8419. byte[] DataArray = mySerialProcess.HexStringToBytes(CmdRevStrTemp, true);
  8420. ZeroInit = (ushort)((DataArray[3] << 8) + DataArray[2]);
  8421. Zero1 = (ushort)((DataArray[5] << 8) + DataArray[4]);
  8422. Zero2 = (ushort)((DataArray[7] << 8) + DataArray[6]);
  8423. Zero3 = (ushort)((DataArray[9] << 8) + DataArray[8]);
  8424. ZeroNew = (ushort)((DataArray[11] << 8) + DataArray[10]);
  8425. MaxTorque = (ushort)((DataArray[13] << 8) + DataArray[12]);
  8426. K1_T = (ushort)((DataArray[15] << 8) + DataArray[14]);
  8427. K1 = (ushort)((DataArray[17] << 8) + DataArray[16]);
  8428. K2_T = (ushort)((DataArray[19] << 8) + DataArray[18]);
  8429. K2 = (ushort)((DataArray[21] << 8) + DataArray[20]);
  8430. K3_T = (ushort)((DataArray[23] << 8) + DataArray[22]);
  8431. K3 = (ushort)((DataArray[25] << 8) + DataArray[24]);
  8432. K4_T = (ushort)((DataArray[27] << 8) + DataArray[26]);
  8433. K4 = (ushort)((DataArray[29] << 8) + DataArray[28]);
  8434. richTextBox_CheckModeLog.AppendText("力矩传感器零点: " + ZeroInit.ToString() + "," + Zero1.ToString() + "," +
  8435. Zero2.ToString() + "," + Zero3.ToString() + "," + ZeroNew.ToString() + "\r\n");
  8436. richTextBox_CheckModeLog.AppendText("最大力矩: " + MaxTorque.ToString() + "\r\n");
  8437. richTextBox_CheckModeLog.AppendText("力矩传感器标定: " + "[" + K1_T.ToString() + "," + K1.ToString() + "]" + "," +
  8438. "[" + K2_T.ToString() + "," + K2.ToString() + "]" + "," + "[" + K3_T.ToString() + "," + K3.ToString() + "]" + "," +
  8439. "[" + K4_T.ToString() + "," + K4.ToString() + "]" + "\r\n");
  8440. //传感器标定检验
  8441. if (checkBox_CheckModeTorque.Checked)
  8442. {
  8443. richTextBox_CheckModeLog.AppendText("力矩零点范围: " + TorqueParamsForm.Zero.Min.ToString() + " - " + TorqueParamsForm.Zero.Max.ToString() + "\r\n");
  8444. richTextBox_CheckModeLog.AppendText("K1范围: " + TorqueParamsForm.K1.T.ToString() + "," + TorqueParamsForm.K1.Min.ToString() + " - " + TorqueParamsForm.K1.Max.ToString() + "\r\n");
  8445. richTextBox_CheckModeLog.AppendText("K2范围: " + TorqueParamsForm.K2.T.ToString() + "," + TorqueParamsForm.K2.Min.ToString() + " - " + TorqueParamsForm.K2.Max.ToString() + "\r\n");
  8446. richTextBox_CheckModeLog.AppendText("K3范围: " + TorqueParamsForm.K3.T.ToString() + "," + TorqueParamsForm.K3.Min.ToString() + " - " + TorqueParamsForm.K3.Max.ToString() + "\r\n");
  8447. richTextBox_CheckModeLog.AppendText("K4范围: " + TorqueParamsForm.K4.T.ToString() + "," + TorqueParamsForm.K4.Min.ToString() + " - " + TorqueParamsForm.K4.Max.ToString() + "\r\n");
  8448. //与设置值比较
  8449. if ((ZeroInit <= TorqueParamsForm.Zero.Max) && (ZeroInit >= TorqueParamsForm.Zero.Min)
  8450. && (K1_T == TorqueParamsForm.K1.T) && (K1 <= TorqueParamsForm.K1.Max) && (K1 >= TorqueParamsForm.K1.Min)
  8451. && (K2_T == TorqueParamsForm.K2.T) && (K2 <= TorqueParamsForm.K2.Max) && (K2 >= TorqueParamsForm.K2.Min)
  8452. && (K3_T == TorqueParamsForm.K3.T) && (K3 <= TorqueParamsForm.K3.Max) && (K3 >= TorqueParamsForm.K3.Min)
  8453. && (K4_T == TorqueParamsForm.K4.T) && (K4 <= TorqueParamsForm.K4.Max) && (K4 >= TorqueParamsForm.K4.Min)
  8454. )
  8455. {
  8456. label_CheckModeTorque.BackColor = Color.Green;
  8457. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定正常" + "\r\n");
  8458. Delay_ms(500);
  8459. }
  8460. else
  8461. {
  8462. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定超范围" + "\r\n");
  8463. label_CheckModeStatus.Text = "存在故障!";
  8464. label_CheckModeResult.BackColor = Color.Red;
  8465. label_CheckModeResult.Text = "测试异常";
  8466. Delay_ms(500);
  8467. //存储异常并上传
  8468. CheckMode_Stop(false);
  8469. return;
  8470. }
  8471. }
  8472. else
  8473. {
  8474. label_CheckModeTorque.BackColor = Color.Yellow;
  8475. label_CheckModeStatus.Text = "跳过传感器标定检验";
  8476. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过传感器标定检验" + "\r\n");
  8477. Delay_ms(500);
  8478. }
  8479. } while (false);
  8480. //读取MOS内阻校准参数
  8481. do
  8482. {
  8483. if (checkBox_CheckModeMos.Checked)
  8484. {
  8485. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据" + "\r\n");
  8486. //读取显示校准返回数据
  8487. foreach (Control c in groupBox21.Controls)
  8488. {
  8489. if (c is TextBox)
  8490. c.Text = "";
  8491. }
  8492. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8493. ACK_WaitCnt = 0;
  8494. while (ACK_WaitCnt <= 2) ; //1s
  8495. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  8496. {
  8497. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据,第1次重发" + "\r\n");
  8498. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8499. ACK_WaitCnt = 0;
  8500. while (ACK_WaitCnt <= 2) ; //1s
  8501. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  8502. {
  8503. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据,第2次重发" + "\r\n");
  8504. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8505. ACK_WaitCnt = 0;
  8506. while (ACK_WaitCnt <= 2) ; //1s
  8507. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  8508. {
  8509. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果异常" + "\r\n");
  8510. label_CheckModeStatus.Text = "存在故障!";
  8511. label_CheckModeResult.BackColor = Color.Red;
  8512. label_CheckModeResult.Text = "测试异常";
  8513. Delay_ms(500);
  8514. //存储异常并上传
  8515. CheckMode_Stop(false);
  8516. return;
  8517. }
  8518. }
  8519. }
  8520. else
  8521. {
  8522. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻:" + textBox_MOS_R1.Text + " " + textBox_MOS_R2.Text + " " + textBox_MOS_R3.Text + "\r\n");
  8523. }
  8524. //与校准返回数据对比
  8525. string[] MOS_R1_Th = toolStripTextBox_MOS1.Text.Split(',');
  8526. string[] MOS_R2_Th = toolStripTextBox_MOS2.Text.Split(',');
  8527. string[] MOS_R3_Th = toolStripTextBox_MOS3.Text.Split(',');
  8528. if ((Convert.ToUInt16(textBox_MOS_R1.Text) >= Convert.ToUInt16(MOS_R1_Th[0])) && (Convert.ToUInt16(textBox_MOS_R1.Text) <= Convert.ToUInt16(MOS_R1_Th[1])) &&
  8529. (Convert.ToUInt16(textBox_MOS_R2.Text) >= Convert.ToUInt16(MOS_R2_Th[0])) && (Convert.ToUInt16(textBox_MOS_R2.Text) <= Convert.ToUInt16(MOS_R2_Th[1])) &&
  8530. (Convert.ToUInt16(textBox_MOS_R3.Text) >= Convert.ToUInt16(MOS_R3_Th[0])) && (Convert.ToUInt16(textBox_MOS_R3.Text) <= Convert.ToUInt16(MOS_R3_Th[1]))
  8531. )
  8532. {
  8533. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准合格" + "\r\n");
  8534. label_CheckModeMos.BackColor = Color.Green;
  8535. }
  8536. else
  8537. {
  8538. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准超范围" + "\r\n");
  8539. label_CheckModeStatus.Text = "存在故障!";
  8540. label_CheckModeResult.BackColor = Color.Red;
  8541. label_CheckModeResult.Text = "测试异常";
  8542. Delay_ms(500);
  8543. //存储异常并上传
  8544. CheckMode_Stop(false);
  8545. return;
  8546. }
  8547. }
  8548. else
  8549. {
  8550. label_CheckModeMos.BackColor = Color.Yellow;
  8551. label_CheckModeStatus.Text = "跳过MOS内阻校准检验";
  8552. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过MOS内阻校准检验" + "\r\n");
  8553. Delay_ms(500);
  8554. }
  8555. } while (false);
  8556. //测试合格
  8557. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  8558. label_CheckModeStatus.Text = "测试结束!";
  8559. label_CheckModeResult.BackColor = Color.Green;
  8560. label_CheckModeResult.Text = "测试合格";
  8561. Delay_ms(500);
  8562. //存储并上传
  8563. CheckMode_Stop(true);
  8564. return;
  8565. }
  8566. private void CheckModeLabelInit()
  8567. {
  8568. //测试状态标签
  8569. label_CheckModeResult.BackColor = Color.Yellow;
  8570. label_CheckModeResult.Text = "测试中";
  8571. //测试过程标签
  8572. label_CheckModeStatus.Text = "测试就绪";
  8573. //测试结果标签
  8574. foreach (Control c in groupBox31.Controls)
  8575. {
  8576. if (c is Label)
  8577. {
  8578. if (c.Text == string.Empty)
  8579. c.BackColor = Color.Red;
  8580. }
  8581. }
  8582. }
  8583. private void 调试记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  8584. {
  8585. System.Diagnostics.Process.Start("explorer.exe", Directory.GetCurrentDirectory());
  8586. }
  8587. private void 生产记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  8588. {
  8589. System.Diagnostics.Process.Start("explorer.exe", localInfo.LocalDataPath);
  8590. }
  8591. private void 累计运行时间ToolStripMenuItem_MouseHover(object sender, EventArgs e)
  8592. {
  8593. UInt32 Time = (UInt32)stopwatch.ElapsedMilliseconds / 1000;
  8594. UInt32 hour = Time / 3600;
  8595. UInt32 min = (Time % 3600) / 60;
  8596. UInt32 s = (Time % 60);
  8597. toolStripMenuItem_RunTime.Text = hour.ToString() + ":" + min.ToString("00") + ":" + s.ToString("00");
  8598. }
  8599. private void richTextBox_CheckModeLog_TextChanged(object sender, EventArgs e)
  8600. {
  8601. richTextBox_CheckModeLog.SelectionStart = richTextBox_CheckModeLog.Text.Length;
  8602. richTextBox_CheckModeLog.ScrollToCaret();
  8603. }
  8604. private void 力矩传感器检验ToolStripMenuItem_Click(object sender, EventArgs e)
  8605. {
  8606. TorqueParamsForm.ShowDialog();
  8607. }
  8608. private void textBox_CheckModeScan_KeyUp(object sender, KeyEventArgs e)
  8609. {
  8610. if (e.KeyCode == Keys.Enter)
  8611. CheckTestStart();
  8612. }
  8613. private void textBox_FacModeScan_KeyUp(object sender, KeyEventArgs e)
  8614. {
  8615. if (e.KeyCode == Keys.Enter)
  8616. TestStart();
  8617. }
  8618. private void button_SpeedDec10_Click(object sender, EventArgs e)
  8619. {
  8620. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  8621. if (Percent <= 10)
  8622. Percent = 0;
  8623. else
  8624. Percent -= 10;
  8625. //生产模式转速设置值更新
  8626. textBox_MotorSpeedPercent.Text = Percent.ToString();
  8627. //设置转速百分比
  8628. var Data = new byte[1];
  8629. Data[0] = (byte)Percent;
  8630. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  8631. }
  8632. private void button_SpeedAdd10_Click(object sender, EventArgs e)
  8633. {
  8634. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  8635. if (Percent >= 90)
  8636. Percent = 100;
  8637. else
  8638. Percent += 10;
  8639. //生产模式转速设置值更新
  8640. textBox_MotorSpeedPercent.Text = Percent.ToString();
  8641. //设置转速百分比
  8642. var Data = new byte[1];
  8643. Data[0] = (byte)Percent;
  8644. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  8645. }
  8646. private void button_SpeedDec1_Click(object sender, EventArgs e)
  8647. {
  8648. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  8649. if (Percent <= 1)
  8650. Percent = 0;
  8651. else
  8652. Percent -= 1;
  8653. //生产模式转速设置值更新
  8654. textBox_MotorSpeedPercent.Text = Percent.ToString();
  8655. //设置转速百分比
  8656. var Data = new byte[1];
  8657. Data[0] = (byte)Percent;
  8658. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  8659. }
  8660. private void button_SpeedAdd1_Click(object sender, EventArgs e)
  8661. {
  8662. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  8663. if (Percent >= 99)
  8664. Percent = 100;
  8665. else
  8666. Percent += 1;
  8667. //生产模式转速设置值更新
  8668. textBox_MotorSpeedPercent.Text = Percent.ToString();
  8669. //设置转速百分比
  8670. var Data = new byte[1];
  8671. Data[0] = (byte)Percent;
  8672. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  8673. }
  8674. bool WriteLockStatus = true;
  8675. private void pictureBox_WriteLock_Click(object sender, EventArgs e)
  8676. {
  8677. if (WriteLockStatus == true)
  8678. {
  8679. EnterForm1.ShowDialog();
  8680. try
  8681. {
  8682. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  8683. {
  8684. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  8685. {
  8686. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  8687. foreach (Control c in groupBox2.Controls)
  8688. {
  8689. if (c is CheckBox)
  8690. c.Enabled = true;
  8691. }
  8692. WriteLockStatus = !WriteLockStatus;
  8693. }
  8694. else
  8695. {
  8696. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8697. }
  8698. }
  8699. else
  8700. {
  8701. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8702. }
  8703. }
  8704. catch (Exception)
  8705. {
  8706. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8707. }
  8708. }
  8709. else
  8710. {
  8711. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  8712. foreach (Control c in groupBox2.Controls)
  8713. {
  8714. if (c is CheckBox)
  8715. c.Enabled = false;
  8716. }
  8717. WriteLockStatus = !WriteLockStatus;
  8718. }
  8719. }
  8720. bool ReadLockStatus = true;
  8721. private void pictureBox_ReadLock_Click(object sender, EventArgs e)
  8722. {
  8723. if (ReadLockStatus == true)
  8724. {
  8725. EnterForm1.ShowDialog();
  8726. try
  8727. {
  8728. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  8729. {
  8730. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  8731. {
  8732. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  8733. foreach (Control c in groupBox29.Controls)
  8734. {
  8735. if (c is CheckBox)
  8736. c.Enabled = true;
  8737. }
  8738. ReadLockStatus = !ReadLockStatus;
  8739. }
  8740. else
  8741. {
  8742. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8743. }
  8744. }
  8745. else
  8746. {
  8747. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8748. }
  8749. }
  8750. catch (Exception)
  8751. {
  8752. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8753. }
  8754. }
  8755. else
  8756. {
  8757. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  8758. foreach (Control c in groupBox29.Controls)
  8759. {
  8760. if (c is CheckBox)
  8761. c.Enabled = false;
  8762. }
  8763. ReadLockStatus = !ReadLockStatus;
  8764. }
  8765. }
  8766. private void 屏幕键盘ToolStripMenuItem_Click(object sender, EventArgs e)
  8767. {
  8768. System.Diagnostics.Process.Start("osk.exe");
  8769. }
  8770. private void checkBox_OffLineCheckMode_CheckedChanged(object sender, EventArgs e)
  8771. {
  8772. comboBox_CheckModeCfgDate.SelectedIndex = -1;
  8773. comboBox_CheckModeCfgFile.SelectedIndex = -1;
  8774. checkBox_OffLineFacMode.Checked = checkBox_OffLineCheckMode.Checked;
  8775. }
  8776. private void checkBox_OffLineFacMode_CheckedChanged(object sender, EventArgs e)
  8777. {
  8778. comboBox_FacModeCfgDate.SelectedIndex = -1;
  8779. comboBox_FacModeCfgFile.SelectedIndex = -1;
  8780. checkBox_OffLineCheckMode.Checked = checkBox_OffLineFacMode.Checked;
  8781. }
  8782. private void 版本ToolStripMenuItem_Click(object sender, EventArgs e)
  8783. {
  8784. VersionForm.ShowDialog();
  8785. }
  8786. private void button_MOS_Cal_Click(object sender, EventArgs e)
  8787. {
  8788. textBox_MOS_R1.Text = "";
  8789. textBox_MOS_R2.Text = "";
  8790. textBox_MOS_R3.Text = "";
  8791. try
  8792. {
  8793. var Code = new byte[18];
  8794. for (int i = 0; i < 18; i++)
  8795. Code[i] = 0;
  8796. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  8797. ushort uwDataTemp = 0;
  8798. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  8799. Code[2] = (byte)(uwDataTemp & 0xFF);
  8800. Code[3] = (byte)(uwDataTemp >> 8);
  8801. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  8802. Code[4] = (byte)(uwDataTemp & 0xFF);
  8803. Code[5] = (byte)(uwDataTemp >> 8);
  8804. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  8805. Code[6] = (byte)(uwDataTemp & 0xFF);
  8806. Code[7] = (byte)(uwDataTemp >> 8);
  8807. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  8808. Code[8] = (byte)(uwDataTemp & 0xFF);
  8809. Code[9] = (byte)(uwDataTemp >> 8);
  8810. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  8811. Code[10] = (byte)(uwDataTemp & 0xFF);
  8812. Code[11] = (byte)(uwDataTemp >> 8);
  8813. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  8814. }
  8815. catch (Exception)
  8816. {
  8817. MessageBox.Show("系数填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8818. }
  8819. }
  8820. private void button_MOS_Read_Click(object sender, EventArgs e)
  8821. {
  8822. foreach (Control c in groupBox21.Controls)
  8823. {
  8824. if (c is TextBox)
  8825. c.Text = "";
  8826. }
  8827. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8828. }
  8829. private void button_MOS_Write_Click(object sender, EventArgs e)
  8830. {
  8831. try
  8832. {
  8833. var Code = new byte[34];
  8834. for (int i = 0; i < 34; i++)
  8835. Code[i] = 0;
  8836. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  8837. ushort uwDataTemp = 0;
  8838. uwDataTemp = Convert.ToUInt16(textBox_MOS_R1.Text);
  8839. Code[2] = (byte)(uwDataTemp & 0xFF);
  8840. Code[3] = (byte)(uwDataTemp >> 8);
  8841. uwDataTemp = Convert.ToUInt16(textBox_MOS_R2.Text);
  8842. Code[4] = (byte)(uwDataTemp & 0xFF);
  8843. Code[5] = (byte)(uwDataTemp >> 8);
  8844. uwDataTemp = Convert.ToUInt16(textBox_MOS_R3.Text);
  8845. Code[6] = (byte)(uwDataTemp & 0xFF);
  8846. Code[7] = (byte)(uwDataTemp >> 8);
  8847. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  8848. Code[8] = (byte)(uwDataTemp & 0xFF);
  8849. Code[9] = (byte)(uwDataTemp >> 8);
  8850. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  8851. Code[10] = (byte)(uwDataTemp & 0xFF);
  8852. Code[11] = (byte)(uwDataTemp >> 8);
  8853. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  8854. Code[12] = (byte)(uwDataTemp & 0xFF);
  8855. Code[13] = (byte)(uwDataTemp >> 8);
  8856. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  8857. Code[14] = (byte)(uwDataTemp & 0xFF);
  8858. Code[15] = (byte)(uwDataTemp >> 8);
  8859. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  8860. Code[16] = (byte)(uwDataTemp & 0xFF);
  8861. Code[17] = (byte)(uwDataTemp >> 8);
  8862. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4C22, Code);
  8863. }
  8864. catch (Exception)
  8865. {
  8866. MessageBox.Show("数据填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8867. }
  8868. }
  8869. /// <summary>
  8870. /// 测试模式点击文本框自动全选
  8871. /// </summary>
  8872. /// <param name="sender"></param>
  8873. /// <param name="e"></param>
  8874. private void textBox_FacModeScan_MouseClick(object sender, MouseEventArgs e)
  8875. {
  8876. textBox_FacModeScan.SelectAll();
  8877. }
  8878. /// <summary>
  8879. /// 检验模式点击文本框自动全选
  8880. /// </summary>
  8881. /// <param name="sender"></param>
  8882. /// <param name="e"></param>
  8883. private void textBox_CheckModeScan_MouseClick(object sender, MouseEventArgs e)
  8884. {
  8885. textBox_CheckModeScan.SelectAll();
  8886. }
  8887. /// <summary>
  8888. /// 鼠标放置显示连接服务器信息
  8889. /// </summary>
  8890. /// <param name="sender"></param>
  8891. /// <param name="e"></param>
  8892. private void label_ServerStatus_MouseHover(object sender, EventArgs e)
  8893. {
  8894. // 创建the ToolTip
  8895. ToolTip toolTip1 = new ToolTip();
  8896. // 设置显示样式
  8897. toolTip1.AutoPopDelay = 30000;//提示信息的可见时间
  8898. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  8899. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  8900. toolTip1.ShowAlways = true;//是否显示提示框
  8901. if (myFtp.IsNetConnected)
  8902. {
  8903. toolTip1.SetToolTip(this.label_ServerStatus, "IP: " + ServerIP);//设置故障内容显示
  8904. }
  8905. else
  8906. {
  8907. toolTip1.SetToolTip(this.label_ServerStatus, "网络断开");//设置故障内容显示
  8908. }
  8909. }
  8910. /// <summary>
  8911. /// UART协议类型修改
  8912. /// </summary>
  8913. /// <param name="sender"></param>
  8914. /// <param name="e"></param>
  8915. private void 协议类型ToolStripMenuItem_SelectedIndexChanged(object sender, EventArgs e)
  8916. {
  8917. var Code = new byte[2];
  8918. Code[0] = (byte)协议类型ToolStripMenuItem.SelectedIndex;
  8919. Code[1] = 0x00;
  8920. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  8921. }
  8922. /// <summary>
  8923. /// 显示本机信息
  8924. /// </summary>
  8925. /// <param name="sender"></param>
  8926. /// <param name="e"></param>
  8927. private void 本机信息ToolStripMenuItem_Click(object sender, EventArgs e)
  8928. {
  8929. MessageBox.Show(Local_HdInformation, "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
  8930. }
  8931. /// <summary>
  8932. /// 量产模式删除当前选中文件
  8933. /// </summary>
  8934. /// <param name="sender"></param>
  8935. /// <param name="e"></param>
  8936. private void label112_DoubleClick(object sender, EventArgs e)
  8937. {
  8938. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  8939. {
  8940. EnterForm1.ShowDialog();
  8941. try
  8942. {
  8943. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  8944. {
  8945. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  8946. {
  8947. try
  8948. {
  8949. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + comboBox_FacModeCfgFile.Text);
  8950. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_FacModeCfgFile.Text) + ".src");
  8951. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_FacModeCfgFile.Text) + ".png");
  8952. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  8953. }
  8954. catch (Exception)
  8955. {
  8956. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8957. }
  8958. }
  8959. else
  8960. {
  8961. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8962. }
  8963. }
  8964. }
  8965. catch (Exception)
  8966. {
  8967. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8968. }
  8969. }
  8970. }
  8971. /// <summary>
  8972. /// 检验模式删除当前选中文件
  8973. /// </summary>
  8974. /// <param name="sender"></param>
  8975. /// <param name="e"></param>
  8976. private void label138_DoubleClick(object sender, EventArgs e)
  8977. {
  8978. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  8979. {
  8980. EnterForm1.ShowDialog();
  8981. try
  8982. {
  8983. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  8984. {
  8985. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  8986. {
  8987. try
  8988. {
  8989. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + comboBox_CheckModeCfgFile.Text);
  8990. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_CheckModeCfgFile.Text) + ".src");
  8991. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_CheckModeCfgFile.Text) + ".png");
  8992. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  8993. }
  8994. catch (Exception)
  8995. {
  8996. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8997. }
  8998. }
  8999. else
  9000. {
  9001. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9002. }
  9003. }
  9004. }
  9005. catch (Exception)
  9006. {
  9007. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9008. }
  9009. }
  9010. }
  9011. /// <summary>
  9012. /// 读取整车信息2
  9013. /// </summary>
  9014. /// <param name="sender"></param>
  9015. /// <param name="e"></param>
  9016. private void button_ReadBikeParam2_Click(object sender, EventArgs e)
  9017. {
  9018. richTextBox_BikeParam2.Clear();
  9019. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null);
  9020. }
  9021. /// <summary>
  9022. /// 写入整车信息2
  9023. /// </summary>
  9024. /// <param name="sender"></param>
  9025. /// <param name="e"></param>
  9026. private void button_WriteBikeParam2_Click(object sender, EventArgs e)
  9027. {
  9028. var ConfigParam = new byte[34];
  9029. for (int i = 0; i < 34; i++)
  9030. ConfigParam[i] = 0;
  9031. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  9032. string[] strDataTemp = richTextBox_BikeParam2.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  9033. try
  9034. {
  9035. for (int i = 0; i < strDataTemp.Length; i++)
  9036. {
  9037. short wDataTemp = 0;
  9038. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  9039. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  9040. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  9041. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  9042. }
  9043. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4D22, ConfigParam);
  9044. }
  9045. catch (Exception)
  9046. {
  9047. timer_500ms.Enabled = false;
  9048. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9049. timer_500ms.Enabled = true;
  9050. }
  9051. }
  9052. /// <summary>
  9053. /// 读取用户骑行参数
  9054. /// </summary>
  9055. /// <param name="sender"></param>
  9056. /// <param name="e"></param>
  9057. private void button_ReadUsrRideParam_Click(object sender, EventArgs e)
  9058. {
  9059. richTextBox_UsrRidesParam.Clear();
  9060. if (checkBox_UserRideParam_OBC.Checked)
  9061. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x4300, null);
  9062. else
  9063. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  9064. }
  9065. /// <summary>
  9066. /// 写入用户骑行参数
  9067. /// </summary>
  9068. /// <param name="sender"></param>
  9069. /// <param name="e"></param>
  9070. private void button_WriteUsrRidetParam_Click(object sender, EventArgs e)
  9071. {
  9072. var ConfigParam = new byte[34];
  9073. for (int i = 0; i < 34; i++)
  9074. ConfigParam[i] = 0;
  9075. if (checkBox_UserRideParam_OBC.Checked)
  9076. {
  9077. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  9078. string[] strDataTemp = richTextBox_UsrRidesParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  9079. try
  9080. {
  9081. for (int i = 0; i < strDataTemp.Length; i++)
  9082. {
  9083. ConfigParam[i + 2] = Convert.ToByte(strDataTemp[i].Split('=')[1]);
  9084. }
  9085. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4B22, ConfigParam);
  9086. }
  9087. catch (Exception)
  9088. {
  9089. timer_500ms.Enabled = false;
  9090. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9091. timer_500ms.Enabled = true;
  9092. }
  9093. }
  9094. else
  9095. {
  9096. string[] strDataTemp = richTextBox_UsrRidesParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  9097. try
  9098. {
  9099. for (int i = 0; i < strDataTemp.Length; i++)
  9100. {
  9101. ConfigParam[i] = Convert.ToByte(strDataTemp[i].Split('=')[1]);
  9102. }
  9103. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x4420, ConfigParam);
  9104. }
  9105. catch (Exception)
  9106. {
  9107. timer_500ms.Enabled = false;
  9108. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9109. timer_500ms.Enabled = true;
  9110. }
  9111. }
  9112. }
  9113. /// <summary>
  9114. /// 读取产品标签
  9115. /// </summary>
  9116. /// <param name="sender"></param>
  9117. /// <param name="e"></param>
  9118. private void button_ReadTag_Click(object sender, EventArgs e)
  9119. {
  9120. textBox_TagInfo.Text = "---";
  9121. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4E00, null);
  9122. }
  9123. /// <summary>
  9124. /// 写入产品标签
  9125. /// </summary>
  9126. /// <param name="sender"></param>
  9127. /// <param name="e"></param>
  9128. private void button_WriteTag_Click(object sender, EventArgs e)
  9129. {
  9130. string User = textBox_TagInfo.Text;
  9131. var UserArray = new byte[32];
  9132. for (ushort i = 0; i < User.Length; i++)
  9133. {
  9134. UserArray[i] = (byte)User[i];
  9135. }
  9136. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D20, UserArray);
  9137. }
  9138. /// <summary>
  9139. /// 上位机读取骑行历史
  9140. /// </summary>
  9141. /// <param name="sender"></param>
  9142. /// <param name="e"></param>
  9143. private void button_ReadRideLog_Click(object sender, EventArgs e)
  9144. {
  9145. textBox_ODO_KM.Text = "---";
  9146. textBox_ODO_TIME.Text = "---";
  9147. textBox_TRIP_KM.Text = "---";
  9148. textBox_TRIP_TIME.Text = "---";
  9149. textBox_OBC_TRIP_KM.Text = "";
  9150. textBox_OBC_TRIP_TIME.Text = "";
  9151. textBox_OBC_ODO_KM.Text = "";
  9152. textBox_OBC_ODO_TIME.Text = "";
  9153. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2E00, null);
  9154. }
  9155. /// <summary>
  9156. /// 上位机写入骑行历史
  9157. /// </summary>
  9158. /// <param name="sender"></param>
  9159. /// <param name="e"></param>
  9160. private void button_WriteRideLog_Click(object sender, EventArgs e)
  9161. {
  9162. UInt32 Data;
  9163. var UserArray = new byte[16];
  9164. try
  9165. {
  9166. Data = Convert.ToUInt32(textBox_ODO_KM.Text);
  9167. UserArray[0] = (byte)(Data & 0xFF);
  9168. UserArray[1] = (byte)(Data >> 8);
  9169. UserArray[2] = (byte)(Data >> 16);
  9170. UserArray[3] = (byte)(Data >> 24);
  9171. Data = Convert.ToUInt32(textBox_ODO_TIME.Text);
  9172. UserArray[4] = (byte)(Data & 0xFF);
  9173. UserArray[5] = (byte)(Data >> 8);
  9174. UserArray[6] = (byte)(Data >> 16);
  9175. UserArray[7] = (byte)(Data >> 24);
  9176. Data = Convert.ToUInt32(textBox_TRIP_KM.Text);
  9177. UserArray[8] = (byte)(Data & 0xFF);
  9178. UserArray[9] = (byte)(Data >> 8);
  9179. UserArray[10] = (byte)(Data >> 16);
  9180. UserArray[11] = (byte)(Data >> 24);
  9181. Data = Convert.ToUInt32(textBox_TRIP_TIME.Text);
  9182. UserArray[12] = (byte)(Data & 0xFF);
  9183. UserArray[13] = (byte)(Data >> 8);
  9184. UserArray[14] = (byte)(Data >> 16);
  9185. UserArray[15] = (byte)(Data >> 24);
  9186. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B10, UserArray);
  9187. }
  9188. catch (Exception ex)
  9189. {
  9190. MessageBox.Show("数据格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9191. }
  9192. }
  9193. /// <summary>
  9194. /// 获取删除配置文件日期列表
  9195. /// </summary>
  9196. /// <param name="sender"></param>
  9197. /// <param name="e"></param>
  9198. private void toolStripTextBox_DelCfgFile_Click(object sender, EventArgs e)
  9199. {
  9200. string[] DateList = { "" };
  9201. //网络断开时直接退出
  9202. if (!myFtp.IsNetConnected)
  9203. return;
  9204. //从服务器更新日期列表
  9205. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
  9206. toolStripTextBox_DelCfgFile.Items.Clear();
  9207. //日期列表加载,显示最近30条
  9208. if (DateList.Length > 30)
  9209. {
  9210. toolStripTextBox_DelCfgFile.Items.Add("支持最近30条");
  9211. toolStripTextBox_DelCfgFile.Items.Add("-----");
  9212. }
  9213. for (int i = (DateList.Length > 30) ? (DateList.Length - 30) : 0; i < DateList.Length; i++)//显示最近30个日期
  9214. {
  9215. toolStripTextBox_DelCfgFile.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  9216. }
  9217. }
  9218. /// <summary>
  9219. /// 删除指定配置文件
  9220. /// </summary>
  9221. /// <param name="sender"></param>
  9222. /// <param name="e"></param>
  9223. private void toolStripTextBox_DelCfgFile_SelectedIndexChanged(object sender, EventArgs e)
  9224. {
  9225. //提示输入文件名
  9226. Scan scan_form = new Scan();
  9227. scan_form.ShowDialog();
  9228. do
  9229. {
  9230. if (scan_form.textBox_Scan.Text == string.Empty)
  9231. {
  9232. timer_500ms.Enabled = false;
  9233. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9234. timer_500ms.Enabled = true;
  9235. break;
  9236. }
  9237. string DelFile = scan_form.textBox_Scan.Text;
  9238. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9239. {
  9240. EnterForm1.ShowDialog();
  9241. try
  9242. {
  9243. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9244. {
  9245. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  9246. {
  9247. try
  9248. {
  9249. if (DelFile.Contains("."))
  9250. DelFile = Path.GetFileNameWithoutExtension(DelFile);
  9251. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".ttcfg");
  9252. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".src");
  9253. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".png");
  9254. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9255. }
  9256. catch (Exception)
  9257. {
  9258. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9259. }
  9260. }
  9261. else
  9262. {
  9263. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9264. }
  9265. }
  9266. }
  9267. catch (Exception)
  9268. {
  9269. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9270. }
  9271. }
  9272. } while (false);
  9273. }
  9274. /// <summary>
  9275. /// 获取删除样机测试记录日期列表
  9276. /// </summary>
  9277. /// <param name="sender"></param>
  9278. /// <param name="e"></param>
  9279. private void toolStripTextBox_DelLogFile_Click(object sender, EventArgs e)
  9280. {
  9281. string[] DateList = { "" };
  9282. //网络断开时直接退出
  9283. if (!myFtp.IsNetConnected)
  9284. return;
  9285. //从服务器更新日期列表
  9286. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName);
  9287. toolStripTextBox_DelLogFile.Items.Clear();
  9288. //日期列表加载,显示最近30天
  9289. if (DateList.Length > 30)
  9290. {
  9291. toolStripTextBox_DelLogFile.Items.Add("支持最近30条");
  9292. toolStripTextBox_DelLogFile.Items.Add("-----");
  9293. }
  9294. for (int i = (DateList.Length > 30) ? (DateList.Length - 30) : 0; i < DateList.Length; i++)//显示最近30个日期
  9295. {
  9296. toolStripTextBox_DelLogFile.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  9297. }
  9298. }
  9299. /// <summary>
  9300. /// 删除指定的样机测试记录
  9301. /// </summary>
  9302. /// <param name="sender"></param>
  9303. /// <param name="e"></param>
  9304. private void toolStripTextBox_DelLogFile_SelectedIndexChanged(object sender, EventArgs e)
  9305. {
  9306. //提示输入文件名
  9307. Scan scan_form = new Scan();
  9308. scan_form.ShowDialog();
  9309. do
  9310. {
  9311. if (scan_form.textBox_Scan.Text == string.Empty)
  9312. {
  9313. timer_500ms.Enabled = false;
  9314. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9315. timer_500ms.Enabled = true;
  9316. break;
  9317. }
  9318. string DelFile = scan_form.textBox_Scan.Text;
  9319. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9320. {
  9321. EnterForm1.ShowDialog();
  9322. try
  9323. {
  9324. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9325. {
  9326. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  9327. {
  9328. try
  9329. {
  9330. //删除指定目录下面所有文件和文件夹
  9331. myFtp.DelDirectoryWithAll(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName + "\\" + toolStripTextBox_DelLogFile.Text + "\\" + DelFile);
  9332. myFtp.RemoveDirectory(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName + "\\" + toolStripTextBox_DelLogFile.Text + "\\" + DelFile);
  9333. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9334. }
  9335. catch (Exception)
  9336. {
  9337. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9338. }
  9339. }
  9340. else
  9341. {
  9342. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9343. }
  9344. }
  9345. }
  9346. catch (Exception)
  9347. {
  9348. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9349. }
  9350. }
  9351. } while (false);
  9352. }
  9353. /// <summary>
  9354. /// CAN协议选择
  9355. /// </summary>
  9356. /// <param name="sender"></param>
  9357. /// <param name="e"></param>
  9358. private void cANToolStripMenuItem_Click(object sender, EventArgs e)
  9359. {
  9360. cANToolStripMenuItem.Checked= true;
  9361. uARTToolStripMenuItem.Checked = false;
  9362. UART协议ToolStripMenuItem.Visible = false;
  9363. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9364. }
  9365. /// <summary>
  9366. /// UART协议选择
  9367. /// </summary>
  9368. /// <param name="sender"></param>
  9369. /// <param name="e"></param>
  9370. private void uARTToolStripMenuItem_Click(object sender, EventArgs e)
  9371. {
  9372. cANToolStripMenuItem.Checked = false;
  9373. uARTToolStripMenuItem.Checked = true;
  9374. UART协议ToolStripMenuItem.Visible = true;
  9375. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9376. }
  9377. /// <summary>
  9378. /// 清除流水号
  9379. /// </summary>
  9380. /// <param name="sender"></param>
  9381. /// <param name="e"></param>
  9382. private void label131_DoubleClick(object sender, EventArgs e)
  9383. {
  9384. if (MessageBox.Show("确认清零流水号?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9385. {
  9386. label_FacModeSerial.Text = "0";
  9387. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, label_FacModeSerial.Text);
  9388. }
  9389. }
  9390. /// <summary>
  9391. /// 清除流水号
  9392. /// </summary>
  9393. /// <param name="sender"></param>
  9394. /// <param name="e"></param>
  9395. private void label135_DoubleClick(object sender, EventArgs e)
  9396. {
  9397. if (MessageBox.Show("确认清零流水号?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9398. {
  9399. label_CheckModeSerial.Text = "0";
  9400. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, label_CheckModeSerial.Text);
  9401. }
  9402. }
  9403. /// <summary>
  9404. /// 打开自动更新
  9405. /// </summary>
  9406. /// <param name="sender"></param>
  9407. /// <param name="e"></param>
  9408. private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
  9409. {
  9410. 打开ToolStripMenuItem.Checked = true;
  9411. 关闭ToolStripMenuItem.Checked = false;
  9412. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9413. }
  9414. /// <summary>
  9415. /// 关闭自动更新
  9416. /// </summary>
  9417. /// <param name="sender"></param>
  9418. /// <param name="e"></param>
  9419. private void 关闭ToolStripMenuItem_Click(object sender, EventArgs e)
  9420. {
  9421. 打开ToolStripMenuItem.Checked = false;
  9422. 关闭ToolStripMenuItem.Checked = true;
  9423. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9424. }
  9425. /// <summary>
  9426. /// 显示完整配置文件
  9427. /// </summary>
  9428. /// <param name="sender"></param>
  9429. /// <param name="e"></param>
  9430. private void comboBox_FacModeCfgFile_MouseHover_1(object sender, EventArgs e)
  9431. {
  9432. // 创建the ToolTip
  9433. ToolTip toolTip1 = new ToolTip();
  9434. // 设置显示样式
  9435. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  9436. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  9437. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  9438. toolTip1.ShowAlways = true;//是否显示提示框
  9439. // 设置伴随的对象.
  9440. toolTip1.SetToolTip(this.comboBox_FacModeCfgFile, comboBox_FacModeCfgFile.Text);//设置故障内容显示
  9441. }
  9442. /// <summary>
  9443. /// 显示完整配置文件
  9444. /// </summary>
  9445. /// <param name="sender"></param>
  9446. /// <param name="e"></param>
  9447. private void comboBox_CheckModeCfgFile_MouseHover_1(object sender, EventArgs e)
  9448. {
  9449. // 创建the ToolTip
  9450. ToolTip toolTip1 = new ToolTip();
  9451. // 设置显示样式
  9452. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  9453. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  9454. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  9455. toolTip1.ShowAlways = true;//是否显示提示框
  9456. // 设置伴随的对象.
  9457. toolTip1.SetToolTip(this.comboBox_CheckModeCfgFile, comboBox_CheckModeCfgFile.Text);//设置故障内容显示
  9458. }
  9459. /// <summary>
  9460. /// 手动发送指令
  9461. /// </summary>
  9462. /// <param name="sender"></param>
  9463. /// <param name="e"></param>
  9464. private void 发送指令ToolStripMenuItem_Click(object sender, EventArgs e)
  9465. {
  9466. //提示
  9467. Scan scan_form = new Scan();
  9468. scan_form.label1.Text = "按照16进制填写,相邻字节用空格隔开,依次填写ID、Mode、Cmd、Data\r\n例如:07 31 16 22 05 01 02 03 04 05";
  9469. scan_form.ShowDialog();
  9470. //发送写入的指令,填写ID、类型、命令字、数据
  9471. do
  9472. {
  9473. if (scan_form.textBox_Scan.Text == string.Empty)
  9474. {
  9475. timer_500ms.Enabled = false;
  9476. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9477. timer_500ms.Enabled = true;
  9478. break;
  9479. }
  9480. //输入文本转换为字节流
  9481. var InputData = new byte[256];
  9482. InputData = mySerialProcess.HexStringToBytes(scan_form.textBox_Scan.Text, true);
  9483. //ID
  9484. ushort ID;
  9485. ID = (ushort)((InputData[0] << 8) + InputData[1]);
  9486. //Mode
  9487. byte Mode;
  9488. Mode = InputData[2];
  9489. //Cmd
  9490. ushort Cmd;
  9491. Cmd = (ushort)((InputData[3] << 8) + InputData[4]);
  9492. //Data
  9493. var Data = new byte[Cmd & 0x00FF];
  9494. for (int i = 0; i < (Cmd & 0x00FF); i++)
  9495. Data[i] = InputData[5 + i];
  9496. //发送数据
  9497. mySerialProcess.SendCmdWithoutNotice(ID, Mode, Cmd, Data);
  9498. } while (false);
  9499. }
  9500. /// <summary>
  9501. /// 启动位置传感器校准
  9502. /// </summary>
  9503. /// <param name="sender"></param>
  9504. /// <param name="e"></param>
  9505. private void button_AngleCalStart_Click(object sender, EventArgs e)
  9506. {
  9507. for (int i = 0; i < 7; i++)
  9508. for (int j = 0; j < 6; j++)
  9509. {
  9510. dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = "";
  9511. }
  9512. foreach (Control cr in tabPage_AngleCal.Controls)
  9513. {
  9514. if (cr is TextBox)
  9515. {
  9516. if ((cr != textBox_AngleDiffTh) && (cr != textBox_AngleZeroTh))
  9517. cr.Text = "";
  9518. }
  9519. }
  9520. var Data = new byte[2];
  9521. mySerialProcess.SendCmd((ushort)0x751, (byte)0x0C, (ushort)0x5002, Data);
  9522. }
  9523. /// <summary>
  9524. /// 导出位置传感器校准数据
  9525. /// </summary>
  9526. /// <param name="sender"></param>
  9527. /// <param name="e"></param>
  9528. private void button_AngleExportData_Click(object sender, EventArgs e)
  9529. {
  9530. //读出产品信息
  9531. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  9532. Delay_ms(200);
  9533. SaveFileDialog sfd = new SaveFileDialog
  9534. {
  9535. FileName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + "位置传感器角度数据_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt",
  9536. Filter = "文本文档(*.txt)|*.txt",
  9537. Title = "Save"
  9538. };
  9539. if (sfd.ShowDialog() != DialogResult.OK)
  9540. {
  9541. return;
  9542. }
  9543. string filepath = sfd.FileName;
  9544. FileStream fs = new FileStream(filepath, FileMode.OpenOrCreate);
  9545. using (StreamWriter sw = new StreamWriter(fs))
  9546. {
  9547. sw.Write("标准值 ");
  9548. sw.Write("60.00 ");
  9549. sw.Write("120.00 ");
  9550. sw.Write("180.00 ");
  9551. sw.Write("240.00 ");
  9552. sw.Write("300.00 ");
  9553. sw.Write("360.00 ");
  9554. for (int i = 0; i < 42; i++)
  9555. {
  9556. if ((i % 6 == 0))
  9557. {
  9558. sw.Write("\r\n" + "采集值" + (i / 6 + 1).ToString() + " ");
  9559. }
  9560. sw.Write(AngledataRecord[i] + " ");
  9561. }
  9562. sw.Write("\r\n" + "历史零点位置 " + textBox_AngleZeroInit.Text);
  9563. sw.Write("\r\n" + "当前零点位置 " + textBox_AngleZeroCur.Text);
  9564. sw.Write("\r\n" + "零点误差 " + textBox_AngleZeroDiff.Text);
  9565. sw.Write("\r\n" + "最小偏差值 " + textBox_AngleDiffMin.Text);
  9566. sw.Write("\r\n" + "最大偏差值 " + textBox_AngleDiffMax.Text);
  9567. sw.Write("\r\n" + "平均偏差值 " + textBox_AngleDiffAvg.Text);
  9568. sw.Flush();
  9569. }
  9570. fs.Close();
  9571. }
  9572. /// <summary>
  9573. /// 写入校准数据
  9574. /// </summary>
  9575. /// <param name="sender"></param>
  9576. /// <param name="e"></param>
  9577. private void button_AngleWrite_Click(object sender, EventArgs e)
  9578. {
  9579. if ((textBox_AngleDiffAvg.Text == "") || (textBox_AngleZeroInit.Text == ""))
  9580. {
  9581. timer_500ms.Enabled = false;
  9582. MessageBox.Show("请先启动校准,以确认校准数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9583. timer_500ms.Enabled = true;
  9584. return;
  9585. }
  9586. timer_500ms.Enabled = false;
  9587. string str1 = "确认校准数据,历史零点: " + textBox_AngleZeroInit.Text + ", 偏差平均值: " + textBox_AngleDiffAvg.Text;
  9588. if (MessageBox.Show(str1, "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9589. {
  9590. var SaveFlag = new byte[4];
  9591. for (int i = 0; i < 4; i++)
  9592. SaveFlag[i] = 0;
  9593. SaveFlag[0] = (byte)(1);
  9594. double data1 = Convert.ToDouble(textBox_AngleZeroInit.Text) - Convert.ToDouble(textBox_AngleDiffAvg.Text);
  9595. if (data1 > 360)
  9596. {
  9597. data1 -= 360;
  9598. }
  9599. else if (data1 < -360)
  9600. {
  9601. data1 += 360;
  9602. }
  9603. Int16 data2 = (Int16)(data1 * 32768 / 360);
  9604. SaveFlag[2] = (byte)(data2);
  9605. SaveFlag[3] = (byte)(data2 >> 8);
  9606. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, SaveFlag);
  9607. }
  9608. else
  9609. MessageBoxTimeOut.Show("写入取消", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9610. timer_500ms.Enabled = true;
  9611. }
  9612. /// <summary>
  9613. /// 存储允许偏差
  9614. /// </summary>
  9615. /// <param name="sender"></param>
  9616. /// <param name="e"></param>
  9617. private void textBox_AngleDiffTh_KeyDown(object sender, KeyEventArgs e)
  9618. {
  9619. if (e.KeyCode == Keys.Enter)
  9620. {
  9621. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9622. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  9623. }
  9624. }
  9625. /// <summary>
  9626. /// 存储零点允许偏差
  9627. /// </summary>
  9628. /// <param name="sender"></param>
  9629. /// <param name="e"></param>
  9630. private void textBox_AngleZeroTh_KeyDown(object sender, KeyEventArgs e)
  9631. {
  9632. if (e.KeyCode == Keys.Enter)
  9633. {
  9634. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9635. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  9636. }
  9637. }
  9638. /// <summary>
  9639. /// 删除服务器配置文件
  9640. /// </summary>
  9641. /// <param name="sender"></param>
  9642. /// <param name="e"></param>
  9643. private void 重置ToolStripMenuItem_Click(object sender, EventArgs e)
  9644. {
  9645. if (MessageBox.Show("重置后软件自动关闭,确认重置?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9646. {
  9647. if(File.Exists(localInfo.LocalPath + localInfo.ServerCfgFileName))
  9648. File.Delete(localInfo.LocalPath + localInfo.ServerCfgFileName);
  9649. if(File.Exists(localInfo.LocalPath + localInfo.ConfigFileName))
  9650. File.Delete(localInfo.LocalPath + localInfo.ConfigFileName);
  9651. System.Environment.Exit(0);
  9652. }
  9653. }
  9654. /// <summary>
  9655. /// 按下Enter保存数据
  9656. /// </summary>
  9657. /// <param name="sender"></param>
  9658. /// <param name="e"></param>
  9659. private void toolStripTextBox_AngleAvgMax_KeyDown(object sender, KeyEventArgs e)
  9660. {
  9661. textBox_AngleDiffTh.Text = toolStripTextBox_AngleAvgMax.Text;
  9662. if (e.KeyCode == Keys.Enter)
  9663. {
  9664. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9665. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  9666. }
  9667. }
  9668. /// <summary>
  9669. /// 按下Enter保存数据
  9670. /// </summary>
  9671. /// <param name="sender"></param>
  9672. /// <param name="e"></param>
  9673. private void toolStripTextBox_AngleZeroMax_KeyDown(object sender, KeyEventArgs e)
  9674. {
  9675. textBox_AngleZeroTh.Text = toolStripTextBox_AngleZeroMax.Text;
  9676. if (e.KeyCode == Keys.Enter)
  9677. {
  9678. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9679. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  9680. }
  9681. }
  9682. /// <summary>
  9683. /// 打开或关闭指令窗口
  9684. /// </summary>
  9685. /// <param name="sender"></param>
  9686. /// <param name="e"></param>
  9687. private void 指令调试ToolStripMenuItem_Click(object sender, EventArgs e)
  9688. {
  9689. if (指令调试ToolStripMenuItem.Checked == false)
  9690. {
  9691. if (DebugForm.debug1 == null || DebugForm.debug1.IsDisposed)
  9692. {
  9693. DebugForm.debug1 = new DebugForm();
  9694. DebugForm.debug1.Show();
  9695. this.DebugWindowIsOpen = true;
  9696. }
  9697. else
  9698. {
  9699. DebugForm.debug1.Activate();
  9700. this.DebugWindowIsOpen = true;
  9701. }
  9702. 指令调试ToolStripMenuItem.Checked = true;
  9703. }
  9704. else
  9705. {
  9706. if (this.DebugWindowIsOpen == true)
  9707. {
  9708. DebugForm.debug1.Close();
  9709. this.DebugWindowIsOpen = false;
  9710. this.DebugDataDisplayEnable = false;
  9711. }
  9712. 指令调试ToolStripMenuItem.Checked = false;
  9713. }
  9714. }
  9715. }
  9716. }