mainForm.cs 533 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145
  1. using NPOI.POIFS.Crypt.Dsig;
  2. using NPOI.SS.Formula.Functions;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.Diagnostics;
  7. using System.Diagnostics.Eventing.Reader;
  8. using System.Drawing;
  9. using System.Globalization;
  10. using System.IO;
  11. using System.IO.Ports;
  12. using System.Linq;
  13. using System.Reflection;
  14. using System.Runtime.InteropServices;
  15. using System.Runtime.InteropServices.ComTypes;
  16. using System.Text;
  17. using System.Text.RegularExpressions;
  18. using System.Threading;
  19. using System.Web;
  20. using System.Windows.Forms;
  21. using System.Xml.Linq;
  22. using static NPOI.POIFS.Crypt.CryptoFunctions;
  23. namespace Welling_Motor_Debug_Tool
  24. {
  25. public partial class mainForm : Form
  26. {
  27. #region 变量定义
  28. //版本号
  29. public static string Version = "2.5.3";
  30. //串口实例
  31. Serial_Process mySerialProcess = new Serial_Process();
  32. string PortNumSave = "";
  33. string PortBaudrateSave = "";
  34. //本地信息定义
  35. LocalInfo localInfo = new LocalInfo();
  36. //FTP实例
  37. ftp myFtp = new ftp();
  38. public string ServerIP = "";
  39. public string ServerPort = "";
  40. public string ServerUser = "";
  41. public string ServerPassWd = "";
  42. public bool OfflineFlag = false;
  43. //MC运行信息超时计数
  44. bool MC_RunInfo_Refresh = false;
  45. ushort MC_RunInfo_Refresh_Cnt = 0;
  46. //MC调试信息超时计数
  47. bool MC_DebugInfo_Refresh = false;
  48. ushort MC_DebugInfo_Refresh_Cnt = 0;
  49. //MC故障码超时计数
  50. bool MC_ErrorCode_Refresh = false;
  51. ushort MC_ErrorCode_Refresh_Cnt = 0;
  52. //配置参数实例
  53. Params myParams = new Params();
  54. //记录文件名称
  55. string RunInfoSaveFilename = "";
  56. //BMS运行信息超时计数
  57. bool BMS_RunInfo_Refresh = false;
  58. ushort BMS_RunInfo_Refresh_Cnt = 0;
  59. //生产模式关机指令反馈状态
  60. bool PowerOffAckStatus = false;
  61. //登录窗口
  62. public static Login EnterForm1 = new Login();
  63. //生产配置文件信息
  64. ArrayList array_CfgInfo = new ArrayList();
  65. //写入参数返回标志和计数
  66. public bool WriteACK = false;
  67. public ushort ACK_WaitCnt = 0;
  68. //写入参数返回提示标志
  69. public bool ACK_DisFlag = true;
  70. //Boot版本信息
  71. public string BootInfo = "";
  72. //接收指令临时缓存,转string
  73. public string CmdRevStrTemp = "";
  74. //计时器,用于统计运行时间
  75. public Stopwatch stopwatch = new Stopwatch();
  76. //力矩传感器检验参数窗口
  77. public static TorqueParams TorqueParamsForm = new TorqueParams();
  78. //参数生成窗口
  79. public static GenerateParams GenerateParamsForm = new GenerateParams();
  80. //版本信息窗口
  81. public static Version VersionForm = new Version();
  82. //本机硬件信息
  83. public string Local_HdInformation = "";
  84. //指令窗口显示
  85. public bool DebugWindowIsOpen = false, DebugDataDisplayEnable = false;
  86. //位置传感器数据记录
  87. string[] AngledataRecord = new string[42];
  88. //服务器设置窗口
  89. public static ServerSelect ServerCfgForm1 = new ServerSelect();
  90. #endregion
  91. #region 故障日志结构体定义
  92. //故障日志记录信息 60 bytes,1K空间可以保存最近16条故障记录
  93. [StructLayout(LayoutKind.Sequential)]
  94. public struct MC_ErrorLogSaveInfo_Struct_t
  95. {
  96. public UInt16 Error_Index; //故障列表索引 2 bytes, 地址偏移 0
  97. public UInt16 NotesInfo1; //备注信息1,地址偏移 2
  98. public UInt16 NotesInfo2; //备注信息2,地址偏移 4
  99. public UInt16 NotesInfo3; //备注信息3,地址偏移 6
  100. public UInt32 ErrorCode; //故障码 4 bytes, 地址偏移 8
  101. public UInt32 RunTime; //运行时间 4bytes, 地址偏移 12
  102. //电机运行信息,占用空间32bytes
  103. [StructLayout(LayoutKind.Sequential)]
  104. public struct MC_RunInfo_Struct_t
  105. {
  106. public ushort BikeSpeed; //车速 0.1km/h,地址偏移0
  107. public ushort MotorSpeed; //输出转速 1rpm,地址偏移2
  108. public ushort Power; //电功率 1W,地址偏移4
  109. public ushort BusVoltage; //母线电压 1mV,地址偏移6
  110. public ushort BusCurrent; //母线电流 1mA,地址偏移8
  111. public byte Cadence; //踏频 1rpm,地址偏移10
  112. public byte Torque; //踩踏力矩 1Nm,地址偏移11
  113. public byte CadenceDir; //踩踏方向 0-正,1-反,2-停止,地址偏移12
  114. public byte GearSt; //助力档位,地址偏移13
  115. public byte LightSwitch; //灯开关 0xF0-关,0xF1-开,地址偏移14
  116. public byte SOC; //剩余电量 1%,地址偏移15
  117. public ushort RemainDistance; //续航里程 1km,地址偏移16
  118. public ushort Torque_AD; //力矩寄存器,地址偏移18
  119. public byte PowerPerKm; //平均功耗 0.01Ah/km ,地址偏移20
  120. public byte T_PCB; //PCB温度 +40℃,地址偏移21
  121. public byte T_Coil; //绕组温度 +40℃,地址偏移22
  122. public byte T_MCU; //MCU温度 +40℃,地址偏移23
  123. public ushort Ride_Km; //开机后骑行里程 0.1km, 地址偏移24
  124. public ushort Ride_Time; //开机后骑行时间 1s,地址偏移26
  125. public UInt32 RS; //预留 4bytes
  126. };
  127. [MarshalAs(UnmanagedType.Struct)]
  128. public MC_RunInfo_Struct_t RunInfo; //运行信息 32bytes, 地址偏移 16
  129. //控制变量
  130. public Int16 IqCurrent; //Pu, 地址偏移 48
  131. public Int16 IqVoltage; //Pu, 地址偏移 50
  132. public Int16 IdCurrent; //Pu, 地址偏移 52
  133. public Int16 IdVoltage; //Pu, 地址偏移 54
  134. //状态机
  135. public UInt16 FSM; //高到低依次表示系统状态机、二层状态机、电机状态机、助力状态机, 地址偏移 56
  136. //预留
  137. public UInt16 RS1;
  138. public UInt16 RS2;
  139. public UInt16 RS3;
  140. };
  141. #endregion
  142. #region 屏幕缩放比例获取
  143. public class PrimaryScreen
  144. {
  145. #region Win32 API
  146. [DllImport("user32.dll")]
  147. static extern IntPtr GetDC(IntPtr ptr);
  148. [DllImport("gdi32.dll")]
  149. static extern int GetDeviceCaps(
  150. IntPtr hdc, // handle to DC
  151. int nIndex // index of capability
  152. );
  153. [DllImport("user32.dll", EntryPoint = "ReleaseDC")]
  154. static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDc);
  155. #endregion
  156. #region DeviceCaps常量
  157. const int HORZRES = 8;
  158. const int VERTRES = 10;
  159. const int LOGPIXELSX = 88;
  160. const int LOGPIXELSY = 90;
  161. const int DESKTOPVERTRES = 117;
  162. const int DESKTOPHORZRES = 118;
  163. #endregion
  164. #region 属性
  165. /// <summary>
  166. /// 获取屏幕分辨率当前物理大小
  167. /// </summary>
  168. public static Size WorkingArea
  169. {
  170. get
  171. {
  172. IntPtr hdc = GetDC(IntPtr.Zero);
  173. Size size = new Size();
  174. size.Width = GetDeviceCaps(hdc, HORZRES);
  175. size.Height = GetDeviceCaps(hdc, VERTRES);
  176. ReleaseDC(IntPtr.Zero, hdc);
  177. return size;
  178. }
  179. }
  180. /// <summary>
  181. /// 当前系统DPI_X 大小 一般为96
  182. /// </summary>
  183. public static int DpiX
  184. {
  185. get
  186. {
  187. IntPtr hdc = GetDC(IntPtr.Zero);
  188. int DpiX = GetDeviceCaps(hdc, LOGPIXELSX);
  189. ReleaseDC(IntPtr.Zero, hdc);
  190. return DpiX;
  191. }
  192. }
  193. /// <summary>
  194. /// 当前系统DPI_Y 大小 一般为96
  195. /// </summary>
  196. public static int DpiY
  197. {
  198. get
  199. {
  200. IntPtr hdc = GetDC(IntPtr.Zero);
  201. int DpiX = GetDeviceCaps(hdc, LOGPIXELSY);
  202. ReleaseDC(IntPtr.Zero, hdc);
  203. return DpiX;
  204. }
  205. }
  206. /// <summary>
  207. /// 获取真实设置的桌面分辨率大小
  208. /// </summary>
  209. public static Size DESKTOP
  210. {
  211. get
  212. {
  213. IntPtr hdc = GetDC(IntPtr.Zero);
  214. Size size = new Size();
  215. size.Width = GetDeviceCaps(hdc, DESKTOPHORZRES);
  216. size.Height = GetDeviceCaps(hdc, DESKTOPVERTRES);
  217. ReleaseDC(IntPtr.Zero, hdc);
  218. return size;
  219. }
  220. }
  221. /// <summary>
  222. /// 获取宽度缩放百分比
  223. /// </summary>
  224. public static float ScaleX
  225. {
  226. get
  227. {
  228. IntPtr hdc = GetDC(IntPtr.Zero);
  229. int t = GetDeviceCaps(hdc, DESKTOPHORZRES);
  230. int d = GetDeviceCaps(hdc, HORZRES);
  231. float ScaleX = (float)GetDeviceCaps(hdc, DESKTOPHORZRES) / (float)GetDeviceCaps(hdc, HORZRES);
  232. ReleaseDC(IntPtr.Zero, hdc);
  233. return ScaleX;
  234. }
  235. }
  236. /// <summary>
  237. /// 获取高度缩放百分比
  238. /// </summary>
  239. public static float ScaleY
  240. {
  241. get
  242. {
  243. IntPtr hdc = GetDC(IntPtr.Zero);
  244. float ScaleY = (float)(float)GetDeviceCaps(hdc, DESKTOPVERTRES) / (float)GetDeviceCaps(hdc, VERTRES);
  245. ReleaseDC(IntPtr.Zero, hdc);
  246. return ScaleY;
  247. }
  248. }
  249. #endregion
  250. }
  251. #endregion
  252. public static mainForm mainform1 = null;
  253. public mainForm()
  254. {
  255. InitializeComponent();
  256. mainform1 = this;
  257. System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
  258. stopwatch.Start();
  259. //端口初始化
  260. mySerialProcess.Init();
  261. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  262. //检查文件夹
  263. if (!Directory.Exists(localInfo.LocalPath))
  264. {
  265. Directory.CreateDirectory(localInfo.LocalPath);
  266. }
  267. if (!Directory.Exists(localInfo.LocalDataPath))
  268. {
  269. Directory.CreateDirectory(localInfo.LocalDataPath);
  270. }
  271. if (!Directory.Exists(localInfo.ToolsPath))
  272. {
  273. Directory.CreateDirectory(localInfo.ToolsPath);
  274. }
  275. if (!Directory.Exists(localInfo.LocalPath + localInfo.CfgPathName))
  276. {
  277. Directory.CreateDirectory(localInfo.LocalPath + localInfo.CfgPathName);
  278. }
  279. //检查备忘录文件
  280. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.NoteFileName))
  281. {
  282. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.NoteFileName, "");
  283. }
  284. //检验流水号记录文件
  285. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.SerialNumFileName1))
  286. {
  287. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, "0");
  288. }
  289. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.SerialNumFileName2))
  290. {
  291. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, "0");
  292. }
  293. //服务器初始化
  294. do
  295. {
  296. //检查是否存在配置文件
  297. if (File.Exists(localInfo.LocalPath + localInfo.ServerCfgFileName)) //存在配置文件从文件选择
  298. {
  299. //解密
  300. string sLine = aes.DecryptFromFile(localInfo.LocalPath + localInfo.ServerCfgFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  301. string[] array_CfgInfo = sLine.Split(',');
  302. //解析配置文件
  303. ServerIP = array_CfgInfo[0].ToString();
  304. ServerPort = array_CfgInfo[1].ToString();
  305. ServerUser = array_CfgInfo[2].ToString();
  306. ServerPassWd = array_CfgInfo[3].ToString();
  307. if (array_CfgInfo[4].ToString() == "True")
  308. {
  309. OfflineFlag = true;
  310. checkBox_OffLineFacMode.Checked = true;
  311. checkBox_OffLineCheckMode.Checked = true;
  312. }
  313. }
  314. else //不存在配置文件由用户选择
  315. {
  316. ServerCfgForm1.ShowDialog();
  317. switch (ServerCfgForm1.comboBox_Server.SelectedIndex)
  318. {
  319. case 0: //武汉园区
  320. case 1: //顺德工厂
  321. {
  322. ServerIP = "10.177.130.30";
  323. ServerPort = "15021";
  324. ServerUser = "factory_test";
  325. ServerPassWd = "ttium";
  326. OfflineFlag = false;
  327. checkBox_OffLineFacMode.Checked = false;
  328. checkBox_OffLineCheckMode.Checked = false;
  329. break;
  330. }
  331. case 2: //威灵园区
  332. case 3: //越南工厂
  333. case 4: //公司外部
  334. {
  335. ServerIP = "8.134.109.44";
  336. ServerPort = "21";
  337. ServerUser = "ttium";
  338. ServerPassWd = "ttium123";
  339. OfflineFlag = false;
  340. checkBox_OffLineFacMode.Checked = false;
  341. checkBox_OffLineCheckMode.Checked = false;
  342. break;
  343. }
  344. case 5: //离线使用
  345. {
  346. //输入管理员密码
  347. Scan scan_form = new Scan();
  348. scan_form.label1.Text = "请输入管理员密码";
  349. scan_form.textBox_Scan.UseSystemPasswordChar = true;
  350. scan_form.ShowDialog();
  351. if (scan_form.textBox_Scan.Text == "ttium.123")
  352. {
  353. //检查许可
  354. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.OffLineUseKeyFileName)) //未许可
  355. {
  356. if (MessageBox.Show("无离线授权,请导入许可文件!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
  357. {
  358. Licences myLicences = new Licences();
  359. myLicences.ShowDialog();
  360. //从许可文件读取内容
  361. string str_lic = aes.DecryptFromFile(myLicences.textBox_LicencePath.Text, "2D820F88F60A39D5", "3687C5216B19D16B");
  362. string PC_Code = PC_Information.GetCPUSerialNumber();
  363. if (PC_Code == str_lic) //授权码正确
  364. {
  365. aes.EncryptToFile(PC_Code, localInfo.LocalPath + localInfo.OffLineUseKeyFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  366. string strInfo = "";
  367. strInfo = "0;" + DateTime.Now.ToString("yyyyMMdd");
  368. aes.EncryptToFile(strInfo, localInfo.LocalPath + localInfo.OfflineUseLogFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  369. }
  370. else //授权码错误
  371. {
  372. MessageBox.Show("许可文件无效,请联系管理员!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  373. System.Environment.Exit(0);
  374. }
  375. }
  376. else
  377. {
  378. System.Environment.Exit(0);
  379. }
  380. }
  381. else //已授权
  382. {
  383. string str_Key = aes.DecryptFromFile(localInfo.LocalPath + localInfo.OffLineUseKeyFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  384. //判断授权是否正确
  385. if (PC_Information.GetCPUSerialNumber() == str_Key) //授权正确
  386. {
  387. //检查离线使用记录文件
  388. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.OfflineUseLogFileName))
  389. {
  390. MessageBox.Show("许可文件内容缺失,请联系管理员!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  391. File.Delete(localInfo.LocalPath + localInfo.OffLineUseKeyFileName);//缺少离线使用记录文件时,自动删除许可文件,下次打开重新导入许可
  392. System.Environment.Exit(0);
  393. }
  394. //获取离线使用记录并更新
  395. string UseLog = aes.DecryptFromFile(localInfo.LocalPath + localInfo.OfflineUseLogFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  396. UInt32 UseTimes = Convert.ToUInt32(UseLog.Split(';')[0]);
  397. UseTimes++;
  398. string str = UseTimes.ToString() + ";" + UseLog.Split(';')[1];
  399. aes.EncryptToFile(str, localInfo.LocalPath + localInfo.OfflineUseLogFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  400. //判断授权期限
  401. DateTime DataOrigin = new DateTime();
  402. DateTime.TryParseExact(UseLog.Split(';')[1], "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None, out DataOrigin);
  403. DateTime DataEnd = DataOrigin.AddDays(90);
  404. DateTime NowDate = DateTime.Now.Date;
  405. if ((NowDate > DataEnd) || (UseTimes > 1000)) //第一次打开软件90天内,或1000次内
  406. {
  407. MessageBox.Show("离线授权过期,请联系管理员!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  408. File.Delete(localInfo.LocalPath + localInfo.OffLineUseKeyFileName);//许可过期或超出使用次数,自动删除许可文件和使用记录,下次打开重新导入许可
  409. File.Delete(localInfo.LocalPath + localInfo.OfflineUseLogFileName);//许可过期或超出使用次数,自动删除许可文件和使用记录,下次打开重新导入许可
  410. System.Environment.Exit(0);
  411. }
  412. }
  413. else
  414. {
  415. MessageBox.Show("离线授权错误,请联系管理员!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  416. File.Delete(localInfo.LocalPath + localInfo.OffLineUseKeyFileName);//许可文件不匹配,自动删除许可文件和使用记录,下次打开重新导入许可
  417. File.Delete(localInfo.LocalPath + localInfo.OfflineUseLogFileName);//许可文件不匹配,自动删除许可文件和使用记录,下次打开重新导入许可
  418. System.Environment.Exit(0);
  419. }
  420. }
  421. OfflineFlag = true;
  422. checkBox_OffLineFacMode.Checked = true;
  423. checkBox_OffLineCheckMode.Checked = true;
  424. }
  425. else
  426. {
  427. MessageBox.Show("密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  428. System.Environment.Exit(0);
  429. }
  430. break;
  431. }
  432. default: //无效
  433. {
  434. System.Environment.Exit(0);
  435. break;
  436. }
  437. }
  438. //保存网络配置文件
  439. if (ServerCfgForm1.checkBox_NoticeSw.Checked)
  440. {
  441. string str = ServerIP + "," + ServerPort + "," + ServerUser + "," + ServerPassWd + "," + (OfflineFlag == true).ToString();
  442. //加密保存
  443. aes.EncryptToFile(str, localInfo.LocalPath + localInfo.ServerCfgFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  444. }
  445. }
  446. } while (false);
  447. //检查配置文件
  448. if (File.Exists(localInfo.LocalPath + localInfo.ConfigFileName)) //存在配置文件,导入配置信息
  449. {
  450. //打开文件
  451. StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.ConfigFileName);
  452. string sLine = "";
  453. ArrayList array_CfgInfo = new ArrayList();
  454. array_CfgInfo.Clear();
  455. while (sLine != null)
  456. {
  457. sLine = objReader.ReadLine();
  458. array_CfgInfo.Add(sLine);
  459. }
  460. objReader.Close();
  461. //解析配置文件
  462. try
  463. {
  464. int index = -1;
  465. //Port Set
  466. index = Array.IndexOf(array_CfgInfo.ToArray(), "[PortSet]");
  467. PortNumSave = array_CfgInfo[index + 1].ToString().Split(':')[1];
  468. PortBaudrateSave = array_CfgInfo[index + 2].ToString().Split(':')[1];
  469. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.IndexOf(PortNumSave);
  470. toolStripComboBox_Baudrate.SelectedIndex = toolStripComboBox_Baudrate.Items.IndexOf(PortBaudrateSave);
  471. 连接开机ToolStripMenuItem.Checked = (array_CfgInfo[index + 3].ToString().Split(':')[1] == "True");
  472. 断开关机ToolStripMenuItem.Checked = (array_CfgInfo[index + 4].ToString().Split(':')[1] == "True");
  473. 识别通讯盒ToolStripMenuItem.Checked = (array_CfgInfo[index + 5].ToString().Split(':')[1] == "True");
  474. //Option
  475. index = Array.IndexOf(array_CfgInfo.ToArray(), "[Option]");
  476. 写入存储ToolStripMenuItem.Checked = (array_CfgInfo[index + 1].ToString().Split(':')[1] == "True");
  477. //Server Set
  478. index = Array.IndexOf(array_CfgInfo.ToArray(), "[ServerSet]");
  479. toolStripTextBox_ServerPath.Text = array_CfgInfo[index + 1].ToString().Split(':')[1];
  480. //MacInfo
  481. index = Array.IndexOf(array_CfgInfo.ToArray(), "[MacInfo]");
  482. toolStripTextBox_MAC.Text = array_CfgInfo[index + 1].ToString().Split(':')[1];
  483. toolStripTextBoxMACAddr.Text = array_CfgInfo[index + 2].ToString().Split(':')[1];
  484. toolStripTextBox_MACDate.Text = DateTime.Now.ToString("yyyyMMdd");
  485. toolStripTextBox_MACPD.Text = array_CfgInfo[index + 4].ToString().Split(':')[1];
  486. //Log Address
  487. index = Array.IndexOf(array_CfgInfo.ToArray(), "[LogAddress]");
  488. textBox_LogAddrBegin.Text = array_CfgInfo[index + 1].ToString().Split(':')[1];
  489. textBox_LogAddrEnd.Text = array_CfgInfo[index + 2].ToString().Split(':')[1];
  490. //电机类型
  491. index = Array.IndexOf(array_CfgInfo.ToArray(), "[MotorType]");
  492. 中置电机MIGIC_ToolStripMenuItem.Checked = (array_CfgInfo[index + 1].ToString().Split(':')[1] == "True");
  493. 中置电机VP_ToolStripMenuItem.Checked = (array_CfgInfo[index + 2].ToString().Split(':')[1] == "True");
  494. 轮毂电机ToolStripMenuItem.Checked = (array_CfgInfo[index + 3].ToString().Split(':')[1] == "True");
  495. //检测阈值
  496. index = Array.IndexOf(array_CfgInfo.ToArray(), "[CheckValue]");
  497. toolStripTextBox_ThVol.Text = array_CfgInfo[index + 1].ToString().Split(':')[1];
  498. toolStripTextBox_ThCur.Text = array_CfgInfo[index + 2].ToString().Split(':')[1];
  499. toolStripTextBox_ThSpeed.Text = array_CfgInfo[index + 3].ToString().Split(':')[1];
  500. toolStripTextBox_ThTor.Text = array_CfgInfo[index + 4].ToString().Split(':')[1];
  501. toolStripTextBox_ThCad.Text = array_CfgInfo[index + 5].ToString().Split(':')[1];
  502. toolStripTextBox_ThBikeSpeed.Text = array_CfgInfo[index + 6].ToString().Split(':')[1];
  503. toolStripTextBox_ThT_PCB.Text = array_CfgInfo[index + 7].ToString().Split(':')[1];
  504. toolStripTextBox_ThT_MCU.Text = array_CfgInfo[index + 8].ToString().Split(':')[1];
  505. toolStripTextBox_ThT_Motor.Text = array_CfgInfo[index + 9].ToString().Split(':')[1];
  506. //MOS内阻校准系数
  507. index = Array.IndexOf(array_CfgInfo.ToArray(), "[MosCalK]");
  508. toolStripTextBox_MosCalK.Text = array_CfgInfo[index + 1].ToString().Split(':')[1];
  509. toolStripTextBox_MOS1.Text= array_CfgInfo[index + 2].ToString().Split(':')[1];
  510. toolStripTextBox_MOS2.Text = array_CfgInfo[index + 3].ToString().Split(':')[1];
  511. toolStripTextBox_MOS3.Text = array_CfgInfo[index + 4].ToString().Split(':')[1];
  512. //通信协议类型
  513. index = Array.IndexOf(array_CfgInfo.ToArray(), "[ProtocolType]");
  514. cANToolStripMenuItem.Checked = (array_CfgInfo[index + 1].ToString().Split(':')[1] == "True");
  515. uARTToolStripMenuItem.Checked = (array_CfgInfo[index + 2].ToString().Split(':')[1] == "True");
  516. //自动更新开关
  517. index = Array.IndexOf(array_CfgInfo.ToArray(), "[AutoUpdate]");
  518. 打开ToolStripMenuItem.Checked = (array_CfgInfo[index + 1].ToString().Split(':')[1] == "True");
  519. 关闭ToolStripMenuItem.Checked = !打开ToolStripMenuItem.Checked;
  520. //位置校准偏差
  521. index = Array.IndexOf(array_CfgInfo.ToArray(), "[AngleCal]");
  522. textBox_AngleDiffTh.Text = array_CfgInfo[index + 1].ToString().Split(':')[1];
  523. toolStripTextBox_AngleAvgMax.Text = textBox_AngleDiffTh.Text;
  524. textBox_AngleZeroTh.Text = array_CfgInfo[index + 2].ToString().Split(':')[1];
  525. toolStripTextBox_AngleZeroMax.Text = textBox_AngleZeroTh.Text;
  526. }
  527. catch (System.Exception)
  528. {
  529. timer_500ms.Enabled = false;
  530. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  531. timer_500ms.Enabled = true;
  532. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  533. }
  534. }
  535. else //不存在配置文件,生成文件写入默认值
  536. {
  537. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  538. }
  539. //解析本地流水号记录
  540. do
  541. {
  542. //测试模式
  543. label_FacModeSerial.Text = File.ReadAllText(localInfo.LocalPath + localInfo.SerialNumFileName1);
  544. //检验模式
  545. label_CheckModeSerial.Text = File.ReadAllText(localInfo.LocalPath + localInfo.SerialNumFileName2);
  546. } while (false);
  547. //获取本机信息,读取时间较长,优先从本地文件获取
  548. do
  549. {
  550. try
  551. {
  552. //本地文件为空,读取信息保存
  553. if (!File.Exists(localInfo.LocalPath + localInfo.PC_InfoFileName))
  554. {
  555. Local_HdInformation = "";
  556. Local_HdInformation += "计算机名称: " + System.Environment.UserName + "\r\n";
  557. Local_HdInformation += "IP地址: " + PC_Information.GetIpAddress() + "\r\n";
  558. Local_HdInformation += "系统ID: " + PC_Information.GetSystemID() + "\r\n";
  559. Local_HdInformation += "操作系统类型: " + PC_Information.GetSystemType() + "\r\n";
  560. Local_HdInformation += "主板型号: " + PC_Information.GetBoardType() + "\r\n";
  561. Local_HdInformation += "主板厂商: " + PC_Information.GetBoardManufacturer() + "\r\n";
  562. Local_HdInformation += "主板ID: " + PC_Information.GetBIOSSerialNumber() + "\r\n";
  563. Local_HdInformation += "CPU型号: " + PC_Information.GetCpuName() + "\r\n";
  564. Local_HdInformation += "CPU厂商: " + PC_Information.GetCpuManufacturer() + "\r\n";
  565. Local_HdInformation += "CPU ID: " + PC_Information.GetCPUSerialNumber() + "\r\n";
  566. Local_HdInformation += "内存容量: " + PC_Information.GetPhysicalMemory() + " GB" + "\r\n";
  567. Local_HdInformation += "MAC ID: " + PC_Information.GetNetCardMACAddress().Replace(":", "-") + "\r\n";
  568. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.PC_InfoFileName, Local_HdInformation);
  569. }
  570. //从本地读取,计算机名和IP地址重新读
  571. else
  572. {
  573. Local_HdInformation = "";
  574. string[] fileInfo = File.ReadAllLines(localInfo.LocalPath + localInfo.PC_InfoFileName, Encoding.UTF8);
  575. fileInfo[0] = "计算机名称: " + System.Environment.UserName;
  576. fileInfo[1] = "IP地址: " + PC_Information.GetIpAddress();
  577. for (int i = 0; i < fileInfo.Length; i++)
  578. Local_HdInformation += fileInfo[i] + "\r\n";
  579. File.Delete(localInfo.LocalPath + localInfo.PC_InfoFileName);
  580. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.PC_InfoFileName, Local_HdInformation);
  581. }
  582. }
  583. catch(Exception)
  584. {
  585. }
  586. } while (false);
  587. //系统登录
  588. do
  589. {
  590. EnterForm1.ShowDialog();
  591. try
  592. {
  593. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  594. {
  595. if (EnterForm1.comboBox_User.Text.Contains("量产"))
  596. {
  597. //隐藏设置项
  598. 其它配置项ToolStripMenuItem.Visible = false;
  599. 写入存储ToolStripMenuItem.Visible = false;
  600. 服务器配置ToolStripMenuItem.Visible = false;
  601. 判断阈值ToolStripMenuItem.Visible = false;
  602. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  603. mOS内阻范围ToolStripMenuItem.Visible = false;
  604. 力矩传感器检验ToolStripMenuItem.Visible = false;
  605. 位置校准偏差范围ToolStripMenuItem.Visible = false;
  606. //显示生产信息
  607. 生产信息ToolStripMenuItem.Visible = true;
  608. //显示电机类型,但不可编辑
  609. 电机类型ToolStripMenuItem.Visible = true;
  610. 中置电机MIGIC_ToolStripMenuItem.Enabled = false;
  611. 中置电机VP_ToolStripMenuItem.Enabled = false;
  612. 轮毂电机ToolStripMenuItem.Enabled = false;
  613. if (uARTToolStripMenuItem.Checked)
  614. UART协议ToolStripMenuItem.Visible = true;
  615. //隐藏研发调试界面
  616. tabPage_MotorParam.Parent = null;
  617. tabPage_BikeParam.Parent = null;
  618. tabPage_BikeParam2.Parent = null;
  619. tabPage_ControlParam.Parent = null;
  620. tabPage_SensorParam.Parent = null;
  621. tabPage_AssistParam.Parent = null;
  622. tabPage_UsrRideParam.Parent = null;
  623. tabPage_DebugParam.Parent = null;
  624. tabPage_RecordInfo.Parent = null;
  625. tabPage_OtherInfo.Parent = null;
  626. tabPage_OBC.Parent = null;
  627. tabPage_RAMorFLASH.Parent = null;
  628. tabPage_FactoryMode.Parent = null;
  629. tabPage_DebugInfo.Parent = null;
  630. tabPage_AngleCal.Parent = null;
  631. tabPage_FuncSet.Parent = null;
  632. //显示运行信息
  633. tabPage_RunInfo.Parent = tabControl2;
  634. //根据电机类型修改生产信息和电机类型
  635. if (EnterForm1.comboBox_User.Text.Contains("中置MIGIC"))
  636. {
  637. 中置电机MIGIC_ToolStripMenuItem.Checked = true;
  638. 中置电机VP_ToolStripMenuItem.Checked = false;
  639. 轮毂电机ToolStripMenuItem.Checked = false;
  640. toolStripTextBox_MACPD.Text = "MM_MC1";
  641. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  642. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  643. }
  644. else if (EnterForm1.comboBox_User.Text.Contains("中置VP"))
  645. {
  646. 中置电机MIGIC_ToolStripMenuItem.Checked = false;
  647. 中置电机VP_ToolStripMenuItem.Checked = true;
  648. 轮毂电机ToolStripMenuItem.Checked = false;
  649. toolStripTextBox_MACPD.Text = "MM_MV1";
  650. toolStripTextBox_ServerPath.Text = "MC_VP_TEST";
  651. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  652. }
  653. else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
  654. {
  655. 中置电机MIGIC_ToolStripMenuItem.Checked = false;
  656. 中置电机VP_ToolStripMenuItem.Checked = false;
  657. 轮毂电机ToolStripMenuItem.Checked = true;
  658. toolStripTextBox_MACPD.Text = "GF_250_1";
  659. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  660. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  661. }
  662. //显示对应生产测试界面
  663. if (EnterForm1.comboBox_User.Text.Contains("写入"))
  664. {
  665. tabPage_ProductMode_Write.Parent = tabControl1;
  666. tabPage_ProductMode_Write.Select();
  667. tabPage_ProductMode_Read.Parent = null;
  668. }
  669. else if (EnterForm1.comboBox_User.Text.Contains("检验"))
  670. {
  671. tabPage_ProductMode_Read.Parent = tabControl1;
  672. tabPage_ProductMode_Read.Select();
  673. tabPage_ProductMode_Write.Parent = null;
  674. }
  675. //应答指令不提示
  676. ACK_DisFlag = false;
  677. //退出登录
  678. break;
  679. }
  680. else if (EnterForm1.comboBox_User.Text == "工程参数配置")
  681. {
  682. //隐藏工作台内容,新建窗口完成配置
  683. groupBox1.Visible = false;
  684. groupBox3.Visible = false;
  685. tabControl2.Visible = false;
  686. //隐藏提示信息
  687. label_StarInfo.Visible = false;
  688. //打开参数配置框
  689. GenerateParamsForm.ShowDialog();
  690. System.Environment.Exit(0);
  691. //退出登录
  692. break;
  693. }
  694. else if (EnterForm1.comboBox_User.Text.Contains("样机"))
  695. {
  696. //隐藏量产界面
  697. tabPage_ProductMode_Read.Parent = null;
  698. tabPage_ProductMode_Write.Parent = null;
  699. //隐藏配置项
  700. 其它配置项ToolStripMenuItem.Visible = false;
  701. 服务器配置ToolStripMenuItem.Visible = false;
  702. 判断阈值ToolStripMenuItem.Visible = false;
  703. 力矩传感器检验ToolStripMenuItem.Visible = false;
  704. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  705. mOS内阻范围ToolStripMenuItem.Visible = false;
  706. 位置校准偏差范围ToolStripMenuItem.Visible = false;
  707. //显示生产信息
  708. 生产信息ToolStripMenuItem.Visible = true;
  709. //显示电机类型
  710. 电机类型ToolStripMenuItem.Visible = true;
  711. 中置电机MIGIC_ToolStripMenuItem.Enabled = true;
  712. 中置电机VP_ToolStripMenuItem.Enabled=true;
  713. 轮毂电机ToolStripMenuItem.Enabled = true;
  714. if (uARTToolStripMenuItem.Checked)
  715. UART协议ToolStripMenuItem.Visible = true;
  716. if (EnterForm1.comboBox_User.Text.Contains("中置MIGIC"))
  717. {
  718. 中置电机MIGIC_ToolStripMenuItem.Checked = true;
  719. 中置电机VP_ToolStripMenuItem.Checked = false;
  720. 轮毂电机ToolStripMenuItem.Checked = false;
  721. toolStripTextBox_MACPD.Text = "MM_MC1";
  722. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  723. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  724. }
  725. else if (EnterForm1.comboBox_User.Text.Contains("中置VP"))
  726. {
  727. 中置电机MIGIC_ToolStripMenuItem.Checked = false;
  728. 中置电机VP_ToolStripMenuItem.Checked = true;
  729. 轮毂电机ToolStripMenuItem.Checked = false;
  730. toolStripTextBox_MACPD.Text = "MM_MV1";
  731. toolStripTextBox_ServerPath.Text = "MC_VP_TEST";
  732. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  733. }
  734. else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
  735. {
  736. 中置电机MIGIC_ToolStripMenuItem.Checked = false;
  737. 中置电机VP_ToolStripMenuItem.Checked = false;
  738. 轮毂电机ToolStripMenuItem.Checked = true;
  739. toolStripTextBox_MACPD.Text = "GF_250_1";
  740. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  741. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  742. }
  743. //退出登录
  744. break;
  745. }
  746. else if (EnterForm1.comboBox_User.Text == "FCT治具测试")
  747. {
  748. //隐藏设置项
  749. 其它配置项ToolStripMenuItem.Visible = false;
  750. 写入存储ToolStripMenuItem.Visible = false;
  751. 服务器配置ToolStripMenuItem.Visible = false;
  752. 判断阈值ToolStripMenuItem.Visible = false;
  753. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  754. mOS内阻范围ToolStripMenuItem.Visible = false;
  755. 力矩传感器检验ToolStripMenuItem.Visible = false;
  756. 位置校准偏差范围ToolStripMenuItem.Visible = false;
  757. //显示生产信息
  758. 生产信息ToolStripMenuItem.Visible = true;
  759. //显示电机类型,但不可编辑
  760. 电机类型ToolStripMenuItem.Visible = false;
  761. 中置电机MIGIC_ToolStripMenuItem.Enabled = false;
  762. 中置电机VP_ToolStripMenuItem.Enabled = false;
  763. 轮毂电机ToolStripMenuItem.Enabled = false;
  764. if (uARTToolStripMenuItem.Checked)
  765. UART协议ToolStripMenuItem.Visible = true;
  766. //隐藏研发调试界面
  767. tabPage_MotorParam.Parent = null;
  768. tabPage_BikeParam.Parent = null;
  769. tabPage_BikeParam2.Parent = null;
  770. tabPage_ControlParam.Parent = null;
  771. tabPage_SensorParam.Parent = null;
  772. tabPage_AssistParam.Parent = null;
  773. tabPage_UsrRideParam.Parent = null;
  774. tabPage_DebugParam.Parent = null;
  775. tabPage_RecordInfo.Parent = null;
  776. tabPage_OtherInfo.Parent = null;
  777. tabPage_OBC.Parent = null;
  778. tabPage_RAMorFLASH.Parent = null;
  779. tabPage_FactoryMode.Parent = null;
  780. tabPage_DebugInfo.Parent = null;
  781. tabPage_AngleCal.Parent = null;
  782. tabPage_FuncSet.Parent = null;
  783. //显示运行信息
  784. tabPage_RunInfo.Parent = tabControl2;
  785. //目前仅轮毂使用
  786. 中置电机MIGIC_ToolStripMenuItem.Checked = false;
  787. 中置电机VP_ToolStripMenuItem.Checked = false;
  788. 轮毂电机ToolStripMenuItem.Checked = true;
  789. toolStripTextBox_MACPD.Text = "GF_250_1";
  790. toolStripTextBox_ServerPath.Text = "HUB_Control_FCT";
  791. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  792. //显示量产测试界面
  793. tabPage_ProductMode_Write.Parent = tabControl1;
  794. tabPage_ProductMode_Write.Select();
  795. tabPage_ProductMode_Read.Parent = null;
  796. checkBox_OffLineFacMode.Checked = false;
  797. checkBox_OffLineFacMode.Enabled = true;
  798. checkBox_OffLineCheckMode.Checked = false;
  799. checkBox_OffLineCheckMode.Enabled = true;
  800. //应答指令不提示
  801. ACK_DisFlag = false;
  802. //退出登录
  803. break;
  804. }
  805. else if (EnterForm1.comboBox_User.Text == "研发调试")
  806. {
  807. //隐藏量产界面
  808. tabPage_ProductMode_Read.Parent = null;
  809. tabPage_ProductMode_Write.Parent = null;
  810. 服务器配置ToolStripMenuItem.Visible = false;
  811. if (uARTToolStripMenuItem.Checked)
  812. UART协议ToolStripMenuItem.Visible = true;
  813. //退出登录
  814. break;
  815. }
  816. else if (EnterForm1.comboBox_User.Text == "管理员")
  817. {
  818. //不隐藏任何界面
  819. //...
  820. //退出登录
  821. break;
  822. }
  823. else
  824. {
  825. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  826. //重新登录
  827. continue;
  828. }
  829. }
  830. else
  831. {
  832. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  833. //重新登录
  834. continue;
  835. }
  836. }
  837. catch (Exception)
  838. {
  839. System.Environment.Exit(0);
  840. }
  841. } while (true);
  842. //配置网络FTP服务器
  843. myFtp.FtpOption(ServerIP, ServerPort, ServerUser, ServerPassWd, "admin", "ttium_admin");
  844. //创建线程,定时检测网络连接状态
  845. Thread th = new Thread(NetworkCheck);
  846. th.IsBackground = true;
  847. th.Start();
  848. //允许跨线程访问
  849. Control.CheckForIllegalCrossThreadCalls = false;
  850. }
  851. /// <summary>
  852. /// 检查网络状态线程
  853. /// </summary>
  854. private void NetworkCheck()
  855. {
  856. //允许离线使用,直接退出
  857. if (OfflineFlag == true) //允许离线使用
  858. {
  859. MessageBoxTimeOut.Show("离线使用,不检测网络状态!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  860. return;
  861. }
  862. //不允许离线使用,实时监测网络状态
  863. else
  864. {
  865. //初始化第一次连接FTP服务器
  866. bool Result = myFtp.CheckFtp();
  867. if (Result == true)//服务器连接成功
  868. {
  869. myFtp.IsNetConnected = true;
  870. //上传登录日志
  871. do
  872. {
  873. //日志文件名
  874. string date = DateTime.Now.ToString("yyyy-MM-dd_HHmmss_fff");
  875. string fileName = date;
  876. //日志内容
  877. string fileInfo = Local_HdInformation;
  878. //保存本地
  879. if (!Directory.Exists(localInfo.LocalLogPath))
  880. Directory.CreateDirectory(localInfo.LocalLogPath);
  881. System.IO.File.WriteAllText(localInfo.LocalLogPath + fileName, fileInfo);
  882. //上传服务器
  883. myFtp.UploadFile(localInfo.LocalLogPath + fileName, "/Tools/Welling_Motor_Debug_Tool/log");
  884. } while (false);
  885. }
  886. else//服务器连接失败
  887. {
  888. myFtp.IsNetConnected = false;
  889. if (EnterForm1.comboBox_User.Text != "管理员")
  890. {
  891. MessageBoxTimeOut.Show("网络断开,将自动关闭!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  892. this.Close();
  893. }
  894. }
  895. //创建定时器,定时30s检查网络
  896. System.Timers.Timer timer_CheckNet = new System.Timers.Timer();
  897. timer_CheckNet.Enabled = true;
  898. timer_CheckNet.Interval = 30000;
  899. timer_CheckNet.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_CheckNet_Tick);
  900. timer_CheckNet.Start();
  901. while (true)
  902. {
  903. Thread.Sleep(1);
  904. if (myFtp.IsNetConnected == false)
  905. {
  906. label_Server_ComStatus.Text = "网络已断开";
  907. label_ServerStatus.BackColor = Color.Red;
  908. }
  909. else
  910. {
  911. label_Server_ComStatus.Text = "网络已连接";
  912. label_ServerStatus.BackColor = Color.Green;
  913. }
  914. }
  915. }
  916. }
  917. /// <summary>
  918. /// 线程中定时任务,检查网络状态
  919. /// </summary>
  920. /// <param name="sender"></param>
  921. /// <param name="e"></param>
  922. private void timer_CheckNet_Tick(object sender, EventArgs e)
  923. {
  924. //连接FTP服务器
  925. bool Result = myFtp.CheckFtp();
  926. if (Result == true)//服务器连接成功
  927. {
  928. myFtp.IsNetConnected = true;
  929. //允许使用
  930. groupBox1.Enabled = true;
  931. groupBox3.Enabled = true;
  932. tabControl2.Enabled = true;
  933. }
  934. else//服务器连接失败
  935. {
  936. myFtp.IsNetConnected = false;
  937. if (EnterForm1.comboBox_User.Text != "管理员")
  938. {
  939. MessageBoxTimeOut.Show("网络断开, 请检查网络!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Warning); //提示框自动3s关闭
  940. //禁止使用
  941. groupBox1.Enabled = false;
  942. groupBox3.Enabled = false;
  943. tabControl2.Enabled = false;
  944. }
  945. }
  946. }
  947. #region 非独占性延时函数
  948. public static void Delay_ms(int milliSecond)
  949. {
  950. int start = Environment.TickCount;
  951. while (Math.Abs(Environment.TickCount - start) < milliSecond)//毫秒
  952. {
  953. Application.DoEvents();
  954. }
  955. }
  956. #endregion
  957. private void MainForm_Load(object sender, System.EventArgs e)
  958. {
  959. timer_500ms.Start();
  960. //页面初始化
  961. label_BuildTime.Text = "编译时间:" + System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString("yyyy-MM-dd HH:mm:ss");
  962. label_Computername.Text = System.Environment.UserName;
  963. label_UserName.Text = EnterForm1.comboBox_User.Text;
  964. //位置校准表格初始化
  965. for (int i = 0; i < 7; i++)
  966. {
  967. int index = dataGridView_AngleCal.Rows.Add();
  968. dataGridView_AngleCal.Rows[index].Cells[0].Value = i + 1;
  969. }
  970. dataGridView_AngleCal.AllowUserToAddRows = false;
  971. //拓展功能表格初始化
  972. for (int i = 0; i < 8; i++)
  973. {
  974. int index = dataGridView_FunSet.Rows.Add();
  975. dataGridView_FunSet.Rows[index].Cells[0].Value = "#" + (i + 1).ToString();
  976. }
  977. dataGridView_FunSet.AllowUserToAddRows = false;
  978. //窗体显示版本
  979. this.Text += Version;
  980. //检查版本,自动更新
  981. do
  982. {
  983. if ((打开ToolStripMenuItem.Checked == false) || OfflineFlag == true)//关闭自动更新或离线时
  984. {
  985. break;
  986. }
  987. //检查网络状态
  988. if (myFtp.CheckFtp() == false)
  989. {
  990. MessageBoxTimeOut.Show("网络断开,自动更新失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  991. break;
  992. }
  993. else
  994. {
  995. //检查本地文件删除
  996. if (System.IO.File.Exists(localInfo.LocalPath + "\\Version"))
  997. System.IO.File.Delete(localInfo.LocalPath + "\\Version");
  998. //读取最新版本号
  999. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/Version", localInfo.LocalPath);
  1000. StreamReader objReader = new StreamReader(localInfo.LocalPath + "\\Version");
  1001. string sLine = "";
  1002. ArrayList arrText = new ArrayList();//创建一个动态数组
  1003. while (sLine != null)
  1004. {
  1005. sLine = objReader.ReadLine();
  1006. arrText.Add(sLine);
  1007. }
  1008. objReader.Close();
  1009. System.IO.File.Delete(localInfo.LocalPath + "\\Version");
  1010. //检查是否有最新版本
  1011. string[] VerOld = mainForm.Version.Trim().Split('.');
  1012. string[] VerNew = arrText[0].ToString().Trim().Split('.');
  1013. int VerOld_int = Convert.ToInt32(VerOld[0]) * 10000 + Convert.ToInt32(VerOld[1].PadLeft(2, '0')) * 100 + Convert.ToInt32(VerOld[2].PadLeft(2, '0'));
  1014. int VerNew_int = Convert.ToInt32(VerNew[0]) * 10000 + Convert.ToInt32(VerNew[1].PadLeft(2, '0')) * 100 + Convert.ToInt32(VerNew[2].PadLeft(2, '0'));
  1015. if (VerNew_int <= VerOld_int)
  1016. {
  1017. //版本已是最新,跳出
  1018. break;
  1019. }
  1020. //确认下载最新版本
  1021. if (MessageBox.Show("是否更新新版本?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1022. {
  1023. string SavePath = Directory.GetCurrentDirectory();
  1024. string[] FileList = myFtp.GetFileNameList("/Tools/Welling_Motor_Debug_Tool");
  1025. foreach (string file in FileList)
  1026. {
  1027. if (file.Contains(".exe"))
  1028. {
  1029. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/" + file, SavePath);
  1030. MessageBox.Show("新版本下载完成,请手动删除旧版本!\r\n最新版本:" + file, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  1031. System.Environment.Exit(0);
  1032. }
  1033. }
  1034. }
  1035. }
  1036. } while (false);
  1037. //下拉控件初始值设定
  1038. comboBox_WorkMode.SelectedIndex = 0;
  1039. comboBox_GearSt.SelectedIndex = 0;
  1040. comboBox_LightSwitch.SelectedIndex = 1;
  1041. comboBox_OBC_SetGearST.SelectedIndex = 0;
  1042. comboBox_OBC_LightSw.SelectedIndex = 1;
  1043. comboBox_AssistTorque.SelectedIndex = 0;
  1044. comboBox_AssistCadence.SelectedIndex = 0;
  1045. //combobox事件定义
  1046. this.comboBox_WorkMode.SelectedIndexChanged += new System.EventHandler(this.comboBox_WorkMode_SelectedIndexChanged);
  1047. this.comboBox_GearSt.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  1048. this.comboBox_LightSwitch.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  1049. this.comboBox_OBC_SetGearST.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  1050. this.comboBox_OBC_LightSw.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  1051. //端口自动连接
  1052. if ((PortNumSave != string.Empty) && (PortBaudrateSave != string.Empty)) //有数值时采用上次使用的值
  1053. {
  1054. try
  1055. {
  1056. PortConnect();
  1057. }
  1058. catch (System.Exception)
  1059. {
  1060. timer_500ms.Enabled = false;
  1061. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  1062. timer_500ms.Enabled = true;
  1063. }
  1064. }
  1065. //不识别联动装置盒自动打开界面
  1066. #if true
  1067. groupBox1.Visible = true;
  1068. groupBox3.Visible = true;
  1069. tabControl2.Visible = true;
  1070. label_StarInfo.Visible = false;
  1071. #endif
  1072. //创建线程,定时解析数据
  1073. Thread th = new Thread(Task_SerialProcess);
  1074. th.IsBackground = true;
  1075. th.Start();
  1076. }
  1077. #region 结构体与字节流相互转换
  1078. public static class MyConverter
  1079. {
  1080. /// <summary>
  1081. /// 由结构体转换为byte数组
  1082. /// </summary>
  1083. public static byte[] StructureToByte<T>(T structure)
  1084. {
  1085. int size = Marshal.SizeOf(typeof(T));
  1086. byte[] buffer = new byte[size];
  1087. IntPtr bufferIntPtr = Marshal.AllocHGlobal(size);
  1088. try
  1089. {
  1090. Marshal.StructureToPtr(structure, bufferIntPtr, true);
  1091. Marshal.Copy(bufferIntPtr, buffer, 0, size);
  1092. }
  1093. finally
  1094. {
  1095. Marshal.FreeHGlobal(bufferIntPtr);
  1096. }
  1097. return buffer;
  1098. }
  1099. /// <summary>
  1100. /// 由byte数组转换为结构体
  1101. /// </summary>
  1102. public static T ByteToStructure<T>(byte[] dataBuffer, ushort StarIndex)
  1103. {
  1104. object structure = null;
  1105. int size = Marshal.SizeOf(typeof(T));
  1106. IntPtr allocIntPtr = Marshal.AllocHGlobal(size);
  1107. try
  1108. {
  1109. Marshal.Copy(dataBuffer, StarIndex, allocIntPtr, size);
  1110. structure = Marshal.PtrToStructure(allocIntPtr, typeof(T));
  1111. }
  1112. finally
  1113. {
  1114. Marshal.FreeHGlobal(allocIntPtr);
  1115. }
  1116. return (T)structure;
  1117. }
  1118. }
  1119. #endregion
  1120. #region 故障日志解析显示
  1121. private void ErrorLogDisplay(MC_ErrorLogSaveInfo_Struct_t Log1, MC_ErrorLogSaveInfo_Struct_t Log2)
  1122. {
  1123. string SaveData = "";
  1124. //Log1
  1125. if (Log1.Error_Index != 0xFFFF)
  1126. {
  1127. SaveData += "故障序号:" + Convert.ToString(Log1.Error_Index) + ", ";
  1128. SaveData += "备注1:" + Convert.ToString(Log1.NotesInfo1) + ", ";
  1129. SaveData += "备注2:" + Convert.ToString(Log1.NotesInfo2) + ", ";
  1130. SaveData += "备注3:" + Convert.ToString(Log1.NotesInfo3) + ", ";
  1131. SaveData += "故障码:" + "0x" + Convert.ToString(Log1.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  1132. SaveData += "运行时间:" + Convert.ToString(Log1.RunTime) + "min" + ", ";
  1133. SaveData += "车速:" + ((float)Log1.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  1134. SaveData += "电机转速:" + Convert.ToString(Log1.RunInfo.MotorSpeed) + "rpm" + ", ";
  1135. SaveData += "功率:" + Convert.ToString(Log1.RunInfo.Power * 2) + "w" + ", ";
  1136. SaveData += "电压:" + Convert.ToString(Log1.RunInfo.BusVoltage) + "mV" + ", ";
  1137. SaveData += "电流:" + Convert.ToString(Log1.RunInfo.BusCurrent) + "mA" + ", ";
  1138. SaveData += "踏频:" + Convert.ToString(Log1.RunInfo.Cadence) + "rpm" + ", ";
  1139. SaveData += "力矩:" + Convert.ToString(Log1.RunInfo.Torque) + "N.m" + ", ";
  1140. SaveData += "方向:" + ((Log1.RunInfo.CadenceDir == 0) ? "正" : ((Log1.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  1141. SaveData += "档位:" + "0x" + Convert.ToString(Log1.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  1142. SaveData += "灯开关:" + ((Log1.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  1143. SaveData += "电量:" + Convert.ToString(Log1.RunInfo.SOC) + "%" + ", ";
  1144. if ((Log1.RunInfo.RemainDistance == 0xEEEE) || (Log1.RunInfo.RemainDistance == 0xFFFF))
  1145. {
  1146. SaveData += "续航:" + "---km" + ", ";
  1147. }
  1148. else
  1149. {
  1150. SaveData += "续航:" + Convert.ToString(Log1.RunInfo.RemainDistance) + "km" + ", ";
  1151. }
  1152. SaveData += "力矩AD:" + Convert.ToString(Log1.RunInfo.Torque_AD) + ", ";
  1153. SaveData += "功耗:" + Convert.ToString(Log1.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  1154. SaveData += "PCB温度:" + Convert.ToString((int)(Log1.RunInfo.T_PCB - 40)) + "℃" + ", ";
  1155. SaveData += "绕组温度:" + Convert.ToString((int)(Log1.RunInfo.T_Coil - 40)) + "℃" + ", ";
  1156. SaveData += "MCU温度:" + Convert.ToString((int)(Log1.RunInfo.T_MCU - 40)) + "℃" + ", ";
  1157. SaveData += "单次里程:" + Convert.ToString((float)Log1.RunInfo.Ride_Km / 10f) + "km" + ", ";
  1158. SaveData += "单次时间:" + Convert.ToString(Log1.RunInfo.Ride_Time) + "s" + ", ";
  1159. SaveData += "q轴电流:" + Convert.ToString(Log1.IqCurrent) + ", ";
  1160. SaveData += "q轴电压:" + Convert.ToString(Log1.IqVoltage) + ", ";
  1161. SaveData += "d轴电流:" + Convert.ToString(Log1.IdCurrent) + ", ";
  1162. SaveData += "d轴电压:" + Convert.ToString(Log1.IdVoltage) + ", ";
  1163. SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
  1164. SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
  1165. SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
  1166. SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
  1167. SaveData += "\r\n\r\n";
  1168. richTextBox_Record.AppendText(SaveData);
  1169. SaveData = "";
  1170. }
  1171. //Log2
  1172. if (Log2.Error_Index != 0xFFFF)
  1173. {
  1174. SaveData += "故障序号:" + Convert.ToString(Log2.Error_Index) + ", ";
  1175. SaveData += "备注1:" + Convert.ToString(Log2.NotesInfo1) + ", ";
  1176. SaveData += "备注2:" + Convert.ToString(Log2.NotesInfo2) + ", ";
  1177. SaveData += "备注3:" + Convert.ToString(Log2.NotesInfo3) + ", ";
  1178. SaveData += "故障码:" + "0x" + Convert.ToString(Log2.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  1179. SaveData += "运行时间:" + Convert.ToString(Log2.RunTime) + "min" + ", ";
  1180. SaveData += "车速:" + ((float)Log2.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  1181. SaveData += "电机转速:" + Convert.ToString(Log2.RunInfo.MotorSpeed) + "rpm" + ", ";
  1182. SaveData += "功率:" + Convert.ToString(Log2.RunInfo.Power * 2) + "w" + ", ";
  1183. SaveData += "电压:" + Convert.ToString(Log2.RunInfo.BusVoltage) + "mV" + ", ";
  1184. SaveData += "电流:" + Convert.ToString(Log2.RunInfo.BusCurrent) + "mA" + ", ";
  1185. SaveData += "踏频:" + Convert.ToString(Log2.RunInfo.Cadence) + "rpm" + ", ";
  1186. SaveData += "力矩:" + Convert.ToString(Log2.RunInfo.Torque) + "N.m" + ", ";
  1187. SaveData += "方向:" + ((Log2.RunInfo.CadenceDir == 0) ? "正" : ((Log2.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  1188. SaveData += "档位:" + "0x" + Convert.ToString(Log2.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  1189. SaveData += "灯开关:" + ((Log2.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  1190. SaveData += "电量:" + Convert.ToString(Log2.RunInfo.SOC) + "%" + ", ";
  1191. if ((Log2.RunInfo.RemainDistance == 0xEEEE) || (Log2.RunInfo.RemainDistance == 0xFFFF))
  1192. {
  1193. SaveData += "续航:" + "---km" + ", ";
  1194. }
  1195. else
  1196. {
  1197. SaveData += "续航:" + Convert.ToString(Log2.RunInfo.RemainDistance) + "km" + ", ";
  1198. }
  1199. SaveData += "力矩AD:" + Convert.ToString(Log2.RunInfo.Torque_AD) + ", ";
  1200. SaveData += "功耗:" + Convert.ToString(Log2.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  1201. SaveData += "PCB温度:" + Convert.ToString((int)(Log2.RunInfo.T_PCB - 40)) + "DegreeC" + ", ";
  1202. SaveData += "绕组温度:" + Convert.ToString((int)(Log2.RunInfo.T_Coil - 40)) + "DegreeC" + ", ";
  1203. SaveData += "MCU温度:" + Convert.ToString((int)(Log2.RunInfo.T_MCU - 40)) + "DegreeC" + ", ";
  1204. SaveData += "单次里程:" + Convert.ToString((float)Log2.RunInfo.Ride_Km / 10f) + "km" + ", ";
  1205. SaveData += "单次时间:" + Convert.ToString(Log2.RunInfo.Ride_Time) + "s" + ", ";
  1206. SaveData += "q轴电流:" + Convert.ToString(Log2.IqCurrent) + ", ";
  1207. SaveData += "q轴电压:" + Convert.ToString(Log2.IqVoltage) + ", ";
  1208. SaveData += "d轴电流:" + Convert.ToString(Log2.IdCurrent) + ", ";
  1209. SaveData += "d轴电压:" + Convert.ToString(Log2.IdVoltage) + ", ";
  1210. SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
  1211. SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
  1212. SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
  1213. SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
  1214. SaveData += "\r\n\r\n";
  1215. richTextBox_Record.AppendText(SaveData);
  1216. SaveData = "";
  1217. }
  1218. }
  1219. #endregion
  1220. #region 串口数据解析线程
  1221. /// <summary>
  1222. /// 串口数据解析线程
  1223. /// </summary>
  1224. private void Task_SerialProcess()
  1225. {
  1226. //创建定时器,定时读取串口数据
  1227. System.Timers.Timer timer_ReadSerial = new System.Timers.Timer();
  1228. timer_ReadSerial.Enabled = true;
  1229. timer_ReadSerial.Interval = 20;
  1230. timer_ReadSerial.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_ReadSerial_Tick);
  1231. timer_ReadSerial.Start();
  1232. while (true)
  1233. {
  1234. Thread.Sleep(1);
  1235. };
  1236. }
  1237. /// <summary>
  1238. /// 串口解析定时器
  1239. /// </summary>
  1240. /// <param name="sender"></param>
  1241. /// <param name="e"></param>
  1242. private void timer_ReadSerial_Tick(object sender, EventArgs e)
  1243. {
  1244. //串口解析
  1245. Serial_process(mySerialProcess.buffer);
  1246. }
  1247. #endregion
  1248. #region 数据解析
  1249. public void Serial_process(List<byte> buffer)
  1250. {
  1251. byte DataNum = 0; //记录每条命令数据段的长度
  1252. ushort PackageID, Cmd;
  1253. byte[] Data = new byte[1024];
  1254. try
  1255. {
  1256. while (buffer.Count >= 13)//当buffer中的数据的个数大于等于4个时,即每一帧的数据长度所在位(第4位)出现时
  1257. {
  1258. if (buffer[0] == 0x55 && buffer[1] == 0xAA)//判断帧头
  1259. {
  1260. PackageID = (ushort)(buffer[2] * 256 + buffer[3]);
  1261. if ((PackageID == 0x0710) || (PackageID == 0x0715) || (PackageID == 0x07FF) || (PackageID == 0x0720) || (PackageID == 0x0713))
  1262. {
  1263. int CmdLen = buffer[5];
  1264. if (buffer.Count < CmdLen + 11) break;//如果接收到的数据没有达到一帧数据的指定长度, 则执行下次循环
  1265. while (CmdLen > 0) //读取命令段
  1266. {
  1267. Cmd = (ushort)(buffer[6] * 256 + buffer[7]);
  1268. DataNum = (byte)(buffer[7]);//命令字的第二个字节的表示数据位的长度
  1269. if (DataNum <= (CmdLen - 2))
  1270. {
  1271. for (int i = 0; i < DataNum; i++)
  1272. {
  1273. Data[i] = buffer[i + 8];
  1274. }
  1275. // 串口接收的数据 显示在子窗口
  1276. if (this.DebugWindowIsOpen && this.DebugDataDisplayEnable)
  1277. {
  1278. string strTemp = String.Empty;
  1279. strTemp += System.DateTimeOffset.Now.ToString("HH:mm:ss.fff") + " <-- ";
  1280. for (int i = 0; i < CmdLen + 11; i++)
  1281. {
  1282. strTemp += (buffer[i].ToString("X2") + " ");
  1283. }
  1284. strTemp += "\n";
  1285. DebugForm.debug1.richTextBox_DebugRev.Text += strTemp;
  1286. }
  1287. buffer.RemoveRange(0, CmdLen + 11);
  1288. DataCmdProcess(PackageID, Cmd, Data);//对于不同的命令段,做不同的处理
  1289. DataRevToString(Cmd, Data);//指令数据转为字符串
  1290. }
  1291. }
  1292. }
  1293. else
  1294. {
  1295. buffer.RemoveAt(0);//ID不对
  1296. }
  1297. }
  1298. else
  1299. {
  1300. buffer.RemoveAt(0);//帧头不对,删除帧头高字节
  1301. }
  1302. }
  1303. }
  1304. catch (Exception)
  1305. {
  1306. }
  1307. }
  1308. private void DataCmdProcess(ushort ID, ushort CmdTemp, byte[] Data)
  1309. {
  1310. int DataTemp;
  1311. ushort uData16;
  1312. unchecked
  1313. {
  1314. this.Invoke((EventHandler)(delegate { label_RecCount.Text = Convert.ToString(Convert.ToInt32(label_RecCount.Text) + 1); }));
  1315. }
  1316. #region 解析发送给CDL的指令
  1317. if (ID == 0x7FF)
  1318. {
  1319. switch (CmdTemp)
  1320. {
  1321. case 0x1100://
  1322. {
  1323. unchecked
  1324. {
  1325. this.Invoke((EventHandler)(delegate
  1326. {
  1327. //CDL连接成功
  1328. mySerialProcess.CDL_Online_Flag = true;
  1329. MessageBoxTimeOut.Show("连接成功!", "提示", 500);
  1330. groupBox1.Visible = true;
  1331. groupBox3.Visible = true;
  1332. tabControl2.Visible = true;
  1333. label_StarInfo.Visible = false;
  1334. }));
  1335. }
  1336. break;
  1337. }
  1338. default: break;
  1339. }
  1340. }
  1341. #endregion
  1342. #region 解析电机的命令
  1343. else if ((ID == 0x715) || (ID == 0x710))
  1344. {
  1345. switch (CmdTemp)
  1346. {
  1347. case 0x1020://电机运行信息
  1348. {
  1349. unchecked
  1350. {
  1351. this.Invoke((EventHandler)(delegate
  1352. {
  1353. MC_RunInfo_Refresh = true;
  1354. //车速
  1355. DataTemp = (int)(Data[1] * 256 + Data[0]);
  1356. textBox_RunInfo_BikeSpeed.Text = ((float)DataTemp / 10f).ToString("0.0") + " km/h";
  1357. //输出转速
  1358. DataTemp = (ushort)(Data[3] * 256 + Data[2]);
  1359. textBox_RunInfo_MotorSpeed.Text = Convert.ToString(DataTemp) + " rpm";
  1360. Class_MotorSpeed.String = textBox_RunInfo_MotorSpeed.Text;
  1361. Class_MotorSpeed.Data = DataTemp;
  1362. //电功率
  1363. DataTemp = (ushort)(Data[5] * 256 + Data[4]);
  1364. textBox_RunInfo_Power.Text = Convert.ToString(DataTemp) + " W";
  1365. //母线电压
  1366. DataTemp = (ushort)(Data[7] * 256 + Data[6]);
  1367. textBox_RunInfo_Vol.Text = Convert.ToString(DataTemp) + " mV";
  1368. //textBox_RunInfo_Vol.Text = (DataTemp / 1000f).ToString("0.0") + " V";
  1369. //母线电流
  1370. DataTemp = (short)(Data[9] * 256 + Data[8]);
  1371. textBox_RunInfo_Current.Text = Convert.ToString(DataTemp) + " mA";
  1372. //textBox_RunInfo_Current.Text = (DataTemp / 1000f).ToString("0.0") + " A";
  1373. Class_CurrentData.String = textBox_RunInfo_Current.Text;
  1374. Class_CurrentData.Data = DataTemp;
  1375. //踏频
  1376. DataTemp = (ushort)(Data[10]);
  1377. textBox_RunInfo_Cadence.Text = Convert.ToString(DataTemp) + " rpm";
  1378. Class_CadenceData.String = textBox_RunInfo_Cadence.Text;
  1379. Class_CadenceData.Data = DataTemp;
  1380. //踩踏力矩
  1381. DataTemp = (ushort)(Data[11]);
  1382. textBox_RunInfo_Torque.Text = Convert.ToString(DataTemp) + " N.m";
  1383. Class_TorqueData.String = textBox_RunInfo_Torque.Text;
  1384. Class_TorqueData.Data = DataTemp;
  1385. //踩踏方向
  1386. DataTemp = (ushort)(Data[12]);
  1387. if (DataTemp == 0)
  1388. {
  1389. textBox_RunInfo_Dir.Text = "正向";
  1390. }
  1391. else if (DataTemp == 1)
  1392. {
  1393. textBox_RunInfo_Dir.Text = "反向";
  1394. }
  1395. else if (DataTemp == 2)
  1396. {
  1397. textBox_RunInfo_Dir.Text = "停止";
  1398. }
  1399. //助力档位
  1400. DataTemp = (ushort)(Data[13]);
  1401. if (DataTemp == 0x33)
  1402. {
  1403. textBox_RunInfo_GearSt.Text = "SMART";
  1404. //comboBox_GearSt.SelectedIndex = 5;
  1405. //comboBox_OBC_SetGearST.SelectedIndex = 5;
  1406. }
  1407. else if (DataTemp == 0x22)
  1408. {
  1409. textBox_RunInfo_GearSt.Text = "WALK";
  1410. //comboBox_GearSt.SelectedIndex = 6;
  1411. //comboBox_OBC_SetGearST.SelectedIndex = 6;
  1412. }
  1413. else
  1414. {
  1415. string[] Gears = new string[5] { "OFF", "ECO", "NORM", "SPORT", "TURBO" };
  1416. textBox_RunInfo_GearSt.Text = Gears[DataTemp];
  1417. //comboBox_GearSt.SelectedIndex = DataTemp;
  1418. //comboBox_OBC_SetGearST.SelectedIndex = DataTemp;
  1419. }
  1420. //大灯状态
  1421. DataTemp = (ushort)(Data[14]);
  1422. if (DataTemp == 0xF0)
  1423. {
  1424. textBox_RunInfo_LightSwitch.Text = "OFF";
  1425. //comboBox_LightSwitch.SelectedIndex = 1;
  1426. //comboBox_OBC_LightSw.SelectedIndex = 1;
  1427. }
  1428. else if (DataTemp == 0xF1)
  1429. {
  1430. textBox_RunInfo_LightSwitch.Text = "ON";
  1431. //comboBox_LightSwitch.SelectedIndex = 0;
  1432. //comboBox_OBC_LightSw.SelectedIndex = 0;
  1433. }
  1434. //剩余电量
  1435. DataTemp = (ushort)(Data[15]);
  1436. textBox_RunInfo_SOC.Text = Convert.ToString(DataTemp) + " %";
  1437. //剩余续航里程
  1438. DataTemp = (ushort)(Data[17] * 256 + Data[16]);
  1439. if ((DataTemp == 0xEEEE) || (DataTemp == 0xFFFF))
  1440. {
  1441. textBox_RunInfo_Range.Text = "---";
  1442. }
  1443. else
  1444. {
  1445. textBox_RunInfo_Range.Text = Convert.ToString(DataTemp) + " km";
  1446. }
  1447. //预留(显示力矩Reg),空2bytes
  1448. DataTemp = (ushort)(Data[19] * 256 + Data[18]);
  1449. textBox_TorqueReg.Text = Convert.ToString(DataTemp);
  1450. //平均功耗
  1451. DataTemp = (ushort)(Data[20]);
  1452. textBox_RunInfo_AvgPower.Text = Convert.ToString(DataTemp * 10) + " mAh/km";
  1453. //PCB温度
  1454. DataTemp = (ushort)(Data[21]);
  1455. textBox_RunInfo_T_PCB.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1456. Class_MotorTemp.String = textBox_RunInfo_T_PCB.Text;
  1457. Class_MotorTemp.Data = DataTemp - 40;
  1458. //绕组温度
  1459. DataTemp = (ushort)(Data[22]);
  1460. textBox_RunInfo_T_Coil.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1461. //MCU温度
  1462. DataTemp = (ushort)(Data[23]);
  1463. textBox_RunInfo_T_MCU.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1464. //单次里程
  1465. DataTemp = (ushort)(Data[25] * 256 + Data[24]);
  1466. textBox_RunInfo_Trip.Text = ((float)DataTemp / 10f).ToString("0.0") + " km";
  1467. //单次时间
  1468. DataTemp = (ushort)(Data[27] * 256 + Data[26]);
  1469. textBox_RunInfo_Trip_Time.Text = Convert.ToString(DataTemp) + " s";
  1470. //RSV1
  1471. DataTemp = (ushort)(Data[28]);
  1472. textBox_RunInfo_RSV1.Text = Convert.ToString(DataTemp);
  1473. //RSV2
  1474. DataTemp = (ushort)(Data[29]);
  1475. textBox_RunInfo_RSV2.Text = Convert.ToString(DataTemp);
  1476. //RSV3
  1477. DataTemp = (ushort)(Data[30]);
  1478. textBox_RunInfo_RSV3.Text = Convert.ToString(DataTemp);
  1479. //GearBox
  1480. DataTemp = (ushort)(Data[31]);
  1481. textBox_RunInfo_GearBox.Text = Convert.ToString(DataTemp);
  1482. //数据保存
  1483. RunInfoAutoSave();
  1484. }));
  1485. }
  1486. break;
  1487. }
  1488. case 0x1104://故障码
  1489. {
  1490. unchecked
  1491. {
  1492. this.Invoke((EventHandler)(delegate
  1493. {
  1494. MC_ErrorCode_Refresh = true;
  1495. textBox_ErrorCode.Text =
  1496. Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() +
  1497. Convert.ToString(Data[2], 16).PadLeft(2, '0').ToUpper() +
  1498. Convert.ToString(Data[1], 16).PadLeft(2, '0').ToUpper() +
  1499. Convert.ToString(Data[0], 16).PadLeft(2, '0').ToUpper() +
  1500. "H";
  1501. }));
  1502. }
  1503. break;
  1504. }
  1505. case 0xA903://反馈指令
  1506. {
  1507. unchecked
  1508. {
  1509. this.Invoke((EventHandler)(delegate
  1510. {
  1511. if (ACK_DisFlag == true)
  1512. {
  1513. MessageBoxTimeOut.Show("OK", "反馈指令", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  1514. //关机反馈
  1515. PowerOffAckStatus = true;
  1516. }
  1517. //应答标志置位
  1518. WriteACK = true;
  1519. }));
  1520. }
  1521. break;
  1522. }
  1523. case 0xB226://马达参数
  1524. {
  1525. unchecked
  1526. {
  1527. this.Invoke((EventHandler)(delegate
  1528. {
  1529. richTextBox_MotorParam.Clear();
  1530. for (int i = 0; i < myParams.MotorParam.Count; i++)
  1531. {
  1532. if (i == 6)
  1533. richTextBox_MotorParam.AppendText(myParams.MotorParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1534. else
  1535. richTextBox_MotorParam.AppendText(myParams.MotorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1536. }
  1537. richTextBox_MotorParam.Text = richTextBox_MotorParam.Text.Substring(0, richTextBox_MotorParam.Text.Length - 2);
  1538. }));
  1539. }
  1540. break;
  1541. }
  1542. case 0xB31A://整车信息
  1543. {
  1544. unchecked
  1545. {
  1546. this.Invoke((EventHandler)(delegate
  1547. {
  1548. richTextBox_BikeParam.Clear();
  1549. for (int i = 0; i < myParams.BikeParam.Count; i++)
  1550. {
  1551. if (i == 9)
  1552. richTextBox_BikeParam.AppendText(myParams.BikeParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1553. else
  1554. richTextBox_BikeParam.AppendText(myParams.BikeParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1555. //更新前后灯参数
  1556. if (i == 8)
  1557. {
  1558. comboBox_TailLightMode.SelectedIndex = ((Data[2 * i + 1] >> 4) & 0x0F) - 1;
  1559. comboBox_TailLightVol.SelectedIndex = ((Data[2 * i + 1] & 0x0F) == 6) ? 0 : 1;
  1560. comboBox_FrontLightVol.SelectedIndex = ((Data[2 * i] & 0x0F) == 6) ? 0 : 1;
  1561. }
  1562. //更新开关机参数
  1563. else if (i == 11)
  1564. {
  1565. textBox_PowerOnDelay.Text = Convert.ToString((Data[2 * i + 1] >> 4) & 0x0F);
  1566. textBox_PowerOffDelay.Text = Convert.ToString(Data[2 * i + 1] & 0x0F);
  1567. textBox_AutoPowerOff.Text = Convert.ToString(Data[2 * i]);
  1568. }
  1569. }
  1570. richTextBox_BikeParam.Text = richTextBox_BikeParam.Text.Substring(0, richTextBox_BikeParam.Text.Length - 2);
  1571. }));
  1572. }
  1573. break;
  1574. }
  1575. case 0xB420://控制器参数
  1576. {
  1577. unchecked
  1578. {
  1579. this.Invoke((EventHandler)(delegate
  1580. {
  1581. richTextBox_ControlParam.Clear();
  1582. for (int i = 0; i < myParams.ControlParam.Count; i++)
  1583. {
  1584. richTextBox_ControlParam.AppendText(myParams.ControlParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1585. //转把定速巡航
  1586. if (i == 13)
  1587. {
  1588. comboBox_Bike_CCS.SelectedIndex = ((Data[2 * i]) == 0xAA) ? 1 : 2;
  1589. }
  1590. }
  1591. richTextBox_ControlParam.Text = richTextBox_ControlParam.Text.Substring(0, richTextBox_ControlParam.Text.Length - 2);
  1592. }));
  1593. }
  1594. break;
  1595. }
  1596. case 0xB528://传感器参数
  1597. {
  1598. unchecked
  1599. {
  1600. this.Invoke((EventHandler)(delegate
  1601. {
  1602. richTextBox_SensorParam.Clear();
  1603. for (int i = 0; i < myParams.SensorParam.Count; i++)
  1604. {
  1605. richTextBox_SensorParam.AppendText(myParams.SensorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1606. }
  1607. richTextBox_SensorParam.Text = richTextBox_SensorParam.Text.Substring(0, richTextBox_SensorParam.Text.Length - 2);
  1608. //更新生产模式页面传感器零点和标定值
  1609. textBox_FacModeSensorADC0.Text = (Data[9] * 256 + Data[8]).ToString();
  1610. textBox_FacModeSensorADC1.Text = (Data[15] * 256 + Data[14]).ToString();
  1611. textBox_FacModeSensorADC2.Text = (Data[19] * 256 + Data[18]).ToString();
  1612. textBox_FacModeSensorADC3.Text = (Data[23] * 256 + Data[22]).ToString();
  1613. textBox_FacModeSensorADC4.Text = (Data[27] * 256 + Data[26]).ToString();
  1614. WriteACK = true;
  1615. }));
  1616. }
  1617. break;
  1618. }
  1619. case 0xB64C://助力参数
  1620. {
  1621. unchecked
  1622. {
  1623. this.Invoke((EventHandler)(delegate
  1624. {
  1625. richTextBox_AssistParam.Clear();
  1626. int index_1 = myParams.AssistParam.IndexOf("转矩曲线.a");
  1627. int index_2 = myParams.AssistParam.IndexOf("踏频曲线.d");
  1628. int index_3 = myParams.AssistParam.IndexOf("踏频助力加速限制");
  1629. int index_4 = myParams.AssistParam.IndexOf("踏频助力电流步进");
  1630. for (int i = 0; i < myParams.AssistParam.Count; i++)
  1631. {
  1632. if (i < index_1) //数据占用2bytes
  1633. {
  1634. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1635. }
  1636. else if (i <= index_2) //数据占用4bytes
  1637. {
  1638. 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])) + ", ");
  1639. }
  1640. else if (i < index_3) //数据占用2bytes,无符号
  1641. {
  1642. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1643. }
  1644. else if (i <= index_4) //数据占用2bytes,有符号
  1645. {
  1646. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1647. }
  1648. else //数据占用2bytes,无符号
  1649. {
  1650. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1651. }
  1652. }
  1653. richTextBox_AssistParam.Text = richTextBox_AssistParam.Text.Substring(0, richTextBox_AssistParam.Text.Length - 2);
  1654. }));
  1655. }
  1656. break;
  1657. }
  1658. case 0xB74C://历史记录
  1659. {
  1660. unchecked
  1661. {
  1662. this.Invoke((EventHandler)(delegate
  1663. {
  1664. richTextBox_Record.Clear();
  1665. for (int i = 0; i < myParams.Record.Count; i++)
  1666. {
  1667. richTextBox_Record.AppendText(myParams.Record[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  1668. }
  1669. richTextBox_Record.Text = richTextBox_Record.Text.Substring(0, richTextBox_Record.Text.Length - 2);
  1670. }));
  1671. }
  1672. break;
  1673. }
  1674. case 0xB83A://调试参数
  1675. {
  1676. unchecked
  1677. {
  1678. this.Invoke((EventHandler)(delegate
  1679. {
  1680. richTextBox_DebugParam.Clear();
  1681. for (int i = 0; i < myParams.DebugParam.Count; i++)
  1682. {
  1683. richTextBox_DebugParam.AppendText(myParams.DebugParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1684. }
  1685. richTextBox_DebugParam.Text = richTextBox_DebugParam.Text.Substring(0, richTextBox_DebugParam.Text.Length - 2);
  1686. }));
  1687. }
  1688. break;
  1689. }
  1690. case 0xB904://存储标志
  1691. {
  1692. unchecked
  1693. {
  1694. this.Invoke((EventHandler)(delegate
  1695. {
  1696. ushort Flag = 0;
  1697. Flag = (ushort)(Data[1] * 256 + Data[0]);//EEPROM存储标志
  1698. if (Flag == 0)
  1699. {
  1700. radioButton_EE_SaveNo.Checked = true;
  1701. radioButton_EE_SaveYes.Checked = false;
  1702. }
  1703. else
  1704. {
  1705. radioButton_EE_SaveNo.Checked = false;
  1706. radioButton_EE_SaveYes.Checked = true;
  1707. }
  1708. Flag = (ushort)(Data[3] * 256 + Data[2]);//SIP偏移校准存储标志
  1709. if (Flag == 0)
  1710. {
  1711. radioButton_SIP_SaveNo.Checked = true;
  1712. radioButton_SIP_SaveYes.Checked = false;
  1713. }
  1714. else
  1715. {
  1716. radioButton_SIP_SaveNo.Checked = false;
  1717. radioButton_SIP_SaveYes.Checked = true;
  1718. }
  1719. }));
  1720. }
  1721. break;
  1722. }
  1723. case 0x1240://电机版本信息
  1724. {
  1725. unchecked
  1726. {
  1727. this.Invoke((EventHandler)(delegate
  1728. {
  1729. //电机型号
  1730. textBox_Model.Text = "";
  1731. textBox_OBC_ReadModel.Text = "";
  1732. textBox_FacModeName.Text = "";
  1733. for (ushort i = 0; i < 16; i++)
  1734. {
  1735. if (Data[i] == 0x2E)
  1736. {
  1737. break;
  1738. }
  1739. textBox_Model.Text += ((char)Data[i]).ToString();
  1740. textBox_OBC_ReadModel.Text += ((char)Data[i]).ToString();
  1741. textBox_FacModeName.Text += ((char)Data[i]).ToString();
  1742. }
  1743. Class_Motor_Ver.Mode = textBox_Model.Text;
  1744. //电机SN
  1745. textBox_SN.Text = "";
  1746. textBox_OBC_ReadSN.Text = "";
  1747. textBox_FacModeNum.Text = "";
  1748. for (ushort i = 0; i < 16; i++)
  1749. {
  1750. if (Data[16 + i] == 0x2E)
  1751. {
  1752. break;
  1753. }
  1754. textBox_SN.Text += ((char)Data[16 + i]).ToString();
  1755. textBox_OBC_ReadSN.Text += ((char)Data[16 + i]).ToString();
  1756. textBox_FacModeNum.Text += ((char)Data[16 + i]).ToString();
  1757. }
  1758. Class_Motor_Ver.SN = textBox_SN.Text;
  1759. //电机HW
  1760. textBox_HW.Text = "";
  1761. textBox_OBC_ReadHW.Text = "";
  1762. textBox_FacModeHW.Text = "";
  1763. for (ushort i = 0; i < 8; i++)//前8位:硬件板号
  1764. {
  1765. if (Data[32 + i] == 0x2E)
  1766. {
  1767. break;
  1768. }
  1769. else if (Data[32 + i] == 'r')
  1770. {
  1771. Data[32 + i] = (byte)'.';
  1772. break;
  1773. }
  1774. string strTemp = "";
  1775. strTemp = ((char)Data[32 + i]).ToString();
  1776. textBox_HW.Text += strTemp;
  1777. textBox_OBC_ReadHW.Text += strTemp;
  1778. textBox_FacModeHW.Text += strTemp;
  1779. }
  1780. for (ushort i = 0; i < 4; i++)//9-12位:单片机型号
  1781. {
  1782. if (Data[40 + i] == 0x2E)
  1783. {
  1784. break;
  1785. }
  1786. else if (Data[40 + i] == 'r')
  1787. {
  1788. Data[40 + i] = (byte)'.';
  1789. break;
  1790. }
  1791. string strTemp = "";
  1792. strTemp = ((char)Data[40 + i]).ToString();
  1793. textBox_HW.Text += strTemp;
  1794. textBox_OBC_ReadHW.Text += strTemp;
  1795. textBox_FacModeHW.Text += strTemp;
  1796. }
  1797. for (ushort i = 0; i < 4; i++)//13-16位:单片机ID
  1798. {
  1799. string strTemp = "";
  1800. strTemp = Convert.ToString(Data[44 + i], 16).PadLeft(2, '0').ToUpper();
  1801. textBox_HW.Text += strTemp;
  1802. textBox_OBC_ReadHW.Text += strTemp;
  1803. textBox_FacModeHW.Text += strTemp;
  1804. }
  1805. Class_Motor_Ver.HW = textBox_HW.Text;
  1806. //电机FW
  1807. textBox_FW.Text = "";
  1808. textBox_OBC_ReadFW.Text = "";
  1809. textBox_FacModeFW.Text = "";
  1810. for (ushort i = 0; i < 16; i++)
  1811. {
  1812. if ((Data[48 + i] == 0x2E) || (Data[48 + i] == 0x00) || (Data[48 + i] == (char)' '))
  1813. {
  1814. break;
  1815. }
  1816. if (Data[48 + i] == 'r')
  1817. {
  1818. Data[48 + i] = (byte)'.';
  1819. }
  1820. textBox_FW.Text += ((char)Data[48 + i]).ToString();
  1821. textBox_OBC_ReadFW.Text += ((char)Data[48 + i]).ToString();
  1822. textBox_FacModeFW.Text += ((char)Data[48 + i]).ToString();
  1823. }
  1824. Class_Motor_Ver.FW = textBox_FW.Text;
  1825. }));
  1826. }
  1827. break;
  1828. }
  1829. case 0xA610://自定义1
  1830. {
  1831. unchecked
  1832. {
  1833. this.Invoke((EventHandler)(delegate
  1834. {
  1835. textBox_User1.Text = "";
  1836. for (ushort i = 0; i < 16; i++)
  1837. {
  1838. if (Data[i] == 0x2E)
  1839. {
  1840. break;
  1841. }
  1842. textBox_User1.Text += ((char)Data[i]).ToString();
  1843. }
  1844. }));
  1845. }
  1846. break;
  1847. }
  1848. case 0xA710://自定义2
  1849. {
  1850. unchecked
  1851. {
  1852. this.Invoke((EventHandler)(delegate
  1853. {
  1854. textBox_User2.Text = "";
  1855. for (ushort i = 0; i < 16; i++)
  1856. {
  1857. if (Data[i] == 0x2E)
  1858. {
  1859. break;
  1860. }
  1861. textBox_User2.Text += ((char)Data[i]).ToString();
  1862. }
  1863. }));
  1864. }
  1865. break;
  1866. }
  1867. case 0xA810://自定义1
  1868. {
  1869. unchecked
  1870. {
  1871. this.Invoke((EventHandler)(delegate
  1872. {
  1873. textBox_User3.Text = "";
  1874. for (ushort i = 0; i < 16; i++)
  1875. {
  1876. if (Data[i] == 0x2E)
  1877. {
  1878. break;
  1879. }
  1880. textBox_User3.Text += ((char)Data[i]).ToString();
  1881. }
  1882. }));
  1883. }
  1884. break;
  1885. }
  1886. case 0xA520://生产信息
  1887. {
  1888. unchecked
  1889. {
  1890. this.Invoke((EventHandler)(delegate
  1891. {
  1892. //生产商
  1893. textBox_MAC.Text = "";
  1894. for (ushort i = 0; i < 8; i++)
  1895. {
  1896. if (Data[i] == 0x2E)
  1897. {
  1898. break;
  1899. }
  1900. textBox_MAC.Text += ((char)Data[i]).ToString();
  1901. }
  1902. //生产地
  1903. textBox_MACAdd.Text = "";
  1904. for (ushort i = 0; i < 8; i++)
  1905. {
  1906. if (Data[8 + i] == 0x2E)
  1907. {
  1908. break;
  1909. }
  1910. textBox_MACAdd.Text += ((char)Data[8 + i]).ToString();
  1911. }
  1912. //生产日期
  1913. textBox_MACDate.Text = "";
  1914. for (ushort i = 0; i < 8; i++)
  1915. {
  1916. if (Data[16 + i] == 0x2E)
  1917. {
  1918. break;
  1919. }
  1920. textBox_MACDate.Text += ((char)Data[16 + i]).ToString();
  1921. }
  1922. //品牌信息
  1923. textBox_PP.Text = "";
  1924. for (ushort i = 0; i < 8; i++)
  1925. {
  1926. if (Data[24 + i] == 0x2E)
  1927. {
  1928. break;
  1929. }
  1930. textBox_PP.Text += ((char)Data[24 + i]).ToString();
  1931. }
  1932. }));
  1933. }
  1934. break;
  1935. }
  1936. case 0xA408://密钥
  1937. {
  1938. unchecked
  1939. {
  1940. this.Invoke((EventHandler)(delegate
  1941. {
  1942. textBox_Key.Text = "";
  1943. for (ushort i = 0; i < 8; i++)
  1944. {
  1945. textBox_Key.Text += ((char)Data[i]).ToString();
  1946. }
  1947. }));
  1948. }
  1949. break;
  1950. }
  1951. case 0xAB09://存储器数据
  1952. case 0xAB0A:
  1953. case 0xAB0B:
  1954. case 0xAB0C:
  1955. {
  1956. unchecked
  1957. {
  1958. this.Invoke((EventHandler)(delegate
  1959. {
  1960. long ByteNum = 0;
  1961. ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
  1962. if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
  1963. {
  1964. for (int i = 0; i < ByteNum; i++)
  1965. {
  1966. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  1967. }
  1968. }
  1969. else //根据设置自动转换10进制显示
  1970. {
  1971. if (checkBox_ReadRanFlash_ChangeFormat.Checked == true) //10进制显示
  1972. {
  1973. switch (ByteNum)
  1974. {
  1975. case 1:
  1976. {
  1977. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8]) + ", ");
  1978. break;
  1979. }
  1980. case 2:
  1981. {
  1982. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8)) + ", ");
  1983. break;
  1984. }
  1985. case 3:
  1986. {
  1987. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16)) + ", ");
  1988. break;
  1989. }
  1990. case 4:
  1991. {
  1992. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24)) + ", ");
  1993. break;
  1994. }
  1995. default:
  1996. {
  1997. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  1998. break;
  1999. }
  2000. }
  2001. }
  2002. else //16进制显示
  2003. {
  2004. switch (ByteNum)
  2005. {
  2006. case 1:
  2007. {
  2008. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8], 16).PadLeft(2, '0').ToUpper() + ", ");
  2009. break;
  2010. }
  2011. case 2:
  2012. {
  2013. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8), 16).PadLeft(4, '0').ToUpper() + ", ");
  2014. break;
  2015. }
  2016. case 3:
  2017. {
  2018. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16), 16).PadLeft(6, '0').ToUpper() + ", ");
  2019. break;
  2020. }
  2021. case 4:
  2022. {
  2023. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24), 16).PadLeft(8, '0').ToUpper() + ", ");
  2024. break;
  2025. }
  2026. default:
  2027. {
  2028. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  2029. break;
  2030. }
  2031. }
  2032. }
  2033. }
  2034. }));
  2035. }
  2036. break;
  2037. }
  2038. case 0xAB88://故障日志
  2039. {
  2040. unchecked
  2041. {
  2042. this.Invoke((EventHandler)(delegate
  2043. {
  2044. //电机存储的故障日志,一包128字节包含2条故障日志
  2045. var ErrorLogSaveInfo1 = new MC_ErrorLogSaveInfo_Struct_t();
  2046. var ErrorLogSaveInfo2 = new MC_ErrorLogSaveInfo_Struct_t();
  2047. ErrorLogSaveInfo1 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 8);
  2048. ErrorLogSaveInfo2 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 72);
  2049. //数据显示
  2050. ErrorLogDisplay(ErrorLogSaveInfo1, ErrorLogSaveInfo2);
  2051. }));
  2052. }
  2053. break;
  2054. }
  2055. case 0x1401://在线检测结果
  2056. {
  2057. unchecked
  2058. {
  2059. this.Invoke((EventHandler)(delegate
  2060. {
  2061. textBox_Online.Text = Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() + "H";
  2062. }));
  2063. }
  2064. break;
  2065. }
  2066. case 0x1510://骑行历史信息
  2067. {
  2068. unchecked
  2069. {
  2070. this.Invoke((EventHandler)(delegate
  2071. {
  2072. long DataTemp32;
  2073. //ODO里程
  2074. DataTemp32 = (long)((Data[3] << 24) + (Data[2] << 16) + (Data[1] << 8) + Data[0]);
  2075. textBox_OBC_ODO_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  2076. textBox_ODO_KM.Text = DataTemp32.ToString();
  2077. //ODO时间
  2078. DataTemp32 = (long)((Data[7] << 24) + (Data[6] << 16) + (Data[5] << 8) + Data[4]);
  2079. if (DataTemp32 >= 60 * 100000)
  2080. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  2081. else
  2082. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  2083. textBox_ODO_TIME.Text = DataTemp32.ToString();
  2084. //TRIP里程
  2085. DataTemp32 = (long)((Data[11] << 24) + (Data[10] << 16) + (Data[9] << 8) + Data[8]);
  2086. textBox_OBC_TRIP_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  2087. textBox_TRIP_KM.Text = DataTemp32.ToString();
  2088. //TRIP时间
  2089. DataTemp32 = (long)((Data[15] << 24) + (Data[14] << 16) + (Data[13] << 8) + Data[12]);
  2090. if (DataTemp32 >= 60 * 100000)
  2091. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  2092. else
  2093. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  2094. textBox_TRIP_TIME.Text = DataTemp32.ToString();
  2095. }));
  2096. }
  2097. break;
  2098. }
  2099. case 0x1720://客户信息
  2100. {
  2101. unchecked
  2102. {
  2103. this.Invoke((EventHandler)(delegate
  2104. {
  2105. //软件标识
  2106. textBox_SP.Text = "";
  2107. textBox_OBC_ReadSP.Text = "";
  2108. textBox_FacModeSP.Text = "";
  2109. for (ushort i = 0; i < 23; i++)
  2110. {
  2111. if (Data[i] == 'r')
  2112. {
  2113. Data[i] = (byte)'.';
  2114. }
  2115. textBox_SP.Text += ((char)Data[i]).ToString();
  2116. textBox_OBC_ReadSP.Text += ((char)Data[i]).ToString();
  2117. textBox_FacModeSP.Text += ((char)Data[i]).ToString();
  2118. }
  2119. //Git提交版本信息
  2120. textBox_FacModeGit.Text = "";
  2121. for (ushort i = 0; i < 9; i++)
  2122. {
  2123. textBox_SP.Text += ((char)Data[23 + i]).ToString();
  2124. textBox_FacModeGit.Text += ((char)Data[23 + i]).ToString();
  2125. }
  2126. Class_Motor_Ver.Special = textBox_SP.Text;
  2127. }));
  2128. }
  2129. break;
  2130. }
  2131. case 0xBA20: //调试信息
  2132. {
  2133. unchecked
  2134. {
  2135. this.Invoke((EventHandler)(delegate
  2136. {
  2137. MC_DebugInfo_Refresh = true;
  2138. //系统状态机
  2139. DataTemp = (short)(Data[0]);
  2140. textBox_DebugInfo_SysFun.Text = Convert.ToString(DataTemp);
  2141. //二层状态机
  2142. DataTemp = (short)(Data[1]);
  2143. textBox_DebugInfo_SecondFun.Text = Convert.ToString(DataTemp);
  2144. //电机状态机
  2145. DataTemp = (short)(Data[2]);
  2146. textBox_DebugInfo_MotorFun.Text = Convert.ToString(DataTemp);
  2147. //助力状态机
  2148. DataTemp = (short)(Data[3]);
  2149. textBox_DebugInfo_AssistFun.Text = Convert.ToString(DataTemp);
  2150. //IdRef
  2151. DataTemp = (short)(Data[5] * 256 + Data[4]);
  2152. textBox_DebugInfo_IdRef.Text = Convert.ToString(DataTemp);
  2153. //IqRef
  2154. DataTemp = (short)(Data[7] * 256 + Data[6]);
  2155. textBox_DebugInfo_IqRef.Text = Convert.ToString(DataTemp);
  2156. //UdRef
  2157. DataTemp = (short)(Data[9] * 256 + Data[8]);
  2158. textBox_DebugInfo_UdRef.Text = Convert.ToString(DataTemp);
  2159. //UqRef
  2160. DataTemp = (short)(Data[11] * 256 + Data[10]);
  2161. textBox_DebugInfo_UqRef.Text = Convert.ToString(DataTemp);
  2162. //瞬时力矩
  2163. DataTemp = (short)(Data[13] * 256 + Data[12]);
  2164. textBox_DebugInfo_TorquePu.Text = Convert.ToString(DataTemp);
  2165. //时间滤波力矩
  2166. DataTemp = (short)(Data[15] * 256 + Data[14]);
  2167. textBox_DebugInfo_TorqueFil.Text = Convert.ToString(DataTemp);
  2168. //踏频滤波力矩
  2169. DataTemp = (short)(Data[17] * 256 + Data[16]);
  2170. textBox_DebugInfo_TorqueCadence.Text = Convert.ToString(DataTemp);
  2171. //IdFdb
  2172. DataTemp = (short)(Data[19] * 256 + Data[18]);
  2173. textBox_DebugInfo_IdFdb.Text = Convert.ToString(DataTemp);
  2174. //IqFdb
  2175. DataTemp = (short)(Data[21] * 256 + Data[20]);
  2176. textBox_DebugInfo_IqFdb.Text = Convert.ToString(DataTemp);
  2177. //助力输出
  2178. DataTemp = (short)(Data[23] * 256 + Data[22]);
  2179. textBox_DebugInfo_AssistOut.Text = Convert.ToString(DataTemp);
  2180. //转把百分比
  2181. DataTemp = (short)(Data[25] * 256 + Data[24]);
  2182. textBox_DebugInfo_ThrottlePer.Text = Convert.ToString(DataTemp);
  2183. //数据保存
  2184. RunInfoAutoSave();
  2185. }));
  2186. }
  2187. break;
  2188. }
  2189. case 0xBB20: //产品标签信息
  2190. {
  2191. unchecked
  2192. {
  2193. this.Invoke((EventHandler)(delegate
  2194. {
  2195. //产品标签
  2196. textBox_TagInfo.Text = "";
  2197. for (ushort i = 0; i < 32; i++)
  2198. {
  2199. textBox_TagInfo.Text += ((char)Data[i]).ToString();
  2200. }
  2201. }));
  2202. }
  2203. break;
  2204. }
  2205. case 0xBC20: //内阻校正信息
  2206. {
  2207. unchecked
  2208. {
  2209. this.Invoke((EventHandler)(delegate
  2210. {
  2211. //内阻1
  2212. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  2213. textBox_MOS_R1.Text = Convert.ToString(uData16);
  2214. //内阻2
  2215. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  2216. textBox_MOS_R2.Text = Convert.ToString(uData16);
  2217. //内阻3
  2218. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  2219. textBox_MOS_R3.Text = Convert.ToString(uData16);
  2220. //K1
  2221. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  2222. textBox_MOS_K1.Text = Convert.ToString(uData16);
  2223. //K2
  2224. uData16 = (ushort)(Data[9] * 256 + Data[8]);
  2225. textBox_MOS_K2.Text = Convert.ToString(uData16);
  2226. //K3
  2227. uData16 = (ushort)(Data[11] * 256 + Data[10]);
  2228. textBox_MOS_K3.Text = Convert.ToString(uData16);
  2229. //K4
  2230. uData16 = (ushort)(Data[13] * 256 + Data[12]);
  2231. textBox_MOS_K4.Text = Convert.ToString(uData16);
  2232. //K5
  2233. uData16 = (ushort)(Data[15] * 256 + Data[14]);
  2234. textBox_MOS_K5.Text = Convert.ToString(uData16);
  2235. }));
  2236. }
  2237. break;
  2238. }
  2239. case 0xBD20: //整车信息2
  2240. {
  2241. unchecked
  2242. {
  2243. this.Invoke((EventHandler)(delegate
  2244. {
  2245. richTextBox_BikeParam2.Clear();
  2246. for (int i = 0; i < myParams.BikeParam2.Count; i++)
  2247. {
  2248. richTextBox_BikeParam2.AppendText(myParams.BikeParam2[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  2249. }
  2250. richTextBox_BikeParam2.Text = richTextBox_BikeParam2.Text.Substring(0, richTextBox_BikeParam2.Text.Length - 2);
  2251. }));
  2252. }
  2253. break;
  2254. }
  2255. case 0xBE20: //用户骑行参数
  2256. {
  2257. unchecked
  2258. {
  2259. this.Invoke((EventHandler)(delegate
  2260. {
  2261. richTextBox_UsrRidesParam.Clear();
  2262. for (int i = 0; i < myParams.UsrRideParam.Count; i++)
  2263. {
  2264. richTextBox_UsrRidesParam.AppendText(myParams.UsrRideParam[i] + "=" + Convert.ToString(Data[i]) + ", ");
  2265. }
  2266. richTextBox_UsrRidesParam.Text = richTextBox_UsrRidesParam.Text.Substring(0, richTextBox_UsrRidesParam.Text.Length - 2);
  2267. }));
  2268. }
  2269. break;
  2270. }
  2271. case 0xBF58: //位置传感器校准值
  2272. {
  2273. unchecked
  2274. {
  2275. this.Invoke((EventHandler)(delegate
  2276. {
  2277. string[] str1 = new string[42];
  2278. double[] error1 = new double[42];
  2279. //更新校准数据
  2280. for (int i = 0; i < 42; i++)
  2281. {
  2282. double data1 = (Data[4 + i * 2] + (Data[4 + i * 2 + 1] << 8)) / 32767.0 * 360;
  2283. error1[i] = data1 - (60 * (i % 6) + 60);
  2284. if (error1[i] < -180)
  2285. {
  2286. error1[i] = error1[i] + 360;
  2287. }
  2288. str1[i] = data1.ToString("F2");
  2289. AngledataRecord[i] = str1[i];
  2290. }
  2291. for (int i = 0; i < 7; i++)
  2292. for (int j = 0; j < 6; j++)
  2293. {
  2294. dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = str1[6 * i + j];
  2295. }
  2296. //计算偏差最小值、最大值和平均值
  2297. //Array.ConvertAll(error1, Math.Abs);
  2298. textBox_AngleDiffMin.Text = error1.Min().ToString("F2");
  2299. textBox_AngleDiffMax.Text = error1.Max().ToString("F2");
  2300. textBox_AngleDiffAvg.Text = error1.Average().ToString("F2");
  2301. //计算零点偏差
  2302. double tmp1 = ((Int16)(Data[0] + (Data[1] << 8))) / 32767.0 * 360;
  2303. textBox_AngleZeroInit.Text = tmp1.ToString("F2");
  2304. double tmp2 = ((Int16)(Data[2] + (Data[3] << 8))) / 32767.0 * 360;
  2305. textBox_AngleZeroCur.Text = tmp2.ToString("F2");
  2306. double tmp3 = (tmp2 - tmp1);
  2307. textBox_AngleZeroDiff.Text = tmp3.ToString("F2");
  2308. }));
  2309. }
  2310. break;
  2311. }
  2312. case 0xC008: //故障日志地址
  2313. {
  2314. unchecked
  2315. {
  2316. this.Invoke((EventHandler)(delegate
  2317. {
  2318. uint Addr_Begin = 0, Addr_End = 0;
  2319. Addr_Begin = (uint)((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]);
  2320. Addr_End = (uint)((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]);
  2321. textBox_LogAddrBegin.Text = Convert.ToString(Addr_Begin, 16).PadLeft(8, '0').ToUpper();
  2322. textBox_LogAddrEnd.Text = Convert.ToString(Addr_End, 16).PadLeft(8, '0').ToUpper();
  2323. }));
  2324. }
  2325. break;
  2326. }
  2327. case 0xC109: //Boot版本信息
  2328. {
  2329. BootInfo = "";
  2330. for (ushort i = 0; i < 9; i++)
  2331. {
  2332. BootInfo += ((char)Data[i]).ToString();
  2333. }
  2334. break;
  2335. }
  2336. case 0xC142: //功能配置表
  2337. {
  2338. unchecked
  2339. {
  2340. this.Invoke((EventHandler)(delegate
  2341. {
  2342. //块编号
  2343. ushort Num = (ushort)(Data[1] * 256 + Data[0]);
  2344. comboBox_FunSet_BlockNum.SelectedIndex = Num - 1;
  2345. //显示数据
  2346. for (int i = 0; i < 64; i++)
  2347. {
  2348. dataGridView_FunSet.Rows[i / 8].Cells[i % 8 + 1].Value = Data[i + 2].ToString();
  2349. }
  2350. }));
  2351. }
  2352. break;
  2353. }
  2354. case 0xC220: //定制编号
  2355. {
  2356. unchecked
  2357. {
  2358. this.Invoke((EventHandler)(delegate
  2359. {
  2360. //定制编号
  2361. textBox_UserNum.Text = "";
  2362. for (ushort i = 0; i < 32; i++)
  2363. {
  2364. textBox_UserNum.Text += ((char)Data[i]).ToString();
  2365. }
  2366. }));
  2367. }
  2368. break;
  2369. }
  2370. default:
  2371. {
  2372. break;
  2373. }
  2374. }
  2375. //存储器导出数据显示
  2376. if ((CmdTemp & 0xFF00) == 0xAB00)
  2377. {
  2378. unchecked
  2379. {
  2380. this.Invoke((EventHandler)(delegate
  2381. {
  2382. long ByteNum = 0;
  2383. ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
  2384. if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
  2385. {
  2386. for (int i = 0; i < ByteNum; i++)
  2387. {
  2388. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  2389. }
  2390. }
  2391. }));
  2392. }
  2393. }
  2394. }
  2395. #endregion
  2396. #region 解析BMS广播的命令
  2397. else if (ID == 0x720)
  2398. {
  2399. switch (CmdTemp)
  2400. {
  2401. case 0x1010://BMS运行信息
  2402. {
  2403. unchecked
  2404. {
  2405. this.Invoke((EventHandler)(delegate
  2406. {
  2407. BMS_RunInfo_Refresh = true;
  2408. richTextBox_OBC_BMS_RunInfo.Clear();
  2409. //电压
  2410. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  2411. richTextBox_OBC_BMS_RunInfo.AppendText("电压:" + Convert.ToString(uData16) + " mV" + "\r\n");
  2412. //电流
  2413. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  2414. richTextBox_OBC_BMS_RunInfo.AppendText("电流:" + Convert.ToString(uData16) + " mA" + "\r\n");
  2415. //剩余容量
  2416. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  2417. richTextBox_OBC_BMS_RunInfo.AppendText("剩余容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  2418. //满充容量
  2419. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  2420. richTextBox_OBC_BMS_RunInfo.AppendText("满充容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  2421. //电芯温度
  2422. richTextBox_OBC_BMS_RunInfo.AppendText("电芯温度:" + Convert.ToString((int)(Data[8] - 40) + " ℃" + "\r\n"));
  2423. //剩余电量
  2424. richTextBox_OBC_BMS_RunInfo.AppendText("剩余电量:" + Convert.ToString(Data[9]) + " %" + "\r\n");
  2425. //电池状态
  2426. richTextBox_OBC_BMS_RunInfo.AppendText("电池状态:" + Convert.ToString(Data[10], 16).PadLeft(2, '0').ToUpper() + " H" + "\r\n");
  2427. //SOH
  2428. richTextBox_OBC_BMS_RunInfo.AppendText("电池寿命:" + Convert.ToString(Data[11]) + " %" + "\r\n");
  2429. //循环次数
  2430. richTextBox_OBC_BMS_RunInfo.AppendText("循环次数:" + Convert.ToString((ushort)(Data[13] * 256 + Data[12])) + " 次");
  2431. }));
  2432. }
  2433. break;
  2434. }
  2435. default: break;
  2436. }
  2437. }
  2438. #endregion
  2439. #region 解析电机发送OBC的命令
  2440. else if (ID == 0x713)
  2441. {
  2442. switch (CmdTemp)
  2443. {
  2444. case 0x5408://电机用户参数
  2445. {
  2446. unchecked
  2447. {
  2448. this.Invoke((EventHandler)(delegate
  2449. {
  2450. richTextBox_OBC_ReadUserInfo.Clear();
  2451. //默认周长
  2452. richTextBox_OBC_ReadUserInfo.AppendText("默认周长:" + Convert.ToString((int)Data[0]) + " cm" + "\r\n");
  2453. //启动模式
  2454. richTextBox_OBC_ReadUserInfo.AppendText("启动模式:" + ((Data[1] == 0x01) ? "柔和" : (Data[1] == 0x02) ? "正常" : (Data[1] == 0x03) ? "强劲" : "无效") + "\r\n");
  2455. comboBox_OBC_StartMode.SelectedIndex = Data[1] - 1;
  2456. //限速
  2457. richTextBox_OBC_ReadUserInfo.AppendText("限速:" + Convert.ToString(Data[2]) + " km/h" + "\r\n");
  2458. //周长微调
  2459. numericUpDown_OBC_WheelAdj.Value = (int)(Data[3] > 128 ? (Data[3] - 256) : Data[3]);
  2460. richTextBox_OBC_ReadUserInfo.AppendText("周长微调:" + Convert.ToString(numericUpDown_OBC_WheelAdj.Value) + " cm" + "\r\n");
  2461. //助力方案
  2462. richTextBox_OBC_ReadUserInfo.AppendText("助力方案:" + Convert.ToString(Data[4]) + "\r\n");
  2463. comboBox_OBC_AssistFunc.SelectedIndex = Data[4] - 1;
  2464. //关机时间
  2465. richTextBox_OBC_ReadUserInfo.AppendText("关机时间:" + Convert.ToString(Data[5]) + " min" + "\r\n");
  2466. numericUpDown_OBC_OffTime.Value = (int)Data[5];
  2467. //限速微调
  2468. numericUpDown_OBC_SpeedLimitAdj.Value = (int)(Data[6] > 128 ? (Data[6] - 256) : Data[6]);
  2469. richTextBox_OBC_ReadUserInfo.AppendText("限速微调:" + Convert.ToString(numericUpDown_OBC_SpeedLimitAdj.Value) + " km/h" + "\r\n");
  2470. //定速巡航
  2471. comboBox_OBC_BikeCCS.SelectedIndex = (Data[7] == 0xAA) ? 1 : 2;
  2472. richTextBox_OBC_ReadUserInfo.AppendText("转把巡航:" + comboBox_OBC_BikeCCS.Text + "\r\n");
  2473. }));
  2474. }
  2475. break;
  2476. }
  2477. case 0x5303://电机应答反馈
  2478. {
  2479. unchecked
  2480. {
  2481. this.Invoke((EventHandler)(delegate
  2482. {
  2483. MessageBoxTimeOut.Show("OK", "反馈指令", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  2484. }));
  2485. }
  2486. break;
  2487. }
  2488. case 0x5620: //用户骑行参数
  2489. {
  2490. unchecked
  2491. {
  2492. this.Invoke((EventHandler)(delegate
  2493. {
  2494. richTextBox_UsrRidesParam.Clear();
  2495. for (int i = 0; i < myParams.UsrRideParam.Count; i++)
  2496. {
  2497. richTextBox_UsrRidesParam.AppendText(myParams.UsrRideParam[i] + "=" + Convert.ToString(Data[i]) + ", ");
  2498. }
  2499. richTextBox_UsrRidesParam.Text = richTextBox_UsrRidesParam.Text.Substring(0, richTextBox_UsrRidesParam.Text.Length - 2);
  2500. }));
  2501. }
  2502. break;
  2503. }
  2504. default: break;
  2505. }
  2506. }
  2507. #endregion
  2508. }
  2509. private void DataRevToString(ushort CmdTemp, byte[] Data)
  2510. {
  2511. CmdRevStrTemp = "";
  2512. CmdRevStrTemp += Convert.ToString(CmdTemp >> 8, 16).PadLeft(2, '0').ToUpper() + " ";
  2513. CmdRevStrTemp += Convert.ToString(CmdTemp & 0xFF, 16).PadLeft(2, '0').ToUpper() + " ";
  2514. ushort len = (ushort)(CmdTemp & 0x00FF);
  2515. for (int i = 0; i < len ; i++)
  2516. {
  2517. CmdRevStrTemp += Convert.ToString(Data[i], 16).PadLeft(2, '0').ToUpper() + " ";
  2518. }
  2519. }
  2520. #endregion
  2521. /// <summary>
  2522. /// 端口连接或断开
  2523. /// </summary>
  2524. private void PortConnect()
  2525. {
  2526. bool result = false;
  2527. if (连接ToolStripMenuItem.Text == "连接")
  2528. {
  2529. result = mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, 连接开机ToolStripMenuItem.Checked, 识别通讯盒ToolStripMenuItem.Checked);
  2530. if (result)
  2531. {
  2532. toolStripComboBox_ComNum.Enabled = false;
  2533. toolStripComboBox_Baudrate.Enabled = false;
  2534. 刷新ToolStripMenuItem.Enabled = false;
  2535. 连接ToolStripMenuItem.Text = "断开";
  2536. 连接ToolStripMenuItem.Checked = true;
  2537. label_COM_Sta.Text = toolStripComboBox_ComNum.Text + "已连接," + toolStripComboBox_Baudrate.Text;
  2538. label_PortStatus.BackColor = Color.Green;
  2539. }
  2540. }
  2541. else if (连接ToolStripMenuItem.Text == "断开")
  2542. {
  2543. checkBox_OBC_StartSetGearSt.Checked = false;
  2544. checkBox_OBC_StartReadBMS.Checked = false;
  2545. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2546. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  2547. toolStripComboBox_ComNum.Enabled = true;
  2548. toolStripComboBox_Baudrate.Enabled = true;
  2549. 刷新ToolStripMenuItem.Enabled = true;
  2550. 连接ToolStripMenuItem.Text = "连接";
  2551. 连接ToolStripMenuItem.Checked = false;
  2552. label_COM_Sta.Text = "连接状态:未连接";
  2553. label_PortStatus.BackColor = Color.Red;
  2554. }
  2555. }
  2556. /// <summary>
  2557. /// 端口连接事件
  2558. /// </summary>
  2559. /// <param name="sender"></param>
  2560. /// <param name="e"></param>
  2561. private void 连接ToolStripMenuItem_Click(object sender, System.EventArgs e)
  2562. {
  2563. PortConnect();
  2564. }
  2565. /// <summary>
  2566. /// 端口号刷新事件
  2567. /// </summary>
  2568. /// <param name="sender"></param>
  2569. /// <param name="e"></param>
  2570. private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
  2571. {
  2572. toolStripComboBox_ComNum.Items.Clear();
  2573. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  2574. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
  2575. }
  2576. /// <summary>
  2577. /// 存储标志修改事件
  2578. /// </summary>
  2579. /// <param name="sender"></param>
  2580. /// <param name="e"></param>
  2581. private void 写入存储ToolStripMenuItem_Click(object sender, EventArgs e)
  2582. {
  2583. if (写入存储ToolStripMenuItem.Checked)
  2584. {
  2585. EnterForm1.ShowDialog();
  2586. try
  2587. {
  2588. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  2589. {
  2590. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  2591. {
  2592. 写入存储ToolStripMenuItem.Checked = false;
  2593. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  2594. }
  2595. else
  2596. {
  2597. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2598. }
  2599. }
  2600. else
  2601. {
  2602. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2603. }
  2604. }
  2605. catch (Exception)
  2606. {
  2607. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2608. }
  2609. }
  2610. else
  2611. {
  2612. 写入存储ToolStripMenuItem.Checked = true;
  2613. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  2614. }
  2615. }
  2616. /// <summary>
  2617. /// 1s定时器
  2618. /// </summary>
  2619. /// <param name="sender"></param>
  2620. /// <param name="e"></param>
  2621. private void timer_1s_Tick(object sender, EventArgs e)
  2622. {
  2623. //时间更新
  2624. label_SystemTime.Text = "系统时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2625. //MC_Runinfo超时清除
  2626. if (MC_RunInfo_Refresh == false)
  2627. {
  2628. MC_RunInfo_Refresh_Cnt++;
  2629. if (MC_RunInfo_Refresh_Cnt > 10)//5s
  2630. {
  2631. MC_RunInfo_Clear();
  2632. MC_RunInfo_Refresh_Cnt = 0;
  2633. }
  2634. }
  2635. else
  2636. {
  2637. MC_RunInfo_Refresh_Cnt = 0;
  2638. }
  2639. MC_RunInfo_Refresh = false;
  2640. //MC_Debuginfo超时清除
  2641. if (MC_DebugInfo_Refresh == false)
  2642. {
  2643. MC_DebugInfo_Refresh_Cnt++;
  2644. if (MC_DebugInfo_Refresh_Cnt > 10)//5s
  2645. {
  2646. MC_DebugInfo_Clear();
  2647. MC_DebugInfo_Refresh_Cnt = 0;
  2648. }
  2649. }
  2650. else
  2651. {
  2652. MC_DebugInfo_Refresh_Cnt = 0;
  2653. }
  2654. MC_DebugInfo_Refresh = false;
  2655. //BMS_RunInfo超时清除
  2656. if (BMS_RunInfo_Refresh == false)
  2657. {
  2658. BMS_RunInfo_Refresh_Cnt++;
  2659. if (BMS_RunInfo_Refresh_Cnt > 10)//5s
  2660. {
  2661. richTextBox_OBC_BMS_RunInfo.Clear();
  2662. BMS_RunInfo_Refresh_Cnt = 0;
  2663. }
  2664. }
  2665. else
  2666. {
  2667. BMS_RunInfo_Refresh_Cnt = 0;
  2668. }
  2669. BMS_RunInfo_Refresh = false;
  2670. //故障码超时清除
  2671. if (MC_ErrorCode_Refresh == false)
  2672. {
  2673. MC_ErrorCode_Refresh_Cnt++;
  2674. if (MC_ErrorCode_Refresh_Cnt > 10)//5s
  2675. {
  2676. textBox_ErrorCode.Text = "---";
  2677. MC_ErrorCode_Refresh_Cnt = 0;
  2678. }
  2679. }
  2680. else
  2681. {
  2682. MC_ErrorCode_Refresh_Cnt = 0;
  2683. }
  2684. MC_ErrorCode_Refresh = false;
  2685. //CDL连接超时
  2686. if (识别通讯盒ToolStripMenuItem.Checked)
  2687. {
  2688. if (mySerialProcess.CDL_Online_Flag == false)
  2689. {
  2690. mySerialProcess.CDL_OnlineCheck_Cnt++;
  2691. if (mySerialProcess.CDL_OnlineCheck_Cnt > 1)//1s
  2692. {
  2693. timer_500ms.Enabled = false;
  2694. MessageBox.Show("连接失败!", "提示");
  2695. timer_500ms.Enabled = true;
  2696. //关闭串口
  2697. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  2698. toolStripComboBox_ComNum.Enabled = true;
  2699. toolStripComboBox_Baudrate.Enabled = true;
  2700. 刷新ToolStripMenuItem.Enabled = true;
  2701. 连接ToolStripMenuItem.Text = "连接";
  2702. 连接ToolStripMenuItem.Checked = false;
  2703. label_COM_Sta.Text = "连接状态:未连接";
  2704. label_PortStatus.BackColor = Color.Red;
  2705. }
  2706. }
  2707. }
  2708. //OBC定时发送设置档位
  2709. if (checkBox_OBC_StartSetGearSt.Checked == true)
  2710. {
  2711. var CtrlCode = new byte[2];
  2712. if (comboBox_OBC_SetGearST.SelectedIndex == 5)//档位
  2713. CtrlCode[0] = 0x33;
  2714. else if (comboBox_OBC_SetGearST.SelectedIndex == 6)//档位
  2715. CtrlCode[0] = 0x22;
  2716. else
  2717. CtrlCode[0] = (byte)comboBox_OBC_SetGearST.SelectedIndex;
  2718. if (comboBox_OBC_LightSw.SelectedIndex == 0)//车灯
  2719. CtrlCode[1] = 0xF1;
  2720. else
  2721. CtrlCode[1] = 0xF0;
  2722. if (!mySerialProcess.SendCmdWithoutNotice((ushort)0x731, (byte)0x0C, (ushort)0x3002, CtrlCode))
  2723. {
  2724. checkBox_OBC_StartSetGearSt.Checked = false;
  2725. }
  2726. }
  2727. //OBC定时发送查询电池
  2728. if (checkBox_OBC_StartReadBMS.Checked == true)
  2729. {
  2730. if (!mySerialProcess.SendCmd((ushort)0x732, (byte)0x11, (ushort)0x5000, null))
  2731. {
  2732. checkBox_OBC_StartReadBMS.Checked = false;
  2733. }
  2734. }
  2735. //定时读取存储器
  2736. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  2737. {
  2738. var Address = new byte[4];
  2739. UInt32 Address_Begin;
  2740. UInt32 Addres_End;
  2741. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  2742. richTextBox_RamFlasgData.Clear();
  2743. do
  2744. {
  2745. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  2746. {
  2747. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2748. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2749. continue;
  2750. }
  2751. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  2752. {
  2753. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2754. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2755. continue;
  2756. }
  2757. else
  2758. {
  2759. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  2760. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2761. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  2762. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2763. if (Addres_End < Address_Begin)
  2764. {
  2765. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2766. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2767. continue;
  2768. }
  2769. else
  2770. {
  2771. var SendByte = new byte[8];
  2772. SendByte[0] = (byte)(Address_Begin >> 24);
  2773. SendByte[1] = (byte)(Address_Begin >> 16);
  2774. SendByte[2] = (byte)(Address_Begin >> 8);
  2775. SendByte[3] = (byte)(Address_Begin);
  2776. SendByte[4] = (byte)(Addres_End >> 24);
  2777. SendByte[5] = (byte)(Addres_End >> 16);
  2778. SendByte[6] = (byte)(Addres_End >> 8);
  2779. SendByte[7] = (byte)(Addres_End);
  2780. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte))
  2781. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2782. }
  2783. }
  2784. } while (false);
  2785. }
  2786. //写入参数等待计时
  2787. ACK_WaitCnt++;
  2788. }
  2789. /// <summary>
  2790. /// 运行信息清除
  2791. /// </summary>
  2792. private void MC_RunInfo_Clear()
  2793. {
  2794. foreach (Control c in tabPage_RunInfo.Controls)
  2795. {
  2796. if ((c is TextBox))
  2797. {
  2798. if (c.Name != textBox_ErrorCode.ToString())
  2799. c.Text = "---";
  2800. }
  2801. }
  2802. }
  2803. /// <summary>
  2804. /// 调试信息清除
  2805. /// </summary>
  2806. private void MC_DebugInfo_Clear()
  2807. {
  2808. foreach (Control c in tabPage_DebugInfo.Controls)
  2809. {
  2810. if ((c is TextBox))
  2811. {
  2812. if (c.Name != textBox_ErrorCode.ToString())
  2813. c.Text = "---";
  2814. }
  2815. }
  2816. }
  2817. /// <summary>
  2818. /// 读取马达参数
  2819. /// </summary>
  2820. /// <param name="sender"></param>
  2821. /// <param name="e"></param>
  2822. private void button_Read_MotorParam_Click(object sender, EventArgs e)
  2823. {
  2824. richTextBox_MotorParam.Clear();
  2825. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null);
  2826. }
  2827. /// <summary>
  2828. /// 写入马达参数
  2829. /// </summary>
  2830. /// <param name="sender"></param>
  2831. /// <param name="e"></param>
  2832. private void button_Write_Click(object sender, EventArgs e)
  2833. {
  2834. var ConfigParam = new byte[40];
  2835. for (int i = 0; i < 40; i++)
  2836. ConfigParam[i] = 0;
  2837. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2838. short wDataTemp = 0;
  2839. ushort DataTemp = 0;
  2840. string[] strDataTemp = richTextBox_MotorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2841. try
  2842. {
  2843. for (int i = 0; i < strDataTemp.Length; i++)
  2844. {
  2845. if (i == 6)
  2846. {
  2847. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  2848. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  2849. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  2850. }
  2851. else
  2852. {
  2853. DataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2854. ConfigParam[2 * i + 2] = (byte)DataTemp;
  2855. ConfigParam[2 * i + 3] = (byte)(DataTemp >> 8);
  2856. }
  2857. }
  2858. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B28, ConfigParam);
  2859. }
  2860. catch (Exception)
  2861. {
  2862. timer_500ms.Enabled = false;
  2863. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2864. timer_500ms.Enabled = true;
  2865. }
  2866. }
  2867. /// <summary>
  2868. /// 读取整车信息
  2869. /// </summary>
  2870. /// <param name="sender"></param>
  2871. /// <param name="e"></param>
  2872. private void button_ReadBikeParam_Click(object sender, EventArgs e)
  2873. {
  2874. richTextBox_BikeParam.Clear();
  2875. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null);
  2876. }
  2877. /// <summary>
  2878. /// 写入整车信息
  2879. /// </summary>
  2880. /// <param name="sender"></param>
  2881. /// <param name="e"></param>
  2882. private void button_WriteBikeParam_Click(object sender, EventArgs e)
  2883. {
  2884. var ConfigParam = new byte[28];
  2885. for (int i = 0; i < 28; i++)
  2886. ConfigParam[i] = 0;
  2887. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2888. string[] strDataTemp = richTextBox_BikeParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2889. try
  2890. {
  2891. for (int i = 0; i < strDataTemp.Length; i++)
  2892. {
  2893. short wDataTemp = 0;
  2894. //前后灯参数修改
  2895. if (i == 8)
  2896. {
  2897. wDataTemp |= (short)((comboBox_TailLightMode.SelectedIndex + 1) << 12); //Bit15~Bit12:尾灯模式
  2898. wDataTemp |= (short)((comboBox_TailLightVol.SelectedIndex == 0 ? 6 : 12) << 8); //Bit11~Bit8:尾灯电压
  2899. wDataTemp |= (short)(comboBox_FrontLightVol.SelectedIndex == 0 ? 6 : 12); //Bit7~Bit0:前灯电压
  2900. }
  2901. //开关机参数
  2902. else if (i == 11)
  2903. {
  2904. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOnDelay.Text) << 12);
  2905. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOffDelay.Text) << 8);
  2906. wDataTemp |= (short)(Convert.ToInt16(textBox_AutoPowerOff.Text));
  2907. }
  2908. else
  2909. {
  2910. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  2911. }
  2912. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  2913. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  2914. }
  2915. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D1C, ConfigParam);
  2916. }
  2917. catch (Exception)
  2918. {
  2919. timer_500ms.Enabled = false;
  2920. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2921. timer_500ms.Enabled = true;
  2922. }
  2923. }
  2924. /// <summary>
  2925. /// 读取控制器参数
  2926. /// </summary>
  2927. /// <param name="sender"></param>
  2928. /// <param name="e"></param>
  2929. private void button_ReadControlParam_Click(object sender, EventArgs e)
  2930. {
  2931. richTextBox_ControlParam.Clear();
  2932. comboBox_Bike_CCS.SelectedIndex = 0;
  2933. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
  2934. }
  2935. /// <summary>
  2936. /// 写入控制器参数
  2937. /// </summary>
  2938. /// <param name="sender"></param>
  2939. /// <param name="e"></param>
  2940. private void button_WriteControlParam_Click(object sender, EventArgs e)
  2941. {
  2942. var ConfigParam = new byte[34];
  2943. for (int i = 0; i < 34; i++)
  2944. ConfigParam[i] = 0;
  2945. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2946. ushort uwDataTemp = 0;
  2947. string[] strDataTemp = richTextBox_ControlParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2948. try
  2949. {
  2950. for (int i = 0; i < strDataTemp.Length; i++)
  2951. {
  2952. if (i == 13)
  2953. {
  2954. uwDataTemp = (comboBox_Bike_CCS.SelectedIndex == 1) ? (ushort)0x00AA : (ushort)0x0000;
  2955. }
  2956. else
  2957. {
  2958. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2959. }
  2960. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2961. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2962. }
  2963. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3F22, ConfigParam);
  2964. }
  2965. catch (Exception)
  2966. {
  2967. timer_500ms.Enabled = false;
  2968. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2969. timer_500ms.Enabled = true;
  2970. }
  2971. }
  2972. /// <summary>
  2973. /// 读取助力参数
  2974. /// </summary>
  2975. /// <param name="sender"></param>
  2976. /// <param name="e"></param>
  2977. private void button_ReadAssistParam_Click(object sender, EventArgs e)
  2978. {
  2979. var ConfigParam = new byte[4];
  2980. int AssistNum = 0;
  2981. try
  2982. {
  2983. AssistNum = Convert.ToInt32(comboBox_AssistTorque.Text);
  2984. ConfigParam[0] = (byte)(AssistNum & 0xFF);
  2985. ConfigParam[1] = (byte)(AssistNum >> 8);
  2986. AssistNum = Convert.ToInt32(comboBox_AssistCadence.Text);
  2987. ConfigParam[2] = (byte)(AssistNum & 0xFF);
  2988. ConfigParam[3] = (byte)(AssistNum >> 8);
  2989. richTextBox_AssistParam.Clear();
  2990. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam);
  2991. }
  2992. catch (Exception)
  2993. {
  2994. timer_500ms.Enabled = false;
  2995. MessageBox.Show("请选择助力参数编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2996. timer_500ms.Enabled = true;
  2997. }
  2998. }
  2999. /// <summary>
  3000. /// 写入助力参数
  3001. /// </summary>
  3002. /// <param name="sender"></param>
  3003. /// <param name="e"></param>
  3004. private void button_WriteAssistParam_Click(object sender, EventArgs e)
  3005. {
  3006. var ConfigParam = new byte[80];
  3007. for (int i = 0; i < 80; i++)
  3008. ConfigParam[i] = 0;
  3009. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  3010. long lDataTemp = 0;
  3011. string[] strDataTemp = richTextBox_AssistParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  3012. int index_1 = 0, index_2 = 0;
  3013. try
  3014. {
  3015. for (int i = 0; i < strDataTemp.Length; i++)
  3016. {
  3017. if (strDataTemp[i].Split('=')[0] == "转矩曲线.a")
  3018. {
  3019. index_1 = i;
  3020. break;
  3021. }
  3022. }
  3023. for (int i = 0; i < strDataTemp.Length; i++)
  3024. {
  3025. if (strDataTemp[i].Split('=')[0] == "踏频曲线.d")
  3026. {
  3027. index_2 = i;
  3028. break;
  3029. }
  3030. }
  3031. for (int i = 0; i < strDataTemp.Length; i++)
  3032. {
  3033. lDataTemp = Convert.ToInt32(strDataTemp[i].Split('=')[1]);
  3034. if (i < index_1)
  3035. {
  3036. ConfigParam[2 * i + 4] = (byte)lDataTemp;
  3037. ConfigParam[2 * i + 5] = (byte)(lDataTemp >> 8);
  3038. }
  3039. else if (i <= index_2)
  3040. {
  3041. ConfigParam[4 * i - 4] = (byte)lDataTemp;
  3042. ConfigParam[4 * i - 3] = (byte)(lDataTemp >> 8);
  3043. ConfigParam[4 * i - 2] = (byte)(lDataTemp >> 16);
  3044. ConfigParam[4 * i - 1] = (byte)(lDataTemp >> 24);
  3045. }
  3046. else
  3047. {
  3048. ConfigParam[2 * i + 20] = (byte)lDataTemp;
  3049. ConfigParam[2 * i + 21] = (byte)(lDataTemp >> 8);
  3050. }
  3051. }
  3052. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4450, ConfigParam);
  3053. }
  3054. catch (Exception)
  3055. {
  3056. timer_500ms.Enabled = false;
  3057. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3058. timer_500ms.Enabled = true;
  3059. }
  3060. }
  3061. /// <summary>
  3062. /// 读取调试参数
  3063. /// </summary>
  3064. /// <param name="sender"></param>
  3065. /// <param name="e"></param>
  3066. private void button_ReadDebugParam_Click(object sender, EventArgs e)
  3067. {
  3068. richTextBox_DebugParam.Clear();
  3069. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  3070. }
  3071. /// <summary>
  3072. /// 写入调试参数
  3073. /// </summary>
  3074. /// <param name="sender"></param>
  3075. /// <param name="e"></param>
  3076. private void button_WriteDebugParam_Click(object sender, EventArgs e)
  3077. {
  3078. var ConfigParam = new byte[60];
  3079. for (int i = 0; i < 60; i++)
  3080. ConfigParam[i] = 0;
  3081. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  3082. ushort uwDataTemp = 0;
  3083. string[] strDataTemp = richTextBox_DebugParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  3084. try
  3085. {
  3086. for (int i = 0; i < strDataTemp.Length; i++)
  3087. {
  3088. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  3089. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3090. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3091. }
  3092. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam);
  3093. }
  3094. catch (Exception)
  3095. {
  3096. timer_500ms.Enabled = false;
  3097. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3098. timer_500ms.Enabled = true;
  3099. }
  3100. }
  3101. /// <summary>
  3102. /// 读取历史
  3103. /// </summary>
  3104. /// <param name="sender"></param>
  3105. /// <param name="e"></param>
  3106. private void button_ReadRecord_Click(object sender, EventArgs e)
  3107. {
  3108. richTextBox_Record.Clear();
  3109. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null);
  3110. }
  3111. /// <summary>
  3112. /// 读取传感器参数
  3113. /// </summary>
  3114. /// <param name="sender"></param>
  3115. /// <param name="e"></param>
  3116. private void button_ReadSensorParam_Click(object sender, EventArgs e)
  3117. {
  3118. richTextBox_SensorParam.Clear();
  3119. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3120. }
  3121. /// <summary>
  3122. /// 写入力矩传感器标定值
  3123. /// </summary>
  3124. /// <param name="sender"></param>
  3125. /// <param name="e"></param>
  3126. private void button_Write_Cal_Click(object sender, EventArgs e)
  3127. {
  3128. var ConfigParam = new byte[4];
  3129. for (int i = 0; i < 4; i++)
  3130. ConfigParam[i] = 0;
  3131. ushort uwDataTemp = 0;
  3132. try
  3133. {
  3134. uwDataTemp = Convert.ToUInt16(comboBox_TorqueSet.Text);//负载序号
  3135. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  3136. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  3137. uwDataTemp = (ushort)(decimal.Parse(textBox_Load.Text) * 10); ;//负载值0.1Nm
  3138. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  3139. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  3140. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  3141. }
  3142. catch (Exception)
  3143. {
  3144. timer_500ms.Enabled = false;
  3145. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3146. timer_500ms.Enabled = true;
  3147. }
  3148. }
  3149. /// <summary>
  3150. /// 写入传感器参数
  3151. /// </summary>
  3152. /// <param name="sender"></param>
  3153. /// <param name="e"></param>
  3154. private void button_WriteSensorParam_Click(object sender, EventArgs e)
  3155. {
  3156. var ConfigParam = new byte[14];
  3157. for (int i = 0; i < 14; i++)
  3158. ConfigParam[i] = 0;
  3159. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  3160. ushort uwDataTemp = 0;
  3161. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  3162. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  3163. int index = 0;
  3164. try
  3165. {
  3166. for (int i = 0; i < strDataTemp.Length; i++)
  3167. {
  3168. if (strDataTemp[i].Split('=')[0] == "力矩传感器踏频脉冲数")
  3169. {
  3170. index = i;
  3171. break;
  3172. }
  3173. }
  3174. for (int i = 0; i < (strDataTemp.Length - index); i++)
  3175. {
  3176. uwDataTemp = Convert.ToUInt16(strDataTemp[i + index].Split('=')[1]);
  3177. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3178. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3179. }
  3180. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x420E, ConfigParam);
  3181. }
  3182. catch (Exception)
  3183. {
  3184. timer_500ms.Enabled = false;
  3185. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3186. timer_500ms.Enabled = true;
  3187. }
  3188. }
  3189. /// <summary>
  3190. /// 写入型号
  3191. /// </summary>
  3192. /// <param name="sender"></param>
  3193. /// <param name="e"></param>
  3194. private void button_WriteModel_Click(object sender, EventArgs e)
  3195. {
  3196. string Mode = textBox_Model.Text;
  3197. var ModeArray = new byte[16];
  3198. for (ushort i = 0; i < Mode.Length; i++)
  3199. {
  3200. ModeArray[i] = (byte)Mode[i];
  3201. }
  3202. if (Mode.Length < 16)
  3203. {
  3204. ModeArray[Mode.Length] = (byte)'.';
  3205. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  3206. {
  3207. ModeArray[Mode.Length + 1 + i] = 0x20;
  3208. }
  3209. }
  3210. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  3211. }
  3212. /// <summary>
  3213. /// 写入SN
  3214. /// </summary>
  3215. /// <param name="sender"></param>
  3216. /// <param name="e"></param>
  3217. private void button_WriteSN_Click(object sender, EventArgs e)
  3218. {
  3219. string SN = textBox_SN.Text;
  3220. var SNArray = new byte[16];
  3221. for (ushort i = 0; i < SN.Length; i++)
  3222. {
  3223. SNArray[i] = (byte)SN[i];
  3224. }
  3225. if (SN.Length < 16)
  3226. {
  3227. SNArray[SN.Length] = (byte)'.';
  3228. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  3229. {
  3230. SNArray[SN.Length + 1 + i] = 0x20;
  3231. }
  3232. }
  3233. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  3234. }
  3235. /// <summary>
  3236. /// 查询版本信息
  3237. /// </summary>
  3238. /// <param name="sender"></param>
  3239. /// <param name="e"></param>
  3240. private void button_ReadVersion_Click(object sender, EventArgs e)
  3241. {
  3242. textBox_Model.Text = "---";
  3243. textBox_SN.Text = "---";
  3244. textBox_HW.Text = "---";
  3245. textBox_FW.Text = "---";
  3246. textBox_SP.Text = "---";
  3247. textBox_OBC_ReadModel.Text = "---";
  3248. textBox_OBC_ReadSN.Text = "---";
  3249. textBox_OBC_ReadHW.Text = "---";
  3250. textBox_OBC_ReadFW.Text = "---";
  3251. textBox_OBC_ReadSP.Text = "---";
  3252. textBox_FacModeName.Text = "---";
  3253. textBox_FacModeNum.Text = "---";
  3254. textBox_FacModeHW.Text = "---";
  3255. textBox_FacModeFW.Text = "---";
  3256. textBox_FacModeSP.Text = "---";
  3257. Class_Motor_Ver.Mode = "---";
  3258. Class_Motor_Ver.SN = "---";
  3259. Class_Motor_Ver.HW = "---";
  3260. Class_Motor_Ver.FW = "---";
  3261. Class_Motor_Ver.Special = "---";
  3262. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  3263. }
  3264. /// <summary>
  3265. /// 查询自定义1
  3266. /// </summary>
  3267. /// <param name="sender"></param>
  3268. /// <param name="e"></param>
  3269. private void button_ReadUser1_Click(object sender, EventArgs e)
  3270. {
  3271. textBox_User1.Text = "---";
  3272. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null);
  3273. }
  3274. /// <summary>
  3275. /// 查询自定义2
  3276. /// </summary>
  3277. /// <param name="sender"></param>
  3278. /// <param name="e"></param>
  3279. private void button_ReadUser2_Click(object sender, EventArgs e)
  3280. {
  3281. textBox_User2.Text = "---";
  3282. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null);
  3283. }
  3284. /// <summary>
  3285. /// 查询自定义3
  3286. /// </summary>
  3287. /// <param name="sender"></param>
  3288. /// <param name="e"></param>
  3289. private void button_ReadUser3_Click(object sender, EventArgs e)
  3290. {
  3291. textBox_User3.Text = "---";
  3292. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null);
  3293. }
  3294. /// <summary>
  3295. /// 写入自定义字符串1
  3296. /// </summary>
  3297. /// <param name="sender"></param>
  3298. /// <param name="e"></param>
  3299. private void button_WriteUser1_Click(object sender, EventArgs e)
  3300. {
  3301. string User = textBox_User1.Text;
  3302. var UserArray = new byte[16];
  3303. for (ushort i = 0; i < User.Length; i++)
  3304. {
  3305. UserArray[i] = (byte)User[i];
  3306. }
  3307. if (User.Length < 16)
  3308. {
  3309. UserArray[User.Length] = (byte)'.';
  3310. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3311. {
  3312. UserArray[User.Length + 1 + i] = 0x20;
  3313. }
  3314. }
  3315. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1410, UserArray);
  3316. }
  3317. /// <summary>
  3318. /// 写入自定义字符串2
  3319. /// </summary>
  3320. /// <param name="sender"></param>
  3321. /// <param name="e"></param>
  3322. private void button_WriteUser2_Click(object sender, EventArgs e)
  3323. {
  3324. string User = textBox_User2.Text;
  3325. var UserArray = new byte[16];
  3326. for (ushort i = 0; i < User.Length; i++)
  3327. {
  3328. UserArray[i] = (byte)User[i];
  3329. }
  3330. if (User.Length < 16)
  3331. {
  3332. UserArray[User.Length] = (byte)'.';
  3333. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3334. {
  3335. UserArray[User.Length + 1 + i] = 0x20;
  3336. }
  3337. }
  3338. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1610, UserArray);
  3339. }
  3340. /// <summary>
  3341. /// 写入自定义字符串3
  3342. /// </summary>
  3343. /// <param name="sender"></param>
  3344. /// <param name="e"></param>
  3345. private void button_WriteUser3_Click(object sender, EventArgs e)
  3346. {
  3347. string User = textBox_User3.Text;
  3348. var UserArray = new byte[16];
  3349. for (ushort i = 0; i < User.Length; i++)
  3350. {
  3351. UserArray[i] = (byte)User[i];
  3352. }
  3353. if (User.Length < 16)
  3354. {
  3355. UserArray[User.Length] = (byte)'.';
  3356. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3357. {
  3358. UserArray[User.Length + 1 + i] = 0x20;
  3359. }
  3360. }
  3361. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1810, UserArray);
  3362. }
  3363. /// <summary>
  3364. /// 查询生产信息
  3365. /// </summary>
  3366. /// <param name="sender"></param>
  3367. /// <param name="e"></param>
  3368. private void button_ReadMAC_Click(object sender, EventArgs e)
  3369. {
  3370. textBox_MAC.Text = "---";
  3371. textBox_MACAdd.Text = "---";
  3372. textBox_MACDate.Text = "---";
  3373. textBox_PP.Text = "---";
  3374. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null);
  3375. }
  3376. /// <summary>
  3377. /// 写入生产信息
  3378. /// </summary>
  3379. /// <param name="sender"></param>
  3380. /// <param name="e"></param>
  3381. private void button_WriteMac_Click(object sender, EventArgs e)
  3382. {
  3383. var MACArray = new byte[32];
  3384. //填入生产商
  3385. for (ushort i = 0; i < textBox_MAC.Text.Length; i++)
  3386. {
  3387. MACArray[i] = (byte)textBox_MAC.Text[i];
  3388. }
  3389. if (textBox_MAC.Text.Length < 8)
  3390. {
  3391. MACArray[textBox_MAC.Text.Length] = (byte)'.';
  3392. for (ushort i = 0; i < 8 - textBox_MAC.Text.Length - 1; i++)
  3393. {
  3394. MACArray[textBox_MAC.Text.Length + 1 + i] = 0x20;
  3395. }
  3396. }
  3397. //填入生产地
  3398. for (ushort i = 0; i < textBox_MACAdd.Text.Length; i++)
  3399. {
  3400. MACArray[8 + i] = (byte)textBox_MACAdd.Text[i];
  3401. }
  3402. if (textBox_MACAdd.Text.Length < 8)
  3403. {
  3404. MACArray[textBox_MACAdd.Text.Length + 8] = (byte)'.';
  3405. for (ushort i = 0; i < 8 - textBox_MACAdd.Text.Length - 1; i++)
  3406. {
  3407. MACArray[textBox_MACAdd.Text.Length + 1 + i + 8] = 0x20;
  3408. }
  3409. }
  3410. //填入生产日期
  3411. for (ushort i = 0; i < textBox_MACDate.Text.Length; i++)
  3412. {
  3413. MACArray[16 + i] = (byte)textBox_MACDate.Text[i];
  3414. }
  3415. if (textBox_MACDate.Text.Length < 8)
  3416. {
  3417. MACArray[textBox_MACDate.Text.Length + 16] = (byte)'.';
  3418. for (ushort i = 0; i < 8 - textBox_MACDate.Text.Length - 1; i++)
  3419. {
  3420. MACArray[textBox_MACDate.Text.Length + 1 + i + 16] = 0x20;
  3421. }
  3422. }
  3423. //填入品牌
  3424. for (ushort i = 0; i < textBox_PP.Text.Length; i++)
  3425. {
  3426. MACArray[24 + i] = (byte)textBox_PP.Text[i];
  3427. }
  3428. if (textBox_PP.Text.Length < 8)
  3429. {
  3430. MACArray[textBox_PP.Text.Length + 24] = (byte)'.';
  3431. for (ushort i = 0; i < 8 - textBox_PP.Text.Length - 1; i++)
  3432. {
  3433. MACArray[textBox_PP.Text.Length + 1 + i + 24] = 0x20;
  3434. }
  3435. }
  3436. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  3437. }
  3438. /// <summary>
  3439. /// 查询密钥
  3440. /// </summary>
  3441. /// <param name="sender"></param>
  3442. /// <param name="e"></param>
  3443. private void button_ReadKey_Click(object sender, EventArgs e)
  3444. {
  3445. textBox_Key.Text = "---";
  3446. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null);
  3447. }
  3448. /// <summary>
  3449. /// 写入校验密钥
  3450. /// </summary>
  3451. /// <param name="sender"></param>
  3452. /// <param name="e"></param>
  3453. private void button_WriteKey_Click(object sender, EventArgs e)
  3454. {
  3455. string Key = textBox_Key.Text;
  3456. var KeyArray = new byte[8];
  3457. if (Key.Length != 8)
  3458. {
  3459. timer_500ms.Enabled = false;
  3460. MessageBox.Show("请检查字符长度是否为8", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3461. timer_500ms.Enabled = true;
  3462. return;
  3463. }
  3464. for (ushort i = 0; i < Key.Length; i++)
  3465. {
  3466. KeyArray[i] = (byte)Key[i];
  3467. }
  3468. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1108, KeyArray);
  3469. }
  3470. /// <summary>
  3471. /// 查询在线检测结果
  3472. /// </summary>
  3473. /// <param name="sender"></param>
  3474. /// <param name="e"></param>
  3475. private void button_ReadOnLine_Click(object sender, EventArgs e)
  3476. {
  3477. textBox_Online.Text = "---";
  3478. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2100, null);
  3479. }
  3480. /// <summary>
  3481. /// 系统清除
  3482. /// </summary>
  3483. /// <param name="sender"></param>
  3484. /// <param name="e"></param>
  3485. private void button_SystemClear_Click(object sender, EventArgs e)
  3486. {
  3487. var Code = new byte[5];
  3488. Code[0] = (byte)'C';
  3489. Code[1] = (byte)'L';
  3490. Code[2] = (byte)'E';
  3491. Code[3] = (byte)'A';
  3492. Code[4] = (byte)'R';
  3493. timer_500ms.Enabled = false;
  3494. if (MessageBox.Show("系统清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3495. {
  3496. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3497. {
  3498. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3499. {
  3500. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  3501. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3502. }
  3503. }
  3504. }
  3505. timer_500ms.Enabled = true;
  3506. }
  3507. /// <summary>
  3508. /// 参数还原
  3509. /// </summary>
  3510. /// <param name="sender"></param>
  3511. /// <param name="e"></param>
  3512. private void button_Recovery_Click(object sender, EventArgs e)
  3513. {
  3514. var Code = new byte[8];
  3515. Code[0] = (byte)'R';
  3516. Code[1] = (byte)'E';
  3517. Code[2] = (byte)'C';
  3518. Code[3] = (byte)'O';
  3519. Code[4] = (byte)'V';
  3520. Code[5] = (byte)'E';
  3521. Code[6] = (byte)'R';
  3522. Code[7] = (byte)'Y';
  3523. timer_500ms.Enabled = false;
  3524. if (MessageBox.Show("参数还原后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3525. {
  3526. if (MessageBox.Show("请再次确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3527. {
  3528. if (MessageBox.Show("请最后确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3529. {
  3530. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2708, Code);
  3531. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3532. }
  3533. }
  3534. }
  3535. timer_500ms.Enabled = true;
  3536. }
  3537. /// <summary>
  3538. /// 系统复位
  3539. /// </summary>
  3540. /// <param name="sender"></param>
  3541. /// <param name="e"></param>
  3542. private void button_Reset_Click(object sender, EventArgs e)
  3543. {
  3544. var Code_Off = new byte[5];
  3545. var Code_Reset = new byte[5];
  3546. Code_Off[0] = (byte)'O';
  3547. Code_Off[1] = (byte)'F';
  3548. Code_Off[2] = (byte)'F';
  3549. Code_Off[3] = (byte)'.';
  3550. Code_Off[4] = (byte)'.';
  3551. Code_Reset[0] = (byte)'R';
  3552. Code_Reset[1] = (byte)'E';
  3553. Code_Reset[2] = (byte)'S';
  3554. Code_Reset[3] = (byte)'E';
  3555. Code_Reset[4] = (byte)'T';
  3556. timer_500ms.Enabled = false;
  3557. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3558. {
  3559. timer_500ms.Enabled = true;
  3560. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  3561. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  3562. PowerOffAckStatus = false;
  3563. Delay_ms(250);
  3564. int TryCnt = 3;
  3565. while ((TryCnt--) >= 0)
  3566. {
  3567. if (!PowerOffAckStatus)
  3568. {
  3569. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  3570. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  3571. PowerOffAckStatus = false;
  3572. Delay_ms(250);
  3573. }
  3574. else break;
  3575. }
  3576. if (PowerOffAckStatus)
  3577. {
  3578. MessageBoxTimeOut.Show("已关机!", "提示", 3000, MessageBoxButtons.OK, MessageBoxIcon.None);
  3579. }
  3580. else
  3581. {
  3582. timer_500ms.Enabled = false;
  3583. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3584. timer_500ms.Enabled = true;
  3585. }
  3586. }
  3587. timer_500ms.Enabled = true;
  3588. }
  3589. /// <summary>
  3590. /// 记录清除
  3591. /// </summary>
  3592. /// <param name="sender"></param>
  3593. /// <param name="e"></param>
  3594. private void button_ClearLog_Click(object sender, EventArgs e)
  3595. {
  3596. var Code = new byte[9];
  3597. Code[0] = (byte)'L';
  3598. Code[1] = (byte)'O';
  3599. Code[2] = (byte)'G';
  3600. Code[3] = (byte)' ';
  3601. Code[4] = (byte)'C';
  3602. Code[5] = (byte)'L';
  3603. Code[6] = (byte)'E';
  3604. Code[7] = (byte)'A';
  3605. Code[8] = (byte)'R';
  3606. timer_500ms.Enabled = false;
  3607. if (MessageBox.Show("历史记录信息清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3608. {
  3609. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3610. {
  3611. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3612. {
  3613. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3909, Code);
  3614. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3615. }
  3616. }
  3617. }
  3618. timer_500ms.Enabled = true;
  3619. }
  3620. /// <summary>
  3621. /// 打开系统计算器
  3622. /// </summary>
  3623. /// <param name="sender"></param>
  3624. /// <param name="e"></param>
  3625. private void 计算器ToolStripMenuItem_Click(object sender, EventArgs e)
  3626. {
  3627. System.Diagnostics.Process.Start("calc.exe");
  3628. }
  3629. /// <summary>
  3630. ///故障转换和显示
  3631. /// </summary>
  3632. List<string> ErrorInfo = new List<string>{ "过流保护", "低压保护", "过压保护", "堵转保护","过热保护","速度传感器故障","力矩传感器故障","霍尔故障",
  3633. "马达缺相","NTC故障","BMS校验失败","","OBC校验失败","MCU故障","踏频传感器故障","指拨故障","MOS短路","电压异常","","","","","","","","","","","","",
  3634. "",""};
  3635. private string ErrorInfoDisplay(UInt32 Code)
  3636. {
  3637. string Result = "";
  3638. if (Code == 0)
  3639. {
  3640. Result = "无故障";
  3641. }
  3642. else
  3643. {
  3644. for (int i = 0; i < 32; i++)
  3645. {
  3646. if ((Code & 0x01) == 0x01)
  3647. {
  3648. Result += ErrorInfo[i] + " ";
  3649. }
  3650. Code >>= 1;
  3651. }
  3652. }
  3653. return Result;
  3654. }
  3655. /// <summary>
  3656. /// 鼠标滑过故障码显示具体内容
  3657. /// </summary>
  3658. /// <param name="sender"></param>
  3659. /// <param name="e"></param>
  3660. private void textBox_ErrorCode_MouseHover(object sender, EventArgs e)
  3661. {
  3662. // 创建the ToolTip
  3663. ToolTip toolTip1 = new ToolTip();
  3664. // 设置显示样式
  3665. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  3666. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  3667. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  3668. toolTip1.ShowAlways = true;//是否显示提示框
  3669. // 设置伴随的对象.
  3670. string ErrorCode = this.textBox_ErrorCode.Text;
  3671. UInt32 Code = ErrorCode.Contains("H") ? Convert.ToUInt32(ErrorCode.Split('H')[0], 16) : 0;
  3672. toolTip1.SetToolTip(this.textBox_ErrorCode, ErrorInfoDisplay(Code));//设置故障内容显示
  3673. }
  3674. /// <summary>
  3675. /// 数据记录
  3676. /// </summary>
  3677. private void RunInfoAutoSave()
  3678. {
  3679. if (运行信息记录ToolStripMenuItem.Checked == true)
  3680. {
  3681. if (RunInfoSaveFilename == string.Empty)
  3682. {
  3683. return;
  3684. }
  3685. string SaveData = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff").Replace(" ", "_") + " --> ";
  3686. foreach (Control c in tabPage_RunInfo.Controls)
  3687. {
  3688. if (c is TextBox)
  3689. {
  3690. SaveData += c.Text + " , ";
  3691. }
  3692. }
  3693. foreach (Control c in tabPage_DebugInfo.Controls)
  3694. {
  3695. if (c is TextBox)
  3696. {
  3697. SaveData += c.Text + " , ";
  3698. }
  3699. }
  3700. SaveData += "\r\n";
  3701. System.IO.File.AppendAllText(RunInfoSaveFilename, SaveData);//sb.ToString());
  3702. }
  3703. }
  3704. /// <summary>
  3705. /// 打开或关闭数据记录
  3706. /// </summary>
  3707. /// <param name="sender"></param>
  3708. /// <param name="e"></param>
  3709. private void 记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  3710. {
  3711. if (运行信息记录ToolStripMenuItem.Checked == false)
  3712. {
  3713. if (mySerialProcess.mySerial.IsOpen == true)
  3714. {
  3715. RunInfoSaveFilename = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_运行信息" + ".txt";
  3716. System.IO.File.AppendAllText(RunInfoSaveFilename, "时间 --> 车速 , 转速 , 踏频 , 力矩Reg , 力矩 , 踩踏方向 , 电压 , 电流 , 功率 , 电量 , " +
  3717. "PCB温度 , 绕组温度 , MOS温度 , 挡位 , 灯开关 , 续航 , 平均功耗 , 单次里程 , 单次时间 , 故障码 , " +
  3718. "系统状态机 , 二层状态机 , 电机状态机 , 助力状态机 , D轴电流给定 , Q轴电流给定 , D轴电压给定 , Q轴电压给定 , 瞬时力矩 , 时间滤波力矩 , 踏频滤波力矩 , D轴电流反馈 , Q轴电流反馈 , 助力函数输出" + "\r\n");
  3719. MessageBoxTimeOut.Show("开始记录", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  3720. 运行信息记录ToolStripMenuItem.Checked = true;
  3721. }
  3722. else
  3723. {
  3724. timer_500ms.Enabled = false;
  3725. MessageBox.Show("请连接电机", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3726. timer_500ms.Enabled = true;
  3727. }
  3728. }
  3729. else
  3730. {
  3731. 运行信息记录ToolStripMenuItem.Checked = false;
  3732. MessageBoxTimeOut.Show("停止记录", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  3733. }
  3734. }
  3735. /// <summary>
  3736. /// 仪表启动控制档位开关事件
  3737. /// </summary>
  3738. /// <param name="sender"></param>
  3739. /// <param name="e"></param>
  3740. private void checkBox_OBC_StartSetGearSt_CheckedChanged(object sender, EventArgs e)
  3741. {
  3742. if (checkBox_OBC_StartSetGearSt.Checked == true)
  3743. {
  3744. //检查串口是否打开
  3745. if (!mySerialProcess.mySerial.IsOpen)
  3746. {
  3747. timer_500ms.Enabled = false;
  3748. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3749. timer_500ms.Enabled = true;
  3750. checkBox_OBC_StartSetGearSt.Checked = false;
  3751. return;
  3752. }
  3753. //检查是否选择档位和打开车灯
  3754. if ((comboBox_OBC_SetGearST.SelectedIndex == -1) || (comboBox_OBC_LightSw.SelectedIndex == -1))
  3755. {
  3756. timer_500ms.Enabled = false;
  3757. MessageBox.Show("请检查档位设置和大灯开关!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3758. timer_500ms.Enabled = true;
  3759. checkBox_OBC_StartSetGearSt.Checked = false;
  3760. return;
  3761. }
  3762. }
  3763. }
  3764. /// <summary>
  3765. /// OBC查询电机用户参数
  3766. /// </summary>
  3767. /// <param name="sender"></param>
  3768. /// <param name="e"></param>
  3769. private void button_OBC_ReadUserInfo_Click(object sender, EventArgs e)
  3770. {
  3771. richTextBox_OBC_ReadUserInfo.Clear();
  3772. comboBox_OBC_BikeCCS.SelectedIndex = 0;
  3773. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3300, null);
  3774. }
  3775. /// <summary>
  3776. /// OBC设置电机用户参数
  3777. /// </summary>
  3778. /// <param name="sender"></param>
  3779. /// <param name="e"></param>
  3780. private void button_OBC_WriteUserInfo_Click(object sender, EventArgs e)
  3781. {
  3782. var UserInfoCode = new byte[8];
  3783. for (int i = 0; i < UserInfoCode.Length; i++)
  3784. UserInfoCode[i] = 0;
  3785. if (comboBox_OBC_StartMode.SelectedIndex == -1)//检查数据有效性
  3786. {
  3787. timer_500ms.Enabled = false;
  3788. MessageBox.Show("请选择启动模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3789. timer_500ms.Enabled = true;
  3790. return;
  3791. }
  3792. if (comboBox_OBC_AssistFunc.SelectedIndex == -1)//检查数据有效性
  3793. {
  3794. timer_500ms.Enabled = false;
  3795. MessageBox.Show("请选择助力方案!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3796. timer_500ms.Enabled = true;
  3797. return;
  3798. }
  3799. //周长微调
  3800. UserInfoCode[0] = (byte)(int)numericUpDown_OBC_WheelAdj.Value;
  3801. //启动模式
  3802. UserInfoCode[1] = (byte)(comboBox_OBC_StartMode.SelectedIndex + 1);
  3803. //助力方案
  3804. UserInfoCode[2] = (byte)(comboBox_OBC_AssistFunc.SelectedIndex + 1);
  3805. //自动关机时间
  3806. UserInfoCode[3] = (byte)(uint)numericUpDown_OBC_OffTime.Value;
  3807. //限速微调
  3808. UserInfoCode[4] = (byte)(int)numericUpDown_OBC_SpeedLimitAdj.Value;
  3809. //定速巡航开关
  3810. UserInfoCode[5] = (byte)((comboBox_OBC_BikeCCS.SelectedIndex == 1) ? 0xAA : 0x00);
  3811. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3408, UserInfoCode);
  3812. }
  3813. /// <summary>
  3814. /// OBC查询电机版本信息
  3815. /// </summary>
  3816. /// <param name="sender"></param>
  3817. /// <param name="e"></param>
  3818. private void button_OBC_ReadVerInfo_Click(object sender, EventArgs e)
  3819. {
  3820. textBox_Model.Text = "---";
  3821. textBox_SN.Text = "---";
  3822. textBox_HW.Text = "---";
  3823. textBox_FW.Text = "---";
  3824. textBox_SP.Text = "---";
  3825. textBox_OBC_ReadModel.Text = "---";
  3826. textBox_OBC_ReadSN.Text = "---";
  3827. textBox_OBC_ReadHW.Text = "---";
  3828. textBox_OBC_ReadFW.Text = "---";
  3829. textBox_OBC_ReadSP.Text = "---";
  3830. textBox_FacModeName.Text = "---";
  3831. textBox_FacModeNum.Text = "---";
  3832. textBox_FacModeHW.Text = "---";
  3833. textBox_FacModeFW.Text = "---";
  3834. textBox_FacModeSP.Text = "---";
  3835. Class_Motor_Ver.Mode = "---";
  3836. Class_Motor_Ver.SN = "---";
  3837. Class_Motor_Ver.HW = "---";
  3838. Class_Motor_Ver.FW = "---";
  3839. Class_Motor_Ver.Special = "---";
  3840. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  3841. }
  3842. /// <summary>
  3843. /// OBC读取骑行历史
  3844. /// </summary>
  3845. /// <param name="sender"></param>
  3846. /// <param name="e"></param>
  3847. private void button_OBC_ReadRideInfo_Click(object sender, EventArgs e)
  3848. {
  3849. textBox_OBC_TRIP_KM.Text = "";
  3850. textBox_OBC_TRIP_TIME.Text = "";
  3851. textBox_OBC_ODO_KM.Text = "";
  3852. textBox_OBC_ODO_TIME.Text = "";
  3853. textBox_ODO_KM.Text = "---";
  3854. textBox_ODO_TIME.Text = "---";
  3855. textBox_TRIP_KM.Text = "---";
  3856. textBox_TRIP_TIME.Text = "---";
  3857. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3500, null);
  3858. }
  3859. /// <summary>
  3860. /// OBC清除TRIP里程
  3861. /// </summary>
  3862. /// <param name="sender"></param>
  3863. /// <param name="e"></param>
  3864. private void button_OBC_ClearTrip_Click(object sender, EventArgs e)
  3865. {
  3866. var Code = new byte[5];
  3867. Code[0] = (byte)'C';
  3868. Code[1] = (byte)'L';
  3869. Code[2] = (byte)'E';
  3870. Code[3] = (byte)'A';
  3871. Code[4] = (byte)'R';
  3872. timer_500ms.Enabled = false;
  3873. if (MessageBox.Show("TRIP清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3874. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3605, Code);
  3875. timer_500ms.Enabled = true;
  3876. }
  3877. private void checkBox_OBC_StartReadBMS_CheckedChanged(object sender, EventArgs e)
  3878. {
  3879. if (checkBox_OBC_StartReadBMS.Checked == true)
  3880. {
  3881. //检查串口是否打开
  3882. if (!mySerialProcess.mySerial.IsOpen)
  3883. {
  3884. timer_500ms.Enabled = false;
  3885. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3886. timer_500ms.Enabled = true;
  3887. checkBox_OBC_StartReadBMS.Checked = false;
  3888. return;
  3889. }
  3890. }
  3891. }
  3892. /// <summary>
  3893. /// 写入力矩传感器参数
  3894. /// </summary>
  3895. /// <param name="sender"></param>
  3896. /// <param name="e"></param>
  3897. private void button_WriteTqSensorParam_Click(object sender, EventArgs e)
  3898. {
  3899. var ConfigParam = new byte[46];
  3900. for (int i = 0; i < 14; i++)
  3901. ConfigParam[i] = 0;
  3902. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  3903. ushort uwDataTemp = 0;
  3904. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  3905. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  3906. int index = 0;
  3907. try
  3908. {
  3909. for (int i = 0; i < strDataTemp.Length; i++)
  3910. {
  3911. if (strDataTemp[i].Split('=')[0] == "第四阶段转矩点采集值")
  3912. {
  3913. index = i;
  3914. break;
  3915. }
  3916. }
  3917. for (int i = 0; i < (index + 1); i++)
  3918. {
  3919. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  3920. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3921. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3922. }
  3923. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x472E, ConfigParam);
  3924. }
  3925. catch (Exception)
  3926. {
  3927. timer_500ms.Enabled = false;
  3928. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3929. timer_500ms.Enabled = true;
  3930. }
  3931. }
  3932. /// <summary>
  3933. /// 查询存储标志
  3934. /// </summary>
  3935. /// <param name="sender"></param>
  3936. /// <param name="e"></param>
  3937. private void button_ReadSaveFlag_Click(object sender, EventArgs e)
  3938. {
  3939. radioButton_EE_SaveYes.Checked = false;
  3940. radioButton_EE_SaveNo.Checked = false;
  3941. radioButton_SIP_SaveYes.Checked = false;
  3942. radioButton_SIP_SaveNo.Checked = false;
  3943. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null);
  3944. }
  3945. /// <summary>
  3946. /// 写入存储标志
  3947. /// </summary>
  3948. /// <param name="sender"></param>
  3949. /// <param name="e"></param>
  3950. private void button_WriteSaveFlag_Click(object sender, EventArgs e)
  3951. {
  3952. var SaveFlag = new byte[6];
  3953. for (int i = 0; i < 6; i++)
  3954. SaveFlag[i] = 0;
  3955. if ((radioButton_EE_SaveYes.Checked == false) && (radioButton_EE_SaveNo.Checked == false))
  3956. {
  3957. timer_500ms.Enabled = false;
  3958. MessageBox.Show("请选择EEPROM存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3959. timer_500ms.Enabled = true;
  3960. return;
  3961. }
  3962. if ((radioButton_SIP_SaveYes.Checked == false) && (radioButton_SIP_SaveNo.Checked == false))
  3963. {
  3964. timer_500ms.Enabled = false;
  3965. MessageBox.Show("请选择SIP校验存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3966. timer_500ms.Enabled = true;
  3967. return;
  3968. }
  3969. SaveFlag[0] = (byte)((checkBox_SaveYes.Checked) ? 0x01 : 0x00);
  3970. SaveFlag[2] = (byte)(radioButton_EE_SaveYes.Checked ? 0x01 : 0x00);
  3971. SaveFlag[3] = 0;
  3972. SaveFlag[4] = (byte)(radioButton_SIP_SaveYes.Checked ? 0x01 : 0x00);
  3973. SaveFlag[5] = 0;
  3974. timer_500ms.Enabled = false;
  3975. if (MessageBox.Show("确认修改存储标志?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3976. {
  3977. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4906, SaveFlag);
  3978. }
  3979. timer_500ms.Enabled = true;
  3980. }
  3981. /// <summary>
  3982. /// 读取指定地址数据
  3983. /// </summary>
  3984. /// <param name="sender"></param>
  3985. /// <param name="e"></param>
  3986. private void button_ReadRamFlash_Click(object sender, EventArgs e)
  3987. {
  3988. var Address = new byte[4];
  3989. UInt32 Address_Begin;
  3990. UInt32 Addres_End;
  3991. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  3992. richTextBox_RamFlasgData.Clear();
  3993. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  3994. {
  3995. timer_500ms.Enabled = false;
  3996. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3997. timer_500ms.Enabled = true;
  3998. return;
  3999. }
  4000. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  4001. {
  4002. timer_500ms.Enabled = false;
  4003. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4004. timer_500ms.Enabled = true;
  4005. return;
  4006. }
  4007. else
  4008. {
  4009. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  4010. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  4011. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  4012. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  4013. if (Addres_End < Address_Begin)
  4014. {
  4015. timer_500ms.Enabled = false;
  4016. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4017. timer_500ms.Enabled = true;
  4018. return;
  4019. }
  4020. else
  4021. {
  4022. var SendByte = new byte[8];
  4023. SendByte[0] = (byte)(Address_Begin >> 24);
  4024. SendByte[1] = (byte)(Address_Begin >> 16);
  4025. SendByte[2] = (byte)(Address_Begin >> 8);
  4026. SendByte[3] = (byte)(Address_Begin);
  4027. SendByte[4] = (byte)(Addres_End >> 24);
  4028. SendByte[5] = (byte)(Addres_End >> 16);
  4029. SendByte[6] = (byte)(Addres_End >> 8);
  4030. SendByte[7] = (byte)(Addres_End);
  4031. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  4032. }
  4033. }
  4034. }
  4035. /// <summary>
  4036. /// 工作模式选择
  4037. /// </summary>
  4038. /// <param name="sender"></param>
  4039. /// <param name="e"></param>
  4040. private void comboBox_WorkMode_SelectedIndexChanged(object sender, EventArgs e)
  4041. {
  4042. var RunMode = new byte[1];
  4043. if (comboBox_WorkMode.Text == "配置模式")
  4044. RunMode[0] = 0x01;
  4045. else if (comboBox_WorkMode.Text == "调试模式")
  4046. RunMode[0] = 0x02;
  4047. else
  4048. RunMode[0] = 0x00;
  4049. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  4050. }
  4051. /// <summary>
  4052. /// 助力档位选择
  4053. /// </summary>
  4054. /// <param name="sender"></param>
  4055. /// <param name="e"></param>
  4056. private void comboBox_GearSt_SelectedIndexChanged(object sender, EventArgs e)
  4057. {
  4058. var CtrlCode = new byte[2];
  4059. if (comboBox_GearSt.SelectedIndex == 5)//档位
  4060. CtrlCode[0] = 0x33;
  4061. else if (comboBox_GearSt.SelectedIndex == 6)//档位
  4062. CtrlCode[0] = 0x22;
  4063. else
  4064. CtrlCode[0] = (byte)comboBox_GearSt.SelectedIndex;
  4065. if (comboBox_LightSwitch.SelectedIndex == 0)//车灯
  4066. CtrlCode[1] = 0xF1;
  4067. else
  4068. CtrlCode[1] = 0xF0;
  4069. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
  4070. comboBox_OBC_SetGearST.SelectedIndex = comboBox_GearSt.SelectedIndex;
  4071. comboBox_OBC_LightSw.SelectedIndex = comboBox_LightSwitch.SelectedIndex;
  4072. Delay_ms(500);
  4073. //设置百分比
  4074. do
  4075. {
  4076. var PercentCode = new byte[1];
  4077. if (comboBox_GearSt.SelectedIndex == 0) //Off
  4078. {
  4079. PercentCode[0] = 0;
  4080. textBox_MotorSpeedPercent.Text = "0";
  4081. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, PercentCode);
  4082. }
  4083. else if (comboBox_GearSt.SelectedIndex == 6) //Walk
  4084. {
  4085. if (comboBox_WorkMode.SelectedIndex != 0)
  4086. {
  4087. PercentCode[0] = 100;
  4088. textBox_MotorSpeedPercent.Text = "100";
  4089. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, PercentCode);
  4090. }
  4091. }
  4092. } while (false);
  4093. }
  4094. /// <summary>
  4095. /// 仪表档位选择
  4096. /// </summary>
  4097. /// <param name="sender"></param>
  4098. /// <param name="e"></param>
  4099. private void comboBox_OBC_SetGearST_SelectedIndexChanged(object sender, EventArgs e)
  4100. {
  4101. comboBox_GearSt.SelectedIndex = comboBox_OBC_SetGearST.SelectedIndex;
  4102. comboBox_LightSwitch.SelectedIndex = comboBox_OBC_LightSw.SelectedIndex;
  4103. }
  4104. /// <summary>
  4105. /// 生产模式初始化
  4106. /// </summary>
  4107. /// <param name="sender"></param>
  4108. /// <param name="e"></param>
  4109. private void button_FacModeInit_Click(object sender, EventArgs e)
  4110. {
  4111. var Code = new byte[5];
  4112. Code[0] = (byte)'C';
  4113. Code[1] = (byte)'L';
  4114. Code[2] = (byte)'E';
  4115. Code[3] = (byte)'A';
  4116. Code[4] = (byte)'R';
  4117. timer_500ms.Enabled = false;
  4118. if (MessageBox.Show("电机即将初始化!", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  4119. {
  4120. if (MessageBox.Show("请再次确认", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  4121. {
  4122. timer_500ms.Enabled = true;
  4123. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  4124. PowerOffAckStatus = false;
  4125. Delay_ms(250);
  4126. int TryCnt = 3;
  4127. while ((TryCnt--) >= 0)
  4128. {
  4129. if (!PowerOffAckStatus)
  4130. {
  4131. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  4132. PowerOffAckStatus = false;
  4133. Delay_ms(250);
  4134. }
  4135. else break;
  4136. }
  4137. if (PowerOffAckStatus)
  4138. {
  4139. timer_500ms.Enabled = false;
  4140. MessageBox.Show("系统已关机,请保持无负载重新开机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  4141. timer_500ms.Enabled = true;
  4142. }
  4143. else
  4144. {
  4145. timer_500ms.Enabled = false;
  4146. MessageBox.Show("初始化失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4147. timer_500ms.Enabled = true;
  4148. }
  4149. timer_500ms.Enabled = true;
  4150. }
  4151. }
  4152. timer_500ms.Enabled = true;
  4153. //清除历史测试记录
  4154. textBox_FacModeSensorADC0.Text = "";
  4155. textBox_FacModeSensorADC1.Text = "";
  4156. textBox_FacModeSensorADC2.Text = "";
  4157. textBox_FacModeSensorADC3.Text = "";
  4158. textBox_FacModeSensorADC4.Text = "";
  4159. LightSwitchStatus = false;
  4160. MotorRunStatus = false;
  4161. textBox_MotorSpeedPercent.Text = "5";
  4162. textBox_FacModeName.Text = "";
  4163. textBox_FacModeNum.Text = "";
  4164. textBox_FacModeHW.Text = "";
  4165. textBox_FacModeFW.Text = "";
  4166. }
  4167. /// <summary>
  4168. /// 生产模式读取传感器参数
  4169. /// </summary>
  4170. /// <param name="sender"></param>
  4171. /// <param name="e"></param>
  4172. private void button_FacModeSensorRead_Click(object sender, EventArgs e)
  4173. {
  4174. richTextBox_SensorParam.Clear();
  4175. textBox_FacModeSensorADC0.Text = "";
  4176. textBox_FacModeSensorADC1.Text = "";
  4177. textBox_FacModeSensorADC2.Text = "";
  4178. textBox_FacModeSensorADC3.Text = "";
  4179. textBox_FacModeSensorADC4.Text = "";
  4180. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4181. //零点判断
  4182. label1_TorqueCal0.BackColor = Color.Red;
  4183. WriteACK = false;
  4184. ACK_WaitCnt = 0;
  4185. Delay_ms(200);
  4186. if (WriteACK == true) //力矩读取正常
  4187. {
  4188. WriteACK = false;
  4189. //获取零点
  4190. ushort ZeroNew;
  4191. ZeroNew = (ushort)Convert.ToUInt16(textBox_FacModeSensorADC0.Text);
  4192. //比较零点
  4193. if ((ZeroNew <= TorqueParamsForm.Zero.Max) && (ZeroNew >= TorqueParamsForm.Zero.Min))
  4194. {
  4195. label1_TorqueCal0.BackColor = Color.Green;
  4196. }
  4197. else
  4198. {
  4199. MessageBoxTimeOut.Show("力矩传感器零点超范围!\r\n" + "最新零点:" + ZeroNew.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4200. }
  4201. }
  4202. else //力矩读取不正常
  4203. {
  4204. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4205. }
  4206. }
  4207. /// <summary>
  4208. /// 生产模式传感器标定1
  4209. /// </summary>
  4210. /// <param name="sender"></param>
  4211. /// <param name="e"></param>
  4212. private void buttonFacModeSet1_Click(object sender, EventArgs e)
  4213. {
  4214. var ConfigParam = new byte[4];
  4215. for (int i = 0; i < 4; i++)
  4216. ConfigParam[i] = 0;
  4217. ushort uwDataTemp = 0;
  4218. try
  4219. {
  4220. uwDataTemp = 1;//负载序号
  4221. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4222. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4223. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal1.Text) * 10); ;//负载值0.1Nm
  4224. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4225. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4226. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4227. Delay_ms(2000);
  4228. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4229. //标定1判断
  4230. label1_TorqueCal1.BackColor = Color.Red;
  4231. WriteACK = false;
  4232. ACK_WaitCnt = 0;
  4233. Delay_ms(200);
  4234. if (WriteACK == true) //力矩读取正常
  4235. {
  4236. WriteACK = false;
  4237. //获取标定1
  4238. ushort K1_T, K1;
  4239. K1_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal1.Text) * 10);
  4240. K1 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC1.Text));
  4241. //比较标定1
  4242. if ((K1_T == TorqueParamsForm.K1.T) && (K1 <= TorqueParamsForm.K1.Max) && (K1 >= TorqueParamsForm.K1.Min))
  4243. {
  4244. label1_TorqueCal1.BackColor = Color.Green;
  4245. }
  4246. else
  4247. {
  4248. MessageBoxTimeOut.Show("力矩传感器标定1超范围!\r\n" + "加载扭矩:" + K1_T.ToString() + "\r\n标定值:" + K1.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4249. }
  4250. }
  4251. else //力矩读取不正常
  4252. {
  4253. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4254. }
  4255. }
  4256. catch (Exception)
  4257. {
  4258. timer_500ms.Enabled = false;
  4259. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4260. timer_500ms.Enabled = true;
  4261. }
  4262. }
  4263. /// <summary>
  4264. /// 生产模式传感器标定2
  4265. /// </summary>
  4266. /// <param name="sender"></param>
  4267. /// <param name="e"></param>
  4268. private void buttonFacModeSet2_Click(object sender, EventArgs e)
  4269. {
  4270. var ConfigParam = new byte[4];
  4271. for (int i = 0; i < 4; i++)
  4272. ConfigParam[i] = 0;
  4273. ushort uwDataTemp = 0;
  4274. try
  4275. {
  4276. uwDataTemp = 2;//负载序号
  4277. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4278. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4279. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal2.Text) * 10); ;//负载值0.1Nm
  4280. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4281. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4282. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4283. Delay_ms(2000);
  4284. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4285. //标定2判断
  4286. label1_TorqueCal2.BackColor = Color.Red;
  4287. WriteACK = false;
  4288. ACK_WaitCnt = 0;
  4289. Delay_ms(200);
  4290. if (WriteACK == true) //力矩读取正常
  4291. {
  4292. WriteACK = false;
  4293. //获取标定2
  4294. ushort K2_T, K2;
  4295. K2_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal2.Text) * 10);
  4296. K2 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC2.Text));
  4297. //比较标定1
  4298. if ((K2_T == TorqueParamsForm.K2.T) && (K2 <= TorqueParamsForm.K2.Max) && (K2 >= TorqueParamsForm.K2.Min))
  4299. {
  4300. label1_TorqueCal2.BackColor = Color.Green;
  4301. }
  4302. else
  4303. {
  4304. MessageBoxTimeOut.Show("力矩传感器标定2超范围!\r\n" + "加载扭矩:" + K2_T.ToString() + "\r\n标定值:" + K2.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4305. }
  4306. }
  4307. else //力矩读取不正常
  4308. {
  4309. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4310. }
  4311. }
  4312. catch (Exception)
  4313. {
  4314. timer_500ms.Enabled = false;
  4315. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4316. timer_500ms.Enabled = true;
  4317. }
  4318. }
  4319. /// <summary>
  4320. /// 生产模式传感器标定3
  4321. /// </summary>
  4322. /// <param name="sender"></param>
  4323. /// <param name="e"></param>
  4324. private void buttonFacModeSet3_Click(object sender, EventArgs e)
  4325. {
  4326. var ConfigParam = new byte[4];
  4327. for (int i = 0; i < 4; i++)
  4328. ConfigParam[i] = 0;
  4329. ushort uwDataTemp = 0;
  4330. try
  4331. {
  4332. uwDataTemp = 3;//负载序号
  4333. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4334. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4335. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal3.Text) * 10); ;//负载值0.1Nm
  4336. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4337. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4338. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4339. Delay_ms(2000);
  4340. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4341. //标定3判断
  4342. label1_TorqueCal3.BackColor = Color.Red;
  4343. WriteACK = false;
  4344. ACK_WaitCnt = 0;
  4345. Delay_ms(200);
  4346. if (WriteACK == true) //力矩读取正常
  4347. {
  4348. WriteACK = false;
  4349. //获取标定3
  4350. ushort K3_T, K3;
  4351. K3_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal3.Text) * 10);
  4352. K3 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC3.Text));
  4353. //比较标定1
  4354. if ((K3_T == TorqueParamsForm.K3.T) && (K3 <= TorqueParamsForm.K3.Max) && (K3 >= TorqueParamsForm.K3.Min))
  4355. {
  4356. label1_TorqueCal3.BackColor = Color.Green;
  4357. }
  4358. else
  4359. {
  4360. MessageBoxTimeOut.Show("力矩传感器标定3超范围!\r\n" + "加载扭矩:" + K3_T.ToString() + "\r\n标定值:" + K3.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4361. }
  4362. }
  4363. else //力矩读取不正常
  4364. {
  4365. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4366. }
  4367. }
  4368. catch (Exception)
  4369. {
  4370. timer_500ms.Enabled = false;
  4371. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4372. timer_500ms.Enabled = true;
  4373. }
  4374. }
  4375. /// <summary>
  4376. /// 生产模式传感器标定4
  4377. /// </summary>
  4378. /// <param name="sender"></param>
  4379. /// <param name="e"></param>
  4380. private void buttonFacModeSet4_Click(object sender, EventArgs e)
  4381. {
  4382. var ConfigParam = new byte[4];
  4383. for (int i = 0; i < 4; i++)
  4384. ConfigParam[i] = 0;
  4385. ushort uwDataTemp = 0;
  4386. try
  4387. {
  4388. WriteACK = false;
  4389. uwDataTemp = 4;//负载序号
  4390. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4391. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4392. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal4.Text) * 10); ;//负载值0.1Nm
  4393. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4394. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4395. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4396. Delay_ms(2000);
  4397. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4398. //标定4判断
  4399. label1_TorqueCal4.BackColor = Color.Red;
  4400. WriteACK = false;
  4401. ACK_WaitCnt = 0;
  4402. Delay_ms(200);
  4403. if (WriteACK == true) //力矩读取正常
  4404. {
  4405. //获取标定4
  4406. ushort K4_T, K4;
  4407. K4_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal4.Text) * 10);
  4408. K4 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC4.Text));
  4409. //比较标定1
  4410. if ((K4_T == TorqueParamsForm.K4.T) && (K4 <= TorqueParamsForm.K4.Max) && (K4 >= TorqueParamsForm.K4.Min))
  4411. {
  4412. label1_TorqueCal4.BackColor = Color.Green;
  4413. }
  4414. else
  4415. {
  4416. MessageBoxTimeOut.Show("力矩传感器标定4超范围!\r\n" + "加载扭矩:" + K4_T.ToString() + "\r\n标定值:" + K4.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4417. }
  4418. }
  4419. else //力矩读取不正常
  4420. {
  4421. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4422. }
  4423. }
  4424. catch (Exception)
  4425. {
  4426. timer_500ms.Enabled = false;
  4427. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4428. timer_500ms.Enabled = true;
  4429. }
  4430. }
  4431. /// <summary>
  4432. /// 生产模式开关灯
  4433. /// </summary>
  4434. /// <param name="sender"></param>
  4435. /// <param name="e"></param>
  4436. bool LightSwitchStatus = false;
  4437. private void button_FacModeLightSW_Click(object sender, EventArgs e)
  4438. {
  4439. var CtrlCode = new byte[2];
  4440. CtrlCode[0] = 0x00;
  4441. if (LightSwitchStatus)
  4442. {
  4443. CtrlCode[1] = 0xF0;
  4444. button_FacModeLightSW.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(128)))));
  4445. }
  4446. else
  4447. {
  4448. CtrlCode[1] = 0xF1;
  4449. button_FacModeLightSW.BackColor = Color.Yellow;
  4450. }
  4451. if (mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode))
  4452. {
  4453. LightSwitchStatus = !LightSwitchStatus;
  4454. comboBox_LightSwitch.SelectedIndex = LightSwitchStatus ? 0 : 1;
  4455. comboBox_OBC_LightSw.SelectedIndex = LightSwitchStatus ? 0 : 1;
  4456. }
  4457. }
  4458. /// <summary>
  4459. /// 生产模式电机控制
  4460. /// </summary>
  4461. /// <param name="sender"></param>
  4462. /// <param name="e"></param>
  4463. bool MotorRunStatus = false;
  4464. private void button_FacModeMotorRun_Click(object sender, EventArgs e)
  4465. {
  4466. string DebugDefaultInfo = "";
  4467. //获取调试信息
  4468. if (richTextBox_DebugParam.Text == string.Empty)
  4469. {
  4470. richTextBox_DebugParam.Clear();
  4471. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  4472. }
  4473. Delay_ms(200);
  4474. DebugDefaultInfo = richTextBox_DebugParam.Text;
  4475. //获取参数
  4476. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  4477. if (strDataTemp.Length != 29)
  4478. {
  4479. timer_500ms.Enabled = false;
  4480. MessageBox.Show("数据格式不正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4481. timer_500ms.Enabled = true;
  4482. return;
  4483. }
  4484. //设置参数
  4485. var ConfigParam = new byte[60];
  4486. for (int i = 0; i < 60; i++)
  4487. ConfigParam[i] = 0;
  4488. ConfigParam[0] = 0x00;
  4489. ushort uwDataTemp = 0;
  4490. if (!MotorRunStatus) //停止状态
  4491. {
  4492. //设置速度环
  4493. strDataTemp[0] = "整体运行模式=3";
  4494. //发送数据
  4495. try
  4496. {
  4497. for (int i = 0; i < strDataTemp.Length; i++)
  4498. {
  4499. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  4500. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  4501. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  4502. }
  4503. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  4504. return;
  4505. }
  4506. catch (Exception)
  4507. {
  4508. timer_500ms.Enabled = false;
  4509. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4510. timer_500ms.Enabled = true;
  4511. }
  4512. Delay_ms(200);
  4513. //设置转速百分比100%
  4514. textBox_MotorSpeedPercent.Text = "100";
  4515. ConfigParam[0] = (byte)100;
  4516. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, ConfigParam);
  4517. MotorRunStatus = !MotorRunStatus;
  4518. button_FacModeMotorRun.BackColor = Color.Yellow;
  4519. Delay_ms(200);
  4520. //电机进入配置模式
  4521. var RunMode = new byte[1];
  4522. RunMode[0] = 0x01;
  4523. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  4524. }
  4525. else //运转状态
  4526. {
  4527. //设置转速百分比0%
  4528. textBox_MotorSpeedPercent.Text = "0";
  4529. ConfigParam[0] = (byte)0;
  4530. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, ConfigParam);
  4531. MotorRunStatus = !MotorRunStatus;
  4532. button_FacModeMotorRun.BackColor = Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
  4533. Delay_ms(200);
  4534. //还原为原始值
  4535. strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  4536. try
  4537. {
  4538. for (int i = 0; i < strDataTemp.Length; i++)
  4539. {
  4540. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  4541. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  4542. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  4543. }
  4544. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  4545. return;
  4546. }
  4547. catch (Exception)
  4548. {
  4549. timer_500ms.Enabled = false;
  4550. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4551. timer_500ms.Enabled = true;
  4552. }
  4553. Delay_ms(200);
  4554. //电机退出配置模式
  4555. var RunMode = new byte[1];
  4556. RunMode[0] = 0x00;
  4557. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  4558. }
  4559. }
  4560. /// <summary>
  4561. /// 生产模式写入型号
  4562. /// </summary>
  4563. /// <param name="sender"></param>
  4564. /// <param name="e"></param>
  4565. private void button_FacModeSetName_Click(object sender, EventArgs e)
  4566. {
  4567. string Mode = textBox_FacModeName.Text;
  4568. var ModeArray = new byte[16];
  4569. for (ushort i = 0; i < Mode.Length; i++)
  4570. {
  4571. ModeArray[i] = (byte)Mode[i];
  4572. }
  4573. if (Mode.Length < 16)
  4574. {
  4575. ModeArray[Mode.Length] = (byte)'.';
  4576. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  4577. {
  4578. ModeArray[Mode.Length + 1 + i] = 0x20;
  4579. }
  4580. }
  4581. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  4582. }
  4583. /// <summary>
  4584. /// 生产模式写入SN
  4585. /// </summary>
  4586. /// <param name="sender"></param>
  4587. /// <param name="e"></param>
  4588. private void Button_FacModeSetNum_Click(object sender, EventArgs e)
  4589. {
  4590. string SN = textBox_FacModeNum.Text;
  4591. var SNArray = new byte[16];
  4592. for (ushort i = 0; i < SN.Length; i++)
  4593. {
  4594. SNArray[i] = (byte)SN[i];
  4595. }
  4596. if (SN.Length < 16)
  4597. {
  4598. SNArray[SN.Length] = (byte)'.';
  4599. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  4600. {
  4601. SNArray[SN.Length + 1 + i] = 0x20;
  4602. }
  4603. }
  4604. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  4605. }
  4606. /// <summary>
  4607. /// 生产模式读取版本信息
  4608. /// </summary>
  4609. /// <param name="sender"></param>
  4610. /// <param name="e"></param>
  4611. private void Button_FacModeReadVer_Click_1(object sender, EventArgs e)
  4612. {
  4613. textBox_Model.Text = "---";
  4614. textBox_SN.Text = "---";
  4615. textBox_HW.Text = "---";
  4616. textBox_FW.Text = "---";
  4617. textBox_SP.Text = "---";
  4618. textBox_OBC_ReadModel.Text = "---";
  4619. textBox_OBC_ReadSN.Text = "---";
  4620. textBox_OBC_ReadHW.Text = "---";
  4621. textBox_OBC_ReadFW.Text = "---";
  4622. textBox_OBC_ReadSP.Text = "---";
  4623. textBox_FacModeName.Text = "---";
  4624. textBox_FacModeNum.Text = "---";
  4625. textBox_FacModeHW.Text = "---";
  4626. textBox_FacModeFW.Text = "---";
  4627. textBox_FacModeSP.Text = "---";
  4628. textBox_FacModeGit.Text = "---";
  4629. Class_Motor_Ver.Mode = "---";
  4630. Class_Motor_Ver.SN = "---";
  4631. Class_Motor_Ver.HW = "---";
  4632. Class_Motor_Ver.FW = "---";
  4633. Class_Motor_Ver.Special = "---";
  4634. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  4635. }
  4636. /// <summary>
  4637. /// 生产模式写入生产信息
  4638. /// </summary>
  4639. /// <param name="sender"></param>
  4640. /// <param name="e"></param>
  4641. private void Button_FacModeSetMacDate_Click(object sender, EventArgs e)
  4642. {
  4643. var MACArray = new byte[32];
  4644. string MacDefaultInfo = "";
  4645. string MacAddDefaultInfo = "";
  4646. string MacDateDefaultInfo = DateTime.Now.ToString("yyyyMMdd");
  4647. string MacPPDefaultInfo = "";
  4648. do
  4649. {
  4650. //填入生产商
  4651. if (toolStripTextBox_MAC.Text == string.Empty)
  4652. {
  4653. break;
  4654. }
  4655. MacDefaultInfo = toolStripTextBox_MAC.Text;
  4656. for (ushort i = 0; i < MacDefaultInfo.Length; i++)
  4657. {
  4658. MACArray[i] = (byte)MacDefaultInfo[i];
  4659. }
  4660. if (MacDefaultInfo.Length < 8)
  4661. {
  4662. MACArray[MacDefaultInfo.Length] = (byte)'.';
  4663. for (ushort i = 0; i < 8 - MacDefaultInfo.Length - 1; i++)
  4664. {
  4665. MACArray[MacDefaultInfo.Length + 1 + i] = 0x20;
  4666. }
  4667. }
  4668. //填入生产地
  4669. if (toolStripTextBoxMACAddr.Text == string.Empty)
  4670. {
  4671. break;
  4672. }
  4673. MacAddDefaultInfo = toolStripTextBoxMACAddr.Text;
  4674. for (ushort i = 0; i < MacAddDefaultInfo.Length; i++)
  4675. {
  4676. MACArray[8 + i] = (byte)MacAddDefaultInfo[i];
  4677. }
  4678. if (MacAddDefaultInfo.Length < 8)
  4679. {
  4680. MACArray[MacAddDefaultInfo.Length + 8] = (byte)'.';
  4681. for (ushort i = 0; i < 8 - MacAddDefaultInfo.Length - 1; i++)
  4682. {
  4683. MACArray[MacAddDefaultInfo.Length + 1 + i + 8] = 0x20;
  4684. }
  4685. }
  4686. //填入生产日期
  4687. if (toolStripTextBox_MACDate.Text == string.Empty)
  4688. {
  4689. break;
  4690. }
  4691. MacDateDefaultInfo = toolStripTextBox_MACDate.Text;
  4692. for (ushort i = 0; i < MacDateDefaultInfo.Length; i++)
  4693. {
  4694. MACArray[16 + i] = (byte)MacDateDefaultInfo[i];
  4695. }
  4696. if (MacDateDefaultInfo.Length < 8)
  4697. {
  4698. MACArray[MacDateDefaultInfo.Length + 16] = (byte)'.';
  4699. for (ushort i = 0; i < 8 - MacDateDefaultInfo.Length - 1; i++)
  4700. {
  4701. MACArray[MacDateDefaultInfo.Length + 1 + i + 16] = 0x20;
  4702. }
  4703. }
  4704. //填入产品标识
  4705. if (toolStripTextBox_MACPD.Text == string.Empty)
  4706. {
  4707. break;
  4708. }
  4709. MacPPDefaultInfo = toolStripTextBox_MACPD.Text;
  4710. for (ushort i = 0; i < MacPPDefaultInfo.Length; i++)
  4711. {
  4712. MACArray[24 + i] = (byte)MacPPDefaultInfo[i];
  4713. }
  4714. if (MacPPDefaultInfo.Length < 8)
  4715. {
  4716. MACArray[MacPPDefaultInfo.Length + 24] = (byte)'.';
  4717. for (ushort i = 0; i < 8 - MacPPDefaultInfo.Length - 1; i++)
  4718. {
  4719. MACArray[MacPPDefaultInfo.Length + 1 + i + 24] = 0x20;
  4720. }
  4721. }
  4722. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  4723. return;
  4724. } while (false);
  4725. timer_500ms.Enabled = false;
  4726. MessageBox.Show("生产信息配置不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4727. timer_500ms.Enabled = true;
  4728. }
  4729. /// <summary>
  4730. /// 生产模式保存测试页面
  4731. /// </summary>
  4732. /// <param name="sender"></param>
  4733. /// <param name="e"></param>
  4734. private void Button_FacModeSaveResult_Click(object sender, EventArgs e)
  4735. {
  4736. Button_FacModeSaveResult.Text = "存储中…";
  4737. string[] AssistParams = new string[15];
  4738. do
  4739. {
  4740. //读取一次马达参数
  4741. richTextBox_MotorParam.Clear();
  4742. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break; ;
  4743. Delay_ms(100);
  4744. //读取一次整车参数
  4745. richTextBox_BikeParam.Clear();
  4746. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  4747. Delay_ms(100);
  4748. //读取一次整车参数2
  4749. richTextBox_BikeParam2.Clear();
  4750. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null)) break;
  4751. Delay_ms(100);
  4752. //读取一次控制参数
  4753. richTextBox_ControlParam.Clear();
  4754. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  4755. Delay_ms(100);
  4756. //查询传感器
  4757. richTextBox_SensorParam.Clear();
  4758. textBox_FacModeSensorADC0.Text = "";
  4759. textBox_FacModeSensorADC1.Text = "";
  4760. textBox_FacModeSensorADC2.Text = "";
  4761. textBox_FacModeSensorADC3.Text = "";
  4762. textBox_FacModeSensorADC4.Text = "";
  4763. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  4764. Delay_ms(100);
  4765. //读取15次助力参数
  4766. for (int i = 1; i <= 15; i++)
  4767. {
  4768. var ConfigParam = new byte[4];
  4769. richTextBox_AssistParam.Clear();
  4770. ConfigParam[0] = (byte)(i & 0xFF);
  4771. ConfigParam[1] = (byte)(i >> 8);
  4772. ConfigParam[2] = (byte)(((i >= 5) ? 5 : i) & 0xFF);
  4773. ConfigParam[3] = (byte)(((i >= 5) ? 5 : i) >> 8);
  4774. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  4775. Delay_ms(200);
  4776. AssistParams[i - 1] = richTextBox_AssistParam.Text + "\r\n";
  4777. }
  4778. //读取一次用户骑行参数
  4779. richTextBox_UsrRidesParam.Clear();
  4780. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  4781. Delay_ms(100);
  4782. //读取一次调试信息
  4783. richTextBox_DebugParam.Clear();
  4784. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  4785. Delay_ms(100);
  4786. //读取一次历史信息
  4787. richTextBox_Record.Clear();
  4788. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  4789. Delay_ms(100);
  4790. //读取一次电机运行信息
  4791. var CtrlCode = new byte[2];
  4792. CtrlCode[0] = 0x00;
  4793. CtrlCode[1] = 0xF0;
  4794. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode)) break;
  4795. Delay_ms(100);
  4796. //读取一次版本信息
  4797. textBox_Model.Text = "---";
  4798. textBox_SN.Text = "---";
  4799. textBox_HW.Text = "---";
  4800. textBox_FW.Text = "---";
  4801. textBox_OBC_ReadModel.Text = "---";
  4802. textBox_OBC_ReadSN.Text = "---";
  4803. textBox_OBC_ReadHW.Text = "---";
  4804. textBox_OBC_ReadFW.Text = "---";
  4805. textBox_FacModeName.Text = "---";
  4806. textBox_FacModeNum.Text = "---";
  4807. textBox_FacModeHW.Text = "---";
  4808. textBox_FacModeFW.Text = "---";
  4809. Class_Motor_Ver.Mode = "---";
  4810. Class_Motor_Ver.SN = "---";
  4811. Class_Motor_Ver.HW = "---";
  4812. Class_Motor_Ver.FW = "---";
  4813. Class_Motor_Ver.Special = "---";
  4814. if (!mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null)) break;
  4815. Delay_ms(100);
  4816. //读取一次生产信息
  4817. textBox_MAC.Text = "";
  4818. textBox_MACAdd.Text = "";
  4819. textBox_MACDate.Text = "";
  4820. textBox_PP.Text = "";
  4821. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  4822. Delay_ms(100);
  4823. //读取一次自定义信息
  4824. textBox_User1.Text = "---";
  4825. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  4826. Delay_ms(100);
  4827. textBox_User2.Text = "---";
  4828. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  4829. Delay_ms(100);
  4830. textBox_User3.Text = "---";
  4831. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  4832. Delay_ms(100);
  4833. //读取一次密钥
  4834. textBox_Key.Text = "---";
  4835. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  4836. Delay_ms(100);
  4837. //读取一次存储标志
  4838. radioButton_EE_SaveYes.Checked = false;
  4839. radioButton_EE_SaveNo.Checked = false;
  4840. radioButton_SIP_SaveYes.Checked = false;
  4841. radioButton_SIP_SaveNo.Checked = false;
  4842. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  4843. Delay_ms(100);
  4844. //读取一次MOS内阻校准参数
  4845. foreach (Control c in groupBox21.Controls)
  4846. {
  4847. if (c is TextBox)
  4848. c.Text = "";
  4849. }
  4850. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  4851. Delay_ms(100);
  4852. //提示检查
  4853. #if false
  4854. timer_1s.Enabled = false;
  4855. if (MessageBox.Show("请检查信息是否完整!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  4856. {
  4857. MessageBox.Show("请检查参数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4858. timer_1s.Enabled = true;
  4859. return;
  4860. }
  4861. timer_1s.Enabled = true;
  4862. Delay_ms(200);
  4863. #endif
  4864. //判断数据是否有效
  4865. if ((textBox_FacModeName.Text == "---") || (textBox_FacModeNum.Text == "---"))
  4866. {
  4867. MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4868. break;
  4869. }
  4870. if ((textBox_FacModeName.Text == string.Empty) || (textBox_FacModeNum.Text == string.Empty))
  4871. {
  4872. MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4873. break;
  4874. }
  4875. //设置文件存储路径
  4876. string Save_Path = localInfo.LocalPath + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
  4877. string PD_PathName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_"); ;
  4878. Save_Path += PD_PathName;
  4879. if (!Directory.Exists(Save_Path))
  4880. Directory.CreateDirectory(Save_Path);
  4881. //保存页面
  4882. string PIC_SaveFileName = "";
  4883. Double scaleX = PrimaryScreen.ScaleX;
  4884. Double scaleY = PrimaryScreen.ScaleY;
  4885. //保存页面
  4886. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  4887. Graphics g = Graphics.FromImage(bit);
  4888. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  4889. PIC_SaveFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_测试页面" + ".png";
  4890. bit.Save(PIC_SaveFileName);
  4891. //保存数据
  4892. string DataFileName = "";
  4893. string FileInfo = "";
  4894. DataFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_记录数据" + ".txt";
  4895. FileInfo += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  4896. FileInfo += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  4897. FileInfo += "\r\n";
  4898. FileInfo += "[电机信息]\r\n";
  4899. FileInfo += "电机型号: " + textBox_FacModeName.Text + "\r\n";
  4900. FileInfo += "电机编号: " + textBox_FacModeNum.Text + "\r\n";
  4901. FileInfo += "硬件版本: " + textBox_HW.Text + "\r\n";
  4902. FileInfo += "软件版本: " + textBox_FW.Text + "\r\n";
  4903. FileInfo += "软件标识: " + textBox_SP.Text + "\r\n";
  4904. FileInfo += "Git信息: " + textBox_FacModeGit.Text + "\r\n";
  4905. FileInfo += "\r\n";
  4906. FileInfo += "[马达参数]\r\n";
  4907. FileInfo += richTextBox_MotorParam.Text + "\r\n";
  4908. FileInfo += "\r\n";
  4909. FileInfo += "[整车参数]\r\n";
  4910. FileInfo += richTextBox_BikeParam.Text + "\r\n";
  4911. FileInfo += "\r\n";
  4912. FileInfo += "[控制参数]\r\n";
  4913. FileInfo += richTextBox_ControlParam.Text + "\r\n";
  4914. FileInfo += "\r\n";
  4915. FileInfo += "[传感器参数]\r\n";
  4916. FileInfo += richTextBox_SensorParam.Text + "\r\n";
  4917. FileInfo += "\r\n";
  4918. FileInfo += "[助力参数]\r\n";
  4919. for(int i=0;i<15;i++)
  4920. {
  4921. FileInfo += AssistParams[i] + "\r\n";
  4922. }
  4923. FileInfo += "[调试参数]\r\n";
  4924. FileInfo += richTextBox_DebugParam.Text + "\r\n";
  4925. FileInfo += "\r\n";
  4926. FileInfo += "[历史信息]\r\n";
  4927. FileInfo += richTextBox_Record.Text + "\r\n";
  4928. FileInfo += "\r\n";
  4929. FileInfo += "[MOS内阻校准参数]\r\n";
  4930. FileInfo += textBox_MOS_K1.Text + ", ";
  4931. FileInfo += textBox_MOS_K2.Text + ", ";
  4932. FileInfo += textBox_MOS_K3.Text + ", ";
  4933. FileInfo += textBox_MOS_K4.Text + ", ";
  4934. FileInfo += textBox_MOS_K5.Text + ", ";
  4935. FileInfo += textBox_MOS_R1.Text + ", ";
  4936. FileInfo += textBox_MOS_R2.Text + ", ";
  4937. FileInfo += textBox_MOS_R3.Text + "\r\n";
  4938. FileInfo += "\r\n";
  4939. FileInfo += "[整车参数2]\r\n";
  4940. FileInfo += richTextBox_BikeParam2.Text + "\r\n";
  4941. FileInfo += "\r\n";
  4942. FileInfo += "[用户骑行参数]\r\n";
  4943. FileInfo += richTextBox_UsrRidesParam.Text + "\r\n";
  4944. FileInfo += "\r\n";
  4945. FileInfo += "[生产信息]\r\n";
  4946. FileInfo += "生产商: " + textBox_MAC.Text + "\r\n";
  4947. FileInfo += "生产地: " + textBox_MACAdd.Text + "\r\n";
  4948. FileInfo += "生产日期: " + textBox_MACDate.Text + "\r\n";
  4949. FileInfo += "产品标识: " + textBox_PP.Text + "\r\n";
  4950. FileInfo += "\r\n";
  4951. FileInfo += "[自定义信息]\r\n";
  4952. FileInfo += "自定义1: " + textBox_User1.Text + "\r\n";
  4953. FileInfo += "自定义2: " + textBox_User2.Text + "\r\n";
  4954. FileInfo += "自定义3: " + textBox_User3.Text + "\r\n";
  4955. FileInfo += "\r\n";
  4956. FileInfo += "[校验密钥]\r\n";
  4957. FileInfo += textBox_Key.Text + "\r\n";
  4958. FileInfo += "\r\n";
  4959. FileInfo += "[存储标志]\r\n";
  4960. FileInfo += "EEPROM: " + ((radioButton_EE_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  4961. FileInfo += "SIP: " + ((radioButton_SIP_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  4962. FileInfo += "\r\n";
  4963. FileInfo += Local_HdInformation;
  4964. FileInfo += "\r\n";
  4965. FileInfo += "文件格式: V2.0\r\n";
  4966. System.IO.File.WriteAllText(DataFileName, FileInfo);
  4967. Delay_ms(1000);
  4968. timer_500ms.Enabled = false;
  4969. MessageBox.Show("存储完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  4970. timer_500ms.Enabled = true;
  4971. //数据上传
  4972. if (myFtp.IsNetConnected == true)
  4973. {
  4974. string DataNow = DateTime.Now.ToString("yyyy-MM-dd");
  4975. //检查路径
  4976. if (myFtp.DirectoryExist("\\", toolStripTextBox_ServerPath.Text) == false)
  4977. {
  4978. myFtp.MakeDir(toolStripTextBox_ServerPath.Text);
  4979. }
  4980. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text, "Samples") == false)
  4981. {
  4982. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples");
  4983. }
  4984. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples", DataNow) == false)
  4985. {
  4986. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow);
  4987. }
  4988. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow, PD_PathName) == false)
  4989. {
  4990. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4991. }
  4992. //上传文件
  4993. bool result1 = myFtp.UploadFile(PIC_SaveFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4994. bool result2 = myFtp.UploadFile(DataFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4995. if ((result1 & result2) == true)
  4996. {
  4997. MessageBoxTimeOut.Show("数据已上传!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  4998. }
  4999. else
  5000. {
  5001. timer_500ms.Enabled = false;
  5002. MessageBox.Show("数据上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5003. timer_500ms.Enabled = true;
  5004. }
  5005. }
  5006. else
  5007. {
  5008. timer_500ms.Enabled = false;
  5009. MessageBox.Show("服务器断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5010. timer_500ms.Enabled = true;
  5011. }
  5012. Button_FacModeSaveResult.Text = "保存数据";
  5013. return;
  5014. } while (false);
  5015. timer_500ms.Enabled = false;
  5016. MessageBox.Show("保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5017. timer_500ms.Enabled = true;
  5018. Button_FacModeSaveResult.Text = "保存数据";
  5019. }
  5020. /// <summary>
  5021. /// 工具箱页面保存
  5022. /// </summary>
  5023. /// <param name="sender"></param>
  5024. /// <param name="e"></param>
  5025. private void 页面保存ToolStripMenuItem_Click(object sender, EventArgs e)
  5026. {
  5027. Double scaleX = PrimaryScreen.ScaleX;
  5028. Double scaleY = PrimaryScreen.ScaleY;
  5029. //保存页面
  5030. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  5031. Graphics g = Graphics.FromImage(bit);
  5032. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  5033. SaveFileDialog sf = new SaveFileDialog();
  5034. sf.Title = "页面保存";
  5035. sf.FileName = "MotorInfo_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".png";
  5036. sf.Filter = "图片|*.png";
  5037. timer_500ms.Enabled = false;
  5038. if (sf.ShowDialog() == DialogResult.OK)
  5039. {
  5040. bit.Save(sf.FileName);//默认保存格式为PNG,保存成jpg格式质量不是很好
  5041. }
  5042. timer_500ms.Enabled = true;
  5043. }
  5044. /// <summary>
  5045. /// 生产模式关机
  5046. /// </summary>
  5047. /// <param name="sender"></param>
  5048. /// <param name="e"></param>
  5049. private void Button_FacModePowerOff_Click(object sender, EventArgs e)
  5050. {
  5051. var Code_Off = new byte[5];
  5052. var Code_Reset = new byte[5];
  5053. Code_Off[0] = (byte)'O';
  5054. Code_Off[1] = (byte)'F';
  5055. Code_Off[2] = (byte)'F';
  5056. Code_Off[3] = (byte)'.';
  5057. Code_Off[4] = (byte)'.';
  5058. Code_Reset[0] = (byte)'R';
  5059. Code_Reset[1] = (byte)'E';
  5060. Code_Reset[2] = (byte)'S';
  5061. Code_Reset[3] = (byte)'E';
  5062. Code_Reset[4] = (byte)'T';
  5063. timer_500ms.Enabled = false;
  5064. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  5065. {
  5066. timer_500ms.Enabled = true;
  5067. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  5068. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  5069. PowerOffAckStatus = false;
  5070. Delay_ms(250);
  5071. int TryCnt = 3;
  5072. while ((TryCnt--) >= 0)
  5073. {
  5074. if (!PowerOffAckStatus)
  5075. {
  5076. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  5077. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  5078. PowerOffAckStatus = false;
  5079. Delay_ms(250);
  5080. }
  5081. else break;
  5082. }
  5083. if (PowerOffAckStatus)
  5084. {
  5085. timer_500ms.Enabled = false;
  5086. MessageBox.Show("已关机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  5087. timer_500ms.Enabled = true;
  5088. }
  5089. else
  5090. {
  5091. timer_500ms.Enabled = false;
  5092. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5093. timer_500ms.Enabled = true;
  5094. }
  5095. }
  5096. timer_500ms.Enabled = true;
  5097. }
  5098. //仪表电源键按下
  5099. private void button_OBC_ButtonPower_Click(object sender, EventArgs e)
  5100. {
  5101. var Code = new byte[2];
  5102. Code[0] = 0;
  5103. Code[1] = 0b00100000;
  5104. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5105. }
  5106. /// <summary>
  5107. /// 仪表加键按下
  5108. /// </summary>
  5109. /// <param name="sender"></param>
  5110. /// <param name="e"></param>
  5111. private void button_OBC_ButtonAcc_Click(object sender, EventArgs e)
  5112. {
  5113. var Code = new byte[2];
  5114. Code[0] = 0;
  5115. Code[1] = 0b00010000;
  5116. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5117. }
  5118. /// <summary>
  5119. /// 仪表减键按下
  5120. /// </summary>
  5121. /// <param name="sender"></param>
  5122. /// <param name="e"></param>
  5123. private void button_OBC_ButtonDec_Click(object sender, EventArgs e)
  5124. {
  5125. var Code = new byte[2];
  5126. Code[0] = 0;
  5127. Code[1] = 0b00001000;
  5128. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5129. }
  5130. /// <summary>
  5131. /// 仪表Walk键按下
  5132. /// </summary>
  5133. /// <param name="sender"></param>
  5134. /// <param name="e"></param>
  5135. private void button_OBC_ButtonWalk_Click(object sender, EventArgs e)
  5136. {
  5137. var Code = new byte[2];
  5138. Code[0] = 0;
  5139. Code[1] = 0b00000100;
  5140. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5141. }
  5142. /// <summary>
  5143. /// 仪表Light键按下
  5144. /// </summary>
  5145. /// <param name="sender"></param>
  5146. /// <param name="e"></param>
  5147. private void button_OBC_ButtonLight_Click(object sender, EventArgs e)
  5148. {
  5149. var Code = new byte[2];
  5150. Code[0] = 0;
  5151. Code[1] = 0b00000010;
  5152. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5153. }
  5154. /// <summary>
  5155. /// 仪表Set键按下
  5156. /// </summary>
  5157. /// <param name="sender"></param>
  5158. /// <param name="e"></param>
  5159. private void button_OBC_ButtonSet_Click(object sender, EventArgs e)
  5160. {
  5161. var Code = new byte[2];
  5162. Code[0] = 0;
  5163. Code[1] = 0b00000001;
  5164. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5165. }
  5166. /// <summary>
  5167. /// 导出电机故障日志
  5168. /// </summary>
  5169. /// <param name="sender"></param>
  5170. /// <param name="e"></param>
  5171. private void button_ExportLog_Click(object sender, EventArgs e)
  5172. {
  5173. var Address = new byte[4];
  5174. UInt32 Address_Begin;
  5175. UInt32 Addres_End;
  5176. string textBox_Address_Begin = textBox_LogAddrBegin.Text;
  5177. string textBox_Address_End = textBox_LogAddrEnd.Text;
  5178. richTextBox_Record.Clear();
  5179. textBox_LogAddrBegin.ReadOnly = true;
  5180. textBox_LogAddrEnd.ReadOnly = true;
  5181. if (!mySerialProcess.mySerial.IsOpen)
  5182. {
  5183. timer_500ms.Enabled = false;
  5184. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5185. timer_500ms.Enabled = true;
  5186. return;
  5187. }
  5188. if ((textBox_Address_Begin == string.Empty) || (textBox_Address_End == string.Empty))
  5189. {
  5190. timer_500ms.Enabled = false;
  5191. MessageBox.Show("请输入日志存储起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5192. timer_500ms.Enabled = true;
  5193. return;
  5194. }
  5195. else
  5196. {
  5197. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin, false);
  5198. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  5199. Address = mySerialProcess.HexStringToBytes(textBox_Address_End, false);
  5200. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  5201. if (Addres_End <= Address_Begin)
  5202. {
  5203. timer_500ms.Enabled = false;
  5204. MessageBox.Show("结束地址应大于起始地址!", "提示");
  5205. timer_500ms.Enabled = true;
  5206. return;
  5207. }
  5208. else if (((Addres_End - Address_Begin + 1) % 128) != 0) //
  5209. {
  5210. timer_500ms.Enabled = false;
  5211. MessageBox.Show("(结束地址 - 起始地址 + 1)应为128整数倍!", "提示");
  5212. timer_500ms.Enabled = true;
  5213. return;
  5214. }
  5215. else
  5216. {
  5217. UInt32 ReadCount = 0;
  5218. button_ExportLog.Text = "导出中...";
  5219. button_ExportLog.Enabled = false;
  5220. ReadCount = (Addres_End - Address_Begin + 1) / 128;
  5221. for (ushort i = 0; i < ReadCount; i++)
  5222. {
  5223. var SendByte = new byte[8];
  5224. UInt32 Address_Temp_Begin;
  5225. UInt32 Address_Temp_End;
  5226. Address_Temp_Begin = Address_Begin + 128 * (UInt32)i;
  5227. SendByte[0] = (byte)(Address_Temp_Begin >> 24);
  5228. SendByte[1] = (byte)(Address_Temp_Begin >> 16);
  5229. SendByte[2] = (byte)(Address_Temp_Begin >> 8);
  5230. SendByte[3] = (byte)(Address_Temp_Begin);
  5231. Address_Temp_End = Address_Temp_Begin + 127;
  5232. SendByte[4] = (byte)(Address_Temp_End >> 24);
  5233. SendByte[5] = (byte)(Address_Temp_End >> 16);
  5234. SendByte[6] = (byte)(Address_Temp_End >> 8);
  5235. SendByte[7] = (byte)(Address_Temp_End);
  5236. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  5237. Delay_ms(200);//Thread.Sleep(200);
  5238. }
  5239. button_ExportLog.Text = "导出日志";
  5240. button_ExportLog.Enabled = true;
  5241. }
  5242. }
  5243. }
  5244. /// <summary>
  5245. /// 保存日志信息
  5246. /// </summary>
  5247. /// <param name="sender"></param>
  5248. /// <param name="e"></param>
  5249. private void button_SaveRecordInfo_Click(object sender, EventArgs e)
  5250. {
  5251. string SaveInfo = "";
  5252. if (richTextBox_Record.Text == string.Empty)
  5253. {
  5254. timer_500ms.Enabled = false;
  5255. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  5256. timer_500ms.Enabled = true;
  5257. return;
  5258. }
  5259. //获取保存信息
  5260. SaveInfo += "读取时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  5261. SaveInfo += "电机型号:" + textBox_FacModeName.Text + "\r\n";
  5262. SaveInfo += "电机SN:" + textBox_FacModeNum.Text + "\r\n";
  5263. SaveInfo += "硬件版本:" + textBox_FacModeHW.Text + "\r\n";
  5264. SaveInfo += "软件版本:" + textBox_FacModeFW.Text + "\r\n";
  5265. SaveInfo += "\r\n";
  5266. SaveInfo += richTextBox_Record.Text;
  5267. //设置保存路径和文件名
  5268. SaveFileDialog sf = new SaveFileDialog();
  5269. sf.Title = "数据保存";
  5270. sf.FileName = "MotorLog_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".ttlog";
  5271. sf.FileName.Replace(" ", "");
  5272. sf.Filter = "日志|*.ttlog";
  5273. if (sf.ShowDialog() == DialogResult.OK)
  5274. {
  5275. System.IO.File.AppendAllText(sf.FileName, SaveInfo);
  5276. }
  5277. }
  5278. /// <summary>
  5279. /// 双击修改日志起始地址
  5280. /// </summary>
  5281. /// <param name="sender"></param>
  5282. /// <param name="e"></param>
  5283. private void label_LogAddrBegin_DoubleClick_1(object sender, EventArgs e)
  5284. {
  5285. textBox_LogAddrBegin.ReadOnly = false;
  5286. }
  5287. /// <summary>
  5288. /// 双击修改日志结束地址
  5289. /// </summary>
  5290. /// <param name="sender"></param>
  5291. /// <param name="e"></param>
  5292. private void label88_DoubleClick(object sender, EventArgs e)
  5293. {
  5294. textBox_LogAddrEnd.ReadOnly = false;
  5295. }
  5296. /// <summary>
  5297. /// 存储器自动读取选择
  5298. /// </summary>
  5299. /// <param name="sender"></param>
  5300. /// <param name="e"></param>
  5301. private void checkBox_ReadRanFlash_AutoSW_CheckedChanged(object sender, EventArgs e)
  5302. {
  5303. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  5304. {
  5305. //检查串口是否打开
  5306. if (!mySerialProcess.mySerial.IsOpen)
  5307. {
  5308. timer_500ms.Enabled = false;
  5309. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5310. timer_500ms.Enabled = true;
  5311. checkBox_ReadRanFlash_AutoSW.Checked = false;
  5312. return;
  5313. }
  5314. }
  5315. }
  5316. /// <summary>
  5317. /// 系统开机按钮
  5318. /// </summary>
  5319. /// <param name="sender"></param>
  5320. /// <param name="e"></param>
  5321. private void 开机ToolStripMenuItem_Click(object sender, EventArgs e)
  5322. {
  5323. byte[] Data = new byte[1];
  5324. Data[0] = 0xF1;
  5325. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  5326. }
  5327. /// <summary>
  5328. /// 系统关机按钮
  5329. /// </summary>
  5330. /// <param name="sender"></param>
  5331. /// <param name="e"></param>
  5332. private void 关机ToolStripMenuItem_Click(object sender, EventArgs e)
  5333. {
  5334. byte[] Data = new byte[1];
  5335. Data[0] = 0xF0;
  5336. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  5337. }
  5338. /// <summary>
  5339. /// 连接开机选择
  5340. /// </summary>
  5341. /// <param name="sender"></param>
  5342. /// <param name="e"></param>
  5343. private void 连接开机ToolStripMenuItem_Click(object sender, EventArgs e)
  5344. {
  5345. //输入用户名
  5346. EnterForm1.ShowDialog();
  5347. try
  5348. {
  5349. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5350. {
  5351. if (EnterForm1.comboBox_User.Text == "管理员")
  5352. {
  5353. 连接开机ToolStripMenuItem.Checked = !连接开机ToolStripMenuItem.Checked;
  5354. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5355. }
  5356. else
  5357. {
  5358. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5359. }
  5360. }
  5361. else
  5362. {
  5363. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5364. }
  5365. }
  5366. catch (Exception)
  5367. {
  5368. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5369. }
  5370. }
  5371. /// <summary>
  5372. /// 断开关机选择
  5373. /// </summary>
  5374. /// <param name="sender"></param>
  5375. /// <param name="e"></param>
  5376. private void 断开关机ToolStripMenuItem_Click(object sender, EventArgs e)
  5377. {
  5378. //输入用户名
  5379. EnterForm1.ShowDialog();
  5380. try
  5381. {
  5382. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5383. {
  5384. if (EnterForm1.comboBox_User.Text == "管理员")
  5385. {
  5386. 断开关机ToolStripMenuItem.Checked = !断开关机ToolStripMenuItem.Checked;
  5387. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5388. }
  5389. else
  5390. {
  5391. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5392. }
  5393. }
  5394. else
  5395. {
  5396. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5397. }
  5398. }
  5399. catch (Exception)
  5400. {
  5401. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5402. }
  5403. }
  5404. /// <summary>
  5405. /// 识别通讯盒选择
  5406. /// </summary>
  5407. /// <param name="sender"></param>
  5408. /// <param name="e"></param>
  5409. private void 识别通讯盒ToolStripMenuItem_Click(object sender, EventArgs e)
  5410. {
  5411. //输入用户名
  5412. EnterForm1.ShowDialog();
  5413. try
  5414. {
  5415. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5416. {
  5417. if (EnterForm1.comboBox_User.Text == "管理员")
  5418. {
  5419. 识别通讯盒ToolStripMenuItem.Checked = !识别通讯盒ToolStripMenuItem.Checked;
  5420. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5421. }
  5422. else
  5423. {
  5424. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5425. }
  5426. }
  5427. else
  5428. {
  5429. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5430. }
  5431. }
  5432. catch (Exception)
  5433. {
  5434. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5435. }
  5436. }
  5437. /// <summary>
  5438. /// 将配置信息导出为cfg文件
  5439. /// </summary>
  5440. private void ConfigFileSave(bool DeleteFlag, string FileName)
  5441. {
  5442. if (DeleteFlag)
  5443. {
  5444. if (File.Exists(FileName))
  5445. File.Delete(FileName);
  5446. }
  5447. string CfgFileInfo = "";
  5448. CfgFileInfo += "[PortSet]" + "\r\n";
  5449. CfgFileInfo += "PortNum:" + toolStripComboBox_ComNum.Text + "\r\n";
  5450. CfgFileInfo += "PortBaudrate:" + "115200" + "\r\n";
  5451. CfgFileInfo += "AutoOn:" + 连接开机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5452. CfgFileInfo += "AutoOff:" + 断开关机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5453. CfgFileInfo += "CheckCDL:" + 识别通讯盒ToolStripMenuItem.Checked.ToString() + "\r\n";
  5454. CfgFileInfo += "\r\n";
  5455. CfgFileInfo += "[Option]" + "\r\n";
  5456. CfgFileInfo += "SaveWhenWrite:" + 写入存储ToolStripMenuItem.Checked.ToString() + "\r\n";
  5457. CfgFileInfo += "\r\n";
  5458. CfgFileInfo += "[ServerSet]" + "\r\n";
  5459. CfgFileInfo += "PathName:" + toolStripTextBox_ServerPath.Text + "\r\n";
  5460. CfgFileInfo += "\r\n";
  5461. CfgFileInfo += "[MacInfo]" + "\r\n";
  5462. CfgFileInfo += "MacName:" + toolStripTextBox_MAC.Text + "\r\n";
  5463. CfgFileInfo += "MacAddress:" + toolStripTextBoxMACAddr.Text + "\r\n";
  5464. CfgFileInfo += "MacDate:" + toolStripTextBox_MACDate.Text + "\r\n";
  5465. CfgFileInfo += "MacPdInfo:" + toolStripTextBox_MACPD.Text + "\r\n";
  5466. CfgFileInfo += "\r\n";
  5467. CfgFileInfo += "[LogAddress]" + "\r\n";
  5468. CfgFileInfo += "BeginAddress:" + textBox_LogAddrBegin.Text + "\r\n";
  5469. CfgFileInfo += "EndAddress:" + textBox_LogAddrEnd.Text + "\r\n";
  5470. CfgFileInfo += "\r\n";
  5471. CfgFileInfo += "[MotorType]" + "\r\n";
  5472. CfgFileInfo += "MidMotor1:" + 中置电机MIGIC_ToolStripMenuItem.Checked.ToString() + "\r\n";
  5473. CfgFileInfo += "MidMotor2:" + 中置电机VP_ToolStripMenuItem.Checked.ToString() + "\r\n";
  5474. CfgFileInfo += "HubMotor:" + 轮毂电机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5475. CfgFileInfo += "\r\n";
  5476. CfgFileInfo += "[CheckValue]" + "\r\n";
  5477. CfgFileInfo += "Voltage:" + toolStripTextBox_ThVol.Text + "\r\n";
  5478. CfgFileInfo += "Current:" + toolStripTextBox_ThCur.Text + "\r\n";
  5479. CfgFileInfo += "MotorSpeed:" + toolStripTextBox_ThSpeed.Text + "\r\n";
  5480. CfgFileInfo += "Torque:" + toolStripTextBox_ThTor.Text + "\r\n";
  5481. CfgFileInfo += "Cadence:" + toolStripTextBox_ThCad.Text + "\r\n";
  5482. CfgFileInfo += "BikeSpeed:" + toolStripTextBox_ThBikeSpeed.Text + "\r\n";
  5483. CfgFileInfo += "T_PCB:" + toolStripTextBox_ThT_PCB.Text + "\r\n";
  5484. CfgFileInfo += "T_MCU:" + toolStripTextBox_ThT_MCU.Text + "\r\n";
  5485. CfgFileInfo += "T_Motor:" + toolStripTextBox_ThT_Motor.Text + "\r\n";
  5486. CfgFileInfo += "\r\n";
  5487. CfgFileInfo += "[MosCalK]" + "\r\n";
  5488. CfgFileInfo += "K1-K5:" + toolStripTextBox_MosCalK.Text + "\r\n";
  5489. CfgFileInfo += "MOS1:" + toolStripTextBox_MOS1.Text + "\r\n";
  5490. CfgFileInfo += "MOS2:" + toolStripTextBox_MOS2.Text + "\r\n";
  5491. CfgFileInfo += "MOS3:" + toolStripTextBox_MOS3.Text + "\r\n";
  5492. CfgFileInfo += "\r\n";
  5493. CfgFileInfo += "[ProtocolType]" + "\r\n";
  5494. CfgFileInfo += "CAN:" + cANToolStripMenuItem.Checked.ToString() + "\r\n";
  5495. CfgFileInfo += "UART:" + uARTToolStripMenuItem.Checked.ToString() + "\r\n";
  5496. CfgFileInfo += "\r\n";
  5497. CfgFileInfo += "[AutoUpdate]" + "\r\n";
  5498. CfgFileInfo += "AutoUpdate:" + 打开ToolStripMenuItem.Checked.ToString() + "\r\n";
  5499. CfgFileInfo += "\r\n";
  5500. CfgFileInfo += "[AngleCal]" + "\r\n";
  5501. CfgFileInfo += "MaxDiffLimit:" + textBox_AngleDiffTh.Text + "\r\n";
  5502. CfgFileInfo += "ZeroDiffLimit:" + textBox_AngleZeroTh.Text + "\r\n";
  5503. System.IO.File.WriteAllText(FileName, CfgFileInfo);
  5504. }
  5505. /// <summary>
  5506. /// 配置状态更新,点击时保存
  5507. /// </summary>
  5508. private void ConfigFileSave_Click(object sender, EventArgs e)
  5509. {
  5510. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5511. }
  5512. /// <summary>
  5513. /// 文本框修改结束,回车保存
  5514. /// </summary>
  5515. /// <param name="sender"></param>
  5516. /// <param name="e"></param>
  5517. private void ConfigFileSave_KeyDown(object sender, KeyEventArgs e)
  5518. {
  5519. if (e.KeyCode == Keys.Enter)
  5520. {
  5521. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5522. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  5523. }
  5524. }
  5525. /// <summary>
  5526. /// 弹出扫码按钮
  5527. /// </summary>
  5528. /// <param name="sender"></param>
  5529. /// <param name="e"></param>
  5530. private void button_ScanCode_Click(object sender, EventArgs e)
  5531. {
  5532. Scan scan_form = new Scan();
  5533. scan_form.ShowDialog();
  5534. do
  5535. {
  5536. if (scan_form.textBox_Scan.Text == string.Empty)
  5537. {
  5538. timer_500ms.Enabled = false;
  5539. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5540. timer_500ms.Enabled = true;
  5541. break;
  5542. }
  5543. string ScanInfo = scan_form.textBox_Scan.Text;
  5544. string regexInfo = "";
  5545. string[] InfoList = { "" };
  5546. try
  5547. {
  5548. if (中置电机MIGIC_ToolStripMenuItem.Checked == true)
  5549. {
  5550. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  5551. InfoList = Regex.Split(ScanInfo, regexInfo, RegexOptions.IgnoreCase);
  5552. }
  5553. else if (中置电机VP_ToolStripMenuItem.Checked == true)
  5554. {
  5555. Regex regex = new Regex(@"^M[12][0-9](0?[1-9]|1[0-2])((0?[1-9])|((1|2)[0-9])|30|31)[A-Z]\d{4}[A-Z][A-Z]?$");
  5556. if (ScanInfo.Contains(" "))
  5557. {
  5558. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  5559. string Mode = InfoList[0];
  5560. string Sn = InfoList[1];
  5561. if (regex.IsMatch(Sn) == false)
  5562. {
  5563. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN格式错误" + "\r\n");
  5564. label_FacModeStatus.Text = "存在故障!";
  5565. label_FacModeResult.BackColor = Color.Red;
  5566. label_FacModeResult.Text = "标签格式错误";
  5567. Delay_ms(500);
  5568. //存储异常并上传
  5569. FacMode_Stop(false);
  5570. return;
  5571. }
  5572. }
  5573. else
  5574. {
  5575. MessageBox.Show("SN格式错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5576. return;
  5577. }
  5578. }
  5579. else if (轮毂电机ToolStripMenuItem.Checked == true)
  5580. {
  5581. if (!ScanInfo.Contains("/")) //老编码规则
  5582. {
  5583. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  5584. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  5585. string Spec = InfoList[1];
  5586. string Sn = InfoList[2];
  5587. InfoList[0] = Model.Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  5588. InfoList[1] = Sn;
  5589. }
  5590. else //新编码规则
  5591. {
  5592. Dictionary<string, string> Dic_Ver = new Dictionary<string, string>
  5593. {
  5594. { "01", "A" },
  5595. { "02", "B" },
  5596. { "03", "C" },
  5597. { "04", "D" },
  5598. { "05", "E" },
  5599. { "06", "F" },
  5600. { "07", "G" },
  5601. { "08", "H" },
  5602. { "09", "I" }
  5603. };
  5604. Dictionary<string, string> Dic_Vol = new Dictionary<string, string>
  5605. {
  5606. { "24V", "A" },
  5607. { "36V", "B" },
  5608. { "42V", "C" },
  5609. { "48V", "D" },
  5610. { "52V", "E" },
  5611. { "60V", "F" }
  5612. };
  5613. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  5614. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  5615. string Spec = InfoList[1].Replace("-", "").Replace("/", "");
  5616. string Sn = InfoList[2];
  5617. InfoList[0] = Model[2] + Dic_Ver[Model.Substring(3, 2)] + Model[5] + Dic_Ver[Model.Substring(6, 2)] + Model[9];
  5618. InfoList[0] += Dic_Vol[Spec.Substring(0, 3)] + Spec.Substring(3, 3) + Spec.Substring(13, 4) + Spec.Substring(Spec.Length - 4, 3);
  5619. InfoList[1] = Sn;
  5620. }
  5621. }
  5622. }
  5623. catch (Exception)
  5624. {
  5625. MessageBox.Show("格式错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5626. return;
  5627. }
  5628. if (InfoList.Length >= 2)
  5629. {
  5630. //写入型号
  5631. textBox_FacModeName.Text = InfoList[0];
  5632. string Mode = textBox_FacModeName.Text;
  5633. var ModeArray = new byte[16];
  5634. for (ushort i = 0; i < Mode.Length; i++)
  5635. {
  5636. ModeArray[i] = (byte)Mode[i];
  5637. }
  5638. if (Mode.Length < 16)
  5639. {
  5640. ModeArray[Mode.Length] = (byte)'.';
  5641. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  5642. {
  5643. ModeArray[Mode.Length + 1 + i] = 0x20;
  5644. }
  5645. }
  5646. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  5647. //写入SN
  5648. textBox_FacModeNum.Text = InfoList[1];
  5649. string SN = textBox_FacModeNum.Text;
  5650. var SNArray = new byte[16];
  5651. for (ushort i = 0; i < SN.Length; i++)
  5652. {
  5653. SNArray[i] = (byte)SN[i];
  5654. }
  5655. if (SN.Length < 16)
  5656. {
  5657. SNArray[SN.Length] = (byte)'.';
  5658. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  5659. {
  5660. SNArray[SN.Length + 1 + i] = 0x20;
  5661. }
  5662. }
  5663. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  5664. }
  5665. else
  5666. {
  5667. timer_500ms.Enabled = false;
  5668. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5669. timer_500ms.Enabled = true;
  5670. break;
  5671. }
  5672. } while (false);
  5673. scan_form.Dispose();
  5674. }
  5675. /// <summary>
  5676. /// 切换电机类型
  5677. /// </summary>
  5678. /// <param name="sender"></param>
  5679. /// <param name="e"></param>
  5680. private void 中置电机ToolStripMenuItem_Click(object sender, EventArgs e)
  5681. {
  5682. 中置电机MIGIC_ToolStripMenuItem.Checked = true;
  5683. 中置电机VP_ToolStripMenuItem.Checked = false;
  5684. 轮毂电机ToolStripMenuItem.Checked = false;
  5685. toolStripTextBox_MACPD.Text = "MM_MC1";
  5686. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  5687. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5688. }
  5689. private void 中置电机小牙盘ToolStripMenuItem_Click(object sender, EventArgs e)
  5690. {
  5691. 中置电机MIGIC_ToolStripMenuItem.Checked = false;
  5692. 中置电机VP_ToolStripMenuItem.Checked = true;
  5693. 轮毂电机ToolStripMenuItem.Checked = false;
  5694. toolStripTextBox_MACPD.Text = "MM_MV1";
  5695. toolStripTextBox_ServerPath.Text = "MC_VP_TEST";
  5696. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5697. }
  5698. /// <summary>
  5699. /// 切换电机类型
  5700. /// </summary>
  5701. /// <param name="sender"></param>
  5702. /// <param name="e"></param>
  5703. private void 轮毂电机ToolStripMenuItem_Click(object sender, EventArgs e)
  5704. {
  5705. 中置电机MIGIC_ToolStripMenuItem.Checked = false;
  5706. 中置电机VP_ToolStripMenuItem.Checked = false;
  5707. 轮毂电机ToolStripMenuItem.Checked = true;
  5708. toolStripTextBox_MACPD.Text = "GF_250_1";
  5709. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  5710. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5711. }
  5712. /// <summary>
  5713. /// 获取配置文件日期
  5714. /// </summary>
  5715. /// <param name="DisAll"></param>
  5716. private void GetDateList(bool DisAll)
  5717. {
  5718. string[] DateList = { "" };
  5719. //从服务器更新日期列表
  5720. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  5721. {
  5722. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
  5723. }
  5724. //从本地更新日期列表
  5725. else
  5726. {
  5727. DateList = Directory.GetDirectories(localInfo.LocalPath + "\\" + localInfo.CfgPathName);
  5728. }
  5729. comboBox_FacModeCfgDate.Items.Clear();
  5730. comboBox_CheckModeCfgDate.Items.Clear();
  5731. //日期列表加载
  5732. if (DisAll == true)
  5733. {
  5734. comboBox_FacModeCfgDate.Items.Add("显示近期");
  5735. comboBox_CheckModeCfgDate.Items.Add("显示近期");
  5736. comboBox_FacModeCfgDate.Items.Add("---");
  5737. comboBox_CheckModeCfgDate.Items.Add("---");
  5738. foreach (var file in DateList)
  5739. {
  5740. comboBox_FacModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5741. comboBox_CheckModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5742. }
  5743. }
  5744. else
  5745. {
  5746. if (DateList.Length > 10)
  5747. {
  5748. comboBox_FacModeCfgDate.Items.Add("显示全部");
  5749. comboBox_CheckModeCfgDate.Items.Add("显示全部");
  5750. comboBox_FacModeCfgDate.Items.Add("---");
  5751. comboBox_CheckModeCfgDate.Items.Add("---");
  5752. }
  5753. for (int i = (DateList.Length > 10) ? (DateList.Length - 10) : 0; i < DateList.Length; i++)//显示最近10个日期
  5754. {
  5755. comboBox_FacModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  5756. comboBox_CheckModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  5757. }
  5758. }
  5759. }
  5760. /// <summary>
  5761. /// 获取配置文件列表
  5762. /// </summary>
  5763. /// <param name="date"></param>
  5764. private void GetFileListFrom(string date)
  5765. {
  5766. string[] FileList = { "" };
  5767. //从服务器更新文件列表
  5768. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  5769. {
  5770. FileList = myFtp.GetFileNameList(toolStripTextBox_ServerPath.Text + "/cfg/" + date);
  5771. }
  5772. else
  5773. {
  5774. FileList = Directory.GetFiles(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + date);
  5775. }
  5776. comboBox_CheckModeCfgFile.Items.Clear();
  5777. comboBox_FacModeCfgFile.Items.Clear();
  5778. foreach (var file in FileList)
  5779. {
  5780. if (file.Contains(".ttcfg"))
  5781. {
  5782. comboBox_CheckModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5783. comboBox_FacModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5784. }
  5785. }
  5786. }
  5787. /// <summary>
  5788. /// 检验模式选择文件日期
  5789. /// </summary>
  5790. /// <param name="sender"></param>
  5791. /// <param name="e"></param>
  5792. private void comboBox_CheckModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  5793. {
  5794. if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示全部")
  5795. {
  5796. GetDateList(true);
  5797. }
  5798. else if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示近期")
  5799. {
  5800. GetDateList(false);
  5801. }
  5802. else
  5803. {
  5804. comboBox_CheckModeCfgFile.Text = "";
  5805. GetFileListFrom(comboBox_CheckModeCfgDate.SelectedItem.ToString());
  5806. }
  5807. }
  5808. /// <summary>
  5809. /// 配置模式选择文件日期
  5810. /// </summary>
  5811. /// <param name="sender"></param>
  5812. /// <param name="e"></param>
  5813. private void comboBox_FacModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  5814. {
  5815. if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示全部")
  5816. {
  5817. GetDateList(true);
  5818. }
  5819. else if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示近期")
  5820. {
  5821. GetDateList(false);
  5822. }
  5823. else
  5824. {
  5825. comboBox_FacModeCfgFile.Text = "";
  5826. GetFileListFrom(comboBox_FacModeCfgDate.SelectedItem.ToString());
  5827. }
  5828. }
  5829. /// <summary>
  5830. /// 选中量产模式
  5831. /// </summary>
  5832. /// <param name="sender"></param>
  5833. /// <param name="e"></param>
  5834. private void tabControl1_Selected(object sender, TabControlEventArgs e)
  5835. {
  5836. //更新生产配置文件目录
  5837. GetDateList(false);
  5838. }
  5839. /// <summary>
  5840. /// 量产测试结束
  5841. /// </summary>
  5842. /// <param name=""></param>
  5843. private void FacMode_Stop(bool OK_Flag)
  5844. {
  5845. //打开开始按钮
  5846. button__FacMode_Start.Enabled = true;
  5847. //系统关机
  5848. var Code = new byte[32];//发送的指令数据
  5849. Code[0] = 0xF0;
  5850. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5851. //关闭串口
  5852. //mySerialProcess.SerialClose(false);
  5853. //路径设置
  5854. string LocalSavePath = "";
  5855. string ServerSavePath = "";
  5856. if (OK_Flag)
  5857. {
  5858. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "OK\\";
  5859. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/OK/";
  5860. }
  5861. else
  5862. {
  5863. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "FAIL\\";
  5864. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/FAIL/";
  5865. }
  5866. if (Directory.Exists(LocalSavePath) == false)
  5867. {
  5868. Directory.CreateDirectory(LocalSavePath);
  5869. }
  5870. //保存和上传
  5871. string LogSavePath = "";
  5872. string LogSaveFileName = "";
  5873. string ProductInfo = textBox_FacModeScan.Text.Replace(" ", "_").Replace("/", "-");
  5874. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  5875. if (Directory.Exists(LogSavePath) == false)
  5876. {
  5877. Directory.CreateDirectory(LogSavePath);
  5878. }
  5879. //测试页面
  5880. Double scaleX = PrimaryScreen.ScaleX;
  5881. Double scaleY = PrimaryScreen.ScaleY;
  5882. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  5883. Graphics g = Graphics.FromImage(bit);
  5884. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  5885. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  5886. bit.Save(LogSaveFileName);
  5887. //上传测试页面到服务器
  5888. if (myFtp.IsNetConnected == true)
  5889. {
  5890. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  5891. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  5892. {
  5893. myFtp.MakeDir(ServerSavePath + DateNow);
  5894. }
  5895. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  5896. {
  5897. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  5898. }
  5899. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  5900. if (result == true)
  5901. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  5902. }
  5903. else
  5904. {
  5905. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  5906. }
  5907. //测试记录
  5908. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  5909. string file_str = "";
  5910. file_str += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  5911. file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  5912. file_str += "检验记录:\r\n" + richTextBox_FacModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  5913. file_str += "检验结果:\r\n" + label_FacModeResult.Text + "\r\n\r\n";
  5914. file_str += Local_HdInformation;
  5915. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  5916. //上传测试记录到服务器
  5917. if (myFtp.IsNetConnected == true)
  5918. {
  5919. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  5920. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  5921. {
  5922. myFtp.MakeDir(ServerSavePath + DateNow);
  5923. }
  5924. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  5925. {
  5926. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  5927. }
  5928. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  5929. if (result == true)
  5930. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  5931. }
  5932. else
  5933. {
  5934. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  5935. }
  5936. //扫码框清空
  5937. textBox_FacModeScan.Text = "";
  5938. }
  5939. /// <summary>
  5940. /// 量产测试开始
  5941. /// </summary>
  5942. /// <param name="sender"></param>
  5943. /// <param name="e"></param>
  5944. private void button__FacMode_Start_Click(object sender, EventArgs e)
  5945. {
  5946. //关闭测试项目编辑
  5947. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  5948. foreach (Control c in groupBox2.Controls)
  5949. {
  5950. if (c is CheckBox)
  5951. c.Enabled = false;
  5952. }
  5953. WriteLockStatus = true;
  5954. //检查配置文件
  5955. if (comboBox_FacModeCfgFile.Text == "")
  5956. {
  5957. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5958. return;
  5959. }
  5960. //开始测试
  5961. TestStart();
  5962. }
  5963. /// <summary>
  5964. /// 测试子函数
  5965. /// </summary>
  5966. private void TestStart()
  5967. {
  5968. //初始化标签
  5969. FacModelLabelInit();
  5970. richTextBox_FacModeLog.Clear();
  5971. //按钮禁止操作
  5972. button__FacMode_Start.Enabled = false;
  5973. //记录配置文件
  5974. richTextBox_FacModeLog.AppendText("配置文件:" + comboBox_FacModeCfgDate.Text + " / " + comboBox_FacModeCfgFile.Text + "\r\n");
  5975. //检查打标信息格式
  5976. label_FacModeStatus.Text = "检查扫码信息";
  5977. Delay_ms(500);
  5978. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  5979. if (textBox_FacModeScan.Text == string.Empty)
  5980. {
  5981. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5982. button__FacMode_Start.Enabled = true;
  5983. return;
  5984. }
  5985. try
  5986. {
  5987. if (中置电机MIGIC_ToolStripMenuItem.Checked == true)
  5988. {
  5989. if (textBox_FacModeScan.Text.Split(' ').Length != 7)
  5990. {
  5991. label_FacModeStatus.Text = "存在故障!";
  5992. label_FacModeResult.BackColor = Color.Red;
  5993. label_FacModeResult.Text = "标签格式错误";
  5994. button__FacMode_Start.Enabled = true;
  5995. return;
  5996. }
  5997. }
  5998. else if (中置电机VP_ToolStripMenuItem.Checked == true)
  5999. {
  6000. if (textBox_FacModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 2)
  6001. {
  6002. label_FacModeStatus.Text = "存在故障!";
  6003. label_FacModeResult.BackColor = Color.Red;
  6004. label_FacModeResult.Text = "标签格式错误";
  6005. button__FacMode_Start.Enabled = true;
  6006. return;
  6007. }
  6008. }
  6009. else if (轮毂电机ToolStripMenuItem.Checked == true)
  6010. {
  6011. if (textBox_FacModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  6012. {
  6013. label_FacModeStatus.Text = "存在故障!";
  6014. label_FacModeResult.BackColor = Color.Red;
  6015. label_FacModeResult.Text = "标签格式错误";
  6016. button__FacMode_Start.Enabled = true;
  6017. return;
  6018. }
  6019. }
  6020. }
  6021. catch (System.Exception)
  6022. {
  6023. label_FacModeStatus.Text = "存在故障!";
  6024. label_FacModeResult.BackColor = Color.Red;
  6025. label_FacModeResult.Text = "标签格式错误";
  6026. button__FacMode_Start.Enabled = true;
  6027. return;
  6028. }
  6029. //打开串口
  6030. mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false);
  6031. if (!mySerialProcess.mySerial.IsOpen)
  6032. {
  6033. MessageBox.Show("请检查串口连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6034. //按钮禁止操作
  6035. button__FacMode_Start.Enabled = true;
  6036. return;
  6037. }
  6038. //流水号计数
  6039. int serial = Convert.ToInt32(label_FacModeSerial.Text);
  6040. serial += 1;
  6041. label_FacModeSerial.Text = serial.ToString();
  6042. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, serial.ToString());
  6043. //创建线程,执行测试任务
  6044. Thread th = new Thread(FacModeTest_Task);
  6045. th.Start();
  6046. }
  6047. /// <summary>
  6048. /// 执行一次测试任务
  6049. /// </summary>
  6050. private void FacModeTest_Task()
  6051. {
  6052. //开始测试
  6053. richTextBox_FacModeLog.AppendText("产品标签:" + textBox_FacModeScan.Text + "\r\n");
  6054. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  6055. //变量定义
  6056. var Code = new byte[255];//发送的指令数据
  6057. label_FacModeStatus.Text = "开始测试";
  6058. Delay_ms(500);
  6059. label_FacModeStatus.Text = "系统开机";
  6060. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  6061. if (uARTToolStripMenuItem.Checked)
  6062. {
  6063. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送复位指令,切换联动装置盒波特率" + "\r\n");
  6064. Code[0] = (byte)'R';
  6065. Code[1] = (byte)'E';
  6066. Code[2] = (byte)'S';
  6067. Code[3] = (byte)'E';
  6068. Code[4] = (byte)'T';
  6069. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  6070. Delay_ms(500);
  6071. }
  6072. //发送开机指令
  6073. //确保测试前先关机,发送关机指令再发送开机指令
  6074. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  6075. Code[0] = 0xF0;
  6076. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6077. Delay_ms(1500);
  6078. BootInfo = "";
  6079. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  6080. Code[0] = 0xF1;
  6081. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6082. ACK_WaitCnt = 0;
  6083. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  6084. while (ACK_WaitCnt <= 20); //10s,等待开机成功,联动装置盒控制器接口波特率需等待5s接口自动切换为9600
  6085. //检查BOOT版本
  6086. if (BootInfo != string.Empty)
  6087. {
  6088. label_FacModeBootVer.BackColor = Color.Green;
  6089. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  6090. Delay_ms(500);
  6091. }
  6092. else
  6093. {
  6094. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
  6095. label_FacModeStatus.Text = "存在故障!";
  6096. label_FacModeResult.BackColor = Color.Red;
  6097. label_FacModeResult.Text = "测试异常";
  6098. Delay_ms(500);
  6099. //存储异常并上传
  6100. FacMode_Stop(false);
  6101. return;
  6102. }
  6103. //系统清除
  6104. if (checkBox_FacModeSysClear.Checked)
  6105. {
  6106. do
  6107. {
  6108. #if false
  6109. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  6110. {
  6111. Code[0] = 0x00;//5S协议
  6112. Code[1] = 0x00;
  6113. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6114. Delay_ms(500);
  6115. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6116. Delay_ms(500);
  6117. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  6118. }
  6119. #endif
  6120. //发送系统清除指令
  6121. label_FacModeStatus.Text = "系统清除";
  6122. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除" + "\r\n");
  6123. Code[0] = (byte)'C';
  6124. Code[1] = (byte)'L';
  6125. Code[2] = (byte)'E';
  6126. Code[3] = (byte)'A';
  6127. Code[4] = (byte)'R';
  6128. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  6129. WriteACK = false;
  6130. ACK_WaitCnt = 0;
  6131. while (ACK_WaitCnt <= 6); //3s
  6132. //等待系统清除完成指令
  6133. if (WriteACK == true)
  6134. {
  6135. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  6136. label_FacModeSysClear.BackColor = Color.Green;
  6137. }
  6138. else
  6139. {
  6140. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除,重发第1次" + "\r\n");
  6141. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  6142. ACK_WaitCnt = 0;
  6143. while (ACK_WaitCnt <= 6) ; //3s
  6144. //等待系统清除完成指令
  6145. if (WriteACK == true)
  6146. {
  6147. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  6148. label_FacModeSysClear.BackColor = Color.Green;
  6149. }
  6150. else
  6151. {
  6152. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除,重发第2次" + "\r\n");
  6153. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  6154. ACK_WaitCnt = 0;
  6155. while (ACK_WaitCnt <= 6) ; //3s
  6156. //等待系统清除完成指令
  6157. if (WriteACK == true)
  6158. {
  6159. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  6160. label_FacModeSysClear.BackColor = Color.Green;
  6161. }
  6162. else
  6163. {
  6164. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除失败" + "\r\n");
  6165. label_FacModeStatus.Text = "存在故障!";
  6166. label_FacModeResult.BackColor = Color.Red;
  6167. label_FacModeResult.Text = "测试异常";
  6168. Delay_ms(500);
  6169. //存储异常并上传
  6170. FacMode_Stop(false);
  6171. return;
  6172. }
  6173. }
  6174. }
  6175. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  6176. if (uARTToolStripMenuItem.Checked)
  6177. {
  6178. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送复位指令,切换联动装置盒波特率" + "\r\n");
  6179. Code[0] = (byte)'R';
  6180. Code[1] = (byte)'E';
  6181. Code[2] = (byte)'S';
  6182. Code[3] = (byte)'E';
  6183. Code[4] = (byte)'T';
  6184. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  6185. Delay_ms(500);
  6186. }
  6187. //系统清除后需重新开机
  6188. label_FacModeStatus.Text = "重新开机";
  6189. //确保测试前先关机,发送关机指令再发送开机指令
  6190. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新发送关机指令" + "\r\n");
  6191. Code[0] = 0xF0;
  6192. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6193. Delay_ms(3000);
  6194. BootInfo = "";
  6195. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新发送开机指令" + "\r\n");
  6196. Code[0] = 0xF1;
  6197. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6198. ACK_WaitCnt = 0;
  6199. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  6200. while (ACK_WaitCnt <= 20);
  6201. //获取Boot版本信息
  6202. if (BootInfo != string.Empty)
  6203. {
  6204. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机成功" + "\r\n");
  6205. Delay_ms(500);
  6206. }
  6207. else
  6208. {
  6209. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机失败" + "\r\n");
  6210. label_FacModeStatus.Text = "存在故障!";
  6211. label_FacModeResult.BackColor = Color.Red;
  6212. label_FacModeResult.Text = "测试异常";
  6213. Delay_ms(500);
  6214. //存储异常并上传
  6215. FacMode_Stop(false);
  6216. return;
  6217. }
  6218. } while (false);
  6219. }
  6220. else
  6221. {
  6222. label_FacModeSysClear.BackColor = Color.Yellow;
  6223. label_FacModeStatus.Text = "跳过系统清除!";
  6224. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过系统清除" + "\r\n");
  6225. Delay_ms(500);
  6226. }
  6227. #if false
  6228. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  6229. {
  6230. Code[0] = 0x00;//5S协议
  6231. Code[1] = 0x00;
  6232. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6233. Delay_ms(500);
  6234. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6235. Delay_ms(500);
  6236. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  6237. }
  6238. #endif
  6239. //检查是否有故障
  6240. if (textBox_ErrorCode.Text.Contains("H"))
  6241. {
  6242. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "故障码:" + textBox_ErrorCode.Text + "\r\n");
  6243. label_FacModeStatus.Text = "电机存在故障!";
  6244. label_FacModeResult.BackColor = Color.Red;
  6245. label_FacModeResult.Text = "测试异常";
  6246. Delay_ms(500);
  6247. //存储异常并上传
  6248. FacMode_Stop(false);
  6249. return;
  6250. }
  6251. //MOS内阻校准
  6252. if (checkBox_FacMode_MosCal.Checked)
  6253. {
  6254. label_FacModeStatus.Text = "MOS内阻校准";
  6255. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始MOS内阻校准" + "\r\n");
  6256. Delay_ms(500);
  6257. //提示进行负载切换
  6258. if (MessageBox.Show("电阻负载切换完成,开始校准?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
  6259. {
  6260. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "取消MOS内阻校准" + "\r\n");
  6261. label_FacModeStatus.Text = "存在故障!";
  6262. label_FacModeResult.BackColor = Color.Red;
  6263. label_FacModeResult.Text = "测试异常";
  6264. Delay_ms(500);
  6265. //存储异常并上传
  6266. FacMode_Stop(false);
  6267. return;
  6268. }
  6269. //确认后发送校准指令
  6270. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令" + "\r\n");
  6271. string[] K = toolStripTextBox_MosCalK.Text.Split(',');
  6272. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  6273. ushort uwDataTemp = 0;
  6274. uwDataTemp = Convert.ToUInt16(K[0]);
  6275. Code[2] = (byte)(uwDataTemp & 0xFF);
  6276. Code[3] = (byte)(uwDataTemp >> 8);
  6277. uwDataTemp = Convert.ToUInt16(K[1]);
  6278. Code[4] = (byte)(uwDataTemp & 0xFF);
  6279. Code[5] = (byte)(uwDataTemp >> 8);
  6280. uwDataTemp = Convert.ToUInt16(K[2]);
  6281. Code[6] = (byte)(uwDataTemp & 0xFF);
  6282. Code[7] = (byte)(uwDataTemp >> 8);
  6283. uwDataTemp = Convert.ToUInt16(K[3]);
  6284. Code[8] = (byte)(uwDataTemp & 0xFF);
  6285. Code[9] = (byte)(uwDataTemp >> 8);
  6286. uwDataTemp = Convert.ToUInt16(K[4]);
  6287. Code[10] = (byte)(uwDataTemp & 0xFF);
  6288. Code[11] = (byte)(uwDataTemp >> 8);
  6289. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  6290. WriteACK = false;
  6291. ACK_WaitCnt = 0;
  6292. while (ACK_WaitCnt <= 6) ; //3s
  6293. if (WriteACK == true)
  6294. {
  6295. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  6296. }
  6297. else
  6298. {
  6299. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令,第1次重发" + "\r\n");
  6300. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  6301. ACK_WaitCnt = 0;
  6302. while (ACK_WaitCnt <= 6) ; //3s
  6303. if (WriteACK == true)
  6304. {
  6305. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  6306. }
  6307. else
  6308. {
  6309. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令,第2次重发" + "\r\n");
  6310. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  6311. ACK_WaitCnt = 0;
  6312. while (ACK_WaitCnt <= 6) ; //3s
  6313. if (WriteACK == true)
  6314. {
  6315. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  6316. }
  6317. else
  6318. {
  6319. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准异常" + "\r\n");
  6320. label_FacModeStatus.Text = "存在故障!";
  6321. label_FacModeResult.BackColor = Color.Red;
  6322. label_FacModeResult.Text = "测试异常";
  6323. Delay_ms(500);
  6324. //存储异常并上传
  6325. FacMode_Stop(false);
  6326. return;
  6327. }
  6328. }
  6329. }
  6330. #if false
  6331. //因控制器复位需发送指令重新进入5S协议
  6332. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  6333. {
  6334. Code[0] = 0x00;//5S协议
  6335. Code[1] = 0x00;
  6336. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6337. Delay_ms(500);
  6338. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6339. Delay_ms(500);
  6340. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  6341. }
  6342. #endif
  6343. //读取显示校准返回数据
  6344. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果" + "\r\n");
  6345. foreach (Control c in groupBox21.Controls)
  6346. {
  6347. if (c is TextBox)
  6348. c.Text = "";
  6349. }
  6350. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  6351. ACK_WaitCnt = 0;
  6352. while (ACK_WaitCnt <= 2) ; //1s
  6353. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  6354. {
  6355. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果,第1次重发" + "\r\n");
  6356. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  6357. ACK_WaitCnt = 0;
  6358. while (ACK_WaitCnt <= 2) ; //1s
  6359. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  6360. {
  6361. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果,第2次重发" + "\r\n");
  6362. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  6363. ACK_WaitCnt = 0;
  6364. while (ACK_WaitCnt <= 2) ; //1s
  6365. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  6366. {
  6367. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果异常" + "\r\n");
  6368. label_FacModeStatus.Text = "存在故障!";
  6369. label_FacModeResult.BackColor = Color.Red;
  6370. label_FacModeResult.Text = "测试异常";
  6371. Delay_ms(500);
  6372. //存储异常并上传
  6373. FacMode_Stop(false);
  6374. return;
  6375. }
  6376. }
  6377. }
  6378. else
  6379. {
  6380. 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");
  6381. }
  6382. //与校准返回数据对比
  6383. string[] MOS_R1_Th = toolStripTextBox_MOS1.Text.Split(',');
  6384. string[] MOS_R2_Th = toolStripTextBox_MOS2.Text.Split(',');
  6385. string[] MOS_R3_Th = toolStripTextBox_MOS3.Text.Split(',');
  6386. 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])) &&
  6387. (Convert.ToUInt16(textBox_MOS_R2.Text) >= Convert.ToUInt16(MOS_R2_Th[0])) && (Convert.ToUInt16(textBox_MOS_R2.Text) <= Convert.ToUInt16(MOS_R2_Th[1])) &&
  6388. (Convert.ToUInt16(textBox_MOS_R3.Text) >= Convert.ToUInt16(MOS_R3_Th[0])) && (Convert.ToUInt16(textBox_MOS_R3.Text) <= Convert.ToUInt16(MOS_R3_Th[1]))
  6389. )
  6390. {
  6391. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准合格" + "\r\n");
  6392. label_FacModeMosCal.BackColor = Color.Green;
  6393. //提示切换负载
  6394. MessageBox.Show("请将负载切换回电机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  6395. }
  6396. else
  6397. {
  6398. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准超范围" + "\r\n");
  6399. label_FacModeStatus.Text = "存在故障!";
  6400. label_FacModeResult.BackColor = Color.Red;
  6401. label_FacModeResult.Text = "测试异常";
  6402. Delay_ms(500);
  6403. //存储异常并上传
  6404. FacMode_Stop(false);
  6405. //提示切换负载
  6406. MessageBox.Show("请将负载切换回电机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  6407. return;
  6408. }
  6409. }
  6410. else
  6411. {
  6412. label_FacModeMosCal.BackColor = Color.Yellow;
  6413. label_FacModeStatus.Text = "跳过MOS内阻校准!";
  6414. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过MOS内阻校准" + "\r\n");
  6415. Delay_ms(500);
  6416. }
  6417. //位置校准
  6418. if (checkBox_FacMode_AngleCal.Checked)
  6419. {
  6420. //校准前进行一次开关机保存初始化数据
  6421. label_FacModeStatus.Text = "位置校准";
  6422. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始位置校准" + "\r\n");
  6423. //确保测试前先关机,发送关机指令再发送开机指令
  6424. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  6425. Code[0] = 0xF0;
  6426. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6427. Delay_ms(1500);
  6428. BootInfo = "";
  6429. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  6430. Code[0] = 0xF1;
  6431. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6432. ACK_WaitCnt = 0;
  6433. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  6434. while (ACK_WaitCnt <= 10) ; //5s
  6435. //获取Boot版本信息
  6436. if (BootInfo != string.Empty)
  6437. {
  6438. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机成功" + "\r\n");
  6439. Delay_ms(500);
  6440. }
  6441. else
  6442. {
  6443. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机失败" + "\r\n");
  6444. label_FacModeStatus.Text = "存在故障!";
  6445. label_FacModeResult.BackColor = Color.Red;
  6446. label_FacModeResult.Text = "测试异常";
  6447. Delay_ms(500);
  6448. //存储异常并上传
  6449. FacMode_Stop(false);
  6450. return;
  6451. }
  6452. //发送位置校准指令
  6453. for (int i = 0; i < 7; i++)
  6454. for (int j = 0; j < 6; j++)
  6455. {
  6456. dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = "";
  6457. }
  6458. foreach (Control cr in tabPage_AngleCal.Controls)
  6459. {
  6460. if (cr is TextBox)
  6461. {
  6462. if ((cr != textBox_AngleDiffTh) && (cr != textBox_AngleZeroTh))
  6463. cr.Text = "";
  6464. }
  6465. }
  6466. Code[0] = 0;
  6467. Code[1] = 0;
  6468. mySerialProcess.SendCmd((ushort)0x751, (byte)0x0C, (ushort)0x5002, Code);
  6469. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准中,请等待" + "\r\n");
  6470. ACK_WaitCnt = 0;
  6471. while (ACK_WaitCnt <= 50) ; //25s
  6472. //读取位置校准数据
  6473. if (textBox_AngleDiffAvg.Text == string.Empty)
  6474. {
  6475. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准失败" + "\r\n");
  6476. label_FacModeStatus.Text = "存在故障!";
  6477. label_FacModeResult.BackColor = Color.Red;
  6478. label_FacModeResult.Text = "测试异常";
  6479. Delay_ms(500);
  6480. //存储异常并上传
  6481. FacMode_Stop(false);
  6482. return;
  6483. }
  6484. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准数据:" + "\r\n");
  6485. for (int i = 0; i < 7; i++)
  6486. {
  6487. richTextBox_FacModeLog.AppendText("电周期" + (i + 1).ToString()+":");
  6488. for (int j = 0; j < 6; j++)
  6489. {
  6490. richTextBox_FacModeLog.AppendText(dataGridView_AngleCal.Rows[i].Cells[j + 1].Value.ToString() + ", ");
  6491. }
  6492. richTextBox_FacModeLog.AppendText("\r\n");
  6493. Delay_ms(200);
  6494. }
  6495. richTextBox_FacModeLog.AppendText("最小偏差:" + textBox_AngleDiffMin.Text+ ", " + "\r\n");
  6496. richTextBox_FacModeLog.AppendText("最大偏差:" + textBox_AngleDiffMax.Text + ", " + "\r\n");
  6497. richTextBox_FacModeLog.AppendText("平均偏差:" + textBox_AngleDiffAvg.Text + ", " + "\r\n");
  6498. richTextBox_FacModeLog.AppendText("历史零点:" + textBox_AngleZeroInit.Text + ", " + "\r\n");
  6499. richTextBox_FacModeLog.AppendText("当前零点:" + textBox_AngleZeroCur.Text + ", " + "\r\n");
  6500. richTextBox_FacModeLog.AppendText("零点偏差:" + textBox_AngleZeroDiff.Text + ", " + "\r\n");
  6501. //比较位置偏差
  6502. if ((Math.Abs(Convert.ToDouble(textBox_AngleDiffMin.Text)) > Convert.ToDouble(textBox_AngleDiffTh.Text)) ||
  6503. (Math.Abs(Convert.ToDouble(textBox_AngleDiffMax.Text)) > Convert.ToDouble(textBox_AngleDiffTh.Text)) ||
  6504. (Math.Abs(Convert.ToDouble(textBox_AngleDiffAvg.Text)) > Convert.ToDouble(textBox_AngleZeroTh.Text))
  6505. )
  6506. {
  6507. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差过大,无法校准" + "\r\n");
  6508. label_FacModeStatus.Text = "存在故障!";
  6509. label_FacModeResult.BackColor = Color.Red;
  6510. label_FacModeResult.Text = "测试异常";
  6511. Delay_ms(500);
  6512. //存储异常并上传
  6513. FacMode_Stop(false);
  6514. return;
  6515. }
  6516. //写入校准偏差值
  6517. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差满足要求,写入校准数据" + "\r\n");
  6518. double data1 = Convert.ToDouble(textBox_AngleZeroInit.Text) - Convert.ToDouble(textBox_AngleDiffAvg.Text);
  6519. if (data1 > 360)
  6520. {
  6521. data1 -= 360;
  6522. }
  6523. else if (data1 < -360)
  6524. {
  6525. data1 += 360;
  6526. }
  6527. Int16 data2 = (Int16)(data1 * 32768 / 360);
  6528. Code[0] = 0x01;
  6529. Code[1] = 0x00;
  6530. Code[2] = (byte)(data2);
  6531. Code[3] = (byte)(data2 >> 8);
  6532. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
  6533. WriteACK = false;
  6534. ACK_WaitCnt = 0;
  6535. while (ACK_WaitCnt <= 2) ; //1s
  6536. if (WriteACK == true)
  6537. {
  6538. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
  6539. }
  6540. else
  6541. {
  6542. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入位置偏差,第1次重发" + "\r\n");
  6543. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
  6544. WriteACK = false;
  6545. ACK_WaitCnt = 0;
  6546. while (ACK_WaitCnt <= 2) ; //1s
  6547. if (WriteACK == true)
  6548. {
  6549. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
  6550. }
  6551. else
  6552. {
  6553. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入位置偏差,第2次重发" + "\r\n");
  6554. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
  6555. WriteACK = false;
  6556. ACK_WaitCnt = 0;
  6557. while (ACK_WaitCnt <= 2) ; //1s
  6558. if (WriteACK == true)
  6559. {
  6560. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
  6561. }
  6562. else
  6563. {
  6564. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入失败" + "\r\n");
  6565. label_FacModeStatus.Text = "存在故障!";
  6566. label_FacModeResult.BackColor = Color.Red;
  6567. label_FacModeResult.Text = "测试异常";
  6568. Delay_ms(500);
  6569. //存储异常并上传
  6570. FacMode_Stop(false);
  6571. return;
  6572. }
  6573. }
  6574. }
  6575. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准正常,位置偏差值:" + textBox_AngleDiffAvg.Text + "\r\n");
  6576. label_FacModeAngleCal.BackColor = Color.Green;
  6577. }
  6578. else
  6579. {
  6580. label_FacModeAngleCal.BackColor = Color.Yellow;
  6581. label_FacModeStatus.Text = "跳过位置校准!";
  6582. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过位置校准" + "\r\n");
  6583. Delay_ms(500);
  6584. }
  6585. //参数写入
  6586. if (checkBox_FacModeCfgWrite.Checked)
  6587. {
  6588. label_FacModeStatus.Text = "参数写入";
  6589. //写入产品型号和SN
  6590. do
  6591. {
  6592. //根据扫码信息获取型号和SN
  6593. string ScanInfo = textBox_FacModeScan.Text;
  6594. string regexInfo = "";
  6595. string[] InfoList = { "" };
  6596. try
  6597. {
  6598. if (中置电机MIGIC_ToolStripMenuItem.Checked == true)
  6599. {
  6600. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  6601. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  6602. }
  6603. else if (中置电机VP_ToolStripMenuItem.Checked == true)
  6604. {
  6605. Regex regex = new Regex(@"^M[12][0-9](0?[1-9]|1[0-2])((0?[1-9])|((1|2)[0-9])|30|31)[A-Z]\d{4}[A-Z][A-Z]?$");
  6606. if (ScanInfo.Contains(" "))
  6607. {
  6608. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  6609. string Mode = InfoList[0];
  6610. string Sn = InfoList[1];
  6611. if (regex.IsMatch(Sn) == false)
  6612. {
  6613. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN格式错误" + "\r\n");
  6614. label_FacModeStatus.Text = "存在故障!";
  6615. label_FacModeResult.BackColor = Color.Red;
  6616. label_FacModeResult.Text = "标签格式错误";
  6617. Delay_ms(500);
  6618. //存储异常并上传
  6619. FacMode_Stop(false);
  6620. return;
  6621. }
  6622. }
  6623. else
  6624. {
  6625. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  6626. label_FacModeStatus.Text = "存在故障!";
  6627. label_FacModeResult.BackColor = Color.Red;
  6628. label_FacModeResult.Text = "标签格式错误";
  6629. Delay_ms(500);
  6630. //存储异常并上传
  6631. FacMode_Stop(false);
  6632. return;
  6633. }
  6634. }
  6635. else if (轮毂电机ToolStripMenuItem.Checked == true)
  6636. {
  6637. if (!ScanInfo.Contains("/")) //老编码规则
  6638. {
  6639. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  6640. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  6641. string Spec = InfoList[1];
  6642. string Sn = InfoList[2];
  6643. InfoList[0] = Model.Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  6644. InfoList[1] = Sn;
  6645. }
  6646. else //新编码规则
  6647. {
  6648. Dictionary<string, string> Dic_Ver = new Dictionary<string, string>
  6649. {
  6650. { "01", "A" },
  6651. { "02", "B" },
  6652. { "03", "C" },
  6653. { "04", "D" },
  6654. { "05", "E" },
  6655. { "06", "F" },
  6656. { "07", "G" },
  6657. { "08", "H" },
  6658. { "09", "I" }
  6659. };
  6660. Dictionary<string, string> Dic_Vol = new Dictionary<string, string>
  6661. {
  6662. { "24V", "A" },
  6663. { "36V", "B" },
  6664. { "42V", "C" },
  6665. { "48V", "D" },
  6666. { "52V", "E" },
  6667. { "60V", "F" }
  6668. };
  6669. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  6670. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  6671. string Spec = InfoList[1].Replace("-", "").Replace("/", "");
  6672. string Sn = InfoList[2];
  6673. InfoList[0] = Model[2] + Dic_Ver[Model.Substring(3, 2)] + Model[5] + Dic_Ver[Model.Substring(6, 2)] + Model[9];
  6674. InfoList[0] += Dic_Vol[Spec.Substring(0, 3)] + Spec.Substring(3, 3) + Spec.Substring(13, 4) + Spec.Substring(Spec.Length - 4, 3);
  6675. InfoList[1] = Sn;
  6676. }
  6677. }
  6678. }
  6679. catch
  6680. {
  6681. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  6682. label_FacModeStatus.Text = "存在故障!";
  6683. label_FacModeResult.BackColor = Color.Red;
  6684. label_FacModeResult.Text = "标签格式错误";
  6685. Delay_ms(500);
  6686. //存储异常并上传
  6687. FacMode_Stop(false);
  6688. return;
  6689. }
  6690. if (InfoList.Length >= 2)
  6691. {
  6692. //检查配置文件是否与打标信息一致
  6693. //...
  6694. //写入型号
  6695. label_FacModeStatus.Text = "写入型号";
  6696. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号" + "\r\n");
  6697. textBox_FacModeName.Text = InfoList[0];
  6698. string Mode = textBox_FacModeName.Text;
  6699. var ModeArray = new byte[16];
  6700. for (ushort i = 0; i < Mode.Length; i++)
  6701. {
  6702. ModeArray[i] = (byte)Mode[i];
  6703. }
  6704. if (Mode.Length < 16)
  6705. {
  6706. ModeArray[Mode.Length] = (byte)'.';
  6707. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  6708. {
  6709. ModeArray[Mode.Length + 1 + i] = 0x20;
  6710. }
  6711. }
  6712. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6713. WriteACK = false;
  6714. ACK_WaitCnt = 0;
  6715. while (ACK_WaitCnt <= 2); //1s
  6716. if (WriteACK == true)
  6717. {
  6718. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6719. }
  6720. else
  6721. {
  6722. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号,第1次重发" + "\r\n");
  6723. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6724. ACK_WaitCnt = 0;
  6725. while (ACK_WaitCnt <= 2) ; //1s
  6726. if (WriteACK == true)
  6727. {
  6728. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6729. }
  6730. else
  6731. {
  6732. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号,第2次重发" + "\r\n");
  6733. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6734. ACK_WaitCnt = 0;
  6735. while (ACK_WaitCnt <= 2) ; //1s
  6736. if (WriteACK == true)
  6737. {
  6738. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6739. }
  6740. else
  6741. {
  6742. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入失败" + "\r\n");
  6743. label_FacModeStatus.Text = "存在故障!";
  6744. label_FacModeResult.BackColor = Color.Red;
  6745. label_FacModeResult.Text = "测试异常";
  6746. Delay_ms(500);
  6747. //存储异常并上传
  6748. FacMode_Stop(false);
  6749. return;
  6750. }
  6751. }
  6752. }
  6753. //写入SN
  6754. label_FacModeStatus.Text = "写入SN";
  6755. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN" + "\r\n");
  6756. textBox_FacModeNum.Text = InfoList[1];
  6757. string SN = textBox_FacModeNum.Text;
  6758. var SNArray = new byte[16];
  6759. for (ushort i = 0; i < SN.Length; i++)
  6760. {
  6761. SNArray[i] = (byte)SN[i];
  6762. }
  6763. if (SN.Length < 16)
  6764. {
  6765. SNArray[SN.Length] = (byte)'.';
  6766. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  6767. {
  6768. SNArray[SN.Length + 1 + i] = 0x20;
  6769. }
  6770. }
  6771. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6772. WriteACK = false;
  6773. ACK_WaitCnt = 0;
  6774. while (ACK_WaitCnt <= 2); //1s
  6775. if (WriteACK == true)
  6776. {
  6777. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  6778. }
  6779. else
  6780. {
  6781. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN,第1次重发" + "\r\n");
  6782. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6783. ACK_WaitCnt = 0;
  6784. while (ACK_WaitCnt <= 2) ; //1s
  6785. if (WriteACK == true)
  6786. {
  6787. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  6788. }
  6789. else
  6790. {
  6791. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN,第2次重发" + "\r\n");
  6792. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6793. ACK_WaitCnt = 0;
  6794. while (ACK_WaitCnt <= 2) ; //1s
  6795. if (WriteACK == true)
  6796. {
  6797. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  6798. }
  6799. else
  6800. {
  6801. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入失败" + "\r\n");
  6802. label_FacModeStatus.Text = "存在故障!";
  6803. label_FacModeResult.BackColor = Color.Red;
  6804. label_FacModeResult.Text = "测试异常";
  6805. Delay_ms(500);
  6806. //存储异常并上传
  6807. FacMode_Stop(false);
  6808. return;
  6809. }
  6810. }
  6811. }
  6812. }
  6813. else
  6814. {
  6815. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6816. return;
  6817. }
  6818. } while (false);
  6819. //写入配置文件
  6820. do
  6821. {
  6822. label_FacModeStatus.Text = "写入配置文件";
  6823. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  6824. //配置文件
  6825. List<byte[]> CmdList = new List<byte[]>();
  6826. //从服务器下载文件
  6827. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  6828. {
  6829. string SelectFile = "";
  6830. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "/" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  6831. if (File.Exists(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  6832. {
  6833. File.Delete(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  6834. }
  6835. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  6836. //打开文件
  6837. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  6838. CmdList.Clear();
  6839. while (streamReader.Peek() != -1)
  6840. {
  6841. string fileLineInfo = streamReader.ReadLine();
  6842. if (fileLineInfo.IndexOf("[") != -1)
  6843. {
  6844. continue;
  6845. }
  6846. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  6847. }
  6848. streamReader.Close();
  6849. }
  6850. //加载本地文件
  6851. else
  6852. {
  6853. string SelectFile = "";
  6854. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  6855. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  6856. CmdList.Clear();
  6857. while (streamReader.Peek() != -1)
  6858. {
  6859. string fileLineInfo = streamReader.ReadLine();
  6860. if (fileLineInfo.IndexOf("[") != -1)
  6861. {
  6862. continue;
  6863. }
  6864. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  6865. }
  6866. streamReader.Close();
  6867. }
  6868. int CmdNum = CmdList.Count(); //指令个数
  6869. Delay_ms(500);
  6870. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "开始写入" + "\r\n");
  6871. Delay_ms(500);
  6872. //开始写入
  6873. for (int i = 0; i < CmdList.Count; i++)
  6874. {
  6875. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令" + "\r\n");
  6876. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6877. WriteACK = false;
  6878. ACK_WaitCnt = 0;
  6879. while (ACK_WaitCnt <= 2) ; //1s
  6880. if (WriteACK == true)
  6881. {
  6882. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6883. }
  6884. else
  6885. {
  6886. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令,第1次重发" + "\r\n");
  6887. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6888. WriteACK = false;
  6889. ACK_WaitCnt = 0;
  6890. while (ACK_WaitCnt <= 2) ; //1s
  6891. if (WriteACK == true)
  6892. {
  6893. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6894. }
  6895. else
  6896. {
  6897. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令,第2次重发" + "\r\n");
  6898. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6899. WriteACK = false;
  6900. ACK_WaitCnt = 0;
  6901. while (ACK_WaitCnt <= 2) ; //1s
  6902. if (WriteACK == true)
  6903. {
  6904. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6905. }
  6906. else
  6907. {
  6908. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入失败," + "共" + CmdNum.ToString() + "条指令," + "写入成功" + i.ToString() + "条" + "\r\n");
  6909. label_FacModeStatus.Text = "存在故障!";
  6910. label_FacModeResult.BackColor = Color.Red;
  6911. label_FacModeResult.Text = "测试异常";
  6912. Delay_ms(500);
  6913. //存储异常并上传
  6914. FacMode_Stop(false);
  6915. return;
  6916. }
  6917. }
  6918. }
  6919. }
  6920. //写入完成
  6921. label_FacMode_CfgWrite.BackColor = Color.Green;
  6922. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入成功" + "\r\n");
  6923. Delay_ms(500);
  6924. } while (false);
  6925. }
  6926. else
  6927. {
  6928. label_FacMode_CfgWrite.BackColor = Color.Yellow;
  6929. label_FacModeStatus.Text = "跳过参数写入!";
  6930. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数写入" + "\r\n");
  6931. Delay_ms(500);
  6932. }
  6933. //BMS通讯
  6934. if (checkBox_FacModeBMS.Checked)
  6935. {
  6936. if (label_FacModeBMS.BackColor == Color.Red)
  6937. {
  6938. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "BMS通讯异常" + "\r\n");
  6939. label_FacModeStatus.Text = "存在故障!";
  6940. label_FacModeResult.BackColor = Color.Red;
  6941. label_FacModeResult.Text = "测试异常";
  6942. Delay_ms(500);
  6943. //存储异常并上传
  6944. FacMode_Stop(false);
  6945. return;
  6946. }
  6947. }
  6948. else
  6949. {
  6950. label_FacModeBMS.BackColor = Color.Yellow;
  6951. label_FacModeStatus.Text = "跳过BMS通讯检测!";
  6952. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过BMS通讯检测" + "\r\n");
  6953. Delay_ms(500);
  6954. }
  6955. //基础功能检测
  6956. if (checkBox_FacBaseFucTest.Checked)
  6957. {
  6958. label_FacModeStatus.Text = "基础功能检测";
  6959. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始基础功能检测" + "\r\n");
  6960. //确认负载位置
  6961. if (checkBox_FacMode_MosCal.Checked)
  6962. {
  6963. if (MessageBox.Show("请再次确认负载是否切换回电机?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  6964. {
  6965. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "负载已切换为电机,继续测试" + "\r\n");
  6966. }
  6967. else
  6968. {
  6969. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试取消" + "\r\n");
  6970. label_FacModeStatus.Text = "存在故障!";
  6971. label_FacModeResult.BackColor = Color.Red;
  6972. label_FacModeResult.Text = "测试异常";
  6973. Delay_ms(500);
  6974. //存储异常并上传
  6975. FacMode_Stop(false);
  6976. return;
  6977. }
  6978. }
  6979. //发送指令进入配置模式
  6980. do
  6981. {
  6982. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6983. Code[0] = 0x01;
  6984. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6985. WriteACK = false;
  6986. ACK_WaitCnt = 0;
  6987. while (ACK_WaitCnt <= 2); //1s
  6988. if (textBox_RunInfo_Vol.Text != "---")
  6989. {
  6990. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  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. }
  7002. else
  7003. {
  7004. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7005. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7006. ACK_WaitCnt = 0;
  7007. while (ACK_WaitCnt <= 2) ; //1s
  7008. if (textBox_RunInfo_Vol.Text != "---")
  7009. {
  7010. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7011. }
  7012. else
  7013. {
  7014. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7015. label_FacModeStatus.Text = "存在故障!";
  7016. label_FacModeResult.BackColor = Color.Red;
  7017. label_FacModeResult.Text = "测试异常";
  7018. Delay_ms(500);
  7019. //存储异常并上传
  7020. FacMode_Stop(false);
  7021. return;
  7022. }
  7023. }
  7024. }
  7025. } while (false);
  7026. //发送指令启动电机
  7027. do
  7028. {
  7029. #if false //通过运行模式3启动电机
  7030. //发送指令读取调试信息
  7031. richTextBox_DebugParam.Clear();
  7032. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  7033. WriteACK = false;
  7034. ACK_WaitCnt = 0;
  7035. while (ACK_WaitCnt <= 2); //1s
  7036. //获取调试信息
  7037. string DebugDefaultInfo = "";
  7038. if (richTextBox_DebugParam.Text == string.Empty)
  7039. {
  7040. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
  7041. label_FacModeStatus.Text = "存在故障!";
  7042. label_FacModeResult.BackColor = Color.Red;
  7043. label_FacModeResult.Text = "测试异常";
  7044. Delay_ms(500);
  7045. //存储异常并上传
  7046. FacMode_Stop(false);
  7047. return;
  7048. }
  7049. else
  7050. {
  7051. DebugDefaultInfo = richTextBox_DebugParam.Text;
  7052. }
  7053. //设置模式
  7054. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  7055. strDataTemp[0] = "整体运行模式=3";
  7056. //发送数据
  7057. Code[0] = 0;
  7058. Code[1] = 0;
  7059. for (int i = 0; i < strDataTemp.Length; i++)
  7060. {
  7061. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  7062. Code[2 * i + 2] = (byte)uwDataTemp;
  7063. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  7064. }
  7065. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  7066. label_FacModeStatus.Text = "启动电机";
  7067. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "启动电机" + "\r\n");
  7068. #else //通过Walk模式启动电机
  7069. //设置转速100%
  7070. var Data = new byte[1];
  7071. Data[0] = (byte)100;
  7072. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7073. Delay_ms(500);
  7074. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7075. Delay_ms(500);
  7076. //启动电机进入WALK模式
  7077. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "基础功能检测,进入WALK" + "\r\n");
  7078. Code[0] = 0x22;
  7079. Code[1] = 0xF0;
  7080. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7081. WriteACK = false;
  7082. ACK_WaitCnt = 0;
  7083. while (ACK_WaitCnt <= 2) ; //1s
  7084. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  7085. {
  7086. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第1次重发" + "\r\n");
  7087. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7088. ACK_WaitCnt = 0;
  7089. while (ACK_WaitCnt <= 2) ; //1s
  7090. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  7091. {
  7092. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第2次重发" + "\r\n");
  7093. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7094. ACK_WaitCnt = 0;
  7095. while (ACK_WaitCnt <= 2) ; //1s
  7096. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  7097. {
  7098. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
  7099. label_FacModeStatus.Text = "存在故障!";
  7100. label_FacModeResult.BackColor = Color.Red;
  7101. label_FacModeResult.Text = "测试异常";
  7102. Delay_ms(500);
  7103. //存储异常并上传
  7104. FacMode_Stop(false);
  7105. return;
  7106. }
  7107. }
  7108. }
  7109. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入WALK,开始检测" + "\r\n");
  7110. #endif
  7111. Delay_ms(5000);
  7112. } while (false);
  7113. //判断车速
  7114. if ((Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) <= Convert.ToDouble( toolStripTextBox_ThBikeSpeed.Text.Split(',')[1])) &&
  7115. (Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThBikeSpeed.Text.Split(',')[0])))
  7116. {
  7117. label_FacModeSpeed.BackColor = Color.Green;
  7118. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器正常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
  7119. }
  7120. else
  7121. {
  7122. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器异常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
  7123. label_FacModeStatus.Text = "存在故障!";
  7124. label_FacModeResult.BackColor = Color.Red;
  7125. label_FacModeResult.Text = "测试异常";
  7126. Delay_ms(500);
  7127. //存储异常并上传
  7128. FacMode_Stop(false);
  7129. return;
  7130. }
  7131. //判断电压
  7132. if ((Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[1])) &&
  7133. (Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[0])))
  7134. {
  7135. label_FacModeVolTest.BackColor = Color.Green;
  7136. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量正常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
  7137. }
  7138. else
  7139. {
  7140. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量异常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
  7141. label_FacModeStatus.Text = "存在故障!";
  7142. label_FacModeResult.BackColor = Color.Red;
  7143. label_FacModeResult.Text = "测试异常";
  7144. Delay_ms(500);
  7145. //存储异常并上传
  7146. FacMode_Stop(false);
  7147. return;
  7148. }
  7149. //判断电流
  7150. if ((Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[1])) &&
  7151. (Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[0])))
  7152. {
  7153. label_FacModeCurrentTest.BackColor = Color.Green;
  7154. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量正常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  7155. }
  7156. else
  7157. {
  7158. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量异常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  7159. label_FacModeStatus.Text = "存在故障!";
  7160. label_FacModeResult.BackColor = Color.Red;
  7161. label_FacModeResult.Text = "测试异常";
  7162. Delay_ms(500);
  7163. //存储异常并上传
  7164. FacMode_Stop(false);
  7165. return;
  7166. }
  7167. //判断温度
  7168. if ((Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[1])) &&
  7169. (Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[0])) &&
  7170. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[1])) &&
  7171. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[0])) &&
  7172. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[1])) &&
  7173. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[0])))
  7174. {
  7175. label_FacModeNTC.BackColor = Color.Green;
  7176. 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");
  7177. }
  7178. else
  7179. {
  7180. 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");
  7181. label_FacModeStatus.Text = "存在故障!";
  7182. label_FacModeResult.BackColor = Color.Red;
  7183. label_FacModeResult.Text = "测试异常";
  7184. Delay_ms(500);
  7185. //存储异常并上传
  7186. FacMode_Stop(false);
  7187. return;
  7188. }
  7189. //判断转速
  7190. if ((Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[1])) &&
  7191. (Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[0])))
  7192. {
  7193. label_FacModeMotorSpeed.BackColor = Color.Green;
  7194. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速正常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
  7195. }
  7196. else
  7197. {
  7198. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速异常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
  7199. label_FacModeStatus.Text = "存在故障!";
  7200. label_FacModeResult.BackColor = Color.Red;
  7201. label_FacModeResult.Text = "测试异常";
  7202. Delay_ms(500);
  7203. //存储异常并上传
  7204. FacMode_Stop(false);
  7205. return;
  7206. }
  7207. //中置判断踏频
  7208. if ((中置电机MIGIC_ToolStripMenuItem.Checked == true) || (中置电机VP_ToolStripMenuItem.Checked == true))
  7209. {
  7210. if ((Convert.ToDouble(textBox_RunInfo_Cadence.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[1])) &&
  7211. (Convert.ToDouble(textBox_RunInfo_Cadence.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[0])))
  7212. {
  7213. label_FacModeCad.BackColor = Color.Green;
  7214. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器正常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  7215. }
  7216. else
  7217. {
  7218. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器异常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  7219. label_FacModeStatus.Text = "存在故障!";
  7220. label_FacModeResult.BackColor = Color.Red;
  7221. label_FacModeResult.Text = "测试异常";
  7222. Delay_ms(500);
  7223. //存储异常并上传
  7224. FacMode_Stop(false);
  7225. return;
  7226. }
  7227. }
  7228. //发送指令停止电机
  7229. do
  7230. {
  7231. //设置转速0%
  7232. var Data = new byte[1];
  7233. Data[0] = (byte)0;
  7234. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7235. Delay_ms(500);
  7236. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7237. Delay_ms(500);
  7238. #if false //通过修改调试模式停止电机
  7239. //获取调试信息
  7240. string DebugDefaultInfo = "";
  7241. if (richTextBox_DebugParam.Text == string.Empty)
  7242. {
  7243. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
  7244. label_FacModeStatus.Text = "存在故障!";
  7245. label_FacModeResult.BackColor = Color.Red;
  7246. label_FacModeResult.Text = "测试异常";
  7247. Delay_ms(500);
  7248. //存储异常并上传
  7249. FacMode_Stop(false);
  7250. return;
  7251. }
  7252. else
  7253. {
  7254. DebugDefaultInfo = richTextBox_DebugParam.Text;
  7255. }
  7256. //设置模式
  7257. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  7258. //发送数据
  7259. Code[0] = 0;
  7260. Code[1] = 0;
  7261. for (int i = 0; i < strDataTemp.Length; i++)
  7262. {
  7263. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  7264. Code[2 * i + 2] = (byte)uwDataTemp;
  7265. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  7266. }
  7267. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  7268. label_FacModeStatus.Text = "停止电机";
  7269. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "停止电机" + "\r\n");
  7270. #else //通过调整档位停止电机
  7271. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK" + "\r\n");
  7272. Code[0] = 0x00;
  7273. Code[1] = 0xF0;
  7274. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7275. WriteACK = false;
  7276. ACK_WaitCnt = 0;
  7277. while (ACK_WaitCnt <= 2) ; //1s
  7278. if (textBox_RunInfo_GearSt.Text != "OFF")
  7279. {
  7280. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK,第1次重发" + "\r\n");
  7281. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7282. ACK_WaitCnt = 0;
  7283. while (ACK_WaitCnt <= 2) ; //1s
  7284. if (textBox_RunInfo_GearSt.Text != "OFF")
  7285. {
  7286. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK,第2次重发" + "\r\n");
  7287. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7288. ACK_WaitCnt = 0;
  7289. while (ACK_WaitCnt <= 2) ; //1s
  7290. if (textBox_RunInfo_GearSt.Text != "OFF")
  7291. {
  7292. }
  7293. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
  7294. label_FacModeStatus.Text = "存在故障!";
  7295. label_FacModeResult.BackColor = Color.Red;
  7296. label_FacModeResult.Text = "测试异常";
  7297. Delay_ms(500);
  7298. //存储异常并上传
  7299. FacMode_Stop(false);
  7300. return;
  7301. }
  7302. }
  7303. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已退出WALK,基础功能检测完成" + "\r\n");
  7304. #endif
  7305. Delay_ms(2000);
  7306. } while (false);
  7307. }
  7308. else
  7309. {
  7310. label_FacModeSpeed.BackColor = Color.Yellow;
  7311. label_FacModeVolTest.BackColor = Color.Yellow;
  7312. label_FacModeCurrentTest.BackColor = Color.Yellow;
  7313. label_FacModeNTC.BackColor = Color.Yellow;
  7314. label_FacModeMotorSpeed.BackColor = Color.Yellow;
  7315. label_FacModeStatus.Text = "跳过基础功能检测!";
  7316. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过基础功能检测" + "\r\n");
  7317. Delay_ms(500);
  7318. }
  7319. //力矩检测
  7320. if (checkBox_FacTor.Checked)
  7321. {
  7322. label_FacModeStatus.Text = "力矩传感器检测!";
  7323. //发送指令进入配置模式
  7324. do
  7325. {
  7326. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  7327. {
  7328. break;
  7329. }
  7330. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  7331. Code[0] = 0x01;
  7332. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7333. WriteACK = false;
  7334. ACK_WaitCnt = 0;
  7335. while (ACK_WaitCnt <= 2) ; //1s
  7336. if (textBox_RunInfo_Vol.Text != "---")
  7337. {
  7338. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7339. Delay_ms(500);
  7340. }
  7341. else
  7342. {
  7343. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  7344. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7345. ACK_WaitCnt = 0;
  7346. while (ACK_WaitCnt <= 2) ; //1s
  7347. if (textBox_RunInfo_Vol.Text != "---")
  7348. {
  7349. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7350. Delay_ms(500);
  7351. }
  7352. else
  7353. {
  7354. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7355. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7356. ACK_WaitCnt = 0;
  7357. while (ACK_WaitCnt <= 2) ; //1s
  7358. if (textBox_RunInfo_Vol.Text != "---")
  7359. {
  7360. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7361. Delay_ms(500);
  7362. }
  7363. else
  7364. {
  7365. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7366. label_FacModeStatus.Text = "存在故障!";
  7367. label_FacModeResult.BackColor = Color.Red;
  7368. label_FacModeResult.Text = "测试异常";
  7369. Delay_ms(500);
  7370. //存储异常并上传
  7371. FacMode_Stop(false);
  7372. return;
  7373. }
  7374. }
  7375. }
  7376. } while (false);
  7377. ushort Max = 0, Torque = 0;
  7378. //提示输入力矩信号
  7379. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟力矩信号输入" + "\r\n");
  7380. ACK_WaitCnt = 0;
  7381. while (ACK_WaitCnt <= 20) //10s
  7382. {
  7383. //获取力矩值
  7384. Torque = (ushort)Convert.ToInt16(textBox_RunInfo_Torque.Text.Split(' ')[0]);
  7385. if (Torque > Max)
  7386. Max = Torque;
  7387. if ((Max <= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[1])) &&
  7388. (Max >= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[0])) &&
  7389. (ACK_WaitCnt >= 6))
  7390. {
  7391. label_FacModeTq.BackColor = Color.Green;
  7392. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器正常" + " " + textBox_RunInfo_Torque.Text + "\r\n");
  7393. break;
  7394. }
  7395. }
  7396. if (ACK_WaitCnt >= 20)
  7397. {
  7398. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器异常" + " " + textBox_RunInfo_Torque.Text + "\r\n");
  7399. label_FacModeStatus.Text = "存在故障!";
  7400. label_FacModeResult.BackColor = Color.Red;
  7401. label_FacModeResult.Text = "测试异常";
  7402. Delay_ms(500);
  7403. //存储异常并上传
  7404. FacMode_Stop(false);
  7405. return;
  7406. }
  7407. }
  7408. else
  7409. {
  7410. label_FacModeTq.BackColor = Color.Yellow;
  7411. label_FacModeStatus.Text = "跳过力矩检测!";
  7412. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过力矩检测" + "\r\n");
  7413. Delay_ms(500);
  7414. }
  7415. //踏频检测
  7416. if (checkBox_FacCad.Checked)
  7417. {
  7418. label_FacModeStatus.Text = "踏频传感器检测!";
  7419. //发送指令进入配置模式
  7420. do
  7421. {
  7422. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  7423. {
  7424. break;
  7425. }
  7426. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  7427. Code[0] = 0x01;
  7428. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7429. WriteACK = false;
  7430. ACK_WaitCnt = 0;
  7431. while (ACK_WaitCnt <= 2) ; //1s
  7432. if (textBox_RunInfo_Vol.Text != "---")
  7433. {
  7434. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7435. Delay_ms(500);
  7436. }
  7437. else
  7438. {
  7439. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  7440. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7441. ACK_WaitCnt = 0;
  7442. while (ACK_WaitCnt <= 2) ; //1s
  7443. if (textBox_RunInfo_Vol.Text != "---")
  7444. {
  7445. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7446. Delay_ms(500);
  7447. }
  7448. else
  7449. {
  7450. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7451. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7452. ACK_WaitCnt = 0;
  7453. while (ACK_WaitCnt <= 2) ; //1s
  7454. if (textBox_RunInfo_Vol.Text != "---")
  7455. {
  7456. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7457. Delay_ms(500);
  7458. }
  7459. else
  7460. {
  7461. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7462. label_FacModeStatus.Text = "存在故障!";
  7463. label_FacModeResult.BackColor = Color.Red;
  7464. label_FacModeResult.Text = "测试异常";
  7465. Delay_ms(500);
  7466. //存储异常并上传
  7467. FacMode_Stop(false);
  7468. return;
  7469. }
  7470. }
  7471. }
  7472. } while (false);
  7473. ushort Max = 0, Cadence = 0;
  7474. //提示输入踏频信号
  7475. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟踏频信号输入" + "\r\n");
  7476. ACK_WaitCnt = 0;
  7477. while (ACK_WaitCnt <= 20) //10s
  7478. {
  7479. //获取踏频
  7480. Cadence = (ushort)Convert.ToInt16(textBox_RunInfo_Cadence.Text.Split(' ')[0]);
  7481. if (Cadence > Max)
  7482. Max = Cadence;
  7483. if ((Max <= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[1])) &&
  7484. (Max >= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[0])) &&
  7485. (ACK_WaitCnt >= 6)) //3s内有踏频值达到阈值
  7486. {
  7487. label_FacModeCad.BackColor = Color.Green;
  7488. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器正常" + " " + Max.ToString() + " rpm" + "\r\n");
  7489. break;
  7490. }
  7491. }
  7492. if (ACK_WaitCnt >= 20)
  7493. {
  7494. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器异常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  7495. label_FacModeStatus.Text = "存在故障!";
  7496. label_FacModeResult.BackColor = Color.Red;
  7497. label_FacModeResult.Text = "测试异常";
  7498. Delay_ms(500);
  7499. //存储异常并上传
  7500. FacMode_Stop(false);
  7501. return;
  7502. }
  7503. }
  7504. else
  7505. {
  7506. label_FacModeCad.BackColor = Color.Yellow;
  7507. label_FacModeStatus.Text = "跳过踏频检测!";
  7508. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过踏频检测" + "\r\n");
  7509. Delay_ms(500);
  7510. }
  7511. //转把检测
  7512. if (checkBox_FacThrrotleTest.Checked)
  7513. {
  7514. label_FacModeStatus.Text = "转把检测";
  7515. //发送指令进入配置模式
  7516. do
  7517. {
  7518. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  7519. {
  7520. break;
  7521. }
  7522. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  7523. Code[0] = 0x01;
  7524. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7525. WriteACK = false;
  7526. ACK_WaitCnt = 0;
  7527. while (ACK_WaitCnt <= 2) ; //1s
  7528. if (textBox_RunInfo_Vol.Text != "---")
  7529. {
  7530. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7531. Delay_ms(500);
  7532. }
  7533. else
  7534. {
  7535. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  7536. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7537. ACK_WaitCnt = 0;
  7538. while (ACK_WaitCnt <= 2) ; //1s
  7539. if (textBox_RunInfo_Vol.Text != "---")
  7540. {
  7541. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7542. Delay_ms(500);
  7543. }
  7544. else
  7545. {
  7546. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7547. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7548. ACK_WaitCnt = 0;
  7549. while (ACK_WaitCnt <= 2) ; //1s
  7550. if (textBox_RunInfo_Vol.Text != "---")
  7551. {
  7552. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7553. Delay_ms(500);
  7554. }
  7555. else
  7556. {
  7557. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7558. label_FacModeStatus.Text = "存在故障!";
  7559. label_FacModeResult.BackColor = Color.Red;
  7560. label_FacModeResult.Text = "测试异常";
  7561. Delay_ms(500);
  7562. //存储异常并上传
  7563. FacMode_Stop(false);
  7564. return;
  7565. }
  7566. }
  7567. }
  7568. } while (false);
  7569. //进入TURBO档
  7570. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把检测,发送指令进入TURBO" + "\r\n");
  7571. Code[0] = 0x04;
  7572. Code[1] = 0xF0;
  7573. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7574. WriteACK = false;
  7575. ACK_WaitCnt = 0;
  7576. while (ACK_WaitCnt <= 2) ; //1s
  7577. if (textBox_RunInfo_GearSt.Text != "TURBO")
  7578. {
  7579. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO,第1次重发" + "\r\n");
  7580. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7581. ACK_WaitCnt = 0;
  7582. while (ACK_WaitCnt <= 2) ; //1s
  7583. if (textBox_RunInfo_GearSt.Text != "TURBO")
  7584. {
  7585. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO,第2次重发" + "\r\n");
  7586. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7587. ACK_WaitCnt = 0;
  7588. while (ACK_WaitCnt <= 2) ; //1s
  7589. if (textBox_RunInfo_GearSt.Text != "TURBO")
  7590. {
  7591. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO异常" + "\r\n");
  7592. label_FacModeStatus.Text = "存在故障!";
  7593. label_FacModeResult.BackColor = Color.Red;
  7594. label_FacModeResult.Text = "测试异常";
  7595. Delay_ms(500);
  7596. //存储异常并上传
  7597. FacMode_Stop(false);
  7598. return;
  7599. }
  7600. }
  7601. }
  7602. //进入TURBO后,如果电机直接启动,认为转把电压异常
  7603. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把自检,请松开转把" + "\r\n");
  7604. Delay_ms(3000);
  7605. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) > 500)
  7606. {
  7607. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把电压异常" + "\r\n");
  7608. label_FacModeStatus.Text = "存在故障!";
  7609. label_FacModeResult.BackColor = Color.Red;
  7610. label_FacModeResult.Text = "测试异常";
  7611. Delay_ms(500);
  7612. //存储异常并上传
  7613. FacMode_Stop(false);
  7614. return;
  7615. }
  7616. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把自检正常" + "\r\n");
  7617. Delay_ms(500);
  7618. //提示转动转把
  7619. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入TURBO,10s内转动转把" + "\r\n");
  7620. ACK_WaitCnt = 0;
  7621. while (ACK_WaitCnt <= 20)
  7622. {
  7623. if ((Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) > 500) && (ACK_WaitCnt >= 10)) //5s
  7624. {
  7625. label_FacModeGas.BackColor = Color.Green;
  7626. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能正常,电机转速:" + textBox_RunInfo_MotorSpeed.Text + ",请松开转把" + "\r\n");
  7627. break;
  7628. }
  7629. }
  7630. if (ACK_WaitCnt >= 20) //转把超时
  7631. {
  7632. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能异常,请松开转把" + "\r\n");
  7633. label_FacModeStatus.Text = "存在故障!";
  7634. label_FacModeResult.BackColor = Color.Red;
  7635. label_FacModeResult.Text = "测试异常";
  7636. Delay_ms(500);
  7637. //存储异常并上传
  7638. FacMode_Stop(false);
  7639. return;
  7640. }
  7641. }
  7642. else
  7643. {
  7644. label_FacModeGas.BackColor = Color.Yellow;
  7645. label_FacModeStatus.Text = "跳过转把检测!";
  7646. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过转把检测" + "\r\n");
  7647. Delay_ms(500);
  7648. }
  7649. //刹车检测
  7650. if (checkBox_FacBreakTest.Checked)
  7651. {
  7652. label_FacModeStatus.Text = "刹把检测";
  7653. //发送指令进入配置模式
  7654. do
  7655. {
  7656. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  7657. {
  7658. break;
  7659. }
  7660. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  7661. Code[0] = 0x01;
  7662. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7663. WriteACK = false;
  7664. ACK_WaitCnt = 0;
  7665. while (ACK_WaitCnt <= 2) ; //1s
  7666. if (textBox_RunInfo_Vol.Text != "---")
  7667. {
  7668. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7669. Delay_ms(500);
  7670. }
  7671. else
  7672. {
  7673. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  7674. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7675. ACK_WaitCnt = 0;
  7676. while (ACK_WaitCnt <= 2) ; //1s
  7677. if (textBox_RunInfo_Vol.Text != "---")
  7678. {
  7679. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7680. Delay_ms(500);
  7681. }
  7682. else
  7683. {
  7684. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7685. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7686. ACK_WaitCnt = 0;
  7687. while (ACK_WaitCnt <= 2) ; //1s
  7688. if (textBox_RunInfo_Vol.Text != "---")
  7689. {
  7690. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7691. Delay_ms(500);
  7692. }
  7693. else
  7694. {
  7695. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7696. label_FacModeStatus.Text = "存在故障!";
  7697. label_FacModeResult.BackColor = Color.Red;
  7698. label_FacModeResult.Text = "测试异常";
  7699. Delay_ms(500);
  7700. //存储异常并上传
  7701. FacMode_Stop(false);
  7702. return;
  7703. }
  7704. }
  7705. }
  7706. } while (false);
  7707. //测试前先确定电机已停止
  7708. UInt16 WaitTime = 20;
  7709. do
  7710. {
  7711. WaitTime--;
  7712. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 100)
  7713. {
  7714. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机停止,开始进行剎把检测,进入WALK" + "\r\n");
  7715. break;
  7716. }
  7717. if (WaitTime == 0)
  7718. {
  7719. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机无法停止,剎把检测异常" + "\r\n");
  7720. label_FacModeStatus.Text = "存在故障!";
  7721. label_FacModeResult.BackColor = Color.Red;
  7722. label_FacModeResult.Text = "测试异常";
  7723. Delay_ms(500);
  7724. //存储异常并上传
  7725. FacMode_Stop(false);
  7726. return;
  7727. }
  7728. Delay_ms(500);
  7729. } while (true);
  7730. //设置转速100%
  7731. var Data = new byte[1];
  7732. Data[0] = (byte)100;
  7733. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7734. Delay_ms(500);
  7735. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7736. Delay_ms(500);
  7737. //启动电机进入WALK模式
  7738. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把检测,进入WALK" + "\r\n");
  7739. Code[0] = 0x22;
  7740. Code[1] = 0xF0;
  7741. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7742. WriteACK = false;
  7743. ACK_WaitCnt = 0;
  7744. while (ACK_WaitCnt <= 2) ; //1s
  7745. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 500))
  7746. {
  7747. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第1次重发" + "\r\n");
  7748. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7749. ACK_WaitCnt = 0;
  7750. while (ACK_WaitCnt <= 2) ; //1s
  7751. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 500))
  7752. {
  7753. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第2次重发" + "\r\n");
  7754. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7755. ACK_WaitCnt = 0;
  7756. while (ACK_WaitCnt <= 2) ; //1s
  7757. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 500))
  7758. {
  7759. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
  7760. label_FacModeStatus.Text = "存在故障!";
  7761. label_FacModeResult.BackColor = Color.Red;
  7762. label_FacModeResult.Text = "测试异常";
  7763. Delay_ms(500);
  7764. //存储异常并上传
  7765. FacMode_Stop(false);
  7766. return;
  7767. }
  7768. }
  7769. }
  7770. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,10s内操作剎把" + "\r\n");
  7771. ACK_WaitCnt = 0;
  7772. while (ACK_WaitCnt <= 20)
  7773. {
  7774. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 100)
  7775. {
  7776. label_FacModeBreak.BackColor = Color.Green;
  7777. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把功能正常,松开剎把" + "\r\n");
  7778. break;
  7779. }
  7780. }
  7781. if (ACK_WaitCnt >= 20) //剎把超时
  7782. {
  7783. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速:" + textBox_RunInfo_MotorSpeed.Text + "," + "剎把功能异常,松开剎把" + "\r\n");
  7784. label_FacModeStatus.Text = "存在故障!";
  7785. label_FacModeResult.BackColor = Color.Red;
  7786. label_FacModeResult.Text = "测试异常";
  7787. Delay_ms(500);
  7788. //存储异常并上传
  7789. FacMode_Stop(false);
  7790. return;
  7791. }
  7792. //停止电机
  7793. Code[0] = 0x00;
  7794. Code[1] = 0xF0;
  7795. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7796. WriteACK = false;
  7797. ACK_WaitCnt = 0;
  7798. while (ACK_WaitCnt <= 2) ; //1s
  7799. if (textBox_RunInfo_GearSt.Text != "OFF")
  7800. {
  7801. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK,第1次重发" + "\r\n");
  7802. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7803. ACK_WaitCnt = 0;
  7804. while (ACK_WaitCnt <= 2) ; //1s
  7805. if (textBox_RunInfo_GearSt.Text != "OFF")
  7806. {
  7807. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK,第2次重发" + "\r\n");
  7808. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7809. ACK_WaitCnt = 0;
  7810. while (ACK_WaitCnt <= 2) ; //1s
  7811. if (textBox_RunInfo_GearSt.Text != "OFF")
  7812. {
  7813. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
  7814. label_FacModeStatus.Text = "存在故障!";
  7815. label_FacModeResult.BackColor = Color.Red;
  7816. label_FacModeResult.Text = "测试异常";
  7817. Delay_ms(500);
  7818. //存储异常并上传
  7819. FacMode_Stop(false);
  7820. return;
  7821. }
  7822. }
  7823. }
  7824. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK" + "\r\n");
  7825. Delay_ms(500);
  7826. }
  7827. else
  7828. {
  7829. label_FacModeBreak.BackColor = Color.Yellow;
  7830. label_FacModeStatus.Text = "跳过刹车检测!";
  7831. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过刹车检测" + "\r\n");
  7832. Delay_ms(500);
  7833. }
  7834. //前后灯检测
  7835. if (checkBox_FacLightTest.Checked)
  7836. {
  7837. //前后灯检测
  7838. label_FacModeStatus.Text = "前后灯检测";
  7839. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开灯指令" + "\r\n");
  7840. //发送指令打开车灯
  7841. Code[0] = 0x00;
  7842. Code[1] = 0xF1;
  7843. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7844. WriteACK = false;
  7845. ACK_WaitCnt = 0;
  7846. while (ACK_WaitCnt <= 2) ; //1s
  7847. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7848. {
  7849. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令,第1次重发" + "\r\n");
  7850. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7851. ACK_WaitCnt = 0;
  7852. while (ACK_WaitCnt <= 2); //1s
  7853. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7854. {
  7855. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令,第2次重发" + "\r\n");
  7856. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7857. ACK_WaitCnt = 0;
  7858. while (ACK_WaitCnt <= 2) ; //1s
  7859. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7860. {
  7861. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令发送异常" + "\r\n");
  7862. label_FacModeStatus.Text = "存在故障!";
  7863. label_FacModeResult.BackColor = Color.Red;
  7864. label_FacModeResult.Text = "测试异常";
  7865. Delay_ms(500);
  7866. //存储异常并上传
  7867. FacMode_Stop(false);
  7868. return;
  7869. }
  7870. }
  7871. }
  7872. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已打开前后灯" + "\r\n");
  7873. Delay_ms(500);
  7874. //提示检查灯压是否正确
  7875. if (MessageBox.Show("前后灯是否正常开启?", "前后灯判断", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  7876. {
  7877. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯开启正常" + "\r\n");
  7878. Delay_ms(500);
  7879. }
  7880. else
  7881. {
  7882. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯开启异常" + "\r\n");
  7883. label_FacModeStatus.Text = "存在故障!";
  7884. label_FacModeResult.BackColor = Color.Red;
  7885. label_FacModeResult.Text = "测试异常";
  7886. Delay_ms(500);
  7887. //存储异常并上传
  7888. FacMode_Stop(false);
  7889. return;
  7890. }
  7891. //发送指令关闭车灯
  7892. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关灯指令" + "\r\n");
  7893. Code[0] = 0x00;
  7894. Code[1] = 0xF0;
  7895. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7896. WriteACK = false;
  7897. ACK_WaitCnt = 0;
  7898. while (ACK_WaitCnt <= 2) ; //1s
  7899. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7900. {
  7901. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令,第1次重发" + "\r\n");
  7902. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7903. ACK_WaitCnt = 0;
  7904. while (ACK_WaitCnt <= 2) ; //1s
  7905. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7906. {
  7907. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令,第2次重发" + "\r\n");
  7908. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7909. ACK_WaitCnt = 0;
  7910. while (ACK_WaitCnt <= 2) ; //1s
  7911. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7912. {
  7913. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令发送异常" + "\r\n");
  7914. label_FacModeStatus.Text = "存在故障!";
  7915. label_FacModeResult.BackColor = Color.Red;
  7916. label_FacModeResult.Text = "测试异常";
  7917. Delay_ms(500);
  7918. //存储异常并上传
  7919. FacMode_Stop(false);
  7920. return;
  7921. }
  7922. }
  7923. }
  7924. //提示检查灯压是否关闭
  7925. if (MessageBox.Show("前后灯是否正常关闭?", "前后灯判断", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  7926. {
  7927. label_FacModeLightF.BackColor = Color.Green;
  7928. label_FacModeLightB.BackColor = Color.Green;
  7929. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯关闭正常" + "\r\n");
  7930. Delay_ms(500);
  7931. }
  7932. else
  7933. {
  7934. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯关闭异常" + "\r\n");
  7935. label_FacModeStatus.Text = "存在故障!";
  7936. label_FacModeResult.BackColor = Color.Red;
  7937. label_FacModeResult.Text = "测试异常";
  7938. Delay_ms(500);
  7939. //存储异常并上传
  7940. FacMode_Stop(false);
  7941. return;
  7942. }
  7943. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已关闭前后灯" + "\r\n");
  7944. }
  7945. else
  7946. {
  7947. label_FacModeLightF.BackColor = Color.Yellow;
  7948. label_FacModeLightB.BackColor = Color.Yellow;
  7949. label_FacModeStatus.Text = "跳过前后灯检测!";
  7950. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过前后灯检测" + "\r\n");
  7951. Delay_ms(500);
  7952. }
  7953. //软件版本检测
  7954. do
  7955. {
  7956. label_FacModeStatus.Text = "软件版本确认";
  7957. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  7958. //发送指令读取版本
  7959. Class_Motor_Ver.Mode = "---";
  7960. Class_Motor_Ver.SN = "---";
  7961. Class_Motor_Ver.HW = "---";
  7962. Class_Motor_Ver.FW = "---";
  7963. Class_Motor_Ver.Special = "---";
  7964. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7965. ACK_WaitCnt = 0;
  7966. while (ACK_WaitCnt <= 2) ; //1s
  7967. if (Class_Motor_Ver.Mode == "---")
  7968. {
  7969. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第1次重发" + "\r\n");
  7970. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7971. ACK_WaitCnt = 0;
  7972. while (ACK_WaitCnt <= 2) ; //1s
  7973. if (Class_Motor_Ver.Mode == "---")
  7974. {
  7975. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第2次重发" + "\r\n");
  7976. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7977. ACK_WaitCnt = 0;
  7978. while (ACK_WaitCnt <= 2) ; //1s
  7979. if (Class_Motor_Ver.Mode == "---")
  7980. {
  7981. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息失败" + "\r\n");
  7982. label_FacModeStatus.Text = "存在故障!";
  7983. label_FacModeResult.BackColor = Color.Red;
  7984. label_FacModeResult.Text = "测试异常";
  7985. Delay_ms(500);
  7986. //存储异常并上传
  7987. FacMode_Stop(false);
  7988. return;
  7989. }
  7990. }
  7991. }
  7992. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  7993. richTextBox_FacModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  7994. richTextBox_FacModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  7995. richTextBox_FacModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  7996. richTextBox_FacModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  7997. richTextBox_FacModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  7998. //判断版本是否正确
  7999. string VerCheck = comboBox_FacModeCfgFile.Text.Split('_')[3] + "_" + comboBox_FacModeCfgFile.Text.Split('_')[4];
  8000. string VerRead = "";
  8001. try
  8002. {
  8003. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  8004. }
  8005. catch (System.Exception)
  8006. {
  8007. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  8008. label_FacModeStatus.Text = "存在故障!";
  8009. label_FacModeResult.BackColor = Color.Red;
  8010. label_FacModeResult.Text = "测试异常";
  8011. Delay_ms(500);
  8012. //存储异常并上传
  8013. FacMode_Stop(false);
  8014. return;
  8015. }
  8016. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  8017. {
  8018. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
  8019. label_FacModeStatus.Text = "存在故障!";
  8020. label_FacModeResult.BackColor = Color.Red;
  8021. label_FacModeResult.Text = "测试异常";
  8022. Delay_ms(500);
  8023. //存储异常并上传
  8024. FacMode_Stop(false);
  8025. return;
  8026. }
  8027. label_FacModeFWVersion.BackColor = Color.Green;
  8028. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  8029. Delay_ms(500);
  8030. } while (false);
  8031. //测试合格
  8032. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  8033. label_FacModeStatus.Text = "测试结束!";
  8034. label_FacModeResult.BackColor = Color.Green;
  8035. label_FacModeResult.Text = "测试合格";
  8036. Delay_ms(500);
  8037. //存储并上传
  8038. FacMode_Stop(true);
  8039. return;
  8040. }
  8041. private void FacModelLabelInit()
  8042. {
  8043. //测试状态标签
  8044. label_FacModeResult.BackColor = Color.Yellow;
  8045. label_FacModeResult.Text = "测试中";
  8046. //测试过程标签
  8047. label_FacModeStatus.Text = "测试就绪";
  8048. //测试结果标签
  8049. foreach (Control c in groupBox28.Controls)
  8050. {
  8051. if (c is Label)
  8052. {
  8053. if (c.Text == string.Empty)
  8054. c.BackColor = Color.Red;
  8055. }
  8056. }
  8057. }
  8058. private void comboBox_CheckModeCfgDate_Click(object sender, EventArgs e)
  8059. {
  8060. //更新生产配置文件目录
  8061. GetDateList(false);
  8062. }
  8063. private void comboBox_FacModeCfgDate_Click(object sender, EventArgs e)
  8064. {
  8065. //更新生产配置文件目录
  8066. GetDateList(false);
  8067. }
  8068. private void richTextBox_FacModeLog_TextChanged(object sender, EventArgs e)
  8069. {
  8070. richTextBox_FacModeLog.SelectionStart = richTextBox_FacModeLog.Text.Length;
  8071. richTextBox_FacModeLog.ScrollToCaret();
  8072. }
  8073. /// <summary>
  8074. /// 参数检验测试停止
  8075. /// </summary>
  8076. /// <param name="OK_Flag"></param>
  8077. private void CheckMode_Stop(bool OK_Flag)
  8078. {
  8079. //打开开始按钮
  8080. button_CheckModeStart.Enabled = true;
  8081. //导出电机参数
  8082. string Params = "";
  8083. do
  8084. {
  8085. if (!OK_Flag)
  8086. {
  8087. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试异常,停止导出" + "\r\n");
  8088. break;
  8089. }
  8090. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "导出电机存储参数" + "\r\n");
  8091. //读取一次马达参数
  8092. richTextBox_MotorParam.Clear();
  8093. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break; ;
  8094. Delay_ms(100);
  8095. Params += "[马达参数]" + "\r\n" + richTextBox_MotorParam.Text + "\r\n";
  8096. Params += "\r\n";
  8097. //读取一次整车参数
  8098. richTextBox_BikeParam.Clear();
  8099. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  8100. Delay_ms(100);
  8101. Params += "[整车参数]" + "\r\n" + richTextBox_BikeParam.Text + "\r\n";
  8102. Params += "\r\n";
  8103. //读取一次控制参数
  8104. richTextBox_ControlParam.Clear();
  8105. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  8106. Delay_ms(100);
  8107. Params += "[控制参数]" + "\r\n" + richTextBox_ControlParam.Text + "\r\n";
  8108. Params += "\r\n";
  8109. //查询传感器
  8110. richTextBox_SensorParam.Clear();
  8111. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  8112. Delay_ms(100);
  8113. Params += "[传感器参数]" + "\r\n" + richTextBox_SensorParam.Text + "\r\n";
  8114. Params += "\r\n";
  8115. //读取15次助力参数
  8116. Params += "[助力参数]" + "\r\n";
  8117. for (int i = 1; i <= 15; i++)
  8118. {
  8119. var ConfigParam = new byte[4];
  8120. richTextBox_AssistParam.Clear();
  8121. ConfigParam[0] = (byte)(i & 0xFF);
  8122. ConfigParam[1] = (byte)(i >> 8);
  8123. ConfigParam[2] = (byte)(((i >= 5) ? 5 : i) & 0xFF);
  8124. ConfigParam[3] = (byte)(((i >= 5) ? 5 : i) >> 8);
  8125. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  8126. Delay_ms(200);
  8127. Params += richTextBox_AssistParam.Text + "\r\n";
  8128. Params += "\r\n";
  8129. }
  8130. //读取一次调试信息
  8131. richTextBox_DebugParam.Clear();
  8132. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  8133. Delay_ms(100);
  8134. Params += "[调试参数]" + "\r\n" + richTextBox_DebugParam.Text + "\r\n";
  8135. Params += "\r\n";
  8136. //读取一次历史信息
  8137. richTextBox_Record.Clear();
  8138. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  8139. Delay_ms(100);
  8140. Params += "[历史信息]" + "\r\n" + richTextBox_Record.Text + "\r\n";
  8141. Params += "\r\n";
  8142. //读取一次MOS内阻校准参数
  8143. foreach (Control c in groupBox21.Controls)
  8144. {
  8145. if (c is TextBox)
  8146. c.Text = "";
  8147. }
  8148. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8149. Delay_ms(100);
  8150. Params += "[MOS内阻校准参数]" + "\r\n";
  8151. Params += textBox_MOS_K1.Text + ", " + textBox_MOS_K2.Text + ", " + textBox_MOS_K3.Text + ", " + textBox_MOS_K4.Text + ", "
  8152. + textBox_MOS_K5.Text + ", " + textBox_MOS_R1.Text + ", " + textBox_MOS_R2.Text + ", " + textBox_MOS_R3.Text + ", " + "\r\n";
  8153. Params += "\r\n";
  8154. //读取一次整车参数2
  8155. richTextBox_BikeParam2.Clear();
  8156. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null)) break;
  8157. Delay_ms(100);
  8158. Params += "[整车参数2]" + "\r\n" + richTextBox_BikeParam2.Text + "\r\n";
  8159. Params += "\r\n";
  8160. //读取一次用户骑行参数
  8161. richTextBox_UsrRidesParam.Clear();
  8162. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  8163. Delay_ms(100);
  8164. Params += "[用户骑行参数]" + "\r\n" + richTextBox_UsrRidesParam.Text + "\r\n";
  8165. Params += "\r\n";
  8166. //读取一次生产信息
  8167. textBox_MAC.Text = "";
  8168. textBox_MACAdd.Text = "";
  8169. textBox_MACDate.Text = "";
  8170. textBox_PP.Text = "";
  8171. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  8172. Delay_ms(100);
  8173. Params += "[生产信息]" + "\r\n";
  8174. Params += "生产商: " + textBox_MAC.Text + "\r\n";
  8175. Params += "生产地: " + textBox_MACAdd.Text + "\r\n";
  8176. Params += "生产日期: " + textBox_MACDate.Text + "\r\n";
  8177. Params += "产品标识: " + textBox_PP.Text + "\r\n";
  8178. Params += "\r\n";
  8179. //读取一次自定义信息
  8180. textBox_User1.Text = "---";
  8181. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  8182. Delay_ms(100);
  8183. textBox_User2.Text = "---";
  8184. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  8185. Delay_ms(100);
  8186. textBox_User3.Text = "---";
  8187. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  8188. Delay_ms(100);
  8189. Params += "[自定义信息]" + "\r\n";
  8190. Params += "自定义1: " + textBox_User1.Text + "\r\n";
  8191. Params += "自定义2: " + textBox_User2.Text + "\r\n";
  8192. Params += "自定义3: " + textBox_User3.Text + "\r\n";
  8193. Params += "\r\n";
  8194. //读取一次密钥
  8195. textBox_Key.Text = "---";
  8196. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  8197. Delay_ms(100);
  8198. Params += "[校验密钥]" + "\r\n" + textBox_Key.Text + "\r\n";
  8199. Params += "\r\n";
  8200. //读取一次存储标志
  8201. radioButton_EE_SaveYes.Checked = false;
  8202. radioButton_EE_SaveNo.Checked = false;
  8203. radioButton_SIP_SaveYes.Checked = false;
  8204. radioButton_SIP_SaveNo.Checked = false;
  8205. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  8206. Delay_ms(100);
  8207. Params += "[存储标志]" + "\r\n";
  8208. Params += "EEPROM: " + ((radioButton_EE_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  8209. Params += "SIP: " + ((radioButton_SIP_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  8210. Params += "\r\n";
  8211. } while (false);
  8212. //系统关机
  8213. var Code = new byte[32];//发送的指令数据
  8214. Code[0] = 0xF0;
  8215. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  8216. //关闭串口
  8217. //mySerialProcess.SerialClose(false);
  8218. //路径设置
  8219. string LocalSavePath = "";
  8220. string ServerSavePath = "";
  8221. if (OK_Flag)
  8222. {
  8223. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "OK\\";
  8224. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/OK/";
  8225. }
  8226. else
  8227. {
  8228. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "FAIL\\";
  8229. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/FAIL/";
  8230. }
  8231. if (Directory.Exists(LocalSavePath) == false)
  8232. {
  8233. Directory.CreateDirectory(LocalSavePath);
  8234. }
  8235. //保存和上传
  8236. string LogSavePath = "";
  8237. string LogSaveFileName = "";
  8238. string ProductInfo = textBox_CheckModeScan.Text.Replace(" ", "_").Replace("/", "-"); ;
  8239. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  8240. if (Directory.Exists(LogSavePath) == false)
  8241. {
  8242. Directory.CreateDirectory(LogSavePath);
  8243. }
  8244. //测试页面
  8245. Double scaleX = PrimaryScreen.ScaleX;
  8246. Double scaleY = PrimaryScreen.ScaleY;
  8247. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  8248. Graphics g = Graphics.FromImage(bit);
  8249. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  8250. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  8251. bit.Save(LogSaveFileName);
  8252. //上传测试页面到服务器
  8253. if (myFtp.IsNetConnected == true)
  8254. {
  8255. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  8256. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  8257. {
  8258. myFtp.MakeDir(ServerSavePath + DateNow);
  8259. }
  8260. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  8261. {
  8262. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  8263. }
  8264. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  8265. if (result == true)
  8266. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  8267. }
  8268. //测试记录
  8269. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  8270. string file_str = "";
  8271. file_str += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  8272. file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  8273. file_str += "检验记录:\r\n" + richTextBox_CheckModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  8274. file_str += "检验结果:\r\n" + label_CheckModeResult.Text + "\r\n\r\n";
  8275. file_str += Local_HdInformation;
  8276. file_str += "\r\n电机存储参数:\r\n" + Params + "\r\n";
  8277. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  8278. //上传测试记录到服务器
  8279. if (myFtp.IsNetConnected == true)
  8280. {
  8281. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  8282. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  8283. {
  8284. myFtp.MakeDir(ServerSavePath + DateNow);
  8285. }
  8286. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  8287. {
  8288. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  8289. }
  8290. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  8291. if (result == true)
  8292. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  8293. }
  8294. //扫码框清空
  8295. textBox_CheckModeScan.Text = "";
  8296. }
  8297. /// <summary>
  8298. /// 参数检验开始
  8299. /// </summary>
  8300. /// <param name="sender"></param>
  8301. /// <param name="e"></param>
  8302. private void button_CheckModeStart_Click(object sender, EventArgs e)
  8303. {
  8304. //测试项目关闭编辑
  8305. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  8306. foreach (Control c in groupBox29.Controls)
  8307. {
  8308. if (c is CheckBox)
  8309. c.Enabled = false;
  8310. }
  8311. ReadLockStatus = true;
  8312. //检查配置文件
  8313. if (comboBox_CheckModeCfgFile.Text == "")
  8314. {
  8315. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  8316. return;
  8317. }
  8318. //开始测试
  8319. CheckTestStart();
  8320. }
  8321. /// <summary>
  8322. /// 参数检验测试子函数
  8323. /// </summary>
  8324. private void CheckTestStart()
  8325. {
  8326. //初始化标签
  8327. CheckModeLabelInit();
  8328. richTextBox_CheckModeLog.Clear();
  8329. //按钮禁止操作
  8330. button_CheckModeStart.Enabled = false;
  8331. //记录配置文件
  8332. richTextBox_CheckModeLog.AppendText("配置文件:" + comboBox_CheckModeCfgDate.Text + " / " + comboBox_CheckModeCfgFile.Text + "\r\n");
  8333. //检查打标信息
  8334. label_CheckModeStatus.Text = "检查扫码信息";
  8335. Delay_ms(500);
  8336. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  8337. if (textBox_CheckModeScan.Text == string.Empty)
  8338. {
  8339. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  8340. button__FacMode_Start.Enabled = false;
  8341. return;
  8342. }
  8343. try
  8344. {
  8345. if (中置电机MIGIC_ToolStripMenuItem.Checked == true)
  8346. {
  8347. if (textBox_CheckModeScan.Text.Split(' ').Length != 7)
  8348. {
  8349. label_CheckModeStatus.Text = "存在故障!";
  8350. label_CheckModeResult.BackColor = Color.Red;
  8351. label_CheckModeResult.Text = "标签格式错误";
  8352. button_CheckModeStart.Enabled = true;
  8353. return;
  8354. }
  8355. }
  8356. else if (中置电机VP_ToolStripMenuItem.Checked == true)
  8357. {
  8358. if (textBox_CheckModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 2)
  8359. {
  8360. label_CheckModeStatus.Text = "存在故障!";
  8361. label_CheckModeResult.BackColor = Color.Red;
  8362. label_CheckModeResult.Text = "标签格式错误";
  8363. button_CheckModeStart.Enabled = true;
  8364. return;
  8365. }
  8366. }
  8367. else if (轮毂电机ToolStripMenuItem.Checked == true)
  8368. {
  8369. if (textBox_CheckModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  8370. {
  8371. label_CheckModeStatus.Text = "存在故障!";
  8372. label_CheckModeResult.BackColor = Color.Red;
  8373. label_CheckModeResult.Text = "标签格式错误";
  8374. button_CheckModeStart.Enabled = true;
  8375. return;
  8376. }
  8377. }
  8378. }
  8379. catch (System.Exception)
  8380. {
  8381. label_CheckModeStatus.Text = "存在故障!";
  8382. label_CheckModeResult.BackColor = Color.Red;
  8383. label_CheckModeResult.Text = "标签格式错误";
  8384. button_CheckModeStart.Enabled = true;
  8385. return;
  8386. }
  8387. //打开串口
  8388. mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false);
  8389. if (!mySerialProcess.mySerial.IsOpen)
  8390. {
  8391. MessageBox.Show("请检查串口连接!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  8392. button__FacMode_Start.Enabled = false;
  8393. return;
  8394. }
  8395. //流水号计数
  8396. int serial = Convert.ToInt32(label_CheckModeSerial.Text);
  8397. serial += 1;
  8398. label_CheckModeSerial.Text = serial.ToString();
  8399. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, serial.ToString());
  8400. //创建线程,执行测试任务
  8401. Thread th = new Thread(CheckModeTest_Task);
  8402. th.Start();
  8403. }
  8404. /// <summary>
  8405. /// 执行一次测试任务
  8406. /// </summary>
  8407. private void CheckModeTest_Task()
  8408. {
  8409. //开始测试
  8410. richTextBox_CheckModeLog.AppendText("产品标签:" + textBox_CheckModeScan.Text + "\r\n");
  8411. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  8412. //变量定义
  8413. var Code = new byte[255];//发送的指令数据
  8414. label_CheckModeStatus.Text = "开始测试";
  8415. Delay_ms(500);
  8416. label_CheckModeStatus.Text = "系统开机";
  8417. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  8418. if (uARTToolStripMenuItem.Checked)
  8419. {
  8420. Code[0] = (byte)'R';
  8421. Code[1] = (byte)'E';
  8422. Code[2] = (byte)'S';
  8423. Code[3] = (byte)'E';
  8424. Code[4] = (byte)'T';
  8425. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  8426. Delay_ms(500);
  8427. }
  8428. //系统开机,确保测试前先关机,发送关机指令再发送开机指令
  8429. //确保测试前先关机,发送关机指令再发送开机指令
  8430. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  8431. Code[0] = 0xF0;
  8432. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  8433. Delay_ms(1500);
  8434. BootInfo = "";
  8435. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  8436. Code[0] = 0xF1;
  8437. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  8438. ACK_WaitCnt = 0;
  8439. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  8440. while (ACK_WaitCnt <= 20);
  8441. //检查BOOT版本
  8442. if (BootInfo != string.Empty)
  8443. {
  8444. label_CheckModeBoot.BackColor = Color.Green;
  8445. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  8446. Delay_ms(500);
  8447. }
  8448. else
  8449. {
  8450. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
  8451. label_CheckModeStatus.Text = "存在故障!";
  8452. label_CheckModeResult.BackColor = Color.Red;
  8453. label_CheckModeResult.Text = "测试异常";
  8454. Delay_ms(500);
  8455. //存储异常并上传
  8456. CheckMode_Stop(false);
  8457. return;
  8458. }
  8459. #if false
  8460. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  8461. {
  8462. Code[0] = 0x00;//5S协议
  8463. Code[1] = 0x00;
  8464. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  8465. Delay_ms(500);
  8466. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  8467. Delay_ms(500);
  8468. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  8469. }
  8470. #endif
  8471. //发送指令读取版本信息
  8472. do
  8473. {
  8474. label_CheckModeStatus.Text = "读取版本信息";
  8475. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  8476. //发送指令读取版本
  8477. Class_Motor_Ver.Mode = "---";
  8478. Class_Motor_Ver.SN = "---";
  8479. Class_Motor_Ver.HW = "---";
  8480. Class_Motor_Ver.FW = "---";
  8481. Class_Motor_Ver.Special = "---";
  8482. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  8483. ACK_WaitCnt = 0;
  8484. while (ACK_WaitCnt <= 2) ; //1s
  8485. if (Class_Motor_Ver.Mode == "---")
  8486. {
  8487. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第1次重发" + "\r\n");
  8488. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  8489. ACK_WaitCnt = 0;
  8490. while (ACK_WaitCnt <= 2) ; //1s
  8491. if (Class_Motor_Ver.Mode == "---")
  8492. {
  8493. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第2次重发" + "\r\n");
  8494. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  8495. ACK_WaitCnt = 0;
  8496. while (ACK_WaitCnt <= 2) ; //1s
  8497. if (Class_Motor_Ver.Mode == "---")
  8498. {
  8499. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取失败" + "\r\n");
  8500. label_CheckModeStatus.Text = "存在故障!";
  8501. label_CheckModeResult.BackColor = Color.Red;
  8502. label_CheckModeResult.Text = "测试异常";
  8503. Delay_ms(500);
  8504. //存储异常并上传
  8505. CheckMode_Stop(false);
  8506. return;
  8507. }
  8508. }
  8509. }
  8510. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  8511. richTextBox_CheckModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  8512. richTextBox_CheckModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  8513. richTextBox_CheckModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  8514. richTextBox_CheckModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  8515. richTextBox_CheckModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  8516. Delay_ms(500);
  8517. } while (false);
  8518. //软件版本检查
  8519. if (checkBox_CheckModeFWVer.Checked)
  8520. {
  8521. //判断版本是否正确
  8522. string VerCheck = comboBox_CheckModeCfgFile.Text.Split('_')[3] + "_" + comboBox_CheckModeCfgFile.Text.Split('_')[4];
  8523. string VerRead = "";
  8524. try
  8525. {
  8526. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  8527. }
  8528. catch (System.Exception)
  8529. {
  8530. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  8531. label_CheckModeStatus.Text = "存在故障!";
  8532. label_CheckModeResult.BackColor = Color.Red;
  8533. label_CheckModeResult.Text = "测试异常";
  8534. Delay_ms(500);
  8535. //存储异常并上传
  8536. CheckMode_Stop(false);
  8537. return;
  8538. }
  8539. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  8540. {
  8541. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
  8542. label_CheckModeStatus.Text = "存在故障!";
  8543. label_CheckModeResult.BackColor = Color.Red;
  8544. label_CheckModeResult.Text = "测试异常";
  8545. Delay_ms(500);
  8546. //存储异常并上传
  8547. CheckMode_Stop(false);
  8548. return;
  8549. }
  8550. label_CheckModeFWVer.BackColor = Color.Green;
  8551. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  8552. Delay_ms(500);
  8553. }
  8554. else
  8555. {
  8556. label_CheckModeFWVer.BackColor = Color.Yellow;
  8557. label_CheckModeStatus.Text = "跳过软件版本查询";
  8558. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过软件版本查询" + "\r\n");
  8559. Delay_ms(500);
  8560. }
  8561. //打标信息核对
  8562. if (checkBox_CheckModeSN.Checked)
  8563. {
  8564. label_CheckModeStatus.Text = "核对打标信息";
  8565. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "核对打标信息" + "\r\n");
  8566. //根据扫码信息获取型号和SN
  8567. string ScanInfo = textBox_CheckModeScan.Text;
  8568. string regexInfo = "";
  8569. string[] InfoList = { "" };
  8570. try
  8571. {
  8572. if (中置电机MIGIC_ToolStripMenuItem.Checked == true)
  8573. {
  8574. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  8575. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  8576. }
  8577. else if (中置电机VP_ToolStripMenuItem.Checked == true)
  8578. {
  8579. Regex regex = new Regex(@"^M[12][0-9](0?[1-9]|1[0-2])((0?[1-9])|((1|2)[0-9])|30|31)[A-Z]\d{4}[A-Z][A-Z]?$");
  8580. if (ScanInfo.Contains(" "))
  8581. {
  8582. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  8583. string Mode = InfoList[0];
  8584. string Sn = InfoList[1];
  8585. if (regex.IsMatch(Sn) == false)
  8586. {
  8587. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN格式错误" + "\r\n");
  8588. label_FacModeStatus.Text = "存在故障!";
  8589. label_FacModeResult.BackColor = Color.Red;
  8590. label_FacModeResult.Text = "标签格式错误";
  8591. Delay_ms(500);
  8592. //存储异常并上传
  8593. FacMode_Stop(false);
  8594. return;
  8595. }
  8596. }
  8597. else
  8598. {
  8599. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  8600. label_FacModeStatus.Text = "存在故障!";
  8601. label_FacModeResult.BackColor = Color.Red;
  8602. label_FacModeResult.Text = "标签格式错误";
  8603. Delay_ms(500);
  8604. //存储异常并上传
  8605. FacMode_Stop(false);
  8606. return;
  8607. }
  8608. }
  8609. else if (轮毂电机ToolStripMenuItem.Checked == true)
  8610. {
  8611. if (!ScanInfo.Contains("/")) //老编码规则
  8612. {
  8613. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  8614. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  8615. string Spec = InfoList[1];
  8616. string Sn = InfoList[2];
  8617. InfoList[0] = Model.Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  8618. InfoList[1] = Sn;
  8619. }
  8620. else //新编码规则
  8621. {
  8622. Dictionary<string, string> Dic_Ver = new Dictionary<string, string>
  8623. {
  8624. { "01", "A" },
  8625. { "02", "B" },
  8626. { "03", "C" },
  8627. { "04", "D" },
  8628. { "05", "E" },
  8629. { "06", "F" },
  8630. { "07", "G" },
  8631. { "08", "H" },
  8632. { "09", "I" }
  8633. };
  8634. Dictionary<string, string> Dic_Vol = new Dictionary<string, string>
  8635. {
  8636. { "24V", "A" },
  8637. { "36V", "B" },
  8638. { "42V", "C" },
  8639. { "48V", "D" },
  8640. { "52V", "E" },
  8641. { "60V", "F" }
  8642. };
  8643. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  8644. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  8645. string Spec = InfoList[1].Replace("-", "").Replace("/", "");
  8646. string Sn = InfoList[2];
  8647. InfoList[0] = Model[2] + Dic_Ver[Model.Substring(3, 2)] + Model[5] + Dic_Ver[Model.Substring(6, 2)] + Model[9];
  8648. InfoList[0] += Dic_Vol[Spec.Substring(0, 3)] + Spec.Substring(3, 3) + Spec.Substring(13, 4) + Spec.Substring(Spec.Length - 4, 3);
  8649. InfoList[1] = Sn;
  8650. }
  8651. }
  8652. }
  8653. catch
  8654. {
  8655. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  8656. label_FacModeStatus.Text = "存在故障!";
  8657. label_FacModeResult.BackColor = Color.Red;
  8658. label_FacModeResult.Text = "标签格式错误";
  8659. Delay_ms(500);
  8660. //存储异常并上传
  8661. CheckMode_Stop(false);
  8662. return;
  8663. }
  8664. //核对型号
  8665. if (string.Equals(InfoList[0], Class_Motor_Ver.Mode) == false) //型号错误,直接结束
  8666. {
  8667. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号不一致" + "\r\n");
  8668. label_CheckModeStatus.Text = "存在故障!";
  8669. label_CheckModeResult.BackColor = Color.Red;
  8670. label_CheckModeResult.Text = "测试异常";
  8671. Delay_ms(500);
  8672. //存储异常并上传
  8673. CheckMode_Stop(false);
  8674. return;
  8675. }
  8676. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号一致" + "\r\n");
  8677. Delay_ms(500);
  8678. //核对SN
  8679. if (string.Equals(InfoList[1], Class_Motor_Ver.SN) == false) //型号错误,直接结束
  8680. {
  8681. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN不一致" + "\r\n");
  8682. label_CheckModeStatus.Text = "存在故障!";
  8683. label_CheckModeResult.BackColor = Color.Red;
  8684. label_CheckModeResult.Text = "测试异常";
  8685. Delay_ms(500);
  8686. //存储异常并上传
  8687. CheckMode_Stop(false);
  8688. return;
  8689. }
  8690. label_CheckModeSN.BackColor = Color.Green;
  8691. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN一致" + "\r\n");
  8692. Delay_ms(500);
  8693. }
  8694. else
  8695. {
  8696. label_CheckModeSN.BackColor = Color.Yellow;
  8697. label_CheckModeStatus.Text = "跳过打标信息确认";
  8698. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过打标信息确认" + "\r\n");
  8699. Delay_ms(500);
  8700. }
  8701. //参数检验
  8702. if (checkBox_CheckModeCfg.Checked)
  8703. {
  8704. //读取配置文件信息
  8705. label_CheckModeStatus.Text = "参数检查";
  8706. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  8707. //配置文件
  8708. List<byte[]> CmdList = new List<byte[]>();
  8709. Dictionary<string, string> ConfigCmd = new Dictionary<string, string>();//配置文件格式
  8710. //从服务器下载文件
  8711. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  8712. {
  8713. string SelectFile = "";
  8714. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "/" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  8715. if (File.Exists(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  8716. {
  8717. File.Delete(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  8718. }
  8719. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  8720. //打开文件
  8721. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  8722. ConfigCmd.Clear();
  8723. while (streamReader.Peek() != -1)
  8724. {
  8725. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  8726. if (fileLineInfo.Contains("["))
  8727. {
  8728. if (fileLineInfo.Contains("助力参数"))
  8729. {
  8730. fileLineInfo = streamReader.ReadLine();
  8731. }
  8732. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  8733. }
  8734. }
  8735. streamReader.Close();
  8736. }
  8737. //从本地加载文件
  8738. else
  8739. {
  8740. string SelectFile = "";
  8741. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  8742. //打开文件
  8743. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  8744. ConfigCmd.Clear();
  8745. while (streamReader.Peek() != -1)
  8746. {
  8747. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  8748. if (fileLineInfo.Contains("["))
  8749. {
  8750. if (fileLineInfo.Contains("助力参数"))
  8751. {
  8752. fileLineInfo = streamReader.ReadLine();
  8753. }
  8754. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  8755. }
  8756. }
  8757. streamReader.Close();
  8758. }
  8759. int CmdNum = ConfigCmd.Count(); //指令个数
  8760. Delay_ms(500);
  8761. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "\r\n");
  8762. Delay_ms(500);
  8763. //逐条读取比较
  8764. try
  8765. {
  8766. foreach (string key in ConfigCmd.Keys)
  8767. {
  8768. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令:" + "\r\n");
  8769. CmdRevStrTemp = "";
  8770. if (key.Contains("曲线"))
  8771. {
  8772. byte LineNum = 0;
  8773. var code = new byte[4];
  8774. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  8775. if (LineNum <= 5)
  8776. {
  8777. code[0] = (byte)(LineNum & 0xFF);
  8778. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8779. code[2] = (byte)(LineNum & 0xFF);
  8780. code[3] = (byte)((LineNum >> 8) & 0xFF);
  8781. }
  8782. else
  8783. {
  8784. code[0] = (byte)(LineNum & 0xFF);
  8785. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8786. code[2] = (byte)(5 & 0xFF);
  8787. code[3] = (byte)((5 >> 8) & 0xFF);
  8788. }
  8789. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  8790. }
  8791. else
  8792. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  8793. Delay_ms(500);
  8794. if (CmdRevStrTemp == string.Empty)
  8795. {
  8796. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令,第1次重发" + "\r\n");
  8797. if (key.Contains("曲线"))
  8798. {
  8799. byte LineNum = 0;
  8800. var code = new byte[4];
  8801. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  8802. if (LineNum <= 5)
  8803. {
  8804. code[0] = (byte)(LineNum & 0xFF);
  8805. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8806. code[2] = (byte)(LineNum & 0xFF);
  8807. code[3] = (byte)((LineNum >> 8) & 0xFF);
  8808. }
  8809. else
  8810. {
  8811. code[0] = (byte)(LineNum & 0xFF);
  8812. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8813. code[2] = (byte)(5 & 0xFF);
  8814. code[3] = (byte)((5 >> 8) & 0xFF);
  8815. }
  8816. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  8817. }
  8818. else
  8819. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  8820. Delay_ms(500);
  8821. if (CmdRevStrTemp == string.Empty)
  8822. {
  8823. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令,第2次重发" + "\r\n");
  8824. if (key.Contains("曲线"))
  8825. {
  8826. byte LineNum = 0;
  8827. var code = new byte[4];
  8828. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  8829. if (LineNum <= 5)
  8830. {
  8831. code[0] = (byte)(LineNum & 0xFF);
  8832. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8833. code[2] = (byte)(LineNum & 0xFF);
  8834. code[3] = (byte)((LineNum >> 8) & 0xFF);
  8835. }
  8836. else
  8837. {
  8838. code[0] = (byte)(LineNum & 0xFF);
  8839. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8840. code[2] = (byte)(5 & 0xFF);
  8841. code[3] = (byte)((5 >> 8) & 0xFF);
  8842. }
  8843. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  8844. }
  8845. else
  8846. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  8847. Delay_ms(500);
  8848. if (CmdRevStrTemp == string.Empty)
  8849. {
  8850. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "指令读取失败" + "\r\n");
  8851. label_CheckModeStatus.Text = "存在故障!";
  8852. label_CheckModeResult.BackColor = Color.Red;
  8853. label_CheckModeResult.Text = "测试异常";
  8854. Delay_ms(500);
  8855. //存储异常并上传
  8856. CheckMode_Stop(false);
  8857. return;
  8858. }
  8859. }
  8860. }
  8861. //比较当前指令,读取的配置文件和返回数据比较
  8862. string ParamWrite = ConfigCmd[key].Substring(24, ConfigCmd[key].Length - 40).Trim();
  8863. string ParamRead = "";
  8864. ushort CmdGet = Convert.ToUInt16(CmdRevStrTemp.Substring(0, 6).Trim().Replace(" ", ""), 16);//接收到指令的命令字
  8865. ushort CmdRev = myParams.ConfigCheckRevCmd[key];//接收指令设计值
  8866. if (CmdGet != CmdRev)
  8867. {
  8868. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "接收指令不正确" + "\r\n");
  8869. richTextBox_CheckModeLog.AppendText("接收指令:" + "0x" + CmdGet.ToString("X2") + "\r\n");
  8870. richTextBox_CheckModeLog.AppendText("正确指令应为:" + "0x" + CmdRev.ToString("X2") + "\r\n");
  8871. label_CheckModeStatus.Text = "存在故障!";
  8872. label_CheckModeResult.BackColor = Color.Red;
  8873. label_CheckModeResult.Text = "测试异常";
  8874. Delay_ms(500);
  8875. //存储异常并上传
  8876. CheckMode_Stop(false);
  8877. return;
  8878. }
  8879. if (string.Compare(key, "[其它传感器参数]") == 0)
  8880. ParamRead = CmdRevStrTemp.Substring(90, CmdRevStrTemp.Length - 90).Trim(); //去掉命令字、力矩传感器标定参数
  8881. else if (string.Compare(key, "[力矩传感器参数]") == 0)
  8882. ParamRead = CmdRevStrTemp.Substring(6, CmdRevStrTemp.Length - 6 - 36).Trim(); //去掉命令字、其它传感器参数
  8883. else if (string.Compare(key, "[控制参数]") == 0)
  8884. ParamRead = CmdRevStrTemp.Substring(18, CmdRevStrTemp.Length - 18).Trim(); //去掉命令字、位置零点
  8885. else
  8886. ParamRead = CmdRevStrTemp.Substring(6, CmdRevStrTemp.Length - 6).Trim(); //去掉命令字
  8887. if (ParamWrite.Contains(ParamRead))
  8888. {
  8889. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "一致" + "\r\n");
  8890. continue;
  8891. }
  8892. else
  8893. {
  8894. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "不一致" + "\r\n");
  8895. richTextBox_CheckModeLog.AppendText("写入参数:" + ParamWrite + "\r\n");
  8896. richTextBox_CheckModeLog.AppendText("读出参数:" + ParamRead + "\r\n");
  8897. label_CheckModeStatus.Text = "存在故障!";
  8898. label_CheckModeResult.BackColor = Color.Red;
  8899. label_CheckModeResult.Text = "测试异常";
  8900. Delay_ms(500);
  8901. //存储异常并上传
  8902. CheckMode_Stop(false);
  8903. return;
  8904. }
  8905. }
  8906. }
  8907. catch (System.Exception)
  8908. {
  8909. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数检验失败" + "\r\n");
  8910. label_CheckModeStatus.Text = "存在故障!";
  8911. label_CheckModeResult.BackColor = Color.Red;
  8912. label_CheckModeResult.Text = "测试异常";
  8913. Delay_ms(500);
  8914. //存储异常并上传
  8915. CheckMode_Stop(false);
  8916. return;
  8917. }
  8918. label_CheckModeCfg.BackColor = Color.Green;
  8919. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数检验正确" + "\r\n");
  8920. Delay_ms(500);
  8921. }
  8922. else
  8923. {
  8924. label_CheckModeCfg.BackColor = Color.Yellow;
  8925. label_CheckModeStatus.Text = "跳过参数检验";
  8926. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数检验" + "\r\n");
  8927. Delay_ms(500);
  8928. }
  8929. //读取力矩传感器
  8930. do
  8931. {
  8932. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据" + "\r\n");
  8933. //发送指令读取力矩传感器标定数据
  8934. CmdRevStrTemp = "";
  8935. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  8936. ACK_WaitCnt = 0;
  8937. while (ACK_WaitCnt <= 2) ; //1s
  8938. if (CmdRevStrTemp == string.Empty)
  8939. {
  8940. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据,第1次重发" + "\r\n");
  8941. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  8942. ACK_WaitCnt = 0;
  8943. while (ACK_WaitCnt <= 2) ; //1s
  8944. if (CmdRevStrTemp == string.Empty)
  8945. {
  8946. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据,第2次重发" + "\r\n");
  8947. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  8948. ACK_WaitCnt = 0;
  8949. while (ACK_WaitCnt <= 2) ; //1s
  8950. if (CmdRevStrTemp == string.Empty)
  8951. {
  8952. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取失败" + "\r\n");
  8953. label_CheckModeStatus.Text = "存在故障!";
  8954. label_CheckModeResult.BackColor = Color.Red;
  8955. label_CheckModeResult.Text = "测试异常";
  8956. Delay_ms(500);
  8957. //存储异常并上传
  8958. CheckMode_Stop(false);
  8959. return;
  8960. }
  8961. }
  8962. }
  8963. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取成功" + "\r\n");
  8964. //取力矩传感器数据
  8965. ushort ZeroInit, Zero1, Zero2, Zero3, ZeroNew;
  8966. ushort MaxTorque;
  8967. ushort K1_T, K1, K2_T, K2, K3_T, K3, K4_T, K4;
  8968. byte[] DataArray = mySerialProcess.HexStringToBytes(CmdRevStrTemp, true);
  8969. ushort Cmd = (ushort)((DataArray[0] << 8) + DataArray[1]);
  8970. if (Cmd != 0xB528)
  8971. {
  8972. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器参数错误,CMD: 0x" + Convert.ToString(Cmd, 16).PadLeft(2, '0').ToUpper() + "\r\n");
  8973. label_CheckModeStatus.Text = "存在故障!";
  8974. label_CheckModeResult.BackColor = Color.Red;
  8975. label_CheckModeResult.Text = "测试异常";
  8976. Delay_ms(500);
  8977. //存储异常并上传
  8978. CheckMode_Stop(false);
  8979. return;
  8980. }
  8981. ZeroInit = (ushort)((DataArray[3] << 8) + DataArray[2]);
  8982. Zero1 = (ushort)((DataArray[5] << 8) + DataArray[4]);
  8983. Zero2 = (ushort)((DataArray[7] << 8) + DataArray[6]);
  8984. Zero3 = (ushort)((DataArray[9] << 8) + DataArray[8]);
  8985. ZeroNew = (ushort)((DataArray[11] << 8) + DataArray[10]);
  8986. MaxTorque = (ushort)((DataArray[13] << 8) + DataArray[12]);
  8987. K1_T = (ushort)((DataArray[15] << 8) + DataArray[14]);
  8988. K1 = (ushort)((DataArray[17] << 8) + DataArray[16]);
  8989. K2_T = (ushort)((DataArray[19] << 8) + DataArray[18]);
  8990. K2 = (ushort)((DataArray[21] << 8) + DataArray[20]);
  8991. K3_T = (ushort)((DataArray[23] << 8) + DataArray[22]);
  8992. K3 = (ushort)((DataArray[25] << 8) + DataArray[24]);
  8993. K4_T = (ushort)((DataArray[27] << 8) + DataArray[26]);
  8994. K4 = (ushort)((DataArray[29] << 8) + DataArray[28]);
  8995. richTextBox_CheckModeLog.AppendText("力矩传感器零点: " + ZeroInit.ToString() + "," + Zero1.ToString() + "," +
  8996. Zero2.ToString() + "," + Zero3.ToString() + "," + ZeroNew.ToString() + "\r\n");
  8997. richTextBox_CheckModeLog.AppendText("最大力矩: " + MaxTorque.ToString() + "\r\n");
  8998. richTextBox_CheckModeLog.AppendText("力矩传感器标定: " + "[" + K1_T.ToString() + "," + K1.ToString() + "]" + "," +
  8999. "[" + K2_T.ToString() + "," + K2.ToString() + "]" + "," + "[" + K3_T.ToString() + "," + K3.ToString() + "]" + "," +
  9000. "[" + K4_T.ToString() + "," + K4.ToString() + "]" + "\r\n");
  9001. //传感器标定检验
  9002. if (checkBox_CheckModeTorque.Checked)
  9003. {
  9004. richTextBox_CheckModeLog.AppendText("力矩零点范围: " + TorqueParamsForm.Zero.Min.ToString() + " - " + TorqueParamsForm.Zero.Max.ToString() + "\r\n");
  9005. richTextBox_CheckModeLog.AppendText("K1范围: " + TorqueParamsForm.K1.T.ToString() + "," + TorqueParamsForm.K1.Min.ToString() + " - " + TorqueParamsForm.K1.Max.ToString() + "\r\n");
  9006. richTextBox_CheckModeLog.AppendText("K2范围: " + TorqueParamsForm.K2.T.ToString() + "," + TorqueParamsForm.K2.Min.ToString() + " - " + TorqueParamsForm.K2.Max.ToString() + "\r\n");
  9007. richTextBox_CheckModeLog.AppendText("K3范围: " + TorqueParamsForm.K3.T.ToString() + "," + TorqueParamsForm.K3.Min.ToString() + " - " + TorqueParamsForm.K3.Max.ToString() + "\r\n");
  9008. richTextBox_CheckModeLog.AppendText("K4范围: " + TorqueParamsForm.K4.T.ToString() + "," + TorqueParamsForm.K4.Min.ToString() + " - " + TorqueParamsForm.K4.Max.ToString() + "\r\n");
  9009. //与设置值比较
  9010. if ((ZeroInit <= TorqueParamsForm.Zero.Max) && (ZeroInit >= TorqueParamsForm.Zero.Min)
  9011. && (K1_T == TorqueParamsForm.K1.T) && (K1 <= TorqueParamsForm.K1.Max) && (K1 >= TorqueParamsForm.K1.Min)
  9012. && (K2_T == TorqueParamsForm.K2.T) && (K2 <= TorqueParamsForm.K2.Max) && (K2 >= TorqueParamsForm.K2.Min)
  9013. && (K3_T == TorqueParamsForm.K3.T) && (K3 <= TorqueParamsForm.K3.Max) && (K3 >= TorqueParamsForm.K3.Min)
  9014. && (K4_T == TorqueParamsForm.K4.T) && (K4 <= TorqueParamsForm.K4.Max) && (K4 >= TorqueParamsForm.K4.Min)
  9015. )
  9016. {
  9017. label_CheckModeTorque.BackColor = Color.Green;
  9018. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定正常" + "\r\n");
  9019. Delay_ms(500);
  9020. }
  9021. else
  9022. {
  9023. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定超范围" + "\r\n");
  9024. label_CheckModeStatus.Text = "存在故障!";
  9025. label_CheckModeResult.BackColor = Color.Red;
  9026. label_CheckModeResult.Text = "测试异常";
  9027. Delay_ms(500);
  9028. //存储异常并上传
  9029. CheckMode_Stop(false);
  9030. return;
  9031. }
  9032. }
  9033. else
  9034. {
  9035. label_CheckModeTorque.BackColor = Color.Yellow;
  9036. label_CheckModeStatus.Text = "跳过传感器标定检验";
  9037. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过传感器标定检验" + "\r\n");
  9038. Delay_ms(500);
  9039. }
  9040. } while (false);
  9041. //读取MOS内阻校准参数
  9042. do
  9043. {
  9044. if (checkBox_CheckModeMos.Checked)
  9045. {
  9046. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据" + "\r\n");
  9047. //读取显示校准返回数据
  9048. foreach (Control c in groupBox21.Controls)
  9049. {
  9050. if (c is TextBox)
  9051. c.Text = "";
  9052. }
  9053. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  9054. ACK_WaitCnt = 0;
  9055. while (ACK_WaitCnt <= 2) ; //1s
  9056. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  9057. {
  9058. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据,第1次重发" + "\r\n");
  9059. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  9060. ACK_WaitCnt = 0;
  9061. while (ACK_WaitCnt <= 2) ; //1s
  9062. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  9063. {
  9064. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据,第2次重发" + "\r\n");
  9065. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  9066. ACK_WaitCnt = 0;
  9067. while (ACK_WaitCnt <= 2) ; //1s
  9068. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  9069. {
  9070. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果异常" + "\r\n");
  9071. label_CheckModeStatus.Text = "存在故障!";
  9072. label_CheckModeResult.BackColor = Color.Red;
  9073. label_CheckModeResult.Text = "测试异常";
  9074. Delay_ms(500);
  9075. //存储异常并上传
  9076. CheckMode_Stop(false);
  9077. return;
  9078. }
  9079. }
  9080. }
  9081. else
  9082. {
  9083. 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");
  9084. }
  9085. //与校准返回数据对比
  9086. string[] MOS_R1_Th = toolStripTextBox_MOS1.Text.Split(',');
  9087. string[] MOS_R2_Th = toolStripTextBox_MOS2.Text.Split(',');
  9088. string[] MOS_R3_Th = toolStripTextBox_MOS3.Text.Split(',');
  9089. 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])) &&
  9090. (Convert.ToUInt16(textBox_MOS_R2.Text) >= Convert.ToUInt16(MOS_R2_Th[0])) && (Convert.ToUInt16(textBox_MOS_R2.Text) <= Convert.ToUInt16(MOS_R2_Th[1])) &&
  9091. (Convert.ToUInt16(textBox_MOS_R3.Text) >= Convert.ToUInt16(MOS_R3_Th[0])) && (Convert.ToUInt16(textBox_MOS_R3.Text) <= Convert.ToUInt16(MOS_R3_Th[1]))
  9092. )
  9093. {
  9094. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准合格" + "\r\n");
  9095. label_CheckModeMos.BackColor = Color.Green;
  9096. }
  9097. else
  9098. {
  9099. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准超范围" + "\r\n");
  9100. label_CheckModeStatus.Text = "存在故障!";
  9101. label_CheckModeResult.BackColor = Color.Red;
  9102. label_CheckModeResult.Text = "测试异常";
  9103. Delay_ms(500);
  9104. //存储异常并上传
  9105. CheckMode_Stop(false);
  9106. return;
  9107. }
  9108. }
  9109. else
  9110. {
  9111. label_CheckModeMos.BackColor = Color.Yellow;
  9112. label_CheckModeStatus.Text = "跳过MOS内阻校准检验";
  9113. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过MOS内阻校准检验" + "\r\n");
  9114. Delay_ms(500);
  9115. }
  9116. } while (false);
  9117. //读取位置校准参数
  9118. do
  9119. {
  9120. if (checkBox_CheckModeAngle.Checked)
  9121. {
  9122. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取位置校准数据" + "\r\n");
  9123. //发送指令读取位置
  9124. CmdRevStrTemp = "";
  9125. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
  9126. ACK_WaitCnt = 0;
  9127. while (ACK_WaitCnt <= 2) ; //1s
  9128. if (CmdRevStrTemp == string.Empty)
  9129. {
  9130. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取位置校准数据,第1次重发" + "\r\n");
  9131. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x3E00, null);
  9132. ACK_WaitCnt = 0;
  9133. while (ACK_WaitCnt <= 2) ; //1s
  9134. if (CmdRevStrTemp == string.Empty)
  9135. {
  9136. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取位置校准数据,第2次重发" + "\r\n");
  9137. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x3E00, null);
  9138. ACK_WaitCnt = 0;
  9139. while (ACK_WaitCnt <= 2) ; //1s
  9140. if (CmdRevStrTemp == string.Empty)
  9141. {
  9142. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准数据读取失败" + "\r\n");
  9143. label_CheckModeStatus.Text = "存在故障!";
  9144. label_CheckModeResult.BackColor = Color.Red;
  9145. label_CheckModeResult.Text = "测试异常";
  9146. Delay_ms(500);
  9147. //存储异常并上传
  9148. CheckMode_Stop(false);
  9149. return;
  9150. }
  9151. }
  9152. }
  9153. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准数据读取成功" + "\r\n");
  9154. //取零点数据
  9155. UInt16 AngleZero_Init = 0, AngleZero_Cur = 0;
  9156. byte[] DataArray = mySerialProcess.HexStringToBytes(CmdRevStrTemp, true);
  9157. ushort Cmd = (ushort)((DataArray[0] << 8) + DataArray[1]);
  9158. if (Cmd != 0xB420)
  9159. {
  9160. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置传感器参数错误,CMD: 0x" + Convert.ToString(Cmd, 16).PadLeft(2, '0').ToUpper() + "\r\n");
  9161. label_CheckModeStatus.Text = "存在故障!";
  9162. label_CheckModeResult.BackColor = Color.Red;
  9163. label_CheckModeResult.Text = "测试异常";
  9164. Delay_ms(500);
  9165. //存储异常并上传
  9166. CheckMode_Stop(false);
  9167. return;
  9168. }
  9169. AngleZero_Init = (ushort)((DataArray[3] << 8) + DataArray[2]);
  9170. AngleZero_Cur = (ushort)((DataArray[5] << 8) + DataArray[4]);
  9171. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置出厂零点: " + AngleZero_Init.ToString() + ",位置当前零点: " + AngleZero_Cur.ToString() + "\r\n");
  9172. int AngleZeroDiff = Math.Abs(AngleZero_Cur - AngleZero_Init);
  9173. int AngleZeroTH = Convert.ToInt32(textBox_AngleZeroTh.Text);
  9174. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置零点校准值: " + AngleZeroDiff.ToString() + ",判断阈值: " + AngleZeroTH.ToString() + "\r\n");
  9175. //判断
  9176. if (AngleZeroDiff <= AngleZeroTH)
  9177. {
  9178. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置传感器校准合格" + "\r\n");
  9179. label_CheckModeAngle.BackColor = Color.Green;
  9180. }
  9181. else
  9182. {
  9183. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置传感器校准超范围" + "\r\n");
  9184. label_CheckModeStatus.Text = "存在故障!";
  9185. label_CheckModeResult.BackColor = Color.Red;
  9186. label_CheckModeResult.Text = "测试异常";
  9187. Delay_ms(500);
  9188. //存储异常并上传
  9189. CheckMode_Stop(false);
  9190. return;
  9191. }
  9192. }
  9193. else
  9194. {
  9195. label_CheckModeAngle.BackColor = Color.Yellow;
  9196. label_CheckModeStatus.Text = "跳过位置传感器校准检验";
  9197. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过位置传感器校准检验" + "\r\n");
  9198. Delay_ms(500);
  9199. }
  9200. } while (false);
  9201. //测试合格
  9202. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  9203. label_CheckModeStatus.Text = "测试结束!";
  9204. label_CheckModeResult.BackColor = Color.Green;
  9205. label_CheckModeResult.Text = "测试合格";
  9206. Delay_ms(500);
  9207. //存储并上传
  9208. CheckMode_Stop(true);
  9209. return;
  9210. }
  9211. private void CheckModeLabelInit()
  9212. {
  9213. //测试状态标签
  9214. label_CheckModeResult.BackColor = Color.Yellow;
  9215. label_CheckModeResult.Text = "测试中";
  9216. //测试过程标签
  9217. label_CheckModeStatus.Text = "测试就绪";
  9218. //测试结果标签
  9219. foreach (Control c in groupBox31.Controls)
  9220. {
  9221. if (c is Label)
  9222. {
  9223. if (c.Text == string.Empty)
  9224. c.BackColor = Color.Red;
  9225. }
  9226. }
  9227. }
  9228. private void 调试记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  9229. {
  9230. System.Diagnostics.Process.Start("explorer.exe", Directory.GetCurrentDirectory());
  9231. }
  9232. private void 生产记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  9233. {
  9234. System.Diagnostics.Process.Start("explorer.exe", localInfo.LocalDataPath);
  9235. }
  9236. private void 累计运行时间ToolStripMenuItem_MouseHover(object sender, EventArgs e)
  9237. {
  9238. UInt32 Time = (UInt32)stopwatch.ElapsedMilliseconds / 1000;
  9239. UInt32 hour = Time / 3600;
  9240. UInt32 min = (Time % 3600) / 60;
  9241. UInt32 s = (Time % 60);
  9242. toolStripMenuItem_RunTime.Text = hour.ToString() + ":" + min.ToString("00") + ":" + s.ToString("00");
  9243. }
  9244. private void richTextBox_CheckModeLog_TextChanged(object sender, EventArgs e)
  9245. {
  9246. richTextBox_CheckModeLog.SelectionStart = richTextBox_CheckModeLog.Text.Length;
  9247. richTextBox_CheckModeLog.ScrollToCaret();
  9248. }
  9249. private void 力矩传感器检验ToolStripMenuItem_Click(object sender, EventArgs e)
  9250. {
  9251. TorqueParamsForm.ShowDialog();
  9252. }
  9253. private void textBox_CheckModeScan_KeyUp(object sender, KeyEventArgs e)
  9254. {
  9255. if (e.KeyCode == Keys.Enter)
  9256. CheckTestStart();
  9257. }
  9258. private void textBox_FacModeScan_KeyUp(object sender, KeyEventArgs e)
  9259. {
  9260. if (e.KeyCode == Keys.Enter)
  9261. TestStart();
  9262. }
  9263. private void button_SpeedDec10_Click(object sender, EventArgs e)
  9264. {
  9265. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  9266. if (Percent <= 10)
  9267. Percent = 0;
  9268. else
  9269. Percent -= 10;
  9270. //生产模式转速设置值更新
  9271. textBox_MotorSpeedPercent.Text = Percent.ToString();
  9272. //设置转速百分比
  9273. var Data = new byte[1];
  9274. Data[0] = (byte)Percent;
  9275. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  9276. }
  9277. private void button_SpeedAdd10_Click(object sender, EventArgs e)
  9278. {
  9279. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  9280. if (Percent >= 90)
  9281. Percent = 100;
  9282. else
  9283. Percent += 10;
  9284. //生产模式转速设置值更新
  9285. textBox_MotorSpeedPercent.Text = Percent.ToString();
  9286. //设置转速百分比
  9287. var Data = new byte[1];
  9288. Data[0] = (byte)Percent;
  9289. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  9290. }
  9291. private void button_SpeedDec1_Click(object sender, EventArgs e)
  9292. {
  9293. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  9294. if (Percent <= 1)
  9295. Percent = 0;
  9296. else
  9297. Percent -= 1;
  9298. //生产模式转速设置值更新
  9299. textBox_MotorSpeedPercent.Text = Percent.ToString();
  9300. //设置转速百分比
  9301. var Data = new byte[1];
  9302. Data[0] = (byte)Percent;
  9303. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  9304. }
  9305. private void button_SpeedAdd1_Click(object sender, EventArgs e)
  9306. {
  9307. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  9308. if (Percent >= 99)
  9309. Percent = 100;
  9310. else
  9311. Percent += 1;
  9312. //生产模式转速设置值更新
  9313. textBox_MotorSpeedPercent.Text = Percent.ToString();
  9314. //设置转速百分比
  9315. var Data = new byte[1];
  9316. Data[0] = (byte)Percent;
  9317. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  9318. }
  9319. bool WriteLockStatus = true;
  9320. private void pictureBox_WriteLock_Click(object sender, EventArgs e)
  9321. {
  9322. if (WriteLockStatus == true)
  9323. {
  9324. EnterForm1.ShowDialog();
  9325. try
  9326. {
  9327. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9328. {
  9329. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  9330. {
  9331. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  9332. foreach (Control c in groupBox2.Controls)
  9333. {
  9334. if (c is CheckBox)
  9335. c.Enabled = true;
  9336. }
  9337. WriteLockStatus = !WriteLockStatus;
  9338. }
  9339. else
  9340. {
  9341. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9342. }
  9343. }
  9344. else
  9345. {
  9346. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9347. }
  9348. }
  9349. catch (Exception)
  9350. {
  9351. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9352. }
  9353. }
  9354. else
  9355. {
  9356. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  9357. foreach (Control c in groupBox2.Controls)
  9358. {
  9359. if (c is CheckBox)
  9360. c.Enabled = false;
  9361. }
  9362. WriteLockStatus = !WriteLockStatus;
  9363. }
  9364. }
  9365. bool ReadLockStatus = true;
  9366. private void pictureBox_ReadLock_Click(object sender, EventArgs e)
  9367. {
  9368. if (ReadLockStatus == true)
  9369. {
  9370. EnterForm1.ShowDialog();
  9371. try
  9372. {
  9373. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9374. {
  9375. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  9376. {
  9377. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  9378. foreach (Control c in groupBox29.Controls)
  9379. {
  9380. if (c is CheckBox)
  9381. c.Enabled = true;
  9382. }
  9383. ReadLockStatus = !ReadLockStatus;
  9384. }
  9385. else
  9386. {
  9387. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9388. }
  9389. }
  9390. else
  9391. {
  9392. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9393. }
  9394. }
  9395. catch (Exception)
  9396. {
  9397. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9398. }
  9399. }
  9400. else
  9401. {
  9402. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  9403. foreach (Control c in groupBox29.Controls)
  9404. {
  9405. if (c is CheckBox)
  9406. c.Enabled = false;
  9407. }
  9408. ReadLockStatus = !ReadLockStatus;
  9409. }
  9410. }
  9411. private void 屏幕键盘ToolStripMenuItem_Click(object sender, EventArgs e)
  9412. {
  9413. System.Diagnostics.Process.Start("osk.exe");
  9414. }
  9415. private void checkBox_OffLineCheckMode_CheckedChanged(object sender, EventArgs e)
  9416. {
  9417. comboBox_CheckModeCfgDate.SelectedIndex = -1;
  9418. comboBox_CheckModeCfgFile.SelectedIndex = -1;
  9419. checkBox_OffLineFacMode.Checked = checkBox_OffLineCheckMode.Checked;
  9420. }
  9421. private void checkBox_OffLineFacMode_CheckedChanged(object sender, EventArgs e)
  9422. {
  9423. comboBox_FacModeCfgDate.SelectedIndex = -1;
  9424. comboBox_FacModeCfgFile.SelectedIndex = -1;
  9425. checkBox_OffLineCheckMode.Checked = checkBox_OffLineFacMode.Checked;
  9426. }
  9427. private void 版本ToolStripMenuItem_Click(object sender, EventArgs e)
  9428. {
  9429. VersionForm.ShowDialog();
  9430. }
  9431. private void button_MOS_Cal_Click(object sender, EventArgs e)
  9432. {
  9433. textBox_MOS_R1.Text = "";
  9434. textBox_MOS_R2.Text = "";
  9435. textBox_MOS_R3.Text = "";
  9436. try
  9437. {
  9438. var Code = new byte[18];
  9439. for (int i = 0; i < 18; i++)
  9440. Code[i] = 0;
  9441. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  9442. ushort uwDataTemp = 0;
  9443. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  9444. Code[2] = (byte)(uwDataTemp & 0xFF);
  9445. Code[3] = (byte)(uwDataTemp >> 8);
  9446. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  9447. Code[4] = (byte)(uwDataTemp & 0xFF);
  9448. Code[5] = (byte)(uwDataTemp >> 8);
  9449. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  9450. Code[6] = (byte)(uwDataTemp & 0xFF);
  9451. Code[7] = (byte)(uwDataTemp >> 8);
  9452. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  9453. Code[8] = (byte)(uwDataTemp & 0xFF);
  9454. Code[9] = (byte)(uwDataTemp >> 8);
  9455. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  9456. Code[10] = (byte)(uwDataTemp & 0xFF);
  9457. Code[11] = (byte)(uwDataTemp >> 8);
  9458. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  9459. }
  9460. catch (Exception)
  9461. {
  9462. MessageBox.Show("系数填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9463. }
  9464. }
  9465. private void button_MOS_Read_Click(object sender, EventArgs e)
  9466. {
  9467. foreach (Control c in groupBox21.Controls)
  9468. {
  9469. if (c is TextBox)
  9470. c.Text = "";
  9471. }
  9472. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  9473. }
  9474. private void button_MOS_Write_Click(object sender, EventArgs e)
  9475. {
  9476. try
  9477. {
  9478. var Code = new byte[34];
  9479. for (int i = 0; i < 34; i++)
  9480. Code[i] = 0;
  9481. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  9482. ushort uwDataTemp = 0;
  9483. uwDataTemp = Convert.ToUInt16(textBox_MOS_R1.Text);
  9484. Code[2] = (byte)(uwDataTemp & 0xFF);
  9485. Code[3] = (byte)(uwDataTemp >> 8);
  9486. uwDataTemp = Convert.ToUInt16(textBox_MOS_R2.Text);
  9487. Code[4] = (byte)(uwDataTemp & 0xFF);
  9488. Code[5] = (byte)(uwDataTemp >> 8);
  9489. uwDataTemp = Convert.ToUInt16(textBox_MOS_R3.Text);
  9490. Code[6] = (byte)(uwDataTemp & 0xFF);
  9491. Code[7] = (byte)(uwDataTemp >> 8);
  9492. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  9493. Code[8] = (byte)(uwDataTemp & 0xFF);
  9494. Code[9] = (byte)(uwDataTemp >> 8);
  9495. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  9496. Code[10] = (byte)(uwDataTemp & 0xFF);
  9497. Code[11] = (byte)(uwDataTemp >> 8);
  9498. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  9499. Code[12] = (byte)(uwDataTemp & 0xFF);
  9500. Code[13] = (byte)(uwDataTemp >> 8);
  9501. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  9502. Code[14] = (byte)(uwDataTemp & 0xFF);
  9503. Code[15] = (byte)(uwDataTemp >> 8);
  9504. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  9505. Code[16] = (byte)(uwDataTemp & 0xFF);
  9506. Code[17] = (byte)(uwDataTemp >> 8);
  9507. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4C22, Code);
  9508. }
  9509. catch (Exception)
  9510. {
  9511. MessageBox.Show("数据填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9512. }
  9513. }
  9514. /// <summary>
  9515. /// 测试模式点击文本框自动全选
  9516. /// </summary>
  9517. /// <param name="sender"></param>
  9518. /// <param name="e"></param>
  9519. private void textBox_FacModeScan_MouseClick(object sender, MouseEventArgs e)
  9520. {
  9521. textBox_FacModeScan.SelectAll();
  9522. }
  9523. /// <summary>
  9524. /// 检验模式点击文本框自动全选
  9525. /// </summary>
  9526. /// <param name="sender"></param>
  9527. /// <param name="e"></param>
  9528. private void textBox_CheckModeScan_MouseClick(object sender, MouseEventArgs e)
  9529. {
  9530. textBox_CheckModeScan.SelectAll();
  9531. }
  9532. /// <summary>
  9533. /// 鼠标放置显示连接服务器信息
  9534. /// </summary>
  9535. /// <param name="sender"></param>
  9536. /// <param name="e"></param>
  9537. private void label_ServerStatus_MouseHover(object sender, EventArgs e)
  9538. {
  9539. // 创建the ToolTip
  9540. ToolTip toolTip1 = new ToolTip();
  9541. // 设置显示样式
  9542. toolTip1.AutoPopDelay = 30000;//提示信息的可见时间
  9543. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  9544. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  9545. toolTip1.ShowAlways = true;//是否显示提示框
  9546. if (myFtp.IsNetConnected)
  9547. {
  9548. toolTip1.SetToolTip(this.label_ServerStatus, "IP: " + ServerIP);//设置故障内容显示
  9549. }
  9550. else
  9551. {
  9552. toolTip1.SetToolTip(this.label_ServerStatus, "网络断开");//设置故障内容显示
  9553. }
  9554. }
  9555. /// <summary>
  9556. /// UART协议类型修改
  9557. /// </summary>
  9558. /// <param name="sender"></param>
  9559. /// <param name="e"></param>
  9560. private void 协议类型ToolStripMenuItem_SelectedIndexChanged(object sender, EventArgs e)
  9561. {
  9562. var Code = new byte[2];
  9563. Code[0] = (byte)协议类型ToolStripMenuItem.SelectedIndex;
  9564. Code[1] = 0x00;
  9565. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  9566. }
  9567. /// <summary>
  9568. /// 显示本机信息
  9569. /// </summary>
  9570. /// <param name="sender"></param>
  9571. /// <param name="e"></param>
  9572. private void 本机信息ToolStripMenuItem_Click(object sender, EventArgs e)
  9573. {
  9574. MessageBox.Show(Local_HdInformation, "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
  9575. }
  9576. /// <summary>
  9577. /// 量产模式删除当前选中文件
  9578. /// </summary>
  9579. /// <param name="sender"></param>
  9580. /// <param name="e"></param>
  9581. private void label112_DoubleClick(object sender, EventArgs e)
  9582. {
  9583. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9584. {
  9585. EnterForm1.ShowDialog();
  9586. try
  9587. {
  9588. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9589. {
  9590. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  9591. {
  9592. try
  9593. {
  9594. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + comboBox_FacModeCfgFile.Text);
  9595. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_FacModeCfgFile.Text) + ".src");
  9596. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_FacModeCfgFile.Text) + ".png");
  9597. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9598. }
  9599. catch (Exception)
  9600. {
  9601. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9602. }
  9603. }
  9604. else
  9605. {
  9606. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9607. }
  9608. }
  9609. }
  9610. catch (Exception)
  9611. {
  9612. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9613. }
  9614. }
  9615. }
  9616. /// <summary>
  9617. /// 检验模式删除当前选中文件
  9618. /// </summary>
  9619. /// <param name="sender"></param>
  9620. /// <param name="e"></param>
  9621. private void label138_DoubleClick(object sender, EventArgs e)
  9622. {
  9623. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9624. {
  9625. EnterForm1.ShowDialog();
  9626. try
  9627. {
  9628. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9629. {
  9630. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  9631. {
  9632. try
  9633. {
  9634. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + comboBox_CheckModeCfgFile.Text);
  9635. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_CheckModeCfgFile.Text) + ".src");
  9636. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_CheckModeCfgFile.Text) + ".png");
  9637. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9638. }
  9639. catch (Exception)
  9640. {
  9641. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9642. }
  9643. }
  9644. else
  9645. {
  9646. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9647. }
  9648. }
  9649. }
  9650. catch (Exception)
  9651. {
  9652. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9653. }
  9654. }
  9655. }
  9656. /// <summary>
  9657. /// 读取整车信息2
  9658. /// </summary>
  9659. /// <param name="sender"></param>
  9660. /// <param name="e"></param>
  9661. private void button_ReadBikeParam2_Click(object sender, EventArgs e)
  9662. {
  9663. richTextBox_BikeParam2.Clear();
  9664. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null);
  9665. }
  9666. /// <summary>
  9667. /// 写入整车信息2
  9668. /// </summary>
  9669. /// <param name="sender"></param>
  9670. /// <param name="e"></param>
  9671. private void button_WriteBikeParam2_Click(object sender, EventArgs e)
  9672. {
  9673. var ConfigParam = new byte[34];
  9674. for (int i = 0; i < 34; i++)
  9675. ConfigParam[i] = 0;
  9676. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  9677. string[] strDataTemp = richTextBox_BikeParam2.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  9678. try
  9679. {
  9680. for (int i = 0; i < strDataTemp.Length; i++)
  9681. {
  9682. short wDataTemp = 0;
  9683. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  9684. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  9685. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  9686. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  9687. }
  9688. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4D22, ConfigParam);
  9689. }
  9690. catch (Exception)
  9691. {
  9692. timer_500ms.Enabled = false;
  9693. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9694. timer_500ms.Enabled = true;
  9695. }
  9696. }
  9697. /// <summary>
  9698. /// 读取用户骑行参数
  9699. /// </summary>
  9700. /// <param name="sender"></param>
  9701. /// <param name="e"></param>
  9702. private void button_ReadUsrRideParam_Click(object sender, EventArgs e)
  9703. {
  9704. richTextBox_UsrRidesParam.Clear();
  9705. if (checkBox_UserRideParam_OBC.Checked)
  9706. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x4300, null);
  9707. else
  9708. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  9709. }
  9710. /// <summary>
  9711. /// 写入用户骑行参数
  9712. /// </summary>
  9713. /// <param name="sender"></param>
  9714. /// <param name="e"></param>
  9715. private void button_WriteUsrRidetParam_Click(object sender, EventArgs e)
  9716. {
  9717. var ConfigParam = new byte[34];
  9718. for (int i = 0; i < 34; i++)
  9719. ConfigParam[i] = 0;
  9720. if (checkBox_UserRideParam_OBC.Checked)
  9721. {
  9722. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  9723. string[] strDataTemp = richTextBox_UsrRidesParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  9724. try
  9725. {
  9726. for (int i = 0; i < strDataTemp.Length; i++)
  9727. {
  9728. ConfigParam[i + 2] = Convert.ToByte(strDataTemp[i].Split('=')[1]);
  9729. }
  9730. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4B22, ConfigParam);
  9731. }
  9732. catch (Exception)
  9733. {
  9734. timer_500ms.Enabled = false;
  9735. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9736. timer_500ms.Enabled = true;
  9737. }
  9738. }
  9739. else
  9740. {
  9741. string[] strDataTemp = richTextBox_UsrRidesParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  9742. try
  9743. {
  9744. for (int i = 0; i < strDataTemp.Length; i++)
  9745. {
  9746. ConfigParam[i] = Convert.ToByte(strDataTemp[i].Split('=')[1]);
  9747. }
  9748. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x4420, ConfigParam);
  9749. }
  9750. catch (Exception)
  9751. {
  9752. timer_500ms.Enabled = false;
  9753. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9754. timer_500ms.Enabled = true;
  9755. }
  9756. }
  9757. }
  9758. /// <summary>
  9759. /// 读取产品标签
  9760. /// </summary>
  9761. /// <param name="sender"></param>
  9762. /// <param name="e"></param>
  9763. private void button_ReadTag_Click(object sender, EventArgs e)
  9764. {
  9765. textBox_TagInfo.Text = "---";
  9766. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4E00, null);
  9767. }
  9768. /// <summary>
  9769. /// 写入产品标签
  9770. /// </summary>
  9771. /// <param name="sender"></param>
  9772. /// <param name="e"></param>
  9773. private void button_WriteTag_Click(object sender, EventArgs e)
  9774. {
  9775. string User = textBox_TagInfo.Text;
  9776. var UserArray = new byte[32];
  9777. for (ushort i = 0; i < User.Length; i++)
  9778. {
  9779. UserArray[i] = (byte)User[i];
  9780. }
  9781. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D20, UserArray);
  9782. }
  9783. /// <summary>
  9784. /// 上位机读取骑行历史
  9785. /// </summary>
  9786. /// <param name="sender"></param>
  9787. /// <param name="e"></param>
  9788. private void button_ReadRideLog_Click(object sender, EventArgs e)
  9789. {
  9790. textBox_ODO_KM.Text = "---";
  9791. textBox_ODO_TIME.Text = "---";
  9792. textBox_TRIP_KM.Text = "---";
  9793. textBox_TRIP_TIME.Text = "---";
  9794. textBox_OBC_TRIP_KM.Text = "";
  9795. textBox_OBC_TRIP_TIME.Text = "";
  9796. textBox_OBC_ODO_KM.Text = "";
  9797. textBox_OBC_ODO_TIME.Text = "";
  9798. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2E00, null);
  9799. }
  9800. /// <summary>
  9801. /// 上位机写入骑行历史
  9802. /// </summary>
  9803. /// <param name="sender"></param>
  9804. /// <param name="e"></param>
  9805. private void button_WriteRideLog_Click(object sender, EventArgs e)
  9806. {
  9807. UInt32 Data;
  9808. var UserArray = new byte[16];
  9809. try
  9810. {
  9811. Data = Convert.ToUInt32(textBox_ODO_KM.Text);
  9812. UserArray[0] = (byte)(Data & 0xFF);
  9813. UserArray[1] = (byte)(Data >> 8);
  9814. UserArray[2] = (byte)(Data >> 16);
  9815. UserArray[3] = (byte)(Data >> 24);
  9816. Data = Convert.ToUInt32(textBox_ODO_TIME.Text);
  9817. UserArray[4] = (byte)(Data & 0xFF);
  9818. UserArray[5] = (byte)(Data >> 8);
  9819. UserArray[6] = (byte)(Data >> 16);
  9820. UserArray[7] = (byte)(Data >> 24);
  9821. Data = Convert.ToUInt32(textBox_TRIP_KM.Text);
  9822. UserArray[8] = (byte)(Data & 0xFF);
  9823. UserArray[9] = (byte)(Data >> 8);
  9824. UserArray[10] = (byte)(Data >> 16);
  9825. UserArray[11] = (byte)(Data >> 24);
  9826. Data = Convert.ToUInt32(textBox_TRIP_TIME.Text);
  9827. UserArray[12] = (byte)(Data & 0xFF);
  9828. UserArray[13] = (byte)(Data >> 8);
  9829. UserArray[14] = (byte)(Data >> 16);
  9830. UserArray[15] = (byte)(Data >> 24);
  9831. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B10, UserArray);
  9832. }
  9833. catch (Exception ex)
  9834. {
  9835. MessageBox.Show("数据格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9836. }
  9837. }
  9838. /// <summary>
  9839. /// 获取删除配置文件日期列表
  9840. /// </summary>
  9841. /// <param name="sender"></param>
  9842. /// <param name="e"></param>
  9843. private void toolStripTextBox_DelCfgFile_Click(object sender, EventArgs e)
  9844. {
  9845. string[] DateList = { "" };
  9846. //网络断开时直接退出
  9847. if (!myFtp.IsNetConnected)
  9848. return;
  9849. //从服务器更新日期列表
  9850. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
  9851. toolStripTextBox_DelCfgFile.Items.Clear();
  9852. //日期列表加载,显示最近30条
  9853. if (DateList.Length > 30)
  9854. {
  9855. toolStripTextBox_DelCfgFile.Items.Add("支持最近30条");
  9856. toolStripTextBox_DelCfgFile.Items.Add("-----");
  9857. }
  9858. for (int i = (DateList.Length > 30) ? (DateList.Length - 30) : 0; i < DateList.Length; i++)//显示最近30个日期
  9859. {
  9860. toolStripTextBox_DelCfgFile.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  9861. }
  9862. }
  9863. /// <summary>
  9864. /// 删除指定配置文件
  9865. /// </summary>
  9866. /// <param name="sender"></param>
  9867. /// <param name="e"></param>
  9868. private void toolStripTextBox_DelCfgFile_SelectedIndexChanged(object sender, EventArgs e)
  9869. {
  9870. //提示输入文件名
  9871. Scan scan_form = new Scan();
  9872. scan_form.ShowDialog();
  9873. do
  9874. {
  9875. if (scan_form.textBox_Scan.Text == string.Empty)
  9876. {
  9877. timer_500ms.Enabled = false;
  9878. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9879. timer_500ms.Enabled = true;
  9880. break;
  9881. }
  9882. string DelFile = scan_form.textBox_Scan.Text;
  9883. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9884. {
  9885. EnterForm1.ShowDialog();
  9886. try
  9887. {
  9888. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9889. {
  9890. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  9891. {
  9892. try
  9893. {
  9894. if (DelFile.Contains("."))
  9895. DelFile = Path.GetFileNameWithoutExtension(DelFile);
  9896. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".ttcfg");
  9897. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".src");
  9898. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".png");
  9899. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9900. }
  9901. catch (Exception)
  9902. {
  9903. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9904. }
  9905. }
  9906. else
  9907. {
  9908. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9909. }
  9910. }
  9911. }
  9912. catch (Exception)
  9913. {
  9914. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9915. }
  9916. }
  9917. } while (false);
  9918. }
  9919. /// <summary>
  9920. /// 获取删除样机测试记录日期列表
  9921. /// </summary>
  9922. /// <param name="sender"></param>
  9923. /// <param name="e"></param>
  9924. private void toolStripTextBox_DelLogFile_Click(object sender, EventArgs e)
  9925. {
  9926. string[] DateList = { "" };
  9927. //网络断开时直接退出
  9928. if (!myFtp.IsNetConnected)
  9929. return;
  9930. //从服务器更新日期列表
  9931. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName);
  9932. toolStripTextBox_DelLogFile.Items.Clear();
  9933. //日期列表加载,显示最近30天
  9934. if (DateList.Length > 30)
  9935. {
  9936. toolStripTextBox_DelLogFile.Items.Add("支持最近30条");
  9937. toolStripTextBox_DelLogFile.Items.Add("-----");
  9938. }
  9939. for (int i = (DateList.Length > 30) ? (DateList.Length - 30) : 0; i < DateList.Length; i++)//显示最近30个日期
  9940. {
  9941. toolStripTextBox_DelLogFile.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  9942. }
  9943. }
  9944. /// <summary>
  9945. /// 删除指定的样机测试记录
  9946. /// </summary>
  9947. /// <param name="sender"></param>
  9948. /// <param name="e"></param>
  9949. private void toolStripTextBox_DelLogFile_SelectedIndexChanged(object sender, EventArgs e)
  9950. {
  9951. //提示输入文件名
  9952. Scan scan_form = new Scan();
  9953. scan_form.ShowDialog();
  9954. do
  9955. {
  9956. if (scan_form.textBox_Scan.Text == string.Empty)
  9957. {
  9958. timer_500ms.Enabled = false;
  9959. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9960. timer_500ms.Enabled = true;
  9961. break;
  9962. }
  9963. string DelFile = scan_form.textBox_Scan.Text;
  9964. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9965. {
  9966. EnterForm1.ShowDialog();
  9967. try
  9968. {
  9969. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9970. {
  9971. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  9972. {
  9973. try
  9974. {
  9975. //删除指定目录下面所有文件和文件夹
  9976. myFtp.DelDirectoryWithAll(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName + "\\" + toolStripTextBox_DelLogFile.Text + "\\" + DelFile);
  9977. myFtp.RemoveDirectory(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName + "\\" + toolStripTextBox_DelLogFile.Text + "\\" + DelFile);
  9978. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9979. }
  9980. catch (Exception)
  9981. {
  9982. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9983. }
  9984. }
  9985. else
  9986. {
  9987. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9988. }
  9989. }
  9990. }
  9991. catch (Exception)
  9992. {
  9993. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9994. }
  9995. }
  9996. } while (false);
  9997. }
  9998. /// <summary>
  9999. /// CAN协议选择
  10000. /// </summary>
  10001. /// <param name="sender"></param>
  10002. /// <param name="e"></param>
  10003. private void cANToolStripMenuItem_Click(object sender, EventArgs e)
  10004. {
  10005. cANToolStripMenuItem.Checked= true;
  10006. uARTToolStripMenuItem.Checked = false;
  10007. UART协议ToolStripMenuItem.Visible = false;
  10008. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  10009. }
  10010. /// <summary>
  10011. /// UART协议选择
  10012. /// </summary>
  10013. /// <param name="sender"></param>
  10014. /// <param name="e"></param>
  10015. private void uARTToolStripMenuItem_Click(object sender, EventArgs e)
  10016. {
  10017. cANToolStripMenuItem.Checked = false;
  10018. uARTToolStripMenuItem.Checked = true;
  10019. UART协议ToolStripMenuItem.Visible = true;
  10020. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  10021. }
  10022. /// <summary>
  10023. /// 清除流水号
  10024. /// </summary>
  10025. /// <param name="sender"></param>
  10026. /// <param name="e"></param>
  10027. private void label131_DoubleClick(object sender, EventArgs e)
  10028. {
  10029. if (MessageBox.Show("确认清零流水号?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  10030. {
  10031. label_FacModeSerial.Text = "0";
  10032. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, label_FacModeSerial.Text);
  10033. }
  10034. }
  10035. /// <summary>
  10036. /// 清除流水号
  10037. /// </summary>
  10038. /// <param name="sender"></param>
  10039. /// <param name="e"></param>
  10040. private void label135_DoubleClick(object sender, EventArgs e)
  10041. {
  10042. if (MessageBox.Show("确认清零流水号?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  10043. {
  10044. label_CheckModeSerial.Text = "0";
  10045. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, label_CheckModeSerial.Text);
  10046. }
  10047. }
  10048. /// <summary>
  10049. /// 打开自动更新
  10050. /// </summary>
  10051. /// <param name="sender"></param>
  10052. /// <param name="e"></param>
  10053. private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
  10054. {
  10055. 打开ToolStripMenuItem.Checked = true;
  10056. 关闭ToolStripMenuItem.Checked = false;
  10057. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  10058. }
  10059. /// <summary>
  10060. /// 关闭自动更新
  10061. /// </summary>
  10062. /// <param name="sender"></param>
  10063. /// <param name="e"></param>
  10064. private void 关闭ToolStripMenuItem_Click(object sender, EventArgs e)
  10065. {
  10066. 打开ToolStripMenuItem.Checked = false;
  10067. 关闭ToolStripMenuItem.Checked = true;
  10068. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  10069. }
  10070. /// <summary>
  10071. /// 显示完整配置文件
  10072. /// </summary>
  10073. /// <param name="sender"></param>
  10074. /// <param name="e"></param>
  10075. private void comboBox_FacModeCfgFile_MouseHover_1(object sender, EventArgs e)
  10076. {
  10077. // 创建the ToolTip
  10078. ToolTip toolTip1 = new ToolTip();
  10079. // 设置显示样式
  10080. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  10081. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  10082. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  10083. toolTip1.ShowAlways = true;//是否显示提示框
  10084. // 设置伴随的对象.
  10085. toolTip1.SetToolTip(this.comboBox_FacModeCfgFile, comboBox_FacModeCfgFile.Text);//设置故障内容显示
  10086. }
  10087. /// <summary>
  10088. /// 显示完整配置文件
  10089. /// </summary>
  10090. /// <param name="sender"></param>
  10091. /// <param name="e"></param>
  10092. private void comboBox_CheckModeCfgFile_MouseHover_1(object sender, EventArgs e)
  10093. {
  10094. // 创建the ToolTip
  10095. ToolTip toolTip1 = new ToolTip();
  10096. // 设置显示样式
  10097. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  10098. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  10099. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  10100. toolTip1.ShowAlways = true;//是否显示提示框
  10101. // 设置伴随的对象.
  10102. toolTip1.SetToolTip(this.comboBox_CheckModeCfgFile, comboBox_CheckModeCfgFile.Text);//设置故障内容显示
  10103. }
  10104. /// <summary>
  10105. /// 手动发送指令
  10106. /// </summary>
  10107. /// <param name="sender"></param>
  10108. /// <param name="e"></param>
  10109. private void 发送指令ToolStripMenuItem_Click(object sender, EventArgs e)
  10110. {
  10111. //提示
  10112. Scan scan_form = new Scan();
  10113. scan_form.label1.Text = "按照16进制填写,相邻字节用空格隔开,依次填写ID、Mode、Cmd、Data\r\n例如:07 31 16 22 05 01 02 03 04 05";
  10114. scan_form.ShowDialog();
  10115. //发送写入的指令,填写ID、类型、命令字、数据
  10116. do
  10117. {
  10118. if (scan_form.textBox_Scan.Text == string.Empty)
  10119. {
  10120. timer_500ms.Enabled = false;
  10121. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10122. timer_500ms.Enabled = true;
  10123. break;
  10124. }
  10125. //输入文本转换为字节流
  10126. var InputData = new byte[256];
  10127. InputData = mySerialProcess.HexStringToBytes(scan_form.textBox_Scan.Text, true);
  10128. //ID
  10129. ushort ID;
  10130. ID = (ushort)((InputData[0] << 8) + InputData[1]);
  10131. //Mode
  10132. byte Mode;
  10133. Mode = InputData[2];
  10134. //Cmd
  10135. ushort Cmd;
  10136. Cmd = (ushort)((InputData[3] << 8) + InputData[4]);
  10137. //Data
  10138. var Data = new byte[Cmd & 0x00FF];
  10139. for (int i = 0; i < (Cmd & 0x00FF); i++)
  10140. Data[i] = InputData[5 + i];
  10141. //发送数据
  10142. mySerialProcess.SendCmdWithoutNotice(ID, Mode, Cmd, Data);
  10143. } while (false);
  10144. }
  10145. /// <summary>
  10146. /// 启动位置传感器校准
  10147. /// </summary>
  10148. /// <param name="sender"></param>
  10149. /// <param name="e"></param>
  10150. private void button_AngleCalStart_Click(object sender, EventArgs e)
  10151. {
  10152. for (int i = 0; i < 7; i++)
  10153. for (int j = 0; j < 6; j++)
  10154. {
  10155. dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = "";
  10156. }
  10157. foreach (Control cr in tabPage_AngleCal.Controls)
  10158. {
  10159. if (cr is TextBox)
  10160. {
  10161. if ((cr != textBox_AngleDiffTh) && (cr != textBox_AngleZeroTh))
  10162. cr.Text = "";
  10163. }
  10164. }
  10165. var Data = new byte[2];
  10166. mySerialProcess.SendCmd((ushort)0x751, (byte)0x0C, (ushort)0x5002, Data);
  10167. }
  10168. /// <summary>
  10169. /// 导出位置传感器校准数据
  10170. /// </summary>
  10171. /// <param name="sender"></param>
  10172. /// <param name="e"></param>
  10173. private void button_AngleExportData_Click(object sender, EventArgs e)
  10174. {
  10175. //读出产品信息
  10176. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  10177. Delay_ms(200);
  10178. SaveFileDialog sfd = new SaveFileDialog
  10179. {
  10180. FileName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + "位置传感器角度数据_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt",
  10181. Filter = "文本文档(*.txt)|*.txt",
  10182. Title = "Save"
  10183. };
  10184. if (sfd.ShowDialog() != DialogResult.OK)
  10185. {
  10186. return;
  10187. }
  10188. string filepath = sfd.FileName;
  10189. FileStream fs = new FileStream(filepath, FileMode.OpenOrCreate);
  10190. using (StreamWriter sw = new StreamWriter(fs))
  10191. {
  10192. sw.Write("标准值 ");
  10193. sw.Write("60.00 ");
  10194. sw.Write("120.00 ");
  10195. sw.Write("180.00 ");
  10196. sw.Write("240.00 ");
  10197. sw.Write("300.00 ");
  10198. sw.Write("360.00 ");
  10199. for (int i = 0; i < 42; i++)
  10200. {
  10201. if ((i % 6 == 0))
  10202. {
  10203. sw.Write("\r\n" + "采集值" + (i / 6 + 1).ToString() + " ");
  10204. }
  10205. sw.Write(AngledataRecord[i] + " ");
  10206. }
  10207. sw.Write("\r\n" + "历史零点位置 " + textBox_AngleZeroInit.Text);
  10208. sw.Write("\r\n" + "当前零点位置 " + textBox_AngleZeroCur.Text);
  10209. sw.Write("\r\n" + "零点误差 " + textBox_AngleZeroDiff.Text);
  10210. sw.Write("\r\n" + "最小偏差值 " + textBox_AngleDiffMin.Text);
  10211. sw.Write("\r\n" + "最大偏差值 " + textBox_AngleDiffMax.Text);
  10212. sw.Write("\r\n" + "平均偏差值 " + textBox_AngleDiffAvg.Text);
  10213. sw.Flush();
  10214. }
  10215. fs.Close();
  10216. }
  10217. /// <summary>
  10218. /// 写入校准数据
  10219. /// </summary>
  10220. /// <param name="sender"></param>
  10221. /// <param name="e"></param>
  10222. private void button_AngleWrite_Click(object sender, EventArgs e)
  10223. {
  10224. if ((textBox_AngleDiffAvg.Text == "") || (textBox_AngleZeroInit.Text == ""))
  10225. {
  10226. timer_500ms.Enabled = false;
  10227. MessageBox.Show("请先启动校准,以确认校准数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  10228. timer_500ms.Enabled = true;
  10229. return;
  10230. }
  10231. timer_500ms.Enabled = false;
  10232. string str1 = "确认校准数据,历史零点: " + textBox_AngleZeroInit.Text + ", 偏差平均值: " + textBox_AngleDiffAvg.Text;
  10233. if (MessageBox.Show(str1, "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  10234. {
  10235. var SaveFlag = new byte[4];
  10236. for (int i = 0; i < 4; i++)
  10237. SaveFlag[i] = 0;
  10238. SaveFlag[0] = (byte)(1);
  10239. double data1 = Convert.ToDouble(textBox_AngleZeroInit.Text) - Convert.ToDouble(textBox_AngleDiffAvg.Text);
  10240. if (data1 > 360)
  10241. {
  10242. data1 -= 360;
  10243. }
  10244. else if (data1 < -360)
  10245. {
  10246. data1 += 360;
  10247. }
  10248. Int16 data2 = (Int16)(data1 * 32768 / 360);
  10249. SaveFlag[2] = (byte)(data2);
  10250. SaveFlag[3] = (byte)(data2 >> 8);
  10251. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, SaveFlag);
  10252. timer_500ms.Enabled = true;
  10253. }
  10254. else
  10255. {
  10256. timer_500ms.Enabled = true;
  10257. MessageBoxTimeOut.Show("写入取消", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  10258. }
  10259. }
  10260. /// <summary>
  10261. /// 存储允许偏差
  10262. /// </summary>
  10263. /// <param name="sender"></param>
  10264. /// <param name="e"></param>
  10265. private void textBox_AngleDiffTh_KeyDown(object sender, KeyEventArgs e)
  10266. {
  10267. if (e.KeyCode == Keys.Enter)
  10268. {
  10269. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  10270. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  10271. }
  10272. }
  10273. /// <summary>
  10274. /// 存储零点允许偏差
  10275. /// </summary>
  10276. /// <param name="sender"></param>
  10277. /// <param name="e"></param>
  10278. private void textBox_AngleZeroTh_KeyDown(object sender, KeyEventArgs e)
  10279. {
  10280. if (e.KeyCode == Keys.Enter)
  10281. {
  10282. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  10283. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  10284. }
  10285. }
  10286. /// <summary>
  10287. /// 删除服务器配置文件
  10288. /// </summary>
  10289. /// <param name="sender"></param>
  10290. /// <param name="e"></param>
  10291. private void 重置ToolStripMenuItem_Click(object sender, EventArgs e)
  10292. {
  10293. if (MessageBox.Show("重置后软件自动关闭,确认重置?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  10294. {
  10295. if(File.Exists(localInfo.LocalPath + localInfo.ServerCfgFileName))
  10296. File.Delete(localInfo.LocalPath + localInfo.ServerCfgFileName);
  10297. if(File.Exists(localInfo.LocalPath + localInfo.ConfigFileName))
  10298. File.Delete(localInfo.LocalPath + localInfo.ConfigFileName);
  10299. System.Environment.Exit(0);
  10300. }
  10301. }
  10302. /// <summary>
  10303. /// 按下Enter保存数据
  10304. /// </summary>
  10305. /// <param name="sender"></param>
  10306. /// <param name="e"></param>
  10307. private void toolStripTextBox_AngleAvgMax_KeyDown(object sender, KeyEventArgs e)
  10308. {
  10309. textBox_AngleDiffTh.Text = toolStripTextBox_AngleAvgMax.Text;
  10310. if (e.KeyCode == Keys.Enter)
  10311. {
  10312. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  10313. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  10314. }
  10315. }
  10316. /// <summary>
  10317. /// 按下Enter保存数据
  10318. /// </summary>
  10319. /// <param name="sender"></param>
  10320. /// <param name="e"></param>
  10321. private void toolStripTextBox_AngleZeroMax_KeyDown(object sender, KeyEventArgs e)
  10322. {
  10323. textBox_AngleZeroTh.Text = toolStripTextBox_AngleZeroMax.Text;
  10324. if (e.KeyCode == Keys.Enter)
  10325. {
  10326. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  10327. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  10328. }
  10329. }
  10330. private void 帮助ToolStripMenuItem_Click(object sender, EventArgs e)
  10331. {
  10332. //检查本地文件
  10333. if (!File.Exists(localInfo.LocalPath + localInfo.HelpFilename))
  10334. {
  10335. if (!OfflineFlag)
  10336. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/help/" + localInfo.HelpFilename, localInfo.LocalPath);
  10337. else
  10338. {
  10339. MessageBoxTimeOut.Show("未找到帮助文件!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10340. return;
  10341. }
  10342. }
  10343. //调用本地浏览器打开帮助文件
  10344. System.Diagnostics.Process.Start("explorer", localInfo.LocalPath + localInfo.HelpFilename);
  10345. }
  10346. /// <summary>
  10347. /// 读取故障日志地址
  10348. /// </summary>
  10349. /// <param name="sender"></param>
  10350. /// <param name="e"></param>
  10351. private void button_ReadLogAddr_Click(object sender, EventArgs e)
  10352. {
  10353. textBox_LogAddrBegin.Text = "";
  10354. textBox_LogAddrEnd.Text = "";
  10355. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x5200, null);
  10356. }
  10357. /// <summary>
  10358. /// 写入硬件版本
  10359. /// </summary>
  10360. /// <param name="sender"></param>
  10361. /// <param name="e"></param>
  10362. private void button_WriteHW_Click(object sender, EventArgs e)
  10363. {
  10364. string HW = textBox_HW.Text;
  10365. var HWArray = new byte[16];
  10366. for (ushort i = 0; i < HW.Length; i++)
  10367. {
  10368. HWArray[i] = (byte)HW[i];
  10369. }
  10370. if (HW.Length < 16)
  10371. {
  10372. HWArray[HW.Length] = (byte)'.';
  10373. for (ushort i = 0; i < 16 - HW.Length - 1; i++)
  10374. {
  10375. HWArray[HW.Length + 1 + i] = 0x20;
  10376. }
  10377. }
  10378. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5310, HWArray);
  10379. }
  10380. /// <summary>
  10381. /// 生产模式写入HW
  10382. /// </summary>
  10383. /// <param name="sender"></param>
  10384. /// <param name="e"></param>
  10385. private void Button_FacModeSetHW_Click(object sender, EventArgs e)
  10386. {
  10387. string HW = textBox_FacModeHW.Text;
  10388. var HWArray = new byte[16];
  10389. for (ushort i = 0; i < HW.Length; i++)
  10390. {
  10391. HWArray[i] = (byte)HW[i];
  10392. }
  10393. if (HW.Length < 16)
  10394. {
  10395. HWArray[HW.Length] = (byte)'.';
  10396. for (ushort i = 0; i < 16 - HW.Length - 1; i++)
  10397. {
  10398. HWArray[HW.Length + 1 + i] = 0x20;
  10399. }
  10400. }
  10401. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5310, HWArray);
  10402. }
  10403. /// <summary>
  10404. /// 读取定制编号
  10405. /// </summary>
  10406. /// <param name="sender"></param>
  10407. /// <param name="e"></param>
  10408. private void button_ReadUserNum_Click(object sender, EventArgs e)
  10409. {
  10410. textBox_UserNum.Text = "---";
  10411. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x5600, null);
  10412. }
  10413. /// <summary>
  10414. /// 写入定制编号
  10415. /// </summary>
  10416. /// <param name="sender"></param>
  10417. /// <param name="e"></param>
  10418. private void button_WriteUserNum_Click(object sender, EventArgs e)
  10419. {
  10420. string User = textBox_UserNum.Text;
  10421. var UserArray = new byte[32];
  10422. for (ushort i = 0; i < User.Length; i++)
  10423. {
  10424. UserArray[i] = (byte)User[i];
  10425. }
  10426. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5720, UserArray);
  10427. }
  10428. /// <summary>
  10429. /// 读取指定块拓展功能
  10430. /// </summary>
  10431. /// <param name="sender"></param>
  10432. /// <param name="e"></param>
  10433. private void button_FunSet_Read_Click(object sender, EventArgs e)
  10434. {
  10435. if (comboBox_FunSet_BlockNum.SelectedIndex < 0)
  10436. {
  10437. MessageBox.Show("请选择块编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10438. }
  10439. else
  10440. {
  10441. //清空当前内容
  10442. for (int i = 0; i < 8; i++)
  10443. for (int j = 0; j < 8; j++)
  10444. {
  10445. dataGridView_FunSet.Rows[i].Cells[j + 1].Value = "";
  10446. }
  10447. //发送读取指令
  10448. ushort Num = (ushort)(comboBox_FunSet_BlockNum.SelectedIndex + 1);
  10449. var Code = new byte[2];
  10450. Code[0] = (byte)(Num & 0xFF);
  10451. Code[1] = (byte)(Num >> 8);
  10452. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x5402, Code);
  10453. }
  10454. }
  10455. /// <summary>
  10456. /// 写入指定块或指定单元参数
  10457. /// </summary>
  10458. /// <param name="sender"></param>
  10459. /// <param name="e"></param>
  10460. private void button_FunSet_Write_Click(object sender, EventArgs e)
  10461. {
  10462. if (radioButton_WriteByBlock.Checked == true)
  10463. {
  10464. if (comboBox_FunSet_BlockNum.SelectedIndex < 0)
  10465. MessageBox.Show("请选择块编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10466. else
  10467. {
  10468. //开始按块写入
  10469. ushort Num = (ushort)(comboBox_FunSet_BlockNum.SelectedIndex + 1);
  10470. var Code = new byte[66];
  10471. Code[0] = (byte)(Num & 0xFF);
  10472. Code[1] = (byte)(Num >> 8);
  10473. for (int i = 0; i < 8; i++)
  10474. for (int j = 0; j < 8; j++)
  10475. {
  10476. try
  10477. {
  10478. byte Data = Convert.ToByte(dataGridView_FunSet.Rows[i].Cells[j + 1].Value);
  10479. Code[i * 8 + j + 2] = (byte)(Data & 0xFF);
  10480. }
  10481. catch (Exception)
  10482. {
  10483. MessageBox.Show("数据格式错误或超范围!\r\n" + "单元编号:" + (i + 1).ToString() + "\r\n" + "参数:" + (j + 1).ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10484. return;
  10485. }
  10486. }
  10487. if (MessageBox.Show("请核对块编号!\r\n" + "块编号:" + (Num).ToString(), "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  10488. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5542, Code);
  10489. else
  10490. MessageBoxTimeOut.Show("取消写入", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  10491. }
  10492. }
  10493. else if (radioButton_WriteByUnit.Checked == true)
  10494. {
  10495. if (comboBox_FunSet_BlockNum.SelectedIndex < 0)
  10496. MessageBox.Show("请选择块编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10497. else
  10498. {
  10499. if (comboBox_FunSet_UnitNum.SelectedIndex < 0)
  10500. MessageBox.Show("请选择单元编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10501. else
  10502. {
  10503. //开始按单元写入
  10504. ushort Num1 = (ushort)(comboBox_FunSet_BlockNum.SelectedIndex + 1);
  10505. ushort Num2 = (ushort)(comboBox_FunSet_UnitNum.SelectedIndex + 1);
  10506. var Code = new byte[12];
  10507. Code[0] = (byte)(Num1 & 0xFF);
  10508. Code[1] = (byte)(Num1 >> 8);
  10509. Code[2] = (byte)(Num2 & 0xFF);
  10510. Code[3] = (byte)(Num2 >> 8);
  10511. for (int i = 0; i < 8; i++)
  10512. {
  10513. try
  10514. {
  10515. byte Data = Convert.ToByte(dataGridView_FunSet.Rows[Num2 - 1].Cells[i + 1].Value);
  10516. Code[i + 4] = (byte)(Data & 0xFF);
  10517. }
  10518. catch (Exception)
  10519. {
  10520. MessageBox.Show("数据格式错误或超范围!\r\n" + "单元编号:" + Num2.ToString() + "\r\n" + "参数:" + (i + 1).ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10521. return;
  10522. }
  10523. }
  10524. if (MessageBox.Show("请核对块编号和单元编号!\r\n" + "块编号:" + Num1.ToString() + "\r\n" + "单元编号:" + Num2.ToString(), "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  10525. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x550C, Code);
  10526. else
  10527. MessageBoxTimeOut.Show("取消写入", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  10528. }
  10529. }
  10530. }
  10531. else
  10532. {
  10533. MessageBox.Show("请选择写入方式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10534. }
  10535. }
  10536. /// <summary>
  10537. /// 按块写入时隐藏单元编号
  10538. /// </summary>
  10539. /// <param name="sender"></param>
  10540. /// <param name="e"></param>
  10541. private void radioButton_WriteByUnit_CheckedChanged(object sender, EventArgs e)
  10542. {
  10543. if (radioButton_WriteByUnit.Checked == true)
  10544. {
  10545. label159.Visible = true;
  10546. comboBox_FunSet_UnitNum.Visible = true;
  10547. }
  10548. else
  10549. {
  10550. label159.Visible = false;
  10551. comboBox_FunSet_UnitNum.Visible = false;
  10552. }
  10553. }
  10554. /// <summary>
  10555. /// 打开或关闭指令窗口
  10556. /// </summary>
  10557. /// <param name="sender"></param>
  10558. /// <param name="e"></param>
  10559. private void 指令调试ToolStripMenuItem_Click(object sender, EventArgs e)
  10560. {
  10561. if (指令调试ToolStripMenuItem.Checked == false)
  10562. {
  10563. if (DebugForm.debug1 == null || DebugForm.debug1.IsDisposed)
  10564. {
  10565. DebugForm.debug1 = new DebugForm();
  10566. DebugForm.debug1.Show();
  10567. this.DebugWindowIsOpen = true;
  10568. }
  10569. else
  10570. {
  10571. DebugForm.debug1.Activate();
  10572. this.DebugWindowIsOpen = true;
  10573. }
  10574. 指令调试ToolStripMenuItem.Checked = true;
  10575. }
  10576. else
  10577. {
  10578. if (this.DebugWindowIsOpen == true)
  10579. {
  10580. DebugForm.debug1.Close();
  10581. this.DebugWindowIsOpen = false;
  10582. this.DebugDataDisplayEnable = false;
  10583. }
  10584. 指令调试ToolStripMenuItem.Checked = false;
  10585. }
  10586. }
  10587. }
  10588. }