mainForm.cs 321 KB

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