mainForm.cs 358 KB

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