mainForm.cs 495 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473
  1. using NPOI.POIFS.Crypt.Dsig;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Diagnostics;
  6. using System.Diagnostics.Eventing.Reader;
  7. using System.Drawing;
  8. using System.IO;
  9. using System.IO.Ports;
  10. using System.Linq;
  11. using System.Reflection;
  12. using System.Runtime.InteropServices;
  13. using System.Runtime.InteropServices.ComTypes;
  14. using System.Text;
  15. using System.Text.RegularExpressions;
  16. using System.Threading;
  17. using System.Web;
  18. using System.Windows.Forms;
  19. using System.Xml.Linq;
  20. namespace Welling_Motor_Debug_Tool
  21. {
  22. public partial class mainForm : Form
  23. {
  24. #region 变量定义
  25. //版本号
  26. public static string Version = "2.4.1";
  27. //串口实例
  28. Serial_Process mySerialProcess = new Serial_Process();
  29. string PortNumSave = "";
  30. string PortBaudrateSave = "";
  31. //本地信息定义
  32. LocalInfo localInfo = new LocalInfo();
  33. //FTP实例
  34. ftp myFtp = new ftp();
  35. public string ServerIP = "";
  36. public string ServerPort = "";
  37. public string ServerUser = "";
  38. public string ServerPassWd = "";
  39. public bool OfflineFlag = false;
  40. //MC运行信息超时计数
  41. bool MC_RunInfo_Refresh = false;
  42. ushort MC_RunInfo_Refresh_Cnt = 0;
  43. //MC调试信息超时计数
  44. bool MC_DebugInfo_Refresh = false;
  45. ushort MC_DebugInfo_Refresh_Cnt = 0;
  46. //MC故障码超时计数
  47. bool MC_ErrorCode_Refresh = false;
  48. ushort MC_ErrorCode_Refresh_Cnt = 0;
  49. //配置参数实例
  50. Params myParams = new Params();
  51. //记录文件名称
  52. string RunInfoSaveFilename = "";
  53. //BMS运行信息超时计数
  54. bool BMS_RunInfo_Refresh = false;
  55. ushort BMS_RunInfo_Refresh_Cnt = 0;
  56. //生产模式关机指令反馈状态
  57. bool PowerOffAckStatus = false;
  58. //登录窗口
  59. public static Login EnterForm1 = new Login();
  60. //生产配置文件信息
  61. ArrayList array_CfgInfo = new ArrayList();
  62. //写入参数返回标志和计数
  63. public bool WriteACK = false;
  64. public ushort ACK_WaitCnt = 0;
  65. //写入参数返回提示标志
  66. public bool ACK_DisFlag = true;
  67. //Boot版本信息
  68. public string BootInfo = "";
  69. //接收指令临时缓存,转string
  70. public string CmdRevStrTemp = "";
  71. //计时器,用于统计运行时间
  72. public Stopwatch stopwatch = new Stopwatch();
  73. //力矩传感器检验参数窗口
  74. public static TorqueParams TorqueParamsForm = new TorqueParams();
  75. //参数生成窗口
  76. public static GenerateParams GenerateParamsForm = new GenerateParams();
  77. //版本信息窗口
  78. public static Version VersionForm = new Version();
  79. //本机硬件信息
  80. public string Local_HdInformation = "";
  81. //指令窗口显示
  82. public bool DebugWindowIsOpen = false, DebugDataDisplayEnable = false;
  83. //位置传感器数据记录
  84. string[] AngledataRecord = new string[42];
  85. //服务器设置窗口
  86. public static ServerSelect ServerCfgForm1 = new ServerSelect();
  87. #endregion
  88. #region 故障日志结构体定义
  89. //故障日志记录信息 60 bytes,1K空间可以保存最近16条故障记录
  90. [StructLayout(LayoutKind.Sequential)]
  91. public struct MC_ErrorLogSaveInfo_Struct_t
  92. {
  93. public UInt16 Error_Index; //故障列表索引 2 bytes, 地址偏移 0
  94. public UInt16 NotesInfo1; //备注信息1,地址偏移 2
  95. public UInt16 NotesInfo2; //备注信息2,地址偏移 4
  96. public UInt16 NotesInfo3; //备注信息3,地址偏移 6
  97. public UInt32 ErrorCode; //故障码 4 bytes, 地址偏移 8
  98. public UInt32 RunTime; //运行时间 4bytes, 地址偏移 12
  99. //电机运行信息,占用空间32bytes
  100. [StructLayout(LayoutKind.Sequential)]
  101. public struct MC_RunInfo_Struct_t
  102. {
  103. public ushort BikeSpeed; //车速 0.1km/h,地址偏移0
  104. public ushort MotorSpeed; //输出转速 1rpm,地址偏移2
  105. public ushort Power; //电功率 1W,地址偏移4
  106. public ushort BusVoltage; //母线电压 1mV,地址偏移6
  107. public ushort BusCurrent; //母线电流 1mA,地址偏移8
  108. public byte Cadence; //踏频 1rpm,地址偏移10
  109. public byte Torque; //踩踏力矩 1Nm,地址偏移11
  110. public byte CadenceDir; //踩踏方向 0-正,1-反,2-停止,地址偏移12
  111. public byte GearSt; //助力档位,地址偏移13
  112. public byte LightSwitch; //灯开关 0xF0-关,0xF1-开,地址偏移14
  113. public byte SOC; //剩余电量 1%,地址偏移15
  114. public ushort RemainDistance; //续航里程 1km,地址偏移16
  115. public ushort Torque_AD; //力矩寄存器,地址偏移18
  116. public byte PowerPerKm; //平均功耗 0.01Ah/km ,地址偏移20
  117. public byte T_PCB; //PCB温度 +40℃,地址偏移21
  118. public byte T_Coil; //绕组温度 +40℃,地址偏移22
  119. public byte T_MCU; //MCU温度 +40℃,地址偏移23
  120. public ushort Ride_Km; //开机后骑行里程 0.1km, 地址偏移24
  121. public ushort Ride_Time; //开机后骑行时间 1s,地址偏移26
  122. public UInt32 RS; //预留 4bytes
  123. };
  124. [MarshalAs(UnmanagedType.Struct)]
  125. public MC_RunInfo_Struct_t RunInfo; //运行信息 32bytes, 地址偏移 16
  126. //控制变量
  127. public Int16 IqCurrent; //Pu, 地址偏移 48
  128. public Int16 IqVoltage; //Pu, 地址偏移 50
  129. public Int16 IdCurrent; //Pu, 地址偏移 52
  130. public Int16 IdVoltage; //Pu, 地址偏移 54
  131. //状态机
  132. public UInt16 FSM; //高到低依次表示系统状态机、二层状态机、电机状态机、助力状态机, 地址偏移 56
  133. //预留
  134. public UInt16 RS1;
  135. public UInt16 RS2;
  136. public UInt16 RS3;
  137. };
  138. #endregion
  139. #region 屏幕缩放比例获取
  140. public class PrimaryScreen
  141. {
  142. #region Win32 API
  143. [DllImport("user32.dll")]
  144. static extern IntPtr GetDC(IntPtr ptr);
  145. [DllImport("gdi32.dll")]
  146. static extern int GetDeviceCaps(
  147. IntPtr hdc, // handle to DC
  148. int nIndex // index of capability
  149. );
  150. [DllImport("user32.dll", EntryPoint = "ReleaseDC")]
  151. static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDc);
  152. #endregion
  153. #region DeviceCaps常量
  154. const int HORZRES = 8;
  155. const int VERTRES = 10;
  156. const int LOGPIXELSX = 88;
  157. const int LOGPIXELSY = 90;
  158. const int DESKTOPVERTRES = 117;
  159. const int DESKTOPHORZRES = 118;
  160. #endregion
  161. #region 属性
  162. /// <summary>
  163. /// 获取屏幕分辨率当前物理大小
  164. /// </summary>
  165. public static Size WorkingArea
  166. {
  167. get
  168. {
  169. IntPtr hdc = GetDC(IntPtr.Zero);
  170. Size size = new Size();
  171. size.Width = GetDeviceCaps(hdc, HORZRES);
  172. size.Height = GetDeviceCaps(hdc, VERTRES);
  173. ReleaseDC(IntPtr.Zero, hdc);
  174. return size;
  175. }
  176. }
  177. /// <summary>
  178. /// 当前系统DPI_X 大小 一般为96
  179. /// </summary>
  180. public static int DpiX
  181. {
  182. get
  183. {
  184. IntPtr hdc = GetDC(IntPtr.Zero);
  185. int DpiX = GetDeviceCaps(hdc, LOGPIXELSX);
  186. ReleaseDC(IntPtr.Zero, hdc);
  187. return DpiX;
  188. }
  189. }
  190. /// <summary>
  191. /// 当前系统DPI_Y 大小 一般为96
  192. /// </summary>
  193. public static int DpiY
  194. {
  195. get
  196. {
  197. IntPtr hdc = GetDC(IntPtr.Zero);
  198. int DpiX = GetDeviceCaps(hdc, LOGPIXELSY);
  199. ReleaseDC(IntPtr.Zero, hdc);
  200. return DpiX;
  201. }
  202. }
  203. /// <summary>
  204. /// 获取真实设置的桌面分辨率大小
  205. /// </summary>
  206. public static Size DESKTOP
  207. {
  208. get
  209. {
  210. IntPtr hdc = GetDC(IntPtr.Zero);
  211. Size size = new Size();
  212. size.Width = GetDeviceCaps(hdc, DESKTOPHORZRES);
  213. size.Height = GetDeviceCaps(hdc, DESKTOPVERTRES);
  214. ReleaseDC(IntPtr.Zero, hdc);
  215. return size;
  216. }
  217. }
  218. /// <summary>
  219. /// 获取宽度缩放百分比
  220. /// </summary>
  221. public static float ScaleX
  222. {
  223. get
  224. {
  225. IntPtr hdc = GetDC(IntPtr.Zero);
  226. int t = GetDeviceCaps(hdc, DESKTOPHORZRES);
  227. int d = GetDeviceCaps(hdc, HORZRES);
  228. float ScaleX = (float)GetDeviceCaps(hdc, DESKTOPHORZRES) / (float)GetDeviceCaps(hdc, HORZRES);
  229. ReleaseDC(IntPtr.Zero, hdc);
  230. return ScaleX;
  231. }
  232. }
  233. /// <summary>
  234. /// 获取高度缩放百分比
  235. /// </summary>
  236. public static float ScaleY
  237. {
  238. get
  239. {
  240. IntPtr hdc = GetDC(IntPtr.Zero);
  241. float ScaleY = (float)(float)GetDeviceCaps(hdc, DESKTOPVERTRES) / (float)GetDeviceCaps(hdc, VERTRES);
  242. ReleaseDC(IntPtr.Zero, hdc);
  243. return ScaleY;
  244. }
  245. }
  246. #endregion
  247. }
  248. #endregion
  249. public static mainForm mainform1 = null;
  250. public mainForm()
  251. {
  252. InitializeComponent();
  253. mainform1 = this;
  254. System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
  255. stopwatch.Start();
  256. //端口初始化
  257. mySerialProcess.Init();
  258. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  259. //检查备忘录文件
  260. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.NoteFileName))
  261. {
  262. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.NoteFileName, "");
  263. }
  264. //检验流水号记录文件
  265. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.SerialNumFileName1))
  266. {
  267. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, "0");
  268. }
  269. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.SerialNumFileName2))
  270. {
  271. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, "0");
  272. }
  273. //检查文件夹
  274. if (!Directory.Exists(localInfo.LocalPath))
  275. {
  276. Directory.CreateDirectory(localInfo.LocalPath);
  277. }
  278. if (!Directory.Exists(localInfo.LocalDataPath))
  279. {
  280. Directory.CreateDirectory(localInfo.LocalDataPath);
  281. }
  282. if (!Directory.Exists(localInfo.ToolsPath))
  283. {
  284. Directory.CreateDirectory(localInfo.ToolsPath);
  285. }
  286. if (!Directory.Exists(localInfo.LocalPath + localInfo.CfgPathName))
  287. {
  288. Directory.CreateDirectory(localInfo.LocalPath + localInfo.CfgPathName);
  289. }
  290. //服务器初始化
  291. do
  292. {
  293. //检查是否存在配置文件
  294. if (File.Exists(localInfo.LocalPath + localInfo.ServerCfgFileName)) //存在配置文件从文件选择
  295. {
  296. //解密
  297. string sLine = aes.DecryptFromFile(localInfo.LocalPath + localInfo.ServerCfgFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  298. string[] array_CfgInfo = sLine.Split(',');
  299. //解析配置文件
  300. ServerIP = array_CfgInfo[0].ToString();
  301. ServerPort = array_CfgInfo[1].ToString();
  302. ServerUser = array_CfgInfo[2].ToString();
  303. ServerPassWd = array_CfgInfo[3].ToString();
  304. if (array_CfgInfo[4].ToString() == "True")
  305. {
  306. OfflineFlag = true;
  307. checkBox_OffLineFacMode.Checked = true;
  308. checkBox_OffLineCheckMode.Checked = true;
  309. }
  310. }
  311. else //不存在配置文件由用户选择
  312. {
  313. ServerCfgForm1.ShowDialog();
  314. switch (ServerCfgForm1.comboBox_Server.SelectedIndex)
  315. {
  316. case 0: //武汉园区
  317. case 1: //顺德工厂
  318. {
  319. ServerIP = "10.177.130.30";
  320. ServerPort = "15021";
  321. ServerUser = "factory_test";
  322. ServerPassWd = "ttium";
  323. OfflineFlag = false;
  324. checkBox_OffLineFacMode.Checked = false;
  325. checkBox_OffLineCheckMode.Checked = false;
  326. break;
  327. }
  328. case 2: //威灵园区
  329. case 3: //越南工厂
  330. case 4: //公司外部
  331. {
  332. ServerIP = "8.134.109.44";
  333. ServerPort = "21";
  334. ServerUser = "ttium";
  335. ServerPassWd = "ttium123";
  336. OfflineFlag = false;
  337. checkBox_OffLineFacMode.Checked = false;
  338. checkBox_OffLineCheckMode.Checked = false;
  339. break;
  340. }
  341. case 5: //离线使用
  342. {
  343. //输入管理员密码
  344. Scan scan_form = new Scan();
  345. scan_form.label1.Text = "请输入管理员密码";
  346. scan_form.textBox_Scan.UseSystemPasswordChar = true;
  347. scan_form.ShowDialog();
  348. if (scan_form.textBox_Scan.Text == "ttium.123")
  349. {
  350. OfflineFlag = true;
  351. checkBox_OffLineFacMode.Checked = true;
  352. checkBox_OffLineCheckMode.Checked = true;
  353. }
  354. else
  355. {
  356. MessageBox.Show("密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  357. System.Environment.Exit(0);
  358. }
  359. break;
  360. }
  361. default: //无效
  362. {
  363. System.Environment.Exit(0);
  364. break;
  365. }
  366. }
  367. //保存网络配置文件
  368. if (ServerCfgForm1.checkBox_NoticeSw.Checked)
  369. {
  370. string str = ServerIP + "," + ServerPort + "," + ServerUser + "," + ServerPassWd + "," + (OfflineFlag == true).ToString();
  371. //加密保存
  372. aes.EncryptToFile(str, localInfo.LocalPath + localInfo.ServerCfgFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  373. }
  374. }
  375. } while (false);
  376. //检查配置文件
  377. if (File.Exists(localInfo.LocalPath + localInfo.ConfigFileName)) //存在配置文件,导入配置信息
  378. {
  379. //打开文件
  380. StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.ConfigFileName);
  381. string sLine = "";
  382. ArrayList array_CfgInfo = new ArrayList();
  383. array_CfgInfo.Clear();
  384. while (sLine != null)
  385. {
  386. sLine = objReader.ReadLine();
  387. array_CfgInfo.Add(sLine);
  388. }
  389. objReader.Close();
  390. //解析配置文件
  391. try
  392. {
  393. //Port Set
  394. PortNumSave = array_CfgInfo[1].ToString().Split(':')[1];
  395. PortBaudrateSave = array_CfgInfo[2].ToString().Split(':')[1];
  396. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.IndexOf(PortNumSave);
  397. toolStripComboBox_Baudrate.SelectedIndex = toolStripComboBox_Baudrate.Items.IndexOf(PortBaudrateSave);
  398. 连接开机ToolStripMenuItem.Checked = (array_CfgInfo[3].ToString().Split(':')[1] == "True");
  399. 断开关机ToolStripMenuItem.Checked = (array_CfgInfo[4].ToString().Split(':')[1] == "True");
  400. 识别通讯盒ToolStripMenuItem.Checked = (array_CfgInfo[5].ToString().Split(':')[1] == "True");
  401. //Option
  402. 写入存储ToolStripMenuItem.Checked = (array_CfgInfo[8].ToString().Split(':')[1] == "True");
  403. //Server Set
  404. toolStripTextBox_ServerPath.Text = array_CfgInfo[11].ToString().Split(':')[1];
  405. //MacInfo
  406. toolStripTextBox_MAC.Text = array_CfgInfo[14].ToString().Split(':')[1];
  407. toolStripTextBoxMACAddr.Text = array_CfgInfo[15].ToString().Split(':')[1];
  408. toolStripTextBox_MACDate.Text = DateTime.Now.ToString("yyyyMMdd");
  409. toolStripTextBox_MACPD.Text = array_CfgInfo[17].ToString().Split(':')[1];
  410. //Log Address
  411. textBox_LogAddrBegin.Text = array_CfgInfo[20].ToString().Split(':')[1];
  412. textBox_LogAddrEnd.Text = array_CfgInfo[21].ToString().Split(':')[1];
  413. //电机类型
  414. 中置电机ToolStripMenuItem.Checked = (array_CfgInfo[24].ToString().Split(':')[1] == "True");
  415. 轮毂电机ToolStripMenuItem.Checked = !中置电机ToolStripMenuItem.Checked;
  416. //检测阈值
  417. toolStripTextBox_ThVol.Text = array_CfgInfo[28].ToString().Split(':')[1];
  418. toolStripTextBox_ThCur.Text = array_CfgInfo[29].ToString().Split(':')[1];
  419. toolStripTextBox_ThSpeed.Text = array_CfgInfo[30].ToString().Split(':')[1];
  420. toolStripTextBox_ThTor.Text = array_CfgInfo[31].ToString().Split(':')[1];
  421. toolStripTextBox_ThCad.Text = array_CfgInfo[32].ToString().Split(':')[1];
  422. toolStripTextBox_ThBikeSpeed.Text = array_CfgInfo[33].ToString().Split(':')[1];
  423. toolStripTextBox_ThT_PCB.Text = array_CfgInfo[34].ToString().Split(':')[1];
  424. toolStripTextBox_ThT_MCU.Text = array_CfgInfo[35].ToString().Split(':')[1];
  425. toolStripTextBox_ThT_Motor.Text = array_CfgInfo[36].ToString().Split(':')[1];
  426. //MOS内阻校准系数
  427. toolStripTextBox_MosCalK.Text = array_CfgInfo[39].ToString().Split(':')[1];
  428. toolStripTextBox_MOS1.Text= array_CfgInfo[40].ToString().Split(':')[1];
  429. toolStripTextBox_MOS2.Text = array_CfgInfo[41].ToString().Split(':')[1];
  430. toolStripTextBox_MOS3.Text = array_CfgInfo[42].ToString().Split(':')[1];
  431. //通信协议类型
  432. cANToolStripMenuItem.Checked = (array_CfgInfo[45].ToString().Split(':')[1] == "True");
  433. uARTToolStripMenuItem.Checked = !cANToolStripMenuItem.Checked;
  434. //自动更新开关
  435. 打开ToolStripMenuItem.Checked = (array_CfgInfo[49].ToString().Split(':')[1] == "True");
  436. 关闭ToolStripMenuItem.Checked = !打开ToolStripMenuItem.Checked;
  437. //位置校准偏差
  438. textBox_AngleDiffTh.Text = array_CfgInfo[52].ToString().Split(':')[1];
  439. toolStripTextBox_AngleAvgMax.Text = textBox_AngleDiffTh.Text;
  440. textBox_AngleZeroTh.Text = array_CfgInfo[53].ToString().Split(':')[1];
  441. toolStripTextBox_AngleZeroMax.Text = textBox_AngleZeroTh.Text;
  442. }
  443. catch (System.Exception)
  444. {
  445. timer_500ms.Enabled = false;
  446. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  447. timer_500ms.Enabled = true;
  448. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  449. }
  450. }
  451. else //不存在配置文件,生成文件写入默认值
  452. {
  453. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  454. }
  455. //解析本地流水号记录
  456. do
  457. {
  458. //测试模式
  459. label_FacModeSerial.Text = File.ReadAllText(localInfo.LocalPath + localInfo.SerialNumFileName1);
  460. //检验模式
  461. label_CheckModeSerial.Text = File.ReadAllText(localInfo.LocalPath + localInfo.SerialNumFileName2);
  462. } while (false);
  463. //获取本机信息,读取时间较长,优先从本地文件获取
  464. do
  465. {
  466. try
  467. {
  468. //本地文件为空,读取信息保存
  469. if (!File.Exists(localInfo.LocalPath + localInfo.PC_InfoFileName))
  470. {
  471. Local_HdInformation = "";
  472. Local_HdInformation += "计算机名称: " + System.Environment.UserName + "\r\n";
  473. Local_HdInformation += "IP地址: " + PC_Information.GetIpAddress() + "\r\n";
  474. Local_HdInformation += "系统ID: " + PC_Information.GetSystemID() + "\r\n";
  475. Local_HdInformation += "操作系统类型: " + PC_Information.GetSystemType() + "\r\n";
  476. Local_HdInformation += "主板型号: " + PC_Information.GetBoardType() + "\r\n";
  477. Local_HdInformation += "主板厂商: " + PC_Information.GetBoardManufacturer() + "\r\n";
  478. Local_HdInformation += "主板ID: " + PC_Information.GetBIOSSerialNumber() + "\r\n";
  479. Local_HdInformation += "CPU型号: " + PC_Information.GetCpuName() + "\r\n";
  480. Local_HdInformation += "CPU厂商: " + PC_Information.GetCpuManufacturer() + "\r\n";
  481. Local_HdInformation += "CPU ID: " + PC_Information.GetCPUSerialNumber() + "\r\n";
  482. Local_HdInformation += "内存容量: " + PC_Information.GetPhysicalMemory() + " GB" + "\r\n";
  483. Local_HdInformation += "MAC ID: " + PC_Information.GetNetCardMACAddress().Replace(":", "-") + "\r\n";
  484. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.PC_InfoFileName, Local_HdInformation);
  485. }
  486. //从本地读取,计算机名和IP地址重新读
  487. else
  488. {
  489. Local_HdInformation = "";
  490. string[] fileInfo = File.ReadAllLines(localInfo.LocalPath + localInfo.PC_InfoFileName, Encoding.UTF8);
  491. fileInfo[0] = "计算机名称: " + System.Environment.UserName;
  492. fileInfo[1] = "IP地址: " + PC_Information.GetIpAddress();
  493. for (int i = 0; i < fileInfo.Length; i++)
  494. Local_HdInformation += fileInfo[i] + "\r\n";
  495. File.Delete(localInfo.LocalPath + localInfo.PC_InfoFileName);
  496. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.PC_InfoFileName, Local_HdInformation);
  497. }
  498. }
  499. catch(Exception)
  500. {
  501. }
  502. } while (false);
  503. //系统登录
  504. do
  505. {
  506. EnterForm1.ShowDialog();
  507. try
  508. {
  509. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  510. {
  511. if (EnterForm1.comboBox_User.Text.Contains("量产"))
  512. {
  513. //隐藏设置项
  514. 其它配置项ToolStripMenuItem.Visible = false;
  515. 写入存储ToolStripMenuItem.Visible = false;
  516. 服务器配置ToolStripMenuItem.Visible = false;
  517. 判断阈值ToolStripMenuItem.Visible = false;
  518. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  519. mOS内阻范围ToolStripMenuItem.Visible = false;
  520. 力矩传感器检验ToolStripMenuItem.Visible = false;
  521. 位置校准偏差范围ToolStripMenuItem.Visible = false;
  522. //显示生产信息
  523. 生产信息ToolStripMenuItem.Visible = true;
  524. //显示电机类型,但不可编辑
  525. 电机类型ToolStripMenuItem.Visible = true;
  526. 中置电机ToolStripMenuItem.Enabled = false;
  527. 轮毂电机ToolStripMenuItem.Enabled = false;
  528. if (uARTToolStripMenuItem.Checked)
  529. UART协议ToolStripMenuItem.Visible = true;
  530. //隐藏研发调试界面
  531. tabPage_MotorParam.Parent = null;
  532. tabPage_BikeParam.Parent = null;
  533. tabPage_BikeParam2.Parent = null;
  534. tabPage_ControlParam.Parent = null;
  535. tabPage_SensorParam.Parent = null;
  536. tabPage_AssistParam.Parent = null;
  537. tabPage_UsrRideParam.Parent = null;
  538. tabPage_DebugParam.Parent = null;
  539. tabPage_RecordInfo.Parent = null;
  540. tabPage_OtherInfo.Parent = null;
  541. tabPage_OBC.Parent = null;
  542. tabPage_RAMorFLASH.Parent = null;
  543. tabPage_FactoryMode.Parent = null;
  544. tabPage_DebugInfo.Parent = null;
  545. tabPage_AngleCal.Parent = null;
  546. //显示运行信息
  547. tabPage_RunInfo.Parent = tabControl2;
  548. //根据电机类型修改生产信息和电机类型
  549. if (EnterForm1.comboBox_User.Text.Contains("中置"))
  550. {
  551. 中置电机ToolStripMenuItem.Checked = true;
  552. 轮毂电机ToolStripMenuItem.Checked = false;
  553. toolStripTextBox_MACPD.Text = "MM_MC1";
  554. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  555. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  556. }
  557. else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
  558. {
  559. 中置电机ToolStripMenuItem.Checked = false;
  560. 轮毂电机ToolStripMenuItem.Checked = true;
  561. toolStripTextBox_MACPD.Text = "GF_250_1";
  562. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  563. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  564. }
  565. //显示对应生产测试界面
  566. if (EnterForm1.comboBox_User.Text.Contains("写入"))
  567. {
  568. tabPage_ProductMode_Write.Parent = tabControl1;
  569. tabPage_ProductMode_Write.Select();
  570. tabPage_ProductMode_Read.Parent = null;
  571. }
  572. else if (EnterForm1.comboBox_User.Text.Contains("检验"))
  573. {
  574. tabPage_ProductMode_Read.Parent = tabControl1;
  575. tabPage_ProductMode_Read.Select();
  576. tabPage_ProductMode_Write.Parent = null;
  577. }
  578. //应答指令不提示
  579. ACK_DisFlag = false;
  580. //退出登录
  581. break;
  582. }
  583. else if (EnterForm1.comboBox_User.Text == "工程参数配置")
  584. {
  585. //隐藏工作台内容,新建窗口完成配置
  586. groupBox1.Visible = false;
  587. groupBox3.Visible = false;
  588. tabControl2.Visible = false;
  589. //隐藏提示信息
  590. label_StarInfo.Visible = false;
  591. //打开参数配置框
  592. GenerateParamsForm.ShowDialog();
  593. System.Environment.Exit(0);
  594. //退出登录
  595. break;
  596. }
  597. else if (EnterForm1.comboBox_User.Text.Contains("样机"))
  598. {
  599. //隐藏量产界面
  600. tabPage_ProductMode_Read.Parent = null;
  601. tabPage_ProductMode_Write.Parent = null;
  602. //隐藏配置项
  603. 其它配置项ToolStripMenuItem.Visible = false;
  604. 服务器配置ToolStripMenuItem.Visible = false;
  605. 判断阈值ToolStripMenuItem.Visible = false;
  606. 力矩传感器检验ToolStripMenuItem.Visible = false;
  607. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  608. mOS内阻范围ToolStripMenuItem.Visible = false;
  609. 位置校准偏差范围ToolStripMenuItem.Visible = false;
  610. //显示生产信息
  611. 生产信息ToolStripMenuItem.Visible = true;
  612. //显示电机类型,但不可编辑
  613. 电机类型ToolStripMenuItem.Visible = true;
  614. 中置电机ToolStripMenuItem.Enabled = true;
  615. 轮毂电机ToolStripMenuItem.Enabled = true;
  616. if (uARTToolStripMenuItem.Checked)
  617. UART协议ToolStripMenuItem.Visible = true;
  618. if (EnterForm1.comboBox_User.Text.Contains("中置"))
  619. {
  620. 中置电机ToolStripMenuItem.Checked = true;
  621. 轮毂电机ToolStripMenuItem.Checked = false;
  622. toolStripTextBox_MACPD.Text = "MM_MC1";
  623. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  624. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  625. }
  626. else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
  627. {
  628. 中置电机ToolStripMenuItem.Checked = false;
  629. 轮毂电机ToolStripMenuItem.Checked = true;
  630. toolStripTextBox_MACPD.Text = "GF_250_1";
  631. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  632. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  633. }
  634. //退出登录
  635. break;
  636. }
  637. else if (EnterForm1.comboBox_User.Text == "FCT治具测试")
  638. {
  639. //隐藏设置项
  640. 其它配置项ToolStripMenuItem.Visible = false;
  641. 写入存储ToolStripMenuItem.Visible = false;
  642. 服务器配置ToolStripMenuItem.Visible = false;
  643. 判断阈值ToolStripMenuItem.Visible = false;
  644. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  645. mOS内阻范围ToolStripMenuItem.Visible = false;
  646. 力矩传感器检验ToolStripMenuItem.Visible = false;
  647. 位置校准偏差范围ToolStripMenuItem.Visible = false;
  648. //显示生产信息
  649. 生产信息ToolStripMenuItem.Visible = true;
  650. //显示电机类型,但不可编辑
  651. 电机类型ToolStripMenuItem.Visible = false;
  652. 中置电机ToolStripMenuItem.Enabled = false;
  653. 轮毂电机ToolStripMenuItem.Enabled = false;
  654. if (uARTToolStripMenuItem.Checked)
  655. UART协议ToolStripMenuItem.Visible = true;
  656. //隐藏研发调试界面
  657. tabPage_MotorParam.Parent = null;
  658. tabPage_BikeParam.Parent = null;
  659. tabPage_BikeParam2.Parent = null;
  660. tabPage_ControlParam.Parent = null;
  661. tabPage_SensorParam.Parent = null;
  662. tabPage_AssistParam.Parent = null;
  663. tabPage_UsrRideParam.Parent = null;
  664. tabPage_DebugParam.Parent = null;
  665. tabPage_RecordInfo.Parent = null;
  666. tabPage_OtherInfo.Parent = null;
  667. tabPage_OBC.Parent = null;
  668. tabPage_RAMorFLASH.Parent = null;
  669. tabPage_FactoryMode.Parent = null;
  670. tabPage_DebugInfo.Parent = null;
  671. tabPage_AngleCal.Parent = null;
  672. //显示运行信息
  673. tabPage_RunInfo.Parent = tabControl2;
  674. //目前仅轮毂使用
  675. 中置电机ToolStripMenuItem.Checked = false;
  676. 轮毂电机ToolStripMenuItem.Checked = true;
  677. toolStripTextBox_MACPD.Text = "GF_250_1";
  678. toolStripTextBox_ServerPath.Text = "HUB_Control_FCT";
  679. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  680. //显示量产测试界面
  681. tabPage_ProductMode_Write.Parent = tabControl1;
  682. tabPage_ProductMode_Write.Select();
  683. tabPage_ProductMode_Read.Parent = null;
  684. checkBox_OffLineFacMode.Checked = false;
  685. checkBox_OffLineFacMode.Enabled = true;
  686. checkBox_OffLineCheckMode.Checked = false;
  687. checkBox_OffLineCheckMode.Enabled = true;
  688. //应答指令不提示
  689. ACK_DisFlag = false;
  690. //退出登录
  691. break;
  692. }
  693. else if (EnterForm1.comboBox_User.Text == "研发调试")
  694. {
  695. //隐藏量产界面
  696. tabPage_ProductMode_Read.Parent = null;
  697. tabPage_ProductMode_Write.Parent = null;
  698. 服务器配置ToolStripMenuItem.Visible = false;
  699. if (uARTToolStripMenuItem.Checked)
  700. UART协议ToolStripMenuItem.Visible = true;
  701. //退出登录
  702. break;
  703. }
  704. else if (EnterForm1.comboBox_User.Text == "管理员")
  705. {
  706. //不隐藏任何界面
  707. //...
  708. //退出登录
  709. break;
  710. }
  711. else
  712. {
  713. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  714. //重新登录
  715. continue;
  716. }
  717. }
  718. else
  719. {
  720. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  721. //重新登录
  722. continue;
  723. }
  724. }
  725. catch (Exception)
  726. {
  727. System.Environment.Exit(0);
  728. }
  729. } while (true);
  730. //配置网络FTP服务器
  731. myFtp.FtpOption(ServerIP, ServerPort, ServerUser, ServerPassWd, "admin", "ttium_admin");
  732. //创建线程,定时检测网络连接状态
  733. Thread th = new Thread(NetworkCheck);
  734. th.IsBackground = true;
  735. th.Start();
  736. //允许跨线程访问
  737. Control.CheckForIllegalCrossThreadCalls = false;
  738. }
  739. /// <summary>
  740. /// 检查网络状态线程
  741. /// </summary>
  742. private void NetworkCheck()
  743. {
  744. //允许离线使用,直接退出
  745. if (OfflineFlag == true) //允许离线使用
  746. {
  747. timer_500ms.Enabled = false;
  748. MessageBoxTimeOut.Show("离线使用,不检测网络状态!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  749. timer_500ms.Enabled = true;
  750. return;
  751. }
  752. //不允许离线使用,实时监测网络状态
  753. else
  754. {
  755. //初始化第一次连接FTP服务器
  756. bool Result = myFtp.CheckFtp();
  757. if (Result == true)//服务器连接成功
  758. {
  759. myFtp.IsNetConnected = true;
  760. //上传登录日志
  761. do
  762. {
  763. //日志文件名
  764. string date = DateTime.Now.ToString("yyyy-MM-dd_HHmmss_fff");
  765. string fileName = date;
  766. //日志内容
  767. string fileInfo = Local_HdInformation;
  768. //保存本地
  769. if (!Directory.Exists(localInfo.LocalLogPath))
  770. Directory.CreateDirectory(localInfo.LocalLogPath);
  771. System.IO.File.WriteAllText(localInfo.LocalLogPath + fileName, fileInfo);
  772. //上传服务器
  773. myFtp.UploadFile(localInfo.LocalLogPath + fileName, "/Tools/Welling_Motor_Debug_Tool/log");
  774. } while (false);
  775. }
  776. else//服务器连接失败
  777. {
  778. myFtp.IsNetConnected = false;
  779. if (EnterForm1.comboBox_User.Text != "管理员")
  780. {
  781. timer_500ms.Enabled = false;
  782. MessageBoxTimeOut.Show("网络断开,将自动关闭!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  783. timer_500ms.Enabled = true;
  784. this.Close();
  785. }
  786. }
  787. //创建定时器,定时30s检查网络
  788. System.Timers.Timer timer_CheckNet = new System.Timers.Timer();
  789. timer_CheckNet.Enabled = true;
  790. timer_CheckNet.Interval = 30000;
  791. timer_CheckNet.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_CheckNet_Tick);
  792. timer_CheckNet.Start();
  793. while (true)
  794. {
  795. Thread.Sleep(1);
  796. if (myFtp.IsNetConnected == false)
  797. {
  798. label_Server_ComStatus.Text = "网络已断开";
  799. label_ServerStatus.BackColor = Color.Red;
  800. }
  801. else
  802. {
  803. label_Server_ComStatus.Text = "网络已连接";
  804. label_ServerStatus.BackColor = Color.Green;
  805. }
  806. }
  807. }
  808. }
  809. /// <summary>
  810. /// 线程中定时任务,检查网络状态
  811. /// </summary>
  812. /// <param name="sender"></param>
  813. /// <param name="e"></param>
  814. private void timer_CheckNet_Tick(object sender, EventArgs e)
  815. {
  816. //连接FTP服务器
  817. bool Result = myFtp.CheckFtp();
  818. if (Result == true)//服务器连接成功
  819. {
  820. myFtp.IsNetConnected = true;
  821. //允许使用
  822. groupBox1.Enabled = true;
  823. groupBox3.Enabled = true;
  824. tabControl2.Enabled = true;
  825. }
  826. else//服务器连接失败
  827. {
  828. myFtp.IsNetConnected = false;
  829. if (EnterForm1.comboBox_User.Text != "管理员")
  830. {
  831. timer_500ms.Enabled = false;
  832. MessageBoxTimeOut.Show("网络断开, 请检查网络!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Warning); //提示框自动3s关闭
  833. timer_500ms.Enabled = true;
  834. //禁止使用
  835. groupBox1.Enabled = false;
  836. groupBox3.Enabled = false;
  837. tabControl2.Enabled = false;
  838. }
  839. }
  840. }
  841. #region 非独占性延时函数
  842. public static void Delay_ms(int milliSecond)
  843. {
  844. int start = Environment.TickCount;
  845. while (Math.Abs(Environment.TickCount - start) < milliSecond)//毫秒
  846. {
  847. Application.DoEvents();
  848. }
  849. }
  850. #endregion
  851. private void MainForm_Load(object sender, System.EventArgs e)
  852. {
  853. timer_500ms.Start();
  854. //页面初始化
  855. label_BuildTime.Text = "编译时间:" + System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString("yyyy-MM-dd HH:mm:ss");
  856. label_Computername.Text = System.Environment.UserName;
  857. label_UserName.Text = EnterForm1.comboBox_User.Text;
  858. //位置校准表格初始化
  859. for (int i = 0; i < 7; i++)
  860. {
  861. int index = dataGridView_AngleCal.Rows.Add();
  862. dataGridView_AngleCal.Rows[index].Cells[0].Value = i + 1;
  863. }
  864. dataGridView_AngleCal.AllowUserToAddRows = false;
  865. this.Text += Version;
  866. //检查版本,自动更新
  867. do
  868. {
  869. if ((打开ToolStripMenuItem.Checked == false) || OfflineFlag == true)//关闭自动更新或离线时
  870. {
  871. break;
  872. }
  873. //检查网络状态
  874. if (myFtp.CheckFtp() == false)
  875. {
  876. MessageBoxTimeOut.Show("网络断开,自动更新失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  877. break;
  878. }
  879. else
  880. {
  881. //检查本地文件删除
  882. if (System.IO.File.Exists(localInfo.LocalPath + "\\Version"))
  883. System.IO.File.Delete(localInfo.LocalPath + "\\Version");
  884. //读取最新版本号
  885. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/Version", localInfo.LocalPath);
  886. StreamReader objReader = new StreamReader(localInfo.LocalPath + "\\Version");
  887. string sLine = "";
  888. ArrayList arrText = new ArrayList();//创建一个动态数组
  889. while (sLine != null)
  890. {
  891. sLine = objReader.ReadLine();
  892. arrText.Add(sLine);
  893. }
  894. objReader.Close();
  895. System.IO.File.Delete(localInfo.LocalPath + "\\Version");
  896. //检查是否有最新版本
  897. string[] VerOld = mainForm.Version.Trim().Split('.');
  898. string[] VerNew = arrText[0].ToString().Trim().Split('.');
  899. int VerOld_int = Convert.ToInt32(VerOld[0]) * 10000 + Convert.ToInt32(VerOld[1].PadLeft(2, '0')) * 100 + Convert.ToInt32(VerOld[2].PadLeft(2, '0'));
  900. int VerNew_int = Convert.ToInt32(VerNew[0]) * 10000 + Convert.ToInt32(VerNew[1].PadLeft(2, '0')) * 100 + Convert.ToInt32(VerNew[2].PadLeft(2, '0'));
  901. if (VerNew_int <= VerOld_int)
  902. {
  903. //版本已是最新,跳出
  904. break;
  905. }
  906. //确认下载最新版本
  907. if (MessageBox.Show("是否更新新版本?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  908. {
  909. string SavePath = Directory.GetCurrentDirectory();
  910. string[] FileList = myFtp.GetFileNameList("/Tools/Welling_Motor_Debug_Tool");
  911. foreach (string file in FileList)
  912. {
  913. if (file.Contains(".exe"))
  914. {
  915. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/" + file, SavePath);
  916. MessageBox.Show("新版本下载完成,请手动删除旧版本!\r\n最新版本:" + file, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  917. System.Environment.Exit(0);
  918. }
  919. }
  920. }
  921. }
  922. } while (false);
  923. //下拉控件初始值设定
  924. comboBox_WorkMode.SelectedIndex = 0;
  925. comboBox_GearSt.SelectedIndex = 0;
  926. comboBox_LightSwitch.SelectedIndex = 1;
  927. comboBox_OBC_SetGearST.SelectedIndex = 0;
  928. comboBox_OBC_LightSw.SelectedIndex = 1;
  929. comboBox_AssistTorque.SelectedIndex = 0;
  930. comboBox_AssistCadence.SelectedIndex = 0;
  931. //combobox事件定义
  932. this.comboBox_WorkMode.SelectedIndexChanged += new System.EventHandler(this.comboBox_WorkMode_SelectedIndexChanged);
  933. this.comboBox_GearSt.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  934. this.comboBox_LightSwitch.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  935. this.comboBox_OBC_SetGearST.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  936. this.comboBox_OBC_LightSw.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  937. //端口自动连接
  938. if ((PortNumSave != string.Empty) && (PortBaudrateSave != string.Empty)) //有数值时采用上次使用的值
  939. {
  940. try
  941. {
  942. PortConnect();
  943. }
  944. catch (System.Exception)
  945. {
  946. timer_500ms.Enabled = false;
  947. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  948. timer_500ms.Enabled = true;
  949. }
  950. }
  951. //不识别联动装置盒自动打开界面
  952. #if true
  953. groupBox1.Visible = true;
  954. groupBox3.Visible = true;
  955. tabControl2.Visible = true;
  956. label_StarInfo.Visible = false;
  957. #endif
  958. //创建线程,定时解析数据
  959. Thread th = new Thread(Task_SerialProcess);
  960. th.IsBackground = true;
  961. th.Start();
  962. }
  963. #region 结构体与字节流相互转换
  964. public static class MyConverter
  965. {
  966. /// <summary>
  967. /// 由结构体转换为byte数组
  968. /// </summary>
  969. public static byte[] StructureToByte<T>(T structure)
  970. {
  971. int size = Marshal.SizeOf(typeof(T));
  972. byte[] buffer = new byte[size];
  973. IntPtr bufferIntPtr = Marshal.AllocHGlobal(size);
  974. try
  975. {
  976. Marshal.StructureToPtr(structure, bufferIntPtr, true);
  977. Marshal.Copy(bufferIntPtr, buffer, 0, size);
  978. }
  979. finally
  980. {
  981. Marshal.FreeHGlobal(bufferIntPtr);
  982. }
  983. return buffer;
  984. }
  985. /// <summary>
  986. /// 由byte数组转换为结构体
  987. /// </summary>
  988. public static T ByteToStructure<T>(byte[] dataBuffer, ushort StarIndex)
  989. {
  990. object structure = null;
  991. int size = Marshal.SizeOf(typeof(T));
  992. IntPtr allocIntPtr = Marshal.AllocHGlobal(size);
  993. try
  994. {
  995. Marshal.Copy(dataBuffer, StarIndex, allocIntPtr, size);
  996. structure = Marshal.PtrToStructure(allocIntPtr, typeof(T));
  997. }
  998. finally
  999. {
  1000. Marshal.FreeHGlobal(allocIntPtr);
  1001. }
  1002. return (T)structure;
  1003. }
  1004. }
  1005. #endregion
  1006. #region 故障日志解析显示
  1007. private void ErrorLogDisplay(MC_ErrorLogSaveInfo_Struct_t Log1, MC_ErrorLogSaveInfo_Struct_t Log2)
  1008. {
  1009. string SaveData = "";
  1010. //Log1
  1011. if (Log1.Error_Index != 0xFFFF)
  1012. {
  1013. SaveData += "故障序号:" + Convert.ToString(Log1.Error_Index) + ", ";
  1014. SaveData += "备注1:" + Convert.ToString(Log1.NotesInfo1) + ", ";
  1015. SaveData += "备注2:" + Convert.ToString(Log1.NotesInfo2) + ", ";
  1016. SaveData += "备注3:" + Convert.ToString(Log1.NotesInfo3) + ", ";
  1017. SaveData += "故障码:" + "0x" + Convert.ToString(Log1.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  1018. SaveData += "运行时间:" + Convert.ToString(Log1.RunTime) + "min" + ", ";
  1019. SaveData += "车速:" + ((float)Log1.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  1020. SaveData += "电机转速:" + Convert.ToString(Log1.RunInfo.MotorSpeed) + "rpm" + ", ";
  1021. SaveData += "功率:" + Convert.ToString(Log1.RunInfo.Power * 2) + "w" + ", ";
  1022. SaveData += "电压:" + Convert.ToString(Log1.RunInfo.BusVoltage) + "mV" + ", ";
  1023. SaveData += "电流:" + Convert.ToString(Log1.RunInfo.BusCurrent) + "mA" + ", ";
  1024. SaveData += "踏频:" + Convert.ToString(Log1.RunInfo.Cadence) + "rpm" + ", ";
  1025. SaveData += "力矩:" + Convert.ToString(Log1.RunInfo.Torque) + "N.m" + ", ";
  1026. SaveData += "方向:" + ((Log1.RunInfo.CadenceDir == 0) ? "正" : ((Log1.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  1027. SaveData += "档位:" + "0x" + Convert.ToString(Log1.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  1028. SaveData += "灯开关:" + ((Log1.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  1029. SaveData += "电量:" + Convert.ToString(Log1.RunInfo.SOC) + "%" + ", ";
  1030. if ((Log1.RunInfo.RemainDistance == 0xEEEE) || (Log1.RunInfo.RemainDistance == 0xFFFF))
  1031. {
  1032. SaveData += "续航:" + "---km" + ", ";
  1033. }
  1034. else
  1035. {
  1036. SaveData += "续航:" + Convert.ToString(Log1.RunInfo.RemainDistance) + "km" + ", ";
  1037. }
  1038. SaveData += "力矩AD:" + Convert.ToString(Log1.RunInfo.Torque_AD) + ", ";
  1039. SaveData += "功耗:" + Convert.ToString(Log1.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  1040. SaveData += "PCB温度:" + Convert.ToString((int)(Log1.RunInfo.T_PCB - 40)) + "℃" + ", ";
  1041. SaveData += "绕组温度:" + Convert.ToString((int)(Log1.RunInfo.T_Coil - 40)) + "℃" + ", ";
  1042. SaveData += "MCU温度:" + Convert.ToString((int)(Log1.RunInfo.T_MCU - 40)) + "℃" + ", ";
  1043. SaveData += "单次里程:" + Convert.ToString((float)Log1.RunInfo.Ride_Km / 10f) + "km" + ", ";
  1044. SaveData += "单次时间:" + Convert.ToString(Log1.RunInfo.Ride_Time) + "s" + ", ";
  1045. SaveData += "q轴电流:" + Convert.ToString(Log1.IqCurrent) + ", ";
  1046. SaveData += "q轴电压:" + Convert.ToString(Log1.IqVoltage) + ", ";
  1047. SaveData += "d轴电流:" + Convert.ToString(Log1.IdCurrent) + ", ";
  1048. SaveData += "d轴电压:" + Convert.ToString(Log1.IdVoltage) + ", ";
  1049. SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
  1050. SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
  1051. SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
  1052. SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
  1053. SaveData += "\r\n\r\n";
  1054. richTextBox_Record.AppendText(SaveData);
  1055. SaveData = "";
  1056. }
  1057. //Log2
  1058. if (Log2.Error_Index != 0xFFFF)
  1059. {
  1060. SaveData += "故障序号:" + Convert.ToString(Log2.Error_Index) + ", ";
  1061. SaveData += "备注1:" + Convert.ToString(Log2.NotesInfo1) + ", ";
  1062. SaveData += "备注2:" + Convert.ToString(Log2.NotesInfo2) + ", ";
  1063. SaveData += "备注3:" + Convert.ToString(Log2.NotesInfo3) + ", ";
  1064. SaveData += "故障码:" + "0x" + Convert.ToString(Log2.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  1065. SaveData += "运行时间:" + Convert.ToString(Log2.RunTime) + "min" + ", ";
  1066. SaveData += "车速:" + ((float)Log2.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  1067. SaveData += "电机转速:" + Convert.ToString(Log2.RunInfo.MotorSpeed) + "rpm" + ", ";
  1068. SaveData += "功率:" + Convert.ToString(Log2.RunInfo.Power * 2) + "w" + ", ";
  1069. SaveData += "电压:" + Convert.ToString(Log2.RunInfo.BusVoltage) + "mV" + ", ";
  1070. SaveData += "电流:" + Convert.ToString(Log2.RunInfo.BusCurrent) + "mA" + ", ";
  1071. SaveData += "踏频:" + Convert.ToString(Log2.RunInfo.Cadence) + "rpm" + ", ";
  1072. SaveData += "力矩:" + Convert.ToString(Log2.RunInfo.Torque) + "N.m" + ", ";
  1073. SaveData += "方向:" + ((Log2.RunInfo.CadenceDir == 0) ? "正" : ((Log2.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  1074. SaveData += "档位:" + "0x" + Convert.ToString(Log2.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  1075. SaveData += "灯开关:" + ((Log2.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  1076. SaveData += "电量:" + Convert.ToString(Log2.RunInfo.SOC) + "%" + ", ";
  1077. if ((Log2.RunInfo.RemainDistance == 0xEEEE) || (Log2.RunInfo.RemainDistance == 0xFFFF))
  1078. {
  1079. SaveData += "续航:" + "---km" + ", ";
  1080. }
  1081. else
  1082. {
  1083. SaveData += "续航:" + Convert.ToString(Log2.RunInfo.RemainDistance) + "km" + ", ";
  1084. }
  1085. SaveData += "力矩AD:" + Convert.ToString(Log2.RunInfo.Torque_AD) + ", ";
  1086. SaveData += "功耗:" + Convert.ToString(Log2.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  1087. SaveData += "PCB温度:" + Convert.ToString((int)(Log2.RunInfo.T_PCB - 40)) + "DegreeC" + ", ";
  1088. SaveData += "绕组温度:" + Convert.ToString((int)(Log2.RunInfo.T_Coil - 40)) + "DegreeC" + ", ";
  1089. SaveData += "MCU温度:" + Convert.ToString((int)(Log2.RunInfo.T_MCU - 40)) + "DegreeC" + ", ";
  1090. SaveData += "单次里程:" + Convert.ToString((float)Log2.RunInfo.Ride_Km / 10f) + "km" + ", ";
  1091. SaveData += "单次时间:" + Convert.ToString(Log2.RunInfo.Ride_Time) + "s" + ", ";
  1092. SaveData += "q轴电流:" + Convert.ToString(Log2.IqCurrent) + ", ";
  1093. SaveData += "q轴电压:" + Convert.ToString(Log2.IqVoltage) + ", ";
  1094. SaveData += "d轴电流:" + Convert.ToString(Log2.IdCurrent) + ", ";
  1095. SaveData += "d轴电压:" + Convert.ToString(Log2.IdVoltage) + ", ";
  1096. SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
  1097. SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
  1098. SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
  1099. SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
  1100. SaveData += "\r\n\r\n";
  1101. richTextBox_Record.AppendText(SaveData);
  1102. SaveData = "";
  1103. }
  1104. }
  1105. #endregion
  1106. #region 串口数据解析线程
  1107. /// <summary>
  1108. /// 串口数据解析线程
  1109. /// </summary>
  1110. private void Task_SerialProcess()
  1111. {
  1112. //创建定时器,定时读取串口数据
  1113. System.Timers.Timer timer_ReadSerial = new System.Timers.Timer();
  1114. timer_ReadSerial.Enabled = true;
  1115. timer_ReadSerial.Interval = 20;
  1116. timer_ReadSerial.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_ReadSerial_Tick);
  1117. timer_ReadSerial.Start();
  1118. while (true)
  1119. {
  1120. Thread.Sleep(1);
  1121. };
  1122. }
  1123. /// <summary>
  1124. /// 串口解析定时器
  1125. /// </summary>
  1126. /// <param name="sender"></param>
  1127. /// <param name="e"></param>
  1128. private void timer_ReadSerial_Tick(object sender, EventArgs e)
  1129. {
  1130. //串口解析
  1131. Serial_process(mySerialProcess.buffer);
  1132. }
  1133. #endregion
  1134. #region 数据解析
  1135. public void Serial_process(List<byte> buffer)
  1136. {
  1137. byte DataNum = 0; //记录每条命令数据段的长度
  1138. ushort PackageID, Cmd;
  1139. byte[] Data = new byte[1024];
  1140. try
  1141. {
  1142. while (buffer.Count >= 13)//当buffer中的数据的个数大于等于4个时,即每一帧的数据长度所在位(第4位)出现时
  1143. {
  1144. if (buffer[0] == 0x55 && buffer[1] == 0xAA)//判断帧头
  1145. {
  1146. PackageID = (ushort)(buffer[2] * 256 + buffer[3]);
  1147. if ((PackageID == 0x0710) || (PackageID == 0x0715) || (PackageID == 0x07FF) || (PackageID == 0x0720) || (PackageID == 0x0713))
  1148. {
  1149. int CmdLen = buffer[5];
  1150. if (buffer.Count < CmdLen + 11) break;//如果接收到的数据没有达到一帧数据的指定长度, 则执行下次循环
  1151. while (CmdLen > 0) //读取命令段
  1152. {
  1153. Cmd = (ushort)(buffer[6] * 256 + buffer[7]);
  1154. DataNum = (byte)(buffer[7]);//命令字的第二个字节的表示数据位的长度
  1155. if (DataNum <= (CmdLen - 2))
  1156. {
  1157. for (int i = 0; i < DataNum; i++)
  1158. {
  1159. Data[i] = buffer[i + 8];
  1160. }
  1161. // 串口接收的数据 显示在子窗口
  1162. if (this.DebugWindowIsOpen && this.DebugDataDisplayEnable)
  1163. {
  1164. string strTemp = String.Empty;
  1165. strTemp += System.DateTimeOffset.Now.ToString("HH:mm:ss.fff") + " <-- ";
  1166. for (int i = 0; i < CmdLen + 11; i++)
  1167. {
  1168. strTemp += (buffer[i].ToString("X2") + " ");
  1169. }
  1170. strTemp += "\n";
  1171. DebugForm.debug1.richTextBox_DebugRev.Text += strTemp;
  1172. }
  1173. buffer.RemoveRange(0, CmdLen + 11);
  1174. DataCmdProcess(PackageID, Cmd, Data);//对于不同的命令段,做不同的处理
  1175. DataRevToString(Cmd, Data);//指令数据转为字符串
  1176. }
  1177. }
  1178. }
  1179. else
  1180. {
  1181. buffer.RemoveAt(0);//ID不对
  1182. }
  1183. }
  1184. else
  1185. {
  1186. buffer.RemoveAt(0);//帧头不对,删除帧头高字节
  1187. }
  1188. }
  1189. }
  1190. catch (Exception)
  1191. {
  1192. }
  1193. }
  1194. private void DataCmdProcess(ushort ID, ushort CmdTemp, byte[] Data)
  1195. {
  1196. int DataTemp;
  1197. ushort uData16;
  1198. unchecked
  1199. {
  1200. this.Invoke((EventHandler)(delegate { label_RecCount.Text = Convert.ToString(Convert.ToInt32(label_RecCount.Text) + 1); }));
  1201. }
  1202. #region 解析发送给CDL的指令
  1203. if (ID == 0x7FF)
  1204. {
  1205. switch (CmdTemp)
  1206. {
  1207. case 0x1100://
  1208. {
  1209. unchecked
  1210. {
  1211. this.Invoke((EventHandler)(delegate
  1212. {
  1213. //CDL连接成功
  1214. mySerialProcess.CDL_Online_Flag = true;
  1215. MessageBoxTimeOut.Show("连接成功!", "提示", 500);
  1216. groupBox1.Visible = true;
  1217. groupBox3.Visible = true;
  1218. tabControl2.Visible = true;
  1219. label_StarInfo.Visible = false;
  1220. }));
  1221. }
  1222. break;
  1223. }
  1224. default: break;
  1225. }
  1226. }
  1227. #endregion
  1228. #region 解析电机的命令
  1229. else if ((ID == 0x715) || (ID == 0x710))
  1230. {
  1231. switch (CmdTemp)
  1232. {
  1233. case 0x1020://电机运行信息
  1234. {
  1235. unchecked
  1236. {
  1237. this.Invoke((EventHandler)(delegate
  1238. {
  1239. MC_RunInfo_Refresh = true;
  1240. //车速
  1241. DataTemp = (int)(Data[1] * 256 + Data[0]);
  1242. textBox_RunInfo_BikeSpeed.Text = ((float)DataTemp / 10f).ToString("0.0") + " km/h";
  1243. //输出转速
  1244. DataTemp = (ushort)(Data[3] * 256 + Data[2]);
  1245. textBox_RunInfo_MotorSpeed.Text = Convert.ToString(DataTemp) + " rpm";
  1246. Class_MotorSpeed.String = textBox_RunInfo_MotorSpeed.Text;
  1247. Class_MotorSpeed.Data = DataTemp;
  1248. //电功率
  1249. DataTemp = (ushort)(Data[5] * 256 + Data[4]);
  1250. textBox_RunInfo_Power.Text = Convert.ToString(DataTemp) + " W";
  1251. //母线电压
  1252. DataTemp = (ushort)(Data[7] * 256 + Data[6]);
  1253. textBox_RunInfo_Vol.Text = Convert.ToString(DataTemp) + " mV";
  1254. //textBox_RunInfo_Vol.Text = (DataTemp / 1000f).ToString("0.0") + " V";
  1255. //母线电流
  1256. DataTemp = (short)(Data[9] * 256 + Data[8]);
  1257. textBox_RunInfo_Current.Text = Convert.ToString(DataTemp) + " mA";
  1258. //textBox_RunInfo_Current.Text = (DataTemp / 1000f).ToString("0.0") + " A";
  1259. Class_CurrentData.String = textBox_RunInfo_Current.Text;
  1260. Class_CurrentData.Data = DataTemp;
  1261. //踏频
  1262. DataTemp = (ushort)(Data[10]);
  1263. textBox_RunInfo_Cadence.Text = Convert.ToString(DataTemp) + " rpm";
  1264. Class_CadenceData.String = textBox_RunInfo_Cadence.Text;
  1265. Class_CadenceData.Data = DataTemp;
  1266. //踩踏力矩
  1267. DataTemp = (ushort)(Data[11]);
  1268. textBox_RunInfo_Torque.Text = Convert.ToString(DataTemp) + " N.m";
  1269. Class_TorqueData.String = textBox_RunInfo_Torque.Text;
  1270. Class_TorqueData.Data = DataTemp;
  1271. //踩踏方向
  1272. DataTemp = (ushort)(Data[12]);
  1273. if (DataTemp == 0)
  1274. {
  1275. textBox_RunInfo_Dir.Text = "正向";
  1276. }
  1277. else if (DataTemp == 1)
  1278. {
  1279. textBox_RunInfo_Dir.Text = "反向";
  1280. }
  1281. else if (DataTemp == 2)
  1282. {
  1283. textBox_RunInfo_Dir.Text = "停止";
  1284. }
  1285. //助力档位
  1286. DataTemp = (ushort)(Data[13]);
  1287. if (DataTemp == 0x33)
  1288. {
  1289. textBox_RunInfo_GearSt.Text = "SMART";
  1290. //comboBox_GearSt.SelectedIndex = 5;
  1291. //comboBox_OBC_SetGearST.SelectedIndex = 5;
  1292. }
  1293. else if (DataTemp == 0x22)
  1294. {
  1295. textBox_RunInfo_GearSt.Text = "WALK";
  1296. //comboBox_GearSt.SelectedIndex = 6;
  1297. //comboBox_OBC_SetGearST.SelectedIndex = 6;
  1298. }
  1299. else
  1300. {
  1301. string[] Gears = new string[5] { "OFF", "ECO", "NORM", "SPORT", "TURBO" };
  1302. textBox_RunInfo_GearSt.Text = Gears[DataTemp];
  1303. //comboBox_GearSt.SelectedIndex = DataTemp;
  1304. //comboBox_OBC_SetGearST.SelectedIndex = DataTemp;
  1305. }
  1306. //大灯状态
  1307. DataTemp = (ushort)(Data[14]);
  1308. if (DataTemp == 0xF0)
  1309. {
  1310. textBox_RunInfo_LightSwitch.Text = "OFF";
  1311. //comboBox_LightSwitch.SelectedIndex = 1;
  1312. //comboBox_OBC_LightSw.SelectedIndex = 1;
  1313. }
  1314. else if (DataTemp == 0xF1)
  1315. {
  1316. textBox_RunInfo_LightSwitch.Text = "ON";
  1317. //comboBox_LightSwitch.SelectedIndex = 0;
  1318. //comboBox_OBC_LightSw.SelectedIndex = 0;
  1319. }
  1320. //剩余电量
  1321. DataTemp = (ushort)(Data[15]);
  1322. textBox_RunInfo_SOC.Text = Convert.ToString(DataTemp) + " %";
  1323. //剩余续航里程
  1324. DataTemp = (ushort)(Data[17] * 256 + Data[16]);
  1325. if ((DataTemp == 0xEEEE) || (DataTemp == 0xFFFF))
  1326. {
  1327. textBox_RunInfo_Range.Text = "---";
  1328. }
  1329. else
  1330. {
  1331. textBox_RunInfo_Range.Text = Convert.ToString(DataTemp) + " km";
  1332. }
  1333. //预留(显示力矩Reg),空2bytes
  1334. DataTemp = (ushort)(Data[19] * 256 + Data[18]);
  1335. textBox_TorqueReg.Text = Convert.ToString(DataTemp);
  1336. //平均功耗
  1337. DataTemp = (ushort)(Data[20]);
  1338. textBox_RunInfo_AvgPower.Text = Convert.ToString(DataTemp * 10) + " mAh/km";
  1339. //PCB温度
  1340. DataTemp = (ushort)(Data[21]);
  1341. textBox_RunInfo_T_PCB.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1342. Class_MotorTemp.String = textBox_RunInfo_T_PCB.Text;
  1343. Class_MotorTemp.Data = DataTemp - 40;
  1344. //绕组温度
  1345. DataTemp = (ushort)(Data[22]);
  1346. textBox_RunInfo_T_Coil.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1347. //MCU温度
  1348. DataTemp = (ushort)(Data[23]);
  1349. textBox_RunInfo_T_MCU.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1350. //单次里程
  1351. DataTemp = (ushort)(Data[25] * 256 + Data[24]);
  1352. textBox_RunInfo_Trip.Text = ((float)DataTemp / 10f).ToString("0.0") + " km";
  1353. //单次时间
  1354. DataTemp = (ushort)(Data[27] * 256 + Data[26]);
  1355. textBox_RunInfo_Trip_Time.Text = Convert.ToString(DataTemp) + " s";
  1356. //数据保存
  1357. RunInfoAutoSave();
  1358. }));
  1359. }
  1360. break;
  1361. }
  1362. case 0x1104://故障码
  1363. {
  1364. unchecked
  1365. {
  1366. this.Invoke((EventHandler)(delegate
  1367. {
  1368. MC_ErrorCode_Refresh = true;
  1369. textBox_ErrorCode.Text =
  1370. Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() +
  1371. Convert.ToString(Data[2], 16).PadLeft(2, '0').ToUpper() +
  1372. Convert.ToString(Data[1], 16).PadLeft(2, '0').ToUpper() +
  1373. Convert.ToString(Data[0], 16).PadLeft(2, '0').ToUpper() +
  1374. "H";
  1375. }));
  1376. }
  1377. break;
  1378. }
  1379. case 0xA903://反馈指令
  1380. {
  1381. unchecked
  1382. {
  1383. this.Invoke((EventHandler)(delegate
  1384. {
  1385. if (ACK_DisFlag == true)
  1386. {
  1387. timer_500ms.Enabled = false;
  1388. MessageBoxTimeOut.Show("OK", "反馈指令", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  1389. timer_500ms.Enabled = true;
  1390. //关机反馈
  1391. PowerOffAckStatus = true;
  1392. }
  1393. //应答标志置位
  1394. WriteACK = true;
  1395. }));
  1396. }
  1397. break;
  1398. }
  1399. case 0xB226://马达参数
  1400. {
  1401. unchecked
  1402. {
  1403. this.Invoke((EventHandler)(delegate
  1404. {
  1405. richTextBox_MotorParam.Clear();
  1406. for (int i = 0; i < myParams.MotorParam.Count; i++)
  1407. {
  1408. if (i == 6)
  1409. richTextBox_MotorParam.AppendText(myParams.MotorParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1410. else
  1411. richTextBox_MotorParam.AppendText(myParams.MotorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1412. }
  1413. richTextBox_MotorParam.Text = richTextBox_MotorParam.Text.Substring(0, richTextBox_MotorParam.Text.Length - 2);
  1414. }));
  1415. }
  1416. break;
  1417. }
  1418. case 0xB31A://整车信息
  1419. {
  1420. unchecked
  1421. {
  1422. this.Invoke((EventHandler)(delegate
  1423. {
  1424. richTextBox_BikeParam.Clear();
  1425. for (int i = 0; i < myParams.BikeParam.Count; i++)
  1426. {
  1427. if (i == 9)
  1428. richTextBox_BikeParam.AppendText(myParams.BikeParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1429. else
  1430. richTextBox_BikeParam.AppendText(myParams.BikeParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1431. //更新前后灯参数
  1432. if (i == 8)
  1433. {
  1434. comboBox_TailLightMode.SelectedIndex = ((Data[2 * i + 1] >> 4) & 0x0F) - 1;
  1435. comboBox_TailLightVol.SelectedIndex = ((Data[2 * i + 1] & 0x0F) == 6) ? 0 : 1;
  1436. comboBox_FrontLightVol.SelectedIndex = ((Data[2 * i] & 0x0F) == 6) ? 0 : 1;
  1437. }
  1438. //更新开关机参数
  1439. else if (i == 11)
  1440. {
  1441. textBox_PowerOnDelay.Text = Convert.ToString((Data[2 * i + 1] >> 4) & 0x0F);
  1442. textBox_PowerOffDelay.Text = Convert.ToString(Data[2 * i + 1] & 0x0F);
  1443. textBox_AutoPowerOff.Text = Convert.ToString(Data[2 * i]);
  1444. }
  1445. }
  1446. richTextBox_BikeParam.Text = richTextBox_BikeParam.Text.Substring(0, richTextBox_BikeParam.Text.Length - 2);
  1447. }));
  1448. }
  1449. break;
  1450. }
  1451. case 0xB420://控制器参数
  1452. {
  1453. unchecked
  1454. {
  1455. this.Invoke((EventHandler)(delegate
  1456. {
  1457. richTextBox_ControlParam.Clear();
  1458. for (int i = 0; i < myParams.ControlParam.Count; i++)
  1459. {
  1460. richTextBox_ControlParam.AppendText(myParams.ControlParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1461. //转把定速巡航
  1462. if (i == 13)
  1463. {
  1464. comboBox_Bike_CCS.SelectedIndex = ((Data[2 * i]) == 0xAA) ? 1 : 2;
  1465. }
  1466. }
  1467. richTextBox_ControlParam.Text = richTextBox_ControlParam.Text.Substring(0, richTextBox_ControlParam.Text.Length - 2);
  1468. }));
  1469. }
  1470. break;
  1471. }
  1472. case 0xB528://传感器参数
  1473. {
  1474. unchecked
  1475. {
  1476. this.Invoke((EventHandler)(delegate
  1477. {
  1478. richTextBox_SensorParam.Clear();
  1479. for (int i = 0; i < myParams.SensorParam.Count; i++)
  1480. {
  1481. richTextBox_SensorParam.AppendText(myParams.SensorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1482. }
  1483. richTextBox_SensorParam.Text = richTextBox_SensorParam.Text.Substring(0, richTextBox_SensorParam.Text.Length - 2);
  1484. //更新生产模式页面传感器零点和标定值
  1485. textBox_FacModeSensorADC0.Text = (Data[9] * 256 + Data[8]).ToString();
  1486. textBox_FacModeSensorADC1.Text = (Data[15] * 256 + Data[14]).ToString();
  1487. textBox_FacModeSensorADC2.Text = (Data[19] * 256 + Data[18]).ToString();
  1488. textBox_FacModeSensorADC3.Text = (Data[23] * 256 + Data[22]).ToString();
  1489. textBox_FacModeSensorADC4.Text = (Data[27] * 256 + Data[26]).ToString();
  1490. WriteACK = true;
  1491. }));
  1492. }
  1493. break;
  1494. }
  1495. case 0xB64C://助力参数
  1496. {
  1497. unchecked
  1498. {
  1499. this.Invoke((EventHandler)(delegate
  1500. {
  1501. richTextBox_AssistParam.Clear();
  1502. int index_1 = myParams.AssistParam.IndexOf("转矩曲线.a");
  1503. int index_2 = myParams.AssistParam.IndexOf("踏频曲线.d");
  1504. int index_3 = myParams.AssistParam.IndexOf("踏频助力加速限制");
  1505. int index_4 = myParams.AssistParam.IndexOf("踏频助力电流步进");
  1506. for (int i = 0; i < myParams.AssistParam.Count; i++)
  1507. {
  1508. if (i < index_1) //数据占用2bytes
  1509. {
  1510. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1511. }
  1512. else if (i <= index_2) //数据占用4bytes
  1513. {
  1514. 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])) + ", ");
  1515. }
  1516. else if (i < index_3) //数据占用2bytes,无符号
  1517. {
  1518. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1519. }
  1520. else if (i <= index_4) //数据占用2bytes,有符号
  1521. {
  1522. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1523. }
  1524. else //数据占用2bytes,无符号
  1525. {
  1526. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1527. }
  1528. }
  1529. richTextBox_AssistParam.Text = richTextBox_AssistParam.Text.Substring(0, richTextBox_AssistParam.Text.Length - 2);
  1530. }));
  1531. }
  1532. break;
  1533. }
  1534. case 0xB74C://历史记录
  1535. {
  1536. unchecked
  1537. {
  1538. this.Invoke((EventHandler)(delegate
  1539. {
  1540. richTextBox_Record.Clear();
  1541. for (int i = 0; i < myParams.Record.Count; i++)
  1542. {
  1543. richTextBox_Record.AppendText(myParams.Record[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  1544. }
  1545. richTextBox_Record.Text = richTextBox_Record.Text.Substring(0, richTextBox_Record.Text.Length - 2);
  1546. }));
  1547. }
  1548. break;
  1549. }
  1550. case 0xB83A://调试参数
  1551. {
  1552. unchecked
  1553. {
  1554. this.Invoke((EventHandler)(delegate
  1555. {
  1556. richTextBox_DebugParam.Clear();
  1557. for (int i = 0; i < myParams.DebugParam.Count; i++)
  1558. {
  1559. richTextBox_DebugParam.AppendText(myParams.DebugParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1560. }
  1561. richTextBox_DebugParam.Text = richTextBox_DebugParam.Text.Substring(0, richTextBox_DebugParam.Text.Length - 2);
  1562. }));
  1563. }
  1564. break;
  1565. }
  1566. case 0xB904://存储标志
  1567. {
  1568. unchecked
  1569. {
  1570. this.Invoke((EventHandler)(delegate
  1571. {
  1572. ushort Flag = 0;
  1573. Flag = (ushort)(Data[1] * 256 + Data[0]);//EEPROM存储标志
  1574. if (Flag == 0)
  1575. {
  1576. radioButton_EE_SaveNo.Checked = true;
  1577. radioButton_EE_SaveYes.Checked = false;
  1578. }
  1579. else
  1580. {
  1581. radioButton_EE_SaveNo.Checked = false;
  1582. radioButton_EE_SaveYes.Checked = true;
  1583. }
  1584. Flag = (ushort)(Data[3] * 256 + Data[2]);//SIP偏移校准存储标志
  1585. if (Flag == 0)
  1586. {
  1587. radioButton_SIP_SaveNo.Checked = true;
  1588. radioButton_SIP_SaveYes.Checked = false;
  1589. }
  1590. else
  1591. {
  1592. radioButton_SIP_SaveNo.Checked = false;
  1593. radioButton_SIP_SaveYes.Checked = true;
  1594. }
  1595. }));
  1596. }
  1597. break;
  1598. }
  1599. case 0x1240://电机版本信息
  1600. {
  1601. unchecked
  1602. {
  1603. this.Invoke((EventHandler)(delegate
  1604. {
  1605. //电机型号
  1606. textBox_Model.Text = "";
  1607. textBox_OBC_ReadModel.Text = "";
  1608. textBox_FacModeName.Text = "";
  1609. for (ushort i = 0; i < 16; i++)
  1610. {
  1611. if (Data[i] == 0x2E)
  1612. {
  1613. break;
  1614. }
  1615. textBox_Model.Text += ((char)Data[i]).ToString();
  1616. textBox_OBC_ReadModel.Text += ((char)Data[i]).ToString();
  1617. textBox_FacModeName.Text += ((char)Data[i]).ToString();
  1618. }
  1619. Class_Motor_Ver.Mode = textBox_Model.Text;
  1620. //电机SN
  1621. textBox_SN.Text = "";
  1622. textBox_OBC_ReadSN.Text = "";
  1623. textBox_FacModeNum.Text = "";
  1624. for (ushort i = 0; i < 16; i++)
  1625. {
  1626. if (Data[16 + i] == 0x2E)
  1627. {
  1628. break;
  1629. }
  1630. textBox_SN.Text += ((char)Data[16 + i]).ToString();
  1631. textBox_OBC_ReadSN.Text += ((char)Data[16 + i]).ToString();
  1632. textBox_FacModeNum.Text += ((char)Data[16 + i]).ToString();
  1633. }
  1634. Class_Motor_Ver.SN = textBox_SN.Text;
  1635. //电机HW
  1636. textBox_HW.Text = "";
  1637. textBox_OBC_ReadHW.Text = "";
  1638. textBox_FacModeHW.Text = "";
  1639. for (ushort i = 0; i < 8; i++)//前8位:硬件板号
  1640. {
  1641. if (Data[32 + i] == 0x2E)
  1642. {
  1643. break;
  1644. }
  1645. else if (Data[32 + i] == 'r')
  1646. {
  1647. Data[32 + i] = (byte)'.';
  1648. break;
  1649. }
  1650. string strTemp = "";
  1651. strTemp = ((char)Data[32 + i]).ToString();
  1652. textBox_HW.Text += strTemp;
  1653. textBox_OBC_ReadHW.Text += strTemp;
  1654. textBox_FacModeHW.Text += strTemp;
  1655. }
  1656. for (ushort i = 0; i < 4; i++)//9-12位:单片机型号
  1657. {
  1658. if (Data[40 + i] == 0x2E)
  1659. {
  1660. break;
  1661. }
  1662. else if (Data[40 + i] == 'r')
  1663. {
  1664. Data[40 + i] = (byte)'.';
  1665. break;
  1666. }
  1667. string strTemp = "";
  1668. strTemp = ((char)Data[40 + i]).ToString();
  1669. textBox_HW.Text += strTemp;
  1670. textBox_OBC_ReadHW.Text += strTemp;
  1671. textBox_FacModeHW.Text += strTemp;
  1672. }
  1673. for (ushort i = 0; i < 4; i++)//13-16位:单片机ID
  1674. {
  1675. string strTemp = "";
  1676. strTemp = Convert.ToString(Data[44 + i], 16).PadLeft(2, '0').ToUpper();
  1677. textBox_HW.Text += strTemp;
  1678. textBox_OBC_ReadHW.Text += strTemp;
  1679. textBox_FacModeHW.Text += strTemp;
  1680. }
  1681. Class_Motor_Ver.HW = textBox_HW.Text;
  1682. //电机FW
  1683. textBox_FW.Text = "";
  1684. textBox_OBC_ReadFW.Text = "";
  1685. textBox_FacModeFW.Text = "";
  1686. for (ushort i = 0; i < 16; i++)
  1687. {
  1688. if ((Data[48 + i] == 0x2E) || (Data[48 + i] == 0x00) || (Data[48 + i] == (char)' '))
  1689. {
  1690. break;
  1691. }
  1692. if (Data[48 + i] == 'r')
  1693. {
  1694. Data[48 + i] = (byte)'.';
  1695. }
  1696. textBox_FW.Text += ((char)Data[48 + i]).ToString();
  1697. textBox_OBC_ReadFW.Text += ((char)Data[48 + i]).ToString();
  1698. textBox_FacModeFW.Text += ((char)Data[48 + i]).ToString();
  1699. }
  1700. Class_Motor_Ver.FW = textBox_FW.Text;
  1701. }));
  1702. }
  1703. break;
  1704. }
  1705. case 0xA610://自定义1
  1706. {
  1707. unchecked
  1708. {
  1709. this.Invoke((EventHandler)(delegate
  1710. {
  1711. textBox_User1.Text = "";
  1712. for (ushort i = 0; i < 16; i++)
  1713. {
  1714. if (Data[i] == 0x2E)
  1715. {
  1716. break;
  1717. }
  1718. textBox_User1.Text += ((char)Data[i]).ToString();
  1719. }
  1720. }));
  1721. }
  1722. break;
  1723. }
  1724. case 0xA710://自定义2
  1725. {
  1726. unchecked
  1727. {
  1728. this.Invoke((EventHandler)(delegate
  1729. {
  1730. textBox_User2.Text = "";
  1731. for (ushort i = 0; i < 16; i++)
  1732. {
  1733. if (Data[i] == 0x2E)
  1734. {
  1735. break;
  1736. }
  1737. textBox_User2.Text += ((char)Data[i]).ToString();
  1738. }
  1739. }));
  1740. }
  1741. break;
  1742. }
  1743. case 0xA810://自定义1
  1744. {
  1745. unchecked
  1746. {
  1747. this.Invoke((EventHandler)(delegate
  1748. {
  1749. textBox_User3.Text = "";
  1750. for (ushort i = 0; i < 16; i++)
  1751. {
  1752. if (Data[i] == 0x2E)
  1753. {
  1754. break;
  1755. }
  1756. textBox_User3.Text += ((char)Data[i]).ToString();
  1757. }
  1758. }));
  1759. }
  1760. break;
  1761. }
  1762. case 0xA520://生产信息
  1763. {
  1764. unchecked
  1765. {
  1766. this.Invoke((EventHandler)(delegate
  1767. {
  1768. //生产商
  1769. textBox_MAC.Text = "";
  1770. for (ushort i = 0; i < 8; i++)
  1771. {
  1772. if (Data[i] == 0x2E)
  1773. {
  1774. break;
  1775. }
  1776. textBox_MAC.Text += ((char)Data[i]).ToString();
  1777. }
  1778. //生产地
  1779. textBox_MACAdd.Text = "";
  1780. for (ushort i = 0; i < 8; i++)
  1781. {
  1782. if (Data[8 + i] == 0x2E)
  1783. {
  1784. break;
  1785. }
  1786. textBox_MACAdd.Text += ((char)Data[8 + i]).ToString();
  1787. }
  1788. //生产日期
  1789. textBox_MACDate.Text = "";
  1790. for (ushort i = 0; i < 8; i++)
  1791. {
  1792. if (Data[16 + i] == 0x2E)
  1793. {
  1794. break;
  1795. }
  1796. textBox_MACDate.Text += ((char)Data[16 + i]).ToString();
  1797. }
  1798. //品牌信息
  1799. textBox_PP.Text = "";
  1800. for (ushort i = 0; i < 8; i++)
  1801. {
  1802. if (Data[24 + i] == 0x2E)
  1803. {
  1804. break;
  1805. }
  1806. textBox_PP.Text += ((char)Data[24 + i]).ToString();
  1807. }
  1808. }));
  1809. }
  1810. break;
  1811. }
  1812. case 0xA408://密钥
  1813. {
  1814. unchecked
  1815. {
  1816. this.Invoke((EventHandler)(delegate
  1817. {
  1818. textBox_Key.Text = "";
  1819. for (ushort i = 0; i < 8; i++)
  1820. {
  1821. textBox_Key.Text += ((char)Data[i]).ToString();
  1822. }
  1823. }));
  1824. }
  1825. break;
  1826. }
  1827. case 0xAB09://存储器数据
  1828. case 0xAB0A:
  1829. case 0xAB0B:
  1830. case 0xAB0C:
  1831. {
  1832. unchecked
  1833. {
  1834. this.Invoke((EventHandler)(delegate
  1835. {
  1836. long ByteNum = 0;
  1837. ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
  1838. if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
  1839. {
  1840. for (int i = 0; i < ByteNum; i++)
  1841. {
  1842. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  1843. }
  1844. }
  1845. else //根据设置自动转换10进制显示
  1846. {
  1847. if (checkBox_ReadRanFlash_ChangeFormat.Checked == true) //10进制显示
  1848. {
  1849. switch (ByteNum)
  1850. {
  1851. case 1:
  1852. {
  1853. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8]) + ", ");
  1854. break;
  1855. }
  1856. case 2:
  1857. {
  1858. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8)) + ", ");
  1859. break;
  1860. }
  1861. case 3:
  1862. {
  1863. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16)) + ", ");
  1864. break;
  1865. }
  1866. case 4:
  1867. {
  1868. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24)) + ", ");
  1869. break;
  1870. }
  1871. default:
  1872. {
  1873. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  1874. break;
  1875. }
  1876. }
  1877. }
  1878. else //16进制显示
  1879. {
  1880. switch (ByteNum)
  1881. {
  1882. case 1:
  1883. {
  1884. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8], 16).PadLeft(2, '0').ToUpper() + ", ");
  1885. break;
  1886. }
  1887. case 2:
  1888. {
  1889. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8), 16).PadLeft(4, '0').ToUpper() + ", ");
  1890. break;
  1891. }
  1892. case 3:
  1893. {
  1894. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16), 16).PadLeft(6, '0').ToUpper() + ", ");
  1895. break;
  1896. }
  1897. case 4:
  1898. {
  1899. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24), 16).PadLeft(8, '0').ToUpper() + ", ");
  1900. break;
  1901. }
  1902. default:
  1903. {
  1904. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  1905. break;
  1906. }
  1907. }
  1908. }
  1909. }
  1910. }));
  1911. }
  1912. break;
  1913. }
  1914. case 0xAB88://故障日志
  1915. {
  1916. unchecked
  1917. {
  1918. this.Invoke((EventHandler)(delegate
  1919. {
  1920. //电机存储的故障日志,一包128字节包含2条故障日志
  1921. var ErrorLogSaveInfo1 = new MC_ErrorLogSaveInfo_Struct_t();
  1922. var ErrorLogSaveInfo2 = new MC_ErrorLogSaveInfo_Struct_t();
  1923. ErrorLogSaveInfo1 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 8);
  1924. ErrorLogSaveInfo2 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 72);
  1925. //数据显示
  1926. ErrorLogDisplay(ErrorLogSaveInfo1, ErrorLogSaveInfo2);
  1927. }));
  1928. }
  1929. break;
  1930. }
  1931. case 0x1401://在线检测结果
  1932. {
  1933. unchecked
  1934. {
  1935. this.Invoke((EventHandler)(delegate
  1936. {
  1937. textBox_Online.Text = Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() + "H";
  1938. }));
  1939. }
  1940. break;
  1941. }
  1942. case 0x1510://骑行历史信息
  1943. {
  1944. unchecked
  1945. {
  1946. this.Invoke((EventHandler)(delegate
  1947. {
  1948. long DataTemp32;
  1949. //ODO里程
  1950. DataTemp32 = (long)((Data[3] << 24) + (Data[2] << 16) + (Data[1] << 8) + Data[0]);
  1951. textBox_OBC_ODO_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  1952. textBox_ODO_KM.Text = DataTemp32.ToString();
  1953. //ODO时间
  1954. DataTemp32 = (long)((Data[7] << 24) + (Data[6] << 16) + (Data[5] << 8) + Data[4]);
  1955. if (DataTemp32 >= 60 * 100000)
  1956. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  1957. else
  1958. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  1959. textBox_ODO_TIME.Text = DataTemp32.ToString();
  1960. //TRIP里程
  1961. DataTemp32 = (long)((Data[11] << 24) + (Data[10] << 16) + (Data[9] << 8) + Data[8]);
  1962. textBox_OBC_TRIP_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  1963. textBox_TRIP_KM.Text = DataTemp32.ToString();
  1964. //TRIP时间
  1965. DataTemp32 = (long)((Data[15] << 24) + (Data[14] << 16) + (Data[13] << 8) + Data[12]);
  1966. if (DataTemp32 >= 60 * 100000)
  1967. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  1968. else
  1969. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  1970. textBox_TRIP_TIME.Text = DataTemp32.ToString();
  1971. }));
  1972. }
  1973. break;
  1974. }
  1975. case 0x1720://客户信息
  1976. {
  1977. unchecked
  1978. {
  1979. this.Invoke((EventHandler)(delegate
  1980. {
  1981. //软件标识
  1982. textBox_SP.Text = "";
  1983. textBox_OBC_ReadSP.Text = "";
  1984. textBox_FacModeSP.Text = "";
  1985. for (ushort i = 0; i < 23; i++)
  1986. {
  1987. if (Data[i] == 'r')
  1988. {
  1989. Data[i] = (byte)'.';
  1990. }
  1991. textBox_SP.Text += ((char)Data[i]).ToString();
  1992. textBox_OBC_ReadSP.Text += ((char)Data[i]).ToString();
  1993. textBox_FacModeSP.Text += ((char)Data[i]).ToString();
  1994. }
  1995. //Git提交版本信息
  1996. textBox_FacModeGit.Text = "";
  1997. for (ushort i = 0; i < 9; i++)
  1998. {
  1999. textBox_SP.Text += ((char)Data[23 + i]).ToString();
  2000. textBox_FacModeGit.Text += ((char)Data[23 + i]).ToString();
  2001. }
  2002. Class_Motor_Ver.Special = textBox_SP.Text;
  2003. }));
  2004. }
  2005. break;
  2006. }
  2007. case 0xBA20: //调试信息
  2008. {
  2009. unchecked
  2010. {
  2011. this.Invoke((EventHandler)(delegate
  2012. {
  2013. MC_DebugInfo_Refresh = true;
  2014. //系统状态机
  2015. DataTemp = (short)(Data[0]);
  2016. textBox_DebugInfo_SysFun.Text = Convert.ToString(DataTemp);
  2017. //二层状态机
  2018. DataTemp = (short)(Data[1]);
  2019. textBox_DebugInfo_SecondFun.Text = Convert.ToString(DataTemp);
  2020. //电机状态机
  2021. DataTemp = (short)(Data[2]);
  2022. textBox_DebugInfo_MotorFun.Text = Convert.ToString(DataTemp);
  2023. //助力状态机
  2024. DataTemp = (short)(Data[3]);
  2025. textBox_DebugInfo_AssistFun.Text = Convert.ToString(DataTemp);
  2026. //IdRef
  2027. DataTemp = (short)(Data[5] * 256 + Data[4]);
  2028. textBox_DebugInfo_IdRef.Text = Convert.ToString(DataTemp);
  2029. //IqRef
  2030. DataTemp = (short)(Data[7] * 256 + Data[6]);
  2031. textBox_DebugInfo_IqRef.Text = Convert.ToString(DataTemp);
  2032. //UdRef
  2033. DataTemp = (short)(Data[9] * 256 + Data[8]);
  2034. textBox_DebugInfo_UdRef.Text = Convert.ToString(DataTemp);
  2035. //UqRef
  2036. DataTemp = (short)(Data[11] * 256 + Data[10]);
  2037. textBox_DebugInfo_UqRef.Text = Convert.ToString(DataTemp);
  2038. //瞬时力矩
  2039. DataTemp = (short)(Data[13] * 256 + Data[12]);
  2040. textBox_DebugInfo_TorquePu.Text = Convert.ToString(DataTemp);
  2041. //时间滤波力矩
  2042. DataTemp = (short)(Data[15] * 256 + Data[14]);
  2043. textBox_DebugInfo_TorqueFil.Text = Convert.ToString(DataTemp);
  2044. //踏频滤波力矩
  2045. DataTemp = (short)(Data[17] * 256 + Data[16]);
  2046. textBox_DebugInfo_TorqueCadence.Text = Convert.ToString(DataTemp);
  2047. //IdFdb
  2048. DataTemp = (short)(Data[19] * 256 + Data[18]);
  2049. textBox_DebugInfo_IdFdb.Text = Convert.ToString(DataTemp);
  2050. //IqFdb
  2051. DataTemp = (short)(Data[21] * 256 + Data[20]);
  2052. textBox_DebugInfo_IqFdb.Text = Convert.ToString(DataTemp);
  2053. //助力输出
  2054. DataTemp = (short)(Data[23] * 256 + Data[22]);
  2055. textBox_DebugInfo_AssistOut.Text = Convert.ToString(DataTemp);
  2056. //转把百分比
  2057. DataTemp = (short)(Data[25] * 256 + Data[24]);
  2058. textBox_DebugInfo_ThrottlePer.Text = Convert.ToString(DataTemp);
  2059. //数据保存
  2060. RunInfoAutoSave();
  2061. }));
  2062. }
  2063. break;
  2064. }
  2065. case 0xBB20: //产品标签信息
  2066. {
  2067. unchecked
  2068. {
  2069. this.Invoke((EventHandler)(delegate
  2070. {
  2071. //产品标签
  2072. textBox_TagInfo.Text = "";
  2073. for (ushort i = 0; i < 32; i++)
  2074. {
  2075. textBox_TagInfo.Text += ((char)Data[i]).ToString();
  2076. }
  2077. }));
  2078. }
  2079. break;
  2080. }
  2081. case 0xBC20: //内阻校正信息
  2082. {
  2083. unchecked
  2084. {
  2085. this.Invoke((EventHandler)(delegate
  2086. {
  2087. //内阻1
  2088. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  2089. textBox_MOS_R1.Text = Convert.ToString(uData16);
  2090. //内阻2
  2091. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  2092. textBox_MOS_R2.Text = Convert.ToString(uData16);
  2093. //内阻3
  2094. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  2095. textBox_MOS_R3.Text = Convert.ToString(uData16);
  2096. //K1
  2097. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  2098. textBox_MOS_K1.Text = Convert.ToString(uData16);
  2099. //K2
  2100. uData16 = (ushort)(Data[9] * 256 + Data[8]);
  2101. textBox_MOS_K2.Text = Convert.ToString(uData16);
  2102. //K3
  2103. uData16 = (ushort)(Data[11] * 256 + Data[10]);
  2104. textBox_MOS_K3.Text = Convert.ToString(uData16);
  2105. //K4
  2106. uData16 = (ushort)(Data[13] * 256 + Data[12]);
  2107. textBox_MOS_K4.Text = Convert.ToString(uData16);
  2108. //K5
  2109. uData16 = (ushort)(Data[15] * 256 + Data[14]);
  2110. textBox_MOS_K5.Text = Convert.ToString(uData16);
  2111. }));
  2112. }
  2113. break;
  2114. }
  2115. case 0xBD20: //整车信息2
  2116. {
  2117. unchecked
  2118. {
  2119. this.Invoke((EventHandler)(delegate
  2120. {
  2121. richTextBox_BikeParam2.Clear();
  2122. for (int i = 0; i < myParams.BikeParam2.Count; i++)
  2123. {
  2124. richTextBox_BikeParam2.AppendText(myParams.BikeParam2[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  2125. }
  2126. richTextBox_BikeParam2.Text = richTextBox_BikeParam2.Text.Substring(0, richTextBox_BikeParam2.Text.Length - 2);
  2127. }));
  2128. }
  2129. break;
  2130. }
  2131. case 0xBE20: //用户骑行参数
  2132. {
  2133. unchecked
  2134. {
  2135. this.Invoke((EventHandler)(delegate
  2136. {
  2137. richTextBox_UsrRidesParam.Clear();
  2138. for (int i = 0; i < myParams.UsrRideParam.Count; i++)
  2139. {
  2140. richTextBox_UsrRidesParam.AppendText(myParams.UsrRideParam[i] + "=" + Convert.ToString(Data[i]) + ", ");
  2141. }
  2142. richTextBox_UsrRidesParam.Text = richTextBox_UsrRidesParam.Text.Substring(0, richTextBox_UsrRidesParam.Text.Length - 2);
  2143. }));
  2144. }
  2145. break;
  2146. }
  2147. case 0xBF58:
  2148. {
  2149. unchecked
  2150. {
  2151. this.Invoke((EventHandler)(delegate
  2152. {
  2153. string[] str1 = new string[42];
  2154. double[] error1 = new double[42];
  2155. //更新校准数据
  2156. for (int i = 0; i < 42; i++)
  2157. {
  2158. double data1 = (Data[4 + i * 2] + (Data[4 + i * 2 + 1] << 8)) / 32767.0 * 360;
  2159. error1[i] = data1 - (60 * (i % 6) + 60);
  2160. if (error1[i] < -180)
  2161. {
  2162. error1[i] = error1[i] + 360;
  2163. }
  2164. str1[i] = data1.ToString("F2");
  2165. AngledataRecord[i] = str1[i];
  2166. }
  2167. for (int i = 0; i < 7; i++)
  2168. for (int j = 0; j < 6; j++)
  2169. {
  2170. dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = str1[6 * i + j];
  2171. }
  2172. //计算偏差最小值、最大值和平均值
  2173. //Array.ConvertAll(error1, Math.Abs);
  2174. textBox_AngleDiffMin.Text = error1.Min().ToString("F2");
  2175. textBox_AngleDiffMax.Text = error1.Max().ToString("F2");
  2176. textBox_AngleDiffAvg.Text = error1.Average().ToString("F2");
  2177. //计算零点偏差
  2178. double tmp1 = ((Int16)(Data[0] + (Data[1] << 8))) / 32767.0 * 360;
  2179. textBox_AngleZeroInit.Text = tmp1.ToString("F2");
  2180. double tmp2 = ((Int16)(Data[2] + (Data[3] << 8))) / 32767.0 * 360;
  2181. textBox_AngleZeroCur.Text = tmp2.ToString("F2");
  2182. double tmp3 = (tmp2 - tmp1);
  2183. textBox_AngleZeroDiff.Text = tmp3.ToString("F2");
  2184. }));
  2185. }
  2186. break;
  2187. }
  2188. case 0xC109: //Boot版本信息
  2189. {
  2190. BootInfo = "";
  2191. for (ushort i = 0; i < 9; i++)
  2192. {
  2193. BootInfo += ((char)Data[i]).ToString();
  2194. }
  2195. break;
  2196. }
  2197. default:
  2198. {
  2199. break;
  2200. }
  2201. }
  2202. //存储器导出数据显示
  2203. if ((CmdTemp & 0xFF00) == 0xAB00)
  2204. {
  2205. unchecked
  2206. {
  2207. this.Invoke((EventHandler)(delegate
  2208. {
  2209. long ByteNum = 0;
  2210. ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
  2211. if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
  2212. {
  2213. for (int i = 0; i < ByteNum; i++)
  2214. {
  2215. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  2216. }
  2217. }
  2218. }));
  2219. }
  2220. }
  2221. }
  2222. #endregion
  2223. #region 解析BMS广播的命令
  2224. else if (ID == 0x720)
  2225. {
  2226. switch (CmdTemp)
  2227. {
  2228. case 0x1010://BMS运行信息
  2229. {
  2230. unchecked
  2231. {
  2232. this.Invoke((EventHandler)(delegate
  2233. {
  2234. BMS_RunInfo_Refresh = true;
  2235. richTextBox_OBC_BMS_RunInfo.Clear();
  2236. //电压
  2237. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  2238. richTextBox_OBC_BMS_RunInfo.AppendText("电压:" + Convert.ToString(uData16) + " mV" + "\r\n");
  2239. //电流
  2240. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  2241. richTextBox_OBC_BMS_RunInfo.AppendText("电流:" + Convert.ToString(uData16) + " mA" + "\r\n");
  2242. //剩余容量
  2243. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  2244. richTextBox_OBC_BMS_RunInfo.AppendText("剩余容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  2245. //满充容量
  2246. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  2247. richTextBox_OBC_BMS_RunInfo.AppendText("满充容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  2248. //电芯温度
  2249. richTextBox_OBC_BMS_RunInfo.AppendText("电芯温度:" + Convert.ToString((int)(Data[8] - 40) + " ℃" + "\r\n"));
  2250. //剩余电量
  2251. richTextBox_OBC_BMS_RunInfo.AppendText("剩余电量:" + Convert.ToString(Data[9]) + " %" + "\r\n");
  2252. //电池状态
  2253. richTextBox_OBC_BMS_RunInfo.AppendText("电池状态:" + Convert.ToString(Data[10], 16).PadLeft(2, '0').ToUpper() + " H" + "\r\n");
  2254. //SOH
  2255. richTextBox_OBC_BMS_RunInfo.AppendText("电池寿命:" + Convert.ToString(Data[11]) + " %" + "\r\n");
  2256. //循环次数
  2257. richTextBox_OBC_BMS_RunInfo.AppendText("循环次数:" + Convert.ToString((ushort)(Data[13] * 256 + Data[12])) + " 次");
  2258. }));
  2259. }
  2260. break;
  2261. }
  2262. default: break;
  2263. }
  2264. }
  2265. #endregion
  2266. #region 解析电机发送OBC的命令
  2267. else if (ID == 0x713)
  2268. {
  2269. switch (CmdTemp)
  2270. {
  2271. case 0x5408://电机用户参数
  2272. {
  2273. unchecked
  2274. {
  2275. this.Invoke((EventHandler)(delegate
  2276. {
  2277. richTextBox_OBC_ReadUserInfo.Clear();
  2278. //默认周长
  2279. richTextBox_OBC_ReadUserInfo.AppendText("默认周长:" + Convert.ToString((int)Data[0]) + " cm" + "\r\n");
  2280. //启动模式
  2281. richTextBox_OBC_ReadUserInfo.AppendText("启动模式:" + ((Data[1] == 0x01) ? "柔和" : (Data[1] == 0x02) ? "正常" : (Data[1] == 0x03) ? "强劲" : "无效") + "\r\n");
  2282. comboBox_OBC_StartMode.SelectedIndex = Data[1] - 1;
  2283. //限速
  2284. richTextBox_OBC_ReadUserInfo.AppendText("限速:" + Convert.ToString(Data[2]) + " km/h" + "\r\n");
  2285. //周长微调
  2286. numericUpDown_OBC_WheelAdj.Value = (int)(Data[3] > 128 ? (Data[3] - 256) : Data[3]);
  2287. richTextBox_OBC_ReadUserInfo.AppendText("周长微调:" + Convert.ToString(numericUpDown_OBC_WheelAdj.Value) + " cm" + "\r\n");
  2288. //助力方案
  2289. richTextBox_OBC_ReadUserInfo.AppendText("助力方案:" + Convert.ToString(Data[4]) + "\r\n");
  2290. comboBox_OBC_AssistFunc.SelectedIndex = Data[4] - 1;
  2291. //关机时间
  2292. richTextBox_OBC_ReadUserInfo.AppendText("关机时间:" + Convert.ToString(Data[5]) + " min" + "\r\n");
  2293. numericUpDown_OBC_OffTime.Value = (int)Data[5];
  2294. //限速微调
  2295. numericUpDown_OBC_SpeedLimitAdj.Value = (int)(Data[6] > 128 ? (Data[6] - 256) : Data[6]);
  2296. richTextBox_OBC_ReadUserInfo.AppendText("限速微调:" + Convert.ToString(numericUpDown_OBC_SpeedLimitAdj.Value) + " km/h" + "\r\n");
  2297. //定速巡航
  2298. comboBox_OBC_BikeCCS.SelectedIndex = (Data[7] == 0xAA) ? 1 : 2;
  2299. richTextBox_OBC_ReadUserInfo.AppendText("转把巡航:" + comboBox_OBC_BikeCCS.Text + "\r\n");
  2300. }));
  2301. }
  2302. break;
  2303. }
  2304. case 0x5303://电机应答反馈
  2305. {
  2306. unchecked
  2307. {
  2308. this.Invoke((EventHandler)(delegate
  2309. {
  2310. timer_500ms.Enabled = false;
  2311. MessageBoxTimeOut.Show("OK", "反馈指令", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  2312. timer_500ms.Enabled = true;
  2313. }));
  2314. }
  2315. break;
  2316. }
  2317. case 0x5620: //用户骑行参数
  2318. {
  2319. unchecked
  2320. {
  2321. this.Invoke((EventHandler)(delegate
  2322. {
  2323. richTextBox_UsrRidesParam.Clear();
  2324. for (int i = 0; i < myParams.UsrRideParam.Count; i++)
  2325. {
  2326. richTextBox_UsrRidesParam.AppendText(myParams.UsrRideParam[i] + "=" + Convert.ToString(Data[i]) + ", ");
  2327. }
  2328. richTextBox_UsrRidesParam.Text = richTextBox_UsrRidesParam.Text.Substring(0, richTextBox_UsrRidesParam.Text.Length - 2);
  2329. }));
  2330. }
  2331. break;
  2332. }
  2333. default: break;
  2334. }
  2335. }
  2336. #endregion
  2337. }
  2338. private void DataRevToString(ushort CmdTemp, byte[] Data)
  2339. {
  2340. CmdRevStrTemp = "";
  2341. CmdRevStrTemp += Convert.ToString(CmdTemp >> 8, 16).PadLeft(2, '0').ToUpper() + " ";
  2342. CmdRevStrTemp += Convert.ToString(CmdTemp & 0xFF, 16).PadLeft(2, '0').ToUpper() + " ";
  2343. ushort len = (ushort)(CmdTemp & 0x00FF);
  2344. for (int i = 0; i < len ; i++)
  2345. {
  2346. CmdRevStrTemp += Convert.ToString(Data[i], 16).PadLeft(2, '0').ToUpper() + " ";
  2347. }
  2348. }
  2349. #endregion
  2350. /// <summary>
  2351. /// 端口连接或断开
  2352. /// </summary>
  2353. private void PortConnect()
  2354. {
  2355. bool result = false;
  2356. if (连接ToolStripMenuItem.Text == "连接")
  2357. {
  2358. result = mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, 连接开机ToolStripMenuItem.Checked, 识别通讯盒ToolStripMenuItem.Checked);
  2359. if (result)
  2360. {
  2361. toolStripComboBox_ComNum.Enabled = false;
  2362. toolStripComboBox_Baudrate.Enabled = false;
  2363. 刷新ToolStripMenuItem.Enabled = false;
  2364. 连接ToolStripMenuItem.Text = "断开";
  2365. 连接ToolStripMenuItem.Checked = true;
  2366. label_COM_Sta.Text = toolStripComboBox_ComNum.Text + "已连接," + toolStripComboBox_Baudrate.Text;
  2367. label_PortStatus.BackColor = Color.Green;
  2368. }
  2369. }
  2370. else if (连接ToolStripMenuItem.Text == "断开")
  2371. {
  2372. checkBox_OBC_StartSetGearSt.Checked = false;
  2373. checkBox_OBC_StartReadBMS.Checked = false;
  2374. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2375. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  2376. toolStripComboBox_ComNum.Enabled = true;
  2377. toolStripComboBox_Baudrate.Enabled = true;
  2378. 刷新ToolStripMenuItem.Enabled = true;
  2379. 连接ToolStripMenuItem.Text = "连接";
  2380. 连接ToolStripMenuItem.Checked = false;
  2381. label_COM_Sta.Text = "连接状态:未连接";
  2382. label_PortStatus.BackColor = Color.Red;
  2383. }
  2384. }
  2385. /// <summary>
  2386. /// 端口连接事件
  2387. /// </summary>
  2388. /// <param name="sender"></param>
  2389. /// <param name="e"></param>
  2390. private void 连接ToolStripMenuItem_Click(object sender, System.EventArgs e)
  2391. {
  2392. PortConnect();
  2393. }
  2394. /// <summary>
  2395. /// 端口号刷新事件
  2396. /// </summary>
  2397. /// <param name="sender"></param>
  2398. /// <param name="e"></param>
  2399. private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
  2400. {
  2401. toolStripComboBox_ComNum.Items.Clear();
  2402. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  2403. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
  2404. }
  2405. /// <summary>
  2406. /// 存储标志修改事件
  2407. /// </summary>
  2408. /// <param name="sender"></param>
  2409. /// <param name="e"></param>
  2410. private void 写入存储ToolStripMenuItem_Click(object sender, EventArgs e)
  2411. {
  2412. if (写入存储ToolStripMenuItem.Checked)
  2413. {
  2414. EnterForm1.ShowDialog();
  2415. try
  2416. {
  2417. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  2418. {
  2419. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  2420. {
  2421. 写入存储ToolStripMenuItem.Checked = false;
  2422. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  2423. }
  2424. else
  2425. {
  2426. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2427. }
  2428. }
  2429. else
  2430. {
  2431. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2432. }
  2433. }
  2434. catch (Exception)
  2435. {
  2436. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2437. }
  2438. }
  2439. else
  2440. {
  2441. 写入存储ToolStripMenuItem.Checked = true;
  2442. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  2443. }
  2444. }
  2445. /// <summary>
  2446. /// 1s定时器
  2447. /// </summary>
  2448. /// <param name="sender"></param>
  2449. /// <param name="e"></param>
  2450. private void timer_1s_Tick(object sender, EventArgs e)
  2451. {
  2452. //时间更新
  2453. label_SystemTime.Text = "系统时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2454. //MC_Runinfo超时清除
  2455. if (MC_RunInfo_Refresh == false)
  2456. {
  2457. MC_RunInfo_Refresh_Cnt++;
  2458. if (MC_RunInfo_Refresh_Cnt > 10)//5s
  2459. {
  2460. MC_RunInfo_Clear();
  2461. MC_RunInfo_Refresh_Cnt = 0;
  2462. }
  2463. }
  2464. else
  2465. {
  2466. MC_RunInfo_Refresh_Cnt = 0;
  2467. }
  2468. MC_RunInfo_Refresh = false;
  2469. //MC_Debuginfo超时清除
  2470. if (MC_DebugInfo_Refresh == false)
  2471. {
  2472. MC_DebugInfo_Refresh_Cnt++;
  2473. if (MC_DebugInfo_Refresh_Cnt > 10)//5s
  2474. {
  2475. MC_DebugInfo_Clear();
  2476. MC_DebugInfo_Refresh_Cnt = 0;
  2477. }
  2478. }
  2479. else
  2480. {
  2481. MC_DebugInfo_Refresh_Cnt = 0;
  2482. }
  2483. MC_DebugInfo_Refresh = false;
  2484. //BMS_RunInfo超时清除
  2485. if (BMS_RunInfo_Refresh == false)
  2486. {
  2487. BMS_RunInfo_Refresh_Cnt++;
  2488. if (BMS_RunInfo_Refresh_Cnt > 10)//5s
  2489. {
  2490. richTextBox_OBC_BMS_RunInfo.Clear();
  2491. BMS_RunInfo_Refresh_Cnt = 0;
  2492. }
  2493. }
  2494. else
  2495. {
  2496. BMS_RunInfo_Refresh_Cnt = 0;
  2497. }
  2498. BMS_RunInfo_Refresh = false;
  2499. //故障码超时清除
  2500. if (MC_ErrorCode_Refresh == false)
  2501. {
  2502. MC_ErrorCode_Refresh_Cnt++;
  2503. if (MC_ErrorCode_Refresh_Cnt > 10)//5s
  2504. {
  2505. textBox_ErrorCode.Text = "---";
  2506. MC_ErrorCode_Refresh_Cnt = 0;
  2507. }
  2508. }
  2509. else
  2510. {
  2511. MC_ErrorCode_Refresh_Cnt = 0;
  2512. }
  2513. MC_ErrorCode_Refresh = false;
  2514. //CDL连接超时
  2515. if (识别通讯盒ToolStripMenuItem.Checked)
  2516. {
  2517. if (mySerialProcess.CDL_Online_Flag == false)
  2518. {
  2519. mySerialProcess.CDL_OnlineCheck_Cnt++;
  2520. if (mySerialProcess.CDL_OnlineCheck_Cnt > 1)//1s
  2521. {
  2522. timer_500ms.Enabled = false;
  2523. MessageBox.Show("连接失败!", "提示");
  2524. timer_500ms.Enabled = true;
  2525. //关闭串口
  2526. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  2527. toolStripComboBox_ComNum.Enabled = true;
  2528. toolStripComboBox_Baudrate.Enabled = true;
  2529. 刷新ToolStripMenuItem.Enabled = true;
  2530. 连接ToolStripMenuItem.Text = "连接";
  2531. 连接ToolStripMenuItem.Checked = false;
  2532. label_COM_Sta.Text = "连接状态:未连接";
  2533. label_PortStatus.BackColor = Color.Red;
  2534. }
  2535. }
  2536. }
  2537. //OBC定时发送设置档位
  2538. if (checkBox_OBC_StartSetGearSt.Checked == true)
  2539. {
  2540. var CtrlCode = new byte[2];
  2541. if (comboBox_OBC_SetGearST.SelectedIndex == 5)//档位
  2542. CtrlCode[0] = 0x33;
  2543. else if (comboBox_OBC_SetGearST.SelectedIndex == 6)//档位
  2544. CtrlCode[0] = 0x22;
  2545. else
  2546. CtrlCode[0] = (byte)comboBox_OBC_SetGearST.SelectedIndex;
  2547. if (comboBox_OBC_LightSw.SelectedIndex == 0)//车灯
  2548. CtrlCode[1] = 0xF1;
  2549. else
  2550. CtrlCode[1] = 0xF0;
  2551. if (!mySerialProcess.SendCmdWithoutNotice((ushort)0x731, (byte)0x0C, (ushort)0x3002, CtrlCode))
  2552. {
  2553. checkBox_OBC_StartSetGearSt.Checked = false;
  2554. }
  2555. }
  2556. //OBC定时发送查询电池
  2557. if (checkBox_OBC_StartReadBMS.Checked == true)
  2558. {
  2559. if (!mySerialProcess.SendCmd((ushort)0x732, (byte)0x11, (ushort)0x5000, null))
  2560. {
  2561. checkBox_OBC_StartReadBMS.Checked = false;
  2562. }
  2563. }
  2564. //定时读取存储器
  2565. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  2566. {
  2567. var Address = new byte[4];
  2568. UInt32 Address_Begin;
  2569. UInt32 Addres_End;
  2570. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  2571. richTextBox_RamFlasgData.Clear();
  2572. do
  2573. {
  2574. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  2575. {
  2576. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2577. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2578. continue;
  2579. }
  2580. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  2581. {
  2582. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2583. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2584. continue;
  2585. }
  2586. else
  2587. {
  2588. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  2589. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2590. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  2591. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2592. if (Addres_End < Address_Begin)
  2593. {
  2594. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2595. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2596. continue;
  2597. }
  2598. else
  2599. {
  2600. var SendByte = new byte[8];
  2601. SendByte[0] = (byte)(Address_Begin >> 24);
  2602. SendByte[1] = (byte)(Address_Begin >> 16);
  2603. SendByte[2] = (byte)(Address_Begin >> 8);
  2604. SendByte[3] = (byte)(Address_Begin);
  2605. SendByte[4] = (byte)(Addres_End >> 24);
  2606. SendByte[5] = (byte)(Addres_End >> 16);
  2607. SendByte[6] = (byte)(Addres_End >> 8);
  2608. SendByte[7] = (byte)(Addres_End);
  2609. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte))
  2610. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2611. }
  2612. }
  2613. } while (false);
  2614. }
  2615. //写入参数等待计时
  2616. ACK_WaitCnt++;
  2617. }
  2618. /// <summary>
  2619. /// 运行信息清除
  2620. /// </summary>
  2621. private void MC_RunInfo_Clear()
  2622. {
  2623. foreach (Control c in tabPage_RunInfo.Controls)
  2624. {
  2625. if ((c is TextBox))
  2626. {
  2627. if (c.Name != textBox_ErrorCode.ToString())
  2628. c.Text = "---";
  2629. }
  2630. }
  2631. }
  2632. /// <summary>
  2633. /// 调试信息清除
  2634. /// </summary>
  2635. private void MC_DebugInfo_Clear()
  2636. {
  2637. foreach (Control c in tabPage_DebugInfo.Controls)
  2638. {
  2639. if ((c is TextBox))
  2640. {
  2641. if (c.Name != textBox_ErrorCode.ToString())
  2642. c.Text = "---";
  2643. }
  2644. }
  2645. }
  2646. /// <summary>
  2647. /// 读取马达参数
  2648. /// </summary>
  2649. /// <param name="sender"></param>
  2650. /// <param name="e"></param>
  2651. private void button_Read_MotorParam_Click(object sender, EventArgs e)
  2652. {
  2653. richTextBox_MotorParam.Clear();
  2654. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null);
  2655. }
  2656. /// <summary>
  2657. /// 写入马达参数
  2658. /// </summary>
  2659. /// <param name="sender"></param>
  2660. /// <param name="e"></param>
  2661. private void button_Write_Click(object sender, EventArgs e)
  2662. {
  2663. var ConfigParam = new byte[40];
  2664. for (int i = 0; i < 40; i++)
  2665. ConfigParam[i] = 0;
  2666. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2667. short wDataTemp = 0;
  2668. ushort DataTemp = 0;
  2669. string[] strDataTemp = richTextBox_MotorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2670. try
  2671. {
  2672. for (int i = 0; i < strDataTemp.Length; i++)
  2673. {
  2674. if (i == 6)
  2675. {
  2676. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  2677. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  2678. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  2679. }
  2680. else
  2681. {
  2682. DataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2683. ConfigParam[2 * i + 2] = (byte)DataTemp;
  2684. ConfigParam[2 * i + 3] = (byte)(DataTemp >> 8);
  2685. }
  2686. }
  2687. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B28, ConfigParam);
  2688. }
  2689. catch (Exception)
  2690. {
  2691. timer_500ms.Enabled = false;
  2692. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2693. timer_500ms.Enabled = true;
  2694. }
  2695. }
  2696. /// <summary>
  2697. /// 读取整车信息
  2698. /// </summary>
  2699. /// <param name="sender"></param>
  2700. /// <param name="e"></param>
  2701. private void button_ReadBikeParam_Click(object sender, EventArgs e)
  2702. {
  2703. richTextBox_BikeParam.Clear();
  2704. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null);
  2705. }
  2706. /// <summary>
  2707. /// 写入整车信息
  2708. /// </summary>
  2709. /// <param name="sender"></param>
  2710. /// <param name="e"></param>
  2711. private void button_WriteBikeParam_Click(object sender, EventArgs e)
  2712. {
  2713. var ConfigParam = new byte[28];
  2714. for (int i = 0; i < 28; i++)
  2715. ConfigParam[i] = 0;
  2716. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2717. string[] strDataTemp = richTextBox_BikeParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2718. try
  2719. {
  2720. for (int i = 0; i < strDataTemp.Length; i++)
  2721. {
  2722. short wDataTemp = 0;
  2723. //前后灯参数修改
  2724. if (i == 8)
  2725. {
  2726. wDataTemp |= (short)((comboBox_TailLightMode.SelectedIndex + 1) << 12); //Bit15~Bit12:尾灯模式
  2727. wDataTemp |= (short)((comboBox_TailLightVol.SelectedIndex == 0 ? 6 : 12) << 8); //Bit11~Bit8:尾灯电压
  2728. wDataTemp |= (short)(comboBox_FrontLightVol.SelectedIndex == 0 ? 6 : 12); //Bit7~Bit0:前灯电压
  2729. }
  2730. //开关机参数
  2731. else if (i == 11)
  2732. {
  2733. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOnDelay.Text) << 12);
  2734. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOffDelay.Text) << 8);
  2735. wDataTemp |= (short)(Convert.ToInt16(textBox_AutoPowerOff.Text));
  2736. }
  2737. else
  2738. {
  2739. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  2740. }
  2741. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  2742. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  2743. }
  2744. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D1C, ConfigParam);
  2745. }
  2746. catch (Exception)
  2747. {
  2748. timer_500ms.Enabled = false;
  2749. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2750. timer_500ms.Enabled = true;
  2751. }
  2752. }
  2753. /// <summary>
  2754. /// 读取控制器参数
  2755. /// </summary>
  2756. /// <param name="sender"></param>
  2757. /// <param name="e"></param>
  2758. private void button_ReadControlParam_Click(object sender, EventArgs e)
  2759. {
  2760. richTextBox_ControlParam.Clear();
  2761. comboBox_Bike_CCS.SelectedIndex = 0;
  2762. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
  2763. }
  2764. /// <summary>
  2765. /// 写入控制器参数
  2766. /// </summary>
  2767. /// <param name="sender"></param>
  2768. /// <param name="e"></param>
  2769. private void button_WriteControlParam_Click(object sender, EventArgs e)
  2770. {
  2771. var ConfigParam = new byte[34];
  2772. for (int i = 0; i < 34; i++)
  2773. ConfigParam[i] = 0;
  2774. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2775. ushort uwDataTemp = 0;
  2776. string[] strDataTemp = richTextBox_ControlParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2777. try
  2778. {
  2779. for (int i = 0; i < strDataTemp.Length; i++)
  2780. {
  2781. if (i == 13)
  2782. {
  2783. uwDataTemp = (comboBox_Bike_CCS.SelectedIndex == 1) ? (ushort)0x00AA : (ushort)0x0000;
  2784. }
  2785. else
  2786. {
  2787. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2788. }
  2789. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2790. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2791. }
  2792. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3F22, ConfigParam);
  2793. }
  2794. catch (Exception)
  2795. {
  2796. timer_500ms.Enabled = false;
  2797. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2798. timer_500ms.Enabled = true;
  2799. }
  2800. }
  2801. /// <summary>
  2802. /// 读取助力参数
  2803. /// </summary>
  2804. /// <param name="sender"></param>
  2805. /// <param name="e"></param>
  2806. private void button_ReadAssistParam_Click(object sender, EventArgs e)
  2807. {
  2808. var ConfigParam = new byte[4];
  2809. int AssistNum = 0;
  2810. try
  2811. {
  2812. AssistNum = Convert.ToInt32(comboBox_AssistTorque.Text);
  2813. ConfigParam[0] = (byte)(AssistNum & 0xFF);
  2814. ConfigParam[1] = (byte)(AssistNum >> 8);
  2815. AssistNum = Convert.ToInt32(comboBox_AssistCadence.Text);
  2816. ConfigParam[2] = (byte)(AssistNum & 0xFF);
  2817. ConfigParam[3] = (byte)(AssistNum >> 8);
  2818. richTextBox_AssistParam.Clear();
  2819. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam);
  2820. }
  2821. catch (Exception)
  2822. {
  2823. timer_500ms.Enabled = false;
  2824. MessageBox.Show("请选择助力参数编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2825. timer_500ms.Enabled = true;
  2826. }
  2827. }
  2828. /// <summary>
  2829. /// 写入助力参数
  2830. /// </summary>
  2831. /// <param name="sender"></param>
  2832. /// <param name="e"></param>
  2833. private void button_WriteAssistParam_Click(object sender, EventArgs e)
  2834. {
  2835. var ConfigParam = new byte[80];
  2836. for (int i = 0; i < 80; i++)
  2837. ConfigParam[i] = 0;
  2838. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2839. long lDataTemp = 0;
  2840. string[] strDataTemp = richTextBox_AssistParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2841. int index_1 = 0, index_2 = 0;
  2842. try
  2843. {
  2844. for (int i = 0; i < strDataTemp.Length; i++)
  2845. {
  2846. if (strDataTemp[i].Split('=')[0] == "转矩曲线.a")
  2847. {
  2848. index_1 = i;
  2849. break;
  2850. }
  2851. }
  2852. for (int i = 0; i < strDataTemp.Length; i++)
  2853. {
  2854. if (strDataTemp[i].Split('=')[0] == "踏频曲线.d")
  2855. {
  2856. index_2 = i;
  2857. break;
  2858. }
  2859. }
  2860. for (int i = 0; i < strDataTemp.Length; i++)
  2861. {
  2862. lDataTemp = Convert.ToInt32(strDataTemp[i].Split('=')[1]);
  2863. if (i < index_1)
  2864. {
  2865. ConfigParam[2 * i + 4] = (byte)lDataTemp;
  2866. ConfigParam[2 * i + 5] = (byte)(lDataTemp >> 8);
  2867. }
  2868. else if (i <= index_2)
  2869. {
  2870. ConfigParam[4 * i - 4] = (byte)lDataTemp;
  2871. ConfigParam[4 * i - 3] = (byte)(lDataTemp >> 8);
  2872. ConfigParam[4 * i - 2] = (byte)(lDataTemp >> 16);
  2873. ConfigParam[4 * i - 1] = (byte)(lDataTemp >> 24);
  2874. }
  2875. else
  2876. {
  2877. ConfigParam[2 * i + 20] = (byte)lDataTemp;
  2878. ConfigParam[2 * i + 21] = (byte)(lDataTemp >> 8);
  2879. }
  2880. }
  2881. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4450, ConfigParam);
  2882. }
  2883. catch (Exception)
  2884. {
  2885. timer_500ms.Enabled = false;
  2886. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2887. timer_500ms.Enabled = true;
  2888. }
  2889. }
  2890. /// <summary>
  2891. /// 读取调试参数
  2892. /// </summary>
  2893. /// <param name="sender"></param>
  2894. /// <param name="e"></param>
  2895. private void button_ReadDebugParam_Click(object sender, EventArgs e)
  2896. {
  2897. richTextBox_DebugParam.Clear();
  2898. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  2899. }
  2900. /// <summary>
  2901. /// 写入调试参数
  2902. /// </summary>
  2903. /// <param name="sender"></param>
  2904. /// <param name="e"></param>
  2905. private void button_WriteDebugParam_Click(object sender, EventArgs e)
  2906. {
  2907. var ConfigParam = new byte[60];
  2908. for (int i = 0; i < 60; i++)
  2909. ConfigParam[i] = 0;
  2910. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2911. ushort uwDataTemp = 0;
  2912. string[] strDataTemp = richTextBox_DebugParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2913. try
  2914. {
  2915. for (int i = 0; i < strDataTemp.Length; i++)
  2916. {
  2917. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2918. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2919. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2920. }
  2921. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam);
  2922. }
  2923. catch (Exception)
  2924. {
  2925. timer_500ms.Enabled = false;
  2926. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2927. timer_500ms.Enabled = true;
  2928. }
  2929. }
  2930. /// <summary>
  2931. /// 读取历史
  2932. /// </summary>
  2933. /// <param name="sender"></param>
  2934. /// <param name="e"></param>
  2935. private void button_ReadRecord_Click(object sender, EventArgs e)
  2936. {
  2937. richTextBox_Record.Clear();
  2938. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null);
  2939. }
  2940. /// <summary>
  2941. /// 读取传感器参数
  2942. /// </summary>
  2943. /// <param name="sender"></param>
  2944. /// <param name="e"></param>
  2945. private void button_ReadSensorParam_Click(object sender, EventArgs e)
  2946. {
  2947. richTextBox_SensorParam.Clear();
  2948. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  2949. }
  2950. /// <summary>
  2951. /// 写入力矩传感器标定值
  2952. /// </summary>
  2953. /// <param name="sender"></param>
  2954. /// <param name="e"></param>
  2955. private void button_Write_Cal_Click(object sender, EventArgs e)
  2956. {
  2957. var ConfigParam = new byte[4];
  2958. for (int i = 0; i < 4; i++)
  2959. ConfigParam[i] = 0;
  2960. ushort uwDataTemp = 0;
  2961. try
  2962. {
  2963. uwDataTemp = Convert.ToUInt16(comboBox_TorqueSet.Text);//负载序号
  2964. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  2965. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  2966. uwDataTemp = (ushort)(decimal.Parse(textBox_Load.Text) * 10); ;//负载值0.1Nm
  2967. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  2968. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  2969. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  2970. }
  2971. catch (Exception)
  2972. {
  2973. timer_500ms.Enabled = false;
  2974. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2975. timer_500ms.Enabled = true;
  2976. }
  2977. }
  2978. /// <summary>
  2979. /// 写入传感器参数
  2980. /// </summary>
  2981. /// <param name="sender"></param>
  2982. /// <param name="e"></param>
  2983. private void button_WriteSensorParam_Click(object sender, EventArgs e)
  2984. {
  2985. var ConfigParam = new byte[14];
  2986. for (int i = 0; i < 14; i++)
  2987. ConfigParam[i] = 0;
  2988. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2989. ushort uwDataTemp = 0;
  2990. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  2991. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2992. int index = 0;
  2993. try
  2994. {
  2995. for (int i = 0; i < strDataTemp.Length; i++)
  2996. {
  2997. if (strDataTemp[i].Split('=')[0] == "力矩传感器踏频脉冲数")
  2998. {
  2999. index = i;
  3000. break;
  3001. }
  3002. }
  3003. for (int i = 0; i < (strDataTemp.Length - index); i++)
  3004. {
  3005. uwDataTemp = Convert.ToUInt16(strDataTemp[i + index].Split('=')[1]);
  3006. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3007. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3008. }
  3009. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x420E, ConfigParam);
  3010. }
  3011. catch (Exception)
  3012. {
  3013. timer_500ms.Enabled = false;
  3014. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3015. timer_500ms.Enabled = true;
  3016. }
  3017. }
  3018. /// <summary>
  3019. /// 写入型号
  3020. /// </summary>
  3021. /// <param name="sender"></param>
  3022. /// <param name="e"></param>
  3023. private void button_WriteModel_Click(object sender, EventArgs e)
  3024. {
  3025. string Mode = textBox_Model.Text;
  3026. var ModeArray = new byte[16];
  3027. for (ushort i = 0; i < Mode.Length; i++)
  3028. {
  3029. ModeArray[i] = (byte)Mode[i];
  3030. }
  3031. if (Mode.Length < 16)
  3032. {
  3033. ModeArray[Mode.Length] = (byte)'.';
  3034. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  3035. {
  3036. ModeArray[Mode.Length + 1 + i] = 0x20;
  3037. }
  3038. }
  3039. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  3040. }
  3041. /// <summary>
  3042. /// 写入SN
  3043. /// </summary>
  3044. /// <param name="sender"></param>
  3045. /// <param name="e"></param>
  3046. private void button_WriteSN_Click(object sender, EventArgs e)
  3047. {
  3048. string SN = textBox_SN.Text;
  3049. var SNArray = new byte[16];
  3050. for (ushort i = 0; i < SN.Length; i++)
  3051. {
  3052. SNArray[i] = (byte)SN[i];
  3053. }
  3054. if (SN.Length < 16)
  3055. {
  3056. SNArray[SN.Length] = (byte)'.';
  3057. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  3058. {
  3059. SNArray[SN.Length + 1 + i] = 0x20;
  3060. }
  3061. }
  3062. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  3063. }
  3064. /// <summary>
  3065. /// 查询版本信息
  3066. /// </summary>
  3067. /// <param name="sender"></param>
  3068. /// <param name="e"></param>
  3069. private void button_ReadVersion_Click(object sender, EventArgs e)
  3070. {
  3071. textBox_Model.Text = "---";
  3072. textBox_SN.Text = "---";
  3073. textBox_HW.Text = "---";
  3074. textBox_FW.Text = "---";
  3075. textBox_SP.Text = "---";
  3076. textBox_OBC_ReadModel.Text = "---";
  3077. textBox_OBC_ReadSN.Text = "---";
  3078. textBox_OBC_ReadHW.Text = "---";
  3079. textBox_OBC_ReadFW.Text = "---";
  3080. textBox_OBC_ReadSP.Text = "---";
  3081. textBox_FacModeName.Text = "---";
  3082. textBox_FacModeNum.Text = "---";
  3083. textBox_FacModeHW.Text = "---";
  3084. textBox_FacModeFW.Text = "---";
  3085. textBox_FacModeSP.Text = "---";
  3086. Class_Motor_Ver.Mode = "---";
  3087. Class_Motor_Ver.SN = "---";
  3088. Class_Motor_Ver.HW = "---";
  3089. Class_Motor_Ver.FW = "---";
  3090. Class_Motor_Ver.Special = "---";
  3091. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  3092. }
  3093. /// <summary>
  3094. /// 查询自定义1
  3095. /// </summary>
  3096. /// <param name="sender"></param>
  3097. /// <param name="e"></param>
  3098. private void button_ReadUser1_Click(object sender, EventArgs e)
  3099. {
  3100. textBox_User1.Text = "---";
  3101. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null);
  3102. }
  3103. /// <summary>
  3104. /// 查询自定义2
  3105. /// </summary>
  3106. /// <param name="sender"></param>
  3107. /// <param name="e"></param>
  3108. private void button_ReadUser2_Click(object sender, EventArgs e)
  3109. {
  3110. textBox_User2.Text = "---";
  3111. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null);
  3112. }
  3113. /// <summary>
  3114. /// 查询自定义3
  3115. /// </summary>
  3116. /// <param name="sender"></param>
  3117. /// <param name="e"></param>
  3118. private void button_ReadUser3_Click(object sender, EventArgs e)
  3119. {
  3120. textBox_User3.Text = "---";
  3121. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null);
  3122. }
  3123. /// <summary>
  3124. /// 写入自定义字符串1
  3125. /// </summary>
  3126. /// <param name="sender"></param>
  3127. /// <param name="e"></param>
  3128. private void button_WriteUser1_Click(object sender, EventArgs e)
  3129. {
  3130. string User = textBox_User1.Text;
  3131. var UserArray = new byte[16];
  3132. for (ushort i = 0; i < User.Length; i++)
  3133. {
  3134. UserArray[i] = (byte)User[i];
  3135. }
  3136. if (User.Length < 16)
  3137. {
  3138. UserArray[User.Length] = (byte)'.';
  3139. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3140. {
  3141. UserArray[User.Length + 1 + i] = 0x20;
  3142. }
  3143. }
  3144. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1410, UserArray);
  3145. }
  3146. /// <summary>
  3147. /// 写入自定义字符串2
  3148. /// </summary>
  3149. /// <param name="sender"></param>
  3150. /// <param name="e"></param>
  3151. private void button_WriteUser2_Click(object sender, EventArgs e)
  3152. {
  3153. string User = textBox_User2.Text;
  3154. var UserArray = new byte[16];
  3155. for (ushort i = 0; i < User.Length; i++)
  3156. {
  3157. UserArray[i] = (byte)User[i];
  3158. }
  3159. if (User.Length < 16)
  3160. {
  3161. UserArray[User.Length] = (byte)'.';
  3162. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3163. {
  3164. UserArray[User.Length + 1 + i] = 0x20;
  3165. }
  3166. }
  3167. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1610, UserArray);
  3168. }
  3169. /// <summary>
  3170. /// 写入自定义字符串3
  3171. /// </summary>
  3172. /// <param name="sender"></param>
  3173. /// <param name="e"></param>
  3174. private void button_WriteUser3_Click(object sender, EventArgs e)
  3175. {
  3176. string User = textBox_User3.Text;
  3177. var UserArray = new byte[16];
  3178. for (ushort i = 0; i < User.Length; i++)
  3179. {
  3180. UserArray[i] = (byte)User[i];
  3181. }
  3182. if (User.Length < 16)
  3183. {
  3184. UserArray[User.Length] = (byte)'.';
  3185. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3186. {
  3187. UserArray[User.Length + 1 + i] = 0x20;
  3188. }
  3189. }
  3190. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1810, UserArray);
  3191. }
  3192. /// <summary>
  3193. /// 查询生产信息
  3194. /// </summary>
  3195. /// <param name="sender"></param>
  3196. /// <param name="e"></param>
  3197. private void button_ReadMAC_Click(object sender, EventArgs e)
  3198. {
  3199. textBox_MAC.Text = "---";
  3200. textBox_MACAdd.Text = "---";
  3201. textBox_MACDate.Text = "---";
  3202. textBox_PP.Text = "---";
  3203. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null);
  3204. }
  3205. /// <summary>
  3206. /// 写入生产信息
  3207. /// </summary>
  3208. /// <param name="sender"></param>
  3209. /// <param name="e"></param>
  3210. private void button_WriteMac_Click(object sender, EventArgs e)
  3211. {
  3212. var MACArray = new byte[32];
  3213. //填入生产商
  3214. for (ushort i = 0; i < textBox_MAC.Text.Length; i++)
  3215. {
  3216. MACArray[i] = (byte)textBox_MAC.Text[i];
  3217. }
  3218. if (textBox_MAC.Text.Length < 8)
  3219. {
  3220. MACArray[textBox_MAC.Text.Length] = (byte)'.';
  3221. for (ushort i = 0; i < 8 - textBox_MAC.Text.Length - 1; i++)
  3222. {
  3223. MACArray[textBox_MAC.Text.Length + 1 + i] = 0x20;
  3224. }
  3225. }
  3226. //填入生产地
  3227. for (ushort i = 0; i < textBox_MACAdd.Text.Length; i++)
  3228. {
  3229. MACArray[8 + i] = (byte)textBox_MACAdd.Text[i];
  3230. }
  3231. if (textBox_MACAdd.Text.Length < 8)
  3232. {
  3233. MACArray[textBox_MACAdd.Text.Length + 8] = (byte)'.';
  3234. for (ushort i = 0; i < 8 - textBox_MACAdd.Text.Length - 1; i++)
  3235. {
  3236. MACArray[textBox_MACAdd.Text.Length + 1 + i + 8] = 0x20;
  3237. }
  3238. }
  3239. //填入生产日期
  3240. for (ushort i = 0; i < textBox_MACDate.Text.Length; i++)
  3241. {
  3242. MACArray[16 + i] = (byte)textBox_MACDate.Text[i];
  3243. }
  3244. if (textBox_MACDate.Text.Length < 8)
  3245. {
  3246. MACArray[textBox_MACDate.Text.Length + 16] = (byte)'.';
  3247. for (ushort i = 0; i < 8 - textBox_MACDate.Text.Length - 1; i++)
  3248. {
  3249. MACArray[textBox_MACDate.Text.Length + 1 + i + 16] = 0x20;
  3250. }
  3251. }
  3252. //填入品牌
  3253. for (ushort i = 0; i < textBox_PP.Text.Length; i++)
  3254. {
  3255. MACArray[24 + i] = (byte)textBox_PP.Text[i];
  3256. }
  3257. if (textBox_PP.Text.Length < 8)
  3258. {
  3259. MACArray[textBox_PP.Text.Length + 24] = (byte)'.';
  3260. for (ushort i = 0; i < 8 - textBox_PP.Text.Length - 1; i++)
  3261. {
  3262. MACArray[textBox_PP.Text.Length + 1 + i + 24] = 0x20;
  3263. }
  3264. }
  3265. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  3266. }
  3267. /// <summary>
  3268. /// 查询密钥
  3269. /// </summary>
  3270. /// <param name="sender"></param>
  3271. /// <param name="e"></param>
  3272. private void button_ReadKey_Click(object sender, EventArgs e)
  3273. {
  3274. textBox_Key.Text = "---";
  3275. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null);
  3276. }
  3277. /// <summary>
  3278. /// 写入校验密钥
  3279. /// </summary>
  3280. /// <param name="sender"></param>
  3281. /// <param name="e"></param>
  3282. private void button_WriteKey_Click(object sender, EventArgs e)
  3283. {
  3284. string Key = textBox_Key.Text;
  3285. var KeyArray = new byte[8];
  3286. if (Key.Length != 8)
  3287. {
  3288. timer_500ms.Enabled = false;
  3289. MessageBox.Show("请检查字符长度是否为8", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3290. timer_500ms.Enabled = true;
  3291. return;
  3292. }
  3293. for (ushort i = 0; i < Key.Length; i++)
  3294. {
  3295. KeyArray[i] = (byte)Key[i];
  3296. }
  3297. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1108, KeyArray);
  3298. }
  3299. /// <summary>
  3300. /// 查询在线检测结果
  3301. /// </summary>
  3302. /// <param name="sender"></param>
  3303. /// <param name="e"></param>
  3304. private void button_ReadOnLine_Click(object sender, EventArgs e)
  3305. {
  3306. textBox_Online.Text = "---";
  3307. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2100, null);
  3308. }
  3309. /// <summary>
  3310. /// 系统清除
  3311. /// </summary>
  3312. /// <param name="sender"></param>
  3313. /// <param name="e"></param>
  3314. private void button_SystemClear_Click(object sender, EventArgs e)
  3315. {
  3316. var Code = new byte[5];
  3317. Code[0] = (byte)'C';
  3318. Code[1] = (byte)'L';
  3319. Code[2] = (byte)'E';
  3320. Code[3] = (byte)'A';
  3321. Code[4] = (byte)'R';
  3322. timer_500ms.Enabled = false;
  3323. if (MessageBox.Show("系统清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3324. {
  3325. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3326. {
  3327. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3328. {
  3329. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  3330. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3331. }
  3332. }
  3333. }
  3334. timer_500ms.Enabled = true;
  3335. }
  3336. /// <summary>
  3337. /// 参数还原
  3338. /// </summary>
  3339. /// <param name="sender"></param>
  3340. /// <param name="e"></param>
  3341. private void button_Recovery_Click(object sender, EventArgs e)
  3342. {
  3343. var Code = new byte[8];
  3344. Code[0] = (byte)'R';
  3345. Code[1] = (byte)'E';
  3346. Code[2] = (byte)'C';
  3347. Code[3] = (byte)'O';
  3348. Code[4] = (byte)'V';
  3349. Code[5] = (byte)'E';
  3350. Code[6] = (byte)'R';
  3351. Code[7] = (byte)'Y';
  3352. timer_500ms.Enabled = false;
  3353. if (MessageBox.Show("参数还原后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3354. {
  3355. if (MessageBox.Show("请再次确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3356. {
  3357. if (MessageBox.Show("请最后确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3358. {
  3359. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2708, Code);
  3360. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3361. }
  3362. }
  3363. }
  3364. timer_500ms.Enabled = true;
  3365. }
  3366. /// <summary>
  3367. /// 系统复位
  3368. /// </summary>
  3369. /// <param name="sender"></param>
  3370. /// <param name="e"></param>
  3371. private void button_Reset_Click(object sender, EventArgs e)
  3372. {
  3373. var Code_Off = new byte[5];
  3374. var Code_Reset = new byte[5];
  3375. Code_Off[0] = (byte)'O';
  3376. Code_Off[1] = (byte)'F';
  3377. Code_Off[2] = (byte)'F';
  3378. Code_Off[3] = (byte)'.';
  3379. Code_Off[4] = (byte)'.';
  3380. Code_Reset[0] = (byte)'R';
  3381. Code_Reset[1] = (byte)'E';
  3382. Code_Reset[2] = (byte)'S';
  3383. Code_Reset[3] = (byte)'E';
  3384. Code_Reset[4] = (byte)'T';
  3385. timer_500ms.Enabled = false;
  3386. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3387. {
  3388. timer_500ms.Enabled = true;
  3389. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  3390. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  3391. PowerOffAckStatus = false;
  3392. Delay_ms(250);
  3393. int TryCnt = 3;
  3394. while ((TryCnt--) >= 0)
  3395. {
  3396. if (!PowerOffAckStatus)
  3397. {
  3398. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  3399. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  3400. PowerOffAckStatus = false;
  3401. Delay_ms(250);
  3402. }
  3403. else break;
  3404. }
  3405. if (PowerOffAckStatus)
  3406. {
  3407. timer_500ms.Enabled = false;
  3408. MessageBoxTimeOut.Show("已关机!", "提示", 3000, MessageBoxButtons.OK, MessageBoxIcon.None);
  3409. timer_500ms.Enabled = true;
  3410. }
  3411. else
  3412. {
  3413. timer_500ms.Enabled = false;
  3414. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3415. timer_500ms.Enabled = true;
  3416. }
  3417. }
  3418. timer_500ms.Enabled = true;
  3419. }
  3420. /// <summary>
  3421. /// 记录清除
  3422. /// </summary>
  3423. /// <param name="sender"></param>
  3424. /// <param name="e"></param>
  3425. private void button_ClearLog_Click(object sender, EventArgs e)
  3426. {
  3427. var Code = new byte[9];
  3428. Code[0] = (byte)'L';
  3429. Code[1] = (byte)'O';
  3430. Code[2] = (byte)'G';
  3431. Code[3] = (byte)' ';
  3432. Code[4] = (byte)'C';
  3433. Code[5] = (byte)'L';
  3434. Code[6] = (byte)'E';
  3435. Code[7] = (byte)'A';
  3436. Code[8] = (byte)'R';
  3437. timer_500ms.Enabled = false;
  3438. if (MessageBox.Show("历史记录信息清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3439. {
  3440. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3441. {
  3442. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3443. {
  3444. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3909, Code);
  3445. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3446. }
  3447. }
  3448. }
  3449. timer_500ms.Enabled = true;
  3450. }
  3451. /// <summary>
  3452. /// 打开系统计算器
  3453. /// </summary>
  3454. /// <param name="sender"></param>
  3455. /// <param name="e"></param>
  3456. private void 计算器ToolStripMenuItem_Click(object sender, EventArgs e)
  3457. {
  3458. System.Diagnostics.Process.Start("calc.exe");
  3459. }
  3460. /// <summary>
  3461. ///故障转换和显示
  3462. /// </summary>
  3463. List<string> ErrorInfo = new List<string>{ "过流保护", "低压保护", "过压保护", "堵转保护","过热保护","速度传感器故障","力矩传感器故障","霍尔故障",
  3464. "马达缺相","NTC故障","BMS校验失败","","OBC校验失败","MCU故障","踏频传感器故障","指拨故障","MOS短路","电压异常","","","","","","","","","","","","",
  3465. "",""};
  3466. private string ErrorInfoDisplay(UInt32 Code)
  3467. {
  3468. string Result = "";
  3469. if (Code == 0)
  3470. {
  3471. Result = "无故障";
  3472. }
  3473. else
  3474. {
  3475. for (int i = 0; i < 32; i++)
  3476. {
  3477. if ((Code & 0x01) == 0x01)
  3478. {
  3479. Result += ErrorInfo[i] + " ";
  3480. }
  3481. Code >>= 1;
  3482. }
  3483. }
  3484. return Result;
  3485. }
  3486. /// <summary>
  3487. /// 鼠标滑过故障码显示具体内容
  3488. /// </summary>
  3489. /// <param name="sender"></param>
  3490. /// <param name="e"></param>
  3491. private void textBox_ErrorCode_MouseHover(object sender, EventArgs e)
  3492. {
  3493. // 创建the ToolTip
  3494. ToolTip toolTip1 = new ToolTip();
  3495. // 设置显示样式
  3496. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  3497. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  3498. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  3499. toolTip1.ShowAlways = true;//是否显示提示框
  3500. // 设置伴随的对象.
  3501. string ErrorCode = this.textBox_ErrorCode.Text;
  3502. UInt32 Code = ErrorCode.Contains("H") ? Convert.ToUInt32(ErrorCode.Split('H')[0], 16) : 0;
  3503. toolTip1.SetToolTip(this.textBox_ErrorCode, ErrorInfoDisplay(Code));//设置故障内容显示
  3504. }
  3505. /// <summary>
  3506. /// 数据记录
  3507. /// </summary>
  3508. private void RunInfoAutoSave()
  3509. {
  3510. if (运行信息记录ToolStripMenuItem.Checked == true)
  3511. {
  3512. if (RunInfoSaveFilename == string.Empty)
  3513. {
  3514. return;
  3515. }
  3516. string SaveData = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff").Replace(" ", "_") + " --> ";
  3517. foreach (Control c in tabPage_RunInfo.Controls)
  3518. {
  3519. if (c is TextBox)
  3520. {
  3521. SaveData += c.Text + " , ";
  3522. }
  3523. }
  3524. foreach (Control c in tabPage_DebugInfo.Controls)
  3525. {
  3526. if (c is TextBox)
  3527. {
  3528. SaveData += c.Text + " , ";
  3529. }
  3530. }
  3531. SaveData += "\r\n";
  3532. System.IO.File.AppendAllText(RunInfoSaveFilename, SaveData);//sb.ToString());
  3533. }
  3534. }
  3535. /// <summary>
  3536. /// 打开或关闭数据记录
  3537. /// </summary>
  3538. /// <param name="sender"></param>
  3539. /// <param name="e"></param>
  3540. private void 记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  3541. {
  3542. if (运行信息记录ToolStripMenuItem.Checked == false)
  3543. {
  3544. if (mySerialProcess.mySerial.IsOpen == true)
  3545. {
  3546. RunInfoSaveFilename = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_运行信息" + ".txt";
  3547. System.IO.File.AppendAllText(RunInfoSaveFilename, "时间 --> 车速 , 转速 , 踏频 , 力矩Reg , 力矩 , 踩踏方向 , 电压 , 电流 , 功率 , 电量 , " +
  3548. "PCB温度 , 绕组温度 , MOS温度 , 挡位 , 灯开关 , 续航 , 平均功耗 , 单次里程 , 单次时间 , 故障码 , " +
  3549. "系统状态机 , 二层状态机 , 电机状态机 , 助力状态机 , D轴电流给定 , Q轴电流给定 , D轴电压给定 , Q轴电压给定 , 瞬时力矩 , 时间滤波力矩 , 踏频滤波力矩 , D轴电流反馈 , Q轴电流反馈 , 助力函数输出" + "\r\n");
  3550. timer_500ms.Enabled = false;
  3551. MessageBoxTimeOut.Show("开始记录", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  3552. timer_500ms.Enabled = true;
  3553. 运行信息记录ToolStripMenuItem.Checked = true;
  3554. }
  3555. else
  3556. {
  3557. timer_500ms.Enabled = false;
  3558. MessageBox.Show("请连接电机", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3559. timer_500ms.Enabled = true;
  3560. }
  3561. }
  3562. else
  3563. {
  3564. 运行信息记录ToolStripMenuItem.Checked = false;
  3565. timer_500ms.Enabled = false;
  3566. MessageBoxTimeOut.Show("停止记录", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  3567. timer_500ms.Enabled = true;
  3568. }
  3569. }
  3570. /// <summary>
  3571. /// 仪表启动控制档位开关事件
  3572. /// </summary>
  3573. /// <param name="sender"></param>
  3574. /// <param name="e"></param>
  3575. private void checkBox_OBC_StartSetGearSt_CheckedChanged(object sender, EventArgs e)
  3576. {
  3577. if (checkBox_OBC_StartSetGearSt.Checked == true)
  3578. {
  3579. //检查串口是否打开
  3580. if (!mySerialProcess.mySerial.IsOpen)
  3581. {
  3582. timer_500ms.Enabled = false;
  3583. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3584. timer_500ms.Enabled = true;
  3585. checkBox_OBC_StartSetGearSt.Checked = false;
  3586. return;
  3587. }
  3588. //检查是否选择档位和打开车灯
  3589. if ((comboBox_OBC_SetGearST.SelectedIndex == -1) || (comboBox_OBC_LightSw.SelectedIndex == -1))
  3590. {
  3591. timer_500ms.Enabled = false;
  3592. MessageBox.Show("请检查档位设置和大灯开关!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3593. timer_500ms.Enabled = true;
  3594. checkBox_OBC_StartSetGearSt.Checked = false;
  3595. return;
  3596. }
  3597. }
  3598. }
  3599. /// <summary>
  3600. /// OBC查询电机用户参数
  3601. /// </summary>
  3602. /// <param name="sender"></param>
  3603. /// <param name="e"></param>
  3604. private void button_OBC_ReadUserInfo_Click(object sender, EventArgs e)
  3605. {
  3606. richTextBox_OBC_ReadUserInfo.Clear();
  3607. comboBox_OBC_BikeCCS.SelectedIndex = 0;
  3608. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3300, null);
  3609. }
  3610. /// <summary>
  3611. /// OBC设置电机用户参数
  3612. /// </summary>
  3613. /// <param name="sender"></param>
  3614. /// <param name="e"></param>
  3615. private void button_OBC_WriteUserInfo_Click(object sender, EventArgs e)
  3616. {
  3617. var UserInfoCode = new byte[8];
  3618. for (int i = 0; i < UserInfoCode.Length; i++)
  3619. UserInfoCode[i] = 0;
  3620. if (comboBox_OBC_StartMode.SelectedIndex == -1)//检查数据有效性
  3621. {
  3622. timer_500ms.Enabled = false;
  3623. MessageBox.Show("请选择启动模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3624. timer_500ms.Enabled = true;
  3625. return;
  3626. }
  3627. if (comboBox_OBC_AssistFunc.SelectedIndex == -1)//检查数据有效性
  3628. {
  3629. timer_500ms.Enabled = false;
  3630. MessageBox.Show("请选择助力方案!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3631. timer_500ms.Enabled = true;
  3632. return;
  3633. }
  3634. //周长微调
  3635. UserInfoCode[0] = (byte)(int)numericUpDown_OBC_WheelAdj.Value;
  3636. //启动模式
  3637. UserInfoCode[1] = (byte)(comboBox_OBC_StartMode.SelectedIndex + 1);
  3638. //助力方案
  3639. UserInfoCode[2] = (byte)(comboBox_OBC_AssistFunc.SelectedIndex + 1);
  3640. //自动关机时间
  3641. UserInfoCode[3] = (byte)(uint)numericUpDown_OBC_OffTime.Value;
  3642. //限速微调
  3643. UserInfoCode[4] = (byte)(int)numericUpDown_OBC_SpeedLimitAdj.Value;
  3644. //定速巡航开关
  3645. UserInfoCode[5] = (byte)((comboBox_OBC_BikeCCS.SelectedIndex == 1) ? 0xAA : 0x00);
  3646. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3408, UserInfoCode);
  3647. }
  3648. /// <summary>
  3649. /// OBC查询电机版本信息
  3650. /// </summary>
  3651. /// <param name="sender"></param>
  3652. /// <param name="e"></param>
  3653. private void button_OBC_ReadVerInfo_Click(object sender, EventArgs e)
  3654. {
  3655. textBox_Model.Text = "---";
  3656. textBox_SN.Text = "---";
  3657. textBox_HW.Text = "---";
  3658. textBox_FW.Text = "---";
  3659. textBox_SP.Text = "---";
  3660. textBox_OBC_ReadModel.Text = "---";
  3661. textBox_OBC_ReadSN.Text = "---";
  3662. textBox_OBC_ReadHW.Text = "---";
  3663. textBox_OBC_ReadFW.Text = "---";
  3664. textBox_OBC_ReadSP.Text = "---";
  3665. textBox_FacModeName.Text = "---";
  3666. textBox_FacModeNum.Text = "---";
  3667. textBox_FacModeHW.Text = "---";
  3668. textBox_FacModeFW.Text = "---";
  3669. textBox_FacModeSP.Text = "---";
  3670. Class_Motor_Ver.Mode = "---";
  3671. Class_Motor_Ver.SN = "---";
  3672. Class_Motor_Ver.HW = "---";
  3673. Class_Motor_Ver.FW = "---";
  3674. Class_Motor_Ver.Special = "---";
  3675. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  3676. }
  3677. /// <summary>
  3678. /// OBC读取骑行历史
  3679. /// </summary>
  3680. /// <param name="sender"></param>
  3681. /// <param name="e"></param>
  3682. private void button_OBC_ReadRideInfo_Click(object sender, EventArgs e)
  3683. {
  3684. textBox_OBC_TRIP_KM.Text = "";
  3685. textBox_OBC_TRIP_TIME.Text = "";
  3686. textBox_OBC_ODO_KM.Text = "";
  3687. textBox_OBC_ODO_TIME.Text = "";
  3688. textBox_ODO_KM.Text = "---";
  3689. textBox_ODO_TIME.Text = "---";
  3690. textBox_TRIP_KM.Text = "---";
  3691. textBox_TRIP_TIME.Text = "---";
  3692. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3500, null);
  3693. }
  3694. /// <summary>
  3695. /// OBC清除TRIP里程
  3696. /// </summary>
  3697. /// <param name="sender"></param>
  3698. /// <param name="e"></param>
  3699. private void button_OBC_ClearTrip_Click(object sender, EventArgs e)
  3700. {
  3701. var Code = new byte[5];
  3702. Code[0] = (byte)'C';
  3703. Code[1] = (byte)'L';
  3704. Code[2] = (byte)'E';
  3705. Code[3] = (byte)'A';
  3706. Code[4] = (byte)'R';
  3707. timer_500ms.Enabled = false;
  3708. if (MessageBox.Show("TRIP清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3709. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3605, Code);
  3710. timer_500ms.Enabled = true;
  3711. }
  3712. private void checkBox_OBC_StartReadBMS_CheckedChanged(object sender, EventArgs e)
  3713. {
  3714. if (checkBox_OBC_StartReadBMS.Checked == true)
  3715. {
  3716. //检查串口是否打开
  3717. if (!mySerialProcess.mySerial.IsOpen)
  3718. {
  3719. timer_500ms.Enabled = false;
  3720. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3721. timer_500ms.Enabled = true;
  3722. checkBox_OBC_StartReadBMS.Checked = false;
  3723. return;
  3724. }
  3725. }
  3726. }
  3727. /// <summary>
  3728. /// 写入力矩传感器参数
  3729. /// </summary>
  3730. /// <param name="sender"></param>
  3731. /// <param name="e"></param>
  3732. private void button_WriteTqSensorParam_Click(object sender, EventArgs e)
  3733. {
  3734. var ConfigParam = new byte[46];
  3735. for (int i = 0; i < 14; i++)
  3736. ConfigParam[i] = 0;
  3737. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  3738. ushort uwDataTemp = 0;
  3739. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  3740. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  3741. int index = 0;
  3742. try
  3743. {
  3744. for (int i = 0; i < strDataTemp.Length; i++)
  3745. {
  3746. if (strDataTemp[i].Split('=')[0] == "第四阶段转矩点采集值")
  3747. {
  3748. index = i;
  3749. break;
  3750. }
  3751. }
  3752. for (int i = 0; i < (index + 1); i++)
  3753. {
  3754. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  3755. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3756. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3757. }
  3758. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x472E, ConfigParam);
  3759. }
  3760. catch (Exception)
  3761. {
  3762. timer_500ms.Enabled = false;
  3763. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3764. timer_500ms.Enabled = true;
  3765. }
  3766. }
  3767. /// <summary>
  3768. /// 查询存储标志
  3769. /// </summary>
  3770. /// <param name="sender"></param>
  3771. /// <param name="e"></param>
  3772. private void button_ReadSaveFlag_Click(object sender, EventArgs e)
  3773. {
  3774. radioButton_EE_SaveYes.Checked = false;
  3775. radioButton_EE_SaveNo.Checked = false;
  3776. radioButton_SIP_SaveYes.Checked = false;
  3777. radioButton_SIP_SaveNo.Checked = false;
  3778. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null);
  3779. }
  3780. /// <summary>
  3781. /// 写入存储标志
  3782. /// </summary>
  3783. /// <param name="sender"></param>
  3784. /// <param name="e"></param>
  3785. private void button_WriteSaveFlag_Click(object sender, EventArgs e)
  3786. {
  3787. var SaveFlag = new byte[6];
  3788. for (int i = 0; i < 6; i++)
  3789. SaveFlag[i] = 0;
  3790. if ((radioButton_EE_SaveYes.Checked == false) && (radioButton_EE_SaveNo.Checked == false))
  3791. {
  3792. timer_500ms.Enabled = false;
  3793. MessageBox.Show("请选择EEPROM存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3794. timer_500ms.Enabled = true;
  3795. return;
  3796. }
  3797. if ((radioButton_SIP_SaveYes.Checked == false) && (radioButton_SIP_SaveNo.Checked == false))
  3798. {
  3799. timer_500ms.Enabled = false;
  3800. MessageBox.Show("请选择SIP校验存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3801. timer_500ms.Enabled = true;
  3802. return;
  3803. }
  3804. SaveFlag[0] = (byte)((checkBox_SaveYes.Checked) ? 0x01 : 0x00);
  3805. SaveFlag[2] = (byte)(radioButton_EE_SaveYes.Checked ? 0x01 : 0x00);
  3806. SaveFlag[3] = 0;
  3807. SaveFlag[4] = (byte)(radioButton_SIP_SaveYes.Checked ? 0x01 : 0x00);
  3808. SaveFlag[5] = 0;
  3809. timer_500ms.Enabled = false;
  3810. if (MessageBox.Show("确认修改存储标志?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3811. {
  3812. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4906, SaveFlag);
  3813. }
  3814. timer_500ms.Enabled = true;
  3815. }
  3816. /// <summary>
  3817. /// 读取指定地址数据
  3818. /// </summary>
  3819. /// <param name="sender"></param>
  3820. /// <param name="e"></param>
  3821. private void button_ReadRamFlash_Click(object sender, EventArgs e)
  3822. {
  3823. var Address = new byte[4];
  3824. UInt32 Address_Begin;
  3825. UInt32 Addres_End;
  3826. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  3827. richTextBox_RamFlasgData.Clear();
  3828. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  3829. {
  3830. timer_500ms.Enabled = false;
  3831. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3832. timer_500ms.Enabled = true;
  3833. return;
  3834. }
  3835. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  3836. {
  3837. timer_500ms.Enabled = false;
  3838. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3839. timer_500ms.Enabled = true;
  3840. return;
  3841. }
  3842. else
  3843. {
  3844. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  3845. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  3846. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  3847. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  3848. if (Addres_End < Address_Begin)
  3849. {
  3850. timer_500ms.Enabled = false;
  3851. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3852. timer_500ms.Enabled = true;
  3853. return;
  3854. }
  3855. else
  3856. {
  3857. var SendByte = new byte[8];
  3858. SendByte[0] = (byte)(Address_Begin >> 24);
  3859. SendByte[1] = (byte)(Address_Begin >> 16);
  3860. SendByte[2] = (byte)(Address_Begin >> 8);
  3861. SendByte[3] = (byte)(Address_Begin);
  3862. SendByte[4] = (byte)(Addres_End >> 24);
  3863. SendByte[5] = (byte)(Addres_End >> 16);
  3864. SendByte[6] = (byte)(Addres_End >> 8);
  3865. SendByte[7] = (byte)(Addres_End);
  3866. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  3867. }
  3868. }
  3869. }
  3870. /// <summary>
  3871. /// 工作模式选择
  3872. /// </summary>
  3873. /// <param name="sender"></param>
  3874. /// <param name="e"></param>
  3875. private void comboBox_WorkMode_SelectedIndexChanged(object sender, EventArgs e)
  3876. {
  3877. var RunMode = new byte[1];
  3878. if (comboBox_WorkMode.Text == "配置模式")
  3879. RunMode[0] = 0x01;
  3880. else if (comboBox_WorkMode.Text == "调试模式")
  3881. RunMode[0] = 0x02;
  3882. else
  3883. RunMode[0] = 0x00;
  3884. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  3885. }
  3886. /// <summary>
  3887. /// 助力档位选择
  3888. /// </summary>
  3889. /// <param name="sender"></param>
  3890. /// <param name="e"></param>
  3891. private void comboBox_GearSt_SelectedIndexChanged(object sender, EventArgs e)
  3892. {
  3893. var CtrlCode = new byte[2];
  3894. if (comboBox_GearSt.SelectedIndex == 5)//档位
  3895. CtrlCode[0] = 0x33;
  3896. else if (comboBox_GearSt.SelectedIndex == 6)//档位
  3897. CtrlCode[0] = 0x22;
  3898. else
  3899. CtrlCode[0] = (byte)comboBox_GearSt.SelectedIndex;
  3900. if (comboBox_LightSwitch.SelectedIndex == 0)//车灯
  3901. CtrlCode[1] = 0xF1;
  3902. else
  3903. CtrlCode[1] = 0xF0;
  3904. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
  3905. comboBox_OBC_SetGearST.SelectedIndex = comboBox_GearSt.SelectedIndex;
  3906. comboBox_OBC_LightSw.SelectedIndex = comboBox_LightSwitch.SelectedIndex;
  3907. Delay_ms(500);
  3908. //设置百分比
  3909. do
  3910. {
  3911. var PercentCode = new byte[1];
  3912. if (comboBox_GearSt.SelectedIndex == 0) //Off
  3913. {
  3914. PercentCode[0] = 0;
  3915. textBox_MotorSpeedPercent.Text = "0";
  3916. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, PercentCode);
  3917. }
  3918. else if (comboBox_GearSt.SelectedIndex == 6) //Walk
  3919. {
  3920. if (comboBox_WorkMode.SelectedIndex != 0)
  3921. {
  3922. PercentCode[0] = 100;
  3923. textBox_MotorSpeedPercent.Text = "100";
  3924. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, PercentCode);
  3925. }
  3926. }
  3927. } while (false);
  3928. }
  3929. /// <summary>
  3930. /// 仪表档位选择
  3931. /// </summary>
  3932. /// <param name="sender"></param>
  3933. /// <param name="e"></param>
  3934. private void comboBox_OBC_SetGearST_SelectedIndexChanged(object sender, EventArgs e)
  3935. {
  3936. comboBox_GearSt.SelectedIndex = comboBox_OBC_SetGearST.SelectedIndex;
  3937. comboBox_LightSwitch.SelectedIndex = comboBox_OBC_LightSw.SelectedIndex;
  3938. }
  3939. /// <summary>
  3940. /// 生产模式初始化
  3941. /// </summary>
  3942. /// <param name="sender"></param>
  3943. /// <param name="e"></param>
  3944. private void button_FacModeInit_Click(object sender, EventArgs e)
  3945. {
  3946. var Code = new byte[5];
  3947. Code[0] = (byte)'C';
  3948. Code[1] = (byte)'L';
  3949. Code[2] = (byte)'E';
  3950. Code[3] = (byte)'A';
  3951. Code[4] = (byte)'R';
  3952. timer_500ms.Enabled = false;
  3953. if (MessageBox.Show("电机即将初始化!", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3954. {
  3955. if (MessageBox.Show("请再次确认", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3956. {
  3957. timer_500ms.Enabled = true;
  3958. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  3959. PowerOffAckStatus = false;
  3960. Delay_ms(250);
  3961. int TryCnt = 3;
  3962. while ((TryCnt--) >= 0)
  3963. {
  3964. if (!PowerOffAckStatus)
  3965. {
  3966. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  3967. PowerOffAckStatus = false;
  3968. Delay_ms(250);
  3969. }
  3970. else break;
  3971. }
  3972. if (PowerOffAckStatus)
  3973. {
  3974. timer_500ms.Enabled = false;
  3975. MessageBox.Show("系统已关机,请保持无负载重新开机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  3976. timer_500ms.Enabled = true;
  3977. }
  3978. else
  3979. {
  3980. timer_500ms.Enabled = false;
  3981. MessageBox.Show("初始化失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3982. timer_500ms.Enabled = true;
  3983. }
  3984. timer_500ms.Enabled = true;
  3985. }
  3986. }
  3987. timer_500ms.Enabled = true;
  3988. //清除历史测试记录
  3989. textBox_FacModeSensorADC0.Text = "";
  3990. textBox_FacModeSensorADC1.Text = "";
  3991. textBox_FacModeSensorADC2.Text = "";
  3992. textBox_FacModeSensorADC3.Text = "";
  3993. textBox_FacModeSensorADC4.Text = "";
  3994. LightSwitchStatus = false;
  3995. MotorRunStatus = false;
  3996. textBox_MotorSpeedPercent.Text = "5";
  3997. textBox_FacModeName.Text = "";
  3998. textBox_FacModeNum.Text = "";
  3999. textBox_FacModeHW.Text = "";
  4000. textBox_FacModeFW.Text = "";
  4001. }
  4002. /// <summary>
  4003. /// 生产模式读取传感器参数
  4004. /// </summary>
  4005. /// <param name="sender"></param>
  4006. /// <param name="e"></param>
  4007. private void button_FacModeSensorRead_Click(object sender, EventArgs e)
  4008. {
  4009. richTextBox_SensorParam.Clear();
  4010. textBox_FacModeSensorADC0.Text = "";
  4011. textBox_FacModeSensorADC1.Text = "";
  4012. textBox_FacModeSensorADC2.Text = "";
  4013. textBox_FacModeSensorADC3.Text = "";
  4014. textBox_FacModeSensorADC4.Text = "";
  4015. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4016. //零点判断
  4017. label1_TorqueCal0.BackColor = Color.Red;
  4018. WriteACK = false;
  4019. ACK_WaitCnt = 0;
  4020. Delay_ms(200);
  4021. if (WriteACK == true) //力矩读取正常
  4022. {
  4023. WriteACK = false;
  4024. //获取零点
  4025. ushort ZeroNew;
  4026. ZeroNew = (ushort)Convert.ToUInt16(textBox_FacModeSensorADC0.Text);
  4027. //比较零点
  4028. if ((ZeroNew <= TorqueParamsForm.Zero.Max) && (ZeroNew >= TorqueParamsForm.Zero.Min))
  4029. {
  4030. label1_TorqueCal0.BackColor = Color.Green;
  4031. }
  4032. else
  4033. {
  4034. MessageBoxTimeOut.Show("力矩传感器零点超范围!\r\n" + "最新零点:" + ZeroNew.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4035. }
  4036. }
  4037. else //力矩读取不正常
  4038. {
  4039. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4040. }
  4041. }
  4042. /// <summary>
  4043. /// 生产模式传感器标定1
  4044. /// </summary>
  4045. /// <param name="sender"></param>
  4046. /// <param name="e"></param>
  4047. private void buttonFacModeSet1_Click(object sender, EventArgs e)
  4048. {
  4049. var ConfigParam = new byte[4];
  4050. for (int i = 0; i < 4; i++)
  4051. ConfigParam[i] = 0;
  4052. ushort uwDataTemp = 0;
  4053. try
  4054. {
  4055. uwDataTemp = 1;//负载序号
  4056. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4057. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4058. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal1.Text) * 10); ;//负载值0.1Nm
  4059. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4060. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4061. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4062. Delay_ms(200);
  4063. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4064. //标定1判断
  4065. label1_TorqueCal1.BackColor = Color.Red;
  4066. WriteACK = false;
  4067. ACK_WaitCnt = 0;
  4068. Delay_ms(200);
  4069. if (WriteACK == true) //力矩读取正常
  4070. {
  4071. WriteACK = false;
  4072. //获取标定1
  4073. ushort K1_T, K1;
  4074. K1_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal1.Text) * 10);
  4075. K1 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC1.Text));
  4076. //比较标定1
  4077. if ((K1_T == TorqueParamsForm.K1.T) && (K1 <= TorqueParamsForm.K1.Max) && (K1 >= TorqueParamsForm.K1.Min))
  4078. {
  4079. label1_TorqueCal1.BackColor = Color.Green;
  4080. }
  4081. else
  4082. {
  4083. MessageBoxTimeOut.Show("力矩传感器标定1超范围!\r\n" + "加载扭矩:" + K1_T.ToString() + "\r\n标定值:" + K1.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4084. }
  4085. }
  4086. else //力矩读取不正常
  4087. {
  4088. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4089. }
  4090. }
  4091. catch (Exception)
  4092. {
  4093. timer_500ms.Enabled = false;
  4094. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4095. timer_500ms.Enabled = true;
  4096. }
  4097. }
  4098. /// <summary>
  4099. /// 生产模式传感器标定2
  4100. /// </summary>
  4101. /// <param name="sender"></param>
  4102. /// <param name="e"></param>
  4103. private void buttonFacModeSet2_Click(object sender, EventArgs e)
  4104. {
  4105. var ConfigParam = new byte[4];
  4106. for (int i = 0; i < 4; i++)
  4107. ConfigParam[i] = 0;
  4108. ushort uwDataTemp = 0;
  4109. try
  4110. {
  4111. uwDataTemp = 2;//负载序号
  4112. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4113. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4114. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal2.Text) * 10); ;//负载值0.1Nm
  4115. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4116. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4117. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4118. Delay_ms(200);
  4119. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4120. //标定2判断
  4121. label1_TorqueCal2.BackColor = Color.Red;
  4122. WriteACK = false;
  4123. ACK_WaitCnt = 0;
  4124. Delay_ms(200);
  4125. if (WriteACK == true) //力矩读取正常
  4126. {
  4127. WriteACK = false;
  4128. //获取标定2
  4129. ushort K2_T, K2;
  4130. K2_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal2.Text) * 10);
  4131. K2 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC2.Text));
  4132. //比较标定1
  4133. if ((K2_T == TorqueParamsForm.K2.T) && (K2 <= TorqueParamsForm.K2.Max) && (K2 >= TorqueParamsForm.K2.Min))
  4134. {
  4135. label1_TorqueCal2.BackColor = Color.Green;
  4136. }
  4137. else
  4138. {
  4139. MessageBoxTimeOut.Show("力矩传感器标定2超范围!\r\n" + "加载扭矩:" + K2_T.ToString() + "\r\n标定值:" + K2.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4140. }
  4141. }
  4142. else //力矩读取不正常
  4143. {
  4144. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4145. }
  4146. }
  4147. catch (Exception)
  4148. {
  4149. timer_500ms.Enabled = false;
  4150. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4151. timer_500ms.Enabled = true;
  4152. }
  4153. }
  4154. /// <summary>
  4155. /// 生产模式传感器标定3
  4156. /// </summary>
  4157. /// <param name="sender"></param>
  4158. /// <param name="e"></param>
  4159. private void buttonFacModeSet3_Click(object sender, EventArgs e)
  4160. {
  4161. var ConfigParam = new byte[4];
  4162. for (int i = 0; i < 4; i++)
  4163. ConfigParam[i] = 0;
  4164. ushort uwDataTemp = 0;
  4165. try
  4166. {
  4167. uwDataTemp = 3;//负载序号
  4168. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4169. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4170. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal3.Text) * 10); ;//负载值0.1Nm
  4171. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4172. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4173. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4174. Delay_ms(200);
  4175. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4176. //标定3判断
  4177. label1_TorqueCal3.BackColor = Color.Red;
  4178. WriteACK = false;
  4179. ACK_WaitCnt = 0;
  4180. Delay_ms(200);
  4181. if (WriteACK == true) //力矩读取正常
  4182. {
  4183. WriteACK = false;
  4184. //获取标定3
  4185. ushort K3_T, K3;
  4186. K3_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal3.Text) * 10);
  4187. K3 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC3.Text));
  4188. //比较标定1
  4189. if ((K3_T == TorqueParamsForm.K3.T) && (K3 <= TorqueParamsForm.K3.Max) && (K3 >= TorqueParamsForm.K3.Min))
  4190. {
  4191. label1_TorqueCal3.BackColor = Color.Green;
  4192. }
  4193. else
  4194. {
  4195. MessageBoxTimeOut.Show("力矩传感器标定3超范围!\r\n" + "加载扭矩:" + K3_T.ToString() + "\r\n标定值:" + K3.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4196. }
  4197. }
  4198. else //力矩读取不正常
  4199. {
  4200. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4201. }
  4202. }
  4203. catch (Exception)
  4204. {
  4205. timer_500ms.Enabled = false;
  4206. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4207. timer_500ms.Enabled = true;
  4208. }
  4209. }
  4210. /// <summary>
  4211. /// 生产模式传感器标定4
  4212. /// </summary>
  4213. /// <param name="sender"></param>
  4214. /// <param name="e"></param>
  4215. private void buttonFacModeSet4_Click(object sender, EventArgs e)
  4216. {
  4217. var ConfigParam = new byte[4];
  4218. for (int i = 0; i < 4; i++)
  4219. ConfigParam[i] = 0;
  4220. ushort uwDataTemp = 0;
  4221. try
  4222. {
  4223. WriteACK = false;
  4224. uwDataTemp = 4;//负载序号
  4225. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4226. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4227. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal4.Text) * 10); ;//负载值0.1Nm
  4228. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4229. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4230. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4231. Delay_ms(200);
  4232. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4233. //标定4判断
  4234. label1_TorqueCal4.BackColor = Color.Red;
  4235. WriteACK = false;
  4236. ACK_WaitCnt = 0;
  4237. Delay_ms(200);
  4238. if (WriteACK == true) //力矩读取正常
  4239. {
  4240. //获取标定4
  4241. ushort K4_T, K4;
  4242. K4_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal4.Text) * 10);
  4243. K4 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC4.Text));
  4244. //比较标定1
  4245. if ((K4_T == TorqueParamsForm.K4.T) && (K4 <= TorqueParamsForm.K4.Max) && (K4 >= TorqueParamsForm.K4.Min))
  4246. {
  4247. label1_TorqueCal4.BackColor = Color.Green;
  4248. }
  4249. else
  4250. {
  4251. MessageBoxTimeOut.Show("力矩传感器标定4超范围!\r\n" + "加载扭矩:" + K4_T.ToString() + "\r\n标定值:" + K4.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4252. }
  4253. }
  4254. else //力矩读取不正常
  4255. {
  4256. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4257. }
  4258. }
  4259. catch (Exception)
  4260. {
  4261. timer_500ms.Enabled = false;
  4262. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4263. timer_500ms.Enabled = true;
  4264. }
  4265. }
  4266. /// <summary>
  4267. /// 生产模式开关灯
  4268. /// </summary>
  4269. /// <param name="sender"></param>
  4270. /// <param name="e"></param>
  4271. bool LightSwitchStatus = false;
  4272. private void button_FacModeLightSW_Click(object sender, EventArgs e)
  4273. {
  4274. var CtrlCode = new byte[2];
  4275. CtrlCode[0] = 0x00;
  4276. if (LightSwitchStatus)
  4277. {
  4278. CtrlCode[1] = 0xF0;
  4279. button_FacModeLightSW.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(128)))));
  4280. }
  4281. else
  4282. {
  4283. CtrlCode[1] = 0xF1;
  4284. button_FacModeLightSW.BackColor = Color.Yellow;
  4285. }
  4286. if (mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode))
  4287. {
  4288. LightSwitchStatus = !LightSwitchStatus;
  4289. comboBox_LightSwitch.SelectedIndex = LightSwitchStatus ? 0 : 1;
  4290. comboBox_OBC_LightSw.SelectedIndex = LightSwitchStatus ? 0 : 1;
  4291. }
  4292. }
  4293. /// <summary>
  4294. /// 生产模式电机控制
  4295. /// </summary>
  4296. /// <param name="sender"></param>
  4297. /// <param name="e"></param>
  4298. bool MotorRunStatus = false;
  4299. private void button_FacModeMotorRun_Click(object sender, EventArgs e)
  4300. {
  4301. string DebugDefaultInfo = "";
  4302. //获取调试信息
  4303. if (richTextBox_DebugParam.Text == string.Empty)
  4304. {
  4305. richTextBox_DebugParam.Clear();
  4306. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  4307. }
  4308. Delay_ms(200);
  4309. DebugDefaultInfo = richTextBox_DebugParam.Text;
  4310. //获取参数
  4311. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  4312. if (strDataTemp.Length != 29)
  4313. {
  4314. timer_500ms.Enabled = false;
  4315. MessageBox.Show("数据格式不正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4316. timer_500ms.Enabled = true;
  4317. return;
  4318. }
  4319. //设置参数
  4320. var ConfigParam = new byte[60];
  4321. for (int i = 0; i < 60; i++)
  4322. ConfigParam[i] = 0;
  4323. ConfigParam[0] = 0x00;
  4324. ushort uwDataTemp = 0;
  4325. if (!MotorRunStatus) //停止状态
  4326. {
  4327. //设置速度环
  4328. strDataTemp[0] = "整体运行模式=3";
  4329. //发送数据
  4330. try
  4331. {
  4332. for (int i = 0; i < strDataTemp.Length; i++)
  4333. {
  4334. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  4335. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  4336. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  4337. }
  4338. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  4339. return;
  4340. }
  4341. catch (Exception)
  4342. {
  4343. timer_500ms.Enabled = false;
  4344. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4345. timer_500ms.Enabled = true;
  4346. }
  4347. Delay_ms(200);
  4348. //设置转速百分比100%
  4349. textBox_MotorSpeedPercent.Text = "100";
  4350. ConfigParam[0] = (byte)100;
  4351. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, ConfigParam);
  4352. MotorRunStatus = !MotorRunStatus;
  4353. button_FacModeMotorRun.BackColor = Color.Yellow;
  4354. Delay_ms(200);
  4355. //电机进入配置模式
  4356. var RunMode = new byte[1];
  4357. RunMode[0] = 0x01;
  4358. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  4359. }
  4360. else //运转状态
  4361. {
  4362. //设置转速百分比0%
  4363. textBox_MotorSpeedPercent.Text = "0";
  4364. ConfigParam[0] = (byte)0;
  4365. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, ConfigParam);
  4366. MotorRunStatus = !MotorRunStatus;
  4367. button_FacModeMotorRun.BackColor = Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
  4368. Delay_ms(200);
  4369. //还原为原始值
  4370. strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  4371. try
  4372. {
  4373. for (int i = 0; i < strDataTemp.Length; i++)
  4374. {
  4375. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  4376. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  4377. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  4378. }
  4379. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  4380. return;
  4381. }
  4382. catch (Exception)
  4383. {
  4384. timer_500ms.Enabled = false;
  4385. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4386. timer_500ms.Enabled = true;
  4387. }
  4388. Delay_ms(200);
  4389. //电机退出配置模式
  4390. var RunMode = new byte[1];
  4391. RunMode[0] = 0x00;
  4392. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  4393. }
  4394. }
  4395. /// <summary>
  4396. /// 生产模式写入型号
  4397. /// </summary>
  4398. /// <param name="sender"></param>
  4399. /// <param name="e"></param>
  4400. private void button_FacModeSetName_Click(object sender, EventArgs e)
  4401. {
  4402. string Mode = textBox_FacModeName.Text;
  4403. var ModeArray = new byte[16];
  4404. for (ushort i = 0; i < Mode.Length; i++)
  4405. {
  4406. ModeArray[i] = (byte)Mode[i];
  4407. }
  4408. if (Mode.Length < 16)
  4409. {
  4410. ModeArray[Mode.Length] = (byte)'.';
  4411. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  4412. {
  4413. ModeArray[Mode.Length + 1 + i] = 0x20;
  4414. }
  4415. }
  4416. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  4417. }
  4418. /// <summary>
  4419. /// 生产模式写入SN
  4420. /// </summary>
  4421. /// <param name="sender"></param>
  4422. /// <param name="e"></param>
  4423. private void Button_FacModeSetNum_Click(object sender, EventArgs e)
  4424. {
  4425. string SN = textBox_FacModeNum.Text;
  4426. var SNArray = new byte[16];
  4427. for (ushort i = 0; i < SN.Length; i++)
  4428. {
  4429. SNArray[i] = (byte)SN[i];
  4430. }
  4431. if (SN.Length < 16)
  4432. {
  4433. SNArray[SN.Length] = (byte)'.';
  4434. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  4435. {
  4436. SNArray[SN.Length + 1 + i] = 0x20;
  4437. }
  4438. }
  4439. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  4440. }
  4441. /// <summary>
  4442. /// 生产模式读取版本信息
  4443. /// </summary>
  4444. /// <param name="sender"></param>
  4445. /// <param name="e"></param>
  4446. private void Button_FacModeReadVer_Click_1(object sender, EventArgs e)
  4447. {
  4448. textBox_Model.Text = "---";
  4449. textBox_SN.Text = "---";
  4450. textBox_HW.Text = "---";
  4451. textBox_FW.Text = "---";
  4452. textBox_SP.Text = "---";
  4453. textBox_OBC_ReadModel.Text = "---";
  4454. textBox_OBC_ReadSN.Text = "---";
  4455. textBox_OBC_ReadHW.Text = "---";
  4456. textBox_OBC_ReadFW.Text = "---";
  4457. textBox_OBC_ReadSP.Text = "---";
  4458. textBox_FacModeName.Text = "---";
  4459. textBox_FacModeNum.Text = "---";
  4460. textBox_FacModeHW.Text = "---";
  4461. textBox_FacModeFW.Text = "---";
  4462. textBox_FacModeSP.Text = "---";
  4463. textBox_FacModeGit.Text = "---";
  4464. Class_Motor_Ver.Mode = "---";
  4465. Class_Motor_Ver.SN = "---";
  4466. Class_Motor_Ver.HW = "---";
  4467. Class_Motor_Ver.FW = "---";
  4468. Class_Motor_Ver.Special = "---";
  4469. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  4470. }
  4471. /// <summary>
  4472. /// 生产模式写入生产信息
  4473. /// </summary>
  4474. /// <param name="sender"></param>
  4475. /// <param name="e"></param>
  4476. private void Button_FacModeSetMacDate_Click(object sender, EventArgs e)
  4477. {
  4478. var MACArray = new byte[32];
  4479. string MacDefaultInfo = "";
  4480. string MacAddDefaultInfo = "";
  4481. string MacDateDefaultInfo = DateTime.Now.ToString("yyyyMMdd");
  4482. string MacPPDefaultInfo = "";
  4483. do
  4484. {
  4485. //填入生产商
  4486. if (toolStripTextBox_MAC.Text == string.Empty)
  4487. {
  4488. break;
  4489. }
  4490. MacDefaultInfo = toolStripTextBox_MAC.Text;
  4491. for (ushort i = 0; i < MacDefaultInfo.Length; i++)
  4492. {
  4493. MACArray[i] = (byte)MacDefaultInfo[i];
  4494. }
  4495. if (MacDefaultInfo.Length < 8)
  4496. {
  4497. MACArray[MacDefaultInfo.Length] = (byte)'.';
  4498. for (ushort i = 0; i < 8 - MacDefaultInfo.Length - 1; i++)
  4499. {
  4500. MACArray[MacDefaultInfo.Length + 1 + i] = 0x20;
  4501. }
  4502. }
  4503. //填入生产地
  4504. if (toolStripTextBoxMACAddr.Text == string.Empty)
  4505. {
  4506. break;
  4507. }
  4508. MacAddDefaultInfo = toolStripTextBoxMACAddr.Text;
  4509. for (ushort i = 0; i < MacAddDefaultInfo.Length; i++)
  4510. {
  4511. MACArray[8 + i] = (byte)MacAddDefaultInfo[i];
  4512. }
  4513. if (MacAddDefaultInfo.Length < 8)
  4514. {
  4515. MACArray[MacAddDefaultInfo.Length + 8] = (byte)'.';
  4516. for (ushort i = 0; i < 8 - MacAddDefaultInfo.Length - 1; i++)
  4517. {
  4518. MACArray[MacAddDefaultInfo.Length + 1 + i + 8] = 0x20;
  4519. }
  4520. }
  4521. //填入生产日期
  4522. if (toolStripTextBox_MACDate.Text == string.Empty)
  4523. {
  4524. break;
  4525. }
  4526. MacDateDefaultInfo = toolStripTextBox_MACDate.Text;
  4527. for (ushort i = 0; i < MacDateDefaultInfo.Length; i++)
  4528. {
  4529. MACArray[16 + i] = (byte)MacDateDefaultInfo[i];
  4530. }
  4531. if (MacDateDefaultInfo.Length < 8)
  4532. {
  4533. MACArray[MacDateDefaultInfo.Length + 16] = (byte)'.';
  4534. for (ushort i = 0; i < 8 - MacDateDefaultInfo.Length - 1; i++)
  4535. {
  4536. MACArray[MacDateDefaultInfo.Length + 1 + i + 16] = 0x20;
  4537. }
  4538. }
  4539. //填入产品标识
  4540. if (toolStripTextBox_MACPD.Text == string.Empty)
  4541. {
  4542. break;
  4543. }
  4544. MacPPDefaultInfo = toolStripTextBox_MACPD.Text;
  4545. for (ushort i = 0; i < MacPPDefaultInfo.Length; i++)
  4546. {
  4547. MACArray[24 + i] = (byte)MacPPDefaultInfo[i];
  4548. }
  4549. if (MacPPDefaultInfo.Length < 8)
  4550. {
  4551. MACArray[MacPPDefaultInfo.Length + 24] = (byte)'.';
  4552. for (ushort i = 0; i < 8 - MacPPDefaultInfo.Length - 1; i++)
  4553. {
  4554. MACArray[MacPPDefaultInfo.Length + 1 + i + 24] = 0x20;
  4555. }
  4556. }
  4557. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  4558. return;
  4559. } while (false);
  4560. timer_500ms.Enabled = false;
  4561. MessageBox.Show("生产信息配置不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4562. timer_500ms.Enabled = true;
  4563. }
  4564. /// <summary>
  4565. /// 生产模式保存测试页面
  4566. /// </summary>
  4567. /// <param name="sender"></param>
  4568. /// <param name="e"></param>
  4569. private void Button_FacModeSaveResult_Click(object sender, EventArgs e)
  4570. {
  4571. Button_FacModeSaveResult.Text = "存储中…";
  4572. string[] AssistParams = new string[15];
  4573. do
  4574. {
  4575. //读取一次马达参数
  4576. richTextBox_MotorParam.Clear();
  4577. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break; ;
  4578. Delay_ms(100);
  4579. //读取一次整车参数
  4580. richTextBox_BikeParam.Clear();
  4581. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  4582. Delay_ms(100);
  4583. //读取一次整车参数2
  4584. richTextBox_BikeParam2.Clear();
  4585. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null)) break;
  4586. Delay_ms(100);
  4587. //读取一次控制参数
  4588. richTextBox_ControlParam.Clear();
  4589. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  4590. Delay_ms(100);
  4591. //查询传感器
  4592. richTextBox_SensorParam.Clear();
  4593. textBox_FacModeSensorADC0.Text = "";
  4594. textBox_FacModeSensorADC1.Text = "";
  4595. textBox_FacModeSensorADC2.Text = "";
  4596. textBox_FacModeSensorADC3.Text = "";
  4597. textBox_FacModeSensorADC4.Text = "";
  4598. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  4599. Delay_ms(100);
  4600. //读取15次助力参数
  4601. for (int i = 1; i <= 15; i++)
  4602. {
  4603. var ConfigParam = new byte[4];
  4604. richTextBox_AssistParam.Clear();
  4605. ConfigParam[0] = (byte)(i & 0xFF);
  4606. ConfigParam[1] = (byte)(i >> 8);
  4607. ConfigParam[2] = (byte)(((i >= 5) ? 5 : i) & 0xFF);
  4608. ConfigParam[3] = (byte)(((i >= 5) ? 5 : i) >> 8);
  4609. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  4610. Delay_ms(200);
  4611. AssistParams[i - 1] = richTextBox_AssistParam.Text + "\r\n";
  4612. }
  4613. //读取一次用户骑行参数
  4614. richTextBox_UsrRidesParam.Clear();
  4615. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  4616. Delay_ms(100);
  4617. //读取一次调试信息
  4618. richTextBox_DebugParam.Clear();
  4619. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  4620. Delay_ms(100);
  4621. //读取一次历史信息
  4622. richTextBox_Record.Clear();
  4623. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  4624. Delay_ms(100);
  4625. //读取一次电机运行信息
  4626. var CtrlCode = new byte[2];
  4627. CtrlCode[0] = 0x00;
  4628. CtrlCode[1] = 0xF0;
  4629. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode)) break;
  4630. Delay_ms(100);
  4631. //读取一次版本信息
  4632. textBox_Model.Text = "---";
  4633. textBox_SN.Text = "---";
  4634. textBox_HW.Text = "---";
  4635. textBox_FW.Text = "---";
  4636. textBox_OBC_ReadModel.Text = "---";
  4637. textBox_OBC_ReadSN.Text = "---";
  4638. textBox_OBC_ReadHW.Text = "---";
  4639. textBox_OBC_ReadFW.Text = "---";
  4640. textBox_FacModeName.Text = "---";
  4641. textBox_FacModeNum.Text = "---";
  4642. textBox_FacModeHW.Text = "---";
  4643. textBox_FacModeFW.Text = "---";
  4644. Class_Motor_Ver.Mode = "---";
  4645. Class_Motor_Ver.SN = "---";
  4646. Class_Motor_Ver.HW = "---";
  4647. Class_Motor_Ver.FW = "---";
  4648. Class_Motor_Ver.Special = "---";
  4649. if (!mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null)) break;
  4650. Delay_ms(100);
  4651. //读取一次生产信息
  4652. textBox_MAC.Text = "";
  4653. textBox_MACAdd.Text = "";
  4654. textBox_MACDate.Text = "";
  4655. textBox_PP.Text = "";
  4656. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  4657. Delay_ms(100);
  4658. //读取一次自定义信息
  4659. textBox_User1.Text = "---";
  4660. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  4661. Delay_ms(100);
  4662. textBox_User2.Text = "---";
  4663. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  4664. Delay_ms(100);
  4665. textBox_User3.Text = "---";
  4666. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  4667. Delay_ms(100);
  4668. //读取一次密钥
  4669. textBox_Key.Text = "---";
  4670. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  4671. Delay_ms(100);
  4672. //读取一次存储标志
  4673. radioButton_EE_SaveYes.Checked = false;
  4674. radioButton_EE_SaveNo.Checked = false;
  4675. radioButton_SIP_SaveYes.Checked = false;
  4676. radioButton_SIP_SaveNo.Checked = false;
  4677. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  4678. Delay_ms(100);
  4679. //读取一次MOS内阻校准参数
  4680. foreach (Control c in groupBox21.Controls)
  4681. {
  4682. if (c is TextBox)
  4683. c.Text = "";
  4684. }
  4685. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  4686. Delay_ms(100);
  4687. //提示检查
  4688. #if false
  4689. timer_1s.Enabled = false;
  4690. if (MessageBox.Show("请检查信息是否完整!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  4691. {
  4692. MessageBox.Show("请检查参数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4693. timer_1s.Enabled = true;
  4694. return;
  4695. }
  4696. timer_1s.Enabled = true;
  4697. Delay_ms(200);
  4698. #endif
  4699. //判断数据是否有效
  4700. if ((textBox_FacModeName.Text == "---") || (textBox_FacModeNum.Text == "---"))
  4701. {
  4702. MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4703. break;
  4704. }
  4705. if ((textBox_FacModeName.Text == string.Empty) || (textBox_FacModeNum.Text == string.Empty))
  4706. {
  4707. MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4708. break;
  4709. }
  4710. //设置文件存储路径
  4711. string Save_Path = localInfo.LocalPath + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
  4712. string PD_PathName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_"); ;
  4713. Save_Path += PD_PathName;
  4714. if (!Directory.Exists(Save_Path))
  4715. Directory.CreateDirectory(Save_Path);
  4716. //保存页面
  4717. string PIC_SaveFileName = "";
  4718. Double scaleX = PrimaryScreen.ScaleX;
  4719. Double scaleY = PrimaryScreen.ScaleY;
  4720. //保存页面
  4721. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  4722. Graphics g = Graphics.FromImage(bit);
  4723. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  4724. PIC_SaveFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_测试页面" + ".png";
  4725. bit.Save(PIC_SaveFileName);
  4726. //保存数据
  4727. string DataFileName = "";
  4728. string FileInfo = "";
  4729. DataFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_记录数据" + ".txt";
  4730. FileInfo += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  4731. FileInfo += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  4732. FileInfo += "\r\n";
  4733. FileInfo += "[电机信息]\r\n";
  4734. FileInfo += "电机型号: " + textBox_FacModeName.Text + "\r\n";
  4735. FileInfo += "电机编号: " + textBox_FacModeNum.Text + "\r\n";
  4736. FileInfo += "硬件版本: " + textBox_HW.Text + "\r\n";
  4737. FileInfo += "软件版本: " + textBox_FW.Text + "\r\n";
  4738. FileInfo += "软件标识: " + textBox_SP.Text + "\r\n";
  4739. FileInfo += "Git信息: " + textBox_FacModeGit.Text + "\r\n";
  4740. FileInfo += "\r\n";
  4741. FileInfo += "[马达参数]\r\n";
  4742. FileInfo += richTextBox_MotorParam.Text + "\r\n";
  4743. FileInfo += "\r\n";
  4744. FileInfo += "[整车参数]\r\n";
  4745. FileInfo += richTextBox_BikeParam.Text + "\r\n";
  4746. FileInfo += "\r\n";
  4747. FileInfo += "[控制参数]\r\n";
  4748. FileInfo += richTextBox_ControlParam.Text + "\r\n";
  4749. FileInfo += "\r\n";
  4750. FileInfo += "[传感器参数]\r\n";
  4751. FileInfo += richTextBox_SensorParam.Text + "\r\n";
  4752. FileInfo += "\r\n";
  4753. FileInfo += "[助力参数]\r\n";
  4754. for(int i=0;i<15;i++)
  4755. {
  4756. FileInfo += AssistParams[i] + "\r\n";
  4757. }
  4758. FileInfo += "[调试参数]\r\n";
  4759. FileInfo += richTextBox_DebugParam.Text + "\r\n";
  4760. FileInfo += "\r\n";
  4761. FileInfo += "[历史信息]\r\n";
  4762. FileInfo += richTextBox_Record.Text + "\r\n";
  4763. FileInfo += "\r\n";
  4764. FileInfo += "[MOS内阻校准参数]\r\n";
  4765. FileInfo += textBox_MOS_K1.Text + ", ";
  4766. FileInfo += textBox_MOS_K2.Text + ", ";
  4767. FileInfo += textBox_MOS_K3.Text + ", ";
  4768. FileInfo += textBox_MOS_K4.Text + ", ";
  4769. FileInfo += textBox_MOS_K5.Text + ", ";
  4770. FileInfo += textBox_MOS_R1.Text + ", ";
  4771. FileInfo += textBox_MOS_R2.Text + ", ";
  4772. FileInfo += textBox_MOS_R3.Text + "\r\n";
  4773. FileInfo += "\r\n";
  4774. FileInfo += "[整车参数2]\r\n";
  4775. FileInfo += richTextBox_BikeParam2.Text + "\r\n";
  4776. FileInfo += "\r\n";
  4777. FileInfo += "[用户骑行参数]\r\n";
  4778. FileInfo += richTextBox_UsrRidesParam.Text + "\r\n";
  4779. FileInfo += "\r\n";
  4780. FileInfo += "[生产信息]\r\n";
  4781. FileInfo += "生产商: " + textBox_MAC.Text + "\r\n";
  4782. FileInfo += "生产地: " + textBox_MACAdd.Text + "\r\n";
  4783. FileInfo += "生产日期: " + textBox_MACDate.Text + "\r\n";
  4784. FileInfo += "产品标识: " + textBox_PP.Text + "\r\n";
  4785. FileInfo += "\r\n";
  4786. FileInfo += "[自定义信息]\r\n";
  4787. FileInfo += "自定义1: " + textBox_User1.Text + "\r\n";
  4788. FileInfo += "自定义2: " + textBox_User2.Text + "\r\n";
  4789. FileInfo += "自定义3: " + textBox_User3.Text + "\r\n";
  4790. FileInfo += "\r\n";
  4791. FileInfo += "[校验密钥]\r\n";
  4792. FileInfo += textBox_Key.Text + "\r\n";
  4793. FileInfo += "\r\n";
  4794. FileInfo += "[存储标志]\r\n";
  4795. FileInfo += "EEPROM: " + ((radioButton_EE_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  4796. FileInfo += "SIP: " + ((radioButton_SIP_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  4797. FileInfo += "\r\n";
  4798. FileInfo += Local_HdInformation;
  4799. FileInfo += "\r\n";
  4800. FileInfo += "文件格式: V2.0\r\n";
  4801. System.IO.File.WriteAllText(DataFileName, FileInfo);
  4802. Delay_ms(1000);
  4803. timer_500ms.Enabled = false;
  4804. MessageBox.Show("存储完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  4805. timer_500ms.Enabled = true;
  4806. //数据上传
  4807. if (myFtp.IsNetConnected == true)
  4808. {
  4809. string DataNow = DateTime.Now.ToString("yyyy-MM-dd");
  4810. //检查路径
  4811. if (myFtp.DirectoryExist("\\", toolStripTextBox_ServerPath.Text) == false)
  4812. {
  4813. myFtp.MakeDir(toolStripTextBox_ServerPath.Text);
  4814. }
  4815. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text, "Samples") == false)
  4816. {
  4817. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples");
  4818. }
  4819. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples", DataNow) == false)
  4820. {
  4821. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow);
  4822. }
  4823. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow, PD_PathName) == false)
  4824. {
  4825. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4826. }
  4827. //上传文件
  4828. bool result1 = myFtp.UploadFile(PIC_SaveFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4829. bool result2 = myFtp.UploadFile(DataFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4830. if ((result1 & result2) == true)
  4831. {
  4832. timer_500ms.Enabled = false;
  4833. MessageBoxTimeOut.Show("数据已上传!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  4834. timer_500ms.Enabled = true;
  4835. }
  4836. else
  4837. {
  4838. timer_500ms.Enabled = false;
  4839. MessageBox.Show("数据上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4840. timer_500ms.Enabled = true;
  4841. }
  4842. }
  4843. else
  4844. {
  4845. timer_500ms.Enabled = false;
  4846. MessageBox.Show("服务器断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4847. timer_500ms.Enabled = true;
  4848. }
  4849. Button_FacModeSaveResult.Text = "保存数据";
  4850. return;
  4851. } while (false);
  4852. timer_500ms.Enabled = false;
  4853. MessageBox.Show("保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4854. timer_500ms.Enabled = true;
  4855. Button_FacModeSaveResult.Text = "保存数据";
  4856. }
  4857. /// <summary>
  4858. /// 工具箱页面保存
  4859. /// </summary>
  4860. /// <param name="sender"></param>
  4861. /// <param name="e"></param>
  4862. private void 页面保存ToolStripMenuItem_Click(object sender, EventArgs e)
  4863. {
  4864. Double scaleX = PrimaryScreen.ScaleX;
  4865. Double scaleY = PrimaryScreen.ScaleY;
  4866. //保存页面
  4867. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  4868. Graphics g = Graphics.FromImage(bit);
  4869. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  4870. SaveFileDialog sf = new SaveFileDialog();
  4871. sf.Title = "页面保存";
  4872. sf.FileName = "MotorInfo_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".png";
  4873. sf.Filter = "图片|*.png";
  4874. timer_500ms.Enabled = false;
  4875. if (sf.ShowDialog() == DialogResult.OK)
  4876. {
  4877. bit.Save(sf.FileName);//默认保存格式为PNG,保存成jpg格式质量不是很好
  4878. }
  4879. timer_500ms.Enabled = true;
  4880. }
  4881. /// <summary>
  4882. /// 生产模式关机
  4883. /// </summary>
  4884. /// <param name="sender"></param>
  4885. /// <param name="e"></param>
  4886. private void Button_FacModePowerOff_Click(object sender, EventArgs e)
  4887. {
  4888. var Code_Off = new byte[5];
  4889. var Code_Reset = new byte[5];
  4890. Code_Off[0] = (byte)'O';
  4891. Code_Off[1] = (byte)'F';
  4892. Code_Off[2] = (byte)'F';
  4893. Code_Off[3] = (byte)'.';
  4894. Code_Off[4] = (byte)'.';
  4895. Code_Reset[0] = (byte)'R';
  4896. Code_Reset[1] = (byte)'E';
  4897. Code_Reset[2] = (byte)'S';
  4898. Code_Reset[3] = (byte)'E';
  4899. Code_Reset[4] = (byte)'T';
  4900. timer_500ms.Enabled = false;
  4901. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  4902. {
  4903. timer_500ms.Enabled = true;
  4904. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  4905. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  4906. PowerOffAckStatus = false;
  4907. Delay_ms(250);
  4908. int TryCnt = 3;
  4909. while ((TryCnt--) >= 0)
  4910. {
  4911. if (!PowerOffAckStatus)
  4912. {
  4913. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  4914. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  4915. PowerOffAckStatus = false;
  4916. Delay_ms(250);
  4917. }
  4918. else break;
  4919. }
  4920. if (PowerOffAckStatus)
  4921. {
  4922. timer_500ms.Enabled = false;
  4923. MessageBox.Show("已关机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  4924. timer_500ms.Enabled = true;
  4925. }
  4926. else
  4927. {
  4928. timer_500ms.Enabled = false;
  4929. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4930. timer_500ms.Enabled = true;
  4931. }
  4932. }
  4933. timer_500ms.Enabled = true;
  4934. }
  4935. //仪表电源键按下
  4936. private void button_OBC_ButtonPower_Click(object sender, EventArgs e)
  4937. {
  4938. var Code = new byte[2];
  4939. Code[0] = 0;
  4940. Code[1] = 0b00100000;
  4941. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4942. }
  4943. /// <summary>
  4944. /// 仪表加键按下
  4945. /// </summary>
  4946. /// <param name="sender"></param>
  4947. /// <param name="e"></param>
  4948. private void button_OBC_ButtonAcc_Click(object sender, EventArgs e)
  4949. {
  4950. var Code = new byte[2];
  4951. Code[0] = 0;
  4952. Code[1] = 0b00010000;
  4953. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4954. }
  4955. /// <summary>
  4956. /// 仪表减键按下
  4957. /// </summary>
  4958. /// <param name="sender"></param>
  4959. /// <param name="e"></param>
  4960. private void button_OBC_ButtonDec_Click(object sender, EventArgs e)
  4961. {
  4962. var Code = new byte[2];
  4963. Code[0] = 0;
  4964. Code[1] = 0b00001000;
  4965. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4966. }
  4967. /// <summary>
  4968. /// 仪表Walk键按下
  4969. /// </summary>
  4970. /// <param name="sender"></param>
  4971. /// <param name="e"></param>
  4972. private void button_OBC_ButtonWalk_Click(object sender, EventArgs e)
  4973. {
  4974. var Code = new byte[2];
  4975. Code[0] = 0;
  4976. Code[1] = 0b00000100;
  4977. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4978. }
  4979. /// <summary>
  4980. /// 仪表Light键按下
  4981. /// </summary>
  4982. /// <param name="sender"></param>
  4983. /// <param name="e"></param>
  4984. private void button_OBC_ButtonLight_Click(object sender, EventArgs e)
  4985. {
  4986. var Code = new byte[2];
  4987. Code[0] = 0;
  4988. Code[1] = 0b00000010;
  4989. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4990. }
  4991. /// <summary>
  4992. /// 仪表Set键按下
  4993. /// </summary>
  4994. /// <param name="sender"></param>
  4995. /// <param name="e"></param>
  4996. private void button_OBC_ButtonSet_Click(object sender, EventArgs e)
  4997. {
  4998. var Code = new byte[2];
  4999. Code[0] = 0;
  5000. Code[1] = 0b00000001;
  5001. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5002. }
  5003. /// <summary>
  5004. /// 导出电机故障日志
  5005. /// </summary>
  5006. /// <param name="sender"></param>
  5007. /// <param name="e"></param>
  5008. private void button_ExportLog_Click(object sender, EventArgs e)
  5009. {
  5010. var Address = new byte[4];
  5011. UInt32 Address_Begin;
  5012. UInt32 Addres_End;
  5013. string textBox_Address_Begin = textBox_LogAddrBegin.Text;
  5014. string textBox_Address_End = textBox_LogAddrEnd.Text;
  5015. richTextBox_Record.Clear();
  5016. textBox_LogAddrBegin.ReadOnly = true;
  5017. textBox_LogAddrEnd.ReadOnly = true;
  5018. if (!mySerialProcess.mySerial.IsOpen)
  5019. {
  5020. timer_500ms.Enabled = false;
  5021. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5022. timer_500ms.Enabled = true;
  5023. return;
  5024. }
  5025. if ((textBox_Address_Begin == string.Empty) || (textBox_Address_End == string.Empty))
  5026. {
  5027. timer_500ms.Enabled = false;
  5028. MessageBox.Show("请输入日志存储起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5029. timer_500ms.Enabled = true;
  5030. return;
  5031. }
  5032. else
  5033. {
  5034. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin, false);
  5035. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  5036. Address = mySerialProcess.HexStringToBytes(textBox_Address_End, false);
  5037. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  5038. if (Addres_End <= Address_Begin)
  5039. {
  5040. timer_500ms.Enabled = false;
  5041. MessageBox.Show("结束地址应大于起始地址!", "提示");
  5042. timer_500ms.Enabled = true;
  5043. return;
  5044. }
  5045. else if (((Addres_End - Address_Begin + 1) % 128) != 0) //
  5046. {
  5047. timer_500ms.Enabled = false;
  5048. MessageBox.Show("(结束地址 - 起始地址 + 1)应为128整数倍!", "提示");
  5049. timer_500ms.Enabled = true;
  5050. return;
  5051. }
  5052. else
  5053. {
  5054. UInt32 ReadCount = 0;
  5055. button_ExportLog.Text = "导出中...";
  5056. button_ExportLog.Enabled = false;
  5057. ReadCount = (Addres_End - Address_Begin + 1) / 128;
  5058. for (ushort i = 0; i < ReadCount; i++)
  5059. {
  5060. var SendByte = new byte[8];
  5061. UInt32 Address_Temp_Begin;
  5062. UInt32 Address_Temp_End;
  5063. Address_Temp_Begin = Address_Begin + 128 * (UInt32)i;
  5064. SendByte[0] = (byte)(Address_Temp_Begin >> 24);
  5065. SendByte[1] = (byte)(Address_Temp_Begin >> 16);
  5066. SendByte[2] = (byte)(Address_Temp_Begin >> 8);
  5067. SendByte[3] = (byte)(Address_Temp_Begin);
  5068. Address_Temp_End = Address_Temp_Begin + 127;
  5069. SendByte[4] = (byte)(Address_Temp_End >> 24);
  5070. SendByte[5] = (byte)(Address_Temp_End >> 16);
  5071. SendByte[6] = (byte)(Address_Temp_End >> 8);
  5072. SendByte[7] = (byte)(Address_Temp_End);
  5073. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  5074. Delay_ms(200);//Thread.Sleep(200);
  5075. }
  5076. button_ExportLog.Text = "导出日志";
  5077. button_ExportLog.Enabled = true;
  5078. }
  5079. }
  5080. }
  5081. /// <summary>
  5082. /// 保存日志信息
  5083. /// </summary>
  5084. /// <param name="sender"></param>
  5085. /// <param name="e"></param>
  5086. private void button_SaveRecordInfo_Click(object sender, EventArgs e)
  5087. {
  5088. string SaveInfo = "";
  5089. if (richTextBox_Record.Text == string.Empty)
  5090. {
  5091. timer_500ms.Enabled = false;
  5092. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  5093. timer_500ms.Enabled = true;
  5094. return;
  5095. }
  5096. //获取保存信息
  5097. SaveInfo += "读取时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  5098. SaveInfo += "电机型号:" + textBox_FacModeName.Text + "\r\n";
  5099. SaveInfo += "电机SN:" + textBox_FacModeNum.Text + "\r\n";
  5100. SaveInfo += "硬件版本:" + textBox_FacModeHW.Text + "\r\n";
  5101. SaveInfo += "软件版本:" + textBox_FacModeFW.Text + "\r\n";
  5102. SaveInfo += "\r\n";
  5103. SaveInfo += richTextBox_Record.Text;
  5104. //设置保存路径和文件名
  5105. SaveFileDialog sf = new SaveFileDialog();
  5106. sf.Title = "数据保存";
  5107. sf.FileName = "MotorLog_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".ttlog";
  5108. sf.FileName.Replace(" ", "");
  5109. sf.Filter = "日志|*.ttlog";
  5110. if (sf.ShowDialog() == DialogResult.OK)
  5111. {
  5112. System.IO.File.AppendAllText(sf.FileName, SaveInfo);
  5113. }
  5114. }
  5115. /// <summary>
  5116. /// 双击修改日志起始地址
  5117. /// </summary>
  5118. /// <param name="sender"></param>
  5119. /// <param name="e"></param>
  5120. private void label_LogAddrBegin_DoubleClick_1(object sender, EventArgs e)
  5121. {
  5122. textBox_LogAddrBegin.ReadOnly = false;
  5123. }
  5124. /// <summary>
  5125. /// 双击修改日志结束地址
  5126. /// </summary>
  5127. /// <param name="sender"></param>
  5128. /// <param name="e"></param>
  5129. private void label88_DoubleClick(object sender, EventArgs e)
  5130. {
  5131. textBox_LogAddrEnd.ReadOnly = false;
  5132. }
  5133. /// <summary>
  5134. /// 存储器自动读取选择
  5135. /// </summary>
  5136. /// <param name="sender"></param>
  5137. /// <param name="e"></param>
  5138. private void checkBox_ReadRanFlash_AutoSW_CheckedChanged(object sender, EventArgs e)
  5139. {
  5140. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  5141. {
  5142. //检查串口是否打开
  5143. if (!mySerialProcess.mySerial.IsOpen)
  5144. {
  5145. timer_500ms.Enabled = false;
  5146. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5147. timer_500ms.Enabled = true;
  5148. checkBox_ReadRanFlash_AutoSW.Checked = false;
  5149. return;
  5150. }
  5151. }
  5152. }
  5153. /// <summary>
  5154. /// 系统开机按钮
  5155. /// </summary>
  5156. /// <param name="sender"></param>
  5157. /// <param name="e"></param>
  5158. private void 开机ToolStripMenuItem_Click(object sender, EventArgs e)
  5159. {
  5160. byte[] Data = new byte[1];
  5161. Data[0] = 0xF1;
  5162. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  5163. }
  5164. /// <summary>
  5165. /// 系统关机按钮
  5166. /// </summary>
  5167. /// <param name="sender"></param>
  5168. /// <param name="e"></param>
  5169. private void 关机ToolStripMenuItem_Click(object sender, EventArgs e)
  5170. {
  5171. byte[] Data = new byte[1];
  5172. Data[0] = 0xF0;
  5173. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  5174. }
  5175. /// <summary>
  5176. /// 连接开机选择
  5177. /// </summary>
  5178. /// <param name="sender"></param>
  5179. /// <param name="e"></param>
  5180. private void 连接开机ToolStripMenuItem_Click(object sender, EventArgs e)
  5181. {
  5182. //输入用户名
  5183. EnterForm1.ShowDialog();
  5184. try
  5185. {
  5186. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5187. {
  5188. if (EnterForm1.comboBox_User.Text == "管理员")
  5189. {
  5190. 连接开机ToolStripMenuItem.Checked = !连接开机ToolStripMenuItem.Checked;
  5191. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5192. }
  5193. else
  5194. {
  5195. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5196. }
  5197. }
  5198. else
  5199. {
  5200. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5201. }
  5202. }
  5203. catch (Exception)
  5204. {
  5205. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5206. }
  5207. }
  5208. /// <summary>
  5209. /// 断开关机选择
  5210. /// </summary>
  5211. /// <param name="sender"></param>
  5212. /// <param name="e"></param>
  5213. private void 断开关机ToolStripMenuItem_Click(object sender, EventArgs e)
  5214. {
  5215. //输入用户名
  5216. EnterForm1.ShowDialog();
  5217. try
  5218. {
  5219. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5220. {
  5221. if (EnterForm1.comboBox_User.Text == "管理员")
  5222. {
  5223. 断开关机ToolStripMenuItem.Checked = !断开关机ToolStripMenuItem.Checked;
  5224. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5225. }
  5226. else
  5227. {
  5228. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5229. }
  5230. }
  5231. else
  5232. {
  5233. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5234. }
  5235. }
  5236. catch (Exception)
  5237. {
  5238. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5239. }
  5240. }
  5241. /// <summary>
  5242. /// 识别通讯盒选择
  5243. /// </summary>
  5244. /// <param name="sender"></param>
  5245. /// <param name="e"></param>
  5246. private void 识别通讯盒ToolStripMenuItem_Click(object sender, EventArgs e)
  5247. {
  5248. //输入用户名
  5249. EnterForm1.ShowDialog();
  5250. try
  5251. {
  5252. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5253. {
  5254. if (EnterForm1.comboBox_User.Text == "管理员")
  5255. {
  5256. 识别通讯盒ToolStripMenuItem.Checked = !识别通讯盒ToolStripMenuItem.Checked;
  5257. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5258. }
  5259. else
  5260. {
  5261. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5262. }
  5263. }
  5264. else
  5265. {
  5266. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5267. }
  5268. }
  5269. catch (Exception)
  5270. {
  5271. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5272. }
  5273. }
  5274. /// <summary>
  5275. /// 将配置信息导出为cfg文件
  5276. /// </summary>
  5277. private void ConfigFileSave(bool DeleteFlag, string FileName)
  5278. {
  5279. if (DeleteFlag)
  5280. {
  5281. if (File.Exists(FileName))
  5282. File.Delete(FileName);
  5283. }
  5284. string CfgFileInfo = "";
  5285. CfgFileInfo += "[PortSet]" + "\r\n";
  5286. CfgFileInfo += "PortNum:" + toolStripComboBox_ComNum.Text + "\r\n";
  5287. CfgFileInfo += "PortBaudrate:" + "115200" + "\r\n";
  5288. CfgFileInfo += "AutoOn:" + 连接开机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5289. CfgFileInfo += "AutoOff:" + 断开关机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5290. CfgFileInfo += "CheckCDL:" + 识别通讯盒ToolStripMenuItem.Checked.ToString() + "\r\n";
  5291. CfgFileInfo += "\r\n";
  5292. CfgFileInfo += "[Option]" + "\r\n";
  5293. CfgFileInfo += "SaveWhenWrite:" + 写入存储ToolStripMenuItem.Checked.ToString() + "\r\n";
  5294. CfgFileInfo += "\r\n";
  5295. CfgFileInfo += "[ServerSet]" + "\r\n";
  5296. CfgFileInfo += "PathName:" + toolStripTextBox_ServerPath.Text + "\r\n";
  5297. CfgFileInfo += "\r\n";
  5298. CfgFileInfo += "[MacInfo]" + "\r\n";
  5299. CfgFileInfo += "MacName:" + toolStripTextBox_MAC.Text + "\r\n";
  5300. CfgFileInfo += "MacAddress:" + toolStripTextBoxMACAddr.Text + "\r\n";
  5301. CfgFileInfo += "MacDate:" + toolStripTextBox_MACDate.Text + "\r\n";
  5302. CfgFileInfo += "MacPdInfo:" + toolStripTextBox_MACPD.Text + "\r\n";
  5303. CfgFileInfo += "\r\n";
  5304. CfgFileInfo += "[LogAddress]" + "\r\n";
  5305. CfgFileInfo += "BeginAddress:" + textBox_LogAddrBegin.Text + "\r\n";
  5306. CfgFileInfo += "EndAddress:" + textBox_LogAddrEnd.Text + "\r\n";
  5307. CfgFileInfo += "\r\n";
  5308. CfgFileInfo += "[MotorType]" + "\r\n";
  5309. CfgFileInfo += "MidMotor:" + 中置电机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5310. CfgFileInfo += "HubMotor:" + 轮毂电机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5311. CfgFileInfo += "\r\n";
  5312. CfgFileInfo += "[CheckValue]" + "\r\n";
  5313. CfgFileInfo += "Voltage:" + toolStripTextBox_ThVol.Text + "\r\n";
  5314. CfgFileInfo += "Current:" + toolStripTextBox_ThCur.Text + "\r\n";
  5315. CfgFileInfo += "MotorSpeed:" + toolStripTextBox_ThSpeed.Text + "\r\n";
  5316. CfgFileInfo += "Torque:" + toolStripTextBox_ThTor.Text + "\r\n";
  5317. CfgFileInfo += "Cadence:" + toolStripTextBox_ThCad.Text + "\r\n";
  5318. CfgFileInfo += "BikeSpeed:" + toolStripTextBox_ThBikeSpeed.Text + "\r\n";
  5319. CfgFileInfo += "T_PCB:" + toolStripTextBox_ThT_PCB.Text + "\r\n";
  5320. CfgFileInfo += "T_MCU:" + toolStripTextBox_ThT_MCU.Text + "\r\n";
  5321. CfgFileInfo += "T_Motor:" + toolStripTextBox_ThT_Motor.Text + "\r\n";
  5322. CfgFileInfo += "\r\n";
  5323. CfgFileInfo += "[MosCalK]" + "\r\n";
  5324. CfgFileInfo += "K1-K5:" + toolStripTextBox_MosCalK.Text + "\r\n";
  5325. CfgFileInfo += "MOS1:" + toolStripTextBox_MOS1.Text + "\r\n";
  5326. CfgFileInfo += "MOS2:" + toolStripTextBox_MOS2.Text + "\r\n";
  5327. CfgFileInfo += "MOS3:" + toolStripTextBox_MOS3.Text + "\r\n";
  5328. CfgFileInfo += "\r\n";
  5329. CfgFileInfo += "[ProtocolType]" + "\r\n";
  5330. CfgFileInfo += "CAN:" + cANToolStripMenuItem.Checked.ToString() + "\r\n";
  5331. CfgFileInfo += "UART:" + uARTToolStripMenuItem.Checked.ToString() + "\r\n";
  5332. CfgFileInfo += "\r\n";
  5333. CfgFileInfo += "[AutoUpdate]" + "\r\n";
  5334. CfgFileInfo += "AutoUpdate:" + 打开ToolStripMenuItem.Checked.ToString() + "\r\n";
  5335. CfgFileInfo += "\r\n";
  5336. CfgFileInfo += "[AngleCal]" + "\r\n";
  5337. CfgFileInfo += "MaxDiffLimit:" + textBox_AngleDiffTh.Text + "\r\n";
  5338. CfgFileInfo += "ZeroDiffLimit:" + textBox_AngleZeroTh.Text + "\r\n";
  5339. System.IO.File.WriteAllText(FileName, CfgFileInfo);
  5340. }
  5341. /// <summary>
  5342. /// 配置状态更新,点击时保存
  5343. /// </summary>
  5344. private void ConfigFileSave_Click(object sender, EventArgs e)
  5345. {
  5346. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5347. }
  5348. /// <summary>
  5349. /// 文本框修改结束,回车保存
  5350. /// </summary>
  5351. /// <param name="sender"></param>
  5352. /// <param name="e"></param>
  5353. private void ConfigFileSave_KeyDown(object sender, KeyEventArgs e)
  5354. {
  5355. if (e.KeyCode == Keys.Enter)
  5356. {
  5357. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5358. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  5359. }
  5360. }
  5361. /// <summary>
  5362. /// 弹出扫码按钮
  5363. /// </summary>
  5364. /// <param name="sender"></param>
  5365. /// <param name="e"></param>
  5366. private void button_ScanCode_Click(object sender, EventArgs e)
  5367. {
  5368. Scan scan_form = new Scan();
  5369. scan_form.ShowDialog();
  5370. do
  5371. {
  5372. if (scan_form.textBox_Scan.Text == string.Empty)
  5373. {
  5374. timer_500ms.Enabled = false;
  5375. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5376. timer_500ms.Enabled = true;
  5377. break;
  5378. }
  5379. string ScanInfo = scan_form.textBox_Scan.Text;
  5380. string regexInfo = "";
  5381. string[] InfoList = { "" };
  5382. try
  5383. {
  5384. if (中置电机ToolStripMenuItem.Checked == true)
  5385. {
  5386. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  5387. InfoList = Regex.Split(ScanInfo, regexInfo, RegexOptions.IgnoreCase);
  5388. }
  5389. else if (轮毂电机ToolStripMenuItem.Checked == true)
  5390. {
  5391. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  5392. string Model = InfoList[0];
  5393. string Spec = InfoList[1];
  5394. string Sn = InfoList[2];
  5395. InfoList[0] = Model.Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  5396. InfoList[1] = Sn;
  5397. }
  5398. }
  5399. catch (Exception)
  5400. {
  5401. MessageBox.Show("格式错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5402. return;
  5403. }
  5404. if (InfoList.Length >= 2)
  5405. {
  5406. //写入型号
  5407. textBox_FacModeName.Text = InfoList[0];
  5408. string Mode = textBox_FacModeName.Text;
  5409. var ModeArray = new byte[16];
  5410. for (ushort i = 0; i < Mode.Length; i++)
  5411. {
  5412. ModeArray[i] = (byte)Mode[i];
  5413. }
  5414. if (Mode.Length < 16)
  5415. {
  5416. ModeArray[Mode.Length] = (byte)'.';
  5417. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  5418. {
  5419. ModeArray[Mode.Length + 1 + i] = 0x20;
  5420. }
  5421. }
  5422. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  5423. //写入SN
  5424. textBox_FacModeNum.Text = InfoList[1];
  5425. string SN = textBox_FacModeNum.Text;
  5426. var SNArray = new byte[16];
  5427. for (ushort i = 0; i < SN.Length; i++)
  5428. {
  5429. SNArray[i] = (byte)SN[i];
  5430. }
  5431. if (SN.Length < 16)
  5432. {
  5433. SNArray[SN.Length] = (byte)'.';
  5434. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  5435. {
  5436. SNArray[SN.Length + 1 + i] = 0x20;
  5437. }
  5438. }
  5439. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  5440. }
  5441. else
  5442. {
  5443. timer_500ms.Enabled = false;
  5444. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5445. timer_500ms.Enabled = true;
  5446. break;
  5447. }
  5448. } while (false);
  5449. scan_form.Dispose();
  5450. }
  5451. /// <summary>
  5452. /// 切换电机类型
  5453. /// </summary>
  5454. /// <param name="sender"></param>
  5455. /// <param name="e"></param>
  5456. private void 中置电机ToolStripMenuItem_Click(object sender, EventArgs e)
  5457. {
  5458. 中置电机ToolStripMenuItem.Checked = true;
  5459. 轮毂电机ToolStripMenuItem.Checked = false;
  5460. toolStripTextBox_MACPD.Text = "MM_MC1";
  5461. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  5462. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5463. }
  5464. /// <summary>
  5465. /// 切换电机类型
  5466. /// </summary>
  5467. /// <param name="sender"></param>
  5468. /// <param name="e"></param>
  5469. private void 轮毂电机ToolStripMenuItem_Click(object sender, EventArgs e)
  5470. {
  5471. 中置电机ToolStripMenuItem.Checked = false;
  5472. 轮毂电机ToolStripMenuItem.Checked = true;
  5473. toolStripTextBox_MACPD.Text = "GF_250_1";
  5474. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  5475. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5476. }
  5477. /// <summary>
  5478. /// 获取配置文件日期
  5479. /// </summary>
  5480. /// <param name="DisAll"></param>
  5481. private void GetDateList(bool DisAll)
  5482. {
  5483. string[] DateList = { "" };
  5484. //从服务器更新日期列表
  5485. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  5486. {
  5487. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
  5488. }
  5489. //从本地更新日期列表
  5490. else
  5491. {
  5492. DateList = Directory.GetDirectories(localInfo.LocalPath + "\\" + localInfo.CfgPathName);
  5493. }
  5494. comboBox_FacModeCfgDate.Items.Clear();
  5495. comboBox_CheckModeCfgDate.Items.Clear();
  5496. //日期列表加载
  5497. if (DisAll == true)
  5498. {
  5499. comboBox_FacModeCfgDate.Items.Add("显示近期");
  5500. comboBox_CheckModeCfgDate.Items.Add("显示近期");
  5501. comboBox_FacModeCfgDate.Items.Add("---");
  5502. comboBox_CheckModeCfgDate.Items.Add("---");
  5503. foreach (var file in DateList)
  5504. {
  5505. comboBox_FacModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5506. comboBox_CheckModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5507. }
  5508. }
  5509. else
  5510. {
  5511. if (DateList.Length > 10)
  5512. {
  5513. comboBox_FacModeCfgDate.Items.Add("显示全部");
  5514. comboBox_CheckModeCfgDate.Items.Add("显示全部");
  5515. comboBox_FacModeCfgDate.Items.Add("---");
  5516. comboBox_CheckModeCfgDate.Items.Add("---");
  5517. }
  5518. for (int i = (DateList.Length > 10) ? (DateList.Length - 10) : 0; i < DateList.Length; i++)//显示最近10个日期
  5519. {
  5520. comboBox_FacModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  5521. comboBox_CheckModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  5522. }
  5523. }
  5524. }
  5525. /// <summary>
  5526. /// 获取配置文件列表
  5527. /// </summary>
  5528. /// <param name="date"></param>
  5529. private void GetFileListFrom(string date)
  5530. {
  5531. string[] FileList = { "" };
  5532. //从服务器更新文件列表
  5533. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  5534. {
  5535. FileList = myFtp.GetFileNameList(toolStripTextBox_ServerPath.Text + "/cfg/" + date);
  5536. }
  5537. else
  5538. {
  5539. FileList = Directory.GetFiles(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + date);
  5540. }
  5541. comboBox_CheckModeCfgFile.Items.Clear();
  5542. comboBox_FacModeCfgFile.Items.Clear();
  5543. foreach (var file in FileList)
  5544. {
  5545. if (file.Contains(".ttcfg"))
  5546. {
  5547. comboBox_CheckModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5548. comboBox_FacModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5549. }
  5550. }
  5551. }
  5552. /// <summary>
  5553. /// 检验模式选择文件日期
  5554. /// </summary>
  5555. /// <param name="sender"></param>
  5556. /// <param name="e"></param>
  5557. private void comboBox_CheckModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  5558. {
  5559. if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示全部")
  5560. {
  5561. GetDateList(true);
  5562. }
  5563. else if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示近期")
  5564. {
  5565. GetDateList(false);
  5566. }
  5567. else
  5568. {
  5569. comboBox_CheckModeCfgFile.Text = "";
  5570. GetFileListFrom(comboBox_CheckModeCfgDate.SelectedItem.ToString());
  5571. }
  5572. }
  5573. /// <summary>
  5574. /// 配置模式选择文件日期
  5575. /// </summary>
  5576. /// <param name="sender"></param>
  5577. /// <param name="e"></param>
  5578. private void comboBox_FacModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  5579. {
  5580. if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示全部")
  5581. {
  5582. GetDateList(true);
  5583. }
  5584. else if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示近期")
  5585. {
  5586. GetDateList(false);
  5587. }
  5588. else
  5589. {
  5590. comboBox_FacModeCfgFile.Text = "";
  5591. GetFileListFrom(comboBox_FacModeCfgDate.SelectedItem.ToString());
  5592. }
  5593. }
  5594. /// <summary>
  5595. /// 选中量产模式
  5596. /// </summary>
  5597. /// <param name="sender"></param>
  5598. /// <param name="e"></param>
  5599. private void tabControl1_Selected(object sender, TabControlEventArgs e)
  5600. {
  5601. //更新生产配置文件目录
  5602. GetDateList(false);
  5603. }
  5604. /// <summary>
  5605. /// 量产测试结束
  5606. /// </summary>
  5607. /// <param name=""></param>
  5608. private void FacMode_Stop(bool OK_Flag)
  5609. {
  5610. //打开开始按钮
  5611. button__FacMode_Start.Enabled = true;
  5612. //系统关机
  5613. var Code = new byte[32];//发送的指令数据
  5614. Code[0] = 0xF0;
  5615. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5616. //关闭串口
  5617. //mySerialProcess.SerialClose(false);
  5618. //路径设置
  5619. string LocalSavePath = "";
  5620. string ServerSavePath = "";
  5621. if (OK_Flag)
  5622. {
  5623. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "OK\\";
  5624. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/OK/";
  5625. }
  5626. else
  5627. {
  5628. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "FAIL\\";
  5629. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/FAIL/";
  5630. }
  5631. if (Directory.Exists(LocalSavePath) == false)
  5632. {
  5633. Directory.CreateDirectory(LocalSavePath);
  5634. }
  5635. //保存和上传
  5636. string LogSavePath = "";
  5637. string LogSaveFileName = "";
  5638. string ProductInfo = textBox_FacModeScan.Text.Replace(" ", "_");
  5639. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  5640. if (Directory.Exists(LogSavePath) == false)
  5641. {
  5642. Directory.CreateDirectory(LogSavePath);
  5643. }
  5644. //测试页面
  5645. Double scaleX = PrimaryScreen.ScaleX;
  5646. Double scaleY = PrimaryScreen.ScaleY;
  5647. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  5648. Graphics g = Graphics.FromImage(bit);
  5649. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  5650. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  5651. bit.Save(LogSaveFileName);
  5652. //上传测试页面到服务器
  5653. if (myFtp.IsNetConnected == true)
  5654. {
  5655. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  5656. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  5657. {
  5658. myFtp.MakeDir(ServerSavePath + DateNow);
  5659. }
  5660. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  5661. {
  5662. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  5663. }
  5664. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  5665. if (result == true)
  5666. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  5667. }
  5668. else
  5669. {
  5670. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  5671. }
  5672. //测试记录
  5673. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  5674. string file_str = "";
  5675. file_str += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  5676. file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  5677. file_str += "检验记录:\r\n" + richTextBox_FacModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  5678. file_str += "检验结果:\r\n" + label_FacModeResult.Text + "\r\n\r\n";
  5679. file_str += Local_HdInformation;
  5680. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  5681. //上传测试记录到服务器
  5682. if (myFtp.IsNetConnected == true)
  5683. {
  5684. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  5685. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  5686. {
  5687. myFtp.MakeDir(ServerSavePath + DateNow);
  5688. }
  5689. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  5690. {
  5691. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  5692. }
  5693. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  5694. if (result == true)
  5695. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  5696. }
  5697. else
  5698. {
  5699. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  5700. }
  5701. //扫码框清空
  5702. textBox_FacModeScan.Text = "";
  5703. }
  5704. /// <summary>
  5705. /// 量产测试开始
  5706. /// </summary>
  5707. /// <param name="sender"></param>
  5708. /// <param name="e"></param>
  5709. private void button__FacMode_Start_Click(object sender, EventArgs e)
  5710. {
  5711. //关闭测试项目编辑
  5712. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  5713. foreach (Control c in groupBox2.Controls)
  5714. {
  5715. if (c is CheckBox)
  5716. c.Enabled = false;
  5717. }
  5718. WriteLockStatus = true;
  5719. //检查配置文件
  5720. if (comboBox_FacModeCfgFile.Text == "")
  5721. {
  5722. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5723. return;
  5724. }
  5725. //开始测试
  5726. TestStart();
  5727. }
  5728. /// <summary>
  5729. /// 测试子函数
  5730. /// </summary>
  5731. private void TestStart()
  5732. {
  5733. //初始化标签
  5734. FacModelLabelInit();
  5735. richTextBox_FacModeLog.Clear();
  5736. //按钮禁止操作
  5737. button__FacMode_Start.Enabled = false;
  5738. //记录配置文件
  5739. richTextBox_FacModeLog.AppendText("配置文件:" + comboBox_FacModeCfgDate.Text + " / " + comboBox_FacModeCfgFile.Text + "\r\n");
  5740. //检查打标信息格式
  5741. label_FacModeStatus.Text = "检查扫码信息";
  5742. Delay_ms(500);
  5743. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  5744. if (textBox_FacModeScan.Text == string.Empty)
  5745. {
  5746. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5747. button__FacMode_Start.Enabled = true;
  5748. return;
  5749. }
  5750. try
  5751. {
  5752. if (中置电机ToolStripMenuItem.Checked == true)
  5753. {
  5754. if (textBox_FacModeScan.Text.Split(' ').Length != 7)
  5755. {
  5756. label_FacModeStatus.Text = "存在故障!";
  5757. label_FacModeResult.BackColor = Color.Red;
  5758. label_FacModeResult.Text = "标签格式错误";
  5759. button__FacMode_Start.Enabled = true;
  5760. return;
  5761. }
  5762. }
  5763. else if (轮毂电机ToolStripMenuItem.Checked == true)
  5764. {
  5765. if (textBox_FacModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  5766. {
  5767. label_FacModeStatus.Text = "存在故障!";
  5768. label_FacModeResult.BackColor = Color.Red;
  5769. label_FacModeResult.Text = "标签格式错误";
  5770. button__FacMode_Start.Enabled = true;
  5771. return;
  5772. }
  5773. }
  5774. }
  5775. catch (System.Exception)
  5776. {
  5777. label_FacModeStatus.Text = "存在故障!";
  5778. label_FacModeResult.BackColor = Color.Red;
  5779. label_FacModeResult.Text = "标签格式错误";
  5780. button__FacMode_Start.Enabled = true;
  5781. return;
  5782. }
  5783. //打开串口
  5784. mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false);
  5785. if (!mySerialProcess.mySerial.IsOpen)
  5786. {
  5787. MessageBox.Show("请检查串口连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5788. //按钮禁止操作
  5789. button__FacMode_Start.Enabled = true;
  5790. return;
  5791. }
  5792. //流水号计数
  5793. int serial = Convert.ToInt32(label_FacModeSerial.Text);
  5794. serial += 1;
  5795. label_FacModeSerial.Text = serial.ToString();
  5796. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, serial.ToString());
  5797. //创建线程,执行测试任务
  5798. Thread th = new Thread(FacModeTest_Task);
  5799. th.Start();
  5800. }
  5801. /// <summary>
  5802. /// 执行一次测试任务
  5803. /// </summary>
  5804. private void FacModeTest_Task()
  5805. {
  5806. //开始测试
  5807. richTextBox_FacModeLog.AppendText("产品标签:" + textBox_FacModeScan.Text + "\r\n");
  5808. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  5809. //变量定义
  5810. var Code = new byte[255];//发送的指令数据
  5811. label_FacModeStatus.Text = "开始测试";
  5812. BootInfo = "";
  5813. Delay_ms(500);
  5814. label_FacModeStatus.Text = "系统开机";
  5815. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  5816. if (uARTToolStripMenuItem.Checked)
  5817. {
  5818. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送复位指令,切换联动装置盒波特率" + "\r\n");
  5819. Code[0] = (byte)'R';
  5820. Code[1] = (byte)'E';
  5821. Code[2] = (byte)'S';
  5822. Code[3] = (byte)'E';
  5823. Code[4] = (byte)'T';
  5824. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  5825. Delay_ms(500);
  5826. }
  5827. //发送开机指令
  5828. //确保测试前先关机,发送关机指令再发送开机指令
  5829. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  5830. Code[0] = 0xF0;
  5831. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5832. Delay_ms(1500);
  5833. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  5834. Code[0] = 0xF1;
  5835. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5836. ACK_WaitCnt = 0;
  5837. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  5838. while (ACK_WaitCnt <= 20) ; //10s,等待开机成功,联动装置盒控制器接口波特率需等待5s接口自动切换为9600
  5839. //检查BOOT版本
  5840. if (BootInfo != string.Empty)
  5841. {
  5842. label_FacModeBootVer.BackColor = Color.Green;
  5843. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  5844. Delay_ms(500);
  5845. }
  5846. else
  5847. {
  5848. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
  5849. label_FacModeStatus.Text = "存在故障!";
  5850. label_FacModeResult.BackColor = Color.Red;
  5851. label_FacModeResult.Text = "测试异常";
  5852. Delay_ms(500);
  5853. //存储异常并上传
  5854. FacMode_Stop(false);
  5855. return;
  5856. }
  5857. //系统清除
  5858. if (checkBox_FacModeSysClear.Checked)
  5859. {
  5860. do
  5861. {
  5862. #if false
  5863. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  5864. {
  5865. Code[0] = 0x00;//5S协议
  5866. Code[1] = 0x00;
  5867. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5868. Delay_ms(500);
  5869. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5870. Delay_ms(500);
  5871. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  5872. }
  5873. #endif
  5874. //发送系统清除指令
  5875. label_FacModeStatus.Text = "系统清除";
  5876. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除" + "\r\n");
  5877. Code[0] = (byte)'C';
  5878. Code[1] = (byte)'L';
  5879. Code[2] = (byte)'E';
  5880. Code[3] = (byte)'A';
  5881. Code[4] = (byte)'R';
  5882. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  5883. WriteACK = false;
  5884. ACK_WaitCnt = 0;
  5885. while (ACK_WaitCnt <= 6); //3s
  5886. //等待系统清除完成指令
  5887. if (WriteACK == true)
  5888. {
  5889. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  5890. label_FacModeSysClear.BackColor = Color.Green;
  5891. }
  5892. else
  5893. {
  5894. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除,重发第1次" + "\r\n");
  5895. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  5896. ACK_WaitCnt = 0;
  5897. while (ACK_WaitCnt <= 6) ; //3s
  5898. //等待系统清除完成指令
  5899. if (WriteACK == true)
  5900. {
  5901. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  5902. label_FacModeSysClear.BackColor = Color.Green;
  5903. }
  5904. else
  5905. {
  5906. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除,重发第2次" + "\r\n");
  5907. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  5908. ACK_WaitCnt = 0;
  5909. while (ACK_WaitCnt <= 6) ; //3s
  5910. //等待系统清除完成指令
  5911. if (WriteACK == true)
  5912. {
  5913. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  5914. label_FacModeSysClear.BackColor = Color.Green;
  5915. }
  5916. else
  5917. {
  5918. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除失败" + "\r\n");
  5919. label_FacModeStatus.Text = "存在故障!";
  5920. label_FacModeResult.BackColor = Color.Red;
  5921. label_FacModeResult.Text = "测试异常";
  5922. Delay_ms(500);
  5923. //存储异常并上传
  5924. FacMode_Stop(false);
  5925. return;
  5926. }
  5927. }
  5928. }
  5929. BootInfo = "";
  5930. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  5931. if (uARTToolStripMenuItem.Checked)
  5932. {
  5933. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送复位指令,切换联动装置盒波特率" + "\r\n");
  5934. Code[0] = (byte)'R';
  5935. Code[1] = (byte)'E';
  5936. Code[2] = (byte)'S';
  5937. Code[3] = (byte)'E';
  5938. Code[4] = (byte)'T';
  5939. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  5940. Delay_ms(500);
  5941. }
  5942. //系统清除后需重新开机
  5943. label_FacModeStatus.Text = "重新开机";
  5944. //确保测试前先关机,发送关机指令再发送开机指令
  5945. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新发送关机指令" + "\r\n");
  5946. Code[0] = 0xF0;
  5947. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5948. Delay_ms(1500);
  5949. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新发送开机指令" + "\r\n");
  5950. Code[0] = 0xF1;
  5951. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5952. ACK_WaitCnt = 0;
  5953. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  5954. while (ACK_WaitCnt <= 20); //10s
  5955. //获取Boot版本信息
  5956. if (BootInfo != string.Empty)
  5957. {
  5958. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机成功" + "\r\n");
  5959. Delay_ms(500);
  5960. }
  5961. else
  5962. {
  5963. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机失败" + "\r\n");
  5964. label_FacModeStatus.Text = "存在故障!";
  5965. label_FacModeResult.BackColor = Color.Red;
  5966. label_FacModeResult.Text = "测试异常";
  5967. Delay_ms(500);
  5968. //存储异常并上传
  5969. FacMode_Stop(false);
  5970. return;
  5971. }
  5972. } while (false);
  5973. }
  5974. else
  5975. {
  5976. label_FacModeSysClear.BackColor = Color.Yellow;
  5977. label_FacModeStatus.Text = "跳过系统清除!";
  5978. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过系统清除" + "\r\n");
  5979. Delay_ms(500);
  5980. }
  5981. #if false
  5982. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  5983. {
  5984. Code[0] = 0x00;//5S协议
  5985. Code[1] = 0x00;
  5986. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5987. Delay_ms(500);
  5988. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5989. Delay_ms(500);
  5990. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  5991. }
  5992. #endif
  5993. //检查是否有故障
  5994. if (textBox_ErrorCode.Text.Contains("H"))
  5995. {
  5996. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "故障码:" + textBox_ErrorCode.Text + "\r\n");
  5997. label_FacModeStatus.Text = "电机存在故障!";
  5998. label_FacModeResult.BackColor = Color.Red;
  5999. label_FacModeResult.Text = "测试异常";
  6000. Delay_ms(500);
  6001. //存储异常并上传
  6002. FacMode_Stop(false);
  6003. return;
  6004. }
  6005. //MOS内阻校准
  6006. if (checkBox_FacMode_MosCal.Checked)
  6007. {
  6008. label_FacModeStatus.Text = "MOS内阻校准";
  6009. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始MOS内阻校准" + "\r\n");
  6010. Delay_ms(500);
  6011. //提示进行负载切换
  6012. if (MessageBox.Show("电阻负载切换完成,开始校准?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
  6013. {
  6014. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "取消MOS内阻校准" + "\r\n");
  6015. label_FacModeStatus.Text = "存在故障!";
  6016. label_FacModeResult.BackColor = Color.Red;
  6017. label_FacModeResult.Text = "测试异常";
  6018. Delay_ms(500);
  6019. //存储异常并上传
  6020. FacMode_Stop(false);
  6021. return;
  6022. }
  6023. //确认后发送校准指令
  6024. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令" + "\r\n");
  6025. string[] K = toolStripTextBox_MosCalK.Text.Split(',');
  6026. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  6027. ushort uwDataTemp = 0;
  6028. uwDataTemp = Convert.ToUInt16(K[0]);
  6029. Code[2] = (byte)(uwDataTemp & 0xFF);
  6030. Code[3] = (byte)(uwDataTemp >> 8);
  6031. uwDataTemp = Convert.ToUInt16(K[1]);
  6032. Code[4] = (byte)(uwDataTemp & 0xFF);
  6033. Code[5] = (byte)(uwDataTemp >> 8);
  6034. uwDataTemp = Convert.ToUInt16(K[2]);
  6035. Code[6] = (byte)(uwDataTemp & 0xFF);
  6036. Code[7] = (byte)(uwDataTemp >> 8);
  6037. uwDataTemp = Convert.ToUInt16(K[3]);
  6038. Code[8] = (byte)(uwDataTemp & 0xFF);
  6039. Code[9] = (byte)(uwDataTemp >> 8);
  6040. uwDataTemp = Convert.ToUInt16(K[4]);
  6041. Code[10] = (byte)(uwDataTemp & 0xFF);
  6042. Code[11] = (byte)(uwDataTemp >> 8);
  6043. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  6044. WriteACK = false;
  6045. ACK_WaitCnt = 0;
  6046. while (ACK_WaitCnt <= 6) ; //3s
  6047. if (WriteACK == true)
  6048. {
  6049. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  6050. }
  6051. else
  6052. {
  6053. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令,第1次重发" + "\r\n");
  6054. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  6055. ACK_WaitCnt = 0;
  6056. while (ACK_WaitCnt <= 6) ; //3s
  6057. if (WriteACK == true)
  6058. {
  6059. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  6060. }
  6061. else
  6062. {
  6063. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令,第2次重发" + "\r\n");
  6064. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  6065. ACK_WaitCnt = 0;
  6066. while (ACK_WaitCnt <= 6) ; //3s
  6067. if (WriteACK == true)
  6068. {
  6069. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  6070. }
  6071. else
  6072. {
  6073. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准异常" + "\r\n");
  6074. label_FacModeStatus.Text = "存在故障!";
  6075. label_FacModeResult.BackColor = Color.Red;
  6076. label_FacModeResult.Text = "测试异常";
  6077. Delay_ms(500);
  6078. //存储异常并上传
  6079. FacMode_Stop(false);
  6080. return;
  6081. }
  6082. }
  6083. }
  6084. #if false
  6085. //因控制器复位需发送指令重新进入5S协议
  6086. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  6087. {
  6088. Code[0] = 0x00;//5S协议
  6089. Code[1] = 0x00;
  6090. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6091. Delay_ms(500);
  6092. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6093. Delay_ms(500);
  6094. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  6095. }
  6096. #endif
  6097. //读取显示校准返回数据
  6098. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果" + "\r\n");
  6099. foreach (Control c in groupBox21.Controls)
  6100. {
  6101. if (c is TextBox)
  6102. c.Text = "";
  6103. }
  6104. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  6105. ACK_WaitCnt = 0;
  6106. while (ACK_WaitCnt <= 2) ; //1s
  6107. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  6108. {
  6109. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果,第1次重发" + "\r\n");
  6110. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  6111. ACK_WaitCnt = 0;
  6112. while (ACK_WaitCnt <= 2) ; //1s
  6113. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  6114. {
  6115. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果,第2次重发" + "\r\n");
  6116. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  6117. ACK_WaitCnt = 0;
  6118. while (ACK_WaitCnt <= 2) ; //1s
  6119. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  6120. {
  6121. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果异常" + "\r\n");
  6122. label_FacModeStatus.Text = "存在故障!";
  6123. label_FacModeResult.BackColor = Color.Red;
  6124. label_FacModeResult.Text = "测试异常";
  6125. Delay_ms(500);
  6126. //存储异常并上传
  6127. FacMode_Stop(false);
  6128. return;
  6129. }
  6130. }
  6131. }
  6132. else
  6133. {
  6134. 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");
  6135. }
  6136. //与校准返回数据对比
  6137. string[] MOS_R1_Th = toolStripTextBox_MOS1.Text.Split(',');
  6138. string[] MOS_R2_Th = toolStripTextBox_MOS2.Text.Split(',');
  6139. string[] MOS_R3_Th = toolStripTextBox_MOS3.Text.Split(',');
  6140. 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])) &&
  6141. (Convert.ToUInt16(textBox_MOS_R2.Text) >= Convert.ToUInt16(MOS_R2_Th[0])) && (Convert.ToUInt16(textBox_MOS_R2.Text) <= Convert.ToUInt16(MOS_R2_Th[1])) &&
  6142. (Convert.ToUInt16(textBox_MOS_R3.Text) >= Convert.ToUInt16(MOS_R3_Th[0])) && (Convert.ToUInt16(textBox_MOS_R3.Text) <= Convert.ToUInt16(MOS_R3_Th[1]))
  6143. )
  6144. {
  6145. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准合格" + "\r\n");
  6146. label_FacModeMosCal.BackColor = Color.Green;
  6147. //提示切换负载
  6148. MessageBox.Show("请将负载切换回电机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  6149. }
  6150. else
  6151. {
  6152. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准超范围" + "\r\n");
  6153. label_FacModeStatus.Text = "存在故障!";
  6154. label_FacModeResult.BackColor = Color.Red;
  6155. label_FacModeResult.Text = "测试异常";
  6156. Delay_ms(500);
  6157. //存储异常并上传
  6158. FacMode_Stop(false);
  6159. //提示切换负载
  6160. MessageBox.Show("请将负载切换回电机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  6161. return;
  6162. }
  6163. }
  6164. else
  6165. {
  6166. label_FacModeMosCal.BackColor = Color.Yellow;
  6167. label_FacModeStatus.Text = "跳过MOS内阻校准!";
  6168. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过MOS内阻校准" + "\r\n");
  6169. Delay_ms(500);
  6170. }
  6171. //位置校准
  6172. if (checkBox_FacMode_AngleCal.Checked)
  6173. {
  6174. //校准前进行一次开关机保存初始化数据
  6175. BootInfo = "";
  6176. label_FacModeStatus.Text = "位置校准";
  6177. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始位置校准" + "\r\n");
  6178. //确保测试前先关机,发送关机指令再发送开机指令
  6179. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  6180. Code[0] = 0xF0;
  6181. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6182. Delay_ms(1500);
  6183. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  6184. Code[0] = 0xF1;
  6185. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6186. ACK_WaitCnt = 0;
  6187. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  6188. while (ACK_WaitCnt <= 10) ; //5s
  6189. //获取Boot版本信息
  6190. if (BootInfo != string.Empty)
  6191. {
  6192. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机成功" + "\r\n");
  6193. Delay_ms(500);
  6194. }
  6195. else
  6196. {
  6197. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机失败" + "\r\n");
  6198. label_FacModeStatus.Text = "存在故障!";
  6199. label_FacModeResult.BackColor = Color.Red;
  6200. label_FacModeResult.Text = "测试异常";
  6201. Delay_ms(500);
  6202. //存储异常并上传
  6203. FacMode_Stop(false);
  6204. return;
  6205. }
  6206. //发送位置校准指令
  6207. for (int i = 0; i < 7; i++)
  6208. for (int j = 0; j < 6; j++)
  6209. {
  6210. dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = "";
  6211. }
  6212. foreach (Control cr in tabPage_AngleCal.Controls)
  6213. {
  6214. if (cr is TextBox)
  6215. {
  6216. if ((cr != textBox_AngleDiffTh) && (cr != textBox_AngleZeroTh))
  6217. cr.Text = "";
  6218. }
  6219. }
  6220. Code[0] = 0;
  6221. Code[1] = 0;
  6222. mySerialProcess.SendCmd((ushort)0x751, (byte)0x0C, (ushort)0x5002, Code);
  6223. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准中,请等待" + "\r\n");
  6224. ACK_WaitCnt = 0;
  6225. while (ACK_WaitCnt <= 50) ; //25s
  6226. //读取位置校准数据
  6227. if (textBox_AngleDiffAvg.Text == string.Empty)
  6228. {
  6229. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准失败" + "\r\n");
  6230. label_FacModeStatus.Text = "存在故障!";
  6231. label_FacModeResult.BackColor = Color.Red;
  6232. label_FacModeResult.Text = "测试异常";
  6233. Delay_ms(500);
  6234. //存储异常并上传
  6235. FacMode_Stop(false);
  6236. return;
  6237. }
  6238. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准数据:" + "\r\n");
  6239. for (int i = 0; i < 7; i++)
  6240. {
  6241. richTextBox_FacModeLog.AppendText("电周期" + (i + 1).ToString()+":");
  6242. for (int j = 0; j < 6; j++)
  6243. {
  6244. richTextBox_FacModeLog.AppendText(dataGridView_AngleCal.Rows[i].Cells[j + 1].Value.ToString() + ", ");
  6245. }
  6246. richTextBox_FacModeLog.AppendText("\r\n");
  6247. Delay_ms(200);
  6248. }
  6249. richTextBox_FacModeLog.AppendText("最小偏差:" + textBox_AngleDiffMin.Text+ ", " + "\r\n");
  6250. richTextBox_FacModeLog.AppendText("最大偏差:" + textBox_AngleDiffMax.Text + ", " + "\r\n");
  6251. richTextBox_FacModeLog.AppendText("平均偏差:" + textBox_AngleDiffAvg.Text + ", " + "\r\n");
  6252. richTextBox_FacModeLog.AppendText("历史零点:" + textBox_AngleZeroInit.Text + ", " + "\r\n");
  6253. richTextBox_FacModeLog.AppendText("当前零点:" + textBox_AngleZeroCur.Text + ", " + "\r\n");
  6254. richTextBox_FacModeLog.AppendText("零点偏差:" + textBox_AngleZeroDiff.Text + ", " + "\r\n");
  6255. //比较位置偏差
  6256. if ((Math.Abs(Convert.ToDouble(textBox_AngleDiffMin.Text)) > Convert.ToDouble(textBox_AngleDiffTh.Text)) ||
  6257. (Math.Abs(Convert.ToDouble(textBox_AngleDiffMax.Text)) > Convert.ToDouble(textBox_AngleDiffTh.Text)) ||
  6258. (Math.Abs(Convert.ToDouble(textBox_AngleDiffAvg.Text)) > Convert.ToDouble(textBox_AngleZeroTh.Text))
  6259. )
  6260. {
  6261. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差过大,无法校准" + "\r\n");
  6262. label_FacModeStatus.Text = "存在故障!";
  6263. label_FacModeResult.BackColor = Color.Red;
  6264. label_FacModeResult.Text = "测试异常";
  6265. Delay_ms(500);
  6266. //存储异常并上传
  6267. FacMode_Stop(false);
  6268. return;
  6269. }
  6270. //写入校准偏差值
  6271. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差满足要求,写入校准数据" + "\r\n");
  6272. double data1 = Convert.ToDouble(textBox_AngleZeroInit.Text) - Convert.ToDouble(textBox_AngleDiffAvg.Text);
  6273. if (data1 > 360)
  6274. {
  6275. data1 -= 360;
  6276. }
  6277. else if (data1 < -360)
  6278. {
  6279. data1 += 360;
  6280. }
  6281. Int16 data2 = (Int16)(data1 * 32768 / 360);
  6282. Code[0] = 0x01;
  6283. Code[1] = 0x00;
  6284. Code[2] = (byte)(data2);
  6285. Code[3] = (byte)(data2 >> 8);
  6286. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
  6287. WriteACK = false;
  6288. ACK_WaitCnt = 0;
  6289. while (ACK_WaitCnt <= 2) ; //1s
  6290. if (WriteACK == true)
  6291. {
  6292. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
  6293. }
  6294. else
  6295. {
  6296. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入位置偏差,第1次重发" + "\r\n");
  6297. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
  6298. WriteACK = false;
  6299. ACK_WaitCnt = 0;
  6300. while (ACK_WaitCnt <= 2) ; //1s
  6301. if (WriteACK == true)
  6302. {
  6303. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
  6304. }
  6305. else
  6306. {
  6307. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入位置偏差,第2次重发" + "\r\n");
  6308. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
  6309. WriteACK = false;
  6310. ACK_WaitCnt = 0;
  6311. while (ACK_WaitCnt <= 2) ; //1s
  6312. if (WriteACK == true)
  6313. {
  6314. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
  6315. }
  6316. else
  6317. {
  6318. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入失败" + "\r\n");
  6319. label_FacModeStatus.Text = "存在故障!";
  6320. label_FacModeResult.BackColor = Color.Red;
  6321. label_FacModeResult.Text = "测试异常";
  6322. Delay_ms(500);
  6323. //存储异常并上传
  6324. FacMode_Stop(false);
  6325. return;
  6326. }
  6327. }
  6328. }
  6329. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准正常,位置偏差值:" + textBox_AngleDiffAvg.Text + "\r\n");
  6330. label_FacModeAngleCal.BackColor = Color.Green;
  6331. }
  6332. else
  6333. {
  6334. label_FacModeAngleCal.BackColor = Color.Yellow;
  6335. label_FacModeStatus.Text = "跳过位置校准!";
  6336. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过位置校准" + "\r\n");
  6337. Delay_ms(500);
  6338. }
  6339. //参数写入
  6340. if (checkBox_FacModeCfgWrite.Checked)
  6341. {
  6342. label_FacModeStatus.Text = "参数写入";
  6343. //写入产品型号和SN
  6344. do
  6345. {
  6346. //根据扫码信息获取型号和SN
  6347. string ScanInfo = textBox_FacModeScan.Text;
  6348. string regexInfo = "";
  6349. string[] InfoList = { "" };
  6350. try
  6351. {
  6352. if (中置电机ToolStripMenuItem.Checked == true)
  6353. {
  6354. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  6355. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  6356. }
  6357. else if (轮毂电机ToolStripMenuItem.Checked == true)
  6358. {
  6359. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  6360. string Model = InfoList[0];
  6361. string Spec = InfoList[1];
  6362. string Sn = InfoList[2];
  6363. InfoList[0] = Model.Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  6364. InfoList[1] = Sn;
  6365. }
  6366. }
  6367. catch
  6368. {
  6369. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  6370. label_FacModeStatus.Text = "存在故障!";
  6371. label_FacModeResult.BackColor = Color.Red;
  6372. label_FacModeResult.Text = "标签格式错误";
  6373. Delay_ms(500);
  6374. //存储异常并上传
  6375. FacMode_Stop(false);
  6376. return;
  6377. }
  6378. if (InfoList.Length >= 2)
  6379. {
  6380. //检查配置文件是否与打标信息一致
  6381. //...
  6382. //写入型号
  6383. label_FacModeStatus.Text = "写入型号";
  6384. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号" + "\r\n");
  6385. textBox_FacModeName.Text = InfoList[0];
  6386. string Mode = textBox_FacModeName.Text;
  6387. var ModeArray = new byte[16];
  6388. for (ushort i = 0; i < Mode.Length; i++)
  6389. {
  6390. ModeArray[i] = (byte)Mode[i];
  6391. }
  6392. if (Mode.Length < 16)
  6393. {
  6394. ModeArray[Mode.Length] = (byte)'.';
  6395. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  6396. {
  6397. ModeArray[Mode.Length + 1 + i] = 0x20;
  6398. }
  6399. }
  6400. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6401. WriteACK = false;
  6402. ACK_WaitCnt = 0;
  6403. while (ACK_WaitCnt <= 2); //1s
  6404. if (WriteACK == true)
  6405. {
  6406. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6407. }
  6408. else
  6409. {
  6410. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号,第1次重发" + "\r\n");
  6411. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6412. ACK_WaitCnt = 0;
  6413. while (ACK_WaitCnt <= 2) ; //1s
  6414. if (WriteACK == true)
  6415. {
  6416. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6417. }
  6418. else
  6419. {
  6420. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号,第2次重发" + "\r\n");
  6421. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6422. ACK_WaitCnt = 0;
  6423. while (ACK_WaitCnt <= 2) ; //1s
  6424. if (WriteACK == true)
  6425. {
  6426. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6427. }
  6428. else
  6429. {
  6430. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入失败" + "\r\n");
  6431. label_FacModeStatus.Text = "存在故障!";
  6432. label_FacModeResult.BackColor = Color.Red;
  6433. label_FacModeResult.Text = "测试异常";
  6434. Delay_ms(500);
  6435. //存储异常并上传
  6436. FacMode_Stop(false);
  6437. return;
  6438. }
  6439. }
  6440. }
  6441. //写入SN
  6442. label_FacModeStatus.Text = "写入SN";
  6443. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN" + "\r\n");
  6444. textBox_FacModeNum.Text = InfoList[1];
  6445. string SN = textBox_FacModeNum.Text;
  6446. var SNArray = new byte[16];
  6447. for (ushort i = 0; i < SN.Length; i++)
  6448. {
  6449. SNArray[i] = (byte)SN[i];
  6450. }
  6451. if (SN.Length < 16)
  6452. {
  6453. SNArray[SN.Length] = (byte)'.';
  6454. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  6455. {
  6456. SNArray[SN.Length + 1 + i] = 0x20;
  6457. }
  6458. }
  6459. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6460. WriteACK = false;
  6461. ACK_WaitCnt = 0;
  6462. while (ACK_WaitCnt <= 2); //1s
  6463. if (WriteACK == true)
  6464. {
  6465. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  6466. }
  6467. else
  6468. {
  6469. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN,第1次重发" + "\r\n");
  6470. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6471. ACK_WaitCnt = 0;
  6472. while (ACK_WaitCnt <= 2) ; //1s
  6473. if (WriteACK == true)
  6474. {
  6475. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  6476. }
  6477. else
  6478. {
  6479. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN,第2次重发" + "\r\n");
  6480. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6481. ACK_WaitCnt = 0;
  6482. while (ACK_WaitCnt <= 2) ; //1s
  6483. if (WriteACK == true)
  6484. {
  6485. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  6486. }
  6487. else
  6488. {
  6489. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入失败" + "\r\n");
  6490. label_FacModeStatus.Text = "存在故障!";
  6491. label_FacModeResult.BackColor = Color.Red;
  6492. label_FacModeResult.Text = "测试异常";
  6493. Delay_ms(500);
  6494. //存储异常并上传
  6495. FacMode_Stop(false);
  6496. return;
  6497. }
  6498. }
  6499. }
  6500. }
  6501. else
  6502. {
  6503. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6504. return;
  6505. }
  6506. } while (false);
  6507. //写入配置文件
  6508. do
  6509. {
  6510. label_FacModeStatus.Text = "写入配置文件";
  6511. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  6512. //配置文件
  6513. List<byte[]> CmdList = new List<byte[]>();
  6514. //从服务器下载文件
  6515. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  6516. {
  6517. string SelectFile = "";
  6518. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "/" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  6519. if (File.Exists(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  6520. {
  6521. File.Delete(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  6522. }
  6523. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  6524. //打开文件
  6525. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  6526. CmdList.Clear();
  6527. while (streamReader.Peek() != -1)
  6528. {
  6529. string fileLineInfo = streamReader.ReadLine();
  6530. if (fileLineInfo.IndexOf("[") != -1)
  6531. {
  6532. continue;
  6533. }
  6534. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  6535. }
  6536. streamReader.Close();
  6537. }
  6538. //加载本地文件
  6539. else
  6540. {
  6541. string SelectFile = "";
  6542. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  6543. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  6544. CmdList.Clear();
  6545. while (streamReader.Peek() != -1)
  6546. {
  6547. string fileLineInfo = streamReader.ReadLine();
  6548. if (fileLineInfo.IndexOf("[") != -1)
  6549. {
  6550. continue;
  6551. }
  6552. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  6553. }
  6554. streamReader.Close();
  6555. }
  6556. int CmdNum = CmdList.Count(); //指令个数
  6557. Delay_ms(500);
  6558. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "开始写入" + "\r\n");
  6559. Delay_ms(500);
  6560. //开始写入
  6561. for (int i = 0; i < CmdList.Count; i++)
  6562. {
  6563. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令" + "\r\n");
  6564. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6565. WriteACK = false;
  6566. ACK_WaitCnt = 0;
  6567. while (ACK_WaitCnt <= 2) ; //1s
  6568. if (WriteACK == true)
  6569. {
  6570. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6571. }
  6572. else
  6573. {
  6574. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令,第1次重发" + "\r\n");
  6575. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6576. WriteACK = false;
  6577. ACK_WaitCnt = 0;
  6578. while (ACK_WaitCnt <= 2) ; //1s
  6579. if (WriteACK == true)
  6580. {
  6581. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6582. }
  6583. else
  6584. {
  6585. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令,第2次重发" + "\r\n");
  6586. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6587. WriteACK = false;
  6588. ACK_WaitCnt = 0;
  6589. while (ACK_WaitCnt <= 2) ; //1s
  6590. if (WriteACK == true)
  6591. {
  6592. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6593. }
  6594. else
  6595. {
  6596. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入失败," + "共" + CmdNum.ToString() + "条指令," + "写入成功" + i.ToString() + "条" + "\r\n");
  6597. label_FacModeStatus.Text = "存在故障!";
  6598. label_FacModeResult.BackColor = Color.Red;
  6599. label_FacModeResult.Text = "测试异常";
  6600. Delay_ms(500);
  6601. //存储异常并上传
  6602. FacMode_Stop(false);
  6603. return;
  6604. }
  6605. }
  6606. }
  6607. }
  6608. //写入完成
  6609. label_FacMode_CfgWrite.BackColor = Color.Green;
  6610. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入成功" + "\r\n");
  6611. Delay_ms(500);
  6612. } while (false);
  6613. }
  6614. else
  6615. {
  6616. label_FacMode_CfgWrite.BackColor = Color.Yellow;
  6617. label_FacModeStatus.Text = "跳过参数写入!";
  6618. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数写入" + "\r\n");
  6619. Delay_ms(500);
  6620. }
  6621. //BMS通讯
  6622. if (checkBox_FacModeBMS.Checked)
  6623. {
  6624. if (label_FacModeBMS.BackColor == Color.Red)
  6625. {
  6626. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "BMS通讯异常" + "\r\n");
  6627. label_FacModeStatus.Text = "存在故障!";
  6628. label_FacModeResult.BackColor = Color.Red;
  6629. label_FacModeResult.Text = "测试异常";
  6630. Delay_ms(500);
  6631. //存储异常并上传
  6632. FacMode_Stop(false);
  6633. return;
  6634. }
  6635. }
  6636. else
  6637. {
  6638. label_FacModeBMS.BackColor = Color.Yellow;
  6639. label_FacModeStatus.Text = "跳过BMS通讯检测!";
  6640. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过BMS通讯检测" + "\r\n");
  6641. Delay_ms(500);
  6642. }
  6643. //基础功能检测
  6644. if (checkBox_FacBaseFucTest.Checked)
  6645. {
  6646. label_FacModeStatus.Text = "基础功能检测";
  6647. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始基础功能检测" + "\r\n");
  6648. //确认负载位置
  6649. if (checkBox_FacMode_MosCal.Checked)
  6650. {
  6651. if (MessageBox.Show("请再次确认负载是否切换回电机?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  6652. {
  6653. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "负载已切换为电机,继续测试" + "\r\n");
  6654. }
  6655. else
  6656. {
  6657. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试取消" + "\r\n");
  6658. label_FacModeStatus.Text = "存在故障!";
  6659. label_FacModeResult.BackColor = Color.Red;
  6660. label_FacModeResult.Text = "测试异常";
  6661. Delay_ms(500);
  6662. //存储异常并上传
  6663. FacMode_Stop(false);
  6664. return;
  6665. }
  6666. }
  6667. //发送指令进入配置模式
  6668. do
  6669. {
  6670. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6671. Code[0] = 0x01;
  6672. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6673. WriteACK = false;
  6674. ACK_WaitCnt = 0;
  6675. while (ACK_WaitCnt <= 2); //1s
  6676. if (textBox_RunInfo_Vol.Text != "---")
  6677. {
  6678. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6679. }
  6680. else
  6681. {
  6682. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  6683. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6684. ACK_WaitCnt = 0;
  6685. while (ACK_WaitCnt <= 2) ; //1s
  6686. if (textBox_RunInfo_Vol.Text != "---")
  6687. {
  6688. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6689. }
  6690. else
  6691. {
  6692. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  6693. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6694. ACK_WaitCnt = 0;
  6695. while (ACK_WaitCnt <= 2) ; //1s
  6696. if (textBox_RunInfo_Vol.Text != "---")
  6697. {
  6698. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6699. }
  6700. else
  6701. {
  6702. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  6703. label_FacModeStatus.Text = "存在故障!";
  6704. label_FacModeResult.BackColor = Color.Red;
  6705. label_FacModeResult.Text = "测试异常";
  6706. Delay_ms(500);
  6707. //存储异常并上传
  6708. FacMode_Stop(false);
  6709. return;
  6710. }
  6711. }
  6712. }
  6713. } while (false);
  6714. //发送指令启动电机
  6715. do
  6716. {
  6717. #if false //通过运行模式3启动电机
  6718. //发送指令读取调试信息
  6719. richTextBox_DebugParam.Clear();
  6720. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  6721. WriteACK = false;
  6722. ACK_WaitCnt = 0;
  6723. while (ACK_WaitCnt <= 2); //1s
  6724. //获取调试信息
  6725. string DebugDefaultInfo = "";
  6726. if (richTextBox_DebugParam.Text == string.Empty)
  6727. {
  6728. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
  6729. label_FacModeStatus.Text = "存在故障!";
  6730. label_FacModeResult.BackColor = Color.Red;
  6731. label_FacModeResult.Text = "测试异常";
  6732. Delay_ms(500);
  6733. //存储异常并上传
  6734. FacMode_Stop(false);
  6735. return;
  6736. }
  6737. else
  6738. {
  6739. DebugDefaultInfo = richTextBox_DebugParam.Text;
  6740. }
  6741. //设置模式
  6742. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  6743. strDataTemp[0] = "整体运行模式=3";
  6744. //发送数据
  6745. Code[0] = 0;
  6746. Code[1] = 0;
  6747. for (int i = 0; i < strDataTemp.Length; i++)
  6748. {
  6749. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  6750. Code[2 * i + 2] = (byte)uwDataTemp;
  6751. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  6752. }
  6753. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  6754. label_FacModeStatus.Text = "启动电机";
  6755. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "启动电机" + "\r\n");
  6756. #else //通过Walk模式启动电机
  6757. //设置转速100%
  6758. var Data = new byte[1];
  6759. Data[0] = (byte)100;
  6760. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6761. Delay_ms(500);
  6762. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6763. Delay_ms(500);
  6764. //启动电机进入WALK模式
  6765. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "基础功能检测,进入WALK" + "\r\n");
  6766. Code[0] = 0x22;
  6767. Code[1] = 0xF0;
  6768. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6769. WriteACK = false;
  6770. ACK_WaitCnt = 0;
  6771. while (ACK_WaitCnt <= 2) ; //1s
  6772. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6773. {
  6774. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第1次重发" + "\r\n");
  6775. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6776. ACK_WaitCnt = 0;
  6777. while (ACK_WaitCnt <= 2) ; //1s
  6778. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6779. {
  6780. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第2次重发" + "\r\n");
  6781. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6782. ACK_WaitCnt = 0;
  6783. while (ACK_WaitCnt <= 2) ; //1s
  6784. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6785. {
  6786. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
  6787. label_FacModeStatus.Text = "存在故障!";
  6788. label_FacModeResult.BackColor = Color.Red;
  6789. label_FacModeResult.Text = "测试异常";
  6790. Delay_ms(500);
  6791. //存储异常并上传
  6792. FacMode_Stop(false);
  6793. return;
  6794. }
  6795. }
  6796. }
  6797. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入WALK,开始检测" + "\r\n");
  6798. #endif
  6799. Delay_ms(3000);
  6800. } while (false);
  6801. //判断车速
  6802. if ((Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) <= Convert.ToDouble( toolStripTextBox_ThBikeSpeed.Text.Split(',')[1])) &&
  6803. (Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThBikeSpeed.Text.Split(',')[0])))
  6804. {
  6805. label_FacModeSpeed.BackColor = Color.Green;
  6806. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器正常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
  6807. }
  6808. else
  6809. {
  6810. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器异常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
  6811. label_FacModeStatus.Text = "存在故障!";
  6812. label_FacModeResult.BackColor = Color.Red;
  6813. label_FacModeResult.Text = "测试异常";
  6814. Delay_ms(500);
  6815. //存储异常并上传
  6816. FacMode_Stop(false);
  6817. return;
  6818. }
  6819. //判断电压
  6820. if ((Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[1])) &&
  6821. (Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[0])))
  6822. {
  6823. label_FacModeVolTest.BackColor = Color.Green;
  6824. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量正常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
  6825. }
  6826. else
  6827. {
  6828. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量异常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
  6829. label_FacModeStatus.Text = "存在故障!";
  6830. label_FacModeResult.BackColor = Color.Red;
  6831. label_FacModeResult.Text = "测试异常";
  6832. Delay_ms(500);
  6833. //存储异常并上传
  6834. FacMode_Stop(false);
  6835. return;
  6836. }
  6837. //判断电流
  6838. if ((Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[1])) &&
  6839. (Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[0])))
  6840. {
  6841. label_FacModeCurrentTest.BackColor = Color.Green;
  6842. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量正常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  6843. }
  6844. else
  6845. {
  6846. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量异常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  6847. label_FacModeStatus.Text = "存在故障!";
  6848. label_FacModeResult.BackColor = Color.Red;
  6849. label_FacModeResult.Text = "测试异常";
  6850. Delay_ms(500);
  6851. //存储异常并上传
  6852. FacMode_Stop(false);
  6853. return;
  6854. }
  6855. //判断温度
  6856. if ((Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[1])) &&
  6857. (Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[0])) &&
  6858. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[1])) &&
  6859. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[0])) &&
  6860. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[1])) &&
  6861. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[0])))
  6862. {
  6863. label_FacModeNTC.BackColor = Color.Green;
  6864. 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");
  6865. }
  6866. else
  6867. {
  6868. 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");
  6869. label_FacModeStatus.Text = "存在故障!";
  6870. label_FacModeResult.BackColor = Color.Red;
  6871. label_FacModeResult.Text = "测试异常";
  6872. Delay_ms(500);
  6873. //存储异常并上传
  6874. FacMode_Stop(false);
  6875. return;
  6876. }
  6877. //判断转速
  6878. if ((Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[1])) &&
  6879. (Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[0])))
  6880. {
  6881. label_FacModeMotorSpeed.BackColor = Color.Green;
  6882. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速正常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
  6883. }
  6884. else
  6885. {
  6886. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速异常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
  6887. label_FacModeStatus.Text = "存在故障!";
  6888. label_FacModeResult.BackColor = Color.Red;
  6889. label_FacModeResult.Text = "测试异常";
  6890. Delay_ms(500);
  6891. //存储异常并上传
  6892. FacMode_Stop(false);
  6893. return;
  6894. }
  6895. //发送指令停止电机
  6896. do
  6897. {
  6898. //设置转速0%
  6899. var Data = new byte[1];
  6900. Data[0] = (byte)0;
  6901. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6902. Delay_ms(500);
  6903. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6904. Delay_ms(500);
  6905. #if false //通过修改调试模式停止电机
  6906. //获取调试信息
  6907. string DebugDefaultInfo = "";
  6908. if (richTextBox_DebugParam.Text == string.Empty)
  6909. {
  6910. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
  6911. label_FacModeStatus.Text = "存在故障!";
  6912. label_FacModeResult.BackColor = Color.Red;
  6913. label_FacModeResult.Text = "测试异常";
  6914. Delay_ms(500);
  6915. //存储异常并上传
  6916. FacMode_Stop(false);
  6917. return;
  6918. }
  6919. else
  6920. {
  6921. DebugDefaultInfo = richTextBox_DebugParam.Text;
  6922. }
  6923. //设置模式
  6924. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  6925. //发送数据
  6926. Code[0] = 0;
  6927. Code[1] = 0;
  6928. for (int i = 0; i < strDataTemp.Length; i++)
  6929. {
  6930. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  6931. Code[2 * i + 2] = (byte)uwDataTemp;
  6932. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  6933. }
  6934. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  6935. label_FacModeStatus.Text = "停止电机";
  6936. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "停止电机" + "\r\n");
  6937. #else //通过调整档位停止电机
  6938. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK" + "\r\n");
  6939. Code[0] = 0x00;
  6940. Code[1] = 0xF0;
  6941. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6942. WriteACK = false;
  6943. ACK_WaitCnt = 0;
  6944. while (ACK_WaitCnt <= 2) ; //1s
  6945. if (textBox_RunInfo_GearSt.Text != "OFF")
  6946. {
  6947. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK,第1次重发" + "\r\n");
  6948. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6949. ACK_WaitCnt = 0;
  6950. while (ACK_WaitCnt <= 2) ; //1s
  6951. if (textBox_RunInfo_GearSt.Text != "OFF")
  6952. {
  6953. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK,第2次重发" + "\r\n");
  6954. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6955. ACK_WaitCnt = 0;
  6956. while (ACK_WaitCnt <= 2) ; //1s
  6957. if (textBox_RunInfo_GearSt.Text != "OFF")
  6958. {
  6959. }
  6960. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
  6961. label_FacModeStatus.Text = "存在故障!";
  6962. label_FacModeResult.BackColor = Color.Red;
  6963. label_FacModeResult.Text = "测试异常";
  6964. Delay_ms(500);
  6965. //存储异常并上传
  6966. FacMode_Stop(false);
  6967. return;
  6968. }
  6969. }
  6970. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已退出WALK,基础功能检测完成" + "\r\n");
  6971. #endif
  6972. Delay_ms(2000);
  6973. } while (false);
  6974. }
  6975. else
  6976. {
  6977. label_FacModeSpeed.BackColor = Color.Yellow;
  6978. label_FacModeVolTest.BackColor = Color.Yellow;
  6979. label_FacModeCurrentTest.BackColor = Color.Yellow;
  6980. label_FacModeNTC.BackColor = Color.Yellow;
  6981. label_FacModeMotorSpeed.BackColor = Color.Yellow;
  6982. label_FacModeStatus.Text = "跳过基础功能检测!";
  6983. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过基础功能检测" + "\r\n");
  6984. Delay_ms(500);
  6985. }
  6986. //力矩检测
  6987. if (checkBox_FacTor.Checked)
  6988. {
  6989. label_FacModeStatus.Text = "力矩传感器检测!";
  6990. //发送指令进入配置模式
  6991. do
  6992. {
  6993. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  6994. {
  6995. break;
  6996. }
  6997. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6998. Code[0] = 0x01;
  6999. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7000. WriteACK = false;
  7001. ACK_WaitCnt = 0;
  7002. while (ACK_WaitCnt <= 2) ; //1s
  7003. if (textBox_RunInfo_Vol.Text != "---")
  7004. {
  7005. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7006. Delay_ms(500);
  7007. }
  7008. else
  7009. {
  7010. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  7011. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7012. ACK_WaitCnt = 0;
  7013. while (ACK_WaitCnt <= 2) ; //1s
  7014. if (textBox_RunInfo_Vol.Text != "---")
  7015. {
  7016. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7017. Delay_ms(500);
  7018. }
  7019. else
  7020. {
  7021. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7022. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7023. ACK_WaitCnt = 0;
  7024. while (ACK_WaitCnt <= 2) ; //1s
  7025. if (textBox_RunInfo_Vol.Text != "---")
  7026. {
  7027. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7028. Delay_ms(500);
  7029. }
  7030. else
  7031. {
  7032. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7033. label_FacModeStatus.Text = "存在故障!";
  7034. label_FacModeResult.BackColor = Color.Red;
  7035. label_FacModeResult.Text = "测试异常";
  7036. Delay_ms(500);
  7037. //存储异常并上传
  7038. FacMode_Stop(false);
  7039. return;
  7040. }
  7041. }
  7042. }
  7043. } while (false);
  7044. ushort Max = 0, Torque = 0;
  7045. //提示输入力矩信号
  7046. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟力矩信号输入" + "\r\n");
  7047. ACK_WaitCnt = 0;
  7048. while (ACK_WaitCnt <= 20) //10s
  7049. {
  7050. //获取力矩值
  7051. Torque = (ushort)Convert.ToInt16(textBox_RunInfo_Torque.Text.Split(' ')[0]);
  7052. if (Torque > Max)
  7053. Max = Torque;
  7054. if ((Max <= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[1])) &&
  7055. (Max >= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[0])) &&
  7056. (ACK_WaitCnt >= 6))
  7057. {
  7058. label_FacModeTq.BackColor = Color.Green;
  7059. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器正常" + " " + textBox_RunInfo_Torque.Text + "\r\n");
  7060. break;
  7061. }
  7062. }
  7063. if (ACK_WaitCnt >= 20)
  7064. {
  7065. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器异常" + " " + textBox_RunInfo_Torque.Text + "\r\n");
  7066. label_FacModeStatus.Text = "存在故障!";
  7067. label_FacModeResult.BackColor = Color.Red;
  7068. label_FacModeResult.Text = "测试异常";
  7069. Delay_ms(500);
  7070. //存储异常并上传
  7071. FacMode_Stop(false);
  7072. return;
  7073. }
  7074. }
  7075. else
  7076. {
  7077. label_FacModeTq.BackColor = Color.Yellow;
  7078. label_FacModeStatus.Text = "跳过力矩检测!";
  7079. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过力矩检测" + "\r\n");
  7080. Delay_ms(500);
  7081. }
  7082. //踏频检测
  7083. if (checkBox_FacCad.Checked)
  7084. {
  7085. label_FacModeStatus.Text = "踏频传感器检测!";
  7086. //发送指令进入配置模式
  7087. do
  7088. {
  7089. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  7090. {
  7091. break;
  7092. }
  7093. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  7094. Code[0] = 0x01;
  7095. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7096. WriteACK = false;
  7097. ACK_WaitCnt = 0;
  7098. while (ACK_WaitCnt <= 2) ; //1s
  7099. if (textBox_RunInfo_Vol.Text != "---")
  7100. {
  7101. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7102. Delay_ms(500);
  7103. }
  7104. else
  7105. {
  7106. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  7107. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7108. ACK_WaitCnt = 0;
  7109. while (ACK_WaitCnt <= 2) ; //1s
  7110. if (textBox_RunInfo_Vol.Text != "---")
  7111. {
  7112. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7113. Delay_ms(500);
  7114. }
  7115. else
  7116. {
  7117. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7118. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7119. ACK_WaitCnt = 0;
  7120. while (ACK_WaitCnt <= 2) ; //1s
  7121. if (textBox_RunInfo_Vol.Text != "---")
  7122. {
  7123. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7124. Delay_ms(500);
  7125. }
  7126. else
  7127. {
  7128. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7129. label_FacModeStatus.Text = "存在故障!";
  7130. label_FacModeResult.BackColor = Color.Red;
  7131. label_FacModeResult.Text = "测试异常";
  7132. Delay_ms(500);
  7133. //存储异常并上传
  7134. FacMode_Stop(false);
  7135. return;
  7136. }
  7137. }
  7138. }
  7139. } while (false);
  7140. ushort Max = 0, Cadence = 0;
  7141. //提示输入踏频信号
  7142. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟踏频信号输入" + "\r\n");
  7143. ACK_WaitCnt = 0;
  7144. while (ACK_WaitCnt <= 20) //10s
  7145. {
  7146. //获取踏频
  7147. Cadence = (ushort)Convert.ToInt16(textBox_RunInfo_Cadence.Text.Split(' ')[0]);
  7148. if (Cadence > Max)
  7149. Max = Cadence;
  7150. if ((Max <= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[1])) &&
  7151. (Max >= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[0])) &&
  7152. (ACK_WaitCnt >= 6))
  7153. {
  7154. label_FacModeCad.BackColor = Color.Green;
  7155. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器正常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  7156. break;
  7157. }
  7158. }
  7159. if (ACK_WaitCnt >= 20)
  7160. {
  7161. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器异常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  7162. label_FacModeStatus.Text = "存在故障!";
  7163. label_FacModeResult.BackColor = Color.Red;
  7164. label_FacModeResult.Text = "测试异常";
  7165. Delay_ms(500);
  7166. //存储异常并上传
  7167. FacMode_Stop(false);
  7168. return;
  7169. }
  7170. }
  7171. else
  7172. {
  7173. label_FacModeCad.BackColor = Color.Yellow;
  7174. label_FacModeStatus.Text = "跳过踏频检测!";
  7175. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过踏频检测" + "\r\n");
  7176. Delay_ms(500);
  7177. }
  7178. //转把检测
  7179. if (checkBox_FacThrrotleTest.Checked)
  7180. {
  7181. label_FacModeStatus.Text = "转把检测";
  7182. //发送指令进入配置模式
  7183. do
  7184. {
  7185. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  7186. {
  7187. break;
  7188. }
  7189. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  7190. Code[0] = 0x01;
  7191. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7192. WriteACK = false;
  7193. ACK_WaitCnt = 0;
  7194. while (ACK_WaitCnt <= 2) ; //1s
  7195. if (textBox_RunInfo_Vol.Text != "---")
  7196. {
  7197. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7198. Delay_ms(500);
  7199. }
  7200. else
  7201. {
  7202. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  7203. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7204. ACK_WaitCnt = 0;
  7205. while (ACK_WaitCnt <= 2) ; //1s
  7206. if (textBox_RunInfo_Vol.Text != "---")
  7207. {
  7208. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7209. Delay_ms(500);
  7210. }
  7211. else
  7212. {
  7213. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7214. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7215. ACK_WaitCnt = 0;
  7216. while (ACK_WaitCnt <= 2) ; //1s
  7217. if (textBox_RunInfo_Vol.Text != "---")
  7218. {
  7219. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7220. Delay_ms(500);
  7221. }
  7222. else
  7223. {
  7224. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7225. label_FacModeStatus.Text = "存在故障!";
  7226. label_FacModeResult.BackColor = Color.Red;
  7227. label_FacModeResult.Text = "测试异常";
  7228. Delay_ms(500);
  7229. //存储异常并上传
  7230. FacMode_Stop(false);
  7231. return;
  7232. }
  7233. }
  7234. }
  7235. } while (false);
  7236. //进入TURBO档
  7237. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把检测,发送指令进入TURBO" + "\r\n");
  7238. Code[0] = 0x04;
  7239. Code[1] = 0xF0;
  7240. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7241. WriteACK = false;
  7242. ACK_WaitCnt = 0;
  7243. while (ACK_WaitCnt <= 2) ; //1s
  7244. if (textBox_RunInfo_GearSt.Text != "TURBO")
  7245. {
  7246. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO,第1次重发" + "\r\n");
  7247. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7248. ACK_WaitCnt = 0;
  7249. while (ACK_WaitCnt <= 2) ; //1s
  7250. if (textBox_RunInfo_GearSt.Text != "TURBO")
  7251. {
  7252. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO,第2次重发" + "\r\n");
  7253. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7254. ACK_WaitCnt = 0;
  7255. while (ACK_WaitCnt <= 2) ; //1s
  7256. if (textBox_RunInfo_GearSt.Text != "TURBO")
  7257. {
  7258. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO异常" + "\r\n");
  7259. label_FacModeStatus.Text = "存在故障!";
  7260. label_FacModeResult.BackColor = Color.Red;
  7261. label_FacModeResult.Text = "测试异常";
  7262. Delay_ms(500);
  7263. //存储异常并上传
  7264. FacMode_Stop(false);
  7265. return;
  7266. }
  7267. }
  7268. }
  7269. //进入TURBO后,如果电机直接启动,认为转把电压异常
  7270. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把自检,请松开转把" + "\r\n");
  7271. Delay_ms(3000);
  7272. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) > 500)
  7273. {
  7274. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把电压异常" + "\r\n");
  7275. label_FacModeStatus.Text = "存在故障!";
  7276. label_FacModeResult.BackColor = Color.Red;
  7277. label_FacModeResult.Text = "测试异常";
  7278. Delay_ms(500);
  7279. //存储异常并上传
  7280. FacMode_Stop(false);
  7281. return;
  7282. }
  7283. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把自检正常" + "\r\n");
  7284. Delay_ms(500);
  7285. //提示转动转把
  7286. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入TURBO,10s内转动转把" + "\r\n");
  7287. ACK_WaitCnt = 0;
  7288. while (ACK_WaitCnt <= 20)
  7289. {
  7290. if ((Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) > 500) && (ACK_WaitCnt >= 10))
  7291. {
  7292. label_FacModeGas.BackColor = Color.Green;
  7293. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能正常,松开转把" + "\r\n");
  7294. break;
  7295. }
  7296. }
  7297. if (ACK_WaitCnt >= 20) //转把超时
  7298. {
  7299. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能异常,松开转把" + "\r\n");
  7300. label_FacModeStatus.Text = "存在故障!";
  7301. label_FacModeResult.BackColor = Color.Red;
  7302. label_FacModeResult.Text = "测试异常";
  7303. Delay_ms(500);
  7304. //存储异常并上传
  7305. FacMode_Stop(false);
  7306. return;
  7307. }
  7308. }
  7309. else
  7310. {
  7311. label_FacModeGas.BackColor = Color.Yellow;
  7312. label_FacModeStatus.Text = "跳过转把检测!";
  7313. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过转把检测" + "\r\n");
  7314. Delay_ms(500);
  7315. }
  7316. //刹车检测
  7317. if (checkBox_FacBreakTest.Checked)
  7318. {
  7319. label_FacModeStatus.Text = "刹把检测";
  7320. //发送指令进入配置模式
  7321. do
  7322. {
  7323. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  7324. {
  7325. break;
  7326. }
  7327. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  7328. Code[0] = 0x01;
  7329. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7330. WriteACK = false;
  7331. ACK_WaitCnt = 0;
  7332. while (ACK_WaitCnt <= 2) ; //1s
  7333. if (textBox_RunInfo_Vol.Text != "---")
  7334. {
  7335. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7336. Delay_ms(500);
  7337. }
  7338. else
  7339. {
  7340. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  7341. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7342. ACK_WaitCnt = 0;
  7343. while (ACK_WaitCnt <= 2) ; //1s
  7344. if (textBox_RunInfo_Vol.Text != "---")
  7345. {
  7346. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7347. Delay_ms(500);
  7348. }
  7349. else
  7350. {
  7351. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7352. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7353. ACK_WaitCnt = 0;
  7354. while (ACK_WaitCnt <= 2) ; //1s
  7355. if (textBox_RunInfo_Vol.Text != "---")
  7356. {
  7357. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7358. Delay_ms(500);
  7359. }
  7360. else
  7361. {
  7362. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7363. label_FacModeStatus.Text = "存在故障!";
  7364. label_FacModeResult.BackColor = Color.Red;
  7365. label_FacModeResult.Text = "测试异常";
  7366. Delay_ms(500);
  7367. //存储异常并上传
  7368. FacMode_Stop(false);
  7369. return;
  7370. }
  7371. }
  7372. }
  7373. } while (false);
  7374. //测试前先确定电机已停止
  7375. UInt16 WaitTime = 10;
  7376. do
  7377. {
  7378. WaitTime--;
  7379. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 100)
  7380. {
  7381. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机停止,开始进行剎把检测,进入WALK" + "\r\n");
  7382. break;
  7383. }
  7384. if (WaitTime == 0)
  7385. {
  7386. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机无法停止,剎把检测异常" + "\r\n");
  7387. label_FacModeStatus.Text = "存在故障!";
  7388. label_FacModeResult.BackColor = Color.Red;
  7389. label_FacModeResult.Text = "测试异常";
  7390. Delay_ms(500);
  7391. //存储异常并上传
  7392. FacMode_Stop(false);
  7393. return;
  7394. }
  7395. Delay_ms(500);
  7396. } while (true);
  7397. //设置转速100%
  7398. var Data = new byte[1];
  7399. Data[0] = (byte)100;
  7400. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7401. Delay_ms(500);
  7402. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7403. Delay_ms(500);
  7404. //启动电机进入WALK模式
  7405. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把检测,进入WALK" + "\r\n");
  7406. Code[0] = 0x22;
  7407. Code[1] = 0xF0;
  7408. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7409. WriteACK = false;
  7410. ACK_WaitCnt = 0;
  7411. while (ACK_WaitCnt <= 2) ; //1s
  7412. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 500))
  7413. {
  7414. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第1次重发" + "\r\n");
  7415. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7416. ACK_WaitCnt = 0;
  7417. while (ACK_WaitCnt <= 2) ; //1s
  7418. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 500))
  7419. {
  7420. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第2次重发" + "\r\n");
  7421. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7422. ACK_WaitCnt = 0;
  7423. while (ACK_WaitCnt <= 2) ; //1s
  7424. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 500))
  7425. {
  7426. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
  7427. label_FacModeStatus.Text = "存在故障!";
  7428. label_FacModeResult.BackColor = Color.Red;
  7429. label_FacModeResult.Text = "测试异常";
  7430. Delay_ms(500);
  7431. //存储异常并上传
  7432. FacMode_Stop(false);
  7433. return;
  7434. }
  7435. }
  7436. }
  7437. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,10s内操作剎把" + "\r\n");
  7438. ACK_WaitCnt = 0;
  7439. while (ACK_WaitCnt <= 20)
  7440. {
  7441. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 100)
  7442. {
  7443. label_FacModeBreak.BackColor = Color.Green;
  7444. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把功能正常,松开剎把" + "\r\n");
  7445. break;
  7446. }
  7447. }
  7448. if (ACK_WaitCnt >= 20) //剎把超时
  7449. {
  7450. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速:" + textBox_RunInfo_MotorSpeed.Text + "," + "剎把功能异常,松开剎把" + "\r\n");
  7451. label_FacModeStatus.Text = "存在故障!";
  7452. label_FacModeResult.BackColor = Color.Red;
  7453. label_FacModeResult.Text = "测试异常";
  7454. Delay_ms(500);
  7455. //存储异常并上传
  7456. FacMode_Stop(false);
  7457. return;
  7458. }
  7459. //停止电机
  7460. Code[0] = 0x00;
  7461. Code[1] = 0xF0;
  7462. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7463. WriteACK = false;
  7464. ACK_WaitCnt = 0;
  7465. while (ACK_WaitCnt <= 2) ; //1s
  7466. if (textBox_RunInfo_GearSt.Text != "OFF")
  7467. {
  7468. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK,第1次重发" + "\r\n");
  7469. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7470. ACK_WaitCnt = 0;
  7471. while (ACK_WaitCnt <= 2) ; //1s
  7472. if (textBox_RunInfo_GearSt.Text != "OFF")
  7473. {
  7474. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK,第2次重发" + "\r\n");
  7475. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7476. ACK_WaitCnt = 0;
  7477. while (ACK_WaitCnt <= 2) ; //1s
  7478. if (textBox_RunInfo_GearSt.Text != "OFF")
  7479. {
  7480. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
  7481. label_FacModeStatus.Text = "存在故障!";
  7482. label_FacModeResult.BackColor = Color.Red;
  7483. label_FacModeResult.Text = "测试异常";
  7484. Delay_ms(500);
  7485. //存储异常并上传
  7486. FacMode_Stop(false);
  7487. return;
  7488. }
  7489. }
  7490. }
  7491. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK" + "\r\n");
  7492. Delay_ms(500);
  7493. }
  7494. else
  7495. {
  7496. label_FacModeBreak.BackColor = Color.Yellow;
  7497. label_FacModeStatus.Text = "跳过刹车检测!";
  7498. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过刹车检测" + "\r\n");
  7499. Delay_ms(500);
  7500. }
  7501. //前后灯检测
  7502. if (checkBox_FacLightTest.Checked)
  7503. {
  7504. //前后灯检测
  7505. label_FacModeStatus.Text = "前后灯检测";
  7506. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开灯指令" + "\r\n");
  7507. //发送指令打开车灯
  7508. Code[0] = 0x00;
  7509. Code[1] = 0xF1;
  7510. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7511. WriteACK = false;
  7512. ACK_WaitCnt = 0;
  7513. while (ACK_WaitCnt <= 2) ; //1s
  7514. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7515. {
  7516. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令,第1次重发" + "\r\n");
  7517. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7518. ACK_WaitCnt = 0;
  7519. while (ACK_WaitCnt <= 2); //1s
  7520. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7521. {
  7522. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令,第2次重发" + "\r\n");
  7523. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7524. ACK_WaitCnt = 0;
  7525. while (ACK_WaitCnt <= 2) ; //1s
  7526. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7527. {
  7528. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令发送异常" + "\r\n");
  7529. label_FacModeStatus.Text = "存在故障!";
  7530. label_FacModeResult.BackColor = Color.Red;
  7531. label_FacModeResult.Text = "测试异常";
  7532. Delay_ms(500);
  7533. //存储异常并上传
  7534. FacMode_Stop(false);
  7535. return;
  7536. }
  7537. }
  7538. }
  7539. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已打开前后灯" + "\r\n");
  7540. Delay_ms(500);
  7541. //提示检查灯压是否正确
  7542. if (MessageBox.Show("前后灯是否正常开启?", "前后灯判断", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  7543. {
  7544. label_FacModeLightF.BackColor = Color.Green;
  7545. label_FacModeLightB.BackColor = Color.Green;
  7546. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯正常" + "\r\n");
  7547. Delay_ms(500);
  7548. }
  7549. else
  7550. {
  7551. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯异常" + "\r\n");
  7552. label_FacModeStatus.Text = "存在故障!";
  7553. label_FacModeResult.BackColor = Color.Red;
  7554. label_FacModeResult.Text = "测试异常";
  7555. Delay_ms(500);
  7556. //存储异常并上传
  7557. FacMode_Stop(false);
  7558. return;
  7559. }
  7560. //发送指令关闭车灯
  7561. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关灯指令" + "\r\n");
  7562. Code[0] = 0x00;
  7563. Code[1] = 0xF0;
  7564. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7565. WriteACK = false;
  7566. ACK_WaitCnt = 0;
  7567. while (ACK_WaitCnt <= 2) ; //1s
  7568. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7569. {
  7570. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令,第1次重发" + "\r\n");
  7571. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7572. ACK_WaitCnt = 0;
  7573. while (ACK_WaitCnt <= 2) ; //1s
  7574. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7575. {
  7576. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令,第2次重发" + "\r\n");
  7577. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7578. ACK_WaitCnt = 0;
  7579. while (ACK_WaitCnt <= 2) ; //1s
  7580. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7581. {
  7582. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令发送异常" + "\r\n");
  7583. label_FacModeStatus.Text = "存在故障!";
  7584. label_FacModeResult.BackColor = Color.Red;
  7585. label_FacModeResult.Text = "测试异常";
  7586. Delay_ms(500);
  7587. //存储异常并上传
  7588. FacMode_Stop(false);
  7589. return;
  7590. }
  7591. }
  7592. }
  7593. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已关闭前后灯" + "\r\n");
  7594. Delay_ms(500);
  7595. }
  7596. else
  7597. {
  7598. label_FacModeLightF.BackColor = Color.Yellow;
  7599. label_FacModeLightB.BackColor = Color.Yellow;
  7600. label_FacModeStatus.Text = "跳过前后灯检测!";
  7601. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过前后灯检测" + "\r\n");
  7602. Delay_ms(500);
  7603. }
  7604. //软件版本检测
  7605. do
  7606. {
  7607. label_FacModeStatus.Text = "软件版本确认";
  7608. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  7609. //发送指令读取版本
  7610. Class_Motor_Ver.Mode = "---";
  7611. Class_Motor_Ver.SN = "---";
  7612. Class_Motor_Ver.HW = "---";
  7613. Class_Motor_Ver.FW = "---";
  7614. Class_Motor_Ver.Special = "---";
  7615. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7616. ACK_WaitCnt = 0;
  7617. while (ACK_WaitCnt <= 2) ; //1s
  7618. if (Class_Motor_Ver.Mode == "---")
  7619. {
  7620. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第1次重发" + "\r\n");
  7621. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7622. ACK_WaitCnt = 0;
  7623. while (ACK_WaitCnt <= 2) ; //1s
  7624. if (Class_Motor_Ver.Mode == "---")
  7625. {
  7626. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第2次重发" + "\r\n");
  7627. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7628. ACK_WaitCnt = 0;
  7629. while (ACK_WaitCnt <= 2) ; //1s
  7630. if (Class_Motor_Ver.Mode == "---")
  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. }
  7643. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  7644. richTextBox_FacModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  7645. richTextBox_FacModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  7646. richTextBox_FacModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  7647. richTextBox_FacModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  7648. richTextBox_FacModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  7649. //判断版本是否正确
  7650. string VerCheck = comboBox_FacModeCfgFile.Text.Split('_')[3] + "_" + comboBox_FacModeCfgFile.Text.Split('_')[4];
  7651. string VerRead = "";
  7652. try
  7653. {
  7654. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  7655. }
  7656. catch (System.Exception)
  7657. {
  7658. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  7659. label_FacModeStatus.Text = "存在故障!";
  7660. label_FacModeResult.BackColor = Color.Red;
  7661. label_FacModeResult.Text = "测试异常";
  7662. Delay_ms(500);
  7663. //存储异常并上传
  7664. FacMode_Stop(false);
  7665. return;
  7666. }
  7667. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  7668. {
  7669. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
  7670. label_FacModeStatus.Text = "存在故障!";
  7671. label_FacModeResult.BackColor = Color.Red;
  7672. label_FacModeResult.Text = "测试异常";
  7673. Delay_ms(500);
  7674. //存储异常并上传
  7675. FacMode_Stop(false);
  7676. return;
  7677. }
  7678. label_FacModeFWVersion.BackColor = Color.Green;
  7679. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  7680. Delay_ms(500);
  7681. } while (false);
  7682. //测试合格
  7683. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  7684. label_FacModeStatus.Text = "测试结束!";
  7685. label_FacModeResult.BackColor = Color.Green;
  7686. label_FacModeResult.Text = "测试合格";
  7687. Delay_ms(500);
  7688. //存储并上传
  7689. FacMode_Stop(true);
  7690. return;
  7691. }
  7692. private void FacModelLabelInit()
  7693. {
  7694. //测试状态标签
  7695. label_FacModeResult.BackColor = Color.Yellow;
  7696. label_FacModeResult.Text = "测试中";
  7697. //测试过程标签
  7698. label_FacModeStatus.Text = "测试就绪";
  7699. //测试结果标签
  7700. foreach (Control c in groupBox28.Controls)
  7701. {
  7702. if (c is Label)
  7703. {
  7704. if (c.Text == string.Empty)
  7705. c.BackColor = Color.Red;
  7706. }
  7707. }
  7708. }
  7709. private void comboBox_CheckModeCfgDate_Click(object sender, EventArgs e)
  7710. {
  7711. //更新生产配置文件目录
  7712. GetDateList(false);
  7713. }
  7714. private void comboBox_FacModeCfgDate_Click(object sender, EventArgs e)
  7715. {
  7716. //更新生产配置文件目录
  7717. GetDateList(false);
  7718. }
  7719. private void richTextBox_FacModeLog_TextChanged(object sender, EventArgs e)
  7720. {
  7721. richTextBox_FacModeLog.SelectionStart = richTextBox_FacModeLog.Text.Length;
  7722. richTextBox_FacModeLog.ScrollToCaret();
  7723. }
  7724. /// <summary>
  7725. /// 参数检验测试停止
  7726. /// </summary>
  7727. /// <param name="OK_Flag"></param>
  7728. private void CheckMode_Stop(bool OK_Flag)
  7729. {
  7730. //打开开始按钮
  7731. button_CheckModeStart.Enabled = true;
  7732. //导出电机参数
  7733. string Params = "";
  7734. do
  7735. {
  7736. if (!OK_Flag)
  7737. {
  7738. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试异常,停止导出" + "\r\n");
  7739. break;
  7740. }
  7741. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "导出电机存储参数" + "\r\n");
  7742. //读取一次马达参数
  7743. richTextBox_MotorParam.Clear();
  7744. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break; ;
  7745. Delay_ms(100);
  7746. Params += "[马达参数]" + "\r\n" + richTextBox_MotorParam.Text + "\r\n";
  7747. Params += "\r\n";
  7748. //读取一次整车参数
  7749. richTextBox_BikeParam.Clear();
  7750. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  7751. Delay_ms(100);
  7752. Params += "[整车参数]" + "\r\n" + richTextBox_BikeParam.Text + "\r\n";
  7753. Params += "\r\n";
  7754. //读取一次控制参数
  7755. richTextBox_ControlParam.Clear();
  7756. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  7757. Delay_ms(100);
  7758. Params += "[控制参数]" + "\r\n" + richTextBox_ControlParam.Text + "\r\n";
  7759. Params += "\r\n";
  7760. //查询传感器
  7761. richTextBox_SensorParam.Clear();
  7762. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  7763. Delay_ms(100);
  7764. Params += "[传感器参数]" + "\r\n" + richTextBox_SensorParam.Text + "\r\n";
  7765. Params += "\r\n";
  7766. //读取15次助力参数
  7767. Params += "[助力参数]" + "\r\n";
  7768. for (int i = 1; i <= 15; i++)
  7769. {
  7770. var ConfigParam = new byte[4];
  7771. richTextBox_AssistParam.Clear();
  7772. ConfigParam[0] = (byte)(i & 0xFF);
  7773. ConfigParam[1] = (byte)(i >> 8);
  7774. ConfigParam[2] = (byte)(((i >= 5) ? 5 : i) & 0xFF);
  7775. ConfigParam[3] = (byte)(((i >= 5) ? 5 : i) >> 8);
  7776. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  7777. Delay_ms(200);
  7778. Params += richTextBox_AssistParam.Text + "\r\n";
  7779. Params += "\r\n";
  7780. }
  7781. //读取一次调试信息
  7782. richTextBox_DebugParam.Clear();
  7783. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  7784. Delay_ms(100);
  7785. Params += "[调试参数]" + "\r\n" + richTextBox_DebugParam.Text + "\r\n";
  7786. Params += "\r\n";
  7787. //读取一次历史信息
  7788. richTextBox_Record.Clear();
  7789. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  7790. Delay_ms(100);
  7791. Params += "[历史信息]" + "\r\n" + richTextBox_Record.Text + "\r\n";
  7792. Params += "\r\n";
  7793. //读取一次MOS内阻校准参数
  7794. foreach (Control c in groupBox21.Controls)
  7795. {
  7796. if (c is TextBox)
  7797. c.Text = "";
  7798. }
  7799. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  7800. Delay_ms(100);
  7801. Params += "[MOS内阻校准参数]" + "\r\n";
  7802. Params += textBox_MOS_K1.Text + ", " + textBox_MOS_K2.Text + ", " + textBox_MOS_K3.Text + ", " + textBox_MOS_K4.Text + ", "
  7803. + textBox_MOS_K5.Text + ", " + textBox_MOS_R1.Text + ", " + textBox_MOS_R2.Text + ", " + textBox_MOS_R3.Text + ", " + "\r\n";
  7804. Params += "\r\n";
  7805. //读取一次整车参数2
  7806. richTextBox_BikeParam2.Clear();
  7807. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null)) break;
  7808. Delay_ms(100);
  7809. Params += "[整车参数2]" + "\r\n" + richTextBox_BikeParam2.Text + "\r\n";
  7810. Params += "\r\n";
  7811. //读取一次用户骑行参数
  7812. richTextBox_UsrRidesParam.Clear();
  7813. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  7814. Delay_ms(100);
  7815. Params += "[用户骑行参数]" + "\r\n" + richTextBox_UsrRidesParam.Text + "\r\n";
  7816. Params += "\r\n";
  7817. //读取一次生产信息
  7818. textBox_MAC.Text = "";
  7819. textBox_MACAdd.Text = "";
  7820. textBox_MACDate.Text = "";
  7821. textBox_PP.Text = "";
  7822. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  7823. Delay_ms(100);
  7824. Params += "[生产信息]" + "\r\n";
  7825. Params += "生产商: " + textBox_MAC.Text + "\r\n";
  7826. Params += "生产地: " + textBox_MACAdd.Text + "\r\n";
  7827. Params += "生产日期: " + textBox_MACDate.Text + "\r\n";
  7828. Params += "产品标识: " + textBox_PP.Text + "\r\n";
  7829. Params += "\r\n";
  7830. //读取一次自定义信息
  7831. textBox_User1.Text = "---";
  7832. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  7833. Delay_ms(100);
  7834. textBox_User2.Text = "---";
  7835. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  7836. Delay_ms(100);
  7837. textBox_User3.Text = "---";
  7838. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  7839. Delay_ms(100);
  7840. Params += "[自定义信息]" + "\r\n";
  7841. Params += "自定义1: " + textBox_User1.Text + "\r\n";
  7842. Params += "自定义2: " + textBox_User2.Text + "\r\n";
  7843. Params += "自定义3: " + textBox_User3.Text + "\r\n";
  7844. Params += "\r\n";
  7845. //读取一次密钥
  7846. textBox_Key.Text = "---";
  7847. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  7848. Delay_ms(100);
  7849. Params += "[校验密钥]" + "\r\n" + textBox_Key.Text + "\r\n";
  7850. Params += "\r\n";
  7851. //读取一次存储标志
  7852. radioButton_EE_SaveYes.Checked = false;
  7853. radioButton_EE_SaveNo.Checked = false;
  7854. radioButton_SIP_SaveYes.Checked = false;
  7855. radioButton_SIP_SaveNo.Checked = false;
  7856. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  7857. Delay_ms(100);
  7858. Params += "[存储标志]" + "\r\n";
  7859. Params += "EEPROM: " + ((radioButton_EE_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  7860. Params += "SIP: " + ((radioButton_SIP_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  7861. Params += "\r\n";
  7862. } while (false);
  7863. //系统关机
  7864. var Code = new byte[32];//发送的指令数据
  7865. Code[0] = 0xF0;
  7866. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  7867. //关闭串口
  7868. //mySerialProcess.SerialClose(false);
  7869. //路径设置
  7870. string LocalSavePath = "";
  7871. string ServerSavePath = "";
  7872. if (OK_Flag)
  7873. {
  7874. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "OK\\";
  7875. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/OK/";
  7876. }
  7877. else
  7878. {
  7879. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "FAIL\\";
  7880. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/FAIL/";
  7881. }
  7882. if (Directory.Exists(LocalSavePath) == false)
  7883. {
  7884. Directory.CreateDirectory(LocalSavePath);
  7885. }
  7886. //保存和上传
  7887. string LogSavePath = "";
  7888. string LogSaveFileName = "";
  7889. string ProductInfo = textBox_CheckModeScan.Text.Replace(" ", "_"); ;
  7890. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  7891. if (Directory.Exists(LogSavePath) == false)
  7892. {
  7893. Directory.CreateDirectory(LogSavePath);
  7894. }
  7895. //测试页面
  7896. Double scaleX = PrimaryScreen.ScaleX;
  7897. Double scaleY = PrimaryScreen.ScaleY;
  7898. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  7899. Graphics g = Graphics.FromImage(bit);
  7900. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  7901. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  7902. bit.Save(LogSaveFileName);
  7903. //上传测试页面到服务器
  7904. if (myFtp.IsNetConnected == true)
  7905. {
  7906. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  7907. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  7908. {
  7909. myFtp.MakeDir(ServerSavePath + DateNow);
  7910. }
  7911. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  7912. {
  7913. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  7914. }
  7915. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  7916. if (result == true)
  7917. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  7918. }
  7919. //测试记录
  7920. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  7921. string file_str = "";
  7922. file_str += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  7923. file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  7924. file_str += "检验记录:\r\n" + richTextBox_CheckModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  7925. file_str += "检验结果:\r\n" + label_CheckModeResult.Text + "\r\n\r\n";
  7926. file_str += Local_HdInformation;
  7927. file_str += "\r\n电机存储参数:\r\n" + Params + "\r\n";
  7928. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  7929. //上传测试记录到服务器
  7930. if (myFtp.IsNetConnected == true)
  7931. {
  7932. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  7933. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  7934. {
  7935. myFtp.MakeDir(ServerSavePath + DateNow);
  7936. }
  7937. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  7938. {
  7939. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  7940. }
  7941. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  7942. if (result == true)
  7943. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  7944. }
  7945. //扫码框清空
  7946. textBox_CheckModeScan.Text = "";
  7947. }
  7948. /// <summary>
  7949. /// 参数检验开始
  7950. /// </summary>
  7951. /// <param name="sender"></param>
  7952. /// <param name="e"></param>
  7953. private void button_CheckModeStart_Click(object sender, EventArgs e)
  7954. {
  7955. //测试项目关闭编辑
  7956. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  7957. foreach (Control c in groupBox29.Controls)
  7958. {
  7959. if (c is CheckBox)
  7960. c.Enabled = false;
  7961. }
  7962. ReadLockStatus = true;
  7963. //检查配置文件
  7964. if (comboBox_CheckModeCfgFile.Text == "")
  7965. {
  7966. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  7967. return;
  7968. }
  7969. //开始测试
  7970. CheckTestStart();
  7971. }
  7972. /// <summary>
  7973. /// 参数检验测试子函数
  7974. /// </summary>
  7975. private void CheckTestStart()
  7976. {
  7977. //初始化标签
  7978. CheckModeLabelInit();
  7979. richTextBox_CheckModeLog.Clear();
  7980. //按钮禁止操作
  7981. button_CheckModeStart.Enabled = false;
  7982. //记录配置文件
  7983. richTextBox_CheckModeLog.AppendText("配置文件:" + comboBox_CheckModeCfgDate.Text + " / " + comboBox_CheckModeCfgFile.Text + "\r\n");
  7984. //检查打标信息
  7985. label_CheckModeStatus.Text = "检查扫码信息";
  7986. Delay_ms(500);
  7987. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  7988. if (textBox_CheckModeScan.Text == string.Empty)
  7989. {
  7990. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  7991. button__FacMode_Start.Enabled = false;
  7992. return;
  7993. }
  7994. try
  7995. {
  7996. if (中置电机ToolStripMenuItem.Checked == true)
  7997. {
  7998. if (textBox_CheckModeScan.Text.Split(' ').Length != 7)
  7999. {
  8000. label_CheckModeStatus.Text = "存在故障!";
  8001. label_CheckModeResult.BackColor = Color.Red;
  8002. label_CheckModeResult.Text = "标签格式错误";
  8003. button_CheckModeStart.Enabled = true;
  8004. return;
  8005. }
  8006. }
  8007. else if (轮毂电机ToolStripMenuItem.Checked == true)
  8008. {
  8009. if (textBox_CheckModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  8010. {
  8011. label_CheckModeStatus.Text = "存在故障!";
  8012. label_CheckModeResult.BackColor = Color.Red;
  8013. label_CheckModeResult.Text = "标签格式错误";
  8014. button_CheckModeStart.Enabled = true;
  8015. return;
  8016. }
  8017. }
  8018. }
  8019. catch (System.Exception)
  8020. {
  8021. label_CheckModeStatus.Text = "存在故障!";
  8022. label_CheckModeResult.BackColor = Color.Red;
  8023. label_CheckModeResult.Text = "标签格式错误";
  8024. button_CheckModeStart.Enabled = true;
  8025. return;
  8026. }
  8027. //打开串口
  8028. mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false);
  8029. if (!mySerialProcess.mySerial.IsOpen)
  8030. {
  8031. MessageBox.Show("请检查串口连接!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  8032. button__FacMode_Start.Enabled = false;
  8033. return;
  8034. }
  8035. //流水号计数
  8036. int serial = Convert.ToInt32(label_CheckModeSerial.Text);
  8037. serial += 1;
  8038. label_CheckModeSerial.Text = serial.ToString();
  8039. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, serial.ToString());
  8040. //创建线程,执行测试任务
  8041. Thread th = new Thread(CheckModeTest_Task);
  8042. th.Start();
  8043. }
  8044. /// <summary>
  8045. /// 执行一次测试任务
  8046. /// </summary>
  8047. private void CheckModeTest_Task()
  8048. {
  8049. //开始测试
  8050. richTextBox_CheckModeLog.AppendText("产品标签:" + textBox_CheckModeScan.Text + "\r\n");
  8051. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  8052. //变量定义
  8053. var Code = new byte[255];//发送的指令数据
  8054. ushort DataTemp;
  8055. short DataTemp_Int16;
  8056. string ResultPathName = "";
  8057. label_CheckModeStatus.Text = "开始测试";
  8058. BootInfo = "";
  8059. Delay_ms(500);
  8060. label_CheckModeStatus.Text = "系统开机";
  8061. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  8062. if (uARTToolStripMenuItem.Checked)
  8063. {
  8064. Code[0] = (byte)'R';
  8065. Code[1] = (byte)'E';
  8066. Code[2] = (byte)'S';
  8067. Code[3] = (byte)'E';
  8068. Code[4] = (byte)'T';
  8069. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  8070. Delay_ms(500);
  8071. }
  8072. //系统开机,确保测试前先关机,发送关机指令再发送开机指令
  8073. //确保测试前先关机,发送关机指令再发送开机指令
  8074. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  8075. Code[0] = 0xF0;
  8076. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  8077. Delay_ms(1500);
  8078. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  8079. Code[0] = 0xF1;
  8080. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  8081. ACK_WaitCnt = 0;
  8082. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  8083. while (ACK_WaitCnt <= 20) ; //10s
  8084. //检查BOOT版本
  8085. if (BootInfo != string.Empty)
  8086. {
  8087. label_CheckModeBoot.BackColor = Color.Green;
  8088. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  8089. Delay_ms(500);
  8090. }
  8091. else
  8092. {
  8093. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
  8094. label_CheckModeStatus.Text = "存在故障!";
  8095. label_CheckModeResult.BackColor = Color.Red;
  8096. label_CheckModeResult.Text = "测试异常";
  8097. Delay_ms(500);
  8098. //存储异常并上传
  8099. CheckMode_Stop(false);
  8100. return;
  8101. }
  8102. #if false
  8103. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  8104. {
  8105. Code[0] = 0x00;//5S协议
  8106. Code[1] = 0x00;
  8107. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  8108. Delay_ms(500);
  8109. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  8110. Delay_ms(500);
  8111. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  8112. }
  8113. #endif
  8114. //发送指令读取版本信息
  8115. do
  8116. {
  8117. label_CheckModeStatus.Text = "读取版本信息";
  8118. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  8119. //发送指令读取版本
  8120. Class_Motor_Ver.Mode = "---";
  8121. Class_Motor_Ver.SN = "---";
  8122. Class_Motor_Ver.HW = "---";
  8123. Class_Motor_Ver.FW = "---";
  8124. Class_Motor_Ver.Special = "---";
  8125. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  8126. ACK_WaitCnt = 0;
  8127. while (ACK_WaitCnt <= 2) ; //1s
  8128. if (Class_Motor_Ver.Mode == "---")
  8129. {
  8130. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第1次重发" + "\r\n");
  8131. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  8132. ACK_WaitCnt = 0;
  8133. while (ACK_WaitCnt <= 2) ; //1s
  8134. if (Class_Motor_Ver.Mode == "---")
  8135. {
  8136. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第2次重发" + "\r\n");
  8137. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  8138. ACK_WaitCnt = 0;
  8139. while (ACK_WaitCnt <= 2) ; //1s
  8140. if (Class_Motor_Ver.Mode == "---")
  8141. {
  8142. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取失败" + "\r\n");
  8143. label_CheckModeStatus.Text = "存在故障!";
  8144. label_CheckModeResult.BackColor = Color.Red;
  8145. label_CheckModeResult.Text = "测试异常";
  8146. Delay_ms(500);
  8147. //存储异常并上传
  8148. CheckMode_Stop(false);
  8149. return;
  8150. }
  8151. }
  8152. }
  8153. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  8154. Delay_ms(500);
  8155. } while (false);
  8156. //软件版本检查
  8157. if (checkBox_CheckModeFWVer.Checked)
  8158. {
  8159. richTextBox_CheckModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  8160. richTextBox_CheckModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  8161. richTextBox_CheckModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  8162. richTextBox_CheckModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  8163. richTextBox_CheckModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  8164. //判断版本是否正确
  8165. string VerCheck = comboBox_CheckModeCfgFile.Text.Split('_')[3] + "_" + comboBox_CheckModeCfgFile.Text.Split('_')[4];
  8166. string VerRead = "";
  8167. try
  8168. {
  8169. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  8170. }
  8171. catch (System.Exception)
  8172. {
  8173. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  8174. label_CheckModeStatus.Text = "存在故障!";
  8175. label_CheckModeResult.BackColor = Color.Red;
  8176. label_CheckModeResult.Text = "测试异常";
  8177. Delay_ms(500);
  8178. //存储异常并上传
  8179. CheckMode_Stop(false);
  8180. return;
  8181. }
  8182. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  8183. {
  8184. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
  8185. label_CheckModeStatus.Text = "存在故障!";
  8186. label_CheckModeResult.BackColor = Color.Red;
  8187. label_CheckModeResult.Text = "测试异常";
  8188. Delay_ms(500);
  8189. //存储异常并上传
  8190. CheckMode_Stop(false);
  8191. return;
  8192. }
  8193. label_CheckModeFWVer.BackColor = Color.Green;
  8194. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  8195. Delay_ms(500);
  8196. }
  8197. else
  8198. {
  8199. label_CheckModeFWVer.BackColor = Color.Yellow;
  8200. label_CheckModeStatus.Text = "跳过软件版本查询";
  8201. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过软件版本查询" + "\r\n");
  8202. Delay_ms(500);
  8203. }
  8204. //打标信息核对
  8205. if (checkBox_CheckModeSN.Checked)
  8206. {
  8207. label_CheckModeStatus.Text = "核对打标信息";
  8208. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "核对打标信息" + "\r\n");
  8209. //根据扫码信息获取型号和SN
  8210. string ScanInfo = textBox_CheckModeScan.Text;
  8211. string regexInfo = "";
  8212. string[] InfoList = { "" };
  8213. try
  8214. {
  8215. if (中置电机ToolStripMenuItem.Checked == true)
  8216. {
  8217. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  8218. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  8219. }
  8220. else if (轮毂电机ToolStripMenuItem.Checked == true)
  8221. {
  8222. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  8223. string Model = InfoList[0];
  8224. string Spec = InfoList[1];
  8225. string Sn = InfoList[2];
  8226. InfoList[0] = Model.Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  8227. InfoList[1] = Sn;
  8228. }
  8229. }
  8230. catch
  8231. {
  8232. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  8233. label_FacModeStatus.Text = "存在故障!";
  8234. label_FacModeResult.BackColor = Color.Red;
  8235. label_FacModeResult.Text = "标签格式错误";
  8236. Delay_ms(500);
  8237. //存储异常并上传
  8238. CheckMode_Stop(false);
  8239. return;
  8240. }
  8241. //核对型号
  8242. if (string.Equals(InfoList[0], Class_Motor_Ver.Mode) == false) //型号错误,直接结束
  8243. {
  8244. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号不一致" + "\r\n");
  8245. label_CheckModeStatus.Text = "存在故障!";
  8246. label_CheckModeResult.BackColor = Color.Red;
  8247. label_CheckModeResult.Text = "测试异常";
  8248. Delay_ms(500);
  8249. //存储异常并上传
  8250. CheckMode_Stop(false);
  8251. return;
  8252. }
  8253. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号一致" + "\r\n");
  8254. Delay_ms(500);
  8255. //核对SN
  8256. if (string.Equals(InfoList[1], Class_Motor_Ver.SN) == false) //型号错误,直接结束
  8257. {
  8258. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN不一致" + "\r\n");
  8259. label_CheckModeStatus.Text = "存在故障!";
  8260. label_CheckModeResult.BackColor = Color.Red;
  8261. label_CheckModeResult.Text = "测试异常";
  8262. Delay_ms(500);
  8263. //存储异常并上传
  8264. CheckMode_Stop(false);
  8265. return;
  8266. }
  8267. label_CheckModeSN.BackColor = Color.Green;
  8268. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN一致" + "\r\n");
  8269. Delay_ms(500);
  8270. }
  8271. else
  8272. {
  8273. label_CheckModeSN.BackColor = Color.Yellow;
  8274. label_CheckModeStatus.Text = "跳过打标信息确认";
  8275. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过打标信息确认" + "\r\n");
  8276. Delay_ms(500);
  8277. }
  8278. //参数检验
  8279. if (checkBox_CheckModeCfg.Checked)
  8280. {
  8281. //读取配置文件信息
  8282. label_CheckModeStatus.Text = "参数检查";
  8283. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  8284. //配置文件
  8285. List<byte[]> CmdList = new List<byte[]>();
  8286. Dictionary<string, string> ConfigCmd = new Dictionary<string, string>();//配置文件格式
  8287. //从服务器下载文件
  8288. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  8289. {
  8290. string SelectFile = "";
  8291. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "/" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  8292. if (File.Exists(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  8293. {
  8294. File.Delete(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  8295. }
  8296. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  8297. //打开文件
  8298. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  8299. ConfigCmd.Clear();
  8300. while (streamReader.Peek() != -1)
  8301. {
  8302. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  8303. if (fileLineInfo.Contains("["))
  8304. {
  8305. if (fileLineInfo.Contains("助力参数"))
  8306. {
  8307. fileLineInfo = streamReader.ReadLine();
  8308. }
  8309. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  8310. }
  8311. }
  8312. streamReader.Close();
  8313. }
  8314. //从本地加载文件
  8315. else
  8316. {
  8317. string SelectFile = "";
  8318. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  8319. //打开文件
  8320. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  8321. ConfigCmd.Clear();
  8322. while (streamReader.Peek() != -1)
  8323. {
  8324. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  8325. if (fileLineInfo.Contains("["))
  8326. {
  8327. if (fileLineInfo.Contains("助力参数"))
  8328. {
  8329. fileLineInfo = streamReader.ReadLine();
  8330. }
  8331. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  8332. }
  8333. }
  8334. streamReader.Close();
  8335. }
  8336. int CmdNum = ConfigCmd.Count(); //指令个数
  8337. Delay_ms(500);
  8338. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "\r\n");
  8339. Delay_ms(500);
  8340. //逐条读取比较
  8341. try
  8342. {
  8343. foreach (string key in ConfigCmd.Keys)
  8344. {
  8345. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令:" + "\r\n");
  8346. CmdRevStrTemp = "";
  8347. if (key.Contains("曲线"))
  8348. {
  8349. byte LineNum = 0;
  8350. var code = new byte[4];
  8351. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  8352. if (LineNum <= 5)
  8353. {
  8354. code[0] = (byte)(LineNum & 0xFF);
  8355. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8356. code[2] = (byte)(LineNum & 0xFF);
  8357. code[3] = (byte)((LineNum >> 8) & 0xFF);
  8358. }
  8359. else
  8360. {
  8361. code[0] = (byte)(LineNum & 0xFF);
  8362. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8363. code[2] = (byte)(5 & 0xFF);
  8364. code[3] = (byte)((5 >> 8) & 0xFF);
  8365. }
  8366. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  8367. }
  8368. else
  8369. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  8370. Delay_ms(500);
  8371. if (CmdRevStrTemp == string.Empty)
  8372. {
  8373. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令,第1次重发" + "\r\n");
  8374. if (key.Contains("曲线"))
  8375. {
  8376. byte LineNum = 0;
  8377. var code = new byte[4];
  8378. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  8379. if (LineNum <= 5)
  8380. {
  8381. code[0] = (byte)(LineNum & 0xFF);
  8382. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8383. code[2] = (byte)(LineNum & 0xFF);
  8384. code[3] = (byte)((LineNum >> 8) & 0xFF);
  8385. }
  8386. else
  8387. {
  8388. code[0] = (byte)(LineNum & 0xFF);
  8389. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8390. code[2] = (byte)(5 & 0xFF);
  8391. code[3] = (byte)((5 >> 8) & 0xFF);
  8392. }
  8393. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  8394. }
  8395. else
  8396. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  8397. Delay_ms(500);
  8398. if (CmdRevStrTemp == string.Empty)
  8399. {
  8400. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令,第2次重发" + "\r\n");
  8401. if (key.Contains("曲线"))
  8402. {
  8403. byte LineNum = 0;
  8404. var code = new byte[4];
  8405. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  8406. if (LineNum <= 5)
  8407. {
  8408. code[0] = (byte)(LineNum & 0xFF);
  8409. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8410. code[2] = (byte)(LineNum & 0xFF);
  8411. code[3] = (byte)((LineNum >> 8) & 0xFF);
  8412. }
  8413. else
  8414. {
  8415. code[0] = (byte)(LineNum & 0xFF);
  8416. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8417. code[2] = (byte)(5 & 0xFF);
  8418. code[3] = (byte)((5 >> 8) & 0xFF);
  8419. }
  8420. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  8421. }
  8422. else
  8423. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  8424. Delay_ms(500);
  8425. if (CmdRevStrTemp == string.Empty)
  8426. {
  8427. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "指令读取失败" + "\r\n");
  8428. label_CheckModeStatus.Text = "存在故障!";
  8429. label_CheckModeResult.BackColor = Color.Red;
  8430. label_CheckModeResult.Text = "测试异常";
  8431. Delay_ms(500);
  8432. //存储异常并上传
  8433. CheckMode_Stop(false);
  8434. return;
  8435. }
  8436. }
  8437. }
  8438. //比较当前指令,读取的配置文件和返回数据比较
  8439. string ParamWrite = ConfigCmd[key].Substring(24, ConfigCmd[key].Length - 40).Trim();
  8440. string ParamRead = "";
  8441. if (string.Compare(key, "[其它传感器参数]") == 0)
  8442. ParamRead = CmdRevStrTemp.Substring(90, CmdRevStrTemp.Length - 90).Trim(); //去掉去掉命令字、力矩传感器参数
  8443. else if (string.Compare(key, "[控制参数]") == 0)
  8444. ParamRead = CmdRevStrTemp.Substring(18, CmdRevStrTemp.Length - 18).Trim(); //去掉去掉命令字、位置零点
  8445. else
  8446. ParamRead = CmdRevStrTemp.Substring(6, CmdRevStrTemp.Length - 6).Trim(); //去掉命令字
  8447. if (ParamWrite.Contains(ParamRead))
  8448. {
  8449. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "一致" + "\r\n");
  8450. continue;
  8451. }
  8452. else
  8453. {
  8454. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "不一致" + "\r\n");
  8455. richTextBox_CheckModeLog.AppendText("写入参数:" + ParamWrite + "\r\n");
  8456. richTextBox_CheckModeLog.AppendText("读出参数:" + ParamRead + "\r\n");
  8457. label_CheckModeStatus.Text = "存在故障!";
  8458. label_CheckModeResult.BackColor = Color.Red;
  8459. label_CheckModeResult.Text = "测试异常";
  8460. Delay_ms(500);
  8461. //存储异常并上传
  8462. CheckMode_Stop(false);
  8463. return;
  8464. }
  8465. }
  8466. }
  8467. catch (System.Exception)
  8468. {
  8469. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数检验失败" + "\r\n");
  8470. label_CheckModeStatus.Text = "存在故障!";
  8471. label_CheckModeResult.BackColor = Color.Red;
  8472. label_CheckModeResult.Text = "测试异常";
  8473. Delay_ms(500);
  8474. //存储异常并上传
  8475. CheckMode_Stop(false);
  8476. return;
  8477. }
  8478. label_CheckModeCfg.BackColor = Color.Green;
  8479. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数检验正确" + "\r\n");
  8480. Delay_ms(500);
  8481. }
  8482. else
  8483. {
  8484. label_CheckModeCfg.BackColor = Color.Yellow;
  8485. label_CheckModeStatus.Text = "跳过参数检验";
  8486. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数检验" + "\r\n");
  8487. Delay_ms(500);
  8488. }
  8489. //读取力矩传感器
  8490. do
  8491. {
  8492. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据" + "\r\n");
  8493. //发送指令读取力矩传感器标定数据
  8494. CmdRevStrTemp = "";
  8495. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  8496. ACK_WaitCnt = 0;
  8497. while (ACK_WaitCnt <= 2) ; //1s
  8498. if (CmdRevStrTemp == string.Empty)
  8499. {
  8500. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据,第1次重发" + "\r\n");
  8501. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  8502. ACK_WaitCnt = 0;
  8503. while (ACK_WaitCnt <= 2) ; //1s
  8504. if (CmdRevStrTemp == string.Empty)
  8505. {
  8506. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据,第2次重发" + "\r\n");
  8507. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  8508. ACK_WaitCnt = 0;
  8509. while (ACK_WaitCnt <= 2) ; //1s
  8510. if (CmdRevStrTemp == string.Empty)
  8511. {
  8512. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取失败" + "\r\n");
  8513. label_CheckModeStatus.Text = "存在故障!";
  8514. label_CheckModeResult.BackColor = Color.Red;
  8515. label_CheckModeResult.Text = "测试异常";
  8516. Delay_ms(500);
  8517. //存储异常并上传
  8518. CheckMode_Stop(false);
  8519. return;
  8520. }
  8521. }
  8522. }
  8523. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取成功" + "\r\n");
  8524. //取力矩传感器数据
  8525. ushort ZeroInit, Zero1, Zero2, Zero3, ZeroNew;
  8526. ushort MaxTorque;
  8527. ushort K1_T, K1, K2_T, K2, K3_T, K3, K4_T, K4;
  8528. byte[] DataArray = mySerialProcess.HexStringToBytes(CmdRevStrTemp, true);
  8529. ushort Cmd = (ushort)((DataArray[0] << 8) + DataArray[1]);
  8530. if (Cmd != 0xB528)
  8531. {
  8532. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器参数错误,CMD: 0x" + Convert.ToString(Cmd, 16).PadLeft(2, '0').ToUpper() + "\r\n");
  8533. label_CheckModeStatus.Text = "存在故障!";
  8534. label_CheckModeResult.BackColor = Color.Red;
  8535. label_CheckModeResult.Text = "测试异常";
  8536. Delay_ms(500);
  8537. //存储异常并上传
  8538. CheckMode_Stop(false);
  8539. return;
  8540. }
  8541. ZeroInit = (ushort)((DataArray[3] << 8) + DataArray[2]);
  8542. Zero1 = (ushort)((DataArray[5] << 8) + DataArray[4]);
  8543. Zero2 = (ushort)((DataArray[7] << 8) + DataArray[6]);
  8544. Zero3 = (ushort)((DataArray[9] << 8) + DataArray[8]);
  8545. ZeroNew = (ushort)((DataArray[11] << 8) + DataArray[10]);
  8546. MaxTorque = (ushort)((DataArray[13] << 8) + DataArray[12]);
  8547. K1_T = (ushort)((DataArray[15] << 8) + DataArray[14]);
  8548. K1 = (ushort)((DataArray[17] << 8) + DataArray[16]);
  8549. K2_T = (ushort)((DataArray[19] << 8) + DataArray[18]);
  8550. K2 = (ushort)((DataArray[21] << 8) + DataArray[20]);
  8551. K3_T = (ushort)((DataArray[23] << 8) + DataArray[22]);
  8552. K3 = (ushort)((DataArray[25] << 8) + DataArray[24]);
  8553. K4_T = (ushort)((DataArray[27] << 8) + DataArray[26]);
  8554. K4 = (ushort)((DataArray[29] << 8) + DataArray[28]);
  8555. richTextBox_CheckModeLog.AppendText("力矩传感器零点: " + ZeroInit.ToString() + "," + Zero1.ToString() + "," +
  8556. Zero2.ToString() + "," + Zero3.ToString() + "," + ZeroNew.ToString() + "\r\n");
  8557. richTextBox_CheckModeLog.AppendText("最大力矩: " + MaxTorque.ToString() + "\r\n");
  8558. richTextBox_CheckModeLog.AppendText("力矩传感器标定: " + "[" + K1_T.ToString() + "," + K1.ToString() + "]" + "," +
  8559. "[" + K2_T.ToString() + "," + K2.ToString() + "]" + "," + "[" + K3_T.ToString() + "," + K3.ToString() + "]" + "," +
  8560. "[" + K4_T.ToString() + "," + K4.ToString() + "]" + "\r\n");
  8561. //传感器标定检验
  8562. if (checkBox_CheckModeTorque.Checked)
  8563. {
  8564. richTextBox_CheckModeLog.AppendText("力矩零点范围: " + TorqueParamsForm.Zero.Min.ToString() + " - " + TorqueParamsForm.Zero.Max.ToString() + "\r\n");
  8565. richTextBox_CheckModeLog.AppendText("K1范围: " + TorqueParamsForm.K1.T.ToString() + "," + TorqueParamsForm.K1.Min.ToString() + " - " + TorqueParamsForm.K1.Max.ToString() + "\r\n");
  8566. richTextBox_CheckModeLog.AppendText("K2范围: " + TorqueParamsForm.K2.T.ToString() + "," + TorqueParamsForm.K2.Min.ToString() + " - " + TorqueParamsForm.K2.Max.ToString() + "\r\n");
  8567. richTextBox_CheckModeLog.AppendText("K3范围: " + TorqueParamsForm.K3.T.ToString() + "," + TorqueParamsForm.K3.Min.ToString() + " - " + TorqueParamsForm.K3.Max.ToString() + "\r\n");
  8568. richTextBox_CheckModeLog.AppendText("K4范围: " + TorqueParamsForm.K4.T.ToString() + "," + TorqueParamsForm.K4.Min.ToString() + " - " + TorqueParamsForm.K4.Max.ToString() + "\r\n");
  8569. //与设置值比较
  8570. if ((ZeroInit <= TorqueParamsForm.Zero.Max) && (ZeroInit >= TorqueParamsForm.Zero.Min)
  8571. && (K1_T == TorqueParamsForm.K1.T) && (K1 <= TorqueParamsForm.K1.Max) && (K1 >= TorqueParamsForm.K1.Min)
  8572. && (K2_T == TorqueParamsForm.K2.T) && (K2 <= TorqueParamsForm.K2.Max) && (K2 >= TorqueParamsForm.K2.Min)
  8573. && (K3_T == TorqueParamsForm.K3.T) && (K3 <= TorqueParamsForm.K3.Max) && (K3 >= TorqueParamsForm.K3.Min)
  8574. && (K4_T == TorqueParamsForm.K4.T) && (K4 <= TorqueParamsForm.K4.Max) && (K4 >= TorqueParamsForm.K4.Min)
  8575. )
  8576. {
  8577. label_CheckModeTorque.BackColor = Color.Green;
  8578. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定正常" + "\r\n");
  8579. Delay_ms(500);
  8580. }
  8581. else
  8582. {
  8583. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定超范围" + "\r\n");
  8584. label_CheckModeStatus.Text = "存在故障!";
  8585. label_CheckModeResult.BackColor = Color.Red;
  8586. label_CheckModeResult.Text = "测试异常";
  8587. Delay_ms(500);
  8588. //存储异常并上传
  8589. CheckMode_Stop(false);
  8590. return;
  8591. }
  8592. }
  8593. else
  8594. {
  8595. label_CheckModeTorque.BackColor = Color.Yellow;
  8596. label_CheckModeStatus.Text = "跳过传感器标定检验";
  8597. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过传感器标定检验" + "\r\n");
  8598. Delay_ms(500);
  8599. }
  8600. } while (false);
  8601. //读取MOS内阻校准参数
  8602. do
  8603. {
  8604. if (checkBox_CheckModeMos.Checked)
  8605. {
  8606. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据" + "\r\n");
  8607. //读取显示校准返回数据
  8608. foreach (Control c in groupBox21.Controls)
  8609. {
  8610. if (c is TextBox)
  8611. c.Text = "";
  8612. }
  8613. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8614. ACK_WaitCnt = 0;
  8615. while (ACK_WaitCnt <= 2) ; //1s
  8616. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  8617. {
  8618. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据,第1次重发" + "\r\n");
  8619. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8620. ACK_WaitCnt = 0;
  8621. while (ACK_WaitCnt <= 2) ; //1s
  8622. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  8623. {
  8624. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据,第2次重发" + "\r\n");
  8625. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8626. ACK_WaitCnt = 0;
  8627. while (ACK_WaitCnt <= 2) ; //1s
  8628. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  8629. {
  8630. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果异常" + "\r\n");
  8631. label_CheckModeStatus.Text = "存在故障!";
  8632. label_CheckModeResult.BackColor = Color.Red;
  8633. label_CheckModeResult.Text = "测试异常";
  8634. Delay_ms(500);
  8635. //存储异常并上传
  8636. CheckMode_Stop(false);
  8637. return;
  8638. }
  8639. }
  8640. }
  8641. else
  8642. {
  8643. 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");
  8644. }
  8645. //与校准返回数据对比
  8646. string[] MOS_R1_Th = toolStripTextBox_MOS1.Text.Split(',');
  8647. string[] MOS_R2_Th = toolStripTextBox_MOS2.Text.Split(',');
  8648. string[] MOS_R3_Th = toolStripTextBox_MOS3.Text.Split(',');
  8649. 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])) &&
  8650. (Convert.ToUInt16(textBox_MOS_R2.Text) >= Convert.ToUInt16(MOS_R2_Th[0])) && (Convert.ToUInt16(textBox_MOS_R2.Text) <= Convert.ToUInt16(MOS_R2_Th[1])) &&
  8651. (Convert.ToUInt16(textBox_MOS_R3.Text) >= Convert.ToUInt16(MOS_R3_Th[0])) && (Convert.ToUInt16(textBox_MOS_R3.Text) <= Convert.ToUInt16(MOS_R3_Th[1]))
  8652. )
  8653. {
  8654. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准合格" + "\r\n");
  8655. label_CheckModeMos.BackColor = Color.Green;
  8656. }
  8657. else
  8658. {
  8659. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准超范围" + "\r\n");
  8660. label_CheckModeStatus.Text = "存在故障!";
  8661. label_CheckModeResult.BackColor = Color.Red;
  8662. label_CheckModeResult.Text = "测试异常";
  8663. Delay_ms(500);
  8664. //存储异常并上传
  8665. CheckMode_Stop(false);
  8666. return;
  8667. }
  8668. }
  8669. else
  8670. {
  8671. label_CheckModeMos.BackColor = Color.Yellow;
  8672. label_CheckModeStatus.Text = "跳过MOS内阻校准检验";
  8673. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过MOS内阻校准检验" + "\r\n");
  8674. Delay_ms(500);
  8675. }
  8676. } while (false);
  8677. //读取位置校准参数
  8678. do
  8679. {
  8680. if (checkBox_CheckModeAngle.Checked)
  8681. {
  8682. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取位置校准数据" + "\r\n");
  8683. //发送指令读取位置
  8684. CmdRevStrTemp = "";
  8685. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
  8686. ACK_WaitCnt = 0;
  8687. while (ACK_WaitCnt <= 2) ; //1s
  8688. if (CmdRevStrTemp == string.Empty)
  8689. {
  8690. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取位置校准数据,第1次重发" + "\r\n");
  8691. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x3E00, null);
  8692. ACK_WaitCnt = 0;
  8693. while (ACK_WaitCnt <= 2) ; //1s
  8694. if (CmdRevStrTemp == string.Empty)
  8695. {
  8696. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取位置校准数据,第2次重发" + "\r\n");
  8697. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x3E00, null);
  8698. ACK_WaitCnt = 0;
  8699. while (ACK_WaitCnt <= 2) ; //1s
  8700. if (CmdRevStrTemp == string.Empty)
  8701. {
  8702. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准数据读取失败" + "\r\n");
  8703. label_CheckModeStatus.Text = "存在故障!";
  8704. label_CheckModeResult.BackColor = Color.Red;
  8705. label_CheckModeResult.Text = "测试异常";
  8706. Delay_ms(500);
  8707. //存储异常并上传
  8708. CheckMode_Stop(false);
  8709. return;
  8710. }
  8711. }
  8712. }
  8713. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准数据读取成功" + "\r\n");
  8714. //取零点数据
  8715. UInt16 AngleZero_Init = 0, AngleZero_Cur = 0;
  8716. byte[] DataArray = mySerialProcess.HexStringToBytes(CmdRevStrTemp, true);
  8717. ushort Cmd = (ushort)((DataArray[0] << 8) + DataArray[1]);
  8718. if (Cmd != 0xB420)
  8719. {
  8720. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置传感器参数错误,CMD: 0x" + Convert.ToString(Cmd, 16).PadLeft(2, '0').ToUpper() + "\r\n");
  8721. label_CheckModeStatus.Text = "存在故障!";
  8722. label_CheckModeResult.BackColor = Color.Red;
  8723. label_CheckModeResult.Text = "测试异常";
  8724. Delay_ms(500);
  8725. //存储异常并上传
  8726. CheckMode_Stop(false);
  8727. return;
  8728. }
  8729. AngleZero_Init = (ushort)((DataArray[3] << 8) + DataArray[2]);
  8730. AngleZero_Cur = (ushort)((DataArray[5] << 8) + DataArray[4]);
  8731. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置出厂零点: " + AngleZero_Init.ToString() + ",位置当前零点: " + AngleZero_Cur.ToString() + "\r\n");
  8732. int AngleZeroDiff = Math.Abs(AngleZero_Cur - AngleZero_Init);
  8733. int AngleZeroTH = Convert.ToInt32(textBox_AngleZeroTh.Text);
  8734. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置零点校准值: " + AngleZeroDiff.ToString() + ",判断阈值: " + AngleZeroTH.ToString() + "\r\n");
  8735. //判断
  8736. if (AngleZeroDiff <= AngleZeroTH)
  8737. {
  8738. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置传感器校准合格" + "\r\n");
  8739. label_CheckModeAngle.BackColor = Color.Green;
  8740. }
  8741. else
  8742. {
  8743. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置传感器校准超范围" + "\r\n");
  8744. label_CheckModeStatus.Text = "存在故障!";
  8745. label_CheckModeResult.BackColor = Color.Red;
  8746. label_CheckModeResult.Text = "测试异常";
  8747. Delay_ms(500);
  8748. //存储异常并上传
  8749. CheckMode_Stop(false);
  8750. return;
  8751. }
  8752. }
  8753. else
  8754. {
  8755. label_CheckModeAngle.BackColor = Color.Yellow;
  8756. label_CheckModeStatus.Text = "跳过位置传感器校准检验";
  8757. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过位置传感器校准检验" + "\r\n");
  8758. Delay_ms(500);
  8759. }
  8760. } while (false);
  8761. //测试合格
  8762. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  8763. label_CheckModeStatus.Text = "测试结束!";
  8764. label_CheckModeResult.BackColor = Color.Green;
  8765. label_CheckModeResult.Text = "测试合格";
  8766. Delay_ms(500);
  8767. //存储并上传
  8768. CheckMode_Stop(true);
  8769. return;
  8770. }
  8771. private void CheckModeLabelInit()
  8772. {
  8773. //测试状态标签
  8774. label_CheckModeResult.BackColor = Color.Yellow;
  8775. label_CheckModeResult.Text = "测试中";
  8776. //测试过程标签
  8777. label_CheckModeStatus.Text = "测试就绪";
  8778. //测试结果标签
  8779. foreach (Control c in groupBox31.Controls)
  8780. {
  8781. if (c is Label)
  8782. {
  8783. if (c.Text == string.Empty)
  8784. c.BackColor = Color.Red;
  8785. }
  8786. }
  8787. }
  8788. private void 调试记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  8789. {
  8790. System.Diagnostics.Process.Start("explorer.exe", Directory.GetCurrentDirectory());
  8791. }
  8792. private void 生产记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  8793. {
  8794. System.Diagnostics.Process.Start("explorer.exe", localInfo.LocalDataPath);
  8795. }
  8796. private void 累计运行时间ToolStripMenuItem_MouseHover(object sender, EventArgs e)
  8797. {
  8798. UInt32 Time = (UInt32)stopwatch.ElapsedMilliseconds / 1000;
  8799. UInt32 hour = Time / 3600;
  8800. UInt32 min = (Time % 3600) / 60;
  8801. UInt32 s = (Time % 60);
  8802. toolStripMenuItem_RunTime.Text = hour.ToString() + ":" + min.ToString("00") + ":" + s.ToString("00");
  8803. }
  8804. private void richTextBox_CheckModeLog_TextChanged(object sender, EventArgs e)
  8805. {
  8806. richTextBox_CheckModeLog.SelectionStart = richTextBox_CheckModeLog.Text.Length;
  8807. richTextBox_CheckModeLog.ScrollToCaret();
  8808. }
  8809. private void 力矩传感器检验ToolStripMenuItem_Click(object sender, EventArgs e)
  8810. {
  8811. TorqueParamsForm.ShowDialog();
  8812. }
  8813. private void textBox_CheckModeScan_KeyUp(object sender, KeyEventArgs e)
  8814. {
  8815. if (e.KeyCode == Keys.Enter)
  8816. CheckTestStart();
  8817. }
  8818. private void textBox_FacModeScan_KeyUp(object sender, KeyEventArgs e)
  8819. {
  8820. if (e.KeyCode == Keys.Enter)
  8821. TestStart();
  8822. }
  8823. private void button_SpeedDec10_Click(object sender, EventArgs e)
  8824. {
  8825. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  8826. if (Percent <= 10)
  8827. Percent = 0;
  8828. else
  8829. Percent -= 10;
  8830. //生产模式转速设置值更新
  8831. textBox_MotorSpeedPercent.Text = Percent.ToString();
  8832. //设置转速百分比
  8833. var Data = new byte[1];
  8834. Data[0] = (byte)Percent;
  8835. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  8836. }
  8837. private void button_SpeedAdd10_Click(object sender, EventArgs e)
  8838. {
  8839. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  8840. if (Percent >= 90)
  8841. Percent = 100;
  8842. else
  8843. Percent += 10;
  8844. //生产模式转速设置值更新
  8845. textBox_MotorSpeedPercent.Text = Percent.ToString();
  8846. //设置转速百分比
  8847. var Data = new byte[1];
  8848. Data[0] = (byte)Percent;
  8849. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  8850. }
  8851. private void button_SpeedDec1_Click(object sender, EventArgs e)
  8852. {
  8853. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  8854. if (Percent <= 1)
  8855. Percent = 0;
  8856. else
  8857. Percent -= 1;
  8858. //生产模式转速设置值更新
  8859. textBox_MotorSpeedPercent.Text = Percent.ToString();
  8860. //设置转速百分比
  8861. var Data = new byte[1];
  8862. Data[0] = (byte)Percent;
  8863. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  8864. }
  8865. private void button_SpeedAdd1_Click(object sender, EventArgs e)
  8866. {
  8867. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  8868. if (Percent >= 99)
  8869. Percent = 100;
  8870. else
  8871. Percent += 1;
  8872. //生产模式转速设置值更新
  8873. textBox_MotorSpeedPercent.Text = Percent.ToString();
  8874. //设置转速百分比
  8875. var Data = new byte[1];
  8876. Data[0] = (byte)Percent;
  8877. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  8878. }
  8879. bool WriteLockStatus = true;
  8880. private void pictureBox_WriteLock_Click(object sender, EventArgs e)
  8881. {
  8882. if (WriteLockStatus == true)
  8883. {
  8884. EnterForm1.ShowDialog();
  8885. try
  8886. {
  8887. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  8888. {
  8889. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  8890. {
  8891. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  8892. foreach (Control c in groupBox2.Controls)
  8893. {
  8894. if (c is CheckBox)
  8895. c.Enabled = true;
  8896. }
  8897. WriteLockStatus = !WriteLockStatus;
  8898. }
  8899. else
  8900. {
  8901. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8902. }
  8903. }
  8904. else
  8905. {
  8906. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8907. }
  8908. }
  8909. catch (Exception)
  8910. {
  8911. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8912. }
  8913. }
  8914. else
  8915. {
  8916. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  8917. foreach (Control c in groupBox2.Controls)
  8918. {
  8919. if (c is CheckBox)
  8920. c.Enabled = false;
  8921. }
  8922. WriteLockStatus = !WriteLockStatus;
  8923. }
  8924. }
  8925. bool ReadLockStatus = true;
  8926. private void pictureBox_ReadLock_Click(object sender, EventArgs e)
  8927. {
  8928. if (ReadLockStatus == true)
  8929. {
  8930. EnterForm1.ShowDialog();
  8931. try
  8932. {
  8933. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  8934. {
  8935. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  8936. {
  8937. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  8938. foreach (Control c in groupBox29.Controls)
  8939. {
  8940. if (c is CheckBox)
  8941. c.Enabled = true;
  8942. }
  8943. ReadLockStatus = !ReadLockStatus;
  8944. }
  8945. else
  8946. {
  8947. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8948. }
  8949. }
  8950. else
  8951. {
  8952. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8953. }
  8954. }
  8955. catch (Exception)
  8956. {
  8957. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8958. }
  8959. }
  8960. else
  8961. {
  8962. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  8963. foreach (Control c in groupBox29.Controls)
  8964. {
  8965. if (c is CheckBox)
  8966. c.Enabled = false;
  8967. }
  8968. ReadLockStatus = !ReadLockStatus;
  8969. }
  8970. }
  8971. private void 屏幕键盘ToolStripMenuItem_Click(object sender, EventArgs e)
  8972. {
  8973. System.Diagnostics.Process.Start("osk.exe");
  8974. }
  8975. private void checkBox_OffLineCheckMode_CheckedChanged(object sender, EventArgs e)
  8976. {
  8977. comboBox_CheckModeCfgDate.SelectedIndex = -1;
  8978. comboBox_CheckModeCfgFile.SelectedIndex = -1;
  8979. checkBox_OffLineFacMode.Checked = checkBox_OffLineCheckMode.Checked;
  8980. }
  8981. private void checkBox_OffLineFacMode_CheckedChanged(object sender, EventArgs e)
  8982. {
  8983. comboBox_FacModeCfgDate.SelectedIndex = -1;
  8984. comboBox_FacModeCfgFile.SelectedIndex = -1;
  8985. checkBox_OffLineCheckMode.Checked = checkBox_OffLineFacMode.Checked;
  8986. }
  8987. private void 版本ToolStripMenuItem_Click(object sender, EventArgs e)
  8988. {
  8989. VersionForm.ShowDialog();
  8990. }
  8991. private void button_MOS_Cal_Click(object sender, EventArgs e)
  8992. {
  8993. textBox_MOS_R1.Text = "";
  8994. textBox_MOS_R2.Text = "";
  8995. textBox_MOS_R3.Text = "";
  8996. try
  8997. {
  8998. var Code = new byte[18];
  8999. for (int i = 0; i < 18; i++)
  9000. Code[i] = 0;
  9001. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  9002. ushort uwDataTemp = 0;
  9003. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  9004. Code[2] = (byte)(uwDataTemp & 0xFF);
  9005. Code[3] = (byte)(uwDataTemp >> 8);
  9006. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  9007. Code[4] = (byte)(uwDataTemp & 0xFF);
  9008. Code[5] = (byte)(uwDataTemp >> 8);
  9009. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  9010. Code[6] = (byte)(uwDataTemp & 0xFF);
  9011. Code[7] = (byte)(uwDataTemp >> 8);
  9012. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  9013. Code[8] = (byte)(uwDataTemp & 0xFF);
  9014. Code[9] = (byte)(uwDataTemp >> 8);
  9015. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  9016. Code[10] = (byte)(uwDataTemp & 0xFF);
  9017. Code[11] = (byte)(uwDataTemp >> 8);
  9018. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  9019. }
  9020. catch (Exception)
  9021. {
  9022. MessageBox.Show("系数填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9023. }
  9024. }
  9025. private void button_MOS_Read_Click(object sender, EventArgs e)
  9026. {
  9027. foreach (Control c in groupBox21.Controls)
  9028. {
  9029. if (c is TextBox)
  9030. c.Text = "";
  9031. }
  9032. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  9033. }
  9034. private void button_MOS_Write_Click(object sender, EventArgs e)
  9035. {
  9036. try
  9037. {
  9038. var Code = new byte[34];
  9039. for (int i = 0; i < 34; i++)
  9040. Code[i] = 0;
  9041. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  9042. ushort uwDataTemp = 0;
  9043. uwDataTemp = Convert.ToUInt16(textBox_MOS_R1.Text);
  9044. Code[2] = (byte)(uwDataTemp & 0xFF);
  9045. Code[3] = (byte)(uwDataTemp >> 8);
  9046. uwDataTemp = Convert.ToUInt16(textBox_MOS_R2.Text);
  9047. Code[4] = (byte)(uwDataTemp & 0xFF);
  9048. Code[5] = (byte)(uwDataTemp >> 8);
  9049. uwDataTemp = Convert.ToUInt16(textBox_MOS_R3.Text);
  9050. Code[6] = (byte)(uwDataTemp & 0xFF);
  9051. Code[7] = (byte)(uwDataTemp >> 8);
  9052. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  9053. Code[8] = (byte)(uwDataTemp & 0xFF);
  9054. Code[9] = (byte)(uwDataTemp >> 8);
  9055. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  9056. Code[10] = (byte)(uwDataTemp & 0xFF);
  9057. Code[11] = (byte)(uwDataTemp >> 8);
  9058. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  9059. Code[12] = (byte)(uwDataTemp & 0xFF);
  9060. Code[13] = (byte)(uwDataTemp >> 8);
  9061. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  9062. Code[14] = (byte)(uwDataTemp & 0xFF);
  9063. Code[15] = (byte)(uwDataTemp >> 8);
  9064. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  9065. Code[16] = (byte)(uwDataTemp & 0xFF);
  9066. Code[17] = (byte)(uwDataTemp >> 8);
  9067. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4C22, Code);
  9068. }
  9069. catch (Exception)
  9070. {
  9071. MessageBox.Show("数据填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9072. }
  9073. }
  9074. /// <summary>
  9075. /// 测试模式点击文本框自动全选
  9076. /// </summary>
  9077. /// <param name="sender"></param>
  9078. /// <param name="e"></param>
  9079. private void textBox_FacModeScan_MouseClick(object sender, MouseEventArgs e)
  9080. {
  9081. textBox_FacModeScan.SelectAll();
  9082. }
  9083. /// <summary>
  9084. /// 检验模式点击文本框自动全选
  9085. /// </summary>
  9086. /// <param name="sender"></param>
  9087. /// <param name="e"></param>
  9088. private void textBox_CheckModeScan_MouseClick(object sender, MouseEventArgs e)
  9089. {
  9090. textBox_CheckModeScan.SelectAll();
  9091. }
  9092. /// <summary>
  9093. /// 鼠标放置显示连接服务器信息
  9094. /// </summary>
  9095. /// <param name="sender"></param>
  9096. /// <param name="e"></param>
  9097. private void label_ServerStatus_MouseHover(object sender, EventArgs e)
  9098. {
  9099. // 创建the ToolTip
  9100. ToolTip toolTip1 = new ToolTip();
  9101. // 设置显示样式
  9102. toolTip1.AutoPopDelay = 30000;//提示信息的可见时间
  9103. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  9104. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  9105. toolTip1.ShowAlways = true;//是否显示提示框
  9106. if (myFtp.IsNetConnected)
  9107. {
  9108. toolTip1.SetToolTip(this.label_ServerStatus, "IP: " + ServerIP);//设置故障内容显示
  9109. }
  9110. else
  9111. {
  9112. toolTip1.SetToolTip(this.label_ServerStatus, "网络断开");//设置故障内容显示
  9113. }
  9114. }
  9115. /// <summary>
  9116. /// UART协议类型修改
  9117. /// </summary>
  9118. /// <param name="sender"></param>
  9119. /// <param name="e"></param>
  9120. private void 协议类型ToolStripMenuItem_SelectedIndexChanged(object sender, EventArgs e)
  9121. {
  9122. var Code = new byte[2];
  9123. Code[0] = (byte)协议类型ToolStripMenuItem.SelectedIndex;
  9124. Code[1] = 0x00;
  9125. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  9126. }
  9127. /// <summary>
  9128. /// 显示本机信息
  9129. /// </summary>
  9130. /// <param name="sender"></param>
  9131. /// <param name="e"></param>
  9132. private void 本机信息ToolStripMenuItem_Click(object sender, EventArgs e)
  9133. {
  9134. MessageBox.Show(Local_HdInformation, "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
  9135. }
  9136. /// <summary>
  9137. /// 量产模式删除当前选中文件
  9138. /// </summary>
  9139. /// <param name="sender"></param>
  9140. /// <param name="e"></param>
  9141. private void label112_DoubleClick(object sender, EventArgs e)
  9142. {
  9143. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9144. {
  9145. EnterForm1.ShowDialog();
  9146. try
  9147. {
  9148. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9149. {
  9150. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  9151. {
  9152. try
  9153. {
  9154. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + comboBox_FacModeCfgFile.Text);
  9155. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_FacModeCfgFile.Text) + ".src");
  9156. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_FacModeCfgFile.Text) + ".png");
  9157. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9158. }
  9159. catch (Exception)
  9160. {
  9161. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9162. }
  9163. }
  9164. else
  9165. {
  9166. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9167. }
  9168. }
  9169. }
  9170. catch (Exception)
  9171. {
  9172. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9173. }
  9174. }
  9175. }
  9176. /// <summary>
  9177. /// 检验模式删除当前选中文件
  9178. /// </summary>
  9179. /// <param name="sender"></param>
  9180. /// <param name="e"></param>
  9181. private void label138_DoubleClick(object sender, EventArgs e)
  9182. {
  9183. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9184. {
  9185. EnterForm1.ShowDialog();
  9186. try
  9187. {
  9188. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9189. {
  9190. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  9191. {
  9192. try
  9193. {
  9194. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + comboBox_CheckModeCfgFile.Text);
  9195. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_CheckModeCfgFile.Text) + ".src");
  9196. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_CheckModeCfgFile.Text) + ".png");
  9197. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9198. }
  9199. catch (Exception)
  9200. {
  9201. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9202. }
  9203. }
  9204. else
  9205. {
  9206. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9207. }
  9208. }
  9209. }
  9210. catch (Exception)
  9211. {
  9212. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9213. }
  9214. }
  9215. }
  9216. /// <summary>
  9217. /// 读取整车信息2
  9218. /// </summary>
  9219. /// <param name="sender"></param>
  9220. /// <param name="e"></param>
  9221. private void button_ReadBikeParam2_Click(object sender, EventArgs e)
  9222. {
  9223. richTextBox_BikeParam2.Clear();
  9224. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null);
  9225. }
  9226. /// <summary>
  9227. /// 写入整车信息2
  9228. /// </summary>
  9229. /// <param name="sender"></param>
  9230. /// <param name="e"></param>
  9231. private void button_WriteBikeParam2_Click(object sender, EventArgs e)
  9232. {
  9233. var ConfigParam = new byte[34];
  9234. for (int i = 0; i < 34; i++)
  9235. ConfigParam[i] = 0;
  9236. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  9237. string[] strDataTemp = richTextBox_BikeParam2.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  9238. try
  9239. {
  9240. for (int i = 0; i < strDataTemp.Length; i++)
  9241. {
  9242. short wDataTemp = 0;
  9243. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  9244. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  9245. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  9246. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  9247. }
  9248. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4D22, ConfigParam);
  9249. }
  9250. catch (Exception)
  9251. {
  9252. timer_500ms.Enabled = false;
  9253. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9254. timer_500ms.Enabled = true;
  9255. }
  9256. }
  9257. /// <summary>
  9258. /// 读取用户骑行参数
  9259. /// </summary>
  9260. /// <param name="sender"></param>
  9261. /// <param name="e"></param>
  9262. private void button_ReadUsrRideParam_Click(object sender, EventArgs e)
  9263. {
  9264. richTextBox_UsrRidesParam.Clear();
  9265. if (checkBox_UserRideParam_OBC.Checked)
  9266. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x4300, null);
  9267. else
  9268. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  9269. }
  9270. /// <summary>
  9271. /// 写入用户骑行参数
  9272. /// </summary>
  9273. /// <param name="sender"></param>
  9274. /// <param name="e"></param>
  9275. private void button_WriteUsrRidetParam_Click(object sender, EventArgs e)
  9276. {
  9277. var ConfigParam = new byte[34];
  9278. for (int i = 0; i < 34; i++)
  9279. ConfigParam[i] = 0;
  9280. if (checkBox_UserRideParam_OBC.Checked)
  9281. {
  9282. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  9283. string[] strDataTemp = richTextBox_UsrRidesParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  9284. try
  9285. {
  9286. for (int i = 0; i < strDataTemp.Length; i++)
  9287. {
  9288. ConfigParam[i + 2] = Convert.ToByte(strDataTemp[i].Split('=')[1]);
  9289. }
  9290. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4B22, ConfigParam);
  9291. }
  9292. catch (Exception)
  9293. {
  9294. timer_500ms.Enabled = false;
  9295. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9296. timer_500ms.Enabled = true;
  9297. }
  9298. }
  9299. else
  9300. {
  9301. string[] strDataTemp = richTextBox_UsrRidesParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  9302. try
  9303. {
  9304. for (int i = 0; i < strDataTemp.Length; i++)
  9305. {
  9306. ConfigParam[i] = Convert.ToByte(strDataTemp[i].Split('=')[1]);
  9307. }
  9308. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x4420, ConfigParam);
  9309. }
  9310. catch (Exception)
  9311. {
  9312. timer_500ms.Enabled = false;
  9313. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9314. timer_500ms.Enabled = true;
  9315. }
  9316. }
  9317. }
  9318. /// <summary>
  9319. /// 读取产品标签
  9320. /// </summary>
  9321. /// <param name="sender"></param>
  9322. /// <param name="e"></param>
  9323. private void button_ReadTag_Click(object sender, EventArgs e)
  9324. {
  9325. textBox_TagInfo.Text = "---";
  9326. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4E00, null);
  9327. }
  9328. /// <summary>
  9329. /// 写入产品标签
  9330. /// </summary>
  9331. /// <param name="sender"></param>
  9332. /// <param name="e"></param>
  9333. private void button_WriteTag_Click(object sender, EventArgs e)
  9334. {
  9335. string User = textBox_TagInfo.Text;
  9336. var UserArray = new byte[32];
  9337. for (ushort i = 0; i < User.Length; i++)
  9338. {
  9339. UserArray[i] = (byte)User[i];
  9340. }
  9341. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D20, UserArray);
  9342. }
  9343. /// <summary>
  9344. /// 上位机读取骑行历史
  9345. /// </summary>
  9346. /// <param name="sender"></param>
  9347. /// <param name="e"></param>
  9348. private void button_ReadRideLog_Click(object sender, EventArgs e)
  9349. {
  9350. textBox_ODO_KM.Text = "---";
  9351. textBox_ODO_TIME.Text = "---";
  9352. textBox_TRIP_KM.Text = "---";
  9353. textBox_TRIP_TIME.Text = "---";
  9354. textBox_OBC_TRIP_KM.Text = "";
  9355. textBox_OBC_TRIP_TIME.Text = "";
  9356. textBox_OBC_ODO_KM.Text = "";
  9357. textBox_OBC_ODO_TIME.Text = "";
  9358. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2E00, null);
  9359. }
  9360. /// <summary>
  9361. /// 上位机写入骑行历史
  9362. /// </summary>
  9363. /// <param name="sender"></param>
  9364. /// <param name="e"></param>
  9365. private void button_WriteRideLog_Click(object sender, EventArgs e)
  9366. {
  9367. UInt32 Data;
  9368. var UserArray = new byte[16];
  9369. try
  9370. {
  9371. Data = Convert.ToUInt32(textBox_ODO_KM.Text);
  9372. UserArray[0] = (byte)(Data & 0xFF);
  9373. UserArray[1] = (byte)(Data >> 8);
  9374. UserArray[2] = (byte)(Data >> 16);
  9375. UserArray[3] = (byte)(Data >> 24);
  9376. Data = Convert.ToUInt32(textBox_ODO_TIME.Text);
  9377. UserArray[4] = (byte)(Data & 0xFF);
  9378. UserArray[5] = (byte)(Data >> 8);
  9379. UserArray[6] = (byte)(Data >> 16);
  9380. UserArray[7] = (byte)(Data >> 24);
  9381. Data = Convert.ToUInt32(textBox_TRIP_KM.Text);
  9382. UserArray[8] = (byte)(Data & 0xFF);
  9383. UserArray[9] = (byte)(Data >> 8);
  9384. UserArray[10] = (byte)(Data >> 16);
  9385. UserArray[11] = (byte)(Data >> 24);
  9386. Data = Convert.ToUInt32(textBox_TRIP_TIME.Text);
  9387. UserArray[12] = (byte)(Data & 0xFF);
  9388. UserArray[13] = (byte)(Data >> 8);
  9389. UserArray[14] = (byte)(Data >> 16);
  9390. UserArray[15] = (byte)(Data >> 24);
  9391. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B10, UserArray);
  9392. }
  9393. catch (Exception ex)
  9394. {
  9395. MessageBox.Show("数据格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9396. }
  9397. }
  9398. /// <summary>
  9399. /// 获取删除配置文件日期列表
  9400. /// </summary>
  9401. /// <param name="sender"></param>
  9402. /// <param name="e"></param>
  9403. private void toolStripTextBox_DelCfgFile_Click(object sender, EventArgs e)
  9404. {
  9405. string[] DateList = { "" };
  9406. //网络断开时直接退出
  9407. if (!myFtp.IsNetConnected)
  9408. return;
  9409. //从服务器更新日期列表
  9410. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
  9411. toolStripTextBox_DelCfgFile.Items.Clear();
  9412. //日期列表加载,显示最近30条
  9413. if (DateList.Length > 30)
  9414. {
  9415. toolStripTextBox_DelCfgFile.Items.Add("支持最近30条");
  9416. toolStripTextBox_DelCfgFile.Items.Add("-----");
  9417. }
  9418. for (int i = (DateList.Length > 30) ? (DateList.Length - 30) : 0; i < DateList.Length; i++)//显示最近30个日期
  9419. {
  9420. toolStripTextBox_DelCfgFile.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  9421. }
  9422. }
  9423. /// <summary>
  9424. /// 删除指定配置文件
  9425. /// </summary>
  9426. /// <param name="sender"></param>
  9427. /// <param name="e"></param>
  9428. private void toolStripTextBox_DelCfgFile_SelectedIndexChanged(object sender, EventArgs e)
  9429. {
  9430. //提示输入文件名
  9431. Scan scan_form = new Scan();
  9432. scan_form.ShowDialog();
  9433. do
  9434. {
  9435. if (scan_form.textBox_Scan.Text == string.Empty)
  9436. {
  9437. timer_500ms.Enabled = false;
  9438. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9439. timer_500ms.Enabled = true;
  9440. break;
  9441. }
  9442. string DelFile = scan_form.textBox_Scan.Text;
  9443. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9444. {
  9445. EnterForm1.ShowDialog();
  9446. try
  9447. {
  9448. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9449. {
  9450. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  9451. {
  9452. try
  9453. {
  9454. if (DelFile.Contains("."))
  9455. DelFile = Path.GetFileNameWithoutExtension(DelFile);
  9456. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".ttcfg");
  9457. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".src");
  9458. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".png");
  9459. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9460. }
  9461. catch (Exception)
  9462. {
  9463. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9464. }
  9465. }
  9466. else
  9467. {
  9468. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9469. }
  9470. }
  9471. }
  9472. catch (Exception)
  9473. {
  9474. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9475. }
  9476. }
  9477. } while (false);
  9478. }
  9479. /// <summary>
  9480. /// 获取删除样机测试记录日期列表
  9481. /// </summary>
  9482. /// <param name="sender"></param>
  9483. /// <param name="e"></param>
  9484. private void toolStripTextBox_DelLogFile_Click(object sender, EventArgs e)
  9485. {
  9486. string[] DateList = { "" };
  9487. //网络断开时直接退出
  9488. if (!myFtp.IsNetConnected)
  9489. return;
  9490. //从服务器更新日期列表
  9491. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName);
  9492. toolStripTextBox_DelLogFile.Items.Clear();
  9493. //日期列表加载,显示最近30天
  9494. if (DateList.Length > 30)
  9495. {
  9496. toolStripTextBox_DelLogFile.Items.Add("支持最近30条");
  9497. toolStripTextBox_DelLogFile.Items.Add("-----");
  9498. }
  9499. for (int i = (DateList.Length > 30) ? (DateList.Length - 30) : 0; i < DateList.Length; i++)//显示最近30个日期
  9500. {
  9501. toolStripTextBox_DelLogFile.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  9502. }
  9503. }
  9504. /// <summary>
  9505. /// 删除指定的样机测试记录
  9506. /// </summary>
  9507. /// <param name="sender"></param>
  9508. /// <param name="e"></param>
  9509. private void toolStripTextBox_DelLogFile_SelectedIndexChanged(object sender, EventArgs e)
  9510. {
  9511. //提示输入文件名
  9512. Scan scan_form = new Scan();
  9513. scan_form.ShowDialog();
  9514. do
  9515. {
  9516. if (scan_form.textBox_Scan.Text == string.Empty)
  9517. {
  9518. timer_500ms.Enabled = false;
  9519. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9520. timer_500ms.Enabled = true;
  9521. break;
  9522. }
  9523. string DelFile = scan_form.textBox_Scan.Text;
  9524. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9525. {
  9526. EnterForm1.ShowDialog();
  9527. try
  9528. {
  9529. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9530. {
  9531. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  9532. {
  9533. try
  9534. {
  9535. //删除指定目录下面所有文件和文件夹
  9536. myFtp.DelDirectoryWithAll(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName + "\\" + toolStripTextBox_DelLogFile.Text + "\\" + DelFile);
  9537. myFtp.RemoveDirectory(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName + "\\" + toolStripTextBox_DelLogFile.Text + "\\" + DelFile);
  9538. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9539. }
  9540. catch (Exception)
  9541. {
  9542. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9543. }
  9544. }
  9545. else
  9546. {
  9547. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9548. }
  9549. }
  9550. }
  9551. catch (Exception)
  9552. {
  9553. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9554. }
  9555. }
  9556. } while (false);
  9557. }
  9558. /// <summary>
  9559. /// CAN协议选择
  9560. /// </summary>
  9561. /// <param name="sender"></param>
  9562. /// <param name="e"></param>
  9563. private void cANToolStripMenuItem_Click(object sender, EventArgs e)
  9564. {
  9565. cANToolStripMenuItem.Checked= true;
  9566. uARTToolStripMenuItem.Checked = false;
  9567. UART协议ToolStripMenuItem.Visible = false;
  9568. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9569. }
  9570. /// <summary>
  9571. /// UART协议选择
  9572. /// </summary>
  9573. /// <param name="sender"></param>
  9574. /// <param name="e"></param>
  9575. private void uARTToolStripMenuItem_Click(object sender, EventArgs e)
  9576. {
  9577. cANToolStripMenuItem.Checked = false;
  9578. uARTToolStripMenuItem.Checked = true;
  9579. UART协议ToolStripMenuItem.Visible = true;
  9580. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9581. }
  9582. /// <summary>
  9583. /// 清除流水号
  9584. /// </summary>
  9585. /// <param name="sender"></param>
  9586. /// <param name="e"></param>
  9587. private void label131_DoubleClick(object sender, EventArgs e)
  9588. {
  9589. if (MessageBox.Show("确认清零流水号?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9590. {
  9591. label_FacModeSerial.Text = "0";
  9592. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, label_FacModeSerial.Text);
  9593. }
  9594. }
  9595. /// <summary>
  9596. /// 清除流水号
  9597. /// </summary>
  9598. /// <param name="sender"></param>
  9599. /// <param name="e"></param>
  9600. private void label135_DoubleClick(object sender, EventArgs e)
  9601. {
  9602. if (MessageBox.Show("确认清零流水号?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9603. {
  9604. label_CheckModeSerial.Text = "0";
  9605. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, label_CheckModeSerial.Text);
  9606. }
  9607. }
  9608. /// <summary>
  9609. /// 打开自动更新
  9610. /// </summary>
  9611. /// <param name="sender"></param>
  9612. /// <param name="e"></param>
  9613. private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
  9614. {
  9615. 打开ToolStripMenuItem.Checked = true;
  9616. 关闭ToolStripMenuItem.Checked = false;
  9617. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9618. }
  9619. /// <summary>
  9620. /// 关闭自动更新
  9621. /// </summary>
  9622. /// <param name="sender"></param>
  9623. /// <param name="e"></param>
  9624. private void 关闭ToolStripMenuItem_Click(object sender, EventArgs e)
  9625. {
  9626. 打开ToolStripMenuItem.Checked = false;
  9627. 关闭ToolStripMenuItem.Checked = true;
  9628. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9629. }
  9630. /// <summary>
  9631. /// 显示完整配置文件
  9632. /// </summary>
  9633. /// <param name="sender"></param>
  9634. /// <param name="e"></param>
  9635. private void comboBox_FacModeCfgFile_MouseHover_1(object sender, EventArgs e)
  9636. {
  9637. // 创建the ToolTip
  9638. ToolTip toolTip1 = new ToolTip();
  9639. // 设置显示样式
  9640. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  9641. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  9642. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  9643. toolTip1.ShowAlways = true;//是否显示提示框
  9644. // 设置伴随的对象.
  9645. toolTip1.SetToolTip(this.comboBox_FacModeCfgFile, comboBox_FacModeCfgFile.Text);//设置故障内容显示
  9646. }
  9647. /// <summary>
  9648. /// 显示完整配置文件
  9649. /// </summary>
  9650. /// <param name="sender"></param>
  9651. /// <param name="e"></param>
  9652. private void comboBox_CheckModeCfgFile_MouseHover_1(object sender, EventArgs e)
  9653. {
  9654. // 创建the ToolTip
  9655. ToolTip toolTip1 = new ToolTip();
  9656. // 设置显示样式
  9657. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  9658. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  9659. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  9660. toolTip1.ShowAlways = true;//是否显示提示框
  9661. // 设置伴随的对象.
  9662. toolTip1.SetToolTip(this.comboBox_CheckModeCfgFile, comboBox_CheckModeCfgFile.Text);//设置故障内容显示
  9663. }
  9664. /// <summary>
  9665. /// 手动发送指令
  9666. /// </summary>
  9667. /// <param name="sender"></param>
  9668. /// <param name="e"></param>
  9669. private void 发送指令ToolStripMenuItem_Click(object sender, EventArgs e)
  9670. {
  9671. //提示
  9672. Scan scan_form = new Scan();
  9673. scan_form.label1.Text = "按照16进制填写,相邻字节用空格隔开,依次填写ID、Mode、Cmd、Data\r\n例如:07 31 16 22 05 01 02 03 04 05";
  9674. scan_form.ShowDialog();
  9675. //发送写入的指令,填写ID、类型、命令字、数据
  9676. do
  9677. {
  9678. if (scan_form.textBox_Scan.Text == string.Empty)
  9679. {
  9680. timer_500ms.Enabled = false;
  9681. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9682. timer_500ms.Enabled = true;
  9683. break;
  9684. }
  9685. //输入文本转换为字节流
  9686. var InputData = new byte[256];
  9687. InputData = mySerialProcess.HexStringToBytes(scan_form.textBox_Scan.Text, true);
  9688. //ID
  9689. ushort ID;
  9690. ID = (ushort)((InputData[0] << 8) + InputData[1]);
  9691. //Mode
  9692. byte Mode;
  9693. Mode = InputData[2];
  9694. //Cmd
  9695. ushort Cmd;
  9696. Cmd = (ushort)((InputData[3] << 8) + InputData[4]);
  9697. //Data
  9698. var Data = new byte[Cmd & 0x00FF];
  9699. for (int i = 0; i < (Cmd & 0x00FF); i++)
  9700. Data[i] = InputData[5 + i];
  9701. //发送数据
  9702. mySerialProcess.SendCmdWithoutNotice(ID, Mode, Cmd, Data);
  9703. } while (false);
  9704. }
  9705. /// <summary>
  9706. /// 启动位置传感器校准
  9707. /// </summary>
  9708. /// <param name="sender"></param>
  9709. /// <param name="e"></param>
  9710. private void button_AngleCalStart_Click(object sender, EventArgs e)
  9711. {
  9712. for (int i = 0; i < 7; i++)
  9713. for (int j = 0; j < 6; j++)
  9714. {
  9715. dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = "";
  9716. }
  9717. foreach (Control cr in tabPage_AngleCal.Controls)
  9718. {
  9719. if (cr is TextBox)
  9720. {
  9721. if ((cr != textBox_AngleDiffTh) && (cr != textBox_AngleZeroTh))
  9722. cr.Text = "";
  9723. }
  9724. }
  9725. var Data = new byte[2];
  9726. mySerialProcess.SendCmd((ushort)0x751, (byte)0x0C, (ushort)0x5002, Data);
  9727. }
  9728. /// <summary>
  9729. /// 导出位置传感器校准数据
  9730. /// </summary>
  9731. /// <param name="sender"></param>
  9732. /// <param name="e"></param>
  9733. private void button_AngleExportData_Click(object sender, EventArgs e)
  9734. {
  9735. //读出产品信息
  9736. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  9737. Delay_ms(200);
  9738. SaveFileDialog sfd = new SaveFileDialog
  9739. {
  9740. FileName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + "位置传感器角度数据_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt",
  9741. Filter = "文本文档(*.txt)|*.txt",
  9742. Title = "Save"
  9743. };
  9744. if (sfd.ShowDialog() != DialogResult.OK)
  9745. {
  9746. return;
  9747. }
  9748. string filepath = sfd.FileName;
  9749. FileStream fs = new FileStream(filepath, FileMode.OpenOrCreate);
  9750. using (StreamWriter sw = new StreamWriter(fs))
  9751. {
  9752. sw.Write("标准值 ");
  9753. sw.Write("60.00 ");
  9754. sw.Write("120.00 ");
  9755. sw.Write("180.00 ");
  9756. sw.Write("240.00 ");
  9757. sw.Write("300.00 ");
  9758. sw.Write("360.00 ");
  9759. for (int i = 0; i < 42; i++)
  9760. {
  9761. if ((i % 6 == 0))
  9762. {
  9763. sw.Write("\r\n" + "采集值" + (i / 6 + 1).ToString() + " ");
  9764. }
  9765. sw.Write(AngledataRecord[i] + " ");
  9766. }
  9767. sw.Write("\r\n" + "历史零点位置 " + textBox_AngleZeroInit.Text);
  9768. sw.Write("\r\n" + "当前零点位置 " + textBox_AngleZeroCur.Text);
  9769. sw.Write("\r\n" + "零点误差 " + textBox_AngleZeroDiff.Text);
  9770. sw.Write("\r\n" + "最小偏差值 " + textBox_AngleDiffMin.Text);
  9771. sw.Write("\r\n" + "最大偏差值 " + textBox_AngleDiffMax.Text);
  9772. sw.Write("\r\n" + "平均偏差值 " + textBox_AngleDiffAvg.Text);
  9773. sw.Flush();
  9774. }
  9775. fs.Close();
  9776. }
  9777. /// <summary>
  9778. /// 写入校准数据
  9779. /// </summary>
  9780. /// <param name="sender"></param>
  9781. /// <param name="e"></param>
  9782. private void button_AngleWrite_Click(object sender, EventArgs e)
  9783. {
  9784. if ((textBox_AngleDiffAvg.Text == "") || (textBox_AngleZeroInit.Text == ""))
  9785. {
  9786. timer_500ms.Enabled = false;
  9787. MessageBox.Show("请先启动校准,以确认校准数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9788. timer_500ms.Enabled = true;
  9789. return;
  9790. }
  9791. timer_500ms.Enabled = false;
  9792. string str1 = "确认校准数据,历史零点: " + textBox_AngleZeroInit.Text + ", 偏差平均值: " + textBox_AngleDiffAvg.Text;
  9793. if (MessageBox.Show(str1, "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9794. {
  9795. var SaveFlag = new byte[4];
  9796. for (int i = 0; i < 4; i++)
  9797. SaveFlag[i] = 0;
  9798. SaveFlag[0] = (byte)(1);
  9799. double data1 = Convert.ToDouble(textBox_AngleZeroInit.Text) - Convert.ToDouble(textBox_AngleDiffAvg.Text);
  9800. if (data1 > 360)
  9801. {
  9802. data1 -= 360;
  9803. }
  9804. else if (data1 < -360)
  9805. {
  9806. data1 += 360;
  9807. }
  9808. Int16 data2 = (Int16)(data1 * 32768 / 360);
  9809. SaveFlag[2] = (byte)(data2);
  9810. SaveFlag[3] = (byte)(data2 >> 8);
  9811. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, SaveFlag);
  9812. }
  9813. else
  9814. MessageBoxTimeOut.Show("写入取消", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9815. timer_500ms.Enabled = true;
  9816. }
  9817. /// <summary>
  9818. /// 存储允许偏差
  9819. /// </summary>
  9820. /// <param name="sender"></param>
  9821. /// <param name="e"></param>
  9822. private void textBox_AngleDiffTh_KeyDown(object sender, KeyEventArgs e)
  9823. {
  9824. if (e.KeyCode == Keys.Enter)
  9825. {
  9826. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9827. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  9828. }
  9829. }
  9830. /// <summary>
  9831. /// 存储零点允许偏差
  9832. /// </summary>
  9833. /// <param name="sender"></param>
  9834. /// <param name="e"></param>
  9835. private void textBox_AngleZeroTh_KeyDown(object sender, KeyEventArgs e)
  9836. {
  9837. if (e.KeyCode == Keys.Enter)
  9838. {
  9839. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9840. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  9841. }
  9842. }
  9843. /// <summary>
  9844. /// 删除服务器配置文件
  9845. /// </summary>
  9846. /// <param name="sender"></param>
  9847. /// <param name="e"></param>
  9848. private void 重置ToolStripMenuItem_Click(object sender, EventArgs e)
  9849. {
  9850. if (MessageBox.Show("重置后软件自动关闭,确认重置?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9851. {
  9852. if(File.Exists(localInfo.LocalPath + localInfo.ServerCfgFileName))
  9853. File.Delete(localInfo.LocalPath + localInfo.ServerCfgFileName);
  9854. if(File.Exists(localInfo.LocalPath + localInfo.ConfigFileName))
  9855. File.Delete(localInfo.LocalPath + localInfo.ConfigFileName);
  9856. System.Environment.Exit(0);
  9857. }
  9858. }
  9859. /// <summary>
  9860. /// 按下Enter保存数据
  9861. /// </summary>
  9862. /// <param name="sender"></param>
  9863. /// <param name="e"></param>
  9864. private void toolStripTextBox_AngleAvgMax_KeyDown(object sender, KeyEventArgs e)
  9865. {
  9866. textBox_AngleDiffTh.Text = toolStripTextBox_AngleAvgMax.Text;
  9867. if (e.KeyCode == Keys.Enter)
  9868. {
  9869. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9870. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  9871. }
  9872. }
  9873. /// <summary>
  9874. /// 按下Enter保存数据
  9875. /// </summary>
  9876. /// <param name="sender"></param>
  9877. /// <param name="e"></param>
  9878. private void toolStripTextBox_AngleZeroMax_KeyDown(object sender, KeyEventArgs e)
  9879. {
  9880. textBox_AngleZeroTh.Text = toolStripTextBox_AngleZeroMax.Text;
  9881. if (e.KeyCode == Keys.Enter)
  9882. {
  9883. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9884. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  9885. }
  9886. }
  9887. private void 帮助ToolStripMenuItem_Click(object sender, EventArgs e)
  9888. {
  9889. //检查本地文件
  9890. if (!File.Exists(localInfo.LocalPath + localInfo.HelpFilename))
  9891. {
  9892. if (!OfflineFlag)
  9893. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/help/" + localInfo.HelpFilename, localInfo.LocalPath);
  9894. else
  9895. {
  9896. MessageBoxTimeOut.Show("未找到帮助文件!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9897. return;
  9898. }
  9899. }
  9900. //调用本地浏览器打开帮助文件
  9901. System.Diagnostics.Process.Start("explorer", localInfo.LocalPath + localInfo.HelpFilename);
  9902. }
  9903. /// <summary>
  9904. /// 打开或关闭指令窗口
  9905. /// </summary>
  9906. /// <param name="sender"></param>
  9907. /// <param name="e"></param>
  9908. private void 指令调试ToolStripMenuItem_Click(object sender, EventArgs e)
  9909. {
  9910. if (指令调试ToolStripMenuItem.Checked == false)
  9911. {
  9912. if (DebugForm.debug1 == null || DebugForm.debug1.IsDisposed)
  9913. {
  9914. DebugForm.debug1 = new DebugForm();
  9915. DebugForm.debug1.Show();
  9916. this.DebugWindowIsOpen = true;
  9917. }
  9918. else
  9919. {
  9920. DebugForm.debug1.Activate();
  9921. this.DebugWindowIsOpen = true;
  9922. }
  9923. 指令调试ToolStripMenuItem.Checked = true;
  9924. }
  9925. else
  9926. {
  9927. if (this.DebugWindowIsOpen == true)
  9928. {
  9929. DebugForm.debug1.Close();
  9930. this.DebugWindowIsOpen = false;
  9931. this.DebugDataDisplayEnable = false;
  9932. }
  9933. 指令调试ToolStripMenuItem.Checked = false;
  9934. }
  9935. }
  9936. }
  9937. }