mainForm.cs 604 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627
  1. using NPOI.POIFS.Crypt.Dsig;
  2. using NPOI.SS.Formula.Functions;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.Diagnostics;
  7. using System.Diagnostics.Eventing.Reader;
  8. using System.Drawing;
  9. using System.Globalization;
  10. using System.IO;
  11. using System.IO.Ports;
  12. using System.Linq;
  13. using System.Reflection;
  14. using System.Runtime.InteropServices;
  15. using System.Runtime.InteropServices.ComTypes;
  16. using System.Text;
  17. using System.Text.RegularExpressions;
  18. using System.Threading;
  19. using System.Web;
  20. using System.Windows.Forms;
  21. using System.Xml.Linq;
  22. using static NPOI.POIFS.Crypt.CryptoFunctions;
  23. namespace Welling_Motor_Debug_Tool
  24. {
  25. public partial class mainForm : Form
  26. {
  27. #region 变量定义
  28. //版本号
  29. public static string Version = "2.5.3";
  30. //串口实例
  31. Serial_Process mySerialProcess = new Serial_Process();
  32. string PortNumSave = "";
  33. string PortBaudrateSave = "";
  34. //本地信息定义
  35. LocalInfo localInfo = new LocalInfo();
  36. //FTP实例
  37. ftp myFtp = new ftp();
  38. public string ServerIP = "";
  39. public string ServerPort = "";
  40. public string ServerUser = "";
  41. public string ServerPassWd = "";
  42. public bool OfflineFlag = false;
  43. //MC运行信息超时计数
  44. bool MC_RunInfo_Refresh = false;
  45. ushort MC_RunInfo_Refresh_Cnt = 0;
  46. //MC调试信息超时计数
  47. bool MC_DebugInfo_Refresh = false;
  48. ushort MC_DebugInfo_Refresh_Cnt = 0;
  49. //MC故障码超时计数
  50. bool MC_ErrorCode_Refresh = false;
  51. ushort MC_ErrorCode_Refresh_Cnt = 0;
  52. //配置参数实例
  53. Params myParams = new Params();
  54. //记录文件名称
  55. string RunInfoSaveFilename = "";
  56. //BMS运行信息超时计数
  57. bool BMS_RunInfo_Refresh = false;
  58. ushort BMS_RunInfo_Refresh_Cnt = 0;
  59. //生产模式关机指令反馈状态
  60. bool PowerOffAckStatus = false;
  61. //登录窗口
  62. public static Login EnterForm1 = new Login();
  63. //生产配置文件信息
  64. ArrayList array_CfgInfo = new ArrayList();
  65. //写入参数返回标志和计数
  66. public bool WriteACK = false;
  67. public ushort ACK_WaitCnt = 0;
  68. //写入参数返回提示标志
  69. public bool ACK_DisFlag = true;
  70. //Boot版本信息
  71. public string BootInfo = "";
  72. //接收指令临时缓存,转string
  73. public string CmdRevStrTemp = "";
  74. //计时器,用于统计运行时间
  75. public Stopwatch stopwatch = new Stopwatch();
  76. //力矩传感器检验参数窗口
  77. public static TorqueParams TorqueParamsForm = new TorqueParams();
  78. //参数生成窗口
  79. public static GenerateParams GenerateParamsForm = new GenerateParams();
  80. //版本信息窗口
  81. public static Version VersionForm = new Version();
  82. //本机硬件信息
  83. public string Local_HdInformation = "";
  84. //指令窗口显示
  85. public bool DebugWindowIsOpen = false, DebugDataDisplayEnable = false;
  86. //位置传感器数据记录
  87. string[] AngledataRecord = new string[42];
  88. //服务器设置窗口
  89. public static ServerSelect ServerCfgForm1 = new ServerSelect();
  90. #endregion
  91. #region 故障日志结构体定义
  92. //故障日志记录信息 60 bytes,1K空间可以保存最近16条故障记录
  93. [StructLayout(LayoutKind.Sequential)]
  94. public struct MC_ErrorLogSaveInfo_Struct_t
  95. {
  96. public UInt16 Error_Index; //故障列表索引 2 bytes, 地址偏移 0
  97. public UInt16 NotesInfo1; //备注信息1,地址偏移 2
  98. public UInt16 NotesInfo2; //备注信息2,地址偏移 4
  99. public UInt16 NotesInfo3; //备注信息3,地址偏移 6
  100. public UInt32 ErrorCode; //故障码 4 bytes, 地址偏移 8
  101. public UInt32 RunTime; //运行时间 4bytes, 地址偏移 12
  102. //电机运行信息,占用空间32bytes
  103. [StructLayout(LayoutKind.Sequential)]
  104. public struct MC_RunInfo_Struct_t
  105. {
  106. public ushort BikeSpeed; //车速 0.1km/h,地址偏移0
  107. public ushort MotorSpeed; //输出转速 1rpm,地址偏移2
  108. public ushort Power; //电功率 1W,地址偏移4
  109. public ushort BusVoltage; //母线电压 1mV,地址偏移6
  110. public ushort BusCurrent; //母线电流 1mA,地址偏移8
  111. public byte Cadence; //踏频 1rpm,地址偏移10
  112. public byte Torque; //踩踏力矩 1Nm,地址偏移11
  113. public byte CadenceDir; //踩踏方向 0-正,1-反,2-停止,地址偏移12
  114. public byte GearSt; //助力档位,地址偏移13
  115. public byte LightSwitch; //灯开关 0xF0-关,0xF1-开,地址偏移14
  116. public byte SOC; //剩余电量 1%,地址偏移15
  117. public ushort RemainDistance; //续航里程 1km,地址偏移16
  118. public ushort Torque_AD; //力矩寄存器,地址偏移18
  119. public byte PowerPerKm; //平均功耗 0.01Ah/km ,地址偏移20
  120. public byte T_PCB; //PCB温度 +40℃,地址偏移21
  121. public byte T_Coil; //绕组温度 +40℃,地址偏移22
  122. public byte T_MCU; //MCU温度 +40℃,地址偏移23
  123. public ushort Ride_Km; //开机后骑行里程 0.1km, 地址偏移24
  124. public ushort Ride_Time; //开机后骑行时间 1s,地址偏移26
  125. public UInt32 RS; //预留 4bytes
  126. };
  127. [MarshalAs(UnmanagedType.Struct)]
  128. public MC_RunInfo_Struct_t RunInfo; //运行信息 32bytes, 地址偏移 16
  129. //控制变量
  130. public Int16 IqCurrent; //Pu, 地址偏移 48
  131. public Int16 IqVoltage; //Pu, 地址偏移 50
  132. public Int16 IdCurrent; //Pu, 地址偏移 52
  133. public Int16 IdVoltage; //Pu, 地址偏移 54
  134. //状态机
  135. public UInt16 FSM; //高到低依次表示系统状态机、二层状态机、电机状态机、助力状态机, 地址偏移 56
  136. //预留
  137. public UInt16 RS1;
  138. public UInt16 RS2;
  139. public UInt16 RS3;
  140. };
  141. #endregion
  142. #region 屏幕缩放比例获取
  143. public class PrimaryScreen
  144. {
  145. #region Win32 API
  146. [DllImport("user32.dll")]
  147. static extern IntPtr GetDC(IntPtr ptr);
  148. [DllImport("gdi32.dll")]
  149. static extern int GetDeviceCaps(
  150. IntPtr hdc, // handle to DC
  151. int nIndex // index of capability
  152. );
  153. [DllImport("user32.dll", EntryPoint = "ReleaseDC")]
  154. static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDc);
  155. #endregion
  156. #region DeviceCaps常量
  157. const int HORZRES = 8;
  158. const int VERTRES = 10;
  159. const int LOGPIXELSX = 88;
  160. const int LOGPIXELSY = 90;
  161. const int DESKTOPVERTRES = 117;
  162. const int DESKTOPHORZRES = 118;
  163. #endregion
  164. #region 属性
  165. /// <summary>
  166. /// 获取屏幕分辨率当前物理大小
  167. /// </summary>
  168. public static Size WorkingArea
  169. {
  170. get
  171. {
  172. IntPtr hdc = GetDC(IntPtr.Zero);
  173. Size size = new Size();
  174. size.Width = GetDeviceCaps(hdc, HORZRES);
  175. size.Height = GetDeviceCaps(hdc, VERTRES);
  176. ReleaseDC(IntPtr.Zero, hdc);
  177. return size;
  178. }
  179. }
  180. /// <summary>
  181. /// 当前系统DPI_X 大小 一般为96
  182. /// </summary>
  183. public static int DpiX
  184. {
  185. get
  186. {
  187. IntPtr hdc = GetDC(IntPtr.Zero);
  188. int DpiX = GetDeviceCaps(hdc, LOGPIXELSX);
  189. ReleaseDC(IntPtr.Zero, hdc);
  190. return DpiX;
  191. }
  192. }
  193. /// <summary>
  194. /// 当前系统DPI_Y 大小 一般为96
  195. /// </summary>
  196. public static int DpiY
  197. {
  198. get
  199. {
  200. IntPtr hdc = GetDC(IntPtr.Zero);
  201. int DpiX = GetDeviceCaps(hdc, LOGPIXELSY);
  202. ReleaseDC(IntPtr.Zero, hdc);
  203. return DpiX;
  204. }
  205. }
  206. /// <summary>
  207. /// 获取真实设置的桌面分辨率大小
  208. /// </summary>
  209. public static Size DESKTOP
  210. {
  211. get
  212. {
  213. IntPtr hdc = GetDC(IntPtr.Zero);
  214. Size size = new Size();
  215. size.Width = GetDeviceCaps(hdc, DESKTOPHORZRES);
  216. size.Height = GetDeviceCaps(hdc, DESKTOPVERTRES);
  217. ReleaseDC(IntPtr.Zero, hdc);
  218. return size;
  219. }
  220. }
  221. /// <summary>
  222. /// 获取宽度缩放百分比
  223. /// </summary>
  224. public static float ScaleX
  225. {
  226. get
  227. {
  228. IntPtr hdc = GetDC(IntPtr.Zero);
  229. int t = GetDeviceCaps(hdc, DESKTOPHORZRES);
  230. int d = GetDeviceCaps(hdc, HORZRES);
  231. float ScaleX = (float)GetDeviceCaps(hdc, DESKTOPHORZRES) / (float)GetDeviceCaps(hdc, HORZRES);
  232. ReleaseDC(IntPtr.Zero, hdc);
  233. return ScaleX;
  234. }
  235. }
  236. /// <summary>
  237. /// 获取高度缩放百分比
  238. /// </summary>
  239. public static float ScaleY
  240. {
  241. get
  242. {
  243. IntPtr hdc = GetDC(IntPtr.Zero);
  244. float ScaleY = (float)(float)GetDeviceCaps(hdc, DESKTOPVERTRES) / (float)GetDeviceCaps(hdc, VERTRES);
  245. ReleaseDC(IntPtr.Zero, hdc);
  246. return ScaleY;
  247. }
  248. }
  249. #endregion
  250. }
  251. #endregion
  252. public static mainForm mainform1 = null;
  253. public mainForm()
  254. {
  255. InitializeComponent();
  256. mainform1 = this;
  257. System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
  258. stopwatch.Start();
  259. //端口初始化
  260. mySerialProcess.Init();
  261. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  262. //检查文件夹
  263. if (!Directory.Exists(localInfo.LocalPath))
  264. {
  265. Directory.CreateDirectory(localInfo.LocalPath);
  266. }
  267. if (!Directory.Exists(localInfo.LocalDataPath))
  268. {
  269. Directory.CreateDirectory(localInfo.LocalDataPath);
  270. }
  271. if (!Directory.Exists(localInfo.ToolsPath))
  272. {
  273. Directory.CreateDirectory(localInfo.ToolsPath);
  274. }
  275. if (!Directory.Exists(localInfo.LocalPath + localInfo.CfgPathName))
  276. {
  277. Directory.CreateDirectory(localInfo.LocalPath + localInfo.CfgPathName);
  278. }
  279. //检查备忘录文件
  280. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.NoteFileName))
  281. {
  282. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.NoteFileName, "");
  283. }
  284. //检验流水号记录文件
  285. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.SerialNumFileName1))
  286. {
  287. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, "0");
  288. }
  289. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.SerialNumFileName2))
  290. {
  291. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, "0");
  292. }
  293. //检查软件打开记录并累加
  294. 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 == "GIANT");
  1444. if (str != "GIANT")
  1445. toolStripTextBox_OPTION_Others.Text = str;
  1446. else
  1447. toolStripTextBox_OPTION_Others.Text = "";
  1448. }));
  1449. }
  1450. break;
  1451. }
  1452. default: break;
  1453. }
  1454. }
  1455. #endregion
  1456. #region 解析电机的命令
  1457. else if ((ID == 0x715) || (ID == 0x710))
  1458. {
  1459. switch (CmdTemp)
  1460. {
  1461. case 0x1020://电机运行信息
  1462. {
  1463. unchecked
  1464. {
  1465. this.Invoke((EventHandler)(delegate
  1466. {
  1467. MC_RunInfo_Refresh = true;
  1468. //车速
  1469. DataTemp = (int)(Data[1] * 256 + Data[0]);
  1470. textBox_RunInfo_BikeSpeed.Text = ((float)DataTemp / 10f).ToString("0.0") + " km/h";
  1471. //输出转速
  1472. DataTemp = (ushort)(Data[3] * 256 + Data[2]);
  1473. textBox_RunInfo_MotorSpeed.Text = Convert.ToString(DataTemp) + " rpm";
  1474. Class_MotorSpeed.String = textBox_RunInfo_MotorSpeed.Text;
  1475. Class_MotorSpeed.Data = DataTemp;
  1476. //电功率
  1477. DataTemp = (ushort)(Data[5] * 256 + Data[4]);
  1478. textBox_RunInfo_Power.Text = Convert.ToString(DataTemp) + " W";
  1479. //母线电压
  1480. DataTemp = (ushort)(Data[7] * 256 + Data[6]);
  1481. textBox_RunInfo_Vol.Text = Convert.ToString(DataTemp) + " mV";
  1482. //textBox_RunInfo_Vol.Text = (DataTemp / 1000f).ToString("0.0") + " V";
  1483. //母线电流
  1484. DataTemp = (short)(Data[9] * 256 + Data[8]);
  1485. textBox_RunInfo_Current.Text = Convert.ToString(DataTemp) + " mA";
  1486. //textBox_RunInfo_Current.Text = (DataTemp / 1000f).ToString("0.0") + " A";
  1487. Class_CurrentData.String = textBox_RunInfo_Current.Text;
  1488. Class_CurrentData.Data = DataTemp;
  1489. //踏频
  1490. DataTemp = (ushort)(Data[10]);
  1491. textBox_RunInfo_Cadence.Text = Convert.ToString(DataTemp) + " rpm";
  1492. Class_CadenceData.String = textBox_RunInfo_Cadence.Text;
  1493. Class_CadenceData.Data = DataTemp;
  1494. //踩踏力矩
  1495. DataTemp = (ushort)(Data[11]);
  1496. textBox_RunInfo_Torque.Text = Convert.ToString(DataTemp) + " N.m";
  1497. Class_TorqueData.String = textBox_RunInfo_Torque.Text;
  1498. Class_TorqueData.Data = DataTemp;
  1499. //踩踏方向
  1500. DataTemp = (ushort)(Data[12]);
  1501. if (DataTemp == 0)
  1502. {
  1503. textBox_RunInfo_Dir.Text = "正向";
  1504. }
  1505. else if (DataTemp == 1)
  1506. {
  1507. textBox_RunInfo_Dir.Text = "反向";
  1508. }
  1509. else if (DataTemp == 2)
  1510. {
  1511. textBox_RunInfo_Dir.Text = "停止";
  1512. }
  1513. //助力档位
  1514. DataTemp = (ushort)(Data[13]);
  1515. if (DataTemp == 0x33)
  1516. {
  1517. textBox_RunInfo_GearSt.Text = "SMART";
  1518. //comboBox_GearSt.SelectedIndex = 5;
  1519. //comboBox_OBC_SetGearST.SelectedIndex = 5;
  1520. }
  1521. else if (DataTemp == 0x22)
  1522. {
  1523. textBox_RunInfo_GearSt.Text = "WALK";
  1524. //comboBox_GearSt.SelectedIndex = 6;
  1525. //comboBox_OBC_SetGearST.SelectedIndex = 6;
  1526. }
  1527. else
  1528. {
  1529. string[] Gears = new string[5] { "OFF", "ECO", "NORM", "SPORT", "TURBO" };
  1530. textBox_RunInfo_GearSt.Text = Gears[DataTemp];
  1531. //comboBox_GearSt.SelectedIndex = DataTemp;
  1532. //comboBox_OBC_SetGearST.SelectedIndex = DataTemp;
  1533. }
  1534. //大灯状态
  1535. DataTemp = (ushort)(Data[14]);
  1536. if (DataTemp == 0xF0)
  1537. {
  1538. textBox_RunInfo_LightSwitch.Text = "OFF";
  1539. //comboBox_LightSwitch.SelectedIndex = 1;
  1540. //comboBox_OBC_LightSw.SelectedIndex = 1;
  1541. }
  1542. else if (DataTemp == 0xF1)
  1543. {
  1544. textBox_RunInfo_LightSwitch.Text = "ON";
  1545. //comboBox_LightSwitch.SelectedIndex = 0;
  1546. //comboBox_OBC_LightSw.SelectedIndex = 0;
  1547. }
  1548. //剩余电量
  1549. DataTemp = (ushort)(Data[15]);
  1550. textBox_RunInfo_SOC.Text = Convert.ToString(DataTemp) + " %";
  1551. //剩余续航里程
  1552. DataTemp = (ushort)(Data[17] * 256 + Data[16]);
  1553. if ((DataTemp == 0xEEEE) || (DataTemp == 0xFFFF))
  1554. {
  1555. textBox_RunInfo_Range.Text = "---";
  1556. }
  1557. else
  1558. {
  1559. textBox_RunInfo_Range.Text = Convert.ToString(DataTemp) + " km";
  1560. }
  1561. //预留(显示力矩Reg),空2bytes
  1562. DataTemp = (ushort)(Data[19] * 256 + Data[18]);
  1563. textBox_TorqueReg.Text = Convert.ToString(DataTemp);
  1564. //平均功耗
  1565. DataTemp = (ushort)(Data[20]);
  1566. textBox_RunInfo_AvgPower.Text = Convert.ToString(DataTemp * 10) + " mAh/km";
  1567. //PCB温度
  1568. DataTemp = (ushort)(Data[21]);
  1569. textBox_RunInfo_T_PCB.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1570. Class_MotorTemp.String = textBox_RunInfo_T_PCB.Text;
  1571. Class_MotorTemp.Data = DataTemp - 40;
  1572. //绕组温度
  1573. DataTemp = (ushort)(Data[22]);
  1574. textBox_RunInfo_T_Coil.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1575. //MCU温度
  1576. DataTemp = (ushort)(Data[23]);
  1577. textBox_RunInfo_T_MCU.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1578. //单次里程
  1579. DataTemp = (ushort)(Data[25] * 256 + Data[24]);
  1580. textBox_RunInfo_Trip.Text = ((float)DataTemp / 10f).ToString("0.0") + " km";
  1581. //单次时间
  1582. DataTemp = (ushort)(Data[27] * 256 + Data[26]);
  1583. textBox_RunInfo_Trip_Time.Text = Convert.ToString(DataTemp) + " s";
  1584. //RSV1
  1585. DataTemp = (ushort)(Data[28]);
  1586. textBox_RunInfo_RSV1.Text = Convert.ToString(DataTemp);
  1587. //RSV2
  1588. DataTemp = (ushort)(Data[29]);
  1589. textBox_RunInfo_RSV2.Text = Convert.ToString(DataTemp);
  1590. //RSV3
  1591. DataTemp = (ushort)(Data[30]);
  1592. textBox_RunInfo_RSV3.Text = Convert.ToString(DataTemp);
  1593. //GearBox
  1594. DataTemp = (ushort)(Data[31]);
  1595. textBox_RunInfo_GearBox.Text = Convert.ToString(DataTemp);
  1596. //数据保存
  1597. RunInfoAutoSave();
  1598. }));
  1599. }
  1600. break;
  1601. }
  1602. case 0x1104://故障码
  1603. {
  1604. unchecked
  1605. {
  1606. this.Invoke((EventHandler)(delegate
  1607. {
  1608. MC_ErrorCode_Refresh = true;
  1609. textBox_ErrorCode.Text =
  1610. Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() +
  1611. Convert.ToString(Data[2], 16).PadLeft(2, '0').ToUpper() +
  1612. Convert.ToString(Data[1], 16).PadLeft(2, '0').ToUpper() +
  1613. Convert.ToString(Data[0], 16).PadLeft(2, '0').ToUpper() +
  1614. "H";
  1615. }));
  1616. }
  1617. break;
  1618. }
  1619. case 0xA903://反馈指令
  1620. {
  1621. unchecked
  1622. {
  1623. this.Invoke((EventHandler)(delegate
  1624. {
  1625. if (ACK_DisFlag == true)
  1626. {
  1627. MessageBoxTimeOut.Show("OK", "反馈指令", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  1628. //关机反馈
  1629. PowerOffAckStatus = true;
  1630. }
  1631. //应答标志置位
  1632. WriteACK = true;
  1633. }));
  1634. }
  1635. break;
  1636. }
  1637. case 0xB226://马达参数
  1638. {
  1639. unchecked
  1640. {
  1641. this.Invoke((EventHandler)(delegate
  1642. {
  1643. richTextBox_MotorParam.Clear();
  1644. for (int i = 0; i < myParams.MotorParam.Count; i++)
  1645. {
  1646. if (i == 6)
  1647. richTextBox_MotorParam.AppendText(myParams.MotorParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1648. else
  1649. richTextBox_MotorParam.AppendText(myParams.MotorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1650. }
  1651. richTextBox_MotorParam.Text = richTextBox_MotorParam.Text.Substring(0, richTextBox_MotorParam.Text.Length - 2);
  1652. }));
  1653. }
  1654. break;
  1655. }
  1656. case 0xB31A://整车信息
  1657. {
  1658. unchecked
  1659. {
  1660. this.Invoke((EventHandler)(delegate
  1661. {
  1662. richTextBox_BikeParam.Clear();
  1663. for (int i = 0; i < myParams.BikeParam.Count; i++)
  1664. {
  1665. if (i == 9)
  1666. richTextBox_BikeParam.AppendText(myParams.BikeParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1667. else
  1668. richTextBox_BikeParam.AppendText(myParams.BikeParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1669. //更新前后灯参数
  1670. if (i == 8)
  1671. {
  1672. comboBox_TailLightMode.SelectedIndex = ((Data[2 * i + 1] >> 4) & 0x0F) - 1;
  1673. comboBox_TailLightVol.SelectedIndex = ((Data[2 * i + 1] & 0x0F) == 6) ? 0 : 1;
  1674. comboBox_FrontLightVol.SelectedIndex = ((Data[2 * i] & 0x0F) == 6) ? 0 : 1;
  1675. }
  1676. //更新开关机参数
  1677. else if (i == 11)
  1678. {
  1679. textBox_PowerOnDelay.Text = Convert.ToString((Data[2 * i + 1] >> 4) & 0x0F);
  1680. textBox_PowerOffDelay.Text = Convert.ToString(Data[2 * i + 1] & 0x0F);
  1681. textBox_AutoPowerOff.Text = Convert.ToString(Data[2 * i]);
  1682. }
  1683. }
  1684. richTextBox_BikeParam.Text = richTextBox_BikeParam.Text.Substring(0, richTextBox_BikeParam.Text.Length - 2);
  1685. }));
  1686. }
  1687. break;
  1688. }
  1689. case 0xB420://控制器参数
  1690. {
  1691. unchecked
  1692. {
  1693. this.Invoke((EventHandler)(delegate
  1694. {
  1695. richTextBox_ControlParam.Clear();
  1696. for (int i = 0; i < myParams.ControlParam.Count; i++)
  1697. {
  1698. richTextBox_ControlParam.AppendText(myParams.ControlParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1699. //转把定速巡航
  1700. if (i == 13)
  1701. {
  1702. comboBox_Bike_CCS.SelectedIndex = ((Data[2 * i]) == 0xAA) ? 1 : 2;
  1703. }
  1704. }
  1705. richTextBox_ControlParam.Text = richTextBox_ControlParam.Text.Substring(0, richTextBox_ControlParam.Text.Length - 2);
  1706. }));
  1707. }
  1708. break;
  1709. }
  1710. case 0xB528://传感器参数
  1711. {
  1712. unchecked
  1713. {
  1714. this.Invoke((EventHandler)(delegate
  1715. {
  1716. richTextBox_SensorParam.Clear();
  1717. for (int i = 0; i < myParams.SensorParam.Count; i++)
  1718. {
  1719. richTextBox_SensorParam.AppendText(myParams.SensorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1720. }
  1721. richTextBox_SensorParam.Text = richTextBox_SensorParam.Text.Substring(0, richTextBox_SensorParam.Text.Length - 2);
  1722. //更新生产模式页面传感器零点和标定值
  1723. textBox_FacModeSensorADC0.Text = (Data[9] * 256 + Data[8]).ToString();
  1724. textBox_FacModeSensorADC1.Text = (Data[15] * 256 + Data[14]).ToString();
  1725. textBox_FacModeSensorADC2.Text = (Data[19] * 256 + Data[18]).ToString();
  1726. textBox_FacModeSensorADC3.Text = (Data[23] * 256 + Data[22]).ToString();
  1727. textBox_FacModeSensorADC4.Text = (Data[27] * 256 + Data[26]).ToString();
  1728. WriteACK = true;
  1729. }));
  1730. }
  1731. break;
  1732. }
  1733. case 0xB64C://助力参数
  1734. {
  1735. unchecked
  1736. {
  1737. this.Invoke((EventHandler)(delegate
  1738. {
  1739. richTextBox_AssistParam.Clear();
  1740. int index_1 = myParams.AssistParam.IndexOf("转矩曲线.a");
  1741. int index_2 = myParams.AssistParam.IndexOf("踏频曲线.d");
  1742. int index_3 = myParams.AssistParam.IndexOf("踏频助力加速限制");
  1743. int index_4 = myParams.AssistParam.IndexOf("踏频助力电流步进");
  1744. for (int i = 0; i < myParams.AssistParam.Count; i++)
  1745. {
  1746. if (i < index_1) //数据占用2bytes
  1747. {
  1748. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1749. }
  1750. else if (i <= index_2) //数据占用4bytes
  1751. {
  1752. 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])) + ", ");
  1753. }
  1754. else if (i < index_3) //数据占用2bytes,无符号
  1755. {
  1756. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1757. }
  1758. else if (i <= index_4) //数据占用2bytes,有符号
  1759. {
  1760. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1761. }
  1762. else //数据占用2bytes,无符号
  1763. {
  1764. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1765. }
  1766. }
  1767. richTextBox_AssistParam.Text = richTextBox_AssistParam.Text.Substring(0, richTextBox_AssistParam.Text.Length - 2);
  1768. }));
  1769. }
  1770. break;
  1771. }
  1772. case 0xB74C://历史记录
  1773. {
  1774. unchecked
  1775. {
  1776. this.Invoke((EventHandler)(delegate
  1777. {
  1778. richTextBox_Record.Clear();
  1779. for (int i = 0; i < myParams.Record.Count; i++)
  1780. {
  1781. richTextBox_Record.AppendText(myParams.Record[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  1782. }
  1783. richTextBox_Record.Text = richTextBox_Record.Text.Substring(0, richTextBox_Record.Text.Length - 2);
  1784. }));
  1785. }
  1786. break;
  1787. }
  1788. case 0xB83A://调试参数
  1789. {
  1790. unchecked
  1791. {
  1792. this.Invoke((EventHandler)(delegate
  1793. {
  1794. richTextBox_DebugParam.Clear();
  1795. for (int i = 0; i < myParams.DebugParam.Count; i++)
  1796. {
  1797. richTextBox_DebugParam.AppendText(myParams.DebugParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1798. }
  1799. richTextBox_DebugParam.Text = richTextBox_DebugParam.Text.Substring(0, richTextBox_DebugParam.Text.Length - 2);
  1800. }));
  1801. }
  1802. break;
  1803. }
  1804. case 0xB904://存储标志
  1805. {
  1806. unchecked
  1807. {
  1808. this.Invoke((EventHandler)(delegate
  1809. {
  1810. ushort Flag = 0;
  1811. Flag = (ushort)(Data[1] * 256 + Data[0]);//EEPROM存储标志
  1812. if (Flag == 0)
  1813. {
  1814. radioButton_EE_SaveNo.Checked = true;
  1815. radioButton_EE_SaveYes.Checked = false;
  1816. }
  1817. else
  1818. {
  1819. radioButton_EE_SaveNo.Checked = false;
  1820. radioButton_EE_SaveYes.Checked = true;
  1821. }
  1822. Flag = (ushort)(Data[3] * 256 + Data[2]);//SIP偏移校准存储标志
  1823. if (Flag == 0)
  1824. {
  1825. radioButton_SIP_SaveNo.Checked = true;
  1826. radioButton_SIP_SaveYes.Checked = false;
  1827. }
  1828. else
  1829. {
  1830. radioButton_SIP_SaveNo.Checked = false;
  1831. radioButton_SIP_SaveYes.Checked = true;
  1832. }
  1833. }));
  1834. }
  1835. break;
  1836. }
  1837. case 0x1240://电机版本信息
  1838. {
  1839. unchecked
  1840. {
  1841. this.Invoke((EventHandler)(delegate
  1842. {
  1843. //电机型号
  1844. textBox_Model.Text = "";
  1845. textBox_OBC_ReadModel.Text = "";
  1846. textBox_FacModeName.Text = "";
  1847. for (ushort i = 0; i < 16; i++)
  1848. {
  1849. if (Data[i] == 0x2E)
  1850. {
  1851. break;
  1852. }
  1853. textBox_Model.Text += ((char)Data[i]).ToString();
  1854. textBox_OBC_ReadModel.Text += ((char)Data[i]).ToString();
  1855. textBox_FacModeName.Text += ((char)Data[i]).ToString();
  1856. }
  1857. Class_Motor_Ver.Mode = textBox_Model.Text;
  1858. //电机SN
  1859. textBox_SN.Text = "";
  1860. textBox_OBC_ReadSN.Text = "";
  1861. textBox_FacModeNum.Text = "";
  1862. for (ushort i = 0; i < 16; i++)
  1863. {
  1864. if (Data[16 + i] == 0x2E)
  1865. {
  1866. break;
  1867. }
  1868. textBox_SN.Text += ((char)Data[16 + i]).ToString();
  1869. textBox_OBC_ReadSN.Text += ((char)Data[16 + i]).ToString();
  1870. textBox_FacModeNum.Text += ((char)Data[16 + i]).ToString();
  1871. }
  1872. Class_Motor_Ver.SN = textBox_SN.Text;
  1873. //电机HW
  1874. textBox_HW.Text = "";
  1875. textBox_OBC_ReadHW.Text = "";
  1876. textBox_FacModeHW.Text = "";
  1877. for (ushort i = 0; i < 8; i++)//前8位:硬件板号
  1878. {
  1879. if (Data[32 + i] == 0x2E)
  1880. {
  1881. break;
  1882. }
  1883. else if (Data[32 + i] == 'r')
  1884. {
  1885. Data[32 + i] = (byte)'.';
  1886. break;
  1887. }
  1888. string strTemp = "";
  1889. strTemp = ((char)Data[32 + i]).ToString();
  1890. textBox_HW.Text += strTemp;
  1891. textBox_OBC_ReadHW.Text += strTemp;
  1892. textBox_FacModeHW.Text += strTemp;
  1893. }
  1894. for (ushort i = 0; i < 4; i++)//9-12位:单片机型号
  1895. {
  1896. if (Data[40 + i] == 0x2E)
  1897. {
  1898. break;
  1899. }
  1900. else if (Data[40 + i] == 'r')
  1901. {
  1902. Data[40 + i] = (byte)'.';
  1903. break;
  1904. }
  1905. string strTemp = "";
  1906. strTemp = ((char)Data[40 + i]).ToString();
  1907. textBox_HW.Text += strTemp;
  1908. textBox_OBC_ReadHW.Text += strTemp;
  1909. textBox_FacModeHW.Text += strTemp;
  1910. }
  1911. for (ushort i = 0; i < 4; i++)//13-16位:单片机ID
  1912. {
  1913. string strTemp = "";
  1914. strTemp = Convert.ToString(Data[44 + i], 16).PadLeft(2, '0').ToUpper();
  1915. textBox_HW.Text += strTemp;
  1916. textBox_OBC_ReadHW.Text += strTemp;
  1917. textBox_FacModeHW.Text += strTemp;
  1918. }
  1919. Class_Motor_Ver.HW = textBox_HW.Text;
  1920. //电机FW
  1921. textBox_FW.Text = "";
  1922. textBox_OBC_ReadFW.Text = "";
  1923. textBox_FacModeFW.Text = "";
  1924. for (ushort i = 0; i < 16; i++)
  1925. {
  1926. if ((Data[48 + i] == 0x2E) || (Data[48 + i] == 0x00) || (Data[48 + i] == (char)' '))
  1927. {
  1928. break;
  1929. }
  1930. if (Data[48 + i] == 'r')
  1931. {
  1932. Data[48 + i] = (byte)'.';
  1933. }
  1934. textBox_FW.Text += ((char)Data[48 + i]).ToString();
  1935. textBox_OBC_ReadFW.Text += ((char)Data[48 + i]).ToString();
  1936. textBox_FacModeFW.Text += ((char)Data[48 + i]).ToString();
  1937. }
  1938. Class_Motor_Ver.FW = textBox_FW.Text;
  1939. }));
  1940. }
  1941. break;
  1942. }
  1943. case 0xA610://自定义1
  1944. {
  1945. unchecked
  1946. {
  1947. this.Invoke((EventHandler)(delegate
  1948. {
  1949. textBox_User1.Text = "";
  1950. for (ushort i = 0; i < 16; i++)
  1951. {
  1952. if (Data[i] == 0x2E)
  1953. {
  1954. break;
  1955. }
  1956. textBox_User1.Text += ((char)Data[i]).ToString();
  1957. }
  1958. }));
  1959. }
  1960. break;
  1961. }
  1962. case 0xA710://自定义2
  1963. {
  1964. unchecked
  1965. {
  1966. this.Invoke((EventHandler)(delegate
  1967. {
  1968. textBox_User2.Text = "";
  1969. for (ushort i = 0; i < 16; i++)
  1970. {
  1971. if (Data[i] == 0x2E)
  1972. {
  1973. break;
  1974. }
  1975. textBox_User2.Text += ((char)Data[i]).ToString();
  1976. }
  1977. }));
  1978. }
  1979. break;
  1980. }
  1981. case 0xA810://自定义1
  1982. {
  1983. unchecked
  1984. {
  1985. this.Invoke((EventHandler)(delegate
  1986. {
  1987. textBox_User3.Text = "";
  1988. for (ushort i = 0; i < 16; i++)
  1989. {
  1990. if (Data[i] == 0x2E)
  1991. {
  1992. break;
  1993. }
  1994. textBox_User3.Text += ((char)Data[i]).ToString();
  1995. }
  1996. }));
  1997. }
  1998. break;
  1999. }
  2000. case 0xA520://生产信息
  2001. {
  2002. unchecked
  2003. {
  2004. this.Invoke((EventHandler)(delegate
  2005. {
  2006. //生产商
  2007. textBox_MAC.Text = "";
  2008. for (ushort i = 0; i < 8; i++)
  2009. {
  2010. if (Data[i] == 0x2E)
  2011. {
  2012. break;
  2013. }
  2014. textBox_MAC.Text += ((char)Data[i]).ToString();
  2015. }
  2016. //生产地
  2017. textBox_MACAdd.Text = "";
  2018. for (ushort i = 0; i < 8; i++)
  2019. {
  2020. if (Data[8 + i] == 0x2E)
  2021. {
  2022. break;
  2023. }
  2024. textBox_MACAdd.Text += ((char)Data[8 + i]).ToString();
  2025. }
  2026. //生产日期
  2027. textBox_MACDate.Text = "";
  2028. for (ushort i = 0; i < 8; i++)
  2029. {
  2030. if (Data[16 + i] == 0x2E)
  2031. {
  2032. break;
  2033. }
  2034. textBox_MACDate.Text += ((char)Data[16 + i]).ToString();
  2035. }
  2036. //品牌信息
  2037. textBox_PP.Text = "";
  2038. for (ushort i = 0; i < 8; i++)
  2039. {
  2040. if (Data[24 + i] == 0x2E)
  2041. {
  2042. break;
  2043. }
  2044. textBox_PP.Text += ((char)Data[24 + i]).ToString();
  2045. }
  2046. }));
  2047. }
  2048. break;
  2049. }
  2050. case 0xA408://密钥
  2051. {
  2052. unchecked
  2053. {
  2054. this.Invoke((EventHandler)(delegate
  2055. {
  2056. textBox_Key.Text = "";
  2057. for (ushort i = 0; i < 8; i++)
  2058. {
  2059. textBox_Key.Text += ((char)Data[i]).ToString();
  2060. }
  2061. }));
  2062. }
  2063. break;
  2064. }
  2065. case 0xAB09://存储器数据
  2066. case 0xAB0A:
  2067. case 0xAB0B:
  2068. case 0xAB0C:
  2069. {
  2070. unchecked
  2071. {
  2072. this.Invoke((EventHandler)(delegate
  2073. {
  2074. long ByteNum = 0;
  2075. ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
  2076. if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
  2077. {
  2078. for (int i = 0; i < ByteNum; i++)
  2079. {
  2080. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  2081. }
  2082. }
  2083. else //根据设置自动转换10进制显示
  2084. {
  2085. if (checkBox_ReadRanFlash_ChangeFormat.Checked == true) //10进制显示
  2086. {
  2087. switch (ByteNum)
  2088. {
  2089. case 1:
  2090. {
  2091. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8]) + ", ");
  2092. break;
  2093. }
  2094. case 2:
  2095. {
  2096. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8)) + ", ");
  2097. break;
  2098. }
  2099. case 3:
  2100. {
  2101. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16)) + ", ");
  2102. break;
  2103. }
  2104. case 4:
  2105. {
  2106. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24)) + ", ");
  2107. break;
  2108. }
  2109. default:
  2110. {
  2111. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  2112. break;
  2113. }
  2114. }
  2115. }
  2116. else //16进制显示
  2117. {
  2118. switch (ByteNum)
  2119. {
  2120. case 1:
  2121. {
  2122. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8], 16).PadLeft(2, '0').ToUpper() + ", ");
  2123. break;
  2124. }
  2125. case 2:
  2126. {
  2127. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8), 16).PadLeft(4, '0').ToUpper() + ", ");
  2128. break;
  2129. }
  2130. case 3:
  2131. {
  2132. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16), 16).PadLeft(6, '0').ToUpper() + ", ");
  2133. break;
  2134. }
  2135. case 4:
  2136. {
  2137. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24), 16).PadLeft(8, '0').ToUpper() + ", ");
  2138. break;
  2139. }
  2140. default:
  2141. {
  2142. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  2143. break;
  2144. }
  2145. }
  2146. }
  2147. }
  2148. }));
  2149. }
  2150. break;
  2151. }
  2152. case 0xAB88://故障日志
  2153. {
  2154. unchecked
  2155. {
  2156. this.Invoke((EventHandler)(delegate
  2157. {
  2158. //电机存储的故障日志,一包128字节包含2条故障日志
  2159. var ErrorLogSaveInfo1 = new MC_ErrorLogSaveInfo_Struct_t();
  2160. var ErrorLogSaveInfo2 = new MC_ErrorLogSaveInfo_Struct_t();
  2161. ErrorLogSaveInfo1 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 8);
  2162. ErrorLogSaveInfo2 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 72);
  2163. //数据显示
  2164. ErrorLogDisplay(ErrorLogSaveInfo1, ErrorLogSaveInfo2);
  2165. }));
  2166. }
  2167. break;
  2168. }
  2169. case 0x1401://在线检测结果
  2170. {
  2171. unchecked
  2172. {
  2173. this.Invoke((EventHandler)(delegate
  2174. {
  2175. textBox_Online.Text = Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() + "H";
  2176. }));
  2177. }
  2178. break;
  2179. }
  2180. case 0x1510://骑行历史信息
  2181. {
  2182. unchecked
  2183. {
  2184. this.Invoke((EventHandler)(delegate
  2185. {
  2186. long DataTemp32;
  2187. //ODO里程
  2188. DataTemp32 = (long)((Data[3] << 24) + (Data[2] << 16) + (Data[1] << 8) + Data[0]);
  2189. textBox_OBC_ODO_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  2190. textBox_ODO_KM.Text = DataTemp32.ToString();
  2191. //ODO时间
  2192. DataTemp32 = (long)((Data[7] << 24) + (Data[6] << 16) + (Data[5] << 8) + Data[4]);
  2193. if (DataTemp32 >= 60 * 100000)
  2194. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  2195. else
  2196. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  2197. textBox_ODO_TIME.Text = DataTemp32.ToString();
  2198. //TRIP里程
  2199. DataTemp32 = (long)((Data[11] << 24) + (Data[10] << 16) + (Data[9] << 8) + Data[8]);
  2200. textBox_OBC_TRIP_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  2201. textBox_TRIP_KM.Text = DataTemp32.ToString();
  2202. //TRIP时间
  2203. DataTemp32 = (long)((Data[15] << 24) + (Data[14] << 16) + (Data[13] << 8) + Data[12]);
  2204. if (DataTemp32 >= 60 * 100000)
  2205. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  2206. else
  2207. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  2208. textBox_TRIP_TIME.Text = DataTemp32.ToString();
  2209. }));
  2210. }
  2211. break;
  2212. }
  2213. case 0x1720://客户信息
  2214. {
  2215. unchecked
  2216. {
  2217. this.Invoke((EventHandler)(delegate
  2218. {
  2219. //软件标识
  2220. textBox_SP.Text = "";
  2221. textBox_OBC_ReadSP.Text = "";
  2222. textBox_FacModeSP.Text = "";
  2223. for (ushort i = 0; i < 23; i++)
  2224. {
  2225. if (Data[i] == 'r')
  2226. {
  2227. Data[i] = (byte)'.';
  2228. }
  2229. textBox_SP.Text += ((char)Data[i]).ToString();
  2230. textBox_OBC_ReadSP.Text += ((char)Data[i]).ToString();
  2231. textBox_FacModeSP.Text += ((char)Data[i]).ToString();
  2232. }
  2233. //Git提交版本信息
  2234. textBox_FacModeGit.Text = "";
  2235. for (ushort i = 0; i < 9; i++)
  2236. {
  2237. textBox_SP.Text += ((char)Data[23 + i]).ToString();
  2238. textBox_FacModeGit.Text += ((char)Data[23 + i]).ToString();
  2239. }
  2240. Class_Motor_Ver.Special = textBox_SP.Text;
  2241. }));
  2242. }
  2243. break;
  2244. }
  2245. case 0xBA20: //调试信息
  2246. {
  2247. unchecked
  2248. {
  2249. this.Invoke((EventHandler)(delegate
  2250. {
  2251. MC_DebugInfo_Refresh = true;
  2252. //系统状态机
  2253. DataTemp = (short)(Data[0]);
  2254. textBox_DebugInfo_SysFun.Text = Convert.ToString(DataTemp);
  2255. //二层状态机
  2256. DataTemp = (short)(Data[1]);
  2257. textBox_DebugInfo_SecondFun.Text = Convert.ToString(DataTemp);
  2258. //电机状态机
  2259. DataTemp = (short)(Data[2]);
  2260. textBox_DebugInfo_MotorFun.Text = Convert.ToString(DataTemp);
  2261. //助力状态机
  2262. DataTemp = (short)(Data[3]);
  2263. textBox_DebugInfo_AssistFun.Text = Convert.ToString(DataTemp);
  2264. //IdRef
  2265. DataTemp = (short)(Data[5] * 256 + Data[4]);
  2266. textBox_DebugInfo_IdRef.Text = Convert.ToString(DataTemp);
  2267. //IqRef
  2268. DataTemp = (short)(Data[7] * 256 + Data[6]);
  2269. textBox_DebugInfo_IqRef.Text = Convert.ToString(DataTemp);
  2270. //UdRef
  2271. DataTemp = (short)(Data[9] * 256 + Data[8]);
  2272. textBox_DebugInfo_UdRef.Text = Convert.ToString(DataTemp);
  2273. //UqRef
  2274. DataTemp = (short)(Data[11] * 256 + Data[10]);
  2275. textBox_DebugInfo_UqRef.Text = Convert.ToString(DataTemp);
  2276. //瞬时力矩
  2277. DataTemp = (short)(Data[13] * 256 + Data[12]);
  2278. textBox_DebugInfo_TorquePu.Text = Convert.ToString(DataTemp);
  2279. //时间滤波力矩
  2280. DataTemp = (short)(Data[15] * 256 + Data[14]);
  2281. textBox_DebugInfo_TorqueFil.Text = Convert.ToString(DataTemp);
  2282. //踏频滤波力矩
  2283. DataTemp = (short)(Data[17] * 256 + Data[16]);
  2284. textBox_DebugInfo_TorqueCadence.Text = Convert.ToString(DataTemp);
  2285. //IdFdb
  2286. DataTemp = (short)(Data[19] * 256 + Data[18]);
  2287. textBox_DebugInfo_IdFdb.Text = Convert.ToString(DataTemp);
  2288. //IqFdb
  2289. DataTemp = (short)(Data[21] * 256 + Data[20]);
  2290. textBox_DebugInfo_IqFdb.Text = Convert.ToString(DataTemp);
  2291. //助力输出
  2292. DataTemp = (short)(Data[23] * 256 + Data[22]);
  2293. textBox_DebugInfo_AssistOut.Text = Convert.ToString(DataTemp);
  2294. //转把百分比
  2295. DataTemp = (short)(Data[25] * 256 + Data[24]);
  2296. textBox_DebugInfo_ThrottlePer.Text = Convert.ToString(DataTemp);
  2297. //数据保存
  2298. RunInfoAutoSave();
  2299. }));
  2300. }
  2301. break;
  2302. }
  2303. case 0xBB20: //产品标签信息
  2304. {
  2305. unchecked
  2306. {
  2307. this.Invoke((EventHandler)(delegate
  2308. {
  2309. //产品标签
  2310. textBox_TagInfo.Text = "";
  2311. for (ushort i = 0; i < 32; i++)
  2312. {
  2313. textBox_TagInfo.Text += ((char)Data[i]).ToString();
  2314. }
  2315. }));
  2316. }
  2317. break;
  2318. }
  2319. case 0xBC20: //内阻校正信息
  2320. {
  2321. unchecked
  2322. {
  2323. this.Invoke((EventHandler)(delegate
  2324. {
  2325. //内阻1
  2326. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  2327. textBox_MOS_R1.Text = Convert.ToString(uData16);
  2328. //内阻2
  2329. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  2330. textBox_MOS_R2.Text = Convert.ToString(uData16);
  2331. //内阻3
  2332. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  2333. textBox_MOS_R3.Text = Convert.ToString(uData16);
  2334. //K1
  2335. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  2336. textBox_MOS_K1.Text = Convert.ToString(uData16);
  2337. //K2
  2338. uData16 = (ushort)(Data[9] * 256 + Data[8]);
  2339. textBox_MOS_K2.Text = Convert.ToString(uData16);
  2340. //K3
  2341. uData16 = (ushort)(Data[11] * 256 + Data[10]);
  2342. textBox_MOS_K3.Text = Convert.ToString(uData16);
  2343. //K4
  2344. uData16 = (ushort)(Data[13] * 256 + Data[12]);
  2345. textBox_MOS_K4.Text = Convert.ToString(uData16);
  2346. //K5
  2347. uData16 = (ushort)(Data[15] * 256 + Data[14]);
  2348. textBox_MOS_K5.Text = Convert.ToString(uData16);
  2349. }));
  2350. }
  2351. break;
  2352. }
  2353. case 0xBD20: //整车信息2
  2354. {
  2355. unchecked
  2356. {
  2357. this.Invoke((EventHandler)(delegate
  2358. {
  2359. richTextBox_BikeParam2.Clear();
  2360. for (int i = 0; i < myParams.BikeParam2.Count; i++)
  2361. {
  2362. richTextBox_BikeParam2.AppendText(myParams.BikeParam2[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  2363. }
  2364. richTextBox_BikeParam2.Text = richTextBox_BikeParam2.Text.Substring(0, richTextBox_BikeParam2.Text.Length - 2);
  2365. }));
  2366. }
  2367. break;
  2368. }
  2369. case 0xBE20: //用户骑行参数
  2370. {
  2371. unchecked
  2372. {
  2373. this.Invoke((EventHandler)(delegate
  2374. {
  2375. richTextBox_UsrRidesParam.Clear();
  2376. for (int i = 0; i < myParams.UsrRideParam.Count; i++)
  2377. {
  2378. richTextBox_UsrRidesParam.AppendText(myParams.UsrRideParam[i] + "=" + Convert.ToString(Data[i]) + ", ");
  2379. }
  2380. richTextBox_UsrRidesParam.Text = richTextBox_UsrRidesParam.Text.Substring(0, richTextBox_UsrRidesParam.Text.Length - 2);
  2381. }));
  2382. }
  2383. break;
  2384. }
  2385. case 0xBF58: //位置传感器校准值
  2386. {
  2387. unchecked
  2388. {
  2389. this.Invoke((EventHandler)(delegate
  2390. {
  2391. string[] str1 = new string[42];
  2392. double[] error1 = new double[42];
  2393. //更新校准数据
  2394. for (int i = 0; i < 42; i++)
  2395. {
  2396. double data1 = (Data[4 + i * 2] + (Data[4 + i * 2 + 1] << 8)) / 32767.0 * 360;
  2397. error1[i] = data1 - (60 * (i % 6) + 60);
  2398. if (error1[i] < -180)
  2399. {
  2400. error1[i] = error1[i] + 360;
  2401. }
  2402. str1[i] = data1.ToString("F2");
  2403. AngledataRecord[i] = str1[i];
  2404. }
  2405. for (int i = 0; i < 7; i++)
  2406. for (int j = 0; j < 6; j++)
  2407. {
  2408. dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = str1[6 * i + j];
  2409. }
  2410. //计算偏差最小值、最大值和平均值
  2411. //Array.ConvertAll(error1, Math.Abs);
  2412. textBox_AngleDiffMin.Text = error1.Min().ToString("F2");
  2413. textBox_AngleDiffMax.Text = error1.Max().ToString("F2");
  2414. textBox_AngleDiffAvg.Text = error1.Average().ToString("F2");
  2415. //计算零点偏差
  2416. double tmp1 = ((Int16)(Data[0] + (Data[1] << 8))) / 32767.0 * 360;
  2417. textBox_AngleZeroInit.Text = tmp1.ToString("F2");
  2418. double tmp2 = ((Int16)(Data[2] + (Data[3] << 8))) / 32767.0 * 360;
  2419. textBox_AngleZeroCur.Text = tmp2.ToString("F2");
  2420. double tmp3 = (tmp2 - tmp1);
  2421. textBox_AngleZeroDiff.Text = tmp3.ToString("F2");
  2422. }));
  2423. }
  2424. break;
  2425. }
  2426. case 0xC008: //故障日志地址
  2427. {
  2428. unchecked
  2429. {
  2430. this.Invoke((EventHandler)(delegate
  2431. {
  2432. uint Addr_Begin = 0, Addr_End = 0;
  2433. Addr_Begin = (uint)((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]);
  2434. Addr_End = (uint)((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]);
  2435. textBox_LogAddrBegin.Text = Convert.ToString(Addr_Begin, 16).PadLeft(8, '0').ToUpper();
  2436. textBox_LogAddrEnd.Text = Convert.ToString(Addr_End, 16).PadLeft(8, '0').ToUpper();
  2437. }));
  2438. }
  2439. break;
  2440. }
  2441. case 0xC109: //Boot版本信息
  2442. {
  2443. BootInfo = "";
  2444. for (ushort i = 0; i < 9; i++)
  2445. {
  2446. BootInfo += ((char)Data[i]).ToString();
  2447. }
  2448. break;
  2449. }
  2450. case 0xC142: //功能配置表
  2451. {
  2452. unchecked
  2453. {
  2454. this.Invoke((EventHandler)(delegate
  2455. {
  2456. //块编号
  2457. ushort Num = (ushort)(Data[1] * 256 + Data[0]);
  2458. comboBox_FunSet_BlockNum.SelectedIndex = Num - 1;
  2459. //显示数据
  2460. for (int i = 0; i < 64; i++)
  2461. {
  2462. dataGridView_FunSet.Rows[i / 8].Cells[i % 8 + 1].Value = Data[i + 2].ToString();
  2463. }
  2464. }));
  2465. }
  2466. break;
  2467. }
  2468. case 0xC220: //定制编号
  2469. {
  2470. unchecked
  2471. {
  2472. this.Invoke((EventHandler)(delegate
  2473. {
  2474. //定制编号
  2475. textBox_UserNum.Text = "";
  2476. for (ushort i = 0; i < 32; i++)
  2477. {
  2478. textBox_UserNum.Text += ((char)Data[i]).ToString();
  2479. }
  2480. }));
  2481. }
  2482. break;
  2483. }
  2484. default:
  2485. {
  2486. break;
  2487. }
  2488. }
  2489. //存储器导出数据显示
  2490. if ((CmdTemp & 0xFF00) == 0xAB00)
  2491. {
  2492. unchecked
  2493. {
  2494. this.Invoke((EventHandler)(delegate
  2495. {
  2496. long ByteNum = 0;
  2497. ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
  2498. if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
  2499. {
  2500. for (int i = 0; i < ByteNum; i++)
  2501. {
  2502. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  2503. }
  2504. }
  2505. }));
  2506. }
  2507. }
  2508. }
  2509. #endregion
  2510. #region 解析BMS广播的命令
  2511. else if (ID == 0x720)
  2512. {
  2513. switch (CmdTemp)
  2514. {
  2515. case 0x1010://BMS运行信息
  2516. {
  2517. unchecked
  2518. {
  2519. this.Invoke((EventHandler)(delegate
  2520. {
  2521. BMS_RunInfo_Refresh = true;
  2522. richTextBox_OBC_BMS_RunInfo.Clear();
  2523. //电压
  2524. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  2525. richTextBox_OBC_BMS_RunInfo.AppendText("电压:" + Convert.ToString(uData16) + " mV" + "\r\n");
  2526. //电流
  2527. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  2528. richTextBox_OBC_BMS_RunInfo.AppendText("电流:" + Convert.ToString(uData16) + " mA" + "\r\n");
  2529. //剩余容量
  2530. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  2531. richTextBox_OBC_BMS_RunInfo.AppendText("剩余容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  2532. //满充容量
  2533. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  2534. richTextBox_OBC_BMS_RunInfo.AppendText("满充容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  2535. //电芯温度
  2536. richTextBox_OBC_BMS_RunInfo.AppendText("电芯温度:" + Convert.ToString((int)(Data[8] - 40) + " ℃" + "\r\n"));
  2537. //剩余电量
  2538. richTextBox_OBC_BMS_RunInfo.AppendText("剩余电量:" + Convert.ToString(Data[9]) + " %" + "\r\n");
  2539. //电池状态
  2540. richTextBox_OBC_BMS_RunInfo.AppendText("电池状态:" + Convert.ToString(Data[10], 16).PadLeft(2, '0').ToUpper() + " H" + "\r\n");
  2541. //SOH
  2542. richTextBox_OBC_BMS_RunInfo.AppendText("电池寿命:" + Convert.ToString(Data[11]) + " %" + "\r\n");
  2543. //循环次数
  2544. richTextBox_OBC_BMS_RunInfo.AppendText("循环次数:" + Convert.ToString((ushort)(Data[13] * 256 + Data[12])) + " 次");
  2545. }));
  2546. }
  2547. break;
  2548. }
  2549. default: break;
  2550. }
  2551. }
  2552. #endregion
  2553. #region 解析电机发送OBC的命令
  2554. else if (ID == 0x713)
  2555. {
  2556. switch (CmdTemp)
  2557. {
  2558. case 0x5408://电机用户参数
  2559. {
  2560. unchecked
  2561. {
  2562. this.Invoke((EventHandler)(delegate
  2563. {
  2564. richTextBox_OBC_ReadUserInfo.Clear();
  2565. //默认周长
  2566. richTextBox_OBC_ReadUserInfo.AppendText("默认周长:" + Convert.ToString((int)Data[0]) + " cm" + "\r\n");
  2567. //启动模式
  2568. richTextBox_OBC_ReadUserInfo.AppendText("启动模式:" + ((Data[1] == 0x01) ? "柔和" : (Data[1] == 0x02) ? "正常" : (Data[1] == 0x03) ? "强劲" : "无效") + "\r\n");
  2569. comboBox_OBC_StartMode.SelectedIndex = Data[1] - 1;
  2570. //限速
  2571. richTextBox_OBC_ReadUserInfo.AppendText("限速:" + Convert.ToString(Data[2]) + " km/h" + "\r\n");
  2572. //周长微调
  2573. numericUpDown_OBC_WheelAdj.Value = (int)(Data[3] > 128 ? (Data[3] - 256) : Data[3]);
  2574. richTextBox_OBC_ReadUserInfo.AppendText("周长微调:" + Convert.ToString(numericUpDown_OBC_WheelAdj.Value) + " cm" + "\r\n");
  2575. //助力方案
  2576. richTextBox_OBC_ReadUserInfo.AppendText("助力方案:" + Convert.ToString(Data[4]) + "\r\n");
  2577. comboBox_OBC_AssistFunc.SelectedIndex = Data[4] - 1;
  2578. //关机时间
  2579. richTextBox_OBC_ReadUserInfo.AppendText("关机时间:" + Convert.ToString(Data[5]) + " min" + "\r\n");
  2580. numericUpDown_OBC_OffTime.Value = (int)Data[5];
  2581. //限速微调
  2582. numericUpDown_OBC_SpeedLimitAdj.Value = (int)(Data[6] > 128 ? (Data[6] - 256) : Data[6]);
  2583. richTextBox_OBC_ReadUserInfo.AppendText("限速微调:" + Convert.ToString(numericUpDown_OBC_SpeedLimitAdj.Value) + " km/h" + "\r\n");
  2584. //定速巡航
  2585. comboBox_OBC_BikeCCS.SelectedIndex = (Data[7] == 0xAA) ? 1 : 2;
  2586. richTextBox_OBC_ReadUserInfo.AppendText("转把巡航:" + comboBox_OBC_BikeCCS.Text + "\r\n");
  2587. }));
  2588. }
  2589. break;
  2590. }
  2591. case 0x5303://电机应答反馈
  2592. {
  2593. unchecked
  2594. {
  2595. this.Invoke((EventHandler)(delegate
  2596. {
  2597. MessageBoxTimeOut.Show("OK", "反馈指令", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  2598. }));
  2599. }
  2600. break;
  2601. }
  2602. case 0x5620: //用户骑行参数
  2603. {
  2604. unchecked
  2605. {
  2606. this.Invoke((EventHandler)(delegate
  2607. {
  2608. richTextBox_UsrRidesParam.Clear();
  2609. for (int i = 0; i < myParams.UsrRideParam.Count; i++)
  2610. {
  2611. richTextBox_UsrRidesParam.AppendText(myParams.UsrRideParam[i] + "=" + Convert.ToString(Data[i]) + ", ");
  2612. }
  2613. richTextBox_UsrRidesParam.Text = richTextBox_UsrRidesParam.Text.Substring(0, richTextBox_UsrRidesParam.Text.Length - 2);
  2614. }));
  2615. }
  2616. break;
  2617. }
  2618. default: break;
  2619. }
  2620. }
  2621. #endregion
  2622. }
  2623. private void DataRevToString(ushort CmdTemp, byte[] Data)
  2624. {
  2625. CmdRevStrTemp = "";
  2626. CmdRevStrTemp += Convert.ToString(CmdTemp >> 8, 16).PadLeft(2, '0').ToUpper() + " ";
  2627. CmdRevStrTemp += Convert.ToString(CmdTemp & 0xFF, 16).PadLeft(2, '0').ToUpper() + " ";
  2628. ushort len = (ushort)(CmdTemp & 0x00FF);
  2629. for (int i = 0; i < len ; i++)
  2630. {
  2631. CmdRevStrTemp += Convert.ToString(Data[i], 16).PadLeft(2, '0').ToUpper() + " ";
  2632. }
  2633. }
  2634. #endregion
  2635. /// <summary>
  2636. /// 端口连接或断开
  2637. /// </summary>
  2638. private void PortConnect()
  2639. {
  2640. bool result = false;
  2641. if (连接ToolStripMenuItem.Text == "连接")
  2642. {
  2643. result = mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, 连接开机ToolStripMenuItem.Checked, 识别通讯盒ToolStripMenuItem.Checked);
  2644. if (result)
  2645. {
  2646. toolStripComboBox_ComNum.Enabled = false;
  2647. toolStripComboBox_Baudrate.Enabled = false;
  2648. 刷新ToolStripMenuItem.Enabled = false;
  2649. 连接ToolStripMenuItem.Text = "断开";
  2650. 连接ToolStripMenuItem.Checked = true;
  2651. label_COM_Sta.Text = toolStripComboBox_ComNum.Text + "已连接," + toolStripComboBox_Baudrate.Text;
  2652. label_PortStatus.BackColor = Color.Green;
  2653. }
  2654. }
  2655. else if (连接ToolStripMenuItem.Text == "断开")
  2656. {
  2657. checkBox_OBC_StartSetGearSt.Checked = false;
  2658. checkBox_OBC_StartReadBMS.Checked = false;
  2659. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2660. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  2661. toolStripComboBox_ComNum.Enabled = true;
  2662. toolStripComboBox_Baudrate.Enabled = true;
  2663. 刷新ToolStripMenuItem.Enabled = true;
  2664. 连接ToolStripMenuItem.Text = "连接";
  2665. 连接ToolStripMenuItem.Checked = false;
  2666. label_COM_Sta.Text = "连接状态:未连接";
  2667. label_PortStatus.BackColor = Color.Red;
  2668. }
  2669. }
  2670. /// <summary>
  2671. /// 端口连接事件
  2672. /// </summary>
  2673. /// <param name="sender"></param>
  2674. /// <param name="e"></param>
  2675. private void 连接ToolStripMenuItem_Click(object sender, System.EventArgs e)
  2676. {
  2677. PortConnect();
  2678. }
  2679. /// <summary>
  2680. /// 端口号刷新事件
  2681. /// </summary>
  2682. /// <param name="sender"></param>
  2683. /// <param name="e"></param>
  2684. private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
  2685. {
  2686. toolStripComboBox_ComNum.Items.Clear();
  2687. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  2688. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
  2689. }
  2690. /// <summary>
  2691. /// 存储标志修改事件
  2692. /// </summary>
  2693. /// <param name="sender"></param>
  2694. /// <param name="e"></param>
  2695. private void 写入存储ToolStripMenuItem_Click(object sender, EventArgs e)
  2696. {
  2697. if (写入存储ToolStripMenuItem.Checked)
  2698. {
  2699. EnterForm1.ShowDialog();
  2700. try
  2701. {
  2702. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  2703. {
  2704. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  2705. {
  2706. 写入存储ToolStripMenuItem.Checked = false;
  2707. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  2708. }
  2709. else
  2710. {
  2711. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2712. }
  2713. }
  2714. else
  2715. {
  2716. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2717. }
  2718. }
  2719. catch (Exception)
  2720. {
  2721. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2722. }
  2723. }
  2724. else
  2725. {
  2726. 写入存储ToolStripMenuItem.Checked = true;
  2727. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  2728. }
  2729. }
  2730. /// <summary>
  2731. /// 1s定时器
  2732. /// </summary>
  2733. /// <param name="sender"></param>
  2734. /// <param name="e"></param>
  2735. private void timer_1s_Tick(object sender, EventArgs e)
  2736. {
  2737. //时间更新
  2738. label_SystemTime.Text = "系统时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2739. //MC_Runinfo超时清除
  2740. if (MC_RunInfo_Refresh == false)
  2741. {
  2742. MC_RunInfo_Refresh_Cnt++;
  2743. if (MC_RunInfo_Refresh_Cnt > 10)//5s
  2744. {
  2745. MC_RunInfo_Clear();
  2746. MC_RunInfo_Refresh_Cnt = 0;
  2747. }
  2748. }
  2749. else
  2750. {
  2751. MC_RunInfo_Refresh_Cnt = 0;
  2752. }
  2753. MC_RunInfo_Refresh = false;
  2754. //MC_Debuginfo超时清除
  2755. if (MC_DebugInfo_Refresh == false)
  2756. {
  2757. MC_DebugInfo_Refresh_Cnt++;
  2758. if (MC_DebugInfo_Refresh_Cnt > 10)//5s
  2759. {
  2760. MC_DebugInfo_Clear();
  2761. MC_DebugInfo_Refresh_Cnt = 0;
  2762. }
  2763. }
  2764. else
  2765. {
  2766. MC_DebugInfo_Refresh_Cnt = 0;
  2767. }
  2768. MC_DebugInfo_Refresh = false;
  2769. //BMS_RunInfo超时清除
  2770. if (BMS_RunInfo_Refresh == false)
  2771. {
  2772. BMS_RunInfo_Refresh_Cnt++;
  2773. if (BMS_RunInfo_Refresh_Cnt > 10)//5s
  2774. {
  2775. richTextBox_OBC_BMS_RunInfo.Clear();
  2776. BMS_RunInfo_Refresh_Cnt = 0;
  2777. }
  2778. }
  2779. else
  2780. {
  2781. BMS_RunInfo_Refresh_Cnt = 0;
  2782. }
  2783. BMS_RunInfo_Refresh = false;
  2784. //故障码超时清除
  2785. if (MC_ErrorCode_Refresh == false)
  2786. {
  2787. MC_ErrorCode_Refresh_Cnt++;
  2788. if (MC_ErrorCode_Refresh_Cnt > 10)//5s
  2789. {
  2790. textBox_ErrorCode.Text = "---";
  2791. MC_ErrorCode_Refresh_Cnt = 0;
  2792. }
  2793. }
  2794. else
  2795. {
  2796. MC_ErrorCode_Refresh_Cnt = 0;
  2797. }
  2798. MC_ErrorCode_Refresh = false;
  2799. //CDL连接超时
  2800. if (识别通讯盒ToolStripMenuItem.Checked)
  2801. {
  2802. if (mySerialProcess.CDL_Online_Flag == false)
  2803. {
  2804. mySerialProcess.CDL_OnlineCheck_Cnt++;
  2805. if (mySerialProcess.CDL_OnlineCheck_Cnt > 1)//1s
  2806. {
  2807. timer_500ms.Enabled = false;
  2808. MessageBox.Show("连接失败!", "提示");
  2809. timer_500ms.Enabled = true;
  2810. //关闭串口
  2811. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  2812. toolStripComboBox_ComNum.Enabled = true;
  2813. toolStripComboBox_Baudrate.Enabled = true;
  2814. 刷新ToolStripMenuItem.Enabled = true;
  2815. 连接ToolStripMenuItem.Text = "连接";
  2816. 连接ToolStripMenuItem.Checked = false;
  2817. label_COM_Sta.Text = "连接状态:未连接";
  2818. label_PortStatus.BackColor = Color.Red;
  2819. }
  2820. }
  2821. }
  2822. //OBC定时发送设置档位
  2823. if (checkBox_OBC_StartSetGearSt.Checked == true)
  2824. {
  2825. var CtrlCode = new byte[2];
  2826. if (comboBox_OBC_SetGearST.SelectedIndex == 5)//档位
  2827. CtrlCode[0] = 0x33;
  2828. else if (comboBox_OBC_SetGearST.SelectedIndex == 6)//档位
  2829. CtrlCode[0] = 0x22;
  2830. else
  2831. CtrlCode[0] = (byte)comboBox_OBC_SetGearST.SelectedIndex;
  2832. if (comboBox_OBC_LightSw.SelectedIndex == 0)//车灯
  2833. CtrlCode[1] = 0xF1;
  2834. else
  2835. CtrlCode[1] = 0xF0;
  2836. if (!mySerialProcess.SendCmdWithoutNotice((ushort)0x731, (byte)0x0C, (ushort)0x3002, CtrlCode))
  2837. {
  2838. checkBox_OBC_StartSetGearSt.Checked = false;
  2839. }
  2840. }
  2841. //OBC定时发送查询电池
  2842. if (checkBox_OBC_StartReadBMS.Checked == true)
  2843. {
  2844. if (!mySerialProcess.SendCmd((ushort)0x732, (byte)0x11, (ushort)0x5000, null))
  2845. {
  2846. checkBox_OBC_StartReadBMS.Checked = false;
  2847. }
  2848. }
  2849. //定时读取存储器
  2850. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  2851. {
  2852. var Address = new byte[4];
  2853. UInt32 Address_Begin;
  2854. UInt32 Addres_End;
  2855. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  2856. richTextBox_RamFlasgData.Clear();
  2857. do
  2858. {
  2859. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  2860. {
  2861. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2862. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2863. continue;
  2864. }
  2865. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  2866. {
  2867. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2868. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2869. continue;
  2870. }
  2871. else
  2872. {
  2873. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  2874. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2875. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  2876. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2877. if (Addres_End < Address_Begin)
  2878. {
  2879. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2880. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2881. continue;
  2882. }
  2883. else
  2884. {
  2885. var SendByte = new byte[8];
  2886. SendByte[0] = (byte)(Address_Begin >> 24);
  2887. SendByte[1] = (byte)(Address_Begin >> 16);
  2888. SendByte[2] = (byte)(Address_Begin >> 8);
  2889. SendByte[3] = (byte)(Address_Begin);
  2890. SendByte[4] = (byte)(Addres_End >> 24);
  2891. SendByte[5] = (byte)(Addres_End >> 16);
  2892. SendByte[6] = (byte)(Addres_End >> 8);
  2893. SendByte[7] = (byte)(Addres_End);
  2894. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte))
  2895. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2896. }
  2897. }
  2898. } while (false);
  2899. }
  2900. }
  2901. /// <summary>
  2902. /// 运行信息清除
  2903. /// </summary>
  2904. private void MC_RunInfo_Clear()
  2905. {
  2906. foreach (Control c in tabPage_RunInfo.Controls)
  2907. {
  2908. if ((c is TextBox))
  2909. {
  2910. if (c.Name != textBox_ErrorCode.ToString())
  2911. c.Text = "---";
  2912. }
  2913. }
  2914. }
  2915. /// <summary>
  2916. /// 调试信息清除
  2917. /// </summary>
  2918. private void MC_DebugInfo_Clear()
  2919. {
  2920. foreach (Control c in tabPage_DebugInfo.Controls)
  2921. {
  2922. if ((c is TextBox))
  2923. {
  2924. if (c.Name != textBox_ErrorCode.ToString())
  2925. c.Text = "---";
  2926. }
  2927. }
  2928. }
  2929. /// <summary>
  2930. /// 读取马达参数
  2931. /// </summary>
  2932. /// <param name="sender"></param>
  2933. /// <param name="e"></param>
  2934. private void button_Read_MotorParam_Click(object sender, EventArgs e)
  2935. {
  2936. richTextBox_MotorParam.Clear();
  2937. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null);
  2938. }
  2939. /// <summary>
  2940. /// 写入马达参数
  2941. /// </summary>
  2942. /// <param name="sender"></param>
  2943. /// <param name="e"></param>
  2944. private void button_Write_Click(object sender, EventArgs e)
  2945. {
  2946. var ConfigParam = new byte[40];
  2947. for (int i = 0; i < 40; i++)
  2948. ConfigParam[i] = 0;
  2949. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2950. short wDataTemp = 0;
  2951. ushort DataTemp = 0;
  2952. string[] strDataTemp = richTextBox_MotorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2953. try
  2954. {
  2955. for (int i = 0; i < strDataTemp.Length; i++)
  2956. {
  2957. if (i == 6)
  2958. {
  2959. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  2960. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  2961. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  2962. }
  2963. else
  2964. {
  2965. DataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2966. ConfigParam[2 * i + 2] = (byte)DataTemp;
  2967. ConfigParam[2 * i + 3] = (byte)(DataTemp >> 8);
  2968. }
  2969. }
  2970. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B28, ConfigParam);
  2971. }
  2972. catch (Exception)
  2973. {
  2974. timer_500ms.Enabled = false;
  2975. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2976. timer_500ms.Enabled = true;
  2977. }
  2978. }
  2979. /// <summary>
  2980. /// 读取整车信息
  2981. /// </summary>
  2982. /// <param name="sender"></param>
  2983. /// <param name="e"></param>
  2984. private void button_ReadBikeParam_Click(object sender, EventArgs e)
  2985. {
  2986. richTextBox_BikeParam.Clear();
  2987. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null);
  2988. }
  2989. /// <summary>
  2990. /// 写入整车信息
  2991. /// </summary>
  2992. /// <param name="sender"></param>
  2993. /// <param name="e"></param>
  2994. private void button_WriteBikeParam_Click(object sender, EventArgs e)
  2995. {
  2996. var ConfigParam = new byte[28];
  2997. for (int i = 0; i < 28; i++)
  2998. ConfigParam[i] = 0;
  2999. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  3000. string[] strDataTemp = richTextBox_BikeParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  3001. try
  3002. {
  3003. for (int i = 0; i < strDataTemp.Length; i++)
  3004. {
  3005. short wDataTemp = 0;
  3006. //前后灯参数修改
  3007. if (i == 8)
  3008. {
  3009. wDataTemp |= (short)((comboBox_TailLightMode.SelectedIndex + 1) << 12); //Bit15~Bit12:尾灯模式
  3010. wDataTemp |= (short)((comboBox_TailLightVol.SelectedIndex == 0 ? 6 : 12) << 8); //Bit11~Bit8:尾灯电压
  3011. wDataTemp |= (short)(comboBox_FrontLightVol.SelectedIndex == 0 ? 6 : 12); //Bit7~Bit0:前灯电压
  3012. }
  3013. //开关机参数
  3014. else if (i == 11)
  3015. {
  3016. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOnDelay.Text) << 12);
  3017. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOffDelay.Text) << 8);
  3018. wDataTemp |= (short)(Convert.ToInt16(textBox_AutoPowerOff.Text));
  3019. }
  3020. else
  3021. {
  3022. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  3023. }
  3024. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  3025. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  3026. }
  3027. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D1C, ConfigParam);
  3028. }
  3029. catch (Exception)
  3030. {
  3031. timer_500ms.Enabled = false;
  3032. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3033. timer_500ms.Enabled = true;
  3034. }
  3035. }
  3036. /// <summary>
  3037. /// 读取控制器参数
  3038. /// </summary>
  3039. /// <param name="sender"></param>
  3040. /// <param name="e"></param>
  3041. private void button_ReadControlParam_Click(object sender, EventArgs e)
  3042. {
  3043. richTextBox_ControlParam.Clear();
  3044. comboBox_Bike_CCS.SelectedIndex = 0;
  3045. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
  3046. }
  3047. /// <summary>
  3048. /// 写入控制器参数
  3049. /// </summary>
  3050. /// <param name="sender"></param>
  3051. /// <param name="e"></param>
  3052. private void button_WriteControlParam_Click(object sender, EventArgs e)
  3053. {
  3054. var ConfigParam = new byte[34];
  3055. for (int i = 0; i < 34; i++)
  3056. ConfigParam[i] = 0;
  3057. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  3058. ushort uwDataTemp = 0;
  3059. string[] strDataTemp = richTextBox_ControlParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  3060. try
  3061. {
  3062. for (int i = 0; i < strDataTemp.Length; i++)
  3063. {
  3064. if (i == 13)
  3065. {
  3066. uwDataTemp = (comboBox_Bike_CCS.SelectedIndex == 1) ? (ushort)0x00AA : (ushort)0x0000;
  3067. }
  3068. else
  3069. {
  3070. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  3071. }
  3072. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3073. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3074. }
  3075. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3F22, ConfigParam);
  3076. }
  3077. catch (Exception)
  3078. {
  3079. timer_500ms.Enabled = false;
  3080. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3081. timer_500ms.Enabled = true;
  3082. }
  3083. }
  3084. /// <summary>
  3085. /// 读取助力参数
  3086. /// </summary>
  3087. /// <param name="sender"></param>
  3088. /// <param name="e"></param>
  3089. private void button_ReadAssistParam_Click(object sender, EventArgs e)
  3090. {
  3091. var ConfigParam = new byte[4];
  3092. int AssistNum = 0;
  3093. try
  3094. {
  3095. AssistNum = Convert.ToInt32(comboBox_AssistTorque.Text);
  3096. ConfigParam[0] = (byte)(AssistNum & 0xFF);
  3097. ConfigParam[1] = (byte)(AssistNum >> 8);
  3098. AssistNum = Convert.ToInt32(comboBox_AssistCadence.Text);
  3099. ConfigParam[2] = (byte)(AssistNum & 0xFF);
  3100. ConfigParam[3] = (byte)(AssistNum >> 8);
  3101. richTextBox_AssistParam.Clear();
  3102. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam);
  3103. }
  3104. catch (Exception)
  3105. {
  3106. timer_500ms.Enabled = false;
  3107. MessageBox.Show("请选择助力参数编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3108. timer_500ms.Enabled = true;
  3109. }
  3110. }
  3111. /// <summary>
  3112. /// 写入助力参数
  3113. /// </summary>
  3114. /// <param name="sender"></param>
  3115. /// <param name="e"></param>
  3116. private void button_WriteAssistParam_Click(object sender, EventArgs e)
  3117. {
  3118. var ConfigParam = new byte[80];
  3119. for (int i = 0; i < 80; i++)
  3120. ConfigParam[i] = 0;
  3121. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  3122. long lDataTemp = 0;
  3123. string[] strDataTemp = richTextBox_AssistParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  3124. int index_1 = 0, index_2 = 0;
  3125. try
  3126. {
  3127. for (int i = 0; i < strDataTemp.Length; i++)
  3128. {
  3129. if (strDataTemp[i].Split('=')[0] == "转矩曲线.a")
  3130. {
  3131. index_1 = i;
  3132. break;
  3133. }
  3134. }
  3135. for (int i = 0; i < strDataTemp.Length; i++)
  3136. {
  3137. if (strDataTemp[i].Split('=')[0] == "踏频曲线.d")
  3138. {
  3139. index_2 = i;
  3140. break;
  3141. }
  3142. }
  3143. for (int i = 0; i < strDataTemp.Length; i++)
  3144. {
  3145. lDataTemp = Convert.ToInt32(strDataTemp[i].Split('=')[1]);
  3146. if (i < index_1)
  3147. {
  3148. ConfigParam[2 * i + 4] = (byte)lDataTemp;
  3149. ConfigParam[2 * i + 5] = (byte)(lDataTemp >> 8);
  3150. }
  3151. else if (i <= index_2)
  3152. {
  3153. ConfigParam[4 * i - 4] = (byte)lDataTemp;
  3154. ConfigParam[4 * i - 3] = (byte)(lDataTemp >> 8);
  3155. ConfigParam[4 * i - 2] = (byte)(lDataTemp >> 16);
  3156. ConfigParam[4 * i - 1] = (byte)(lDataTemp >> 24);
  3157. }
  3158. else
  3159. {
  3160. ConfigParam[2 * i + 20] = (byte)lDataTemp;
  3161. ConfigParam[2 * i + 21] = (byte)(lDataTemp >> 8);
  3162. }
  3163. }
  3164. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4450, ConfigParam);
  3165. }
  3166. catch (Exception)
  3167. {
  3168. timer_500ms.Enabled = false;
  3169. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3170. timer_500ms.Enabled = true;
  3171. }
  3172. }
  3173. /// <summary>
  3174. /// 读取调试参数
  3175. /// </summary>
  3176. /// <param name="sender"></param>
  3177. /// <param name="e"></param>
  3178. private void button_ReadDebugParam_Click(object sender, EventArgs e)
  3179. {
  3180. richTextBox_DebugParam.Clear();
  3181. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  3182. }
  3183. /// <summary>
  3184. /// 写入调试参数
  3185. /// </summary>
  3186. /// <param name="sender"></param>
  3187. /// <param name="e"></param>
  3188. private void button_WriteDebugParam_Click(object sender, EventArgs e)
  3189. {
  3190. var ConfigParam = new byte[60];
  3191. for (int i = 0; i < 60; i++)
  3192. ConfigParam[i] = 0;
  3193. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  3194. ushort uwDataTemp = 0;
  3195. string[] strDataTemp = richTextBox_DebugParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  3196. try
  3197. {
  3198. for (int i = 0; i < strDataTemp.Length; i++)
  3199. {
  3200. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  3201. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3202. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3203. }
  3204. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam);
  3205. }
  3206. catch (Exception)
  3207. {
  3208. timer_500ms.Enabled = false;
  3209. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3210. timer_500ms.Enabled = true;
  3211. }
  3212. }
  3213. /// <summary>
  3214. /// 读取历史
  3215. /// </summary>
  3216. /// <param name="sender"></param>
  3217. /// <param name="e"></param>
  3218. private void button_ReadRecord_Click(object sender, EventArgs e)
  3219. {
  3220. richTextBox_Record.Clear();
  3221. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null);
  3222. }
  3223. /// <summary>
  3224. /// 读取传感器参数
  3225. /// </summary>
  3226. /// <param name="sender"></param>
  3227. /// <param name="e"></param>
  3228. private void button_ReadSensorParam_Click(object sender, EventArgs e)
  3229. {
  3230. richTextBox_SensorParam.Clear();
  3231. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3232. }
  3233. /// <summary>
  3234. /// 写入力矩传感器标定值
  3235. /// </summary>
  3236. /// <param name="sender"></param>
  3237. /// <param name="e"></param>
  3238. private void button_Write_Cal_Click(object sender, EventArgs e)
  3239. {
  3240. var ConfigParam = new byte[4];
  3241. for (int i = 0; i < 4; i++)
  3242. ConfigParam[i] = 0;
  3243. ushort uwDataTemp = 0;
  3244. try
  3245. {
  3246. uwDataTemp = Convert.ToUInt16(comboBox_TorqueSet.Text);//负载序号
  3247. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  3248. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  3249. uwDataTemp = (ushort)(decimal.Parse(textBox_Load.Text) * 10); ;//负载值0.1Nm
  3250. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  3251. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  3252. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  3253. }
  3254. catch (Exception)
  3255. {
  3256. timer_500ms.Enabled = false;
  3257. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3258. timer_500ms.Enabled = true;
  3259. }
  3260. }
  3261. /// <summary>
  3262. /// 写入传感器参数
  3263. /// </summary>
  3264. /// <param name="sender"></param>
  3265. /// <param name="e"></param>
  3266. private void button_WriteSensorParam_Click(object sender, EventArgs e)
  3267. {
  3268. var ConfigParam = new byte[14];
  3269. for (int i = 0; i < 14; i++)
  3270. ConfigParam[i] = 0;
  3271. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  3272. ushort uwDataTemp = 0;
  3273. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  3274. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  3275. int index = 0;
  3276. try
  3277. {
  3278. for (int i = 0; i < strDataTemp.Length; i++)
  3279. {
  3280. if (strDataTemp[i].Split('=')[0] == "力矩传感器踏频脉冲数")
  3281. {
  3282. index = i;
  3283. break;
  3284. }
  3285. }
  3286. for (int i = 0; i < (strDataTemp.Length - index); i++)
  3287. {
  3288. uwDataTemp = Convert.ToUInt16(strDataTemp[i + index].Split('=')[1]);
  3289. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3290. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3291. }
  3292. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x420E, ConfigParam);
  3293. }
  3294. catch (Exception)
  3295. {
  3296. timer_500ms.Enabled = false;
  3297. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3298. timer_500ms.Enabled = true;
  3299. }
  3300. }
  3301. /// <summary>
  3302. /// 写入型号
  3303. /// </summary>
  3304. /// <param name="sender"></param>
  3305. /// <param name="e"></param>
  3306. private void button_WriteModel_Click(object sender, EventArgs e)
  3307. {
  3308. string Mode = textBox_Model.Text;
  3309. var ModeArray = new byte[16];
  3310. for (ushort i = 0; i < Mode.Length; i++)
  3311. {
  3312. ModeArray[i] = (byte)Mode[i];
  3313. }
  3314. if (Mode.Length < 16)
  3315. {
  3316. ModeArray[Mode.Length] = (byte)'.';
  3317. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  3318. {
  3319. ModeArray[Mode.Length + 1 + i] = 0x20;
  3320. }
  3321. }
  3322. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  3323. }
  3324. /// <summary>
  3325. /// 写入SN
  3326. /// </summary>
  3327. /// <param name="sender"></param>
  3328. /// <param name="e"></param>
  3329. private void button_WriteSN_Click(object sender, EventArgs e)
  3330. {
  3331. string SN = textBox_SN.Text;
  3332. var SNArray = new byte[16];
  3333. for (ushort i = 0; i < SN.Length; i++)
  3334. {
  3335. SNArray[i] = (byte)SN[i];
  3336. }
  3337. if (SN.Length < 16)
  3338. {
  3339. SNArray[SN.Length] = (byte)'.';
  3340. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  3341. {
  3342. SNArray[SN.Length + 1 + i] = 0x20;
  3343. }
  3344. }
  3345. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  3346. }
  3347. /// <summary>
  3348. /// 查询版本信息
  3349. /// </summary>
  3350. /// <param name="sender"></param>
  3351. /// <param name="e"></param>
  3352. private void button_ReadVersion_Click(object sender, EventArgs e)
  3353. {
  3354. textBox_Model.Text = "---";
  3355. textBox_SN.Text = "---";
  3356. textBox_HW.Text = "---";
  3357. textBox_FW.Text = "---";
  3358. textBox_SP.Text = "---";
  3359. textBox_OBC_ReadModel.Text = "---";
  3360. textBox_OBC_ReadSN.Text = "---";
  3361. textBox_OBC_ReadHW.Text = "---";
  3362. textBox_OBC_ReadFW.Text = "---";
  3363. textBox_OBC_ReadSP.Text = "---";
  3364. textBox_FacModeName.Text = "---";
  3365. textBox_FacModeNum.Text = "---";
  3366. textBox_FacModeHW.Text = "---";
  3367. textBox_FacModeFW.Text = "---";
  3368. textBox_FacModeSP.Text = "---";
  3369. Class_Motor_Ver.Mode = "---";
  3370. Class_Motor_Ver.SN = "---";
  3371. Class_Motor_Ver.HW = "---";
  3372. Class_Motor_Ver.FW = "---";
  3373. Class_Motor_Ver.Special = "---";
  3374. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  3375. }
  3376. /// <summary>
  3377. /// 查询自定义1
  3378. /// </summary>
  3379. /// <param name="sender"></param>
  3380. /// <param name="e"></param>
  3381. private void button_ReadUser1_Click(object sender, EventArgs e)
  3382. {
  3383. textBox_User1.Text = "---";
  3384. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null);
  3385. }
  3386. /// <summary>
  3387. /// 查询自定义2
  3388. /// </summary>
  3389. /// <param name="sender"></param>
  3390. /// <param name="e"></param>
  3391. private void button_ReadUser2_Click(object sender, EventArgs e)
  3392. {
  3393. textBox_User2.Text = "---";
  3394. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null);
  3395. }
  3396. /// <summary>
  3397. /// 查询自定义3
  3398. /// </summary>
  3399. /// <param name="sender"></param>
  3400. /// <param name="e"></param>
  3401. private void button_ReadUser3_Click(object sender, EventArgs e)
  3402. {
  3403. textBox_User3.Text = "---";
  3404. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null);
  3405. }
  3406. /// <summary>
  3407. /// 写入自定义字符串1
  3408. /// </summary>
  3409. /// <param name="sender"></param>
  3410. /// <param name="e"></param>
  3411. private void button_WriteUser1_Click(object sender, EventArgs e)
  3412. {
  3413. string User = textBox_User1.Text;
  3414. var UserArray = new byte[16];
  3415. for (ushort i = 0; i < User.Length; i++)
  3416. {
  3417. UserArray[i] = (byte)User[i];
  3418. }
  3419. if (User.Length < 16)
  3420. {
  3421. UserArray[User.Length] = (byte)'.';
  3422. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3423. {
  3424. UserArray[User.Length + 1 + i] = 0x20;
  3425. }
  3426. }
  3427. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1410, UserArray);
  3428. }
  3429. /// <summary>
  3430. /// 写入自定义字符串2
  3431. /// </summary>
  3432. /// <param name="sender"></param>
  3433. /// <param name="e"></param>
  3434. private void button_WriteUser2_Click(object sender, EventArgs e)
  3435. {
  3436. string User = textBox_User2.Text;
  3437. var UserArray = new byte[16];
  3438. for (ushort i = 0; i < User.Length; i++)
  3439. {
  3440. UserArray[i] = (byte)User[i];
  3441. }
  3442. if (User.Length < 16)
  3443. {
  3444. UserArray[User.Length] = (byte)'.';
  3445. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3446. {
  3447. UserArray[User.Length + 1 + i] = 0x20;
  3448. }
  3449. }
  3450. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1610, UserArray);
  3451. }
  3452. /// <summary>
  3453. /// 写入自定义字符串3
  3454. /// </summary>
  3455. /// <param name="sender"></param>
  3456. /// <param name="e"></param>
  3457. private void button_WriteUser3_Click(object sender, EventArgs e)
  3458. {
  3459. string User = textBox_User3.Text;
  3460. var UserArray = new byte[16];
  3461. for (ushort i = 0; i < User.Length; i++)
  3462. {
  3463. UserArray[i] = (byte)User[i];
  3464. }
  3465. if (User.Length < 16)
  3466. {
  3467. UserArray[User.Length] = (byte)'.';
  3468. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3469. {
  3470. UserArray[User.Length + 1 + i] = 0x20;
  3471. }
  3472. }
  3473. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1810, UserArray);
  3474. }
  3475. /// <summary>
  3476. /// 查询生产信息
  3477. /// </summary>
  3478. /// <param name="sender"></param>
  3479. /// <param name="e"></param>
  3480. private void button_ReadMAC_Click(object sender, EventArgs e)
  3481. {
  3482. textBox_MAC.Text = "---";
  3483. textBox_MACAdd.Text = "---";
  3484. textBox_MACDate.Text = "---";
  3485. textBox_PP.Text = "---";
  3486. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null);
  3487. }
  3488. /// <summary>
  3489. /// 写入生产信息
  3490. /// </summary>
  3491. /// <param name="sender"></param>
  3492. /// <param name="e"></param>
  3493. private void button_WriteMac_Click(object sender, EventArgs e)
  3494. {
  3495. var MACArray = new byte[32];
  3496. //填入生产商
  3497. for (ushort i = 0; i < textBox_MAC.Text.Length; i++)
  3498. {
  3499. MACArray[i] = (byte)textBox_MAC.Text[i];
  3500. }
  3501. if (textBox_MAC.Text.Length < 8)
  3502. {
  3503. MACArray[textBox_MAC.Text.Length] = (byte)'.';
  3504. for (ushort i = 0; i < 8 - textBox_MAC.Text.Length - 1; i++)
  3505. {
  3506. MACArray[textBox_MAC.Text.Length + 1 + i] = 0x20;
  3507. }
  3508. }
  3509. //填入生产地
  3510. for (ushort i = 0; i < textBox_MACAdd.Text.Length; i++)
  3511. {
  3512. MACArray[8 + i] = (byte)textBox_MACAdd.Text[i];
  3513. }
  3514. if (textBox_MACAdd.Text.Length < 8)
  3515. {
  3516. MACArray[textBox_MACAdd.Text.Length + 8] = (byte)'.';
  3517. for (ushort i = 0; i < 8 - textBox_MACAdd.Text.Length - 1; i++)
  3518. {
  3519. MACArray[textBox_MACAdd.Text.Length + 1 + i + 8] = 0x20;
  3520. }
  3521. }
  3522. //填入生产日期
  3523. for (ushort i = 0; i < textBox_MACDate.Text.Length; i++)
  3524. {
  3525. MACArray[16 + i] = (byte)textBox_MACDate.Text[i];
  3526. }
  3527. if (textBox_MACDate.Text.Length < 8)
  3528. {
  3529. MACArray[textBox_MACDate.Text.Length + 16] = (byte)'.';
  3530. for (ushort i = 0; i < 8 - textBox_MACDate.Text.Length - 1; i++)
  3531. {
  3532. MACArray[textBox_MACDate.Text.Length + 1 + i + 16] = 0x20;
  3533. }
  3534. }
  3535. //填入品牌
  3536. for (ushort i = 0; i < textBox_PP.Text.Length; i++)
  3537. {
  3538. MACArray[24 + i] = (byte)textBox_PP.Text[i];
  3539. }
  3540. if (textBox_PP.Text.Length < 8)
  3541. {
  3542. MACArray[textBox_PP.Text.Length + 24] = (byte)'.';
  3543. for (ushort i = 0; i < 8 - textBox_PP.Text.Length - 1; i++)
  3544. {
  3545. MACArray[textBox_PP.Text.Length + 1 + i + 24] = 0x20;
  3546. }
  3547. }
  3548. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  3549. }
  3550. /// <summary>
  3551. /// 查询密钥
  3552. /// </summary>
  3553. /// <param name="sender"></param>
  3554. /// <param name="e"></param>
  3555. private void button_ReadKey_Click(object sender, EventArgs e)
  3556. {
  3557. textBox_Key.Text = "---";
  3558. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null);
  3559. }
  3560. /// <summary>
  3561. /// 写入校验密钥
  3562. /// </summary>
  3563. /// <param name="sender"></param>
  3564. /// <param name="e"></param>
  3565. private void button_WriteKey_Click(object sender, EventArgs e)
  3566. {
  3567. string Key = textBox_Key.Text;
  3568. var KeyArray = new byte[8];
  3569. if (Key.Length != 8)
  3570. {
  3571. timer_500ms.Enabled = false;
  3572. MessageBox.Show("请检查字符长度是否为8", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3573. timer_500ms.Enabled = true;
  3574. return;
  3575. }
  3576. for (ushort i = 0; i < Key.Length; i++)
  3577. {
  3578. KeyArray[i] = (byte)Key[i];
  3579. }
  3580. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1108, KeyArray);
  3581. }
  3582. /// <summary>
  3583. /// 查询在线检测结果
  3584. /// </summary>
  3585. /// <param name="sender"></param>
  3586. /// <param name="e"></param>
  3587. private void button_ReadOnLine_Click(object sender, EventArgs e)
  3588. {
  3589. textBox_Online.Text = "---";
  3590. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2100, null);
  3591. }
  3592. /// <summary>
  3593. /// 系统清除
  3594. /// </summary>
  3595. /// <param name="sender"></param>
  3596. /// <param name="e"></param>
  3597. private void button_SystemClear_Click(object sender, EventArgs e)
  3598. {
  3599. var Code = new byte[5];
  3600. Code[0] = (byte)'C';
  3601. Code[1] = (byte)'L';
  3602. Code[2] = (byte)'E';
  3603. Code[3] = (byte)'A';
  3604. Code[4] = (byte)'R';
  3605. timer_500ms.Enabled = false;
  3606. if (MessageBox.Show("系统清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3607. {
  3608. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3609. {
  3610. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3611. {
  3612. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  3613. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3614. }
  3615. }
  3616. }
  3617. timer_500ms.Enabled = true;
  3618. }
  3619. /// <summary>
  3620. /// 参数还原
  3621. /// </summary>
  3622. /// <param name="sender"></param>
  3623. /// <param name="e"></param>
  3624. private void button_Recovery_Click(object sender, EventArgs e)
  3625. {
  3626. var Code = new byte[8];
  3627. Code[0] = (byte)'R';
  3628. Code[1] = (byte)'E';
  3629. Code[2] = (byte)'C';
  3630. Code[3] = (byte)'O';
  3631. Code[4] = (byte)'V';
  3632. Code[5] = (byte)'E';
  3633. Code[6] = (byte)'R';
  3634. Code[7] = (byte)'Y';
  3635. timer_500ms.Enabled = false;
  3636. if (MessageBox.Show("参数还原后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3637. {
  3638. if (MessageBox.Show("请再次确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3639. {
  3640. if (MessageBox.Show("请最后确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3641. {
  3642. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2708, Code);
  3643. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3644. }
  3645. }
  3646. }
  3647. timer_500ms.Enabled = true;
  3648. }
  3649. /// <summary>
  3650. /// 系统复位
  3651. /// </summary>
  3652. /// <param name="sender"></param>
  3653. /// <param name="e"></param>
  3654. private void button_Reset_Click(object sender, EventArgs e)
  3655. {
  3656. var Code_Off = new byte[5];
  3657. var Code_Reset = new byte[5];
  3658. Code_Off[0] = (byte)'O';
  3659. Code_Off[1] = (byte)'F';
  3660. Code_Off[2] = (byte)'F';
  3661. Code_Off[3] = (byte)'.';
  3662. Code_Off[4] = (byte)'.';
  3663. Code_Reset[0] = (byte)'R';
  3664. Code_Reset[1] = (byte)'E';
  3665. Code_Reset[2] = (byte)'S';
  3666. Code_Reset[3] = (byte)'E';
  3667. Code_Reset[4] = (byte)'T';
  3668. timer_500ms.Enabled = false;
  3669. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3670. {
  3671. timer_500ms.Enabled = true;
  3672. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  3673. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  3674. PowerOffAckStatus = false;
  3675. Delay_ms(250);
  3676. int TryCnt = 3;
  3677. while ((TryCnt--) >= 0)
  3678. {
  3679. if (!PowerOffAckStatus)
  3680. {
  3681. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  3682. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  3683. PowerOffAckStatus = false;
  3684. Delay_ms(250);
  3685. }
  3686. else break;
  3687. }
  3688. if (PowerOffAckStatus)
  3689. {
  3690. MessageBoxTimeOut.Show("已关机!", "提示", 3000, MessageBoxButtons.OK, MessageBoxIcon.None);
  3691. }
  3692. else
  3693. {
  3694. timer_500ms.Enabled = false;
  3695. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3696. timer_500ms.Enabled = true;
  3697. }
  3698. }
  3699. timer_500ms.Enabled = true;
  3700. }
  3701. /// <summary>
  3702. /// 记录清除
  3703. /// </summary>
  3704. /// <param name="sender"></param>
  3705. /// <param name="e"></param>
  3706. private void button_ClearLog_Click(object sender, EventArgs e)
  3707. {
  3708. var Code = new byte[9];
  3709. Code[0] = (byte)'L';
  3710. Code[1] = (byte)'O';
  3711. Code[2] = (byte)'G';
  3712. Code[3] = (byte)' ';
  3713. Code[4] = (byte)'C';
  3714. Code[5] = (byte)'L';
  3715. Code[6] = (byte)'E';
  3716. Code[7] = (byte)'A';
  3717. Code[8] = (byte)'R';
  3718. timer_500ms.Enabled = false;
  3719. if (MessageBox.Show("历史记录信息清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3720. {
  3721. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3722. {
  3723. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3724. {
  3725. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3909, Code);
  3726. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3727. }
  3728. }
  3729. }
  3730. timer_500ms.Enabled = true;
  3731. }
  3732. /// <summary>
  3733. /// 打开系统计算器
  3734. /// </summary>
  3735. /// <param name="sender"></param>
  3736. /// <param name="e"></param>
  3737. private void 计算器ToolStripMenuItem_Click(object sender, EventArgs e)
  3738. {
  3739. System.Diagnostics.Process.Start("calc.exe");
  3740. }
  3741. /// <summary>
  3742. ///故障转换和显示
  3743. /// </summary>
  3744. List<string> ErrorInfo = new List<string>{ "过流保护", "低压保护", "过压保护", "堵转保护","过热保护","速度传感器故障","力矩传感器故障","霍尔故障",
  3745. "马达缺相","NTC故障","BMS校验失败","","OBC校验失败","MCU故障","踏频传感器故障","指拨故障","MOS短路","电压异常","","","","","","","","","","","","",
  3746. "",""};
  3747. private string ErrorInfoDisplay(UInt32 Code)
  3748. {
  3749. string Result = "";
  3750. if (Code == 0)
  3751. {
  3752. Result = "无故障";
  3753. }
  3754. else
  3755. {
  3756. for (int i = 0; i < 32; i++)
  3757. {
  3758. if ((Code & 0x01) == 0x01)
  3759. {
  3760. Result += ErrorInfo[i] + " ";
  3761. }
  3762. Code >>= 1;
  3763. }
  3764. }
  3765. return Result;
  3766. }
  3767. /// <summary>
  3768. /// 鼠标滑过故障码显示具体内容
  3769. /// </summary>
  3770. /// <param name="sender"></param>
  3771. /// <param name="e"></param>
  3772. private void textBox_ErrorCode_MouseHover(object sender, EventArgs e)
  3773. {
  3774. // 创建the ToolTip
  3775. ToolTip toolTip1 = new ToolTip();
  3776. // 设置显示样式
  3777. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  3778. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  3779. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  3780. toolTip1.ShowAlways = true;//是否显示提示框
  3781. // 设置伴随的对象.
  3782. string ErrorCode = this.textBox_ErrorCode.Text;
  3783. UInt32 Code = ErrorCode.Contains("H") ? Convert.ToUInt32(ErrorCode.Split('H')[0], 16) : 0;
  3784. toolTip1.SetToolTip(this.textBox_ErrorCode, ErrorInfoDisplay(Code));//设置故障内容显示
  3785. }
  3786. /// <summary>
  3787. /// 数据记录
  3788. /// </summary>
  3789. private void RunInfoAutoSave()
  3790. {
  3791. if (运行信息记录ToolStripMenuItem.Checked == true)
  3792. {
  3793. if (RunInfoSaveFilename == string.Empty)
  3794. {
  3795. return;
  3796. }
  3797. string SaveData = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff").Replace(" ", "_") + " --> ";
  3798. foreach (Control c in tabPage_RunInfo.Controls)
  3799. {
  3800. if (c is TextBox)
  3801. {
  3802. SaveData += c.Text + " , ";
  3803. }
  3804. }
  3805. foreach (Control c in tabPage_DebugInfo.Controls)
  3806. {
  3807. if (c is TextBox)
  3808. {
  3809. SaveData += c.Text + " , ";
  3810. }
  3811. }
  3812. SaveData += "\r\n";
  3813. System.IO.File.AppendAllText(RunInfoSaveFilename, SaveData);//sb.ToString());
  3814. }
  3815. }
  3816. /// <summary>
  3817. /// 打开或关闭数据记录
  3818. /// </summary>
  3819. /// <param name="sender"></param>
  3820. /// <param name="e"></param>
  3821. private void 记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  3822. {
  3823. if (运行信息记录ToolStripMenuItem.Checked == false)
  3824. {
  3825. if (mySerialProcess.mySerial.IsOpen == true)
  3826. {
  3827. RunInfoSaveFilename = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_运行信息" + ".txt";
  3828. System.IO.File.AppendAllText(RunInfoSaveFilename, "时间 --> 车速 , 转速 , 踏频 , 力矩Reg , 力矩 , 踩踏方向 , 电压 , 电流 , 功率 , 电量 , " +
  3829. "PCB温度 , 绕组温度 , MOS温度 , 挡位 , 灯开关 , 续航 , 平均功耗 , 单次里程 , 单次时间 , 故障码 , " +
  3830. "系统状态机 , 二层状态机 , 电机状态机 , 助力状态机 , D轴电流给定 , Q轴电流给定 , D轴电压给定 , Q轴电压给定 , 瞬时力矩 , 时间滤波力矩 , 踏频滤波力矩 , D轴电流反馈 , Q轴电流反馈 , 助力函数输出" + "\r\n");
  3831. MessageBoxTimeOut.Show("开始记录", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  3832. 运行信息记录ToolStripMenuItem.Checked = true;
  3833. }
  3834. else
  3835. {
  3836. timer_500ms.Enabled = false;
  3837. MessageBox.Show("请连接电机", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3838. timer_500ms.Enabled = true;
  3839. }
  3840. }
  3841. else
  3842. {
  3843. 运行信息记录ToolStripMenuItem.Checked = false;
  3844. MessageBoxTimeOut.Show("停止记录", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  3845. }
  3846. }
  3847. /// <summary>
  3848. /// 仪表启动控制档位开关事件
  3849. /// </summary>
  3850. /// <param name="sender"></param>
  3851. /// <param name="e"></param>
  3852. private void checkBox_OBC_StartSetGearSt_CheckedChanged(object sender, EventArgs e)
  3853. {
  3854. if (checkBox_OBC_StartSetGearSt.Checked == true)
  3855. {
  3856. //检查串口是否打开
  3857. if (!mySerialProcess.mySerial.IsOpen)
  3858. {
  3859. timer_500ms.Enabled = false;
  3860. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3861. timer_500ms.Enabled = true;
  3862. checkBox_OBC_StartSetGearSt.Checked = false;
  3863. return;
  3864. }
  3865. //检查是否选择档位和打开车灯
  3866. if ((comboBox_OBC_SetGearST.SelectedIndex == -1) || (comboBox_OBC_LightSw.SelectedIndex == -1))
  3867. {
  3868. timer_500ms.Enabled = false;
  3869. MessageBox.Show("请检查档位设置和大灯开关!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3870. timer_500ms.Enabled = true;
  3871. checkBox_OBC_StartSetGearSt.Checked = false;
  3872. return;
  3873. }
  3874. }
  3875. }
  3876. /// <summary>
  3877. /// OBC查询电机用户参数
  3878. /// </summary>
  3879. /// <param name="sender"></param>
  3880. /// <param name="e"></param>
  3881. private void button_OBC_ReadUserInfo_Click(object sender, EventArgs e)
  3882. {
  3883. richTextBox_OBC_ReadUserInfo.Clear();
  3884. comboBox_OBC_BikeCCS.SelectedIndex = 0;
  3885. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3300, null);
  3886. }
  3887. /// <summary>
  3888. /// OBC设置电机用户参数
  3889. /// </summary>
  3890. /// <param name="sender"></param>
  3891. /// <param name="e"></param>
  3892. private void button_OBC_WriteUserInfo_Click(object sender, EventArgs e)
  3893. {
  3894. var UserInfoCode = new byte[8];
  3895. for (int i = 0; i < UserInfoCode.Length; i++)
  3896. UserInfoCode[i] = 0;
  3897. if (comboBox_OBC_StartMode.SelectedIndex == -1)//检查数据有效性
  3898. {
  3899. timer_500ms.Enabled = false;
  3900. MessageBox.Show("请选择启动模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3901. timer_500ms.Enabled = true;
  3902. return;
  3903. }
  3904. if (comboBox_OBC_AssistFunc.SelectedIndex == -1)//检查数据有效性
  3905. {
  3906. timer_500ms.Enabled = false;
  3907. MessageBox.Show("请选择助力方案!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3908. timer_500ms.Enabled = true;
  3909. return;
  3910. }
  3911. //周长微调
  3912. UserInfoCode[0] = (byte)(int)numericUpDown_OBC_WheelAdj.Value;
  3913. //启动模式
  3914. UserInfoCode[1] = (byte)(comboBox_OBC_StartMode.SelectedIndex + 1);
  3915. //助力方案
  3916. UserInfoCode[2] = (byte)(comboBox_OBC_AssistFunc.SelectedIndex + 1);
  3917. //自动关机时间
  3918. UserInfoCode[3] = (byte)(uint)numericUpDown_OBC_OffTime.Value;
  3919. //限速微调
  3920. UserInfoCode[4] = (byte)(int)numericUpDown_OBC_SpeedLimitAdj.Value;
  3921. //定速巡航开关
  3922. UserInfoCode[5] = (byte)((comboBox_OBC_BikeCCS.SelectedIndex == 1) ? 0xAA : 0x00);
  3923. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3408, UserInfoCode);
  3924. }
  3925. /// <summary>
  3926. /// OBC查询电机版本信息
  3927. /// </summary>
  3928. /// <param name="sender"></param>
  3929. /// <param name="e"></param>
  3930. private void button_OBC_ReadVerInfo_Click(object sender, EventArgs e)
  3931. {
  3932. textBox_Model.Text = "---";
  3933. textBox_SN.Text = "---";
  3934. textBox_HW.Text = "---";
  3935. textBox_FW.Text = "---";
  3936. textBox_SP.Text = "---";
  3937. textBox_OBC_ReadModel.Text = "---";
  3938. textBox_OBC_ReadSN.Text = "---";
  3939. textBox_OBC_ReadHW.Text = "---";
  3940. textBox_OBC_ReadFW.Text = "---";
  3941. textBox_OBC_ReadSP.Text = "---";
  3942. textBox_FacModeName.Text = "---";
  3943. textBox_FacModeNum.Text = "---";
  3944. textBox_FacModeHW.Text = "---";
  3945. textBox_FacModeFW.Text = "---";
  3946. textBox_FacModeSP.Text = "---";
  3947. Class_Motor_Ver.Mode = "---";
  3948. Class_Motor_Ver.SN = "---";
  3949. Class_Motor_Ver.HW = "---";
  3950. Class_Motor_Ver.FW = "---";
  3951. Class_Motor_Ver.Special = "---";
  3952. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  3953. }
  3954. /// <summary>
  3955. /// OBC读取骑行历史
  3956. /// </summary>
  3957. /// <param name="sender"></param>
  3958. /// <param name="e"></param>
  3959. private void button_OBC_ReadRideInfo_Click(object sender, EventArgs e)
  3960. {
  3961. textBox_OBC_TRIP_KM.Text = "";
  3962. textBox_OBC_TRIP_TIME.Text = "";
  3963. textBox_OBC_ODO_KM.Text = "";
  3964. textBox_OBC_ODO_TIME.Text = "";
  3965. textBox_ODO_KM.Text = "---";
  3966. textBox_ODO_TIME.Text = "---";
  3967. textBox_TRIP_KM.Text = "---";
  3968. textBox_TRIP_TIME.Text = "---";
  3969. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3500, null);
  3970. }
  3971. /// <summary>
  3972. /// OBC清除TRIP里程
  3973. /// </summary>
  3974. /// <param name="sender"></param>
  3975. /// <param name="e"></param>
  3976. private void button_OBC_ClearTrip_Click(object sender, EventArgs e)
  3977. {
  3978. var Code = new byte[5];
  3979. Code[0] = (byte)'C';
  3980. Code[1] = (byte)'L';
  3981. Code[2] = (byte)'E';
  3982. Code[3] = (byte)'A';
  3983. Code[4] = (byte)'R';
  3984. timer_500ms.Enabled = false;
  3985. if (MessageBox.Show("TRIP清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3986. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3605, Code);
  3987. timer_500ms.Enabled = true;
  3988. }
  3989. private void checkBox_OBC_StartReadBMS_CheckedChanged(object sender, EventArgs e)
  3990. {
  3991. if (checkBox_OBC_StartReadBMS.Checked == true)
  3992. {
  3993. //检查串口是否打开
  3994. if (!mySerialProcess.mySerial.IsOpen)
  3995. {
  3996. timer_500ms.Enabled = false;
  3997. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3998. timer_500ms.Enabled = true;
  3999. checkBox_OBC_StartReadBMS.Checked = false;
  4000. return;
  4001. }
  4002. }
  4003. }
  4004. /// <summary>
  4005. /// 写入力矩传感器参数
  4006. /// </summary>
  4007. /// <param name="sender"></param>
  4008. /// <param name="e"></param>
  4009. private void button_WriteTqSensorParam_Click(object sender, EventArgs e)
  4010. {
  4011. var ConfigParam = new byte[46];
  4012. for (int i = 0; i < 14; i++)
  4013. ConfigParam[i] = 0;
  4014. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  4015. ushort uwDataTemp = 0;
  4016. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  4017. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  4018. int index = 0;
  4019. try
  4020. {
  4021. for (int i = 0; i < strDataTemp.Length; i++)
  4022. {
  4023. if (strDataTemp[i].Split('=')[0] == "第四阶段转矩点采集值")
  4024. {
  4025. index = i;
  4026. break;
  4027. }
  4028. }
  4029. for (int i = 0; i < (index + 1); i++)
  4030. {
  4031. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  4032. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  4033. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  4034. }
  4035. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x472E, ConfigParam);
  4036. }
  4037. catch (Exception)
  4038. {
  4039. timer_500ms.Enabled = false;
  4040. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4041. timer_500ms.Enabled = true;
  4042. }
  4043. }
  4044. /// <summary>
  4045. /// 查询存储标志
  4046. /// </summary>
  4047. /// <param name="sender"></param>
  4048. /// <param name="e"></param>
  4049. private void button_ReadSaveFlag_Click(object sender, EventArgs e)
  4050. {
  4051. radioButton_EE_SaveYes.Checked = false;
  4052. radioButton_EE_SaveNo.Checked = false;
  4053. radioButton_SIP_SaveYes.Checked = false;
  4054. radioButton_SIP_SaveNo.Checked = false;
  4055. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null);
  4056. }
  4057. /// <summary>
  4058. /// 写入存储标志
  4059. /// </summary>
  4060. /// <param name="sender"></param>
  4061. /// <param name="e"></param>
  4062. private void button_WriteSaveFlag_Click(object sender, EventArgs e)
  4063. {
  4064. var SaveFlag = new byte[6];
  4065. for (int i = 0; i < 6; i++)
  4066. SaveFlag[i] = 0;
  4067. if ((radioButton_EE_SaveYes.Checked == false) && (radioButton_EE_SaveNo.Checked == false))
  4068. {
  4069. timer_500ms.Enabled = false;
  4070. MessageBox.Show("请选择EEPROM存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4071. timer_500ms.Enabled = true;
  4072. return;
  4073. }
  4074. if ((radioButton_SIP_SaveYes.Checked == false) && (radioButton_SIP_SaveNo.Checked == false))
  4075. {
  4076. timer_500ms.Enabled = false;
  4077. MessageBox.Show("请选择SIP校验存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4078. timer_500ms.Enabled = true;
  4079. return;
  4080. }
  4081. SaveFlag[0] = (byte)((checkBox_SaveYes.Checked) ? 0x01 : 0x00);
  4082. SaveFlag[2] = (byte)(radioButton_EE_SaveYes.Checked ? 0x01 : 0x00);
  4083. SaveFlag[3] = 0;
  4084. SaveFlag[4] = (byte)(radioButton_SIP_SaveYes.Checked ? 0x01 : 0x00);
  4085. SaveFlag[5] = 0;
  4086. timer_500ms.Enabled = false;
  4087. if (MessageBox.Show("确认修改存储标志?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  4088. {
  4089. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4906, SaveFlag);
  4090. }
  4091. timer_500ms.Enabled = true;
  4092. }
  4093. /// <summary>
  4094. /// 读取指定地址数据
  4095. /// </summary>
  4096. /// <param name="sender"></param>
  4097. /// <param name="e"></param>
  4098. private void button_ReadRamFlash_Click(object sender, EventArgs e)
  4099. {
  4100. var Address = new byte[4];
  4101. UInt32 Address_Begin;
  4102. UInt32 Addres_End;
  4103. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  4104. richTextBox_RamFlasgData.Clear();
  4105. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  4106. {
  4107. timer_500ms.Enabled = false;
  4108. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4109. timer_500ms.Enabled = true;
  4110. return;
  4111. }
  4112. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  4113. {
  4114. timer_500ms.Enabled = false;
  4115. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4116. timer_500ms.Enabled = true;
  4117. return;
  4118. }
  4119. else
  4120. {
  4121. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  4122. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  4123. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  4124. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  4125. if (Addres_End < Address_Begin)
  4126. {
  4127. timer_500ms.Enabled = false;
  4128. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4129. timer_500ms.Enabled = true;
  4130. return;
  4131. }
  4132. else
  4133. {
  4134. var SendByte = new byte[8];
  4135. SendByte[0] = (byte)(Address_Begin >> 24);
  4136. SendByte[1] = (byte)(Address_Begin >> 16);
  4137. SendByte[2] = (byte)(Address_Begin >> 8);
  4138. SendByte[3] = (byte)(Address_Begin);
  4139. SendByte[4] = (byte)(Addres_End >> 24);
  4140. SendByte[5] = (byte)(Addres_End >> 16);
  4141. SendByte[6] = (byte)(Addres_End >> 8);
  4142. SendByte[7] = (byte)(Addres_End);
  4143. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  4144. }
  4145. }
  4146. }
  4147. /// <summary>
  4148. /// 工作模式选择
  4149. /// </summary>
  4150. /// <param name="sender"></param>
  4151. /// <param name="e"></param>
  4152. private void comboBox_WorkMode_SelectedIndexChanged(object sender, EventArgs e)
  4153. {
  4154. var RunMode = new byte[1];
  4155. if (comboBox_WorkMode.Text == "配置模式")
  4156. RunMode[0] = 0x01;
  4157. else if (comboBox_WorkMode.Text == "调试模式")
  4158. RunMode[0] = 0x02;
  4159. else
  4160. RunMode[0] = 0x00;
  4161. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  4162. }
  4163. /// <summary>
  4164. /// 助力档位选择
  4165. /// </summary>
  4166. /// <param name="sender"></param>
  4167. /// <param name="e"></param>
  4168. private void comboBox_GearSt_SelectedIndexChanged(object sender, EventArgs e)
  4169. {
  4170. var CtrlCode = new byte[2];
  4171. if (comboBox_GearSt.SelectedIndex == 5)//档位
  4172. CtrlCode[0] = 0x33;
  4173. else if (comboBox_GearSt.SelectedIndex == 6)//档位
  4174. CtrlCode[0] = 0x22;
  4175. else
  4176. CtrlCode[0] = (byte)comboBox_GearSt.SelectedIndex;
  4177. if (comboBox_LightSwitch.SelectedIndex == 0)//车灯
  4178. CtrlCode[1] = 0xF1;
  4179. else
  4180. CtrlCode[1] = 0xF0;
  4181. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
  4182. comboBox_OBC_SetGearST.SelectedIndex = comboBox_GearSt.SelectedIndex;
  4183. comboBox_OBC_LightSw.SelectedIndex = comboBox_LightSwitch.SelectedIndex;
  4184. Delay_ms(500);
  4185. //设置百分比
  4186. do
  4187. {
  4188. var PercentCode = new byte[1];
  4189. if (comboBox_GearSt.SelectedIndex == 0) //Off
  4190. {
  4191. PercentCode[0] = 0;
  4192. textBox_MotorSpeedPercent.Text = "0";
  4193. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, PercentCode);
  4194. }
  4195. else if (comboBox_GearSt.SelectedIndex == 6) //Walk
  4196. {
  4197. if (comboBox_WorkMode.SelectedIndex != 0)
  4198. {
  4199. PercentCode[0] = 100;
  4200. textBox_MotorSpeedPercent.Text = "100";
  4201. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, PercentCode);
  4202. }
  4203. }
  4204. } while (false);
  4205. }
  4206. /// <summary>
  4207. /// 仪表档位选择
  4208. /// </summary>
  4209. /// <param name="sender"></param>
  4210. /// <param name="e"></param>
  4211. private void comboBox_OBC_SetGearST_SelectedIndexChanged(object sender, EventArgs e)
  4212. {
  4213. comboBox_GearSt.SelectedIndex = comboBox_OBC_SetGearST.SelectedIndex;
  4214. comboBox_LightSwitch.SelectedIndex = comboBox_OBC_LightSw.SelectedIndex;
  4215. }
  4216. /// <summary>
  4217. /// 生产模式初始化
  4218. /// </summary>
  4219. /// <param name="sender"></param>
  4220. /// <param name="e"></param>
  4221. private void button_FacModeInit_Click(object sender, EventArgs e)
  4222. {
  4223. var Code = new byte[5];
  4224. Code[0] = (byte)'C';
  4225. Code[1] = (byte)'L';
  4226. Code[2] = (byte)'E';
  4227. Code[3] = (byte)'A';
  4228. Code[4] = (byte)'R';
  4229. timer_500ms.Enabled = false;
  4230. if (MessageBox.Show("电机即将初始化!", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  4231. {
  4232. if (MessageBox.Show("请再次确认", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  4233. {
  4234. timer_500ms.Enabled = true;
  4235. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  4236. PowerOffAckStatus = false;
  4237. Delay_ms(250);
  4238. int TryCnt = 3;
  4239. while ((TryCnt--) >= 0)
  4240. {
  4241. if (!PowerOffAckStatus)
  4242. {
  4243. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  4244. PowerOffAckStatus = false;
  4245. Delay_ms(250);
  4246. }
  4247. else break;
  4248. }
  4249. if (PowerOffAckStatus)
  4250. {
  4251. timer_500ms.Enabled = false;
  4252. MessageBox.Show("系统已关机,请保持无负载重新开机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  4253. timer_500ms.Enabled = true;
  4254. }
  4255. else
  4256. {
  4257. timer_500ms.Enabled = false;
  4258. MessageBox.Show("初始化失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4259. timer_500ms.Enabled = true;
  4260. }
  4261. timer_500ms.Enabled = true;
  4262. }
  4263. }
  4264. timer_500ms.Enabled = true;
  4265. //清除历史测试记录
  4266. textBox_FacModeSensorADC0.Text = "";
  4267. textBox_FacModeSensorADC1.Text = "";
  4268. textBox_FacModeSensorADC2.Text = "";
  4269. textBox_FacModeSensorADC3.Text = "";
  4270. textBox_FacModeSensorADC4.Text = "";
  4271. LightSwitchStatus = false;
  4272. MotorRunStatus = false;
  4273. textBox_MotorSpeedPercent.Text = "5";
  4274. textBox_FacModeName.Text = "";
  4275. textBox_FacModeNum.Text = "";
  4276. textBox_FacModeHW.Text = "";
  4277. textBox_FacModeFW.Text = "";
  4278. }
  4279. /// <summary>
  4280. /// 生产模式读取传感器参数
  4281. /// </summary>
  4282. /// <param name="sender"></param>
  4283. /// <param name="e"></param>
  4284. private void button_FacModeSensorRead_Click(object sender, EventArgs e)
  4285. {
  4286. richTextBox_SensorParam.Clear();
  4287. textBox_FacModeSensorADC0.Text = "";
  4288. textBox_FacModeSensorADC1.Text = "";
  4289. textBox_FacModeSensorADC2.Text = "";
  4290. textBox_FacModeSensorADC3.Text = "";
  4291. textBox_FacModeSensorADC4.Text = "";
  4292. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4293. //零点判断
  4294. label1_TorqueCal0.BackColor = Color.Red;
  4295. WriteACK = false;
  4296. ACK_WaitCnt = 0;
  4297. Delay_ms(200);
  4298. if (WriteACK == true) //力矩读取正常
  4299. {
  4300. WriteACK = false;
  4301. //获取零点
  4302. ushort ZeroNew;
  4303. ZeroNew = (ushort)Convert.ToUInt16(textBox_FacModeSensorADC0.Text);
  4304. //比较零点
  4305. if ((ZeroNew <= TorqueParamsForm.Zero.Max) && (ZeroNew >= TorqueParamsForm.Zero.Min))
  4306. {
  4307. label1_TorqueCal0.BackColor = Color.Green;
  4308. }
  4309. else
  4310. {
  4311. MessageBoxTimeOut.Show("力矩传感器零点超范围!\r\n" + "最新零点:" + ZeroNew.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4312. }
  4313. }
  4314. else //力矩读取不正常
  4315. {
  4316. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4317. }
  4318. }
  4319. /// <summary>
  4320. /// 生产模式传感器标定1
  4321. /// </summary>
  4322. /// <param name="sender"></param>
  4323. /// <param name="e"></param>
  4324. private void buttonFacModeSet1_Click(object sender, EventArgs e)
  4325. {
  4326. var ConfigParam = new byte[4];
  4327. for (int i = 0; i < 4; i++)
  4328. ConfigParam[i] = 0;
  4329. ushort uwDataTemp = 0;
  4330. try
  4331. {
  4332. uwDataTemp = 1;//负载序号
  4333. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4334. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4335. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal1.Text) * 10); ;//负载值0.1Nm
  4336. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4337. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4338. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4339. Delay_ms(2000);
  4340. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4341. //标定1判断
  4342. label1_TorqueCal1.BackColor = Color.Red;
  4343. WriteACK = false;
  4344. ACK_WaitCnt = 0;
  4345. Delay_ms(200);
  4346. if (WriteACK == true) //力矩读取正常
  4347. {
  4348. WriteACK = false;
  4349. //获取标定1
  4350. ushort K1_T, K1;
  4351. K1_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal1.Text) * 10);
  4352. K1 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC1.Text));
  4353. //比较标定1
  4354. if ((K1_T == TorqueParamsForm.K1.T) && (K1 <= TorqueParamsForm.K1.Max) && (K1 >= TorqueParamsForm.K1.Min))
  4355. {
  4356. label1_TorqueCal1.BackColor = Color.Green;
  4357. }
  4358. else
  4359. {
  4360. MessageBoxTimeOut.Show("力矩传感器标定1超范围!\r\n" + "加载扭矩:" + K1_T.ToString() + "\r\n标定值:" + K1.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4361. }
  4362. }
  4363. else //力矩读取不正常
  4364. {
  4365. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4366. }
  4367. }
  4368. catch (Exception)
  4369. {
  4370. timer_500ms.Enabled = false;
  4371. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4372. timer_500ms.Enabled = true;
  4373. }
  4374. }
  4375. /// <summary>
  4376. /// 生产模式传感器标定2
  4377. /// </summary>
  4378. /// <param name="sender"></param>
  4379. /// <param name="e"></param>
  4380. private void buttonFacModeSet2_Click(object sender, EventArgs e)
  4381. {
  4382. var ConfigParam = new byte[4];
  4383. for (int i = 0; i < 4; i++)
  4384. ConfigParam[i] = 0;
  4385. ushort uwDataTemp = 0;
  4386. try
  4387. {
  4388. uwDataTemp = 2;//负载序号
  4389. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4390. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4391. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal2.Text) * 10); ;//负载值0.1Nm
  4392. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4393. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4394. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4395. Delay_ms(2000);
  4396. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4397. //标定2判断
  4398. label1_TorqueCal2.BackColor = Color.Red;
  4399. WriteACK = false;
  4400. ACK_WaitCnt = 0;
  4401. Delay_ms(200);
  4402. if (WriteACK == true) //力矩读取正常
  4403. {
  4404. WriteACK = false;
  4405. //获取标定2
  4406. ushort K2_T, K2;
  4407. K2_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal2.Text) * 10);
  4408. K2 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC2.Text));
  4409. //比较标定1
  4410. if ((K2_T == TorqueParamsForm.K2.T) && (K2 <= TorqueParamsForm.K2.Max) && (K2 >= TorqueParamsForm.K2.Min))
  4411. {
  4412. label1_TorqueCal2.BackColor = Color.Green;
  4413. }
  4414. else
  4415. {
  4416. MessageBoxTimeOut.Show("力矩传感器标定2超范围!\r\n" + "加载扭矩:" + K2_T.ToString() + "\r\n标定值:" + K2.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4417. }
  4418. }
  4419. else //力矩读取不正常
  4420. {
  4421. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4422. }
  4423. }
  4424. catch (Exception)
  4425. {
  4426. timer_500ms.Enabled = false;
  4427. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4428. timer_500ms.Enabled = true;
  4429. }
  4430. }
  4431. /// <summary>
  4432. /// 生产模式传感器标定3
  4433. /// </summary>
  4434. /// <param name="sender"></param>
  4435. /// <param name="e"></param>
  4436. private void buttonFacModeSet3_Click(object sender, EventArgs e)
  4437. {
  4438. var ConfigParam = new byte[4];
  4439. for (int i = 0; i < 4; i++)
  4440. ConfigParam[i] = 0;
  4441. ushort uwDataTemp = 0;
  4442. try
  4443. {
  4444. uwDataTemp = 3;//负载序号
  4445. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4446. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4447. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal3.Text) * 10); ;//负载值0.1Nm
  4448. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4449. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4450. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4451. Delay_ms(2000);
  4452. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4453. //标定3判断
  4454. label1_TorqueCal3.BackColor = Color.Red;
  4455. WriteACK = false;
  4456. ACK_WaitCnt = 0;
  4457. Delay_ms(200);
  4458. if (WriteACK == true) //力矩读取正常
  4459. {
  4460. WriteACK = false;
  4461. //获取标定3
  4462. ushort K3_T, K3;
  4463. K3_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal3.Text) * 10);
  4464. K3 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC3.Text));
  4465. //比较标定1
  4466. if ((K3_T == TorqueParamsForm.K3.T) && (K3 <= TorqueParamsForm.K3.Max) && (K3 >= TorqueParamsForm.K3.Min))
  4467. {
  4468. label1_TorqueCal3.BackColor = Color.Green;
  4469. }
  4470. else
  4471. {
  4472. MessageBoxTimeOut.Show("力矩传感器标定3超范围!\r\n" + "加载扭矩:" + K3_T.ToString() + "\r\n标定值:" + K3.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4473. }
  4474. }
  4475. else //力矩读取不正常
  4476. {
  4477. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4478. }
  4479. }
  4480. catch (Exception)
  4481. {
  4482. timer_500ms.Enabled = false;
  4483. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4484. timer_500ms.Enabled = true;
  4485. }
  4486. }
  4487. /// <summary>
  4488. /// 生产模式传感器标定4
  4489. /// </summary>
  4490. /// <param name="sender"></param>
  4491. /// <param name="e"></param>
  4492. private void buttonFacModeSet4_Click(object sender, EventArgs e)
  4493. {
  4494. var ConfigParam = new byte[4];
  4495. for (int i = 0; i < 4; i++)
  4496. ConfigParam[i] = 0;
  4497. ushort uwDataTemp = 0;
  4498. try
  4499. {
  4500. WriteACK = false;
  4501. uwDataTemp = 4;//负载序号
  4502. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4503. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4504. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal4.Text) * 10); ;//负载值0.1Nm
  4505. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4506. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4507. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4508. Delay_ms(2000);
  4509. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4510. //标定4判断
  4511. label1_TorqueCal4.BackColor = Color.Red;
  4512. WriteACK = false;
  4513. ACK_WaitCnt = 0;
  4514. Delay_ms(200);
  4515. if (WriteACK == true) //力矩读取正常
  4516. {
  4517. //获取标定4
  4518. ushort K4_T, K4;
  4519. K4_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal4.Text) * 10);
  4520. K4 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC4.Text));
  4521. //比较标定1
  4522. if ((K4_T == TorqueParamsForm.K4.T) && (K4 <= TorqueParamsForm.K4.Max) && (K4 >= TorqueParamsForm.K4.Min))
  4523. {
  4524. label1_TorqueCal4.BackColor = Color.Green;
  4525. }
  4526. else
  4527. {
  4528. MessageBoxTimeOut.Show("力矩传感器标定4超范围!\r\n" + "加载扭矩:" + K4_T.ToString() + "\r\n标定值:" + K4.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4529. }
  4530. }
  4531. else //力矩读取不正常
  4532. {
  4533. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4534. }
  4535. }
  4536. catch (Exception)
  4537. {
  4538. timer_500ms.Enabled = false;
  4539. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4540. timer_500ms.Enabled = true;
  4541. }
  4542. }
  4543. /// <summary>
  4544. /// 生产模式开关灯
  4545. /// </summary>
  4546. /// <param name="sender"></param>
  4547. /// <param name="e"></param>
  4548. bool LightSwitchStatus = false;
  4549. private void button_FacModeLightSW_Click(object sender, EventArgs e)
  4550. {
  4551. var CtrlCode = new byte[2];
  4552. CtrlCode[0] = 0x00;
  4553. if (LightSwitchStatus)
  4554. {
  4555. CtrlCode[1] = 0xF0;
  4556. button_FacModeLightSW.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(128)))));
  4557. }
  4558. else
  4559. {
  4560. CtrlCode[1] = 0xF1;
  4561. button_FacModeLightSW.BackColor = Color.Yellow;
  4562. }
  4563. if (mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode))
  4564. {
  4565. LightSwitchStatus = !LightSwitchStatus;
  4566. comboBox_LightSwitch.SelectedIndex = LightSwitchStatus ? 0 : 1;
  4567. comboBox_OBC_LightSw.SelectedIndex = LightSwitchStatus ? 0 : 1;
  4568. }
  4569. }
  4570. /// <summary>
  4571. /// 生产模式电机控制
  4572. /// </summary>
  4573. /// <param name="sender"></param>
  4574. /// <param name="e"></param>
  4575. bool MotorRunStatus = false;
  4576. private void button_FacModeMotorRun_Click(object sender, EventArgs e)
  4577. {
  4578. string DebugDefaultInfo = "";
  4579. //获取调试信息
  4580. if (richTextBox_DebugParam.Text == string.Empty)
  4581. {
  4582. richTextBox_DebugParam.Clear();
  4583. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  4584. }
  4585. Delay_ms(200);
  4586. DebugDefaultInfo = richTextBox_DebugParam.Text;
  4587. //获取参数
  4588. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  4589. if (strDataTemp.Length != 29)
  4590. {
  4591. timer_500ms.Enabled = false;
  4592. MessageBox.Show("数据格式不正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4593. timer_500ms.Enabled = true;
  4594. return;
  4595. }
  4596. //设置参数
  4597. var ConfigParam = new byte[60];
  4598. for (int i = 0; i < 60; i++)
  4599. ConfigParam[i] = 0;
  4600. ConfigParam[0] = 0x00;
  4601. ushort uwDataTemp = 0;
  4602. if (!MotorRunStatus) //停止状态
  4603. {
  4604. //设置速度环
  4605. strDataTemp[0] = "整体运行模式=3";
  4606. //发送数据
  4607. try
  4608. {
  4609. for (int i = 0; i < strDataTemp.Length; i++)
  4610. {
  4611. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  4612. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  4613. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  4614. }
  4615. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  4616. return;
  4617. }
  4618. catch (Exception)
  4619. {
  4620. timer_500ms.Enabled = false;
  4621. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4622. timer_500ms.Enabled = true;
  4623. }
  4624. Delay_ms(200);
  4625. //设置转速百分比100%
  4626. textBox_MotorSpeedPercent.Text = "100";
  4627. ConfigParam[0] = (byte)100;
  4628. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, ConfigParam);
  4629. MotorRunStatus = !MotorRunStatus;
  4630. button_FacModeMotorRun.BackColor = Color.Yellow;
  4631. Delay_ms(200);
  4632. //电机进入配置模式
  4633. var RunMode = new byte[1];
  4634. RunMode[0] = 0x01;
  4635. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  4636. }
  4637. else //运转状态
  4638. {
  4639. //设置转速百分比0%
  4640. textBox_MotorSpeedPercent.Text = "0";
  4641. ConfigParam[0] = (byte)0;
  4642. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, ConfigParam);
  4643. MotorRunStatus = !MotorRunStatus;
  4644. button_FacModeMotorRun.BackColor = Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
  4645. Delay_ms(200);
  4646. //还原为原始值
  4647. strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  4648. try
  4649. {
  4650. for (int i = 0; i < strDataTemp.Length; i++)
  4651. {
  4652. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  4653. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  4654. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  4655. }
  4656. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  4657. return;
  4658. }
  4659. catch (Exception)
  4660. {
  4661. timer_500ms.Enabled = false;
  4662. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4663. timer_500ms.Enabled = true;
  4664. }
  4665. Delay_ms(200);
  4666. //电机退出配置模式
  4667. var RunMode = new byte[1];
  4668. RunMode[0] = 0x00;
  4669. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  4670. }
  4671. }
  4672. /// <summary>
  4673. /// 生产模式写入型号
  4674. /// </summary>
  4675. /// <param name="sender"></param>
  4676. /// <param name="e"></param>
  4677. private void button_FacModeSetName_Click(object sender, EventArgs e)
  4678. {
  4679. string Mode = textBox_FacModeName.Text;
  4680. var ModeArray = new byte[16];
  4681. for (ushort i = 0; i < Mode.Length; i++)
  4682. {
  4683. ModeArray[i] = (byte)Mode[i];
  4684. }
  4685. if (Mode.Length < 16)
  4686. {
  4687. ModeArray[Mode.Length] = (byte)'.';
  4688. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  4689. {
  4690. ModeArray[Mode.Length + 1 + i] = 0x20;
  4691. }
  4692. }
  4693. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  4694. }
  4695. /// <summary>
  4696. /// 生产模式写入SN
  4697. /// </summary>
  4698. /// <param name="sender"></param>
  4699. /// <param name="e"></param>
  4700. private void Button_FacModeSetNum_Click(object sender, EventArgs e)
  4701. {
  4702. string SN = textBox_FacModeNum.Text;
  4703. var SNArray = new byte[16];
  4704. for (ushort i = 0; i < SN.Length; i++)
  4705. {
  4706. SNArray[i] = (byte)SN[i];
  4707. }
  4708. if (SN.Length < 16)
  4709. {
  4710. SNArray[SN.Length] = (byte)'.';
  4711. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  4712. {
  4713. SNArray[SN.Length + 1 + i] = 0x20;
  4714. }
  4715. }
  4716. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  4717. }
  4718. /// <summary>
  4719. /// 生产模式读取版本信息
  4720. /// </summary>
  4721. /// <param name="sender"></param>
  4722. /// <param name="e"></param>
  4723. private void Button_FacModeReadVer_Click_1(object sender, EventArgs e)
  4724. {
  4725. textBox_Model.Text = "---";
  4726. textBox_SN.Text = "---";
  4727. textBox_HW.Text = "---";
  4728. textBox_FW.Text = "---";
  4729. textBox_SP.Text = "---";
  4730. textBox_OBC_ReadModel.Text = "---";
  4731. textBox_OBC_ReadSN.Text = "---";
  4732. textBox_OBC_ReadHW.Text = "---";
  4733. textBox_OBC_ReadFW.Text = "---";
  4734. textBox_OBC_ReadSP.Text = "---";
  4735. textBox_FacModeName.Text = "---";
  4736. textBox_FacModeNum.Text = "---";
  4737. textBox_FacModeHW.Text = "---";
  4738. textBox_FacModeFW.Text = "---";
  4739. textBox_FacModeSP.Text = "---";
  4740. textBox_FacModeGit.Text = "---";
  4741. Class_Motor_Ver.Mode = "---";
  4742. Class_Motor_Ver.SN = "---";
  4743. Class_Motor_Ver.HW = "---";
  4744. Class_Motor_Ver.FW = "---";
  4745. Class_Motor_Ver.Special = "---";
  4746. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  4747. }
  4748. /// <summary>
  4749. /// 生产模式写入生产信息
  4750. /// </summary>
  4751. /// <param name="sender"></param>
  4752. /// <param name="e"></param>
  4753. private void Button_FacModeSetMacDate_Click(object sender, EventArgs e)
  4754. {
  4755. var MACArray = new byte[32];
  4756. string MacDefaultInfo = "";
  4757. string MacAddDefaultInfo = "";
  4758. string MacDateDefaultInfo = DateTime.Now.ToString("yyyyMMdd");
  4759. string MacPPDefaultInfo = "";
  4760. do
  4761. {
  4762. //填入生产商
  4763. if (toolStripTextBox_MAC.Text == string.Empty)
  4764. {
  4765. break;
  4766. }
  4767. MacDefaultInfo = toolStripTextBox_MAC.Text;
  4768. for (ushort i = 0; i < MacDefaultInfo.Length; i++)
  4769. {
  4770. MACArray[i] = (byte)MacDefaultInfo[i];
  4771. }
  4772. if (MacDefaultInfo.Length < 8)
  4773. {
  4774. MACArray[MacDefaultInfo.Length] = (byte)'.';
  4775. for (ushort i = 0; i < 8 - MacDefaultInfo.Length - 1; i++)
  4776. {
  4777. MACArray[MacDefaultInfo.Length + 1 + i] = 0x20;
  4778. }
  4779. }
  4780. //填入生产地
  4781. if (toolStripTextBoxMACAddr.Text == string.Empty)
  4782. {
  4783. break;
  4784. }
  4785. MacAddDefaultInfo = toolStripTextBoxMACAddr.Text;
  4786. for (ushort i = 0; i < MacAddDefaultInfo.Length; i++)
  4787. {
  4788. MACArray[8 + i] = (byte)MacAddDefaultInfo[i];
  4789. }
  4790. if (MacAddDefaultInfo.Length < 8)
  4791. {
  4792. MACArray[MacAddDefaultInfo.Length + 8] = (byte)'.';
  4793. for (ushort i = 0; i < 8 - MacAddDefaultInfo.Length - 1; i++)
  4794. {
  4795. MACArray[MacAddDefaultInfo.Length + 1 + i + 8] = 0x20;
  4796. }
  4797. }
  4798. //填入生产日期
  4799. if (toolStripTextBox_MACDate.Text == string.Empty)
  4800. {
  4801. break;
  4802. }
  4803. MacDateDefaultInfo = toolStripTextBox_MACDate.Text;
  4804. for (ushort i = 0; i < MacDateDefaultInfo.Length; i++)
  4805. {
  4806. MACArray[16 + i] = (byte)MacDateDefaultInfo[i];
  4807. }
  4808. if (MacDateDefaultInfo.Length < 8)
  4809. {
  4810. MACArray[MacDateDefaultInfo.Length + 16] = (byte)'.';
  4811. for (ushort i = 0; i < 8 - MacDateDefaultInfo.Length - 1; i++)
  4812. {
  4813. MACArray[MacDateDefaultInfo.Length + 1 + i + 16] = 0x20;
  4814. }
  4815. }
  4816. //填入产品标识
  4817. if (toolStripTextBox_MACPD.Text == string.Empty)
  4818. {
  4819. break;
  4820. }
  4821. MacPPDefaultInfo = toolStripTextBox_MACPD.Text;
  4822. for (ushort i = 0; i < MacPPDefaultInfo.Length; i++)
  4823. {
  4824. MACArray[24 + i] = (byte)MacPPDefaultInfo[i];
  4825. }
  4826. if (MacPPDefaultInfo.Length < 8)
  4827. {
  4828. MACArray[MacPPDefaultInfo.Length + 24] = (byte)'.';
  4829. for (ushort i = 0; i < 8 - MacPPDefaultInfo.Length - 1; i++)
  4830. {
  4831. MACArray[MacPPDefaultInfo.Length + 1 + i + 24] = 0x20;
  4832. }
  4833. }
  4834. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  4835. return;
  4836. } while (false);
  4837. timer_500ms.Enabled = false;
  4838. MessageBox.Show("生产信息配置不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4839. timer_500ms.Enabled = true;
  4840. }
  4841. /// <summary>
  4842. /// 建立线程执行一次数据导出
  4843. /// </summary>
  4844. /// <param name=""></param>
  4845. private void SamplesModeExport_Task()
  4846. {
  4847. string[] AssistParams = new string[15];
  4848. do
  4849. {
  4850. //读取一次马达参数
  4851. richTextBox_MotorParam.Clear();
  4852. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break; ;
  4853. ACK_WaitCnt = 0;
  4854. while (ACK_WaitCnt <= 2) //1s
  4855. {
  4856. if (richTextBox_MotorParam.Text != string.Empty)
  4857. break;
  4858. }
  4859. if (richTextBox_MotorParam.Text == string.Empty)
  4860. {
  4861. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break;
  4862. ACK_WaitCnt = 0;
  4863. while (ACK_WaitCnt <= 2) //1s
  4864. {
  4865. if (richTextBox_MotorParam.Text != string.Empty)
  4866. break;
  4867. }
  4868. if (richTextBox_MotorParam.Text == string.Empty)
  4869. {
  4870. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break;
  4871. ACK_WaitCnt = 0;
  4872. while (ACK_WaitCnt <= 2) //1s
  4873. {
  4874. if (richTextBox_MotorParam.Text != string.Empty)
  4875. break;
  4876. }
  4877. }
  4878. }
  4879. //读取一次整车参数
  4880. richTextBox_BikeParam.Clear();
  4881. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  4882. ACK_WaitCnt = 0;
  4883. while (ACK_WaitCnt <= 2) //1s
  4884. {
  4885. if (richTextBox_BikeParam.Text != string.Empty)
  4886. break;
  4887. }
  4888. if (richTextBox_BikeParam.Text == string.Empty)
  4889. {
  4890. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  4891. ACK_WaitCnt = 0;
  4892. while (ACK_WaitCnt <= 2) //1s
  4893. {
  4894. if (richTextBox_BikeParam.Text != string.Empty)
  4895. break;
  4896. }
  4897. if (richTextBox_BikeParam.Text == string.Empty)
  4898. {
  4899. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  4900. ACK_WaitCnt = 0;
  4901. while (ACK_WaitCnt <= 2) //1s
  4902. {
  4903. if (richTextBox_BikeParam.Text != string.Empty)
  4904. break;
  4905. }
  4906. }
  4907. }
  4908. //读取一次整车参数2
  4909. richTextBox_BikeParam2.Clear();
  4910. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null)) break;
  4911. ACK_WaitCnt = 0;
  4912. while (ACK_WaitCnt <= 2) //1s
  4913. {
  4914. if (richTextBox_BikeParam2.Text != string.Empty)
  4915. break;
  4916. }
  4917. if (richTextBox_BikeParam2.Text == string.Empty)
  4918. {
  4919. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null)) break;
  4920. ACK_WaitCnt = 0;
  4921. while (ACK_WaitCnt <= 2) //1s
  4922. {
  4923. if (richTextBox_BikeParam2.Text != string.Empty)
  4924. break;
  4925. }
  4926. if (richTextBox_BikeParam2.Text == string.Empty)
  4927. {
  4928. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null)) break;
  4929. ACK_WaitCnt = 0;
  4930. while (ACK_WaitCnt <= 2) //1s
  4931. {
  4932. if (richTextBox_BikeParam2.Text != string.Empty)
  4933. break;
  4934. }
  4935. }
  4936. }
  4937. //读取一次控制参数
  4938. richTextBox_ControlParam.Clear();
  4939. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  4940. ACK_WaitCnt = 0;
  4941. while (ACK_WaitCnt <= 2) //1s
  4942. {
  4943. if (richTextBox_ControlParam.Text != string.Empty)
  4944. break;
  4945. }
  4946. if (richTextBox_ControlParam.Text == string.Empty)
  4947. {
  4948. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  4949. ACK_WaitCnt = 0;
  4950. while (ACK_WaitCnt <= 2) //1s
  4951. {
  4952. if (richTextBox_ControlParam.Text != string.Empty)
  4953. break;
  4954. }
  4955. if (richTextBox_ControlParam.Text == string.Empty)
  4956. {
  4957. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  4958. ACK_WaitCnt = 0;
  4959. while (ACK_WaitCnt <= 2) //1s
  4960. {
  4961. if (richTextBox_ControlParam.Text != string.Empty)
  4962. break;
  4963. }
  4964. }
  4965. }
  4966. //查询传感器
  4967. richTextBox_SensorParam.Clear();
  4968. textBox_FacModeSensorADC0.Text = "";
  4969. textBox_FacModeSensorADC1.Text = "";
  4970. textBox_FacModeSensorADC2.Text = "";
  4971. textBox_FacModeSensorADC3.Text = "";
  4972. textBox_FacModeSensorADC4.Text = "";
  4973. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  4974. ACK_WaitCnt = 0;
  4975. while (ACK_WaitCnt <= 2) //1s
  4976. {
  4977. if (richTextBox_SensorParam.Text != string.Empty)
  4978. break;
  4979. }
  4980. if (richTextBox_SensorParam.Text == string.Empty)
  4981. {
  4982. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  4983. ACK_WaitCnt = 0;
  4984. while (ACK_WaitCnt <= 2) //1s
  4985. {
  4986. if (richTextBox_SensorParam.Text != string.Empty)
  4987. break;
  4988. }
  4989. if (richTextBox_SensorParam.Text == string.Empty)
  4990. {
  4991. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  4992. ACK_WaitCnt = 0;
  4993. while (ACK_WaitCnt <= 2) //1s
  4994. {
  4995. if (richTextBox_SensorParam.Text != string.Empty)
  4996. break;
  4997. }
  4998. }
  4999. }
  5000. //读取15次助力参数
  5001. for (int i = 1; i <= 15; i++)
  5002. {
  5003. var ConfigParam = new byte[4];
  5004. richTextBox_AssistParam.Clear();
  5005. ConfigParam[0] = (byte)(i & 0xFF);
  5006. ConfigParam[1] = (byte)(i >> 8);
  5007. ConfigParam[2] = (byte)(((i >= 5) ? 5 : i) & 0xFF);
  5008. ConfigParam[3] = (byte)(((i >= 5) ? 5 : i) >> 8);
  5009. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  5010. ACK_WaitCnt = 0;
  5011. while (ACK_WaitCnt <= 2) //1s
  5012. {
  5013. if (richTextBox_AssistParam.Text != string.Empty)
  5014. break;
  5015. }
  5016. if (richTextBox_AssistParam.Text == string.Empty)
  5017. {
  5018. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  5019. ACK_WaitCnt = 0;
  5020. while (ACK_WaitCnt <= 2) //1s
  5021. {
  5022. if (richTextBox_AssistParam.Text != string.Empty)
  5023. break;
  5024. }
  5025. if (richTextBox_AssistParam.Text == string.Empty)
  5026. {
  5027. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  5028. ACK_WaitCnt = 0;
  5029. while (ACK_WaitCnt <= 2) //1s
  5030. {
  5031. if (richTextBox_AssistParam.Text != string.Empty)
  5032. break;
  5033. }
  5034. }
  5035. }
  5036. AssistParams[i - 1] = richTextBox_AssistParam.Text + "\r\n";
  5037. }
  5038. #if true
  5039. //读取一次用户骑行参数
  5040. richTextBox_UsrRidesParam.Clear();
  5041. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  5042. ACK_WaitCnt = 0;
  5043. while (ACK_WaitCnt <= 2) //1s
  5044. {
  5045. if (richTextBox_UsrRidesParam.Text != string.Empty)
  5046. break;
  5047. }
  5048. if (richTextBox_UsrRidesParam.Text == string.Empty)
  5049. {
  5050. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null)) break;
  5051. ACK_WaitCnt = 0;
  5052. while (ACK_WaitCnt <= 2) //1s
  5053. {
  5054. if (richTextBox_UsrRidesParam.Text != string.Empty)
  5055. break;
  5056. }
  5057. if (richTextBox_UsrRidesParam.Text == string.Empty)
  5058. {
  5059. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null)) break;
  5060. ACK_WaitCnt = 0;
  5061. while (ACK_WaitCnt <= 2) //1s
  5062. {
  5063. if (richTextBox_UsrRidesParam.Text != string.Empty)
  5064. break;
  5065. }
  5066. }
  5067. }
  5068. #endif
  5069. //读取一次调试信息
  5070. richTextBox_DebugParam.Clear();
  5071. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  5072. ACK_WaitCnt = 0;
  5073. while (ACK_WaitCnt <= 2) //1s
  5074. {
  5075. if (richTextBox_DebugParam.Text != string.Empty)
  5076. break;
  5077. }
  5078. if (richTextBox_DebugParam.Text == string.Empty)
  5079. {
  5080. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  5081. ACK_WaitCnt = 0;
  5082. while (ACK_WaitCnt <= 2) //1s
  5083. {
  5084. if (richTextBox_DebugParam.Text != string.Empty)
  5085. break;
  5086. }
  5087. if (richTextBox_DebugParam.Text == string.Empty)
  5088. {
  5089. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  5090. ACK_WaitCnt = 0;
  5091. while (ACK_WaitCnt <= 2) //1s
  5092. {
  5093. if (richTextBox_DebugParam.Text != string.Empty)
  5094. break;
  5095. }
  5096. }
  5097. }
  5098. //读取一次历史信息
  5099. richTextBox_Record.Clear();
  5100. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  5101. ACK_WaitCnt = 0;
  5102. while (ACK_WaitCnt <= 2) //1s
  5103. {
  5104. if (richTextBox_Record.Text != string.Empty)
  5105. break;
  5106. }
  5107. if (richTextBox_Record.Text == string.Empty)
  5108. {
  5109. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  5110. ACK_WaitCnt = 0;
  5111. while (ACK_WaitCnt <= 2) //1s
  5112. {
  5113. if (richTextBox_Record.Text != string.Empty)
  5114. break;
  5115. }
  5116. if (richTextBox_Record.Text == string.Empty)
  5117. {
  5118. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  5119. ACK_WaitCnt = 0;
  5120. while (ACK_WaitCnt <= 2) //1s
  5121. {
  5122. if (richTextBox_Record.Text != string.Empty)
  5123. break;
  5124. }
  5125. }
  5126. }
  5127. //读取一次电机运行信息
  5128. var CtrlCode = new byte[2];
  5129. CtrlCode[0] = 0x00;
  5130. CtrlCode[1] = 0xF0;
  5131. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode)) break;
  5132. ACK_WaitCnt = 0;
  5133. while (ACK_WaitCnt <= 2) //1s
  5134. {
  5135. if (textBox_RunInfo_BikeSpeed.Text != string.Empty)
  5136. break;
  5137. }
  5138. if (textBox_RunInfo_BikeSpeed.Text == string.Empty)
  5139. {
  5140. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode)) break;
  5141. ACK_WaitCnt = 0;
  5142. while (ACK_WaitCnt <= 2) //1s
  5143. {
  5144. if (textBox_RunInfo_BikeSpeed.Text != string.Empty)
  5145. break;
  5146. }
  5147. if (textBox_RunInfo_BikeSpeed.Text == string.Empty)
  5148. {
  5149. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode)) break;
  5150. ACK_WaitCnt = 0;
  5151. while (ACK_WaitCnt <= 2) //1s
  5152. {
  5153. if (textBox_RunInfo_BikeSpeed.Text != string.Empty)
  5154. break;
  5155. }
  5156. }
  5157. }
  5158. //读取一次版本信息
  5159. textBox_Model.Text = "---";
  5160. textBox_SN.Text = "---";
  5161. textBox_HW.Text = "---";
  5162. textBox_FW.Text = "---";
  5163. textBox_SP.Text = "---";
  5164. textBox_OBC_ReadModel.Text = "---";
  5165. textBox_OBC_ReadSN.Text = "---";
  5166. textBox_OBC_ReadHW.Text = "---";
  5167. textBox_OBC_ReadFW.Text = "---";
  5168. textBox_FacModeName.Text = "---";
  5169. textBox_FacModeNum.Text = "---";
  5170. textBox_FacModeHW.Text = "---";
  5171. textBox_FacModeFW.Text = "---";
  5172. textBox_FacModeSP.Text = "---";
  5173. Class_Motor_Ver.Mode = "---";
  5174. Class_Motor_Ver.SN = "---";
  5175. Class_Motor_Ver.HW = "---";
  5176. Class_Motor_Ver.FW = "---";
  5177. Class_Motor_Ver.Special = "---";
  5178. if (!mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null)) break;
  5179. ACK_WaitCnt = 0;
  5180. while (ACK_WaitCnt <= 2) //1s
  5181. {
  5182. 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))
  5183. break;
  5184. }
  5185. if (textBox_Model.Text == string.Empty)
  5186. {
  5187. if (!mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null)) break;
  5188. ACK_WaitCnt = 0;
  5189. while (ACK_WaitCnt <= 2) //1s
  5190. {
  5191. 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))
  5192. break;
  5193. }
  5194. if (textBox_Model.Text == string.Empty)
  5195. {
  5196. if (!mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null)) break;
  5197. ACK_WaitCnt = 0;
  5198. while (ACK_WaitCnt <= 2) //1s
  5199. {
  5200. 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))
  5201. break;
  5202. }
  5203. }
  5204. }
  5205. //读取一次生产信息
  5206. textBox_MAC.Text = "";
  5207. textBox_MACAdd.Text = "";
  5208. textBox_MACDate.Text = "";
  5209. textBox_PP.Text = "";
  5210. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  5211. ACK_WaitCnt = 0;
  5212. while (ACK_WaitCnt <= 2) //1s
  5213. {
  5214. if (textBox_MAC.Text != string.Empty)
  5215. break;
  5216. }
  5217. if (textBox_MAC.Text == string.Empty)
  5218. {
  5219. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  5220. ACK_WaitCnt = 0;
  5221. while (ACK_WaitCnt <= 2) //1s
  5222. {
  5223. if (textBox_MAC.Text != string.Empty)
  5224. break;
  5225. }
  5226. if (textBox_MAC.Text == string.Empty)
  5227. {
  5228. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  5229. ACK_WaitCnt = 0;
  5230. while (ACK_WaitCnt <= 2) //1s
  5231. {
  5232. if (textBox_MAC.Text != string.Empty)
  5233. break;
  5234. }
  5235. }
  5236. }
  5237. //读取一次自定义信息
  5238. textBox_User1.Text = "---";
  5239. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  5240. ACK_WaitCnt = 0;
  5241. while (ACK_WaitCnt <= 2) //1s
  5242. {
  5243. if (textBox_User1.Text != string.Empty)
  5244. break;
  5245. }
  5246. if (textBox_User1.Text == string.Empty)
  5247. {
  5248. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  5249. ACK_WaitCnt = 0;
  5250. while (ACK_WaitCnt <= 2) //1s
  5251. {
  5252. if (textBox_User1.Text != string.Empty)
  5253. break;
  5254. }
  5255. if (textBox_User1.Text == string.Empty)
  5256. {
  5257. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  5258. ACK_WaitCnt = 0;
  5259. while (ACK_WaitCnt <= 2) //1s
  5260. {
  5261. if (textBox_User1.Text != string.Empty)
  5262. break;
  5263. }
  5264. }
  5265. }
  5266. textBox_User2.Text = "---";
  5267. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  5268. ACK_WaitCnt = 0;
  5269. while (ACK_WaitCnt <= 2) //1s
  5270. {
  5271. if (textBox_User2.Text != string.Empty)
  5272. break;
  5273. }
  5274. if (textBox_User2.Text == string.Empty)
  5275. {
  5276. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  5277. ACK_WaitCnt = 0;
  5278. while (ACK_WaitCnt <= 2) //1s
  5279. {
  5280. if (textBox_User2.Text != string.Empty)
  5281. break;
  5282. }
  5283. if (textBox_User2.Text == string.Empty)
  5284. {
  5285. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  5286. ACK_WaitCnt = 0;
  5287. while (ACK_WaitCnt <= 2) //1s
  5288. {
  5289. if (textBox_User2.Text != string.Empty)
  5290. break;
  5291. }
  5292. }
  5293. }
  5294. textBox_User3.Text = "---";
  5295. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  5296. ACK_WaitCnt = 0;
  5297. while (ACK_WaitCnt <= 2) //1s
  5298. {
  5299. if (textBox_User3.Text != string.Empty)
  5300. break;
  5301. }
  5302. if (textBox_User3.Text == string.Empty)
  5303. {
  5304. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  5305. ACK_WaitCnt = 0;
  5306. while (ACK_WaitCnt <= 2) //1s
  5307. {
  5308. if (textBox_User3.Text != string.Empty)
  5309. break;
  5310. }
  5311. if (textBox_User3.Text == string.Empty)
  5312. {
  5313. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  5314. ACK_WaitCnt = 0;
  5315. while (ACK_WaitCnt <= 2) //1s
  5316. {
  5317. if (textBox_User3.Text != string.Empty)
  5318. break;
  5319. }
  5320. }
  5321. }
  5322. //读取一次密钥
  5323. textBox_Key.Text = "---";
  5324. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  5325. ACK_WaitCnt = 0;
  5326. while (ACK_WaitCnt <= 2) //1s
  5327. {
  5328. if (textBox_Key.Text != string.Empty)
  5329. break;
  5330. }
  5331. if (textBox_Key.Text == string.Empty)
  5332. {
  5333. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  5334. ACK_WaitCnt = 0;
  5335. while (ACK_WaitCnt <= 2) //1s
  5336. {
  5337. if (textBox_Key.Text != string.Empty)
  5338. break;
  5339. }
  5340. if (textBox_Key.Text == string.Empty)
  5341. {
  5342. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  5343. ACK_WaitCnt = 0;
  5344. while (ACK_WaitCnt <= 2) //1s
  5345. {
  5346. if (textBox_Key.Text != string.Empty)
  5347. break;
  5348. }
  5349. }
  5350. }
  5351. //读取一次存储标志
  5352. radioButton_EE_SaveYes.Checked = false;
  5353. radioButton_EE_SaveNo.Checked = false;
  5354. radioButton_SIP_SaveYes.Checked = false;
  5355. radioButton_SIP_SaveNo.Checked = false;
  5356. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  5357. ACK_WaitCnt = 0;
  5358. while (ACK_WaitCnt <= 2) //1s
  5359. {
  5360. if ((radioButton_EE_SaveYes.Checked | radioButton_EE_SaveNo.Checked | radioButton_SIP_SaveYes.Checked | radioButton_SIP_SaveNo.Checked) == true)
  5361. break;
  5362. }
  5363. if ((radioButton_EE_SaveYes.Checked | radioButton_EE_SaveNo.Checked | radioButton_SIP_SaveYes.Checked | radioButton_SIP_SaveNo.Checked) == false)
  5364. {
  5365. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  5366. ACK_WaitCnt = 0;
  5367. while (ACK_WaitCnt <= 2) //1s
  5368. {
  5369. if ((radioButton_EE_SaveYes.Checked | radioButton_EE_SaveNo.Checked | radioButton_SIP_SaveYes.Checked | radioButton_SIP_SaveNo.Checked) == true)
  5370. break;
  5371. }
  5372. if ((radioButton_EE_SaveYes.Checked | radioButton_EE_SaveNo.Checked | radioButton_SIP_SaveYes.Checked | radioButton_SIP_SaveNo.Checked) == false)
  5373. {
  5374. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  5375. ACK_WaitCnt = 0;
  5376. while (ACK_WaitCnt <= 2) //1s
  5377. {
  5378. if ((radioButton_EE_SaveYes.Checked | radioButton_EE_SaveNo.Checked | radioButton_SIP_SaveYes.Checked | radioButton_SIP_SaveNo.Checked) == true)
  5379. break;
  5380. }
  5381. }
  5382. }
  5383. //读取一次MOS内阻校准参数
  5384. foreach (Control c in groupBox21.Controls)
  5385. {
  5386. if (c is TextBox)
  5387. c.Text = "";
  5388. }
  5389. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  5390. ACK_WaitCnt = 0;
  5391. while (ACK_WaitCnt <= 2) //1s
  5392. {
  5393. if (textBox_MOS_K1.Text != string.Empty)
  5394. break;
  5395. }
  5396. if (textBox_MOS_K1.Text == string.Empty)
  5397. {
  5398. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null)) break;
  5399. ACK_WaitCnt = 0;
  5400. while (ACK_WaitCnt <= 2) //1s
  5401. {
  5402. if (textBox_MOS_K1.Text != string.Empty)
  5403. break;
  5404. }
  5405. if (textBox_MOS_K1.Text == string.Empty)
  5406. {
  5407. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null)) break;
  5408. ACK_WaitCnt = 0;
  5409. while (ACK_WaitCnt <= 2) //1s
  5410. {
  5411. if (textBox_MOS_K1.Text != string.Empty)
  5412. break;
  5413. }
  5414. }
  5415. }
  5416. //提示检查
  5417. #if false
  5418. timer_1s.Enabled = false;
  5419. if (MessageBox.Show("请检查信息是否完整!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  5420. {
  5421. MessageBox.Show("请检查参数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5422. timer_1s.Enabled = true;
  5423. return;
  5424. }
  5425. timer_1s.Enabled = true;
  5426. Delay_ms(200);
  5427. #endif
  5428. //判断数据是否有效
  5429. if ((textBox_FacModeName.Text == "---") || (textBox_FacModeNum.Text == "---"))
  5430. {
  5431. MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5432. break;
  5433. }
  5434. if ((textBox_FacModeName.Text == string.Empty) || (textBox_FacModeNum.Text == string.Empty))
  5435. {
  5436. MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5437. break;
  5438. }
  5439. //设置文件存储路径
  5440. string Save_Path = localInfo.LocalPath + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
  5441. string PD_PathName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_"); ;
  5442. Save_Path += PD_PathName;
  5443. if (!Directory.Exists(Save_Path))
  5444. Directory.CreateDirectory(Save_Path);
  5445. //保存页面
  5446. string PIC_SaveFileName = "";
  5447. Double scaleX = PrimaryScreen.ScaleX;
  5448. Double scaleY = PrimaryScreen.ScaleY;
  5449. //保存页面
  5450. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  5451. Graphics g = Graphics.FromImage(bit);
  5452. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  5453. PIC_SaveFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_测试页面" + ".png";
  5454. bit.Save(PIC_SaveFileName);
  5455. //保存数据
  5456. string DataFileName = "";
  5457. string FileInfo = "";
  5458. DataFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_记录数据" + ".txt";
  5459. FileInfo += "计算机名称:\r\n" + label_Computername.Text + "\r\n";
  5460. FileInfo += "软件运行时间:\r\n" + stopwatch.ElapsedMilliseconds.ToString() + " ms" + "\r\n";
  5461. FileInfo += "软件运行次数:\r\n" + File.ReadAllText(localInfo.LocalPath + localInfo.PowerTimesFilename) + "\r\n";
  5462. FileInfo += "系统时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  5463. FileInfo += "\r\n";
  5464. FileInfo += "[电机信息]\r\n";
  5465. FileInfo += "电机型号: " + textBox_FacModeName.Text + "\r\n";
  5466. FileInfo += "电机编号: " + textBox_FacModeNum.Text + "\r\n";
  5467. FileInfo += "硬件版本: " + textBox_HW.Text + "\r\n";
  5468. FileInfo += "软件版本: " + textBox_FW.Text + "\r\n";
  5469. FileInfo += "软件标识: " + textBox_SP.Text + "\r\n";
  5470. FileInfo += "Git信息: " + textBox_FacModeGit.Text + "\r\n";
  5471. FileInfo += "\r\n";
  5472. FileInfo += "[马达参数]\r\n";
  5473. FileInfo += richTextBox_MotorParam.Text + "\r\n";
  5474. FileInfo += "\r\n";
  5475. FileInfo += "[整车参数]\r\n";
  5476. FileInfo += richTextBox_BikeParam.Text + "\r\n";
  5477. FileInfo += "\r\n";
  5478. FileInfo += "[控制参数]\r\n";
  5479. FileInfo += richTextBox_ControlParam.Text + "\r\n";
  5480. FileInfo += "\r\n";
  5481. FileInfo += "[传感器参数]\r\n";
  5482. FileInfo += richTextBox_SensorParam.Text + "\r\n";
  5483. FileInfo += "\r\n";
  5484. FileInfo += "[助力参数]\r\n";
  5485. for (int i = 0; i < 15; i++)
  5486. {
  5487. FileInfo += AssistParams[i] + "\r\n";
  5488. }
  5489. FileInfo += "[调试参数]\r\n";
  5490. FileInfo += richTextBox_DebugParam.Text + "\r\n";
  5491. FileInfo += "\r\n";
  5492. FileInfo += "[历史信息]\r\n";
  5493. FileInfo += richTextBox_Record.Text + "\r\n";
  5494. FileInfo += "\r\n";
  5495. FileInfo += "[MOS内阻校准参数]\r\n";
  5496. FileInfo += textBox_MOS_K1.Text + ", ";
  5497. FileInfo += textBox_MOS_K2.Text + ", ";
  5498. FileInfo += textBox_MOS_K3.Text + ", ";
  5499. FileInfo += textBox_MOS_K4.Text + ", ";
  5500. FileInfo += textBox_MOS_K5.Text + ", ";
  5501. FileInfo += textBox_MOS_R1.Text + ", ";
  5502. FileInfo += textBox_MOS_R2.Text + ", ";
  5503. FileInfo += textBox_MOS_R3.Text + "\r\n";
  5504. FileInfo += "\r\n";
  5505. FileInfo += "[整车参数2]\r\n";
  5506. FileInfo += richTextBox_BikeParam2.Text + "\r\n";
  5507. FileInfo += "\r\n";
  5508. FileInfo += "[用户骑行参数]\r\n";
  5509. FileInfo += richTextBox_UsrRidesParam.Text + "\r\n";
  5510. FileInfo += "\r\n";
  5511. FileInfo += "[生产信息]\r\n";
  5512. FileInfo += "生产商: " + textBox_MAC.Text + "\r\n";
  5513. FileInfo += "生产地: " + textBox_MACAdd.Text + "\r\n";
  5514. FileInfo += "生产日期: " + textBox_MACDate.Text + "\r\n";
  5515. FileInfo += "产品标识: " + textBox_PP.Text + "\r\n";
  5516. FileInfo += "\r\n";
  5517. FileInfo += "[自定义信息]\r\n";
  5518. FileInfo += "自定义1: " + textBox_User1.Text + "\r\n";
  5519. FileInfo += "自定义2: " + textBox_User2.Text + "\r\n";
  5520. FileInfo += "自定义3: " + textBox_User3.Text + "\r\n";
  5521. FileInfo += "\r\n";
  5522. FileInfo += "[校验密钥]\r\n";
  5523. FileInfo += textBox_Key.Text + "\r\n";
  5524. FileInfo += "\r\n";
  5525. FileInfo += "[存储标志]\r\n";
  5526. FileInfo += "EEPROM: " + ((radioButton_EE_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  5527. FileInfo += "SIP: " + ((radioButton_SIP_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  5528. FileInfo += "\r\n";
  5529. FileInfo += Local_HdInformation;
  5530. FileInfo += "\r\n";
  5531. FileInfo += "文件格式: V2.0\r\n";
  5532. System.IO.File.WriteAllText(DataFileName, FileInfo);
  5533. Delay_ms(1000);
  5534. MessageBoxTimeOut.Show("存储完成!", "提示", 600, MessageBoxButtons.OK, MessageBoxIcon.Information);
  5535. //数据上传
  5536. if (myFtp.IsNetConnected == true)
  5537. {
  5538. string DataNow = DateTime.Now.ToString("yyyy-MM-dd");
  5539. //检查路径
  5540. if (myFtp.DirectoryExist("\\", toolStripTextBox_ServerPath.Text) == false)
  5541. {
  5542. myFtp.MakeDir(toolStripTextBox_ServerPath.Text);
  5543. }
  5544. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text, "Samples") == false)
  5545. {
  5546. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples");
  5547. }
  5548. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples", DataNow) == false)
  5549. {
  5550. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow);
  5551. }
  5552. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow, PD_PathName) == false)
  5553. {
  5554. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  5555. }
  5556. //上传文件
  5557. bool result1 = myFtp.UploadFile(PIC_SaveFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  5558. bool result2 = myFtp.UploadFile(DataFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  5559. if ((result1 & result2) == true)
  5560. {
  5561. MessageBoxTimeOut.Show("数据已上传!", "提示", 600, MessageBoxButtons.OK, MessageBoxIcon.Information);
  5562. }
  5563. else
  5564. {
  5565. MessageBox.Show("数据上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5566. }
  5567. }
  5568. else
  5569. {
  5570. MessageBox.Show("服务器断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5571. }
  5572. Button_FacModeSaveResult.Text = "保存数据";
  5573. Button_FacModeSaveResult.Enabled = true;
  5574. return;
  5575. } while (false);
  5576. MessageBox.Show("保存异常!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5577. Button_FacModeSaveResult.Text = "保存数据";
  5578. Button_FacModeSaveResult.Enabled = true;
  5579. }
  5580. /// <summary>
  5581. /// 生产模式保存测试页面
  5582. /// </summary>
  5583. /// <param name="sender"></param>
  5584. /// <param name="e"></param>
  5585. private void Button_FacModeSaveResult_Click(object sender, EventArgs e)
  5586. {
  5587. Button_FacModeSaveResult.Text = "存储中…";
  5588. Button_FacModeSaveResult.Enabled = false;
  5589. //创建线程,执行数据导出
  5590. Thread th = new Thread(SamplesModeExport_Task);
  5591. th.Start();
  5592. }
  5593. /// <summary>
  5594. /// 工具箱页面保存
  5595. /// </summary>
  5596. /// <param name="sender"></param>
  5597. /// <param name="e"></param>
  5598. private void 页面保存ToolStripMenuItem_Click(object sender, EventArgs e)
  5599. {
  5600. Double scaleX = PrimaryScreen.ScaleX;
  5601. Double scaleY = PrimaryScreen.ScaleY;
  5602. //保存页面
  5603. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  5604. Graphics g = Graphics.FromImage(bit);
  5605. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  5606. SaveFileDialog sf = new SaveFileDialog();
  5607. sf.Title = "页面保存";
  5608. sf.FileName = "MotorInfo_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".png";
  5609. sf.Filter = "图片|*.png";
  5610. timer_500ms.Enabled = false;
  5611. if (sf.ShowDialog() == DialogResult.OK)
  5612. {
  5613. bit.Save(sf.FileName);//默认保存格式为PNG,保存成jpg格式质量不是很好
  5614. }
  5615. timer_500ms.Enabled = true;
  5616. }
  5617. /// <summary>
  5618. /// 生产模式关机
  5619. /// </summary>
  5620. /// <param name="sender"></param>
  5621. /// <param name="e"></param>
  5622. private void Button_FacModePowerOff_Click(object sender, EventArgs e)
  5623. {
  5624. var Code_Off = new byte[5];
  5625. var Code_Reset = new byte[5];
  5626. Code_Off[0] = (byte)'O';
  5627. Code_Off[1] = (byte)'F';
  5628. Code_Off[2] = (byte)'F';
  5629. Code_Off[3] = (byte)'.';
  5630. Code_Off[4] = (byte)'.';
  5631. Code_Reset[0] = (byte)'R';
  5632. Code_Reset[1] = (byte)'E';
  5633. Code_Reset[2] = (byte)'S';
  5634. Code_Reset[3] = (byte)'E';
  5635. Code_Reset[4] = (byte)'T';
  5636. timer_500ms.Enabled = false;
  5637. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  5638. {
  5639. timer_500ms.Enabled = true;
  5640. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  5641. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  5642. PowerOffAckStatus = false;
  5643. Delay_ms(250);
  5644. int TryCnt = 3;
  5645. while ((TryCnt--) >= 0)
  5646. {
  5647. if (!PowerOffAckStatus)
  5648. {
  5649. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  5650. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  5651. PowerOffAckStatus = false;
  5652. Delay_ms(250);
  5653. }
  5654. else break;
  5655. }
  5656. if (PowerOffAckStatus)
  5657. {
  5658. timer_500ms.Enabled = false;
  5659. MessageBox.Show("已关机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  5660. timer_500ms.Enabled = true;
  5661. }
  5662. else
  5663. {
  5664. timer_500ms.Enabled = false;
  5665. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5666. timer_500ms.Enabled = true;
  5667. }
  5668. }
  5669. timer_500ms.Enabled = true;
  5670. }
  5671. //仪表电源键按下
  5672. private void button_OBC_ButtonPower_Click(object sender, EventArgs e)
  5673. {
  5674. var Code = new byte[2];
  5675. Code[0] = 0;
  5676. Code[1] = 0b00100000;
  5677. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5678. }
  5679. /// <summary>
  5680. /// 仪表加键按下
  5681. /// </summary>
  5682. /// <param name="sender"></param>
  5683. /// <param name="e"></param>
  5684. private void button_OBC_ButtonAcc_Click(object sender, EventArgs e)
  5685. {
  5686. var Code = new byte[2];
  5687. Code[0] = 0;
  5688. Code[1] = 0b00010000;
  5689. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5690. }
  5691. /// <summary>
  5692. /// 仪表减键按下
  5693. /// </summary>
  5694. /// <param name="sender"></param>
  5695. /// <param name="e"></param>
  5696. private void button_OBC_ButtonDec_Click(object sender, EventArgs e)
  5697. {
  5698. var Code = new byte[2];
  5699. Code[0] = 0;
  5700. Code[1] = 0b00001000;
  5701. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5702. }
  5703. /// <summary>
  5704. /// 仪表Walk键按下
  5705. /// </summary>
  5706. /// <param name="sender"></param>
  5707. /// <param name="e"></param>
  5708. private void button_OBC_ButtonWalk_Click(object sender, EventArgs e)
  5709. {
  5710. var Code = new byte[2];
  5711. Code[0] = 0;
  5712. Code[1] = 0b00000100;
  5713. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5714. }
  5715. /// <summary>
  5716. /// 仪表Light键按下
  5717. /// </summary>
  5718. /// <param name="sender"></param>
  5719. /// <param name="e"></param>
  5720. private void button_OBC_ButtonLight_Click(object sender, EventArgs e)
  5721. {
  5722. var Code = new byte[2];
  5723. Code[0] = 0;
  5724. Code[1] = 0b00000010;
  5725. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5726. }
  5727. /// <summary>
  5728. /// 仪表Set键按下
  5729. /// </summary>
  5730. /// <param name="sender"></param>
  5731. /// <param name="e"></param>
  5732. private void button_OBC_ButtonSet_Click(object sender, EventArgs e)
  5733. {
  5734. var Code = new byte[2];
  5735. Code[0] = 0;
  5736. Code[1] = 0b00000001;
  5737. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5738. }
  5739. /// <summary>
  5740. /// 导出电机故障日志
  5741. /// </summary>
  5742. /// <param name="sender"></param>
  5743. /// <param name="e"></param>
  5744. private void button_ExportLog_Click(object sender, EventArgs e)
  5745. {
  5746. var Address = new byte[4];
  5747. UInt32 Address_Begin;
  5748. UInt32 Addres_End;
  5749. string textBox_Address_Begin = textBox_LogAddrBegin.Text;
  5750. string textBox_Address_End = textBox_LogAddrEnd.Text;
  5751. richTextBox_Record.Clear();
  5752. textBox_LogAddrBegin.ReadOnly = true;
  5753. textBox_LogAddrEnd.ReadOnly = true;
  5754. if (!mySerialProcess.mySerial.IsOpen)
  5755. {
  5756. timer_500ms.Enabled = false;
  5757. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5758. timer_500ms.Enabled = true;
  5759. return;
  5760. }
  5761. if ((textBox_Address_Begin == string.Empty) || (textBox_Address_End == string.Empty))
  5762. {
  5763. timer_500ms.Enabled = false;
  5764. MessageBox.Show("请输入日志存储起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5765. timer_500ms.Enabled = true;
  5766. return;
  5767. }
  5768. else
  5769. {
  5770. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin, false);
  5771. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  5772. Address = mySerialProcess.HexStringToBytes(textBox_Address_End, false);
  5773. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  5774. if (Addres_End <= Address_Begin)
  5775. {
  5776. timer_500ms.Enabled = false;
  5777. MessageBox.Show("结束地址应大于起始地址!", "提示");
  5778. timer_500ms.Enabled = true;
  5779. return;
  5780. }
  5781. else if (((Addres_End - Address_Begin + 1) % 128) != 0) //
  5782. {
  5783. timer_500ms.Enabled = false;
  5784. MessageBox.Show("(结束地址 - 起始地址 + 1)应为128整数倍!", "提示");
  5785. timer_500ms.Enabled = true;
  5786. return;
  5787. }
  5788. else
  5789. {
  5790. UInt32 ReadCount = 0;
  5791. button_ExportLog.Text = "导出中...";
  5792. button_ExportLog.Enabled = false;
  5793. ReadCount = (Addres_End - Address_Begin + 1) / 128;
  5794. for (ushort i = 0; i < ReadCount; i++)
  5795. {
  5796. var SendByte = new byte[8];
  5797. UInt32 Address_Temp_Begin;
  5798. UInt32 Address_Temp_End;
  5799. Address_Temp_Begin = Address_Begin + 128 * (UInt32)i;
  5800. SendByte[0] = (byte)(Address_Temp_Begin >> 24);
  5801. SendByte[1] = (byte)(Address_Temp_Begin >> 16);
  5802. SendByte[2] = (byte)(Address_Temp_Begin >> 8);
  5803. SendByte[3] = (byte)(Address_Temp_Begin);
  5804. Address_Temp_End = Address_Temp_Begin + 127;
  5805. SendByte[4] = (byte)(Address_Temp_End >> 24);
  5806. SendByte[5] = (byte)(Address_Temp_End >> 16);
  5807. SendByte[6] = (byte)(Address_Temp_End >> 8);
  5808. SendByte[7] = (byte)(Address_Temp_End);
  5809. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  5810. Delay_ms(200);//Thread.Sleep(200);
  5811. }
  5812. button_ExportLog.Text = "导出日志";
  5813. button_ExportLog.Enabled = true;
  5814. }
  5815. }
  5816. }
  5817. /// <summary>
  5818. /// 保存日志信息
  5819. /// </summary>
  5820. /// <param name="sender"></param>
  5821. /// <param name="e"></param>
  5822. private void button_SaveRecordInfo_Click(object sender, EventArgs e)
  5823. {
  5824. string SaveInfo = "";
  5825. if (richTextBox_Record.Text == string.Empty)
  5826. {
  5827. timer_500ms.Enabled = false;
  5828. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  5829. timer_500ms.Enabled = true;
  5830. return;
  5831. }
  5832. //获取保存信息
  5833. SaveInfo += "读取时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  5834. SaveInfo += "电机型号:" + textBox_FacModeName.Text + "\r\n";
  5835. SaveInfo += "电机SN:" + textBox_FacModeNum.Text + "\r\n";
  5836. SaveInfo += "硬件版本:" + textBox_FacModeHW.Text + "\r\n";
  5837. SaveInfo += "软件版本:" + textBox_FacModeFW.Text + "\r\n";
  5838. SaveInfo += "\r\n";
  5839. SaveInfo += richTextBox_Record.Text;
  5840. //设置保存路径和文件名
  5841. SaveFileDialog sf = new SaveFileDialog();
  5842. sf.Title = "数据保存";
  5843. sf.FileName = "MotorLog_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".ttlog";
  5844. sf.FileName.Replace(" ", "");
  5845. sf.Filter = "日志|*.ttlog";
  5846. if (sf.ShowDialog() == DialogResult.OK)
  5847. {
  5848. System.IO.File.AppendAllText(sf.FileName, SaveInfo);
  5849. }
  5850. }
  5851. /// <summary>
  5852. /// 双击修改日志起始地址
  5853. /// </summary>
  5854. /// <param name="sender"></param>
  5855. /// <param name="e"></param>
  5856. private void label_LogAddrBegin_DoubleClick_1(object sender, EventArgs e)
  5857. {
  5858. textBox_LogAddrBegin.ReadOnly = false;
  5859. }
  5860. /// <summary>
  5861. /// 双击修改日志结束地址
  5862. /// </summary>
  5863. /// <param name="sender"></param>
  5864. /// <param name="e"></param>
  5865. private void label88_DoubleClick(object sender, EventArgs e)
  5866. {
  5867. textBox_LogAddrEnd.ReadOnly = false;
  5868. }
  5869. /// <summary>
  5870. /// 存储器自动读取选择
  5871. /// </summary>
  5872. /// <param name="sender"></param>
  5873. /// <param name="e"></param>
  5874. private void checkBox_ReadRanFlash_AutoSW_CheckedChanged(object sender, EventArgs e)
  5875. {
  5876. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  5877. {
  5878. //检查串口是否打开
  5879. if (!mySerialProcess.mySerial.IsOpen)
  5880. {
  5881. timer_500ms.Enabled = false;
  5882. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5883. timer_500ms.Enabled = true;
  5884. checkBox_ReadRanFlash_AutoSW.Checked = false;
  5885. return;
  5886. }
  5887. }
  5888. }
  5889. /// <summary>
  5890. /// 系统开机按钮
  5891. /// </summary>
  5892. /// <param name="sender"></param>
  5893. /// <param name="e"></param>
  5894. private void 开机ToolStripMenuItem_Click(object sender, EventArgs e)
  5895. {
  5896. byte[] Data = new byte[1];
  5897. Data[0] = 0xF1;
  5898. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  5899. }
  5900. /// <summary>
  5901. /// 系统关机按钮
  5902. /// </summary>
  5903. /// <param name="sender"></param>
  5904. /// <param name="e"></param>
  5905. private void 关机ToolStripMenuItem_Click(object sender, EventArgs e)
  5906. {
  5907. byte[] Data = new byte[1];
  5908. Data[0] = 0xF0;
  5909. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  5910. }
  5911. /// <summary>
  5912. /// 连接开机选择
  5913. /// </summary>
  5914. /// <param name="sender"></param>
  5915. /// <param name="e"></param>
  5916. private void 连接开机ToolStripMenuItem_Click(object sender, EventArgs e)
  5917. {
  5918. //输入用户名
  5919. EnterForm1.ShowDialog();
  5920. try
  5921. {
  5922. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5923. {
  5924. if (EnterForm1.comboBox_User.Text == "管理员")
  5925. {
  5926. 连接开机ToolStripMenuItem.Checked = !连接开机ToolStripMenuItem.Checked;
  5927. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5928. }
  5929. else
  5930. {
  5931. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5932. }
  5933. }
  5934. else
  5935. {
  5936. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5937. }
  5938. }
  5939. catch (Exception)
  5940. {
  5941. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5942. }
  5943. }
  5944. /// <summary>
  5945. /// 断开关机选择
  5946. /// </summary>
  5947. /// <param name="sender"></param>
  5948. /// <param name="e"></param>
  5949. private void 断开关机ToolStripMenuItem_Click(object sender, EventArgs e)
  5950. {
  5951. //输入用户名
  5952. EnterForm1.ShowDialog();
  5953. try
  5954. {
  5955. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5956. {
  5957. if (EnterForm1.comboBox_User.Text == "管理员")
  5958. {
  5959. 断开关机ToolStripMenuItem.Checked = !断开关机ToolStripMenuItem.Checked;
  5960. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5961. }
  5962. else
  5963. {
  5964. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5965. }
  5966. }
  5967. else
  5968. {
  5969. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5970. }
  5971. }
  5972. catch (Exception)
  5973. {
  5974. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5975. }
  5976. }
  5977. /// <summary>
  5978. /// 识别通讯盒选择
  5979. /// </summary>
  5980. /// <param name="sender"></param>
  5981. /// <param name="e"></param>
  5982. private void 识别通讯盒ToolStripMenuItem_Click(object sender, EventArgs e)
  5983. {
  5984. //输入用户名
  5985. EnterForm1.ShowDialog();
  5986. try
  5987. {
  5988. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5989. {
  5990. if (EnterForm1.comboBox_User.Text == "管理员")
  5991. {
  5992. 识别通讯盒ToolStripMenuItem.Checked = !识别通讯盒ToolStripMenuItem.Checked;
  5993. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5994. }
  5995. else
  5996. {
  5997. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5998. }
  5999. }
  6000. else
  6001. {
  6002. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  6003. }
  6004. }
  6005. catch (Exception)
  6006. {
  6007. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  6008. }
  6009. }
  6010. /// <summary>
  6011. /// 将配置信息导出为cfg文件
  6012. /// </summary>
  6013. private void ConfigFileSave(bool DeleteFlag, string FileName)
  6014. {
  6015. if (DeleteFlag)
  6016. {
  6017. if (File.Exists(FileName))
  6018. File.Delete(FileName);
  6019. }
  6020. string CfgFileInfo = "";
  6021. CfgFileInfo += "[PortSet]" + "\r\n";
  6022. CfgFileInfo += "PortNum:" + toolStripComboBox_ComNum.Text + "\r\n";
  6023. CfgFileInfo += "PortBaudrate:" + "115200" + "\r\n";
  6024. CfgFileInfo += "AutoOn:" + 连接开机ToolStripMenuItem.Checked.ToString() + "\r\n";
  6025. CfgFileInfo += "AutoOff:" + 断开关机ToolStripMenuItem.Checked.ToString() + "\r\n";
  6026. CfgFileInfo += "CheckCDL:" + 识别通讯盒ToolStripMenuItem.Checked.ToString() + "\r\n";
  6027. CfgFileInfo += "\r\n";
  6028. CfgFileInfo += "[Option]" + "\r\n";
  6029. CfgFileInfo += "SaveWhenWrite:" + 写入存储ToolStripMenuItem.Checked.ToString() + "\r\n";
  6030. CfgFileInfo += "\r\n";
  6031. CfgFileInfo += "[ServerSet]" + "\r\n";
  6032. CfgFileInfo += "PathName:" + toolStripTextBox_ServerPath.Text + "\r\n";
  6033. CfgFileInfo += "\r\n";
  6034. CfgFileInfo += "[MacInfo]" + "\r\n";
  6035. CfgFileInfo += "MacName:" + toolStripTextBox_MAC.Text + "\r\n";
  6036. CfgFileInfo += "MacAddress:" + toolStripTextBoxMACAddr.Text + "\r\n";
  6037. CfgFileInfo += "MacDate:" + toolStripTextBox_MACDate.Text + "\r\n";
  6038. CfgFileInfo += "MacPdInfo:" + toolStripTextBox_MACPD.Text + "\r\n";
  6039. CfgFileInfo += "\r\n";
  6040. CfgFileInfo += "[LogAddress]" + "\r\n";
  6041. CfgFileInfo += "BeginAddress:" + textBox_LogAddrBegin.Text + "\r\n";
  6042. CfgFileInfo += "EndAddress:" + textBox_LogAddrEnd.Text + "\r\n";
  6043. CfgFileInfo += "\r\n";
  6044. CfgFileInfo += "[MotorType]" + "\r\n";
  6045. CfgFileInfo += "MidMotor1:" + 中置电机MIGIC_ToolStripMenuItem.Checked.ToString() + "\r\n";
  6046. CfgFileInfo += "MidMotor2:" + 中置电机VP_ToolStripMenuItem.Checked.ToString() + "\r\n";
  6047. CfgFileInfo += "HubMotor:" + 轮毂电机ToolStripMenuItem.Checked.ToString() + "\r\n";
  6048. CfgFileInfo += "\r\n";
  6049. CfgFileInfo += "[CheckValue]" + "\r\n";
  6050. CfgFileInfo += "Voltage:" + toolStripTextBox_ThVol.Text + "\r\n";
  6051. CfgFileInfo += "Current:" + toolStripTextBox_ThCur.Text + "\r\n";
  6052. CfgFileInfo += "MotorSpeed:" + toolStripTextBox_ThSpeed.Text + "\r\n";
  6053. CfgFileInfo += "Torque:" + toolStripTextBox_ThTor.Text + "\r\n";
  6054. CfgFileInfo += "Cadence:" + toolStripTextBox_ThCad.Text + "\r\n";
  6055. CfgFileInfo += "BikeSpeed:" + toolStripTextBox_ThBikeSpeed.Text + "\r\n";
  6056. CfgFileInfo += "T_PCB:" + toolStripTextBox_ThT_PCB.Text + "\r\n";
  6057. CfgFileInfo += "T_MCU:" + toolStripTextBox_ThT_MCU.Text + "\r\n";
  6058. CfgFileInfo += "T_Motor:" + toolStripTextBox_ThT_Motor.Text + "\r\n";
  6059. CfgFileInfo += "\r\n";
  6060. CfgFileInfo += "[MosCalK]" + "\r\n";
  6061. CfgFileInfo += "K1-K5:" + toolStripTextBox_MosCalK.Text + "\r\n";
  6062. CfgFileInfo += "MOS1:" + toolStripTextBox_MOS1.Text + "\r\n";
  6063. CfgFileInfo += "MOS2:" + toolStripTextBox_MOS2.Text + "\r\n";
  6064. CfgFileInfo += "MOS3:" + toolStripTextBox_MOS3.Text + "\r\n";
  6065. CfgFileInfo += "\r\n";
  6066. CfgFileInfo += "[ProtocolType]" + "\r\n";
  6067. CfgFileInfo += "CAN:" + cANToolStripMenuItem.Checked.ToString() + "\r\n";
  6068. CfgFileInfo += "UART:" + uARTToolStripMenuItem.Checked.ToString() + "\r\n";
  6069. CfgFileInfo += "\r\n";
  6070. CfgFileInfo += "[AutoUpdate]" + "\r\n";
  6071. CfgFileInfo += "AutoUpdate:" + 打开ToolStripMenuItem.Checked.ToString() + "\r\n";
  6072. CfgFileInfo += "\r\n";
  6073. CfgFileInfo += "[AngleCal]" + "\r\n";
  6074. CfgFileInfo += "MaxDiffLimit:" + textBox_AngleDiffTh.Text + "\r\n";
  6075. CfgFileInfo += "ZeroDiffLimit:" + textBox_AngleZeroTh.Text + "\r\n";
  6076. System.IO.File.WriteAllText(FileName, CfgFileInfo);
  6077. }
  6078. /// <summary>
  6079. /// 配置状态更新,点击时保存
  6080. /// </summary>
  6081. private void ConfigFileSave_Click(object sender, EventArgs e)
  6082. {
  6083. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  6084. }
  6085. /// <summary>
  6086. /// 文本框修改结束,回车保存
  6087. /// </summary>
  6088. /// <param name="sender"></param>
  6089. /// <param name="e"></param>
  6090. private void ConfigFileSave_KeyDown(object sender, KeyEventArgs e)
  6091. {
  6092. if (e.KeyCode == Keys.Enter)
  6093. {
  6094. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  6095. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  6096. }
  6097. }
  6098. /// <summary>
  6099. /// 弹出扫码按钮
  6100. /// </summary>
  6101. /// <param name="sender"></param>
  6102. /// <param name="e"></param>
  6103. private void button_ScanCode_Click(object sender, EventArgs e)
  6104. {
  6105. Scan scan_form = new Scan();
  6106. scan_form.ShowDialog();
  6107. do
  6108. {
  6109. if (scan_form.textBox_Scan.Text == string.Empty)
  6110. {
  6111. timer_500ms.Enabled = false;
  6112. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6113. timer_500ms.Enabled = true;
  6114. break;
  6115. }
  6116. string ScanInfo = scan_form.textBox_Scan.Text;
  6117. string regexInfo = "";
  6118. string[] InfoList = { "" };
  6119. try
  6120. {
  6121. if (中置电机MIGIC_ToolStripMenuItem.Checked == true)
  6122. {
  6123. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  6124. InfoList = Regex.Split(ScanInfo, regexInfo, RegexOptions.IgnoreCase);
  6125. }
  6126. else if (中置电机VP_ToolStripMenuItem.Checked == true)
  6127. {
  6128. 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]?$");
  6129. if (ScanInfo.Contains(" "))
  6130. {
  6131. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  6132. string Mode = InfoList[0];
  6133. string Sn = InfoList[1];
  6134. if (regex.IsMatch(Sn) == false)
  6135. {
  6136. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN格式错误" + "\r\n");
  6137. label_FacModeStatus.Text = "存在故障!";
  6138. label_FacModeResult.BackColor = Color.Red;
  6139. label_FacModeResult.Text = "标签格式错误";
  6140. Delay_ms(500);
  6141. //存储异常并上传
  6142. FacMode_Stop(false);
  6143. return;
  6144. }
  6145. }
  6146. else
  6147. {
  6148. MessageBox.Show("SN格式错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  6149. return;
  6150. }
  6151. }
  6152. else if (轮毂电机ToolStripMenuItem.Checked == true)
  6153. {
  6154. if (!ScanInfo.Contains("/")) //老编码规则
  6155. {
  6156. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  6157. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  6158. string Spec = InfoList[1];
  6159. string Sn = InfoList[2];
  6160. InfoList[0] = Model.Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  6161. InfoList[1] = Sn;
  6162. }
  6163. else //新编码规则
  6164. {
  6165. Dictionary<string, string> Dic_Ver = new Dictionary<string, string>
  6166. {
  6167. { "01", "A" },
  6168. { "02", "B" },
  6169. { "03", "C" },
  6170. { "04", "D" },
  6171. { "05", "E" },
  6172. { "06", "F" },
  6173. { "07", "G" },
  6174. { "08", "H" },
  6175. { "09", "I" }
  6176. };
  6177. Dictionary<string, string> Dic_Vol = new Dictionary<string, string>
  6178. {
  6179. { "24V", "A" },
  6180. { "36V", "B" },
  6181. { "42V", "C" },
  6182. { "48V", "D" },
  6183. { "52V", "E" },
  6184. { "60V", "F" }
  6185. };
  6186. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  6187. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  6188. string Spec = InfoList[1].Replace("-", "").Replace("/", "");
  6189. string Sn = InfoList[2];
  6190. InfoList[0] = Model[2] + Dic_Ver[Model.Substring(3, 2)] + Model[5] + Dic_Ver[Model.Substring(6, 2)] + Model[9];
  6191. InfoList[0] += Dic_Vol[Spec.Substring(0, 3)] + Spec.Substring(3, 3) + Spec.Substring(13, 4) + Spec.Substring(Spec.Length - 4, 3);
  6192. InfoList[1] = Sn;
  6193. }
  6194. }
  6195. }
  6196. catch (Exception)
  6197. {
  6198. MessageBox.Show("格式错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  6199. return;
  6200. }
  6201. if (InfoList.Length >= 2)
  6202. {
  6203. //写入型号
  6204. textBox_FacModeName.Text = InfoList[0];
  6205. string Mode = textBox_FacModeName.Text;
  6206. var ModeArray = new byte[16];
  6207. for (ushort i = 0; i < Mode.Length; i++)
  6208. {
  6209. ModeArray[i] = (byte)Mode[i];
  6210. }
  6211. if (Mode.Length < 16)
  6212. {
  6213. ModeArray[Mode.Length] = (byte)'.';
  6214. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  6215. {
  6216. ModeArray[Mode.Length + 1 + i] = 0x20;
  6217. }
  6218. }
  6219. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6220. //写入SN
  6221. textBox_FacModeNum.Text = InfoList[1];
  6222. string SN = textBox_FacModeNum.Text;
  6223. var SNArray = new byte[16];
  6224. for (ushort i = 0; i < SN.Length; i++)
  6225. {
  6226. SNArray[i] = (byte)SN[i];
  6227. }
  6228. if (SN.Length < 16)
  6229. {
  6230. SNArray[SN.Length] = (byte)'.';
  6231. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  6232. {
  6233. SNArray[SN.Length + 1 + i] = 0x20;
  6234. }
  6235. }
  6236. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6237. }
  6238. else
  6239. {
  6240. timer_500ms.Enabled = false;
  6241. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6242. timer_500ms.Enabled = true;
  6243. break;
  6244. }
  6245. } while (false);
  6246. scan_form.Dispose();
  6247. }
  6248. /// <summary>
  6249. /// 切换电机类型
  6250. /// </summary>
  6251. /// <param name="sender"></param>
  6252. /// <param name="e"></param>
  6253. private void 中置电机ToolStripMenuItem_Click(object sender, EventArgs e)
  6254. {
  6255. 中置电机MIGIC_ToolStripMenuItem.Checked = true;
  6256. 中置电机VP_ToolStripMenuItem.Checked = false;
  6257. 轮毂电机ToolStripMenuItem.Checked = false;
  6258. toolStripTextBox_MACPD.Text = "MM_MC1";
  6259. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  6260. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  6261. }
  6262. private void 中置电机小牙盘ToolStripMenuItem_Click(object sender, EventArgs e)
  6263. {
  6264. 中置电机MIGIC_ToolStripMenuItem.Checked = false;
  6265. 中置电机VP_ToolStripMenuItem.Checked = true;
  6266. 轮毂电机ToolStripMenuItem.Checked = false;
  6267. toolStripTextBox_MACPD.Text = "MM_MV1";
  6268. toolStripTextBox_ServerPath.Text = "MC_VP_TEST";
  6269. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  6270. }
  6271. /// <summary>
  6272. /// 切换电机类型
  6273. /// </summary>
  6274. /// <param name="sender"></param>
  6275. /// <param name="e"></param>
  6276. private void 轮毂电机ToolStripMenuItem_Click(object sender, EventArgs e)
  6277. {
  6278. 中置电机MIGIC_ToolStripMenuItem.Checked = false;
  6279. 中置电机VP_ToolStripMenuItem.Checked = false;
  6280. 轮毂电机ToolStripMenuItem.Checked = true;
  6281. toolStripTextBox_MACPD.Text = "GF_250_1";
  6282. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  6283. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  6284. }
  6285. /// <summary>
  6286. /// 获取配置文件日期
  6287. /// </summary>
  6288. /// <param name="DisAll"></param>
  6289. private void GetDateList(bool DisAll)
  6290. {
  6291. string[] DateList = { "" };
  6292. //从服务器更新日期列表
  6293. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  6294. {
  6295. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
  6296. }
  6297. //从本地更新日期列表
  6298. else
  6299. {
  6300. DateList = Directory.GetDirectories(localInfo.LocalPath + "\\" + localInfo.CfgPathName);
  6301. }
  6302. comboBox_FacModeCfgDate.Items.Clear();
  6303. comboBox_CheckModeCfgDate.Items.Clear();
  6304. //日期列表加载
  6305. if (DisAll == true)
  6306. {
  6307. comboBox_FacModeCfgDate.Items.Add("显示近期");
  6308. comboBox_CheckModeCfgDate.Items.Add("显示近期");
  6309. comboBox_FacModeCfgDate.Items.Add("---");
  6310. comboBox_CheckModeCfgDate.Items.Add("---");
  6311. foreach (var file in DateList)
  6312. {
  6313. comboBox_FacModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  6314. comboBox_CheckModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  6315. }
  6316. }
  6317. else
  6318. {
  6319. if (DateList.Length > 10)
  6320. {
  6321. comboBox_FacModeCfgDate.Items.Add("显示全部");
  6322. comboBox_CheckModeCfgDate.Items.Add("显示全部");
  6323. comboBox_FacModeCfgDate.Items.Add("---");
  6324. comboBox_CheckModeCfgDate.Items.Add("---");
  6325. }
  6326. for (int i = (DateList.Length > 10) ? (DateList.Length - 10) : 0; i < DateList.Length; i++)//显示最近10个日期
  6327. {
  6328. comboBox_FacModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  6329. comboBox_CheckModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  6330. }
  6331. }
  6332. }
  6333. /// <summary>
  6334. /// 获取配置文件列表
  6335. /// </summary>
  6336. /// <param name="date"></param>
  6337. private void GetFileListFrom(string date)
  6338. {
  6339. string[] FileList = { "" };
  6340. //从服务器更新文件列表
  6341. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  6342. {
  6343. FileList = myFtp.GetFileNameList(toolStripTextBox_ServerPath.Text + "/cfg/" + date);
  6344. }
  6345. else
  6346. {
  6347. FileList = Directory.GetFiles(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + date);
  6348. }
  6349. comboBox_CheckModeCfgFile.Items.Clear();
  6350. comboBox_FacModeCfgFile.Items.Clear();
  6351. foreach (var file in FileList)
  6352. {
  6353. if (file.Contains(".ttcfg"))
  6354. {
  6355. comboBox_CheckModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  6356. comboBox_FacModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  6357. }
  6358. }
  6359. }
  6360. /// <summary>
  6361. /// 检验模式选择文件日期
  6362. /// </summary>
  6363. /// <param name="sender"></param>
  6364. /// <param name="e"></param>
  6365. private void comboBox_CheckModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  6366. {
  6367. if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示全部")
  6368. {
  6369. GetDateList(true);
  6370. }
  6371. else if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示近期")
  6372. {
  6373. GetDateList(false);
  6374. }
  6375. else
  6376. {
  6377. comboBox_CheckModeCfgFile.Text = "";
  6378. GetFileListFrom(comboBox_CheckModeCfgDate.SelectedItem.ToString());
  6379. }
  6380. }
  6381. /// <summary>
  6382. /// 配置模式选择文件日期
  6383. /// </summary>
  6384. /// <param name="sender"></param>
  6385. /// <param name="e"></param>
  6386. private void comboBox_FacModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  6387. {
  6388. if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示全部")
  6389. {
  6390. GetDateList(true);
  6391. }
  6392. else if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示近期")
  6393. {
  6394. GetDateList(false);
  6395. }
  6396. else
  6397. {
  6398. comboBox_FacModeCfgFile.Text = "";
  6399. GetFileListFrom(comboBox_FacModeCfgDate.SelectedItem.ToString());
  6400. }
  6401. }
  6402. /// <summary>
  6403. /// 选中量产模式
  6404. /// </summary>
  6405. /// <param name="sender"></param>
  6406. /// <param name="e"></param>
  6407. private void tabControl1_Selected(object sender, TabControlEventArgs e)
  6408. {
  6409. //更新生产配置文件目录
  6410. GetDateList(false);
  6411. }
  6412. /// <summary>
  6413. /// 量产测试结束
  6414. /// </summary>
  6415. /// <param name=""></param>
  6416. private void FacMode_Stop(bool OK_Flag)
  6417. {
  6418. //打开开始按钮
  6419. button__FacMode_Start.Enabled = true;
  6420. textBox_FacModeScan.Enabled = true;
  6421. var Code = new byte[32];//发送的指令数据
  6422. //退出配置模式
  6423. Code[0] = 0x00;
  6424. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6425. Delay_ms(1000);
  6426. //系统关机
  6427. Code[0] = 0xF0;
  6428. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6429. //关闭串口
  6430. if (mySerialProcess.SerialClose(false))
  6431. {
  6432. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "串口已关闭" + "\r\n");
  6433. toolStripComboBox_ComNum.Enabled = true;
  6434. toolStripComboBox_Baudrate.Enabled = true;
  6435. 刷新ToolStripMenuItem.Enabled = true;
  6436. 连接ToolStripMenuItem.Text = "连接";
  6437. 连接ToolStripMenuItem.Checked = false;
  6438. label_COM_Sta.Text = "连接状态:未连接";
  6439. label_PortStatus.BackColor = Color.Red;
  6440. }
  6441. //路径设置
  6442. string LocalSavePath = "";
  6443. string ServerSavePath = "";
  6444. if (OK_Flag)
  6445. {
  6446. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "OK\\";
  6447. if (样机测试ToolStripMenuItem.Checked == false)
  6448. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/OK/";
  6449. else
  6450. ServerSavePath = toolStripTextBox_ServerPath.Text + "/Samples/OK/";
  6451. }
  6452. else
  6453. {
  6454. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "FAIL\\";
  6455. if (样机测试ToolStripMenuItem.Checked == false)
  6456. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/FAIL/";
  6457. else
  6458. ServerSavePath = toolStripTextBox_ServerPath.Text + "/Samples/FAIL/";
  6459. }
  6460. if (Directory.Exists(LocalSavePath) == false)
  6461. {
  6462. Directory.CreateDirectory(LocalSavePath);
  6463. }
  6464. //保存和上传
  6465. string LogSavePath = "";
  6466. string LogSaveFileName = "";
  6467. string ProductInfo = textBox_FacModeScan.Text.Replace(" ", "_").Replace("/", "-");
  6468. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  6469. if (Directory.Exists(LogSavePath) == false)
  6470. {
  6471. Directory.CreateDirectory(LogSavePath);
  6472. }
  6473. //测试页面
  6474. Double scaleX = PrimaryScreen.ScaleX;
  6475. Double scaleY = PrimaryScreen.ScaleY;
  6476. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  6477. Graphics g = Graphics.FromImage(bit);
  6478. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  6479. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  6480. bit.Save(LogSaveFileName);
  6481. //上传测试页面到服务器
  6482. if (myFtp.IsNetConnected == true)
  6483. {
  6484. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  6485. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  6486. {
  6487. myFtp.MakeDir(ServerSavePath + DateNow);
  6488. }
  6489. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  6490. {
  6491. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  6492. }
  6493. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  6494. if (result == true)
  6495. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  6496. }
  6497. else
  6498. {
  6499. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  6500. }
  6501. //测试记录
  6502. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  6503. string file_str = "";
  6504. file_str += "计算机名称:\r\n" + label_Computername.Text + "\r\n";
  6505. file_str += "软件运行时间:\r\n" + stopwatch.ElapsedMilliseconds.ToString() + " ms" + "\r\n";
  6506. file_str += "软件运行次数:\r\n" + File.ReadAllText(localInfo.LocalPath + localInfo.PowerTimesFilename) + "\r\n";
  6507. file_str += "系统时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  6508. file_str += "检验记录:\r\n" + richTextBox_FacModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  6509. file_str += "检验结果:\r\n" + label_FacModeResult.Text + "\r\n\r\n";
  6510. file_str += Local_HdInformation;
  6511. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  6512. //上传测试记录到服务器
  6513. if (myFtp.IsNetConnected == true)
  6514. {
  6515. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  6516. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  6517. {
  6518. myFtp.MakeDir(ServerSavePath + DateNow);
  6519. }
  6520. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  6521. {
  6522. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  6523. }
  6524. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  6525. if (result == true)
  6526. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  6527. }
  6528. else
  6529. {
  6530. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  6531. }
  6532. //扫码框清空
  6533. textBox_FacModeScan.Text = "";
  6534. }
  6535. /// <summary>
  6536. /// 量产测试开始
  6537. /// </summary>
  6538. /// <param name="sender"></param>
  6539. /// <param name="e"></param>
  6540. private void button__FacMode_Start_Click(object sender, EventArgs e)
  6541. {
  6542. //关闭测试项目编辑
  6543. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  6544. foreach (Control c in groupBox2.Controls)
  6545. {
  6546. if (c is CheckBox)
  6547. c.Enabled = false;
  6548. }
  6549. WriteLockStatus = true;
  6550. //检查配置文件
  6551. if (样机测试ToolStripMenuItem.Checked == false)
  6552. {
  6553. if (comboBox_FacModeCfgFile.Text == "")
  6554. {
  6555. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6556. return;
  6557. }
  6558. }
  6559. //开始测试
  6560. TestStart();
  6561. }
  6562. /// <summary>
  6563. /// 测试子函数
  6564. /// </summary>
  6565. private void TestStart()
  6566. {
  6567. //初始化标签
  6568. FacModelLabelInit();
  6569. richTextBox_FacModeLog.Clear();
  6570. //按钮禁止操作
  6571. button__FacMode_Start.Enabled = false;
  6572. textBox_FacModeScan.Enabled = false;
  6573. //记录配置文件
  6574. if (样机测试ToolStripMenuItem.Checked == false)
  6575. richTextBox_FacModeLog.AppendText("配置文件:" + comboBox_FacModeCfgDate.Text + " / " + comboBox_FacModeCfgFile.Text + "\r\n");
  6576. else
  6577. richTextBox_FacModeLog.AppendText("样机测试,无配置文件" + "\r\n");
  6578. //检查打标信息格式
  6579. Delay_ms(500);
  6580. if (样机测试ToolStripMenuItem.Checked == false) //量产时严格检查标签格式
  6581. {
  6582. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  6583. if (textBox_FacModeScan.Text == string.Empty)
  6584. {
  6585. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6586. button__FacMode_Start.Enabled = true;
  6587. textBox_FacModeScan.Enabled = true;
  6588. return;
  6589. }
  6590. try
  6591. {
  6592. if (中置电机MIGIC_ToolStripMenuItem.Checked == true)
  6593. {
  6594. if (textBox_FacModeScan.Text.Split(' ').Length != 7)
  6595. {
  6596. label_FacModeStatus.Text = "存在故障!";
  6597. label_FacModeResult.BackColor = Color.Red;
  6598. label_FacModeResult.Text = "标签格式错误";
  6599. button__FacMode_Start.Enabled = true;
  6600. textBox_FacModeScan.Enabled = true;
  6601. return;
  6602. }
  6603. }
  6604. else if (中置电机VP_ToolStripMenuItem.Checked == true)
  6605. {
  6606. if (textBox_FacModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 2)
  6607. {
  6608. label_FacModeStatus.Text = "存在故障!";
  6609. label_FacModeResult.BackColor = Color.Red;
  6610. label_FacModeResult.Text = "标签格式错误";
  6611. button__FacMode_Start.Enabled = true;
  6612. textBox_FacModeScan.Enabled = true;
  6613. return;
  6614. }
  6615. }
  6616. else if (轮毂电机ToolStripMenuItem.Checked == true)
  6617. {
  6618. if (textBox_FacModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  6619. {
  6620. label_FacModeStatus.Text = "存在故障!";
  6621. label_FacModeResult.BackColor = Color.Red;
  6622. label_FacModeResult.Text = "标签格式错误";
  6623. button__FacMode_Start.Enabled = true;
  6624. textBox_FacModeScan.Enabled = true;
  6625. return;
  6626. }
  6627. }
  6628. }
  6629. catch (System.Exception)
  6630. {
  6631. label_FacModeStatus.Text = "存在故障!";
  6632. label_FacModeResult.BackColor = Color.Red;
  6633. label_FacModeResult.Text = "标签格式错误";
  6634. button__FacMode_Start.Enabled = true;
  6635. textBox_FacModeScan.Enabled = true;
  6636. return;
  6637. }
  6638. }
  6639. else //样机测试仅按两个空格分离
  6640. {
  6641. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查标签信息" + "\r\n");
  6642. if (textBox_FacModeScan.Text == string.Empty)
  6643. {
  6644. MessageBox.Show("请输入标签信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6645. button__FacMode_Start.Enabled = true;
  6646. textBox_FacModeScan.Enabled = true;
  6647. return;
  6648. }
  6649. try
  6650. {
  6651. if (textBox_FacModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 2)
  6652. {
  6653. label_FacModeStatus.Text = "存在故障!";
  6654. label_FacModeResult.BackColor = Color.Red;
  6655. label_FacModeResult.Text = "标签格式错误";
  6656. button__FacMode_Start.Enabled = true;
  6657. textBox_FacModeScan.Enabled = true;
  6658. return;
  6659. }
  6660. }
  6661. catch (System.Exception)
  6662. {
  6663. label_FacModeStatus.Text = "存在故障!";
  6664. label_FacModeResult.BackColor = Color.Red;
  6665. label_FacModeResult.Text = "标签格式错误";
  6666. button__FacMode_Start.Enabled = true;
  6667. textBox_FacModeScan.Enabled = true;
  6668. return;
  6669. }
  6670. }
  6671. //打开串口
  6672. if (mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false))
  6673. {
  6674. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "打开串口成功" + "\r\n");
  6675. toolStripComboBox_ComNum.Enabled = false;
  6676. toolStripComboBox_Baudrate.Enabled = false;
  6677. 刷新ToolStripMenuItem.Enabled = false;
  6678. 连接ToolStripMenuItem.Text = "断开";
  6679. 连接ToolStripMenuItem.Checked = true;
  6680. label_COM_Sta.Text = toolStripComboBox_ComNum.Text + "已连接," + toolStripComboBox_Baudrate.Text;
  6681. label_PortStatus.BackColor = Color.Green;
  6682. }
  6683. if (!mySerialProcess.mySerial.IsOpen)
  6684. {
  6685. MessageBox.Show("请检查串口连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6686. //按钮禁止操作
  6687. button__FacMode_Start.Enabled = true;
  6688. textBox_FacModeScan.Enabled = true;
  6689. return;
  6690. }
  6691. //流水号计数
  6692. int serial = Convert.ToInt32(label_FacModeSerial.Text);
  6693. serial += 1;
  6694. label_FacModeSerial.Text = serial.ToString();
  6695. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, serial.ToString());
  6696. //创建线程,执行测试任务
  6697. Thread th = new Thread(FacModeTest_Task);
  6698. th.Start();
  6699. }
  6700. /// <summary>
  6701. /// 执行一次测试任务
  6702. /// </summary>
  6703. private void FacModeTest_Task()
  6704. {
  6705. //开始测试
  6706. richTextBox_FacModeLog.AppendText("产品标签:" + textBox_FacModeScan.Text + "\r\n");
  6707. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  6708. //变量定义
  6709. var Code = new byte[255];//发送的指令数据
  6710. label_FacModeStatus.Text = "开始测试";
  6711. Delay_ms(500);
  6712. label_FacModeStatus.Text = "系统开机";
  6713. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  6714. if (uARTToolStripMenuItem.Checked)
  6715. {
  6716. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送复位指令,切换联动装置盒波特率" + "\r\n");
  6717. Code[0] = (byte)'R';
  6718. Code[1] = (byte)'E';
  6719. Code[2] = (byte)'S';
  6720. Code[3] = (byte)'E';
  6721. Code[4] = (byte)'T';
  6722. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  6723. Delay_ms(500);
  6724. }
  6725. //发送开机指令
  6726. //确保测试前先关机,发送关机指令再发送开机指令
  6727. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  6728. Code[0] = 0xF0;
  6729. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6730. Delay_ms(3000);
  6731. BootInfo = "";
  6732. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  6733. Code[0] = 0xF1;
  6734. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6735. ACK_WaitCnt = 0;
  6736. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  6737. while (ACK_WaitCnt <= 20) //10s,等待开机成功,联动装置盒控制器接口波特率需等待5s接口自动切换为9600
  6738. {
  6739. if (!uARTToolStripMenuItem.Checked) //CAN接口不考虑联动装置盒切换为Boot波特率
  6740. {
  6741. if ((BootInfo != string.Empty) && (ACK_WaitCnt > 10))
  6742. break;
  6743. }
  6744. }
  6745. //检查BOOT版本
  6746. if (BootInfo != string.Empty)
  6747. {
  6748. label_FacModeBootVer.BackColor = Color.Green;
  6749. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  6750. Delay_ms(500);
  6751. }
  6752. else
  6753. {
  6754. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
  6755. label_FacModeStatus.Text = "存在故障!";
  6756. label_FacModeResult.BackColor = Color.Red;
  6757. label_FacModeResult.Text = "测试异常";
  6758. Delay_ms(500);
  6759. //存储异常并上传
  6760. FacMode_Stop(false);
  6761. return;
  6762. }
  6763. //系统清除
  6764. if (checkBox_FacModeSysClear.Checked)
  6765. {
  6766. do
  6767. {
  6768. #if false
  6769. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  6770. {
  6771. Code[0] = 0x00;//5S协议
  6772. Code[1] = 0x00;
  6773. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6774. Delay_ms(500);
  6775. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6776. Delay_ms(500);
  6777. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  6778. }
  6779. #endif
  6780. //发送系统清除指令
  6781. label_FacModeStatus.Text = "系统清除";
  6782. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除" + "\r\n");
  6783. Code[0] = (byte)'C';
  6784. Code[1] = (byte)'L';
  6785. Code[2] = (byte)'E';
  6786. Code[3] = (byte)'A';
  6787. Code[4] = (byte)'R';
  6788. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  6789. WriteACK = false;
  6790. ACK_WaitCnt = 0;
  6791. while (ACK_WaitCnt <= 6); //3s
  6792. //等待系统清除完成指令
  6793. if (WriteACK == true)
  6794. {
  6795. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  6796. label_FacModeSysClear.BackColor = Color.Green;
  6797. }
  6798. else
  6799. {
  6800. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除,重发第1次" + "\r\n");
  6801. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  6802. ACK_WaitCnt = 0;
  6803. while (ACK_WaitCnt <= 6) ; //3s
  6804. //等待系统清除完成指令
  6805. if (WriteACK == true)
  6806. {
  6807. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  6808. label_FacModeSysClear.BackColor = Color.Green;
  6809. }
  6810. else
  6811. {
  6812. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除,重发第2次" + "\r\n");
  6813. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  6814. ACK_WaitCnt = 0;
  6815. while (ACK_WaitCnt <= 6) ; //3s
  6816. //等待系统清除完成指令
  6817. if (WriteACK == true)
  6818. {
  6819. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  6820. label_FacModeSysClear.BackColor = Color.Green;
  6821. }
  6822. else
  6823. {
  6824. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除失败" + "\r\n");
  6825. label_FacModeStatus.Text = "存在故障!";
  6826. label_FacModeResult.BackColor = Color.Red;
  6827. label_FacModeResult.Text = "测试异常";
  6828. Delay_ms(500);
  6829. //存储异常并上传
  6830. FacMode_Stop(false);
  6831. return;
  6832. }
  6833. }
  6834. }
  6835. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  6836. if (uARTToolStripMenuItem.Checked)
  6837. {
  6838. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送复位指令,切换联动装置盒波特率" + "\r\n");
  6839. Code[0] = (byte)'R';
  6840. Code[1] = (byte)'E';
  6841. Code[2] = (byte)'S';
  6842. Code[3] = (byte)'E';
  6843. Code[4] = (byte)'T';
  6844. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  6845. Delay_ms(500);
  6846. }
  6847. //系统清除后需重新开机
  6848. label_FacModeStatus.Text = "重新开机";
  6849. //确保测试前先关机,发送关机指令再发送开机指令
  6850. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新发送关机指令" + "\r\n");
  6851. Code[0] = 0xF0;
  6852. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6853. Delay_ms(3000);
  6854. BootInfo = "";
  6855. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新发送开机指令" + "\r\n");
  6856. Code[0] = 0xF1;
  6857. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6858. ACK_WaitCnt = 0;
  6859. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  6860. while (ACK_WaitCnt <= 20)
  6861. {
  6862. if (!uARTToolStripMenuItem.Checked) //CAN接口不考虑联动装置盒切换为Boot波特率
  6863. {
  6864. if ((BootInfo != string.Empty) && (ACK_WaitCnt > 10))
  6865. break;
  6866. }
  6867. }
  6868. //获取Boot版本信息
  6869. if (BootInfo != string.Empty)
  6870. {
  6871. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机成功" + "\r\n");
  6872. Delay_ms(500);
  6873. }
  6874. else
  6875. {
  6876. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机失败" + "\r\n");
  6877. label_FacModeStatus.Text = "存在故障!";
  6878. label_FacModeResult.BackColor = Color.Red;
  6879. label_FacModeResult.Text = "测试异常";
  6880. Delay_ms(500);
  6881. //存储异常并上传
  6882. FacMode_Stop(false);
  6883. return;
  6884. }
  6885. } while (false);
  6886. }
  6887. else
  6888. {
  6889. label_FacModeSysClear.BackColor = Color.Yellow;
  6890. label_FacModeStatus.Text = "跳过系统清除!";
  6891. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过系统清除" + "\r\n");
  6892. Delay_ms(500);
  6893. }
  6894. #if false
  6895. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  6896. {
  6897. Code[0] = 0x00;//5S协议
  6898. Code[1] = 0x00;
  6899. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6900. Delay_ms(500);
  6901. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6902. Delay_ms(500);
  6903. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  6904. }
  6905. #endif
  6906. //检查是否有故障
  6907. if (textBox_ErrorCode.Text.Contains("H"))
  6908. {
  6909. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "故障码:" + textBox_ErrorCode.Text + "\r\n");
  6910. label_FacModeStatus.Text = "电机存在故障!";
  6911. label_FacModeResult.BackColor = Color.Red;
  6912. label_FacModeResult.Text = "测试异常";
  6913. Delay_ms(500);
  6914. //存储异常并上传
  6915. FacMode_Stop(false);
  6916. return;
  6917. }
  6918. //MOS内阻校准
  6919. if (checkBox_FacMode_MosCal.Checked)
  6920. {
  6921. label_FacModeStatus.Text = "MOS内阻校准";
  6922. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始MOS内阻校准" + "\r\n");
  6923. Delay_ms(500);
  6924. //提示进行负载切换
  6925. if (MessageBox.Show("电阻负载切换完成,开始校准?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
  6926. {
  6927. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "取消MOS内阻校准" + "\r\n");
  6928. label_FacModeStatus.Text = "存在故障!";
  6929. label_FacModeResult.BackColor = Color.Red;
  6930. label_FacModeResult.Text = "测试异常";
  6931. Delay_ms(500);
  6932. //存储异常并上传
  6933. FacMode_Stop(false);
  6934. return;
  6935. }
  6936. //确认后发送校准指令
  6937. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令" + "\r\n");
  6938. string[] K = toolStripTextBox_MosCalK.Text.Split(',');
  6939. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  6940. ushort uwDataTemp = 0;
  6941. uwDataTemp = Convert.ToUInt16(K[0]);
  6942. Code[2] = (byte)(uwDataTemp & 0xFF);
  6943. Code[3] = (byte)(uwDataTemp >> 8);
  6944. uwDataTemp = Convert.ToUInt16(K[1]);
  6945. Code[4] = (byte)(uwDataTemp & 0xFF);
  6946. Code[5] = (byte)(uwDataTemp >> 8);
  6947. uwDataTemp = Convert.ToUInt16(K[2]);
  6948. Code[6] = (byte)(uwDataTemp & 0xFF);
  6949. Code[7] = (byte)(uwDataTemp >> 8);
  6950. uwDataTemp = Convert.ToUInt16(K[3]);
  6951. Code[8] = (byte)(uwDataTemp & 0xFF);
  6952. Code[9] = (byte)(uwDataTemp >> 8);
  6953. uwDataTemp = Convert.ToUInt16(K[4]);
  6954. Code[10] = (byte)(uwDataTemp & 0xFF);
  6955. Code[11] = (byte)(uwDataTemp >> 8);
  6956. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  6957. WriteACK = false;
  6958. ACK_WaitCnt = 0;
  6959. while (ACK_WaitCnt <= 6) ; //3s
  6960. if (WriteACK == true)
  6961. {
  6962. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  6963. }
  6964. else
  6965. {
  6966. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令,第1次重发" + "\r\n");
  6967. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  6968. ACK_WaitCnt = 0;
  6969. while (ACK_WaitCnt <= 6) ; //3s
  6970. if (WriteACK == true)
  6971. {
  6972. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  6973. }
  6974. else
  6975. {
  6976. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令,第2次重发" + "\r\n");
  6977. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  6978. ACK_WaitCnt = 0;
  6979. while (ACK_WaitCnt <= 6) ; //3s
  6980. if (WriteACK == true)
  6981. {
  6982. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  6983. }
  6984. else
  6985. {
  6986. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准异常" + "\r\n");
  6987. label_FacModeStatus.Text = "存在故障!";
  6988. label_FacModeResult.BackColor = Color.Red;
  6989. label_FacModeResult.Text = "测试异常";
  6990. Delay_ms(500);
  6991. //存储异常并上传
  6992. FacMode_Stop(false);
  6993. return;
  6994. }
  6995. }
  6996. }
  6997. #if false
  6998. //因控制器复位需发送指令重新进入5S协议
  6999. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  7000. {
  7001. Code[0] = 0x00;//5S协议
  7002. Code[1] = 0x00;
  7003. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  7004. Delay_ms(500);
  7005. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  7006. Delay_ms(500);
  7007. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  7008. }
  7009. #endif
  7010. //读取显示校准返回数据
  7011. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果" + "\r\n");
  7012. foreach (Control c in groupBox21.Controls)
  7013. {
  7014. if (c is TextBox)
  7015. c.Text = "";
  7016. }
  7017. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  7018. ACK_WaitCnt = 0;
  7019. while (ACK_WaitCnt <= 2) ; //1s
  7020. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  7021. {
  7022. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果,第1次重发" + "\r\n");
  7023. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  7024. ACK_WaitCnt = 0;
  7025. while (ACK_WaitCnt <= 2) ; //1s
  7026. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  7027. {
  7028. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果,第2次重发" + "\r\n");
  7029. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  7030. ACK_WaitCnt = 0;
  7031. while (ACK_WaitCnt <= 2) ; //1s
  7032. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  7033. {
  7034. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果异常" + "\r\n");
  7035. label_FacModeStatus.Text = "存在故障!";
  7036. label_FacModeResult.BackColor = Color.Red;
  7037. label_FacModeResult.Text = "测试异常";
  7038. Delay_ms(500);
  7039. //存储异常并上传
  7040. FacMode_Stop(false);
  7041. return;
  7042. }
  7043. }
  7044. }
  7045. else
  7046. {
  7047. 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");
  7048. }
  7049. //与校准返回数据对比
  7050. string[] MOS_R1_Th = toolStripTextBox_MOS1.Text.Split(',');
  7051. string[] MOS_R2_Th = toolStripTextBox_MOS2.Text.Split(',');
  7052. string[] MOS_R3_Th = toolStripTextBox_MOS3.Text.Split(',');
  7053. 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])) &&
  7054. (Convert.ToUInt16(textBox_MOS_R2.Text) >= Convert.ToUInt16(MOS_R2_Th[0])) && (Convert.ToUInt16(textBox_MOS_R2.Text) <= Convert.ToUInt16(MOS_R2_Th[1])) &&
  7055. (Convert.ToUInt16(textBox_MOS_R3.Text) >= Convert.ToUInt16(MOS_R3_Th[0])) && (Convert.ToUInt16(textBox_MOS_R3.Text) <= Convert.ToUInt16(MOS_R3_Th[1]))
  7056. )
  7057. {
  7058. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准合格" + "\r\n");
  7059. label_FacModeMosCal.BackColor = Color.Green;
  7060. //提示切换负载
  7061. MessageBox.Show("请将负载切换回电机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  7062. }
  7063. else
  7064. {
  7065. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准超范围" + "\r\n");
  7066. label_FacModeStatus.Text = "存在故障!";
  7067. label_FacModeResult.BackColor = Color.Red;
  7068. label_FacModeResult.Text = "测试异常";
  7069. Delay_ms(500);
  7070. //存储异常并上传
  7071. FacMode_Stop(false);
  7072. //提示切换负载
  7073. MessageBox.Show("请将负载切换回电机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  7074. return;
  7075. }
  7076. }
  7077. else
  7078. {
  7079. label_FacModeMosCal.BackColor = Color.Yellow;
  7080. label_FacModeStatus.Text = "跳过MOS内阻校准!";
  7081. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过MOS内阻校准" + "\r\n");
  7082. Delay_ms(500);
  7083. }
  7084. //位置校准
  7085. if (checkBox_FacMode_AngleCal.Checked)
  7086. {
  7087. //校准前进行一次开关机保存初始化数据
  7088. label_FacModeStatus.Text = "位置校准";
  7089. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始位置校准" + "\r\n");
  7090. //确保测试前先关机,发送关机指令再发送开机指令
  7091. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  7092. Code[0] = 0xF0;
  7093. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  7094. Delay_ms(3000);
  7095. BootInfo = "";
  7096. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  7097. Code[0] = 0xF1;
  7098. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  7099. ACK_WaitCnt = 0;
  7100. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  7101. while (ACK_WaitCnt <= 10) //5s
  7102. {
  7103. if (BootInfo != string.Empty)
  7104. {
  7105. break;
  7106. }
  7107. }
  7108. //获取Boot版本信息
  7109. if (BootInfo != string.Empty)
  7110. {
  7111. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机成功" + "\r\n");
  7112. Delay_ms(500);
  7113. }
  7114. else
  7115. {
  7116. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机失败" + "\r\n");
  7117. label_FacModeStatus.Text = "存在故障!";
  7118. label_FacModeResult.BackColor = Color.Red;
  7119. label_FacModeResult.Text = "测试异常";
  7120. Delay_ms(500);
  7121. //存储异常并上传
  7122. FacMode_Stop(false);
  7123. return;
  7124. }
  7125. //发送位置校准指令
  7126. for (int i = 0; i < 7; i++)
  7127. for (int j = 0; j < 6; j++)
  7128. {
  7129. dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = "";
  7130. }
  7131. foreach (Control cr in tabPage_AngleCal.Controls)
  7132. {
  7133. if (cr is TextBox)
  7134. {
  7135. if ((cr != textBox_AngleDiffTh) && (cr != textBox_AngleZeroTh))
  7136. cr.Text = "";
  7137. }
  7138. }
  7139. Code[0] = 0;
  7140. Code[1] = 0;
  7141. mySerialProcess.SendCmd((ushort)0x751, (byte)0x0C, (ushort)0x5002, Code);
  7142. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准中,请等待" + "\r\n");
  7143. ACK_WaitCnt = 0;
  7144. while (ACK_WaitCnt <= 50) ; //25s
  7145. //读取位置校准数据
  7146. if (textBox_AngleDiffAvg.Text == string.Empty)
  7147. {
  7148. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准失败" + "\r\n");
  7149. label_FacModeStatus.Text = "存在故障!";
  7150. label_FacModeResult.BackColor = Color.Red;
  7151. label_FacModeResult.Text = "测试异常";
  7152. Delay_ms(500);
  7153. //存储异常并上传
  7154. FacMode_Stop(false);
  7155. return;
  7156. }
  7157. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准数据:" + "\r\n");
  7158. for (int i = 0; i < 7; i++)
  7159. {
  7160. richTextBox_FacModeLog.AppendText("电周期" + (i + 1).ToString()+":");
  7161. for (int j = 0; j < 6; j++)
  7162. {
  7163. richTextBox_FacModeLog.AppendText(dataGridView_AngleCal.Rows[i].Cells[j + 1].Value.ToString() + ", ");
  7164. }
  7165. richTextBox_FacModeLog.AppendText("\r\n");
  7166. Delay_ms(200);
  7167. }
  7168. richTextBox_FacModeLog.AppendText("最小偏差:" + textBox_AngleDiffMin.Text+ ", " + "\r\n");
  7169. richTextBox_FacModeLog.AppendText("最大偏差:" + textBox_AngleDiffMax.Text + ", " + "\r\n");
  7170. richTextBox_FacModeLog.AppendText("平均偏差:" + textBox_AngleDiffAvg.Text + ", " + "\r\n");
  7171. richTextBox_FacModeLog.AppendText("历史零点:" + textBox_AngleZeroInit.Text + ", " + "\r\n");
  7172. richTextBox_FacModeLog.AppendText("当前零点:" + textBox_AngleZeroCur.Text + ", " + "\r\n");
  7173. richTextBox_FacModeLog.AppendText("零点偏差:" + textBox_AngleZeroDiff.Text + ", " + "\r\n");
  7174. //比较位置偏差
  7175. if ((Math.Abs(Convert.ToDouble(textBox_AngleDiffMin.Text)) > Convert.ToDouble(textBox_AngleDiffTh.Text)) ||
  7176. (Math.Abs(Convert.ToDouble(textBox_AngleDiffMax.Text)) > Convert.ToDouble(textBox_AngleDiffTh.Text)) ||
  7177. (Math.Abs(Convert.ToDouble(textBox_AngleDiffAvg.Text)) > Convert.ToDouble(textBox_AngleZeroTh.Text))
  7178. )
  7179. {
  7180. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差过大,无法校准" + "\r\n");
  7181. label_FacModeStatus.Text = "存在故障!";
  7182. label_FacModeResult.BackColor = Color.Red;
  7183. label_FacModeResult.Text = "测试异常";
  7184. Delay_ms(500);
  7185. //存储异常并上传
  7186. FacMode_Stop(false);
  7187. return;
  7188. }
  7189. //写入校准偏差值
  7190. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差满足要求,写入校准数据" + "\r\n");
  7191. double data1 = Convert.ToDouble(textBox_AngleZeroInit.Text) - Convert.ToDouble(textBox_AngleDiffAvg.Text);
  7192. if (data1 > 360)
  7193. {
  7194. data1 -= 360;
  7195. }
  7196. else if (data1 < -360)
  7197. {
  7198. data1 += 360;
  7199. }
  7200. Int16 data2 = (Int16)(data1 * 32768 / 360);
  7201. Code[0] = 0x01;
  7202. Code[1] = 0x00;
  7203. Code[2] = (byte)(data2);
  7204. Code[3] = (byte)(data2 >> 8);
  7205. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
  7206. WriteACK = false;
  7207. ACK_WaitCnt = 0;
  7208. while (ACK_WaitCnt <= 2) ; //1s
  7209. if (WriteACK == true)
  7210. {
  7211. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
  7212. }
  7213. else
  7214. {
  7215. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入位置偏差,第1次重发" + "\r\n");
  7216. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
  7217. WriteACK = false;
  7218. ACK_WaitCnt = 0;
  7219. while (ACK_WaitCnt <= 2) ; //1s
  7220. if (WriteACK == true)
  7221. {
  7222. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
  7223. }
  7224. else
  7225. {
  7226. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入位置偏差,第2次重发" + "\r\n");
  7227. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
  7228. WriteACK = false;
  7229. ACK_WaitCnt = 0;
  7230. while (ACK_WaitCnt <= 2) ; //1s
  7231. if (WriteACK == true)
  7232. {
  7233. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
  7234. }
  7235. else
  7236. {
  7237. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入失败" + "\r\n");
  7238. label_FacModeStatus.Text = "存在故障!";
  7239. label_FacModeResult.BackColor = Color.Red;
  7240. label_FacModeResult.Text = "测试异常";
  7241. Delay_ms(500);
  7242. //存储异常并上传
  7243. FacMode_Stop(false);
  7244. return;
  7245. }
  7246. }
  7247. }
  7248. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准正常,位置偏差值:" + textBox_AngleDiffAvg.Text + "\r\n");
  7249. label_FacModeAngleCal.BackColor = Color.Green;
  7250. }
  7251. else
  7252. {
  7253. label_FacModeAngleCal.BackColor = Color.Yellow;
  7254. label_FacModeStatus.Text = "跳过位置校准!";
  7255. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过位置校准" + "\r\n");
  7256. Delay_ms(500);
  7257. }
  7258. //参数写入
  7259. if (checkBox_FacModeCfgWrite.Checked)
  7260. {
  7261. label_FacModeStatus.Text = "参数写入";
  7262. //写入产品型号和SN
  7263. do
  7264. {
  7265. //根据扫码信息获取型号和SN
  7266. string ScanInfo = textBox_FacModeScan.Text;
  7267. string regexInfo = "";
  7268. string[] InfoList = { "" };
  7269. try
  7270. {
  7271. if (样机测试ToolStripMenuItem.Checked == true) //样机测试时标签按两个空格分隔
  7272. {
  7273. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  7274. string Mode = InfoList[0];
  7275. string Sn = InfoList[1];
  7276. }
  7277. else
  7278. {
  7279. if (中置电机MIGIC_ToolStripMenuItem.Checked == true)
  7280. {
  7281. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  7282. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  7283. }
  7284. else if (中置电机VP_ToolStripMenuItem.Checked == true)
  7285. {
  7286. 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]?$");
  7287. if (ScanInfo.Contains(" "))
  7288. {
  7289. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  7290. string Mode = InfoList[0];
  7291. string Sn = InfoList[1];
  7292. if (Mode.Length > 16)
  7293. {
  7294. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号长度超16个字符" + "\r\n");
  7295. label_FacModeStatus.Text = "存在故障!";
  7296. label_FacModeResult.BackColor = Color.Red;
  7297. label_FacModeResult.Text = "标签格式错误";
  7298. Delay_ms(500);
  7299. //存储异常并上传
  7300. FacMode_Stop(false);
  7301. return;
  7302. }
  7303. if (regex.IsMatch(Sn) == false)
  7304. {
  7305. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN格式错误" + "\r\n");
  7306. label_FacModeStatus.Text = "存在故障!";
  7307. label_FacModeResult.BackColor = Color.Red;
  7308. label_FacModeResult.Text = "标签格式错误";
  7309. Delay_ms(500);
  7310. //存储异常并上传
  7311. FacMode_Stop(false);
  7312. return;
  7313. }
  7314. }
  7315. else
  7316. {
  7317. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  7318. label_FacModeStatus.Text = "存在故障!";
  7319. label_FacModeResult.BackColor = Color.Red;
  7320. label_FacModeResult.Text = "标签格式错误";
  7321. Delay_ms(500);
  7322. //存储异常并上传
  7323. FacMode_Stop(false);
  7324. return;
  7325. }
  7326. }
  7327. else if (轮毂电机ToolStripMenuItem.Checked == true)
  7328. {
  7329. if (!ScanInfo.Contains("/")) //老编码规则
  7330. {
  7331. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  7332. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  7333. string Spec = InfoList[1];
  7334. string Sn = InfoList[2];
  7335. InfoList[0] = Model.Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  7336. InfoList[1] = Sn;
  7337. }
  7338. else //新编码规则
  7339. {
  7340. Dictionary<string, string> Dic_Ver = new Dictionary<string, string>
  7341. {
  7342. { "01", "A" },
  7343. { "02", "B" },
  7344. { "03", "C" },
  7345. { "04", "D" },
  7346. { "05", "E" },
  7347. { "06", "F" },
  7348. { "07", "G" },
  7349. { "08", "H" },
  7350. { "09", "I" }
  7351. };
  7352. Dictionary<string, string> Dic_Vol = new Dictionary<string, string>
  7353. {
  7354. { "24V", "A" },
  7355. { "36V", "B" },
  7356. { "42V", "C" },
  7357. { "48V", "D" },
  7358. { "52V", "E" },
  7359. { "60V", "F" }
  7360. };
  7361. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  7362. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  7363. string Spec = InfoList[1].Replace("-", "").Replace("/", "");
  7364. string Sn = InfoList[2];
  7365. InfoList[0] = Model[2] + Dic_Ver[Model.Substring(3, 2)] + Model[5] + Dic_Ver[Model.Substring(6, 2)] + Model[9];
  7366. InfoList[0] += Dic_Vol[Spec.Substring(0, 3)] + Spec.Substring(3, 3) + Spec.Substring(13, 4) + Spec.Substring(Spec.Length - 4, 3);
  7367. InfoList[1] = Sn;
  7368. }
  7369. }
  7370. }
  7371. }
  7372. catch
  7373. {
  7374. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  7375. label_FacModeStatus.Text = "存在故障!";
  7376. label_FacModeResult.BackColor = Color.Red;
  7377. label_FacModeResult.Text = "标签格式错误";
  7378. Delay_ms(500);
  7379. //存储异常并上传
  7380. FacMode_Stop(false);
  7381. return;
  7382. }
  7383. if (InfoList.Length >= 2)
  7384. {
  7385. //检查配置文件是否与打标信息一致
  7386. //...
  7387. //写入型号
  7388. label_FacModeStatus.Text = "写入型号";
  7389. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号" + "\r\n");
  7390. textBox_FacModeName.Text = InfoList[0];
  7391. string Mode = textBox_FacModeName.Text;
  7392. var ModeArray = new byte[16];
  7393. for (ushort i = 0; i < Mode.Length; i++)
  7394. {
  7395. ModeArray[i] = (byte)Mode[i];
  7396. }
  7397. if (Mode.Length < 16)
  7398. {
  7399. ModeArray[Mode.Length] = (byte)'.';
  7400. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  7401. {
  7402. ModeArray[Mode.Length + 1 + i] = 0x20;
  7403. }
  7404. }
  7405. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  7406. WriteACK = false;
  7407. ACK_WaitCnt = 0;
  7408. while (ACK_WaitCnt <= 2) //1s
  7409. {
  7410. if (WriteACK == true)
  7411. break;
  7412. }
  7413. if (WriteACK == true)
  7414. {
  7415. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  7416. }
  7417. else
  7418. {
  7419. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号,第1次重发" + "\r\n");
  7420. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  7421. ACK_WaitCnt = 0;
  7422. while (ACK_WaitCnt <= 2) //1s
  7423. {
  7424. if (WriteACK == true)
  7425. break;
  7426. }
  7427. if (WriteACK == true)
  7428. {
  7429. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  7430. }
  7431. else
  7432. {
  7433. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号,第2次重发" + "\r\n");
  7434. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  7435. ACK_WaitCnt = 0;
  7436. while (ACK_WaitCnt <= 2) //1s
  7437. {
  7438. if (WriteACK == true)
  7439. break;
  7440. }
  7441. if (WriteACK == true)
  7442. {
  7443. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  7444. }
  7445. else
  7446. {
  7447. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入失败" + "\r\n");
  7448. label_FacModeStatus.Text = "存在故障!";
  7449. label_FacModeResult.BackColor = Color.Red;
  7450. label_FacModeResult.Text = "测试异常";
  7451. Delay_ms(500);
  7452. //存储异常并上传
  7453. FacMode_Stop(false);
  7454. return;
  7455. }
  7456. }
  7457. }
  7458. //写入SN
  7459. label_FacModeStatus.Text = "写入SN";
  7460. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN" + "\r\n");
  7461. textBox_FacModeNum.Text = InfoList[1];
  7462. string SN = textBox_FacModeNum.Text;
  7463. var SNArray = new byte[16];
  7464. for (ushort i = 0; i < SN.Length; i++)
  7465. {
  7466. SNArray[i] = (byte)SN[i];
  7467. }
  7468. if (SN.Length < 16)
  7469. {
  7470. SNArray[SN.Length] = (byte)'.';
  7471. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  7472. {
  7473. SNArray[SN.Length + 1 + i] = 0x20;
  7474. }
  7475. }
  7476. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  7477. WriteACK = false;
  7478. ACK_WaitCnt = 0;
  7479. while (ACK_WaitCnt <= 2) //1s
  7480. {
  7481. if (WriteACK == true)
  7482. break;
  7483. }
  7484. if (WriteACK == true)
  7485. {
  7486. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  7487. }
  7488. else
  7489. {
  7490. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN,第1次重发" + "\r\n");
  7491. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  7492. ACK_WaitCnt = 0;
  7493. while (ACK_WaitCnt <= 2) //1s
  7494. {
  7495. if (WriteACK == true)
  7496. break;
  7497. }
  7498. if (WriteACK == true)
  7499. {
  7500. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  7501. }
  7502. else
  7503. {
  7504. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN,第2次重发" + "\r\n");
  7505. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  7506. ACK_WaitCnt = 0;
  7507. while (ACK_WaitCnt <= 2) //1s
  7508. {
  7509. if (WriteACK == true)
  7510. break;
  7511. }
  7512. if (WriteACK == true)
  7513. {
  7514. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  7515. }
  7516. else
  7517. {
  7518. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入失败" + "\r\n");
  7519. label_FacModeStatus.Text = "存在故障!";
  7520. label_FacModeResult.BackColor = Color.Red;
  7521. label_FacModeResult.Text = "测试异常";
  7522. Delay_ms(500);
  7523. //存储异常并上传
  7524. FacMode_Stop(false);
  7525. return;
  7526. }
  7527. }
  7528. }
  7529. }
  7530. else
  7531. {
  7532. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  7533. return;
  7534. }
  7535. } while (false);
  7536. //写入配置文件
  7537. do
  7538. {
  7539. if (样机测试ToolStripMenuItem.Checked == true)
  7540. {
  7541. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "样机测试,不执行参数写入" + "\r\n");
  7542. label_FacMode_CfgWrite.BackColor = Color.Yellow;
  7543. break;
  7544. }
  7545. label_FacModeStatus.Text = "写入配置文件";
  7546. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  7547. //配置文件
  7548. List<byte[]> CmdList = new List<byte[]>();
  7549. //从服务器下载文件
  7550. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  7551. {
  7552. string SelectFile = "";
  7553. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "/" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  7554. if (File.Exists(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  7555. {
  7556. File.Delete(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  7557. }
  7558. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  7559. //打开文件
  7560. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  7561. CmdList.Clear();
  7562. while (streamReader.Peek() != -1)
  7563. {
  7564. string fileLineInfo = streamReader.ReadLine();
  7565. if (fileLineInfo.IndexOf("[") != -1)
  7566. {
  7567. continue;
  7568. }
  7569. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  7570. }
  7571. streamReader.Close();
  7572. }
  7573. //加载本地文件
  7574. else
  7575. {
  7576. string SelectFile = "";
  7577. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  7578. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  7579. CmdList.Clear();
  7580. while (streamReader.Peek() != -1)
  7581. {
  7582. string fileLineInfo = streamReader.ReadLine();
  7583. if (fileLineInfo.IndexOf("[") != -1)
  7584. {
  7585. continue;
  7586. }
  7587. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  7588. }
  7589. streamReader.Close();
  7590. }
  7591. int CmdNum = CmdList.Count(); //指令个数
  7592. Delay_ms(500);
  7593. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "开始写入" + "\r\n");
  7594. Delay_ms(500);
  7595. //开始写入
  7596. for (int i = 0; i < CmdList.Count; i++)
  7597. {
  7598. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令" + "\r\n");
  7599. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  7600. WriteACK = false;
  7601. ACK_WaitCnt = 0;
  7602. while (ACK_WaitCnt <= 2) //1s
  7603. {
  7604. if (WriteACK == true)
  7605. break;
  7606. }
  7607. if (WriteACK == true)
  7608. {
  7609. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  7610. }
  7611. else
  7612. {
  7613. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令,第1次重发" + "\r\n");
  7614. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  7615. WriteACK = false;
  7616. ACK_WaitCnt = 0;
  7617. while (ACK_WaitCnt <= 2) //1s
  7618. {
  7619. if (WriteACK == true)
  7620. break;
  7621. }
  7622. if (WriteACK == true)
  7623. {
  7624. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  7625. }
  7626. else
  7627. {
  7628. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令,第2次重发" + "\r\n");
  7629. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  7630. WriteACK = false;
  7631. ACK_WaitCnt = 0;
  7632. while (ACK_WaitCnt <= 2) //1s
  7633. {
  7634. if (WriteACK == true)
  7635. break;
  7636. }
  7637. if (WriteACK == true)
  7638. {
  7639. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  7640. }
  7641. else
  7642. {
  7643. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入失败," + "共" + CmdNum.ToString() + "条指令," + "写入成功" + i.ToString() + "条" + "\r\n");
  7644. label_FacModeStatus.Text = "存在故障!";
  7645. label_FacModeResult.BackColor = Color.Red;
  7646. label_FacModeResult.Text = "测试异常";
  7647. Delay_ms(500);
  7648. //存储异常并上传
  7649. FacMode_Stop(false);
  7650. return;
  7651. }
  7652. }
  7653. }
  7654. }
  7655. //写入完成
  7656. label_FacMode_CfgWrite.BackColor = Color.Green;
  7657. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入成功" + "\r\n");
  7658. Delay_ms(500);
  7659. } while (false);
  7660. }
  7661. else
  7662. {
  7663. label_FacMode_CfgWrite.BackColor = Color.Yellow;
  7664. label_FacModeStatus.Text = "跳过参数写入!";
  7665. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数写入" + "\r\n");
  7666. Delay_ms(500);
  7667. }
  7668. //BMS通讯
  7669. if (checkBox_FacModeBMS.Checked)
  7670. {
  7671. if (label_FacModeBMS.BackColor == Color.Red)
  7672. {
  7673. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "BMS通讯异常" + "\r\n");
  7674. label_FacModeStatus.Text = "存在故障!";
  7675. label_FacModeResult.BackColor = Color.Red;
  7676. label_FacModeResult.Text = "测试异常";
  7677. Delay_ms(500);
  7678. //存储异常并上传
  7679. FacMode_Stop(false);
  7680. return;
  7681. }
  7682. }
  7683. else
  7684. {
  7685. label_FacModeBMS.BackColor = Color.Yellow;
  7686. label_FacModeStatus.Text = "跳过BMS通讯检测!";
  7687. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过BMS通讯检测" + "\r\n");
  7688. Delay_ms(500);
  7689. }
  7690. //基础功能检测
  7691. if (checkBox_FacBaseFucTest.Checked)
  7692. {
  7693. label_FacModeStatus.Text = "基础功能检测";
  7694. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始基础功能检测" + "\r\n");
  7695. //确认负载位置
  7696. if (checkBox_FacMode_MosCal.Checked)
  7697. {
  7698. if (MessageBox.Show("请再次确认负载是否切换回电机?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  7699. {
  7700. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "负载已切换为电机,继续测试" + "\r\n");
  7701. }
  7702. else
  7703. {
  7704. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试取消" + "\r\n");
  7705. label_FacModeStatus.Text = "存在故障!";
  7706. label_FacModeResult.BackColor = Color.Red;
  7707. label_FacModeResult.Text = "测试异常";
  7708. Delay_ms(500);
  7709. //存储异常并上传
  7710. FacMode_Stop(false);
  7711. return;
  7712. }
  7713. }
  7714. //发送指令进入配置模式
  7715. do
  7716. {
  7717. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  7718. Code[0] = 0x01;
  7719. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7720. WriteACK = false;
  7721. ACK_WaitCnt = 0;
  7722. while (ACK_WaitCnt <= 2); //1s
  7723. if (textBox_RunInfo_Vol.Text != "---")
  7724. {
  7725. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7726. }
  7727. else
  7728. {
  7729. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  7730. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7731. ACK_WaitCnt = 0;
  7732. while (ACK_WaitCnt <= 2) ; //1s
  7733. if (textBox_RunInfo_Vol.Text != "---")
  7734. {
  7735. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7736. }
  7737. else
  7738. {
  7739. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7740. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7741. ACK_WaitCnt = 0;
  7742. while (ACK_WaitCnt <= 2) ; //1s
  7743. if (textBox_RunInfo_Vol.Text != "---")
  7744. {
  7745. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7746. }
  7747. else
  7748. {
  7749. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7750. label_FacModeStatus.Text = "存在故障!";
  7751. label_FacModeResult.BackColor = Color.Red;
  7752. label_FacModeResult.Text = "测试异常";
  7753. Delay_ms(500);
  7754. //存储异常并上传
  7755. FacMode_Stop(false);
  7756. return;
  7757. }
  7758. }
  7759. }
  7760. } while (false);
  7761. //发送指令启动电机
  7762. do
  7763. {
  7764. #if false //通过运行模式3启动电机
  7765. //发送指令读取调试信息
  7766. richTextBox_DebugParam.Clear();
  7767. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  7768. WriteACK = false;
  7769. ACK_WaitCnt = 0;
  7770. while (ACK_WaitCnt <= 2); //1s
  7771. //获取调试信息
  7772. string DebugDefaultInfo = "";
  7773. if (richTextBox_DebugParam.Text == string.Empty)
  7774. {
  7775. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
  7776. label_FacModeStatus.Text = "存在故障!";
  7777. label_FacModeResult.BackColor = Color.Red;
  7778. label_FacModeResult.Text = "测试异常";
  7779. Delay_ms(500);
  7780. //存储异常并上传
  7781. FacMode_Stop(false);
  7782. return;
  7783. }
  7784. else
  7785. {
  7786. DebugDefaultInfo = richTextBox_DebugParam.Text;
  7787. }
  7788. //设置模式
  7789. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  7790. strDataTemp[0] = "整体运行模式=3";
  7791. //发送数据
  7792. Code[0] = 0;
  7793. Code[1] = 0;
  7794. for (int i = 0; i < strDataTemp.Length; i++)
  7795. {
  7796. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  7797. Code[2 * i + 2] = (byte)uwDataTemp;
  7798. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  7799. }
  7800. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  7801. label_FacModeStatus.Text = "启动电机";
  7802. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "启动电机" + "\r\n");
  7803. #else //通过Walk模式启动电机
  7804. //设置转速100%
  7805. var Data = new byte[1];
  7806. Data[0] = (byte)100;
  7807. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7808. Delay_ms(500);
  7809. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7810. Delay_ms(500);
  7811. //启动电机进入WALK模式
  7812. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "基础功能检测,进入WALK" + "\r\n");
  7813. Code[0] = 0x22;
  7814. Code[1] = 0xF0;
  7815. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7816. WriteACK = false;
  7817. ACK_WaitCnt = 0;
  7818. while (ACK_WaitCnt <= 2) ; //1s
  7819. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  7820. {
  7821. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第1次重发" + "\r\n");
  7822. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7823. ACK_WaitCnt = 0;
  7824. while (ACK_WaitCnt <= 2) ; //1s
  7825. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  7826. {
  7827. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第2次重发" + "\r\n");
  7828. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7829. ACK_WaitCnt = 0;
  7830. while (ACK_WaitCnt <= 2) ; //1s
  7831. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  7832. {
  7833. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
  7834. label_FacModeStatus.Text = "存在故障!";
  7835. label_FacModeResult.BackColor = Color.Red;
  7836. label_FacModeResult.Text = "测试异常";
  7837. Delay_ms(500);
  7838. //存储异常并上传
  7839. FacMode_Stop(false);
  7840. return;
  7841. }
  7842. }
  7843. }
  7844. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入WALK,开始检测" + "\r\n");
  7845. #endif
  7846. Delay_ms(5000);
  7847. } while (false);
  7848. //判断车速
  7849. if ((Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) <= Convert.ToDouble( toolStripTextBox_ThBikeSpeed.Text.Split(',')[1])) &&
  7850. (Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThBikeSpeed.Text.Split(',')[0])))
  7851. {
  7852. label_FacModeSpeed.BackColor = Color.Green;
  7853. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器正常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
  7854. }
  7855. else
  7856. {
  7857. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器异常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
  7858. label_FacModeStatus.Text = "存在故障!";
  7859. label_FacModeResult.BackColor = Color.Red;
  7860. label_FacModeResult.Text = "测试异常";
  7861. Delay_ms(500);
  7862. //存储异常并上传
  7863. FacMode_Stop(false);
  7864. return;
  7865. }
  7866. //判断电压
  7867. if ((Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[1])) &&
  7868. (Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[0])))
  7869. {
  7870. label_FacModeVolTest.BackColor = Color.Green;
  7871. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量正常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
  7872. }
  7873. else
  7874. {
  7875. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量异常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
  7876. label_FacModeStatus.Text = "存在故障!";
  7877. label_FacModeResult.BackColor = Color.Red;
  7878. label_FacModeResult.Text = "测试异常";
  7879. Delay_ms(500);
  7880. //存储异常并上传
  7881. FacMode_Stop(false);
  7882. return;
  7883. }
  7884. //判断电流
  7885. if ((Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[1])) &&
  7886. (Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[0])))
  7887. {
  7888. label_FacModeCurrentTest.BackColor = Color.Green;
  7889. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量正常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  7890. }
  7891. else
  7892. {
  7893. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量异常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  7894. label_FacModeStatus.Text = "存在故障!";
  7895. label_FacModeResult.BackColor = Color.Red;
  7896. label_FacModeResult.Text = "测试异常";
  7897. Delay_ms(500);
  7898. //存储异常并上传
  7899. FacMode_Stop(false);
  7900. return;
  7901. }
  7902. //判断温度
  7903. if ((Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[1])) &&
  7904. (Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[0])) &&
  7905. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[1])) &&
  7906. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[0])) &&
  7907. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[1])) &&
  7908. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[0])))
  7909. {
  7910. label_FacModeNTC.BackColor = Color.Green;
  7911. 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");
  7912. }
  7913. else
  7914. {
  7915. 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");
  7916. label_FacModeStatus.Text = "存在故障!";
  7917. label_FacModeResult.BackColor = Color.Red;
  7918. label_FacModeResult.Text = "测试异常";
  7919. Delay_ms(500);
  7920. //存储异常并上传
  7921. FacMode_Stop(false);
  7922. return;
  7923. }
  7924. //判断转速
  7925. if ((Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[1])) &&
  7926. (Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[0])))
  7927. {
  7928. label_FacModeMotorSpeed.BackColor = Color.Green;
  7929. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速正常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
  7930. }
  7931. else
  7932. {
  7933. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速异常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
  7934. label_FacModeStatus.Text = "存在故障!";
  7935. label_FacModeResult.BackColor = Color.Red;
  7936. label_FacModeResult.Text = "测试异常";
  7937. Delay_ms(500);
  7938. //存储异常并上传
  7939. FacMode_Stop(false);
  7940. return;
  7941. }
  7942. //中置判断踏频
  7943. if ((中置电机MIGIC_ToolStripMenuItem.Checked == true) || (中置电机VP_ToolStripMenuItem.Checked == true))
  7944. {
  7945. if ((Convert.ToDouble(textBox_RunInfo_Cadence.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[1])) &&
  7946. (Convert.ToDouble(textBox_RunInfo_Cadence.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[0])))
  7947. {
  7948. label_FacModeCad.BackColor = Color.Green;
  7949. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器正常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  7950. }
  7951. else
  7952. {
  7953. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器异常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  7954. label_FacModeStatus.Text = "存在故障!";
  7955. label_FacModeResult.BackColor = Color.Red;
  7956. label_FacModeResult.Text = "测试异常";
  7957. Delay_ms(500);
  7958. //存储异常并上传
  7959. FacMode_Stop(false);
  7960. return;
  7961. }
  7962. }
  7963. //发送指令停止电机
  7964. do
  7965. {
  7966. //设置转速0%
  7967. var Data = new byte[1];
  7968. Data[0] = (byte)0;
  7969. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7970. Delay_ms(500);
  7971. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7972. Delay_ms(500);
  7973. #if false //通过修改调试模式停止电机
  7974. //获取调试信息
  7975. string DebugDefaultInfo = "";
  7976. if (richTextBox_DebugParam.Text == string.Empty)
  7977. {
  7978. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
  7979. label_FacModeStatus.Text = "存在故障!";
  7980. label_FacModeResult.BackColor = Color.Red;
  7981. label_FacModeResult.Text = "测试异常";
  7982. Delay_ms(500);
  7983. //存储异常并上传
  7984. FacMode_Stop(false);
  7985. return;
  7986. }
  7987. else
  7988. {
  7989. DebugDefaultInfo = richTextBox_DebugParam.Text;
  7990. }
  7991. //设置模式
  7992. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  7993. //发送数据
  7994. Code[0] = 0;
  7995. Code[1] = 0;
  7996. for (int i = 0; i < strDataTemp.Length; i++)
  7997. {
  7998. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  7999. Code[2 * i + 2] = (byte)uwDataTemp;
  8000. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  8001. }
  8002. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  8003. label_FacModeStatus.Text = "停止电机";
  8004. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "停止电机" + "\r\n");
  8005. #else //通过调整档位停止电机
  8006. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK" + "\r\n");
  8007. Code[0] = 0x00;
  8008. Code[1] = 0xF0;
  8009. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  8010. WriteACK = false;
  8011. ACK_WaitCnt = 0;
  8012. while (ACK_WaitCnt <= 2) ; //1s
  8013. if (textBox_RunInfo_GearSt.Text != "OFF")
  8014. {
  8015. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK,第1次重发" + "\r\n");
  8016. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  8017. ACK_WaitCnt = 0;
  8018. while (ACK_WaitCnt <= 2) ; //1s
  8019. if (textBox_RunInfo_GearSt.Text != "OFF")
  8020. {
  8021. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK,第2次重发" + "\r\n");
  8022. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  8023. ACK_WaitCnt = 0;
  8024. while (ACK_WaitCnt <= 2) ; //1s
  8025. if (textBox_RunInfo_GearSt.Text != "OFF")
  8026. {
  8027. }
  8028. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
  8029. label_FacModeStatus.Text = "存在故障!";
  8030. label_FacModeResult.BackColor = Color.Red;
  8031. label_FacModeResult.Text = "测试异常";
  8032. Delay_ms(500);
  8033. //存储异常并上传
  8034. FacMode_Stop(false);
  8035. return;
  8036. }
  8037. }
  8038. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已退出WALK,基础功能检测完成" + "\r\n");
  8039. #endif
  8040. Delay_ms(2000);
  8041. } while (false);
  8042. }
  8043. else
  8044. {
  8045. label_FacModeSpeed.BackColor = Color.Yellow;
  8046. label_FacModeVolTest.BackColor = Color.Yellow;
  8047. label_FacModeCurrentTest.BackColor = Color.Yellow;
  8048. label_FacModeNTC.BackColor = Color.Yellow;
  8049. label_FacModeMotorSpeed.BackColor = Color.Yellow;
  8050. label_FacModeStatus.Text = "跳过基础功能检测!";
  8051. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过基础功能检测" + "\r\n");
  8052. Delay_ms(500);
  8053. }
  8054. //力矩检测
  8055. if (checkBox_FacTor.Checked)
  8056. {
  8057. label_FacModeStatus.Text = "力矩传感器检测!";
  8058. //发送指令进入配置模式
  8059. do
  8060. {
  8061. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  8062. {
  8063. break;
  8064. }
  8065. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  8066. Code[0] = 0x01;
  8067. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  8068. WriteACK = false;
  8069. ACK_WaitCnt = 0;
  8070. while (ACK_WaitCnt <= 2) ; //1s
  8071. if (textBox_RunInfo_Vol.Text != "---")
  8072. {
  8073. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  8074. Delay_ms(500);
  8075. }
  8076. else
  8077. {
  8078. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  8079. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  8080. ACK_WaitCnt = 0;
  8081. while (ACK_WaitCnt <= 2) ; //1s
  8082. if (textBox_RunInfo_Vol.Text != "---")
  8083. {
  8084. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  8085. Delay_ms(500);
  8086. }
  8087. else
  8088. {
  8089. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  8090. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  8091. ACK_WaitCnt = 0;
  8092. while (ACK_WaitCnt <= 2) ; //1s
  8093. if (textBox_RunInfo_Vol.Text != "---")
  8094. {
  8095. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  8096. Delay_ms(500);
  8097. }
  8098. else
  8099. {
  8100. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  8101. label_FacModeStatus.Text = "存在故障!";
  8102. label_FacModeResult.BackColor = Color.Red;
  8103. label_FacModeResult.Text = "测试异常";
  8104. Delay_ms(500);
  8105. //存储异常并上传
  8106. FacMode_Stop(false);
  8107. return;
  8108. }
  8109. }
  8110. }
  8111. } while (false);
  8112. ushort Max = 0, Torque = 0;
  8113. //提示输入力矩信号
  8114. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟力矩信号输入" + "\r\n");
  8115. ACK_WaitCnt = 0;
  8116. while (ACK_WaitCnt <= 20) //10s
  8117. {
  8118. //获取力矩值
  8119. Torque = (ushort)Convert.ToInt16(textBox_RunInfo_Torque.Text.Split(' ')[0]);
  8120. if (Torque > Max)
  8121. Max = Torque;
  8122. if ((Max <= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[1])) &&
  8123. (Max >= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[0])) &&
  8124. (ACK_WaitCnt >= 6))
  8125. {
  8126. label_FacModeTq.BackColor = Color.Green;
  8127. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器正常" + " " + textBox_RunInfo_Torque.Text + "\r\n");
  8128. break;
  8129. }
  8130. }
  8131. if (ACK_WaitCnt >= 20)
  8132. {
  8133. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器异常" + " " + textBox_RunInfo_Torque.Text + "\r\n");
  8134. label_FacModeStatus.Text = "存在故障!";
  8135. label_FacModeResult.BackColor = Color.Red;
  8136. label_FacModeResult.Text = "测试异常";
  8137. Delay_ms(500);
  8138. //存储异常并上传
  8139. FacMode_Stop(false);
  8140. return;
  8141. }
  8142. }
  8143. else
  8144. {
  8145. label_FacModeTq.BackColor = Color.Yellow;
  8146. label_FacModeStatus.Text = "跳过力矩检测!";
  8147. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过力矩检测" + "\r\n");
  8148. Delay_ms(500);
  8149. }
  8150. //踏频检测
  8151. if (checkBox_FacCad.Checked)
  8152. {
  8153. if ((中置电机MIGIC_ToolStripMenuItem.Checked == true) || (中置电机VP_ToolStripMenuItem.Checked == true))
  8154. {
  8155. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "中置电机不重复检测踏频" + "\r\n");
  8156. }
  8157. else
  8158. {
  8159. label_FacModeStatus.Text = "踏频传感器检测!";
  8160. //发送指令进入配置模式
  8161. do
  8162. {
  8163. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  8164. {
  8165. break;
  8166. }
  8167. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  8168. Code[0] = 0x01;
  8169. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  8170. WriteACK = false;
  8171. ACK_WaitCnt = 0;
  8172. while (ACK_WaitCnt <= 2) ; //1s
  8173. if (textBox_RunInfo_Vol.Text != "---")
  8174. {
  8175. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  8176. Delay_ms(500);
  8177. }
  8178. else
  8179. {
  8180. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  8181. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  8182. ACK_WaitCnt = 0;
  8183. while (ACK_WaitCnt <= 2) ; //1s
  8184. if (textBox_RunInfo_Vol.Text != "---")
  8185. {
  8186. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  8187. Delay_ms(500);
  8188. }
  8189. else
  8190. {
  8191. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  8192. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  8193. ACK_WaitCnt = 0;
  8194. while (ACK_WaitCnt <= 2) ; //1s
  8195. if (textBox_RunInfo_Vol.Text != "---")
  8196. {
  8197. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  8198. Delay_ms(500);
  8199. }
  8200. else
  8201. {
  8202. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  8203. label_FacModeStatus.Text = "存在故障!";
  8204. label_FacModeResult.BackColor = Color.Red;
  8205. label_FacModeResult.Text = "测试异常";
  8206. Delay_ms(500);
  8207. //存储异常并上传
  8208. FacMode_Stop(false);
  8209. return;
  8210. }
  8211. }
  8212. }
  8213. } while (false);
  8214. ushort Max = 0, Cadence = 0;
  8215. //提示输入踏频信号
  8216. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟踏频信号输入" + "\r\n");
  8217. ACK_WaitCnt = 0;
  8218. while (ACK_WaitCnt <= 20) //10s
  8219. {
  8220. //获取踏频
  8221. Cadence = (ushort)Convert.ToInt16(textBox_RunInfo_Cadence.Text.Split(' ')[0]);
  8222. if (Cadence > Max)
  8223. Max = Cadence;
  8224. if ((Max <= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[1])) &&
  8225. (Max >= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[0])) &&
  8226. (ACK_WaitCnt >= 6)) //3s内有踏频值达到阈值
  8227. {
  8228. label_FacModeCad.BackColor = Color.Green;
  8229. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器正常" + " " + Max.ToString() + " rpm" + "\r\n");
  8230. break;
  8231. }
  8232. }
  8233. if (ACK_WaitCnt >= 20)
  8234. {
  8235. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器异常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  8236. label_FacModeStatus.Text = "存在故障!";
  8237. label_FacModeResult.BackColor = Color.Red;
  8238. label_FacModeResult.Text = "测试异常";
  8239. Delay_ms(500);
  8240. //存储异常并上传
  8241. FacMode_Stop(false);
  8242. return;
  8243. }
  8244. }
  8245. }
  8246. else
  8247. {
  8248. label_FacModeCad.BackColor = Color.Yellow;
  8249. label_FacModeStatus.Text = "跳过踏频检测!";
  8250. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过踏频检测" + "\r\n");
  8251. Delay_ms(500);
  8252. }
  8253. //转把检测
  8254. if (checkBox_FacThrrotleTest.Checked)
  8255. {
  8256. label_FacModeStatus.Text = "转把检测";
  8257. //发送指令进入配置模式
  8258. do
  8259. {
  8260. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  8261. {
  8262. break;
  8263. }
  8264. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  8265. Code[0] = 0x01;
  8266. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  8267. WriteACK = false;
  8268. ACK_WaitCnt = 0;
  8269. while (ACK_WaitCnt <= 2) ; //1s
  8270. if (textBox_RunInfo_Vol.Text != "---")
  8271. {
  8272. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  8273. Delay_ms(500);
  8274. }
  8275. else
  8276. {
  8277. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  8278. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  8279. ACK_WaitCnt = 0;
  8280. while (ACK_WaitCnt <= 2) ; //1s
  8281. if (textBox_RunInfo_Vol.Text != "---")
  8282. {
  8283. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  8284. Delay_ms(500);
  8285. }
  8286. else
  8287. {
  8288. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  8289. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  8290. ACK_WaitCnt = 0;
  8291. while (ACK_WaitCnt <= 2) ; //1s
  8292. if (textBox_RunInfo_Vol.Text != "---")
  8293. {
  8294. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  8295. Delay_ms(500);
  8296. }
  8297. else
  8298. {
  8299. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  8300. label_FacModeStatus.Text = "存在故障!";
  8301. label_FacModeResult.BackColor = Color.Red;
  8302. label_FacModeResult.Text = "测试异常";
  8303. Delay_ms(500);
  8304. //存储异常并上传
  8305. FacMode_Stop(false);
  8306. return;
  8307. }
  8308. }
  8309. }
  8310. } while (false);
  8311. //进入TURBO档
  8312. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把检测,发送指令进入TURBO" + "\r\n");
  8313. Code[0] = 0x04;
  8314. Code[1] = 0xF0;
  8315. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  8316. WriteACK = false;
  8317. ACK_WaitCnt = 0;
  8318. while (ACK_WaitCnt <= 2) ; //1s
  8319. if (textBox_RunInfo_GearSt.Text != "TURBO")
  8320. {
  8321. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO,第1次重发" + "\r\n");
  8322. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  8323. ACK_WaitCnt = 0;
  8324. while (ACK_WaitCnt <= 2) ; //1s
  8325. if (textBox_RunInfo_GearSt.Text != "TURBO")
  8326. {
  8327. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO,第2次重发" + "\r\n");
  8328. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  8329. ACK_WaitCnt = 0;
  8330. while (ACK_WaitCnt <= 2) ; //1s
  8331. if (textBox_RunInfo_GearSt.Text != "TURBO")
  8332. {
  8333. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO异常" + "\r\n");
  8334. label_FacModeStatus.Text = "存在故障!";
  8335. label_FacModeResult.BackColor = Color.Red;
  8336. label_FacModeResult.Text = "测试异常";
  8337. Delay_ms(500);
  8338. //存储异常并上传
  8339. FacMode_Stop(false);
  8340. return;
  8341. }
  8342. }
  8343. }
  8344. //进入TURBO后,如果电机直接启动,认为转把电压异常
  8345. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把自检,请松开转把" + "\r\n");
  8346. Delay_ms(3000);
  8347. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) > 500)
  8348. {
  8349. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把电压异常" + "\r\n");
  8350. label_FacModeStatus.Text = "存在故障!";
  8351. label_FacModeResult.BackColor = Color.Red;
  8352. label_FacModeResult.Text = "测试异常";
  8353. Delay_ms(500);
  8354. //存储异常并上传
  8355. FacMode_Stop(false);
  8356. return;
  8357. }
  8358. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把自检正常" + "\r\n");
  8359. Delay_ms(500);
  8360. //提示转动转把
  8361. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入TURBO,10s内转动转把" + "\r\n");
  8362. ACK_WaitCnt = 0;
  8363. while (ACK_WaitCnt <= 20)
  8364. {
  8365. if ((Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) > 500) && (ACK_WaitCnt >= 10)) //5s
  8366. {
  8367. label_FacModeGas.BackColor = Color.Green;
  8368. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能正常,电机转速:" + textBox_RunInfo_MotorSpeed.Text + ",请松开转把" + "\r\n");
  8369. break;
  8370. }
  8371. }
  8372. if (ACK_WaitCnt >= 20) //转把超时
  8373. {
  8374. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能异常,请松开转把" + "\r\n");
  8375. label_FacModeStatus.Text = "存在故障!";
  8376. label_FacModeResult.BackColor = Color.Red;
  8377. label_FacModeResult.Text = "测试异常";
  8378. Delay_ms(500);
  8379. //存储异常并上传
  8380. FacMode_Stop(false);
  8381. return;
  8382. }
  8383. }
  8384. else
  8385. {
  8386. label_FacModeGas.BackColor = Color.Yellow;
  8387. label_FacModeStatus.Text = "跳过转把检测!";
  8388. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过转把检测" + "\r\n");
  8389. Delay_ms(500);
  8390. }
  8391. //刹车检测
  8392. if (checkBox_FacBreakTest.Checked)
  8393. {
  8394. label_FacModeStatus.Text = "刹把检测";
  8395. //发送指令进入配置模式
  8396. do
  8397. {
  8398. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  8399. {
  8400. break;
  8401. }
  8402. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  8403. Code[0] = 0x01;
  8404. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  8405. WriteACK = false;
  8406. ACK_WaitCnt = 0;
  8407. while (ACK_WaitCnt <= 2) ; //1s
  8408. if (textBox_RunInfo_Vol.Text != "---")
  8409. {
  8410. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  8411. Delay_ms(500);
  8412. }
  8413. else
  8414. {
  8415. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  8416. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  8417. ACK_WaitCnt = 0;
  8418. while (ACK_WaitCnt <= 2) ; //1s
  8419. if (textBox_RunInfo_Vol.Text != "---")
  8420. {
  8421. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  8422. Delay_ms(500);
  8423. }
  8424. else
  8425. {
  8426. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  8427. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  8428. ACK_WaitCnt = 0;
  8429. while (ACK_WaitCnt <= 2) ; //1s
  8430. if (textBox_RunInfo_Vol.Text != "---")
  8431. {
  8432. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  8433. Delay_ms(500);
  8434. }
  8435. else
  8436. {
  8437. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  8438. label_FacModeStatus.Text = "存在故障!";
  8439. label_FacModeResult.BackColor = Color.Red;
  8440. label_FacModeResult.Text = "测试异常";
  8441. Delay_ms(500);
  8442. //存储异常并上传
  8443. FacMode_Stop(false);
  8444. return;
  8445. }
  8446. }
  8447. }
  8448. } while (false);
  8449. //测试前先确定电机已停止
  8450. UInt16 WaitTime = 20;
  8451. do
  8452. {
  8453. WaitTime--;
  8454. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 100)
  8455. {
  8456. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机停止,开始进行剎把检测,进入WALK" + "\r\n");
  8457. break;
  8458. }
  8459. if (WaitTime == 0)
  8460. {
  8461. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机无法停止,剎把检测异常" + "\r\n");
  8462. label_FacModeStatus.Text = "存在故障!";
  8463. label_FacModeResult.BackColor = Color.Red;
  8464. label_FacModeResult.Text = "测试异常";
  8465. Delay_ms(500);
  8466. //存储异常并上传
  8467. FacMode_Stop(false);
  8468. return;
  8469. }
  8470. Delay_ms(500);
  8471. } while (true);
  8472. //设置转速100%
  8473. var Data = new byte[1];
  8474. Data[0] = (byte)100;
  8475. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  8476. Delay_ms(500);
  8477. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  8478. Delay_ms(500);
  8479. //启动电机进入WALK模式
  8480. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把检测,进入WALK" + "\r\n");
  8481. Code[0] = 0x22;
  8482. Code[1] = 0xF0;
  8483. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  8484. WriteACK = false;
  8485. ACK_WaitCnt = 0;
  8486. while (ACK_WaitCnt <= 2) ; //1s
  8487. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 500))
  8488. {
  8489. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第1次重发" + "\r\n");
  8490. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  8491. ACK_WaitCnt = 0;
  8492. while (ACK_WaitCnt <= 2) ; //1s
  8493. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 500))
  8494. {
  8495. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第2次重发" + "\r\n");
  8496. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  8497. ACK_WaitCnt = 0;
  8498. while (ACK_WaitCnt <= 2) ; //1s
  8499. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 500))
  8500. {
  8501. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
  8502. label_FacModeStatus.Text = "存在故障!";
  8503. label_FacModeResult.BackColor = Color.Red;
  8504. label_FacModeResult.Text = "测试异常";
  8505. Delay_ms(500);
  8506. //存储异常并上传
  8507. FacMode_Stop(false);
  8508. return;
  8509. }
  8510. }
  8511. }
  8512. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,10s内操作剎把" + "\r\n");
  8513. ACK_WaitCnt = 0;
  8514. while (ACK_WaitCnt <= 20)
  8515. {
  8516. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 100)
  8517. {
  8518. label_FacModeBreak.BackColor = Color.Green;
  8519. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把功能正常,松开剎把" + "\r\n");
  8520. break;
  8521. }
  8522. }
  8523. if (ACK_WaitCnt >= 20) //剎把超时
  8524. {
  8525. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速:" + textBox_RunInfo_MotorSpeed.Text + "," + "剎把功能异常,松开剎把" + "\r\n");
  8526. label_FacModeStatus.Text = "存在故障!";
  8527. label_FacModeResult.BackColor = Color.Red;
  8528. label_FacModeResult.Text = "测试异常";
  8529. Delay_ms(500);
  8530. //存储异常并上传
  8531. FacMode_Stop(false);
  8532. return;
  8533. }
  8534. //停止电机
  8535. Code[0] = 0x00;
  8536. Code[1] = 0xF0;
  8537. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  8538. WriteACK = false;
  8539. ACK_WaitCnt = 0;
  8540. while (ACK_WaitCnt <= 2) ; //1s
  8541. if (textBox_RunInfo_GearSt.Text != "OFF")
  8542. {
  8543. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK,第1次重发" + "\r\n");
  8544. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  8545. ACK_WaitCnt = 0;
  8546. while (ACK_WaitCnt <= 2) ; //1s
  8547. if (textBox_RunInfo_GearSt.Text != "OFF")
  8548. {
  8549. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK,第2次重发" + "\r\n");
  8550. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  8551. ACK_WaitCnt = 0;
  8552. while (ACK_WaitCnt <= 2) ; //1s
  8553. if (textBox_RunInfo_GearSt.Text != "OFF")
  8554. {
  8555. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
  8556. label_FacModeStatus.Text = "存在故障!";
  8557. label_FacModeResult.BackColor = Color.Red;
  8558. label_FacModeResult.Text = "测试异常";
  8559. Delay_ms(500);
  8560. //存储异常并上传
  8561. FacMode_Stop(false);
  8562. return;
  8563. }
  8564. }
  8565. }
  8566. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK" + "\r\n");
  8567. Delay_ms(500);
  8568. }
  8569. else
  8570. {
  8571. label_FacModeBreak.BackColor = Color.Yellow;
  8572. label_FacModeStatus.Text = "跳过刹车检测!";
  8573. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过刹车检测" + "\r\n");
  8574. Delay_ms(500);
  8575. }
  8576. //前后灯检测
  8577. if (checkBox_FacLightTest.Checked)
  8578. {
  8579. //前后灯检测
  8580. label_FacModeStatus.Text = "前后灯检测";
  8581. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开灯指令" + "\r\n");
  8582. //发送指令打开车灯
  8583. Code[0] = 0x00;
  8584. Code[1] = 0xF1;
  8585. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  8586. WriteACK = false;
  8587. ACK_WaitCnt = 0;
  8588. while (ACK_WaitCnt <= 2) ; //1s
  8589. if (textBox_RunInfo_LightSwitch.Text != "ON")
  8590. {
  8591. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令,第1次重发" + "\r\n");
  8592. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  8593. ACK_WaitCnt = 0;
  8594. while (ACK_WaitCnt <= 2); //1s
  8595. if (textBox_RunInfo_LightSwitch.Text != "ON")
  8596. {
  8597. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令,第2次重发" + "\r\n");
  8598. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  8599. ACK_WaitCnt = 0;
  8600. while (ACK_WaitCnt <= 2) ; //1s
  8601. if (textBox_RunInfo_LightSwitch.Text != "ON")
  8602. {
  8603. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令发送异常" + "\r\n");
  8604. label_FacModeStatus.Text = "存在故障!";
  8605. label_FacModeResult.BackColor = Color.Red;
  8606. label_FacModeResult.Text = "测试异常";
  8607. Delay_ms(500);
  8608. //存储异常并上传
  8609. FacMode_Stop(false);
  8610. return;
  8611. }
  8612. }
  8613. }
  8614. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已打开前后灯" + "\r\n");
  8615. Delay_ms(500);
  8616. //提示检查灯压是否正确
  8617. if (MessageBox.Show("前后灯是否正常开启?", "前后灯判断", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  8618. {
  8619. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯开启正常" + "\r\n");
  8620. Delay_ms(500);
  8621. }
  8622. else
  8623. {
  8624. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯开启异常" + "\r\n");
  8625. label_FacModeStatus.Text = "存在故障!";
  8626. label_FacModeResult.BackColor = Color.Red;
  8627. label_FacModeResult.Text = "测试异常";
  8628. Delay_ms(500);
  8629. //存储异常并上传
  8630. FacMode_Stop(false);
  8631. return;
  8632. }
  8633. //发送指令关闭车灯
  8634. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关灯指令" + "\r\n");
  8635. Code[0] = 0x00;
  8636. Code[1] = 0xF0;
  8637. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  8638. WriteACK = false;
  8639. ACK_WaitCnt = 0;
  8640. while (ACK_WaitCnt <= 2) ; //1s
  8641. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  8642. {
  8643. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令,第1次重发" + "\r\n");
  8644. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  8645. ACK_WaitCnt = 0;
  8646. while (ACK_WaitCnt <= 2) ; //1s
  8647. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  8648. {
  8649. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令,第2次重发" + "\r\n");
  8650. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  8651. ACK_WaitCnt = 0;
  8652. while (ACK_WaitCnt <= 2) ; //1s
  8653. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  8654. {
  8655. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令发送异常" + "\r\n");
  8656. label_FacModeStatus.Text = "存在故障!";
  8657. label_FacModeResult.BackColor = Color.Red;
  8658. label_FacModeResult.Text = "测试异常";
  8659. Delay_ms(500);
  8660. //存储异常并上传
  8661. FacMode_Stop(false);
  8662. return;
  8663. }
  8664. }
  8665. }
  8666. //提示检查灯压是否关闭
  8667. if (MessageBox.Show("前后灯是否正常关闭?", "前后灯判断", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  8668. {
  8669. label_FacModeLightF.BackColor = Color.Green;
  8670. label_FacModeLightB.BackColor = Color.Green;
  8671. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯关闭正常" + "\r\n");
  8672. Delay_ms(500);
  8673. }
  8674. else
  8675. {
  8676. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯关闭异常" + "\r\n");
  8677. label_FacModeStatus.Text = "存在故障!";
  8678. label_FacModeResult.BackColor = Color.Red;
  8679. label_FacModeResult.Text = "测试异常";
  8680. Delay_ms(500);
  8681. //存储异常并上传
  8682. FacMode_Stop(false);
  8683. return;
  8684. }
  8685. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已关闭前后灯" + "\r\n");
  8686. }
  8687. else
  8688. {
  8689. label_FacModeLightF.BackColor = Color.Yellow;
  8690. label_FacModeLightB.BackColor = Color.Yellow;
  8691. label_FacModeStatus.Text = "跳过前后灯检测!";
  8692. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过前后灯检测" + "\r\n");
  8693. Delay_ms(500);
  8694. }
  8695. //软件版本检测
  8696. do
  8697. {
  8698. label_FacModeStatus.Text = "软件版本确认";
  8699. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  8700. //发送指令读取版本
  8701. Class_Motor_Ver.Mode = "---";
  8702. Class_Motor_Ver.SN = "---";
  8703. Class_Motor_Ver.HW = "---";
  8704. Class_Motor_Ver.FW = "---";
  8705. Class_Motor_Ver.Special = "---";
  8706. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  8707. ACK_WaitCnt = 0;
  8708. while (ACK_WaitCnt <= 2) ; //1s
  8709. if (Class_Motor_Ver.Mode == "---")
  8710. {
  8711. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第1次重发" + "\r\n");
  8712. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  8713. ACK_WaitCnt = 0;
  8714. while (ACK_WaitCnt <= 2) ; //1s
  8715. if (Class_Motor_Ver.Mode == "---")
  8716. {
  8717. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第2次重发" + "\r\n");
  8718. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  8719. ACK_WaitCnt = 0;
  8720. while (ACK_WaitCnt <= 2) ; //1s
  8721. if (Class_Motor_Ver.Mode == "---")
  8722. {
  8723. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息失败" + "\r\n");
  8724. label_FacModeStatus.Text = "存在故障!";
  8725. label_FacModeResult.BackColor = Color.Red;
  8726. label_FacModeResult.Text = "测试异常";
  8727. Delay_ms(500);
  8728. //存储异常并上传
  8729. FacMode_Stop(false);
  8730. return;
  8731. }
  8732. }
  8733. }
  8734. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  8735. richTextBox_FacModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  8736. richTextBox_FacModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  8737. richTextBox_FacModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  8738. richTextBox_FacModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  8739. richTextBox_FacModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  8740. //判断版本是否正确
  8741. if (样机测试ToolStripMenuItem.Checked == true)
  8742. {
  8743. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "样机测试,不检测软件版本" + "\r\n");
  8744. label_FacModeFWVersion.BackColor = Color.Yellow;
  8745. break;
  8746. }
  8747. string VerCheck = "";
  8748. try
  8749. {
  8750. VerCheck = comboBox_FacModeCfgFile.Text.Split('_')[3] + "_" + comboBox_FacModeCfgFile.Text.Split('_')[4];
  8751. }
  8752. catch (System.Exception)
  8753. {
  8754. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "配置文件名格式错误" + "\r\n");
  8755. label_FacModeStatus.Text = "存在故障!";
  8756. label_FacModeResult.BackColor = Color.Red;
  8757. label_FacModeResult.Text = "测试异常";
  8758. Delay_ms(500);
  8759. //存储异常并上传
  8760. FacMode_Stop(false);
  8761. return;
  8762. }
  8763. string VerRead = "";
  8764. try
  8765. {
  8766. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  8767. }
  8768. catch (System.Exception)
  8769. {
  8770. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  8771. label_FacModeStatus.Text = "存在故障!";
  8772. label_FacModeResult.BackColor = Color.Red;
  8773. label_FacModeResult.Text = "测试异常";
  8774. Delay_ms(500);
  8775. //存储异常并上传
  8776. FacMode_Stop(false);
  8777. return;
  8778. }
  8779. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  8780. {
  8781. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误:" + VerRead + ",正确版本为:" + VerCheck + "\r\n");
  8782. label_FacModeStatus.Text = "存在故障!";
  8783. label_FacModeResult.BackColor = Color.Red;
  8784. label_FacModeResult.Text = "测试异常";
  8785. Delay_ms(500);
  8786. //存储异常并上传
  8787. FacMode_Stop(false);
  8788. return;
  8789. }
  8790. label_FacModeFWVersion.BackColor = Color.Green;
  8791. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  8792. Delay_ms(500);
  8793. } while (false);
  8794. //测试合格
  8795. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  8796. label_FacModeStatus.Text = "测试结束!";
  8797. label_FacModeResult.BackColor = Color.Green;
  8798. label_FacModeResult.Text = "测试合格";
  8799. Delay_ms(500);
  8800. //存储并上传
  8801. FacMode_Stop(true);
  8802. return;
  8803. }
  8804. private void FacModelLabelInit()
  8805. {
  8806. //测试状态标签
  8807. label_FacModeResult.BackColor = Color.Yellow;
  8808. label_FacModeResult.Text = "测试中";
  8809. //测试过程标签
  8810. label_FacModeStatus.Text = "测试就绪";
  8811. //测试结果标签
  8812. foreach (Control c in groupBox28.Controls)
  8813. {
  8814. if (c is Label)
  8815. {
  8816. if (c.Text == string.Empty)
  8817. c.BackColor = Color.Red;
  8818. }
  8819. }
  8820. }
  8821. private void comboBox_CheckModeCfgDate_Click(object sender, EventArgs e)
  8822. {
  8823. //更新生产配置文件目录
  8824. GetDateList(false);
  8825. }
  8826. private void comboBox_FacModeCfgDate_Click(object sender, EventArgs e)
  8827. {
  8828. //更新生产配置文件目录
  8829. GetDateList(false);
  8830. }
  8831. private void richTextBox_FacModeLog_TextChanged(object sender, EventArgs e)
  8832. {
  8833. richTextBox_FacModeLog.SelectionStart = richTextBox_FacModeLog.Text.Length;
  8834. richTextBox_FacModeLog.ScrollToCaret();
  8835. }
  8836. /// <summary>
  8837. /// 参数检验测试停止
  8838. /// </summary>
  8839. /// <param name="OK_Flag"></param>
  8840. private void CheckMode_Stop(bool OK_Flag)
  8841. {
  8842. //打开开始按钮
  8843. button_CheckModeStart.Enabled = true;
  8844. textBox_CheckModeScan.Enabled = true;
  8845. //导出电机参数
  8846. string Params = "";
  8847. do
  8848. {
  8849. if (!OK_Flag)
  8850. {
  8851. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试异常,不导出参数" + "\r\n");
  8852. break;
  8853. }
  8854. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "导出电机存储参数" + "\r\n");
  8855. //读取一次马达参数
  8856. richTextBox_MotorParam.Clear();
  8857. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break;
  8858. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 1 次读马达参数" + "\r\n");
  8859. ACK_WaitCnt = 0;
  8860. while (ACK_WaitCnt <= 2) //1s
  8861. {
  8862. if (richTextBox_MotorParam.Text != string.Empty)
  8863. break;
  8864. }
  8865. if (richTextBox_MotorParam.Text == string.Empty)
  8866. {
  8867. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break;
  8868. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 2 次读马达参数" + "\r\n");
  8869. ACK_WaitCnt = 0;
  8870. while (ACK_WaitCnt <= 2) //1s
  8871. {
  8872. if (richTextBox_MotorParam.Text != string.Empty)
  8873. break;
  8874. }
  8875. if (richTextBox_MotorParam.Text == string.Empty)
  8876. {
  8877. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break;
  8878. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 3 次读马达参数" + "\r\n");
  8879. ACK_WaitCnt = 0;
  8880. while (ACK_WaitCnt <= 2) //1s
  8881. {
  8882. if (richTextBox_MotorParam.Text != string.Empty)
  8883. break;
  8884. }
  8885. }
  8886. }
  8887. Params += "[马达参数]" + "\r\n" + richTextBox_MotorParam.Text + "\r\n";
  8888. Params += "\r\n";
  8889. //读取一次整车参数
  8890. richTextBox_BikeParam.Clear();
  8891. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  8892. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 1 次读整车参数" + "\r\n");
  8893. ACK_WaitCnt = 0;
  8894. while (ACK_WaitCnt <= 2) //1s
  8895. {
  8896. if (richTextBox_BikeParam.Text != string.Empty)
  8897. break;
  8898. }
  8899. if (richTextBox_BikeParam.Text == string.Empty)
  8900. {
  8901. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  8902. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 2 次读整车参数" + "\r\n");
  8903. ACK_WaitCnt = 0;
  8904. while (ACK_WaitCnt <= 2) //1s
  8905. {
  8906. if (richTextBox_BikeParam.Text != string.Empty)
  8907. break;
  8908. }
  8909. if (richTextBox_BikeParam.Text == string.Empty)
  8910. {
  8911. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  8912. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 3 次读整车参数" + "\r\n");
  8913. ACK_WaitCnt = 0;
  8914. while (ACK_WaitCnt <= 2) //1s
  8915. {
  8916. if (richTextBox_BikeParam.Text != string.Empty)
  8917. break;
  8918. }
  8919. }
  8920. }
  8921. Params += "[整车参数]" + "\r\n" + richTextBox_BikeParam.Text + "\r\n";
  8922. Params += "\r\n";
  8923. //读取一次控制参数
  8924. richTextBox_ControlParam.Clear();
  8925. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  8926. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 1 次读控制参数" + "\r\n");
  8927. ACK_WaitCnt = 0;
  8928. while (ACK_WaitCnt <= 2) //1s
  8929. {
  8930. if (richTextBox_ControlParam.Text != string.Empty)
  8931. break;
  8932. }
  8933. if (richTextBox_ControlParam.Text == string.Empty)
  8934. {
  8935. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  8936. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 2 次读控制参数" + "\r\n");
  8937. ACK_WaitCnt = 0;
  8938. while (ACK_WaitCnt <= 2) //1s
  8939. {
  8940. if (richTextBox_ControlParam.Text != string.Empty)
  8941. break;
  8942. }
  8943. if (richTextBox_ControlParam.Text == string.Empty)
  8944. {
  8945. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  8946. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 3 次读控制参数" + "\r\n");
  8947. ACK_WaitCnt = 0;
  8948. while (ACK_WaitCnt <= 2) //1s
  8949. {
  8950. if (richTextBox_ControlParam.Text != string.Empty)
  8951. break;
  8952. }
  8953. }
  8954. }
  8955. Params += "[控制参数]" + "\r\n" + richTextBox_ControlParam.Text + "\r\n";
  8956. Params += "\r\n";
  8957. //查询传感器
  8958. richTextBox_SensorParam.Clear();
  8959. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  8960. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 1 次读传感器信息" + "\r\n");
  8961. ACK_WaitCnt = 0;
  8962. while (ACK_WaitCnt <= 2) //1s
  8963. {
  8964. if (richTextBox_SensorParam.Text != string.Empty)
  8965. break;
  8966. }
  8967. if (richTextBox_SensorParam.Text == string.Empty)
  8968. {
  8969. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  8970. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 2 次读传感器信息" + "\r\n");
  8971. ACK_WaitCnt = 0;
  8972. while (ACK_WaitCnt <= 2) //1s
  8973. {
  8974. if (richTextBox_SensorParam.Text != string.Empty)
  8975. break;
  8976. }
  8977. if (richTextBox_SensorParam.Text == string.Empty)
  8978. {
  8979. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  8980. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 3 次读传感器信息" + "\r\n");
  8981. ACK_WaitCnt = 0;
  8982. while (ACK_WaitCnt <= 2) //1s
  8983. {
  8984. if (richTextBox_SensorParam.Text != string.Empty)
  8985. break;
  8986. }
  8987. }
  8988. }
  8989. Params += "[传感器参数]" + "\r\n" + richTextBox_SensorParam.Text + "\r\n";
  8990. Params += "\r\n";
  8991. //读取15次助力参数
  8992. Params += "[助力参数]" + "\r\n";
  8993. for (int i = 1; i <= 15; i++)
  8994. {
  8995. var ConfigParam = new byte[4];
  8996. richTextBox_AssistParam.Clear();
  8997. ConfigParam[0] = (byte)(i & 0xFF);
  8998. ConfigParam[1] = (byte)(i >> 8);
  8999. ConfigParam[2] = (byte)(((i >= 5) ? 5 : i) & 0xFF);
  9000. ConfigParam[3] = (byte)(((i >= 5) ? 5 : i) >> 8);
  9001. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  9002. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 1 次读助力参数 " + i.ToString() + "\r\n");
  9003. ACK_WaitCnt = 0;
  9004. while (ACK_WaitCnt <= 2) //1s
  9005. {
  9006. if (richTextBox_AssistParam.Text != string.Empty)
  9007. break;
  9008. }
  9009. if (richTextBox_AssistParam.Text == string.Empty)
  9010. {
  9011. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  9012. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 2 次读助力参数 " + i.ToString() + "\r\n");
  9013. ACK_WaitCnt = 0;
  9014. while (ACK_WaitCnt <= 2) //1s
  9015. {
  9016. if (richTextBox_AssistParam.Text != string.Empty)
  9017. break;
  9018. }
  9019. if (richTextBox_AssistParam.Text == string.Empty)
  9020. {
  9021. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  9022. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 3 次读助力参数 " + i.ToString() + "\r\n");
  9023. ACK_WaitCnt = 0;
  9024. while (ACK_WaitCnt <= 2) //1s
  9025. {
  9026. if (richTextBox_AssistParam.Text != string.Empty)
  9027. break;
  9028. }
  9029. }
  9030. }
  9031. Params += richTextBox_AssistParam.Text + "\r\n";
  9032. Params += "\r\n";
  9033. }
  9034. //读取一次调试信息
  9035. richTextBox_DebugParam.Clear();
  9036. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  9037. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 1 次读调试信息" + "\r\n");
  9038. ACK_WaitCnt = 0;
  9039. while (ACK_WaitCnt <= 2) //1s
  9040. {
  9041. if (richTextBox_DebugParam.Text != string.Empty)
  9042. break;
  9043. }
  9044. if (richTextBox_DebugParam.Text == string.Empty)
  9045. {
  9046. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  9047. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 2 次读调试信息" + "\r\n");
  9048. ACK_WaitCnt = 0;
  9049. while (ACK_WaitCnt <= 2) //1s
  9050. {
  9051. if (richTextBox_DebugParam.Text != string.Empty)
  9052. break;
  9053. }
  9054. if (richTextBox_DebugParam.Text == string.Empty)
  9055. {
  9056. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  9057. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 3 次读调试信息" + "\r\n");
  9058. ACK_WaitCnt = 0;
  9059. while (ACK_WaitCnt <= 2) //1s
  9060. {
  9061. if (richTextBox_DebugParam.Text != string.Empty)
  9062. break;
  9063. }
  9064. }
  9065. }
  9066. Params += "[调试参数]" + "\r\n" + richTextBox_DebugParam.Text + "\r\n";
  9067. Params += "\r\n";
  9068. //读取一次历史信息
  9069. richTextBox_Record.Clear();
  9070. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  9071. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 1 次读历史信息" + "\r\n");
  9072. ACK_WaitCnt = 0;
  9073. while (ACK_WaitCnt <= 2) //1s
  9074. {
  9075. if (richTextBox_Record.Text != string.Empty)
  9076. break;
  9077. }
  9078. if (richTextBox_Record.Text == string.Empty)
  9079. {
  9080. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  9081. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 2 次读历史信息" + "\r\n");
  9082. ACK_WaitCnt = 0;
  9083. while (ACK_WaitCnt <= 2) //1s
  9084. {
  9085. if (richTextBox_Record.Text != string.Empty)
  9086. break;
  9087. }
  9088. if (richTextBox_Record.Text == string.Empty)
  9089. {
  9090. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  9091. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 3 次读历史信息" + "\r\n");
  9092. ACK_WaitCnt = 0;
  9093. while (ACK_WaitCnt <= 2) //1s
  9094. {
  9095. if (richTextBox_Record.Text != string.Empty)
  9096. break;
  9097. }
  9098. }
  9099. }
  9100. Params += "[历史信息]" + "\r\n" + richTextBox_Record.Text + "\r\n";
  9101. Params += "\r\n";
  9102. //读取一次MOS内阻校准参数
  9103. foreach (Control c in groupBox21.Controls)
  9104. {
  9105. if (c is TextBox)
  9106. c.Text = "";
  9107. }
  9108. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  9109. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 1 次读MOS内阻校准参数" + "\r\n");
  9110. ACK_WaitCnt = 0;
  9111. while (ACK_WaitCnt <= 2) //1s
  9112. {
  9113. if (textBox_MOS_K1.Text != string.Empty)
  9114. break;
  9115. }
  9116. if (textBox_MOS_K1.Text == string.Empty)
  9117. {
  9118. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null)) break;
  9119. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 2 次读MOS内阻校准参数" + "\r\n");
  9120. ACK_WaitCnt = 0;
  9121. while (ACK_WaitCnt <= 2) //1s
  9122. {
  9123. if (textBox_MOS_K1.Text != string.Empty)
  9124. break;
  9125. }
  9126. if (textBox_MOS_K1.Text == string.Empty)
  9127. {
  9128. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null)) break;
  9129. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 3 次读MOS内阻校准参数" + "\r\n");
  9130. ACK_WaitCnt = 0;
  9131. while (ACK_WaitCnt <= 2) //1s
  9132. {
  9133. if (textBox_MOS_K1.Text != string.Empty)
  9134. break;
  9135. }
  9136. }
  9137. }
  9138. Params += "[MOS内阻校准参数]" + "\r\n";
  9139. Params += textBox_MOS_K1.Text + ", " + textBox_MOS_K2.Text + ", " + textBox_MOS_K3.Text + ", " + textBox_MOS_K4.Text + ", "
  9140. + textBox_MOS_K5.Text + ", " + textBox_MOS_R1.Text + ", " + textBox_MOS_R2.Text + ", " + textBox_MOS_R3.Text + ", " + "\r\n";
  9141. Params += "\r\n";
  9142. //读取一次整车参数2
  9143. richTextBox_BikeParam2.Clear();
  9144. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null)) break;
  9145. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 1 次读整车参数2" + "\r\n");
  9146. ACK_WaitCnt = 0;
  9147. while (ACK_WaitCnt <= 2) //1s
  9148. {
  9149. if (richTextBox_BikeParam2.Text != string.Empty)
  9150. break;
  9151. }
  9152. if (richTextBox_BikeParam2.Text == string.Empty)
  9153. {
  9154. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null)) break;
  9155. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 2 次读整车参数2" + "\r\n");
  9156. ACK_WaitCnt = 0;
  9157. while (ACK_WaitCnt <= 2) //1s
  9158. {
  9159. if (richTextBox_BikeParam2.Text != string.Empty)
  9160. break;
  9161. }
  9162. if (richTextBox_BikeParam2.Text == string.Empty)
  9163. {
  9164. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null)) break;
  9165. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 3 次读整车参数2" + "\r\n");
  9166. ACK_WaitCnt = 0;
  9167. while (ACK_WaitCnt <= 2) //1s
  9168. {
  9169. if (richTextBox_BikeParam2.Text != string.Empty)
  9170. break;
  9171. }
  9172. }
  9173. }
  9174. Params += "[整车参数2]" + "\r\n" + richTextBox_BikeParam2.Text + "\r\n";
  9175. Params += "\r\n";
  9176. //读取一次用户骑行参数
  9177. richTextBox_UsrRidesParam.Clear();
  9178. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null)) break;
  9179. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 1 次读用户骑行参数" + "\r\n");
  9180. ACK_WaitCnt = 0;
  9181. while (ACK_WaitCnt <= 2) //1s
  9182. {
  9183. if (richTextBox_UsrRidesParam.Text != string.Empty)
  9184. break;
  9185. }
  9186. if (richTextBox_UsrRidesParam.Text == string.Empty)
  9187. {
  9188. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null)) break;
  9189. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 2 次读用户骑行参数" + "\r\n");
  9190. ACK_WaitCnt = 0;
  9191. while (ACK_WaitCnt <= 2) //1s
  9192. {
  9193. if (richTextBox_UsrRidesParam.Text != string.Empty)
  9194. break;
  9195. }
  9196. if (richTextBox_UsrRidesParam.Text == string.Empty)
  9197. {
  9198. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null)) break;
  9199. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 3 次读用户骑行参数" + "\r\n");
  9200. ACK_WaitCnt = 0;
  9201. while (ACK_WaitCnt <= 2) //1s
  9202. {
  9203. if (richTextBox_UsrRidesParam.Text != string.Empty)
  9204. break;
  9205. }
  9206. }
  9207. }
  9208. Params += "[用户骑行参数]" + "\r\n" + richTextBox_UsrRidesParam.Text + "\r\n";
  9209. Params += "\r\n";
  9210. //读取一次生产信息
  9211. textBox_MAC.Text = "";
  9212. textBox_MACAdd.Text = "";
  9213. textBox_MACDate.Text = "";
  9214. textBox_PP.Text = "";
  9215. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  9216. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 1 次读生产信息" + "\r\n");
  9217. ACK_WaitCnt = 0;
  9218. while (ACK_WaitCnt <= 2) //1s
  9219. {
  9220. if (textBox_MAC.Text != string.Empty)
  9221. break;
  9222. }
  9223. if (textBox_MAC.Text == string.Empty)
  9224. {
  9225. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  9226. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 2 次读生产信息" + "\r\n");
  9227. ACK_WaitCnt = 0;
  9228. while (ACK_WaitCnt <= 2) //1s
  9229. {
  9230. if (textBox_MAC.Text != string.Empty)
  9231. break;
  9232. }
  9233. if (textBox_MAC.Text == string.Empty)
  9234. {
  9235. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  9236. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 3 次读生产信息" + "\r\n");
  9237. ACK_WaitCnt = 0;
  9238. while (ACK_WaitCnt <= 2) //1s
  9239. {
  9240. if (textBox_MAC.Text != string.Empty)
  9241. break;
  9242. }
  9243. }
  9244. }
  9245. Params += "[生产信息]" + "\r\n";
  9246. Params += "生产商: " + textBox_MAC.Text + "\r\n";
  9247. Params += "生产地: " + textBox_MACAdd.Text + "\r\n";
  9248. Params += "生产日期: " + textBox_MACDate.Text + "\r\n";
  9249. Params += "产品标识: " + textBox_PP.Text + "\r\n";
  9250. Params += "\r\n";
  9251. //读取一次自定义信息
  9252. textBox_User1.Text = "---";
  9253. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  9254. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 1 次读自定义信息1" + "\r\n");
  9255. ACK_WaitCnt = 0;
  9256. while (ACK_WaitCnt <= 2) //1s
  9257. {
  9258. if (textBox_User1.Text != string.Empty)
  9259. break;
  9260. }
  9261. if (textBox_User1.Text == string.Empty)
  9262. {
  9263. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  9264. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 2 次读自定义信息1" + "\r\n");
  9265. ACK_WaitCnt = 0;
  9266. while (ACK_WaitCnt <= 2) //1s
  9267. {
  9268. if (textBox_User1.Text != string.Empty)
  9269. break;
  9270. }
  9271. if (textBox_User1.Text == string.Empty)
  9272. {
  9273. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  9274. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 3 次读自定义信息1" + "\r\n");
  9275. ACK_WaitCnt = 0;
  9276. while (ACK_WaitCnt <= 2) //1s
  9277. {
  9278. if (textBox_User1.Text != string.Empty)
  9279. break;
  9280. }
  9281. }
  9282. }
  9283. textBox_User2.Text = "---";
  9284. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  9285. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 1 次读自定义信息2" + "\r\n");
  9286. ACK_WaitCnt = 0;
  9287. while (ACK_WaitCnt <= 2) //1s
  9288. {
  9289. if (textBox_User2.Text != string.Empty)
  9290. break;
  9291. }
  9292. if (textBox_User2.Text == string.Empty)
  9293. {
  9294. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  9295. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 2 次读自定义信息2" + "\r\n");
  9296. ACK_WaitCnt = 0;
  9297. while (ACK_WaitCnt <= 2) //1s
  9298. {
  9299. if (textBox_User2.Text != string.Empty)
  9300. break;
  9301. }
  9302. if (textBox_User2.Text == string.Empty)
  9303. {
  9304. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  9305. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 3 次读自定义信息2" + "\r\n");
  9306. ACK_WaitCnt = 0;
  9307. while (ACK_WaitCnt <= 2) //1s
  9308. {
  9309. if (textBox_User2.Text != string.Empty)
  9310. break;
  9311. }
  9312. }
  9313. }
  9314. textBox_User3.Text = "---";
  9315. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  9316. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 1 次读自定义信息3" + "\r\n");
  9317. ACK_WaitCnt = 0;
  9318. while (ACK_WaitCnt <= 2) //1s
  9319. {
  9320. if (textBox_User3.Text != string.Empty)
  9321. break;
  9322. }
  9323. if (textBox_User3.Text == string.Empty)
  9324. {
  9325. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  9326. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 2 次读自定义信息3" + "\r\n");
  9327. ACK_WaitCnt = 0;
  9328. while (ACK_WaitCnt <= 2) //1s
  9329. {
  9330. if (textBox_User3.Text != string.Empty)
  9331. break;
  9332. }
  9333. if (textBox_User3.Text == string.Empty)
  9334. {
  9335. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  9336. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 3 次读自定义信息3" + "\r\n");
  9337. ACK_WaitCnt = 0;
  9338. while (ACK_WaitCnt <= 2) //1s
  9339. {
  9340. if (textBox_User3.Text != string.Empty)
  9341. break;
  9342. }
  9343. }
  9344. }
  9345. Params += "[自定义信息]" + "\r\n";
  9346. Params += "自定义1: " + textBox_User1.Text + "\r\n";
  9347. Params += "自定义2: " + textBox_User2.Text + "\r\n";
  9348. Params += "自定义3: " + textBox_User3.Text + "\r\n";
  9349. Params += "\r\n";
  9350. //读取一次密钥
  9351. textBox_Key.Text = "---";
  9352. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  9353. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 1 次读密钥" + "\r\n");
  9354. ACK_WaitCnt = 0;
  9355. while (ACK_WaitCnt <= 2) //1s
  9356. {
  9357. if (textBox_Key.Text != string.Empty)
  9358. break;
  9359. }
  9360. if (textBox_Key.Text == string.Empty)
  9361. {
  9362. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  9363. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 2 次读密钥" + "\r\n");
  9364. ACK_WaitCnt = 0;
  9365. while (ACK_WaitCnt <= 2) //1s
  9366. {
  9367. if (textBox_Key.Text != string.Empty)
  9368. break;
  9369. }
  9370. if (textBox_Key.Text == string.Empty)
  9371. {
  9372. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  9373. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 3 次读密钥" + "\r\n");
  9374. ACK_WaitCnt = 0;
  9375. while (ACK_WaitCnt <= 2) //1s
  9376. {
  9377. if (textBox_Key.Text != string.Empty)
  9378. break;
  9379. }
  9380. }
  9381. }
  9382. Params += "[校验密钥]" + "\r\n" + textBox_Key.Text + "\r\n";
  9383. Params += "\r\n";
  9384. //读取一次存储标志
  9385. radioButton_EE_SaveYes.Checked = false;
  9386. radioButton_EE_SaveNo.Checked = false;
  9387. radioButton_SIP_SaveYes.Checked = false;
  9388. radioButton_SIP_SaveNo.Checked = false;
  9389. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  9390. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 1 次读存储标志" + "\r\n");
  9391. ACK_WaitCnt = 0;
  9392. while (ACK_WaitCnt <= 2) //1s
  9393. {
  9394. if ((radioButton_EE_SaveYes.Checked | radioButton_EE_SaveNo.Checked | radioButton_SIP_SaveYes.Checked | radioButton_SIP_SaveNo.Checked) == true)
  9395. break;
  9396. }
  9397. if ((radioButton_EE_SaveYes.Checked | radioButton_EE_SaveNo.Checked | radioButton_SIP_SaveYes.Checked | radioButton_SIP_SaveNo.Checked) == false)
  9398. {
  9399. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  9400. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 2 次读存储标志" + "\r\n");
  9401. ACK_WaitCnt = 0;
  9402. while (ACK_WaitCnt <= 2) //1s
  9403. {
  9404. if ((radioButton_EE_SaveYes.Checked | radioButton_EE_SaveNo.Checked | radioButton_SIP_SaveYes.Checked | radioButton_SIP_SaveNo.Checked) == true)
  9405. break;
  9406. }
  9407. if ((radioButton_EE_SaveYes.Checked | radioButton_EE_SaveNo.Checked | radioButton_SIP_SaveYes.Checked | radioButton_SIP_SaveNo.Checked) == false)
  9408. {
  9409. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  9410. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第 3 次读存储标志" + "\r\n");
  9411. ACK_WaitCnt = 0;
  9412. while (ACK_WaitCnt <= 2) //1s
  9413. {
  9414. if ((radioButton_EE_SaveYes.Checked | radioButton_EE_SaveNo.Checked | radioButton_SIP_SaveYes.Checked | radioButton_SIP_SaveNo.Checked) == true)
  9415. break;
  9416. }
  9417. }
  9418. }
  9419. Params += "[存储标志]" + "\r\n";
  9420. Params += "EEPROM: " + ((radioButton_EE_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  9421. Params += "SIP: " + ((radioButton_SIP_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  9422. Params += "\r\n";
  9423. } while (false);
  9424. var Code = new byte[32];//发送的指令数据
  9425. //退出配置模式
  9426. Code[0] = 0x00;
  9427. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  9428. Delay_ms(1000);
  9429. //系统关机
  9430. Code[0] = 0xF0;
  9431. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  9432. //关闭串口
  9433. if (mySerialProcess.SerialClose(false))
  9434. {
  9435. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "串口已关闭" + "\r\n");
  9436. toolStripComboBox_ComNum.Enabled = true;
  9437. toolStripComboBox_Baudrate.Enabled = true;
  9438. 刷新ToolStripMenuItem.Enabled = true;
  9439. 连接ToolStripMenuItem.Text = "连接";
  9440. 连接ToolStripMenuItem.Checked = false;
  9441. label_COM_Sta.Text = "连接状态:未连接";
  9442. label_PortStatus.BackColor = Color.Red;
  9443. }
  9444. //路径设置
  9445. string LocalSavePath = "";
  9446. string ServerSavePath = "";
  9447. if (OK_Flag)
  9448. {
  9449. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "OK\\";
  9450. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/OK/";
  9451. }
  9452. else
  9453. {
  9454. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "FAIL\\";
  9455. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/FAIL/";
  9456. }
  9457. if (Directory.Exists(LocalSavePath) == false)
  9458. {
  9459. Directory.CreateDirectory(LocalSavePath);
  9460. }
  9461. //保存和上传
  9462. string LogSavePath = "";
  9463. string LogSaveFileName = "";
  9464. string ProductInfo = textBox_CheckModeScan.Text.Replace(" ", "_").Replace("/", "-"); ;
  9465. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  9466. if (Directory.Exists(LogSavePath) == false)
  9467. {
  9468. Directory.CreateDirectory(LogSavePath);
  9469. }
  9470. //测试页面
  9471. Double scaleX = PrimaryScreen.ScaleX;
  9472. Double scaleY = PrimaryScreen.ScaleY;
  9473. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  9474. Graphics g = Graphics.FromImage(bit);
  9475. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  9476. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  9477. bit.Save(LogSaveFileName);
  9478. //上传测试页面到服务器
  9479. if (myFtp.IsNetConnected == true)
  9480. {
  9481. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  9482. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  9483. {
  9484. myFtp.MakeDir(ServerSavePath + DateNow);
  9485. }
  9486. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  9487. {
  9488. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  9489. }
  9490. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  9491. if (result == true)
  9492. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  9493. }
  9494. //测试记录
  9495. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  9496. string file_str = "";
  9497. file_str += "计算机名称:\r\n" + label_Computername.Text + "\r\n";
  9498. file_str += "软件运行时间:\r\n" + stopwatch.ElapsedMilliseconds.ToString() + " ms" + "\r\n";
  9499. file_str += "软件运行次数:\r\n" + File.ReadAllText(localInfo.LocalPath + localInfo.PowerTimesFilename) + "\r\n";
  9500. file_str += "系统时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  9501. file_str += "检验记录:\r\n" + richTextBox_CheckModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  9502. file_str += "检验结果:\r\n" + label_CheckModeResult.Text + "\r\n\r\n";
  9503. file_str += Local_HdInformation;
  9504. file_str += "\r\n电机存储参数:\r\n" + Params + "\r\n";
  9505. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  9506. //上传测试记录到服务器
  9507. if (myFtp.IsNetConnected == true)
  9508. {
  9509. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  9510. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  9511. {
  9512. myFtp.MakeDir(ServerSavePath + DateNow);
  9513. }
  9514. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  9515. {
  9516. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  9517. }
  9518. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  9519. if (result == true)
  9520. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  9521. }
  9522. //扫码框清空
  9523. textBox_CheckModeScan.Text = "";
  9524. }
  9525. /// <summary>
  9526. /// 参数检验开始
  9527. /// </summary>
  9528. /// <param name="sender"></param>
  9529. /// <param name="e"></param>
  9530. private void button_CheckModeStart_Click(object sender, EventArgs e)
  9531. {
  9532. //测试项目关闭编辑
  9533. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  9534. foreach (Control c in groupBox29.Controls)
  9535. {
  9536. if (c is CheckBox)
  9537. c.Enabled = false;
  9538. }
  9539. ReadLockStatus = true;
  9540. //检查配置文件
  9541. if (comboBox_CheckModeCfgFile.Text == "")
  9542. {
  9543. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9544. return;
  9545. }
  9546. //开始测试
  9547. CheckTestStart();
  9548. }
  9549. /// <summary>
  9550. /// 参数检验测试子函数
  9551. /// </summary>
  9552. private void CheckTestStart()
  9553. {
  9554. //初始化标签
  9555. CheckModeLabelInit();
  9556. richTextBox_CheckModeLog.Clear();
  9557. //按钮禁止操作
  9558. button_CheckModeStart.Enabled = false;
  9559. textBox_CheckModeScan.Enabled = false;
  9560. //记录配置文件
  9561. richTextBox_CheckModeLog.AppendText("配置文件:" + comboBox_CheckModeCfgDate.Text + " / " + comboBox_CheckModeCfgFile.Text + "\r\n");
  9562. //检查打标信息
  9563. label_CheckModeStatus.Text = "检查扫码信息";
  9564. Delay_ms(500);
  9565. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  9566. if (textBox_CheckModeScan.Text == string.Empty)
  9567. {
  9568. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9569. button_CheckModeStart.Enabled = true;
  9570. textBox_CheckModeScan.Enabled = true;
  9571. return;
  9572. }
  9573. try
  9574. {
  9575. if (中置电机MIGIC_ToolStripMenuItem.Checked == true)
  9576. {
  9577. if (textBox_CheckModeScan.Text.Split(' ').Length != 7)
  9578. {
  9579. label_CheckModeStatus.Text = "存在故障!";
  9580. label_CheckModeResult.BackColor = Color.Red;
  9581. label_CheckModeResult.Text = "标签格式错误";
  9582. button_CheckModeStart.Enabled = true;
  9583. textBox_CheckModeScan.Enabled = true;
  9584. return;
  9585. }
  9586. }
  9587. else if (中置电机VP_ToolStripMenuItem.Checked == true)
  9588. {
  9589. if (textBox_CheckModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 2)
  9590. {
  9591. label_CheckModeStatus.Text = "存在故障!";
  9592. label_CheckModeResult.BackColor = Color.Red;
  9593. label_CheckModeResult.Text = "标签格式错误";
  9594. button_CheckModeStart.Enabled = true;
  9595. textBox_CheckModeScan.Enabled = true;
  9596. return;
  9597. }
  9598. }
  9599. else if (轮毂电机ToolStripMenuItem.Checked == true)
  9600. {
  9601. if (textBox_CheckModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  9602. {
  9603. label_CheckModeStatus.Text = "存在故障!";
  9604. label_CheckModeResult.BackColor = Color.Red;
  9605. label_CheckModeResult.Text = "标签格式错误";
  9606. button_CheckModeStart.Enabled = true;
  9607. textBox_CheckModeScan.Enabled = true;
  9608. return;
  9609. }
  9610. }
  9611. }
  9612. catch (System.Exception)
  9613. {
  9614. label_CheckModeStatus.Text = "存在故障!";
  9615. label_CheckModeResult.BackColor = Color.Red;
  9616. label_CheckModeResult.Text = "标签格式错误";
  9617. button_CheckModeStart.Enabled = true;
  9618. textBox_CheckModeScan.Enabled = true;
  9619. return;
  9620. }
  9621. //打开串口
  9622. if (mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false))
  9623. {
  9624. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "打开串口成功" + "\r\n");
  9625. toolStripComboBox_ComNum.Enabled = false;
  9626. toolStripComboBox_Baudrate.Enabled = false;
  9627. 刷新ToolStripMenuItem.Enabled = false;
  9628. 连接ToolStripMenuItem.Text = "断开";
  9629. 连接ToolStripMenuItem.Checked = true;
  9630. label_COM_Sta.Text = toolStripComboBox_ComNum.Text + "已连接," + toolStripComboBox_Baudrate.Text;
  9631. label_PortStatus.BackColor = Color.Green;
  9632. }
  9633. if (!mySerialProcess.mySerial.IsOpen)
  9634. {
  9635. MessageBox.Show("请检查串口连接!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9636. button__FacMode_Start.Enabled = false;
  9637. return;
  9638. }
  9639. //流水号计数
  9640. int serial = Convert.ToInt32(label_CheckModeSerial.Text);
  9641. serial += 1;
  9642. label_CheckModeSerial.Text = serial.ToString();
  9643. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, serial.ToString());
  9644. //创建线程,执行测试任务
  9645. Thread th = new Thread(CheckModeTest_Task);
  9646. th.Start();
  9647. }
  9648. /// <summary>
  9649. /// 执行一次测试任务
  9650. /// </summary>
  9651. private void CheckModeTest_Task()
  9652. {
  9653. //开始测试
  9654. richTextBox_CheckModeLog.AppendText("产品标签:" + textBox_CheckModeScan.Text + "\r\n");
  9655. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  9656. //变量定义
  9657. var Code = new byte[255];//发送的指令数据
  9658. label_CheckModeStatus.Text = "开始测试";
  9659. Delay_ms(500);
  9660. label_CheckModeStatus.Text = "系统开机";
  9661. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  9662. if (uARTToolStripMenuItem.Checked)
  9663. {
  9664. Code[0] = (byte)'R';
  9665. Code[1] = (byte)'E';
  9666. Code[2] = (byte)'S';
  9667. Code[3] = (byte)'E';
  9668. Code[4] = (byte)'T';
  9669. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  9670. Delay_ms(500);
  9671. }
  9672. //系统开机,确保测试前先关机,发送关机指令再发送开机指令
  9673. //确保测试前先关机,发送关机指令再发送开机指令
  9674. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  9675. Code[0] = 0xF0;
  9676. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  9677. Delay_ms(3000);
  9678. BootInfo = "";
  9679. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  9680. Code[0] = 0xF1;
  9681. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  9682. ACK_WaitCnt = 0;
  9683. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  9684. while (ACK_WaitCnt <= 20)
  9685. {
  9686. if (!uARTToolStripMenuItem.Checked) //CAN接口不考虑联动装置盒切换为Boot波特率
  9687. {
  9688. if (BootInfo != string.Empty)
  9689. break;
  9690. }
  9691. }
  9692. //检查BOOT版本
  9693. if (BootInfo != string.Empty)
  9694. {
  9695. label_CheckModeBoot.BackColor = Color.Green;
  9696. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  9697. Delay_ms(500);
  9698. }
  9699. else
  9700. {
  9701. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
  9702. label_CheckModeStatus.Text = "存在故障!";
  9703. label_CheckModeResult.BackColor = Color.Red;
  9704. label_CheckModeResult.Text = "测试异常";
  9705. Delay_ms(500);
  9706. //存储异常并上传
  9707. CheckMode_Stop(false);
  9708. return;
  9709. }
  9710. #if false
  9711. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  9712. {
  9713. Code[0] = 0x00;//5S协议
  9714. Code[1] = 0x00;
  9715. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  9716. Delay_ms(500);
  9717. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  9718. Delay_ms(500);
  9719. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  9720. }
  9721. #endif
  9722. //发送指令读取版本信息
  9723. do
  9724. {
  9725. label_CheckModeStatus.Text = "读取版本信息";
  9726. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  9727. //发送指令读取版本
  9728. Class_Motor_Ver.Mode = "---";
  9729. Class_Motor_Ver.SN = "---";
  9730. Class_Motor_Ver.HW = "---";
  9731. Class_Motor_Ver.FW = "---";
  9732. Class_Motor_Ver.Special = "---";
  9733. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  9734. ACK_WaitCnt = 0;
  9735. while (ACK_WaitCnt <= 2) ; //1s
  9736. if (Class_Motor_Ver.Mode == "---")
  9737. {
  9738. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第1次重发" + "\r\n");
  9739. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  9740. ACK_WaitCnt = 0;
  9741. while (ACK_WaitCnt <= 2) ; //1s
  9742. if (Class_Motor_Ver.Mode == "---")
  9743. {
  9744. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第2次重发" + "\r\n");
  9745. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  9746. ACK_WaitCnt = 0;
  9747. while (ACK_WaitCnt <= 2) ; //1s
  9748. if (Class_Motor_Ver.Mode == "---")
  9749. {
  9750. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取失败" + "\r\n");
  9751. label_CheckModeStatus.Text = "存在故障!";
  9752. label_CheckModeResult.BackColor = Color.Red;
  9753. label_CheckModeResult.Text = "测试异常";
  9754. Delay_ms(500);
  9755. //存储异常并上传
  9756. CheckMode_Stop(false);
  9757. return;
  9758. }
  9759. }
  9760. }
  9761. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  9762. richTextBox_CheckModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  9763. richTextBox_CheckModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  9764. richTextBox_CheckModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  9765. richTextBox_CheckModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  9766. richTextBox_CheckModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  9767. Delay_ms(500);
  9768. } while (false);
  9769. //软件版本检查
  9770. if (checkBox_CheckModeFWVer.Checked)
  9771. {
  9772. //判断版本是否正确
  9773. string VerCheck = comboBox_CheckModeCfgFile.Text.Split('_')[3] + "_" + comboBox_CheckModeCfgFile.Text.Split('_')[4];
  9774. string VerRead = "";
  9775. try
  9776. {
  9777. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  9778. }
  9779. catch (System.Exception)
  9780. {
  9781. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  9782. label_CheckModeStatus.Text = "存在故障!";
  9783. label_CheckModeResult.BackColor = Color.Red;
  9784. label_CheckModeResult.Text = "测试异常";
  9785. Delay_ms(500);
  9786. //存储异常并上传
  9787. CheckMode_Stop(false);
  9788. return;
  9789. }
  9790. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  9791. {
  9792. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
  9793. label_CheckModeStatus.Text = "存在故障!";
  9794. label_CheckModeResult.BackColor = Color.Red;
  9795. label_CheckModeResult.Text = "测试异常";
  9796. Delay_ms(500);
  9797. //存储异常并上传
  9798. CheckMode_Stop(false);
  9799. return;
  9800. }
  9801. label_CheckModeFWVer.BackColor = Color.Green;
  9802. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  9803. Delay_ms(500);
  9804. }
  9805. else
  9806. {
  9807. label_CheckModeFWVer.BackColor = Color.Yellow;
  9808. label_CheckModeStatus.Text = "跳过软件版本查询";
  9809. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过软件版本查询" + "\r\n");
  9810. Delay_ms(500);
  9811. }
  9812. //打标信息核对
  9813. if (checkBox_CheckModeSN.Checked)
  9814. {
  9815. label_CheckModeStatus.Text = "核对打标信息";
  9816. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "核对打标信息" + "\r\n");
  9817. //根据扫码信息获取型号和SN
  9818. string ScanInfo = textBox_CheckModeScan.Text;
  9819. string regexInfo = "";
  9820. string[] InfoList = { "" };
  9821. try
  9822. {
  9823. if (中置电机MIGIC_ToolStripMenuItem.Checked == true)
  9824. {
  9825. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  9826. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  9827. }
  9828. else if (中置电机VP_ToolStripMenuItem.Checked == true)
  9829. {
  9830. 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]?$");
  9831. if (ScanInfo.Contains(" "))
  9832. {
  9833. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  9834. string Mode = InfoList[0];
  9835. string Sn = InfoList[1];
  9836. if (regex.IsMatch(Sn) == false)
  9837. {
  9838. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN格式错误" + "\r\n");
  9839. label_FacModeStatus.Text = "存在故障!";
  9840. label_FacModeResult.BackColor = Color.Red;
  9841. label_FacModeResult.Text = "标签格式错误";
  9842. Delay_ms(500);
  9843. //存储异常并上传
  9844. FacMode_Stop(false);
  9845. return;
  9846. }
  9847. }
  9848. else
  9849. {
  9850. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  9851. label_FacModeStatus.Text = "存在故障!";
  9852. label_FacModeResult.BackColor = Color.Red;
  9853. label_FacModeResult.Text = "标签格式错误";
  9854. Delay_ms(500);
  9855. //存储异常并上传
  9856. FacMode_Stop(false);
  9857. return;
  9858. }
  9859. }
  9860. else if (轮毂电机ToolStripMenuItem.Checked == true)
  9861. {
  9862. if (!ScanInfo.Contains("/")) //老编码规则
  9863. {
  9864. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  9865. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  9866. string Spec = InfoList[1];
  9867. string Sn = InfoList[2];
  9868. InfoList[0] = Model.Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  9869. InfoList[1] = Sn;
  9870. }
  9871. else //新编码规则
  9872. {
  9873. Dictionary<string, string> Dic_Ver = new Dictionary<string, string>
  9874. {
  9875. { "01", "A" },
  9876. { "02", "B" },
  9877. { "03", "C" },
  9878. { "04", "D" },
  9879. { "05", "E" },
  9880. { "06", "F" },
  9881. { "07", "G" },
  9882. { "08", "H" },
  9883. { "09", "I" }
  9884. };
  9885. Dictionary<string, string> Dic_Vol = new Dictionary<string, string>
  9886. {
  9887. { "24V", "A" },
  9888. { "36V", "B" },
  9889. { "42V", "C" },
  9890. { "48V", "D" },
  9891. { "52V", "E" },
  9892. { "60V", "F" }
  9893. };
  9894. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  9895. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  9896. string Spec = InfoList[1].Replace("-", "").Replace("/", "");
  9897. string Sn = InfoList[2];
  9898. InfoList[0] = Model[2] + Dic_Ver[Model.Substring(3, 2)] + Model[5] + Dic_Ver[Model.Substring(6, 2)] + Model[9];
  9899. InfoList[0] += Dic_Vol[Spec.Substring(0, 3)] + Spec.Substring(3, 3) + Spec.Substring(13, 4) + Spec.Substring(Spec.Length - 4, 3);
  9900. InfoList[1] = Sn;
  9901. }
  9902. }
  9903. }
  9904. catch
  9905. {
  9906. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  9907. label_FacModeStatus.Text = "存在故障!";
  9908. label_FacModeResult.BackColor = Color.Red;
  9909. label_FacModeResult.Text = "标签格式错误";
  9910. Delay_ms(500);
  9911. //存储异常并上传
  9912. CheckMode_Stop(false);
  9913. return;
  9914. }
  9915. //核对型号
  9916. if (string.Equals(InfoList[0], Class_Motor_Ver.Mode) == false) //型号错误,直接结束
  9917. {
  9918. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号不一致" + "\r\n");
  9919. label_CheckModeStatus.Text = "存在故障!";
  9920. label_CheckModeResult.BackColor = Color.Red;
  9921. label_CheckModeResult.Text = "测试异常";
  9922. Delay_ms(500);
  9923. //存储异常并上传
  9924. CheckMode_Stop(false);
  9925. return;
  9926. }
  9927. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号一致" + "\r\n");
  9928. Delay_ms(500);
  9929. //核对SN
  9930. if (string.Equals(InfoList[1], Class_Motor_Ver.SN) == false) //型号错误,直接结束
  9931. {
  9932. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN不一致" + "\r\n");
  9933. label_CheckModeStatus.Text = "存在故障!";
  9934. label_CheckModeResult.BackColor = Color.Red;
  9935. label_CheckModeResult.Text = "测试异常";
  9936. Delay_ms(500);
  9937. //存储异常并上传
  9938. CheckMode_Stop(false);
  9939. return;
  9940. }
  9941. label_CheckModeSN.BackColor = Color.Green;
  9942. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN一致" + "\r\n");
  9943. Delay_ms(500);
  9944. }
  9945. else
  9946. {
  9947. label_CheckModeSN.BackColor = Color.Yellow;
  9948. label_CheckModeStatus.Text = "跳过打标信息确认";
  9949. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过打标信息确认" + "\r\n");
  9950. Delay_ms(500);
  9951. }
  9952. //参数检验
  9953. if (checkBox_CheckModeCfg.Checked)
  9954. {
  9955. //读取配置文件信息
  9956. label_CheckModeStatus.Text = "参数检查";
  9957. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  9958. //配置文件
  9959. List<byte[]> CmdList = new List<byte[]>();
  9960. Dictionary<string, string> ConfigCmd = new Dictionary<string, string>();//配置文件格式
  9961. //从服务器下载文件
  9962. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  9963. {
  9964. string SelectFile = "";
  9965. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "/" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  9966. if (File.Exists(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  9967. {
  9968. File.Delete(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  9969. }
  9970. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  9971. //打开文件
  9972. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  9973. ConfigCmd.Clear();
  9974. while (streamReader.Peek() != -1)
  9975. {
  9976. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  9977. if (fileLineInfo.Contains("["))
  9978. {
  9979. if (fileLineInfo.Contains("助力参数"))
  9980. {
  9981. fileLineInfo = streamReader.ReadLine();
  9982. }
  9983. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  9984. }
  9985. }
  9986. streamReader.Close();
  9987. }
  9988. //从本地加载文件
  9989. else
  9990. {
  9991. string SelectFile = "";
  9992. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  9993. //打开文件
  9994. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  9995. ConfigCmd.Clear();
  9996. while (streamReader.Peek() != -1)
  9997. {
  9998. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  9999. if (fileLineInfo.Contains("["))
  10000. {
  10001. if (fileLineInfo.Contains("助力参数"))
  10002. {
  10003. fileLineInfo = streamReader.ReadLine();
  10004. }
  10005. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  10006. }
  10007. }
  10008. streamReader.Close();
  10009. }
  10010. int CmdNum = ConfigCmd.Count(); //指令个数
  10011. Delay_ms(500);
  10012. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "\r\n");
  10013. Delay_ms(500);
  10014. //逐条读取比较
  10015. try
  10016. {
  10017. foreach (string key in ConfigCmd.Keys)
  10018. {
  10019. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令:" + "\r\n");
  10020. CmdRevStrTemp = "";
  10021. if (key.Contains("曲线"))
  10022. {
  10023. byte LineNum = 0;
  10024. var code = new byte[4];
  10025. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  10026. if (LineNum <= 5)
  10027. {
  10028. code[0] = (byte)(LineNum & 0xFF);
  10029. code[1] = (byte)((LineNum >> 8) & 0xFF);
  10030. code[2] = (byte)(LineNum & 0xFF);
  10031. code[3] = (byte)((LineNum >> 8) & 0xFF);
  10032. }
  10033. else
  10034. {
  10035. code[0] = (byte)(LineNum & 0xFF);
  10036. code[1] = (byte)((LineNum >> 8) & 0xFF);
  10037. code[2] = (byte)(5 & 0xFF);
  10038. code[3] = (byte)((5 >> 8) & 0xFF);
  10039. }
  10040. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  10041. }
  10042. else
  10043. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  10044. ACK_WaitCnt = 0;
  10045. while (ACK_WaitCnt <= 2) //1s
  10046. {
  10047. if (CmdRevStrTemp != string.Empty)
  10048. break;
  10049. }
  10050. if (CmdRevStrTemp == string.Empty)
  10051. {
  10052. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令,第1次重发" + "\r\n");
  10053. if (key.Contains("曲线"))
  10054. {
  10055. byte LineNum = 0;
  10056. var code = new byte[4];
  10057. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  10058. if (LineNum <= 5)
  10059. {
  10060. code[0] = (byte)(LineNum & 0xFF);
  10061. code[1] = (byte)((LineNum >> 8) & 0xFF);
  10062. code[2] = (byte)(LineNum & 0xFF);
  10063. code[3] = (byte)((LineNum >> 8) & 0xFF);
  10064. }
  10065. else
  10066. {
  10067. code[0] = (byte)(LineNum & 0xFF);
  10068. code[1] = (byte)((LineNum >> 8) & 0xFF);
  10069. code[2] = (byte)(5 & 0xFF);
  10070. code[3] = (byte)((5 >> 8) & 0xFF);
  10071. }
  10072. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  10073. }
  10074. else
  10075. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  10076. ACK_WaitCnt = 0;
  10077. while (ACK_WaitCnt <= 2) //1s
  10078. {
  10079. if (CmdRevStrTemp != string.Empty)
  10080. break;
  10081. }
  10082. if (CmdRevStrTemp == string.Empty)
  10083. {
  10084. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令,第2次重发" + "\r\n");
  10085. if (key.Contains("曲线"))
  10086. {
  10087. byte LineNum = 0;
  10088. var code = new byte[4];
  10089. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  10090. if (LineNum <= 5)
  10091. {
  10092. code[0] = (byte)(LineNum & 0xFF);
  10093. code[1] = (byte)((LineNum >> 8) & 0xFF);
  10094. code[2] = (byte)(LineNum & 0xFF);
  10095. code[3] = (byte)((LineNum >> 8) & 0xFF);
  10096. }
  10097. else
  10098. {
  10099. code[0] = (byte)(LineNum & 0xFF);
  10100. code[1] = (byte)((LineNum >> 8) & 0xFF);
  10101. code[2] = (byte)(5 & 0xFF);
  10102. code[3] = (byte)((5 >> 8) & 0xFF);
  10103. }
  10104. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  10105. }
  10106. else
  10107. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  10108. ACK_WaitCnt = 0;
  10109. while (ACK_WaitCnt <= 2) //1s
  10110. {
  10111. if (CmdRevStrTemp != string.Empty)
  10112. break;
  10113. }
  10114. if (CmdRevStrTemp == string.Empty)
  10115. {
  10116. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "指令读取失败" + "\r\n");
  10117. label_CheckModeStatus.Text = "存在故障!";
  10118. label_CheckModeResult.BackColor = Color.Red;
  10119. label_CheckModeResult.Text = "测试异常";
  10120. Delay_ms(500);
  10121. //存储异常并上传
  10122. CheckMode_Stop(false);
  10123. return;
  10124. }
  10125. }
  10126. }
  10127. //比较当前指令,读取的配置文件和返回数据比较
  10128. string ParamWrite = ConfigCmd[key].Substring(24, ConfigCmd[key].Length - 40).Trim();
  10129. string ParamRead = "";
  10130. ushort CmdGet = Convert.ToUInt16(CmdRevStrTemp.Substring(0, 6).Trim().Replace(" ", ""), 16);//接收到指令的命令字
  10131. ushort CmdRev = myParams.ConfigCheckRevCmd[key];//接收指令设计值
  10132. if (CmdGet != CmdRev)
  10133. {
  10134. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "接收指令不正确" + "\r\n");
  10135. richTextBox_CheckModeLog.AppendText("接收指令:" + "0x" + CmdGet.ToString("X2") + "\r\n");
  10136. richTextBox_CheckModeLog.AppendText("正确指令应为:" + "0x" + CmdRev.ToString("X2") + "\r\n");
  10137. label_CheckModeStatus.Text = "存在故障!";
  10138. label_CheckModeResult.BackColor = Color.Red;
  10139. label_CheckModeResult.Text = "测试异常";
  10140. Delay_ms(500);
  10141. //存储异常并上传
  10142. CheckMode_Stop(false);
  10143. return;
  10144. }
  10145. if (string.Compare(key, "[其它传感器参数]") == 0)
  10146. ParamRead = CmdRevStrTemp.Substring(90, CmdRevStrTemp.Length - 90).Trim(); //去掉命令字、力矩传感器标定参数
  10147. else if (string.Compare(key, "[力矩传感器参数]") == 0)
  10148. ParamRead = CmdRevStrTemp.Substring(6, CmdRevStrTemp.Length - 6 - 36).Trim(); //去掉命令字、其它传感器参数
  10149. else if (string.Compare(key, "[控制参数]") == 0)
  10150. ParamRead = CmdRevStrTemp.Substring(18, CmdRevStrTemp.Length - 18).Trim(); //去掉命令字、位置零点
  10151. else
  10152. ParamRead = CmdRevStrTemp.Substring(6, CmdRevStrTemp.Length - 6).Trim(); //去掉命令字
  10153. if (ParamWrite.Contains(ParamRead))
  10154. {
  10155. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "一致" + "\r\n");
  10156. continue;
  10157. }
  10158. else
  10159. {
  10160. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "不一致" + "\r\n");
  10161. richTextBox_CheckModeLog.AppendText("写入参数:" + ParamWrite + "\r\n");
  10162. richTextBox_CheckModeLog.AppendText("读出参数:" + ParamRead + "\r\n");
  10163. label_CheckModeStatus.Text = "存在故障!";
  10164. label_CheckModeResult.BackColor = Color.Red;
  10165. label_CheckModeResult.Text = "测试异常";
  10166. Delay_ms(500);
  10167. //存储异常并上传
  10168. CheckMode_Stop(false);
  10169. return;
  10170. }
  10171. }
  10172. }
  10173. catch (System.Exception)
  10174. {
  10175. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数检验失败" + "\r\n");
  10176. label_CheckModeStatus.Text = "存在故障!";
  10177. label_CheckModeResult.BackColor = Color.Red;
  10178. label_CheckModeResult.Text = "测试异常";
  10179. Delay_ms(500);
  10180. //存储异常并上传
  10181. CheckMode_Stop(false);
  10182. return;
  10183. }
  10184. label_CheckModeCfg.BackColor = Color.Green;
  10185. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数检验正确" + "\r\n");
  10186. Delay_ms(500);
  10187. }
  10188. else
  10189. {
  10190. label_CheckModeCfg.BackColor = Color.Yellow;
  10191. label_CheckModeStatus.Text = "跳过参数检验";
  10192. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数检验" + "\r\n");
  10193. Delay_ms(500);
  10194. }
  10195. //读取力矩传感器
  10196. do
  10197. {
  10198. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据" + "\r\n");
  10199. //发送指令读取力矩传感器标定数据
  10200. CmdRevStrTemp = "";
  10201. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  10202. ACK_WaitCnt = 0;
  10203. while (ACK_WaitCnt <= 2) ; //1s
  10204. if (CmdRevStrTemp == string.Empty)
  10205. {
  10206. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据,第1次重发" + "\r\n");
  10207. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  10208. ACK_WaitCnt = 0;
  10209. while (ACK_WaitCnt <= 2) ; //1s
  10210. if (CmdRevStrTemp == string.Empty)
  10211. {
  10212. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据,第2次重发" + "\r\n");
  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") + "->" + "力矩传感器读取失败" + "\r\n");
  10219. label_CheckModeStatus.Text = "存在故障!";
  10220. label_CheckModeResult.BackColor = Color.Red;
  10221. label_CheckModeResult.Text = "测试异常";
  10222. Delay_ms(500);
  10223. //存储异常并上传
  10224. CheckMode_Stop(false);
  10225. return;
  10226. }
  10227. }
  10228. }
  10229. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取成功" + "\r\n");
  10230. //取力矩传感器数据
  10231. ushort ZeroInit, Zero1, Zero2, Zero3, ZeroNew;
  10232. ushort MaxTorque;
  10233. ushort K1_T, K1, K2_T, K2, K3_T, K3, K4_T, K4;
  10234. byte[] DataArray = mySerialProcess.HexStringToBytes(CmdRevStrTemp, true);
  10235. ushort Cmd = (ushort)((DataArray[0] << 8) + DataArray[1]);
  10236. if (Cmd != 0xB528)
  10237. {
  10238. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器参数错误,CMD: 0x" + Convert.ToString(Cmd, 16).PadLeft(2, '0').ToUpper() + "\r\n");
  10239. label_CheckModeStatus.Text = "存在故障!";
  10240. label_CheckModeResult.BackColor = Color.Red;
  10241. label_CheckModeResult.Text = "测试异常";
  10242. Delay_ms(500);
  10243. //存储异常并上传
  10244. CheckMode_Stop(false);
  10245. return;
  10246. }
  10247. ZeroInit = (ushort)((DataArray[3] << 8) + DataArray[2]);
  10248. Zero1 = (ushort)((DataArray[5] << 8) + DataArray[4]);
  10249. Zero2 = (ushort)((DataArray[7] << 8) + DataArray[6]);
  10250. Zero3 = (ushort)((DataArray[9] << 8) + DataArray[8]);
  10251. ZeroNew = (ushort)((DataArray[11] << 8) + DataArray[10]);
  10252. MaxTorque = (ushort)((DataArray[13] << 8) + DataArray[12]);
  10253. K1_T = (ushort)((DataArray[15] << 8) + DataArray[14]);
  10254. K1 = (ushort)((DataArray[17] << 8) + DataArray[16]);
  10255. K2_T = (ushort)((DataArray[19] << 8) + DataArray[18]);
  10256. K2 = (ushort)((DataArray[21] << 8) + DataArray[20]);
  10257. K3_T = (ushort)((DataArray[23] << 8) + DataArray[22]);
  10258. K3 = (ushort)((DataArray[25] << 8) + DataArray[24]);
  10259. K4_T = (ushort)((DataArray[27] << 8) + DataArray[26]);
  10260. K4 = (ushort)((DataArray[29] << 8) + DataArray[28]);
  10261. richTextBox_CheckModeLog.AppendText("力矩传感器零点: " + ZeroInit.ToString() + "," + Zero1.ToString() + "," +
  10262. Zero2.ToString() + "," + Zero3.ToString() + "," + ZeroNew.ToString() + "\r\n");
  10263. richTextBox_CheckModeLog.AppendText("最大力矩: " + MaxTorque.ToString() + "\r\n");
  10264. richTextBox_CheckModeLog.AppendText("力矩传感器标定: " + "[" + K1_T.ToString() + "," + K1.ToString() + "]" + "," +
  10265. "[" + K2_T.ToString() + "," + K2.ToString() + "]" + "," + "[" + K3_T.ToString() + "," + K3.ToString() + "]" + "," +
  10266. "[" + K4_T.ToString() + "," + K4.ToString() + "]" + "\r\n");
  10267. //传感器标定检验
  10268. if (checkBox_CheckModeTorque.Checked)
  10269. {
  10270. richTextBox_CheckModeLog.AppendText("力矩零点范围: " + TorqueParamsForm.Zero.Min.ToString() + " - " + TorqueParamsForm.Zero.Max.ToString() + "\r\n");
  10271. richTextBox_CheckModeLog.AppendText("K1范围: " + TorqueParamsForm.K1.T.ToString() + "," + TorqueParamsForm.K1.Min.ToString() + " - " + TorqueParamsForm.K1.Max.ToString() + "\r\n");
  10272. richTextBox_CheckModeLog.AppendText("K2范围: " + TorqueParamsForm.K2.T.ToString() + "," + TorqueParamsForm.K2.Min.ToString() + " - " + TorqueParamsForm.K2.Max.ToString() + "\r\n");
  10273. richTextBox_CheckModeLog.AppendText("K3范围: " + TorqueParamsForm.K3.T.ToString() + "," + TorqueParamsForm.K3.Min.ToString() + " - " + TorqueParamsForm.K3.Max.ToString() + "\r\n");
  10274. richTextBox_CheckModeLog.AppendText("K4范围: " + TorqueParamsForm.K4.T.ToString() + "," + TorqueParamsForm.K4.Min.ToString() + " - " + TorqueParamsForm.K4.Max.ToString() + "\r\n");
  10275. //与设置值比较
  10276. if ((ZeroInit <= TorqueParamsForm.Zero.Max) && (ZeroInit >= TorqueParamsForm.Zero.Min)
  10277. && (K1_T == TorqueParamsForm.K1.T) && (K1 <= TorqueParamsForm.K1.Max) && (K1 >= TorqueParamsForm.K1.Min)
  10278. && (K2_T == TorqueParamsForm.K2.T) && (K2 <= TorqueParamsForm.K2.Max) && (K2 >= TorqueParamsForm.K2.Min)
  10279. && (K3_T == TorqueParamsForm.K3.T) && (K3 <= TorqueParamsForm.K3.Max) && (K3 >= TorqueParamsForm.K3.Min)
  10280. && (K4_T == TorqueParamsForm.K4.T) && (K4 <= TorqueParamsForm.K4.Max) && (K4 >= TorqueParamsForm.K4.Min)
  10281. )
  10282. {
  10283. label_CheckModeTorque.BackColor = Color.Green;
  10284. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定正常" + "\r\n");
  10285. Delay_ms(500);
  10286. }
  10287. else
  10288. {
  10289. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定超范围" + "\r\n");
  10290. label_CheckModeStatus.Text = "存在故障!";
  10291. label_CheckModeResult.BackColor = Color.Red;
  10292. label_CheckModeResult.Text = "测试异常";
  10293. Delay_ms(500);
  10294. //存储异常并上传
  10295. CheckMode_Stop(false);
  10296. return;
  10297. }
  10298. }
  10299. else
  10300. {
  10301. label_CheckModeTorque.BackColor = Color.Yellow;
  10302. label_CheckModeStatus.Text = "跳过传感器标定检验";
  10303. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过传感器标定检验" + "\r\n");
  10304. Delay_ms(500);
  10305. }
  10306. } while (false);
  10307. //读取MOS内阻校准参数
  10308. do
  10309. {
  10310. if (checkBox_CheckModeMos.Checked)
  10311. {
  10312. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据" + "\r\n");
  10313. //读取显示校准返回数据
  10314. foreach (Control c in groupBox21.Controls)
  10315. {
  10316. if (c is TextBox)
  10317. c.Text = "";
  10318. }
  10319. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  10320. ACK_WaitCnt = 0;
  10321. while (ACK_WaitCnt <= 2) ; //1s
  10322. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  10323. {
  10324. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据,第1次重发" + "\r\n");
  10325. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  10326. ACK_WaitCnt = 0;
  10327. while (ACK_WaitCnt <= 2) ; //1s
  10328. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  10329. {
  10330. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据,第2次重发" + "\r\n");
  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内阻校准结果异常" + "\r\n");
  10337. label_CheckModeStatus.Text = "存在故障!";
  10338. label_CheckModeResult.BackColor = Color.Red;
  10339. label_CheckModeResult.Text = "测试异常";
  10340. Delay_ms(500);
  10341. //存储异常并上传
  10342. CheckMode_Stop(false);
  10343. return;
  10344. }
  10345. }
  10346. }
  10347. else
  10348. {
  10349. 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");
  10350. }
  10351. //与校准返回数据对比
  10352. string[] MOS_R1_Th = toolStripTextBox_MOS1.Text.Split(',');
  10353. string[] MOS_R2_Th = toolStripTextBox_MOS2.Text.Split(',');
  10354. string[] MOS_R3_Th = toolStripTextBox_MOS3.Text.Split(',');
  10355. 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])) &&
  10356. (Convert.ToUInt16(textBox_MOS_R2.Text) >= Convert.ToUInt16(MOS_R2_Th[0])) && (Convert.ToUInt16(textBox_MOS_R2.Text) <= Convert.ToUInt16(MOS_R2_Th[1])) &&
  10357. (Convert.ToUInt16(textBox_MOS_R3.Text) >= Convert.ToUInt16(MOS_R3_Th[0])) && (Convert.ToUInt16(textBox_MOS_R3.Text) <= Convert.ToUInt16(MOS_R3_Th[1]))
  10358. )
  10359. {
  10360. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准合格" + "\r\n");
  10361. label_CheckModeMos.BackColor = Color.Green;
  10362. }
  10363. else
  10364. {
  10365. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准超范围" + "\r\n");
  10366. label_CheckModeStatus.Text = "存在故障!";
  10367. label_CheckModeResult.BackColor = Color.Red;
  10368. label_CheckModeResult.Text = "测试异常";
  10369. Delay_ms(500);
  10370. //存储异常并上传
  10371. CheckMode_Stop(false);
  10372. return;
  10373. }
  10374. }
  10375. else
  10376. {
  10377. label_CheckModeMos.BackColor = Color.Yellow;
  10378. label_CheckModeStatus.Text = "跳过MOS内阻校准检验";
  10379. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过MOS内阻校准检验" + "\r\n");
  10380. Delay_ms(500);
  10381. }
  10382. } while (false);
  10383. //读取位置校准参数
  10384. do
  10385. {
  10386. if (checkBox_CheckModeAngle.Checked)
  10387. {
  10388. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取位置校准数据" + "\r\n");
  10389. //发送指令读取位置
  10390. CmdRevStrTemp = "";
  10391. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
  10392. ACK_WaitCnt = 0;
  10393. while (ACK_WaitCnt <= 2) ; //1s
  10394. if (CmdRevStrTemp == string.Empty)
  10395. {
  10396. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取位置校准数据,第1次重发" + "\r\n");
  10397. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x3E00, null);
  10398. ACK_WaitCnt = 0;
  10399. while (ACK_WaitCnt <= 2) ; //1s
  10400. if (CmdRevStrTemp == string.Empty)
  10401. {
  10402. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取位置校准数据,第2次重发" + "\r\n");
  10403. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 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") + "->" + "位置校准数据读取失败" + "\r\n");
  10409. label_CheckModeStatus.Text = "存在故障!";
  10410. label_CheckModeResult.BackColor = Color.Red;
  10411. label_CheckModeResult.Text = "测试异常";
  10412. Delay_ms(500);
  10413. //存储异常并上传
  10414. CheckMode_Stop(false);
  10415. return;
  10416. }
  10417. }
  10418. }
  10419. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准数据读取成功" + "\r\n");
  10420. //取零点数据
  10421. UInt16 AngleZero_Init = 0, AngleZero_Cur = 0;
  10422. byte[] DataArray = mySerialProcess.HexStringToBytes(CmdRevStrTemp, true);
  10423. ushort Cmd = (ushort)((DataArray[0] << 8) + DataArray[1]);
  10424. if (Cmd != 0xB420)
  10425. {
  10426. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置传感器参数错误,CMD: 0x" + Convert.ToString(Cmd, 16).PadLeft(2, '0').ToUpper() + "\r\n");
  10427. label_CheckModeStatus.Text = "存在故障!";
  10428. label_CheckModeResult.BackColor = Color.Red;
  10429. label_CheckModeResult.Text = "测试异常";
  10430. Delay_ms(500);
  10431. //存储异常并上传
  10432. CheckMode_Stop(false);
  10433. return;
  10434. }
  10435. AngleZero_Init = (ushort)((DataArray[3] << 8) + DataArray[2]);
  10436. AngleZero_Cur = (ushort)((DataArray[5] << 8) + DataArray[4]);
  10437. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置出厂零点: " + AngleZero_Init.ToString() + ",位置当前零点: " + AngleZero_Cur.ToString() + "\r\n");
  10438. //非零判断
  10439. if ((AngleZero_Cur == 0) || (AngleZero_Init == 0))
  10440. {
  10441. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置传感器零点数值错误" + "\r\n");
  10442. label_CheckModeStatus.Text = "存在故障!";
  10443. label_CheckModeResult.BackColor = Color.Red;
  10444. label_CheckModeResult.Text = "测试异常";
  10445. Delay_ms(500);
  10446. //存储异常并上传
  10447. CheckMode_Stop(false);
  10448. return;
  10449. }
  10450. else
  10451. {
  10452. int AngleZeroDiff = (Math.Abs(AngleZero_Cur - AngleZero_Init) * 360) >> 15;
  10453. int AngleZeroTH = Convert.ToInt32(textBox_AngleZeroTh.Text);
  10454. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置零点校准值: " + AngleZeroDiff.ToString() + ",判断阈值: " + AngleZeroTH.ToString() + "\r\n");
  10455. //范围判断
  10456. if (AngleZeroDiff <= AngleZeroTH)
  10457. {
  10458. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置传感器校准合格" + "\r\n");
  10459. label_CheckModeAngle.BackColor = Color.Green;
  10460. }
  10461. else
  10462. {
  10463. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置传感器校准超范围" + "\r\n");
  10464. label_CheckModeStatus.Text = "存在故障!";
  10465. label_CheckModeResult.BackColor = Color.Red;
  10466. label_CheckModeResult.Text = "测试异常";
  10467. Delay_ms(500);
  10468. //存储异常并上传
  10469. CheckMode_Stop(false);
  10470. return;
  10471. }
  10472. }
  10473. }
  10474. else
  10475. {
  10476. label_CheckModeAngle.BackColor = Color.Yellow;
  10477. label_CheckModeStatus.Text = "跳过位置传感器校准检验";
  10478. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过位置传感器校准检验" + "\r\n");
  10479. Delay_ms(500);
  10480. }
  10481. } while (false);
  10482. //测试合格
  10483. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  10484. label_CheckModeStatus.Text = "测试结束!";
  10485. label_CheckModeResult.BackColor = Color.Green;
  10486. label_CheckModeResult.Text = "测试合格";
  10487. Delay_ms(500);
  10488. //存储并上传
  10489. CheckMode_Stop(true);
  10490. return;
  10491. }
  10492. private void CheckModeLabelInit()
  10493. {
  10494. //测试状态标签
  10495. label_CheckModeResult.BackColor = Color.Yellow;
  10496. label_CheckModeResult.Text = "测试中";
  10497. //测试过程标签
  10498. label_CheckModeStatus.Text = "测试就绪";
  10499. //测试结果标签
  10500. foreach (Control c in groupBox31.Controls)
  10501. {
  10502. if (c is Label)
  10503. {
  10504. if (c.Text == string.Empty)
  10505. c.BackColor = Color.Red;
  10506. }
  10507. }
  10508. }
  10509. private void 调试记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  10510. {
  10511. System.Diagnostics.Process.Start("explorer.exe", Directory.GetCurrentDirectory());
  10512. }
  10513. private void 生产记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  10514. {
  10515. System.Diagnostics.Process.Start("explorer.exe", localInfo.LocalDataPath);
  10516. }
  10517. private void 累计运行时间ToolStripMenuItem_MouseHover(object sender, EventArgs e)
  10518. {
  10519. UInt32 Time = (UInt32)stopwatch.ElapsedMilliseconds / 1000;
  10520. UInt32 hour = Time / 3600;
  10521. UInt32 min = (Time % 3600) / 60;
  10522. UInt32 s = (Time % 60);
  10523. toolStripMenuItem_RunTime.Text = hour.ToString() + ":" + min.ToString("00") + ":" + s.ToString("00");
  10524. }
  10525. private void richTextBox_CheckModeLog_TextChanged(object sender, EventArgs e)
  10526. {
  10527. richTextBox_CheckModeLog.SelectionStart = richTextBox_CheckModeLog.Text.Length;
  10528. richTextBox_CheckModeLog.ScrollToCaret();
  10529. }
  10530. private void 力矩传感器检验ToolStripMenuItem_Click(object sender, EventArgs e)
  10531. {
  10532. TorqueParamsForm.ShowDialog();
  10533. }
  10534. private void textBox_CheckModeScan_KeyUp(object sender, KeyEventArgs e)
  10535. {
  10536. if (e.KeyCode == Keys.Enter)
  10537. CheckTestStart();
  10538. }
  10539. private void textBox_FacModeScan_KeyUp(object sender, KeyEventArgs e)
  10540. {
  10541. if (e.KeyCode == Keys.Enter)
  10542. TestStart();
  10543. }
  10544. private void button_SpeedDec10_Click(object sender, EventArgs e)
  10545. {
  10546. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  10547. if (Percent <= 10)
  10548. Percent = 0;
  10549. else
  10550. Percent -= 10;
  10551. //生产模式转速设置值更新
  10552. textBox_MotorSpeedPercent.Text = Percent.ToString();
  10553. //设置转速百分比
  10554. var Data = new byte[1];
  10555. Data[0] = (byte)Percent;
  10556. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  10557. }
  10558. private void button_SpeedAdd10_Click(object sender, EventArgs e)
  10559. {
  10560. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  10561. if (Percent >= 90)
  10562. Percent = 100;
  10563. else
  10564. Percent += 10;
  10565. //生产模式转速设置值更新
  10566. textBox_MotorSpeedPercent.Text = Percent.ToString();
  10567. //设置转速百分比
  10568. var Data = new byte[1];
  10569. Data[0] = (byte)Percent;
  10570. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  10571. }
  10572. private void button_SpeedDec1_Click(object sender, EventArgs e)
  10573. {
  10574. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  10575. if (Percent <= 1)
  10576. Percent = 0;
  10577. else
  10578. Percent -= 1;
  10579. //生产模式转速设置值更新
  10580. textBox_MotorSpeedPercent.Text = Percent.ToString();
  10581. //设置转速百分比
  10582. var Data = new byte[1];
  10583. Data[0] = (byte)Percent;
  10584. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  10585. }
  10586. private void button_SpeedAdd1_Click(object sender, EventArgs e)
  10587. {
  10588. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  10589. if (Percent >= 99)
  10590. Percent = 100;
  10591. else
  10592. Percent += 1;
  10593. //生产模式转速设置值更新
  10594. textBox_MotorSpeedPercent.Text = Percent.ToString();
  10595. //设置转速百分比
  10596. var Data = new byte[1];
  10597. Data[0] = (byte)Percent;
  10598. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  10599. }
  10600. bool WriteLockStatus = true;
  10601. private void pictureBox_WriteLock_Click(object sender, EventArgs e)
  10602. {
  10603. if (WriteLockStatus == true)
  10604. {
  10605. EnterForm1.ShowDialog();
  10606. try
  10607. {
  10608. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  10609. {
  10610. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  10611. {
  10612. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  10613. foreach (Control c in groupBox2.Controls)
  10614. {
  10615. if (c is CheckBox)
  10616. c.Enabled = true;
  10617. }
  10618. WriteLockStatus = !WriteLockStatus;
  10619. }
  10620. else
  10621. {
  10622. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  10623. }
  10624. }
  10625. else
  10626. {
  10627. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  10628. }
  10629. }
  10630. catch (Exception)
  10631. {
  10632. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  10633. }
  10634. }
  10635. else
  10636. {
  10637. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  10638. foreach (Control c in groupBox2.Controls)
  10639. {
  10640. if (c is CheckBox)
  10641. c.Enabled = false;
  10642. }
  10643. WriteLockStatus = !WriteLockStatus;
  10644. }
  10645. }
  10646. bool ReadLockStatus = true;
  10647. private void pictureBox_ReadLock_Click(object sender, EventArgs e)
  10648. {
  10649. if (ReadLockStatus == true)
  10650. {
  10651. EnterForm1.ShowDialog();
  10652. try
  10653. {
  10654. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  10655. {
  10656. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  10657. {
  10658. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  10659. foreach (Control c in groupBox29.Controls)
  10660. {
  10661. if (c is CheckBox)
  10662. c.Enabled = true;
  10663. }
  10664. ReadLockStatus = !ReadLockStatus;
  10665. }
  10666. else
  10667. {
  10668. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  10669. }
  10670. }
  10671. else
  10672. {
  10673. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  10674. }
  10675. }
  10676. catch (Exception)
  10677. {
  10678. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  10679. }
  10680. }
  10681. else
  10682. {
  10683. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  10684. foreach (Control c in groupBox29.Controls)
  10685. {
  10686. if (c is CheckBox)
  10687. c.Enabled = false;
  10688. }
  10689. ReadLockStatus = !ReadLockStatus;
  10690. }
  10691. }
  10692. private void 屏幕键盘ToolStripMenuItem_Click(object sender, EventArgs e)
  10693. {
  10694. System.Diagnostics.Process.Start("osk.exe");
  10695. }
  10696. private void checkBox_OffLineCheckMode_CheckedChanged(object sender, EventArgs e)
  10697. {
  10698. comboBox_CheckModeCfgDate.SelectedIndex = -1;
  10699. comboBox_CheckModeCfgFile.SelectedIndex = -1;
  10700. checkBox_OffLineFacMode.Checked = checkBox_OffLineCheckMode.Checked;
  10701. }
  10702. private void checkBox_OffLineFacMode_CheckedChanged(object sender, EventArgs e)
  10703. {
  10704. comboBox_FacModeCfgDate.SelectedIndex = -1;
  10705. comboBox_FacModeCfgFile.SelectedIndex = -1;
  10706. checkBox_OffLineCheckMode.Checked = checkBox_OffLineFacMode.Checked;
  10707. }
  10708. private void 版本ToolStripMenuItem_Click(object sender, EventArgs e)
  10709. {
  10710. VersionForm.ShowDialog();
  10711. }
  10712. private void button_MOS_Cal_Click(object sender, EventArgs e)
  10713. {
  10714. textBox_MOS_R1.Text = "";
  10715. textBox_MOS_R2.Text = "";
  10716. textBox_MOS_R3.Text = "";
  10717. try
  10718. {
  10719. var Code = new byte[18];
  10720. for (int i = 0; i < 18; i++)
  10721. Code[i] = 0;
  10722. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  10723. ushort uwDataTemp = 0;
  10724. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  10725. Code[2] = (byte)(uwDataTemp & 0xFF);
  10726. Code[3] = (byte)(uwDataTemp >> 8);
  10727. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  10728. Code[4] = (byte)(uwDataTemp & 0xFF);
  10729. Code[5] = (byte)(uwDataTemp >> 8);
  10730. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  10731. Code[6] = (byte)(uwDataTemp & 0xFF);
  10732. Code[7] = (byte)(uwDataTemp >> 8);
  10733. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  10734. Code[8] = (byte)(uwDataTemp & 0xFF);
  10735. Code[9] = (byte)(uwDataTemp >> 8);
  10736. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  10737. Code[10] = (byte)(uwDataTemp & 0xFF);
  10738. Code[11] = (byte)(uwDataTemp >> 8);
  10739. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  10740. }
  10741. catch (Exception)
  10742. {
  10743. MessageBox.Show("系数填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  10744. }
  10745. }
  10746. private void button_MOS_Read_Click(object sender, EventArgs e)
  10747. {
  10748. foreach (Control c in groupBox21.Controls)
  10749. {
  10750. if (c is TextBox)
  10751. c.Text = "";
  10752. }
  10753. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  10754. }
  10755. private void button_MOS_Write_Click(object sender, EventArgs e)
  10756. {
  10757. try
  10758. {
  10759. var Code = new byte[34];
  10760. for (int i = 0; i < 34; i++)
  10761. Code[i] = 0;
  10762. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  10763. ushort uwDataTemp = 0;
  10764. uwDataTemp = Convert.ToUInt16(textBox_MOS_R1.Text);
  10765. Code[2] = (byte)(uwDataTemp & 0xFF);
  10766. Code[3] = (byte)(uwDataTemp >> 8);
  10767. uwDataTemp = Convert.ToUInt16(textBox_MOS_R2.Text);
  10768. Code[4] = (byte)(uwDataTemp & 0xFF);
  10769. Code[5] = (byte)(uwDataTemp >> 8);
  10770. uwDataTemp = Convert.ToUInt16(textBox_MOS_R3.Text);
  10771. Code[6] = (byte)(uwDataTemp & 0xFF);
  10772. Code[7] = (byte)(uwDataTemp >> 8);
  10773. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  10774. Code[8] = (byte)(uwDataTemp & 0xFF);
  10775. Code[9] = (byte)(uwDataTemp >> 8);
  10776. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  10777. Code[10] = (byte)(uwDataTemp & 0xFF);
  10778. Code[11] = (byte)(uwDataTemp >> 8);
  10779. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  10780. Code[12] = (byte)(uwDataTemp & 0xFF);
  10781. Code[13] = (byte)(uwDataTemp >> 8);
  10782. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  10783. Code[14] = (byte)(uwDataTemp & 0xFF);
  10784. Code[15] = (byte)(uwDataTemp >> 8);
  10785. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  10786. Code[16] = (byte)(uwDataTemp & 0xFF);
  10787. Code[17] = (byte)(uwDataTemp >> 8);
  10788. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4C22, Code);
  10789. }
  10790. catch (Exception)
  10791. {
  10792. MessageBox.Show("数据填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  10793. }
  10794. }
  10795. /// <summary>
  10796. /// 测试模式点击文本框自动全选
  10797. /// </summary>
  10798. /// <param name="sender"></param>
  10799. /// <param name="e"></param>
  10800. private void textBox_FacModeScan_MouseClick(object sender, MouseEventArgs e)
  10801. {
  10802. textBox_FacModeScan.SelectAll();
  10803. }
  10804. /// <summary>
  10805. /// 检验模式点击文本框自动全选
  10806. /// </summary>
  10807. /// <param name="sender"></param>
  10808. /// <param name="e"></param>
  10809. private void textBox_CheckModeScan_MouseClick(object sender, MouseEventArgs e)
  10810. {
  10811. textBox_CheckModeScan.SelectAll();
  10812. }
  10813. /// <summary>
  10814. /// 鼠标放置显示连接服务器信息
  10815. /// </summary>
  10816. /// <param name="sender"></param>
  10817. /// <param name="e"></param>
  10818. private void label_ServerStatus_MouseHover(object sender, EventArgs e)
  10819. {
  10820. // 创建the ToolTip
  10821. ToolTip toolTip1 = new ToolTip();
  10822. // 设置显示样式
  10823. toolTip1.AutoPopDelay = 30000;//提示信息的可见时间
  10824. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  10825. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  10826. toolTip1.ShowAlways = true;//是否显示提示框
  10827. if (myFtp.IsNetConnected)
  10828. {
  10829. toolTip1.SetToolTip(this.label_ServerStatus, "IP: " + ServerIP);//设置故障内容显示
  10830. }
  10831. else
  10832. {
  10833. toolTip1.SetToolTip(this.label_ServerStatus, "网络断开");//设置故障内容显示
  10834. }
  10835. }
  10836. /// <summary>
  10837. /// UART协议类型修改
  10838. /// </summary>
  10839. /// <param name="sender"></param>
  10840. /// <param name="e"></param>
  10841. private void 协议类型ToolStripMenuItem_SelectedIndexChanged(object sender, EventArgs e)
  10842. {
  10843. var Code = new byte[2];
  10844. Code[0] = (byte)协议类型ToolStripMenuItem.SelectedIndex;
  10845. Code[1] = 0x00;
  10846. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  10847. }
  10848. /// <summary>
  10849. /// 显示本机信息
  10850. /// </summary>
  10851. /// <param name="sender"></param>
  10852. /// <param name="e"></param>
  10853. private void 本机信息ToolStripMenuItem_Click(object sender, EventArgs e)
  10854. {
  10855. MessageBox.Show(Local_HdInformation, "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
  10856. }
  10857. /// <summary>
  10858. /// 量产模式删除当前选中文件
  10859. /// </summary>
  10860. /// <param name="sender"></param>
  10861. /// <param name="e"></param>
  10862. private void label112_DoubleClick(object sender, EventArgs e)
  10863. {
  10864. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  10865. {
  10866. EnterForm1.ShowDialog();
  10867. try
  10868. {
  10869. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  10870. {
  10871. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  10872. {
  10873. try
  10874. {
  10875. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + comboBox_FacModeCfgFile.Text);
  10876. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_FacModeCfgFile.Text) + ".src");
  10877. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_FacModeCfgFile.Text) + ".png");
  10878. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  10879. }
  10880. catch (Exception)
  10881. {
  10882. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  10883. }
  10884. }
  10885. else
  10886. {
  10887. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  10888. }
  10889. }
  10890. }
  10891. catch (Exception)
  10892. {
  10893. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  10894. }
  10895. }
  10896. }
  10897. /// <summary>
  10898. /// 检验模式删除当前选中文件
  10899. /// </summary>
  10900. /// <param name="sender"></param>
  10901. /// <param name="e"></param>
  10902. private void label138_DoubleClick(object sender, EventArgs e)
  10903. {
  10904. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  10905. {
  10906. EnterForm1.ShowDialog();
  10907. try
  10908. {
  10909. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  10910. {
  10911. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  10912. {
  10913. try
  10914. {
  10915. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + comboBox_CheckModeCfgFile.Text);
  10916. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_CheckModeCfgFile.Text) + ".src");
  10917. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_CheckModeCfgFile.Text) + ".png");
  10918. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  10919. }
  10920. catch (Exception)
  10921. {
  10922. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  10923. }
  10924. }
  10925. else
  10926. {
  10927. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  10928. }
  10929. }
  10930. }
  10931. catch (Exception)
  10932. {
  10933. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  10934. }
  10935. }
  10936. }
  10937. /// <summary>
  10938. /// 读取整车信息2
  10939. /// </summary>
  10940. /// <param name="sender"></param>
  10941. /// <param name="e"></param>
  10942. private void button_ReadBikeParam2_Click(object sender, EventArgs e)
  10943. {
  10944. richTextBox_BikeParam2.Clear();
  10945. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null);
  10946. }
  10947. /// <summary>
  10948. /// 写入整车信息2
  10949. /// </summary>
  10950. /// <param name="sender"></param>
  10951. /// <param name="e"></param>
  10952. private void button_WriteBikeParam2_Click(object sender, EventArgs e)
  10953. {
  10954. var ConfigParam = new byte[34];
  10955. for (int i = 0; i < 34; i++)
  10956. ConfigParam[i] = 0;
  10957. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  10958. string[] strDataTemp = richTextBox_BikeParam2.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  10959. try
  10960. {
  10961. for (int i = 0; i < strDataTemp.Length; i++)
  10962. {
  10963. short wDataTemp = 0;
  10964. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  10965. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  10966. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  10967. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  10968. }
  10969. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4D22, ConfigParam);
  10970. }
  10971. catch (Exception)
  10972. {
  10973. timer_500ms.Enabled = false;
  10974. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  10975. timer_500ms.Enabled = true;
  10976. }
  10977. }
  10978. /// <summary>
  10979. /// 读取用户骑行参数
  10980. /// </summary>
  10981. /// <param name="sender"></param>
  10982. /// <param name="e"></param>
  10983. private void button_ReadUsrRideParam_Click(object sender, EventArgs e)
  10984. {
  10985. richTextBox_UsrRidesParam.Clear();
  10986. if (checkBox_UserRideParam_OBC.Checked)
  10987. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x4300, null);
  10988. else
  10989. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  10990. }
  10991. /// <summary>
  10992. /// 写入用户骑行参数
  10993. /// </summary>
  10994. /// <param name="sender"></param>
  10995. /// <param name="e"></param>
  10996. private void button_WriteUsrRidetParam_Click(object sender, EventArgs e)
  10997. {
  10998. var ConfigParam = new byte[34];
  10999. for (int i = 0; i < 34; i++)
  11000. ConfigParam[i] = 0;
  11001. if (checkBox_UserRideParam_OBC.Checked)
  11002. {
  11003. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  11004. string[] strDataTemp = richTextBox_UsrRidesParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  11005. try
  11006. {
  11007. for (int i = 0; i < strDataTemp.Length; i++)
  11008. {
  11009. ConfigParam[i + 2] = Convert.ToByte(strDataTemp[i].Split('=')[1]);
  11010. }
  11011. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4B22, ConfigParam);
  11012. }
  11013. catch (Exception)
  11014. {
  11015. timer_500ms.Enabled = false;
  11016. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  11017. timer_500ms.Enabled = true;
  11018. }
  11019. }
  11020. else
  11021. {
  11022. string[] strDataTemp = richTextBox_UsrRidesParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  11023. try
  11024. {
  11025. for (int i = 0; i < strDataTemp.Length; i++)
  11026. {
  11027. ConfigParam[i] = Convert.ToByte(strDataTemp[i].Split('=')[1]);
  11028. }
  11029. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x4420, ConfigParam);
  11030. }
  11031. catch (Exception)
  11032. {
  11033. timer_500ms.Enabled = false;
  11034. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  11035. timer_500ms.Enabled = true;
  11036. }
  11037. }
  11038. }
  11039. /// <summary>
  11040. /// 读取产品标签
  11041. /// </summary>
  11042. /// <param name="sender"></param>
  11043. /// <param name="e"></param>
  11044. private void button_ReadTag_Click(object sender, EventArgs e)
  11045. {
  11046. textBox_TagInfo.Text = "---";
  11047. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4E00, null);
  11048. }
  11049. /// <summary>
  11050. /// 写入产品标签
  11051. /// </summary>
  11052. /// <param name="sender"></param>
  11053. /// <param name="e"></param>
  11054. private void button_WriteTag_Click(object sender, EventArgs e)
  11055. {
  11056. string User = textBox_TagInfo.Text;
  11057. var UserArray = new byte[32];
  11058. for (ushort i = 0; i < User.Length; i++)
  11059. {
  11060. UserArray[i] = (byte)User[i];
  11061. }
  11062. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D20, UserArray);
  11063. }
  11064. /// <summary>
  11065. /// 上位机读取骑行历史
  11066. /// </summary>
  11067. /// <param name="sender"></param>
  11068. /// <param name="e"></param>
  11069. private void button_ReadRideLog_Click(object sender, EventArgs e)
  11070. {
  11071. textBox_ODO_KM.Text = "---";
  11072. textBox_ODO_TIME.Text = "---";
  11073. textBox_TRIP_KM.Text = "---";
  11074. textBox_TRIP_TIME.Text = "---";
  11075. textBox_OBC_TRIP_KM.Text = "";
  11076. textBox_OBC_TRIP_TIME.Text = "";
  11077. textBox_OBC_ODO_KM.Text = "";
  11078. textBox_OBC_ODO_TIME.Text = "";
  11079. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2E00, null);
  11080. }
  11081. /// <summary>
  11082. /// 上位机写入骑行历史
  11083. /// </summary>
  11084. /// <param name="sender"></param>
  11085. /// <param name="e"></param>
  11086. private void button_WriteRideLog_Click(object sender, EventArgs e)
  11087. {
  11088. UInt32 Data;
  11089. var UserArray = new byte[16];
  11090. try
  11091. {
  11092. Data = Convert.ToUInt32(textBox_ODO_KM.Text);
  11093. UserArray[0] = (byte)(Data & 0xFF);
  11094. UserArray[1] = (byte)(Data >> 8);
  11095. UserArray[2] = (byte)(Data >> 16);
  11096. UserArray[3] = (byte)(Data >> 24);
  11097. Data = Convert.ToUInt32(textBox_ODO_TIME.Text);
  11098. UserArray[4] = (byte)(Data & 0xFF);
  11099. UserArray[5] = (byte)(Data >> 8);
  11100. UserArray[6] = (byte)(Data >> 16);
  11101. UserArray[7] = (byte)(Data >> 24);
  11102. Data = Convert.ToUInt32(textBox_TRIP_KM.Text);
  11103. UserArray[8] = (byte)(Data & 0xFF);
  11104. UserArray[9] = (byte)(Data >> 8);
  11105. UserArray[10] = (byte)(Data >> 16);
  11106. UserArray[11] = (byte)(Data >> 24);
  11107. Data = Convert.ToUInt32(textBox_TRIP_TIME.Text);
  11108. UserArray[12] = (byte)(Data & 0xFF);
  11109. UserArray[13] = (byte)(Data >> 8);
  11110. UserArray[14] = (byte)(Data >> 16);
  11111. UserArray[15] = (byte)(Data >> 24);
  11112. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B10, UserArray);
  11113. }
  11114. catch (Exception ex)
  11115. {
  11116. MessageBox.Show("数据格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  11117. }
  11118. }
  11119. /// <summary>
  11120. /// 获取删除配置文件日期列表
  11121. /// </summary>
  11122. /// <param name="sender"></param>
  11123. /// <param name="e"></param>
  11124. private void toolStripTextBox_DelCfgFile_Click(object sender, EventArgs e)
  11125. {
  11126. string[] DateList = { "" };
  11127. //网络断开时直接退出
  11128. if (!myFtp.IsNetConnected)
  11129. return;
  11130. //从服务器更新日期列表
  11131. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
  11132. toolStripTextBox_DelCfgFile.Items.Clear();
  11133. //日期列表加载,显示最近30条
  11134. if (DateList.Length > 30)
  11135. {
  11136. toolStripTextBox_DelCfgFile.Items.Add("支持最近30条");
  11137. toolStripTextBox_DelCfgFile.Items.Add("-----");
  11138. }
  11139. for (int i = (DateList.Length > 30) ? (DateList.Length - 30) : 0; i < DateList.Length; i++)//显示最近30个日期
  11140. {
  11141. toolStripTextBox_DelCfgFile.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  11142. }
  11143. }
  11144. /// <summary>
  11145. /// 删除指定配置文件
  11146. /// </summary>
  11147. /// <param name="sender"></param>
  11148. /// <param name="e"></param>
  11149. private void toolStripTextBox_DelCfgFile_SelectedIndexChanged(object sender, EventArgs e)
  11150. {
  11151. //提示输入文件名
  11152. Scan scan_form = new Scan();
  11153. scan_form.ShowDialog();
  11154. do
  11155. {
  11156. if (scan_form.textBox_Scan.Text == string.Empty)
  11157. {
  11158. timer_500ms.Enabled = false;
  11159. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  11160. timer_500ms.Enabled = true;
  11161. break;
  11162. }
  11163. string DelFile = scan_form.textBox_Scan.Text;
  11164. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  11165. {
  11166. EnterForm1.ShowDialog();
  11167. try
  11168. {
  11169. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  11170. {
  11171. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  11172. {
  11173. try
  11174. {
  11175. if (DelFile.Contains("."))
  11176. DelFile = Path.GetFileNameWithoutExtension(DelFile);
  11177. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".ttcfg");
  11178. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".src");
  11179. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".png");
  11180. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  11181. }
  11182. catch (Exception)
  11183. {
  11184. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  11185. }
  11186. }
  11187. else
  11188. {
  11189. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  11190. }
  11191. }
  11192. }
  11193. catch (Exception)
  11194. {
  11195. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  11196. }
  11197. }
  11198. } while (false);
  11199. }
  11200. /// <summary>
  11201. /// 获取删除样机测试记录日期列表
  11202. /// </summary>
  11203. /// <param name="sender"></param>
  11204. /// <param name="e"></param>
  11205. private void toolStripTextBox_DelLogFile_Click(object sender, EventArgs e)
  11206. {
  11207. string[] DateList = { "" };
  11208. //网络断开时直接退出
  11209. if (!myFtp.IsNetConnected)
  11210. return;
  11211. //从服务器更新日期列表
  11212. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName);
  11213. toolStripTextBox_DelLogFile.Items.Clear();
  11214. //日期列表加载,显示最近30天
  11215. if (DateList.Length > 30)
  11216. {
  11217. toolStripTextBox_DelLogFile.Items.Add("支持最近30条");
  11218. toolStripTextBox_DelLogFile.Items.Add("-----");
  11219. }
  11220. for (int i = (DateList.Length > 30) ? (DateList.Length - 30) : 0; i < DateList.Length; i++)//显示最近30个日期
  11221. {
  11222. toolStripTextBox_DelLogFile.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  11223. }
  11224. }
  11225. /// <summary>
  11226. /// 删除指定的样机测试记录
  11227. /// </summary>
  11228. /// <param name="sender"></param>
  11229. /// <param name="e"></param>
  11230. private void toolStripTextBox_DelLogFile_SelectedIndexChanged(object sender, EventArgs e)
  11231. {
  11232. //提示输入文件名
  11233. Scan scan_form = new Scan();
  11234. scan_form.ShowDialog();
  11235. do
  11236. {
  11237. if (scan_form.textBox_Scan.Text == string.Empty)
  11238. {
  11239. timer_500ms.Enabled = false;
  11240. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  11241. timer_500ms.Enabled = true;
  11242. break;
  11243. }
  11244. string DelFile = scan_form.textBox_Scan.Text;
  11245. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  11246. {
  11247. EnterForm1.ShowDialog();
  11248. try
  11249. {
  11250. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  11251. {
  11252. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  11253. {
  11254. try
  11255. {
  11256. //删除指定目录下面所有文件和文件夹
  11257. myFtp.DelDirectoryWithAll(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName + "\\" + toolStripTextBox_DelLogFile.Text + "\\" + DelFile);
  11258. myFtp.RemoveDirectory(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName + "\\" + toolStripTextBox_DelLogFile.Text + "\\" + DelFile);
  11259. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  11260. }
  11261. catch (Exception)
  11262. {
  11263. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  11264. }
  11265. }
  11266. else
  11267. {
  11268. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  11269. }
  11270. }
  11271. }
  11272. catch (Exception)
  11273. {
  11274. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  11275. }
  11276. }
  11277. } while (false);
  11278. }
  11279. /// <summary>
  11280. /// CAN协议选择
  11281. /// </summary>
  11282. /// <param name="sender"></param>
  11283. /// <param name="e"></param>
  11284. private void cANToolStripMenuItem_Click(object sender, EventArgs e)
  11285. {
  11286. cANToolStripMenuItem.Checked= true;
  11287. uARTToolStripMenuItem.Checked = false;
  11288. UART协议ToolStripMenuItem.Visible = false;
  11289. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  11290. }
  11291. /// <summary>
  11292. /// UART协议选择
  11293. /// </summary>
  11294. /// <param name="sender"></param>
  11295. /// <param name="e"></param>
  11296. private void uARTToolStripMenuItem_Click(object sender, EventArgs e)
  11297. {
  11298. cANToolStripMenuItem.Checked = false;
  11299. uARTToolStripMenuItem.Checked = true;
  11300. UART协议ToolStripMenuItem.Visible = true;
  11301. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  11302. }
  11303. /// <summary>
  11304. /// 清除流水号
  11305. /// </summary>
  11306. /// <param name="sender"></param>
  11307. /// <param name="e"></param>
  11308. private void label131_DoubleClick(object sender, EventArgs e)
  11309. {
  11310. if (MessageBox.Show("确认清零流水号?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  11311. {
  11312. label_FacModeSerial.Text = "0";
  11313. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, label_FacModeSerial.Text);
  11314. }
  11315. }
  11316. /// <summary>
  11317. /// 清除流水号
  11318. /// </summary>
  11319. /// <param name="sender"></param>
  11320. /// <param name="e"></param>
  11321. private void label135_DoubleClick(object sender, EventArgs e)
  11322. {
  11323. if (MessageBox.Show("确认清零流水号?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  11324. {
  11325. label_CheckModeSerial.Text = "0";
  11326. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, label_CheckModeSerial.Text);
  11327. }
  11328. }
  11329. /// <summary>
  11330. /// 打开自动更新
  11331. /// </summary>
  11332. /// <param name="sender"></param>
  11333. /// <param name="e"></param>
  11334. private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
  11335. {
  11336. 打开ToolStripMenuItem.Checked = true;
  11337. 关闭ToolStripMenuItem.Checked = false;
  11338. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  11339. }
  11340. /// <summary>
  11341. /// 关闭自动更新
  11342. /// </summary>
  11343. /// <param name="sender"></param>
  11344. /// <param name="e"></param>
  11345. private void 关闭ToolStripMenuItem_Click(object sender, EventArgs e)
  11346. {
  11347. 打开ToolStripMenuItem.Checked = false;
  11348. 关闭ToolStripMenuItem.Checked = true;
  11349. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  11350. }
  11351. /// <summary>
  11352. /// 显示完整配置文件
  11353. /// </summary>
  11354. /// <param name="sender"></param>
  11355. /// <param name="e"></param>
  11356. private void comboBox_FacModeCfgFile_MouseHover_1(object sender, EventArgs e)
  11357. {
  11358. // 创建the ToolTip
  11359. ToolTip toolTip1 = new ToolTip();
  11360. // 设置显示样式
  11361. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  11362. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  11363. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  11364. toolTip1.ShowAlways = true;//是否显示提示框
  11365. // 设置伴随的对象.
  11366. toolTip1.SetToolTip(this.comboBox_FacModeCfgFile, comboBox_FacModeCfgFile.Text);//设置故障内容显示
  11367. }
  11368. /// <summary>
  11369. /// 显示完整配置文件
  11370. /// </summary>
  11371. /// <param name="sender"></param>
  11372. /// <param name="e"></param>
  11373. private void comboBox_CheckModeCfgFile_MouseHover_1(object sender, EventArgs e)
  11374. {
  11375. // 创建the ToolTip
  11376. ToolTip toolTip1 = new ToolTip();
  11377. // 设置显示样式
  11378. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  11379. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  11380. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  11381. toolTip1.ShowAlways = true;//是否显示提示框
  11382. // 设置伴随的对象.
  11383. toolTip1.SetToolTip(this.comboBox_CheckModeCfgFile, comboBox_CheckModeCfgFile.Text);//设置故障内容显示
  11384. }
  11385. /// <summary>
  11386. /// 手动发送指令
  11387. /// </summary>
  11388. /// <param name="sender"></param>
  11389. /// <param name="e"></param>
  11390. private void 发送指令ToolStripMenuItem_Click(object sender, EventArgs e)
  11391. {
  11392. //提示
  11393. Scan scan_form = new Scan();
  11394. scan_form.label1.Text = "按照16进制填写,相邻字节用空格隔开,依次填写ID、Mode、Cmd、Data\r\n例如:07 31 16 22 05 01 02 03 04 05";
  11395. scan_form.ShowDialog();
  11396. //发送写入的指令,填写ID、类型、命令字、数据
  11397. do
  11398. {
  11399. if (scan_form.textBox_Scan.Text == string.Empty)
  11400. {
  11401. timer_500ms.Enabled = false;
  11402. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  11403. timer_500ms.Enabled = true;
  11404. break;
  11405. }
  11406. //输入文本转换为字节流
  11407. var InputData = new byte[256];
  11408. InputData = mySerialProcess.HexStringToBytes(scan_form.textBox_Scan.Text, true);
  11409. //ID
  11410. ushort ID;
  11411. ID = (ushort)((InputData[0] << 8) + InputData[1]);
  11412. //Mode
  11413. byte Mode;
  11414. Mode = InputData[2];
  11415. //Cmd
  11416. ushort Cmd;
  11417. Cmd = (ushort)((InputData[3] << 8) + InputData[4]);
  11418. //Data
  11419. var Data = new byte[Cmd & 0x00FF];
  11420. for (int i = 0; i < (Cmd & 0x00FF); i++)
  11421. Data[i] = InputData[5 + i];
  11422. //发送数据
  11423. mySerialProcess.SendCmdWithoutNotice(ID, Mode, Cmd, Data);
  11424. } while (false);
  11425. }
  11426. /// <summary>
  11427. /// 启动位置传感器校准
  11428. /// </summary>
  11429. /// <param name="sender"></param>
  11430. /// <param name="e"></param>
  11431. private void button_AngleCalStart_Click(object sender, EventArgs e)
  11432. {
  11433. for (int i = 0; i < 7; i++)
  11434. for (int j = 0; j < 6; j++)
  11435. {
  11436. dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = "";
  11437. }
  11438. foreach (Control cr in tabPage_AngleCal.Controls)
  11439. {
  11440. if (cr is TextBox)
  11441. {
  11442. if ((cr != textBox_AngleDiffTh) && (cr != textBox_AngleZeroTh))
  11443. cr.Text = "";
  11444. }
  11445. }
  11446. var Data = new byte[2];
  11447. mySerialProcess.SendCmd((ushort)0x751, (byte)0x0C, (ushort)0x5002, Data);
  11448. }
  11449. /// <summary>
  11450. /// 导出位置传感器校准数据
  11451. /// </summary>
  11452. /// <param name="sender"></param>
  11453. /// <param name="e"></param>
  11454. private void button_AngleExportData_Click(object sender, EventArgs e)
  11455. {
  11456. //读出产品信息
  11457. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  11458. Delay_ms(200);
  11459. SaveFileDialog sfd = new SaveFileDialog
  11460. {
  11461. FileName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + "位置传感器角度数据_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt",
  11462. Filter = "文本文档(*.txt)|*.txt",
  11463. Title = "Save"
  11464. };
  11465. if (sfd.ShowDialog() != DialogResult.OK)
  11466. {
  11467. return;
  11468. }
  11469. string filepath = sfd.FileName;
  11470. FileStream fs = new FileStream(filepath, FileMode.OpenOrCreate);
  11471. using (StreamWriter sw = new StreamWriter(fs))
  11472. {
  11473. sw.Write("标准值 ");
  11474. sw.Write("60.00 ");
  11475. sw.Write("120.00 ");
  11476. sw.Write("180.00 ");
  11477. sw.Write("240.00 ");
  11478. sw.Write("300.00 ");
  11479. sw.Write("360.00 ");
  11480. for (int i = 0; i < 42; i++)
  11481. {
  11482. if ((i % 6 == 0))
  11483. {
  11484. sw.Write("\r\n" + "采集值" + (i / 6 + 1).ToString() + " ");
  11485. }
  11486. sw.Write(AngledataRecord[i] + " ");
  11487. }
  11488. sw.Write("\r\n" + "历史零点位置 " + textBox_AngleZeroInit.Text);
  11489. sw.Write("\r\n" + "当前零点位置 " + textBox_AngleZeroCur.Text);
  11490. sw.Write("\r\n" + "零点误差 " + textBox_AngleZeroDiff.Text);
  11491. sw.Write("\r\n" + "最小偏差值 " + textBox_AngleDiffMin.Text);
  11492. sw.Write("\r\n" + "最大偏差值 " + textBox_AngleDiffMax.Text);
  11493. sw.Write("\r\n" + "平均偏差值 " + textBox_AngleDiffAvg.Text);
  11494. sw.Flush();
  11495. }
  11496. fs.Close();
  11497. }
  11498. /// <summary>
  11499. /// 写入校准数据
  11500. /// </summary>
  11501. /// <param name="sender"></param>
  11502. /// <param name="e"></param>
  11503. private void button_AngleWrite_Click(object sender, EventArgs e)
  11504. {
  11505. if ((textBox_AngleDiffAvg.Text == "") || (textBox_AngleZeroInit.Text == ""))
  11506. {
  11507. timer_500ms.Enabled = false;
  11508. MessageBox.Show("请先启动校准,以确认校准数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  11509. timer_500ms.Enabled = true;
  11510. return;
  11511. }
  11512. timer_500ms.Enabled = false;
  11513. string str1 = "确认校准数据,历史零点: " + textBox_AngleZeroInit.Text + ", 偏差平均值: " + textBox_AngleDiffAvg.Text;
  11514. if (MessageBox.Show(str1, "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  11515. {
  11516. var SaveFlag = new byte[4];
  11517. for (int i = 0; i < 4; i++)
  11518. SaveFlag[i] = 0;
  11519. SaveFlag[0] = (byte)(1);
  11520. double data1 = Convert.ToDouble(textBox_AngleZeroInit.Text) - Convert.ToDouble(textBox_AngleDiffAvg.Text);
  11521. if (data1 > 360)
  11522. {
  11523. data1 -= 360;
  11524. }
  11525. else if (data1 < -360)
  11526. {
  11527. data1 += 360;
  11528. }
  11529. Int16 data2 = (Int16)(data1 * 32768 / 360);
  11530. SaveFlag[2] = (byte)(data2);
  11531. SaveFlag[3] = (byte)(data2 >> 8);
  11532. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, SaveFlag);
  11533. timer_500ms.Enabled = true;
  11534. }
  11535. else
  11536. {
  11537. timer_500ms.Enabled = true;
  11538. MessageBoxTimeOut.Show("写入取消", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  11539. }
  11540. }
  11541. /// <summary>
  11542. /// 存储允许偏差
  11543. /// </summary>
  11544. /// <param name="sender"></param>
  11545. /// <param name="e"></param>
  11546. private void textBox_AngleDiffTh_KeyDown(object sender, KeyEventArgs e)
  11547. {
  11548. if (e.KeyCode == Keys.Enter)
  11549. {
  11550. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  11551. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  11552. }
  11553. }
  11554. /// <summary>
  11555. /// 存储零点允许偏差
  11556. /// </summary>
  11557. /// <param name="sender"></param>
  11558. /// <param name="e"></param>
  11559. private void textBox_AngleZeroTh_KeyDown(object sender, KeyEventArgs e)
  11560. {
  11561. if (e.KeyCode == Keys.Enter)
  11562. {
  11563. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  11564. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  11565. }
  11566. }
  11567. /// <summary>
  11568. /// 删除服务器配置文件
  11569. /// </summary>
  11570. /// <param name="sender"></param>
  11571. /// <param name="e"></param>
  11572. private void 重置ToolStripMenuItem_Click(object sender, EventArgs e)
  11573. {
  11574. if (MessageBox.Show("重置后软件自动关闭,确认重置?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  11575. {
  11576. if(File.Exists(localInfo.LocalPath + localInfo.ServerCfgFileName))
  11577. File.Delete(localInfo.LocalPath + localInfo.ServerCfgFileName);
  11578. if(File.Exists(localInfo.LocalPath + localInfo.ConfigFileName))
  11579. File.Delete(localInfo.LocalPath + localInfo.ConfigFileName);
  11580. System.Environment.Exit(0);
  11581. }
  11582. }
  11583. /// <summary>
  11584. /// 按下Enter保存数据
  11585. /// </summary>
  11586. /// <param name="sender"></param>
  11587. /// <param name="e"></param>
  11588. private void toolStripTextBox_AngleAvgMax_KeyDown(object sender, KeyEventArgs e)
  11589. {
  11590. textBox_AngleDiffTh.Text = toolStripTextBox_AngleAvgMax.Text;
  11591. if (e.KeyCode == Keys.Enter)
  11592. {
  11593. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  11594. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  11595. }
  11596. }
  11597. /// <summary>
  11598. /// 按下Enter保存数据
  11599. /// </summary>
  11600. /// <param name="sender"></param>
  11601. /// <param name="e"></param>
  11602. private void toolStripTextBox_AngleZeroMax_KeyDown(object sender, KeyEventArgs e)
  11603. {
  11604. textBox_AngleZeroTh.Text = toolStripTextBox_AngleZeroMax.Text;
  11605. if (e.KeyCode == Keys.Enter)
  11606. {
  11607. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  11608. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  11609. }
  11610. }
  11611. private void 帮助ToolStripMenuItem_Click(object sender, EventArgs e)
  11612. {
  11613. //检查本地文件
  11614. if (!File.Exists(localInfo.LocalPath + localInfo.HelpFilename))
  11615. {
  11616. if (!OfflineFlag)
  11617. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/help/" + localInfo.HelpFilename, localInfo.LocalPath);
  11618. else
  11619. {
  11620. MessageBoxTimeOut.Show("未找到帮助文件!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  11621. return;
  11622. }
  11623. }
  11624. //调用本地浏览器打开帮助文件
  11625. System.Diagnostics.Process.Start("explorer", localInfo.LocalPath + localInfo.HelpFilename);
  11626. }
  11627. /// <summary>
  11628. /// 读取故障日志地址
  11629. /// </summary>
  11630. /// <param name="sender"></param>
  11631. /// <param name="e"></param>
  11632. private void button_ReadLogAddr_Click(object sender, EventArgs e)
  11633. {
  11634. textBox_LogAddrBegin.Text = "";
  11635. textBox_LogAddrEnd.Text = "";
  11636. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x5200, null);
  11637. }
  11638. /// <summary>
  11639. /// 写入硬件版本
  11640. /// </summary>
  11641. /// <param name="sender"></param>
  11642. /// <param name="e"></param>
  11643. private void button_WriteHW_Click(object sender, EventArgs e)
  11644. {
  11645. string HW = textBox_HW.Text;
  11646. var HWArray = new byte[16];
  11647. for (ushort i = 0; i < HW.Length; i++)
  11648. {
  11649. HWArray[i] = (byte)HW[i];
  11650. }
  11651. if (HW.Length < 16)
  11652. {
  11653. HWArray[HW.Length] = (byte)'.';
  11654. for (ushort i = 0; i < 16 - HW.Length - 1; i++)
  11655. {
  11656. HWArray[HW.Length + 1 + i] = 0x20;
  11657. }
  11658. }
  11659. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5310, HWArray);
  11660. }
  11661. /// <summary>
  11662. /// 生产模式写入HW
  11663. /// </summary>
  11664. /// <param name="sender"></param>
  11665. /// <param name="e"></param>
  11666. private void Button_FacModeSetHW_Click(object sender, EventArgs e)
  11667. {
  11668. string HW = textBox_FacModeHW.Text;
  11669. var HWArray = new byte[16];
  11670. for (ushort i = 0; i < HW.Length; i++)
  11671. {
  11672. HWArray[i] = (byte)HW[i];
  11673. }
  11674. if (HW.Length < 16)
  11675. {
  11676. HWArray[HW.Length] = (byte)'.';
  11677. for (ushort i = 0; i < 16 - HW.Length - 1; i++)
  11678. {
  11679. HWArray[HW.Length + 1 + i] = 0x20;
  11680. }
  11681. }
  11682. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5310, HWArray);
  11683. }
  11684. /// <summary>
  11685. /// 读取定制编号
  11686. /// </summary>
  11687. /// <param name="sender"></param>
  11688. /// <param name="e"></param>
  11689. private void button_ReadUserNum_Click(object sender, EventArgs e)
  11690. {
  11691. textBox_UserNum.Text = "---";
  11692. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x5600, null);
  11693. }
  11694. /// <summary>
  11695. /// 写入定制编号
  11696. /// </summary>
  11697. /// <param name="sender"></param>
  11698. /// <param name="e"></param>
  11699. private void button_WriteUserNum_Click(object sender, EventArgs e)
  11700. {
  11701. string User = textBox_UserNum.Text;
  11702. var UserArray = new byte[32];
  11703. for (ushort i = 0; i < User.Length; i++)
  11704. {
  11705. UserArray[i] = (byte)User[i];
  11706. }
  11707. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5720, UserArray);
  11708. }
  11709. /// <summary>
  11710. /// 读取指定块拓展功能
  11711. /// </summary>
  11712. /// <param name="sender"></param>
  11713. /// <param name="e"></param>
  11714. private void button_FunSet_Read_Click(object sender, EventArgs e)
  11715. {
  11716. if (comboBox_FunSet_BlockNum.SelectedIndex < 0)
  11717. {
  11718. MessageBox.Show("请选择块编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  11719. }
  11720. else
  11721. {
  11722. //清空当前内容
  11723. for (int i = 0; i < 8; i++)
  11724. for (int j = 0; j < 8; j++)
  11725. {
  11726. dataGridView_FunSet.Rows[i].Cells[j + 1].Value = "";
  11727. }
  11728. //发送读取指令
  11729. ushort Num = (ushort)(comboBox_FunSet_BlockNum.SelectedIndex + 1);
  11730. var Code = new byte[2];
  11731. Code[0] = (byte)(Num & 0xFF);
  11732. Code[1] = (byte)(Num >> 8);
  11733. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x5402, Code);
  11734. }
  11735. }
  11736. /// <summary>
  11737. /// 写入指定块或指定单元参数
  11738. /// </summary>
  11739. /// <param name="sender"></param>
  11740. /// <param name="e"></param>
  11741. private void button_FunSet_Write_Click(object sender, EventArgs e)
  11742. {
  11743. if (radioButton_WriteByBlock.Checked == true)
  11744. {
  11745. if (comboBox_FunSet_BlockNum.SelectedIndex < 0)
  11746. MessageBox.Show("请选择块编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  11747. else
  11748. {
  11749. //开始按块写入
  11750. ushort Num = (ushort)(comboBox_FunSet_BlockNum.SelectedIndex + 1);
  11751. var Code = new byte[66];
  11752. Code[0] = (byte)(Num & 0xFF);
  11753. Code[1] = (byte)(Num >> 8);
  11754. for (int i = 0; i < 8; i++)
  11755. for (int j = 0; j < 8; j++)
  11756. {
  11757. try
  11758. {
  11759. byte Data = Convert.ToByte(dataGridView_FunSet.Rows[i].Cells[j + 1].Value);
  11760. Code[i * 8 + j + 2] = (byte)(Data & 0xFF);
  11761. }
  11762. catch (Exception)
  11763. {
  11764. MessageBox.Show("数据格式错误或超范围!\r\n" + "单元编号:" + (i + 1).ToString() + "\r\n" + "参数:" + (j + 1).ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  11765. return;
  11766. }
  11767. }
  11768. if (MessageBox.Show("请核对块编号!\r\n" + "块编号:" + (Num).ToString(), "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  11769. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5542, Code);
  11770. else
  11771. MessageBoxTimeOut.Show("取消写入", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  11772. }
  11773. }
  11774. else if (radioButton_WriteByUnit.Checked == true)
  11775. {
  11776. if (comboBox_FunSet_BlockNum.SelectedIndex < 0)
  11777. MessageBox.Show("请选择块编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  11778. else
  11779. {
  11780. if (comboBox_FunSet_UnitNum.SelectedIndex < 0)
  11781. MessageBox.Show("请选择单元编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  11782. else
  11783. {
  11784. //开始按单元写入
  11785. ushort Num1 = (ushort)(comboBox_FunSet_BlockNum.SelectedIndex + 1);
  11786. ushort Num2 = (ushort)(comboBox_FunSet_UnitNum.SelectedIndex + 1);
  11787. var Code = new byte[12];
  11788. Code[0] = (byte)(Num1 & 0xFF);
  11789. Code[1] = (byte)(Num1 >> 8);
  11790. Code[2] = (byte)(Num2 & 0xFF);
  11791. Code[3] = (byte)(Num2 >> 8);
  11792. for (int i = 0; i < 8; i++)
  11793. {
  11794. try
  11795. {
  11796. byte Data = Convert.ToByte(dataGridView_FunSet.Rows[Num2 - 1].Cells[i + 1].Value);
  11797. Code[i + 4] = (byte)(Data & 0xFF);
  11798. }
  11799. catch (Exception)
  11800. {
  11801. MessageBox.Show("数据格式错误或超范围!\r\n" + "单元编号:" + Num2.ToString() + "\r\n" + "参数:" + (i + 1).ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  11802. return;
  11803. }
  11804. }
  11805. if (MessageBox.Show("请核对块编号和单元编号!\r\n" + "块编号:" + Num1.ToString() + "\r\n" + "单元编号:" + Num2.ToString(), "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  11806. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x550C, Code);
  11807. else
  11808. MessageBoxTimeOut.Show("取消写入", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  11809. }
  11810. }
  11811. }
  11812. else
  11813. {
  11814. MessageBox.Show("请选择写入方式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  11815. }
  11816. }
  11817. /// <summary>
  11818. /// 按块写入时隐藏单元编号
  11819. /// </summary>
  11820. /// <param name="sender"></param>
  11821. /// <param name="e"></param>
  11822. private void radioButton_WriteByUnit_CheckedChanged(object sender, EventArgs e)
  11823. {
  11824. if (radioButton_WriteByUnit.Checked == true)
  11825. {
  11826. label159.Visible = true;
  11827. comboBox_FunSet_UnitNum.Visible = true;
  11828. }
  11829. else
  11830. {
  11831. label159.Visible = false;
  11832. comboBox_FunSet_UnitNum.Visible = false;
  11833. }
  11834. }
  11835. private void 样机测试ToolStripMenuItem_Click(object sender, EventArgs e)
  11836. {
  11837. 样机测试ToolStripMenuItem.Checked = !样机测试ToolStripMenuItem.Checked;
  11838. }
  11839. private void timer_AckWait_Tick(object sender, EventArgs e)
  11840. {
  11841. //写入参数等待计时
  11842. ACK_WaitCnt++;
  11843. }
  11844. /// <summary>
  11845. /// 打开或关闭指令窗口
  11846. /// </summary>
  11847. /// <param name="sender"></param>
  11848. /// <param name="e"></param>
  11849. private void 指令调试ToolStripMenuItem_Click(object sender, EventArgs e)
  11850. {
  11851. if (指令调试ToolStripMenuItem.Checked == false)
  11852. {
  11853. if (DebugForm.debug1 == null || DebugForm.debug1.IsDisposed)
  11854. {
  11855. DebugForm.debug1 = new DebugForm();
  11856. DebugForm.debug1.Show();
  11857. this.DebugWindowIsOpen = true;
  11858. }
  11859. else
  11860. {
  11861. DebugForm.debug1.Activate();
  11862. this.DebugWindowIsOpen = true;
  11863. }
  11864. 指令调试ToolStripMenuItem.Checked = true;
  11865. }
  11866. else
  11867. {
  11868. if (this.DebugWindowIsOpen == true)
  11869. {
  11870. DebugForm.debug1.Close();
  11871. this.DebugWindowIsOpen = false;
  11872. this.DebugDataDisplayEnable = false;
  11873. }
  11874. 指令调试ToolStripMenuItem.Checked = false;
  11875. }
  11876. }
  11877. /// <summary>
  11878. /// 读联动装置盒配置
  11879. /// </summary>
  11880. /// <param name="sender"></param>
  11881. /// <param name="e"></param>
  11882. private void 联动装置盒配置ToolStripMenuItem_Click(object sender, EventArgs e)
  11883. {
  11884. toolStripComboBox_PortMode.SelectedIndex = -1;
  11885. toolStripComboBox_CANBaud.SelectedIndex = -1;
  11886. toolStripComboBox_UARTBOOTBAUD.SelectedIndex = -1;
  11887. toolStripComboBox_UARTAPPBAUD.SelectedIndex = -1;
  11888. toolStripTextBox_CDL_Version.Text = "";
  11889. toolStripTextBox_OPTION_GIANT.Checked = false;
  11890. toolStripTextBox_OPTION_Others.Text = "";
  11891. Read_CDL_Info();
  11892. }
  11893. /// <summary>
  11894. /// 写入联动装置盒接口类型
  11895. /// </summary>
  11896. /// <param name="sender"></param>
  11897. /// <param name="e"></param>
  11898. private void toolStripComboBox_PortMode_Click(object sender, EventArgs e)
  11899. {
  11900. byte[] SendData = new byte[4];
  11901. if (toolStripComboBox_PortMode.SelectedIndex == 0) //CAN
  11902. {
  11903. SendData[0] = 0;
  11904. SendData[1] = 0;
  11905. SendData[2] = 0;
  11906. SendData[3] = 1;
  11907. }
  11908. else if (toolStripComboBox_PortMode.SelectedIndex == 1) //UART
  11909. {
  11910. SendData[0] = 0;
  11911. SendData[1] = 0;
  11912. SendData[2] = 0;
  11913. SendData[3] = 2;
  11914. }
  11915. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x8104, SendData);
  11916. }
  11917. private void toolStripComboBox_UARTBOOTBAUD_Click(object sender, EventArgs e)
  11918. {
  11919. byte[] SendData = new byte[4];
  11920. string str = toolStripComboBox_UARTBOOTBAUD.Text;
  11921. if (str != string.Empty)
  11922. {
  11923. SendData[0] = (byte)((int.Parse(str) >> 24) & 0xFF);
  11924. SendData[1] = (byte)((int.Parse(str) >> 16) & 0xFF);
  11925. SendData[2] = (byte)((int.Parse(str) >> 8) & 0xFF);
  11926. SendData[3] = (byte)((int.Parse(str) >> 0) & 0xFF);
  11927. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x8304, SendData);
  11928. }
  11929. }
  11930. private void toolStripComboBox_UARTAPPBAUD_Click(object sender, EventArgs e)
  11931. {
  11932. byte[] SendData = new byte[4];
  11933. string str = toolStripComboBox_UARTAPPBAUD.Text;
  11934. if (str != string.Empty)
  11935. {
  11936. SendData[0] = (byte)((int.Parse(str) >> 24) & 0xFF);
  11937. SendData[1] = (byte)((int.Parse(str) >> 16) & 0xFF);
  11938. SendData[2] = (byte)((int.Parse(str) >> 8) & 0xFF);
  11939. SendData[3] = (byte)((int.Parse(str) >> 0) & 0xFF);
  11940. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x8504, SendData);
  11941. }
  11942. }
  11943. /// <summary>
  11944. /// 设置CDL GIANT内容
  11945. /// </summary>
  11946. /// <param name="sender"></param>
  11947. /// <param name="e"></param>
  11948. private void toolStripTextBox_OPTION_GIANT_Click(object sender, EventArgs e)
  11949. {
  11950. string User = toolStripTextBox_OPTION_GIANT.Text;
  11951. var UserArray = new byte[16];
  11952. for (ushort i = 0; i < User.Length; i++)
  11953. {
  11954. UserArray[i] = (byte)User[i];
  11955. }
  11956. if (User.Length < 16)
  11957. {
  11958. UserArray[User.Length] = (byte)'.';
  11959. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  11960. {
  11961. UserArray[User.Length + 1 + i] = 0x20;
  11962. }
  11963. }
  11964. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x8910, UserArray);
  11965. }
  11966. /// <summary>
  11967. /// 设定CDL定制内容
  11968. /// </summary>
  11969. /// <param name="sender"></param>
  11970. /// <param name="e"></param>
  11971. private void toolStripTextBox_OPTION_Others_KeyDown(object sender, KeyEventArgs e)
  11972. {
  11973. if (e.KeyCode == Keys.Enter)
  11974. {
  11975. string User = toolStripTextBox_OPTION_Others.Text;
  11976. var UserArray = new byte[16];
  11977. for (ushort i = 0; i < User.Length; i++)
  11978. {
  11979. UserArray[i] = (byte)User[i];
  11980. }
  11981. if (User.Length < 16)
  11982. {
  11983. UserArray[User.Length] = (byte)'.';
  11984. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  11985. {
  11986. UserArray[User.Length + 1 + i] = 0x20;
  11987. }
  11988. }
  11989. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x8910, UserArray);
  11990. }
  11991. }
  11992. private void toolStripComboBox_CANBaud_Click(object sender, EventArgs e)
  11993. {
  11994. byte[] SendData = new byte[4];
  11995. string str = toolStripComboBox_CANBaud.Text;
  11996. if (str != string.Empty)
  11997. {
  11998. SendData[0] = (byte)((int.Parse(str) >> 24) & 0xFF);
  11999. SendData[1] = (byte)((int.Parse(str) >> 16) & 0xFF);
  12000. SendData[2] = (byte)((int.Parse(str) >> 8) & 0xFF);
  12001. SendData[3] = (byte)((int.Parse(str) >> 0) & 0xFF);
  12002. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x8704, SendData);
  12003. }
  12004. }
  12005. //读取联动装置盒数据
  12006. private void Read_CDL_Info()
  12007. {
  12008. //类型
  12009. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x11, (ushort)0x8000, null);
  12010. Delay_ms(100);
  12011. //CAN 波特率
  12012. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x11, (ushort)0x8600, null);
  12013. Delay_ms(100);
  12014. //UART BOOT波特率
  12015. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x11, (ushort)0x8200, null);
  12016. Delay_ms(100);
  12017. //UART APP波特率
  12018. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x11, (ushort)0x8400, null);
  12019. Delay_ms(100);
  12020. //版本
  12021. byte[] SendData = new byte[20];
  12022. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x11, (ushort)0x5514, SendData);
  12023. Delay_ms(100);
  12024. //定制内容
  12025. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x11, (ushort)0x8800, null);
  12026. Delay_ms(100);
  12027. }
  12028. }
  12029. }