mainForm.cs 605 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645
  1. using NPOI.POIFS.Crypt.Dsig;
  2. using NPOI.SS.Formula.Functions;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.Diagnostics;
  7. using System.Diagnostics.Eventing.Reader;
  8. using System.Drawing;
  9. using System.Globalization;
  10. using System.IO;
  11. using System.IO.Ports;
  12. using System.Linq;
  13. using System.Reflection;
  14. using System.Runtime.InteropServices;
  15. using System.Runtime.InteropServices.ComTypes;
  16. using System.Text;
  17. using System.Text.RegularExpressions;
  18. using System.Threading;
  19. using System.Web;
  20. using System.Windows.Forms;
  21. using System.Xml.Linq;
  22. using static NPOI.POIFS.Crypt.CryptoFunctions;
  23. namespace Welling_Motor_Debug_Tool
  24. {
  25. public partial class mainForm : Form
  26. {
  27. #region 变量定义
  28. //版本号
  29. public static string Version = "2.5.5";
  30. //串口实例
  31. Serial_Process mySerialProcess = new Serial_Process();
  32. string PortNumSave = "";
  33. string PortBaudrateSave = "";
  34. //本地信息定义
  35. LocalInfo localInfo = new LocalInfo();
  36. //FTP实例
  37. ftp myFtp = new ftp();
  38. public string ServerIP = "";
  39. public string ServerPort = "";
  40. public string ServerUser = "";
  41. public string ServerPassWd = "";
  42. public bool OfflineFlag = false;
  43. //MC运行信息超时计数
  44. bool MC_RunInfo_Refresh = false;
  45. ushort MC_RunInfo_Refresh_Cnt = 0;
  46. //MC调试信息超时计数
  47. bool MC_DebugInfo_Refresh = false;
  48. ushort MC_DebugInfo_Refresh_Cnt = 0;
  49. //MC故障码超时计数
  50. bool MC_ErrorCode_Refresh = false;
  51. ushort MC_ErrorCode_Refresh_Cnt = 0;
  52. //配置参数实例
  53. Params myParams = new Params();
  54. //记录文件名称
  55. string RunInfoSaveFilename = "";
  56. //BMS运行信息超时计数
  57. bool BMS_RunInfo_Refresh = false;
  58. ushort BMS_RunInfo_Refresh_Cnt = 0;
  59. //生产模式关机指令反馈状态
  60. bool PowerOffAckStatus = false;
  61. //登录窗口
  62. public static Login EnterForm1 = new Login();
  63. //生产配置文件信息
  64. ArrayList array_CfgInfo = new ArrayList();
  65. //写入参数返回标志和计数
  66. public bool WriteACK = false;
  67. public ushort ACK_WaitCnt = 0;
  68. //写入参数返回提示标志
  69. public bool ACK_DisFlag = true;
  70. //Boot版本信息
  71. public string BootInfo = "";
  72. //接收指令临时缓存,转string
  73. public string CmdRevStrTemp = "";
  74. //计时器,用于统计运行时间
  75. public Stopwatch stopwatch = new Stopwatch();
  76. //力矩传感器检验参数窗口
  77. public static TorqueParams TorqueParamsForm = new TorqueParams();
  78. //参数生成窗口
  79. public static GenerateParams GenerateParamsForm = new GenerateParams();
  80. //版本信息窗口
  81. public static Version VersionForm = new Version();
  82. //本机硬件信息
  83. public string Local_HdInformation = "";
  84. //指令窗口显示
  85. public bool DebugWindowIsOpen = false, DebugDataDisplayEnable = false;
  86. //位置传感器数据记录
  87. string[] AngledataRecord = new string[42];
  88. //服务器设置窗口
  89. public static ServerSelect ServerCfgForm1 = new ServerSelect();
  90. #endregion
  91. #region 故障日志结构体定义
  92. //故障日志记录信息 60 bytes,1K空间可以保存最近16条故障记录
  93. [StructLayout(LayoutKind.Sequential)]
  94. public struct MC_ErrorLogSaveInfo_Struct_t
  95. {
  96. public UInt16 Error_Index; //故障列表索引 2 bytes, 地址偏移 0
  97. public UInt16 NotesInfo1; //备注信息1,地址偏移 2
  98. public UInt16 NotesInfo2; //备注信息2,地址偏移 4
  99. public UInt16 NotesInfo3; //备注信息3,地址偏移 6
  100. public UInt32 ErrorCode; //故障码 4 bytes, 地址偏移 8
  101. public UInt32 RunTime; //运行时间 4bytes, 地址偏移 12
  102. //电机运行信息,占用空间32bytes
  103. [StructLayout(LayoutKind.Sequential)]
  104. public struct MC_RunInfo_Struct_t
  105. {
  106. public ushort BikeSpeed; //车速 0.1km/h,地址偏移0
  107. public ushort MotorSpeed; //输出转速 1rpm,地址偏移2
  108. public ushort Power; //电功率 1W,地址偏移4
  109. public ushort BusVoltage; //母线电压 1mV,地址偏移6
  110. public ushort BusCurrent; //母线电流 1mA,地址偏移8
  111. public byte Cadence; //踏频 1rpm,地址偏移10
  112. public byte Torque; //踩踏力矩 1Nm,地址偏移11
  113. public byte CadenceDir; //踩踏方向 0-正,1-反,2-停止,地址偏移12
  114. public byte GearSt; //助力档位,地址偏移13
  115. public byte LightSwitch; //灯开关 0xF0-关,0xF1-开,地址偏移14
  116. public byte SOC; //剩余电量 1%,地址偏移15
  117. public ushort RemainDistance; //续航里程 1km,地址偏移16
  118. public ushort Torque_AD; //力矩寄存器,地址偏移18
  119. public byte PowerPerKm; //平均功耗 0.01Ah/km ,地址偏移20
  120. public byte T_PCB; //PCB温度 +40℃,地址偏移21
  121. public byte T_Coil; //绕组温度 +40℃,地址偏移22
  122. public byte T_MCU; //MCU温度 +40℃,地址偏移23
  123. public ushort Ride_Km; //开机后骑行里程 0.1km, 地址偏移24
  124. public ushort Ride_Time; //开机后骑行时间 1s,地址偏移26
  125. public UInt32 RS; //预留 4bytes
  126. };
  127. [MarshalAs(UnmanagedType.Struct)]
  128. public MC_RunInfo_Struct_t RunInfo; //运行信息 32bytes, 地址偏移 16
  129. //控制变量
  130. public Int16 IqCurrent; //Pu, 地址偏移 48
  131. public Int16 IqVoltage; //Pu, 地址偏移 50
  132. public Int16 IdCurrent; //Pu, 地址偏移 52
  133. public Int16 IdVoltage; //Pu, 地址偏移 54
  134. //状态机
  135. public UInt16 FSM; //高到低依次表示系统状态机、二层状态机、电机状态机、助力状态机, 地址偏移 56
  136. //预留
  137. public UInt16 RS1;
  138. public UInt16 RS2;
  139. public UInt16 RS3;
  140. };
  141. #endregion
  142. #region 屏幕缩放比例获取
  143. public class PrimaryScreen
  144. {
  145. #region Win32 API
  146. [DllImport("user32.dll")]
  147. static extern IntPtr GetDC(IntPtr ptr);
  148. [DllImport("gdi32.dll")]
  149. static extern int GetDeviceCaps(
  150. IntPtr hdc, // handle to DC
  151. int nIndex // index of capability
  152. );
  153. [DllImport("user32.dll", EntryPoint = "ReleaseDC")]
  154. static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDc);
  155. #endregion
  156. #region DeviceCaps常量
  157. const int HORZRES = 8;
  158. const int VERTRES = 10;
  159. const int LOGPIXELSX = 88;
  160. const int LOGPIXELSY = 90;
  161. const int DESKTOPVERTRES = 117;
  162. const int DESKTOPHORZRES = 118;
  163. #endregion
  164. #region 属性
  165. /// <summary>
  166. /// 获取屏幕分辨率当前物理大小
  167. /// </summary>
  168. public static Size WorkingArea
  169. {
  170. get
  171. {
  172. IntPtr hdc = GetDC(IntPtr.Zero);
  173. Size size = new Size();
  174. size.Width = GetDeviceCaps(hdc, HORZRES);
  175. size.Height = GetDeviceCaps(hdc, VERTRES);
  176. ReleaseDC(IntPtr.Zero, hdc);
  177. return size;
  178. }
  179. }
  180. /// <summary>
  181. /// 当前系统DPI_X 大小 一般为96
  182. /// </summary>
  183. public static int DpiX
  184. {
  185. get
  186. {
  187. IntPtr hdc = GetDC(IntPtr.Zero);
  188. int DpiX = GetDeviceCaps(hdc, LOGPIXELSX);
  189. ReleaseDC(IntPtr.Zero, hdc);
  190. return DpiX;
  191. }
  192. }
  193. /// <summary>
  194. /// 当前系统DPI_Y 大小 一般为96
  195. /// </summary>
  196. public static int DpiY
  197. {
  198. get
  199. {
  200. IntPtr hdc = GetDC(IntPtr.Zero);
  201. int DpiX = GetDeviceCaps(hdc, LOGPIXELSY);
  202. ReleaseDC(IntPtr.Zero, hdc);
  203. return DpiX;
  204. }
  205. }
  206. /// <summary>
  207. /// 获取真实设置的桌面分辨率大小
  208. /// </summary>
  209. public static Size DESKTOP
  210. {
  211. get
  212. {
  213. IntPtr hdc = GetDC(IntPtr.Zero);
  214. Size size = new Size();
  215. size.Width = GetDeviceCaps(hdc, DESKTOPHORZRES);
  216. size.Height = GetDeviceCaps(hdc, DESKTOPVERTRES);
  217. ReleaseDC(IntPtr.Zero, hdc);
  218. return size;
  219. }
  220. }
  221. /// <summary>
  222. /// 获取宽度缩放百分比
  223. /// </summary>
  224. public static float ScaleX
  225. {
  226. get
  227. {
  228. IntPtr hdc = GetDC(IntPtr.Zero);
  229. int t = GetDeviceCaps(hdc, DESKTOPHORZRES);
  230. int d = GetDeviceCaps(hdc, HORZRES);
  231. float ScaleX = (float)GetDeviceCaps(hdc, DESKTOPHORZRES) / (float)GetDeviceCaps(hdc, HORZRES);
  232. ReleaseDC(IntPtr.Zero, hdc);
  233. return ScaleX;
  234. }
  235. }
  236. /// <summary>
  237. /// 获取高度缩放百分比
  238. /// </summary>
  239. public static float ScaleY
  240. {
  241. get
  242. {
  243. IntPtr hdc = GetDC(IntPtr.Zero);
  244. float ScaleY = (float)(float)GetDeviceCaps(hdc, DESKTOPVERTRES) / (float)GetDeviceCaps(hdc, VERTRES);
  245. ReleaseDC(IntPtr.Zero, hdc);
  246. return ScaleY;
  247. }
  248. }
  249. #endregion
  250. }
  251. #endregion
  252. public static mainForm mainform1 = null;
  253. public mainForm()
  254. {
  255. InitializeComponent();
  256. mainform1 = this;
  257. System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
  258. stopwatch.Start();
  259. //端口初始化
  260. mySerialProcess.Init();
  261. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  262. //检查文件夹
  263. if (!Directory.Exists(localInfo.LocalPath))
  264. {
  265. Directory.CreateDirectory(localInfo.LocalPath);
  266. }
  267. if (!Directory.Exists(localInfo.LocalDataPath))
  268. {
  269. Directory.CreateDirectory(localInfo.LocalDataPath);
  270. }
  271. if (!Directory.Exists(localInfo.ToolsPath))
  272. {
  273. Directory.CreateDirectory(localInfo.ToolsPath);
  274. }
  275. if (!Directory.Exists(localInfo.LocalPath + localInfo.CfgPathName))
  276. {
  277. Directory.CreateDirectory(localInfo.LocalPath + localInfo.CfgPathName);
  278. }
  279. //检查备忘录文件
  280. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.NoteFileName))
  281. {
  282. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.NoteFileName, "");
  283. }
  284. //检验流水号记录文件
  285. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.SerialNumFileName1))
  286. {
  287. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, "0");
  288. }
  289. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.SerialNumFileName2))
  290. {
  291. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, "0");
  292. }
  293. //检查软件打开记录并累加
  294. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.PowerTimesFilename))
  295. {
  296. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.PowerTimesFilename, "0");
  297. }
  298. int UserTime = Convert.ToInt32(File.ReadAllText(localInfo.LocalPath + localInfo.PowerTimesFilename));
  299. UserTime += 1;
  300. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.PowerTimesFilename, UserTime.ToString());
  301. //服务器初始化
  302. do
  303. {
  304. //检查是否存在配置文件
  305. if (File.Exists(localInfo.LocalPath + localInfo.ServerCfgFileName)) //存在配置文件从文件选择
  306. {
  307. //解密
  308. string sLine = aes.DecryptFromFile(localInfo.LocalPath + localInfo.ServerCfgFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  309. string[] array_CfgInfo = sLine.Split(',');
  310. //解析配置文件
  311. ServerIP = array_CfgInfo[0].ToString();
  312. ServerPort = array_CfgInfo[1].ToString();
  313. ServerUser = array_CfgInfo[2].ToString();
  314. ServerPassWd = array_CfgInfo[3].ToString();
  315. if (array_CfgInfo[4].ToString() == "True")
  316. {
  317. OfflineFlag = true;
  318. checkBox_OffLineFacMode.Checked = true;
  319. checkBox_OffLineCheckMode.Checked = true;
  320. }
  321. }
  322. else //不存在配置文件由用户选择
  323. {
  324. ServerCfgForm1.ShowDialog();
  325. switch (ServerCfgForm1.comboBox_Server.SelectedIndex)
  326. {
  327. case 0: //武汉园区
  328. case 1: //顺德工厂
  329. {
  330. ServerIP = "10.177.130.30";
  331. ServerPort = "15021";
  332. ServerUser = "factory_test";
  333. ServerPassWd = "ttium";
  334. OfflineFlag = false;
  335. checkBox_OffLineFacMode.Checked = false;
  336. checkBox_OffLineCheckMode.Checked = false;
  337. break;
  338. }
  339. case 2: //威灵园区
  340. case 3: //越南工厂
  341. case 4: //公司外部
  342. {
  343. ServerIP = "8.134.109.44";
  344. ServerPort = "21";
  345. ServerUser = "ttium";
  346. ServerPassWd = "ttium123";
  347. OfflineFlag = false;
  348. checkBox_OffLineFacMode.Checked = false;
  349. checkBox_OffLineCheckMode.Checked = false;
  350. break;
  351. }
  352. case 5: //离线使用
  353. {
  354. //输入管理员密码
  355. Scan scan_form = new Scan();
  356. scan_form.label1.Text = "请输入管理员密码";
  357. scan_form.textBox_Scan.UseSystemPasswordChar = true;
  358. scan_form.ShowDialog();
  359. if (scan_form.textBox_Scan.Text == "ttium.123")
  360. {
  361. //检查许可
  362. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.OffLineUseKeyFileName)) //未许可
  363. {
  364. if (MessageBox.Show("无离线授权,请导入许可文件!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
  365. {
  366. Licences myLicences = new Licences();
  367. myLicences.ShowDialog();
  368. //从许可文件读取内容
  369. string str_lic = aes.DecryptFromFile(myLicences.textBox_LicencePath.Text, "2D820F88F60A39D5", "3687C5216B19D16B");
  370. string PC_Code = PC_Information.GetCPUSerialNumber();
  371. if (PC_Code == str_lic) //授权码正确
  372. {
  373. aes.EncryptToFile(PC_Code, localInfo.LocalPath + localInfo.OffLineUseKeyFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  374. string strInfo = "";
  375. strInfo = "0;" + DateTime.Now.ToString("yyyyMMdd");
  376. aes.EncryptToFile(strInfo, localInfo.LocalPath + localInfo.OfflineUseLogFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  377. }
  378. else //授权码错误
  379. {
  380. MessageBox.Show("许可文件无效,请联系管理员!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  381. System.Environment.Exit(0);
  382. }
  383. }
  384. else
  385. {
  386. System.Environment.Exit(0);
  387. }
  388. }
  389. else //已授权
  390. {
  391. string str_Key = aes.DecryptFromFile(localInfo.LocalPath + localInfo.OffLineUseKeyFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  392. //判断授权是否正确
  393. if (PC_Information.GetCPUSerialNumber() == str_Key) //授权正确
  394. {
  395. //检查离线使用记录文件
  396. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.OfflineUseLogFileName))
  397. {
  398. MessageBox.Show("许可文件内容缺失,请联系管理员!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  399. File.Delete(localInfo.LocalPath + localInfo.OffLineUseKeyFileName);//缺少离线使用记录文件时,自动删除许可文件,下次打开重新导入许可
  400. System.Environment.Exit(0);
  401. }
  402. //获取离线使用记录并更新
  403. string UseLog = aes.DecryptFromFile(localInfo.LocalPath + localInfo.OfflineUseLogFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  404. UInt32 UseTimes = Convert.ToUInt32(UseLog.Split(';')[0]);
  405. UseTimes++;
  406. string str = UseTimes.ToString() + ";" + UseLog.Split(';')[1];
  407. aes.EncryptToFile(str, localInfo.LocalPath + localInfo.OfflineUseLogFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  408. //判断授权期限
  409. DateTime DataOrigin = new DateTime();
  410. DateTime.TryParseExact(UseLog.Split(';')[1], "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None, out DataOrigin);
  411. DateTime DataEnd = DataOrigin.AddDays(90);
  412. DateTime NowDate = DateTime.Now.Date;
  413. if ((NowDate > DataEnd) || (UseTimes > 1000)) //第一次打开软件90天内,或1000次内
  414. {
  415. MessageBox.Show("离线授权过期,请联系管理员!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  416. File.Delete(localInfo.LocalPath + localInfo.OffLineUseKeyFileName);//许可过期或超出使用次数,自动删除许可文件和使用记录,下次打开重新导入许可
  417. File.Delete(localInfo.LocalPath + localInfo.OfflineUseLogFileName);//许可过期或超出使用次数,自动删除许可文件和使用记录,下次打开重新导入许可
  418. System.Environment.Exit(0);
  419. }
  420. }
  421. else
  422. {
  423. MessageBox.Show("离线授权错误,请联系管理员!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  424. File.Delete(localInfo.LocalPath + localInfo.OffLineUseKeyFileName);//许可文件不匹配,自动删除许可文件和使用记录,下次打开重新导入许可
  425. File.Delete(localInfo.LocalPath + localInfo.OfflineUseLogFileName);//许可文件不匹配,自动删除许可文件和使用记录,下次打开重新导入许可
  426. System.Environment.Exit(0);
  427. }
  428. }
  429. OfflineFlag = true;
  430. checkBox_OffLineFacMode.Checked = true;
  431. checkBox_OffLineCheckMode.Checked = true;
  432. }
  433. else
  434. {
  435. MessageBox.Show("密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  436. System.Environment.Exit(0);
  437. }
  438. break;
  439. }
  440. default: //无效
  441. {
  442. System.Environment.Exit(0);
  443. break;
  444. }
  445. }
  446. //保存网络配置文件
  447. if (ServerCfgForm1.checkBox_NoticeSw.Checked)
  448. {
  449. string str = ServerIP + "," + ServerPort + "," + ServerUser + "," + ServerPassWd + "," + (OfflineFlag == true).ToString();
  450. //加密保存
  451. aes.EncryptToFile(str, localInfo.LocalPath + localInfo.ServerCfgFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  452. }
  453. }
  454. } while (false);
  455. //检查配置文件
  456. if (File.Exists(localInfo.LocalPath + localInfo.ConfigFileName)) //存在配置文件,导入配置信息
  457. {
  458. //打开文件
  459. StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.ConfigFileName);
  460. string sLine = "";
  461. ArrayList array_CfgInfo = new ArrayList();
  462. array_CfgInfo.Clear();
  463. while (sLine != null)
  464. {
  465. sLine = objReader.ReadLine();
  466. array_CfgInfo.Add(sLine);
  467. }
  468. objReader.Close();
  469. //解析配置文件
  470. try
  471. {
  472. int index = -1;
  473. //Port Set
  474. index = Array.IndexOf(array_CfgInfo.ToArray(), "[PortSet]");
  475. PortNumSave = array_CfgInfo[index + 1].ToString().Split(':')[1];
  476. PortBaudrateSave = array_CfgInfo[index + 2].ToString().Split(':')[1];
  477. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.IndexOf(PortNumSave);
  478. toolStripComboBox_Baudrate.SelectedIndex = toolStripComboBox_Baudrate.Items.IndexOf(PortBaudrateSave);
  479. 连接开机ToolStripMenuItem.Checked = (array_CfgInfo[index + 3].ToString().Split(':')[1] == "True");
  480. 断开关机ToolStripMenuItem.Checked = (array_CfgInfo[index + 4].ToString().Split(':')[1] == "True");
  481. 识别通讯盒ToolStripMenuItem.Checked = (array_CfgInfo[index + 5].ToString().Split(':')[1] == "True");
  482. //Option
  483. index = Array.IndexOf(array_CfgInfo.ToArray(), "[Option]");
  484. 写入存储ToolStripMenuItem.Checked = (array_CfgInfo[index + 1].ToString().Split(':')[1] == "True");
  485. //Server Set
  486. index = Array.IndexOf(array_CfgInfo.ToArray(), "[ServerSet]");
  487. toolStripTextBox_ServerPath.Text = array_CfgInfo[index + 1].ToString().Split(':')[1];
  488. //MacInfo
  489. index = Array.IndexOf(array_CfgInfo.ToArray(), "[MacInfo]");
  490. toolStripTextBox_MAC.Text = array_CfgInfo[index + 1].ToString().Split(':')[1];
  491. toolStripTextBoxMACAddr.Text = array_CfgInfo[index + 2].ToString().Split(':')[1];
  492. toolStripTextBox_MACDate.Text = DateTime.Now.ToString("yyyyMMdd");
  493. toolStripTextBox_MACPD.Text = array_CfgInfo[index + 4].ToString().Split(':')[1];
  494. //Log Address
  495. index = Array.IndexOf(array_CfgInfo.ToArray(), "[LogAddress]");
  496. textBox_LogAddrBegin.Text = array_CfgInfo[index + 1].ToString().Split(':')[1];
  497. textBox_LogAddrEnd.Text = array_CfgInfo[index + 2].ToString().Split(':')[1];
  498. //电机类型
  499. index = Array.IndexOf(array_CfgInfo.ToArray(), "[MotorType]");
  500. 中置电机MIGIC_ToolStripMenuItem.Checked = (array_CfgInfo[index + 1].ToString().Split(':')[1] == "True");
  501. 中置电机VP_ToolStripMenuItem.Checked = (array_CfgInfo[index + 2].ToString().Split(':')[1] == "True");
  502. 轮毂电机ToolStripMenuItem.Checked = (array_CfgInfo[index + 3].ToString().Split(':')[1] == "True");
  503. //检测阈值
  504. index = Array.IndexOf(array_CfgInfo.ToArray(), "[CheckValue]");
  505. toolStripTextBox_ThVol.Text = array_CfgInfo[index + 1].ToString().Split(':')[1];
  506. toolStripTextBox_ThCur.Text = array_CfgInfo[index + 2].ToString().Split(':')[1];
  507. toolStripTextBox_ThSpeed.Text = array_CfgInfo[index + 3].ToString().Split(':')[1];
  508. toolStripTextBox_ThTor.Text = array_CfgInfo[index + 4].ToString().Split(':')[1];
  509. toolStripTextBox_ThCad.Text = array_CfgInfo[index + 5].ToString().Split(':')[1];
  510. toolStripTextBox_ThBikeSpeed.Text = array_CfgInfo[index + 6].ToString().Split(':')[1];
  511. toolStripTextBox_ThT_PCB.Text = array_CfgInfo[index + 7].ToString().Split(':')[1];
  512. toolStripTextBox_ThT_MCU.Text = array_CfgInfo[index + 8].ToString().Split(':')[1];
  513. toolStripTextBox_ThT_Motor.Text = array_CfgInfo[index + 9].ToString().Split(':')[1];
  514. //MOS内阻校准系数
  515. index = Array.IndexOf(array_CfgInfo.ToArray(), "[MosCalK]");
  516. toolStripTextBox_MosCalK.Text = array_CfgInfo[index + 1].ToString().Split(':')[1];
  517. toolStripTextBox_MOS1.Text= array_CfgInfo[index + 2].ToString().Split(':')[1];
  518. toolStripTextBox_MOS2.Text = array_CfgInfo[index + 3].ToString().Split(':')[1];
  519. toolStripTextBox_MOS3.Text = array_CfgInfo[index + 4].ToString().Split(':')[1];
  520. //通信协议类型
  521. index = Array.IndexOf(array_CfgInfo.ToArray(), "[ProtocolType]");
  522. cANToolStripMenuItem.Checked = (array_CfgInfo[index + 1].ToString().Split(':')[1] == "True");
  523. uARTToolStripMenuItem.Checked = (array_CfgInfo[index + 2].ToString().Split(':')[1] == "True");
  524. //自动更新开关
  525. index = Array.IndexOf(array_CfgInfo.ToArray(), "[AutoUpdate]");
  526. 打开ToolStripMenuItem.Checked = (array_CfgInfo[index + 1].ToString().Split(':')[1] == "True");
  527. 关闭ToolStripMenuItem.Checked = !打开ToolStripMenuItem.Checked;
  528. //位置校准偏差
  529. index = Array.IndexOf(array_CfgInfo.ToArray(), "[AngleCal]");
  530. textBox_AngleDiffTh.Text = array_CfgInfo[index + 1].ToString().Split(':')[1];
  531. toolStripTextBox_AngleAvgMax.Text = textBox_AngleDiffTh.Text;
  532. textBox_AngleZeroTh.Text = array_CfgInfo[index + 2].ToString().Split(':')[1];
  533. toolStripTextBox_AngleZeroMax.Text = textBox_AngleZeroTh.Text;
  534. }
  535. catch (System.Exception)
  536. {
  537. timer_500ms.Enabled = false;
  538. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  539. timer_500ms.Enabled = true;
  540. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  541. }
  542. }
  543. else //不存在配置文件,生成文件写入默认值
  544. {
  545. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  546. }
  547. //解析本地流水号记录
  548. do
  549. {
  550. //测试模式
  551. label_FacModeSerial.Text = File.ReadAllText(localInfo.LocalPath + localInfo.SerialNumFileName1);
  552. //检验模式
  553. label_CheckModeSerial.Text = File.ReadAllText(localInfo.LocalPath + localInfo.SerialNumFileName2);
  554. } while (false);
  555. //获取本机信息,读取时间较长,优先从本地文件获取
  556. do
  557. {
  558. try
  559. {
  560. //本地文件为空,读取信息保存
  561. if (!File.Exists(localInfo.LocalPath + localInfo.PC_InfoFileName))
  562. {
  563. Local_HdInformation = "";
  564. Local_HdInformation += "计算机名称: " + System.Environment.UserName + "\r\n";
  565. Local_HdInformation += "IP地址: " + PC_Information.GetIpAddress() + "\r\n";
  566. Local_HdInformation += "系统ID: " + PC_Information.GetSystemID() + "\r\n";
  567. Local_HdInformation += "操作系统类型: " + PC_Information.GetSystemType() + "\r\n";
  568. Local_HdInformation += "主板型号: " + PC_Information.GetBoardType() + "\r\n";
  569. Local_HdInformation += "主板厂商: " + PC_Information.GetBoardManufacturer() + "\r\n";
  570. Local_HdInformation += "主板ID: " + PC_Information.GetBIOSSerialNumber() + "\r\n";
  571. Local_HdInformation += "CPU型号: " + PC_Information.GetCpuName() + "\r\n";
  572. Local_HdInformation += "CPU厂商: " + PC_Information.GetCpuManufacturer() + "\r\n";
  573. Local_HdInformation += "CPU ID: " + PC_Information.GetCPUSerialNumber() + "\r\n";
  574. Local_HdInformation += "内存容量: " + PC_Information.GetPhysicalMemory() + " GB" + "\r\n";
  575. Local_HdInformation += "MAC ID: " + PC_Information.GetNetCardMACAddress().Replace(":", "-") + "\r\n";
  576. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.PC_InfoFileName, Local_HdInformation);
  577. }
  578. //从本地读取,计算机名和IP地址重新读
  579. else
  580. {
  581. Local_HdInformation = "";
  582. string[] fileInfo = File.ReadAllLines(localInfo.LocalPath + localInfo.PC_InfoFileName, Encoding.UTF8);
  583. fileInfo[0] = "计算机名称: " + System.Environment.UserName;
  584. fileInfo[1] = "IP地址: " + PC_Information.GetIpAddress();
  585. for (int i = 0; i < fileInfo.Length; i++)
  586. Local_HdInformation += fileInfo[i] + "\r\n";
  587. File.Delete(localInfo.LocalPath + localInfo.PC_InfoFileName);
  588. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.PC_InfoFileName, Local_HdInformation);
  589. }
  590. }
  591. catch(Exception)
  592. {
  593. }
  594. } while (false);
  595. //系统登录
  596. do
  597. {
  598. EnterForm1.ShowDialog();
  599. try
  600. {
  601. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  602. {
  603. if (EnterForm1.comboBox_User.Text.Contains("量产"))
  604. {
  605. //隐藏设置项
  606. 其它配置项ToolStripMenuItem.Visible = false;
  607. 写入存储ToolStripMenuItem.Visible = false;
  608. 服务器配置ToolStripMenuItem.Visible = false;
  609. 判断阈值ToolStripMenuItem.Visible = false;
  610. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  611. mOS内阻范围ToolStripMenuItem.Visible = false;
  612. 力矩传感器检验ToolStripMenuItem.Visible = false;
  613. 位置校准偏差范围ToolStripMenuItem.Visible = false;
  614. //显示生产信息
  615. 生产信息ToolStripMenuItem.Visible = true;
  616. //显示电机类型,但不可编辑
  617. 电机类型ToolStripMenuItem.Visible = true;
  618. 中置电机MIGIC_ToolStripMenuItem.Enabled = false;
  619. 中置电机VP_ToolStripMenuItem.Enabled = false;
  620. 轮毂电机ToolStripMenuItem.Enabled = false;
  621. if (uARTToolStripMenuItem.Checked)
  622. UART协议ToolStripMenuItem.Visible = true;
  623. //隐藏研发调试界面
  624. tabPage_MotorParam.Parent = null;
  625. tabPage_BikeParam.Parent = null;
  626. tabPage_BikeParam2.Parent = null;
  627. tabPage_ControlParam.Parent = null;
  628. tabPage_SensorParam.Parent = null;
  629. tabPage_AssistParam.Parent = null;
  630. tabPage_UsrRideParam.Parent = null;
  631. tabPage_DebugParam.Parent = null;
  632. tabPage_RecordInfo.Parent = null;
  633. tabPage_OtherInfo.Parent = null;
  634. tabPage_OBC.Parent = null;
  635. tabPage_RAMorFLASH.Parent = null;
  636. tabPage_FactoryMode.Parent = null;
  637. tabPage_DebugInfo.Parent = null;
  638. tabPage_AngleCal.Parent = null;
  639. tabPage_FuncSet.Parent = null;
  640. //显示运行信息
  641. tabPage_RunInfo.Parent = tabControl2;
  642. //根据电机类型修改生产信息和电机类型
  643. if (EnterForm1.comboBox_User.Text.Contains("中置MIGIC"))
  644. {
  645. 中置电机MIGIC_ToolStripMenuItem.Checked = true;
  646. 中置电机VP_ToolStripMenuItem.Checked = false;
  647. 轮毂电机ToolStripMenuItem.Checked = false;
  648. toolStripTextBox_MACPD.Text = "MM_MC1";
  649. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  650. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  651. }
  652. else if (EnterForm1.comboBox_User.Text.Contains("中置VP"))
  653. {
  654. 中置电机MIGIC_ToolStripMenuItem.Checked = false;
  655. 中置电机VP_ToolStripMenuItem.Checked = true;
  656. 轮毂电机ToolStripMenuItem.Checked = false;
  657. toolStripTextBox_MACPD.Text = "MM_MV1";
  658. toolStripTextBox_ServerPath.Text = "MC_VP_TEST";
  659. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  660. }
  661. else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
  662. {
  663. 中置电机MIGIC_ToolStripMenuItem.Checked = false;
  664. 中置电机VP_ToolStripMenuItem.Checked = false;
  665. 轮毂电机ToolStripMenuItem.Checked = true;
  666. toolStripTextBox_MACPD.Text = "GF_250_1";
  667. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  668. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  669. }
  670. //显示对应生产测试界面
  671. if (EnterForm1.comboBox_User.Text.Contains("写入"))
  672. {
  673. tabPage_ProductMode_Write.Parent = tabControl1;
  674. tabPage_ProductMode_Write.Select();
  675. tabPage_ProductMode_Read.Parent = null;
  676. }
  677. else if (EnterForm1.comboBox_User.Text.Contains("检验"))
  678. {
  679. tabPage_ProductMode_Read.Parent = tabControl1;
  680. tabPage_ProductMode_Read.Select();
  681. tabPage_ProductMode_Write.Parent = null;
  682. }
  683. //应答指令不提示
  684. ACK_DisFlag = false;
  685. //退出登录
  686. break;
  687. }
  688. else if (EnterForm1.comboBox_User.Text == "工程参数配置")
  689. {
  690. //隐藏工作台内容,新建窗口完成配置
  691. groupBox1.Visible = false;
  692. groupBox3.Visible = false;
  693. tabControl2.Visible = false;
  694. //隐藏提示信息
  695. label_StarInfo.Visible = false;
  696. //打开参数配置框
  697. GenerateParamsForm.ShowDialog();
  698. System.Environment.Exit(0);
  699. //退出登录
  700. break;
  701. }
  702. else if (EnterForm1.comboBox_User.Text.Contains("样机"))
  703. {
  704. //隐藏量产界面
  705. tabPage_ProductMode_Read.Parent = null;
  706. tabPage_ProductMode_Write.Parent = null;
  707. //隐藏配置项
  708. 其它配置项ToolStripMenuItem.Visible = false;
  709. 服务器配置ToolStripMenuItem.Visible = false;
  710. 判断阈值ToolStripMenuItem.Visible = false;
  711. 力矩传感器检验ToolStripMenuItem.Visible = false;
  712. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  713. mOS内阻范围ToolStripMenuItem.Visible = false;
  714. 位置校准偏差范围ToolStripMenuItem.Visible = false;
  715. 样机测试ToolStripMenuItem.Visible = false;
  716. //显示生产信息
  717. 生产信息ToolStripMenuItem.Visible = true;
  718. //显示电机类型
  719. 电机类型ToolStripMenuItem.Visible = true;
  720. 中置电机MIGIC_ToolStripMenuItem.Enabled = true;
  721. 中置电机VP_ToolStripMenuItem.Enabled=true;
  722. 轮毂电机ToolStripMenuItem.Enabled = true;
  723. if (uARTToolStripMenuItem.Checked)
  724. UART协议ToolStripMenuItem.Visible = true;
  725. if (EnterForm1.comboBox_User.Text.Contains("中置MIGIC"))
  726. {
  727. 中置电机MIGIC_ToolStripMenuItem.Checked = true;
  728. 中置电机VP_ToolStripMenuItem.Checked = false;
  729. 轮毂电机ToolStripMenuItem.Checked = false;
  730. toolStripTextBox_MACPD.Text = "MM_MC1";
  731. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  732. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  733. }
  734. else if (EnterForm1.comboBox_User.Text.Contains("中置VP"))
  735. {
  736. 中置电机MIGIC_ToolStripMenuItem.Checked = false;
  737. 中置电机VP_ToolStripMenuItem.Checked = true;
  738. 轮毂电机ToolStripMenuItem.Checked = false;
  739. toolStripTextBox_MACPD.Text = "MM_MV1";
  740. toolStripTextBox_ServerPath.Text = "MC_VP_TEST";
  741. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  742. }
  743. else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
  744. {
  745. 中置电机MIGIC_ToolStripMenuItem.Checked = false;
  746. 中置电机VP_ToolStripMenuItem.Checked = false;
  747. 轮毂电机ToolStripMenuItem.Checked = true;
  748. toolStripTextBox_MACPD.Text = "GF_250_1";
  749. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  750. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  751. }
  752. //退出登录
  753. break;
  754. }
  755. else if (EnterForm1.comboBox_User.Text == "FCT治具测试")
  756. {
  757. //隐藏设置项
  758. 其它配置项ToolStripMenuItem.Visible = false;
  759. 写入存储ToolStripMenuItem.Visible = false;
  760. 服务器配置ToolStripMenuItem.Visible = false;
  761. 判断阈值ToolStripMenuItem.Visible = false;
  762. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  763. mOS内阻范围ToolStripMenuItem.Visible = false;
  764. 力矩传感器检验ToolStripMenuItem.Visible = false;
  765. 位置校准偏差范围ToolStripMenuItem.Visible = false;
  766. //显示生产信息
  767. 生产信息ToolStripMenuItem.Visible = true;
  768. //显示电机类型,但不可编辑
  769. 电机类型ToolStripMenuItem.Visible = false;
  770. 中置电机MIGIC_ToolStripMenuItem.Enabled = false;
  771. 中置电机VP_ToolStripMenuItem.Enabled = false;
  772. 轮毂电机ToolStripMenuItem.Enabled = false;
  773. if (uARTToolStripMenuItem.Checked)
  774. UART协议ToolStripMenuItem.Visible = true;
  775. //隐藏研发调试界面
  776. tabPage_MotorParam.Parent = null;
  777. tabPage_BikeParam.Parent = null;
  778. tabPage_BikeParam2.Parent = null;
  779. tabPage_ControlParam.Parent = null;
  780. tabPage_SensorParam.Parent = null;
  781. tabPage_AssistParam.Parent = null;
  782. tabPage_UsrRideParam.Parent = null;
  783. tabPage_DebugParam.Parent = null;
  784. tabPage_RecordInfo.Parent = null;
  785. tabPage_OtherInfo.Parent = null;
  786. tabPage_OBC.Parent = null;
  787. tabPage_RAMorFLASH.Parent = null;
  788. tabPage_FactoryMode.Parent = null;
  789. tabPage_DebugInfo.Parent = null;
  790. tabPage_AngleCal.Parent = null;
  791. tabPage_FuncSet.Parent = null;
  792. //显示运行信息
  793. tabPage_RunInfo.Parent = tabControl2;
  794. //目前仅轮毂使用
  795. 中置电机MIGIC_ToolStripMenuItem.Checked = false;
  796. 中置电机VP_ToolStripMenuItem.Checked = false;
  797. 轮毂电机ToolStripMenuItem.Checked = true;
  798. toolStripTextBox_MACPD.Text = "GF_250_1";
  799. toolStripTextBox_ServerPath.Text = "HUB_Control_FCT";
  800. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  801. //显示量产测试界面
  802. tabPage_ProductMode_Write.Parent = tabControl1;
  803. tabPage_ProductMode_Write.Select();
  804. tabPage_ProductMode_Read.Parent = null;
  805. checkBox_OffLineFacMode.Checked = false;
  806. checkBox_OffLineFacMode.Enabled = true;
  807. checkBox_OffLineCheckMode.Checked = false;
  808. checkBox_OffLineCheckMode.Enabled = true;
  809. //应答指令不提示
  810. ACK_DisFlag = false;
  811. //退出登录
  812. break;
  813. }
  814. else if (EnterForm1.comboBox_User.Text == "研发调试")
  815. {
  816. //隐藏量产界面
  817. tabPage_ProductMode_Read.Parent = null;
  818. tabPage_ProductMode_Write.Parent = null;
  819. 服务器配置ToolStripMenuItem.Visible = false;
  820. 样机测试ToolStripMenuItem.Visible = false;
  821. if (uARTToolStripMenuItem.Checked)
  822. UART协议ToolStripMenuItem.Visible = true;
  823. //退出登录
  824. break;
  825. }
  826. else if (EnterForm1.comboBox_User.Text == "管理员")
  827. {
  828. //不隐藏任何界面
  829. //...
  830. //退出登录
  831. break;
  832. }
  833. else
  834. {
  835. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  836. //重新登录
  837. continue;
  838. }
  839. }
  840. else
  841. {
  842. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  843. //重新登录
  844. continue;
  845. }
  846. }
  847. catch (Exception)
  848. {
  849. System.Environment.Exit(0);
  850. }
  851. } while (true);
  852. //配置网络FTP服务器
  853. myFtp.FtpOption(ServerIP, ServerPort, ServerUser, ServerPassWd, "admin", "ttium_admin");
  854. //创建线程,定时检测网络连接状态
  855. Thread th = new Thread(NetworkCheck);
  856. th.IsBackground = true;
  857. th.Start();
  858. //允许跨线程访问
  859. Control.CheckForIllegalCrossThreadCalls = false;
  860. }
  861. /// <summary>
  862. /// 检查网络状态线程
  863. /// </summary>
  864. private void NetworkCheck()
  865. {
  866. //允许离线使用,直接退出
  867. if (OfflineFlag == true) //允许离线使用
  868. {
  869. MessageBoxTimeOut.Show("离线使用,不检测网络状态!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  870. return;
  871. }
  872. //不允许离线使用,实时监测网络状态
  873. else
  874. {
  875. //初始化第一次连接FTP服务器
  876. bool Result = myFtp.CheckFtp();
  877. if (Result == true)//服务器连接成功
  878. {
  879. myFtp.IsNetConnected = true;
  880. //上传登录日志
  881. do
  882. {
  883. //日志文件名
  884. string date = DateTime.Now.ToString("yyyy-MM-dd_HHmmss_fff");
  885. string fileName = date;
  886. //日志内容
  887. string fileInfo = Local_HdInformation;
  888. //保存本地
  889. if (!Directory.Exists(localInfo.LocalLogPath))
  890. Directory.CreateDirectory(localInfo.LocalLogPath);
  891. System.IO.File.WriteAllText(localInfo.LocalLogPath + fileName, fileInfo);
  892. //上传服务器
  893. myFtp.UploadFile(localInfo.LocalLogPath + fileName, "/Tools/Welling_Motor_Debug_Tool/log");
  894. } while (false);
  895. }
  896. else//服务器连接失败
  897. {
  898. myFtp.IsNetConnected = false;
  899. if (EnterForm1.comboBox_User.Text != "管理员")
  900. {
  901. MessageBoxTimeOut.Show("网络断开,将自动关闭!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  902. this.Close();
  903. }
  904. }
  905. //创建定时器,定时30s检查网络
  906. System.Timers.Timer timer_CheckNet = new System.Timers.Timer();
  907. timer_CheckNet.Enabled = true;
  908. timer_CheckNet.Interval = 30000;
  909. timer_CheckNet.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_CheckNet_Tick);
  910. timer_CheckNet.Start();
  911. while (true)
  912. {
  913. Thread.Sleep(1);
  914. if (myFtp.IsNetConnected == false)
  915. {
  916. label_Server_ComStatus.Text = "网络已断开";
  917. label_ServerStatus.BackColor = Color.Red;
  918. }
  919. else
  920. {
  921. label_Server_ComStatus.Text = "网络已连接";
  922. label_ServerStatus.BackColor = Color.Green;
  923. }
  924. }
  925. }
  926. }
  927. /// <summary>
  928. /// 线程中定时任务,检查网络状态
  929. /// </summary>
  930. /// <param name="sender"></param>
  931. /// <param name="e"></param>
  932. private void timer_CheckNet_Tick(object sender, EventArgs e)
  933. {
  934. //连接FTP服务器
  935. bool Result = myFtp.CheckFtp();
  936. if (Result == true)//服务器连接成功
  937. {
  938. myFtp.IsNetConnected = true;
  939. //允许使用
  940. groupBox1.Enabled = true;
  941. groupBox3.Enabled = true;
  942. tabControl2.Enabled = true;
  943. }
  944. else//服务器连接失败
  945. {
  946. myFtp.IsNetConnected = false;
  947. if (EnterForm1.comboBox_User.Text != "管理员")
  948. {
  949. MessageBoxTimeOut.Show("网络断开, 请检查网络!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Warning); //提示框自动3s关闭
  950. //禁止使用
  951. groupBox1.Enabled = false;
  952. groupBox3.Enabled = false;
  953. tabControl2.Enabled = false;
  954. }
  955. }
  956. }
  957. #region 非独占性延时函数
  958. public static void Delay_ms(int milliSecond)
  959. {
  960. int start = Environment.TickCount;
  961. while (Math.Abs(Environment.TickCount - start) < milliSecond)//毫秒
  962. {
  963. Application.DoEvents();
  964. }
  965. }
  966. #endregion
  967. private void MainForm_Load(object sender, System.EventArgs e)
  968. {
  969. timer_500ms.Start();
  970. //页面初始化
  971. label_BuildTime.Text = "编译时间:" + System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString("yyyy-MM-dd HH:mm:ss");
  972. label_Computername.Text = System.Environment.UserName;
  973. label_UserName.Text = EnterForm1.comboBox_User.Text;
  974. //位置校准表格初始化
  975. for (int i = 0; i < 7; i++)
  976. {
  977. int index = dataGridView_AngleCal.Rows.Add();
  978. dataGridView_AngleCal.Rows[index].Cells[0].Value = i + 1;
  979. }
  980. dataGridView_AngleCal.AllowUserToAddRows = false;
  981. //拓展功能表格初始化
  982. for (int i = 0; i < 8; i++)
  983. {
  984. int index = dataGridView_FunSet.Rows.Add();
  985. dataGridView_FunSet.Rows[index].Cells[0].Value = "#" + (i + 1).ToString();
  986. }
  987. dataGridView_FunSet.AllowUserToAddRows = false;
  988. //窗体显示版本
  989. this.Text += Version;
  990. //检查版本,自动更新
  991. do
  992. {
  993. if ((打开ToolStripMenuItem.Checked == false) || OfflineFlag == true)//关闭自动更新或离线时
  994. {
  995. break;
  996. }
  997. //检查网络状态
  998. if (myFtp.CheckFtp() == false)
  999. {
  1000. MessageBoxTimeOut.Show("网络断开,自动更新失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  1001. break;
  1002. }
  1003. else
  1004. {
  1005. //检查本地文件删除
  1006. if (System.IO.File.Exists(localInfo.LocalPath + "\\Version"))
  1007. System.IO.File.Delete(localInfo.LocalPath + "\\Version");
  1008. //读取最新版本号
  1009. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/Version", localInfo.LocalPath);
  1010. StreamReader objReader = new StreamReader(localInfo.LocalPath + "\\Version");
  1011. string sLine = "";
  1012. ArrayList arrText = new ArrayList();//创建一个动态数组
  1013. while (sLine != null)
  1014. {
  1015. sLine = objReader.ReadLine();
  1016. arrText.Add(sLine);
  1017. }
  1018. objReader.Close();
  1019. System.IO.File.Delete(localInfo.LocalPath + "\\Version");
  1020. //检查是否有最新版本
  1021. string[] VerOld = mainForm.Version.Trim().Split('.');
  1022. string[] VerNew = arrText[0].ToString().Trim().Split('.');
  1023. int VerOld_int = Convert.ToInt32(VerOld[0]) * 10000 + Convert.ToInt32(VerOld[1].PadLeft(2, '0')) * 100 + Convert.ToInt32(VerOld[2].PadLeft(2, '0'));
  1024. int VerNew_int = Convert.ToInt32(VerNew[0]) * 10000 + Convert.ToInt32(VerNew[1].PadLeft(2, '0')) * 100 + Convert.ToInt32(VerNew[2].PadLeft(2, '0'));
  1025. if (VerNew_int <= VerOld_int)
  1026. {
  1027. //版本已是最新,跳出
  1028. break;
  1029. }
  1030. //确认下载最新版本
  1031. if (MessageBox.Show("是否更新新版本?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1032. {
  1033. string SavePath = Directory.GetCurrentDirectory();
  1034. string[] FileList = myFtp.GetFileNameList("/Tools/Welling_Motor_Debug_Tool");
  1035. foreach (string file in FileList)
  1036. {
  1037. if (file.Contains(".exe"))
  1038. {
  1039. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/" + file, SavePath);
  1040. MessageBox.Show("新版本下载完成,请手动删除旧版本!\r\n最新版本:" + file, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  1041. System.Environment.Exit(0);
  1042. }
  1043. }
  1044. }
  1045. }
  1046. } while (false);
  1047. //下拉控件初始值设定
  1048. comboBox_WorkMode.SelectedIndex = 0;
  1049. comboBox_GearSt.SelectedIndex = 0;
  1050. comboBox_LightSwitch.SelectedIndex = 1;
  1051. comboBox_OBC_SetGearST.SelectedIndex = 0;
  1052. comboBox_OBC_LightSw.SelectedIndex = 1;
  1053. comboBox_AssistTorque.SelectedIndex = 0;
  1054. comboBox_AssistCadence.SelectedIndex = 0;
  1055. //combobox事件定义
  1056. this.comboBox_WorkMode.SelectedIndexChanged += new System.EventHandler(this.comboBox_WorkMode_SelectedIndexChanged);
  1057. this.comboBox_GearSt.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  1058. this.comboBox_LightSwitch.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  1059. this.comboBox_OBC_SetGearST.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  1060. this.comboBox_OBC_LightSw.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  1061. //端口自动连接
  1062. if ((PortNumSave != string.Empty) && (PortBaudrateSave != string.Empty)) //有数值时采用上次使用的值
  1063. {
  1064. try
  1065. {
  1066. PortConnect();
  1067. }
  1068. catch (System.Exception)
  1069. {
  1070. timer_500ms.Enabled = false;
  1071. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  1072. timer_500ms.Enabled = true;
  1073. }
  1074. }
  1075. //不识别联动装置盒自动打开界面
  1076. #if true
  1077. groupBox1.Visible = true;
  1078. groupBox3.Visible = true;
  1079. tabControl2.Visible = true;
  1080. label_StarInfo.Visible = false;
  1081. #endif
  1082. //创建线程,定时解析数据
  1083. Thread th = new Thread(Task_SerialProcess);
  1084. th.IsBackground = true;
  1085. th.Start();
  1086. }
  1087. #region 结构体与字节流相互转换
  1088. public static class MyConverter
  1089. {
  1090. /// <summary>
  1091. /// 由结构体转换为byte数组
  1092. /// </summary>
  1093. public static byte[] StructureToByte<T>(T structure)
  1094. {
  1095. int size = Marshal.SizeOf(typeof(T));
  1096. byte[] buffer = new byte[size];
  1097. IntPtr bufferIntPtr = Marshal.AllocHGlobal(size);
  1098. try
  1099. {
  1100. Marshal.StructureToPtr(structure, bufferIntPtr, true);
  1101. Marshal.Copy(bufferIntPtr, buffer, 0, size);
  1102. }
  1103. finally
  1104. {
  1105. Marshal.FreeHGlobal(bufferIntPtr);
  1106. }
  1107. return buffer;
  1108. }
  1109. /// <summary>
  1110. /// 由byte数组转换为结构体
  1111. /// </summary>
  1112. public static T ByteToStructure<T>(byte[] dataBuffer, ushort StarIndex)
  1113. {
  1114. object structure = null;
  1115. int size = Marshal.SizeOf(typeof(T));
  1116. IntPtr allocIntPtr = Marshal.AllocHGlobal(size);
  1117. try
  1118. {
  1119. Marshal.Copy(dataBuffer, StarIndex, allocIntPtr, size);
  1120. structure = Marshal.PtrToStructure(allocIntPtr, typeof(T));
  1121. }
  1122. finally
  1123. {
  1124. Marshal.FreeHGlobal(allocIntPtr);
  1125. }
  1126. return (T)structure;
  1127. }
  1128. }
  1129. #endregion
  1130. #region 故障日志解析显示
  1131. private void ErrorLogDisplay(MC_ErrorLogSaveInfo_Struct_t Log1, MC_ErrorLogSaveInfo_Struct_t Log2)
  1132. {
  1133. string SaveData = "";
  1134. //Log1
  1135. if (Log1.Error_Index != 0xFFFF)
  1136. {
  1137. SaveData += "故障序号:" + Convert.ToString(Log1.Error_Index) + ", ";
  1138. SaveData += "备注1:" + Convert.ToString(Log1.NotesInfo1) + ", ";
  1139. SaveData += "备注2:" + Convert.ToString(Log1.NotesInfo2) + ", ";
  1140. SaveData += "备注3:" + Convert.ToString(Log1.NotesInfo3) + ", ";
  1141. SaveData += "故障码:" + "0x" + Convert.ToString(Log1.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  1142. SaveData += "运行时间:" + Convert.ToString(Log1.RunTime) + "min" + ", ";
  1143. SaveData += "车速:" + ((float)Log1.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  1144. SaveData += "电机转速:" + Convert.ToString(Log1.RunInfo.MotorSpeed) + "rpm" + ", ";
  1145. SaveData += "功率:" + Convert.ToString(Log1.RunInfo.Power * 2) + "w" + ", ";
  1146. SaveData += "电压:" + Convert.ToString(Log1.RunInfo.BusVoltage) + "mV" + ", ";
  1147. SaveData += "电流:" + Convert.ToString(Log1.RunInfo.BusCurrent) + "mA" + ", ";
  1148. SaveData += "踏频:" + Convert.ToString(Log1.RunInfo.Cadence) + "rpm" + ", ";
  1149. SaveData += "力矩:" + Convert.ToString(Log1.RunInfo.Torque) + "N.m" + ", ";
  1150. SaveData += "方向:" + ((Log1.RunInfo.CadenceDir == 0) ? "正" : ((Log1.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  1151. SaveData += "档位:" + "0x" + Convert.ToString(Log1.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  1152. SaveData += "灯开关:" + ((Log1.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  1153. SaveData += "电量:" + Convert.ToString(Log1.RunInfo.SOC) + "%" + ", ";
  1154. if ((Log1.RunInfo.RemainDistance == 0xEEEE) || (Log1.RunInfo.RemainDistance == 0xFFFF))
  1155. {
  1156. SaveData += "续航:" + "---km" + ", ";
  1157. }
  1158. else
  1159. {
  1160. SaveData += "续航:" + Convert.ToString(Log1.RunInfo.RemainDistance) + "km" + ", ";
  1161. }
  1162. SaveData += "力矩AD:" + Convert.ToString(Log1.RunInfo.Torque_AD) + ", ";
  1163. SaveData += "功耗:" + Convert.ToString(Log1.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  1164. SaveData += "PCB温度:" + Convert.ToString((int)(Log1.RunInfo.T_PCB - 40)) + "℃" + ", ";
  1165. SaveData += "绕组温度:" + Convert.ToString((int)(Log1.RunInfo.T_Coil - 40)) + "℃" + ", ";
  1166. SaveData += "MCU温度:" + Convert.ToString((int)(Log1.RunInfo.T_MCU - 40)) + "℃" + ", ";
  1167. SaveData += "单次里程:" + Convert.ToString((float)Log1.RunInfo.Ride_Km / 10f) + "km" + ", ";
  1168. SaveData += "单次时间:" + Convert.ToString(Log1.RunInfo.Ride_Time) + "s" + ", ";
  1169. SaveData += "q轴电流:" + Convert.ToString(Log1.IqCurrent) + ", ";
  1170. SaveData += "q轴电压:" + Convert.ToString(Log1.IqVoltage) + ", ";
  1171. SaveData += "d轴电流:" + Convert.ToString(Log1.IdCurrent) + ", ";
  1172. SaveData += "d轴电压:" + Convert.ToString(Log1.IdVoltage) + ", ";
  1173. SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
  1174. SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
  1175. SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
  1176. SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
  1177. SaveData += "\r\n\r\n";
  1178. richTextBox_Record.AppendText(SaveData);
  1179. SaveData = "";
  1180. }
  1181. //Log2
  1182. if (Log2.Error_Index != 0xFFFF)
  1183. {
  1184. SaveData += "故障序号:" + Convert.ToString(Log2.Error_Index) + ", ";
  1185. SaveData += "备注1:" + Convert.ToString(Log2.NotesInfo1) + ", ";
  1186. SaveData += "备注2:" + Convert.ToString(Log2.NotesInfo2) + ", ";
  1187. SaveData += "备注3:" + Convert.ToString(Log2.NotesInfo3) + ", ";
  1188. SaveData += "故障码:" + "0x" + Convert.ToString(Log2.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  1189. SaveData += "运行时间:" + Convert.ToString(Log2.RunTime) + "min" + ", ";
  1190. SaveData += "车速:" + ((float)Log2.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  1191. SaveData += "电机转速:" + Convert.ToString(Log2.RunInfo.MotorSpeed) + "rpm" + ", ";
  1192. SaveData += "功率:" + Convert.ToString(Log2.RunInfo.Power * 2) + "w" + ", ";
  1193. SaveData += "电压:" + Convert.ToString(Log2.RunInfo.BusVoltage) + "mV" + ", ";
  1194. SaveData += "电流:" + Convert.ToString(Log2.RunInfo.BusCurrent) + "mA" + ", ";
  1195. SaveData += "踏频:" + Convert.ToString(Log2.RunInfo.Cadence) + "rpm" + ", ";
  1196. SaveData += "力矩:" + Convert.ToString(Log2.RunInfo.Torque) + "N.m" + ", ";
  1197. SaveData += "方向:" + ((Log2.RunInfo.CadenceDir == 0) ? "正" : ((Log2.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  1198. SaveData += "档位:" + "0x" + Convert.ToString(Log2.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  1199. SaveData += "灯开关:" + ((Log2.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  1200. SaveData += "电量:" + Convert.ToString(Log2.RunInfo.SOC) + "%" + ", ";
  1201. if ((Log2.RunInfo.RemainDistance == 0xEEEE) || (Log2.RunInfo.RemainDistance == 0xFFFF))
  1202. {
  1203. SaveData += "续航:" + "---km" + ", ";
  1204. }
  1205. else
  1206. {
  1207. SaveData += "续航:" + Convert.ToString(Log2.RunInfo.RemainDistance) + "km" + ", ";
  1208. }
  1209. SaveData += "力矩AD:" + Convert.ToString(Log2.RunInfo.Torque_AD) + ", ";
  1210. SaveData += "功耗:" + Convert.ToString(Log2.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  1211. SaveData += "PCB温度:" + Convert.ToString((int)(Log2.RunInfo.T_PCB - 40)) + "DegreeC" + ", ";
  1212. SaveData += "绕组温度:" + Convert.ToString((int)(Log2.RunInfo.T_Coil - 40)) + "DegreeC" + ", ";
  1213. SaveData += "MCU温度:" + Convert.ToString((int)(Log2.RunInfo.T_MCU - 40)) + "DegreeC" + ", ";
  1214. SaveData += "单次里程:" + Convert.ToString((float)Log2.RunInfo.Ride_Km / 10f) + "km" + ", ";
  1215. SaveData += "单次时间:" + Convert.ToString(Log2.RunInfo.Ride_Time) + "s" + ", ";
  1216. SaveData += "q轴电流:" + Convert.ToString(Log2.IqCurrent) + ", ";
  1217. SaveData += "q轴电压:" + Convert.ToString(Log2.IqVoltage) + ", ";
  1218. SaveData += "d轴电流:" + Convert.ToString(Log2.IdCurrent) + ", ";
  1219. SaveData += "d轴电压:" + Convert.ToString(Log2.IdVoltage) + ", ";
  1220. SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
  1221. SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
  1222. SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
  1223. SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
  1224. SaveData += "\r\n\r\n";
  1225. richTextBox_Record.AppendText(SaveData);
  1226. SaveData = "";
  1227. }
  1228. }
  1229. #endregion
  1230. #region 串口数据解析线程
  1231. /// <summary>
  1232. /// 串口数据解析线程
  1233. /// </summary>
  1234. private void Task_SerialProcess()
  1235. {
  1236. //创建定时器,定时读取串口数据
  1237. System.Timers.Timer timer_ReadSerial = new System.Timers.Timer();
  1238. timer_ReadSerial.Enabled = true;
  1239. timer_ReadSerial.Interval = 20;
  1240. timer_ReadSerial.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_ReadSerial_Tick);
  1241. timer_ReadSerial.Start();
  1242. while (true)
  1243. {
  1244. Thread.Sleep(1);
  1245. };
  1246. }
  1247. /// <summary>
  1248. /// 串口解析定时器
  1249. /// </summary>
  1250. /// <param name="sender"></param>
  1251. /// <param name="e"></param>
  1252. private void timer_ReadSerial_Tick(object sender, EventArgs e)
  1253. {
  1254. //串口解析
  1255. Serial_process(mySerialProcess.buffer);
  1256. }
  1257. #endregion
  1258. #region 数据解析
  1259. public void Serial_process(List<byte> buffer)
  1260. {
  1261. byte DataNum = 0; //记录每条命令数据段的长度
  1262. ushort PackageID, Cmd;
  1263. byte[] Data = new byte[1024];
  1264. try
  1265. {
  1266. while (buffer.Count >= 13)//当buffer中的数据的个数大于等于4个时,即每一帧的数据长度所在位(第4位)出现时
  1267. {
  1268. if (buffer[0] == 0x55 && buffer[1] == 0xAA)//判断帧头
  1269. {
  1270. PackageID = (ushort)(buffer[2] * 256 + buffer[3]);
  1271. if ((PackageID == 0x0710) || (PackageID == 0x0715) || (PackageID == 0x07FF) || (PackageID == 0x0720) || (PackageID == 0x0713))
  1272. {
  1273. int CmdLen = buffer[5];
  1274. if (buffer.Count < CmdLen + 11) break;//如果接收到的数据没有达到一帧数据的指定长度, 则执行下次循环
  1275. while (CmdLen > 0) //读取命令段
  1276. {
  1277. Cmd = (ushort)(buffer[6] * 256 + buffer[7]);
  1278. DataNum = (byte)(buffer[7]);//命令字的第二个字节的表示数据位的长度
  1279. if (DataNum <= (CmdLen - 2))
  1280. {
  1281. for (int i = 0; i < DataNum; i++)
  1282. {
  1283. Data[i] = buffer[i + 8];
  1284. }
  1285. // 串口接收的数据 显示在子窗口
  1286. if (this.DebugWindowIsOpen && this.DebugDataDisplayEnable)
  1287. {
  1288. string strTemp = String.Empty;
  1289. strTemp += System.DateTimeOffset.Now.ToString("HH:mm:ss.fff") + " <-- ";
  1290. for (int i = 0; i < CmdLen + 11; i++)
  1291. {
  1292. strTemp += (buffer[i].ToString("X2") + " ");
  1293. }
  1294. strTemp += "\n";
  1295. DebugForm.debug1.richTextBox_DebugRev.Text += strTemp;
  1296. }
  1297. buffer.RemoveRange(0, CmdLen + 11);
  1298. DataCmdProcess(PackageID, Cmd, Data);//对于不同的命令段,做不同的处理
  1299. DataRevToString(Cmd, Data);//指令数据转为字符串
  1300. }
  1301. }
  1302. }
  1303. else
  1304. {
  1305. buffer.RemoveAt(0);//ID不对
  1306. }
  1307. }
  1308. else
  1309. {
  1310. buffer.RemoveAt(0);//帧头不对,删除帧头高字节
  1311. }
  1312. }
  1313. }
  1314. catch (Exception)
  1315. {
  1316. }
  1317. }
  1318. private void DataCmdProcess(ushort ID, ushort CmdTemp, byte[] Data)
  1319. {
  1320. int DataTemp;
  1321. ushort uData16;
  1322. unchecked
  1323. {
  1324. this.Invoke((EventHandler)(delegate { label_RecCount.Text = Convert.ToString(Convert.ToInt32(label_RecCount.Text) + 1); }));
  1325. }
  1326. #region 解析发送给CDL的指令
  1327. if (ID == 0x7FF)
  1328. {
  1329. switch (CmdTemp)
  1330. {
  1331. case 0x1100://握手
  1332. {
  1333. unchecked
  1334. {
  1335. this.Invoke((EventHandler)(delegate
  1336. {
  1337. //CDL连接成功
  1338. mySerialProcess.CDL_Online_Flag = true;
  1339. MessageBoxTimeOut.Show("连接成功!", "提示", 500);
  1340. groupBox1.Visible = true;
  1341. groupBox3.Visible = true;
  1342. tabControl2.Visible = true;
  1343. label_StarInfo.Visible = false;
  1344. }));
  1345. }
  1346. break;
  1347. }
  1348. case 0x551B: //版本
  1349. {
  1350. unchecked
  1351. {
  1352. this.Invoke((EventHandler)(delegate
  1353. {
  1354. string str;
  1355. byte[] Temp = new byte[16];
  1356. Array.Copy(Data, 12, Temp, 0, 16);
  1357. str = System.Text.Encoding.ASCII.GetString(Temp);
  1358. toolStripTextBox_CDL_Version.Text = str;
  1359. }));
  1360. }
  1361. break;
  1362. }
  1363. case 0x8004: //Mode
  1364. {
  1365. unchecked
  1366. {
  1367. this.Invoke((EventHandler)(delegate
  1368. {
  1369. int temp;
  1370. temp = (int)((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]);
  1371. if (temp == 1)
  1372. {
  1373. toolStripComboBox_PortMode.SelectedIndex = 0; //CAN
  1374. }
  1375. else if (temp == 2)
  1376. {
  1377. toolStripComboBox_PortMode.SelectedIndex = 1; //UART
  1378. }
  1379. }));
  1380. }
  1381. break;
  1382. }
  1383. case 0x8003: //ACK
  1384. {
  1385. unchecked
  1386. {
  1387. this.Invoke((EventHandler)(delegate
  1388. {
  1389. MessageBoxTimeOut.Show("OK", "CDL反馈指令", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  1390. }));
  1391. }
  1392. break;
  1393. }
  1394. case 0x8204: //Uart Boot Baudrate
  1395. {
  1396. unchecked
  1397. {
  1398. this.Invoke((EventHandler)(delegate
  1399. {
  1400. int temp;
  1401. temp = (int)((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]);
  1402. toolStripComboBox_UARTBOOTBAUD.SelectedIndex= toolStripComboBox_UARTBOOTBAUD.Items.IndexOf(temp.ToString());
  1403. }));
  1404. }
  1405. break;
  1406. }
  1407. case 0x8404: //Uart App Baudrate
  1408. {
  1409. unchecked
  1410. {
  1411. this.Invoke((EventHandler)(delegate
  1412. {
  1413. int temp;
  1414. temp = (int)((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]);
  1415. toolStripComboBox_UARTAPPBAUD.SelectedIndex = toolStripComboBox_UARTAPPBAUD.Items.IndexOf(temp.ToString());
  1416. }));
  1417. }
  1418. break;
  1419. }
  1420. case 0x8604: //CAN Baudrate
  1421. {
  1422. unchecked
  1423. {
  1424. this.Invoke((EventHandler)(delegate
  1425. {
  1426. int temp;
  1427. temp = (int)((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]);
  1428. toolStripComboBox_CANBaud.SelectedIndex = toolStripComboBox_CANBaud.Items.IndexOf(temp.ToString());
  1429. }));
  1430. }
  1431. break;
  1432. }
  1433. case 0x8810: //定制内容
  1434. {
  1435. unchecked
  1436. {
  1437. this.Invoke((EventHandler)(delegate
  1438. {
  1439. string str;
  1440. byte[] Temp = new byte[16];
  1441. Array.Copy(Data, 0, Temp, 0, 16);
  1442. str = System.Text.Encoding.ASCII.GetString(Temp);
  1443. toolStripTextBox_OPTION_GIANT.Checked = (str.Contains("GIANT"));
  1444. if (!str.Contains("GIANT"))
  1445. {
  1446. if (str.Contains("."))
  1447. toolStripTextBox_OPTION_Others.Text = str.Substring(0, str.IndexOf('.'));
  1448. else
  1449. toolStripTextBox_OPTION_Others.Text = str;
  1450. }
  1451. else
  1452. {
  1453. toolStripTextBox_OPTION_Others.Text = "";
  1454. }
  1455. }));
  1456. }
  1457. break;
  1458. }
  1459. default: break;
  1460. }
  1461. }
  1462. #endregion
  1463. #region 解析电机的命令
  1464. else if ((ID == 0x715) || (ID == 0x710))
  1465. {
  1466. switch (CmdTemp)
  1467. {
  1468. case 0x1020://电机运行信息
  1469. {
  1470. unchecked
  1471. {
  1472. this.Invoke((EventHandler)(delegate
  1473. {
  1474. MC_RunInfo_Refresh = true;
  1475. //车速
  1476. DataTemp = (int)(Data[1] * 256 + Data[0]);
  1477. textBox_RunInfo_BikeSpeed.Text = ((float)DataTemp / 10f).ToString("0.0") + " km/h";
  1478. //输出转速
  1479. DataTemp = (ushort)(Data[3] * 256 + Data[2]);
  1480. textBox_RunInfo_MotorSpeed.Text = Convert.ToString(DataTemp) + " rpm";
  1481. Class_MotorSpeed.String = textBox_RunInfo_MotorSpeed.Text;
  1482. Class_MotorSpeed.Data = DataTemp;
  1483. //电功率
  1484. DataTemp = (ushort)(Data[5] * 256 + Data[4]);
  1485. textBox_RunInfo_Power.Text = Convert.ToString(DataTemp) + " W";
  1486. //母线电压
  1487. DataTemp = (ushort)(Data[7] * 256 + Data[6]);
  1488. textBox_RunInfo_Vol.Text = Convert.ToString(DataTemp) + " mV";
  1489. //textBox_RunInfo_Vol.Text = (DataTemp / 1000f).ToString("0.0") + " V";
  1490. //母线电流
  1491. DataTemp = (short)(Data[9] * 256 + Data[8]);
  1492. textBox_RunInfo_Current.Text = Convert.ToString(DataTemp) + " mA";
  1493. //textBox_RunInfo_Current.Text = (DataTemp / 1000f).ToString("0.0") + " A";
  1494. Class_CurrentData.String = textBox_RunInfo_Current.Text;
  1495. Class_CurrentData.Data = DataTemp;
  1496. //踏频
  1497. DataTemp = (ushort)(Data[10]);
  1498. textBox_RunInfo_Cadence.Text = Convert.ToString(DataTemp) + " rpm";
  1499. Class_CadenceData.String = textBox_RunInfo_Cadence.Text;
  1500. Class_CadenceData.Data = DataTemp;
  1501. //踩踏力矩
  1502. DataTemp = (ushort)(Data[11]);
  1503. textBox_RunInfo_Torque.Text = Convert.ToString(DataTemp) + " N.m";
  1504. Class_TorqueData.String = textBox_RunInfo_Torque.Text;
  1505. Class_TorqueData.Data = DataTemp;
  1506. //踩踏方向
  1507. DataTemp = (ushort)(Data[12]);
  1508. if (DataTemp == 0)
  1509. {
  1510. textBox_RunInfo_Dir.Text = "正向";
  1511. }
  1512. else if (DataTemp == 1)
  1513. {
  1514. textBox_RunInfo_Dir.Text = "反向";
  1515. }
  1516. else if (DataTemp == 2)
  1517. {
  1518. textBox_RunInfo_Dir.Text = "停止";
  1519. }
  1520. //助力档位
  1521. DataTemp = (ushort)(Data[13]);
  1522. if (DataTemp == 0x33)
  1523. {
  1524. textBox_RunInfo_GearSt.Text = "SMART";
  1525. //comboBox_GearSt.SelectedIndex = 5;
  1526. //comboBox_OBC_SetGearST.SelectedIndex = 5;
  1527. }
  1528. else if (DataTemp == 0x22)
  1529. {
  1530. textBox_RunInfo_GearSt.Text = "WALK";
  1531. //comboBox_GearSt.SelectedIndex = 6;
  1532. //comboBox_OBC_SetGearST.SelectedIndex = 6;
  1533. }
  1534. else
  1535. {
  1536. string[] Gears = new string[5] { "OFF", "ECO", "NORM", "SPORT", "TURBO" };
  1537. textBox_RunInfo_GearSt.Text = Gears[DataTemp];
  1538. //comboBox_GearSt.SelectedIndex = DataTemp;
  1539. //comboBox_OBC_SetGearST.SelectedIndex = DataTemp;
  1540. }
  1541. //大灯状态
  1542. DataTemp = (ushort)(Data[14]);
  1543. if (DataTemp == 0xF0)
  1544. {
  1545. textBox_RunInfo_LightSwitch.Text = "OFF";
  1546. //comboBox_LightSwitch.SelectedIndex = 1;
  1547. //comboBox_OBC_LightSw.SelectedIndex = 1;
  1548. }
  1549. else if (DataTemp == 0xF1)
  1550. {
  1551. textBox_RunInfo_LightSwitch.Text = "ON";
  1552. //comboBox_LightSwitch.SelectedIndex = 0;
  1553. //comboBox_OBC_LightSw.SelectedIndex = 0;
  1554. }
  1555. //剩余电量
  1556. DataTemp = (ushort)(Data[15]);
  1557. textBox_RunInfo_SOC.Text = Convert.ToString(DataTemp) + " %";
  1558. //剩余续航里程
  1559. DataTemp = (ushort)(Data[17] * 256 + Data[16]);
  1560. if ((DataTemp == 0xEEEE) || (DataTemp == 0xFFFF))
  1561. {
  1562. textBox_RunInfo_Range.Text = "---";
  1563. }
  1564. else
  1565. {
  1566. textBox_RunInfo_Range.Text = Convert.ToString(DataTemp) + " km";
  1567. }
  1568. //预留(显示力矩Reg),空2bytes
  1569. DataTemp = (ushort)(Data[19] * 256 + Data[18]);
  1570. textBox_TorqueReg.Text = Convert.ToString(DataTemp);
  1571. //平均功耗
  1572. DataTemp = (ushort)(Data[20]);
  1573. textBox_RunInfo_AvgPower.Text = Convert.ToString(DataTemp * 10) + " mAh/km";
  1574. //PCB温度
  1575. DataTemp = (ushort)(Data[21]);
  1576. textBox_RunInfo_T_PCB.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1577. Class_MotorTemp.String = textBox_RunInfo_T_PCB.Text;
  1578. Class_MotorTemp.Data = DataTemp - 40;
  1579. //绕组温度
  1580. DataTemp = (ushort)(Data[22]);
  1581. textBox_RunInfo_T_Coil.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1582. //MCU温度
  1583. DataTemp = (ushort)(Data[23]);
  1584. textBox_RunInfo_T_MCU.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1585. //单次里程
  1586. DataTemp = (ushort)(Data[25] * 256 + Data[24]);
  1587. textBox_RunInfo_Trip.Text = ((float)DataTemp / 10f).ToString("0.0") + " km";
  1588. //单次时间
  1589. DataTemp = (ushort)(Data[27] * 256 + Data[26]);
  1590. textBox_RunInfo_Trip_Time.Text = Convert.ToString(DataTemp) + " s";
  1591. //RSV1
  1592. DataTemp = (ushort)(Data[28]);
  1593. textBox_RunInfo_RSV1.Text = Convert.ToString(DataTemp);
  1594. //RSV2
  1595. DataTemp = (ushort)(Data[29]);
  1596. textBox_RunInfo_RSV2.Text = Convert.ToString(DataTemp);
  1597. //RSV3
  1598. DataTemp = (ushort)(Data[30]);
  1599. textBox_RunInfo_RSV3.Text = Convert.ToString(DataTemp);
  1600. //GearBox
  1601. DataTemp = (ushort)(Data[31]);
  1602. textBox_RunInfo_GearBox.Text = Convert.ToString(DataTemp);
  1603. //数据保存
  1604. RunInfoAutoSave();
  1605. }));
  1606. }
  1607. break;
  1608. }
  1609. case 0x1104://故障码
  1610. {
  1611. unchecked
  1612. {
  1613. this.Invoke((EventHandler)(delegate
  1614. {
  1615. MC_ErrorCode_Refresh = true;
  1616. textBox_ErrorCode.Text =
  1617. Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() +
  1618. Convert.ToString(Data[2], 16).PadLeft(2, '0').ToUpper() +
  1619. Convert.ToString(Data[1], 16).PadLeft(2, '0').ToUpper() +
  1620. Convert.ToString(Data[0], 16).PadLeft(2, '0').ToUpper() +
  1621. "H";
  1622. }));
  1623. }
  1624. break;
  1625. }
  1626. case 0xA903://反馈指令
  1627. {
  1628. unchecked
  1629. {
  1630. this.Invoke((EventHandler)(delegate
  1631. {
  1632. if (ACK_DisFlag == true)
  1633. {
  1634. MessageBoxTimeOut.Show("OK", "反馈指令", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  1635. //关机反馈
  1636. PowerOffAckStatus = true;
  1637. }
  1638. //应答标志置位
  1639. WriteACK = true;
  1640. }));
  1641. }
  1642. break;
  1643. }
  1644. case 0xB226://马达参数
  1645. {
  1646. unchecked
  1647. {
  1648. this.Invoke((EventHandler)(delegate
  1649. {
  1650. richTextBox_MotorParam.Clear();
  1651. for (int i = 0; i < myParams.MotorParam.Count; i++)
  1652. {
  1653. if (i == 6)
  1654. richTextBox_MotorParam.AppendText(myParams.MotorParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1655. else
  1656. richTextBox_MotorParam.AppendText(myParams.MotorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1657. }
  1658. richTextBox_MotorParam.Text = richTextBox_MotorParam.Text.Substring(0, richTextBox_MotorParam.Text.Length - 2);
  1659. }));
  1660. }
  1661. break;
  1662. }
  1663. case 0xB31A://整车信息
  1664. {
  1665. unchecked
  1666. {
  1667. this.Invoke((EventHandler)(delegate
  1668. {
  1669. richTextBox_BikeParam.Clear();
  1670. for (int i = 0; i < myParams.BikeParam.Count; i++)
  1671. {
  1672. if (i == 9)
  1673. richTextBox_BikeParam.AppendText(myParams.BikeParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1674. else
  1675. richTextBox_BikeParam.AppendText(myParams.BikeParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1676. //更新前后灯参数
  1677. if (i == 8)
  1678. {
  1679. comboBox_TailLightMode.SelectedIndex = ((Data[2 * i + 1] >> 4) & 0x0F) - 1;
  1680. comboBox_TailLightVol.SelectedIndex = ((Data[2 * i + 1] & 0x0F) == 6) ? 0 : 1;
  1681. comboBox_FrontLightVol.SelectedIndex = ((Data[2 * i] & 0x0F) == 6) ? 0 : 1;
  1682. }
  1683. //更新开关机参数
  1684. else if (i == 11)
  1685. {
  1686. textBox_PowerOnDelay.Text = Convert.ToString((Data[2 * i + 1] >> 4) & 0x0F);
  1687. textBox_PowerOffDelay.Text = Convert.ToString(Data[2 * i + 1] & 0x0F);
  1688. textBox_AutoPowerOff.Text = Convert.ToString(Data[2 * i]);
  1689. }
  1690. }
  1691. richTextBox_BikeParam.Text = richTextBox_BikeParam.Text.Substring(0, richTextBox_BikeParam.Text.Length - 2);
  1692. }));
  1693. }
  1694. break;
  1695. }
  1696. case 0xB420://控制器参数
  1697. {
  1698. unchecked
  1699. {
  1700. this.Invoke((EventHandler)(delegate
  1701. {
  1702. richTextBox_ControlParam.Clear();
  1703. for (int i = 0; i < myParams.ControlParam.Count; i++)
  1704. {
  1705. richTextBox_ControlParam.AppendText(myParams.ControlParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1706. //转把定速巡航
  1707. if (i == 13)
  1708. {
  1709. comboBox_Bike_CCS.SelectedIndex = ((Data[2 * i]) == 0xAA) ? 1 : 2;
  1710. }
  1711. }
  1712. richTextBox_ControlParam.Text = richTextBox_ControlParam.Text.Substring(0, richTextBox_ControlParam.Text.Length - 2);
  1713. }));
  1714. }
  1715. break;
  1716. }
  1717. case 0xB528://传感器参数
  1718. {
  1719. unchecked
  1720. {
  1721. this.Invoke((EventHandler)(delegate
  1722. {
  1723. richTextBox_SensorParam.Clear();
  1724. for (int i = 0; i < myParams.SensorParam.Count; i++)
  1725. {
  1726. richTextBox_SensorParam.AppendText(myParams.SensorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1727. }
  1728. richTextBox_SensorParam.Text = richTextBox_SensorParam.Text.Substring(0, richTextBox_SensorParam.Text.Length - 2);
  1729. //更新生产模式页面传感器零点和标定值
  1730. textBox_FacModeSensorADC0.Text = (Data[9] * 256 + Data[8]).ToString();
  1731. textBox_FacModeSensorADC1.Text = (Data[15] * 256 + Data[14]).ToString();
  1732. textBox_FacModeSensorADC2.Text = (Data[19] * 256 + Data[18]).ToString();
  1733. textBox_FacModeSensorADC3.Text = (Data[23] * 256 + Data[22]).ToString();
  1734. textBox_FacModeSensorADC4.Text = (Data[27] * 256 + Data[26]).ToString();
  1735. WriteACK = true;
  1736. }));
  1737. }
  1738. break;
  1739. }
  1740. case 0xB64C://助力参数
  1741. {
  1742. unchecked
  1743. {
  1744. this.Invoke((EventHandler)(delegate
  1745. {
  1746. richTextBox_AssistParam.Clear();
  1747. int index_1 = myParams.AssistParam.IndexOf("转矩曲线.a");
  1748. int index_2 = myParams.AssistParam.IndexOf("踏频曲线.d");
  1749. int index_3 = myParams.AssistParam.IndexOf("踏频助力加速限制");
  1750. int index_4 = myParams.AssistParam.IndexOf("踏频助力电流步进");
  1751. for (int i = 0; i < myParams.AssistParam.Count; i++)
  1752. {
  1753. if (i < index_1) //数据占用2bytes
  1754. {
  1755. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1756. }
  1757. else if (i <= index_2) //数据占用4bytes
  1758. {
  1759. 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])) + ", ");
  1760. }
  1761. else if (i < index_3) //数据占用2bytes,无符号
  1762. {
  1763. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1764. }
  1765. else if (i <= index_4) //数据占用2bytes,有符号
  1766. {
  1767. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1768. }
  1769. else //数据占用2bytes,无符号
  1770. {
  1771. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1772. }
  1773. }
  1774. richTextBox_AssistParam.Text = richTextBox_AssistParam.Text.Substring(0, richTextBox_AssistParam.Text.Length - 2);
  1775. }));
  1776. }
  1777. break;
  1778. }
  1779. case 0xB74C://历史记录
  1780. {
  1781. unchecked
  1782. {
  1783. this.Invoke((EventHandler)(delegate
  1784. {
  1785. richTextBox_Record.Clear();
  1786. for (int i = 0; i < myParams.Record.Count; i++)
  1787. {
  1788. richTextBox_Record.AppendText(myParams.Record[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  1789. }
  1790. richTextBox_Record.Text = richTextBox_Record.Text.Substring(0, richTextBox_Record.Text.Length - 2);
  1791. }));
  1792. }
  1793. break;
  1794. }
  1795. case 0xB83A://调试参数
  1796. {
  1797. unchecked
  1798. {
  1799. this.Invoke((EventHandler)(delegate
  1800. {
  1801. richTextBox_DebugParam.Clear();
  1802. for (int i = 0; i < myParams.DebugParam.Count; i++)
  1803. {
  1804. richTextBox_DebugParam.AppendText(myParams.DebugParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1805. }
  1806. richTextBox_DebugParam.Text = richTextBox_DebugParam.Text.Substring(0, richTextBox_DebugParam.Text.Length - 2);
  1807. }));
  1808. }
  1809. break;
  1810. }
  1811. case 0xB904://存储标志
  1812. {
  1813. unchecked
  1814. {
  1815. this.Invoke((EventHandler)(delegate
  1816. {
  1817. ushort Flag = 0;
  1818. Flag = (ushort)(Data[1] * 256 + Data[0]);//EEPROM存储标志
  1819. if (Flag == 0)
  1820. {
  1821. radioButton_EE_SaveNo.Checked = true;
  1822. radioButton_EE_SaveYes.Checked = false;
  1823. }
  1824. else
  1825. {
  1826. radioButton_EE_SaveNo.Checked = false;
  1827. radioButton_EE_SaveYes.Checked = true;
  1828. }
  1829. Flag = (ushort)(Data[3] * 256 + Data[2]);//SIP偏移校准存储标志
  1830. if (Flag == 0)
  1831. {
  1832. radioButton_SIP_SaveNo.Checked = true;
  1833. radioButton_SIP_SaveYes.Checked = false;
  1834. }
  1835. else
  1836. {
  1837. radioButton_SIP_SaveNo.Checked = false;
  1838. radioButton_SIP_SaveYes.Checked = true;
  1839. }
  1840. }));
  1841. }
  1842. break;
  1843. }
  1844. case 0x1240://电机版本信息
  1845. {
  1846. unchecked
  1847. {
  1848. this.Invoke((EventHandler)(delegate
  1849. {
  1850. //电机型号
  1851. textBox_Model.Text = "";
  1852. textBox_OBC_ReadModel.Text = "";
  1853. textBox_FacModeName.Text = "";
  1854. for (ushort i = 0; i < 16; i++)
  1855. {
  1856. if (Data[i] == 0x2E)
  1857. {
  1858. break;
  1859. }
  1860. textBox_Model.Text += ((char)Data[i]).ToString();
  1861. textBox_OBC_ReadModel.Text += ((char)Data[i]).ToString();
  1862. textBox_FacModeName.Text += ((char)Data[i]).ToString();
  1863. }
  1864. Class_Motor_Ver.Mode = textBox_Model.Text;
  1865. //电机SN
  1866. textBox_SN.Text = "";
  1867. textBox_OBC_ReadSN.Text = "";
  1868. textBox_FacModeNum.Text = "";
  1869. for (ushort i = 0; i < 16; i++)
  1870. {
  1871. if (Data[16 + i] == 0x2E)
  1872. {
  1873. break;
  1874. }
  1875. textBox_SN.Text += ((char)Data[16 + i]).ToString();
  1876. textBox_OBC_ReadSN.Text += ((char)Data[16 + i]).ToString();
  1877. textBox_FacModeNum.Text += ((char)Data[16 + i]).ToString();
  1878. }
  1879. Class_Motor_Ver.SN = textBox_SN.Text;
  1880. //电机HW
  1881. textBox_HW.Text = "";
  1882. textBox_OBC_ReadHW.Text = "";
  1883. textBox_FacModeHW.Text = "";
  1884. for (ushort i = 0; i < 8; i++)//前8位:硬件板号
  1885. {
  1886. if (Data[32 + i] == 0x2E)
  1887. {
  1888. break;
  1889. }
  1890. else if (Data[32 + i] == 'r')
  1891. {
  1892. Data[32 + i] = (byte)'.';
  1893. break;
  1894. }
  1895. string strTemp = "";
  1896. strTemp = ((char)Data[32 + i]).ToString();
  1897. textBox_HW.Text += strTemp;
  1898. textBox_OBC_ReadHW.Text += strTemp;
  1899. textBox_FacModeHW.Text += strTemp;
  1900. }
  1901. for (ushort i = 0; i < 4; i++)//9-12位:单片机型号
  1902. {
  1903. if (Data[40 + i] == 0x2E)
  1904. {
  1905. break;
  1906. }
  1907. else if (Data[40 + i] == 'r')
  1908. {
  1909. Data[40 + i] = (byte)'.';
  1910. break;
  1911. }
  1912. string strTemp = "";
  1913. strTemp = ((char)Data[40 + i]).ToString();
  1914. textBox_HW.Text += strTemp;
  1915. textBox_OBC_ReadHW.Text += strTemp;
  1916. textBox_FacModeHW.Text += strTemp;
  1917. }
  1918. for (ushort i = 0; i < 4; i++)//13-16位:单片机ID
  1919. {
  1920. string strTemp = "";
  1921. strTemp = Convert.ToString(Data[44 + i], 16).PadLeft(2, '0').ToUpper();
  1922. textBox_HW.Text += strTemp;
  1923. textBox_OBC_ReadHW.Text += strTemp;
  1924. textBox_FacModeHW.Text += strTemp;
  1925. }
  1926. Class_Motor_Ver.HW = textBox_HW.Text;
  1927. //电机FW
  1928. textBox_FW.Text = "";
  1929. textBox_OBC_ReadFW.Text = "";
  1930. textBox_FacModeFW.Text = "";
  1931. for (ushort i = 0; i < 16; i++)
  1932. {
  1933. if ((Data[48 + i] == 0x2E) || (Data[48 + i] == 0x00) || (Data[48 + i] == (char)' '))
  1934. {
  1935. break;
  1936. }
  1937. if (Data[48 + i] == 'r')
  1938. {
  1939. Data[48 + i] = (byte)'.';
  1940. }
  1941. textBox_FW.Text += ((char)Data[48 + i]).ToString();
  1942. textBox_OBC_ReadFW.Text += ((char)Data[48 + i]).ToString();
  1943. textBox_FacModeFW.Text += ((char)Data[48 + i]).ToString();
  1944. }
  1945. Class_Motor_Ver.FW = textBox_FW.Text;
  1946. }));
  1947. }
  1948. break;
  1949. }
  1950. case 0xA610://自定义1
  1951. {
  1952. unchecked
  1953. {
  1954. this.Invoke((EventHandler)(delegate
  1955. {
  1956. textBox_User1.Text = "";
  1957. for (ushort i = 0; i < 16; i++)
  1958. {
  1959. if (Data[i] == 0x2E)
  1960. {
  1961. break;
  1962. }
  1963. textBox_User1.Text += ((char)Data[i]).ToString();
  1964. }
  1965. }));
  1966. }
  1967. break;
  1968. }
  1969. case 0xA710://自定义2
  1970. {
  1971. unchecked
  1972. {
  1973. this.Invoke((EventHandler)(delegate
  1974. {
  1975. textBox_User2.Text = "";
  1976. for (ushort i = 0; i < 16; i++)
  1977. {
  1978. if (Data[i] == 0x2E)
  1979. {
  1980. break;
  1981. }
  1982. textBox_User2.Text += ((char)Data[i]).ToString();
  1983. }
  1984. }));
  1985. }
  1986. break;
  1987. }
  1988. case 0xA810://自定义1
  1989. {
  1990. unchecked
  1991. {
  1992. this.Invoke((EventHandler)(delegate
  1993. {
  1994. textBox_User3.Text = "";
  1995. for (ushort i = 0; i < 16; i++)
  1996. {
  1997. if (Data[i] == 0x2E)
  1998. {
  1999. break;
  2000. }
  2001. textBox_User3.Text += ((char)Data[i]).ToString();
  2002. }
  2003. }));
  2004. }
  2005. break;
  2006. }
  2007. case 0xA520://生产信息
  2008. {
  2009. unchecked
  2010. {
  2011. this.Invoke((EventHandler)(delegate
  2012. {
  2013. //生产商
  2014. textBox_MAC.Text = "";
  2015. for (ushort i = 0; i < 8; i++)
  2016. {
  2017. if (Data[i] == 0x2E)
  2018. {
  2019. break;
  2020. }
  2021. textBox_MAC.Text += ((char)Data[i]).ToString();
  2022. }
  2023. //生产地
  2024. textBox_MACAdd.Text = "";
  2025. for (ushort i = 0; i < 8; i++)
  2026. {
  2027. if (Data[8 + i] == 0x2E)
  2028. {
  2029. break;
  2030. }
  2031. textBox_MACAdd.Text += ((char)Data[8 + i]).ToString();
  2032. }
  2033. //生产日期
  2034. textBox_MACDate.Text = "";
  2035. for (ushort i = 0; i < 8; i++)
  2036. {
  2037. if (Data[16 + i] == 0x2E)
  2038. {
  2039. break;
  2040. }
  2041. textBox_MACDate.Text += ((char)Data[16 + i]).ToString();
  2042. }
  2043. //品牌信息
  2044. textBox_PP.Text = "";
  2045. for (ushort i = 0; i < 8; i++)
  2046. {
  2047. if (Data[24 + i] == 0x2E)
  2048. {
  2049. break;
  2050. }
  2051. textBox_PP.Text += ((char)Data[24 + i]).ToString();
  2052. }
  2053. }));
  2054. }
  2055. break;
  2056. }
  2057. case 0xA408://密钥
  2058. {
  2059. unchecked
  2060. {
  2061. this.Invoke((EventHandler)(delegate
  2062. {
  2063. textBox_Key.Text = "";
  2064. for (ushort i = 0; i < 8; i++)
  2065. {
  2066. textBox_Key.Text += ((char)Data[i]).ToString();
  2067. }
  2068. }));
  2069. }
  2070. break;
  2071. }
  2072. case 0xAB09://存储器数据
  2073. case 0xAB0A:
  2074. case 0xAB0B:
  2075. case 0xAB0C:
  2076. {
  2077. unchecked
  2078. {
  2079. this.Invoke((EventHandler)(delegate
  2080. {
  2081. long ByteNum = 0;
  2082. ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
  2083. if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
  2084. {
  2085. for (int i = 0; i < ByteNum; i++)
  2086. {
  2087. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  2088. }
  2089. }
  2090. else //根据设置自动转换10进制显示
  2091. {
  2092. if (checkBox_ReadRanFlash_ChangeFormat.Checked == true) //10进制显示
  2093. {
  2094. switch (ByteNum)
  2095. {
  2096. case 1:
  2097. {
  2098. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8]) + ", ");
  2099. break;
  2100. }
  2101. case 2:
  2102. {
  2103. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8)) + ", ");
  2104. break;
  2105. }
  2106. case 3:
  2107. {
  2108. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16)) + ", ");
  2109. break;
  2110. }
  2111. case 4:
  2112. {
  2113. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24)) + ", ");
  2114. break;
  2115. }
  2116. default:
  2117. {
  2118. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  2119. break;
  2120. }
  2121. }
  2122. }
  2123. else //16进制显示
  2124. {
  2125. switch (ByteNum)
  2126. {
  2127. case 1:
  2128. {
  2129. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8], 16).PadLeft(2, '0').ToUpper() + ", ");
  2130. break;
  2131. }
  2132. case 2:
  2133. {
  2134. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8), 16).PadLeft(4, '0').ToUpper() + ", ");
  2135. break;
  2136. }
  2137. case 3:
  2138. {
  2139. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16), 16).PadLeft(6, '0').ToUpper() + ", ");
  2140. break;
  2141. }
  2142. case 4:
  2143. {
  2144. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24), 16).PadLeft(8, '0').ToUpper() + ", ");
  2145. break;
  2146. }
  2147. default:
  2148. {
  2149. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  2150. break;
  2151. }
  2152. }
  2153. }
  2154. }
  2155. }));
  2156. }
  2157. break;
  2158. }
  2159. case 0xAB88://故障日志
  2160. {
  2161. unchecked
  2162. {
  2163. this.Invoke((EventHandler)(delegate
  2164. {
  2165. //电机存储的故障日志,一包128字节包含2条故障日志
  2166. var ErrorLogSaveInfo1 = new MC_ErrorLogSaveInfo_Struct_t();
  2167. var ErrorLogSaveInfo2 = new MC_ErrorLogSaveInfo_Struct_t();
  2168. ErrorLogSaveInfo1 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 8);
  2169. ErrorLogSaveInfo2 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 72);
  2170. //数据显示
  2171. ErrorLogDisplay(ErrorLogSaveInfo1, ErrorLogSaveInfo2);
  2172. }));
  2173. }
  2174. break;
  2175. }
  2176. case 0x1401://在线检测结果
  2177. {
  2178. unchecked
  2179. {
  2180. this.Invoke((EventHandler)(delegate
  2181. {
  2182. textBox_Online.Text = Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() + "H";
  2183. }));
  2184. }
  2185. break;
  2186. }
  2187. case 0x1510://骑行历史信息
  2188. {
  2189. unchecked
  2190. {
  2191. this.Invoke((EventHandler)(delegate
  2192. {
  2193. long DataTemp32;
  2194. //ODO里程
  2195. DataTemp32 = (long)((Data[3] << 24) + (Data[2] << 16) + (Data[1] << 8) + Data[0]);
  2196. textBox_OBC_ODO_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  2197. textBox_ODO_KM.Text = DataTemp32.ToString();
  2198. //ODO时间
  2199. DataTemp32 = (long)((Data[7] << 24) + (Data[6] << 16) + (Data[5] << 8) + Data[4]);
  2200. if (DataTemp32 >= 60 * 100000)
  2201. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  2202. else
  2203. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  2204. textBox_ODO_TIME.Text = DataTemp32.ToString();
  2205. //TRIP里程
  2206. DataTemp32 = (long)((Data[11] << 24) + (Data[10] << 16) + (Data[9] << 8) + Data[8]);
  2207. textBox_OBC_TRIP_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  2208. textBox_TRIP_KM.Text = DataTemp32.ToString();
  2209. //TRIP时间
  2210. DataTemp32 = (long)((Data[15] << 24) + (Data[14] << 16) + (Data[13] << 8) + Data[12]);
  2211. if (DataTemp32 >= 60 * 100000)
  2212. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  2213. else
  2214. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  2215. textBox_TRIP_TIME.Text = DataTemp32.ToString();
  2216. }));
  2217. }
  2218. break;
  2219. }
  2220. case 0x1720://客户信息
  2221. {
  2222. unchecked
  2223. {
  2224. this.Invoke((EventHandler)(delegate
  2225. {
  2226. //软件标识
  2227. textBox_SP.Text = "";
  2228. textBox_OBC_ReadSP.Text = "";
  2229. textBox_FacModeSP.Text = "";
  2230. for (ushort i = 0; i < 23; i++)
  2231. {
  2232. if (Data[i] == 'r')
  2233. {
  2234. Data[i] = (byte)'.';
  2235. }
  2236. textBox_SP.Text += ((char)Data[i]).ToString();
  2237. textBox_OBC_ReadSP.Text += ((char)Data[i]).ToString();
  2238. textBox_FacModeSP.Text += ((char)Data[i]).ToString();
  2239. }
  2240. //Git提交版本信息
  2241. textBox_FacModeGit.Text = "";
  2242. for (ushort i = 0; i < 9; i++)
  2243. {
  2244. textBox_SP.Text += ((char)Data[23 + i]).ToString();
  2245. textBox_FacModeGit.Text += ((char)Data[23 + i]).ToString();
  2246. }
  2247. Class_Motor_Ver.Special = textBox_SP.Text;
  2248. }));
  2249. }
  2250. break;
  2251. }
  2252. case 0xBA20: //调试信息
  2253. {
  2254. unchecked
  2255. {
  2256. this.Invoke((EventHandler)(delegate
  2257. {
  2258. MC_DebugInfo_Refresh = true;
  2259. //系统状态机
  2260. DataTemp = (short)(Data[0]);
  2261. textBox_DebugInfo_SysFun.Text = Convert.ToString(DataTemp);
  2262. //二层状态机
  2263. DataTemp = (short)(Data[1]);
  2264. textBox_DebugInfo_SecondFun.Text = Convert.ToString(DataTemp);
  2265. //电机状态机
  2266. DataTemp = (short)(Data[2]);
  2267. textBox_DebugInfo_MotorFun.Text = Convert.ToString(DataTemp);
  2268. //助力状态机
  2269. DataTemp = (short)(Data[3]);
  2270. textBox_DebugInfo_AssistFun.Text = Convert.ToString(DataTemp);
  2271. //IdRef
  2272. DataTemp = (short)(Data[5] * 256 + Data[4]);
  2273. textBox_DebugInfo_IdRef.Text = Convert.ToString(DataTemp);
  2274. //IqRef
  2275. DataTemp = (short)(Data[7] * 256 + Data[6]);
  2276. textBox_DebugInfo_IqRef.Text = Convert.ToString(DataTemp);
  2277. //UdRef
  2278. DataTemp = (short)(Data[9] * 256 + Data[8]);
  2279. textBox_DebugInfo_UdRef.Text = Convert.ToString(DataTemp);
  2280. //UqRef
  2281. DataTemp = (short)(Data[11] * 256 + Data[10]);
  2282. textBox_DebugInfo_UqRef.Text = Convert.ToString(DataTemp);
  2283. //瞬时力矩
  2284. DataTemp = (short)(Data[13] * 256 + Data[12]);
  2285. textBox_DebugInfo_TorquePu.Text = Convert.ToString(DataTemp);
  2286. //时间滤波力矩
  2287. DataTemp = (short)(Data[15] * 256 + Data[14]);
  2288. textBox_DebugInfo_TorqueFil.Text = Convert.ToString(DataTemp);
  2289. //踏频滤波力矩
  2290. DataTemp = (short)(Data[17] * 256 + Data[16]);
  2291. textBox_DebugInfo_TorqueCadence.Text = Convert.ToString(DataTemp);
  2292. //IdFdb
  2293. DataTemp = (short)(Data[19] * 256 + Data[18]);
  2294. textBox_DebugInfo_IdFdb.Text = Convert.ToString(DataTemp);
  2295. //IqFdb
  2296. DataTemp = (short)(Data[21] * 256 + Data[20]);
  2297. textBox_DebugInfo_IqFdb.Text = Convert.ToString(DataTemp);
  2298. //助力输出
  2299. DataTemp = (short)(Data[23] * 256 + Data[22]);
  2300. textBox_DebugInfo_AssistOut.Text = Convert.ToString(DataTemp);
  2301. //转把百分比
  2302. DataTemp = (short)(Data[25] * 256 + Data[24]);
  2303. textBox_DebugInfo_ThrottlePer.Text = Convert.ToString(DataTemp);
  2304. //数据保存
  2305. RunInfoAutoSave();
  2306. }));
  2307. }
  2308. break;
  2309. }
  2310. case 0xBB20: //产品标签信息
  2311. {
  2312. unchecked
  2313. {
  2314. this.Invoke((EventHandler)(delegate
  2315. {
  2316. //产品标签
  2317. textBox_TagInfo.Text = "";
  2318. for (ushort i = 0; i < 32; i++)
  2319. {
  2320. textBox_TagInfo.Text += ((char)Data[i]).ToString();
  2321. }
  2322. }));
  2323. }
  2324. break;
  2325. }
  2326. case 0xBC20: //内阻校正信息
  2327. {
  2328. unchecked
  2329. {
  2330. this.Invoke((EventHandler)(delegate
  2331. {
  2332. //内阻1
  2333. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  2334. textBox_MOS_R1.Text = Convert.ToString(uData16);
  2335. //内阻2
  2336. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  2337. textBox_MOS_R2.Text = Convert.ToString(uData16);
  2338. //内阻3
  2339. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  2340. textBox_MOS_R3.Text = Convert.ToString(uData16);
  2341. //K1
  2342. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  2343. textBox_MOS_K1.Text = Convert.ToString(uData16);
  2344. //K2
  2345. uData16 = (ushort)(Data[9] * 256 + Data[8]);
  2346. textBox_MOS_K2.Text = Convert.ToString(uData16);
  2347. //K3
  2348. uData16 = (ushort)(Data[11] * 256 + Data[10]);
  2349. textBox_MOS_K3.Text = Convert.ToString(uData16);
  2350. //K4
  2351. uData16 = (ushort)(Data[13] * 256 + Data[12]);
  2352. textBox_MOS_K4.Text = Convert.ToString(uData16);
  2353. //K5
  2354. uData16 = (ushort)(Data[15] * 256 + Data[14]);
  2355. textBox_MOS_K5.Text = Convert.ToString(uData16);
  2356. }));
  2357. }
  2358. break;
  2359. }
  2360. case 0xBD20: //整车信息2
  2361. {
  2362. unchecked
  2363. {
  2364. this.Invoke((EventHandler)(delegate
  2365. {
  2366. richTextBox_BikeParam2.Clear();
  2367. for (int i = 0; i < myParams.BikeParam2.Count; i++)
  2368. {
  2369. richTextBox_BikeParam2.AppendText(myParams.BikeParam2[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  2370. }
  2371. richTextBox_BikeParam2.Text = richTextBox_BikeParam2.Text.Substring(0, richTextBox_BikeParam2.Text.Length - 2);
  2372. }));
  2373. }
  2374. break;
  2375. }
  2376. case 0xBE20: //用户骑行参数
  2377. {
  2378. unchecked
  2379. {
  2380. this.Invoke((EventHandler)(delegate
  2381. {
  2382. richTextBox_UsrRidesParam.Clear();
  2383. for (int i = 0; i < myParams.UsrRideParam.Count; i++)
  2384. {
  2385. richTextBox_UsrRidesParam.AppendText(myParams.UsrRideParam[i] + "=" + Convert.ToString(Data[i]) + ", ");
  2386. }
  2387. richTextBox_UsrRidesParam.Text = richTextBox_UsrRidesParam.Text.Substring(0, richTextBox_UsrRidesParam.Text.Length - 2);
  2388. }));
  2389. }
  2390. break;
  2391. }
  2392. case 0xBF58: //位置传感器校准值
  2393. {
  2394. unchecked
  2395. {
  2396. this.Invoke((EventHandler)(delegate
  2397. {
  2398. string[] str1 = new string[42];
  2399. double[] error1 = new double[42];
  2400. //更新校准数据
  2401. for (int i = 0; i < 42; i++)
  2402. {
  2403. double data1 = (Data[4 + i * 2] + (Data[4 + i * 2 + 1] << 8)) / 32767.0 * 360;
  2404. error1[i] = data1 - (60 * (i % 6) + 60);
  2405. if (error1[i] < -180)
  2406. {
  2407. error1[i] = error1[i] + 360;
  2408. }
  2409. str1[i] = data1.ToString("F2");
  2410. AngledataRecord[i] = str1[i];
  2411. }
  2412. for (int i = 0; i < 7; i++)
  2413. for (int j = 0; j < 6; j++)
  2414. {
  2415. dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = str1[6 * i + j];
  2416. }
  2417. //计算偏差最小值、最大值和平均值
  2418. //Array.ConvertAll(error1, Math.Abs);
  2419. textBox_AngleDiffMin.Text = error1.Min().ToString("F2");
  2420. textBox_AngleDiffMax.Text = error1.Max().ToString("F2");
  2421. textBox_AngleDiffAvg.Text = error1.Average().ToString("F2");
  2422. //计算零点偏差
  2423. double tmp1 = ((Int16)(Data[0] + (Data[1] << 8))) / 32767.0 * 360;
  2424. textBox_AngleZeroInit.Text = tmp1.ToString("F2");
  2425. double tmp2 = ((Int16)(Data[2] + (Data[3] << 8))) / 32767.0 * 360;
  2426. textBox_AngleZeroCur.Text = tmp2.ToString("F2");
  2427. double tmp3 = (tmp2 - tmp1);
  2428. textBox_AngleZeroDiff.Text = tmp3.ToString("F2");
  2429. }));
  2430. }
  2431. break;
  2432. }
  2433. case 0xC008: //故障日志地址
  2434. {
  2435. unchecked
  2436. {
  2437. this.Invoke((EventHandler)(delegate
  2438. {
  2439. uint Addr_Begin = 0, Addr_End = 0;
  2440. Addr_Begin = (uint)((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]);
  2441. Addr_End = (uint)((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]);
  2442. textBox_LogAddrBegin.Text = Convert.ToString(Addr_Begin, 16).PadLeft(8, '0').ToUpper();
  2443. textBox_LogAddrEnd.Text = Convert.ToString(Addr_End, 16).PadLeft(8, '0').ToUpper();
  2444. }));
  2445. }
  2446. break;
  2447. }
  2448. case 0xC109: //Boot版本信息
  2449. {
  2450. BootInfo = "";
  2451. for (ushort i = 0; i < 9; i++)
  2452. {
  2453. BootInfo += ((char)Data[i]).ToString();
  2454. }
  2455. break;
  2456. }
  2457. case 0xC142: //功能配置表
  2458. {
  2459. unchecked
  2460. {
  2461. this.Invoke((EventHandler)(delegate
  2462. {
  2463. //块编号
  2464. ushort Num = (ushort)(Data[1] * 256 + Data[0]);
  2465. comboBox_FunSet_BlockNum.SelectedIndex = Num - 1;
  2466. //显示数据
  2467. for (int i = 0; i < 64; i++)
  2468. {
  2469. dataGridView_FunSet.Rows[i / 8].Cells[i % 8 + 1].Value = Data[i + 2].ToString();
  2470. }
  2471. }));
  2472. }
  2473. break;
  2474. }
  2475. case 0xC220: //定制编号
  2476. {
  2477. unchecked
  2478. {
  2479. this.Invoke((EventHandler)(delegate
  2480. {
  2481. //定制编号
  2482. textBox_UserNum.Text = "";
  2483. for (ushort i = 0; i < 32; i++)
  2484. {
  2485. textBox_UserNum.Text += ((char)Data[i]).ToString();
  2486. }
  2487. }));
  2488. }
  2489. break;
  2490. }
  2491. default:
  2492. {
  2493. break;
  2494. }
  2495. }
  2496. //存储器导出数据显示
  2497. if ((CmdTemp & 0xFF00) == 0xAB00)
  2498. {
  2499. unchecked
  2500. {
  2501. this.Invoke((EventHandler)(delegate
  2502. {
  2503. long ByteNum = 0;
  2504. ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
  2505. if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
  2506. {
  2507. for (int i = 0; i < ByteNum; i++)
  2508. {
  2509. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  2510. }
  2511. }
  2512. }));
  2513. }
  2514. }
  2515. }
  2516. #endregion
  2517. #region 解析BMS广播的命令
  2518. else if (ID == 0x720)
  2519. {
  2520. switch (CmdTemp)
  2521. {
  2522. case 0x1010://BMS运行信息
  2523. {
  2524. unchecked
  2525. {
  2526. this.Invoke((EventHandler)(delegate
  2527. {
  2528. BMS_RunInfo_Refresh = true;
  2529. richTextBox_OBC_BMS_RunInfo.Clear();
  2530. //电压
  2531. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  2532. richTextBox_OBC_BMS_RunInfo.AppendText("电压:" + Convert.ToString(uData16) + " mV" + "\r\n");
  2533. //电流
  2534. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  2535. richTextBox_OBC_BMS_RunInfo.AppendText("电流:" + Convert.ToString(uData16) + " mA" + "\r\n");
  2536. //剩余容量
  2537. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  2538. richTextBox_OBC_BMS_RunInfo.AppendText("剩余容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  2539. //满充容量
  2540. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  2541. richTextBox_OBC_BMS_RunInfo.AppendText("满充容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  2542. //电芯温度
  2543. richTextBox_OBC_BMS_RunInfo.AppendText("电芯温度:" + Convert.ToString((int)(Data[8] - 40) + " ℃" + "\r\n"));
  2544. //剩余电量
  2545. richTextBox_OBC_BMS_RunInfo.AppendText("剩余电量:" + Convert.ToString(Data[9]) + " %" + "\r\n");
  2546. //电池状态
  2547. richTextBox_OBC_BMS_RunInfo.AppendText("电池状态:" + Convert.ToString(Data[10], 16).PadLeft(2, '0').ToUpper() + " H" + "\r\n");
  2548. //SOH
  2549. richTextBox_OBC_BMS_RunInfo.AppendText("电池寿命:" + Convert.ToString(Data[11]) + " %" + "\r\n");
  2550. //循环次数
  2551. richTextBox_OBC_BMS_RunInfo.AppendText("循环次数:" + Convert.ToString((ushort)(Data[13] * 256 + Data[12])) + " 次");
  2552. }));
  2553. }
  2554. break;
  2555. }
  2556. default: break;
  2557. }
  2558. }
  2559. #endregion
  2560. #region 解析电机发送OBC的命令
  2561. else if (ID == 0x713)
  2562. {
  2563. switch (CmdTemp)
  2564. {
  2565. case 0x5408://电机用户参数
  2566. {
  2567. unchecked
  2568. {
  2569. this.Invoke((EventHandler)(delegate
  2570. {
  2571. richTextBox_OBC_ReadUserInfo.Clear();
  2572. //默认周长
  2573. richTextBox_OBC_ReadUserInfo.AppendText("默认周长:" + Convert.ToString((int)Data[0]) + " cm" + "\r\n");
  2574. //启动模式
  2575. richTextBox_OBC_ReadUserInfo.AppendText("启动模式:" + ((Data[1] == 0x01) ? "柔和" : (Data[1] == 0x02) ? "正常" : (Data[1] == 0x03) ? "强劲" : "无效") + "\r\n");
  2576. comboBox_OBC_StartMode.SelectedIndex = Data[1] - 1;
  2577. //限速
  2578. richTextBox_OBC_ReadUserInfo.AppendText("限速:" + Convert.ToString(Data[2]) + " km/h" + "\r\n");
  2579. //周长微调
  2580. numericUpDown_OBC_WheelAdj.Value = (int)(Data[3] > 128 ? (Data[3] - 256) : Data[3]);
  2581. richTextBox_OBC_ReadUserInfo.AppendText("周长微调:" + Convert.ToString(numericUpDown_OBC_WheelAdj.Value) + " cm" + "\r\n");
  2582. //助力方案
  2583. richTextBox_OBC_ReadUserInfo.AppendText("助力方案:" + Convert.ToString(Data[4]) + "\r\n");
  2584. comboBox_OBC_AssistFunc.SelectedIndex = Data[4] - 1;
  2585. //关机时间
  2586. richTextBox_OBC_ReadUserInfo.AppendText("关机时间:" + Convert.ToString(Data[5]) + " min" + "\r\n");
  2587. numericUpDown_OBC_OffTime.Value = (int)Data[5];
  2588. //限速微调
  2589. numericUpDown_OBC_SpeedLimitAdj.Value = (int)(Data[6] > 128 ? (Data[6] - 256) : Data[6]);
  2590. richTextBox_OBC_ReadUserInfo.AppendText("限速微调:" + Convert.ToString(numericUpDown_OBC_SpeedLimitAdj.Value) + " km/h" + "\r\n");
  2591. //定速巡航
  2592. comboBox_OBC_BikeCCS.SelectedIndex = (Data[7] == 0xAA) ? 1 : 2;
  2593. richTextBox_OBC_ReadUserInfo.AppendText("转把巡航:" + comboBox_OBC_BikeCCS.Text + "\r\n");
  2594. }));
  2595. }
  2596. break;
  2597. }
  2598. case 0x5303://电机应答反馈
  2599. {
  2600. unchecked
  2601. {
  2602. this.Invoke((EventHandler)(delegate
  2603. {
  2604. MessageBoxTimeOut.Show("OK", "反馈指令", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  2605. }));
  2606. }
  2607. break;
  2608. }
  2609. case 0x5620: //用户骑行参数
  2610. {
  2611. unchecked
  2612. {
  2613. this.Invoke((EventHandler)(delegate
  2614. {
  2615. richTextBox_UsrRidesParam.Clear();
  2616. for (int i = 0; i < myParams.UsrRideParam.Count; i++)
  2617. {
  2618. richTextBox_UsrRidesParam.AppendText(myParams.UsrRideParam[i] + "=" + Convert.ToString(Data[i]) + ", ");
  2619. }
  2620. richTextBox_UsrRidesParam.Text = richTextBox_UsrRidesParam.Text.Substring(0, richTextBox_UsrRidesParam.Text.Length - 2);
  2621. }));
  2622. }
  2623. break;
  2624. }
  2625. default: break;
  2626. }
  2627. }
  2628. #endregion
  2629. }
  2630. private void DataRevToString(ushort CmdTemp, byte[] Data)
  2631. {
  2632. CmdRevStrTemp = "";
  2633. CmdRevStrTemp += Convert.ToString(CmdTemp >> 8, 16).PadLeft(2, '0').ToUpper() + " ";
  2634. CmdRevStrTemp += Convert.ToString(CmdTemp & 0xFF, 16).PadLeft(2, '0').ToUpper() + " ";
  2635. ushort len = (ushort)(CmdTemp & 0x00FF);
  2636. for (int i = 0; i < len ; i++)
  2637. {
  2638. CmdRevStrTemp += Convert.ToString(Data[i], 16).PadLeft(2, '0').ToUpper() + " ";
  2639. }
  2640. }
  2641. #endregion
  2642. /// <summary>
  2643. /// 端口连接或断开
  2644. /// </summary>
  2645. private void PortConnect()
  2646. {
  2647. bool result = false;
  2648. if (连接ToolStripMenuItem.Text == "连接")
  2649. {
  2650. result = mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, 连接开机ToolStripMenuItem.Checked, 识别通讯盒ToolStripMenuItem.Checked);
  2651. if (result)
  2652. {
  2653. toolStripComboBox_ComNum.Enabled = false;
  2654. toolStripComboBox_Baudrate.Enabled = false;
  2655. 刷新ToolStripMenuItem.Enabled = false;
  2656. 连接ToolStripMenuItem.Text = "断开";
  2657. 连接ToolStripMenuItem.Checked = true;
  2658. label_COM_Sta.Text = toolStripComboBox_ComNum.Text + "已连接," + toolStripComboBox_Baudrate.Text;
  2659. label_PortStatus.BackColor = Color.Green;
  2660. }
  2661. }
  2662. else if (连接ToolStripMenuItem.Text == "断开")
  2663. {
  2664. checkBox_OBC_StartSetGearSt.Checked = false;
  2665. checkBox_OBC_StartReadBMS.Checked = false;
  2666. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2667. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  2668. toolStripComboBox_ComNum.Enabled = true;
  2669. toolStripComboBox_Baudrate.Enabled = true;
  2670. 刷新ToolStripMenuItem.Enabled = true;
  2671. 连接ToolStripMenuItem.Text = "连接";
  2672. 连接ToolStripMenuItem.Checked = false;
  2673. label_COM_Sta.Text = "连接状态:未连接";
  2674. label_PortStatus.BackColor = Color.Red;
  2675. }
  2676. }
  2677. /// <summary>
  2678. /// 端口连接事件
  2679. /// </summary>
  2680. /// <param name="sender"></param>
  2681. /// <param name="e"></param>
  2682. private void 连接ToolStripMenuItem_Click(object sender, System.EventArgs e)
  2683. {
  2684. PortConnect();
  2685. }
  2686. /// <summary>
  2687. /// 端口号刷新事件
  2688. /// </summary>
  2689. /// <param name="sender"></param>
  2690. /// <param name="e"></param>
  2691. private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
  2692. {
  2693. toolStripComboBox_ComNum.Items.Clear();
  2694. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  2695. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
  2696. }
  2697. /// <summary>
  2698. /// 存储标志修改事件
  2699. /// </summary>
  2700. /// <param name="sender"></param>
  2701. /// <param name="e"></param>
  2702. private void 写入存储ToolStripMenuItem_Click(object sender, EventArgs e)
  2703. {
  2704. if (写入存储ToolStripMenuItem.Checked)
  2705. {
  2706. EnterForm1.ShowDialog();
  2707. try
  2708. {
  2709. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  2710. {
  2711. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  2712. {
  2713. 写入存储ToolStripMenuItem.Checked = false;
  2714. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  2715. }
  2716. else
  2717. {
  2718. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2719. }
  2720. }
  2721. else
  2722. {
  2723. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2724. }
  2725. }
  2726. catch (Exception)
  2727. {
  2728. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2729. }
  2730. }
  2731. else
  2732. {
  2733. 写入存储ToolStripMenuItem.Checked = true;
  2734. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  2735. }
  2736. }
  2737. /// <summary>
  2738. /// 1s定时器
  2739. /// </summary>
  2740. /// <param name="sender"></param>
  2741. /// <param name="e"></param>
  2742. private void timer_1s_Tick(object sender, EventArgs e)
  2743. {
  2744. //时间更新
  2745. label_SystemTime.Text = "系统时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2746. //MC_Runinfo超时清除
  2747. if (MC_RunInfo_Refresh == false)
  2748. {
  2749. MC_RunInfo_Refresh_Cnt++;
  2750. if (MC_RunInfo_Refresh_Cnt > 10)//5s
  2751. {
  2752. MC_RunInfo_Clear();
  2753. MC_RunInfo_Refresh_Cnt = 0;
  2754. }
  2755. }
  2756. else
  2757. {
  2758. MC_RunInfo_Refresh_Cnt = 0;
  2759. }
  2760. MC_RunInfo_Refresh = false;
  2761. //MC_Debuginfo超时清除
  2762. if (MC_DebugInfo_Refresh == false)
  2763. {
  2764. MC_DebugInfo_Refresh_Cnt++;
  2765. if (MC_DebugInfo_Refresh_Cnt > 10)//5s
  2766. {
  2767. MC_DebugInfo_Clear();
  2768. MC_DebugInfo_Refresh_Cnt = 0;
  2769. }
  2770. }
  2771. else
  2772. {
  2773. MC_DebugInfo_Refresh_Cnt = 0;
  2774. }
  2775. MC_DebugInfo_Refresh = false;
  2776. //BMS_RunInfo超时清除
  2777. if (BMS_RunInfo_Refresh == false)
  2778. {
  2779. BMS_RunInfo_Refresh_Cnt++;
  2780. if (BMS_RunInfo_Refresh_Cnt > 10)//5s
  2781. {
  2782. richTextBox_OBC_BMS_RunInfo.Clear();
  2783. BMS_RunInfo_Refresh_Cnt = 0;
  2784. }
  2785. }
  2786. else
  2787. {
  2788. BMS_RunInfo_Refresh_Cnt = 0;
  2789. }
  2790. BMS_RunInfo_Refresh = false;
  2791. //故障码超时清除
  2792. if (MC_ErrorCode_Refresh == false)
  2793. {
  2794. MC_ErrorCode_Refresh_Cnt++;
  2795. if (MC_ErrorCode_Refresh_Cnt > 10)//5s
  2796. {
  2797. textBox_ErrorCode.Text = "---";
  2798. MC_ErrorCode_Refresh_Cnt = 0;
  2799. }
  2800. }
  2801. else
  2802. {
  2803. MC_ErrorCode_Refresh_Cnt = 0;
  2804. }
  2805. MC_ErrorCode_Refresh = false;
  2806. //CDL连接超时
  2807. if (识别通讯盒ToolStripMenuItem.Checked)
  2808. {
  2809. if (mySerialProcess.CDL_Online_Flag == false)
  2810. {
  2811. mySerialProcess.CDL_OnlineCheck_Cnt++;
  2812. if (mySerialProcess.CDL_OnlineCheck_Cnt > 1)//1s
  2813. {
  2814. timer_500ms.Enabled = false;
  2815. MessageBox.Show("连接失败!", "提示");
  2816. timer_500ms.Enabled = true;
  2817. //关闭串口
  2818. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  2819. toolStripComboBox_ComNum.Enabled = true;
  2820. toolStripComboBox_Baudrate.Enabled = true;
  2821. 刷新ToolStripMenuItem.Enabled = true;
  2822. 连接ToolStripMenuItem.Text = "连接";
  2823. 连接ToolStripMenuItem.Checked = false;
  2824. label_COM_Sta.Text = "连接状态:未连接";
  2825. label_PortStatus.BackColor = Color.Red;
  2826. }
  2827. }
  2828. }
  2829. //OBC定时发送设置档位
  2830. if (checkBox_OBC_StartSetGearSt.Checked == true)
  2831. {
  2832. var CtrlCode = new byte[2];
  2833. if (comboBox_OBC_SetGearST.SelectedIndex == 5)//档位
  2834. CtrlCode[0] = 0x33;
  2835. else if (comboBox_OBC_SetGearST.SelectedIndex == 6)//档位
  2836. CtrlCode[0] = 0x22;
  2837. else
  2838. CtrlCode[0] = (byte)comboBox_OBC_SetGearST.SelectedIndex;
  2839. if (comboBox_OBC_LightSw.SelectedIndex == 0)//车灯
  2840. CtrlCode[1] = 0xF1;
  2841. else
  2842. CtrlCode[1] = 0xF0;
  2843. if (!mySerialProcess.SendCmdWithoutNotice((ushort)0x731, (byte)0x0C, (ushort)0x3002, CtrlCode))
  2844. {
  2845. checkBox_OBC_StartSetGearSt.Checked = false;
  2846. }
  2847. }
  2848. //OBC定时发送查询电池
  2849. if (checkBox_OBC_StartReadBMS.Checked == true)
  2850. {
  2851. if (!mySerialProcess.SendCmd((ushort)0x732, (byte)0x11, (ushort)0x5000, null))
  2852. {
  2853. checkBox_OBC_StartReadBMS.Checked = false;
  2854. }
  2855. }
  2856. //定时读取存储器
  2857. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  2858. {
  2859. var Address = new byte[4];
  2860. UInt32 Address_Begin;
  2861. UInt32 Addres_End;
  2862. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  2863. richTextBox_RamFlasgData.Clear();
  2864. do
  2865. {
  2866. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  2867. {
  2868. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2869. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2870. continue;
  2871. }
  2872. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  2873. {
  2874. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2875. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2876. continue;
  2877. }
  2878. else
  2879. {
  2880. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  2881. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2882. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  2883. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2884. if (Addres_End < Address_Begin)
  2885. {
  2886. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2887. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2888. continue;
  2889. }
  2890. else
  2891. {
  2892. var SendByte = new byte[8];
  2893. SendByte[0] = (byte)(Address_Begin >> 24);
  2894. SendByte[1] = (byte)(Address_Begin >> 16);
  2895. SendByte[2] = (byte)(Address_Begin >> 8);
  2896. SendByte[3] = (byte)(Address_Begin);
  2897. SendByte[4] = (byte)(Addres_End >> 24);
  2898. SendByte[5] = (byte)(Addres_End >> 16);
  2899. SendByte[6] = (byte)(Addres_End >> 8);
  2900. SendByte[7] = (byte)(Addres_End);
  2901. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte))
  2902. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2903. }
  2904. }
  2905. } while (false);
  2906. }
  2907. }
  2908. /// <summary>
  2909. /// 运行信息清除
  2910. /// </summary>
  2911. private void MC_RunInfo_Clear()
  2912. {
  2913. foreach (Control c in tabPage_RunInfo.Controls)
  2914. {
  2915. if ((c is TextBox))
  2916. {
  2917. if (c.Name != textBox_ErrorCode.ToString())
  2918. c.Text = "---";
  2919. }
  2920. }
  2921. }
  2922. /// <summary>
  2923. /// 调试信息清除
  2924. /// </summary>
  2925. private void MC_DebugInfo_Clear()
  2926. {
  2927. foreach (Control c in tabPage_DebugInfo.Controls)
  2928. {
  2929. if ((c is TextBox))
  2930. {
  2931. if (c.Name != textBox_ErrorCode.ToString())
  2932. c.Text = "---";
  2933. }
  2934. }
  2935. }
  2936. /// <summary>
  2937. /// 读取马达参数
  2938. /// </summary>
  2939. /// <param name="sender"></param>
  2940. /// <param name="e"></param>
  2941. private void button_Read_MotorParam_Click(object sender, EventArgs e)
  2942. {
  2943. richTextBox_MotorParam.Clear();
  2944. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null);
  2945. }
  2946. /// <summary>
  2947. /// 写入马达参数
  2948. /// </summary>
  2949. /// <param name="sender"></param>
  2950. /// <param name="e"></param>
  2951. private void button_Write_Click(object sender, EventArgs e)
  2952. {
  2953. var ConfigParam = new byte[40];
  2954. for (int i = 0; i < 40; i++)
  2955. ConfigParam[i] = 0;
  2956. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2957. short wDataTemp = 0;
  2958. ushort DataTemp = 0;
  2959. string[] strDataTemp = richTextBox_MotorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2960. try
  2961. {
  2962. for (int i = 0; i < strDataTemp.Length; i++)
  2963. {
  2964. if (i == 6)
  2965. {
  2966. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  2967. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  2968. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  2969. }
  2970. else
  2971. {
  2972. DataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2973. ConfigParam[2 * i + 2] = (byte)DataTemp;
  2974. ConfigParam[2 * i + 3] = (byte)(DataTemp >> 8);
  2975. }
  2976. }
  2977. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B28, ConfigParam);
  2978. }
  2979. catch (Exception)
  2980. {
  2981. timer_500ms.Enabled = false;
  2982. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2983. timer_500ms.Enabled = true;
  2984. }
  2985. }
  2986. /// <summary>
  2987. /// 读取整车信息
  2988. /// </summary>
  2989. /// <param name="sender"></param>
  2990. /// <param name="e"></param>
  2991. private void button_ReadBikeParam_Click(object sender, EventArgs e)
  2992. {
  2993. richTextBox_BikeParam.Clear();
  2994. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null);
  2995. }
  2996. /// <summary>
  2997. /// 写入整车信息
  2998. /// </summary>
  2999. /// <param name="sender"></param>
  3000. /// <param name="e"></param>
  3001. private void button_WriteBikeParam_Click(object sender, EventArgs e)
  3002. {
  3003. var ConfigParam = new byte[28];
  3004. for (int i = 0; i < 28; i++)
  3005. ConfigParam[i] = 0;
  3006. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  3007. string[] strDataTemp = richTextBox_BikeParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  3008. try
  3009. {
  3010. for (int i = 0; i < strDataTemp.Length; i++)
  3011. {
  3012. short wDataTemp = 0;
  3013. //前后灯参数修改
  3014. if (i == 8)
  3015. {
  3016. wDataTemp |= (short)((comboBox_TailLightMode.SelectedIndex + 1) << 12); //Bit15~Bit12:尾灯模式
  3017. wDataTemp |= (short)((comboBox_TailLightVol.SelectedIndex == 0 ? 6 : 12) << 8); //Bit11~Bit8:尾灯电压
  3018. wDataTemp |= (short)(comboBox_FrontLightVol.SelectedIndex == 0 ? 6 : 12); //Bit7~Bit0:前灯电压
  3019. }
  3020. //开关机参数
  3021. else if (i == 11)
  3022. {
  3023. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOnDelay.Text) << 12);
  3024. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOffDelay.Text) << 8);
  3025. wDataTemp |= (short)(Convert.ToInt16(textBox_AutoPowerOff.Text));
  3026. }
  3027. else
  3028. {
  3029. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  3030. }
  3031. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  3032. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  3033. }
  3034. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D1C, ConfigParam);
  3035. }
  3036. catch (Exception)
  3037. {
  3038. timer_500ms.Enabled = false;
  3039. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3040. timer_500ms.Enabled = true;
  3041. }
  3042. }
  3043. /// <summary>
  3044. /// 读取控制器参数
  3045. /// </summary>
  3046. /// <param name="sender"></param>
  3047. /// <param name="e"></param>
  3048. private void button_ReadControlParam_Click(object sender, EventArgs e)
  3049. {
  3050. richTextBox_ControlParam.Clear();
  3051. comboBox_Bike_CCS.SelectedIndex = 0;
  3052. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
  3053. }
  3054. /// <summary>
  3055. /// 写入控制器参数
  3056. /// </summary>
  3057. /// <param name="sender"></param>
  3058. /// <param name="e"></param>
  3059. private void button_WriteControlParam_Click(object sender, EventArgs e)
  3060. {
  3061. var ConfigParam = new byte[34];
  3062. for (int i = 0; i < 34; i++)
  3063. ConfigParam[i] = 0;
  3064. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  3065. ushort uwDataTemp = 0;
  3066. string[] strDataTemp = richTextBox_ControlParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  3067. try
  3068. {
  3069. for (int i = 0; i < strDataTemp.Length; i++)
  3070. {
  3071. if (i == 13)
  3072. {
  3073. uwDataTemp = (comboBox_Bike_CCS.SelectedIndex == 1) ? (ushort)0x00AA : (ushort)0x0000;
  3074. }
  3075. else
  3076. {
  3077. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  3078. }
  3079. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3080. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3081. }
  3082. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3F22, ConfigParam);
  3083. }
  3084. catch (Exception)
  3085. {
  3086. timer_500ms.Enabled = false;
  3087. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3088. timer_500ms.Enabled = true;
  3089. }
  3090. }
  3091. /// <summary>
  3092. /// 读取助力参数
  3093. /// </summary>
  3094. /// <param name="sender"></param>
  3095. /// <param name="e"></param>
  3096. private void button_ReadAssistParam_Click(object sender, EventArgs e)
  3097. {
  3098. var ConfigParam = new byte[4];
  3099. int AssistNum = 0;
  3100. try
  3101. {
  3102. AssistNum = Convert.ToInt32(comboBox_AssistTorque.Text);
  3103. ConfigParam[0] = (byte)(AssistNum & 0xFF);
  3104. ConfigParam[1] = (byte)(AssistNum >> 8);
  3105. AssistNum = Convert.ToInt32(comboBox_AssistCadence.Text);
  3106. ConfigParam[2] = (byte)(AssistNum & 0xFF);
  3107. ConfigParam[3] = (byte)(AssistNum >> 8);
  3108. richTextBox_AssistParam.Clear();
  3109. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam);
  3110. }
  3111. catch (Exception)
  3112. {
  3113. timer_500ms.Enabled = false;
  3114. MessageBox.Show("请选择助力参数编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3115. timer_500ms.Enabled = true;
  3116. }
  3117. }
  3118. /// <summary>
  3119. /// 写入助力参数
  3120. /// </summary>
  3121. /// <param name="sender"></param>
  3122. /// <param name="e"></param>
  3123. private void button_WriteAssistParam_Click(object sender, EventArgs e)
  3124. {
  3125. var ConfigParam = new byte[80];
  3126. for (int i = 0; i < 80; i++)
  3127. ConfigParam[i] = 0;
  3128. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  3129. long lDataTemp = 0;
  3130. string[] strDataTemp = richTextBox_AssistParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  3131. int index_1 = 0, index_2 = 0;
  3132. try
  3133. {
  3134. for (int i = 0; i < strDataTemp.Length; i++)
  3135. {
  3136. if (strDataTemp[i].Split('=')[0] == "转矩曲线.a")
  3137. {
  3138. index_1 = i;
  3139. break;
  3140. }
  3141. }
  3142. for (int i = 0; i < strDataTemp.Length; i++)
  3143. {
  3144. if (strDataTemp[i].Split('=')[0] == "踏频曲线.d")
  3145. {
  3146. index_2 = i;
  3147. break;
  3148. }
  3149. }
  3150. for (int i = 0; i < strDataTemp.Length; i++)
  3151. {
  3152. lDataTemp = Convert.ToInt32(strDataTemp[i].Split('=')[1]);
  3153. if (i < index_1)
  3154. {
  3155. ConfigParam[2 * i + 4] = (byte)lDataTemp;
  3156. ConfigParam[2 * i + 5] = (byte)(lDataTemp >> 8);
  3157. }
  3158. else if (i <= index_2)
  3159. {
  3160. ConfigParam[4 * i - 4] = (byte)lDataTemp;
  3161. ConfigParam[4 * i - 3] = (byte)(lDataTemp >> 8);
  3162. ConfigParam[4 * i - 2] = (byte)(lDataTemp >> 16);
  3163. ConfigParam[4 * i - 1] = (byte)(lDataTemp >> 24);
  3164. }
  3165. else
  3166. {
  3167. ConfigParam[2 * i + 20] = (byte)lDataTemp;
  3168. ConfigParam[2 * i + 21] = (byte)(lDataTemp >> 8);
  3169. }
  3170. }
  3171. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4450, ConfigParam);
  3172. }
  3173. catch (Exception)
  3174. {
  3175. timer_500ms.Enabled = false;
  3176. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3177. timer_500ms.Enabled = true;
  3178. }
  3179. }
  3180. /// <summary>
  3181. /// 读取调试参数
  3182. /// </summary>
  3183. /// <param name="sender"></param>
  3184. /// <param name="e"></param>
  3185. private void button_ReadDebugParam_Click(object sender, EventArgs e)
  3186. {
  3187. richTextBox_DebugParam.Clear();
  3188. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  3189. }
  3190. /// <summary>
  3191. /// 写入调试参数
  3192. /// </summary>
  3193. /// <param name="sender"></param>
  3194. /// <param name="e"></param>
  3195. private void button_WriteDebugParam_Click(object sender, EventArgs e)
  3196. {
  3197. var ConfigParam = new byte[60];
  3198. for (int i = 0; i < 60; i++)
  3199. ConfigParam[i] = 0;
  3200. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  3201. ushort uwDataTemp = 0;
  3202. string[] strDataTemp = richTextBox_DebugParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  3203. try
  3204. {
  3205. for (int i = 0; i < strDataTemp.Length; i++)
  3206. {
  3207. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  3208. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3209. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3210. }
  3211. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam);
  3212. }
  3213. catch (Exception)
  3214. {
  3215. timer_500ms.Enabled = false;
  3216. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3217. timer_500ms.Enabled = true;
  3218. }
  3219. }
  3220. /// <summary>
  3221. /// 读取历史
  3222. /// </summary>
  3223. /// <param name="sender"></param>
  3224. /// <param name="e"></param>
  3225. private void button_ReadRecord_Click(object sender, EventArgs e)
  3226. {
  3227. richTextBox_Record.Clear();
  3228. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null);
  3229. }
  3230. /// <summary>
  3231. /// 读取传感器参数
  3232. /// </summary>
  3233. /// <param name="sender"></param>
  3234. /// <param name="e"></param>
  3235. private void button_ReadSensorParam_Click(object sender, EventArgs e)
  3236. {
  3237. richTextBox_SensorParam.Clear();
  3238. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3239. }
  3240. /// <summary>
  3241. /// 写入力矩传感器标定值
  3242. /// </summary>
  3243. /// <param name="sender"></param>
  3244. /// <param name="e"></param>
  3245. private void button_Write_Cal_Click(object sender, EventArgs e)
  3246. {
  3247. var ConfigParam = new byte[4];
  3248. for (int i = 0; i < 4; i++)
  3249. ConfigParam[i] = 0;
  3250. ushort uwDataTemp = 0;
  3251. try
  3252. {
  3253. uwDataTemp = Convert.ToUInt16(comboBox_TorqueSet.Text);//负载序号
  3254. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  3255. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  3256. uwDataTemp = (ushort)(decimal.Parse(textBox_Load.Text) * 10); ;//负载值0.1Nm
  3257. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  3258. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  3259. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  3260. }
  3261. catch (Exception)
  3262. {
  3263. timer_500ms.Enabled = false;
  3264. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3265. timer_500ms.Enabled = true;
  3266. }
  3267. }
  3268. /// <summary>
  3269. /// 写入传感器参数
  3270. /// </summary>
  3271. /// <param name="sender"></param>
  3272. /// <param name="e"></param>
  3273. private void button_WriteSensorParam_Click(object sender, EventArgs e)
  3274. {
  3275. var ConfigParam = new byte[14];
  3276. for (int i = 0; i < 14; i++)
  3277. ConfigParam[i] = 0;
  3278. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  3279. ushort uwDataTemp = 0;
  3280. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  3281. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  3282. int index = 0;
  3283. try
  3284. {
  3285. for (int i = 0; i < strDataTemp.Length; i++)
  3286. {
  3287. if (strDataTemp[i].Split('=')[0] == "力矩传感器踏频脉冲数")
  3288. {
  3289. index = i;
  3290. break;
  3291. }
  3292. }
  3293. for (int i = 0; i < (strDataTemp.Length - index); i++)
  3294. {
  3295. uwDataTemp = Convert.ToUInt16(strDataTemp[i + index].Split('=')[1]);
  3296. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3297. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3298. }
  3299. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x420E, ConfigParam);
  3300. }
  3301. catch (Exception)
  3302. {
  3303. timer_500ms.Enabled = false;
  3304. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3305. timer_500ms.Enabled = true;
  3306. }
  3307. }
  3308. /// <summary>
  3309. /// 写入型号
  3310. /// </summary>
  3311. /// <param name="sender"></param>
  3312. /// <param name="e"></param>
  3313. private void button_WriteModel_Click(object sender, EventArgs e)
  3314. {
  3315. string Mode = textBox_Model.Text;
  3316. var ModeArray = new byte[16];
  3317. for (ushort i = 0; i < Mode.Length; i++)
  3318. {
  3319. ModeArray[i] = (byte)Mode[i];
  3320. }
  3321. if (Mode.Length < 16)
  3322. {
  3323. ModeArray[Mode.Length] = (byte)'.';
  3324. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  3325. {
  3326. ModeArray[Mode.Length + 1 + i] = 0x20;
  3327. }
  3328. }
  3329. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  3330. }
  3331. /// <summary>
  3332. /// 写入SN
  3333. /// </summary>
  3334. /// <param name="sender"></param>
  3335. /// <param name="e"></param>
  3336. private void button_WriteSN_Click(object sender, EventArgs e)
  3337. {
  3338. string SN = textBox_SN.Text;
  3339. var SNArray = new byte[16];
  3340. for (ushort i = 0; i < SN.Length; i++)
  3341. {
  3342. SNArray[i] = (byte)SN[i];
  3343. }
  3344. if (SN.Length < 16)
  3345. {
  3346. SNArray[SN.Length] = (byte)'.';
  3347. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  3348. {
  3349. SNArray[SN.Length + 1 + i] = 0x20;
  3350. }
  3351. }
  3352. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  3353. }
  3354. /// <summary>
  3355. /// 查询版本信息
  3356. /// </summary>
  3357. /// <param name="sender"></param>
  3358. /// <param name="e"></param>
  3359. private void button_ReadVersion_Click(object sender, EventArgs e)
  3360. {
  3361. textBox_Model.Text = "---";
  3362. textBox_SN.Text = "---";
  3363. textBox_HW.Text = "---";
  3364. textBox_FW.Text = "---";
  3365. textBox_SP.Text = "---";
  3366. textBox_OBC_ReadModel.Text = "---";
  3367. textBox_OBC_ReadSN.Text = "---";
  3368. textBox_OBC_ReadHW.Text = "---";
  3369. textBox_OBC_ReadFW.Text = "---";
  3370. textBox_OBC_ReadSP.Text = "---";
  3371. textBox_FacModeName.Text = "---";
  3372. textBox_FacModeNum.Text = "---";
  3373. textBox_FacModeHW.Text = "---";
  3374. textBox_FacModeFW.Text = "---";
  3375. textBox_FacModeSP.Text = "---";
  3376. Class_Motor_Ver.Mode = "---";
  3377. Class_Motor_Ver.SN = "---";
  3378. Class_Motor_Ver.HW = "---";
  3379. Class_Motor_Ver.FW = "---";
  3380. Class_Motor_Ver.Special = "---";
  3381. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  3382. }
  3383. /// <summary>
  3384. /// 查询自定义1
  3385. /// </summary>
  3386. /// <param name="sender"></param>
  3387. /// <param name="e"></param>
  3388. private void button_ReadUser1_Click(object sender, EventArgs e)
  3389. {
  3390. textBox_User1.Text = "---";
  3391. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null);
  3392. }
  3393. /// <summary>
  3394. /// 查询自定义2
  3395. /// </summary>
  3396. /// <param name="sender"></param>
  3397. /// <param name="e"></param>
  3398. private void button_ReadUser2_Click(object sender, EventArgs e)
  3399. {
  3400. textBox_User2.Text = "---";
  3401. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null);
  3402. }
  3403. /// <summary>
  3404. /// 查询自定义3
  3405. /// </summary>
  3406. /// <param name="sender"></param>
  3407. /// <param name="e"></param>
  3408. private void button_ReadUser3_Click(object sender, EventArgs e)
  3409. {
  3410. textBox_User3.Text = "---";
  3411. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null);
  3412. }
  3413. /// <summary>
  3414. /// 写入自定义字符串1
  3415. /// </summary>
  3416. /// <param name="sender"></param>
  3417. /// <param name="e"></param>
  3418. private void button_WriteUser1_Click(object sender, EventArgs e)
  3419. {
  3420. string User = textBox_User1.Text;
  3421. var UserArray = new byte[16];
  3422. for (ushort i = 0; i < User.Length; i++)
  3423. {
  3424. UserArray[i] = (byte)User[i];
  3425. }
  3426. if (User.Length < 16)
  3427. {
  3428. UserArray[User.Length] = (byte)'.';
  3429. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3430. {
  3431. UserArray[User.Length + 1 + i] = 0x20;
  3432. }
  3433. }
  3434. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1410, UserArray);
  3435. }
  3436. /// <summary>
  3437. /// 写入自定义字符串2
  3438. /// </summary>
  3439. /// <param name="sender"></param>
  3440. /// <param name="e"></param>
  3441. private void button_WriteUser2_Click(object sender, EventArgs e)
  3442. {
  3443. string User = textBox_User2.Text;
  3444. var UserArray = new byte[16];
  3445. for (ushort i = 0; i < User.Length; i++)
  3446. {
  3447. UserArray[i] = (byte)User[i];
  3448. }
  3449. if (User.Length < 16)
  3450. {
  3451. UserArray[User.Length] = (byte)'.';
  3452. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3453. {
  3454. UserArray[User.Length + 1 + i] = 0x20;
  3455. }
  3456. }
  3457. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1610, UserArray);
  3458. }
  3459. /// <summary>
  3460. /// 写入自定义字符串3
  3461. /// </summary>
  3462. /// <param name="sender"></param>
  3463. /// <param name="e"></param>
  3464. private void button_WriteUser3_Click(object sender, EventArgs e)
  3465. {
  3466. string User = textBox_User3.Text;
  3467. var UserArray = new byte[16];
  3468. for (ushort i = 0; i < User.Length; i++)
  3469. {
  3470. UserArray[i] = (byte)User[i];
  3471. }
  3472. if (User.Length < 16)
  3473. {
  3474. UserArray[User.Length] = (byte)'.';
  3475. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3476. {
  3477. UserArray[User.Length + 1 + i] = 0x20;
  3478. }
  3479. }
  3480. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1810, UserArray);
  3481. }
  3482. /// <summary>
  3483. /// 查询生产信息
  3484. /// </summary>
  3485. /// <param name="sender"></param>
  3486. /// <param name="e"></param>
  3487. private void button_ReadMAC_Click(object sender, EventArgs e)
  3488. {
  3489. textBox_MAC.Text = "---";
  3490. textBox_MACAdd.Text = "---";
  3491. textBox_MACDate.Text = "---";
  3492. textBox_PP.Text = "---";
  3493. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null);
  3494. }
  3495. /// <summary>
  3496. /// 写入生产信息
  3497. /// </summary>
  3498. /// <param name="sender"></param>
  3499. /// <param name="e"></param>
  3500. private void button_WriteMac_Click(object sender, EventArgs e)
  3501. {
  3502. var MACArray = new byte[32];
  3503. //填入生产商
  3504. for (ushort i = 0; i < textBox_MAC.Text.Length; i++)
  3505. {
  3506. MACArray[i] = (byte)textBox_MAC.Text[i];
  3507. }
  3508. if (textBox_MAC.Text.Length < 8)
  3509. {
  3510. MACArray[textBox_MAC.Text.Length] = (byte)'.';
  3511. for (ushort i = 0; i < 8 - textBox_MAC.Text.Length - 1; i++)
  3512. {
  3513. MACArray[textBox_MAC.Text.Length + 1 + i] = 0x20;
  3514. }
  3515. }
  3516. //填入生产地
  3517. for (ushort i = 0; i < textBox_MACAdd.Text.Length; i++)
  3518. {
  3519. MACArray[8 + i] = (byte)textBox_MACAdd.Text[i];
  3520. }
  3521. if (textBox_MACAdd.Text.Length < 8)
  3522. {
  3523. MACArray[textBox_MACAdd.Text.Length + 8] = (byte)'.';
  3524. for (ushort i = 0; i < 8 - textBox_MACAdd.Text.Length - 1; i++)
  3525. {
  3526. MACArray[textBox_MACAdd.Text.Length + 1 + i + 8] = 0x20;
  3527. }
  3528. }
  3529. //填入生产日期
  3530. for (ushort i = 0; i < textBox_MACDate.Text.Length; i++)
  3531. {
  3532. MACArray[16 + i] = (byte)textBox_MACDate.Text[i];
  3533. }
  3534. if (textBox_MACDate.Text.Length < 8)
  3535. {
  3536. MACArray[textBox_MACDate.Text.Length + 16] = (byte)'.';
  3537. for (ushort i = 0; i < 8 - textBox_MACDate.Text.Length - 1; i++)
  3538. {
  3539. MACArray[textBox_MACDate.Text.Length + 1 + i + 16] = 0x20;
  3540. }
  3541. }
  3542. //填入品牌
  3543. for (ushort i = 0; i < textBox_PP.Text.Length; i++)
  3544. {
  3545. MACArray[24 + i] = (byte)textBox_PP.Text[i];
  3546. }
  3547. if (textBox_PP.Text.Length < 8)
  3548. {
  3549. MACArray[textBox_PP.Text.Length + 24] = (byte)'.';
  3550. for (ushort i = 0; i < 8 - textBox_PP.Text.Length - 1; i++)
  3551. {
  3552. MACArray[textBox_PP.Text.Length + 1 + i + 24] = 0x20;
  3553. }
  3554. }
  3555. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  3556. }
  3557. /// <summary>
  3558. /// 查询密钥
  3559. /// </summary>
  3560. /// <param name="sender"></param>
  3561. /// <param name="e"></param>
  3562. private void button_ReadKey_Click(object sender, EventArgs e)
  3563. {
  3564. textBox_Key.Text = "---";
  3565. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null);
  3566. }
  3567. /// <summary>
  3568. /// 写入校验密钥
  3569. /// </summary>
  3570. /// <param name="sender"></param>
  3571. /// <param name="e"></param>
  3572. private void button_WriteKey_Click(object sender, EventArgs e)
  3573. {
  3574. string Key = textBox_Key.Text;
  3575. var KeyArray = new byte[8];
  3576. if (Key.Length != 8)
  3577. {
  3578. timer_500ms.Enabled = false;
  3579. MessageBox.Show("请检查字符长度是否为8", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3580. timer_500ms.Enabled = true;
  3581. return;
  3582. }
  3583. for (ushort i = 0; i < Key.Length; i++)
  3584. {
  3585. KeyArray[i] = (byte)Key[i];
  3586. }
  3587. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1108, KeyArray);
  3588. }
  3589. /// <summary>
  3590. /// 查询在线检测结果
  3591. /// </summary>
  3592. /// <param name="sender"></param>
  3593. /// <param name="e"></param>
  3594. private void button_ReadOnLine_Click(object sender, EventArgs e)
  3595. {
  3596. textBox_Online.Text = "---";
  3597. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2100, null);
  3598. }
  3599. /// <summary>
  3600. /// 系统清除
  3601. /// </summary>
  3602. /// <param name="sender"></param>
  3603. /// <param name="e"></param>
  3604. private void button_SystemClear_Click(object sender, EventArgs e)
  3605. {
  3606. var Code = new byte[5];
  3607. Code[0] = (byte)'C';
  3608. Code[1] = (byte)'L';
  3609. Code[2] = (byte)'E';
  3610. Code[3] = (byte)'A';
  3611. Code[4] = (byte)'R';
  3612. timer_500ms.Enabled = false;
  3613. if (MessageBox.Show("系统清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3614. {
  3615. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3616. {
  3617. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3618. {
  3619. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  3620. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3621. }
  3622. }
  3623. }
  3624. timer_500ms.Enabled = true;
  3625. }
  3626. /// <summary>
  3627. /// 参数还原
  3628. /// </summary>
  3629. /// <param name="sender"></param>
  3630. /// <param name="e"></param>
  3631. private void button_Recovery_Click(object sender, EventArgs e)
  3632. {
  3633. var Code = new byte[8];
  3634. Code[0] = (byte)'R';
  3635. Code[1] = (byte)'E';
  3636. Code[2] = (byte)'C';
  3637. Code[3] = (byte)'O';
  3638. Code[4] = (byte)'V';
  3639. Code[5] = (byte)'E';
  3640. Code[6] = (byte)'R';
  3641. Code[7] = (byte)'Y';
  3642. timer_500ms.Enabled = false;
  3643. if (MessageBox.Show("参数还原后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3644. {
  3645. if (MessageBox.Show("请再次确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3646. {
  3647. if (MessageBox.Show("请最后确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3648. {
  3649. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2708, Code);
  3650. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3651. }
  3652. }
  3653. }
  3654. timer_500ms.Enabled = true;
  3655. }
  3656. /// <summary>
  3657. /// 系统复位
  3658. /// </summary>
  3659. /// <param name="sender"></param>
  3660. /// <param name="e"></param>
  3661. private void button_Reset_Click(object sender, EventArgs e)
  3662. {
  3663. var Code_Off = new byte[5];
  3664. var Code_Reset = new byte[5];
  3665. Code_Off[0] = (byte)'O';
  3666. Code_Off[1] = (byte)'F';
  3667. Code_Off[2] = (byte)'F';
  3668. Code_Off[3] = (byte)'.';
  3669. Code_Off[4] = (byte)'.';
  3670. Code_Reset[0] = (byte)'R';
  3671. Code_Reset[1] = (byte)'E';
  3672. Code_Reset[2] = (byte)'S';
  3673. Code_Reset[3] = (byte)'E';
  3674. Code_Reset[4] = (byte)'T';
  3675. timer_500ms.Enabled = false;
  3676. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3677. {
  3678. timer_500ms.Enabled = true;
  3679. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  3680. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  3681. PowerOffAckStatus = false;
  3682. Delay_ms(250);
  3683. int TryCnt = 3;
  3684. while ((TryCnt--) >= 0)
  3685. {
  3686. if (!PowerOffAckStatus)
  3687. {
  3688. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  3689. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  3690. PowerOffAckStatus = false;
  3691. Delay_ms(250);
  3692. }
  3693. else break;
  3694. }
  3695. if (PowerOffAckStatus)
  3696. {
  3697. MessageBoxTimeOut.Show("已关机!", "提示", 3000, MessageBoxButtons.OK, MessageBoxIcon.None);
  3698. }
  3699. else
  3700. {
  3701. timer_500ms.Enabled = false;
  3702. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3703. timer_500ms.Enabled = true;
  3704. }
  3705. }
  3706. timer_500ms.Enabled = true;
  3707. }
  3708. /// <summary>
  3709. /// 记录清除
  3710. /// </summary>
  3711. /// <param name="sender"></param>
  3712. /// <param name="e"></param>
  3713. private void button_ClearLog_Click(object sender, EventArgs e)
  3714. {
  3715. var Code = new byte[9];
  3716. Code[0] = (byte)'L';
  3717. Code[1] = (byte)'O';
  3718. Code[2] = (byte)'G';
  3719. Code[3] = (byte)' ';
  3720. Code[4] = (byte)'C';
  3721. Code[5] = (byte)'L';
  3722. Code[6] = (byte)'E';
  3723. Code[7] = (byte)'A';
  3724. Code[8] = (byte)'R';
  3725. timer_500ms.Enabled = false;
  3726. if (MessageBox.Show("历史记录信息清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3727. {
  3728. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3729. {
  3730. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3731. {
  3732. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3909, Code);
  3733. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3734. }
  3735. }
  3736. }
  3737. timer_500ms.Enabled = true;
  3738. }
  3739. /// <summary>
  3740. /// 打开系统计算器
  3741. /// </summary>
  3742. /// <param name="sender"></param>
  3743. /// <param name="e"></param>
  3744. private void 计算器ToolStripMenuItem_Click(object sender, EventArgs e)
  3745. {
  3746. System.Diagnostics.Process.Start("calc.exe");
  3747. }
  3748. /// <summary>
  3749. ///故障转换和显示
  3750. /// </summary>
  3751. List<string> ErrorInfo = new List<string>{ "过流保护", "低压保护", "过压保护", "堵转保护","过热保护","速度传感器故障","力矩传感器故障","霍尔故障",
  3752. "马达缺相","NTC故障","BMS校验失败","","OBC校验失败","MCU故障","踏频传感器故障","指拨故障","MOS短路","电压异常","","","","","","","","","","","","",
  3753. "",""};
  3754. private string ErrorInfoDisplay(UInt32 Code)
  3755. {
  3756. string Result = "";
  3757. if (Code == 0)
  3758. {
  3759. Result = "无故障";
  3760. }
  3761. else
  3762. {
  3763. for (int i = 0; i < 32; i++)
  3764. {
  3765. if ((Code & 0x01) == 0x01)
  3766. {
  3767. Result += ErrorInfo[i] + " ";
  3768. }
  3769. Code >>= 1;
  3770. }
  3771. }
  3772. return Result;
  3773. }
  3774. /// <summary>
  3775. /// 鼠标滑过故障码显示具体内容
  3776. /// </summary>
  3777. /// <param name="sender"></param>
  3778. /// <param name="e"></param>
  3779. private void textBox_ErrorCode_MouseHover(object sender, EventArgs e)
  3780. {
  3781. // 创建the ToolTip
  3782. ToolTip toolTip1 = new ToolTip();
  3783. // 设置显示样式
  3784. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  3785. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  3786. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  3787. toolTip1.ShowAlways = true;//是否显示提示框
  3788. // 设置伴随的对象.
  3789. string ErrorCode = this.textBox_ErrorCode.Text;
  3790. UInt32 Code = ErrorCode.Contains("H") ? Convert.ToUInt32(ErrorCode.Split('H')[0], 16) : 0;
  3791. toolTip1.SetToolTip(this.textBox_ErrorCode, ErrorInfoDisplay(Code));//设置故障内容显示
  3792. }
  3793. /// <summary>
  3794. /// 数据记录
  3795. /// </summary>
  3796. private void RunInfoAutoSave()
  3797. {
  3798. if (运行信息记录ToolStripMenuItem.Checked == true)
  3799. {
  3800. if (RunInfoSaveFilename == string.Empty)
  3801. {
  3802. return;
  3803. }
  3804. string SaveData = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff").Replace(" ", "_") + " --> ";
  3805. foreach (Control c in tabPage_RunInfo.Controls)
  3806. {
  3807. if (c is TextBox)
  3808. {
  3809. SaveData += c.Text + " , ";
  3810. }
  3811. }
  3812. foreach (Control c in tabPage_DebugInfo.Controls)
  3813. {
  3814. if (c is TextBox)
  3815. {
  3816. SaveData += c.Text + " , ";
  3817. }
  3818. }
  3819. SaveData += "\r\n";
  3820. System.IO.File.AppendAllText(RunInfoSaveFilename, SaveData);//sb.ToString());
  3821. }
  3822. }
  3823. /// <summary>
  3824. /// 打开或关闭数据记录
  3825. /// </summary>
  3826. /// <param name="sender"></param>
  3827. /// <param name="e"></param>
  3828. private void 记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  3829. {
  3830. if (运行信息记录ToolStripMenuItem.Checked == false)
  3831. {
  3832. if (mySerialProcess.mySerial.IsOpen == true)
  3833. {
  3834. RunInfoSaveFilename = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_运行信息" + ".txt";
  3835. System.IO.File.AppendAllText(RunInfoSaveFilename, "时间 --> 车速 , 转速 , 踏频 , 力矩Reg , 力矩 , 踩踏方向 , 电压 , 电流 , 功率 , 电量 , " +
  3836. "PCB温度 , 绕组温度 , MOS温度 , 挡位 , 灯开关 , 续航 , 平均功耗 , 单次里程 , 单次时间 , 故障码 , " +
  3837. "系统状态机 , 二层状态机 , 电机状态机 , 助力状态机 , D轴电流给定 , Q轴电流给定 , D轴电压给定 , Q轴电压给定 , 瞬时力矩 , 时间滤波力矩 , 踏频滤波力矩 , D轴电流反馈 , Q轴电流反馈 , 助力函数输出" + "\r\n");
  3838. MessageBoxTimeOut.Show("开始记录", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  3839. 运行信息记录ToolStripMenuItem.Checked = true;
  3840. }
  3841. else
  3842. {
  3843. timer_500ms.Enabled = false;
  3844. MessageBox.Show("请连接电机", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3845. timer_500ms.Enabled = true;
  3846. }
  3847. }
  3848. else
  3849. {
  3850. 运行信息记录ToolStripMenuItem.Checked = false;
  3851. MessageBoxTimeOut.Show("停止记录", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  3852. }
  3853. }
  3854. /// <summary>
  3855. /// 仪表启动控制档位开关事件
  3856. /// </summary>
  3857. /// <param name="sender"></param>
  3858. /// <param name="e"></param>
  3859. private void checkBox_OBC_StartSetGearSt_CheckedChanged(object sender, EventArgs e)
  3860. {
  3861. if (checkBox_OBC_StartSetGearSt.Checked == true)
  3862. {
  3863. //检查串口是否打开
  3864. if (!mySerialProcess.mySerial.IsOpen)
  3865. {
  3866. timer_500ms.Enabled = false;
  3867. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3868. timer_500ms.Enabled = true;
  3869. checkBox_OBC_StartSetGearSt.Checked = false;
  3870. return;
  3871. }
  3872. //检查是否选择档位和打开车灯
  3873. if ((comboBox_OBC_SetGearST.SelectedIndex == -1) || (comboBox_OBC_LightSw.SelectedIndex == -1))
  3874. {
  3875. timer_500ms.Enabled = false;
  3876. MessageBox.Show("请检查档位设置和大灯开关!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3877. timer_500ms.Enabled = true;
  3878. checkBox_OBC_StartSetGearSt.Checked = false;
  3879. return;
  3880. }
  3881. }
  3882. }
  3883. /// <summary>
  3884. /// OBC查询电机用户参数
  3885. /// </summary>
  3886. /// <param name="sender"></param>
  3887. /// <param name="e"></param>
  3888. private void button_OBC_ReadUserInfo_Click(object sender, EventArgs e)
  3889. {
  3890. richTextBox_OBC_ReadUserInfo.Clear();
  3891. comboBox_OBC_BikeCCS.SelectedIndex = 0;
  3892. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3300, null);
  3893. }
  3894. /// <summary>
  3895. /// OBC设置电机用户参数
  3896. /// </summary>
  3897. /// <param name="sender"></param>
  3898. /// <param name="e"></param>
  3899. private void button_OBC_WriteUserInfo_Click(object sender, EventArgs e)
  3900. {
  3901. var UserInfoCode = new byte[8];
  3902. for (int i = 0; i < UserInfoCode.Length; i++)
  3903. UserInfoCode[i] = 0;
  3904. if (comboBox_OBC_StartMode.SelectedIndex == -1)//检查数据有效性
  3905. {
  3906. timer_500ms.Enabled = false;
  3907. MessageBox.Show("请选择启动模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3908. timer_500ms.Enabled = true;
  3909. return;
  3910. }
  3911. if (comboBox_OBC_AssistFunc.SelectedIndex == -1)//检查数据有效性
  3912. {
  3913. timer_500ms.Enabled = false;
  3914. MessageBox.Show("请选择助力方案!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3915. timer_500ms.Enabled = true;
  3916. return;
  3917. }
  3918. //周长微调
  3919. UserInfoCode[0] = (byte)(int)numericUpDown_OBC_WheelAdj.Value;
  3920. //启动模式
  3921. UserInfoCode[1] = (byte)(comboBox_OBC_StartMode.SelectedIndex + 1);
  3922. //助力方案
  3923. UserInfoCode[2] = (byte)(comboBox_OBC_AssistFunc.SelectedIndex + 1);
  3924. //自动关机时间
  3925. UserInfoCode[3] = (byte)(uint)numericUpDown_OBC_OffTime.Value;
  3926. //限速微调
  3927. UserInfoCode[4] = (byte)(int)numericUpDown_OBC_SpeedLimitAdj.Value;
  3928. //定速巡航开关
  3929. UserInfoCode[5] = (byte)((comboBox_OBC_BikeCCS.SelectedIndex == 1) ? 0xAA : 0x00);
  3930. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3408, UserInfoCode);
  3931. }
  3932. /// <summary>
  3933. /// OBC查询电机版本信息
  3934. /// </summary>
  3935. /// <param name="sender"></param>
  3936. /// <param name="e"></param>
  3937. private void button_OBC_ReadVerInfo_Click(object sender, EventArgs e)
  3938. {
  3939. textBox_Model.Text = "---";
  3940. textBox_SN.Text = "---";
  3941. textBox_HW.Text = "---";
  3942. textBox_FW.Text = "---";
  3943. textBox_SP.Text = "---";
  3944. textBox_OBC_ReadModel.Text = "---";
  3945. textBox_OBC_ReadSN.Text = "---";
  3946. textBox_OBC_ReadHW.Text = "---";
  3947. textBox_OBC_ReadFW.Text = "---";
  3948. textBox_OBC_ReadSP.Text = "---";
  3949. textBox_FacModeName.Text = "---";
  3950. textBox_FacModeNum.Text = "---";
  3951. textBox_FacModeHW.Text = "---";
  3952. textBox_FacModeFW.Text = "---";
  3953. textBox_FacModeSP.Text = "---";
  3954. Class_Motor_Ver.Mode = "---";
  3955. Class_Motor_Ver.SN = "---";
  3956. Class_Motor_Ver.HW = "---";
  3957. Class_Motor_Ver.FW = "---";
  3958. Class_Motor_Ver.Special = "---";
  3959. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  3960. }
  3961. /// <summary>
  3962. /// OBC读取骑行历史
  3963. /// </summary>
  3964. /// <param name="sender"></param>
  3965. /// <param name="e"></param>
  3966. private void button_OBC_ReadRideInfo_Click(object sender, EventArgs e)
  3967. {
  3968. textBox_OBC_TRIP_KM.Text = "";
  3969. textBox_OBC_TRIP_TIME.Text = "";
  3970. textBox_OBC_ODO_KM.Text = "";
  3971. textBox_OBC_ODO_TIME.Text = "";
  3972. textBox_ODO_KM.Text = "---";
  3973. textBox_ODO_TIME.Text = "---";
  3974. textBox_TRIP_KM.Text = "---";
  3975. textBox_TRIP_TIME.Text = "---";
  3976. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3500, null);
  3977. }
  3978. /// <summary>
  3979. /// OBC清除TRIP里程
  3980. /// </summary>
  3981. /// <param name="sender"></param>
  3982. /// <param name="e"></param>
  3983. private void button_OBC_ClearTrip_Click(object sender, EventArgs e)
  3984. {
  3985. var Code = new byte[5];
  3986. Code[0] = (byte)'C';
  3987. Code[1] = (byte)'L';
  3988. Code[2] = (byte)'E';
  3989. Code[3] = (byte)'A';
  3990. Code[4] = (byte)'R';
  3991. timer_500ms.Enabled = false;
  3992. if (MessageBox.Show("TRIP清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3993. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3605, Code);
  3994. timer_500ms.Enabled = true;
  3995. }
  3996. private void checkBox_OBC_StartReadBMS_CheckedChanged(object sender, EventArgs e)
  3997. {
  3998. if (checkBox_OBC_StartReadBMS.Checked == true)
  3999. {
  4000. //检查串口是否打开
  4001. if (!mySerialProcess.mySerial.IsOpen)
  4002. {
  4003. timer_500ms.Enabled = false;
  4004. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4005. timer_500ms.Enabled = true;
  4006. checkBox_OBC_StartReadBMS.Checked = false;
  4007. return;
  4008. }
  4009. }
  4010. }
  4011. /// <summary>
  4012. /// 写入力矩传感器参数
  4013. /// </summary>
  4014. /// <param name="sender"></param>
  4015. /// <param name="e"></param>
  4016. private void button_WriteTqSensorParam_Click(object sender, EventArgs e)
  4017. {
  4018. var ConfigParam = new byte[46];
  4019. for (int i = 0; i < 14; i++)
  4020. ConfigParam[i] = 0;
  4021. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  4022. ushort uwDataTemp = 0;
  4023. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  4024. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  4025. int index = 0;
  4026. try
  4027. {
  4028. for (int i = 0; i < strDataTemp.Length; i++)
  4029. {
  4030. if (strDataTemp[i].Split('=')[0] == "第四阶段转矩点采集值")
  4031. {
  4032. index = i;
  4033. break;
  4034. }
  4035. }
  4036. for (int i = 0; i < (index + 1); i++)
  4037. {
  4038. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  4039. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  4040. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  4041. }
  4042. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x472E, ConfigParam);
  4043. }
  4044. catch (Exception)
  4045. {
  4046. timer_500ms.Enabled = false;
  4047. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4048. timer_500ms.Enabled = true;
  4049. }
  4050. }
  4051. /// <summary>
  4052. /// 查询存储标志
  4053. /// </summary>
  4054. /// <param name="sender"></param>
  4055. /// <param name="e"></param>
  4056. private void button_ReadSaveFlag_Click(object sender, EventArgs e)
  4057. {
  4058. radioButton_EE_SaveYes.Checked = false;
  4059. radioButton_EE_SaveNo.Checked = false;
  4060. radioButton_SIP_SaveYes.Checked = false;
  4061. radioButton_SIP_SaveNo.Checked = false;
  4062. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null);
  4063. }
  4064. /// <summary>
  4065. /// 写入存储标志
  4066. /// </summary>
  4067. /// <param name="sender"></param>
  4068. /// <param name="e"></param>
  4069. private void button_WriteSaveFlag_Click(object sender, EventArgs e)
  4070. {
  4071. var SaveFlag = new byte[6];
  4072. for (int i = 0; i < 6; i++)
  4073. SaveFlag[i] = 0;
  4074. if ((radioButton_EE_SaveYes.Checked == false) && (radioButton_EE_SaveNo.Checked == false))
  4075. {
  4076. timer_500ms.Enabled = false;
  4077. MessageBox.Show("请选择EEPROM存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4078. timer_500ms.Enabled = true;
  4079. return;
  4080. }
  4081. if ((radioButton_SIP_SaveYes.Checked == false) && (radioButton_SIP_SaveNo.Checked == false))
  4082. {
  4083. timer_500ms.Enabled = false;
  4084. MessageBox.Show("请选择SIP校验存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4085. timer_500ms.Enabled = true;
  4086. return;
  4087. }
  4088. SaveFlag[0] = (byte)((checkBox_SaveYes.Checked) ? 0x01 : 0x00);
  4089. SaveFlag[2] = (byte)(radioButton_EE_SaveYes.Checked ? 0x01 : 0x00);
  4090. SaveFlag[3] = 0;
  4091. SaveFlag[4] = (byte)(radioButton_SIP_SaveYes.Checked ? 0x01 : 0x00);
  4092. SaveFlag[5] = 0;
  4093. timer_500ms.Enabled = false;
  4094. if (MessageBox.Show("确认修改存储标志?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  4095. {
  4096. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4906, SaveFlag);
  4097. }
  4098. timer_500ms.Enabled = true;
  4099. }
  4100. /// <summary>
  4101. /// 读取指定地址数据
  4102. /// </summary>
  4103. /// <param name="sender"></param>
  4104. /// <param name="e"></param>
  4105. private void button_ReadRamFlash_Click(object sender, EventArgs e)
  4106. {
  4107. var Address = new byte[4];
  4108. UInt32 Address_Begin;
  4109. UInt32 Addres_End;
  4110. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  4111. richTextBox_RamFlasgData.Clear();
  4112. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  4113. {
  4114. timer_500ms.Enabled = false;
  4115. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4116. timer_500ms.Enabled = true;
  4117. return;
  4118. }
  4119. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  4120. {
  4121. timer_500ms.Enabled = false;
  4122. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4123. timer_500ms.Enabled = true;
  4124. return;
  4125. }
  4126. else
  4127. {
  4128. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  4129. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  4130. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  4131. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  4132. if (Addres_End < Address_Begin)
  4133. {
  4134. timer_500ms.Enabled = false;
  4135. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4136. timer_500ms.Enabled = true;
  4137. return;
  4138. }
  4139. else
  4140. {
  4141. var SendByte = new byte[8];
  4142. SendByte[0] = (byte)(Address_Begin >> 24);
  4143. SendByte[1] = (byte)(Address_Begin >> 16);
  4144. SendByte[2] = (byte)(Address_Begin >> 8);
  4145. SendByte[3] = (byte)(Address_Begin);
  4146. SendByte[4] = (byte)(Addres_End >> 24);
  4147. SendByte[5] = (byte)(Addres_End >> 16);
  4148. SendByte[6] = (byte)(Addres_End >> 8);
  4149. SendByte[7] = (byte)(Addres_End);
  4150. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  4151. }
  4152. }
  4153. }
  4154. /// <summary>
  4155. /// 工作模式选择
  4156. /// </summary>
  4157. /// <param name="sender"></param>
  4158. /// <param name="e"></param>
  4159. private void comboBox_WorkMode_SelectedIndexChanged(object sender, EventArgs e)
  4160. {
  4161. var RunMode = new byte[1];
  4162. if (comboBox_WorkMode.Text == "配置模式")
  4163. RunMode[0] = 0x01;
  4164. else if (comboBox_WorkMode.Text == "调试模式")
  4165. RunMode[0] = 0x02;
  4166. else
  4167. RunMode[0] = 0x00;
  4168. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  4169. }
  4170. /// <summary>
  4171. /// 助力档位选择
  4172. /// </summary>
  4173. /// <param name="sender"></param>
  4174. /// <param name="e"></param>
  4175. private void comboBox_GearSt_SelectedIndexChanged(object sender, EventArgs e)
  4176. {
  4177. var CtrlCode = new byte[2];
  4178. if (comboBox_GearSt.SelectedIndex == 5)//档位
  4179. CtrlCode[0] = 0x33;
  4180. else if (comboBox_GearSt.SelectedIndex == 6)//档位
  4181. CtrlCode[0] = 0x22;
  4182. else
  4183. CtrlCode[0] = (byte)comboBox_GearSt.SelectedIndex;
  4184. if (comboBox_LightSwitch.SelectedIndex == 0)//车灯
  4185. CtrlCode[1] = 0xF1;
  4186. else
  4187. CtrlCode[1] = 0xF0;
  4188. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
  4189. comboBox_OBC_SetGearST.SelectedIndex = comboBox_GearSt.SelectedIndex;
  4190. comboBox_OBC_LightSw.SelectedIndex = comboBox_LightSwitch.SelectedIndex;
  4191. Delay_ms(500);
  4192. //设置百分比
  4193. do
  4194. {
  4195. var PercentCode = new byte[1];
  4196. if (comboBox_GearSt.SelectedIndex == 0) //Off
  4197. {
  4198. PercentCode[0] = 0;
  4199. textBox_MotorSpeedPercent.Text = "0";
  4200. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, PercentCode);
  4201. }
  4202. else if (comboBox_GearSt.SelectedIndex == 6) //Walk
  4203. {
  4204. if (comboBox_WorkMode.SelectedIndex != 0)
  4205. {
  4206. PercentCode[0] = 100;
  4207. textBox_MotorSpeedPercent.Text = "100";
  4208. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, PercentCode);
  4209. }
  4210. }
  4211. } while (false);
  4212. }
  4213. /// <summary>
  4214. /// 仪表档位选择
  4215. /// </summary>
  4216. /// <param name="sender"></param>
  4217. /// <param name="e"></param>
  4218. private void comboBox_OBC_SetGearST_SelectedIndexChanged(object sender, EventArgs e)
  4219. {
  4220. comboBox_GearSt.SelectedIndex = comboBox_OBC_SetGearST.SelectedIndex;
  4221. comboBox_LightSwitch.SelectedIndex = comboBox_OBC_LightSw.SelectedIndex;
  4222. }
  4223. /// <summary>
  4224. /// 生产模式初始化
  4225. /// </summary>
  4226. /// <param name="sender"></param>
  4227. /// <param name="e"></param>
  4228. private void button_FacModeInit_Click(object sender, EventArgs e)
  4229. {
  4230. var Code = new byte[5];
  4231. Code[0] = (byte)'C';
  4232. Code[1] = (byte)'L';
  4233. Code[2] = (byte)'E';
  4234. Code[3] = (byte)'A';
  4235. Code[4] = (byte)'R';
  4236. timer_500ms.Enabled = false;
  4237. if (MessageBox.Show("电机即将初始化!", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  4238. {
  4239. if (MessageBox.Show("请再次确认", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  4240. {
  4241. timer_500ms.Enabled = true;
  4242. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  4243. PowerOffAckStatus = false;
  4244. Delay_ms(250);
  4245. int TryCnt = 3;
  4246. while ((TryCnt--) >= 0)
  4247. {
  4248. if (!PowerOffAckStatus)
  4249. {
  4250. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  4251. PowerOffAckStatus = false;
  4252. Delay_ms(250);
  4253. }
  4254. else break;
  4255. }
  4256. if (PowerOffAckStatus)
  4257. {
  4258. timer_500ms.Enabled = false;
  4259. MessageBox.Show("系统已关机,请保持无负载重新开机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  4260. timer_500ms.Enabled = true;
  4261. }
  4262. else
  4263. {
  4264. timer_500ms.Enabled = false;
  4265. MessageBox.Show("初始化失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4266. timer_500ms.Enabled = true;
  4267. }
  4268. timer_500ms.Enabled = true;
  4269. }
  4270. }
  4271. timer_500ms.Enabled = true;
  4272. //清除历史测试记录
  4273. textBox_FacModeSensorADC0.Text = "";
  4274. textBox_FacModeSensorADC1.Text = "";
  4275. textBox_FacModeSensorADC2.Text = "";
  4276. textBox_FacModeSensorADC3.Text = "";
  4277. textBox_FacModeSensorADC4.Text = "";
  4278. LightSwitchStatus = false;
  4279. MotorRunStatus = false;
  4280. textBox_MotorSpeedPercent.Text = "5";
  4281. textBox_FacModeName.Text = "";
  4282. textBox_FacModeNum.Text = "";
  4283. textBox_FacModeHW.Text = "";
  4284. textBox_FacModeFW.Text = "";
  4285. }
  4286. /// <summary>
  4287. /// 生产模式读取传感器参数
  4288. /// </summary>
  4289. /// <param name="sender"></param>
  4290. /// <param name="e"></param>
  4291. private void button_FacModeSensorRead_Click(object sender, EventArgs e)
  4292. {
  4293. richTextBox_SensorParam.Clear();
  4294. textBox_FacModeSensorADC0.Text = "";
  4295. textBox_FacModeSensorADC1.Text = "";
  4296. textBox_FacModeSensorADC2.Text = "";
  4297. textBox_FacModeSensorADC3.Text = "";
  4298. textBox_FacModeSensorADC4.Text = "";
  4299. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4300. //零点判断
  4301. label1_TorqueCal0.BackColor = Color.Red;
  4302. WriteACK = false;
  4303. ACK_WaitCnt = 0;
  4304. Delay_ms(200);
  4305. if (WriteACK == true) //力矩读取正常
  4306. {
  4307. WriteACK = false;
  4308. //获取零点
  4309. ushort ZeroNew;
  4310. ZeroNew = (ushort)Convert.ToUInt16(textBox_FacModeSensorADC0.Text);
  4311. //比较零点
  4312. if ((ZeroNew <= TorqueParamsForm.Zero.Max) && (ZeroNew >= TorqueParamsForm.Zero.Min))
  4313. {
  4314. label1_TorqueCal0.BackColor = Color.Green;
  4315. }
  4316. else
  4317. {
  4318. MessageBoxTimeOut.Show("力矩传感器零点超范围!\r\n" + "最新零点:" + ZeroNew.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4319. }
  4320. }
  4321. else //力矩读取不正常
  4322. {
  4323. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4324. }
  4325. }
  4326. /// <summary>
  4327. /// 生产模式传感器标定1
  4328. /// </summary>
  4329. /// <param name="sender"></param>
  4330. /// <param name="e"></param>
  4331. private void buttonFacModeSet1_Click(object sender, EventArgs e)
  4332. {
  4333. var ConfigParam = new byte[4];
  4334. for (int i = 0; i < 4; i++)
  4335. ConfigParam[i] = 0;
  4336. ushort uwDataTemp = 0;
  4337. try
  4338. {
  4339. uwDataTemp = 1;//负载序号
  4340. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4341. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4342. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal1.Text) * 10); ;//负载值0.1Nm
  4343. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4344. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4345. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4346. Delay_ms(2000);
  4347. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4348. //标定1判断
  4349. label1_TorqueCal1.BackColor = Color.Red;
  4350. WriteACK = false;
  4351. ACK_WaitCnt = 0;
  4352. Delay_ms(200);
  4353. if (WriteACK == true) //力矩读取正常
  4354. {
  4355. WriteACK = false;
  4356. //获取标定1
  4357. ushort K1_T, K1;
  4358. K1_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal1.Text) * 10);
  4359. K1 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC1.Text));
  4360. //比较标定1
  4361. if ((K1_T == TorqueParamsForm.K1.T) && (K1 <= TorqueParamsForm.K1.Max) && (K1 >= TorqueParamsForm.K1.Min))
  4362. {
  4363. label1_TorqueCal1.BackColor = Color.Green;
  4364. }
  4365. else
  4366. {
  4367. MessageBoxTimeOut.Show("力矩传感器标定1超范围!\r\n" + "加载扭矩:" + K1_T.ToString() + "\r\n标定值:" + K1.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4368. }
  4369. }
  4370. else //力矩读取不正常
  4371. {
  4372. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4373. }
  4374. }
  4375. catch (Exception)
  4376. {
  4377. timer_500ms.Enabled = false;
  4378. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4379. timer_500ms.Enabled = true;
  4380. }
  4381. }
  4382. /// <summary>
  4383. /// 生产模式传感器标定2
  4384. /// </summary>
  4385. /// <param name="sender"></param>
  4386. /// <param name="e"></param>
  4387. private void buttonFacModeSet2_Click(object sender, EventArgs e)
  4388. {
  4389. var ConfigParam = new byte[4];
  4390. for (int i = 0; i < 4; i++)
  4391. ConfigParam[i] = 0;
  4392. ushort uwDataTemp = 0;
  4393. try
  4394. {
  4395. uwDataTemp = 2;//负载序号
  4396. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4397. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4398. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal2.Text) * 10); ;//负载值0.1Nm
  4399. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4400. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4401. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4402. Delay_ms(2000);
  4403. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4404. //标定2判断
  4405. label1_TorqueCal2.BackColor = Color.Red;
  4406. WriteACK = false;
  4407. ACK_WaitCnt = 0;
  4408. Delay_ms(200);
  4409. if (WriteACK == true) //力矩读取正常
  4410. {
  4411. WriteACK = false;
  4412. //获取标定2
  4413. ushort K2_T, K2;
  4414. K2_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal2.Text) * 10);
  4415. K2 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC2.Text));
  4416. //比较标定1
  4417. if ((K2_T == TorqueParamsForm.K2.T) && (K2 <= TorqueParamsForm.K2.Max) && (K2 >= TorqueParamsForm.K2.Min))
  4418. {
  4419. label1_TorqueCal2.BackColor = Color.Green;
  4420. }
  4421. else
  4422. {
  4423. MessageBoxTimeOut.Show("力矩传感器标定2超范围!\r\n" + "加载扭矩:" + K2_T.ToString() + "\r\n标定值:" + K2.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4424. }
  4425. }
  4426. else //力矩读取不正常
  4427. {
  4428. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4429. }
  4430. }
  4431. catch (Exception)
  4432. {
  4433. timer_500ms.Enabled = false;
  4434. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4435. timer_500ms.Enabled = true;
  4436. }
  4437. }
  4438. /// <summary>
  4439. /// 生产模式传感器标定3
  4440. /// </summary>
  4441. /// <param name="sender"></param>
  4442. /// <param name="e"></param>
  4443. private void buttonFacModeSet3_Click(object sender, EventArgs e)
  4444. {
  4445. var ConfigParam = new byte[4];
  4446. for (int i = 0; i < 4; i++)
  4447. ConfigParam[i] = 0;
  4448. ushort uwDataTemp = 0;
  4449. try
  4450. {
  4451. uwDataTemp = 3;//负载序号
  4452. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4453. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4454. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal3.Text) * 10); ;//负载值0.1Nm
  4455. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4456. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4457. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4458. Delay_ms(2000);
  4459. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4460. //标定3判断
  4461. label1_TorqueCal3.BackColor = Color.Red;
  4462. WriteACK = false;
  4463. ACK_WaitCnt = 0;
  4464. Delay_ms(200);
  4465. if (WriteACK == true) //力矩读取正常
  4466. {
  4467. WriteACK = false;
  4468. //获取标定3
  4469. ushort K3_T, K3;
  4470. K3_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal3.Text) * 10);
  4471. K3 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC3.Text));
  4472. //比较标定1
  4473. if ((K3_T == TorqueParamsForm.K3.T) && (K3 <= TorqueParamsForm.K3.Max) && (K3 >= TorqueParamsForm.K3.Min))
  4474. {
  4475. label1_TorqueCal3.BackColor = Color.Green;
  4476. }
  4477. else
  4478. {
  4479. MessageBoxTimeOut.Show("力矩传感器标定3超范围!\r\n" + "加载扭矩:" + K3_T.ToString() + "\r\n标定值:" + K3.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4480. }
  4481. }
  4482. else //力矩读取不正常
  4483. {
  4484. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4485. }
  4486. }
  4487. catch (Exception)
  4488. {
  4489. timer_500ms.Enabled = false;
  4490. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4491. timer_500ms.Enabled = true;
  4492. }
  4493. }
  4494. /// <summary>
  4495. /// 生产模式传感器标定4
  4496. /// </summary>
  4497. /// <param name="sender"></param>
  4498. /// <param name="e"></param>
  4499. private void buttonFacModeSet4_Click(object sender, EventArgs e)
  4500. {
  4501. var ConfigParam = new byte[4];
  4502. for (int i = 0; i < 4; i++)
  4503. ConfigParam[i] = 0;
  4504. ushort uwDataTemp = 0;
  4505. try
  4506. {
  4507. WriteACK = false;
  4508. uwDataTemp = 4;//负载序号
  4509. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4510. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4511. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal4.Text) * 10); ;//负载值0.1Nm
  4512. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4513. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4514. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4515. Delay_ms(2000);
  4516. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4517. //标定4判断
  4518. label1_TorqueCal4.BackColor = Color.Red;
  4519. WriteACK = false;
  4520. ACK_WaitCnt = 0;
  4521. Delay_ms(200);
  4522. if (WriteACK == true) //力矩读取正常
  4523. {
  4524. //获取标定4
  4525. ushort K4_T, K4;
  4526. K4_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal4.Text) * 10);
  4527. K4 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC4.Text));
  4528. //比较标定1
  4529. if ((K4_T == TorqueParamsForm.K4.T) && (K4 <= TorqueParamsForm.K4.Max) && (K4 >= TorqueParamsForm.K4.Min))
  4530. {
  4531. label1_TorqueCal4.BackColor = Color.Green;
  4532. }
  4533. else
  4534. {
  4535. MessageBoxTimeOut.Show("力矩传感器标定4超范围!\r\n" + "加载扭矩:" + K4_T.ToString() + "\r\n标定值:" + K4.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4536. }
  4537. }
  4538. else //力矩读取不正常
  4539. {
  4540. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4541. }
  4542. }
  4543. catch (Exception)
  4544. {
  4545. timer_500ms.Enabled = false;
  4546. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4547. timer_500ms.Enabled = true;
  4548. }
  4549. }
  4550. /// <summary>
  4551. /// 生产模式开关灯
  4552. /// </summary>
  4553. /// <param name="sender"></param>
  4554. /// <param name="e"></param>
  4555. bool LightSwitchStatus = false;
  4556. private void button_FacModeLightSW_Click(object sender, EventArgs e)
  4557. {
  4558. var CtrlCode = new byte[2];
  4559. CtrlCode[0] = 0x00;
  4560. if (LightSwitchStatus)
  4561. {
  4562. CtrlCode[1] = 0xF0;
  4563. button_FacModeLightSW.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(128)))));
  4564. }
  4565. else
  4566. {
  4567. CtrlCode[1] = 0xF1;
  4568. button_FacModeLightSW.BackColor = Color.Yellow;
  4569. }
  4570. if (mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode))
  4571. {
  4572. LightSwitchStatus = !LightSwitchStatus;
  4573. comboBox_LightSwitch.SelectedIndex = LightSwitchStatus ? 0 : 1;
  4574. comboBox_OBC_LightSw.SelectedIndex = LightSwitchStatus ? 0 : 1;
  4575. }
  4576. }
  4577. /// <summary>
  4578. /// 生产模式电机控制
  4579. /// </summary>
  4580. /// <param name="sender"></param>
  4581. /// <param name="e"></param>
  4582. bool MotorRunStatus = false;
  4583. private void button_FacModeMotorRun_Click(object sender, EventArgs e)
  4584. {
  4585. string DebugDefaultInfo = "";
  4586. //获取调试信息
  4587. if (richTextBox_DebugParam.Text == string.Empty)
  4588. {
  4589. richTextBox_DebugParam.Clear();
  4590. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  4591. }
  4592. Delay_ms(200);
  4593. DebugDefaultInfo = richTextBox_DebugParam.Text;
  4594. //获取参数
  4595. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  4596. if (strDataTemp.Length != 29)
  4597. {
  4598. timer_500ms.Enabled = false;
  4599. MessageBox.Show("数据格式不正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4600. timer_500ms.Enabled = true;
  4601. return;
  4602. }
  4603. //设置参数
  4604. var ConfigParam = new byte[60];
  4605. for (int i = 0; i < 60; i++)
  4606. ConfigParam[i] = 0;
  4607. ConfigParam[0] = 0x00;
  4608. ushort uwDataTemp = 0;
  4609. if (!MotorRunStatus) //停止状态
  4610. {
  4611. //设置速度环
  4612. strDataTemp[0] = "整体运行模式=3";
  4613. //发送数据
  4614. try
  4615. {
  4616. for (int i = 0; i < strDataTemp.Length; i++)
  4617. {
  4618. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  4619. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  4620. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  4621. }
  4622. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  4623. return;
  4624. }
  4625. catch (Exception)
  4626. {
  4627. timer_500ms.Enabled = false;
  4628. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4629. timer_500ms.Enabled = true;
  4630. }
  4631. Delay_ms(200);
  4632. //设置转速百分比100%
  4633. textBox_MotorSpeedPercent.Text = "100";
  4634. ConfigParam[0] = (byte)100;
  4635. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, ConfigParam);
  4636. MotorRunStatus = !MotorRunStatus;
  4637. button_FacModeMotorRun.BackColor = Color.Yellow;
  4638. Delay_ms(200);
  4639. //电机进入配置模式
  4640. var RunMode = new byte[1];
  4641. RunMode[0] = 0x01;
  4642. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  4643. }
  4644. else //运转状态
  4645. {
  4646. //设置转速百分比0%
  4647. textBox_MotorSpeedPercent.Text = "0";
  4648. ConfigParam[0] = (byte)0;
  4649. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, ConfigParam);
  4650. MotorRunStatus = !MotorRunStatus;
  4651. button_FacModeMotorRun.BackColor = Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
  4652. Delay_ms(200);
  4653. //还原为原始值
  4654. strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  4655. try
  4656. {
  4657. for (int i = 0; i < strDataTemp.Length; i++)
  4658. {
  4659. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  4660. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  4661. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  4662. }
  4663. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  4664. return;
  4665. }
  4666. catch (Exception)
  4667. {
  4668. timer_500ms.Enabled = false;
  4669. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4670. timer_500ms.Enabled = true;
  4671. }
  4672. Delay_ms(200);
  4673. //电机退出配置模式
  4674. var RunMode = new byte[1];
  4675. RunMode[0] = 0x00;
  4676. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  4677. }
  4678. }
  4679. /// <summary>
  4680. /// 生产模式写入型号
  4681. /// </summary>
  4682. /// <param name="sender"></param>
  4683. /// <param name="e"></param>
  4684. private void button_FacModeSetName_Click(object sender, EventArgs e)
  4685. {
  4686. string Mode = textBox_FacModeName.Text;
  4687. var ModeArray = new byte[16];
  4688. for (ushort i = 0; i < Mode.Length; i++)
  4689. {
  4690. ModeArray[i] = (byte)Mode[i];
  4691. }
  4692. if (Mode.Length < 16)
  4693. {
  4694. ModeArray[Mode.Length] = (byte)'.';
  4695. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  4696. {
  4697. ModeArray[Mode.Length + 1 + i] = 0x20;
  4698. }
  4699. }
  4700. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  4701. }
  4702. /// <summary>
  4703. /// 生产模式写入SN
  4704. /// </summary>
  4705. /// <param name="sender"></param>
  4706. /// <param name="e"></param>
  4707. private void Button_FacModeSetNum_Click(object sender, EventArgs e)
  4708. {
  4709. string SN = textBox_FacModeNum.Text;
  4710. var SNArray = new byte[16];
  4711. for (ushort i = 0; i < SN.Length; i++)
  4712. {
  4713. SNArray[i] = (byte)SN[i];
  4714. }
  4715. if (SN.Length < 16)
  4716. {
  4717. SNArray[SN.Length] = (byte)'.';
  4718. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  4719. {
  4720. SNArray[SN.Length + 1 + i] = 0x20;
  4721. }
  4722. }
  4723. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  4724. }
  4725. /// <summary>
  4726. /// 生产模式读取版本信息
  4727. /// </summary>
  4728. /// <param name="sender"></param>
  4729. /// <param name="e"></param>
  4730. private void Button_FacModeReadVer_Click_1(object sender, EventArgs e)
  4731. {
  4732. textBox_Model.Text = "---";
  4733. textBox_SN.Text = "---";
  4734. textBox_HW.Text = "---";
  4735. textBox_FW.Text = "---";
  4736. textBox_SP.Text = "---";
  4737. textBox_OBC_ReadModel.Text = "---";
  4738. textBox_OBC_ReadSN.Text = "---";
  4739. textBox_OBC_ReadHW.Text = "---";
  4740. textBox_OBC_ReadFW.Text = "---";
  4741. textBox_OBC_ReadSP.Text = "---";
  4742. textBox_FacModeName.Text = "---";
  4743. textBox_FacModeNum.Text = "---";
  4744. textBox_FacModeHW.Text = "---";
  4745. textBox_FacModeFW.Text = "---";
  4746. textBox_FacModeSP.Text = "---";
  4747. textBox_FacModeGit.Text = "---";
  4748. Class_Motor_Ver.Mode = "---";
  4749. Class_Motor_Ver.SN = "---";
  4750. Class_Motor_Ver.HW = "---";
  4751. Class_Motor_Ver.FW = "---";
  4752. Class_Motor_Ver.Special = "---";
  4753. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  4754. }
  4755. /// <summary>
  4756. /// 生产模式写入生产信息
  4757. /// </summary>
  4758. /// <param name="sender"></param>
  4759. /// <param name="e"></param>
  4760. private void Button_FacModeSetMacDate_Click(object sender, EventArgs e)
  4761. {
  4762. var MACArray = new byte[32];
  4763. string MacDefaultInfo = "";
  4764. string MacAddDefaultInfo = "";
  4765. string MacDateDefaultInfo = DateTime.Now.ToString("yyyyMMdd");
  4766. string MacPPDefaultInfo = "";
  4767. do
  4768. {
  4769. //填入生产商
  4770. if (toolStripTextBox_MAC.Text == string.Empty)
  4771. {
  4772. break;
  4773. }
  4774. MacDefaultInfo = toolStripTextBox_MAC.Text;
  4775. for (ushort i = 0; i < MacDefaultInfo.Length; i++)
  4776. {
  4777. MACArray[i] = (byte)MacDefaultInfo[i];
  4778. }
  4779. if (MacDefaultInfo.Length < 8)
  4780. {
  4781. MACArray[MacDefaultInfo.Length] = (byte)'.';
  4782. for (ushort i = 0; i < 8 - MacDefaultInfo.Length - 1; i++)
  4783. {
  4784. MACArray[MacDefaultInfo.Length + 1 + i] = 0x20;
  4785. }
  4786. }
  4787. //填入生产地
  4788. if (toolStripTextBoxMACAddr.Text == string.Empty)
  4789. {
  4790. break;
  4791. }
  4792. MacAddDefaultInfo = toolStripTextBoxMACAddr.Text;
  4793. for (ushort i = 0; i < MacAddDefaultInfo.Length; i++)
  4794. {
  4795. MACArray[8 + i] = (byte)MacAddDefaultInfo[i];
  4796. }
  4797. if (MacAddDefaultInfo.Length < 8)
  4798. {
  4799. MACArray[MacAddDefaultInfo.Length + 8] = (byte)'.';
  4800. for (ushort i = 0; i < 8 - MacAddDefaultInfo.Length - 1; i++)
  4801. {
  4802. MACArray[MacAddDefaultInfo.Length + 1 + i + 8] = 0x20;
  4803. }
  4804. }
  4805. //填入生产日期
  4806. if (toolStripTextBox_MACDate.Text == string.Empty)
  4807. {
  4808. break;
  4809. }
  4810. MacDateDefaultInfo = toolStripTextBox_MACDate.Text;
  4811. for (ushort i = 0; i < MacDateDefaultInfo.Length; i++)
  4812. {
  4813. MACArray[16 + i] = (byte)MacDateDefaultInfo[i];
  4814. }
  4815. if (MacDateDefaultInfo.Length < 8)
  4816. {
  4817. MACArray[MacDateDefaultInfo.Length + 16] = (byte)'.';
  4818. for (ushort i = 0; i < 8 - MacDateDefaultInfo.Length - 1; i++)
  4819. {
  4820. MACArray[MacDateDefaultInfo.Length + 1 + i + 16] = 0x20;
  4821. }
  4822. }
  4823. //填入产品标识
  4824. if (toolStripTextBox_MACPD.Text == string.Empty)
  4825. {
  4826. break;
  4827. }
  4828. MacPPDefaultInfo = toolStripTextBox_MACPD.Text;
  4829. for (ushort i = 0; i < MacPPDefaultInfo.Length; i++)
  4830. {
  4831. MACArray[24 + i] = (byte)MacPPDefaultInfo[i];
  4832. }
  4833. if (MacPPDefaultInfo.Length < 8)
  4834. {
  4835. MACArray[MacPPDefaultInfo.Length + 24] = (byte)'.';
  4836. for (ushort i = 0; i < 8 - MacPPDefaultInfo.Length - 1; i++)
  4837. {
  4838. MACArray[MacPPDefaultInfo.Length + 1 + i + 24] = 0x20;
  4839. }
  4840. }
  4841. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  4842. return;
  4843. } while (false);
  4844. timer_500ms.Enabled = false;
  4845. MessageBox.Show("生产信息配置不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4846. timer_500ms.Enabled = true;
  4847. }
  4848. /// <summary>
  4849. /// 建立线程执行一次数据导出
  4850. /// </summary>
  4851. /// <param name=""></param>
  4852. private void SamplesModeExport_Task()
  4853. {
  4854. string[] AssistParams = new string[15];
  4855. do
  4856. {
  4857. //读取一次马达参数
  4858. richTextBox_MotorParam.Clear();
  4859. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break; ;
  4860. ACK_WaitCnt = 0;
  4861. while (ACK_WaitCnt <= 2) //1s
  4862. {
  4863. if (richTextBox_MotorParam.Text != string.Empty)
  4864. break;
  4865. }
  4866. if (richTextBox_MotorParam.Text == string.Empty)
  4867. {
  4868. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break;
  4869. ACK_WaitCnt = 0;
  4870. while (ACK_WaitCnt <= 2) //1s
  4871. {
  4872. if (richTextBox_MotorParam.Text != string.Empty)
  4873. break;
  4874. }
  4875. if (richTextBox_MotorParam.Text == string.Empty)
  4876. {
  4877. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break;
  4878. ACK_WaitCnt = 0;
  4879. while (ACK_WaitCnt <= 2) //1s
  4880. {
  4881. if (richTextBox_MotorParam.Text != string.Empty)
  4882. break;
  4883. }
  4884. }
  4885. }
  4886. //读取一次整车参数
  4887. richTextBox_BikeParam.Clear();
  4888. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  4889. ACK_WaitCnt = 0;
  4890. while (ACK_WaitCnt <= 2) //1s
  4891. {
  4892. if (richTextBox_BikeParam.Text != string.Empty)
  4893. break;
  4894. }
  4895. if (richTextBox_BikeParam.Text == string.Empty)
  4896. {
  4897. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  4898. ACK_WaitCnt = 0;
  4899. while (ACK_WaitCnt <= 2) //1s
  4900. {
  4901. if (richTextBox_BikeParam.Text != string.Empty)
  4902. break;
  4903. }
  4904. if (richTextBox_BikeParam.Text == string.Empty)
  4905. {
  4906. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  4907. ACK_WaitCnt = 0;
  4908. while (ACK_WaitCnt <= 2) //1s
  4909. {
  4910. if (richTextBox_BikeParam.Text != string.Empty)
  4911. break;
  4912. }
  4913. }
  4914. }
  4915. //读取一次整车参数2
  4916. richTextBox_BikeParam2.Clear();
  4917. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null)) break;
  4918. ACK_WaitCnt = 0;
  4919. while (ACK_WaitCnt <= 2) //1s
  4920. {
  4921. if (richTextBox_BikeParam2.Text != string.Empty)
  4922. break;
  4923. }
  4924. if (richTextBox_BikeParam2.Text == string.Empty)
  4925. {
  4926. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null)) break;
  4927. ACK_WaitCnt = 0;
  4928. while (ACK_WaitCnt <= 2) //1s
  4929. {
  4930. if (richTextBox_BikeParam2.Text != string.Empty)
  4931. break;
  4932. }
  4933. if (richTextBox_BikeParam2.Text == string.Empty)
  4934. {
  4935. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null)) break;
  4936. ACK_WaitCnt = 0;
  4937. while (ACK_WaitCnt <= 2) //1s
  4938. {
  4939. if (richTextBox_BikeParam2.Text != string.Empty)
  4940. break;
  4941. }
  4942. }
  4943. }
  4944. //读取一次控制参数
  4945. richTextBox_ControlParam.Clear();
  4946. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  4947. ACK_WaitCnt = 0;
  4948. while (ACK_WaitCnt <= 2) //1s
  4949. {
  4950. if (richTextBox_ControlParam.Text != string.Empty)
  4951. break;
  4952. }
  4953. if (richTextBox_ControlParam.Text == string.Empty)
  4954. {
  4955. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  4956. ACK_WaitCnt = 0;
  4957. while (ACK_WaitCnt <= 2) //1s
  4958. {
  4959. if (richTextBox_ControlParam.Text != string.Empty)
  4960. break;
  4961. }
  4962. if (richTextBox_ControlParam.Text == string.Empty)
  4963. {
  4964. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  4965. ACK_WaitCnt = 0;
  4966. while (ACK_WaitCnt <= 2) //1s
  4967. {
  4968. if (richTextBox_ControlParam.Text != string.Empty)
  4969. break;
  4970. }
  4971. }
  4972. }
  4973. //查询传感器
  4974. richTextBox_SensorParam.Clear();
  4975. textBox_FacModeSensorADC0.Text = "";
  4976. textBox_FacModeSensorADC1.Text = "";
  4977. textBox_FacModeSensorADC2.Text = "";
  4978. textBox_FacModeSensorADC3.Text = "";
  4979. textBox_FacModeSensorADC4.Text = "";
  4980. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  4981. ACK_WaitCnt = 0;
  4982. while (ACK_WaitCnt <= 2) //1s
  4983. {
  4984. if (richTextBox_SensorParam.Text != string.Empty)
  4985. break;
  4986. }
  4987. if (richTextBox_SensorParam.Text == string.Empty)
  4988. {
  4989. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  4990. ACK_WaitCnt = 0;
  4991. while (ACK_WaitCnt <= 2) //1s
  4992. {
  4993. if (richTextBox_SensorParam.Text != string.Empty)
  4994. break;
  4995. }
  4996. if (richTextBox_SensorParam.Text == string.Empty)
  4997. {
  4998. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  4999. ACK_WaitCnt = 0;
  5000. while (ACK_WaitCnt <= 2) //1s
  5001. {
  5002. if (richTextBox_SensorParam.Text != string.Empty)
  5003. break;
  5004. }
  5005. }
  5006. }
  5007. //读取15次助力参数
  5008. for (int i = 1; i <= 15; i++)
  5009. {
  5010. var ConfigParam = new byte[4];
  5011. richTextBox_AssistParam.Clear();
  5012. ConfigParam[0] = (byte)(i & 0xFF);
  5013. ConfigParam[1] = (byte)(i >> 8);
  5014. ConfigParam[2] = (byte)(((i >= 5) ? 5 : i) & 0xFF);
  5015. ConfigParam[3] = (byte)(((i >= 5) ? 5 : i) >> 8);
  5016. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  5017. ACK_WaitCnt = 0;
  5018. while (ACK_WaitCnt <= 2) //1s
  5019. {
  5020. if (richTextBox_AssistParam.Text != string.Empty)
  5021. break;
  5022. }
  5023. if (richTextBox_AssistParam.Text == string.Empty)
  5024. {
  5025. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  5026. ACK_WaitCnt = 0;
  5027. while (ACK_WaitCnt <= 2) //1s
  5028. {
  5029. if (richTextBox_AssistParam.Text != string.Empty)
  5030. break;
  5031. }
  5032. if (richTextBox_AssistParam.Text == string.Empty)
  5033. {
  5034. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  5035. ACK_WaitCnt = 0;
  5036. while (ACK_WaitCnt <= 2) //1s
  5037. {
  5038. if (richTextBox_AssistParam.Text != string.Empty)
  5039. break;
  5040. }
  5041. }
  5042. }
  5043. AssistParams[i - 1] = richTextBox_AssistParam.Text + "\r\n";
  5044. }
  5045. #if true
  5046. //读取一次用户骑行参数
  5047. richTextBox_UsrRidesParam.Clear();
  5048. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  5049. ACK_WaitCnt = 0;
  5050. while (ACK_WaitCnt <= 2) //1s
  5051. {
  5052. if (richTextBox_UsrRidesParam.Text != string.Empty)
  5053. break;
  5054. }
  5055. if (richTextBox_UsrRidesParam.Text == string.Empty)
  5056. {
  5057. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null)) break;
  5058. ACK_WaitCnt = 0;
  5059. while (ACK_WaitCnt <= 2) //1s
  5060. {
  5061. if (richTextBox_UsrRidesParam.Text != string.Empty)
  5062. break;
  5063. }
  5064. if (richTextBox_UsrRidesParam.Text == string.Empty)
  5065. {
  5066. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null)) break;
  5067. ACK_WaitCnt = 0;
  5068. while (ACK_WaitCnt <= 2) //1s
  5069. {
  5070. if (richTextBox_UsrRidesParam.Text != string.Empty)
  5071. break;
  5072. }
  5073. }
  5074. }
  5075. #endif
  5076. //读取一次调试信息
  5077. richTextBox_DebugParam.Clear();
  5078. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  5079. ACK_WaitCnt = 0;
  5080. while (ACK_WaitCnt <= 2) //1s
  5081. {
  5082. if (richTextBox_DebugParam.Text != string.Empty)
  5083. break;
  5084. }
  5085. if (richTextBox_DebugParam.Text == string.Empty)
  5086. {
  5087. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  5088. ACK_WaitCnt = 0;
  5089. while (ACK_WaitCnt <= 2) //1s
  5090. {
  5091. if (richTextBox_DebugParam.Text != string.Empty)
  5092. break;
  5093. }
  5094. if (richTextBox_DebugParam.Text == string.Empty)
  5095. {
  5096. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  5097. ACK_WaitCnt = 0;
  5098. while (ACK_WaitCnt <= 2) //1s
  5099. {
  5100. if (richTextBox_DebugParam.Text != string.Empty)
  5101. break;
  5102. }
  5103. }
  5104. }
  5105. //读取一次历史信息
  5106. richTextBox_Record.Clear();
  5107. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  5108. ACK_WaitCnt = 0;
  5109. while (ACK_WaitCnt <= 2) //1s
  5110. {
  5111. if (richTextBox_Record.Text != string.Empty)
  5112. break;
  5113. }
  5114. if (richTextBox_Record.Text == string.Empty)
  5115. {
  5116. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  5117. ACK_WaitCnt = 0;
  5118. while (ACK_WaitCnt <= 2) //1s
  5119. {
  5120. if (richTextBox_Record.Text != string.Empty)
  5121. break;
  5122. }
  5123. if (richTextBox_Record.Text == string.Empty)
  5124. {
  5125. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  5126. ACK_WaitCnt = 0;
  5127. while (ACK_WaitCnt <= 2) //1s
  5128. {
  5129. if (richTextBox_Record.Text != string.Empty)
  5130. break;
  5131. }
  5132. }
  5133. }
  5134. //读取一次电机运行信息
  5135. var CtrlCode = new byte[2];
  5136. CtrlCode[0] = 0x00;
  5137. CtrlCode[1] = 0xF0;
  5138. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode)) break;
  5139. ACK_WaitCnt = 0;
  5140. while (ACK_WaitCnt <= 2) //1s
  5141. {
  5142. if (textBox_RunInfo_BikeSpeed.Text != string.Empty)
  5143. break;
  5144. }
  5145. if (textBox_RunInfo_BikeSpeed.Text == string.Empty)
  5146. {
  5147. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode)) break;
  5148. ACK_WaitCnt = 0;
  5149. while (ACK_WaitCnt <= 2) //1s
  5150. {
  5151. if (textBox_RunInfo_BikeSpeed.Text != string.Empty)
  5152. break;
  5153. }
  5154. if (textBox_RunInfo_BikeSpeed.Text == string.Empty)
  5155. {
  5156. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode)) break;
  5157. ACK_WaitCnt = 0;
  5158. while (ACK_WaitCnt <= 2) //1s
  5159. {
  5160. if (textBox_RunInfo_BikeSpeed.Text != string.Empty)
  5161. break;
  5162. }
  5163. }
  5164. }
  5165. //读取一次版本信息
  5166. textBox_Model.Text = "---";
  5167. textBox_SN.Text = "---";
  5168. textBox_HW.Text = "---";
  5169. textBox_FW.Text = "---";
  5170. textBox_SP.Text = "---";
  5171. textBox_OBC_ReadModel.Text = "---";
  5172. textBox_OBC_ReadSN.Text = "---";
  5173. textBox_OBC_ReadHW.Text = "---";
  5174. textBox_OBC_ReadFW.Text = "---";
  5175. textBox_FacModeName.Text = "---";
  5176. textBox_FacModeNum.Text = "---";
  5177. textBox_FacModeHW.Text = "---";
  5178. textBox_FacModeFW.Text = "---";
  5179. textBox_FacModeSP.Text = "---";
  5180. Class_Motor_Ver.Mode = "---";
  5181. Class_Motor_Ver.SN = "---";
  5182. Class_Motor_Ver.HW = "---";
  5183. Class_Motor_Ver.FW = "---";
  5184. Class_Motor_Ver.Special = "---";
  5185. if (!mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null)) break;
  5186. ACK_WaitCnt = 0;
  5187. while (ACK_WaitCnt <= 2) //1s
  5188. {
  5189. if ((textBox_Model.Text != string.Empty) && (textBox_SN.Text != string.Empty) && (textBox_HW.Text != string.Empty) && (textBox_SP.Text != string.Empty) && (textBox_FW.Text != string.Empty))
  5190. break;
  5191. }
  5192. if (textBox_Model.Text == string.Empty)
  5193. {
  5194. if (!mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null)) break;
  5195. ACK_WaitCnt = 0;
  5196. while (ACK_WaitCnt <= 2) //1s
  5197. {
  5198. if ((textBox_Model.Text != string.Empty) && (textBox_SN.Text != string.Empty) && (textBox_HW.Text != string.Empty) && (textBox_SP.Text != string.Empty) && (textBox_FW.Text != string.Empty))
  5199. break;
  5200. }
  5201. if (textBox_Model.Text == string.Empty)
  5202. {
  5203. if (!mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null)) break;
  5204. ACK_WaitCnt = 0;
  5205. while (ACK_WaitCnt <= 2) //1s
  5206. {
  5207. if ((textBox_Model.Text != string.Empty) && (textBox_SN.Text != string.Empty) && (textBox_HW.Text != string.Empty) && (textBox_SP.Text != string.Empty) && (textBox_FW.Text != string.Empty))
  5208. break;
  5209. }
  5210. }
  5211. }
  5212. //读取一次生产信息
  5213. textBox_MAC.Text = "";
  5214. textBox_MACAdd.Text = "";
  5215. textBox_MACDate.Text = "";
  5216. textBox_PP.Text = "";
  5217. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  5218. ACK_WaitCnt = 0;
  5219. while (ACK_WaitCnt <= 2) //1s
  5220. {
  5221. if (textBox_MAC.Text != string.Empty)
  5222. break;
  5223. }
  5224. if (textBox_MAC.Text == string.Empty)
  5225. {
  5226. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  5227. ACK_WaitCnt = 0;
  5228. while (ACK_WaitCnt <= 2) //1s
  5229. {
  5230. if (textBox_MAC.Text != string.Empty)
  5231. break;
  5232. }
  5233. if (textBox_MAC.Text == string.Empty)
  5234. {
  5235. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  5236. ACK_WaitCnt = 0;
  5237. while (ACK_WaitCnt <= 2) //1s
  5238. {
  5239. if (textBox_MAC.Text != string.Empty)
  5240. break;
  5241. }
  5242. }
  5243. }
  5244. //读取一次自定义信息
  5245. textBox_User1.Text = "---";
  5246. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  5247. ACK_WaitCnt = 0;
  5248. while (ACK_WaitCnt <= 2) //1s
  5249. {
  5250. if (textBox_User1.Text != string.Empty)
  5251. break;
  5252. }
  5253. if (textBox_User1.Text == string.Empty)
  5254. {
  5255. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  5256. ACK_WaitCnt = 0;
  5257. while (ACK_WaitCnt <= 2) //1s
  5258. {
  5259. if (textBox_User1.Text != string.Empty)
  5260. break;
  5261. }
  5262. if (textBox_User1.Text == string.Empty)
  5263. {
  5264. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  5265. ACK_WaitCnt = 0;
  5266. while (ACK_WaitCnt <= 2) //1s
  5267. {
  5268. if (textBox_User1.Text != string.Empty)
  5269. break;
  5270. }
  5271. }
  5272. }
  5273. textBox_User2.Text = "---";
  5274. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  5275. ACK_WaitCnt = 0;
  5276. while (ACK_WaitCnt <= 2) //1s
  5277. {
  5278. if (textBox_User2.Text != string.Empty)
  5279. break;
  5280. }
  5281. if (textBox_User2.Text == string.Empty)
  5282. {
  5283. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  5284. ACK_WaitCnt = 0;
  5285. while (ACK_WaitCnt <= 2) //1s
  5286. {
  5287. if (textBox_User2.Text != string.Empty)
  5288. break;
  5289. }
  5290. if (textBox_User2.Text == string.Empty)
  5291. {
  5292. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  5293. ACK_WaitCnt = 0;
  5294. while (ACK_WaitCnt <= 2) //1s
  5295. {
  5296. if (textBox_User2.Text != string.Empty)
  5297. break;
  5298. }
  5299. }
  5300. }
  5301. textBox_User3.Text = "---";
  5302. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  5303. ACK_WaitCnt = 0;
  5304. while (ACK_WaitCnt <= 2) //1s
  5305. {
  5306. if (textBox_User3.Text != string.Empty)
  5307. break;
  5308. }
  5309. if (textBox_User3.Text == string.Empty)
  5310. {
  5311. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  5312. ACK_WaitCnt = 0;
  5313. while (ACK_WaitCnt <= 2) //1s
  5314. {
  5315. if (textBox_User3.Text != string.Empty)
  5316. break;
  5317. }
  5318. if (textBox_User3.Text == string.Empty)
  5319. {
  5320. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  5321. ACK_WaitCnt = 0;
  5322. while (ACK_WaitCnt <= 2) //1s
  5323. {
  5324. if (textBox_User3.Text != string.Empty)
  5325. break;
  5326. }
  5327. }
  5328. }
  5329. //读取一次密钥
  5330. textBox_Key.Text = "---";
  5331. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  5332. ACK_WaitCnt = 0;
  5333. while (ACK_WaitCnt <= 2) //1s
  5334. {
  5335. if (textBox_Key.Text != string.Empty)
  5336. break;
  5337. }
  5338. if (textBox_Key.Text == string.Empty)
  5339. {
  5340. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  5341. ACK_WaitCnt = 0;
  5342. while (ACK_WaitCnt <= 2) //1s
  5343. {
  5344. if (textBox_Key.Text != string.Empty)
  5345. break;
  5346. }
  5347. if (textBox_Key.Text == string.Empty)
  5348. {
  5349. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  5350. ACK_WaitCnt = 0;
  5351. while (ACK_WaitCnt <= 2) //1s
  5352. {
  5353. if (textBox_Key.Text != string.Empty)
  5354. break;
  5355. }
  5356. }
  5357. }
  5358. //读取一次存储标志
  5359. radioButton_EE_SaveYes.Checked = false;
  5360. radioButton_EE_SaveNo.Checked = false;
  5361. radioButton_SIP_SaveYes.Checked = false;
  5362. radioButton_SIP_SaveNo.Checked = false;
  5363. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  5364. ACK_WaitCnt = 0;
  5365. while (ACK_WaitCnt <= 2) //1s
  5366. {
  5367. if ((radioButton_EE_SaveYes.Checked | radioButton_EE_SaveNo.Checked | radioButton_SIP_SaveYes.Checked | radioButton_SIP_SaveNo.Checked) == true)
  5368. break;
  5369. }
  5370. if ((radioButton_EE_SaveYes.Checked | radioButton_EE_SaveNo.Checked | radioButton_SIP_SaveYes.Checked | radioButton_SIP_SaveNo.Checked) == false)
  5371. {
  5372. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  5373. ACK_WaitCnt = 0;
  5374. while (ACK_WaitCnt <= 2) //1s
  5375. {
  5376. if ((radioButton_EE_SaveYes.Checked | radioButton_EE_SaveNo.Checked | radioButton_SIP_SaveYes.Checked | radioButton_SIP_SaveNo.Checked) == true)
  5377. break;
  5378. }
  5379. if ((radioButton_EE_SaveYes.Checked | radioButton_EE_SaveNo.Checked | radioButton_SIP_SaveYes.Checked | radioButton_SIP_SaveNo.Checked) == false)
  5380. {
  5381. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  5382. ACK_WaitCnt = 0;
  5383. while (ACK_WaitCnt <= 2) //1s
  5384. {
  5385. if ((radioButton_EE_SaveYes.Checked | radioButton_EE_SaveNo.Checked | radioButton_SIP_SaveYes.Checked | radioButton_SIP_SaveNo.Checked) == true)
  5386. break;
  5387. }
  5388. }
  5389. }
  5390. //读取一次MOS内阻校准参数
  5391. foreach (Control c in groupBox21.Controls)
  5392. {
  5393. if (c is TextBox)
  5394. c.Text = "";
  5395. }
  5396. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  5397. ACK_WaitCnt = 0;
  5398. while (ACK_WaitCnt <= 2) //1s
  5399. {
  5400. if (textBox_MOS_K1.Text != string.Empty)
  5401. break;
  5402. }
  5403. if (textBox_MOS_K1.Text == string.Empty)
  5404. {
  5405. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null)) break;
  5406. ACK_WaitCnt = 0;
  5407. while (ACK_WaitCnt <= 2) //1s
  5408. {
  5409. if (textBox_MOS_K1.Text != string.Empty)
  5410. break;
  5411. }
  5412. if (textBox_MOS_K1.Text == string.Empty)
  5413. {
  5414. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null)) break;
  5415. ACK_WaitCnt = 0;
  5416. while (ACK_WaitCnt <= 2) //1s
  5417. {
  5418. if (textBox_MOS_K1.Text != string.Empty)
  5419. break;
  5420. }
  5421. }
  5422. }
  5423. //提示检查
  5424. #if false
  5425. timer_1s.Enabled = false;
  5426. if (MessageBox.Show("请检查信息是否完整!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  5427. {
  5428. MessageBox.Show("请检查参数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5429. timer_1s.Enabled = true;
  5430. return;
  5431. }
  5432. timer_1s.Enabled = true;
  5433. Delay_ms(200);
  5434. #endif
  5435. //判断数据是否有效
  5436. if ((textBox_FacModeName.Text == "---") || (textBox_FacModeNum.Text == "---"))
  5437. {
  5438. MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5439. break;
  5440. }
  5441. if ((textBox_FacModeName.Text == string.Empty) || (textBox_FacModeNum.Text == string.Empty))
  5442. {
  5443. MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5444. break;
  5445. }
  5446. //设置文件存储路径
  5447. string Save_Path = localInfo.LocalPath + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
  5448. string PD_PathName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_"); ;
  5449. Save_Path += PD_PathName;
  5450. if (!Directory.Exists(Save_Path))
  5451. Directory.CreateDirectory(Save_Path);
  5452. //保存页面
  5453. string PIC_SaveFileName = "";
  5454. Double scaleX = PrimaryScreen.ScaleX;
  5455. Double scaleY = PrimaryScreen.ScaleY;
  5456. //保存页面
  5457. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  5458. Graphics g = Graphics.FromImage(bit);
  5459. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  5460. PIC_SaveFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_测试页面" + ".png";
  5461. bit.Save(PIC_SaveFileName);
  5462. //保存数据
  5463. string DataFileName = "";
  5464. string FileInfo = "";
  5465. DataFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_记录数据" + ".txt";
  5466. FileInfo += "计算机名称:\r\n" + label_Computername.Text + "\r\n";
  5467. FileInfo += "软件运行时间:\r\n" + stopwatch.ElapsedMilliseconds.ToString() + " ms" + "\r\n";
  5468. FileInfo += "软件运行次数:\r\n" + File.ReadAllText(localInfo.LocalPath + localInfo.PowerTimesFilename) + "\r\n";
  5469. FileInfo += "系统时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  5470. FileInfo += "\r\n";
  5471. FileInfo += "[电机信息]\r\n";
  5472. FileInfo += "电机型号: " + textBox_FacModeName.Text + "\r\n";
  5473. FileInfo += "电机编号: " + textBox_FacModeNum.Text + "\r\n";
  5474. FileInfo += "硬件版本: " + textBox_HW.Text + "\r\n";
  5475. FileInfo += "软件版本: " + textBox_FW.Text + "\r\n";
  5476. FileInfo += "软件标识: " + textBox_SP.Text + "\r\n";
  5477. FileInfo += "Git信息: " + textBox_FacModeGit.Text + "\r\n";
  5478. FileInfo += "\r\n";
  5479. FileInfo += "[马达参数]\r\n";
  5480. FileInfo += richTextBox_MotorParam.Text + "\r\n";
  5481. FileInfo += "\r\n";
  5482. FileInfo += "[整车参数]\r\n";
  5483. FileInfo += richTextBox_BikeParam.Text + "\r\n";
  5484. FileInfo += "\r\n";
  5485. FileInfo += "[控制参数]\r\n";
  5486. FileInfo += richTextBox_ControlParam.Text + "\r\n";
  5487. FileInfo += "\r\n";
  5488. FileInfo += "[传感器参数]\r\n";
  5489. FileInfo += richTextBox_SensorParam.Text + "\r\n";
  5490. FileInfo += "\r\n";
  5491. FileInfo += "[助力参数]\r\n";
  5492. for (int i = 0; i < 15; i++)
  5493. {
  5494. FileInfo += AssistParams[i] + "\r\n";
  5495. }
  5496. FileInfo += "[调试参数]\r\n";
  5497. FileInfo += richTextBox_DebugParam.Text + "\r\n";
  5498. FileInfo += "\r\n";
  5499. FileInfo += "[历史信息]\r\n";
  5500. FileInfo += richTextBox_Record.Text + "\r\n";
  5501. FileInfo += "\r\n";
  5502. FileInfo += "[MOS内阻校准参数]\r\n";
  5503. FileInfo += textBox_MOS_K1.Text + ", ";
  5504. FileInfo += textBox_MOS_K2.Text + ", ";
  5505. FileInfo += textBox_MOS_K3.Text + ", ";
  5506. FileInfo += textBox_MOS_K4.Text + ", ";
  5507. FileInfo += textBox_MOS_K5.Text + ", ";
  5508. FileInfo += textBox_MOS_R1.Text + ", ";
  5509. FileInfo += textBox_MOS_R2.Text + ", ";
  5510. FileInfo += textBox_MOS_R3.Text + "\r\n";
  5511. FileInfo += "\r\n";
  5512. FileInfo += "[整车参数2]\r\n";
  5513. FileInfo += richTextBox_BikeParam2.Text + "\r\n";
  5514. FileInfo += "\r\n";
  5515. FileInfo += "[用户骑行参数]\r\n";
  5516. FileInfo += richTextBox_UsrRidesParam.Text + "\r\n";
  5517. FileInfo += "\r\n";
  5518. FileInfo += "[生产信息]\r\n";
  5519. FileInfo += "生产商: " + textBox_MAC.Text + "\r\n";
  5520. FileInfo += "生产地: " + textBox_MACAdd.Text + "\r\n";
  5521. FileInfo += "生产日期: " + textBox_MACDate.Text + "\r\n";
  5522. FileInfo += "产品标识: " + textBox_PP.Text + "\r\n";
  5523. FileInfo += "\r\n";
  5524. FileInfo += "[自定义信息]\r\n";
  5525. FileInfo += "自定义1: " + textBox_User1.Text + "\r\n";
  5526. FileInfo += "自定义2: " + textBox_User2.Text + "\r\n";
  5527. FileInfo += "自定义3: " + textBox_User3.Text + "\r\n";
  5528. FileInfo += "\r\n";
  5529. FileInfo += "[校验密钥]\r\n";
  5530. FileInfo += textBox_Key.Text + "\r\n";
  5531. FileInfo += "\r\n";
  5532. FileInfo += "[存储标志]\r\n";
  5533. FileInfo += "EEPROM: " + ((radioButton_EE_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  5534. FileInfo += "SIP: " + ((radioButton_SIP_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  5535. FileInfo += "\r\n";
  5536. FileInfo += Local_HdInformation;
  5537. FileInfo += "\r\n";
  5538. FileInfo += "文件格式: V2.0\r\n";
  5539. System.IO.File.WriteAllText(DataFileName, FileInfo);
  5540. Delay_ms(1000);
  5541. MessageBoxTimeOut.Show("存储完成!", "提示", 600, MessageBoxButtons.OK, MessageBoxIcon.Information);
  5542. //数据上传
  5543. if (myFtp.IsNetConnected == true)
  5544. {
  5545. string DataNow = DateTime.Now.ToString("yyyy-MM-dd");
  5546. //检查路径
  5547. if (myFtp.DirectoryExist("\\", toolStripTextBox_ServerPath.Text) == false)
  5548. {
  5549. myFtp.MakeDir(toolStripTextBox_ServerPath.Text);
  5550. }
  5551. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text, "Samples") == false)
  5552. {
  5553. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples");
  5554. }
  5555. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples", DataNow) == false)
  5556. {
  5557. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow);
  5558. }
  5559. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow, PD_PathName) == false)
  5560. {
  5561. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  5562. }
  5563. //上传文件
  5564. bool result1 = myFtp.UploadFile(PIC_SaveFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  5565. bool result2 = myFtp.UploadFile(DataFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  5566. if ((result1 & result2) == true)
  5567. {
  5568. MessageBoxTimeOut.Show("数据已上传!", "提示", 600, MessageBoxButtons.OK, MessageBoxIcon.Information);
  5569. }
  5570. else
  5571. {
  5572. MessageBox.Show("数据上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5573. }
  5574. }
  5575. else
  5576. {
  5577. MessageBox.Show("服务器断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5578. }
  5579. Button_FacModeSaveResult.Text = "保存数据";
  5580. Button_FacModeSaveResult.Enabled = true;
  5581. return;
  5582. } while (false);
  5583. MessageBox.Show("保存异常!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5584. Button_FacModeSaveResult.Text = "保存数据";
  5585. Button_FacModeSaveResult.Enabled = true;
  5586. }
  5587. /// <summary>
  5588. /// 生产模式保存测试页面
  5589. /// </summary>
  5590. /// <param name="sender"></param>
  5591. /// <param name="e"></param>
  5592. private void Button_FacModeSaveResult_Click(object sender, EventArgs e)
  5593. {
  5594. Button_FacModeSaveResult.Text = "存储中…";
  5595. Button_FacModeSaveResult.Enabled = false;
  5596. //创建线程,执行数据导出
  5597. Thread th = new Thread(SamplesModeExport_Task);
  5598. th.Start();
  5599. }
  5600. /// <summary>
  5601. /// 工具箱页面保存
  5602. /// </summary>
  5603. /// <param name="sender"></param>
  5604. /// <param name="e"></param>
  5605. private void 页面保存ToolStripMenuItem_Click(object sender, EventArgs e)
  5606. {
  5607. Double scaleX = PrimaryScreen.ScaleX;
  5608. Double scaleY = PrimaryScreen.ScaleY;
  5609. //保存页面
  5610. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  5611. Graphics g = Graphics.FromImage(bit);
  5612. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  5613. SaveFileDialog sf = new SaveFileDialog();
  5614. sf.Title = "页面保存";
  5615. sf.FileName = "MotorInfo_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".png";
  5616. sf.Filter = "图片|*.png";
  5617. timer_500ms.Enabled = false;
  5618. if (sf.ShowDialog() == DialogResult.OK)
  5619. {
  5620. bit.Save(sf.FileName);//默认保存格式为PNG,保存成jpg格式质量不是很好
  5621. }
  5622. timer_500ms.Enabled = true;
  5623. }
  5624. /// <summary>
  5625. /// 生产模式关机
  5626. /// </summary>
  5627. /// <param name="sender"></param>
  5628. /// <param name="e"></param>
  5629. private void Button_FacModePowerOff_Click(object sender, EventArgs e)
  5630. {
  5631. var Code_Off = new byte[5];
  5632. var Code_Reset = new byte[5];
  5633. Code_Off[0] = (byte)'O';
  5634. Code_Off[1] = (byte)'F';
  5635. Code_Off[2] = (byte)'F';
  5636. Code_Off[3] = (byte)'.';
  5637. Code_Off[4] = (byte)'.';
  5638. Code_Reset[0] = (byte)'R';
  5639. Code_Reset[1] = (byte)'E';
  5640. Code_Reset[2] = (byte)'S';
  5641. Code_Reset[3] = (byte)'E';
  5642. Code_Reset[4] = (byte)'T';
  5643. timer_500ms.Enabled = false;
  5644. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  5645. {
  5646. timer_500ms.Enabled = true;
  5647. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  5648. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  5649. PowerOffAckStatus = false;
  5650. Delay_ms(250);
  5651. int TryCnt = 3;
  5652. while ((TryCnt--) >= 0)
  5653. {
  5654. if (!PowerOffAckStatus)
  5655. {
  5656. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  5657. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  5658. PowerOffAckStatus = false;
  5659. Delay_ms(250);
  5660. }
  5661. else break;
  5662. }
  5663. if (PowerOffAckStatus)
  5664. {
  5665. timer_500ms.Enabled = false;
  5666. MessageBox.Show("已关机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  5667. timer_500ms.Enabled = true;
  5668. }
  5669. else
  5670. {
  5671. timer_500ms.Enabled = false;
  5672. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5673. timer_500ms.Enabled = true;
  5674. }
  5675. }
  5676. timer_500ms.Enabled = true;
  5677. }
  5678. //仪表电源键按下
  5679. private void button_OBC_ButtonPower_Click(object sender, EventArgs e)
  5680. {
  5681. var Code = new byte[2];
  5682. Code[0] = 0;
  5683. Code[1] = 0b00100000;
  5684. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5685. }
  5686. /// <summary>
  5687. /// 仪表加键按下
  5688. /// </summary>
  5689. /// <param name="sender"></param>
  5690. /// <param name="e"></param>
  5691. private void button_OBC_ButtonAcc_Click(object sender, EventArgs e)
  5692. {
  5693. var Code = new byte[2];
  5694. Code[0] = 0;
  5695. Code[1] = 0b00010000;
  5696. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5697. }
  5698. /// <summary>
  5699. /// 仪表减键按下
  5700. /// </summary>
  5701. /// <param name="sender"></param>
  5702. /// <param name="e"></param>
  5703. private void button_OBC_ButtonDec_Click(object sender, EventArgs e)
  5704. {
  5705. var Code = new byte[2];
  5706. Code[0] = 0;
  5707. Code[1] = 0b00001000;
  5708. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5709. }
  5710. /// <summary>
  5711. /// 仪表Walk键按下
  5712. /// </summary>
  5713. /// <param name="sender"></param>
  5714. /// <param name="e"></param>
  5715. private void button_OBC_ButtonWalk_Click(object sender, EventArgs e)
  5716. {
  5717. var Code = new byte[2];
  5718. Code[0] = 0;
  5719. Code[1] = 0b00000100;
  5720. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5721. }
  5722. /// <summary>
  5723. /// 仪表Light键按下
  5724. /// </summary>
  5725. /// <param name="sender"></param>
  5726. /// <param name="e"></param>
  5727. private void button_OBC_ButtonLight_Click(object sender, EventArgs e)
  5728. {
  5729. var Code = new byte[2];
  5730. Code[0] = 0;
  5731. Code[1] = 0b00000010;
  5732. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5733. }
  5734. /// <summary>
  5735. /// 仪表Set键按下
  5736. /// </summary>
  5737. /// <param name="sender"></param>
  5738. /// <param name="e"></param>
  5739. private void button_OBC_ButtonSet_Click(object sender, EventArgs e)
  5740. {
  5741. var Code = new byte[2];
  5742. Code[0] = 0;
  5743. Code[1] = 0b00000001;
  5744. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5745. }
  5746. /// <summary>
  5747. /// 导出电机故障日志
  5748. /// </summary>
  5749. /// <param name="sender"></param>
  5750. /// <param name="e"></param>
  5751. private void button_ExportLog_Click(object sender, EventArgs e)
  5752. {
  5753. var Address = new byte[4];
  5754. UInt32 Address_Begin;
  5755. UInt32 Addres_End;
  5756. string textBox_Address_Begin = textBox_LogAddrBegin.Text;
  5757. string textBox_Address_End = textBox_LogAddrEnd.Text;
  5758. richTextBox_Record.Clear();
  5759. textBox_LogAddrBegin.ReadOnly = true;
  5760. textBox_LogAddrEnd.ReadOnly = true;
  5761. if (!mySerialProcess.mySerial.IsOpen)
  5762. {
  5763. timer_500ms.Enabled = false;
  5764. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5765. timer_500ms.Enabled = true;
  5766. return;
  5767. }
  5768. if ((textBox_Address_Begin == string.Empty) || (textBox_Address_End == string.Empty))
  5769. {
  5770. timer_500ms.Enabled = false;
  5771. MessageBox.Show("请输入日志存储起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5772. timer_500ms.Enabled = true;
  5773. return;
  5774. }
  5775. else
  5776. {
  5777. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin, false);
  5778. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  5779. Address = mySerialProcess.HexStringToBytes(textBox_Address_End, false);
  5780. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  5781. if (Addres_End <= Address_Begin)
  5782. {
  5783. timer_500ms.Enabled = false;
  5784. MessageBox.Show("结束地址应大于起始地址!", "提示");
  5785. timer_500ms.Enabled = true;
  5786. return;
  5787. }
  5788. else if (((Addres_End - Address_Begin + 1) % 128) != 0) //
  5789. {
  5790. timer_500ms.Enabled = false;
  5791. MessageBox.Show("(结束地址 - 起始地址 + 1)应为128整数倍!", "提示");
  5792. timer_500ms.Enabled = true;
  5793. return;
  5794. }
  5795. else
  5796. {
  5797. UInt32 ReadCount = 0;
  5798. button_ExportLog.Text = "导出中...";
  5799. button_ExportLog.Enabled = false;
  5800. ReadCount = (Addres_End - Address_Begin + 1) / 128;
  5801. for (ushort i = 0; i < ReadCount; i++)
  5802. {
  5803. var SendByte = new byte[8];
  5804. UInt32 Address_Temp_Begin;
  5805. UInt32 Address_Temp_End;
  5806. Address_Temp_Begin = Address_Begin + 128 * (UInt32)i;
  5807. SendByte[0] = (byte)(Address_Temp_Begin >> 24);
  5808. SendByte[1] = (byte)(Address_Temp_Begin >> 16);
  5809. SendByte[2] = (byte)(Address_Temp_Begin >> 8);
  5810. SendByte[3] = (byte)(Address_Temp_Begin);
  5811. Address_Temp_End = Address_Temp_Begin + 127;
  5812. SendByte[4] = (byte)(Address_Temp_End >> 24);
  5813. SendByte[5] = (byte)(Address_Temp_End >> 16);
  5814. SendByte[6] = (byte)(Address_Temp_End >> 8);
  5815. SendByte[7] = (byte)(Address_Temp_End);
  5816. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  5817. Delay_ms(200);//Thread.Sleep(200);
  5818. }
  5819. button_ExportLog.Text = "导出日志";
  5820. button_ExportLog.Enabled = true;
  5821. }
  5822. }
  5823. }
  5824. /// <summary>
  5825. /// 保存日志信息
  5826. /// </summary>
  5827. /// <param name="sender"></param>
  5828. /// <param name="e"></param>
  5829. private void button_SaveRecordInfo_Click(object sender, EventArgs e)
  5830. {
  5831. string SaveInfo = "";
  5832. if (richTextBox_Record.Text == string.Empty)
  5833. {
  5834. timer_500ms.Enabled = false;
  5835. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  5836. timer_500ms.Enabled = true;
  5837. return;
  5838. }
  5839. //获取保存信息
  5840. SaveInfo += "读取时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  5841. SaveInfo += "电机型号:" + textBox_FacModeName.Text + "\r\n";
  5842. SaveInfo += "电机SN:" + textBox_FacModeNum.Text + "\r\n";
  5843. SaveInfo += "硬件版本:" + textBox_FacModeHW.Text + "\r\n";
  5844. SaveInfo += "软件版本:" + textBox_FacModeFW.Text + "\r\n";
  5845. SaveInfo += "\r\n";
  5846. SaveInfo += richTextBox_Record.Text;
  5847. //设置保存路径和文件名
  5848. SaveFileDialog sf = new SaveFileDialog();
  5849. sf.Title = "数据保存";
  5850. sf.FileName = "MotorLog_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".ttlog";
  5851. sf.FileName.Replace(" ", "");
  5852. sf.Filter = "日志|*.ttlog";
  5853. if (sf.ShowDialog() == DialogResult.OK)
  5854. {
  5855. System.IO.File.AppendAllText(sf.FileName, SaveInfo);
  5856. }
  5857. }
  5858. /// <summary>
  5859. /// 双击修改日志起始地址
  5860. /// </summary>
  5861. /// <param name="sender"></param>
  5862. /// <param name="e"></param>
  5863. private void label_LogAddrBegin_DoubleClick_1(object sender, EventArgs e)
  5864. {
  5865. textBox_LogAddrBegin.ReadOnly = false;
  5866. }
  5867. /// <summary>
  5868. /// 双击修改日志结束地址
  5869. /// </summary>
  5870. /// <param name="sender"></param>
  5871. /// <param name="e"></param>
  5872. private void label88_DoubleClick(object sender, EventArgs e)
  5873. {
  5874. textBox_LogAddrEnd.ReadOnly = false;
  5875. }
  5876. /// <summary>
  5877. /// 存储器自动读取选择
  5878. /// </summary>
  5879. /// <param name="sender"></param>
  5880. /// <param name="e"></param>
  5881. private void checkBox_ReadRanFlash_AutoSW_CheckedChanged(object sender, EventArgs e)
  5882. {
  5883. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  5884. {
  5885. //检查串口是否打开
  5886. if (!mySerialProcess.mySerial.IsOpen)
  5887. {
  5888. timer_500ms.Enabled = false;
  5889. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5890. timer_500ms.Enabled = true;
  5891. checkBox_ReadRanFlash_AutoSW.Checked = false;
  5892. return;
  5893. }
  5894. }
  5895. }
  5896. /// <summary>
  5897. /// 系统开机按钮
  5898. /// </summary>
  5899. /// <param name="sender"></param>
  5900. /// <param name="e"></param>
  5901. private void 开机ToolStripMenuItem_Click(object sender, EventArgs e)
  5902. {
  5903. byte[] Data = new byte[1];
  5904. Data[0] = 0xF1;
  5905. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  5906. }
  5907. /// <summary>
  5908. /// 系统关机按钮
  5909. /// </summary>
  5910. /// <param name="sender"></param>
  5911. /// <param name="e"></param>
  5912. private void 关机ToolStripMenuItem_Click(object sender, EventArgs e)
  5913. {
  5914. byte[] Data = new byte[1];
  5915. Data[0] = 0xF0;
  5916. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  5917. }
  5918. /// <summary>
  5919. /// 连接开机选择
  5920. /// </summary>
  5921. /// <param name="sender"></param>
  5922. /// <param name="e"></param>
  5923. private void 连接开机ToolStripMenuItem_Click(object sender, EventArgs e)
  5924. {
  5925. //输入用户名
  5926. EnterForm1.ShowDialog();
  5927. try
  5928. {
  5929. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5930. {
  5931. if (EnterForm1.comboBox_User.Text == "管理员")
  5932. {
  5933. 连接开机ToolStripMenuItem.Checked = !连接开机ToolStripMenuItem.Checked;
  5934. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5935. }
  5936. else
  5937. {
  5938. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5939. }
  5940. }
  5941. else
  5942. {
  5943. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5944. }
  5945. }
  5946. catch (Exception)
  5947. {
  5948. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5949. }
  5950. }
  5951. /// <summary>
  5952. /// 断开关机选择
  5953. /// </summary>
  5954. /// <param name="sender"></param>
  5955. /// <param name="e"></param>
  5956. private void 断开关机ToolStripMenuItem_Click(object sender, EventArgs e)
  5957. {
  5958. //输入用户名
  5959. EnterForm1.ShowDialog();
  5960. try
  5961. {
  5962. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5963. {
  5964. if (EnterForm1.comboBox_User.Text == "管理员")
  5965. {
  5966. 断开关机ToolStripMenuItem.Checked = !断开关机ToolStripMenuItem.Checked;
  5967. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5968. }
  5969. else
  5970. {
  5971. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5972. }
  5973. }
  5974. else
  5975. {
  5976. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5977. }
  5978. }
  5979. catch (Exception)
  5980. {
  5981. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5982. }
  5983. }
  5984. /// <summary>
  5985. /// 识别通讯盒选择
  5986. /// </summary>
  5987. /// <param name="sender"></param>
  5988. /// <param name="e"></param>
  5989. private void 识别通讯盒ToolStripMenuItem_Click(object sender, EventArgs e)
  5990. {
  5991. //输入用户名
  5992. EnterForm1.ShowDialog();
  5993. try
  5994. {
  5995. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5996. {
  5997. if (EnterForm1.comboBox_User.Text == "管理员")
  5998. {
  5999. 识别通讯盒ToolStripMenuItem.Checked = !识别通讯盒ToolStripMenuItem.Checked;
  6000. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  6001. }
  6002. else
  6003. {
  6004. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  6005. }
  6006. }
  6007. else
  6008. {
  6009. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  6010. }
  6011. }
  6012. catch (Exception)
  6013. {
  6014. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  6015. }
  6016. }
  6017. /// <summary>
  6018. /// 将配置信息导出为cfg文件
  6019. /// </summary>
  6020. private void ConfigFileSave(bool DeleteFlag, string FileName)
  6021. {
  6022. if (DeleteFlag)
  6023. {
  6024. if (File.Exists(FileName))
  6025. File.Delete(FileName);
  6026. }
  6027. string CfgFileInfo = "";
  6028. CfgFileInfo += "[PortSet]" + "\r\n";
  6029. CfgFileInfo += "PortNum:" + toolStripComboBox_ComNum.Text + "\r\n";
  6030. CfgFileInfo += "PortBaudrate:" + "115200" + "\r\n";
  6031. CfgFileInfo += "AutoOn:" + 连接开机ToolStripMenuItem.Checked.ToString() + "\r\n";
  6032. CfgFileInfo += "AutoOff:" + 断开关机ToolStripMenuItem.Checked.ToString() + "\r\n";
  6033. CfgFileInfo += "CheckCDL:" + 识别通讯盒ToolStripMenuItem.Checked.ToString() + "\r\n";
  6034. CfgFileInfo += "\r\n";
  6035. CfgFileInfo += "[Option]" + "\r\n";
  6036. CfgFileInfo += "SaveWhenWrite:" + 写入存储ToolStripMenuItem.Checked.ToString() + "\r\n";
  6037. CfgFileInfo += "\r\n";
  6038. CfgFileInfo += "[ServerSet]" + "\r\n";
  6039. CfgFileInfo += "PathName:" + toolStripTextBox_ServerPath.Text + "\r\n";
  6040. CfgFileInfo += "\r\n";
  6041. CfgFileInfo += "[MacInfo]" + "\r\n";
  6042. CfgFileInfo += "MacName:" + toolStripTextBox_MAC.Text + "\r\n";
  6043. CfgFileInfo += "MacAddress:" + toolStripTextBoxMACAddr.Text + "\r\n";
  6044. CfgFileInfo += "MacDate:" + toolStripTextBox_MACDate.Text + "\r\n";
  6045. CfgFileInfo += "MacPdInfo:" + toolStripTextBox_MACPD.Text + "\r\n";
  6046. CfgFileInfo += "\r\n";
  6047. CfgFileInfo += "[LogAddress]" + "\r\n";
  6048. CfgFileInfo += "BeginAddress:" + textBox_LogAddrBegin.Text + "\r\n";
  6049. CfgFileInfo += "EndAddress:" + textBox_LogAddrEnd.Text + "\r\n";
  6050. CfgFileInfo += "\r\n";
  6051. CfgFileInfo += "[MotorType]" + "\r\n";
  6052. CfgFileInfo += "MidMotor1:" + 中置电机MIGIC_ToolStripMenuItem.Checked.ToString() + "\r\n";
  6053. CfgFileInfo += "MidMotor2:" + 中置电机VP_ToolStripMenuItem.Checked.ToString() + "\r\n";
  6054. CfgFileInfo += "HubMotor:" + 轮毂电机ToolStripMenuItem.Checked.ToString() + "\r\n";
  6055. CfgFileInfo += "\r\n";
  6056. CfgFileInfo += "[CheckValue]" + "\r\n";
  6057. CfgFileInfo += "Voltage:" + toolStripTextBox_ThVol.Text + "\r\n";
  6058. CfgFileInfo += "Current:" + toolStripTextBox_ThCur.Text + "\r\n";
  6059. CfgFileInfo += "MotorSpeed:" + toolStripTextBox_ThSpeed.Text + "\r\n";
  6060. CfgFileInfo += "Torque:" + toolStripTextBox_ThTor.Text + "\r\n";
  6061. CfgFileInfo += "Cadence:" + toolStripTextBox_ThCad.Text + "\r\n";
  6062. CfgFileInfo += "BikeSpeed:" + toolStripTextBox_ThBikeSpeed.Text + "\r\n";
  6063. CfgFileInfo += "T_PCB:" + toolStripTextBox_ThT_PCB.Text + "\r\n";
  6064. CfgFileInfo += "T_MCU:" + toolStripTextBox_ThT_MCU.Text + "\r\n";
  6065. CfgFileInfo += "T_Motor:" + toolStripTextBox_ThT_Motor.Text + "\r\n";
  6066. CfgFileInfo += "\r\n";
  6067. CfgFileInfo += "[MosCalK]" + "\r\n";
  6068. CfgFileInfo += "K1-K5:" + toolStripTextBox_MosCalK.Text + "\r\n";
  6069. CfgFileInfo += "MOS1:" + toolStripTextBox_MOS1.Text + "\r\n";
  6070. CfgFileInfo += "MOS2:" + toolStripTextBox_MOS2.Text + "\r\n";
  6071. CfgFileInfo += "MOS3:" + toolStripTextBox_MOS3.Text + "\r\n";
  6072. CfgFileInfo += "\r\n";
  6073. CfgFileInfo += "[ProtocolType]" + "\r\n";
  6074. CfgFileInfo += "CAN:" + cANToolStripMenuItem.Checked.ToString() + "\r\n";
  6075. CfgFileInfo += "UART:" + uARTToolStripMenuItem.Checked.ToString() + "\r\n";
  6076. CfgFileInfo += "\r\n";
  6077. CfgFileInfo += "[AutoUpdate]" + "\r\n";
  6078. CfgFileInfo += "AutoUpdate:" + 打开ToolStripMenuItem.Checked.ToString() + "\r\n";
  6079. CfgFileInfo += "\r\n";
  6080. CfgFileInfo += "[AngleCal]" + "\r\n";
  6081. CfgFileInfo += "MaxDiffLimit:" + textBox_AngleDiffTh.Text + "\r\n";
  6082. CfgFileInfo += "ZeroDiffLimit:" + textBox_AngleZeroTh.Text + "\r\n";
  6083. System.IO.File.WriteAllText(FileName, CfgFileInfo);
  6084. }
  6085. /// <summary>
  6086. /// 配置状态更新,点击时保存
  6087. /// </summary>
  6088. private void ConfigFileSave_Click(object sender, EventArgs e)
  6089. {
  6090. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  6091. }
  6092. /// <summary>
  6093. /// 文本框修改结束,回车保存
  6094. /// </summary>
  6095. /// <param name="sender"></param>
  6096. /// <param name="e"></param>
  6097. private void ConfigFileSave_KeyDown(object sender, KeyEventArgs e)
  6098. {
  6099. if (e.KeyCode == Keys.Enter)
  6100. {
  6101. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  6102. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  6103. }
  6104. }
  6105. /// <summary>
  6106. /// 弹出扫码按钮
  6107. /// </summary>
  6108. /// <param name="sender"></param>
  6109. /// <param name="e"></param>
  6110. private void button_ScanCode_Click(object sender, EventArgs e)
  6111. {
  6112. Scan scan_form = new Scan();
  6113. scan_form.ShowDialog();
  6114. do
  6115. {
  6116. if (scan_form.textBox_Scan.Text == string.Empty)
  6117. {
  6118. timer_500ms.Enabled = false;
  6119. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6120. timer_500ms.Enabled = true;
  6121. break;
  6122. }
  6123. string ScanInfo = scan_form.textBox_Scan.Text;
  6124. string regexInfo = "";
  6125. string[] InfoList = { "" };
  6126. try
  6127. {
  6128. if (中置电机MIGIC_ToolStripMenuItem.Checked == true)
  6129. {
  6130. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  6131. InfoList = Regex.Split(ScanInfo, regexInfo, RegexOptions.IgnoreCase);
  6132. }
  6133. else if (中置电机VP_ToolStripMenuItem.Checked == true)
  6134. {
  6135. Regex regex = new Regex(@"^M[12][0-9](0?[1-9]|1[0-2])((0?[1-9])|((1|2)[0-9])|30|31)[A-Z]\d{4}[A-Z][A-Z]?$");
  6136. if (ScanInfo.Contains(" "))
  6137. {
  6138. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  6139. string Mode = InfoList[0];
  6140. string Sn = InfoList[1];
  6141. if (regex.IsMatch(Sn) == false)
  6142. {
  6143. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN格式错误" + "\r\n");
  6144. label_FacModeStatus.Text = "存在故障!";
  6145. label_FacModeResult.BackColor = Color.Red;
  6146. label_FacModeResult.Text = "标签格式错误";
  6147. Delay_ms(500);
  6148. //存储异常并上传
  6149. FacMode_Stop(false);
  6150. return;
  6151. }
  6152. }
  6153. else
  6154. {
  6155. MessageBox.Show("SN格式错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  6156. return;
  6157. }
  6158. }
  6159. else if (轮毂电机ToolStripMenuItem.Checked == true)
  6160. {
  6161. if (!ScanInfo.Contains("/")) //老编码规则
  6162. {
  6163. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  6164. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  6165. string Spec = InfoList[1];
  6166. string Sn = InfoList[2];
  6167. InfoList[0] = Model.Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  6168. InfoList[1] = Sn;
  6169. }
  6170. else //新编码规则
  6171. {
  6172. Dictionary<string, string> Dic_Ver = new Dictionary<string, string>
  6173. {
  6174. { "01", "A" },
  6175. { "02", "B" },
  6176. { "03", "C" },
  6177. { "04", "D" },
  6178. { "05", "E" },
  6179. { "06", "F" },
  6180. { "07", "G" },
  6181. { "08", "H" },
  6182. { "09", "I" }
  6183. };
  6184. Dictionary<string, string> Dic_Vol = new Dictionary<string, string>
  6185. {
  6186. { "24V", "A" },
  6187. { "36V", "B" },
  6188. { "42V", "C" },
  6189. { "48V", "D" },
  6190. { "52V", "E" },
  6191. { "60V", "F" }
  6192. };
  6193. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  6194. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  6195. string Spec = InfoList[1].Replace("-", "").Replace("/", "");
  6196. string Sn = InfoList[2];
  6197. InfoList[0] = Model[2] + Dic_Ver[Model.Substring(3, 2)] + Model[5] + Dic_Ver[Model.Substring(6, 2)] + Model[9];
  6198. InfoList[0] += Dic_Vol[Spec.Substring(0, 3)] + Spec.Substring(3, 3) + Spec.Substring(13, 4) + Spec.Substring(Spec.Length - 4, 3);
  6199. InfoList[1] = Sn;
  6200. }
  6201. }
  6202. }
  6203. catch (Exception)
  6204. {
  6205. MessageBox.Show("格式错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  6206. return;
  6207. }
  6208. if (InfoList.Length >= 2)
  6209. {
  6210. //写入型号
  6211. textBox_FacModeName.Text = InfoList[0];
  6212. string Mode = textBox_FacModeName.Text;
  6213. var ModeArray = new byte[16];
  6214. for (ushort i = 0; i < Mode.Length; i++)
  6215. {
  6216. ModeArray[i] = (byte)Mode[i];
  6217. }
  6218. if (Mode.Length < 16)
  6219. {
  6220. ModeArray[Mode.Length] = (byte)'.';
  6221. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  6222. {
  6223. ModeArray[Mode.Length + 1 + i] = 0x20;
  6224. }
  6225. }
  6226. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6227. //写入SN
  6228. textBox_FacModeNum.Text = InfoList[1];
  6229. string SN = textBox_FacModeNum.Text;
  6230. var SNArray = new byte[16];
  6231. for (ushort i = 0; i < SN.Length; i++)
  6232. {
  6233. SNArray[i] = (byte)SN[i];
  6234. }
  6235. if (SN.Length < 16)
  6236. {
  6237. SNArray[SN.Length] = (byte)'.';
  6238. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  6239. {
  6240. SNArray[SN.Length + 1 + i] = 0x20;
  6241. }
  6242. }
  6243. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6244. }
  6245. else
  6246. {
  6247. timer_500ms.Enabled = false;
  6248. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6249. timer_500ms.Enabled = true;
  6250. break;
  6251. }
  6252. } while (false);
  6253. scan_form.Dispose();
  6254. }
  6255. /// <summary>
  6256. /// 切换电机类型
  6257. /// </summary>
  6258. /// <param name="sender"></param>
  6259. /// <param name="e"></param>
  6260. private void 中置电机ToolStripMenuItem_Click(object sender, EventArgs e)
  6261. {
  6262. 中置电机MIGIC_ToolStripMenuItem.Checked = true;
  6263. 中置电机VP_ToolStripMenuItem.Checked = false;
  6264. 轮毂电机ToolStripMenuItem.Checked = false;
  6265. toolStripTextBox_MACPD.Text = "MM_MC1";
  6266. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  6267. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  6268. }
  6269. private void 中置电机小牙盘ToolStripMenuItem_Click(object sender, EventArgs e)
  6270. {
  6271. 中置电机MIGIC_ToolStripMenuItem.Checked = false;
  6272. 中置电机VP_ToolStripMenuItem.Checked = true;
  6273. 轮毂电机ToolStripMenuItem.Checked = false;
  6274. toolStripTextBox_MACPD.Text = "MM_MV1";
  6275. toolStripTextBox_ServerPath.Text = "MC_VP_TEST";
  6276. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  6277. }
  6278. /// <summary>
  6279. /// 切换电机类型
  6280. /// </summary>
  6281. /// <param name="sender"></param>
  6282. /// <param name="e"></param>
  6283. private void 轮毂电机ToolStripMenuItem_Click(object sender, EventArgs e)
  6284. {
  6285. 中置电机MIGIC_ToolStripMenuItem.Checked = false;
  6286. 中置电机VP_ToolStripMenuItem.Checked = false;
  6287. 轮毂电机ToolStripMenuItem.Checked = true;
  6288. toolStripTextBox_MACPD.Text = "GF_250_1";
  6289. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  6290. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  6291. }
  6292. /// <summary>
  6293. /// 获取配置文件日期
  6294. /// </summary>
  6295. /// <param name="DisAll"></param>
  6296. private void GetDateList(bool DisAll)
  6297. {
  6298. string[] DateList = { "" };
  6299. //从服务器更新日期列表
  6300. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  6301. {
  6302. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
  6303. }
  6304. //从本地更新日期列表
  6305. else
  6306. {
  6307. DateList = Directory.GetDirectories(localInfo.LocalPath + "\\" + localInfo.CfgPathName);
  6308. }
  6309. comboBox_FacModeCfgDate.Items.Clear();
  6310. comboBox_CheckModeCfgDate.Items.Clear();
  6311. //日期列表加载
  6312. if (DisAll == true)
  6313. {
  6314. comboBox_FacModeCfgDate.Items.Add("显示近期");
  6315. comboBox_CheckModeCfgDate.Items.Add("显示近期");
  6316. comboBox_FacModeCfgDate.Items.Add("---");
  6317. comboBox_CheckModeCfgDate.Items.Add("---");
  6318. foreach (var file in DateList)
  6319. {
  6320. comboBox_FacModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  6321. comboBox_CheckModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  6322. }
  6323. }
  6324. else
  6325. {
  6326. if (DateList.Length > 10)
  6327. {
  6328. comboBox_FacModeCfgDate.Items.Add("显示全部");
  6329. comboBox_CheckModeCfgDate.Items.Add("显示全部");
  6330. comboBox_FacModeCfgDate.Items.Add("---");
  6331. comboBox_CheckModeCfgDate.Items.Add("---");
  6332. }
  6333. for (int i = (DateList.Length > 10) ? (DateList.Length - 10) : 0; i < DateList.Length; i++)//显示最近10个日期
  6334. {
  6335. comboBox_FacModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  6336. comboBox_CheckModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  6337. }
  6338. }
  6339. }
  6340. /// <summary>
  6341. /// 获取配置文件列表
  6342. /// </summary>
  6343. /// <param name="date"></param>
  6344. private void GetFileListFrom(string date)
  6345. {
  6346. string[] FileList = { "" };
  6347. //从服务器更新文件列表
  6348. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  6349. {
  6350. FileList = myFtp.GetFileNameList(toolStripTextBox_ServerPath.Text + "/cfg/" + date);
  6351. }
  6352. else
  6353. {
  6354. FileList = Directory.GetFiles(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + date);
  6355. }
  6356. comboBox_CheckModeCfgFile.Items.Clear();
  6357. comboBox_FacModeCfgFile.Items.Clear();
  6358. foreach (var file in FileList)
  6359. {
  6360. if (file.Contains(".ttcfg"))
  6361. {
  6362. comboBox_CheckModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  6363. comboBox_FacModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  6364. }
  6365. }
  6366. }
  6367. /// <summary>
  6368. /// 检验模式选择文件日期
  6369. /// </summary>
  6370. /// <param name="sender"></param>
  6371. /// <param name="e"></param>
  6372. private void comboBox_CheckModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  6373. {
  6374. if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示全部")
  6375. {
  6376. GetDateList(true);
  6377. }
  6378. else if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示近期")
  6379. {
  6380. GetDateList(false);
  6381. }
  6382. else
  6383. {
  6384. comboBox_CheckModeCfgFile.Text = "";
  6385. GetFileListFrom(comboBox_CheckModeCfgDate.SelectedItem.ToString());
  6386. }
  6387. }
  6388. /// <summary>
  6389. /// 配置模式选择文件日期
  6390. /// </summary>
  6391. /// <param name="sender"></param>
  6392. /// <param name="e"></param>
  6393. private void comboBox_FacModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  6394. {
  6395. if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示全部")
  6396. {
  6397. GetDateList(true);
  6398. }
  6399. else if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示近期")
  6400. {
  6401. GetDateList(false);
  6402. }
  6403. else
  6404. {
  6405. comboBox_FacModeCfgFile.Text = "";
  6406. GetFileListFrom(comboBox_FacModeCfgDate.SelectedItem.ToString());
  6407. }
  6408. }
  6409. /// <summary>
  6410. /// 选中量产模式
  6411. /// </summary>
  6412. /// <param name="sender"></param>
  6413. /// <param name="e"></param>
  6414. private void tabControl1_Selected(object sender, TabControlEventArgs e)
  6415. {
  6416. //更新生产配置文件目录
  6417. GetDateList(false);
  6418. }
  6419. /// <summary>
  6420. /// 量产测试结束
  6421. /// </summary>
  6422. /// <param name=""></param>
  6423. private void FacMode_Stop(bool OK_Flag)
  6424. {
  6425. //打开开始按钮
  6426. button__FacMode_Start.Enabled = true;
  6427. textBox_FacModeScan.Enabled = true;
  6428. var Code = new byte[32];//发送的指令数据
  6429. //退出配置模式
  6430. Code[0] = 0x00;
  6431. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6432. Delay_ms(1000);
  6433. //系统关机
  6434. Code[0] = 0xF0;
  6435. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6436. //关闭串口
  6437. if (mySerialProcess.SerialClose(false))
  6438. {
  6439. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "串口已关闭" + "\r\n");
  6440. toolStripComboBox_ComNum.Enabled = true;
  6441. toolStripComboBox_Baudrate.Enabled = true;
  6442. 刷新ToolStripMenuItem.Enabled = true;
  6443. 连接ToolStripMenuItem.Text = "连接";
  6444. 连接ToolStripMenuItem.Checked = false;
  6445. label_COM_Sta.Text = "连接状态:未连接";
  6446. label_PortStatus.BackColor = Color.Red;
  6447. }
  6448. //路径设置
  6449. string LocalSavePath = "";
  6450. string ServerSavePath = "";
  6451. if (OK_Flag)
  6452. {
  6453. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "OK\\";
  6454. if (样机测试ToolStripMenuItem.Checked == false)
  6455. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/OK/";
  6456. else
  6457. ServerSavePath = toolStripTextBox_ServerPath.Text + "/Samples/OK/";
  6458. }
  6459. else
  6460. {
  6461. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "FAIL\\";
  6462. if (样机测试ToolStripMenuItem.Checked == false)
  6463. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/FAIL/";
  6464. else
  6465. ServerSavePath = toolStripTextBox_ServerPath.Text + "/Samples/FAIL/";
  6466. }
  6467. if (Directory.Exists(LocalSavePath) == false)
  6468. {
  6469. Directory.CreateDirectory(LocalSavePath);
  6470. }
  6471. //保存和上传
  6472. string LogSavePath = "";
  6473. string LogSaveFileName = "";
  6474. string ProductInfo = textBox_FacModeScan.Text.Replace(" ", "_").Replace("/", "-");
  6475. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  6476. if (Directory.Exists(LogSavePath) == false)
  6477. {
  6478. Directory.CreateDirectory(LogSavePath);
  6479. }
  6480. //测试页面
  6481. Double scaleX = PrimaryScreen.ScaleX;
  6482. Double scaleY = PrimaryScreen.ScaleY;
  6483. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  6484. Graphics g = Graphics.FromImage(bit);
  6485. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  6486. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  6487. bit.Save(LogSaveFileName);
  6488. //上传测试页面到服务器
  6489. if (myFtp.IsNetConnected == true)
  6490. {
  6491. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  6492. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  6493. {
  6494. myFtp.MakeDir(ServerSavePath + DateNow);
  6495. }
  6496. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  6497. {
  6498. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  6499. }
  6500. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  6501. if (result == true)
  6502. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  6503. }
  6504. else
  6505. {
  6506. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  6507. }
  6508. //测试记录
  6509. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  6510. string file_str = "";
  6511. file_str += "计算机名称:\r\n" + label_Computername.Text + "\r\n";
  6512. file_str += "软件运行时间:\r\n" + stopwatch.ElapsedMilliseconds.ToString() + " ms" + "\r\n";
  6513. file_str += "软件运行次数:\r\n" + File.ReadAllText(localInfo.LocalPath + localInfo.PowerTimesFilename) + "\r\n";
  6514. file_str += "系统时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  6515. file_str += "检验记录:\r\n" + richTextBox_FacModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  6516. file_str += "检验结果:\r\n" + label_FacModeResult.Text + "\r\n\r\n";
  6517. file_str += Local_HdInformation;
  6518. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  6519. //上传测试记录到服务器
  6520. if (myFtp.IsNetConnected == true)
  6521. {
  6522. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  6523. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  6524. {
  6525. myFtp.MakeDir(ServerSavePath + DateNow);
  6526. }
  6527. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  6528. {
  6529. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  6530. }
  6531. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  6532. if (result == true)
  6533. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  6534. }
  6535. else
  6536. {
  6537. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  6538. }
  6539. //扫码框清空
  6540. textBox_FacModeScan.Text = "";
  6541. }
  6542. /// <summary>
  6543. /// 量产测试开始
  6544. /// </summary>
  6545. /// <param name="sender"></param>
  6546. /// <param name="e"></param>
  6547. private void button__FacMode_Start_Click(object sender, EventArgs e)
  6548. {
  6549. //关闭测试项目编辑
  6550. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  6551. foreach (Control c in groupBox2.Controls)
  6552. {
  6553. if (c is CheckBox)
  6554. c.Enabled = false;
  6555. }
  6556. WriteLockStatus = true;
  6557. //检查配置文件
  6558. if (样机测试ToolStripMenuItem.Checked == false)
  6559. {
  6560. if (comboBox_FacModeCfgFile.Text == "")
  6561. {
  6562. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6563. return;
  6564. }
  6565. }
  6566. //开始测试
  6567. TestStart();
  6568. }
  6569. /// <summary>
  6570. /// 测试子函数
  6571. /// </summary>
  6572. private void TestStart()
  6573. {
  6574. //初始化标签
  6575. FacModelLabelInit();
  6576. richTextBox_FacModeLog.Clear();
  6577. //按钮禁止操作
  6578. button__FacMode_Start.Enabled = false;
  6579. textBox_FacModeScan.Enabled = false;
  6580. //记录配置文件
  6581. if (样机测试ToolStripMenuItem.Checked == false)
  6582. richTextBox_FacModeLog.AppendText("配置文件:" + comboBox_FacModeCfgDate.Text + " / " + comboBox_FacModeCfgFile.Text + "\r\n");
  6583. else
  6584. richTextBox_FacModeLog.AppendText("样机测试,无配置文件" + "\r\n");
  6585. //检查打标信息格式
  6586. Delay_ms(500);
  6587. if (样机测试ToolStripMenuItem.Checked == false) //量产时严格检查标签格式
  6588. {
  6589. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  6590. if (textBox_FacModeScan.Text == string.Empty)
  6591. {
  6592. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6593. button__FacMode_Start.Enabled = true;
  6594. textBox_FacModeScan.Enabled = true;
  6595. return;
  6596. }
  6597. try
  6598. {
  6599. if (中置电机MIGIC_ToolStripMenuItem.Checked == true)
  6600. {
  6601. if (textBox_FacModeScan.Text.Split(' ').Length != 7)
  6602. {
  6603. label_FacModeStatus.Text = "存在故障!";
  6604. label_FacModeResult.BackColor = Color.Red;
  6605. label_FacModeResult.Text = "标签格式错误";
  6606. button__FacMode_Start.Enabled = true;
  6607. textBox_FacModeScan.Enabled = true;
  6608. return;
  6609. }
  6610. }
  6611. else if (中置电机VP_ToolStripMenuItem.Checked == true)
  6612. {
  6613. if (textBox_FacModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 2)
  6614. {
  6615. label_FacModeStatus.Text = "存在故障!";
  6616. label_FacModeResult.BackColor = Color.Red;
  6617. label_FacModeResult.Text = "标签格式错误";
  6618. button__FacMode_Start.Enabled = true;
  6619. textBox_FacModeScan.Enabled = true;
  6620. return;
  6621. }
  6622. }
  6623. else if (轮毂电机ToolStripMenuItem.Checked == true)
  6624. {
  6625. if (textBox_FacModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  6626. {
  6627. label_FacModeStatus.Text = "存在故障!";
  6628. label_FacModeResult.BackColor = Color.Red;
  6629. label_FacModeResult.Text = "标签格式错误";
  6630. button__FacMode_Start.Enabled = true;
  6631. textBox_FacModeScan.Enabled = true;
  6632. return;
  6633. }
  6634. }
  6635. }
  6636. catch (System.Exception ex)
  6637. {
  6638. label_FacModeStatus.Text = "存在故障!";
  6639. label_FacModeResult.BackColor = Color.Red;
  6640. label_FacModeResult.Text = "标签格式错误";
  6641. button__FacMode_Start.Enabled = true;
  6642. textBox_FacModeScan.Enabled = true;
  6643. System.Windows.Forms.MessageBox.Show(ex.Message);
  6644. return;
  6645. }
  6646. }
  6647. else //样机测试仅按两个空格分离
  6648. {
  6649. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查标签信息" + "\r\n");
  6650. if (textBox_FacModeScan.Text == string.Empty)
  6651. {
  6652. MessageBox.Show("请输入标签信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6653. button__FacMode_Start.Enabled = true;
  6654. textBox_FacModeScan.Enabled = true;
  6655. return;
  6656. }
  6657. try
  6658. {
  6659. if (textBox_FacModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 2)
  6660. {
  6661. label_FacModeStatus.Text = "存在故障!";
  6662. label_FacModeResult.BackColor = Color.Red;
  6663. label_FacModeResult.Text = "标签格式错误";
  6664. button__FacMode_Start.Enabled = true;
  6665. textBox_FacModeScan.Enabled = true;
  6666. return;
  6667. }
  6668. }
  6669. catch (System.Exception ex)
  6670. {
  6671. label_FacModeStatus.Text = "存在故障!";
  6672. label_FacModeResult.BackColor = Color.Red;
  6673. label_FacModeResult.Text = "标签格式错误";
  6674. button__FacMode_Start.Enabled = true;
  6675. textBox_FacModeScan.Enabled = true;
  6676. System.Windows.Forms.MessageBox.Show(ex.Message);
  6677. return;
  6678. }
  6679. }
  6680. //打开串口
  6681. if (mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false))
  6682. {
  6683. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "打开串口成功" + "\r\n");
  6684. toolStripComboBox_ComNum.Enabled = false;
  6685. toolStripComboBox_Baudrate.Enabled = false;
  6686. 刷新ToolStripMenuItem.Enabled = false;
  6687. 连接ToolStripMenuItem.Text = "断开";
  6688. 连接ToolStripMenuItem.Checked = true;
  6689. label_COM_Sta.Text = toolStripComboBox_ComNum.Text + "已连接," + toolStripComboBox_Baudrate.Text;
  6690. label_PortStatus.BackColor = Color.Green;
  6691. }
  6692. if (!mySerialProcess.mySerial.IsOpen)
  6693. {
  6694. MessageBox.Show("请检查串口连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6695. //按钮禁止操作
  6696. button__FacMode_Start.Enabled = true;
  6697. textBox_FacModeScan.Enabled = true;
  6698. return;
  6699. }
  6700. //流水号计数
  6701. int serial = Convert.ToInt32(label_FacModeSerial.Text);
  6702. serial += 1;
  6703. label_FacModeSerial.Text = serial.ToString();
  6704. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, serial.ToString());
  6705. //创建线程,执行测试任务
  6706. Thread th = new Thread(FacModeTest_Task);
  6707. th.Start();
  6708. }
  6709. /// <summary>
  6710. /// 执行一次测试任务
  6711. /// </summary>
  6712. private void FacModeTest_Task()
  6713. {
  6714. //开始测试
  6715. richTextBox_FacModeLog.AppendText("产品标签:" + textBox_FacModeScan.Text + "\r\n");
  6716. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  6717. //变量定义
  6718. var Code = new byte[255];//发送的指令数据
  6719. label_FacModeStatus.Text = "开始测试";
  6720. Delay_ms(500);
  6721. label_FacModeStatus.Text = "系统开机";
  6722. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  6723. if (uARTToolStripMenuItem.Checked)
  6724. {
  6725. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送复位指令,切换联动装置盒波特率" + "\r\n");
  6726. Code[0] = (byte)'R';
  6727. Code[1] = (byte)'E';
  6728. Code[2] = (byte)'S';
  6729. Code[3] = (byte)'E';
  6730. Code[4] = (byte)'T';
  6731. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  6732. Delay_ms(500);
  6733. }
  6734. //发送开机指令
  6735. //确保测试前先关机,发送关机指令再发送开机指令
  6736. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  6737. Code[0] = 0xF0;
  6738. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6739. Delay_ms(4000);
  6740. BootInfo = "";
  6741. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  6742. Code[0] = 0xF1;
  6743. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6744. ACK_WaitCnt = 0;
  6745. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  6746. while (ACK_WaitCnt <= 20) //10s,等待开机成功,联动装置盒控制器接口波特率需等待5s接口自动切换为9600
  6747. {
  6748. if (!uARTToolStripMenuItem.Checked) //CAN接口不考虑联动装置盒切换为Boot波特率
  6749. {
  6750. if ((BootInfo != string.Empty) && (ACK_WaitCnt > 10))
  6751. break;
  6752. }
  6753. }
  6754. //检查BOOT版本
  6755. if (BootInfo != string.Empty)
  6756. {
  6757. label_FacModeBootVer.BackColor = Color.Green;
  6758. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  6759. Delay_ms(500);
  6760. }
  6761. else
  6762. {
  6763. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
  6764. label_FacModeStatus.Text = "存在故障!";
  6765. label_FacModeResult.BackColor = Color.Red;
  6766. label_FacModeResult.Text = "测试异常";
  6767. Delay_ms(500);
  6768. //存储异常并上传
  6769. FacMode_Stop(false);
  6770. return;
  6771. }
  6772. //系统清除
  6773. if (checkBox_FacModeSysClear.Checked)
  6774. {
  6775. do
  6776. {
  6777. #if false
  6778. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  6779. {
  6780. Code[0] = 0x00;//5S协议
  6781. Code[1] = 0x00;
  6782. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6783. Delay_ms(500);
  6784. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6785. Delay_ms(500);
  6786. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  6787. }
  6788. #endif
  6789. //发送系统清除指令
  6790. label_FacModeStatus.Text = "系统清除";
  6791. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除" + "\r\n");
  6792. Code[0] = (byte)'C';
  6793. Code[1] = (byte)'L';
  6794. Code[2] = (byte)'E';
  6795. Code[3] = (byte)'A';
  6796. Code[4] = (byte)'R';
  6797. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  6798. WriteACK = false;
  6799. ACK_WaitCnt = 0;
  6800. while (ACK_WaitCnt <= 6); //3s
  6801. //等待系统清除完成指令
  6802. if (WriteACK == true)
  6803. {
  6804. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  6805. label_FacModeSysClear.BackColor = Color.Green;
  6806. }
  6807. else
  6808. {
  6809. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除,重发第1次" + "\r\n");
  6810. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  6811. ACK_WaitCnt = 0;
  6812. while (ACK_WaitCnt <= 6) ; //3s
  6813. //等待系统清除完成指令
  6814. if (WriteACK == true)
  6815. {
  6816. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  6817. label_FacModeSysClear.BackColor = Color.Green;
  6818. }
  6819. else
  6820. {
  6821. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除,重发第2次" + "\r\n");
  6822. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  6823. ACK_WaitCnt = 0;
  6824. while (ACK_WaitCnt <= 6) ; //3s
  6825. //等待系统清除完成指令
  6826. if (WriteACK == true)
  6827. {
  6828. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  6829. label_FacModeSysClear.BackColor = Color.Green;
  6830. }
  6831. else
  6832. {
  6833. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除失败" + "\r\n");
  6834. label_FacModeStatus.Text = "存在故障!";
  6835. label_FacModeResult.BackColor = Color.Red;
  6836. label_FacModeResult.Text = "测试异常";
  6837. Delay_ms(500);
  6838. //存储异常并上传
  6839. FacMode_Stop(false);
  6840. return;
  6841. }
  6842. }
  6843. }
  6844. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  6845. if (uARTToolStripMenuItem.Checked)
  6846. {
  6847. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送复位指令,切换联动装置盒波特率" + "\r\n");
  6848. Code[0] = (byte)'R';
  6849. Code[1] = (byte)'E';
  6850. Code[2] = (byte)'S';
  6851. Code[3] = (byte)'E';
  6852. Code[4] = (byte)'T';
  6853. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  6854. Delay_ms(500);
  6855. }
  6856. //系统清除后需重新开机
  6857. label_FacModeStatus.Text = "重新开机";
  6858. //确保测试前先关机,发送关机指令再发送开机指令
  6859. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新发送关机指令" + "\r\n");
  6860. Code[0] = 0xF0;
  6861. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6862. Delay_ms(4000);
  6863. BootInfo = "";
  6864. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新发送开机指令" + "\r\n");
  6865. Code[0] = 0xF1;
  6866. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6867. ACK_WaitCnt = 0;
  6868. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  6869. while (ACK_WaitCnt <= 20)
  6870. {
  6871. if (!uARTToolStripMenuItem.Checked) //CAN接口不考虑联动装置盒切换为Boot波特率
  6872. {
  6873. if ((BootInfo != string.Empty) && (ACK_WaitCnt > 10))
  6874. break;
  6875. }
  6876. }
  6877. //获取Boot版本信息
  6878. if (BootInfo != string.Empty)
  6879. {
  6880. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机成功" + "\r\n");
  6881. Delay_ms(500);
  6882. }
  6883. else
  6884. {
  6885. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机失败" + "\r\n");
  6886. label_FacModeStatus.Text = "存在故障!";
  6887. label_FacModeResult.BackColor = Color.Red;
  6888. label_FacModeResult.Text = "测试异常";
  6889. Delay_ms(500);
  6890. //存储异常并上传
  6891. FacMode_Stop(false);
  6892. return;
  6893. }
  6894. } while (false);
  6895. }
  6896. else
  6897. {
  6898. label_FacModeSysClear.BackColor = Color.Yellow;
  6899. label_FacModeStatus.Text = "跳过系统清除!";
  6900. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过系统清除" + "\r\n");
  6901. Delay_ms(500);
  6902. }
  6903. #if false
  6904. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  6905. {
  6906. Code[0] = 0x00;//5S协议
  6907. Code[1] = 0x00;
  6908. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6909. Delay_ms(500);
  6910. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6911. Delay_ms(500);
  6912. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  6913. }
  6914. #endif
  6915. //检查是否有故障
  6916. if (textBox_ErrorCode.Text.Contains("H"))
  6917. {
  6918. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "故障码:" + textBox_ErrorCode.Text + "\r\n");
  6919. label_FacModeStatus.Text = "电机存在故障!";
  6920. label_FacModeResult.BackColor = Color.Red;
  6921. label_FacModeResult.Text = "测试异常";
  6922. Delay_ms(500);
  6923. //存储异常并上传
  6924. FacMode_Stop(false);
  6925. return;
  6926. }
  6927. //MOS内阻校准
  6928. if (checkBox_FacMode_MosCal.Checked)
  6929. {
  6930. label_FacModeStatus.Text = "MOS内阻校准";
  6931. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始MOS内阻校准" + "\r\n");
  6932. Delay_ms(500);
  6933. //提示进行负载切换
  6934. if (MessageBox.Show("电阻负载切换完成,开始校准?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
  6935. {
  6936. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "取消MOS内阻校准" + "\r\n");
  6937. label_FacModeStatus.Text = "存在故障!";
  6938. label_FacModeResult.BackColor = Color.Red;
  6939. label_FacModeResult.Text = "测试异常";
  6940. Delay_ms(500);
  6941. //存储异常并上传
  6942. FacMode_Stop(false);
  6943. return;
  6944. }
  6945. //确认后发送校准指令
  6946. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令" + "\r\n");
  6947. string[] K = toolStripTextBox_MosCalK.Text.Split(',');
  6948. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  6949. ushort uwDataTemp = 0;
  6950. uwDataTemp = Convert.ToUInt16(K[0]);
  6951. Code[2] = (byte)(uwDataTemp & 0xFF);
  6952. Code[3] = (byte)(uwDataTemp >> 8);
  6953. uwDataTemp = Convert.ToUInt16(K[1]);
  6954. Code[4] = (byte)(uwDataTemp & 0xFF);
  6955. Code[5] = (byte)(uwDataTemp >> 8);
  6956. uwDataTemp = Convert.ToUInt16(K[2]);
  6957. Code[6] = (byte)(uwDataTemp & 0xFF);
  6958. Code[7] = (byte)(uwDataTemp >> 8);
  6959. uwDataTemp = Convert.ToUInt16(K[3]);
  6960. Code[8] = (byte)(uwDataTemp & 0xFF);
  6961. Code[9] = (byte)(uwDataTemp >> 8);
  6962. uwDataTemp = Convert.ToUInt16(K[4]);
  6963. Code[10] = (byte)(uwDataTemp & 0xFF);
  6964. Code[11] = (byte)(uwDataTemp >> 8);
  6965. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  6966. WriteACK = false;
  6967. ACK_WaitCnt = 0;
  6968. while (ACK_WaitCnt <= 6) ; //3s
  6969. if (WriteACK == true)
  6970. {
  6971. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  6972. }
  6973. else
  6974. {
  6975. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令,第1次重发" + "\r\n");
  6976. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  6977. ACK_WaitCnt = 0;
  6978. while (ACK_WaitCnt <= 6) ; //3s
  6979. if (WriteACK == true)
  6980. {
  6981. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  6982. }
  6983. else
  6984. {
  6985. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令,第2次重发" + "\r\n");
  6986. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  6987. ACK_WaitCnt = 0;
  6988. while (ACK_WaitCnt <= 6) ; //3s
  6989. if (WriteACK == true)
  6990. {
  6991. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  6992. }
  6993. else
  6994. {
  6995. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准异常" + "\r\n");
  6996. label_FacModeStatus.Text = "存在故障!";
  6997. label_FacModeResult.BackColor = Color.Red;
  6998. label_FacModeResult.Text = "测试异常";
  6999. Delay_ms(500);
  7000. //存储异常并上传
  7001. FacMode_Stop(false);
  7002. return;
  7003. }
  7004. }
  7005. }
  7006. #if false
  7007. //因控制器复位需发送指令重新进入5S协议
  7008. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  7009. {
  7010. Code[0] = 0x00;//5S协议
  7011. Code[1] = 0x00;
  7012. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  7013. Delay_ms(500);
  7014. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  7015. Delay_ms(500);
  7016. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  7017. }
  7018. #endif
  7019. //读取显示校准返回数据
  7020. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果" + "\r\n");
  7021. foreach (Control c in groupBox21.Controls)
  7022. {
  7023. if (c is TextBox)
  7024. c.Text = "";
  7025. }
  7026. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  7027. ACK_WaitCnt = 0;
  7028. while (ACK_WaitCnt <= 2) ; //1s
  7029. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  7030. {
  7031. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果,第1次重发" + "\r\n");
  7032. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  7033. ACK_WaitCnt = 0;
  7034. while (ACK_WaitCnt <= 2) ; //1s
  7035. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  7036. {
  7037. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果,第2次重发" + "\r\n");
  7038. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  7039. ACK_WaitCnt = 0;
  7040. while (ACK_WaitCnt <= 2) ; //1s
  7041. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  7042. {
  7043. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果异常" + "\r\n");
  7044. label_FacModeStatus.Text = "存在故障!";
  7045. label_FacModeResult.BackColor = Color.Red;
  7046. label_FacModeResult.Text = "测试异常";
  7047. Delay_ms(500);
  7048. //存储异常并上传
  7049. FacMode_Stop(false);
  7050. return;
  7051. }
  7052. }
  7053. }
  7054. else
  7055. {
  7056. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻:" + textBox_MOS_R1.Text + " " + textBox_MOS_R2.Text + " " + textBox_MOS_R3.Text + "\r\n");
  7057. }
  7058. //与校准返回数据对比
  7059. string[] MOS_R1_Th = toolStripTextBox_MOS1.Text.Split(',');
  7060. string[] MOS_R2_Th = toolStripTextBox_MOS2.Text.Split(',');
  7061. string[] MOS_R3_Th = toolStripTextBox_MOS3.Text.Split(',');
  7062. if ((Convert.ToUInt16(textBox_MOS_R1.Text) >= Convert.ToUInt16(MOS_R1_Th[0])) && (Convert.ToUInt16(textBox_MOS_R1.Text) <= Convert.ToUInt16(MOS_R1_Th[1])) &&
  7063. (Convert.ToUInt16(textBox_MOS_R2.Text) >= Convert.ToUInt16(MOS_R2_Th[0])) && (Convert.ToUInt16(textBox_MOS_R2.Text) <= Convert.ToUInt16(MOS_R2_Th[1])) &&
  7064. (Convert.ToUInt16(textBox_MOS_R3.Text) >= Convert.ToUInt16(MOS_R3_Th[0])) && (Convert.ToUInt16(textBox_MOS_R3.Text) <= Convert.ToUInt16(MOS_R3_Th[1]))
  7065. )
  7066. {
  7067. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准合格" + "\r\n");
  7068. label_FacModeMosCal.BackColor = Color.Green;
  7069. //提示切换负载
  7070. MessageBox.Show("请将负载切换回电机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  7071. }
  7072. else
  7073. {
  7074. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准超范围" + "\r\n");
  7075. label_FacModeStatus.Text = "存在故障!";
  7076. label_FacModeResult.BackColor = Color.Red;
  7077. label_FacModeResult.Text = "测试异常";
  7078. Delay_ms(500);
  7079. //存储异常并上传
  7080. FacMode_Stop(false);
  7081. //提示切换负载
  7082. MessageBox.Show("请将负载切换回电机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  7083. return;
  7084. }
  7085. }
  7086. else
  7087. {
  7088. label_FacModeMosCal.BackColor = Color.Yellow;
  7089. label_FacModeStatus.Text = "跳过MOS内阻校准!";
  7090. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过MOS内阻校准" + "\r\n");
  7091. Delay_ms(500);
  7092. }
  7093. //位置校准
  7094. if (checkBox_FacMode_AngleCal.Checked)
  7095. {
  7096. //校准前进行一次开关机保存初始化数据
  7097. label_FacModeStatus.Text = "位置校准";
  7098. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始位置校准" + "\r\n");
  7099. //确保测试前先关机,发送关机指令再发送开机指令
  7100. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  7101. Code[0] = 0xF0;
  7102. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  7103. Delay_ms(4000);
  7104. BootInfo = "";
  7105. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  7106. Code[0] = 0xF1;
  7107. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  7108. ACK_WaitCnt = 0;
  7109. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  7110. while (ACK_WaitCnt <= 10) //5s
  7111. {
  7112. if (BootInfo != string.Empty)
  7113. {
  7114. break;
  7115. }
  7116. }
  7117. //获取Boot版本信息
  7118. if (BootInfo != string.Empty)
  7119. {
  7120. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机成功" + "\r\n");
  7121. Delay_ms(500);
  7122. }
  7123. else
  7124. {
  7125. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机失败" + "\r\n");
  7126. label_FacModeStatus.Text = "存在故障!";
  7127. label_FacModeResult.BackColor = Color.Red;
  7128. label_FacModeResult.Text = "测试异常";
  7129. Delay_ms(500);
  7130. //存储异常并上传
  7131. FacMode_Stop(false);
  7132. return;
  7133. }
  7134. //发送位置校准指令
  7135. for (int i = 0; i < 7; i++)
  7136. for (int j = 0; j < 6; j++)
  7137. {
  7138. dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = "";
  7139. }
  7140. foreach (Control cr in tabPage_AngleCal.Controls)
  7141. {
  7142. if (cr is TextBox)
  7143. {
  7144. if ((cr != textBox_AngleDiffTh) && (cr != textBox_AngleZeroTh))
  7145. cr.Text = "";
  7146. }
  7147. }
  7148. Code[0] = 0;
  7149. Code[1] = 0;
  7150. mySerialProcess.SendCmd((ushort)0x751, (byte)0x0C, (ushort)0x5002, Code);
  7151. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准中,请等待" + "\r\n");
  7152. ACK_WaitCnt = 0;
  7153. while (ACK_WaitCnt <= 50) ; //25s
  7154. //读取位置校准数据
  7155. if (textBox_AngleDiffAvg.Text == string.Empty)
  7156. {
  7157. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准失败" + "\r\n");
  7158. label_FacModeStatus.Text = "存在故障!";
  7159. label_FacModeResult.BackColor = Color.Red;
  7160. label_FacModeResult.Text = "测试异常";
  7161. Delay_ms(500);
  7162. //存储异常并上传
  7163. FacMode_Stop(false);
  7164. return;
  7165. }
  7166. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准数据:" + "\r\n");
  7167. for (int i = 0; i < 7; i++)
  7168. {
  7169. richTextBox_FacModeLog.AppendText("电周期" + (i + 1).ToString()+":");
  7170. for (int j = 0; j < 6; j++)
  7171. {
  7172. richTextBox_FacModeLog.AppendText(dataGridView_AngleCal.Rows[i].Cells[j + 1].Value.ToString() + ", ");
  7173. }
  7174. richTextBox_FacModeLog.AppendText("\r\n");
  7175. Delay_ms(200);
  7176. }
  7177. richTextBox_FacModeLog.AppendText("最小偏差:" + textBox_AngleDiffMin.Text+ ", " + "\r\n");
  7178. richTextBox_FacModeLog.AppendText("最大偏差:" + textBox_AngleDiffMax.Text + ", " + "\r\n");
  7179. richTextBox_FacModeLog.AppendText("平均偏差:" + textBox_AngleDiffAvg.Text + ", " + "\r\n");
  7180. richTextBox_FacModeLog.AppendText("历史零点:" + textBox_AngleZeroInit.Text + ", " + "\r\n");
  7181. richTextBox_FacModeLog.AppendText("当前零点:" + textBox_AngleZeroCur.Text + ", " + "\r\n");
  7182. richTextBox_FacModeLog.AppendText("零点偏差:" + textBox_AngleZeroDiff.Text + ", " + "\r\n");
  7183. //比较位置偏差
  7184. if ((Math.Abs(Convert.ToDouble(textBox_AngleDiffMin.Text)) > Convert.ToDouble(textBox_AngleDiffTh.Text)) ||
  7185. (Math.Abs(Convert.ToDouble(textBox_AngleDiffMax.Text)) > Convert.ToDouble(textBox_AngleDiffTh.Text)) ||
  7186. (Math.Abs(Convert.ToDouble(textBox_AngleDiffAvg.Text)) > Convert.ToDouble(textBox_AngleZeroTh.Text))
  7187. )
  7188. {
  7189. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差过大,无法校准" + "\r\n");
  7190. label_FacModeStatus.Text = "存在故障!";
  7191. label_FacModeResult.BackColor = Color.Red;
  7192. label_FacModeResult.Text = "测试异常";
  7193. Delay_ms(500);
  7194. //存储异常并上传
  7195. FacMode_Stop(false);
  7196. return;
  7197. }
  7198. //写入校准偏差值
  7199. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差满足要求,写入校准数据" + "\r\n");
  7200. double data1 = Convert.ToDouble(textBox_AngleZeroInit.Text) - Convert.ToDouble(textBox_AngleDiffAvg.Text);
  7201. if (data1 > 360)
  7202. {
  7203. data1 -= 360;
  7204. }
  7205. else if (data1 < -360)
  7206. {
  7207. data1 += 360;
  7208. }
  7209. Int16 data2 = (Int16)(data1 * 32768 / 360);
  7210. Code[0] = 0x01;
  7211. Code[1] = 0x00;
  7212. Code[2] = (byte)(data2);
  7213. Code[3] = (byte)(data2 >> 8);
  7214. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
  7215. WriteACK = false;
  7216. ACK_WaitCnt = 0;
  7217. while (ACK_WaitCnt <= 2) ; //1s
  7218. if (WriteACK == true)
  7219. {
  7220. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
  7221. }
  7222. else
  7223. {
  7224. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入位置偏差,第1次重发" + "\r\n");
  7225. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
  7226. WriteACK = false;
  7227. ACK_WaitCnt = 0;
  7228. while (ACK_WaitCnt <= 2) ; //1s
  7229. if (WriteACK == true)
  7230. {
  7231. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
  7232. }
  7233. else
  7234. {
  7235. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入位置偏差,第2次重发" + "\r\n");
  7236. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
  7237. WriteACK = false;
  7238. ACK_WaitCnt = 0;
  7239. while (ACK_WaitCnt <= 2) ; //1s
  7240. if (WriteACK == true)
  7241. {
  7242. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
  7243. }
  7244. else
  7245. {
  7246. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入失败" + "\r\n");
  7247. label_FacModeStatus.Text = "存在故障!";
  7248. label_FacModeResult.BackColor = Color.Red;
  7249. label_FacModeResult.Text = "测试异常";
  7250. Delay_ms(500);
  7251. //存储异常并上传
  7252. FacMode_Stop(false);
  7253. return;
  7254. }
  7255. }
  7256. }
  7257. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准正常,位置偏差值:" + textBox_AngleDiffAvg.Text + "\r\n");
  7258. label_FacModeAngleCal.BackColor = Color.Green;
  7259. }
  7260. else
  7261. {
  7262. label_FacModeAngleCal.BackColor = Color.Yellow;
  7263. label_FacModeStatus.Text = "跳过位置校准!";
  7264. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过位置校准" + "\r\n");
  7265. Delay_ms(500);
  7266. }
  7267. //参数写入
  7268. if (checkBox_FacModeCfgWrite.Checked)
  7269. {
  7270. label_FacModeStatus.Text = "参数写入";
  7271. //写入产品型号和SN
  7272. do
  7273. {
  7274. //根据扫码信息获取型号和SN
  7275. string ScanInfo = textBox_FacModeScan.Text;
  7276. string regexInfo = "";
  7277. string[] InfoList = { "" };
  7278. try
  7279. {
  7280. if (样机测试ToolStripMenuItem.Checked == true) //样机测试时标签按两个空格分隔
  7281. {
  7282. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  7283. string Mode = InfoList[0];
  7284. string Sn = InfoList[1];
  7285. }
  7286. else
  7287. {
  7288. if (中置电机MIGIC_ToolStripMenuItem.Checked == true)
  7289. {
  7290. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  7291. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  7292. }
  7293. else if (中置电机VP_ToolStripMenuItem.Checked == true)
  7294. {
  7295. Regex regex = new Regex(@"^M[12][0-9](0?[1-9]|1[0-2])((0?[1-9])|((1|2)[0-9])|30|31)[A-Z]\d{4}[A-Z][A-Z]?$");
  7296. if (ScanInfo.Contains(" "))
  7297. {
  7298. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  7299. string Mode = InfoList[0];
  7300. string Sn = InfoList[1];
  7301. if (Mode.Length > 16)
  7302. {
  7303. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号长度超16个字符" + "\r\n");
  7304. label_FacModeStatus.Text = "存在故障!";
  7305. label_FacModeResult.BackColor = Color.Red;
  7306. label_FacModeResult.Text = "标签格式错误";
  7307. Delay_ms(500);
  7308. //存储异常并上传
  7309. FacMode_Stop(false);
  7310. return;
  7311. }
  7312. if (regex.IsMatch(Sn) == false)
  7313. {
  7314. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN格式错误" + "\r\n");
  7315. label_FacModeStatus.Text = "存在故障!";
  7316. label_FacModeResult.BackColor = Color.Red;
  7317. label_FacModeResult.Text = "标签格式错误";
  7318. Delay_ms(500);
  7319. //存储异常并上传
  7320. FacMode_Stop(false);
  7321. return;
  7322. }
  7323. }
  7324. else
  7325. {
  7326. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  7327. label_FacModeStatus.Text = "存在故障!";
  7328. label_FacModeResult.BackColor = Color.Red;
  7329. label_FacModeResult.Text = "标签格式错误";
  7330. Delay_ms(500);
  7331. //存储异常并上传
  7332. FacMode_Stop(false);
  7333. return;
  7334. }
  7335. }
  7336. else if (轮毂电机ToolStripMenuItem.Checked == true)
  7337. {
  7338. if (!ScanInfo.Contains("/")) //老编码规则
  7339. {
  7340. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  7341. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  7342. string Spec = InfoList[1];
  7343. string Sn = InfoList[2];
  7344. InfoList[0] = Model.Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  7345. InfoList[1] = Sn;
  7346. }
  7347. else //新编码规则
  7348. {
  7349. Dictionary<string, string> Dic_Ver = new Dictionary<string, string>
  7350. {
  7351. { "01", "A" },
  7352. { "02", "B" },
  7353. { "03", "C" },
  7354. { "04", "D" },
  7355. { "05", "E" },
  7356. { "06", "F" },
  7357. { "07", "G" },
  7358. { "08", "H" },
  7359. { "09", "I" }
  7360. };
  7361. Dictionary<string, string> Dic_Vol = new Dictionary<string, string>
  7362. {
  7363. { "24V", "A" },
  7364. { "36V", "B" },
  7365. { "42V", "C" },
  7366. { "48V", "D" },
  7367. { "52V", "E" },
  7368. { "60V", "F" }
  7369. };
  7370. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  7371. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  7372. string Spec = InfoList[1].Replace("-", "").Replace("/", "");
  7373. string Sn = InfoList[2];
  7374. InfoList[0] = Model[2] + Dic_Ver[Model.Substring(3, 2)] + Model[5] + Dic_Ver[Model.Substring(6, 2)] + Model[9];
  7375. InfoList[0] += Dic_Vol[Spec.Substring(0, 3)] + Spec.Substring(3, 3) + Spec.Substring(13, 4) + Spec.Substring(Spec.Length - 4, 3);
  7376. InfoList[1] = Sn;
  7377. }
  7378. }
  7379. }
  7380. }
  7381. catch
  7382. {
  7383. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  7384. label_FacModeStatus.Text = "存在故障!";
  7385. label_FacModeResult.BackColor = Color.Red;
  7386. label_FacModeResult.Text = "标签格式错误";
  7387. Delay_ms(500);
  7388. //存储异常并上传
  7389. FacMode_Stop(false);
  7390. return;
  7391. }
  7392. if (InfoList.Length >= 2)
  7393. {
  7394. //检查配置文件是否与打标信息一致
  7395. //...
  7396. //写入型号
  7397. label_FacModeStatus.Text = "写入型号";
  7398. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号" + "\r\n");
  7399. textBox_FacModeName.Text = InfoList[0];
  7400. string Mode = textBox_FacModeName.Text;
  7401. var ModeArray = new byte[16];
  7402. for (ushort i = 0; i < Mode.Length; i++)
  7403. {
  7404. ModeArray[i] = (byte)Mode[i];
  7405. }
  7406. if (Mode.Length < 16)
  7407. {
  7408. ModeArray[Mode.Length] = (byte)'.';
  7409. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  7410. {
  7411. ModeArray[Mode.Length + 1 + i] = 0x20;
  7412. }
  7413. }
  7414. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  7415. WriteACK = false;
  7416. ACK_WaitCnt = 0;
  7417. while (ACK_WaitCnt <= 2) //1s
  7418. {
  7419. if (WriteACK == true)
  7420. break;
  7421. }
  7422. if (WriteACK == true)
  7423. {
  7424. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  7425. }
  7426. else
  7427. {
  7428. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号,第1次重发" + "\r\n");
  7429. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  7430. ACK_WaitCnt = 0;
  7431. while (ACK_WaitCnt <= 2) //1s
  7432. {
  7433. if (WriteACK == true)
  7434. break;
  7435. }
  7436. if (WriteACK == true)
  7437. {
  7438. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  7439. }
  7440. else
  7441. {
  7442. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号,第2次重发" + "\r\n");
  7443. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  7444. ACK_WaitCnt = 0;
  7445. while (ACK_WaitCnt <= 2) //1s
  7446. {
  7447. if (WriteACK == true)
  7448. break;
  7449. }
  7450. if (WriteACK == true)
  7451. {
  7452. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  7453. }
  7454. else
  7455. {
  7456. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入失败" + "\r\n");
  7457. label_FacModeStatus.Text = "存在故障!";
  7458. label_FacModeResult.BackColor = Color.Red;
  7459. label_FacModeResult.Text = "测试异常";
  7460. Delay_ms(500);
  7461. //存储异常并上传
  7462. FacMode_Stop(false);
  7463. return;
  7464. }
  7465. }
  7466. }
  7467. //写入SN
  7468. label_FacModeStatus.Text = "写入SN";
  7469. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN" + "\r\n");
  7470. textBox_FacModeNum.Text = InfoList[1];
  7471. string SN = textBox_FacModeNum.Text;
  7472. var SNArray = new byte[16];
  7473. for (ushort i = 0; i < SN.Length; i++)
  7474. {
  7475. SNArray[i] = (byte)SN[i];
  7476. }
  7477. if (SN.Length < 16)
  7478. {
  7479. SNArray[SN.Length] = (byte)'.';
  7480. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  7481. {
  7482. SNArray[SN.Length + 1 + i] = 0x20;
  7483. }
  7484. }
  7485. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  7486. WriteACK = false;
  7487. ACK_WaitCnt = 0;
  7488. while (ACK_WaitCnt <= 2) //1s
  7489. {
  7490. if (WriteACK == true)
  7491. break;
  7492. }
  7493. if (WriteACK == true)
  7494. {
  7495. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  7496. }
  7497. else
  7498. {
  7499. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN,第1次重发" + "\r\n");
  7500. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  7501. ACK_WaitCnt = 0;
  7502. while (ACK_WaitCnt <= 2) //1s
  7503. {
  7504. if (WriteACK == true)
  7505. break;
  7506. }
  7507. if (WriteACK == true)
  7508. {
  7509. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  7510. }
  7511. else
  7512. {
  7513. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN,第2次重发" + "\r\n");
  7514. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  7515. ACK_WaitCnt = 0;
  7516. while (ACK_WaitCnt <= 2) //1s
  7517. {
  7518. if (WriteACK == true)
  7519. break;
  7520. }
  7521. if (WriteACK == true)
  7522. {
  7523. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  7524. }
  7525. else
  7526. {
  7527. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入失败" + "\r\n");
  7528. label_FacModeStatus.Text = "存在故障!";
  7529. label_FacModeResult.BackColor = Color.Red;
  7530. label_FacModeResult.Text = "测试异常";
  7531. Delay_ms(500);
  7532. //存储异常并上传
  7533. FacMode_Stop(false);
  7534. return;
  7535. }
  7536. }
  7537. }
  7538. }
  7539. else
  7540. {
  7541. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  7542. return;
  7543. }
  7544. } while (false);
  7545. //写入配置文件
  7546. do
  7547. {
  7548. if (样机测试ToolStripMenuItem.Checked == true)
  7549. {
  7550. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "样机测试,不执行参数写入" + "\r\n");
  7551. label_FacMode_CfgWrite.BackColor = Color.Yellow;
  7552. break;
  7553. }
  7554. label_FacModeStatus.Text = "写入配置文件";
  7555. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  7556. //配置文件
  7557. List<byte[]> CmdList = new List<byte[]>();
  7558. //从服务器下载文件
  7559. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  7560. {
  7561. string SelectFile = "";
  7562. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "/" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  7563. if (File.Exists(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  7564. {
  7565. File.Delete(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  7566. }
  7567. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  7568. //打开文件
  7569. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  7570. CmdList.Clear();
  7571. while (streamReader.Peek() != -1)
  7572. {
  7573. string fileLineInfo = streamReader.ReadLine();
  7574. if (fileLineInfo.IndexOf("[") != -1)
  7575. {
  7576. continue;
  7577. }
  7578. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  7579. }
  7580. streamReader.Close();
  7581. }
  7582. //加载本地文件
  7583. else
  7584. {
  7585. string SelectFile = "";
  7586. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  7587. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  7588. CmdList.Clear();
  7589. while (streamReader.Peek() != -1)
  7590. {
  7591. string fileLineInfo = streamReader.ReadLine();
  7592. if (fileLineInfo.IndexOf("[") != -1)
  7593. {
  7594. continue;
  7595. }
  7596. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  7597. }
  7598. streamReader.Close();
  7599. }
  7600. int CmdNum = CmdList.Count(); //指令个数
  7601. Delay_ms(500);
  7602. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "开始写入" + "\r\n");
  7603. Delay_ms(500);
  7604. //开始写入
  7605. for (int i = 0; i < CmdList.Count; i++)
  7606. {
  7607. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令" + "\r\n");
  7608. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  7609. WriteACK = false;
  7610. ACK_WaitCnt = 0;
  7611. while (ACK_WaitCnt <= 2) //1s
  7612. {
  7613. if (WriteACK == true)
  7614. break;
  7615. }
  7616. if (WriteACK == true)
  7617. {
  7618. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  7619. }
  7620. else
  7621. {
  7622. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令,第1次重发" + "\r\n");
  7623. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  7624. WriteACK = false;
  7625. ACK_WaitCnt = 0;
  7626. while (ACK_WaitCnt <= 2) //1s
  7627. {
  7628. if (WriteACK == true)
  7629. break;
  7630. }
  7631. if (WriteACK == true)
  7632. {
  7633. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  7634. }
  7635. else
  7636. {
  7637. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令,第2次重发" + "\r\n");
  7638. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  7639. WriteACK = false;
  7640. ACK_WaitCnt = 0;
  7641. while (ACK_WaitCnt <= 2) //1s
  7642. {
  7643. if (WriteACK == true)
  7644. break;
  7645. }
  7646. if (WriteACK == true)
  7647. {
  7648. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  7649. }
  7650. else
  7651. {
  7652. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入失败," + "共" + CmdNum.ToString() + "条指令," + "写入成功" + i.ToString() + "条" + "\r\n");
  7653. label_FacModeStatus.Text = "存在故障!";
  7654. label_FacModeResult.BackColor = Color.Red;
  7655. label_FacModeResult.Text = "测试异常";
  7656. Delay_ms(500);
  7657. //存储异常并上传
  7658. FacMode_Stop(false);
  7659. return;
  7660. }
  7661. }
  7662. }
  7663. }
  7664. //写入完成
  7665. label_FacMode_CfgWrite.BackColor = Color.Green;
  7666. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入成功" + "\r\n");
  7667. Delay_ms(500);
  7668. } while (false);
  7669. }
  7670. else
  7671. {
  7672. label_FacMode_CfgWrite.BackColor = Color.Yellow;
  7673. label_FacModeStatus.Text = "跳过参数写入!";
  7674. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数写入" + "\r\n");
  7675. Delay_ms(500);
  7676. }
  7677. //BMS通讯
  7678. if (checkBox_FacModeBMS.Checked)
  7679. {
  7680. if (label_FacModeBMS.BackColor == Color.Red)
  7681. {
  7682. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "BMS通讯异常" + "\r\n");
  7683. label_FacModeStatus.Text = "存在故障!";
  7684. label_FacModeResult.BackColor = Color.Red;
  7685. label_FacModeResult.Text = "测试异常";
  7686. Delay_ms(500);
  7687. //存储异常并上传
  7688. FacMode_Stop(false);
  7689. return;
  7690. }
  7691. }
  7692. else
  7693. {
  7694. label_FacModeBMS.BackColor = Color.Yellow;
  7695. label_FacModeStatus.Text = "跳过BMS通讯检测!";
  7696. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过BMS通讯检测" + "\r\n");
  7697. Delay_ms(500);
  7698. }
  7699. //基础功能检测
  7700. if (checkBox_FacBaseFucTest.Checked)
  7701. {
  7702. label_FacModeStatus.Text = "基础功能检测";
  7703. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始基础功能检测" + "\r\n");
  7704. //确认负载位置
  7705. if (checkBox_FacMode_MosCal.Checked)
  7706. {
  7707. if (MessageBox.Show("请再次确认负载是否切换回电机?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  7708. {
  7709. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "负载已切换为电机,继续测试" + "\r\n");
  7710. }
  7711. else
  7712. {
  7713. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试取消" + "\r\n");
  7714. label_FacModeStatus.Text = "存在故障!";
  7715. label_FacModeResult.BackColor = Color.Red;
  7716. label_FacModeResult.Text = "测试异常";
  7717. Delay_ms(500);
  7718. //存储异常并上传
  7719. FacMode_Stop(false);
  7720. return;
  7721. }
  7722. }
  7723. //发送指令进入配置模式
  7724. do
  7725. {
  7726. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  7727. Code[0] = 0x01;
  7728. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7729. WriteACK = false;
  7730. ACK_WaitCnt = 0;
  7731. while (ACK_WaitCnt <= 2); //1s
  7732. if (textBox_RunInfo_Vol.Text != "---")
  7733. {
  7734. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7735. }
  7736. else
  7737. {
  7738. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  7739. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7740. ACK_WaitCnt = 0;
  7741. while (ACK_WaitCnt <= 2) ; //1s
  7742. if (textBox_RunInfo_Vol.Text != "---")
  7743. {
  7744. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7745. }
  7746. else
  7747. {
  7748. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7749. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7750. ACK_WaitCnt = 0;
  7751. while (ACK_WaitCnt <= 2) ; //1s
  7752. if (textBox_RunInfo_Vol.Text != "---")
  7753. {
  7754. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7755. }
  7756. else
  7757. {
  7758. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7759. label_FacModeStatus.Text = "存在故障!";
  7760. label_FacModeResult.BackColor = Color.Red;
  7761. label_FacModeResult.Text = "测试异常";
  7762. Delay_ms(500);
  7763. //存储异常并上传
  7764. FacMode_Stop(false);
  7765. return;
  7766. }
  7767. }
  7768. }
  7769. } while (false);
  7770. //发送指令启动电机
  7771. do
  7772. {
  7773. #if false //通过运行模式3启动电机
  7774. //发送指令读取调试信息
  7775. richTextBox_DebugParam.Clear();
  7776. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  7777. WriteACK = false;
  7778. ACK_WaitCnt = 0;
  7779. while (ACK_WaitCnt <= 2); //1s
  7780. //获取调试信息
  7781. string DebugDefaultInfo = "";
  7782. if (richTextBox_DebugParam.Text == string.Empty)
  7783. {
  7784. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
  7785. label_FacModeStatus.Text = "存在故障!";
  7786. label_FacModeResult.BackColor = Color.Red;
  7787. label_FacModeResult.Text = "测试异常";
  7788. Delay_ms(500);
  7789. //存储异常并上传
  7790. FacMode_Stop(false);
  7791. return;
  7792. }
  7793. else
  7794. {
  7795. DebugDefaultInfo = richTextBox_DebugParam.Text;
  7796. }
  7797. //设置模式
  7798. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  7799. strDataTemp[0] = "整体运行模式=3";
  7800. //发送数据
  7801. Code[0] = 0;
  7802. Code[1] = 0;
  7803. for (int i = 0; i < strDataTemp.Length; i++)
  7804. {
  7805. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  7806. Code[2 * i + 2] = (byte)uwDataTemp;
  7807. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  7808. }
  7809. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  7810. label_FacModeStatus.Text = "启动电机";
  7811. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "启动电机" + "\r\n");
  7812. #else //通过Walk模式启动电机
  7813. //设置转速100%
  7814. var Data = new byte[1];
  7815. Data[0] = (byte)100;
  7816. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7817. Delay_ms(500);
  7818. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7819. Delay_ms(500);
  7820. //启动电机进入WALK模式
  7821. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "基础功能检测,进入WALK" + "\r\n");
  7822. Code[0] = 0x22;
  7823. Code[1] = 0xF0;
  7824. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7825. WriteACK = false;
  7826. ACK_WaitCnt = 0;
  7827. while (ACK_WaitCnt <= 2) ; //1s
  7828. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  7829. {
  7830. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第1次重发" + "\r\n");
  7831. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7832. ACK_WaitCnt = 0;
  7833. while (ACK_WaitCnt <= 2) ; //1s
  7834. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  7835. {
  7836. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第2次重发" + "\r\n");
  7837. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7838. ACK_WaitCnt = 0;
  7839. while (ACK_WaitCnt <= 2) ; //1s
  7840. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  7841. {
  7842. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
  7843. label_FacModeStatus.Text = "存在故障!";
  7844. label_FacModeResult.BackColor = Color.Red;
  7845. label_FacModeResult.Text = "测试异常";
  7846. Delay_ms(500);
  7847. //存储异常并上传
  7848. FacMode_Stop(false);
  7849. return;
  7850. }
  7851. }
  7852. }
  7853. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入WALK,开始检测" + "\r\n");
  7854. #endif
  7855. Delay_ms(5000);
  7856. } while (false);
  7857. //判断车速
  7858. if ((Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) <= Convert.ToDouble( toolStripTextBox_ThBikeSpeed.Text.Split(',')[1])) &&
  7859. (Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThBikeSpeed.Text.Split(',')[0])))
  7860. {
  7861. label_FacModeSpeed.BackColor = Color.Green;
  7862. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器正常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
  7863. }
  7864. else
  7865. {
  7866. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器异常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
  7867. label_FacModeStatus.Text = "存在故障!";
  7868. label_FacModeResult.BackColor = Color.Red;
  7869. label_FacModeResult.Text = "测试异常";
  7870. Delay_ms(500);
  7871. //存储异常并上传
  7872. FacMode_Stop(false);
  7873. return;
  7874. }
  7875. //判断电压
  7876. if ((Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[1])) &&
  7877. (Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[0])))
  7878. {
  7879. label_FacModeVolTest.BackColor = Color.Green;
  7880. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量正常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
  7881. }
  7882. else
  7883. {
  7884. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量异常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
  7885. label_FacModeStatus.Text = "存在故障!";
  7886. label_FacModeResult.BackColor = Color.Red;
  7887. label_FacModeResult.Text = "测试异常";
  7888. Delay_ms(500);
  7889. //存储异常并上传
  7890. FacMode_Stop(false);
  7891. return;
  7892. }
  7893. //判断电流
  7894. if ((Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[1])) &&
  7895. (Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[0])))
  7896. {
  7897. label_FacModeCurrentTest.BackColor = Color.Green;
  7898. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量正常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  7899. }
  7900. else
  7901. {
  7902. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量异常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  7903. label_FacModeStatus.Text = "存在故障!";
  7904. label_FacModeResult.BackColor = Color.Red;
  7905. label_FacModeResult.Text = "测试异常";
  7906. Delay_ms(500);
  7907. //存储异常并上传
  7908. FacMode_Stop(false);
  7909. return;
  7910. }
  7911. //判断温度
  7912. if ((Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[1])) &&
  7913. (Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[0])) &&
  7914. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[1])) &&
  7915. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[0])) &&
  7916. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[1])) &&
  7917. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[0])))
  7918. {
  7919. label_FacModeNTC.BackColor = Color.Green;
  7920. 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");
  7921. }
  7922. else
  7923. {
  7924. 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");
  7925. label_FacModeStatus.Text = "存在故障!";
  7926. label_FacModeResult.BackColor = Color.Red;
  7927. label_FacModeResult.Text = "测试异常";
  7928. Delay_ms(500);
  7929. //存储异常并上传
  7930. FacMode_Stop(false);
  7931. return;
  7932. }
  7933. //判断转速
  7934. if ((Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[1])) &&
  7935. (Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[0])))
  7936. {
  7937. label_FacModeMotorSpeed.BackColor = Color.Green;
  7938. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速正常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
  7939. }
  7940. else
  7941. {
  7942. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速异常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
  7943. label_FacModeStatus.Text = "存在故障!";
  7944. label_FacModeResult.BackColor = Color.Red;
  7945. label_FacModeResult.Text = "测试异常";
  7946. Delay_ms(500);
  7947. //存储异常并上传
  7948. FacMode_Stop(false);
  7949. return;
  7950. }
  7951. //中置判断踏频
  7952. if ((中置电机MIGIC_ToolStripMenuItem.Checked == true) || (中置电机VP_ToolStripMenuItem.Checked == true))
  7953. {
  7954. if ((Convert.ToDouble(textBox_RunInfo_Cadence.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[1])) &&
  7955. (Convert.ToDouble(textBox_RunInfo_Cadence.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[0])))
  7956. {
  7957. label_FacModeCad.BackColor = Color.Green;
  7958. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器正常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  7959. }
  7960. else
  7961. {
  7962. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器异常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  7963. label_FacModeStatus.Text = "存在故障!";
  7964. label_FacModeResult.BackColor = Color.Red;
  7965. label_FacModeResult.Text = "测试异常";
  7966. Delay_ms(500);
  7967. //存储异常并上传
  7968. FacMode_Stop(false);
  7969. return;
  7970. }
  7971. }
  7972. //发送指令停止电机
  7973. do
  7974. {
  7975. //设置转速0%
  7976. var Data = new byte[1];
  7977. Data[0] = (byte)0;
  7978. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7979. Delay_ms(500);
  7980. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7981. Delay_ms(500);
  7982. #if false //通过修改调试模式停止电机
  7983. //获取调试信息
  7984. string DebugDefaultInfo = "";
  7985. if (richTextBox_DebugParam.Text == string.Empty)
  7986. {
  7987. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
  7988. label_FacModeStatus.Text = "存在故障!";
  7989. label_FacModeResult.BackColor = Color.Red;
  7990. label_FacModeResult.Text = "测试异常";
  7991. Delay_ms(500);
  7992. //存储异常并上传
  7993. FacMode_Stop(false);
  7994. return;
  7995. }
  7996. else
  7997. {
  7998. DebugDefaultInfo = richTextBox_DebugParam.Text;
  7999. }
  8000. //设置模式
  8001. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  8002. //发送数据
  8003. Code[0] = 0;
  8004. Code[1] = 0;
  8005. for (int i = 0; i < strDataTemp.Length; i++)
  8006. {
  8007. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  8008. Code[2 * i + 2] = (byte)uwDataTemp;
  8009. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  8010. }
  8011. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  8012. label_FacModeStatus.Text = "停止电机";
  8013. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "停止电机" + "\r\n");
  8014. #else //通过调整档位停止电机
  8015. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK" + "\r\n");
  8016. Code[0] = 0x00;
  8017. Code[1] = 0xF0;
  8018. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  8019. WriteACK = false;
  8020. ACK_WaitCnt = 0;
  8021. while (ACK_WaitCnt <= 2) ; //1s
  8022. if (textBox_RunInfo_GearSt.Text != "OFF")
  8023. {
  8024. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK,第1次重发" + "\r\n");
  8025. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  8026. ACK_WaitCnt = 0;
  8027. while (ACK_WaitCnt <= 2) ; //1s
  8028. if (textBox_RunInfo_GearSt.Text != "OFF")
  8029. {
  8030. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK,第2次重发" + "\r\n");
  8031. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  8032. ACK_WaitCnt = 0;
  8033. while (ACK_WaitCnt <= 2) ; //1s
  8034. if (textBox_RunInfo_GearSt.Text != "OFF")
  8035. {
  8036. }
  8037. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
  8038. label_FacModeStatus.Text = "存在故障!";
  8039. label_FacModeResult.BackColor = Color.Red;
  8040. label_FacModeResult.Text = "测试异常";
  8041. Delay_ms(500);
  8042. //存储异常并上传
  8043. FacMode_Stop(false);
  8044. return;
  8045. }
  8046. }
  8047. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已退出WALK,基础功能检测完成" + "\r\n");
  8048. #endif
  8049. Delay_ms(2000);
  8050. } while (false);
  8051. }
  8052. else
  8053. {
  8054. label_FacModeSpeed.BackColor = Color.Yellow;
  8055. label_FacModeVolTest.BackColor = Color.Yellow;
  8056. label_FacModeCurrentTest.BackColor = Color.Yellow;
  8057. label_FacModeNTC.BackColor = Color.Yellow;
  8058. label_FacModeMotorSpeed.BackColor = Color.Yellow;
  8059. label_FacModeStatus.Text = "跳过基础功能检测!";
  8060. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过基础功能检测" + "\r\n");
  8061. Delay_ms(500);
  8062. }
  8063. //力矩检测
  8064. if (checkBox_FacTor.Checked)
  8065. {
  8066. label_FacModeStatus.Text = "力矩传感器检测!";
  8067. //发送指令进入配置模式
  8068. do
  8069. {
  8070. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  8071. {
  8072. break;
  8073. }
  8074. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  8075. Code[0] = 0x01;
  8076. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  8077. WriteACK = false;
  8078. ACK_WaitCnt = 0;
  8079. while (ACK_WaitCnt <= 2) ; //1s
  8080. if (textBox_RunInfo_Vol.Text != "---")
  8081. {
  8082. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  8083. Delay_ms(500);
  8084. }
  8085. else
  8086. {
  8087. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  8088. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  8089. ACK_WaitCnt = 0;
  8090. while (ACK_WaitCnt <= 2) ; //1s
  8091. if (textBox_RunInfo_Vol.Text != "---")
  8092. {
  8093. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  8094. Delay_ms(500);
  8095. }
  8096. else
  8097. {
  8098. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  8099. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  8100. ACK_WaitCnt = 0;
  8101. while (ACK_WaitCnt <= 2) ; //1s
  8102. if (textBox_RunInfo_Vol.Text != "---")
  8103. {
  8104. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  8105. Delay_ms(500);
  8106. }
  8107. else
  8108. {
  8109. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  8110. label_FacModeStatus.Text = "存在故障!";
  8111. label_FacModeResult.BackColor = Color.Red;
  8112. label_FacModeResult.Text = "测试异常";
  8113. Delay_ms(500);
  8114. //存储异常并上传
  8115. FacMode_Stop(false);
  8116. return;
  8117. }
  8118. }
  8119. }
  8120. } while (false);
  8121. ushort Max = 0, Torque = 0;
  8122. //提示输入力矩信号
  8123. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟力矩信号输入" + "\r\n");
  8124. ACK_WaitCnt = 0;
  8125. while (ACK_WaitCnt <= 20) //10s
  8126. {
  8127. //获取力矩值
  8128. Torque = (ushort)Convert.ToInt16(textBox_RunInfo_Torque.Text.Split(' ')[0]);
  8129. if (Torque > Max)
  8130. Max = Torque;
  8131. if ((Max <= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[1])) &&
  8132. (Max >= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[0])) &&
  8133. (ACK_WaitCnt >= 6))
  8134. {
  8135. label_FacModeTq.BackColor = Color.Green;
  8136. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器正常" + " " + textBox_RunInfo_Torque.Text + "\r\n");
  8137. break;
  8138. }
  8139. }
  8140. if (ACK_WaitCnt >= 20)
  8141. {
  8142. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器异常" + " " + textBox_RunInfo_Torque.Text + "\r\n");
  8143. label_FacModeStatus.Text = "存在故障!";
  8144. label_FacModeResult.BackColor = Color.Red;
  8145. label_FacModeResult.Text = "测试异常";
  8146. Delay_ms(500);
  8147. //存储异常并上传
  8148. FacMode_Stop(false);
  8149. return;
  8150. }
  8151. }
  8152. else
  8153. {
  8154. label_FacModeTq.BackColor = Color.Yellow;
  8155. label_FacModeStatus.Text = "跳过力矩检测!";
  8156. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过力矩检测" + "\r\n");
  8157. Delay_ms(500);
  8158. }
  8159. //踏频检测
  8160. if (checkBox_FacCad.Checked)
  8161. {
  8162. if ((中置电机MIGIC_ToolStripMenuItem.Checked == true) || (中置电机VP_ToolStripMenuItem.Checked == true))
  8163. {
  8164. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "中置电机不重复检测踏频" + "\r\n");
  8165. }
  8166. else
  8167. {
  8168. label_FacModeStatus.Text = "踏频传感器检测!";
  8169. //发送指令进入配置模式
  8170. do
  8171. {
  8172. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  8173. {
  8174. break;
  8175. }
  8176. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  8177. Code[0] = 0x01;
  8178. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  8179. WriteACK = false;
  8180. ACK_WaitCnt = 0;
  8181. while (ACK_WaitCnt <= 2) ; //1s
  8182. if (textBox_RunInfo_Vol.Text != "---")
  8183. {
  8184. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  8185. Delay_ms(500);
  8186. }
  8187. else
  8188. {
  8189. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  8190. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  8191. ACK_WaitCnt = 0;
  8192. while (ACK_WaitCnt <= 2) ; //1s
  8193. if (textBox_RunInfo_Vol.Text != "---")
  8194. {
  8195. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  8196. Delay_ms(500);
  8197. }
  8198. else
  8199. {
  8200. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  8201. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  8202. ACK_WaitCnt = 0;
  8203. while (ACK_WaitCnt <= 2) ; //1s
  8204. if (textBox_RunInfo_Vol.Text != "---")
  8205. {
  8206. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  8207. Delay_ms(500);
  8208. }
  8209. else
  8210. {
  8211. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  8212. label_FacModeStatus.Text = "存在故障!";
  8213. label_FacModeResult.BackColor = Color.Red;
  8214. label_FacModeResult.Text = "测试异常";
  8215. Delay_ms(500);
  8216. //存储异常并上传
  8217. FacMode_Stop(false);
  8218. return;
  8219. }
  8220. }
  8221. }
  8222. } while (false);
  8223. ushort Max = 0, Cadence = 0;
  8224. //提示输入踏频信号
  8225. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟踏频信号输入" + "\r\n");
  8226. ACK_WaitCnt = 0;
  8227. while (ACK_WaitCnt <= 20) //10s
  8228. {
  8229. //获取踏频
  8230. Cadence = (ushort)Convert.ToInt16(textBox_RunInfo_Cadence.Text.Split(' ')[0]);
  8231. if (Cadence > Max)
  8232. Max = Cadence;
  8233. if ((Max <= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[1])) &&
  8234. (Max >= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[0])) &&
  8235. (ACK_WaitCnt >= 6)) //3s内有踏频值达到阈值
  8236. {
  8237. label_FacModeCad.BackColor = Color.Green;
  8238. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器正常" + " " + Max.ToString() + " rpm" + "\r\n");
  8239. break;
  8240. }
  8241. }
  8242. if (ACK_WaitCnt >= 20)
  8243. {
  8244. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器异常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  8245. label_FacModeStatus.Text = "存在故障!";
  8246. label_FacModeResult.BackColor = Color.Red;
  8247. label_FacModeResult.Text = "测试异常";
  8248. Delay_ms(500);
  8249. //存储异常并上传
  8250. FacMode_Stop(false);
  8251. return;
  8252. }
  8253. }
  8254. }
  8255. else
  8256. {
  8257. label_FacModeCad.BackColor = Color.Yellow;
  8258. label_FacModeStatus.Text = "跳过踏频检测!";
  8259. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过踏频检测" + "\r\n");
  8260. Delay_ms(500);
  8261. }
  8262. //转把检测
  8263. if (checkBox_FacThrrotleTest.Checked)
  8264. {
  8265. label_FacModeStatus.Text = "转把检测";
  8266. //发送指令进入配置模式
  8267. do
  8268. {
  8269. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  8270. {
  8271. break;
  8272. }
  8273. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  8274. Code[0] = 0x01;
  8275. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  8276. WriteACK = false;
  8277. ACK_WaitCnt = 0;
  8278. while (ACK_WaitCnt <= 2) ; //1s
  8279. if (textBox_RunInfo_Vol.Text != "---")
  8280. {
  8281. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  8282. Delay_ms(500);
  8283. }
  8284. else
  8285. {
  8286. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  8287. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  8288. ACK_WaitCnt = 0;
  8289. while (ACK_WaitCnt <= 2) ; //1s
  8290. if (textBox_RunInfo_Vol.Text != "---")
  8291. {
  8292. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  8293. Delay_ms(500);
  8294. }
  8295. else
  8296. {
  8297. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  8298. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  8299. ACK_WaitCnt = 0;
  8300. while (ACK_WaitCnt <= 2) ; //1s
  8301. if (textBox_RunInfo_Vol.Text != "---")
  8302. {
  8303. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  8304. Delay_ms(500);
  8305. }
  8306. else
  8307. {
  8308. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  8309. label_FacModeStatus.Text = "存在故障!";
  8310. label_FacModeResult.BackColor = Color.Red;
  8311. label_FacModeResult.Text = "测试异常";
  8312. Delay_ms(500);
  8313. //存储异常并上传
  8314. FacMode_Stop(false);
  8315. return;
  8316. }
  8317. }
  8318. }
  8319. } while (false);
  8320. //进入TURBO档
  8321. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把检测,发送指令进入TURBO" + "\r\n");
  8322. Code[0] = 0x04;
  8323. Code[1] = 0xF0;
  8324. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  8325. WriteACK = false;
  8326. ACK_WaitCnt = 0;
  8327. while (ACK_WaitCnt <= 2) ; //1s
  8328. if (textBox_RunInfo_GearSt.Text != "TURBO")
  8329. {
  8330. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO,第1次重发" + "\r\n");
  8331. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  8332. ACK_WaitCnt = 0;
  8333. while (ACK_WaitCnt <= 2) ; //1s
  8334. if (textBox_RunInfo_GearSt.Text != "TURBO")
  8335. {
  8336. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO,第2次重发" + "\r\n");
  8337. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  8338. ACK_WaitCnt = 0;
  8339. while (ACK_WaitCnt <= 2) ; //1s
  8340. if (textBox_RunInfo_GearSt.Text != "TURBO")
  8341. {
  8342. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO异常" + "\r\n");
  8343. label_FacModeStatus.Text = "存在故障!";
  8344. label_FacModeResult.BackColor = Color.Red;
  8345. label_FacModeResult.Text = "测试异常";
  8346. Delay_ms(500);
  8347. //存储异常并上传
  8348. FacMode_Stop(false);
  8349. return;
  8350. }
  8351. }
  8352. }
  8353. //进入TURBO后,如果电机直接启动,认为转把电压异常
  8354. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把自检,请松开转把" + "\r\n");
  8355. Delay_ms(3000);
  8356. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) > 500)
  8357. {
  8358. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把电压异常" + "\r\n");
  8359. label_FacModeStatus.Text = "存在故障!";
  8360. label_FacModeResult.BackColor = Color.Red;
  8361. label_FacModeResult.Text = "测试异常";
  8362. Delay_ms(500);
  8363. //存储异常并上传
  8364. FacMode_Stop(false);
  8365. return;
  8366. }
  8367. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把自检正常" + "\r\n");
  8368. Delay_ms(500);
  8369. //提示转动转把
  8370. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入TURBO,10s内转动转把" + "\r\n");
  8371. ACK_WaitCnt = 0;
  8372. while (ACK_WaitCnt <= 20)
  8373. {
  8374. if ((Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) > 500) && (ACK_WaitCnt >= 10)) //5s
  8375. {
  8376. label_FacModeGas.BackColor = Color.Green;
  8377. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能正常,电机转速:" + textBox_RunInfo_MotorSpeed.Text + ",请松开转把" + "\r\n");
  8378. break;
  8379. }
  8380. }
  8381. if (ACK_WaitCnt >= 20) //转把超时
  8382. {
  8383. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能异常,请松开转把" + "\r\n");
  8384. label_FacModeStatus.Text = "存在故障!";
  8385. label_FacModeResult.BackColor = Color.Red;
  8386. label_FacModeResult.Text = "测试异常";
  8387. Delay_ms(500);
  8388. //存储异常并上传
  8389. FacMode_Stop(false);
  8390. return;
  8391. }
  8392. }
  8393. else
  8394. {
  8395. label_FacModeGas.BackColor = Color.Yellow;
  8396. label_FacModeStatus.Text = "跳过转把检测!";
  8397. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过转把检测" + "\r\n");
  8398. Delay_ms(500);
  8399. }
  8400. //刹车检测
  8401. if (checkBox_FacBreakTest.Checked)
  8402. {
  8403. label_FacModeStatus.Text = "刹把检测";
  8404. //发送指令进入配置模式
  8405. do
  8406. {
  8407. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  8408. {
  8409. break;
  8410. }
  8411. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  8412. Code[0] = 0x01;
  8413. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  8414. WriteACK = false;
  8415. ACK_WaitCnt = 0;
  8416. while (ACK_WaitCnt <= 2) ; //1s
  8417. if (textBox_RunInfo_Vol.Text != "---")
  8418. {
  8419. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  8420. Delay_ms(500);
  8421. }
  8422. else
  8423. {
  8424. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  8425. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  8426. ACK_WaitCnt = 0;
  8427. while (ACK_WaitCnt <= 2) ; //1s
  8428. if (textBox_RunInfo_Vol.Text != "---")
  8429. {
  8430. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  8431. Delay_ms(500);
  8432. }
  8433. else
  8434. {
  8435. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  8436. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  8437. ACK_WaitCnt = 0;
  8438. while (ACK_WaitCnt <= 2) ; //1s
  8439. if (textBox_RunInfo_Vol.Text != "---")
  8440. {
  8441. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  8442. Delay_ms(500);
  8443. }
  8444. else
  8445. {
  8446. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  8447. label_FacModeStatus.Text = "存在故障!";
  8448. label_FacModeResult.BackColor = Color.Red;
  8449. label_FacModeResult.Text = "测试异常";
  8450. Delay_ms(500);
  8451. //存储异常并上传
  8452. FacMode_Stop(false);
  8453. return;
  8454. }
  8455. }
  8456. }
  8457. } while (false);
  8458. //测试前先确定电机已停止
  8459. UInt16 WaitTime = 20;
  8460. do
  8461. {
  8462. WaitTime--;
  8463. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 100)
  8464. {
  8465. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机停止,开始进行剎把检测,进入WALK" + "\r\n");
  8466. break;
  8467. }
  8468. if (WaitTime == 0)
  8469. {
  8470. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机无法停止,剎把检测异常" + "\r\n");
  8471. label_FacModeStatus.Text = "存在故障!";
  8472. label_FacModeResult.BackColor = Color.Red;
  8473. label_FacModeResult.Text = "测试异常";
  8474. Delay_ms(500);
  8475. //存储异常并上传
  8476. FacMode_Stop(false);
  8477. return;
  8478. }
  8479. Delay_ms(500);
  8480. } while (true);
  8481. //设置转速100%
  8482. var Data = new byte[1];
  8483. Data[0] = (byte)100;
  8484. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  8485. Delay_ms(500);
  8486. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  8487. Delay_ms(500);
  8488. //启动电机进入WALK模式
  8489. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把检测,进入WALK" + "\r\n");
  8490. Code[0] = 0x22;
  8491. Code[1] = 0xF0;
  8492. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  8493. WriteACK = false;
  8494. ACK_WaitCnt = 0;
  8495. while (ACK_WaitCnt <= 2) ; //1s
  8496. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 500))
  8497. {
  8498. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第1次重发" + "\r\n");
  8499. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  8500. ACK_WaitCnt = 0;
  8501. while (ACK_WaitCnt <= 2) ; //1s
  8502. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 500))
  8503. {
  8504. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第2次重发" + "\r\n");
  8505. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  8506. ACK_WaitCnt = 0;
  8507. while (ACK_WaitCnt <= 2) ; //1s
  8508. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 500))
  8509. {
  8510. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
  8511. label_FacModeStatus.Text = "存在故障!";
  8512. label_FacModeResult.BackColor = Color.Red;
  8513. label_FacModeResult.Text = "测试异常";
  8514. Delay_ms(500);
  8515. //存储异常并上传
  8516. FacMode_Stop(false);
  8517. return;
  8518. }
  8519. }
  8520. }
  8521. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,10s内操作剎把" + "\r\n");
  8522. ACK_WaitCnt = 0;
  8523. while (ACK_WaitCnt <= 20)
  8524. {
  8525. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 100)
  8526. {
  8527. label_FacModeBreak.BackColor = Color.Green;
  8528. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把功能正常,松开剎把" + "\r\n");
  8529. break;
  8530. }
  8531. }
  8532. if (ACK_WaitCnt >= 20) //剎把超时
  8533. {
  8534. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速:" + textBox_RunInfo_MotorSpeed.Text + "," + "剎把功能异常,松开剎把" + "\r\n");
  8535. label_FacModeStatus.Text = "存在故障!";
  8536. label_FacModeResult.BackColor = Color.Red;
  8537. label_FacModeResult.Text = "测试异常";
  8538. Delay_ms(500);
  8539. //存储异常并上传
  8540. FacMode_Stop(false);
  8541. return;
  8542. }
  8543. //停止电机
  8544. Code[0] = 0x00;
  8545. Code[1] = 0xF0;
  8546. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  8547. WriteACK = false;
  8548. ACK_WaitCnt = 0;
  8549. while (ACK_WaitCnt <= 2) ; //1s
  8550. if (textBox_RunInfo_GearSt.Text != "OFF")
  8551. {
  8552. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK,第1次重发" + "\r\n");
  8553. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  8554. ACK_WaitCnt = 0;
  8555. while (ACK_WaitCnt <= 2) ; //1s
  8556. if (textBox_RunInfo_GearSt.Text != "OFF")
  8557. {
  8558. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK,第2次重发" + "\r\n");
  8559. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  8560. ACK_WaitCnt = 0;
  8561. while (ACK_WaitCnt <= 2) ; //1s
  8562. if (textBox_RunInfo_GearSt.Text != "OFF")
  8563. {
  8564. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
  8565. label_FacModeStatus.Text = "存在故障!";
  8566. label_FacModeResult.BackColor = Color.Red;
  8567. label_FacModeResult.Text = "测试异常";
  8568. Delay_ms(500);
  8569. //存储异常并上传
  8570. FacMode_Stop(false);
  8571. return;
  8572. }
  8573. }
  8574. }
  8575. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK" + "\r\n");
  8576. Delay_ms(500);
  8577. }
  8578. else
  8579. {
  8580. label_FacModeBreak.BackColor = Color.Yellow;
  8581. label_FacModeStatus.Text = "跳过刹车检测!";
  8582. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过刹车检测" + "\r\n");
  8583. Delay_ms(500);
  8584. }
  8585. //前后灯检测
  8586. if (checkBox_FacLightTest.Checked)
  8587. {
  8588. //前后灯检测
  8589. label_FacModeStatus.Text = "前后灯检测";
  8590. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开灯指令" + "\r\n");
  8591. //发送指令打开车灯
  8592. Code[0] = 0x00;
  8593. Code[1] = 0xF1;
  8594. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  8595. WriteACK = false;
  8596. ACK_WaitCnt = 0;
  8597. while (ACK_WaitCnt <= 2) ; //1s
  8598. if (textBox_RunInfo_LightSwitch.Text != "ON")
  8599. {
  8600. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令,第1次重发" + "\r\n");
  8601. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  8602. ACK_WaitCnt = 0;
  8603. while (ACK_WaitCnt <= 2); //1s
  8604. if (textBox_RunInfo_LightSwitch.Text != "ON")
  8605. {
  8606. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令,第2次重发" + "\r\n");
  8607. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  8608. ACK_WaitCnt = 0;
  8609. while (ACK_WaitCnt <= 2) ; //1s
  8610. if (textBox_RunInfo_LightSwitch.Text != "ON")
  8611. {
  8612. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令发送异常" + "\r\n");
  8613. label_FacModeStatus.Text = "存在故障!";
  8614. label_FacModeResult.BackColor = Color.Red;
  8615. label_FacModeResult.Text = "测试异常";
  8616. Delay_ms(500);
  8617. //存储异常并上传
  8618. FacMode_Stop(false);
  8619. return;
  8620. }
  8621. }
  8622. }
  8623. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已打开前后灯" + "\r\n");
  8624. Delay_ms(500);
  8625. //提示检查灯压是否正确
  8626. if (MessageBox.Show("前后灯是否正常开启?", "前后灯判断", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  8627. {
  8628. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯开启正常" + "\r\n");
  8629. Delay_ms(500);
  8630. }
  8631. else
  8632. {
  8633. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯开启异常" + "\r\n");
  8634. label_FacModeStatus.Text = "存在故障!";
  8635. label_FacModeResult.BackColor = Color.Red;
  8636. label_FacModeResult.Text = "测试异常";
  8637. Delay_ms(500);
  8638. //存储异常并上传
  8639. FacMode_Stop(false);
  8640. return;
  8641. }
  8642. //发送指令关闭车灯
  8643. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关灯指令" + "\r\n");
  8644. Code[0] = 0x00;
  8645. Code[1] = 0xF0;
  8646. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  8647. WriteACK = false;
  8648. ACK_WaitCnt = 0;
  8649. while (ACK_WaitCnt <= 2) ; //1s
  8650. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  8651. {
  8652. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令,第1次重发" + "\r\n");
  8653. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  8654. ACK_WaitCnt = 0;
  8655. while (ACK_WaitCnt <= 2) ; //1s
  8656. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  8657. {
  8658. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令,第2次重发" + "\r\n");
  8659. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  8660. ACK_WaitCnt = 0;
  8661. while (ACK_WaitCnt <= 2) ; //1s
  8662. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  8663. {
  8664. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令发送异常" + "\r\n");
  8665. label_FacModeStatus.Text = "存在故障!";
  8666. label_FacModeResult.BackColor = Color.Red;
  8667. label_FacModeResult.Text = "测试异常";
  8668. Delay_ms(500);
  8669. //存储异常并上传
  8670. FacMode_Stop(false);
  8671. return;
  8672. }
  8673. }
  8674. }
  8675. //提示检查灯压是否关闭
  8676. if (MessageBox.Show("前后灯是否正常关闭?", "前后灯判断", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  8677. {
  8678. label_FacModeLightF.BackColor = Color.Green;
  8679. label_FacModeLightB.BackColor = Color.Green;
  8680. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯关闭正常" + "\r\n");
  8681. Delay_ms(500);
  8682. }
  8683. else
  8684. {
  8685. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯关闭异常" + "\r\n");
  8686. label_FacModeStatus.Text = "存在故障!";
  8687. label_FacModeResult.BackColor = Color.Red;
  8688. label_FacModeResult.Text = "测试异常";
  8689. Delay_ms(500);
  8690. //存储异常并上传
  8691. FacMode_Stop(false);
  8692. return;
  8693. }
  8694. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已关闭前后灯" + "\r\n");
  8695. }
  8696. else
  8697. {
  8698. label_FacModeLightF.BackColor = Color.Yellow;
  8699. label_FacModeLightB.BackColor = Color.Yellow;
  8700. label_FacModeStatus.Text = "跳过前后灯检测!";
  8701. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过前后灯检测" + "\r\n");
  8702. Delay_ms(500);
  8703. }
  8704. //软件版本检测
  8705. do
  8706. {
  8707. label_FacModeStatus.Text = "软件版本确认";
  8708. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  8709. //发送指令读取版本
  8710. Class_Motor_Ver.Mode = "---";
  8711. Class_Motor_Ver.SN = "---";
  8712. Class_Motor_Ver.HW = "---";
  8713. Class_Motor_Ver.FW = "---";
  8714. Class_Motor_Ver.Special = "---";
  8715. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  8716. ACK_WaitCnt = 0;
  8717. while (ACK_WaitCnt <= 2) ; //1s
  8718. if (Class_Motor_Ver.Mode == "---")
  8719. {
  8720. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第1次重发" + "\r\n");
  8721. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  8722. ACK_WaitCnt = 0;
  8723. while (ACK_WaitCnt <= 2) ; //1s
  8724. if (Class_Motor_Ver.Mode == "---")
  8725. {
  8726. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第2次重发" + "\r\n");
  8727. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  8728. ACK_WaitCnt = 0;
  8729. while (ACK_WaitCnt <= 2) ; //1s
  8730. if (Class_Motor_Ver.Mode == "---")
  8731. {
  8732. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息失败" + "\r\n");
  8733. label_FacModeStatus.Text = "存在故障!";
  8734. label_FacModeResult.BackColor = Color.Red;
  8735. label_FacModeResult.Text = "测试异常";
  8736. Delay_ms(500);
  8737. //存储异常并上传
  8738. FacMode_Stop(false);
  8739. return;
  8740. }
  8741. }
  8742. }
  8743. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  8744. richTextBox_FacModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  8745. richTextBox_FacModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  8746. richTextBox_FacModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  8747. richTextBox_FacModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  8748. richTextBox_FacModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  8749. //判断版本是否正确
  8750. if (样机测试ToolStripMenuItem.Checked == true)
  8751. {
  8752. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "样机测试,不检测软件版本" + "\r\n");
  8753. label_FacModeFWVersion.BackColor = Color.Yellow;
  8754. break;
  8755. }
  8756. string VerCheck = "";
  8757. try
  8758. {
  8759. VerCheck = comboBox_FacModeCfgFile.Text.Split('_')[3] + "_" + comboBox_FacModeCfgFile.Text.Split('_')[4];
  8760. }
  8761. catch (System.Exception)
  8762. {
  8763. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "配置文件名格式错误" + "\r\n");
  8764. label_FacModeStatus.Text = "存在故障!";
  8765. label_FacModeResult.BackColor = Color.Red;
  8766. label_FacModeResult.Text = "测试异常";
  8767. Delay_ms(500);
  8768. //存储异常并上传
  8769. FacMode_Stop(false);
  8770. return;
  8771. }
  8772. string VerRead = "";
  8773. try
  8774. {
  8775. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  8776. }
  8777. catch (System.Exception)
  8778. {
  8779. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  8780. label_FacModeStatus.Text = "存在故障!";
  8781. label_FacModeResult.BackColor = Color.Red;
  8782. label_FacModeResult.Text = "测试异常";
  8783. Delay_ms(500);
  8784. //存储异常并上传
  8785. FacMode_Stop(false);
  8786. return;
  8787. }
  8788. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  8789. {
  8790. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误:" + VerRead + ",正确版本为:" + VerCheck + "\r\n");
  8791. label_FacModeStatus.Text = "存在故障!";
  8792. label_FacModeResult.BackColor = Color.Red;
  8793. label_FacModeResult.Text = "测试异常";
  8794. Delay_ms(500);
  8795. //存储异常并上传
  8796. FacMode_Stop(false);
  8797. return;
  8798. }
  8799. label_FacModeFWVersion.BackColor = Color.Green;
  8800. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  8801. Delay_ms(500);
  8802. } while (false);
  8803. //测试合格
  8804. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  8805. label_FacModeStatus.Text = "测试结束!";
  8806. label_FacModeResult.BackColor = Color.Green;
  8807. label_FacModeResult.Text = "测试合格";
  8808. Delay_ms(500);
  8809. //存储并上传
  8810. FacMode_Stop(true);
  8811. return;
  8812. }
  8813. private void FacModelLabelInit()
  8814. {
  8815. //测试状态标签
  8816. label_FacModeResult.BackColor = Color.Yellow;
  8817. label_FacModeResult.Text = "测试中";
  8818. //测试过程标签
  8819. label_FacModeStatus.Text = "测试就绪";
  8820. //测试结果标签
  8821. foreach (Control c in groupBox28.Controls)
  8822. {
  8823. if (c is Label)
  8824. {
  8825. if (c.Text == string.Empty)
  8826. c.BackColor = Color.Red;
  8827. }
  8828. }
  8829. }
  8830. private void comboBox_CheckModeCfgDate_Click(object sender, EventArgs e)
  8831. {
  8832. //更新生产配置文件目录
  8833. GetDateList(false);
  8834. }
  8835. private void comboBox_FacModeCfgDate_Click(object sender, EventArgs e)
  8836. {
  8837. //更新生产配置文件目录
  8838. GetDateList(false);
  8839. }
  8840. private void richTextBox_FacModeLog_TextChanged(object sender, EventArgs e)
  8841. {
  8842. richTextBox_FacModeLog.SelectionStart = richTextBox_FacModeLog.Text.Length;
  8843. richTextBox_FacModeLog.ScrollToCaret();
  8844. }
  8845. /// <summary>
  8846. /// 参数检验测试停止
  8847. /// </summary>
  8848. /// <param name="OK_Flag"></param>
  8849. private void CheckMode_Stop(bool OK_Flag)
  8850. {
  8851. //打开开始按钮
  8852. button_CheckModeStart.Enabled = true;
  8853. textBox_CheckModeScan.Enabled = true;
  8854. //导出电机参数
  8855. string Params = "";
  8856. do
  8857. {
  8858. if (!OK_Flag)
  8859. {
  8860. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试异常,不导出参数" + "\r\n");
  8861. break;
  8862. }
  8863. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "导出电机存储参数" + "\r\n");
  8864. //读取一次马达参数
  8865. richTextBox_MotorParam.Clear();
  8866. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break;
  8867. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 1 次读马达参数" + "\r\n");
  8868. ACK_WaitCnt = 0;
  8869. while (ACK_WaitCnt <= 2) //1s
  8870. {
  8871. if (richTextBox_MotorParam.Text != string.Empty)
  8872. break;
  8873. }
  8874. if (richTextBox_MotorParam.Text == string.Empty)
  8875. {
  8876. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break;
  8877. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 2 次读马达参数" + "\r\n");
  8878. ACK_WaitCnt = 0;
  8879. while (ACK_WaitCnt <= 2) //1s
  8880. {
  8881. if (richTextBox_MotorParam.Text != string.Empty)
  8882. break;
  8883. }
  8884. if (richTextBox_MotorParam.Text == string.Empty)
  8885. {
  8886. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break;
  8887. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 3 次读马达参数" + "\r\n");
  8888. ACK_WaitCnt = 0;
  8889. while (ACK_WaitCnt <= 2) //1s
  8890. {
  8891. if (richTextBox_MotorParam.Text != string.Empty)
  8892. break;
  8893. }
  8894. }
  8895. }
  8896. Params += "[马达参数]" + "\r\n" + richTextBox_MotorParam.Text + "\r\n";
  8897. Params += "\r\n";
  8898. //读取一次整车参数
  8899. richTextBox_BikeParam.Clear();
  8900. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  8901. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 1 次读整车参数" + "\r\n");
  8902. ACK_WaitCnt = 0;
  8903. while (ACK_WaitCnt <= 2) //1s
  8904. {
  8905. if (richTextBox_BikeParam.Text != string.Empty)
  8906. break;
  8907. }
  8908. if (richTextBox_BikeParam.Text == string.Empty)
  8909. {
  8910. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  8911. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 2 次读整车参数" + "\r\n");
  8912. ACK_WaitCnt = 0;
  8913. while (ACK_WaitCnt <= 2) //1s
  8914. {
  8915. if (richTextBox_BikeParam.Text != string.Empty)
  8916. break;
  8917. }
  8918. if (richTextBox_BikeParam.Text == string.Empty)
  8919. {
  8920. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  8921. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 3 次读整车参数" + "\r\n");
  8922. ACK_WaitCnt = 0;
  8923. while (ACK_WaitCnt <= 2) //1s
  8924. {
  8925. if (richTextBox_BikeParam.Text != string.Empty)
  8926. break;
  8927. }
  8928. }
  8929. }
  8930. Params += "[整车参数]" + "\r\n" + richTextBox_BikeParam.Text + "\r\n";
  8931. Params += "\r\n";
  8932. //读取一次控制参数
  8933. richTextBox_ControlParam.Clear();
  8934. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  8935. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 1 次读控制参数" + "\r\n");
  8936. ACK_WaitCnt = 0;
  8937. while (ACK_WaitCnt <= 2) //1s
  8938. {
  8939. if (richTextBox_ControlParam.Text != string.Empty)
  8940. break;
  8941. }
  8942. if (richTextBox_ControlParam.Text == string.Empty)
  8943. {
  8944. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  8945. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 2 次读控制参数" + "\r\n");
  8946. ACK_WaitCnt = 0;
  8947. while (ACK_WaitCnt <= 2) //1s
  8948. {
  8949. if (richTextBox_ControlParam.Text != string.Empty)
  8950. break;
  8951. }
  8952. if (richTextBox_ControlParam.Text == string.Empty)
  8953. {
  8954. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  8955. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 3 次读控制参数" + "\r\n");
  8956. ACK_WaitCnt = 0;
  8957. while (ACK_WaitCnt <= 2) //1s
  8958. {
  8959. if (richTextBox_ControlParam.Text != string.Empty)
  8960. break;
  8961. }
  8962. }
  8963. }
  8964. Params += "[控制参数]" + "\r\n" + richTextBox_ControlParam.Text + "\r\n";
  8965. Params += "\r\n";
  8966. //查询传感器
  8967. richTextBox_SensorParam.Clear();
  8968. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  8969. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 1 次读传感器信息" + "\r\n");
  8970. ACK_WaitCnt = 0;
  8971. while (ACK_WaitCnt <= 2) //1s
  8972. {
  8973. if (richTextBox_SensorParam.Text != string.Empty)
  8974. break;
  8975. }
  8976. if (richTextBox_SensorParam.Text == string.Empty)
  8977. {
  8978. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  8979. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 2 次读传感器信息" + "\r\n");
  8980. ACK_WaitCnt = 0;
  8981. while (ACK_WaitCnt <= 2) //1s
  8982. {
  8983. if (richTextBox_SensorParam.Text != string.Empty)
  8984. break;
  8985. }
  8986. if (richTextBox_SensorParam.Text == string.Empty)
  8987. {
  8988. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  8989. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 3 次读传感器信息" + "\r\n");
  8990. ACK_WaitCnt = 0;
  8991. while (ACK_WaitCnt <= 2) //1s
  8992. {
  8993. if (richTextBox_SensorParam.Text != string.Empty)
  8994. break;
  8995. }
  8996. }
  8997. }
  8998. Params += "[传感器参数]" + "\r\n" + richTextBox_SensorParam.Text + "\r\n";
  8999. Params += "\r\n";
  9000. //读取15次助力参数
  9001. Params += "[助力参数]" + "\r\n";
  9002. for (int i = 1; i <= 15; i++)
  9003. {
  9004. var ConfigParam = new byte[4];
  9005. richTextBox_AssistParam.Clear();
  9006. ConfigParam[0] = (byte)(i & 0xFF);
  9007. ConfigParam[1] = (byte)(i >> 8);
  9008. ConfigParam[2] = (byte)(((i >= 5) ? 5 : i) & 0xFF);
  9009. ConfigParam[3] = (byte)(((i >= 5) ? 5 : i) >> 8);
  9010. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  9011. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 1 次读助力参数 " + i.ToString() + "\r\n");
  9012. ACK_WaitCnt = 0;
  9013. while (ACK_WaitCnt <= 2) //1s
  9014. {
  9015. if (richTextBox_AssistParam.Text != string.Empty)
  9016. break;
  9017. }
  9018. if (richTextBox_AssistParam.Text == string.Empty)
  9019. {
  9020. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  9021. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 2 次读助力参数 " + i.ToString() + "\r\n");
  9022. ACK_WaitCnt = 0;
  9023. while (ACK_WaitCnt <= 2) //1s
  9024. {
  9025. if (richTextBox_AssistParam.Text != string.Empty)
  9026. break;
  9027. }
  9028. if (richTextBox_AssistParam.Text == string.Empty)
  9029. {
  9030. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  9031. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 3 次读助力参数 " + i.ToString() + "\r\n");
  9032. ACK_WaitCnt = 0;
  9033. while (ACK_WaitCnt <= 2) //1s
  9034. {
  9035. if (richTextBox_AssistParam.Text != string.Empty)
  9036. break;
  9037. }
  9038. }
  9039. }
  9040. Params += richTextBox_AssistParam.Text + "\r\n";
  9041. Params += "\r\n";
  9042. }
  9043. //读取一次调试信息
  9044. richTextBox_DebugParam.Clear();
  9045. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  9046. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 1 次读调试信息" + "\r\n");
  9047. ACK_WaitCnt = 0;
  9048. while (ACK_WaitCnt <= 2) //1s
  9049. {
  9050. if (richTextBox_DebugParam.Text != string.Empty)
  9051. break;
  9052. }
  9053. if (richTextBox_DebugParam.Text == string.Empty)
  9054. {
  9055. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  9056. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 2 次读调试信息" + "\r\n");
  9057. ACK_WaitCnt = 0;
  9058. while (ACK_WaitCnt <= 2) //1s
  9059. {
  9060. if (richTextBox_DebugParam.Text != string.Empty)
  9061. break;
  9062. }
  9063. if (richTextBox_DebugParam.Text == string.Empty)
  9064. {
  9065. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  9066. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 3 次读调试信息" + "\r\n");
  9067. ACK_WaitCnt = 0;
  9068. while (ACK_WaitCnt <= 2) //1s
  9069. {
  9070. if (richTextBox_DebugParam.Text != string.Empty)
  9071. break;
  9072. }
  9073. }
  9074. }
  9075. Params += "[调试参数]" + "\r\n" + richTextBox_DebugParam.Text + "\r\n";
  9076. Params += "\r\n";
  9077. //读取一次历史信息
  9078. richTextBox_Record.Clear();
  9079. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  9080. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 1 次读历史信息" + "\r\n");
  9081. ACK_WaitCnt = 0;
  9082. while (ACK_WaitCnt <= 2) //1s
  9083. {
  9084. if (richTextBox_Record.Text != string.Empty)
  9085. break;
  9086. }
  9087. if (richTextBox_Record.Text == string.Empty)
  9088. {
  9089. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  9090. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 2 次读历史信息" + "\r\n");
  9091. ACK_WaitCnt = 0;
  9092. while (ACK_WaitCnt <= 2) //1s
  9093. {
  9094. if (richTextBox_Record.Text != string.Empty)
  9095. break;
  9096. }
  9097. if (richTextBox_Record.Text == string.Empty)
  9098. {
  9099. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  9100. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 3 次读历史信息" + "\r\n");
  9101. ACK_WaitCnt = 0;
  9102. while (ACK_WaitCnt <= 2) //1s
  9103. {
  9104. if (richTextBox_Record.Text != string.Empty)
  9105. break;
  9106. }
  9107. }
  9108. }
  9109. Params += "[历史信息]" + "\r\n" + richTextBox_Record.Text + "\r\n";
  9110. Params += "\r\n";
  9111. //读取一次MOS内阻校准参数
  9112. foreach (Control c in groupBox21.Controls)
  9113. {
  9114. if (c is TextBox)
  9115. c.Text = "";
  9116. }
  9117. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  9118. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 1 次读MOS内阻校准参数" + "\r\n");
  9119. ACK_WaitCnt = 0;
  9120. while (ACK_WaitCnt <= 2) //1s
  9121. {
  9122. if (textBox_MOS_K1.Text != string.Empty)
  9123. break;
  9124. }
  9125. if (textBox_MOS_K1.Text == string.Empty)
  9126. {
  9127. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null)) break;
  9128. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 2 次读MOS内阻校准参数" + "\r\n");
  9129. ACK_WaitCnt = 0;
  9130. while (ACK_WaitCnt <= 2) //1s
  9131. {
  9132. if (textBox_MOS_K1.Text != string.Empty)
  9133. break;
  9134. }
  9135. if (textBox_MOS_K1.Text == string.Empty)
  9136. {
  9137. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null)) break;
  9138. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 3 次读MOS内阻校准参数" + "\r\n");
  9139. ACK_WaitCnt = 0;
  9140. while (ACK_WaitCnt <= 2) //1s
  9141. {
  9142. if (textBox_MOS_K1.Text != string.Empty)
  9143. break;
  9144. }
  9145. }
  9146. }
  9147. Params += "[MOS内阻校准参数]" + "\r\n";
  9148. Params += textBox_MOS_K1.Text + ", " + textBox_MOS_K2.Text + ", " + textBox_MOS_K3.Text + ", " + textBox_MOS_K4.Text + ", "
  9149. + textBox_MOS_K5.Text + ", " + textBox_MOS_R1.Text + ", " + textBox_MOS_R2.Text + ", " + textBox_MOS_R3.Text + ", " + "\r\n";
  9150. Params += "\r\n";
  9151. //读取一次整车参数2
  9152. richTextBox_BikeParam2.Clear();
  9153. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null)) break;
  9154. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 1 次读整车参数2" + "\r\n");
  9155. ACK_WaitCnt = 0;
  9156. while (ACK_WaitCnt <= 2) //1s
  9157. {
  9158. if (richTextBox_BikeParam2.Text != string.Empty)
  9159. break;
  9160. }
  9161. if (richTextBox_BikeParam2.Text == string.Empty)
  9162. {
  9163. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null)) break;
  9164. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 2 次读整车参数2" + "\r\n");
  9165. ACK_WaitCnt = 0;
  9166. while (ACK_WaitCnt <= 2) //1s
  9167. {
  9168. if (richTextBox_BikeParam2.Text != string.Empty)
  9169. break;
  9170. }
  9171. if (richTextBox_BikeParam2.Text == string.Empty)
  9172. {
  9173. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null)) break;
  9174. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 3 次读整车参数2" + "\r\n");
  9175. ACK_WaitCnt = 0;
  9176. while (ACK_WaitCnt <= 2) //1s
  9177. {
  9178. if (richTextBox_BikeParam2.Text != string.Empty)
  9179. break;
  9180. }
  9181. }
  9182. }
  9183. Params += "[整车参数2]" + "\r\n" + richTextBox_BikeParam2.Text + "\r\n";
  9184. Params += "\r\n";
  9185. //读取一次用户骑行参数
  9186. richTextBox_UsrRidesParam.Clear();
  9187. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null)) break;
  9188. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 1 次读用户骑行参数" + "\r\n");
  9189. ACK_WaitCnt = 0;
  9190. while (ACK_WaitCnt <= 2) //1s
  9191. {
  9192. if (richTextBox_UsrRidesParam.Text != string.Empty)
  9193. break;
  9194. }
  9195. if (richTextBox_UsrRidesParam.Text == string.Empty)
  9196. {
  9197. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null)) break;
  9198. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 2 次读用户骑行参数" + "\r\n");
  9199. ACK_WaitCnt = 0;
  9200. while (ACK_WaitCnt <= 2) //1s
  9201. {
  9202. if (richTextBox_UsrRidesParam.Text != string.Empty)
  9203. break;
  9204. }
  9205. if (richTextBox_UsrRidesParam.Text == string.Empty)
  9206. {
  9207. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null)) break;
  9208. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 3 次读用户骑行参数" + "\r\n");
  9209. ACK_WaitCnt = 0;
  9210. while (ACK_WaitCnt <= 2) //1s
  9211. {
  9212. if (richTextBox_UsrRidesParam.Text != string.Empty)
  9213. break;
  9214. }
  9215. }
  9216. }
  9217. Params += "[用户骑行参数]" + "\r\n" + richTextBox_UsrRidesParam.Text + "\r\n";
  9218. Params += "\r\n";
  9219. //读取一次生产信息
  9220. textBox_MAC.Text = "";
  9221. textBox_MACAdd.Text = "";
  9222. textBox_MACDate.Text = "";
  9223. textBox_PP.Text = "";
  9224. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  9225. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 1 次读生产信息" + "\r\n");
  9226. ACK_WaitCnt = 0;
  9227. while (ACK_WaitCnt <= 2) //1s
  9228. {
  9229. if (textBox_MAC.Text != string.Empty)
  9230. break;
  9231. }
  9232. if (textBox_MAC.Text == string.Empty)
  9233. {
  9234. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  9235. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 2 次读生产信息" + "\r\n");
  9236. ACK_WaitCnt = 0;
  9237. while (ACK_WaitCnt <= 2) //1s
  9238. {
  9239. if (textBox_MAC.Text != string.Empty)
  9240. break;
  9241. }
  9242. if (textBox_MAC.Text == string.Empty)
  9243. {
  9244. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  9245. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 3 次读生产信息" + "\r\n");
  9246. ACK_WaitCnt = 0;
  9247. while (ACK_WaitCnt <= 2) //1s
  9248. {
  9249. if (textBox_MAC.Text != string.Empty)
  9250. break;
  9251. }
  9252. }
  9253. }
  9254. Params += "[生产信息]" + "\r\n";
  9255. Params += "生产商: " + textBox_MAC.Text + "\r\n";
  9256. Params += "生产地: " + textBox_MACAdd.Text + "\r\n";
  9257. Params += "生产日期: " + textBox_MACDate.Text + "\r\n";
  9258. Params += "产品标识: " + textBox_PP.Text + "\r\n";
  9259. Params += "\r\n";
  9260. //读取一次自定义信息
  9261. textBox_User1.Text = "---";
  9262. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  9263. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 1 次读自定义信息1" + "\r\n");
  9264. ACK_WaitCnt = 0;
  9265. while (ACK_WaitCnt <= 2) //1s
  9266. {
  9267. if (textBox_User1.Text != string.Empty)
  9268. break;
  9269. }
  9270. if (textBox_User1.Text == string.Empty)
  9271. {
  9272. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  9273. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 2 次读自定义信息1" + "\r\n");
  9274. ACK_WaitCnt = 0;
  9275. while (ACK_WaitCnt <= 2) //1s
  9276. {
  9277. if (textBox_User1.Text != string.Empty)
  9278. break;
  9279. }
  9280. if (textBox_User1.Text == string.Empty)
  9281. {
  9282. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  9283. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 3 次读自定义信息1" + "\r\n");
  9284. ACK_WaitCnt = 0;
  9285. while (ACK_WaitCnt <= 2) //1s
  9286. {
  9287. if (textBox_User1.Text != string.Empty)
  9288. break;
  9289. }
  9290. }
  9291. }
  9292. textBox_User2.Text = "---";
  9293. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  9294. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 1 次读自定义信息2" + "\r\n");
  9295. ACK_WaitCnt = 0;
  9296. while (ACK_WaitCnt <= 2) //1s
  9297. {
  9298. if (textBox_User2.Text != string.Empty)
  9299. break;
  9300. }
  9301. if (textBox_User2.Text == string.Empty)
  9302. {
  9303. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  9304. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 2 次读自定义信息2" + "\r\n");
  9305. ACK_WaitCnt = 0;
  9306. while (ACK_WaitCnt <= 2) //1s
  9307. {
  9308. if (textBox_User2.Text != string.Empty)
  9309. break;
  9310. }
  9311. if (textBox_User2.Text == string.Empty)
  9312. {
  9313. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  9314. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 3 次读自定义信息2" + "\r\n");
  9315. ACK_WaitCnt = 0;
  9316. while (ACK_WaitCnt <= 2) //1s
  9317. {
  9318. if (textBox_User2.Text != string.Empty)
  9319. break;
  9320. }
  9321. }
  9322. }
  9323. textBox_User3.Text = "---";
  9324. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  9325. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 1 次读自定义信息3" + "\r\n");
  9326. ACK_WaitCnt = 0;
  9327. while (ACK_WaitCnt <= 2) //1s
  9328. {
  9329. if (textBox_User3.Text != string.Empty)
  9330. break;
  9331. }
  9332. if (textBox_User3.Text == string.Empty)
  9333. {
  9334. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  9335. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 2 次读自定义信息3" + "\r\n");
  9336. ACK_WaitCnt = 0;
  9337. while (ACK_WaitCnt <= 2) //1s
  9338. {
  9339. if (textBox_User3.Text != string.Empty)
  9340. break;
  9341. }
  9342. if (textBox_User3.Text == string.Empty)
  9343. {
  9344. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  9345. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 3 次读自定义信息3" + "\r\n");
  9346. ACK_WaitCnt = 0;
  9347. while (ACK_WaitCnt <= 2) //1s
  9348. {
  9349. if (textBox_User3.Text != string.Empty)
  9350. break;
  9351. }
  9352. }
  9353. }
  9354. Params += "[自定义信息]" + "\r\n";
  9355. Params += "自定义1: " + textBox_User1.Text + "\r\n";
  9356. Params += "自定义2: " + textBox_User2.Text + "\r\n";
  9357. Params += "自定义3: " + textBox_User3.Text + "\r\n";
  9358. Params += "\r\n";
  9359. //读取一次密钥
  9360. textBox_Key.Text = "---";
  9361. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  9362. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 1 次读密钥" + "\r\n");
  9363. ACK_WaitCnt = 0;
  9364. while (ACK_WaitCnt <= 2) //1s
  9365. {
  9366. if (textBox_Key.Text != string.Empty)
  9367. break;
  9368. }
  9369. if (textBox_Key.Text == string.Empty)
  9370. {
  9371. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  9372. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 2 次读密钥" + "\r\n");
  9373. ACK_WaitCnt = 0;
  9374. while (ACK_WaitCnt <= 2) //1s
  9375. {
  9376. if (textBox_Key.Text != string.Empty)
  9377. break;
  9378. }
  9379. if (textBox_Key.Text == string.Empty)
  9380. {
  9381. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  9382. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 3 次读密钥" + "\r\n");
  9383. ACK_WaitCnt = 0;
  9384. while (ACK_WaitCnt <= 2) //1s
  9385. {
  9386. if (textBox_Key.Text != string.Empty)
  9387. break;
  9388. }
  9389. }
  9390. }
  9391. Params += "[校验密钥]" + "\r\n" + textBox_Key.Text + "\r\n";
  9392. Params += "\r\n";
  9393. //读取一次存储标志
  9394. radioButton_EE_SaveYes.Checked = false;
  9395. radioButton_EE_SaveNo.Checked = false;
  9396. radioButton_SIP_SaveYes.Checked = false;
  9397. radioButton_SIP_SaveNo.Checked = false;
  9398. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  9399. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 1 次读存储标志" + "\r\n");
  9400. ACK_WaitCnt = 0;
  9401. while (ACK_WaitCnt <= 2) //1s
  9402. {
  9403. if ((radioButton_EE_SaveYes.Checked | radioButton_EE_SaveNo.Checked | radioButton_SIP_SaveYes.Checked | radioButton_SIP_SaveNo.Checked) == true)
  9404. break;
  9405. }
  9406. if ((radioButton_EE_SaveYes.Checked | radioButton_EE_SaveNo.Checked | radioButton_SIP_SaveYes.Checked | radioButton_SIP_SaveNo.Checked) == false)
  9407. {
  9408. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  9409. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 2 次读存储标志" + "\r\n");
  9410. ACK_WaitCnt = 0;
  9411. while (ACK_WaitCnt <= 2) //1s
  9412. {
  9413. if ((radioButton_EE_SaveYes.Checked | radioButton_EE_SaveNo.Checked | radioButton_SIP_SaveYes.Checked | radioButton_SIP_SaveNo.Checked) == true)
  9414. break;
  9415. }
  9416. if ((radioButton_EE_SaveYes.Checked | radioButton_EE_SaveNo.Checked | radioButton_SIP_SaveYes.Checked | radioButton_SIP_SaveNo.Checked) == false)
  9417. {
  9418. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  9419. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 3 次读存储标志" + "\r\n");
  9420. ACK_WaitCnt = 0;
  9421. while (ACK_WaitCnt <= 2) //1s
  9422. {
  9423. if ((radioButton_EE_SaveYes.Checked | radioButton_EE_SaveNo.Checked | radioButton_SIP_SaveYes.Checked | radioButton_SIP_SaveNo.Checked) == true)
  9424. break;
  9425. }
  9426. }
  9427. }
  9428. Params += "[存储标志]" + "\r\n";
  9429. Params += "EEPROM: " + ((radioButton_EE_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  9430. Params += "SIP: " + ((radioButton_SIP_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  9431. Params += "\r\n";
  9432. } while (false);
  9433. var Code = new byte[32];//发送的指令数据
  9434. //退出配置模式
  9435. Code[0] = 0x00;
  9436. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  9437. Delay_ms(1000);
  9438. //系统关机
  9439. Code[0] = 0xF0;
  9440. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  9441. //关闭串口
  9442. if (mySerialProcess.SerialClose(false))
  9443. {
  9444. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "串口已关闭" + "\r\n");
  9445. toolStripComboBox_ComNum.Enabled = true;
  9446. toolStripComboBox_Baudrate.Enabled = true;
  9447. 刷新ToolStripMenuItem.Enabled = true;
  9448. 连接ToolStripMenuItem.Text = "连接";
  9449. 连接ToolStripMenuItem.Checked = false;
  9450. label_COM_Sta.Text = "连接状态:未连接";
  9451. label_PortStatus.BackColor = Color.Red;
  9452. }
  9453. //路径设置
  9454. string LocalSavePath = "";
  9455. string ServerSavePath = "";
  9456. if (OK_Flag)
  9457. {
  9458. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "OK\\";
  9459. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/OK/";
  9460. }
  9461. else
  9462. {
  9463. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "FAIL\\";
  9464. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/FAIL/";
  9465. }
  9466. if (Directory.Exists(LocalSavePath) == false)
  9467. {
  9468. Directory.CreateDirectory(LocalSavePath);
  9469. }
  9470. //保存和上传
  9471. string LogSavePath = "";
  9472. string LogSaveFileName = "";
  9473. string ProductInfo = textBox_CheckModeScan.Text.Replace(" ", "_").Replace("/", "-"); ;
  9474. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  9475. if (Directory.Exists(LogSavePath) == false)
  9476. {
  9477. Directory.CreateDirectory(LogSavePath);
  9478. }
  9479. //测试页面
  9480. Double scaleX = PrimaryScreen.ScaleX;
  9481. Double scaleY = PrimaryScreen.ScaleY;
  9482. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  9483. Graphics g = Graphics.FromImage(bit);
  9484. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  9485. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  9486. bit.Save(LogSaveFileName);
  9487. //上传测试页面到服务器
  9488. if (myFtp.IsNetConnected == true)
  9489. {
  9490. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  9491. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  9492. {
  9493. myFtp.MakeDir(ServerSavePath + DateNow);
  9494. }
  9495. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  9496. {
  9497. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  9498. }
  9499. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  9500. if (result == true)
  9501. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  9502. }
  9503. //测试记录
  9504. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  9505. string file_str = "";
  9506. file_str += "计算机名称:\r\n" + label_Computername.Text + "\r\n";
  9507. file_str += "软件运行时间:\r\n" + stopwatch.ElapsedMilliseconds.ToString() + " ms" + "\r\n";
  9508. file_str += "软件运行次数:\r\n" + File.ReadAllText(localInfo.LocalPath + localInfo.PowerTimesFilename) + "\r\n";
  9509. file_str += "系统时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  9510. file_str += "检验记录:\r\n" + richTextBox_CheckModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  9511. file_str += "检验结果:\r\n" + label_CheckModeResult.Text + "\r\n\r\n";
  9512. file_str += Local_HdInformation;
  9513. file_str += "\r\n电机存储参数:\r\n" + Params + "\r\n";
  9514. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  9515. //上传测试记录到服务器
  9516. if (myFtp.IsNetConnected == true)
  9517. {
  9518. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  9519. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  9520. {
  9521. myFtp.MakeDir(ServerSavePath + DateNow);
  9522. }
  9523. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  9524. {
  9525. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  9526. }
  9527. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  9528. if (result == true)
  9529. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  9530. }
  9531. //扫码框清空
  9532. textBox_CheckModeScan.Text = "";
  9533. }
  9534. /// <summary>
  9535. /// 参数检验开始
  9536. /// </summary>
  9537. /// <param name="sender"></param>
  9538. /// <param name="e"></param>
  9539. private void button_CheckModeStart_Click(object sender, EventArgs e)
  9540. {
  9541. //测试项目关闭编辑
  9542. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  9543. foreach (Control c in groupBox29.Controls)
  9544. {
  9545. if (c is CheckBox)
  9546. c.Enabled = false;
  9547. }
  9548. ReadLockStatus = true;
  9549. //检查配置文件
  9550. if (comboBox_CheckModeCfgFile.Text == "")
  9551. {
  9552. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9553. return;
  9554. }
  9555. //开始测试
  9556. CheckTestStart();
  9557. }
  9558. /// <summary>
  9559. /// 参数检验测试子函数
  9560. /// </summary>
  9561. private void CheckTestStart()
  9562. {
  9563. //初始化标签
  9564. CheckModeLabelInit();
  9565. richTextBox_CheckModeLog.Clear();
  9566. //按钮禁止操作
  9567. button_CheckModeStart.Enabled = false;
  9568. textBox_CheckModeScan.Enabled = false;
  9569. //记录配置文件
  9570. richTextBox_CheckModeLog.AppendText("配置文件:" + comboBox_CheckModeCfgDate.Text + " / " + comboBox_CheckModeCfgFile.Text + "\r\n");
  9571. //检查打标信息
  9572. label_CheckModeStatus.Text = "检查扫码信息";
  9573. Delay_ms(500);
  9574. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  9575. if (textBox_CheckModeScan.Text == string.Empty)
  9576. {
  9577. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9578. button_CheckModeStart.Enabled = true;
  9579. textBox_CheckModeScan.Enabled = true;
  9580. return;
  9581. }
  9582. try
  9583. {
  9584. if (中置电机MIGIC_ToolStripMenuItem.Checked == true)
  9585. {
  9586. if (textBox_CheckModeScan.Text.Split(' ').Length != 7)
  9587. {
  9588. label_CheckModeStatus.Text = "存在故障!";
  9589. label_CheckModeResult.BackColor = Color.Red;
  9590. label_CheckModeResult.Text = "标签格式错误";
  9591. button_CheckModeStart.Enabled = true;
  9592. textBox_CheckModeScan.Enabled = true;
  9593. return;
  9594. }
  9595. }
  9596. else if (中置电机VP_ToolStripMenuItem.Checked == true)
  9597. {
  9598. if (textBox_CheckModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 2)
  9599. {
  9600. label_CheckModeStatus.Text = "存在故障!";
  9601. label_CheckModeResult.BackColor = Color.Red;
  9602. label_CheckModeResult.Text = "标签格式错误";
  9603. button_CheckModeStart.Enabled = true;
  9604. textBox_CheckModeScan.Enabled = true;
  9605. return;
  9606. }
  9607. }
  9608. else if (轮毂电机ToolStripMenuItem.Checked == true)
  9609. {
  9610. if (textBox_CheckModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  9611. {
  9612. label_CheckModeStatus.Text = "存在故障!";
  9613. label_CheckModeResult.BackColor = Color.Red;
  9614. label_CheckModeResult.Text = "标签格式错误";
  9615. button_CheckModeStart.Enabled = true;
  9616. textBox_CheckModeScan.Enabled = true;
  9617. return;
  9618. }
  9619. }
  9620. }
  9621. catch (System.Exception ex)
  9622. {
  9623. label_CheckModeStatus.Text = "存在故障!";
  9624. label_CheckModeResult.BackColor = Color.Red;
  9625. label_CheckModeResult.Text = "标签格式错误";
  9626. button_CheckModeStart.Enabled = true;
  9627. textBox_CheckModeScan.Enabled = true;
  9628. System.Windows.Forms.MessageBox.Show(ex.Message);
  9629. return;
  9630. }
  9631. //打开串口
  9632. if (mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false))
  9633. {
  9634. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "打开串口成功" + "\r\n");
  9635. toolStripComboBox_ComNum.Enabled = false;
  9636. toolStripComboBox_Baudrate.Enabled = false;
  9637. 刷新ToolStripMenuItem.Enabled = false;
  9638. 连接ToolStripMenuItem.Text = "断开";
  9639. 连接ToolStripMenuItem.Checked = true;
  9640. label_COM_Sta.Text = toolStripComboBox_ComNum.Text + "已连接," + toolStripComboBox_Baudrate.Text;
  9641. label_PortStatus.BackColor = Color.Green;
  9642. }
  9643. if (!mySerialProcess.mySerial.IsOpen)
  9644. {
  9645. MessageBox.Show("请检查串口连接!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9646. button__FacMode_Start.Enabled = false;
  9647. return;
  9648. }
  9649. //流水号计数
  9650. int serial = Convert.ToInt32(label_CheckModeSerial.Text);
  9651. serial += 1;
  9652. label_CheckModeSerial.Text = serial.ToString();
  9653. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, serial.ToString());
  9654. //创建线程,执行测试任务
  9655. Thread th = new Thread(CheckModeTest_Task);
  9656. th.Start();
  9657. }
  9658. /// <summary>
  9659. /// 执行一次测试任务
  9660. /// </summary>
  9661. private void CheckModeTest_Task()
  9662. {
  9663. //开始测试
  9664. richTextBox_CheckModeLog.AppendText("产品标签:" + textBox_CheckModeScan.Text + "\r\n");
  9665. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  9666. //变量定义
  9667. var Code = new byte[255];//发送的指令数据
  9668. label_CheckModeStatus.Text = "开始测试";
  9669. Delay_ms(500);
  9670. label_CheckModeStatus.Text = "系统开机";
  9671. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  9672. if (uARTToolStripMenuItem.Checked)
  9673. {
  9674. Code[0] = (byte)'R';
  9675. Code[1] = (byte)'E';
  9676. Code[2] = (byte)'S';
  9677. Code[3] = (byte)'E';
  9678. Code[4] = (byte)'T';
  9679. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  9680. Delay_ms(500);
  9681. }
  9682. //系统开机,确保测试前先关机,发送关机指令再发送开机指令
  9683. //确保测试前先关机,发送关机指令再发送开机指令
  9684. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  9685. Code[0] = 0xF0;
  9686. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  9687. Delay_ms(4000);
  9688. BootInfo = "";
  9689. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  9690. Code[0] = 0xF1;
  9691. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  9692. ACK_WaitCnt = 0;
  9693. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  9694. while (ACK_WaitCnt <= 20)
  9695. {
  9696. if (!uARTToolStripMenuItem.Checked) //CAN接口不考虑联动装置盒切换为Boot波特率
  9697. {
  9698. if (BootInfo != string.Empty)
  9699. break;
  9700. }
  9701. }
  9702. //检查BOOT版本
  9703. if (BootInfo != string.Empty)
  9704. {
  9705. label_CheckModeBoot.BackColor = Color.Green;
  9706. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  9707. Delay_ms(500);
  9708. }
  9709. else
  9710. {
  9711. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
  9712. label_CheckModeStatus.Text = "存在故障!";
  9713. label_CheckModeResult.BackColor = Color.Red;
  9714. label_CheckModeResult.Text = "测试异常";
  9715. Delay_ms(500);
  9716. //存储异常并上传
  9717. CheckMode_Stop(false);
  9718. return;
  9719. }
  9720. #if false
  9721. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  9722. {
  9723. Code[0] = 0x00;//5S协议
  9724. Code[1] = 0x00;
  9725. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  9726. Delay_ms(500);
  9727. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  9728. Delay_ms(500);
  9729. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  9730. }
  9731. #endif
  9732. //发送指令读取版本信息
  9733. do
  9734. {
  9735. label_CheckModeStatus.Text = "读取版本信息";
  9736. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  9737. //发送指令读取版本
  9738. Class_Motor_Ver.Mode = "---";
  9739. Class_Motor_Ver.SN = "---";
  9740. Class_Motor_Ver.HW = "---";
  9741. Class_Motor_Ver.FW = "---";
  9742. Class_Motor_Ver.Special = "---";
  9743. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  9744. ACK_WaitCnt = 0;
  9745. while (ACK_WaitCnt <= 2) ; //1s
  9746. if (Class_Motor_Ver.Mode == "---")
  9747. {
  9748. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第1次重发" + "\r\n");
  9749. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  9750. ACK_WaitCnt = 0;
  9751. while (ACK_WaitCnt <= 2) ; //1s
  9752. if (Class_Motor_Ver.Mode == "---")
  9753. {
  9754. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第2次重发" + "\r\n");
  9755. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  9756. ACK_WaitCnt = 0;
  9757. while (ACK_WaitCnt <= 2) ; //1s
  9758. if (Class_Motor_Ver.Mode == "---")
  9759. {
  9760. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取失败" + "\r\n");
  9761. label_CheckModeStatus.Text = "存在故障!";
  9762. label_CheckModeResult.BackColor = Color.Red;
  9763. label_CheckModeResult.Text = "测试异常";
  9764. Delay_ms(500);
  9765. //存储异常并上传
  9766. CheckMode_Stop(false);
  9767. return;
  9768. }
  9769. }
  9770. }
  9771. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  9772. richTextBox_CheckModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  9773. richTextBox_CheckModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  9774. richTextBox_CheckModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  9775. richTextBox_CheckModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  9776. richTextBox_CheckModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  9777. Delay_ms(500);
  9778. } while (false);
  9779. //软件版本检查
  9780. if (checkBox_CheckModeFWVer.Checked)
  9781. {
  9782. //判断版本是否正确
  9783. string VerCheck = comboBox_CheckModeCfgFile.Text.Split('_')[3] + "_" + comboBox_CheckModeCfgFile.Text.Split('_')[4];
  9784. string VerRead = "";
  9785. try
  9786. {
  9787. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  9788. }
  9789. catch (System.Exception)
  9790. {
  9791. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  9792. label_CheckModeStatus.Text = "存在故障!";
  9793. label_CheckModeResult.BackColor = Color.Red;
  9794. label_CheckModeResult.Text = "测试异常";
  9795. Delay_ms(500);
  9796. //存储异常并上传
  9797. CheckMode_Stop(false);
  9798. return;
  9799. }
  9800. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  9801. {
  9802. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
  9803. label_CheckModeStatus.Text = "存在故障!";
  9804. label_CheckModeResult.BackColor = Color.Red;
  9805. label_CheckModeResult.Text = "测试异常";
  9806. Delay_ms(500);
  9807. //存储异常并上传
  9808. CheckMode_Stop(false);
  9809. return;
  9810. }
  9811. label_CheckModeFWVer.BackColor = Color.Green;
  9812. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  9813. Delay_ms(500);
  9814. }
  9815. else
  9816. {
  9817. label_CheckModeFWVer.BackColor = Color.Yellow;
  9818. label_CheckModeStatus.Text = "跳过软件版本查询";
  9819. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过软件版本查询" + "\r\n");
  9820. Delay_ms(500);
  9821. }
  9822. //打标信息核对
  9823. if (checkBox_CheckModeSN.Checked)
  9824. {
  9825. label_CheckModeStatus.Text = "核对打标信息";
  9826. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "核对打标信息" + "\r\n");
  9827. //根据扫码信息获取型号和SN
  9828. string ScanInfo = textBox_CheckModeScan.Text;
  9829. string regexInfo = "";
  9830. string[] InfoList = { "" };
  9831. try
  9832. {
  9833. if (中置电机MIGIC_ToolStripMenuItem.Checked == true)
  9834. {
  9835. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  9836. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  9837. }
  9838. else if (中置电机VP_ToolStripMenuItem.Checked == true)
  9839. {
  9840. Regex regex = new Regex(@"^M[12][0-9](0?[1-9]|1[0-2])((0?[1-9])|((1|2)[0-9])|30|31)[A-Z]\d{4}[A-Z][A-Z]?$");
  9841. if (ScanInfo.Contains(" "))
  9842. {
  9843. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  9844. string Mode = InfoList[0];
  9845. string Sn = InfoList[1];
  9846. if (regex.IsMatch(Sn) == false)
  9847. {
  9848. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN格式错误" + "\r\n");
  9849. label_FacModeStatus.Text = "存在故障!";
  9850. label_FacModeResult.BackColor = Color.Red;
  9851. label_FacModeResult.Text = "标签格式错误";
  9852. Delay_ms(500);
  9853. //存储异常并上传
  9854. FacMode_Stop(false);
  9855. return;
  9856. }
  9857. }
  9858. else
  9859. {
  9860. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  9861. label_FacModeStatus.Text = "存在故障!";
  9862. label_FacModeResult.BackColor = Color.Red;
  9863. label_FacModeResult.Text = "标签格式错误";
  9864. Delay_ms(500);
  9865. //存储异常并上传
  9866. FacMode_Stop(false);
  9867. return;
  9868. }
  9869. }
  9870. else if (轮毂电机ToolStripMenuItem.Checked == true)
  9871. {
  9872. if (!ScanInfo.Contains("/")) //老编码规则
  9873. {
  9874. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  9875. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  9876. string Spec = InfoList[1];
  9877. string Sn = InfoList[2];
  9878. InfoList[0] = Model.Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  9879. InfoList[1] = Sn;
  9880. }
  9881. else //新编码规则
  9882. {
  9883. Dictionary<string, string> Dic_Ver = new Dictionary<string, string>
  9884. {
  9885. { "01", "A" },
  9886. { "02", "B" },
  9887. { "03", "C" },
  9888. { "04", "D" },
  9889. { "05", "E" },
  9890. { "06", "F" },
  9891. { "07", "G" },
  9892. { "08", "H" },
  9893. { "09", "I" }
  9894. };
  9895. Dictionary<string, string> Dic_Vol = new Dictionary<string, string>
  9896. {
  9897. { "24V", "A" },
  9898. { "36V", "B" },
  9899. { "42V", "C" },
  9900. { "48V", "D" },
  9901. { "52V", "E" },
  9902. { "60V", "F" }
  9903. };
  9904. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  9905. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  9906. string Spec = InfoList[1].Replace("-", "").Replace("/", "");
  9907. string Sn = InfoList[2];
  9908. InfoList[0] = Model[2] + Dic_Ver[Model.Substring(3, 2)] + Model[5] + Dic_Ver[Model.Substring(6, 2)] + Model[9];
  9909. InfoList[0] += Dic_Vol[Spec.Substring(0, 3)] + Spec.Substring(3, 3) + Spec.Substring(13, 4) + Spec.Substring(Spec.Length - 4, 3);
  9910. InfoList[1] = Sn;
  9911. }
  9912. }
  9913. }
  9914. catch
  9915. {
  9916. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  9917. label_FacModeStatus.Text = "存在故障!";
  9918. label_FacModeResult.BackColor = Color.Red;
  9919. label_FacModeResult.Text = "标签格式错误";
  9920. Delay_ms(500);
  9921. //存储异常并上传
  9922. CheckMode_Stop(false);
  9923. return;
  9924. }
  9925. //核对型号
  9926. if (string.Equals(InfoList[0], Class_Motor_Ver.Mode) == false) //型号错误,直接结束
  9927. {
  9928. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号不一致" + "\r\n");
  9929. label_CheckModeStatus.Text = "存在故障!";
  9930. label_CheckModeResult.BackColor = Color.Red;
  9931. label_CheckModeResult.Text = "测试异常";
  9932. Delay_ms(500);
  9933. //存储异常并上传
  9934. CheckMode_Stop(false);
  9935. return;
  9936. }
  9937. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号一致" + "\r\n");
  9938. Delay_ms(500);
  9939. //核对SN
  9940. if (string.Equals(InfoList[1], Class_Motor_Ver.SN) == false) //型号错误,直接结束
  9941. {
  9942. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN不一致" + "\r\n");
  9943. label_CheckModeStatus.Text = "存在故障!";
  9944. label_CheckModeResult.BackColor = Color.Red;
  9945. label_CheckModeResult.Text = "测试异常";
  9946. Delay_ms(500);
  9947. //存储异常并上传
  9948. CheckMode_Stop(false);
  9949. return;
  9950. }
  9951. label_CheckModeSN.BackColor = Color.Green;
  9952. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN一致" + "\r\n");
  9953. Delay_ms(500);
  9954. }
  9955. else
  9956. {
  9957. label_CheckModeSN.BackColor = Color.Yellow;
  9958. label_CheckModeStatus.Text = "跳过打标信息确认";
  9959. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过打标信息确认" + "\r\n");
  9960. Delay_ms(500);
  9961. }
  9962. //参数检验
  9963. if (checkBox_CheckModeCfg.Checked)
  9964. {
  9965. //读取配置文件信息
  9966. label_CheckModeStatus.Text = "参数检查";
  9967. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  9968. //配置文件
  9969. List<byte[]> CmdList = new List<byte[]>();
  9970. Dictionary<string, string> ConfigCmd = new Dictionary<string, string>();//配置文件格式
  9971. //从服务器下载文件
  9972. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  9973. {
  9974. string SelectFile = "";
  9975. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "/" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  9976. if (File.Exists(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  9977. {
  9978. File.Delete(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  9979. }
  9980. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  9981. //打开文件
  9982. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  9983. ConfigCmd.Clear();
  9984. while (streamReader.Peek() != -1)
  9985. {
  9986. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  9987. if (fileLineInfo.Contains("["))
  9988. {
  9989. if (fileLineInfo.Contains("助力参数"))
  9990. {
  9991. fileLineInfo = streamReader.ReadLine();
  9992. }
  9993. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  9994. }
  9995. }
  9996. streamReader.Close();
  9997. }
  9998. //从本地加载文件
  9999. else
  10000. {
  10001. string SelectFile = "";
  10002. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  10003. //打开文件
  10004. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  10005. ConfigCmd.Clear();
  10006. while (streamReader.Peek() != -1)
  10007. {
  10008. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  10009. if (fileLineInfo.Contains("["))
  10010. {
  10011. if (fileLineInfo.Contains("助力参数"))
  10012. {
  10013. fileLineInfo = streamReader.ReadLine();
  10014. }
  10015. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  10016. }
  10017. }
  10018. streamReader.Close();
  10019. }
  10020. int CmdNum = ConfigCmd.Count(); //指令个数
  10021. Delay_ms(500);
  10022. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "\r\n");
  10023. Delay_ms(500);
  10024. //逐条读取比较
  10025. try
  10026. {
  10027. foreach (string key in ConfigCmd.Keys)
  10028. {
  10029. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令:" + "\r\n");
  10030. CmdRevStrTemp = "";
  10031. if (key.Contains("曲线"))
  10032. {
  10033. byte LineNum = 0;
  10034. var code = new byte[4];
  10035. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  10036. if (LineNum <= 5)
  10037. {
  10038. code[0] = (byte)(LineNum & 0xFF);
  10039. code[1] = (byte)((LineNum >> 8) & 0xFF);
  10040. code[2] = (byte)(LineNum & 0xFF);
  10041. code[3] = (byte)((LineNum >> 8) & 0xFF);
  10042. }
  10043. else
  10044. {
  10045. code[0] = (byte)(LineNum & 0xFF);
  10046. code[1] = (byte)((LineNum >> 8) & 0xFF);
  10047. code[2] = (byte)(5 & 0xFF);
  10048. code[3] = (byte)((5 >> 8) & 0xFF);
  10049. }
  10050. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  10051. }
  10052. else
  10053. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  10054. ACK_WaitCnt = 0;
  10055. while (ACK_WaitCnt <= 2) //1s
  10056. {
  10057. if (CmdRevStrTemp != string.Empty)
  10058. break;
  10059. }
  10060. if (CmdRevStrTemp == string.Empty)
  10061. {
  10062. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令,第1次重发" + "\r\n");
  10063. if (key.Contains("曲线"))
  10064. {
  10065. byte LineNum = 0;
  10066. var code = new byte[4];
  10067. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  10068. if (LineNum <= 5)
  10069. {
  10070. code[0] = (byte)(LineNum & 0xFF);
  10071. code[1] = (byte)((LineNum >> 8) & 0xFF);
  10072. code[2] = (byte)(LineNum & 0xFF);
  10073. code[3] = (byte)((LineNum >> 8) & 0xFF);
  10074. }
  10075. else
  10076. {
  10077. code[0] = (byte)(LineNum & 0xFF);
  10078. code[1] = (byte)((LineNum >> 8) & 0xFF);
  10079. code[2] = (byte)(5 & 0xFF);
  10080. code[3] = (byte)((5 >> 8) & 0xFF);
  10081. }
  10082. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  10083. }
  10084. else
  10085. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  10086. ACK_WaitCnt = 0;
  10087. while (ACK_WaitCnt <= 2) //1s
  10088. {
  10089. if (CmdRevStrTemp != string.Empty)
  10090. break;
  10091. }
  10092. if (CmdRevStrTemp == string.Empty)
  10093. {
  10094. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令,第2次重发" + "\r\n");
  10095. if (key.Contains("曲线"))
  10096. {
  10097. byte LineNum = 0;
  10098. var code = new byte[4];
  10099. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  10100. if (LineNum <= 5)
  10101. {
  10102. code[0] = (byte)(LineNum & 0xFF);
  10103. code[1] = (byte)((LineNum >> 8) & 0xFF);
  10104. code[2] = (byte)(LineNum & 0xFF);
  10105. code[3] = (byte)((LineNum >> 8) & 0xFF);
  10106. }
  10107. else
  10108. {
  10109. code[0] = (byte)(LineNum & 0xFF);
  10110. code[1] = (byte)((LineNum >> 8) & 0xFF);
  10111. code[2] = (byte)(5 & 0xFF);
  10112. code[3] = (byte)((5 >> 8) & 0xFF);
  10113. }
  10114. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  10115. }
  10116. else
  10117. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  10118. ACK_WaitCnt = 0;
  10119. while (ACK_WaitCnt <= 2) //1s
  10120. {
  10121. if (CmdRevStrTemp != string.Empty)
  10122. break;
  10123. }
  10124. if (CmdRevStrTemp == string.Empty)
  10125. {
  10126. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "指令读取失败" + "\r\n");
  10127. label_CheckModeStatus.Text = "存在故障!";
  10128. label_CheckModeResult.BackColor = Color.Red;
  10129. label_CheckModeResult.Text = "测试异常";
  10130. Delay_ms(500);
  10131. //存储异常并上传
  10132. CheckMode_Stop(false);
  10133. return;
  10134. }
  10135. }
  10136. }
  10137. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "读取成功" + "\r\n");
  10138. //比较当前指令,读取的配置文件和返回数据比较
  10139. string ParamWrite = ConfigCmd[key].Substring(24, ConfigCmd[key].Length - 40).Trim();
  10140. string ParamRead = "";
  10141. ushort CmdGet = Convert.ToUInt16(CmdRevStrTemp.Substring(0, 6).Trim().Replace(" ", ""), 16);//接收到指令的命令字
  10142. ushort CmdRev = myParams.ConfigCheckRevCmd[key];//接收指令设计值
  10143. if (CmdGet != CmdRev)
  10144. {
  10145. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "接收指令不正确" + "\r\n");
  10146. richTextBox_CheckModeLog.AppendText("接收指令:" + "0x" + CmdGet.ToString("X2") + "\r\n");
  10147. richTextBox_CheckModeLog.AppendText("正确指令应为:" + "0x" + CmdRev.ToString("X2") + "\r\n");
  10148. label_CheckModeStatus.Text = "存在故障!";
  10149. label_CheckModeResult.BackColor = Color.Red;
  10150. label_CheckModeResult.Text = "测试异常";
  10151. Delay_ms(500);
  10152. //存储异常并上传
  10153. CheckMode_Stop(false);
  10154. return;
  10155. }
  10156. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "返回指令正确,比较参数" + "\r\n");
  10157. if (string.Compare(key, "[其它传感器参数]") == 0)
  10158. ParamRead = CmdRevStrTemp.Substring(90, CmdRevStrTemp.Length - 90).Trim(); //去掉命令字、力矩传感器标定参数
  10159. else if (string.Compare(key, "[力矩传感器参数]") == 0)
  10160. ParamRead = CmdRevStrTemp.Substring(36, CmdRevStrTemp.Length - 6 - 30 - 36).Trim(); //去掉命令字、零点、其它传感器参数
  10161. else if (string.Compare(key, "[控制参数]") == 0)
  10162. ParamRead = CmdRevStrTemp.Substring(18, CmdRevStrTemp.Length - 18).Trim(); //去掉命令字、位置零点
  10163. else
  10164. ParamRead = CmdRevStrTemp.Substring(6, CmdRevStrTemp.Length - 6).Trim(); //去掉命令字
  10165. if (ParamWrite.Contains(ParamRead))
  10166. {
  10167. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "一致" + "\r\n");
  10168. continue;
  10169. }
  10170. else
  10171. {
  10172. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "不一致" + "\r\n");
  10173. richTextBox_CheckModeLog.AppendText("写入参数:" + ParamWrite + "\r\n");
  10174. richTextBox_CheckModeLog.AppendText("读出参数:" + ParamRead + "\r\n");
  10175. label_CheckModeStatus.Text = "存在故障!";
  10176. label_CheckModeResult.BackColor = Color.Red;
  10177. label_CheckModeResult.Text = "测试异常";
  10178. Delay_ms(500);
  10179. //存储异常并上传
  10180. CheckMode_Stop(false);
  10181. return;
  10182. }
  10183. }
  10184. }
  10185. catch (System.Exception ex)
  10186. {
  10187. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数检验失败,错误原因:" + ex.Message + "\r\n");
  10188. label_CheckModeStatus.Text = "存在故障!";
  10189. label_CheckModeResult.BackColor = Color.Red;
  10190. label_CheckModeResult.Text = "测试异常";
  10191. Delay_ms(500);
  10192. //存储异常并上传
  10193. CheckMode_Stop(false);
  10194. return;
  10195. }
  10196. label_CheckModeCfg.BackColor = Color.Green;
  10197. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数检验正确" + "\r\n");
  10198. Delay_ms(500);
  10199. }
  10200. else
  10201. {
  10202. label_CheckModeCfg.BackColor = Color.Yellow;
  10203. label_CheckModeStatus.Text = "跳过参数检验";
  10204. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数检验" + "\r\n");
  10205. Delay_ms(500);
  10206. }
  10207. //读取力矩传感器
  10208. do
  10209. {
  10210. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据" + "\r\n");
  10211. //发送指令读取力矩传感器标定数据
  10212. CmdRevStrTemp = "";
  10213. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  10214. ACK_WaitCnt = 0;
  10215. while (ACK_WaitCnt <= 2) ; //1s
  10216. if (CmdRevStrTemp == string.Empty)
  10217. {
  10218. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据,第1次重发" + "\r\n");
  10219. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  10220. ACK_WaitCnt = 0;
  10221. while (ACK_WaitCnt <= 2) ; //1s
  10222. if (CmdRevStrTemp == string.Empty)
  10223. {
  10224. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据,第2次重发" + "\r\n");
  10225. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  10226. ACK_WaitCnt = 0;
  10227. while (ACK_WaitCnt <= 2) ; //1s
  10228. if (CmdRevStrTemp == string.Empty)
  10229. {
  10230. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取失败" + "\r\n");
  10231. label_CheckModeStatus.Text = "存在故障!";
  10232. label_CheckModeResult.BackColor = Color.Red;
  10233. label_CheckModeResult.Text = "测试异常";
  10234. Delay_ms(500);
  10235. //存储异常并上传
  10236. CheckMode_Stop(false);
  10237. return;
  10238. }
  10239. }
  10240. }
  10241. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取成功" + "\r\n");
  10242. //取力矩传感器数据
  10243. ushort ZeroInit, Zero1, Zero2, Zero3, ZeroNew;
  10244. ushort MaxTorque;
  10245. ushort K1_T, K1, K2_T, K2, K3_T, K3, K4_T, K4;
  10246. byte[] DataArray = mySerialProcess.HexStringToBytes(CmdRevStrTemp, true);
  10247. ushort Cmd = (ushort)((DataArray[0] << 8) + DataArray[1]);
  10248. if (Cmd != 0xB528)
  10249. {
  10250. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器参数错误,CMD: 0x" + Convert.ToString(Cmd, 16).PadLeft(2, '0').ToUpper() + "\r\n");
  10251. label_CheckModeStatus.Text = "存在故障!";
  10252. label_CheckModeResult.BackColor = Color.Red;
  10253. label_CheckModeResult.Text = "测试异常";
  10254. Delay_ms(500);
  10255. //存储异常并上传
  10256. CheckMode_Stop(false);
  10257. return;
  10258. }
  10259. ZeroInit = (ushort)((DataArray[3] << 8) + DataArray[2]);
  10260. Zero1 = (ushort)((DataArray[5] << 8) + DataArray[4]);
  10261. Zero2 = (ushort)((DataArray[7] << 8) + DataArray[6]);
  10262. Zero3 = (ushort)((DataArray[9] << 8) + DataArray[8]);
  10263. ZeroNew = (ushort)((DataArray[11] << 8) + DataArray[10]);
  10264. MaxTorque = (ushort)((DataArray[13] << 8) + DataArray[12]);
  10265. K1_T = (ushort)((DataArray[15] << 8) + DataArray[14]);
  10266. K1 = (ushort)((DataArray[17] << 8) + DataArray[16]);
  10267. K2_T = (ushort)((DataArray[19] << 8) + DataArray[18]);
  10268. K2 = (ushort)((DataArray[21] << 8) + DataArray[20]);
  10269. K3_T = (ushort)((DataArray[23] << 8) + DataArray[22]);
  10270. K3 = (ushort)((DataArray[25] << 8) + DataArray[24]);
  10271. K4_T = (ushort)((DataArray[27] << 8) + DataArray[26]);
  10272. K4 = (ushort)((DataArray[29] << 8) + DataArray[28]);
  10273. richTextBox_CheckModeLog.AppendText("力矩传感器零点: " + ZeroInit.ToString() + "," + Zero1.ToString() + "," +
  10274. Zero2.ToString() + "," + Zero3.ToString() + "," + ZeroNew.ToString() + "\r\n");
  10275. richTextBox_CheckModeLog.AppendText("最大力矩: " + MaxTorque.ToString() + "\r\n");
  10276. richTextBox_CheckModeLog.AppendText("力矩传感器标定: " + "[" + K1_T.ToString() + "," + K1.ToString() + "]" + "," +
  10277. "[" + K2_T.ToString() + "," + K2.ToString() + "]" + "," + "[" + K3_T.ToString() + "," + K3.ToString() + "]" + "," +
  10278. "[" + K4_T.ToString() + "," + K4.ToString() + "]" + "\r\n");
  10279. //传感器标定检验
  10280. if (checkBox_CheckModeTorque.Checked)
  10281. {
  10282. richTextBox_CheckModeLog.AppendText("力矩零点范围: " + TorqueParamsForm.Zero.Min.ToString() + " - " + TorqueParamsForm.Zero.Max.ToString() + "\r\n");
  10283. richTextBox_CheckModeLog.AppendText("K1范围: " + TorqueParamsForm.K1.T.ToString() + "," + TorqueParamsForm.K1.Min.ToString() + " - " + TorqueParamsForm.K1.Max.ToString() + "\r\n");
  10284. richTextBox_CheckModeLog.AppendText("K2范围: " + TorqueParamsForm.K2.T.ToString() + "," + TorqueParamsForm.K2.Min.ToString() + " - " + TorqueParamsForm.K2.Max.ToString() + "\r\n");
  10285. richTextBox_CheckModeLog.AppendText("K3范围: " + TorqueParamsForm.K3.T.ToString() + "," + TorqueParamsForm.K3.Min.ToString() + " - " + TorqueParamsForm.K3.Max.ToString() + "\r\n");
  10286. richTextBox_CheckModeLog.AppendText("K4范围: " + TorqueParamsForm.K4.T.ToString() + "," + TorqueParamsForm.K4.Min.ToString() + " - " + TorqueParamsForm.K4.Max.ToString() + "\r\n");
  10287. //与设置值比较
  10288. if ((ZeroInit <= TorqueParamsForm.Zero.Max) && (ZeroInit >= TorqueParamsForm.Zero.Min)
  10289. && (K1_T == TorqueParamsForm.K1.T) && (K1 <= TorqueParamsForm.K1.Max) && (K1 >= TorqueParamsForm.K1.Min)
  10290. && (K2_T == TorqueParamsForm.K2.T) && (K2 <= TorqueParamsForm.K2.Max) && (K2 >= TorqueParamsForm.K2.Min)
  10291. && (K3_T == TorqueParamsForm.K3.T) && (K3 <= TorqueParamsForm.K3.Max) && (K3 >= TorqueParamsForm.K3.Min)
  10292. && (K4_T == TorqueParamsForm.K4.T) && (K4 <= TorqueParamsForm.K4.Max) && (K4 >= TorqueParamsForm.K4.Min)
  10293. )
  10294. {
  10295. label_CheckModeTorque.BackColor = Color.Green;
  10296. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定正常" + "\r\n");
  10297. Delay_ms(500);
  10298. }
  10299. else
  10300. {
  10301. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定超范围" + "\r\n");
  10302. label_CheckModeStatus.Text = "存在故障!";
  10303. label_CheckModeResult.BackColor = Color.Red;
  10304. label_CheckModeResult.Text = "测试异常";
  10305. Delay_ms(500);
  10306. //存储异常并上传
  10307. CheckMode_Stop(false);
  10308. return;
  10309. }
  10310. }
  10311. else
  10312. {
  10313. label_CheckModeTorque.BackColor = Color.Yellow;
  10314. label_CheckModeStatus.Text = "跳过传感器标定检验";
  10315. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过传感器标定检验" + "\r\n");
  10316. Delay_ms(500);
  10317. }
  10318. } while (false);
  10319. //读取MOS内阻校准参数
  10320. do
  10321. {
  10322. if (checkBox_CheckModeMos.Checked)
  10323. {
  10324. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据" + "\r\n");
  10325. //读取显示校准返回数据
  10326. foreach (Control c in groupBox21.Controls)
  10327. {
  10328. if (c is TextBox)
  10329. c.Text = "";
  10330. }
  10331. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  10332. ACK_WaitCnt = 0;
  10333. while (ACK_WaitCnt <= 2) ; //1s
  10334. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  10335. {
  10336. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据,第1次重发" + "\r\n");
  10337. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  10338. ACK_WaitCnt = 0;
  10339. while (ACK_WaitCnt <= 2) ; //1s
  10340. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  10341. {
  10342. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据,第2次重发" + "\r\n");
  10343. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  10344. ACK_WaitCnt = 0;
  10345. while (ACK_WaitCnt <= 2) ; //1s
  10346. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  10347. {
  10348. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果异常" + "\r\n");
  10349. label_CheckModeStatus.Text = "存在故障!";
  10350. label_CheckModeResult.BackColor = Color.Red;
  10351. label_CheckModeResult.Text = "测试异常";
  10352. Delay_ms(500);
  10353. //存储异常并上传
  10354. CheckMode_Stop(false);
  10355. return;
  10356. }
  10357. }
  10358. }
  10359. else
  10360. {
  10361. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻:" + textBox_MOS_R1.Text + " " + textBox_MOS_R2.Text + " " + textBox_MOS_R3.Text + "\r\n");
  10362. }
  10363. //与校准返回数据对比
  10364. string[] MOS_R1_Th = toolStripTextBox_MOS1.Text.Split(',');
  10365. string[] MOS_R2_Th = toolStripTextBox_MOS2.Text.Split(',');
  10366. string[] MOS_R3_Th = toolStripTextBox_MOS3.Text.Split(',');
  10367. if ((Convert.ToUInt16(textBox_MOS_R1.Text) >= Convert.ToUInt16(MOS_R1_Th[0])) && (Convert.ToUInt16(textBox_MOS_R1.Text) <= Convert.ToUInt16(MOS_R1_Th[1])) &&
  10368. (Convert.ToUInt16(textBox_MOS_R2.Text) >= Convert.ToUInt16(MOS_R2_Th[0])) && (Convert.ToUInt16(textBox_MOS_R2.Text) <= Convert.ToUInt16(MOS_R2_Th[1])) &&
  10369. (Convert.ToUInt16(textBox_MOS_R3.Text) >= Convert.ToUInt16(MOS_R3_Th[0])) && (Convert.ToUInt16(textBox_MOS_R3.Text) <= Convert.ToUInt16(MOS_R3_Th[1]))
  10370. )
  10371. {
  10372. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准合格" + "\r\n");
  10373. label_CheckModeMos.BackColor = Color.Green;
  10374. }
  10375. else
  10376. {
  10377. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准超范围" + "\r\n");
  10378. label_CheckModeStatus.Text = "存在故障!";
  10379. label_CheckModeResult.BackColor = Color.Red;
  10380. label_CheckModeResult.Text = "测试异常";
  10381. Delay_ms(500);
  10382. //存储异常并上传
  10383. CheckMode_Stop(false);
  10384. return;
  10385. }
  10386. }
  10387. else
  10388. {
  10389. label_CheckModeMos.BackColor = Color.Yellow;
  10390. label_CheckModeStatus.Text = "跳过MOS内阻校准检验";
  10391. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过MOS内阻校准检验" + "\r\n");
  10392. Delay_ms(500);
  10393. }
  10394. } while (false);
  10395. //读取位置校准参数
  10396. do
  10397. {
  10398. if (checkBox_CheckModeAngle.Checked)
  10399. {
  10400. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取位置校准数据" + "\r\n");
  10401. //发送指令读取位置
  10402. CmdRevStrTemp = "";
  10403. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
  10404. ACK_WaitCnt = 0;
  10405. while (ACK_WaitCnt <= 2) ; //1s
  10406. if (CmdRevStrTemp == string.Empty)
  10407. {
  10408. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取位置校准数据,第1次重发" + "\r\n");
  10409. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x3E00, null);
  10410. ACK_WaitCnt = 0;
  10411. while (ACK_WaitCnt <= 2) ; //1s
  10412. if (CmdRevStrTemp == string.Empty)
  10413. {
  10414. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取位置校准数据,第2次重发" + "\r\n");
  10415. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x3E00, null);
  10416. ACK_WaitCnt = 0;
  10417. while (ACK_WaitCnt <= 2) ; //1s
  10418. if (CmdRevStrTemp == string.Empty)
  10419. {
  10420. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准数据读取失败" + "\r\n");
  10421. label_CheckModeStatus.Text = "存在故障!";
  10422. label_CheckModeResult.BackColor = Color.Red;
  10423. label_CheckModeResult.Text = "测试异常";
  10424. Delay_ms(500);
  10425. //存储异常并上传
  10426. CheckMode_Stop(false);
  10427. return;
  10428. }
  10429. }
  10430. }
  10431. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准数据读取成功" + "\r\n");
  10432. //取零点数据
  10433. UInt16 AngleZero_Init = 0, AngleZero_Cur = 0;
  10434. byte[] DataArray = mySerialProcess.HexStringToBytes(CmdRevStrTemp, true);
  10435. ushort Cmd = (ushort)((DataArray[0] << 8) + DataArray[1]);
  10436. if (Cmd != 0xB420)
  10437. {
  10438. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置传感器参数错误,CMD: 0x" + Convert.ToString(Cmd, 16).PadLeft(2, '0').ToUpper() + "\r\n");
  10439. label_CheckModeStatus.Text = "存在故障!";
  10440. label_CheckModeResult.BackColor = Color.Red;
  10441. label_CheckModeResult.Text = "测试异常";
  10442. Delay_ms(500);
  10443. //存储异常并上传
  10444. CheckMode_Stop(false);
  10445. return;
  10446. }
  10447. AngleZero_Init = (ushort)((DataArray[3] << 8) + DataArray[2]);
  10448. AngleZero_Cur = (ushort)((DataArray[5] << 8) + DataArray[4]);
  10449. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置出厂零点: " + AngleZero_Init.ToString() + ",位置当前零点: " + AngleZero_Cur.ToString() + "\r\n");
  10450. //非零判断
  10451. if ((AngleZero_Cur == 0) || (AngleZero_Init == 0))
  10452. {
  10453. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置传感器零点数值错误" + "\r\n");
  10454. label_CheckModeStatus.Text = "存在故障!";
  10455. label_CheckModeResult.BackColor = Color.Red;
  10456. label_CheckModeResult.Text = "测试异常";
  10457. Delay_ms(500);
  10458. //存储异常并上传
  10459. CheckMode_Stop(false);
  10460. return;
  10461. }
  10462. else
  10463. {
  10464. int AngleZeroDiff = (Math.Abs(AngleZero_Cur - AngleZero_Init) * 36000) >> 15; //0.01°
  10465. int AngleZeroTH = Convert.ToInt32(textBox_AngleZeroTh.Text) * 100;
  10466. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置零点校准角度值: " + ((float)AngleZeroDiff / 100.0f).ToString("0.00") + ",判断阈值: " + ((float)AngleZeroTH / 100.0f).ToString("0.00") + "\r\n");
  10467. //范围判断
  10468. if (AngleZeroDiff <= AngleZeroTH)
  10469. {
  10470. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置传感器校准合格" + "\r\n");
  10471. label_CheckModeAngle.BackColor = Color.Green;
  10472. }
  10473. else
  10474. {
  10475. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置传感器校准超范围" + "\r\n");
  10476. label_CheckModeStatus.Text = "存在故障!";
  10477. label_CheckModeResult.BackColor = Color.Red;
  10478. label_CheckModeResult.Text = "测试异常";
  10479. Delay_ms(500);
  10480. //存储异常并上传
  10481. CheckMode_Stop(false);
  10482. return;
  10483. }
  10484. }
  10485. }
  10486. else
  10487. {
  10488. label_CheckModeAngle.BackColor = Color.Yellow;
  10489. label_CheckModeStatus.Text = "跳过位置传感器校准检验";
  10490. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过位置传感器校准检验" + "\r\n");
  10491. Delay_ms(500);
  10492. }
  10493. } while (false);
  10494. //测试合格
  10495. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  10496. label_CheckModeStatus.Text = "测试结束!";
  10497. label_CheckModeResult.BackColor = Color.Green;
  10498. label_CheckModeResult.Text = "测试合格";
  10499. Delay_ms(500);
  10500. //存储并上传
  10501. CheckMode_Stop(true);
  10502. return;
  10503. }
  10504. private void CheckModeLabelInit()
  10505. {
  10506. //测试状态标签
  10507. label_CheckModeResult.BackColor = Color.Yellow;
  10508. label_CheckModeResult.Text = "测试中";
  10509. //测试过程标签
  10510. label_CheckModeStatus.Text = "测试就绪";
  10511. //测试结果标签
  10512. foreach (Control c in groupBox31.Controls)
  10513. {
  10514. if (c is Label)
  10515. {
  10516. if (c.Text == string.Empty)
  10517. c.BackColor = Color.Red;
  10518. }
  10519. }
  10520. }
  10521. private void 调试记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  10522. {
  10523. System.Diagnostics.Process.Start("explorer.exe", Directory.GetCurrentDirectory());
  10524. }
  10525. private void 生产记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  10526. {
  10527. System.Diagnostics.Process.Start("explorer.exe", localInfo.LocalDataPath);
  10528. }
  10529. private void 累计运行时间ToolStripMenuItem_MouseHover(object sender, EventArgs e)
  10530. {
  10531. UInt32 Time = (UInt32)stopwatch.ElapsedMilliseconds / 1000;
  10532. UInt32 hour = Time / 3600;
  10533. UInt32 min = (Time % 3600) / 60;
  10534. UInt32 s = (Time % 60);
  10535. toolStripMenuItem_RunTime.Text = hour.ToString() + ":" + min.ToString("00") + ":" + s.ToString("00");
  10536. }
  10537. private void richTextBox_CheckModeLog_TextChanged(object sender, EventArgs e)
  10538. {
  10539. richTextBox_CheckModeLog.SelectionStart = richTextBox_CheckModeLog.Text.Length;
  10540. richTextBox_CheckModeLog.ScrollToCaret();
  10541. }
  10542. private void 力矩传感器检验ToolStripMenuItem_Click(object sender, EventArgs e)
  10543. {
  10544. TorqueParamsForm.ShowDialog();
  10545. }
  10546. private void textBox_CheckModeScan_KeyUp(object sender, KeyEventArgs e)
  10547. {
  10548. if (e.KeyCode == Keys.Enter)
  10549. CheckTestStart();
  10550. }
  10551. private void textBox_FacModeScan_KeyUp(object sender, KeyEventArgs e)
  10552. {
  10553. if (e.KeyCode == Keys.Enter)
  10554. TestStart();
  10555. }
  10556. private void button_SpeedDec10_Click(object sender, EventArgs e)
  10557. {
  10558. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  10559. if (Percent <= 10)
  10560. Percent = 0;
  10561. else
  10562. Percent -= 10;
  10563. //生产模式转速设置值更新
  10564. textBox_MotorSpeedPercent.Text = Percent.ToString();
  10565. //设置转速百分比
  10566. var Data = new byte[1];
  10567. Data[0] = (byte)Percent;
  10568. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  10569. }
  10570. private void button_SpeedAdd10_Click(object sender, EventArgs e)
  10571. {
  10572. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  10573. if (Percent >= 90)
  10574. Percent = 100;
  10575. else
  10576. Percent += 10;
  10577. //生产模式转速设置值更新
  10578. textBox_MotorSpeedPercent.Text = Percent.ToString();
  10579. //设置转速百分比
  10580. var Data = new byte[1];
  10581. Data[0] = (byte)Percent;
  10582. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  10583. }
  10584. private void button_SpeedDec1_Click(object sender, EventArgs e)
  10585. {
  10586. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  10587. if (Percent <= 1)
  10588. Percent = 0;
  10589. else
  10590. Percent -= 1;
  10591. //生产模式转速设置值更新
  10592. textBox_MotorSpeedPercent.Text = Percent.ToString();
  10593. //设置转速百分比
  10594. var Data = new byte[1];
  10595. Data[0] = (byte)Percent;
  10596. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  10597. }
  10598. private void button_SpeedAdd1_Click(object sender, EventArgs e)
  10599. {
  10600. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  10601. if (Percent >= 99)
  10602. Percent = 100;
  10603. else
  10604. Percent += 1;
  10605. //生产模式转速设置值更新
  10606. textBox_MotorSpeedPercent.Text = Percent.ToString();
  10607. //设置转速百分比
  10608. var Data = new byte[1];
  10609. Data[0] = (byte)Percent;
  10610. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  10611. }
  10612. bool WriteLockStatus = true;
  10613. private void pictureBox_WriteLock_Click(object sender, EventArgs e)
  10614. {
  10615. if (WriteLockStatus == true)
  10616. {
  10617. EnterForm1.ShowDialog();
  10618. try
  10619. {
  10620. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  10621. {
  10622. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  10623. {
  10624. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  10625. foreach (Control c in groupBox2.Controls)
  10626. {
  10627. if (c is CheckBox)
  10628. c.Enabled = true;
  10629. }
  10630. WriteLockStatus = !WriteLockStatus;
  10631. }
  10632. else
  10633. {
  10634. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  10635. }
  10636. }
  10637. else
  10638. {
  10639. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  10640. }
  10641. }
  10642. catch (Exception)
  10643. {
  10644. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  10645. }
  10646. }
  10647. else
  10648. {
  10649. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  10650. foreach (Control c in groupBox2.Controls)
  10651. {
  10652. if (c is CheckBox)
  10653. c.Enabled = false;
  10654. }
  10655. WriteLockStatus = !WriteLockStatus;
  10656. }
  10657. }
  10658. bool ReadLockStatus = true;
  10659. private void pictureBox_ReadLock_Click(object sender, EventArgs e)
  10660. {
  10661. if (ReadLockStatus == true)
  10662. {
  10663. EnterForm1.ShowDialog();
  10664. try
  10665. {
  10666. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  10667. {
  10668. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  10669. {
  10670. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  10671. foreach (Control c in groupBox29.Controls)
  10672. {
  10673. if (c is CheckBox)
  10674. c.Enabled = true;
  10675. }
  10676. ReadLockStatus = !ReadLockStatus;
  10677. }
  10678. else
  10679. {
  10680. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  10681. }
  10682. }
  10683. else
  10684. {
  10685. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  10686. }
  10687. }
  10688. catch (Exception)
  10689. {
  10690. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  10691. }
  10692. }
  10693. else
  10694. {
  10695. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  10696. foreach (Control c in groupBox29.Controls)
  10697. {
  10698. if (c is CheckBox)
  10699. c.Enabled = false;
  10700. }
  10701. ReadLockStatus = !ReadLockStatus;
  10702. }
  10703. }
  10704. private void 屏幕键盘ToolStripMenuItem_Click(object sender, EventArgs e)
  10705. {
  10706. System.Diagnostics.Process.Start("osk.exe");
  10707. }
  10708. private void checkBox_OffLineCheckMode_CheckedChanged(object sender, EventArgs e)
  10709. {
  10710. comboBox_CheckModeCfgDate.SelectedIndex = -1;
  10711. comboBox_CheckModeCfgFile.SelectedIndex = -1;
  10712. checkBox_OffLineFacMode.Checked = checkBox_OffLineCheckMode.Checked;
  10713. }
  10714. private void checkBox_OffLineFacMode_CheckedChanged(object sender, EventArgs e)
  10715. {
  10716. comboBox_FacModeCfgDate.SelectedIndex = -1;
  10717. comboBox_FacModeCfgFile.SelectedIndex = -1;
  10718. checkBox_OffLineCheckMode.Checked = checkBox_OffLineFacMode.Checked;
  10719. }
  10720. private void 版本ToolStripMenuItem_Click(object sender, EventArgs e)
  10721. {
  10722. VersionForm.ShowDialog();
  10723. }
  10724. private void button_MOS_Cal_Click(object sender, EventArgs e)
  10725. {
  10726. textBox_MOS_R1.Text = "";
  10727. textBox_MOS_R2.Text = "";
  10728. textBox_MOS_R3.Text = "";
  10729. try
  10730. {
  10731. var Code = new byte[18];
  10732. for (int i = 0; i < 18; i++)
  10733. Code[i] = 0;
  10734. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  10735. ushort uwDataTemp = 0;
  10736. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  10737. Code[2] = (byte)(uwDataTemp & 0xFF);
  10738. Code[3] = (byte)(uwDataTemp >> 8);
  10739. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  10740. Code[4] = (byte)(uwDataTemp & 0xFF);
  10741. Code[5] = (byte)(uwDataTemp >> 8);
  10742. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  10743. Code[6] = (byte)(uwDataTemp & 0xFF);
  10744. Code[7] = (byte)(uwDataTemp >> 8);
  10745. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  10746. Code[8] = (byte)(uwDataTemp & 0xFF);
  10747. Code[9] = (byte)(uwDataTemp >> 8);
  10748. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  10749. Code[10] = (byte)(uwDataTemp & 0xFF);
  10750. Code[11] = (byte)(uwDataTemp >> 8);
  10751. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  10752. }
  10753. catch (Exception)
  10754. {
  10755. MessageBox.Show("系数填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  10756. }
  10757. }
  10758. private void button_MOS_Read_Click(object sender, EventArgs e)
  10759. {
  10760. foreach (Control c in groupBox21.Controls)
  10761. {
  10762. if (c is TextBox)
  10763. c.Text = "";
  10764. }
  10765. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  10766. }
  10767. private void button_MOS_Write_Click(object sender, EventArgs e)
  10768. {
  10769. try
  10770. {
  10771. var Code = new byte[34];
  10772. for (int i = 0; i < 34; i++)
  10773. Code[i] = 0;
  10774. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  10775. ushort uwDataTemp = 0;
  10776. uwDataTemp = Convert.ToUInt16(textBox_MOS_R1.Text);
  10777. Code[2] = (byte)(uwDataTemp & 0xFF);
  10778. Code[3] = (byte)(uwDataTemp >> 8);
  10779. uwDataTemp = Convert.ToUInt16(textBox_MOS_R2.Text);
  10780. Code[4] = (byte)(uwDataTemp & 0xFF);
  10781. Code[5] = (byte)(uwDataTemp >> 8);
  10782. uwDataTemp = Convert.ToUInt16(textBox_MOS_R3.Text);
  10783. Code[6] = (byte)(uwDataTemp & 0xFF);
  10784. Code[7] = (byte)(uwDataTemp >> 8);
  10785. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  10786. Code[8] = (byte)(uwDataTemp & 0xFF);
  10787. Code[9] = (byte)(uwDataTemp >> 8);
  10788. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  10789. Code[10] = (byte)(uwDataTemp & 0xFF);
  10790. Code[11] = (byte)(uwDataTemp >> 8);
  10791. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  10792. Code[12] = (byte)(uwDataTemp & 0xFF);
  10793. Code[13] = (byte)(uwDataTemp >> 8);
  10794. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  10795. Code[14] = (byte)(uwDataTemp & 0xFF);
  10796. Code[15] = (byte)(uwDataTemp >> 8);
  10797. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  10798. Code[16] = (byte)(uwDataTemp & 0xFF);
  10799. Code[17] = (byte)(uwDataTemp >> 8);
  10800. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4C22, Code);
  10801. }
  10802. catch (Exception)
  10803. {
  10804. MessageBox.Show("数据填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  10805. }
  10806. }
  10807. /// <summary>
  10808. /// 测试模式点击文本框自动全选
  10809. /// </summary>
  10810. /// <param name="sender"></param>
  10811. /// <param name="e"></param>
  10812. private void textBox_FacModeScan_MouseClick(object sender, MouseEventArgs e)
  10813. {
  10814. textBox_FacModeScan.SelectAll();
  10815. }
  10816. /// <summary>
  10817. /// 检验模式点击文本框自动全选
  10818. /// </summary>
  10819. /// <param name="sender"></param>
  10820. /// <param name="e"></param>
  10821. private void textBox_CheckModeScan_MouseClick(object sender, MouseEventArgs e)
  10822. {
  10823. textBox_CheckModeScan.SelectAll();
  10824. }
  10825. /// <summary>
  10826. /// 鼠标放置显示连接服务器信息
  10827. /// </summary>
  10828. /// <param name="sender"></param>
  10829. /// <param name="e"></param>
  10830. private void label_ServerStatus_MouseHover(object sender, EventArgs e)
  10831. {
  10832. // 创建the ToolTip
  10833. ToolTip toolTip1 = new ToolTip();
  10834. // 设置显示样式
  10835. toolTip1.AutoPopDelay = 30000;//提示信息的可见时间
  10836. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  10837. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  10838. toolTip1.ShowAlways = true;//是否显示提示框
  10839. if (myFtp.IsNetConnected)
  10840. {
  10841. toolTip1.SetToolTip(this.label_ServerStatus, "IP: " + ServerIP);//设置故障内容显示
  10842. }
  10843. else
  10844. {
  10845. toolTip1.SetToolTip(this.label_ServerStatus, "网络断开");//设置故障内容显示
  10846. }
  10847. }
  10848. /// <summary>
  10849. /// UART协议类型修改
  10850. /// </summary>
  10851. /// <param name="sender"></param>
  10852. /// <param name="e"></param>
  10853. private void 协议类型ToolStripMenuItem_SelectedIndexChanged(object sender, EventArgs e)
  10854. {
  10855. var Code = new byte[2];
  10856. Code[0] = (byte)协议类型ToolStripMenuItem.SelectedIndex;
  10857. Code[1] = 0x00;
  10858. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  10859. }
  10860. /// <summary>
  10861. /// 显示本机信息
  10862. /// </summary>
  10863. /// <param name="sender"></param>
  10864. /// <param name="e"></param>
  10865. private void 本机信息ToolStripMenuItem_Click(object sender, EventArgs e)
  10866. {
  10867. MessageBox.Show(Local_HdInformation, "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
  10868. }
  10869. /// <summary>
  10870. /// 量产模式删除当前选中文件
  10871. /// </summary>
  10872. /// <param name="sender"></param>
  10873. /// <param name="e"></param>
  10874. private void label112_DoubleClick(object sender, EventArgs e)
  10875. {
  10876. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  10877. {
  10878. EnterForm1.ShowDialog();
  10879. try
  10880. {
  10881. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  10882. {
  10883. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  10884. {
  10885. try
  10886. {
  10887. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + comboBox_FacModeCfgFile.Text);
  10888. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_FacModeCfgFile.Text) + ".src");
  10889. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_FacModeCfgFile.Text) + ".png");
  10890. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  10891. }
  10892. catch (Exception)
  10893. {
  10894. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  10895. }
  10896. }
  10897. else
  10898. {
  10899. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  10900. }
  10901. }
  10902. }
  10903. catch (Exception)
  10904. {
  10905. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  10906. }
  10907. }
  10908. }
  10909. /// <summary>
  10910. /// 检验模式删除当前选中文件
  10911. /// </summary>
  10912. /// <param name="sender"></param>
  10913. /// <param name="e"></param>
  10914. private void label138_DoubleClick(object sender, EventArgs e)
  10915. {
  10916. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  10917. {
  10918. EnterForm1.ShowDialog();
  10919. try
  10920. {
  10921. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  10922. {
  10923. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  10924. {
  10925. try
  10926. {
  10927. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + comboBox_CheckModeCfgFile.Text);
  10928. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_CheckModeCfgFile.Text) + ".src");
  10929. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_CheckModeCfgFile.Text) + ".png");
  10930. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  10931. }
  10932. catch (Exception)
  10933. {
  10934. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  10935. }
  10936. }
  10937. else
  10938. {
  10939. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  10940. }
  10941. }
  10942. }
  10943. catch (Exception)
  10944. {
  10945. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  10946. }
  10947. }
  10948. }
  10949. /// <summary>
  10950. /// 读取整车信息2
  10951. /// </summary>
  10952. /// <param name="sender"></param>
  10953. /// <param name="e"></param>
  10954. private void button_ReadBikeParam2_Click(object sender, EventArgs e)
  10955. {
  10956. richTextBox_BikeParam2.Clear();
  10957. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null);
  10958. }
  10959. /// <summary>
  10960. /// 写入整车信息2
  10961. /// </summary>
  10962. /// <param name="sender"></param>
  10963. /// <param name="e"></param>
  10964. private void button_WriteBikeParam2_Click(object sender, EventArgs e)
  10965. {
  10966. var ConfigParam = new byte[34];
  10967. for (int i = 0; i < 34; i++)
  10968. ConfigParam[i] = 0;
  10969. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  10970. string[] strDataTemp = richTextBox_BikeParam2.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  10971. try
  10972. {
  10973. for (int i = 0; i < strDataTemp.Length; i++)
  10974. {
  10975. short wDataTemp = 0;
  10976. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  10977. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  10978. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  10979. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  10980. }
  10981. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4D22, ConfigParam);
  10982. }
  10983. catch (Exception)
  10984. {
  10985. timer_500ms.Enabled = false;
  10986. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  10987. timer_500ms.Enabled = true;
  10988. }
  10989. }
  10990. /// <summary>
  10991. /// 读取用户骑行参数
  10992. /// </summary>
  10993. /// <param name="sender"></param>
  10994. /// <param name="e"></param>
  10995. private void button_ReadUsrRideParam_Click(object sender, EventArgs e)
  10996. {
  10997. richTextBox_UsrRidesParam.Clear();
  10998. if (checkBox_UserRideParam_OBC.Checked)
  10999. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x4300, null);
  11000. else
  11001. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  11002. }
  11003. /// <summary>
  11004. /// 写入用户骑行参数
  11005. /// </summary>
  11006. /// <param name="sender"></param>
  11007. /// <param name="e"></param>
  11008. private void button_WriteUsrRidetParam_Click(object sender, EventArgs e)
  11009. {
  11010. var ConfigParam = new byte[34];
  11011. for (int i = 0; i < 34; i++)
  11012. ConfigParam[i] = 0;
  11013. if (checkBox_UserRideParam_OBC.Checked)
  11014. {
  11015. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  11016. string[] strDataTemp = richTextBox_UsrRidesParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  11017. try
  11018. {
  11019. for (int i = 0; i < strDataTemp.Length; i++)
  11020. {
  11021. ConfigParam[i + 2] = Convert.ToByte(strDataTemp[i].Split('=')[1]);
  11022. }
  11023. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4B22, ConfigParam);
  11024. }
  11025. catch (Exception)
  11026. {
  11027. timer_500ms.Enabled = false;
  11028. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  11029. timer_500ms.Enabled = true;
  11030. }
  11031. }
  11032. else
  11033. {
  11034. string[] strDataTemp = richTextBox_UsrRidesParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  11035. try
  11036. {
  11037. for (int i = 0; i < strDataTemp.Length; i++)
  11038. {
  11039. ConfigParam[i] = Convert.ToByte(strDataTemp[i].Split('=')[1]);
  11040. }
  11041. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x4420, ConfigParam);
  11042. }
  11043. catch (Exception)
  11044. {
  11045. timer_500ms.Enabled = false;
  11046. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  11047. timer_500ms.Enabled = true;
  11048. }
  11049. }
  11050. }
  11051. /// <summary>
  11052. /// 读取产品标签
  11053. /// </summary>
  11054. /// <param name="sender"></param>
  11055. /// <param name="e"></param>
  11056. private void button_ReadTag_Click(object sender, EventArgs e)
  11057. {
  11058. textBox_TagInfo.Text = "---";
  11059. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4E00, null);
  11060. }
  11061. /// <summary>
  11062. /// 写入产品标签
  11063. /// </summary>
  11064. /// <param name="sender"></param>
  11065. /// <param name="e"></param>
  11066. private void button_WriteTag_Click(object sender, EventArgs e)
  11067. {
  11068. string User = textBox_TagInfo.Text;
  11069. var UserArray = new byte[32];
  11070. for (ushort i = 0; i < User.Length; i++)
  11071. {
  11072. UserArray[i] = (byte)User[i];
  11073. }
  11074. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D20, UserArray);
  11075. }
  11076. /// <summary>
  11077. /// 上位机读取骑行历史
  11078. /// </summary>
  11079. /// <param name="sender"></param>
  11080. /// <param name="e"></param>
  11081. private void button_ReadRideLog_Click(object sender, EventArgs e)
  11082. {
  11083. textBox_ODO_KM.Text = "---";
  11084. textBox_ODO_TIME.Text = "---";
  11085. textBox_TRIP_KM.Text = "---";
  11086. textBox_TRIP_TIME.Text = "---";
  11087. textBox_OBC_TRIP_KM.Text = "";
  11088. textBox_OBC_TRIP_TIME.Text = "";
  11089. textBox_OBC_ODO_KM.Text = "";
  11090. textBox_OBC_ODO_TIME.Text = "";
  11091. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2E00, null);
  11092. }
  11093. /// <summary>
  11094. /// 上位机写入骑行历史
  11095. /// </summary>
  11096. /// <param name="sender"></param>
  11097. /// <param name="e"></param>
  11098. private void button_WriteRideLog_Click(object sender, EventArgs e)
  11099. {
  11100. UInt32 Data;
  11101. var UserArray = new byte[16];
  11102. try
  11103. {
  11104. Data = Convert.ToUInt32(textBox_ODO_KM.Text);
  11105. UserArray[0] = (byte)(Data & 0xFF);
  11106. UserArray[1] = (byte)(Data >> 8);
  11107. UserArray[2] = (byte)(Data >> 16);
  11108. UserArray[3] = (byte)(Data >> 24);
  11109. Data = Convert.ToUInt32(textBox_ODO_TIME.Text);
  11110. UserArray[4] = (byte)(Data & 0xFF);
  11111. UserArray[5] = (byte)(Data >> 8);
  11112. UserArray[6] = (byte)(Data >> 16);
  11113. UserArray[7] = (byte)(Data >> 24);
  11114. Data = Convert.ToUInt32(textBox_TRIP_KM.Text);
  11115. UserArray[8] = (byte)(Data & 0xFF);
  11116. UserArray[9] = (byte)(Data >> 8);
  11117. UserArray[10] = (byte)(Data >> 16);
  11118. UserArray[11] = (byte)(Data >> 24);
  11119. Data = Convert.ToUInt32(textBox_TRIP_TIME.Text);
  11120. UserArray[12] = (byte)(Data & 0xFF);
  11121. UserArray[13] = (byte)(Data >> 8);
  11122. UserArray[14] = (byte)(Data >> 16);
  11123. UserArray[15] = (byte)(Data >> 24);
  11124. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B10, UserArray);
  11125. }
  11126. catch (Exception ex)
  11127. {
  11128. MessageBox.Show("数据格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  11129. }
  11130. }
  11131. /// <summary>
  11132. /// 获取删除配置文件日期列表
  11133. /// </summary>
  11134. /// <param name="sender"></param>
  11135. /// <param name="e"></param>
  11136. private void toolStripTextBox_DelCfgFile_Click(object sender, EventArgs e)
  11137. {
  11138. string[] DateList = { "" };
  11139. //网络断开时直接退出
  11140. if (!myFtp.IsNetConnected)
  11141. return;
  11142. //从服务器更新日期列表
  11143. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
  11144. toolStripTextBox_DelCfgFile.Items.Clear();
  11145. //日期列表加载,显示最近30条
  11146. if (DateList.Length > 30)
  11147. {
  11148. toolStripTextBox_DelCfgFile.Items.Add("支持最近30条");
  11149. toolStripTextBox_DelCfgFile.Items.Add("-----");
  11150. }
  11151. for (int i = (DateList.Length > 30) ? (DateList.Length - 30) : 0; i < DateList.Length; i++)//显示最近30个日期
  11152. {
  11153. toolStripTextBox_DelCfgFile.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  11154. }
  11155. }
  11156. /// <summary>
  11157. /// 删除指定配置文件
  11158. /// </summary>
  11159. /// <param name="sender"></param>
  11160. /// <param name="e"></param>
  11161. private void toolStripTextBox_DelCfgFile_SelectedIndexChanged(object sender, EventArgs e)
  11162. {
  11163. //提示输入文件名
  11164. Scan scan_form = new Scan();
  11165. scan_form.ShowDialog();
  11166. do
  11167. {
  11168. if (scan_form.textBox_Scan.Text == string.Empty)
  11169. {
  11170. timer_500ms.Enabled = false;
  11171. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  11172. timer_500ms.Enabled = true;
  11173. break;
  11174. }
  11175. string DelFile = scan_form.textBox_Scan.Text;
  11176. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  11177. {
  11178. EnterForm1.ShowDialog();
  11179. try
  11180. {
  11181. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  11182. {
  11183. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  11184. {
  11185. try
  11186. {
  11187. if (DelFile.Contains("."))
  11188. DelFile = Path.GetFileNameWithoutExtension(DelFile);
  11189. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".ttcfg");
  11190. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".src");
  11191. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".png");
  11192. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  11193. }
  11194. catch (Exception)
  11195. {
  11196. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  11197. }
  11198. }
  11199. else
  11200. {
  11201. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  11202. }
  11203. }
  11204. }
  11205. catch (Exception)
  11206. {
  11207. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  11208. }
  11209. }
  11210. } while (false);
  11211. }
  11212. /// <summary>
  11213. /// 获取删除样机测试记录日期列表
  11214. /// </summary>
  11215. /// <param name="sender"></param>
  11216. /// <param name="e"></param>
  11217. private void toolStripTextBox_DelLogFile_Click(object sender, EventArgs e)
  11218. {
  11219. string[] DateList = { "" };
  11220. //网络断开时直接退出
  11221. if (!myFtp.IsNetConnected)
  11222. return;
  11223. //从服务器更新日期列表
  11224. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName);
  11225. toolStripTextBox_DelLogFile.Items.Clear();
  11226. //日期列表加载,显示最近30天
  11227. if (DateList.Length > 30)
  11228. {
  11229. toolStripTextBox_DelLogFile.Items.Add("支持最近30条");
  11230. toolStripTextBox_DelLogFile.Items.Add("-----");
  11231. }
  11232. for (int i = (DateList.Length > 30) ? (DateList.Length - 30) : 0; i < DateList.Length; i++)//显示最近30个日期
  11233. {
  11234. toolStripTextBox_DelLogFile.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  11235. }
  11236. }
  11237. /// <summary>
  11238. /// 删除指定的样机测试记录
  11239. /// </summary>
  11240. /// <param name="sender"></param>
  11241. /// <param name="e"></param>
  11242. private void toolStripTextBox_DelLogFile_SelectedIndexChanged(object sender, EventArgs e)
  11243. {
  11244. //提示输入文件名
  11245. Scan scan_form = new Scan();
  11246. scan_form.ShowDialog();
  11247. do
  11248. {
  11249. if (scan_form.textBox_Scan.Text == string.Empty)
  11250. {
  11251. timer_500ms.Enabled = false;
  11252. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  11253. timer_500ms.Enabled = true;
  11254. break;
  11255. }
  11256. string DelFile = scan_form.textBox_Scan.Text;
  11257. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  11258. {
  11259. EnterForm1.ShowDialog();
  11260. try
  11261. {
  11262. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  11263. {
  11264. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  11265. {
  11266. try
  11267. {
  11268. //删除指定目录下面所有文件和文件夹
  11269. myFtp.DelDirectoryWithAll(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName + "\\" + toolStripTextBox_DelLogFile.Text + "\\" + DelFile);
  11270. myFtp.RemoveDirectory(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName + "\\" + toolStripTextBox_DelLogFile.Text + "\\" + DelFile);
  11271. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  11272. }
  11273. catch (Exception)
  11274. {
  11275. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  11276. }
  11277. }
  11278. else
  11279. {
  11280. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  11281. }
  11282. }
  11283. }
  11284. catch (Exception)
  11285. {
  11286. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  11287. }
  11288. }
  11289. } while (false);
  11290. }
  11291. /// <summary>
  11292. /// CAN协议选择
  11293. /// </summary>
  11294. /// <param name="sender"></param>
  11295. /// <param name="e"></param>
  11296. private void cANToolStripMenuItem_Click(object sender, EventArgs e)
  11297. {
  11298. cANToolStripMenuItem.Checked= true;
  11299. uARTToolStripMenuItem.Checked = false;
  11300. UART协议ToolStripMenuItem.Visible = false;
  11301. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  11302. }
  11303. /// <summary>
  11304. /// UART协议选择
  11305. /// </summary>
  11306. /// <param name="sender"></param>
  11307. /// <param name="e"></param>
  11308. private void uARTToolStripMenuItem_Click(object sender, EventArgs e)
  11309. {
  11310. cANToolStripMenuItem.Checked = false;
  11311. uARTToolStripMenuItem.Checked = true;
  11312. UART协议ToolStripMenuItem.Visible = true;
  11313. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  11314. }
  11315. /// <summary>
  11316. /// 清除流水号
  11317. /// </summary>
  11318. /// <param name="sender"></param>
  11319. /// <param name="e"></param>
  11320. private void label131_DoubleClick(object sender, EventArgs e)
  11321. {
  11322. if (MessageBox.Show("确认清零流水号?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  11323. {
  11324. label_FacModeSerial.Text = "0";
  11325. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, label_FacModeSerial.Text);
  11326. }
  11327. }
  11328. /// <summary>
  11329. /// 清除流水号
  11330. /// </summary>
  11331. /// <param name="sender"></param>
  11332. /// <param name="e"></param>
  11333. private void label135_DoubleClick(object sender, EventArgs e)
  11334. {
  11335. if (MessageBox.Show("确认清零流水号?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  11336. {
  11337. label_CheckModeSerial.Text = "0";
  11338. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, label_CheckModeSerial.Text);
  11339. }
  11340. }
  11341. /// <summary>
  11342. /// 打开自动更新
  11343. /// </summary>
  11344. /// <param name="sender"></param>
  11345. /// <param name="e"></param>
  11346. private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
  11347. {
  11348. 打开ToolStripMenuItem.Checked = true;
  11349. 关闭ToolStripMenuItem.Checked = false;
  11350. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  11351. }
  11352. /// <summary>
  11353. /// 关闭自动更新
  11354. /// </summary>
  11355. /// <param name="sender"></param>
  11356. /// <param name="e"></param>
  11357. private void 关闭ToolStripMenuItem_Click(object sender, EventArgs e)
  11358. {
  11359. 打开ToolStripMenuItem.Checked = false;
  11360. 关闭ToolStripMenuItem.Checked = true;
  11361. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  11362. }
  11363. /// <summary>
  11364. /// 显示完整配置文件
  11365. /// </summary>
  11366. /// <param name="sender"></param>
  11367. /// <param name="e"></param>
  11368. private void comboBox_FacModeCfgFile_MouseHover_1(object sender, EventArgs e)
  11369. {
  11370. // 创建the ToolTip
  11371. ToolTip toolTip1 = new ToolTip();
  11372. // 设置显示样式
  11373. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  11374. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  11375. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  11376. toolTip1.ShowAlways = true;//是否显示提示框
  11377. // 设置伴随的对象.
  11378. toolTip1.SetToolTip(this.comboBox_FacModeCfgFile, comboBox_FacModeCfgFile.Text);//设置故障内容显示
  11379. }
  11380. /// <summary>
  11381. /// 显示完整配置文件
  11382. /// </summary>
  11383. /// <param name="sender"></param>
  11384. /// <param name="e"></param>
  11385. private void comboBox_CheckModeCfgFile_MouseHover_1(object sender, EventArgs e)
  11386. {
  11387. // 创建the ToolTip
  11388. ToolTip toolTip1 = new ToolTip();
  11389. // 设置显示样式
  11390. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  11391. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  11392. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  11393. toolTip1.ShowAlways = true;//是否显示提示框
  11394. // 设置伴随的对象.
  11395. toolTip1.SetToolTip(this.comboBox_CheckModeCfgFile, comboBox_CheckModeCfgFile.Text);//设置故障内容显示
  11396. }
  11397. /// <summary>
  11398. /// 手动发送指令
  11399. /// </summary>
  11400. /// <param name="sender"></param>
  11401. /// <param name="e"></param>
  11402. private void 发送指令ToolStripMenuItem_Click(object sender, EventArgs e)
  11403. {
  11404. //提示
  11405. Scan scan_form = new Scan();
  11406. scan_form.label1.Text = "按照16进制填写,相邻字节用空格隔开,依次填写ID、Mode、Cmd、Data\r\n例如:07 31 16 22 05 01 02 03 04 05";
  11407. scan_form.ShowDialog();
  11408. //发送写入的指令,填写ID、类型、命令字、数据
  11409. do
  11410. {
  11411. if (scan_form.textBox_Scan.Text == string.Empty)
  11412. {
  11413. timer_500ms.Enabled = false;
  11414. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  11415. timer_500ms.Enabled = true;
  11416. break;
  11417. }
  11418. //输入文本转换为字节流
  11419. var InputData = new byte[256];
  11420. InputData = mySerialProcess.HexStringToBytes(scan_form.textBox_Scan.Text, true);
  11421. //ID
  11422. ushort ID;
  11423. ID = (ushort)((InputData[0] << 8) + InputData[1]);
  11424. //Mode
  11425. byte Mode;
  11426. Mode = InputData[2];
  11427. //Cmd
  11428. ushort Cmd;
  11429. Cmd = (ushort)((InputData[3] << 8) + InputData[4]);
  11430. //Data
  11431. var Data = new byte[Cmd & 0x00FF];
  11432. for (int i = 0; i < (Cmd & 0x00FF); i++)
  11433. Data[i] = InputData[5 + i];
  11434. //发送数据
  11435. mySerialProcess.SendCmdWithoutNotice(ID, Mode, Cmd, Data);
  11436. } while (false);
  11437. }
  11438. /// <summary>
  11439. /// 启动位置传感器校准
  11440. /// </summary>
  11441. /// <param name="sender"></param>
  11442. /// <param name="e"></param>
  11443. private void button_AngleCalStart_Click(object sender, EventArgs e)
  11444. {
  11445. for (int i = 0; i < 7; i++)
  11446. for (int j = 0; j < 6; j++)
  11447. {
  11448. dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = "";
  11449. }
  11450. foreach (Control cr in tabPage_AngleCal.Controls)
  11451. {
  11452. if (cr is TextBox)
  11453. {
  11454. if ((cr != textBox_AngleDiffTh) && (cr != textBox_AngleZeroTh))
  11455. cr.Text = "";
  11456. }
  11457. }
  11458. var Data = new byte[2];
  11459. mySerialProcess.SendCmd((ushort)0x751, (byte)0x0C, (ushort)0x5002, Data);
  11460. }
  11461. /// <summary>
  11462. /// 导出位置传感器校准数据
  11463. /// </summary>
  11464. /// <param name="sender"></param>
  11465. /// <param name="e"></param>
  11466. private void button_AngleExportData_Click(object sender, EventArgs e)
  11467. {
  11468. //读出产品信息
  11469. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  11470. Delay_ms(200);
  11471. SaveFileDialog sfd = new SaveFileDialog
  11472. {
  11473. FileName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + "位置传感器角度数据_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt",
  11474. Filter = "文本文档(*.txt)|*.txt",
  11475. Title = "Save"
  11476. };
  11477. if (sfd.ShowDialog() != DialogResult.OK)
  11478. {
  11479. return;
  11480. }
  11481. string filepath = sfd.FileName;
  11482. FileStream fs = new FileStream(filepath, FileMode.OpenOrCreate);
  11483. using (StreamWriter sw = new StreamWriter(fs))
  11484. {
  11485. sw.Write("标准值 ");
  11486. sw.Write("60.00 ");
  11487. sw.Write("120.00 ");
  11488. sw.Write("180.00 ");
  11489. sw.Write("240.00 ");
  11490. sw.Write("300.00 ");
  11491. sw.Write("360.00 ");
  11492. for (int i = 0; i < 42; i++)
  11493. {
  11494. if ((i % 6 == 0))
  11495. {
  11496. sw.Write("\r\n" + "采集值" + (i / 6 + 1).ToString() + " ");
  11497. }
  11498. sw.Write(AngledataRecord[i] + " ");
  11499. }
  11500. sw.Write("\r\n" + "历史零点位置 " + textBox_AngleZeroInit.Text);
  11501. sw.Write("\r\n" + "当前零点位置 " + textBox_AngleZeroCur.Text);
  11502. sw.Write("\r\n" + "零点误差 " + textBox_AngleZeroDiff.Text);
  11503. sw.Write("\r\n" + "最小偏差值 " + textBox_AngleDiffMin.Text);
  11504. sw.Write("\r\n" + "最大偏差值 " + textBox_AngleDiffMax.Text);
  11505. sw.Write("\r\n" + "平均偏差值 " + textBox_AngleDiffAvg.Text);
  11506. sw.Flush();
  11507. }
  11508. fs.Close();
  11509. }
  11510. /// <summary>
  11511. /// 写入校准数据
  11512. /// </summary>
  11513. /// <param name="sender"></param>
  11514. /// <param name="e"></param>
  11515. private void button_AngleWrite_Click(object sender, EventArgs e)
  11516. {
  11517. if ((textBox_AngleDiffAvg.Text == "") || (textBox_AngleZeroInit.Text == ""))
  11518. {
  11519. timer_500ms.Enabled = false;
  11520. MessageBox.Show("请先启动校准,以确认校准数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  11521. timer_500ms.Enabled = true;
  11522. return;
  11523. }
  11524. timer_500ms.Enabled = false;
  11525. string str1 = "确认校准数据,历史零点: " + textBox_AngleZeroInit.Text + ", 偏差平均值: " + textBox_AngleDiffAvg.Text;
  11526. if (MessageBox.Show(str1, "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  11527. {
  11528. var SaveFlag = new byte[4];
  11529. for (int i = 0; i < 4; i++)
  11530. SaveFlag[i] = 0;
  11531. SaveFlag[0] = (byte)(1);
  11532. double data1 = Convert.ToDouble(textBox_AngleZeroInit.Text) - Convert.ToDouble(textBox_AngleDiffAvg.Text);
  11533. if (data1 > 360)
  11534. {
  11535. data1 -= 360;
  11536. }
  11537. else if (data1 < -360)
  11538. {
  11539. data1 += 360;
  11540. }
  11541. Int16 data2 = (Int16)(data1 * 32768 / 360);
  11542. SaveFlag[2] = (byte)(data2);
  11543. SaveFlag[3] = (byte)(data2 >> 8);
  11544. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, SaveFlag);
  11545. timer_500ms.Enabled = true;
  11546. }
  11547. else
  11548. {
  11549. timer_500ms.Enabled = true;
  11550. MessageBoxTimeOut.Show("写入取消", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  11551. }
  11552. }
  11553. /// <summary>
  11554. /// 存储允许偏差
  11555. /// </summary>
  11556. /// <param name="sender"></param>
  11557. /// <param name="e"></param>
  11558. private void textBox_AngleDiffTh_KeyDown(object sender, KeyEventArgs e)
  11559. {
  11560. if (e.KeyCode == Keys.Enter)
  11561. {
  11562. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  11563. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  11564. }
  11565. }
  11566. /// <summary>
  11567. /// 存储零点允许偏差
  11568. /// </summary>
  11569. /// <param name="sender"></param>
  11570. /// <param name="e"></param>
  11571. private void textBox_AngleZeroTh_KeyDown(object sender, KeyEventArgs e)
  11572. {
  11573. if (e.KeyCode == Keys.Enter)
  11574. {
  11575. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  11576. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  11577. }
  11578. }
  11579. /// <summary>
  11580. /// 删除服务器配置文件
  11581. /// </summary>
  11582. /// <param name="sender"></param>
  11583. /// <param name="e"></param>
  11584. private void 重置ToolStripMenuItem_Click(object sender, EventArgs e)
  11585. {
  11586. if (MessageBox.Show("重置后软件自动关闭,确认重置?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  11587. {
  11588. if(File.Exists(localInfo.LocalPath + localInfo.ServerCfgFileName))
  11589. File.Delete(localInfo.LocalPath + localInfo.ServerCfgFileName);
  11590. if(File.Exists(localInfo.LocalPath + localInfo.ConfigFileName))
  11591. File.Delete(localInfo.LocalPath + localInfo.ConfigFileName);
  11592. System.Environment.Exit(0);
  11593. }
  11594. }
  11595. /// <summary>
  11596. /// 按下Enter保存数据
  11597. /// </summary>
  11598. /// <param name="sender"></param>
  11599. /// <param name="e"></param>
  11600. private void toolStripTextBox_AngleAvgMax_KeyDown(object sender, KeyEventArgs e)
  11601. {
  11602. textBox_AngleDiffTh.Text = toolStripTextBox_AngleAvgMax.Text;
  11603. if (e.KeyCode == Keys.Enter)
  11604. {
  11605. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  11606. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  11607. }
  11608. }
  11609. /// <summary>
  11610. /// 按下Enter保存数据
  11611. /// </summary>
  11612. /// <param name="sender"></param>
  11613. /// <param name="e"></param>
  11614. private void toolStripTextBox_AngleZeroMax_KeyDown(object sender, KeyEventArgs e)
  11615. {
  11616. textBox_AngleZeroTh.Text = toolStripTextBox_AngleZeroMax.Text;
  11617. if (e.KeyCode == Keys.Enter)
  11618. {
  11619. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  11620. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  11621. }
  11622. }
  11623. private void 帮助ToolStripMenuItem_Click(object sender, EventArgs e)
  11624. {
  11625. //检查本地文件
  11626. if (!File.Exists(localInfo.LocalPath + localInfo.HelpFilename))
  11627. {
  11628. if (!OfflineFlag)
  11629. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/help/" + localInfo.HelpFilename, localInfo.LocalPath);
  11630. else
  11631. {
  11632. MessageBoxTimeOut.Show("未找到帮助文件!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  11633. return;
  11634. }
  11635. }
  11636. //调用本地浏览器打开帮助文件
  11637. System.Diagnostics.Process.Start("explorer", localInfo.LocalPath + localInfo.HelpFilename);
  11638. }
  11639. /// <summary>
  11640. /// 读取故障日志地址
  11641. /// </summary>
  11642. /// <param name="sender"></param>
  11643. /// <param name="e"></param>
  11644. private void button_ReadLogAddr_Click(object sender, EventArgs e)
  11645. {
  11646. textBox_LogAddrBegin.Text = "";
  11647. textBox_LogAddrEnd.Text = "";
  11648. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x5200, null);
  11649. }
  11650. /// <summary>
  11651. /// 写入硬件版本
  11652. /// </summary>
  11653. /// <param name="sender"></param>
  11654. /// <param name="e"></param>
  11655. private void button_WriteHW_Click(object sender, EventArgs e)
  11656. {
  11657. string HW = textBox_HW.Text;
  11658. var HWArray = new byte[16];
  11659. for (ushort i = 0; i < HW.Length; i++)
  11660. {
  11661. HWArray[i] = (byte)HW[i];
  11662. }
  11663. if (HW.Length < 16)
  11664. {
  11665. HWArray[HW.Length] = (byte)'.';
  11666. for (ushort i = 0; i < 16 - HW.Length - 1; i++)
  11667. {
  11668. HWArray[HW.Length + 1 + i] = 0x20;
  11669. }
  11670. }
  11671. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5310, HWArray);
  11672. }
  11673. /// <summary>
  11674. /// 生产模式写入HW
  11675. /// </summary>
  11676. /// <param name="sender"></param>
  11677. /// <param name="e"></param>
  11678. private void Button_FacModeSetHW_Click(object sender, EventArgs e)
  11679. {
  11680. string HW = textBox_FacModeHW.Text;
  11681. var HWArray = new byte[16];
  11682. for (ushort i = 0; i < HW.Length; i++)
  11683. {
  11684. HWArray[i] = (byte)HW[i];
  11685. }
  11686. if (HW.Length < 16)
  11687. {
  11688. HWArray[HW.Length] = (byte)'.';
  11689. for (ushort i = 0; i < 16 - HW.Length - 1; i++)
  11690. {
  11691. HWArray[HW.Length + 1 + i] = 0x20;
  11692. }
  11693. }
  11694. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5310, HWArray);
  11695. }
  11696. /// <summary>
  11697. /// 读取定制编号
  11698. /// </summary>
  11699. /// <param name="sender"></param>
  11700. /// <param name="e"></param>
  11701. private void button_ReadUserNum_Click(object sender, EventArgs e)
  11702. {
  11703. textBox_UserNum.Text = "---";
  11704. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x5600, null);
  11705. }
  11706. /// <summary>
  11707. /// 写入定制编号
  11708. /// </summary>
  11709. /// <param name="sender"></param>
  11710. /// <param name="e"></param>
  11711. private void button_WriteUserNum_Click(object sender, EventArgs e)
  11712. {
  11713. string User = textBox_UserNum.Text;
  11714. var UserArray = new byte[32];
  11715. for (ushort i = 0; i < User.Length; i++)
  11716. {
  11717. UserArray[i] = (byte)User[i];
  11718. }
  11719. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5720, UserArray);
  11720. }
  11721. /// <summary>
  11722. /// 读取指定块拓展功能
  11723. /// </summary>
  11724. /// <param name="sender"></param>
  11725. /// <param name="e"></param>
  11726. private void button_FunSet_Read_Click(object sender, EventArgs e)
  11727. {
  11728. if (comboBox_FunSet_BlockNum.SelectedIndex < 0)
  11729. {
  11730. MessageBox.Show("请选择块编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  11731. }
  11732. else
  11733. {
  11734. //清空当前内容
  11735. for (int i = 0; i < 8; i++)
  11736. for (int j = 0; j < 8; j++)
  11737. {
  11738. dataGridView_FunSet.Rows[i].Cells[j + 1].Value = "";
  11739. }
  11740. //发送读取指令
  11741. ushort Num = (ushort)(comboBox_FunSet_BlockNum.SelectedIndex + 1);
  11742. var Code = new byte[2];
  11743. Code[0] = (byte)(Num & 0xFF);
  11744. Code[1] = (byte)(Num >> 8);
  11745. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x5402, Code);
  11746. }
  11747. }
  11748. /// <summary>
  11749. /// 写入指定块或指定单元参数
  11750. /// </summary>
  11751. /// <param name="sender"></param>
  11752. /// <param name="e"></param>
  11753. private void button_FunSet_Write_Click(object sender, EventArgs e)
  11754. {
  11755. if (radioButton_WriteByBlock.Checked == true)
  11756. {
  11757. if (comboBox_FunSet_BlockNum.SelectedIndex < 0)
  11758. MessageBox.Show("请选择块编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  11759. else
  11760. {
  11761. //开始按块写入
  11762. ushort Num = (ushort)(comboBox_FunSet_BlockNum.SelectedIndex + 1);
  11763. var Code = new byte[66];
  11764. Code[0] = (byte)(Num & 0xFF);
  11765. Code[1] = (byte)(Num >> 8);
  11766. for (int i = 0; i < 8; i++)
  11767. for (int j = 0; j < 8; j++)
  11768. {
  11769. try
  11770. {
  11771. byte Data = Convert.ToByte(dataGridView_FunSet.Rows[i].Cells[j + 1].Value);
  11772. Code[i * 8 + j + 2] = (byte)(Data & 0xFF);
  11773. }
  11774. catch (Exception)
  11775. {
  11776. MessageBox.Show("数据格式错误或超范围!\r\n" + "单元编号:" + (i + 1).ToString() + "\r\n" + "参数:" + (j + 1).ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  11777. return;
  11778. }
  11779. }
  11780. if (MessageBox.Show("请核对块编号!\r\n" + "块编号:" + (Num).ToString(), "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  11781. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5542, Code);
  11782. else
  11783. MessageBoxTimeOut.Show("取消写入", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  11784. }
  11785. }
  11786. else if (radioButton_WriteByUnit.Checked == true)
  11787. {
  11788. if (comboBox_FunSet_BlockNum.SelectedIndex < 0)
  11789. MessageBox.Show("请选择块编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  11790. else
  11791. {
  11792. if (comboBox_FunSet_UnitNum.SelectedIndex < 0)
  11793. MessageBox.Show("请选择单元编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  11794. else
  11795. {
  11796. //开始按单元写入
  11797. ushort Num1 = (ushort)(comboBox_FunSet_BlockNum.SelectedIndex + 1);
  11798. ushort Num2 = (ushort)(comboBox_FunSet_UnitNum.SelectedIndex + 1);
  11799. var Code = new byte[12];
  11800. Code[0] = (byte)(Num1 & 0xFF);
  11801. Code[1] = (byte)(Num1 >> 8);
  11802. Code[2] = (byte)(Num2 & 0xFF);
  11803. Code[3] = (byte)(Num2 >> 8);
  11804. for (int i = 0; i < 8; i++)
  11805. {
  11806. try
  11807. {
  11808. byte Data = Convert.ToByte(dataGridView_FunSet.Rows[Num2 - 1].Cells[i + 1].Value);
  11809. Code[i + 4] = (byte)(Data & 0xFF);
  11810. }
  11811. catch (Exception)
  11812. {
  11813. MessageBox.Show("数据格式错误或超范围!\r\n" + "单元编号:" + Num2.ToString() + "\r\n" + "参数:" + (i + 1).ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  11814. return;
  11815. }
  11816. }
  11817. if (MessageBox.Show("请核对块编号和单元编号!\r\n" + "块编号:" + Num1.ToString() + "\r\n" + "单元编号:" + Num2.ToString(), "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  11818. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x550C, Code);
  11819. else
  11820. MessageBoxTimeOut.Show("取消写入", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  11821. }
  11822. }
  11823. }
  11824. else
  11825. {
  11826. MessageBox.Show("请选择写入方式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  11827. }
  11828. }
  11829. /// <summary>
  11830. /// 按块写入时隐藏单元编号
  11831. /// </summary>
  11832. /// <param name="sender"></param>
  11833. /// <param name="e"></param>
  11834. private void radioButton_WriteByUnit_CheckedChanged(object sender, EventArgs e)
  11835. {
  11836. if (radioButton_WriteByUnit.Checked == true)
  11837. {
  11838. label159.Visible = true;
  11839. comboBox_FunSet_UnitNum.Visible = true;
  11840. }
  11841. else
  11842. {
  11843. label159.Visible = false;
  11844. comboBox_FunSet_UnitNum.Visible = false;
  11845. }
  11846. }
  11847. private void 样机测试ToolStripMenuItem_Click(object sender, EventArgs e)
  11848. {
  11849. 样机测试ToolStripMenuItem.Checked = !样机测试ToolStripMenuItem.Checked;
  11850. }
  11851. private void timer_AckWait_Tick(object sender, EventArgs e)
  11852. {
  11853. //写入参数等待计时
  11854. ACK_WaitCnt++;
  11855. }
  11856. /// <summary>
  11857. /// 打开或关闭指令窗口
  11858. /// </summary>
  11859. /// <param name="sender"></param>
  11860. /// <param name="e"></param>
  11861. private void 指令调试ToolStripMenuItem_Click(object sender, EventArgs e)
  11862. {
  11863. if (指令调试ToolStripMenuItem.Checked == false)
  11864. {
  11865. if (DebugForm.debug1 == null || DebugForm.debug1.IsDisposed)
  11866. {
  11867. DebugForm.debug1 = new DebugForm();
  11868. DebugForm.debug1.Show();
  11869. this.DebugWindowIsOpen = true;
  11870. }
  11871. else
  11872. {
  11873. DebugForm.debug1.Activate();
  11874. this.DebugWindowIsOpen = true;
  11875. }
  11876. 指令调试ToolStripMenuItem.Checked = true;
  11877. }
  11878. else
  11879. {
  11880. if (this.DebugWindowIsOpen == true)
  11881. {
  11882. DebugForm.debug1.Close();
  11883. this.DebugWindowIsOpen = false;
  11884. this.DebugDataDisplayEnable = false;
  11885. }
  11886. 指令调试ToolStripMenuItem.Checked = false;
  11887. }
  11888. }
  11889. /// <summary>
  11890. /// 读联动装置盒配置
  11891. /// </summary>
  11892. /// <param name="sender"></param>
  11893. /// <param name="e"></param>
  11894. private void 联动装置盒配置ToolStripMenuItem_Click(object sender, EventArgs e)
  11895. {
  11896. toolStripComboBox_PortMode.SelectedIndex = -1;
  11897. toolStripComboBox_CANBaud.SelectedIndex = -1;
  11898. toolStripComboBox_UARTBOOTBAUD.SelectedIndex = -1;
  11899. toolStripComboBox_UARTAPPBAUD.SelectedIndex = -1;
  11900. toolStripTextBox_CDL_Version.Text = "";
  11901. toolStripTextBox_OPTION_GIANT.Checked = false;
  11902. toolStripTextBox_OPTION_Others.Text = "";
  11903. Read_CDL_Info();
  11904. }
  11905. /// <summary>
  11906. /// 写入联动装置盒接口类型
  11907. /// </summary>
  11908. /// <param name="sender"></param>
  11909. /// <param name="e"></param>
  11910. private void toolStripComboBox_PortMode_Click(object sender, EventArgs e)
  11911. {
  11912. byte[] SendData = new byte[4];
  11913. if (toolStripComboBox_PortMode.SelectedIndex == 0) //CAN
  11914. {
  11915. SendData[0] = 0;
  11916. SendData[1] = 0;
  11917. SendData[2] = 0;
  11918. SendData[3] = 1;
  11919. }
  11920. else if (toolStripComboBox_PortMode.SelectedIndex == 1) //UART
  11921. {
  11922. SendData[0] = 0;
  11923. SendData[1] = 0;
  11924. SendData[2] = 0;
  11925. SendData[3] = 2;
  11926. }
  11927. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x8104, SendData);
  11928. }
  11929. private void toolStripComboBox_UARTBOOTBAUD_Click(object sender, EventArgs e)
  11930. {
  11931. byte[] SendData = new byte[4];
  11932. string str = toolStripComboBox_UARTBOOTBAUD.Text;
  11933. if (str != string.Empty)
  11934. {
  11935. SendData[0] = (byte)((int.Parse(str) >> 24) & 0xFF);
  11936. SendData[1] = (byte)((int.Parse(str) >> 16) & 0xFF);
  11937. SendData[2] = (byte)((int.Parse(str) >> 8) & 0xFF);
  11938. SendData[3] = (byte)((int.Parse(str) >> 0) & 0xFF);
  11939. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x8304, SendData);
  11940. }
  11941. }
  11942. private void toolStripComboBox_UARTAPPBAUD_Click(object sender, EventArgs e)
  11943. {
  11944. byte[] SendData = new byte[4];
  11945. string str = toolStripComboBox_UARTAPPBAUD.Text;
  11946. if (str != string.Empty)
  11947. {
  11948. SendData[0] = (byte)((int.Parse(str) >> 24) & 0xFF);
  11949. SendData[1] = (byte)((int.Parse(str) >> 16) & 0xFF);
  11950. SendData[2] = (byte)((int.Parse(str) >> 8) & 0xFF);
  11951. SendData[3] = (byte)((int.Parse(str) >> 0) & 0xFF);
  11952. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x8504, SendData);
  11953. }
  11954. }
  11955. /// <summary>
  11956. /// 设置CDL GIANT内容
  11957. /// </summary>
  11958. /// <param name="sender"></param>
  11959. /// <param name="e"></param>
  11960. private void toolStripTextBox_OPTION_GIANT_Click(object sender, EventArgs e)
  11961. {
  11962. string User = toolStripTextBox_OPTION_GIANT.Text;
  11963. var UserArray = new byte[16];
  11964. for (ushort i = 0; i < User.Length; i++)
  11965. {
  11966. UserArray[i] = (byte)User[i];
  11967. }
  11968. if (User.Length < 16)
  11969. {
  11970. UserArray[User.Length] = (byte)'.';
  11971. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  11972. {
  11973. UserArray[User.Length + 1 + i] = 0x20;
  11974. }
  11975. }
  11976. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x8910, UserArray);
  11977. }
  11978. /// <summary>
  11979. /// 设定CDL定制内容
  11980. /// </summary>
  11981. /// <param name="sender"></param>
  11982. /// <param name="e"></param>
  11983. private void toolStripTextBox_OPTION_Others_KeyDown(object sender, KeyEventArgs e)
  11984. {
  11985. if (e.KeyCode == Keys.Enter)
  11986. {
  11987. string User = toolStripTextBox_OPTION_Others.Text;
  11988. var UserArray = new byte[16];
  11989. for (ushort i = 0; i < User.Length; i++)
  11990. {
  11991. UserArray[i] = (byte)User[i];
  11992. }
  11993. if (User.Length < 16)
  11994. {
  11995. UserArray[User.Length] = (byte)'.';
  11996. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  11997. {
  11998. UserArray[User.Length + 1 + i] = 0x20;
  11999. }
  12000. }
  12001. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x8910, UserArray);
  12002. }
  12003. }
  12004. private void toolStripComboBox_CANBaud_Click(object sender, EventArgs e)
  12005. {
  12006. byte[] SendData = new byte[4];
  12007. string str = toolStripComboBox_CANBaud.Text;
  12008. if (str != string.Empty)
  12009. {
  12010. SendData[0] = (byte)((int.Parse(str) >> 24) & 0xFF);
  12011. SendData[1] = (byte)((int.Parse(str) >> 16) & 0xFF);
  12012. SendData[2] = (byte)((int.Parse(str) >> 8) & 0xFF);
  12013. SendData[3] = (byte)((int.Parse(str) >> 0) & 0xFF);
  12014. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x8704, SendData);
  12015. }
  12016. }
  12017. //读取联动装置盒数据
  12018. private void Read_CDL_Info()
  12019. {
  12020. //类型
  12021. if (!mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x11, (ushort)0x8000, null))
  12022. return;
  12023. Delay_ms(100);
  12024. //CAN 波特率
  12025. if (!mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x11, (ushort)0x8600, null))
  12026. return;
  12027. Delay_ms(100);
  12028. //UART BOOT波特率
  12029. if (!mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x11, (ushort)0x8200, null))
  12030. return;
  12031. Delay_ms(100);
  12032. //UART APP波特率
  12033. if (!mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x11, (ushort)0x8400, null))
  12034. return;
  12035. Delay_ms(100);
  12036. //版本
  12037. byte[] SendData = new byte[20];
  12038. if (!mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x11, (ushort)0x5514, SendData))
  12039. return;
  12040. Delay_ms(100);
  12041. //定制内容
  12042. if (!mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x11, (ushort)0x8800, null))
  12043. return;
  12044. Delay_ms(100);
  12045. }
  12046. }
  12047. }