mainForm.cs 331 KB

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