mainForm.cs 338 KB

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