12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Diagnostics.Eventing.Reader;
- using System.Drawing;
- using System.IO;
- using System.IO.Ports;
- using System.Linq;
- using System.Reflection;
- using System.Runtime.InteropServices;
- using System.Text.RegularExpressions;
- using System.Threading;
- using System.Web;
- using System.Windows.Forms;
- using System.Xml.Linq;
- //using static System.Windows.Forms.VisualStyles.VisualStyleElement;
- namespace Welling_Motor_Debug_Tool
- {
- public partial class mainForm : Form
- {
- #region 变量定义
- //串口实例
- Serial_Process mySerialProcess = new Serial_Process();
- string PortNumSave = "";
- string PortBaudrateSave = "";
- //本地信息定义
- LocalInfo localInfo = new LocalInfo();
- //FTP实例
- ftp myFtp = new ftp();
- //MC运行信息超时计数
- bool MC_RunInfo_Refresh = false;
- ushort MC_RunInfo_Refresh_Cnt = 0;
- //MC调试信息超时计数
- bool MC_DebugInfo_Refresh = false;
- ushort MC_DebugInfo_Refresh_Cnt = 0;
- //MC故障码超时计数
- bool MC_ErrorCode_Refresh = false;
- ushort MC_ErrorCode_Refresh_Cnt = 0;
- //配置参数实例
- Params myParams = new Params();
- //记录文件名称
- string RunInfoSaveFilename = "";
- //BMS运行信息超时计数
- bool BMS_RunInfo_Refresh = false;
- ushort BMS_RunInfo_Refresh_Cnt = 0;
- //生产模式关机指令反馈状态
- bool PowerOffAckStatus = false;
- //登录窗口
- public static Login EnterForm1 = new Login();
- //生产配置文件信息
- ArrayList array_CfgInfo = new ArrayList();
- //写入参数返回标志和计数
- public bool WriteACK = false;
- public ushort WriteCnt = 0;
- public ushort ACK_WaitCnt = 0;
- //写入参数返回提示标志
- public bool ACK_DisFlag = true;
- //Boot版本信息
- public string BootInfo = "";
- //接收指令临时缓存,转string
- public string CmdRevStrTemp = "";
- //计时器,用于统计运行时间
- public Stopwatch stopwatch = new Stopwatch();
- //力矩传感器检验参数窗口
- public static TorqueParams TorqueParamsForm = new TorqueParams();
- #endregion
- #region 故障日志结构体定义
- //故障日志记录信息 60 bytes,1K空间可以保存最近16条故障记录
- [StructLayout(LayoutKind.Sequential)]
- public struct MC_ErrorLogSaveInfo_Struct_t
- {
- public UInt16 Error_Index; //故障列表索引 2 bytes, 地址偏移 0
- public UInt16 NotesInfo1; //备注信息1,地址偏移 2
- public UInt16 NotesInfo2; //备注信息2,地址偏移 4
- public UInt16 NotesInfo3; //备注信息3,地址偏移 6
- public UInt32 ErrorCode; //故障码 4 bytes, 地址偏移 8
- public UInt32 RunTime; //运行时间 4bytes, 地址偏移 12
- //电机运行信息,占用空间32bytes
- [StructLayout(LayoutKind.Sequential)]
- public struct MC_RunInfo_Struct_t
- {
- public ushort BikeSpeed; //车速 0.1km/h,地址偏移0
- public ushort MotorSpeed; //输出转速 1rpm,地址偏移2
- public ushort Power; //电功率 1W,地址偏移4
- public ushort BusVoltage; //母线电压 1mV,地址偏移6
- public ushort BusCurrent; //母线电流 1mA,地址偏移8
- public byte Cadence; //踏频 1rpm,地址偏移10
- public byte Torque; //踩踏力矩 1Nm,地址偏移11
- public byte CadenceDir; //踩踏方向 0-正,1-反,2-停止,地址偏移12
- public byte GearSt; //助力档位,地址偏移13
- public byte LightSwitch; //灯开关 0xF0-关,0xF1-开,地址偏移14
- public byte SOC; //剩余电量 1%,地址偏移15
- public ushort RemainDistance; //续航里程 1km,地址偏移16
- public ushort Torque_AD; //力矩寄存器,地址偏移18
- public byte PowerPerKm; //平均功耗 0.01Ah/km ,地址偏移20
- public byte T_PCB; //PCB温度 +40℃,地址偏移21
- public byte T_Coil; //绕组温度 +40℃,地址偏移22
- public byte T_MCU; //MCU温度 +40℃,地址偏移23
- public ushort Ride_Km; //开机后骑行里程 0.1km, 地址偏移24
- public ushort Ride_Time; //开机后骑行时间 1s,地址偏移26
- public UInt32 RS; //预留 4bytes
- };
- [MarshalAs(UnmanagedType.Struct)]
- public MC_RunInfo_Struct_t RunInfo; //运行信息 32bytes, 地址偏移 16
- //控制变量
- public Int16 IqCurrent; //Pu, 地址偏移 48
- public Int16 IqVoltage; //Pu, 地址偏移 50
- public Int16 IdCurrent; //Pu, 地址偏移 52
- public Int16 IdVoltage; //Pu, 地址偏移 54
- //状态机
- public UInt16 FSM; //高到低依次表示系统状态机、二层状态机、电机状态机、助力状态机, 地址偏移 56
- //预留
- public UInt16 RS1;
- public UInt16 RS2;
- public UInt16 RS3;
- };
- #endregion
- public mainForm()
- {
- InitializeComponent();
- System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
- stopwatch.Start();
- //端口初始化
- mySerialProcess.Init();
- toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
- //检查配置文件
- if (!Directory.Exists(localInfo.LocalPath))
- {
- Directory.CreateDirectory(localInfo.LocalPath);
- }
- if (File.Exists(localInfo.LocalPath + localInfo.ConfigFileName)) //存在配置文件,导入配置信息
- {
- //打开文件
- StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.ConfigFileName);
- string sLine = "";
- ArrayList array_CfgInfo = new ArrayList();
- array_CfgInfo.Clear();
- while (sLine != null)
- {
- sLine = objReader.ReadLine();
- array_CfgInfo.Add(sLine);
- }
- objReader.Close();
- //解析配置文件
- try
- {
- //Port Set
- PortNumSave = array_CfgInfo[1].ToString().Split(':')[1];
- PortBaudrateSave = array_CfgInfo[2].ToString().Split(':')[1];
- toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.IndexOf(PortNumSave);
- toolStripComboBox_Baudrate.SelectedIndex = toolStripComboBox_Baudrate.Items.IndexOf(PortBaudrateSave);
- 连接开机ToolStripMenuItem.Checked = (array_CfgInfo[3].ToString().Split(':')[1] == "True");
- 断开关机ToolStripMenuItem.Checked = (array_CfgInfo[4].ToString().Split(':')[1] == "True");
- 识别通讯盒ToolStripMenuItem.Checked = (array_CfgInfo[5].ToString().Split(':')[1] == "True");
- //Option
- 写入存储ToolStripMenuItem.Checked = (array_CfgInfo[8].ToString().Split(':')[1] == "True");
- 允许ToolStripMenuItem.Checked = (array_CfgInfo[9].ToString().Split(':')[1] == "True");
- 不允许ToolStripMenuItem.Checked = (array_CfgInfo[9].ToString().Split(':')[1] == "False");
- //Server Set
- toolStripTextBox_ServerIP.Text = array_CfgInfo[12].ToString().Split(':')[1];
- toolStripTextBox_ServerPort.Text = array_CfgInfo[13].ToString().Split(':')[1];
- toolStripTextBox_ServerUser.Text = array_CfgInfo[14].ToString().Split(':')[1];
- toolStripTextBox_ServerPasswd.Text = array_CfgInfo[15].ToString().Split(':')[1];
- toolStripTextBox_ServerPath.Text = array_CfgInfo[16].ToString().Split(':')[1];
- //MacInfo
- toolStripTextBox_MAC.Text = array_CfgInfo[19].ToString().Split(':')[1];
- toolStripTextBoxMACAddr.Text = array_CfgInfo[20].ToString().Split(':')[1];
- toolStripTextBox_MACDate.Text = DateTime.Now.ToString("yyyyMMdd");
- toolStripTextBox_MACPD.Text = array_CfgInfo[22].ToString().Split(':')[1];
- //Log Address
- textBox_LogAddrBegin.Text = array_CfgInfo[25].ToString().Split(':')[1];
- textBox_LogAddrEnd.Text = array_CfgInfo[26].ToString().Split(':')[1];
- //电机类型
- 中置电机ToolStripMenuItem.Checked = (array_CfgInfo[29].ToString().Split(':')[1] == "True");
- 轮毂电机ToolStripMenuItem.Checked = !中置电机ToolStripMenuItem.Checked;
- }
- catch (System.Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_1s.Enabled = true;
- ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- }
- else //不存在配置文件,生成文件写入默认值
- {
- ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- //系统登录
- EnterForm1.ShowDialog();
- try
- {
- if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
- {
- if (EnterForm1.comboBox_User.Text.Contains("量产"))
- {
- //隐藏设置项
- 其它配置项ToolStripMenuItem.Visible = false;
- 写入存储ToolStripMenuItem.Visible = false;
- 离线使用ToolStripMenuItem.Visible = false;
- 服务器配置ToolStripMenuItem.Visible = false;
- //显示生产信息
- 生产信息ToolStripMenuItem.Visible = true;
- //显示电机类型,但不可编辑
- 电机类型ToolStripMenuItem.Visible = true;
- 中置电机ToolStripMenuItem.Enabled = false;
- 轮毂电机ToolStripMenuItem.Enabled = false;
- //隐藏研发调试界面
- tabPage_MotorParam.Parent = null;
- tabPage_BikeParam.Parent = null;
- tabPage_ControlParam.Parent = null;
- tabPage_SensorParam.Parent = null;
- tabPage_AssistParam.Parent = null;
- tabPage_DebugParam.Parent = null;
- tabPage_RecordInfo.Parent = null;
- tabPage_OtherInfo.Parent = null;
- tabPage_OBC.Parent = null;
- tabPage_RAMorFLASH.Parent = null;
- tabPage_FactoryMode.Parent = null;
- tabPage_DebugInfo.Parent = null;
- //显示运行信息
- tabPage_RunInfo.Parent = tabControl2;
- //根据电机类型修改生产信息和电机类型
- if (EnterForm1.comboBox_User.Text.Contains("中置"))
- {
- 中置电机ToolStripMenuItem.Checked = true;
- 轮毂电机ToolStripMenuItem.Checked = false;
- toolStripTextBox_MACPD.Text = "MM_MC1";
- toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
- ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
- {
- 中置电机ToolStripMenuItem.Checked = false;
- 轮毂电机ToolStripMenuItem.Checked = true;
- toolStripTextBox_MACPD.Text = "GF_250_1";
- toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
- ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- //显示对应生产测试界面
- if (EnterForm1.comboBox_User.Text.Contains("写入"))
- {
- tabPage_ProductMode_Write.Parent = tabControl1;
- tabPage_ProductMode_Write.Select();
- tabPage_ProductMode_Read.Parent = null;
- }
- else if (EnterForm1.comboBox_User.Text.Contains("检验"))
- {
- tabPage_ProductMode_Read.Parent = tabControl1;
- tabPage_ProductMode_Read.Select();
- tabPage_ProductMode_Write.Parent = null;
- }
- //应答指令不提示
- ACK_DisFlag = false;
- }
- else if (EnterForm1.comboBox_User.Text == "工程配置")
- {
- //隐藏工作台内容,新建窗口完成配置
- groupBox1.Visible = false;
- groupBox2.Visible = false;
- groupBox3.Visible = false;
- //隐藏提示信息
- label_StarInfo.Visible = false;
- //打开参数配置框
- MessageBox.Show("开发中", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- System.Environment.Exit(0);
- }
- else if (EnterForm1.comboBox_User.Text == "研发测试")
- {
- //隐藏量产界面
- tabPage_ProductMode_Read.Parent = null;
- tabPage_ProductMode_Write.Parent = null;
- }
- else
- {
- MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- System.Environment.Exit(0);
- }
- }
- else
- {
- MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- System.Environment.Exit(0);
- }
- }
- catch (Exception)
- {
- MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- System.Environment.Exit(0);
- }
- //端口自动连接
- if ((PortNumSave != string.Empty) && (PortBaudrateSave != string.Empty)) //有数值时采用上次使用的值
- {
- try
- {
- PortConnect();
- }
- catch (System.Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_1s.Enabled = true;
- }
- }
- //配置网络FTP服务器
- myFtp.FtpOption(toolStripTextBox_ServerIP.Text, toolStripTextBox_ServerPort.Text, toolStripTextBox_ServerUser.Text, toolStripTextBox_ServerPasswd.Text);
- //创建线程,定时检测网络连接状态
- Thread th = new Thread(NetworkCheck);
- th.IsBackground = true;
- th.Start();
- }
- /// <summary>
- /// 检查网络状态线程
- /// </summary>
- private void NetworkCheck()
- {
- //初始化第一次连接FTP服务器
- bool Result = myFtp.CheckFtp();
- this.Invoke((EventHandler)(delegate
- {
- if (Result == true)//服务器连接成功
- {
- label_Server_ComStatus.Text = "网络已连接";
- label_ServerStatus.BackColor = Color.Green;
- myFtp.IsNetConnected = true;
- }
- else//服务器连接失败
- {
- label_Server_ComStatus.Text = "网络断开";
- label_ServerStatus.BackColor = Color.Red;
- myFtp.IsNetConnected = false;
- if (允许ToolStripMenuItem.Checked == false) ///不允许离线使用,自动关闭
- {
- timer_1s.Enabled = false;
- MessageBox.Show("网络断开,将自动关闭!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_1s.Enabled = true;
- this.Close();
- }
- else //离线使用
- {
- timer_1s.Enabled = false;
- MessageBox.Show("网络断开,离线使用!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- timer_1s.Enabled = true;
- }
- }
- }));
- //创建定时器,定时30s检查网络
- System.Timers.Timer timer_CheckNet = new System.Timers.Timer();
- timer_CheckNet.Enabled = true;
- timer_CheckNet.Interval = 30000;
- timer_CheckNet.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_CheckNet_Tick);
- timer_CheckNet.Start();
- while (true)
- {
- Thread.Sleep(1);
- }
- }
- /// <summary>
- /// 线程中定时任务,检查网络状态
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void timer_CheckNet_Tick(object sender, EventArgs e)
- {
- //连接FTP服务器
- bool Result = myFtp.CheckFtp();
- this.Invoke((EventHandler)(delegate
- {
- if (Result == true)//服务器连接成功
- {
- label_Server_ComStatus.Text = "网络已连接";
- label_ServerStatus.BackColor = Color.Green;
- myFtp.IsNetConnected = true;
- }
- else//服务器连接失败
- {
- label_Server_ComStatus.Text = "网络断开";
- label_ServerStatus.BackColor = Color.Red;
- myFtp.IsNetConnected = false;
- }
- }));
- }
- #region 非独占性延时函数
- public static void Delay_ms(int milliSecond)
- {
- int start = Environment.TickCount;
- while (Math.Abs(Environment.TickCount - start) < milliSecond)//毫秒
- {
- Application.DoEvents();
- }
- }
- #endregion
- private void MainForm_Load(object sender, System.EventArgs e)
- {
- //页面初始化
- label_BuildTime.Text = "编译时间:" + System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString("yyyy-MM-dd HH:mm:ss");
- label_Computername.Text = "用户名:" + System.Environment.UserName;
- //下拉控件初始值设定
- comboBox_WorkMode.SelectedIndex = 0;
- comboBox_GearSt.SelectedIndex = 0;
- comboBox_LightSwitch.SelectedIndex = 1;
- comboBox_OBC_SetGearST.SelectedIndex = 0;
- comboBox_OBC_LightSw.SelectedIndex = 1;
- comboBox_AssistTorque.SelectedIndex = 0;
- comboBox_AssistCadence.SelectedIndex = 0;
- //combobox事件定义
- this.comboBox_WorkMode.SelectedIndexChanged += new System.EventHandler(this.comboBox_WorkMode_SelectedIndexChanged);
- this.comboBox_GearSt.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
- this.comboBox_LightSwitch.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
- this.comboBox_OBC_SetGearST.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
- this.comboBox_OBC_LightSw.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
- //创建线程,定时解析数据
- Thread th = new Thread(Task_SerialProcess);
- th.IsBackground = true;
- th.Start();
- }
- #region 结构体与字节流相互转换
- public static class MyConverter
- {
- /// <summary>
- /// 由结构体转换为byte数组
- /// </summary>
- public static byte[] StructureToByte<T>(T structure)
- {
- int size = Marshal.SizeOf(typeof(T));
- byte[] buffer = new byte[size];
- IntPtr bufferIntPtr = Marshal.AllocHGlobal(size);
- try
- {
- Marshal.StructureToPtr(structure, bufferIntPtr, true);
- Marshal.Copy(bufferIntPtr, buffer, 0, size);
- }
- finally
- {
- Marshal.FreeHGlobal(bufferIntPtr);
- }
- return buffer;
- }
- /// <summary>
- /// 由byte数组转换为结构体
- /// </summary>
- public static T ByteToStructure<T>(byte[] dataBuffer, ushort StarIndex)
- {
- object structure = null;
- int size = Marshal.SizeOf(typeof(T));
- IntPtr allocIntPtr = Marshal.AllocHGlobal(size);
- try
- {
- Marshal.Copy(dataBuffer, StarIndex, allocIntPtr, size);
- structure = Marshal.PtrToStructure(allocIntPtr, typeof(T));
- }
- finally
- {
- Marshal.FreeHGlobal(allocIntPtr);
- }
- return (T)structure;
- }
- }
- #endregion
- #region 故障日志解析显示
- private void ErrorLogDisplay(MC_ErrorLogSaveInfo_Struct_t Log1, MC_ErrorLogSaveInfo_Struct_t Log2)
- {
- string SaveData = "";
- //Log1
- if (Log1.Error_Index != 0xFFFF)
- {
- SaveData += "故障序号:" + Convert.ToString(Log1.Error_Index) + ", ";
- SaveData += "备注1:" + Convert.ToString(Log1.NotesInfo1) + ", ";
- SaveData += "备注2:" + Convert.ToString(Log1.NotesInfo2) + ", ";
- SaveData += "备注3:" + Convert.ToString(Log1.NotesInfo3) + ", ";
- SaveData += "故障码:" + "0x" + Convert.ToString(Log1.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
- SaveData += "运行时间:" + Convert.ToString(Log1.RunTime) + "min" + ", ";
- SaveData += "车速:" + ((float)Log1.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
- SaveData += "电机转速:" + Convert.ToString(Log1.RunInfo.MotorSpeed) + "rpm" + ", ";
- SaveData += "功率:" + Convert.ToString(Log1.RunInfo.Power * 2) + "w" + ", ";
- SaveData += "电压:" + Convert.ToString(Log1.RunInfo.BusVoltage) + "mV" + ", ";
- SaveData += "电流:" + Convert.ToString(Log1.RunInfo.BusCurrent) + "mA" + ", ";
- SaveData += "踏频:" + Convert.ToString(Log1.RunInfo.Cadence) + "rpm" + ", ";
- SaveData += "力矩:" + Convert.ToString(Log1.RunInfo.Torque) + "N.m" + ", ";
- SaveData += "方向:" + ((Log1.RunInfo.CadenceDir == 0) ? "正" : ((Log1.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
- SaveData += "档位:" + "0x" + Convert.ToString(Log1.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
- SaveData += "灯开关:" + ((Log1.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
- SaveData += "电量:" + Convert.ToString(Log1.RunInfo.SOC) + "%" + ", ";
- if ((Log1.RunInfo.RemainDistance == 0xEEEE) || (Log1.RunInfo.RemainDistance == 0xFFFF))
- {
- SaveData += "续航:" + "---km" + ", ";
- }
- else
- {
- SaveData += "续航:" + Convert.ToString(Log1.RunInfo.RemainDistance) + "km" + ", ";
- }
- SaveData += "力矩AD:" + Convert.ToString(Log1.RunInfo.Torque_AD) + ", ";
- SaveData += "功耗:" + Convert.ToString(Log1.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
- SaveData += "PCB温度:" + Convert.ToString((int)(Log1.RunInfo.T_PCB - 40)) + "℃" + ", ";
- SaveData += "绕组温度:" + Convert.ToString((int)(Log1.RunInfo.T_Coil - 40)) + "℃" + ", ";
- SaveData += "MCU温度:" + Convert.ToString((int)(Log1.RunInfo.T_MCU - 40)) + "℃" + ", ";
- SaveData += "单次里程:" + Convert.ToString((float)Log1.RunInfo.Ride_Km / 10f) + "km" + ", ";
- SaveData += "单次时间:" + Convert.ToString(Log1.RunInfo.Ride_Time) + "s" + ", ";
- SaveData += "q轴电流:" + Convert.ToString(Log1.IqCurrent) + ", ";
- SaveData += "q轴电压:" + Convert.ToString(Log1.IqVoltage) + ", ";
- SaveData += "d轴电流:" + Convert.ToString(Log1.IdCurrent) + ", ";
- SaveData += "d轴电压:" + Convert.ToString(Log1.IdVoltage) + ", ";
- SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
- SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
- SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
- SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
- SaveData += "\r\n\r\n";
- richTextBox_Record.AppendText(SaveData);
- SaveData = "";
- }
- //Log2
- if (Log2.Error_Index != 0xFFFF)
- {
- SaveData += "故障序号:" + Convert.ToString(Log2.Error_Index) + ", ";
- SaveData += "备注1:" + Convert.ToString(Log2.NotesInfo1) + ", ";
- SaveData += "备注2:" + Convert.ToString(Log2.NotesInfo2) + ", ";
- SaveData += "备注3:" + Convert.ToString(Log2.NotesInfo3) + ", ";
- SaveData += "故障码:" + "0x" + Convert.ToString(Log2.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
- SaveData += "运行时间:" + Convert.ToString(Log2.RunTime) + "min" + ", ";
- SaveData += "车速:" + ((float)Log2.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
- SaveData += "电机转速:" + Convert.ToString(Log2.RunInfo.MotorSpeed) + "rpm" + ", ";
- SaveData += "功率:" + Convert.ToString(Log2.RunInfo.Power * 2) + "w" + ", ";
- SaveData += "电压:" + Convert.ToString(Log2.RunInfo.BusVoltage) + "mV" + ", ";
- SaveData += "电流:" + Convert.ToString(Log2.RunInfo.BusCurrent) + "mA" + ", ";
- SaveData += "踏频:" + Convert.ToString(Log2.RunInfo.Cadence) + "rpm" + ", ";
- SaveData += "力矩:" + Convert.ToString(Log2.RunInfo.Torque) + "N.m" + ", ";
- SaveData += "方向:" + ((Log2.RunInfo.CadenceDir == 0) ? "正" : ((Log2.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
- SaveData += "档位:" + "0x" + Convert.ToString(Log2.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
- SaveData += "灯开关:" + ((Log2.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
- SaveData += "电量:" + Convert.ToString(Log2.RunInfo.SOC) + "%" + ", ";
- if ((Log2.RunInfo.RemainDistance == 0xEEEE) || (Log2.RunInfo.RemainDistance == 0xFFFF))
- {
- SaveData += "续航:" + "---km" + ", ";
- }
- else
- {
- SaveData += "续航:" + Convert.ToString(Log2.RunInfo.RemainDistance) + "km" + ", ";
- }
- SaveData += "力矩AD:" + Convert.ToString(Log2.RunInfo.Torque_AD) + ", ";
- SaveData += "功耗:" + Convert.ToString(Log2.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
- SaveData += "PCB温度:" + Convert.ToString((int)(Log2.RunInfo.T_PCB - 40)) + "DegreeC" + ", ";
- SaveData += "绕组温度:" + Convert.ToString((int)(Log2.RunInfo.T_Coil - 40)) + "DegreeC" + ", ";
- SaveData += "MCU温度:" + Convert.ToString((int)(Log2.RunInfo.T_MCU - 40)) + "DegreeC" + ", ";
- SaveData += "单次里程:" + Convert.ToString((float)Log2.RunInfo.Ride_Km / 10f) + "km" + ", ";
- SaveData += "单次时间:" + Convert.ToString(Log2.RunInfo.Ride_Time) + "s" + ", ";
- SaveData += "q轴电流:" + Convert.ToString(Log2.IqCurrent) + ", ";
- SaveData += "q轴电压:" + Convert.ToString(Log2.IqVoltage) + ", ";
- SaveData += "d轴电流:" + Convert.ToString(Log2.IdCurrent) + ", ";
- SaveData += "d轴电压:" + Convert.ToString(Log2.IdVoltage) + ", ";
- SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
- SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
- SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
- SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
- SaveData += "\r\n\r\n";
- richTextBox_Record.AppendText(SaveData);
- SaveData = "";
- }
- }
- #endregion
- #region 串口数据解析线程
- /// <summary>
- /// 串口数据解析线程
- /// </summary>
- private void Task_SerialProcess()
- {
- //创建定时器,定时读取串口数据
- System.Timers.Timer timer_ReadSerial = new System.Timers.Timer();
- timer_ReadSerial.Enabled = true;
- timer_ReadSerial.Interval = 20;
- timer_ReadSerial.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_ReadSerial_Tick);
- timer_ReadSerial.Start();
- while (true)
- {
- Thread.Sleep(1);
- };
- }
- /// <summary>
- /// 串口解析定时器
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void timer_ReadSerial_Tick(object sender, EventArgs e)
- {
- //串口解析
- Serial_process(mySerialProcess.buffer);
- }
- #endregion
- #region 数据解析
- public void Serial_process(List<byte> buffer)
- {
- byte DataNum = 0; //记录每条命令数据段的长度
- ushort PackageID, Cmd;
- byte[] Data = new byte[1024];
- try
- {
- while (buffer.Count >= 13)//当buffer中的数据的个数大于等于4个时,即每一帧的数据长度所在位(第4位)出现时
- {
- if (buffer[0] == 0x55 && buffer[1] == 0xAA)//判断帧头
- {
- PackageID = (ushort)(buffer[2] * 256 + buffer[3]);
- if ((PackageID == 0x0710) || (PackageID == 0x0715) || (PackageID == 0x07FF) || (PackageID == 0x0720) || (PackageID == 0x0713))
- {
- int CmdLen = buffer[5];
- if (buffer.Count < CmdLen + 11) break;//如果接收到的数据没有达到一帧数据的指定长度, 则执行下次循环
- while (CmdLen > 0) //读取命令段
- {
- Cmd = (ushort)(buffer[6] * 256 + buffer[7]);
- DataNum = (byte)(buffer[7]);//命令字的第二个字节的表示数据位的长度
- if (DataNum <= (CmdLen - 2))
- {
- for (int i = 0; i < DataNum; i++)
- {
- Data[i] = buffer[i + 8];
- }
- buffer.RemoveRange(0, CmdLen + 11);
- DataCmdProcess(PackageID, Cmd, Data);//对于不同的命令段,做不同的处理
- DataRevToString(Cmd, Data);//指令数据转为字符串
- }
- }
- }
- else
- {
- buffer.RemoveAt(0);//ID不对
- }
- }
- else
- {
- buffer.RemoveAt(0);//帧头不对,删除帧头高字节
- }
- }
- }
- catch (Exception)
- {
-
- }
- }
- private void DataCmdProcess(ushort ID, ushort CmdTemp, byte[] Data)
- {
- int DataTemp;
- ushort uData16;
- unchecked
- {
- this.Invoke((EventHandler)(delegate { label_RecCount.Text = Convert.ToString(Convert.ToInt32(label_RecCount.Text) + 1); }));
- }
- #region 解析发送给CDL的指令
- if (ID == 0x7FF)
- {
- switch (CmdTemp)
- {
- case 0x1100://
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- //CDL连接成功
- mySerialProcess.CDL_Online_Flag = true;
- MessageBox.Show("连接成功!", "提示");
- groupBox1.Visible = true;
- groupBox3.Visible = true;
- tabControl2.Visible = true;
- label_StarInfo.Visible = false;
- }));
- }
- break;
- }
- default: break;
- }
- }
- #endregion
- #region 解析电机的命令
- else if ((ID == 0x715) || (ID == 0x710))
- {
- switch (CmdTemp)
- {
- case 0x1020://电机运行信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- MC_RunInfo_Refresh = true;
- //车速
- DataTemp = (int)(Data[1] * 256 + Data[0]);
- textBox_RunInfo_BikeSpeed.Text = ((float)DataTemp / 10f).ToString("0.0") + " km/h";
- //输出转速
- DataTemp = (ushort)(Data[3] * 256 + Data[2]);
- textBox_RunInfo_MotorSpeed.Text = Convert.ToString(DataTemp) + " rpm";
- Class_MotorSpeed.String = textBox_RunInfo_MotorSpeed.Text;
- Class_MotorSpeed.Data = DataTemp;
- //电功率
- DataTemp = (ushort)(Data[5] * 256 + Data[4]);
- textBox_RunInfo_Power.Text = Convert.ToString(DataTemp) + " W";
- //母线电压
- DataTemp = (ushort)(Data[7] * 256 + Data[6]);
- textBox_RunInfo_Vol.Text = Convert.ToString(DataTemp) + " mV";
- //textBox_RunInfo_Vol.Text = (DataTemp / 1000f).ToString("0.0") + " V";
- //母线电流
- DataTemp = (short)(Data[9] * 256 + Data[8]);
- textBox_RunInfo_Current.Text = Convert.ToString(DataTemp) + " mA";
- //textBox_RunInfo_Current.Text = (DataTemp / 1000f).ToString("0.0") + " A";
- Class_CurrentData.String = textBox_RunInfo_Current.Text;
- Class_CurrentData.Data = DataTemp;
- //踏频
- DataTemp = (ushort)(Data[10]);
- textBox_RunInfo_Cadence.Text = Convert.ToString(DataTemp) + " rpm";
- Class_CadenceData.String = textBox_RunInfo_Cadence.Text;
- Class_CadenceData.Data = DataTemp;
- //踩踏力矩
- DataTemp = (ushort)(Data[11]);
- textBox_RunInfo_Torque.Text = Convert.ToString(DataTemp) + " N.m";
- Class_TorqueData.String = textBox_RunInfo_Torque.Text;
- Class_TorqueData.Data = DataTemp;
- //踩踏方向
- DataTemp = (ushort)(Data[12]);
- if (DataTemp == 0)
- {
- textBox_RunInfo_Dir.Text = "正向";
- }
- else if (DataTemp == 1)
- {
- textBox_RunInfo_Dir.Text = "反向";
- }
- else if (DataTemp == 2)
- {
- textBox_RunInfo_Dir.Text = "停止";
- }
- //助力档位
- DataTemp = (ushort)(Data[13]);
- if (DataTemp == 0x33)
- {
- textBox_RunInfo_GearSt.Text = "SMART";
- //comboBox_GearSt.SelectedIndex = 5;
- //comboBox_OBC_SetGearST.SelectedIndex = 5;
- }
- else if (DataTemp == 0x22)
- {
- textBox_RunInfo_GearSt.Text = "WALK";
- //comboBox_GearSt.SelectedIndex = 6;
- //comboBox_OBC_SetGearST.SelectedIndex = 6;
- }
- else
- {
- string[] Gears = new string[5] { "OFF", "ECO", "NORM", "SPORT", "TURBO" };
- textBox_RunInfo_GearSt.Text = Gears[DataTemp];
- //comboBox_GearSt.SelectedIndex = DataTemp;
- //comboBox_OBC_SetGearST.SelectedIndex = DataTemp;
- }
- //大灯状态
- DataTemp = (ushort)(Data[14]);
- if (DataTemp == 0xF0)
- {
- textBox_RunInfo_LightSwitch.Text = "OFF";
- //comboBox_LightSwitch.SelectedIndex = 1;
- //comboBox_OBC_LightSw.SelectedIndex = 1;
- }
- else if (DataTemp == 0xF1)
- {
- textBox_RunInfo_LightSwitch.Text = "ON";
- //comboBox_LightSwitch.SelectedIndex = 0;
- //comboBox_OBC_LightSw.SelectedIndex = 0;
- }
- //剩余电量
- DataTemp = (ushort)(Data[15]);
- textBox_RunInfo_SOC.Text = Convert.ToString(DataTemp) + " %";
- //剩余续航里程
- DataTemp = (ushort)(Data[17] * 256 + Data[16]);
- if ((DataTemp == 0xEEEE) || (DataTemp == 0xFFFF))
- {
- textBox_RunInfo_Range.Text = "---";
- }
- else
- {
- textBox_RunInfo_Range.Text = Convert.ToString(DataTemp) + " km";
- }
- //预留(显示力矩Reg),空2bytes
- DataTemp = (ushort)(Data[19] * 256 + Data[18]);
- textBox_TorqueReg.Text = Convert.ToString(DataTemp);
- //平均功耗
- DataTemp = (ushort)(Data[20]);
- textBox_RunInfo_AvgPower.Text = Convert.ToString(DataTemp * 10) + " mAh/km";
- //PCB温度
- DataTemp = (ushort)(Data[21]);
- textBox_RunInfo_T_PCB.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
- Class_MotorTemp.String = textBox_RunInfo_T_PCB.Text;
- Class_MotorTemp.Data = DataTemp - 40;
- //绕组温度
- DataTemp = (ushort)(Data[22]);
- textBox_RunInfo_T_Coil.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
- //MCU温度
- DataTemp = (ushort)(Data[23]);
- textBox_RunInfo_T_MCU.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
- //单次里程
- DataTemp = (ushort)(Data[25] * 256 + Data[24]);
- textBox_RunInfo_Trip.Text = ((float)DataTemp / 10f).ToString("0.0") + " km";
- //单次时间
- DataTemp = (ushort)(Data[27] * 256 + Data[26]);
- textBox_RunInfo_Trip_Time.Text = Convert.ToString(DataTemp) + " s";
- //数据保存
- RunInfoAutoSave();
- }));
- }
- break;
- }
- case 0x1104://故障码
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- MC_ErrorCode_Refresh = true;
- textBox_ErrorCode.Text =
- Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() +
- Convert.ToString(Data[2], 16).PadLeft(2, '0').ToUpper() +
- Convert.ToString(Data[1], 16).PadLeft(2, '0').ToUpper() +
- Convert.ToString(Data[0], 16).PadLeft(2, '0').ToUpper() +
- "H";
- }));
- }
- break;
- }
- case 0xA903://反馈指令
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- if (ACK_DisFlag == true)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("OK", "反馈指令", MessageBoxButtons.OK, MessageBoxIcon.Information);
- timer_1s.Enabled = true;
- //关机反馈
- PowerOffAckStatus = true;
- }
- //应答标志置位
- WriteACK = true;
- WriteCnt++;
- }));
- }
- break;
- }
- case 0xB226://马达参数
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_MotorParam.Clear();
- for (int i = 0; i < myParams.MotorParma.Count; i++)
- {
- if (i == 6)
- richTextBox_MotorParam.AppendText(myParams.MotorParma[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
- else
- richTextBox_MotorParam.AppendText(myParams.MotorParma[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
- }
- richTextBox_MotorParam.Text = richTextBox_MotorParam.Text.Substring(0, richTextBox_MotorParam.Text.Length - 2);
- }));
- }
- break;
- }
- case 0xB31A://整车信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_BikeParam.Clear();
- for (int i = 0; i < myParams.BikeParma.Count; i++)
- {
- if (i == 9)
- richTextBox_BikeParam.AppendText(myParams.BikeParma[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
- else
- richTextBox_BikeParam.AppendText(myParams.BikeParma[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
- //更新前后灯参数
- if (i == 8)
- {
- comboBox_TailLightMode.SelectedIndex = ((Data[2 * i + 1] >> 4) & 0x0F) - 1;
- comboBox_TailLightVol.SelectedIndex = ((Data[2 * i + 1] & 0x0F) == 6) ? 0 : 1;
- comboBox_FrontLightVol.SelectedIndex = ((Data[2 * i] & 0x0F) == 6) ? 0 : 1;
- }
- //更新开关机参数
- else if (i == 11)
- {
- textBox_PowerOnDelay.Text = Convert.ToString((Data[2 * i + 1] >> 4) & 0x0F);
- textBox_PowerOffDelay.Text = Convert.ToString(Data[2 * i + 1] & 0x0F);
- textBox_AutoPowerOff.Text = Convert.ToString(Data[2 * i]);
- }
- }
- richTextBox_BikeParam.Text = richTextBox_BikeParam.Text.Substring(0, richTextBox_BikeParam.Text.Length - 2);
- }));
- }
- break;
- }
- case 0xB420://控制器参数
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_ControlParam.Clear();
- for (int i = 0; i < myParams.ControlParma.Count; i++)
- {
- richTextBox_ControlParam.AppendText(myParams.ControlParma[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
- }
- richTextBox_ControlParam.Text = richTextBox_ControlParam.Text.Substring(0, richTextBox_ControlParam.Text.Length - 2);
- }));
- }
- break;
- }
- case 0xB528://传感器参数
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_SensorParam.Clear();
- for (int i = 0; i < myParams.SensorParam.Count; i++)
- {
- richTextBox_SensorParam.AppendText(myParams.SensorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
- }
- richTextBox_SensorParam.Text = richTextBox_SensorParam.Text.Substring(0, richTextBox_SensorParam.Text.Length - 2);
- //更新生产模式页面传感器零点和标定值
- textBox_FacModeSensorADC0.Text = (Data[1] * 256 + Data[0]).ToString();
- textBox_FacModeSensorADC1.Text = (Data[15] * 256 + Data[14]).ToString();
- textBox_FacModeSensorADC2.Text = (Data[19] * 256 + Data[18]).ToString();
- textBox_FacModeSensorADC3.Text = (Data[23] * 256 + Data[22]).ToString();
- textBox_FacModeSensorADC4.Text = (Data[27] * 256 + Data[26]).ToString();
- }));
- }
- break;
- }
- case 0xB64C://助力参数
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_AssistParam.Clear();
- int index_1 = myParams.AssistParam.IndexOf("转矩曲线.a");
- int index_2 = myParams.AssistParam.IndexOf("踏频曲线.d");
- int index_3 = myParams.AssistParam.IndexOf("踏频助力加速限制");
- int index_4 = myParams.AssistParam.IndexOf("踏频助力电流步进");
- for (int i = 0; i < myParams.AssistParam.Count; i++)
- {
- if (i < index_1) //数据占用2bytes
- {
- richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
- }
- else if (i <= index_2) //数据占用4bytes
- {
- 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])) + ", ");
- }
- else if (i < index_3) //数据占用2bytes,无符号
- {
- richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
- }
- else if (i <= index_4) //数据占用2bytes,有符号
- {
- richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
- }
- else //数据占用2bytes,无符号
- {
- richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
- }
- }
- richTextBox_AssistParam.Text = richTextBox_AssistParam.Text.Substring(0, richTextBox_AssistParam.Text.Length - 2);
- }));
- }
- break;
- }
- case 0xB74C://历史记录
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_Record.Clear();
- for (int i = 0; i < myParams.Record.Count; i++)
- {
- richTextBox_Record.AppendText(myParams.Record[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
- }
- richTextBox_Record.Text = richTextBox_Record.Text.Substring(0, richTextBox_Record.Text.Length - 2);
- }));
- }
- break;
- }
- case 0xB83A://调试参数
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_DebugParam.Clear();
- for (int i = 0; i < myParams.DebugParam.Count; i++)
- {
- richTextBox_DebugParam.AppendText(myParams.DebugParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
- //模式
- if ((short)(Data[1] * 256 + Data[0]) == 3)
- {
- radioButton_Ctl3.Checked = true;
- radioButton_Ctl4.Checked = false;
- radioButton_Ctl5.Checked = false;
- }
- else if ((short)(Data[1] * 256 + Data[0]) == 4)
- {
- radioButton_Ctl3.Checked = false;
- radioButton_Ctl4.Checked = true;
- radioButton_Ctl5.Checked = false;
- }
- else if ((short)(Data[1] * 256 + Data[0]) == 5)
- {
- radioButton_Ctl3.Checked = false;
- radioButton_Ctl4.Checked = false;
- radioButton_Ctl5.Checked = true;
- }
- //位置
- if ((short)(Data[3] * 256 + Data[2]) == 0)
- {
- radioButton_Hall0.Checked = true;
- radioButton_Hall1.Checked = false;
- radioButton_Hall2.Checked = false;
- }
- else if ((short)(Data[3] * 256 + Data[2]) == 1)
- {
- radioButton_Hall0.Checked = false;
- radioButton_Hall1.Checked = true;
- radioButton_Hall2.Checked = false;
- }
- else if ((short)(Data[3] * 256 + Data[2]) == 2)
- {
- radioButton_Hall0.Checked = false;
- radioButton_Hall1.Checked = false;
- radioButton_Hall2.Checked = true;
- }
- //方向
- if ((short)(Data[7] * 256 + Data[6]) == 0)
- {
- radioButton_Dir0.Checked = true;
- radioButton_Dir1.Checked = false;
- }
- else if ((short)(Data[7] * 256 + Data[6]) == 1)
- {
- radioButton_Dir0.Checked = false;
- radioButton_Dir1.Checked = true;
- }
- }
- richTextBox_DebugParam.Text = richTextBox_DebugParam.Text.Substring(0, richTextBox_DebugParam.Text.Length - 2);
- }));
- }
- break;
- }
- case 0xB904://存储标志
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- ushort Flag = 0;
- Flag = (ushort)(Data[1] * 256 + Data[0]);//EEPROM存储标志
- if (Flag == 0)
- {
- radioButton_EE_SaveNo.Checked = true;
- radioButton_EE_SaveYes.Checked = false;
- }
- else
- {
- radioButton_EE_SaveNo.Checked = false;
- radioButton_EE_SaveYes.Checked = true;
- }
- Flag = (ushort)(Data[3] * 256 + Data[2]);//SIP偏移校准存储标志
- if (Flag == 0)
- {
- radioButton_SIP_SaveNo.Checked = true;
- radioButton_SIP_SaveYes.Checked = false;
- }
- else
- {
- radioButton_SIP_SaveNo.Checked = false;
- radioButton_SIP_SaveYes.Checked = true;
- }
- }));
- }
- break;
- }
- case 0x1240://电机版本信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- //电机型号
- textBox_Model.Text = "";
- textBox_OBC_ReadModel.Text = "";
- textBox_FacModeName.Text = "";
- for (ushort i = 0; i < 16; i++)
- {
- if (Data[i] == 0x2E)
- {
- break;
- }
- textBox_Model.Text += ((char)Data[i]).ToString();
- textBox_OBC_ReadModel.Text += ((char)Data[i]).ToString();
- textBox_FacModeName.Text += ((char)Data[i]).ToString();
- }
- Class_Motor_Ver.Mode = textBox_Model.Text;
- //电机SN
- textBox_SN.Text = "";
- textBox_OBC_ReadSN.Text = "";
- textBox_FacModeNum.Text = "";
- for (ushort i = 0; i < 16; i++)
- {
- if (Data[16 + i] == 0x2E)
- {
- break;
- }
- textBox_SN.Text += ((char)Data[16 + i]).ToString();
- textBox_OBC_ReadSN.Text += ((char)Data[16 + i]).ToString();
- textBox_FacModeNum.Text += ((char)Data[16 + i]).ToString();
- }
- Class_Motor_Ver.SN = textBox_SN.Text;
- //电机HW
- textBox_HW.Text = "";
- textBox_OBC_ReadHW.Text = "";
- textBox_FacModeHW.Text = "";
- for (ushort i = 0; i < 8; i++)//前8位:硬件板号
- {
- if (Data[32 + i] == 0x2E)
- {
- break;
- }
- else if (Data[32 + i] == 'r')
- {
- Data[32 + i] = (byte)'.';
- break;
- }
- string strTemp = "";
- strTemp = ((char)Data[32 + i]).ToString();
- textBox_HW.Text += strTemp;
- textBox_OBC_ReadHW.Text += strTemp;
- textBox_FacModeHW.Text += strTemp;
- }
- for (ushort i = 0; i < 4; i++)//9-12位:单片机型号
- {
- if (Data[40 + i] == 0x2E)
- {
- break;
- }
- else if (Data[40 + i] == 'r')
- {
- Data[40 + i] = (byte)'.';
- break;
- }
- string strTemp = "";
- strTemp = ((char)Data[40 + i]).ToString();
- textBox_HW.Text += strTemp;
- textBox_OBC_ReadHW.Text += strTemp;
- textBox_FacModeHW.Text += strTemp;
- }
- for (ushort i = 0; i < 4; i++)//13-16位:单片机ID
- {
- string strTemp = "";
- strTemp = Convert.ToString(Data[44 + i], 16).PadLeft(2, '0').ToUpper();
- textBox_HW.Text += strTemp;
- textBox_OBC_ReadHW.Text += strTemp;
- textBox_FacModeHW.Text += strTemp;
- }
- Class_Motor_Ver.HW = textBox_HW.Text;
- //电机FW
- textBox_FW.Text = "";
- textBox_OBC_ReadFW.Text = "";
- textBox_FacModeFW.Text = "";
- for (ushort i = 0; i < 16; i++)
- {
- if ((Data[48 + i] == 0x2E) || (Data[48 + i] == 0x00) || (Data[48 + i] == (char)' '))
- {
- break;
- }
- if (Data[48 + i] == 'r')
- {
- Data[48 + i] = (byte)'.';
- }
- textBox_FW.Text += ((char)Data[48 + i]).ToString();
- textBox_OBC_ReadFW.Text += ((char)Data[48 + i]).ToString();
- textBox_FacModeFW.Text += ((char)Data[48 + i]).ToString();
- }
- Class_Motor_Ver.FW = textBox_FW.Text;
- }));
- }
- break;
- }
- case 0xA610://自定义1
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- textBox_User1.Text = "";
- for (ushort i = 0; i < 16; i++)
- {
- if (Data[i] == 0x2E)
- {
- break;
- }
- textBox_User1.Text += ((char)Data[i]).ToString();
- }
- }));
- }
- break;
- }
- case 0xA710://自定义2
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- textBox_User2.Text = "";
- for (ushort i = 0; i < 16; i++)
- {
- if (Data[i] == 0x2E)
- {
- break;
- }
- textBox_User2.Text += ((char)Data[i]).ToString();
- }
- }));
- }
- break;
- }
- case 0xA810://自定义1
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- textBox_User3.Text = "";
- for (ushort i = 0; i < 16; i++)
- {
- if (Data[i] == 0x2E)
- {
- break;
- }
- textBox_User3.Text += ((char)Data[i]).ToString();
- }
- }));
- }
- break;
- }
- case 0xA520://生产信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- //生产商
- textBox_MAC.Text = "";
- for (ushort i = 0; i < 8; i++)
- {
- if (Data[i] == 0x2E)
- {
- break;
- }
- textBox_MAC.Text += ((char)Data[i]).ToString();
- }
- //生产地
- textBox_MACAdd.Text = "";
- for (ushort i = 0; i < 8; i++)
- {
- if (Data[8 + i] == 0x2E)
- {
- break;
- }
- textBox_MACAdd.Text += ((char)Data[8 + i]).ToString();
- }
- //生产日期
- textBox_MACDate.Text = "";
- for (ushort i = 0; i < 8; i++)
- {
- if (Data[16 + i] == 0x2E)
- {
- break;
- }
- textBox_MACDate.Text += ((char)Data[16 + i]).ToString();
- }
- //品牌信息
- textBox_PP.Text = "";
- for (ushort i = 0; i < 8; i++)
- {
- if (Data[24 + i] == 0x2E)
- {
- break;
- }
- textBox_PP.Text += ((char)Data[24 + i]).ToString();
- }
- }));
- }
- break;
- }
- case 0xA408://密钥
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- textBox_Key.Text = "";
- for (ushort i = 0; i < 8; i++)
- {
- textBox_Key.Text += ((char)Data[i]).ToString();
- }
- }));
- }
- break;
- }
- case 0xAB09://存储器数据
- case 0xAB0A:
- case 0xAB0B:
- case 0xAB0C:
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- long ByteNum = 0;
- ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
- if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
- {
- for (int i = 0; i < ByteNum; i++)
- {
- richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
- }
- }
- else //根据设置自动转换10进制显示
- {
- if (checkBox_ReadRanFlash_ChangeFormat.Checked == true) //10进制显示
- {
- switch (ByteNum)
- {
- case 1:
- {
- richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8]) + ", ");
- break;
- }
- case 2:
- {
- richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8)) + ", ");
- break;
- }
- case 3:
- {
- richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16)) + ", ");
- break;
- }
- case 4:
- {
- richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24)) + ", ");
- break;
- }
- default:
- {
- richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
- break;
- }
- }
- }
- else //16进制显示
- {
- switch (ByteNum)
- {
- case 1:
- {
- richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8], 16).PadLeft(2, '0').ToUpper() + ", ");
- break;
- }
- case 2:
- {
- richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8), 16).PadLeft(4, '0').ToUpper() + ", ");
- break;
- }
- case 3:
- {
- richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16), 16).PadLeft(6, '0').ToUpper() + ", ");
- break;
- }
- case 4:
- {
- richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24), 16).PadLeft(8, '0').ToUpper() + ", ");
- break;
- }
- default:
- {
- richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
- break;
- }
- }
- }
- }
- }));
- }
- break;
- }
- case 0xAB88://故障日志
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- //电机存储的故障日志,一包128字节包含2条故障日志
- var ErrorLogSaveInfo1 = new MC_ErrorLogSaveInfo_Struct_t();
- var ErrorLogSaveInfo2 = new MC_ErrorLogSaveInfo_Struct_t();
- ErrorLogSaveInfo1 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 8);
- ErrorLogSaveInfo2 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 72);
- //数据显示
- ErrorLogDisplay(ErrorLogSaveInfo1, ErrorLogSaveInfo2);
- }));
- }
- break;
- }
- case 0x1401://在线检测结果
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- textBox_Online.Text = Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() + "H";
- }));
- }
- break;
- }
- case 0x1510://骑行历史信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- long DataTemp32;
- //ODO里程
- DataTemp32 = (long)((Data[3] << 24) + (Data[2] << 16) + (Data[1] << 8) + Data[0]);
- textBox_OBC_ODO_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
- //ODO时间
- DataTemp32 = (long)((Data[7] << 24) + (Data[6] << 16) + (Data[5] << 8) + Data[4]);
- if (DataTemp32 >= 60 * 100000)
- textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
- else
- textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
- //TRIP里程
- DataTemp32 = (long)((Data[11] << 24) + (Data[10] << 16) + (Data[9] << 8) + Data[8]);
- textBox_OBC_TRIP_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
- //TRIP时间
- DataTemp32 = (long)((Data[15] << 24) + (Data[14] << 16) + (Data[13] << 8) + Data[12]);
- if (DataTemp32 >= 60 * 100000)
- textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
- else
- textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
- }));
- }
- break;
- }
- case 0x1720://客户信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- //软件标识
- textBox_SP.Text = "";
- textBox_OBC_ReadSP.Text = "";
- textBox_FacModeSP.Text = "";
- for (ushort i = 0; i < 23; i++)
- {
- if (Data[i] == 'r')
- {
- Data[i] = (byte)'.';
- }
- textBox_SP.Text += ((char)Data[i]).ToString();
- textBox_OBC_ReadSP.Text += ((char)Data[i]).ToString();
- textBox_FacModeSP.Text += ((char)Data[i]).ToString();
- }
- //Git提交版本信息
- textBox_FacModeGit.Text = "";
- for (ushort i = 0; i < 9; i++)
- {
- textBox_FacModeGit.Text += ((char)Data[23 + i]).ToString();
- }
- Class_Motor_Ver.Special = textBox_SP.Text + " " + textBox_FacModeGit.Text;
- }));
- }
- break;
- }
- case 0xBA20: //调试信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- MC_DebugInfo_Refresh = true;
- //系统状态机
- DataTemp = (short)(Data[0]);
- textBox_DebugInfo_SysFun.Text = Convert.ToString(DataTemp);
- //二层状态机
- DataTemp = (short)(Data[1]);
- textBox_DebugInfo_SecondFun.Text = Convert.ToString(DataTemp);
- //电机状态机
- DataTemp = (short)(Data[2]);
- textBox_DebugInfo_MotorFun.Text = Convert.ToString(DataTemp);
- //助力状态机
- DataTemp = (short)(Data[3]);
- textBox_DebugInfo_AssistFun.Text = Convert.ToString(DataTemp);
- //IdRef
- DataTemp = (short)(Data[5] * 256 + Data[4]);
- textBox_DebugInfo_IdRef.Text = Convert.ToString(DataTemp);
- //IqRef
- DataTemp = (short)(Data[7] * 256 + Data[6]);
- textBox_DebugInfo_IqRef.Text = Convert.ToString(DataTemp);
- //UdRef
- DataTemp = (short)(Data[9] * 256 + Data[8]);
- textBox_DebugInfo_UdRef.Text = Convert.ToString(DataTemp);
- //UqRef
- DataTemp = (short)(Data[11] * 256 + Data[10]);
- textBox_DebugInfo_UqRef.Text = Convert.ToString(DataTemp);
- //瞬时力矩
- DataTemp = (short)(Data[13] * 256 + Data[12]);
- textBox_DebugInfo_TorquePu.Text = Convert.ToString(DataTemp);
- //时间滤波力矩
- DataTemp = (short)(Data[15] * 256 + Data[14]);
- textBox_DebugInfo_TorqueFil.Text = Convert.ToString(DataTemp);
- //踏频滤波力矩
- DataTemp = (short)(Data[17] * 256 + Data[16]);
- textBox_DebugInfo_TorqueCadence.Text = Convert.ToString(DataTemp);
- //IdFdb
- DataTemp = (short)(Data[19] * 256 + Data[18]);
- textBox_DebugInfo_IdFdb.Text = Convert.ToString(DataTemp);
- //IqFdb
- DataTemp = (short)(Data[21] * 256 + Data[20]);
- textBox_DebugInfo_IqFdb.Text = Convert.ToString(DataTemp);
- //助力输出
- DataTemp = (short)(Data[23] * 256 + Data[22]);
- textBox_DebugInfo_AssistOut.Text = Convert.ToString(DataTemp);
- //数据保存
- RunInfoAutoSave();
- }));
- }
- break;
- }
- case 0xC109: //Boot版本信息
- {
- BootInfo = "";
- for (ushort i = 0; i < 9; i++)
- {
- BootInfo += ((char)Data[i]).ToString();
- }
- break;
- }
- default:
- {
- break;
- }
- }
- }
- #endregion
- #region 解析BMS广播的命令
- else if (ID == 0x720)
- {
- switch (CmdTemp)
- {
- case 0x1010://BMS运行信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- BMS_RunInfo_Refresh = true;
- richTextBox_OBC_BMS_RunInfo.Clear();
- //电压
- uData16 = (ushort)(Data[1] * 256 + Data[0]);
- richTextBox_OBC_BMS_RunInfo.AppendText("电压:" + Convert.ToString(uData16) + " mV" + "\r\n");
- //电流
- uData16 = (ushort)(Data[3] * 256 + Data[2]);
- richTextBox_OBC_BMS_RunInfo.AppendText("电流:" + Convert.ToString(uData16) + " mA" + "\r\n");
- //剩余容量
- uData16 = (ushort)(Data[5] * 256 + Data[4]);
- richTextBox_OBC_BMS_RunInfo.AppendText("剩余容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
- //满充容量
- uData16 = (ushort)(Data[7] * 256 + Data[6]);
- richTextBox_OBC_BMS_RunInfo.AppendText("满充容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
- //电芯温度
- richTextBox_OBC_BMS_RunInfo.AppendText("电芯温度:" + Convert.ToString((int)(Data[8] - 40) + " ℃" + "\r\n"));
- //剩余电量
- richTextBox_OBC_BMS_RunInfo.AppendText("剩余电量:" + Convert.ToString(Data[9]) + " %" + "\r\n");
- //电池状态
- richTextBox_OBC_BMS_RunInfo.AppendText("电池状态:" + Convert.ToString(Data[10], 16).PadLeft(2, '0').ToUpper() + " H" + "\r\n");
- //SOH
- richTextBox_OBC_BMS_RunInfo.AppendText("电池寿命:" + Convert.ToString(Data[11]) + " %" + "\r\n");
- //循环次数
- richTextBox_OBC_BMS_RunInfo.AppendText("循环次数:" + Convert.ToString((ushort)(Data[13] * 256 + Data[12])) + " 次");
- }));
- }
- break;
- }
- default: break;
- }
- }
- #endregion
- #region 解析电机发送OBC的命令
- else if (ID == 0x713)
- {
- switch (CmdTemp)
- {
- case 0x5408://电机用户参数
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_OBC_ReadUserInfo.Clear();
- //默认周长
- richTextBox_OBC_ReadUserInfo.AppendText("默认周长:" + Convert.ToString((int)Data[0]) + " cm" + "\r\n");
- //启动模式
- richTextBox_OBC_ReadUserInfo.AppendText("启动模式:" + ((Data[1] == 0x01) ? "柔和" : (Data[1] == 0x02) ? "正常" : (Data[1] == 0x03) ? "强劲" : "无效") + "\r\n");
- comboBox_OBC_StartMode.SelectedIndex = Data[1] - 1;
- //限速
- richTextBox_OBC_ReadUserInfo.AppendText("限速:" + Convert.ToString(Data[2]) + " km/h" + "\r\n");
- //周长微调
- numericUpDown_OBC_WheelAdj.Value = (int)(Data[3] > 128 ? (Data[3] - 256) : Data[3]);
- richTextBox_OBC_ReadUserInfo.AppendText("周长微调:" + Convert.ToString(numericUpDown_OBC_WheelAdj.Value) + " cm" + "\r\n");
- //助力方案
- richTextBox_OBC_ReadUserInfo.AppendText("助力方案:" + Convert.ToString(Data[4]) + "\r\n");
- comboBox_OBC_AssistFunc.SelectedIndex = Data[4] - 1;
- //关机时间
- richTextBox_OBC_ReadUserInfo.AppendText("关机时间:" + Convert.ToString(Data[5]) + " min" + "\r\n");
- numericUpDown_OBC_OffTime.Value = (int)Data[5];
- }));
- }
- break;
- }
- case 0x5303://电机应答反馈
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- timer_1s.Enabled = false;
- MessageBox.Show("OK", "反馈指令", MessageBoxButtons.OK, MessageBoxIcon.Information);
- timer_1s.Enabled = true;
- }));
- }
- break;
- }
- default: break;
- }
- }
- #endregion
- }
- private void DataRevToString(ushort CmdTemp, byte[] Data)
- {
- CmdRevStrTemp = "";
- CmdRevStrTemp += Convert.ToString(CmdTemp >> 8, 16).PadLeft(2, '0').ToUpper() + " ";
- CmdRevStrTemp += Convert.ToString(CmdTemp & 0xFF, 16).PadLeft(2, '0').ToUpper() + " ";
- ushort len = (ushort)(CmdTemp & 0x00FF);
- for (int i = 0; i < len ; i++)
- {
- CmdRevStrTemp += Convert.ToString(Data[i], 16).PadLeft(2, '0').ToUpper() + " ";
- }
- }
- #endregion
- /// <summary>
- /// 端口连接或断开
- /// </summary>
- private void PortConnect()
- {
- bool result = false;
- if (连接ToolStripMenuItem.Text == "连接")
- {
- result = mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, 连接开机ToolStripMenuItem.Checked, 识别通讯盒ToolStripMenuItem.Checked);
- if (result)
- {
- toolStripComboBox_ComNum.Enabled = false;
- toolStripComboBox_Baudrate.Enabled = false;
- 刷新ToolStripMenuItem.Enabled = false;
- 连接ToolStripMenuItem.Text = "断开";
- 连接ToolStripMenuItem.Checked = true;
- label_COM_Sta.Text = toolStripComboBox_ComNum.Text + "已连接," + toolStripComboBox_Baudrate.Text;
- label_PortStatus.BackColor = Color.Green;
- }
- }
- else if (连接ToolStripMenuItem.Text == "断开")
- {
- checkBox_OBC_StartSetGearSt.Checked = false;
- checkBox_OBC_StartReadBMS.Checked = false;
- checkBox_ReadRanFlash_AutoSW.Checked = false;
- mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
- toolStripComboBox_ComNum.Enabled = true;
- toolStripComboBox_Baudrate.Enabled = true;
- 刷新ToolStripMenuItem.Enabled = true;
- 连接ToolStripMenuItem.Text = "连接";
- 连接ToolStripMenuItem.Checked = false;
- label_COM_Sta.Text = "连接状态:未连接";
- label_PortStatus.BackColor = Color.Red;
- }
- }
- /// <summary>
- /// 端口连接事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 连接ToolStripMenuItem_Click(object sender, System.EventArgs e)
- {
- PortConnect();
- }
- /// <summary>
- /// 端口号刷新事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- toolStripComboBox_ComNum.Items.Clear();
- toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
- toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
- }
- /// <summary>
- /// 转速调节事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void numericUpDown_SpeedAdj_ValueChanged(object sender, EventArgs e)
- {
- //生产模式转速设置值更新
- trackBar_FacModeMotorSpeedAdj.Value = (int)numericUpDown_SpeedAdj.Value;
- label_FacModeMotorSpeedSet.Text = trackBar_FacModeMotorSpeedAdj.Value.ToString() + "%";
- //设置转速百分比
- var Data = new byte[1];
- Data[0] = (byte)numericUpDown_SpeedAdj.Value;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
- }
- /// <summary>
- /// 存储标志修改事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 写入存储ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- 写入存储ToolStripMenuItem.Checked = !写入存储ToolStripMenuItem.Checked;
- ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- /// <summary>
- /// 1s定时器
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void timer_1s_Tick(object sender, EventArgs e)
- {
- //时间更新
- label_SystemTime.Text = "系统时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
- //MC_Runinfo超时清除
- if (MC_RunInfo_Refresh == false)
- {
- MC_RunInfo_Refresh_Cnt++;
- if (MC_RunInfo_Refresh_Cnt > 10)//5s
- {
- MC_RunInfo_Clear();
- MC_RunInfo_Refresh_Cnt = 0;
- }
- }
- else
- {
- MC_RunInfo_Refresh_Cnt = 0;
- }
- MC_RunInfo_Refresh = false;
- //MC_Debuginfo超时清除
- if (MC_DebugInfo_Refresh == false)
- {
- MC_DebugInfo_Refresh_Cnt++;
- if (MC_DebugInfo_Refresh_Cnt > 10)//5s
- {
- MC_DebugInfo_Clear();
- MC_DebugInfo_Refresh_Cnt = 0;
- }
- }
- else
- {
- MC_DebugInfo_Refresh_Cnt = 0;
- }
- MC_DebugInfo_Refresh = false;
- //BMS_RunInfo超时清除
- if (BMS_RunInfo_Refresh == false)
- {
- BMS_RunInfo_Refresh_Cnt++;
- if (BMS_RunInfo_Refresh_Cnt > 10)//5s
- {
- richTextBox_OBC_BMS_RunInfo.Clear();
- BMS_RunInfo_Refresh_Cnt = 0;
- }
- }
- else
- {
- BMS_RunInfo_Refresh_Cnt = 0;
- }
- BMS_RunInfo_Refresh = false;
- //故障码超时清除
- if (MC_ErrorCode_Refresh == false)
- {
- MC_ErrorCode_Refresh_Cnt++;
- if (MC_ErrorCode_Refresh_Cnt > 10)//5s
- {
- textBox_ErrorCode.Text = "---";
- MC_ErrorCode_Refresh_Cnt = 0;
- }
- }
- else
- {
- MC_ErrorCode_Refresh_Cnt = 0;
- }
- MC_ErrorCode_Refresh = false;
- //CDL连接超时
- if (识别通讯盒ToolStripMenuItem.Checked)
- {
- if (mySerialProcess.CDL_Online_Flag == false)
- {
- mySerialProcess.CDL_OnlineCheck_Cnt++;
- if (mySerialProcess.CDL_OnlineCheck_Cnt > 1)//1s
- {
- timer_1s.Enabled = false;
- MessageBox.Show("连接失败!", "提示");
- timer_1s.Enabled = true;
- //关闭串口
- mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
- toolStripComboBox_ComNum.Enabled = true;
- toolStripComboBox_Baudrate.Enabled = true;
- 刷新ToolStripMenuItem.Enabled = true;
- 连接ToolStripMenuItem.Text = "连接";
- 连接ToolStripMenuItem.Checked = false;
- label_COM_Sta.Text = "连接状态:未连接";
- label_PortStatus.BackColor = Color.Red;
- }
- }
- }
- //OBC定时发送设置档位
- if (checkBox_OBC_StartSetGearSt.Checked == true)
- {
- var CtrlCode = new byte[2];
- if (comboBox_OBC_SetGearST.SelectedIndex == 5)//档位
- CtrlCode[0] = 0x33;
- else if (comboBox_OBC_SetGearST.SelectedIndex == 6)//档位
- CtrlCode[0] = 0x22;
- else
- CtrlCode[0] = (byte)comboBox_OBC_SetGearST.SelectedIndex;
- if (comboBox_OBC_LightSw.SelectedIndex == 0)//车灯
- CtrlCode[1] = 0xF1;
- else
- CtrlCode[1] = 0xF0;
- if (!mySerialProcess.SendCmdWithoutNotice((ushort)0x731, (byte)0x0C, (ushort)0x3002, CtrlCode))
- {
- checkBox_OBC_StartSetGearSt.Checked = false;
- }
- }
- //OBC定时发送查询电池
- if (checkBox_OBC_StartReadBMS.Checked == true)
- {
- if (!mySerialProcess.SendCmd((ushort)0x732, (byte)0x11, (ushort)0x5000, null))
- {
- checkBox_OBC_StartReadBMS.Checked = false;
- }
- }
- //定时读取存储器
- if (checkBox_ReadRanFlash_AutoSW.Checked == true)
- {
- var Address = new byte[4];
- UInt32 Address_Begin;
- UInt32 Addres_End;
- if (checkBox_ReadRanFlash_AutoClear.Checked == true)
- richTextBox_RamFlasgData.Clear();
- do
- {
- if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
- {
- checkBox_ReadRanFlash_AutoSW.Checked = false;
- MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- continue;
- }
- else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
- {
- checkBox_ReadRanFlash_AutoSW.Checked = false;
- MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- continue;
- }
- else
- {
- Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
- Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
- Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
- Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
- if (Addres_End < Address_Begin)
- {
- checkBox_ReadRanFlash_AutoSW.Checked = false;
- MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- continue;
- }
- else
- {
- var SendByte = new byte[8];
- SendByte[0] = (byte)(Address_Begin >> 24);
- SendByte[1] = (byte)(Address_Begin >> 16);
- SendByte[2] = (byte)(Address_Begin >> 8);
- SendByte[3] = (byte)(Address_Begin);
- SendByte[4] = (byte)(Addres_End >> 24);
- SendByte[5] = (byte)(Addres_End >> 16);
- SendByte[6] = (byte)(Addres_End >> 8);
- SendByte[7] = (byte)(Addres_End);
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte))
- checkBox_ReadRanFlash_AutoSW.Checked = false;
- }
- }
- } while (false);
- }
- //写入参数等待计时
- ACK_WaitCnt++;
- }
- /// <summary>
- /// 运行信息清除
- /// </summary>
- private void MC_RunInfo_Clear()
- {
- foreach (Control c in tabPage_RunInfo.Controls)
- {
- if ((c is TextBox))
- {
- if (c.Name != textBox_ErrorCode.ToString())
- c.Text = "---";
- }
- }
- }
- /// <summary>
- /// 调试信息清除
- /// </summary>
- private void MC_DebugInfo_Clear()
- {
- foreach (Control c in tabPage_DebugInfo.Controls)
- {
- if ((c is TextBox))
- {
- if (c.Name != textBox_ErrorCode.ToString())
- c.Text = "---";
- }
- }
- }
- /// <summary>
- /// 读取马达参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_Read_MotorParam_Click(object sender, EventArgs e)
- {
- richTextBox_MotorParam.Clear();
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null);
- }
- /// <summary>
- /// 写入马达参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_Write_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[40];
- for (int i = 0; i < 40; i++)
- ConfigParam[i] = 0;
- ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
- short wDataTemp = 0;
- ushort DataTemp = 0;
- string[] strDataTemp = richTextBox_MotorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- if (i == 6)
- {
- wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
- ConfigParam[2 * i + 2] = (byte)wDataTemp;
- ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
- }
- else
- {
- DataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
- ConfigParam[2 * i + 2] = (byte)DataTemp;
- ConfigParam[2 * i + 3] = (byte)(DataTemp >> 8);
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B28, ConfigParam);
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- /// <summary>
- /// 读取整车信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadBikeParam_Click(object sender, EventArgs e)
- {
- richTextBox_BikeParam.Clear();
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null);
- }
- /// <summary>
- /// 写入整车信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteBikeParam_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[28];
- for (int i = 0; i < 28; i++)
- ConfigParam[i] = 0;
- ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
- string[] strDataTemp = richTextBox_BikeParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- short wDataTemp = 0;
- //前后灯参数修改
- if (i == 8)
- {
- wDataTemp |= (short)((comboBox_TailLightMode.SelectedIndex + 1) << 12); //Bit15~Bit12:尾灯模式
- wDataTemp |= (short)((comboBox_TailLightVol.SelectedIndex == 0 ? 6 : 12) << 8); //Bit11~Bit8:尾灯电压
- wDataTemp |= (short)(comboBox_FrontLightVol.SelectedIndex == 0 ? 6 : 12); //Bit7~Bit0:前灯电压
- }
- //开关机参数
- else if (i == 11)
- {
- wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOnDelay.Text) << 12);
- wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOffDelay.Text) << 8);
- wDataTemp |= (short)(Convert.ToInt16(textBox_AutoPowerOff.Text));
- }
- else
- {
- wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
- }
- ConfigParam[2 * i + 2] = (byte)wDataTemp;
- ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D1C, ConfigParam);
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- /// <summary>
- /// 读取控制器参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadControlParam_Click(object sender, EventArgs e)
- {
- richTextBox_ControlParam.Clear();
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
- }
- /// <summary>
- /// 写入控制器参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteControlParam_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[34];
- for (int i = 0; i < 34; i++)
- ConfigParam[i] = 0;
- ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
- ushort uwDataTemp = 0;
- string[] strDataTemp = richTextBox_ControlParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
- ConfigParam[2 * i + 2] = (byte)uwDataTemp;
- ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3F22, ConfigParam);
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- /// <summary>
- /// 读取助力参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadAssistParam_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[4];
- int AssistNum = 0;
- try
- {
- AssistNum = Convert.ToInt32(comboBox_AssistTorque.Text);
- ConfigParam[0] = (byte)(AssistNum & 0xFF);
- ConfigParam[1] = (byte)(AssistNum >> 8);
- AssistNum = Convert.ToInt32(comboBox_AssistCadence.Text);
- ConfigParam[2] = (byte)(AssistNum & 0xFF);
- ConfigParam[3] = (byte)(AssistNum >> 8);
- richTextBox_AssistParam.Clear();
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam);
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("请选择助力参数编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- /// <summary>
- /// 写入助力参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteAssistParam_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[80];
- for (int i = 0; i < 80; i++)
- ConfigParam[i] = 0;
- ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
- long lDataTemp = 0;
- string[] strDataTemp = richTextBox_AssistParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
- int index_1 = 0, index_2 = 0;
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- if (strDataTemp[i].Split('=')[0] == "转矩曲线.a")
- {
- index_1 = i;
- break;
- }
- }
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- if (strDataTemp[i].Split('=')[0] == "踏频曲线.d")
- {
- index_2 = i;
- break;
- }
- }
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- lDataTemp = Convert.ToInt32(strDataTemp[i].Split('=')[1]);
- if (i < index_1)
- {
- ConfigParam[2 * i + 4] = (byte)lDataTemp;
- ConfigParam[2 * i + 5] = (byte)(lDataTemp >> 8);
- }
- else if (i <= index_2)
- {
- ConfigParam[4 * i - 4] = (byte)lDataTemp;
- ConfigParam[4 * i - 3] = (byte)(lDataTemp >> 8);
- ConfigParam[4 * i - 2] = (byte)(lDataTemp >> 16);
- ConfigParam[4 * i - 1] = (byte)(lDataTemp >> 24);
- }
- else
- {
- ConfigParam[2 * i + 20] = (byte)lDataTemp;
- ConfigParam[2 * i + 21] = (byte)(lDataTemp >> 8);
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4450, ConfigParam);
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- /// <summary>
- /// 读取调试参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadDebugParam_Click(object sender, EventArgs e)
- {
- richTextBox_DebugParam.Clear();
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
- }
- /// <summary>
- /// 写入调试参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteDebugParam_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[60];
- for (int i = 0; i < 60; i++)
- ConfigParam[i] = 0;
- ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
- ushort uwDataTemp = 0;
- string[] strDataTemp = richTextBox_DebugParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
- //模式
- if (radioButton_Ctl3.Checked == true)
- strDataTemp[0] = "整体运行模式=3";
- else if (radioButton_Ctl4.Checked == true)
- strDataTemp[0] = "整体运行模式=4";
- else if (radioButton_Ctl5.Checked == true)
- strDataTemp[0] = "整体运行模式=5";
- //位置
- if (radioButton_Hall0.Checked == true)
- strDataTemp[1] = "位置获取模式=0";
- else if (radioButton_Hall1.Checked == true)
- strDataTemp[1] = "位置获取模式=1";
- else if (radioButton_Hall2.Checked == true)
- strDataTemp[1] = "位置获取模式=2";
- //方向
- if (radioButton_Dir0.Checked == true)
- strDataTemp[3] = "旋转方向=0";
- else if (radioButton_Dir1.Checked == true)
- strDataTemp[3] = "旋转方向=1";
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
- ConfigParam[2 * i + 2] = (byte)uwDataTemp;
- ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam);
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- /// <summary>
- /// 读取历史
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadRecord_Click(object sender, EventArgs e)
- {
- richTextBox_Record.Clear();
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null);
- }
- /// <summary>
- /// 读取传感器参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadSensorParam_Click(object sender, EventArgs e)
- {
- richTextBox_SensorParam.Clear();
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
- }
- /// <summary>
- /// 写入力矩传感器标定值
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_Write_Cal_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[4];
- for (int i = 0; i < 4; i++)
- ConfigParam[i] = 0;
- ushort uwDataTemp = 0;
- try
- {
- uwDataTemp = Convert.ToUInt16(comboBox_TorqueSet.Text);//负载序号
- ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
- ConfigParam[1] = (byte)(uwDataTemp >> 8);
- uwDataTemp = (ushort)(decimal.Parse(textBox_Load.Text) * 10); ;//负载值0.1Nm
- ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
- ConfigParam[3] = (byte)(uwDataTemp >> 8);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- /// <summary>
- /// 写入传感器参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteSensorParam_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[14];
- for (int i = 0; i < 14; i++)
- ConfigParam[i] = 0;
- ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
- ushort uwDataTemp = 0;
- //力矩传感器参数只写入前面14项与力矩传感器相关的参数
- string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
- int index = 0;
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- if (strDataTemp[i].Split('=')[0] == "踏频传感器一圈脉冲数")
- {
- index = i;
- break;
- }
- }
- for (int i = 0; i < (strDataTemp.Length - index); i++)
- {
- uwDataTemp = Convert.ToUInt16(strDataTemp[i + index].Split('=')[1]);
- ConfigParam[2 * i + 2] = (byte)uwDataTemp;
- ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x420E, ConfigParam);
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- /// <summary>
- /// 写入型号
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteModel_Click(object sender, EventArgs e)
- {
- string Mode = textBox_Model.Text;
- var ModeArray = new byte[16];
- for (ushort i = 0; i < Mode.Length; i++)
- {
- ModeArray[i] = (byte)Mode[i];
- }
- if (Mode.Length < 16)
- {
- ModeArray[Mode.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
- {
- ModeArray[Mode.Length + 1 + i] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
- }
- /// <summary>
- /// 写入SN
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteSN_Click(object sender, EventArgs e)
- {
- string SN = textBox_SN.Text;
- var SNArray = new byte[16];
- for (ushort i = 0; i < SN.Length; i++)
- {
- SNArray[i] = (byte)SN[i];
- }
- if (SN.Length < 16)
- {
- SNArray[SN.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - SN.Length - 1; i++)
- {
- SNArray[SN.Length + 1 + i] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
- }
- /// <summary>
- /// 查询版本信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadVersion_Click(object sender, EventArgs e)
- {
- textBox_Model.Text = "---";
- textBox_SN.Text = "---";
- textBox_HW.Text = "---";
- textBox_FW.Text = "---";
- textBox_SP.Text = "---";
- textBox_OBC_ReadModel.Text = "---";
- textBox_OBC_ReadSN.Text = "---";
- textBox_OBC_ReadHW.Text = "---";
- textBox_OBC_ReadFW.Text = "---";
- textBox_OBC_ReadSP.Text = "---";
- textBox_FacModeName.Text = "---";
- textBox_FacModeNum.Text = "---";
- textBox_FacModeHW.Text = "---";
- textBox_FacModeFW.Text = "---";
- textBox_FacModeSP.Text = "---";
- Class_Motor_Ver.Mode = "---";
- Class_Motor_Ver.SN = "---";
- Class_Motor_Ver.HW = "---";
- Class_Motor_Ver.FW = "---";
- Class_Motor_Ver.Special = "---";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
- }
- /// <summary>
- /// 查询自定义1
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadUser1_Click(object sender, EventArgs e)
- {
- textBox_User1.Text = "---";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null);
- }
- /// <summary>
- /// 查询自定义2
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadUser2_Click(object sender, EventArgs e)
- {
- textBox_User2.Text = "---";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null);
- }
- /// <summary>
- /// 查询自定义3
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadUser3_Click(object sender, EventArgs e)
- {
- textBox_User3.Text = "---";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null);
- }
- /// <summary>
- /// 写入自定义字符串1
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteUser1_Click(object sender, EventArgs e)
- {
- string User = textBox_User1.Text;
- var UserArray = new byte[16];
- for (ushort i = 0; i < User.Length; i++)
- {
- UserArray[i] = (byte)User[i];
- }
- if (User.Length < 16)
- {
- UserArray[User.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - User.Length - 1; i++)
- {
- UserArray[User.Length + 1 + i] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1410, UserArray);
- }
- /// <summary>
- /// 写入自定义字符串2
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteUser2_Click(object sender, EventArgs e)
- {
- string User = textBox_User2.Text;
- var UserArray = new byte[16];
- for (ushort i = 0; i < User.Length; i++)
- {
- UserArray[i] = (byte)User[i];
- }
- if (User.Length < 16)
- {
- UserArray[User.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - User.Length - 1; i++)
- {
- UserArray[User.Length + 1 + i] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1610, UserArray);
- }
- /// <summary>
- /// 写入自定义字符串3
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteUser3_Click(object sender, EventArgs e)
- {
- string User = textBox_User3.Text;
- var UserArray = new byte[16];
- for (ushort i = 0; i < User.Length; i++)
- {
- UserArray[i] = (byte)User[i];
- }
- if (User.Length < 16)
- {
- UserArray[User.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - User.Length - 1; i++)
- {
- UserArray[User.Length + 1 + i] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1810, UserArray);
- }
- /// <summary>
- /// 查询生产信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadMAC_Click(object sender, EventArgs e)
- {
- textBox_MAC.Text = "---";
- textBox_MACAdd.Text = "---";
- textBox_MACDate.Text = "---";
- textBox_PP.Text = "---";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null);
- }
- /// <summary>
- /// 写入生产信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteMac_Click(object sender, EventArgs e)
- {
- var MACArray = new byte[32];
- //填入生产商
- for (ushort i = 0; i < textBox_MAC.Text.Length; i++)
- {
- MACArray[i] = (byte)textBox_MAC.Text[i];
- }
- if (textBox_MAC.Text.Length < 8)
- {
- MACArray[textBox_MAC.Text.Length] = (byte)'.';
- for (ushort i = 0; i < 8 - textBox_MAC.Text.Length - 1; i++)
- {
- MACArray[textBox_MAC.Text.Length + 1 + i] = 0x20;
- }
- }
- //填入生产地
- for (ushort i = 0; i < textBox_MACAdd.Text.Length; i++)
- {
- MACArray[8 + i] = (byte)textBox_MACAdd.Text[i];
- }
- if (textBox_MACAdd.Text.Length < 8)
- {
- MACArray[textBox_MACAdd.Text.Length + 8] = (byte)'.';
- for (ushort i = 0; i < 8 - textBox_MACAdd.Text.Length - 1; i++)
- {
- MACArray[textBox_MACAdd.Text.Length + 1 + i + 8] = 0x20;
- }
- }
- //填入生产日期
- for (ushort i = 0; i < textBox_MACDate.Text.Length; i++)
- {
- MACArray[16 + i] = (byte)textBox_MACDate.Text[i];
- }
- if (textBox_MACDate.Text.Length < 8)
- {
- MACArray[textBox_MACDate.Text.Length + 16] = (byte)'.';
- for (ushort i = 0; i < 8 - textBox_MACDate.Text.Length - 1; i++)
- {
- MACArray[textBox_MACDate.Text.Length + 1 + i + 16] = 0x20;
- }
- }
- //填入品牌
- for (ushort i = 0; i < textBox_PP.Text.Length; i++)
- {
- MACArray[24 + i] = (byte)textBox_PP.Text[i];
- }
- if (textBox_PP.Text.Length < 8)
- {
- MACArray[textBox_PP.Text.Length + 24] = (byte)'.';
- for (ushort i = 0; i < 8 - textBox_PP.Text.Length - 1; i++)
- {
- MACArray[textBox_PP.Text.Length + 1 + i + 24] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
- }
- /// <summary>
- /// 查询密钥
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadKey_Click(object sender, EventArgs e)
- {
- textBox_Key.Text = "---";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null);
- }
- /// <summary>
- /// 写入校验密钥
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteKey_Click(object sender, EventArgs e)
- {
- string Key = textBox_Key.Text;
- var KeyArray = new byte[8];
- if (Key.Length != 8)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("请检查字符长度是否为8", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- return;
- }
- for (ushort i = 0; i < Key.Length; i++)
- {
- KeyArray[i] = (byte)Key[i];
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1108, KeyArray);
- }
- /// <summary>
- /// 查询在线检测结果
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadOnLine_Click(object sender, EventArgs e)
- {
- textBox_Online.Text = "---";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2100, null);
- }
- /// <summary>
- /// 系统清除
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_SystemClear_Click(object sender, EventArgs e)
- {
- var Code = new byte[5];
- Code[0] = (byte)'C';
- Code[1] = (byte)'L';
- Code[2] = (byte)'E';
- Code[3] = (byte)'A';
- Code[4] = (byte)'R';
- timer_1s.Enabled = false;
- if (MessageBox.Show("系统清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
- MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- }
- timer_1s.Enabled = true;
- }
- /// <summary>
- /// 参数还原
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_Recovery_Click(object sender, EventArgs e)
- {
- var Code = new byte[8];
- Code[0] = (byte)'R';
- Code[1] = (byte)'E';
- Code[2] = (byte)'C';
- Code[3] = (byte)'O';
- Code[4] = (byte)'V';
- Code[5] = (byte)'E';
- Code[6] = (byte)'R';
- Code[7] = (byte)'Y';
- timer_1s.Enabled = false;
- if (MessageBox.Show("参数还原后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- if (MessageBox.Show("请再次确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- if (MessageBox.Show("请最后确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2708, Code);
- MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- }
- timer_1s.Enabled = true;
- }
- /// <summary>
- /// 系统复位
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_Reset_Click(object sender, EventArgs e)
- {
- var Code_Off = new byte[5];
- var Code_Reset = new byte[5];
- Code_Off[0] = (byte)'O';
- Code_Off[1] = (byte)'F';
- Code_Off[2] = (byte)'F';
- Code_Off[3] = (byte)'.';
- Code_Off[4] = (byte)'.';
- Code_Reset[0] = (byte)'R';
- Code_Reset[1] = (byte)'E';
- Code_Reset[2] = (byte)'S';
- Code_Reset[3] = (byte)'E';
- Code_Reset[4] = (byte)'T';
- timer_1s.Enabled = false;
- if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- timer_1s.Enabled = true;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
- PowerOffAckStatus = false;
- Delay_ms(250);
- int TryCnt = 3;
- while ((TryCnt--) >= 0)
- {
- if (!PowerOffAckStatus)
- {
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
- PowerOffAckStatus = false;
- Delay_ms(250);
- }
- else break;
- }
- if (PowerOffAckStatus)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("已关机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
- timer_1s.Enabled = true;
- }
- else
- {
- timer_1s.Enabled = false;
- MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- timer_1s.Enabled = true;
- }
- /// <summary>
- /// 记录清除
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ClearLog_Click(object sender, EventArgs e)
- {
- var Code = new byte[9];
- Code[0] = (byte)'L';
- Code[1] = (byte)'O';
- Code[2] = (byte)'G';
- Code[3] = (byte)' ';
- Code[4] = (byte)'C';
- Code[5] = (byte)'L';
- Code[6] = (byte)'E';
- Code[7] = (byte)'A';
- Code[8] = (byte)'R';
- timer_1s.Enabled = false;
- if (MessageBox.Show("历史记录信息清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3909, Code);
- MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- }
- timer_1s.Enabled = true;
- }
- /// <summary>
- /// 打开系统计算器
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 计算器ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- System.Diagnostics.Process.Start("calc.exe");
- }
- /// <summary>
- ///故障转换和显示
- /// </summary>
- List<string> ErrorInfo = new List<string>{ "过流保护", "低压保护", "过压保护", "堵转保护","过热保护","速度传感器故障","力矩传感器故障","霍尔故障",
- "马达缺相","NTC故障","BMS校验失败","","OBC校验失败","MCU故障","踏频传感器故障","指拨故障","MOS短路","电压异常","","","","","","","","","","","","",
- "",""};
- private string ErrorInfoDisplay(UInt32 Code)
- {
- string Result = "";
- if (Code == 0)
- {
- Result = "无故障";
- }
- else
- {
- for (int i = 0; i < 32; i++)
- {
- if ((Code & 0x01) == 0x01)
- {
- Result += ErrorInfo[i] + " ";
- }
- Code >>= 1;
- }
- }
- return Result;
- }
- /// <summary>
- /// 鼠标滑过故障码显示具体内容
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void textBox_ErrorCode_MouseHover(object sender, EventArgs e)
- {
- // 创建the ToolTip
- ToolTip toolTip1 = new ToolTip();
- // 设置显示样式
- toolTip1.AutoPopDelay = 30000;//提示信息的可见时间
- toolTip1.InitialDelay = 50;//事件触发多久后出现提示
- toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
- toolTip1.ShowAlways = true;//是否显示提示框
- // 设置伴随的对象.
- string ErrorCode = this.textBox_ErrorCode.Text;
- UInt32 Code = ErrorCode.Contains("H") ? Convert.ToUInt32(ErrorCode.Split('H')[0], 16) : 0;
- toolTip1.SetToolTip(this.textBox_ErrorCode, ErrorInfoDisplay(Code));//设置故障内容显示
- }
- /// <summary>
- /// 数据记录
- /// </summary>
- private void RunInfoAutoSave()
- {
- if (运行信息记录ToolStripMenuItem.Checked == true)
- {
- if (RunInfoSaveFilename == string.Empty)
- {
- return;
- }
- string SaveData = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff").Replace(" ", "_") + " --> ";
- foreach (Control c in tabPage_RunInfo.Controls)
- {
- if (c is TextBox)
- {
- SaveData += c.Text + " , ";
- }
- }
- foreach (Control c in tabPage_DebugInfo.Controls)
- {
- if (c is TextBox)
- {
- SaveData += c.Text + " , ";
- }
- }
- SaveData += "\r\n";
- System.IO.File.AppendAllText(RunInfoSaveFilename, SaveData);//sb.ToString());
- }
- }
- /// <summary>
- /// 打开或关闭数据记录
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- if (运行信息记录ToolStripMenuItem.Checked == false)
- {
- if (mySerialProcess.mySerial.IsOpen == true)
- {
- RunInfoSaveFilename = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_运行信息" + ".txt";
- System.IO.File.AppendAllText(RunInfoSaveFilename, "时间 --> 车速 , 转速 , 踏频 , 力矩Reg , 力矩 , 踩踏方向 , 电压 , 电流 , 功率 , 电量 , " +
- "PCB温度 , 绕组温度 , MOS温度 , 挡位 , 灯开关 , 续航 , 平均功耗 , 单次里程 , 单次时间 , 故障码 , " +
- "系统状态机 , 二层状态机 , 电机状态机 , 助力状态机 , D轴电流给定 , Q轴电流给定 , D轴电压给定 , Q轴电压给定 , 瞬时力矩 , 时间滤波力矩 , 踏频滤波力矩 , D轴电流反馈 , Q轴电流反馈 , 助力函数输出" + "\r\n");
- timer_1s.Enabled = false;
- MessageBox.Show("开始记录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- timer_1s.Enabled = true;
- 运行信息记录ToolStripMenuItem.Checked = true;
- }
- else
- {
- timer_1s.Enabled = false;
- MessageBox.Show("请连接电机", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- timer_1s.Enabled = true;
- }
- }
- else
- {
- 运行信息记录ToolStripMenuItem.Checked = false;
- timer_1s.Enabled = false;
- MessageBox.Show("停止记录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- timer_1s.Enabled = true;
- }
- }
- /// <summary>
- /// 仪表启动控制档位开关事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void checkBox_OBC_StartSetGearSt_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_OBC_StartSetGearSt.Checked == true)
- {
- //检查串口是否打开
- if (!mySerialProcess.mySerial.IsOpen)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_1s.Enabled = true;
- checkBox_OBC_StartSetGearSt.Checked = false;
- return;
- }
- //检查是否选择档位和打开车灯
- if ((comboBox_OBC_SetGearST.SelectedIndex == -1) || (comboBox_OBC_LightSw.SelectedIndex == -1))
- {
- timer_1s.Enabled = false;
- MessageBox.Show("请检查档位设置和大灯开关!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_1s.Enabled = true;
- checkBox_OBC_StartSetGearSt.Checked = false;
- return;
- }
- }
- }
- /// <summary>
- /// OBC查询电机用户参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_ReadUserInfo_Click(object sender, EventArgs e)
- {
- richTextBox_OBC_ReadUserInfo.Clear();
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3300, null);
- }
- /// <summary>
- /// OBC设置电机用户参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_WriteUserInfo_Click(object sender, EventArgs e)
- {
- var UserInfoCode = new byte[8];
- for (int i = 0; i < UserInfoCode.Length; i++)
- UserInfoCode[i] = 0;
- if (comboBox_OBC_StartMode.SelectedIndex == -1)//检查数据有效性
- {
- timer_1s.Enabled = false;
- MessageBox.Show("请选择启动模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- return;
- }
- if (comboBox_OBC_AssistFunc.SelectedIndex == -1)//检查数据有效性
- {
- timer_1s.Enabled = false;
- MessageBox.Show("请选择助力方案!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- return;
- }
- UserInfoCode[0] = (byte)(int)numericUpDown_OBC_WheelAdj.Value;
- UserInfoCode[1] = (byte)(comboBox_OBC_StartMode.SelectedIndex + 1);
- UserInfoCode[2] = (byte)(comboBox_OBC_AssistFunc.SelectedIndex + 1);
- UserInfoCode[3] = (byte)(uint)numericUpDown_OBC_OffTime.Value;
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3408, UserInfoCode);
- }
- /// <summary>
- /// OBC查询电机版本信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_ReadVerInfo_Click(object sender, EventArgs e)
- {
- textBox_Model.Text = "---";
- textBox_SN.Text = "---";
- textBox_HW.Text = "---";
- textBox_FW.Text = "---";
- textBox_SP.Text = "---";
- textBox_OBC_ReadModel.Text = "---";
- textBox_OBC_ReadSN.Text = "---";
- textBox_OBC_ReadHW.Text = "---";
- textBox_OBC_ReadFW.Text = "---";
- textBox_OBC_ReadSP.Text = "---";
- textBox_FacModeName.Text = "---";
- textBox_FacModeNum.Text = "---";
- textBox_FacModeHW.Text = "---";
- textBox_FacModeFW.Text = "---";
- textBox_FacModeSP.Text = "---";
- Class_Motor_Ver.Mode = "---";
- Class_Motor_Ver.SN = "---";
- Class_Motor_Ver.HW = "---";
- Class_Motor_Ver.FW = "---";
- Class_Motor_Ver.Special = "---";
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
- }
- /// <summary>
- /// OBC读取骑行历史
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_ReadRideInfo_Click(object sender, EventArgs e)
- {
- textBox_OBC_TRIP_KM.Text = "";
- textBox_OBC_TRIP_TIME.Text = "";
- textBox_OBC_ODO_KM.Text = "";
- textBox_OBC_ODO_TIME.Text = "";
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3500, null);
- }
- /// <summary>
- /// OBC清除TRIP里程
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_ClearTrip_Click(object sender, EventArgs e)
- {
- var Code = new byte[5];
- Code[0] = (byte)'C';
- Code[1] = (byte)'L';
- Code[2] = (byte)'E';
- Code[3] = (byte)'A';
- Code[4] = (byte)'R';
- timer_1s.Enabled = false;
- if (MessageBox.Show("TRIP清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3605, Code);
- timer_1s.Enabled = true;
- }
- private void checkBox_OBC_StartReadBMS_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_OBC_StartReadBMS.Checked == true)
- {
- //检查串口是否打开
- if (!mySerialProcess.mySerial.IsOpen)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_1s.Enabled = true;
- checkBox_OBC_StartReadBMS.Checked = false;
- return;
- }
- }
- }
- /// <summary>
- /// 写入力矩传感器参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteTqSensorParam_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[46];
- for (int i = 0; i < 14; i++)
- ConfigParam[i] = 0;
- ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
- ushort uwDataTemp = 0;
- //力矩传感器参数只写入前面14项与力矩传感器相关的参数
- string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
- int index = 0;
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- if (strDataTemp[i].Split('=')[0] == "第四阶段转矩点采集值")
- {
- index = i;
- break;
- }
- }
- for (int i = 0; i < (index + 1); i++)
- {
- uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
- ConfigParam[2 * i + 2] = (byte)uwDataTemp;
- ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x472E, ConfigParam);
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- /// <summary>
- /// 查询存储标志
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadSaveFlag_Click(object sender, EventArgs e)
- {
- radioButton_EE_SaveYes.Checked = false;
- radioButton_EE_SaveNo.Checked = false;
- radioButton_SIP_SaveYes.Checked = false;
- radioButton_SIP_SaveNo.Checked = false;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null);
- }
- /// <summary>
- /// 写入存储标志
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteSaveFlag_Click(object sender, EventArgs e)
- {
- var SaveFlag = new byte[6];
- for (int i = 0; i < 6; i++)
- SaveFlag[i] = 0;
- if ((radioButton_EE_SaveYes.Checked == false) && (radioButton_EE_SaveNo.Checked == false))
- {
- timer_1s.Enabled = false;
- MessageBox.Show("请选择EEPROM存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- return;
- }
- if ((radioButton_SIP_SaveYes.Checked == false) && (radioButton_SIP_SaveNo.Checked == false))
- {
- timer_1s.Enabled = false;
- MessageBox.Show("请选择SIP校验存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- return;
- }
- SaveFlag[0] = (byte)((checkBox_SaveYes.Checked) ? 0x01 : 0x00);
- SaveFlag[2] = (byte)(radioButton_EE_SaveYes.Checked ? 0x01 : 0x00);
- SaveFlag[3] = 0;
- SaveFlag[4] = (byte)(radioButton_SIP_SaveYes.Checked ? 0x01 : 0x00);
- SaveFlag[5] = 0;
- timer_1s.Enabled = false;
- if (MessageBox.Show("确认修改存储标志?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4906, SaveFlag);
- }
- timer_1s.Enabled = true;
- }
- /// <summary>
- /// 读取指定地址数据
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadRamFlash_Click(object sender, EventArgs e)
- {
- var Address = new byte[4];
- UInt32 Address_Begin;
- UInt32 Addres_End;
- if (checkBox_ReadRanFlash_AutoClear.Checked == true)
- richTextBox_RamFlasgData.Clear();
- if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
- {
- timer_1s.Enabled = false;
- MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_1s.Enabled = true;
- return;
- }
- else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
- {
- timer_1s.Enabled = false;
- MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_1s.Enabled = true;
- return;
- }
- else
- {
- Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
- Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
- Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
- Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
- if (Addres_End < Address_Begin)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_1s.Enabled = true;
- return;
- }
- else
- {
- var SendByte = new byte[8];
- SendByte[0] = (byte)(Address_Begin >> 24);
- SendByte[1] = (byte)(Address_Begin >> 16);
- SendByte[2] = (byte)(Address_Begin >> 8);
- SendByte[3] = (byte)(Address_Begin);
- SendByte[4] = (byte)(Addres_End >> 24);
- SendByte[5] = (byte)(Addres_End >> 16);
- SendByte[6] = (byte)(Addres_End >> 8);
- SendByte[7] = (byte)(Addres_End);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
- }
- }
- }
- /// <summary>
- /// 工作模式选择
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void comboBox_WorkMode_SelectedIndexChanged(object sender, EventArgs e)
- {
- var RunMode = new byte[1];
- if (comboBox_WorkMode.Text == "配置模式")
- RunMode[0] = 0x01;
- else if (comboBox_WorkMode.Text == "调试模式")
- RunMode[0] = 0x02;
- else
- RunMode[0] = 0x00;
- mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
- }
- /// <summary>
- /// 助力档位选择
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void comboBox_GearSt_SelectedIndexChanged(object sender, EventArgs e)
- {
- var CtrlCode = new byte[2];
- if (comboBox_GearSt.SelectedIndex == 5)//档位
- CtrlCode[0] = 0x33;
- else if (comboBox_GearSt.SelectedIndex == 6)//档位
- CtrlCode[0] = 0x22;
- else
- CtrlCode[0] = (byte)comboBox_GearSt.SelectedIndex;
- if (comboBox_LightSwitch.SelectedIndex == 0)//车灯
- CtrlCode[1] = 0xF1;
- else
- CtrlCode[1] = 0xF0;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
- comboBox_OBC_SetGearST.SelectedIndex = comboBox_GearSt.SelectedIndex;
- comboBox_OBC_LightSw.SelectedIndex = comboBox_LightSwitch.SelectedIndex;
- }
- /// <summary>
- /// 仪表档位选择
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void comboBox_OBC_SetGearST_SelectedIndexChanged(object sender, EventArgs e)
- {
- comboBox_GearSt.SelectedIndex = comboBox_OBC_SetGearST.SelectedIndex;
- comboBox_LightSwitch.SelectedIndex = comboBox_OBC_LightSw.SelectedIndex;
- }
- /// <summary>
- /// 生产模式初始化
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_FacModeInit_Click(object sender, EventArgs e)
- {
- var Code = new byte[5];
- Code[0] = (byte)'C';
- Code[1] = (byte)'L';
- Code[2] = (byte)'E';
- Code[3] = (byte)'A';
- Code[4] = (byte)'R';
- timer_1s.Enabled = false;
- if (MessageBox.Show("电机即将初始化!", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- if (MessageBox.Show("请再次确认", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- timer_1s.Enabled = true;
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
- PowerOffAckStatus = false;
- Delay_ms(250);
- int TryCnt = 3;
- while ((TryCnt--) >= 0)
- {
- if (!PowerOffAckStatus)
- {
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
- PowerOffAckStatus = false;
- Delay_ms(250);
- }
- else break;
- }
- if (PowerOffAckStatus)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("系统已关机,请保持无负载重新开机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
- timer_1s.Enabled = true;
- }
- else
- {
- timer_1s.Enabled = false;
- MessageBox.Show("初始化失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- timer_1s.Enabled = true;
- }
- }
- timer_1s.Enabled = true;
- //清除历史测试记录
- textBox_FacModeSensorADC0.Text = "";
- textBox_FacModeSensorADC1.Text = "";
- textBox_FacModeSensorADC2.Text = "";
- textBox_FacModeSensorADC3.Text = "";
- textBox_FacModeSensorADC4.Text = "";
- checkBox_FacModeCheckBikeSpeed.Checked = false;
- checkBox_FacModeCheckCadence.Checked = false;
- checkBox_FacModeCheckNTC.Checked = false;
- checkBox_FacModeCheckVol.Checked = false;
- LightSwitchStatus = false;
- MotorRunStatus = false;
- trackBar_FacModeMotorSpeedAdj.Value = 5;
- textBox_FacModeName.Text = "";
- textBox_FacModeNum.Text = "";
- textBox_FacModeHW.Text = "";
- textBox_FacModeFW.Text = "";
- }
- /// <summary>
- /// 生产模式读取传感器参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_FacModeSensorRead_Click(object sender, EventArgs e)
- {
- richTextBox_SensorParam.Clear();
- textBox_FacModeSensorADC0.Text = "";
- textBox_FacModeSensorADC1.Text = "";
- textBox_FacModeSensorADC2.Text = "";
- textBox_FacModeSensorADC3.Text = "";
- textBox_FacModeSensorADC4.Text = "";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
- }
- /// <summary>
- /// 生产模式传感器标定1
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void buttonFacModeSet1_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[4];
- for (int i = 0; i < 4; i++)
- ConfigParam[i] = 0;
- ushort uwDataTemp = 0;
- try
- {
- uwDataTemp = 1;//负载序号
- ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
- ConfigParam[1] = (byte)(uwDataTemp >> 8);
- uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal1.Text) * 10); ;//负载值0.1Nm
- ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
- ConfigParam[3] = (byte)(uwDataTemp >> 8);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
- Delay_ms(200);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- /// <summary>
- /// 生产模式传感器标定2
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void buttonFacModeSet2_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[4];
- for (int i = 0; i < 4; i++)
- ConfigParam[i] = 0;
- ushort uwDataTemp = 0;
- try
- {
- uwDataTemp = 2;//负载序号
- ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
- ConfigParam[1] = (byte)(uwDataTemp >> 8);
- uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal2.Text) * 10); ;//负载值0.1Nm
- ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
- ConfigParam[3] = (byte)(uwDataTemp >> 8);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
- Delay_ms(200);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- /// <summary>
- /// 生产模式传感器标定3
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void buttonFacModeSet3_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[4];
- for (int i = 0; i < 4; i++)
- ConfigParam[i] = 0;
- ushort uwDataTemp = 0;
- try
- {
- uwDataTemp = 3;//负载序号
- ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
- ConfigParam[1] = (byte)(uwDataTemp >> 8);
- uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal3.Text) * 10); ;//负载值0.1Nm
- ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
- ConfigParam[3] = (byte)(uwDataTemp >> 8);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
- Delay_ms(200);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- /// <summary>
- /// 生产模式传感器标定3
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void buttonFacModeSet4_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[4];
- for (int i = 0; i < 4; i++)
- ConfigParam[i] = 0;
- ushort uwDataTemp = 0;
- try
- {
- uwDataTemp = 4;//负载序号
- ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
- ConfigParam[1] = (byte)(uwDataTemp >> 8);
- uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal4.Text) * 10); ;//负载值0.1Nm
- ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
- ConfigParam[3] = (byte)(uwDataTemp >> 8);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
- Delay_ms(200);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- /// <summary>
- /// 生产模式采集按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_FacModeWorkMode_Click(object sender, EventArgs e)
- {
- var RunMode = new byte[1];
- if (button_FacModeWorkMode.Text == "开始")
- {
- RunMode[0] = 0x01;
- if (mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode))
- {
- button_FacModeWorkMode.Text = "停止";
- button_FacModeWorkMode.BackColor = Color.Yellow;
- }
- }
- else if (button_FacModeWorkMode.Text == "停止")
- {
- RunMode[0] = 0x00;
- if (mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode))
- {
- button_FacModeWorkMode.Text = "开始";
- button_FacModeWorkMode.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
- }
- }
- }
- /// <summary>
- /// 生产模式开关灯
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- bool LightSwitchStatus = false;
- private void button_FacModeLightSW_Click(object sender, EventArgs e)
- {
- var CtrlCode = new byte[2];
- CtrlCode[0] = 0x00;
- if (LightSwitchStatus)
- {
- CtrlCode[1] = 0xF0;
- button_FacModeLightSW.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(128)))));
- }
- else
- {
- CtrlCode[1] = 0xF1;
- button_FacModeLightSW.BackColor = Color.Yellow;
- }
- if (mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode))
- {
- LightSwitchStatus = !LightSwitchStatus;
- comboBox_LightSwitch.SelectedIndex = LightSwitchStatus ? 0 : 1;
- comboBox_OBC_LightSw.SelectedIndex = LightSwitchStatus ? 0 : 1;
- }
- }
- /// <summary>
- /// 生产模式电机控制
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- bool MotorRunStatus = false;
- private void button_FacModeMotorRun_Click(object sender, EventArgs e)
- {
- string DebugDefaultInfo = "";
- //获取调试信息
- if (richTextBox_DebugParam.Text == string.Empty)
- {
- richTextBox_DebugParam.Clear();
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
- }
- Delay_ms(200);
- DebugDefaultInfo = richTextBox_DebugParam.Text;
- //获取参数
- string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
- if (strDataTemp.Length != 29)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- return;
- }
- //设置参数
- var ConfigParam = new byte[60];
- for (int i = 0; i < 60; i++)
- ConfigParam[i] = 0;
- ConfigParam[0] = 0x00;
- ushort uwDataTemp = 0;
- if (!MotorRunStatus) //停止状态
- {
- //设置速度环
- strDataTemp[0] = "整体运行模式=3";
- //发送数据
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
- ConfigParam[2 * i + 2] = (byte)uwDataTemp;
- ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
- }
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
- return;
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- Delay_ms(200);
- //设置转速百分比100%
- trackBar_FacModeMotorSpeedAdj.Value = 100;
- MotorRunStatus = !MotorRunStatus;
- button_FacModeMotorRun.BackColor = Color.Yellow;
- Delay_ms(200);
- //电机进入配置模式
- var RunMode = new byte[1];
- RunMode[0] = 0x01;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
- button_FacModeWorkMode.Text = "停止";
- button_FacModeWorkMode.BackColor = Color.Yellow;
- }
- else //运转状态
- {
- //设置转速百分比0%
- trackBar_FacModeMotorSpeedAdj.Value = 0;
- MotorRunStatus = !MotorRunStatus;
- button_FacModeMotorRun.BackColor = Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
- Delay_ms(200);
- //还原为原始值
- strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
- ConfigParam[2 * i + 2] = (byte)uwDataTemp;
- ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
- }
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
- return;
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- Delay_ms(200);
- //电机退出配置模式
- var RunMode = new byte[1];
- RunMode[0] = 0x00;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
- button_FacModeWorkMode.Text = "开始";
- button_FacModeWorkMode.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
- }
- }
- /// <summary>
- /// 生产模式转速调节
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void trackBar_FacModeMotorSpeedAdj_ValueChanged(object sender, EventArgs e)
- {
- //转速百分比更新
- label_FacModeMotorSpeedSet.Text = trackBar_FacModeMotorSpeedAdj.Value.ToString() + "%";
- numericUpDown_SpeedAdj.Value = trackBar_FacModeMotorSpeedAdj.Value;
- }
- /// <summary>
- /// 生产模式写入型号
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_FacModeSetName_Click(object sender, EventArgs e)
- {
- string Mode = textBox_FacModeName.Text;
- var ModeArray = new byte[16];
- for (ushort i = 0; i < Mode.Length; i++)
- {
- ModeArray[i] = (byte)Mode[i];
- }
- if (Mode.Length < 16)
- {
- ModeArray[Mode.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
- {
- ModeArray[Mode.Length + 1 + i] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
- }
- /// <summary>
- /// 生产模式写入SN
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Button_FacModeSetNum_Click(object sender, EventArgs e)
- {
- string SN = textBox_FacModeNum.Text;
- var SNArray = new byte[16];
- for (ushort i = 0; i < SN.Length; i++)
- {
- SNArray[i] = (byte)SN[i];
- }
- if (SN.Length < 16)
- {
- SNArray[SN.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - SN.Length - 1; i++)
- {
- SNArray[SN.Length + 1 + i] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
- }
- /// <summary>
- /// 生产模式读取版本信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Button_FacModeReadVer_Click_1(object sender, EventArgs e)
- {
- textBox_Model.Text = "---";
- textBox_SN.Text = "---";
- textBox_HW.Text = "---";
- textBox_FW.Text = "---";
- textBox_SP.Text = "---";
- textBox_OBC_ReadModel.Text = "---";
- textBox_OBC_ReadSN.Text = "---";
- textBox_OBC_ReadHW.Text = "---";
- textBox_OBC_ReadFW.Text = "---";
- textBox_OBC_ReadSP.Text = "---";
- textBox_FacModeName.Text = "---";
- textBox_FacModeNum.Text = "---";
- textBox_FacModeHW.Text = "---";
- textBox_FacModeFW.Text = "---";
- textBox_FacModeSP.Text = "---";
- textBox_FacModeGit.Text = "---";
- Class_Motor_Ver.Mode = "---";
- Class_Motor_Ver.SN = "---";
- Class_Motor_Ver.HW = "---";
- Class_Motor_Ver.FW = "---";
- Class_Motor_Ver.Special = "---";
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
- }
- /// <summary>
- /// 生产模式写入生产信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Button_FacModeSetMacDate_Click(object sender, EventArgs e)
- {
- var MACArray = new byte[32];
- string MacDefaultInfo = "";
- string MacAddDefaultInfo = "";
- string MacDateDefaultInfo = DateTime.Now.ToString("yyyyMMdd");
- string MacPPDefaultInfo = "";
- do
- {
- //填入生产商
- if (toolStripTextBox_MAC.Text == string.Empty)
- {
- break;
- }
- MacDefaultInfo = toolStripTextBox_MAC.Text;
- for (ushort i = 0; i < MacDefaultInfo.Length; i++)
- {
- MACArray[i] = (byte)MacDefaultInfo[i];
- }
- if (MacDefaultInfo.Length < 8)
- {
- MACArray[MacDefaultInfo.Length] = (byte)'.';
- for (ushort i = 0; i < 8 - MacDefaultInfo.Length - 1; i++)
- {
- MACArray[MacDefaultInfo.Length + 1 + i] = 0x20;
- }
- }
- //填入生产地
- if (toolStripTextBoxMACAddr.Text == string.Empty)
- {
- break;
- }
- MacAddDefaultInfo = toolStripTextBoxMACAddr.Text;
- for (ushort i = 0; i < MacAddDefaultInfo.Length; i++)
- {
- MACArray[8 + i] = (byte)MacAddDefaultInfo[i];
- }
- if (MacAddDefaultInfo.Length < 8)
- {
- MACArray[MacAddDefaultInfo.Length + 8] = (byte)'.';
- for (ushort i = 0; i < 8 - MacAddDefaultInfo.Length - 1; i++)
- {
- MACArray[MacAddDefaultInfo.Length + 1 + i + 8] = 0x20;
- }
- }
- //填入生产日期
- if (toolStripTextBox_MACDate.Text == string.Empty)
- {
- break;
- }
- MacDateDefaultInfo = toolStripTextBox_MACDate.Text;
- for (ushort i = 0; i < MacDateDefaultInfo.Length; i++)
- {
- MACArray[16 + i] = (byte)MacDateDefaultInfo[i];
- }
- if (MacDateDefaultInfo.Length < 8)
- {
- MACArray[MacDateDefaultInfo.Length + 16] = (byte)'.';
- for (ushort i = 0; i < 8 - MacDateDefaultInfo.Length - 1; i++)
- {
- MACArray[MacDateDefaultInfo.Length + 1 + i + 16] = 0x20;
- }
- }
- //填入产品标识
- if (toolStripTextBox_MACPD.Text == string.Empty)
- {
- break;
- }
- MacPPDefaultInfo = toolStripTextBox_MACPD.Text;
- for (ushort i = 0; i < MacPPDefaultInfo.Length; i++)
- {
- MACArray[24 + i] = (byte)MacPPDefaultInfo[i];
- }
- if (MacPPDefaultInfo.Length < 8)
- {
- MACArray[MacPPDefaultInfo.Length + 24] = (byte)'.';
- for (ushort i = 0; i < 8 - MacPPDefaultInfo.Length - 1; i++)
- {
- MACArray[MacPPDefaultInfo.Length + 1 + i + 24] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
- return;
- } while (false);
- timer_1s.Enabled = false;
- MessageBox.Show("生产信息配置不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- /// <summary>
- /// 生产模式保存测试页面
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Button_FacModeSaveResult_Click(object sender, EventArgs e)
- {
- Button_FacModeSaveResult.Text = "存储中…";
- string[] AssistParams = new string[15];
- do
- {
- //读取一次马达参数
- richTextBox_MotorParam.Clear();
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break; ;
- Delay_ms(100);
- //读取一次整车参数
- richTextBox_BikeParam.Clear();
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
- Delay_ms(100);
- //读取一次控制参数
- richTextBox_ControlParam.Clear();
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
- Delay_ms(100);
- //查询传感器
- richTextBox_SensorParam.Clear();
- textBox_FacModeSensorADC0.Text = "";
- textBox_FacModeSensorADC1.Text = "";
- textBox_FacModeSensorADC2.Text = "";
- textBox_FacModeSensorADC3.Text = "";
- textBox_FacModeSensorADC4.Text = "";
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
- Delay_ms(100);
- //读取15次助力参数
- for (int i = 1; i <= 15; i++)
- {
- var ConfigParam = new byte[4];
- richTextBox_AssistParam.Clear();
- ConfigParam[0] = (byte)(i & 0xFF);
- ConfigParam[1] = (byte)(i >> 8);
- ConfigParam[2] = (byte)(((i >= 5) ? 5 : i) & 0xFF);
- ConfigParam[3] = (byte)(((i >= 5) ? 5 : i) >> 8);
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
- Delay_ms(200);
- AssistParams[i - 1] = richTextBox_AssistParam.Text + "\r\n";
- }
- //读取一次调试信息
- richTextBox_DebugParam.Clear();
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
- Delay_ms(100);
- //读取一次历史信息
- richTextBox_Record.Clear();
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
- Delay_ms(100);
- //读取一次电机运行信息
- var CtrlCode = new byte[2];
- CtrlCode[0] = 0x00;
- CtrlCode[1] = 0xF0;
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode)) break;
- Delay_ms(100);
- //读取一次版本信息
- textBox_Model.Text = "---";
- textBox_SN.Text = "---";
- textBox_HW.Text = "---";
- textBox_FW.Text = "---";
- textBox_OBC_ReadModel.Text = "---";
- textBox_OBC_ReadSN.Text = "---";
- textBox_OBC_ReadHW.Text = "---";
- textBox_OBC_ReadFW.Text = "---";
- textBox_FacModeName.Text = "---";
- textBox_FacModeNum.Text = "---";
- textBox_FacModeHW.Text = "---";
- textBox_FacModeFW.Text = "---";
- Class_Motor_Ver.Mode = "---";
- Class_Motor_Ver.SN = "---";
- Class_Motor_Ver.HW = "---";
- Class_Motor_Ver.FW = "---";
- Class_Motor_Ver.Special = "---";
- if (!mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null)) break;
- Delay_ms(100);
- //读取一次生产信息
- textBox_MAC.Text = "";
- textBox_MACAdd.Text = "";
- textBox_MACDate.Text = "";
- textBox_PP.Text = "";
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
- Delay_ms(100);
- //读取一次自定义信息
- textBox_User1.Text = "---";
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
- Delay_ms(100);
- textBox_User2.Text = "---";
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
- Delay_ms(100);
- textBox_User3.Text = "---";
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
- Delay_ms(100);
- //读取一次密钥
- textBox_Key.Text = "---";
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
- Delay_ms(100);
- //读取一次存储标志
- radioButton_EE_SaveYes.Checked = false;
- radioButton_EE_SaveNo.Checked = false;
- radioButton_SIP_SaveYes.Checked = false;
- radioButton_SIP_SaveNo.Checked = false;
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
- Delay_ms(100);
- //提示检查
- #if false
- timer_1s.Enabled = false;
- if (MessageBox.Show("请检查信息是否完整!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
- {
- MessageBox.Show("请检查参数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- return;
- }
- timer_1s.Enabled = true;
- Delay_ms(200);
- #endif
- //判断数据是否有效
- if ((textBox_FacModeName.Text == "---") || (textBox_FacModeNum.Text == "---"))
- {
- MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- break;
- }
- if ((textBox_FacModeName.Text == string.Empty) || (textBox_FacModeNum.Text == string.Empty))
- {
- MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- break;
- }
- //设置文件存储路径
- string Save_Path = localInfo.LocalPath + DateTime.Now.ToString("yyyy-MM-dd") + "\\"; ;
- string PD_PathName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_"); ;
- Save_Path += PD_PathName;
- if (!Directory.Exists(Save_Path))
- Directory.CreateDirectory(Save_Path);
- //保存页面
- string PIC_SaveFileName = "";
- Bitmap bit = new Bitmap(this.Width, this.Height);//实例化一个和窗体一样大的bitmap
- Graphics g = Graphics.FromImage(bit);
- g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));//保存整个窗体为图片
- PIC_SaveFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_测试页面" + ".png";
- bit.Save(PIC_SaveFileName);
- //保存数据
- string DataFileName = "";
- string FileInfo = "";
- DataFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_记录数据" + ".txt";
- FileInfo += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
- FileInfo += "\r\n";
- FileInfo += "[电机信息]\r\n";
- FileInfo += "电机型号: " + textBox_FacModeName.Text + "\r\n";
- FileInfo += "电机编号: " + textBox_FacModeNum.Text + "\r\n";
- FileInfo += "硬件版本: " + textBox_HW.Text + "\r\n";
- FileInfo += "软件版本: " + textBox_FW.Text + "\r\n";
- FileInfo += "软件标识: " + textBox_SP.Text + "\r\n";
- FileInfo += "Git信息: " + textBox_FacModeGit.Text + "\r\n";
- FileInfo += "\r\n";
- FileInfo += "[马达参数]\r\n";
- FileInfo += richTextBox_MotorParam.Text + "\r\n";
- FileInfo += "\r\n";
- FileInfo += "[整车参数]\r\n";
- FileInfo += richTextBox_BikeParam.Text + "\r\n";
- FileInfo += "\r\n";
- FileInfo += "[控制参数]\r\n";
- FileInfo += richTextBox_ControlParam.Text + "\r\n";
- FileInfo += "\r\n";
- FileInfo += "[传感器参数]\r\n";
- FileInfo += richTextBox_SensorParam.Text + "\r\n";
- FileInfo += "\r\n";
- FileInfo += "[助力参数]\r\n";
- for(int i=0;i<15;i++)
- {
- FileInfo += AssistParams[i] + "\r\n";
- }
- FileInfo += "[调试参数]\r\n";
- FileInfo += richTextBox_DebugParam.Text + "\r\n";
- FileInfo += "\r\n";
- FileInfo += "[历史信息]\r\n";
- FileInfo += richTextBox_Record.Text + "\r\n";
- FileInfo += "\r\n";
- FileInfo += "[生产信息]\r\n";
- FileInfo += "生产商: " + textBox_MAC.Text + "\r\n";
- FileInfo += "生产地: " + textBox_MACAdd.Text + "\r\n";
- FileInfo += "生产日期: " + textBox_MACDate.Text + "\r\n";
- FileInfo += "产品标识: " + textBox_PP.Text + "\r\n";
- FileInfo += "\r\n";
- FileInfo += "[自定义信息]\r\n";
- FileInfo += "自定义1: " + textBox_User1.Text + "\r\n";
- FileInfo += "自定义2: " + textBox_User2.Text + "\r\n";
- FileInfo += "自定义3: " + textBox_User3.Text + "\r\n";
- FileInfo += "\r\n";
- FileInfo += "[校验密钥]\r\n";
- FileInfo += textBox_Key.Text + "\r\n";
- FileInfo += "\r\n";
- FileInfo += "[存储标志]\r\n";
- FileInfo += "EEPROM: " + ((radioButton_EE_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
- FileInfo += "SIP: " + ((radioButton_SIP_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
- FileInfo += "\r\n";
- System.IO.File.WriteAllText(DataFileName, FileInfo);
- Delay_ms(1000);
- timer_1s.Enabled = false;
- MessageBox.Show("存储完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- timer_1s.Enabled = true;
- //数据上传
- if (myFtp.IsNetConnected == true)
- {
- string DataNow = DateTime.Now.ToString("yyyy-MM-dd");
- //检查路径
- if (myFtp.DirectoryExist("\\", toolStripTextBox_ServerPath.Text) == false)
- {
- myFtp.MakeDir(toolStripTextBox_ServerPath.Text);
- }
- if (myFtp.DirectoryExist("\\", toolStripTextBox_ServerPath.Text + "\\Samples") == false)
- {
- myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples");
- }
- if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples", DataNow) == false)
- {
- myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow);
- }
- if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\" + DataNow, PD_PathName) == false)
- {
- myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
- }
- //上传文件
- bool result1 = myFtp.UploadFile(PIC_SaveFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
- bool result2 = myFtp.UploadFile(DataFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
- if ((result1 & result2) == true)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据已上传!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- timer_1s.Enabled = true;
- }
- else
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_1s.Enabled = true;
- }
- }
- else
- {
- timer_1s.Enabled = false;
- MessageBox.Show("服务器断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_1s.Enabled = true;
- }
- Button_FacModeSaveResult.Text = "保存数据";
- return;
- } while (false);
- timer_1s.Enabled = false;
- MessageBox.Show("保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- Button_FacModeSaveResult.Text = "保存数据";
- }
- /// <summary>
- /// 工具箱页面保存
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 页面保存ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- //保存页面
- Bitmap bit = new Bitmap(this.Width, this.Height);//实例化一个和窗体一样大的bitmap
- Graphics g = Graphics.FromImage(bit);
- g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));//保存整个窗体为图片
- SaveFileDialog sf = new SaveFileDialog();
- sf.Title = "页面保存";
- sf.FileName = "MotorInfo_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".png";
- sf.Filter = "图片|*.png";
- timer_1s.Enabled = false;
- if (sf.ShowDialog() == DialogResult.OK)
- {
- bit.Save(sf.FileName);//默认保存格式为PNG,保存成jpg格式质量不是很好
- }
- timer_1s.Enabled = true;
- }
- /// <summary>
- /// 生产模式关机
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Button_FacModePowerOff_Click(object sender, EventArgs e)
- {
- var Code_Off = new byte[5];
- var Code_Reset = new byte[5];
- Code_Off[0] = (byte)'O';
- Code_Off[1] = (byte)'F';
- Code_Off[2] = (byte)'F';
- Code_Off[3] = (byte)'.';
- Code_Off[4] = (byte)'.';
- Code_Reset[0] = (byte)'R';
- Code_Reset[1] = (byte)'E';
- Code_Reset[2] = (byte)'S';
- Code_Reset[3] = (byte)'E';
- Code_Reset[4] = (byte)'T';
- timer_1s.Enabled = false;
- if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- timer_1s.Enabled = true;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
- PowerOffAckStatus = false;
- Delay_ms(250);
- int TryCnt = 3;
- while ((TryCnt--) >= 0)
- {
- if (!PowerOffAckStatus)
- {
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
- PowerOffAckStatus = false;
- Delay_ms(250);
- }
- else break;
- }
- if (PowerOffAckStatus)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("已关机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
- timer_1s.Enabled = true;
- }
- else
- {
- timer_1s.Enabled = false;
- MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- timer_1s.Enabled = true;
- }
- //仪表电源键按下
- private void button_OBC_ButtonPower_Click(object sender, EventArgs e)
- {
- var Code = new byte[2];
- Code[0] = 0;
- Code[1] = 0b00100000;
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
- }
- /// <summary>
- /// 仪表加键按下
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_ButtonAcc_Click(object sender, EventArgs e)
- {
- var Code = new byte[2];
- Code[0] = 0;
- Code[1] = 0b00010000;
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
- }
- /// <summary>
- /// 仪表减键按下
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_ButtonDec_Click(object sender, EventArgs e)
- {
- var Code = new byte[2];
- Code[0] = 0;
- Code[1] = 0b00001000;
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
- }
- /// <summary>
- /// 仪表Walk键按下
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_ButtonWalk_Click(object sender, EventArgs e)
- {
- var Code = new byte[2];
- Code[0] = 0;
- Code[1] = 0b00000100;
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
- }
- /// <summary>
- /// 仪表Light键按下
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_ButtonLight_Click(object sender, EventArgs e)
- {
- var Code = new byte[2];
- Code[0] = 0;
- Code[1] = 0b00000010;
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
- }
- /// <summary>
- /// 仪表Set键按下
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_ButtonSet_Click(object sender, EventArgs e)
- {
- var Code = new byte[2];
- Code[0] = 0;
- Code[1] = 0b00000001;
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
- }
- /// <summary>
- /// 导出电机故障日志
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ExportLog_Click(object sender, EventArgs e)
- {
- var Address = new byte[4];
- UInt32 Address_Begin;
- UInt32 Addres_End;
- string textBox_Address_Begin = textBox_LogAddrBegin.Text;
- string textBox_Address_End = textBox_LogAddrEnd.Text;
- richTextBox_Record.Clear();
- textBox_LogAddrBegin.ReadOnly = true;
- textBox_LogAddrEnd.ReadOnly = true;
- if (!mySerialProcess.mySerial.IsOpen)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- return;
- }
- if ((textBox_Address_Begin == string.Empty) || (textBox_Address_End == string.Empty))
- {
- timer_1s.Enabled = false;
- MessageBox.Show("请输入日志存储起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- return;
- }
- else
- {
- Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin, false);
- Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
- Address = mySerialProcess.HexStringToBytes(textBox_Address_End, false);
- Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
- if (Addres_End <= Address_Begin)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("结束地址应大于起始地址!", "提示");
- timer_1s.Enabled = true;
- return;
- }
- else if (((Addres_End - Address_Begin + 1) % 128) != 0) //
- {
- timer_1s.Enabled = false;
- MessageBox.Show("(结束地址 - 起始地址 + 1)应为128整数倍!", "提示");
- timer_1s.Enabled = true;
- return;
- }
- else
- {
- UInt32 ReadCount = 0;
- button_ExportLog.Text = "导出中...";
- button_ExportLog.Enabled = false;
- ReadCount = (Addres_End - Address_Begin + 1) / 128;
- for (ushort i = 0; i < ReadCount; i++)
- {
- var SendByte = new byte[8];
- UInt32 Address_Temp_Begin;
- UInt32 Address_Temp_End;
- Address_Temp_Begin = Address_Begin + 128 * (UInt32)i;
- SendByte[0] = (byte)(Address_Temp_Begin >> 24);
- SendByte[1] = (byte)(Address_Temp_Begin >> 16);
- SendByte[2] = (byte)(Address_Temp_Begin >> 8);
- SendByte[3] = (byte)(Address_Temp_Begin);
- Address_Temp_End = Address_Temp_Begin + 127;
- SendByte[4] = (byte)(Address_Temp_End >> 24);
- SendByte[5] = (byte)(Address_Temp_End >> 16);
- SendByte[6] = (byte)(Address_Temp_End >> 8);
- SendByte[7] = (byte)(Address_Temp_End);
- mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
- Delay_ms(200);//Thread.Sleep(200);
- }
- button_ExportLog.Text = "导出日志";
- button_ExportLog.Enabled = true;
- }
- }
- }
- /// <summary>
- /// 保存日志信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_SaveRecordInfo_Click(object sender, EventArgs e)
- {
- string SaveInfo = "";
- if (richTextBox_Record.Text == string.Empty)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- timer_1s.Enabled = true;
- return;
- }
- //获取保存信息
- SaveInfo += "读取时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
- SaveInfo += "电机型号:" + textBox_FacModeName.Text + "\r\n";
- SaveInfo += "电机SN:" + textBox_FacModeNum.Text + "\r\n";
- SaveInfo += "硬件版本:" + textBox_FacModeHW.Text + "\r\n";
- SaveInfo += "软件版本:" + textBox_FacModeFW.Text + "\r\n";
- SaveInfo += "\r\n";
- SaveInfo += richTextBox_Record.Text;
- //设置保存路径和文件名
- SaveFileDialog sf = new SaveFileDialog();
- sf.Title = "数据保存";
- sf.FileName = "MotorLog_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".ttlog";
- sf.FileName.Replace(" ", "");
- sf.Filter = "日志|*.ttlog";
- if (sf.ShowDialog() == DialogResult.OK)
- {
- System.IO.File.AppendAllText(sf.FileName, SaveInfo);
- }
- }
- /// <summary>
- /// 双击修改日志起始地址
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void label_LogAddrBegin_DoubleClick_1(object sender, EventArgs e)
- {
- textBox_LogAddrBegin.ReadOnly = false;
- }
- /// <summary>
- /// 双击修改日志结束地址
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void label88_DoubleClick(object sender, EventArgs e)
- {
- textBox_LogAddrEnd.ReadOnly = false;
- }
- /// <summary>
- /// 存储器自动读取选择
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void checkBox_ReadRanFlash_AutoSW_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_ReadRanFlash_AutoSW.Checked == true)
- {
- //检查串口是否打开
- if (!mySerialProcess.mySerial.IsOpen)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_1s.Enabled = true;
- checkBox_ReadRanFlash_AutoSW.Checked = false;
- return;
- }
- }
- }
- /// <summary>
- /// 系统开机按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 开机ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- byte[] Data = new byte[1];
- Data[0] = 0xF1;
- if (mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data))
- {
- 开机ToolStripMenuItem.Checked = true;
- 关机ToolStripMenuItem.Checked = false;
- }
- }
- /// <summary>
- /// 系统关机按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 关机ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- byte[] Data = new byte[1];
- Data[0] = 0xF0;
- if (mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data))
- {
- 开机ToolStripMenuItem.Checked = false;
- 关机ToolStripMenuItem.Checked = true;
- }
- }
- /// <summary>
- /// 连接开机选择
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 连接开机ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- //输入用户名
- EnterForm1.ShowDialog();
- try
- {
- if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
- {
- if ((EnterForm1.comboBox_User.Text == "工程配置") || (EnterForm1.comboBox_User.Text == "研发测试"))
- {
- 连接开机ToolStripMenuItem.Checked = !连接开机ToolStripMenuItem.Checked;
- ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- else
- {
- MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else
- {
- MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- catch (Exception)
- {
- MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- /// <summary>
- /// 断开关机选择
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 断开关机ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- //输入用户名
- EnterForm1.ShowDialog();
- try
- {
- if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
- {
- if ((EnterForm1.comboBox_User.Text == "工程配置") || (EnterForm1.comboBox_User.Text == "研发测试"))
- {
- 断开关机ToolStripMenuItem.Checked = !断开关机ToolStripMenuItem.Checked;
- ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- else
- {
- MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else
- {
- MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- catch (Exception)
- {
- MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- /// <summary>
- /// 识别通讯盒选择
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 识别通讯盒ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- //输入用户名
- EnterForm1.ShowDialog();
- try
- {
- if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
- {
- if ((EnterForm1.comboBox_User.Text == "工程配置") || (EnterForm1.comboBox_User.Text == "研发测试"))
- {
- 识别通讯盒ToolStripMenuItem.Checked = !识别通讯盒ToolStripMenuItem.Checked;
- ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- else
- {
- MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else
- {
- MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- catch (Exception)
- {
- MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- /// <summary>
- /// 将配置信息导出为cfg文件
- /// </summary>
- private void ConfigFileSave(bool DeleteFlag, string FileName)
- {
- if (DeleteFlag)
- {
- if (File.Exists(FileName))
- File.Delete(FileName);
- }
- string CfgFileInfo = "";
- CfgFileInfo += "[PortSet]" + "\r\n";
- CfgFileInfo += "PortNum:" + toolStripComboBox_ComNum.Text + "\r\n";
- CfgFileInfo += "PortBaudrate:" + toolStripComboBox_Baudrate.Text + "\r\n";
- CfgFileInfo += "AutoOn:" + 连接开机ToolStripMenuItem.Checked.ToString() + "\r\n";
- CfgFileInfo += "AutoOff:" + 断开关机ToolStripMenuItem.Checked.ToString() + "\r\n";
- CfgFileInfo += "CheckCDL:" + 识别通讯盒ToolStripMenuItem.Checked.ToString() + "\r\n";
- CfgFileInfo += "\r\n";
- CfgFileInfo += "[Option]" + "\r\n";
- CfgFileInfo += "SaveWhenWrite:" + 写入存储ToolStripMenuItem.Checked.ToString() + "\r\n";
- CfgFileInfo += "OfflineEnable:" + 允许ToolStripMenuItem.Checked + "\r\n";
- CfgFileInfo += "\r\n";
- CfgFileInfo += "[ServerSet]" + "\r\n";
- CfgFileInfo += "IPAddress:" + toolStripTextBox_ServerIP.Text + "\r\n";
- CfgFileInfo += "Port:" + toolStripTextBox_ServerPort.Text + "\r\n";
- CfgFileInfo += "User:" + toolStripTextBox_ServerUser.Text + "\r\n";
- CfgFileInfo += "Password:" + toolStripTextBox_ServerPasswd.Text + "\r\n";
- CfgFileInfo += "PathName:" + toolStripTextBox_ServerPath.Text + "\r\n";
- CfgFileInfo += "\r\n";
- CfgFileInfo += "[MacInfo]" + "\r\n";
- CfgFileInfo += "MacName:" + toolStripTextBox_MAC.Text + "\r\n";
- CfgFileInfo += "MacAddress:" + toolStripTextBoxMACAddr.Text + "\r\n";
- CfgFileInfo += "MacDate:" + toolStripTextBox_MACDate.Text + "\r\n";
- CfgFileInfo += "MacPdInfo:" + toolStripTextBox_MACPD.Text + "\r\n";
- CfgFileInfo += "\r\n";
- CfgFileInfo += "[LogAddress]" + "\r\n";
- CfgFileInfo += "BeginAddress:" + textBox_LogAddrBegin.Text + "\r\n";
- CfgFileInfo += "EndAddress:" + textBox_LogAddrEnd.Text + "\r\n";
- CfgFileInfo += "\r\n";
- CfgFileInfo += "[MotorType]" + "\r\n";
- CfgFileInfo += "MidMotor:" + 中置电机ToolStripMenuItem.Checked.ToString() + "\r\n";
- CfgFileInfo += "HubMotor:" + 轮毂电机ToolStripMenuItem.Checked.ToString() + "\r\n";
- System.IO.File.WriteAllText(FileName, CfgFileInfo);
- }
- /// <summary>
- /// 配置状态更新,点击时保存
- /// </summary>
- private void ConfigFileSave_Click(object sender, EventArgs e)
- {
- ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- /// <summary>
- /// 文本框修改结束,回车保存
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ConfigFileSave_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- }
- /// <summary>
- /// 允许离线使用
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 允许ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- //输入用户名
- EnterForm1.ShowDialog();
- try
- {
- if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
- {
- if ((EnterForm1.comboBox_User.Text == "工程配置") || (EnterForm1.comboBox_User.Text == "研发测试"))
- {
- 允许ToolStripMenuItem.Checked = true;
- 不允许ToolStripMenuItem.Checked = false;
- ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- else
- {
- MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- 允许ToolStripMenuItem.Checked = false;
- 不允许ToolStripMenuItem.Checked = true;
- }
- }
- else
- {
- MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- 允许ToolStripMenuItem.Checked = false;
- 不允许ToolStripMenuItem.Checked = true;
- }
- }
- catch (Exception)
- {
- MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- 允许ToolStripMenuItem.Checked = false;
- 不允许ToolStripMenuItem.Checked = true;
- }
- }
- /// <summary>
- /// 不允许离线使用
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 不允许ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- 允许ToolStripMenuItem.Checked = false;
- 不允许ToolStripMenuItem.Checked = true;
- ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- /// <summary>
- /// 弹出扫码按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ScanCode_Click(object sender, EventArgs e)
- {
- Scan scan_form = new Scan();
- scan_form.ShowDialog();
- do
- {
- if (scan_form.textBox_Code.Text == string.Empty)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_1s.Enabled = true;
- break;
- }
- string ScanInfo = scan_form.textBox_Code.Text;
- string regexInfo = "";
- string[] InfoList = { "" };
- if (中置电机ToolStripMenuItem.Checked == true)
- {
- regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
- InfoList = Regex.Split(ScanInfo, regexInfo, RegexOptions.IgnoreCase);
- }
- else if (轮毂电机ToolStripMenuItem.Checked == true)
- {
- InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
- string Model = InfoList[0];
- string Spec = InfoList[1];
- string Sn = InfoList[2];
- InfoList[0] = Model.Replace("-", "").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
- InfoList[1] = Sn;
- }
- if (InfoList.Length >= 2)
- {
- //写入型号
- textBox_FacModeName.Text = InfoList[0];
- string Mode = textBox_FacModeName.Text;
- var ModeArray = new byte[16];
- for (ushort i = 0; i < Mode.Length; i++)
- {
- ModeArray[i] = (byte)Mode[i];
- }
- if (Mode.Length < 16)
- {
- ModeArray[Mode.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
- {
- ModeArray[Mode.Length + 1 + i] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
- //写入SN
- textBox_FacModeNum.Text = InfoList[1];
- string SN = textBox_FacModeNum.Text;
- var SNArray = new byte[16];
- for (ushort i = 0; i < SN.Length; i++)
- {
- SNArray[i] = (byte)SN[i];
- }
- if (SN.Length < 16)
- {
- SNArray[SN.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - SN.Length - 1; i++)
- {
- SNArray[SN.Length + 1 + i] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
- }
- else
- {
- timer_1s.Enabled = false;
- MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_1s.Enabled = true;
- break;
- }
- } while (false);
- scan_form.Dispose();
- }
- private void 服务器配置ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- //输入用户名
- EnterForm1.ShowDialog();
- try
- {
- if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
- {
- if ((EnterForm1.comboBox_User.Text == "工程配置") || (EnterForm1.comboBox_User.Text == "研发测试"))
- {
- IP地址ToolStripMenuItem.Visible = true;
- 端口ToolStripMenuItem.Visible = true;
- 用户名ToolStripMenuItem.Visible = true;
- 密码ToolStripMenuItem.Visible = true;
- 存储路径ToolStripMenuItem.Visible = true;
- }
- else
- {
- MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- IP地址ToolStripMenuItem.Visible = false;
- 端口ToolStripMenuItem.Visible = false;
- 用户名ToolStripMenuItem.Visible = false;
- 密码ToolStripMenuItem.Visible = false;
- 存储路径ToolStripMenuItem.Visible = false;
- }
- }
- else
- {
- MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- IP地址ToolStripMenuItem.Visible = false;
- 端口ToolStripMenuItem.Visible = false;
- 用户名ToolStripMenuItem.Visible = false;
- 密码ToolStripMenuItem.Visible = false;
- 存储路径ToolStripMenuItem.Visible = false;
- }
- }
- catch (Exception)
- {
- MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- IP地址ToolStripMenuItem.Visible = false;
- 端口ToolStripMenuItem.Visible = false;
- 用户名ToolStripMenuItem.Visible = false;
- 密码ToolStripMenuItem.Visible = false;
- 存储路径ToolStripMenuItem.Visible = false;
- }
- }
- private void 生产信息ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- //输入用户名
- EnterForm1.ShowDialog();
- try
- {
- if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
- {
- if ((EnterForm1.comboBox_User.Text == "工程配置") || (EnterForm1.comboBox_User.Text == "研发测试"))
- {
- 生产商ToolStripMenuItem.Visible = true;
- 生产地ToolStripMenuItem.Visible = true;
- 生产日期ToolStripMenuItem.Visible = true;
- 产品标识ToolStripMenuItem.Visible = true;
- }
- else
- {
- MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- 生产商ToolStripMenuItem.Visible = false;
- 生产地ToolStripMenuItem.Visible = false;
- 生产日期ToolStripMenuItem.Visible = false;
- 产品标识ToolStripMenuItem.Visible = false;
- }
- }
- else
- {
- MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- 生产商ToolStripMenuItem.Visible = false;
- 生产地ToolStripMenuItem.Visible = false;
- 生产日期ToolStripMenuItem.Visible = false;
- 产品标识ToolStripMenuItem.Visible = false;
- }
- }
- catch (Exception)
- {
- MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- 生产商ToolStripMenuItem.Visible = false;
- 生产地ToolStripMenuItem.Visible = false;
- 生产日期ToolStripMenuItem.Visible = false;
- 产品标识ToolStripMenuItem.Visible = false;
- }
- }
- /// <summary>
- /// 切换电机类型
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 中置电机ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- 中置电机ToolStripMenuItem.Checked = true;
- 轮毂电机ToolStripMenuItem.Checked = false;
- toolStripTextBox_MACPD.Text = "MM_MC1";
- toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
- ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- /// <summary>
- /// 切换电机类型
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 轮毂电机ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- 中置电机ToolStripMenuItem.Checked = false;
- 轮毂电机ToolStripMenuItem.Checked = true;
- toolStripTextBox_MACPD.Text = "GF_250_1";
- toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
- ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- /// <summary>
- /// 获取配置文件日期
- /// </summary>
- /// <param name="DisAll"></param>
- private void GetDateList(bool DisAll)
- {
- string[] DateList = { "" };
- //从服务器更新日期列表
- DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
- comboBox_FacModeCfgDate.Items.Clear();
- comboBox_CheckModeCfgDate.Items.Clear();
- //日期列表加载
- if (DisAll == true)
- {
- comboBox_FacModeCfgDate.Items.Add("显示近期");
- comboBox_CheckModeCfgDate.Items.Add("显示近期");
- comboBox_FacModeCfgDate.Items.Add("---");
- comboBox_CheckModeCfgDate.Items.Add("---");
- foreach (var file in DateList)
- {
- comboBox_FacModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
- comboBox_CheckModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
- }
- }
- else
- {
- if (DateList.Length > 10)
- {
- comboBox_FacModeCfgDate.Items.Add("显示全部");
- comboBox_CheckModeCfgDate.Items.Add("显示全部");
- comboBox_FacModeCfgDate.Items.Add("---");
- comboBox_CheckModeCfgDate.Items.Add("---");
- }
- for (int i = (DateList.Length > 10) ? (DateList.Length - 10) : 0; i < DateList.Length; i++)//显示最近10个日期
- {
- comboBox_FacModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
- comboBox_CheckModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
- }
- }
- }
- /// <summary>
- /// 获取配置文件列表
- /// </summary>
- /// <param name="date"></param>
- private void GetFileListFrom(string date)
- {
- string[] FileList = { "" };
- //从服务器更新文件列表
- FileList = myFtp.GetFileNameList(toolStripTextBox_ServerPath.Text + "/cfg/" + date);
- comboBox_CheckModeCfgFile.Items.Clear();
- comboBox_FacModeCfgFile.Items.Clear();
- foreach (var file in FileList)
- {
- if (file.Contains(".ttcfg"))
- {
- comboBox_CheckModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
- comboBox_FacModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
- }
- }
- }
- /// <summary>
- /// 检验模式选择文件日期
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void comboBox_CheckModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
- {
- if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示全部")
- {
- GetDateList(true);
- }
- else if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示近期")
- {
- GetDateList(false);
- }
- else
- {
- comboBox_CheckModeCfgFile.Text = "";
- GetFileListFrom(comboBox_CheckModeCfgDate.SelectedItem.ToString());
- }
- }
- /// <summary>
- /// 配置模式选择文件日期
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void comboBox_FacModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
- {
- if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示全部")
- {
- GetDateList(true);
- }
- else if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示近期")
- {
- GetDateList(false);
- }
- else
- {
- comboBox_FacModeCfgFile.Text = "";
- GetFileListFrom(comboBox_FacModeCfgDate.SelectedItem.ToString());
- }
- }
- /// <summary>
- /// 选中量产模式
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void tabControl1_Selected(object sender, TabControlEventArgs e)
- {
- //更新生产配置文件目录
- GetDateList(false);
- }
- /// <summary>
- /// 量产测试结束
- /// </summary>
- /// <param name=""></param>
- private void FacMode_Stop(bool OK_Flag)
- {
- //打开开始按钮
- button__FacMode_Start.Enabled = true;
- //系统关机
- var Code = new byte[32];//发送的指令数据
- Code[0] = 0xF0;
- mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
- //路径设置
- string LocalSavePath = "";
- string ServerSavePath = "";
- if (OK_Flag)
- {
- LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "OK\\";
- ServerSavePath = toolStripTextBox_ServerPath + "/funcTest/OK/";
- }
- else
- {
- LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "FAIL\\";
- ServerSavePath = toolStripTextBox_ServerPath + "/funcTest/FAIL/";
- }
- if (Directory.Exists(LocalSavePath) == false)
- {
- Directory.CreateDirectory(LocalSavePath);
- }
- //保存和上传
- string LogSavePath = "";
- string LogSaveFileName = "";
- string ProductInfo = textBox_FacModeScan.Text;
- LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
- if (Directory.Exists(LogSavePath) == false)
- {
- Directory.CreateDirectory(LogSavePath);
- }
- //测试页面
- Bitmap bit = new Bitmap(this.Width, this.Height);//实例化一个和窗体一样大的bitmap
- Graphics g = Graphics.FromImage(bit);
- g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));//保存整个窗体为图片
- LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
- bit.Save(LogSaveFileName);
- //上传测试页面到服务器
- if (myFtp.IsNetConnected == true)
- {
- string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
- if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
- {
- myFtp.MakeDir(ServerSavePath + DateNow);
- }
- if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
- {
- myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
- }
- bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
- if (result == true)
- richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
- }
- //测试记录
- LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
- string file_str = "";
- file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
- file_str += "检验记录:\r\n" + richTextBox_FacModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
- file_str += "检验结果:\r\n" + label_FacModeResult.Text + "\r\n\r\n";
- System.IO.File.WriteAllText(LogSaveFileName, file_str);
- //上传测试记录到服务器
- if (myFtp.IsNetConnected == true)
- {
- string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
- if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
- {
- myFtp.MakeDir(ServerSavePath + DateNow);
- }
- if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
- {
- myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
- }
- bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
- if (result == true)
- richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
- }
- }
- /// <summary>
- /// 量产测试开始
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button__FacMode_Start_Click(object sender, EventArgs e)
- {
- if (!mySerialProcess.mySerial.IsOpen)
- {
- MessageBox.Show("请检查串口连接!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
-
- TestStart();
- }
- /// <summary>
- /// 测试子函数
- /// </summary>
- private void TestStart()
- {
- //初始化标签
- FacModelLabelInit();
- richTextBox_FacModeLog.Clear();
- //按钮禁止操作
- button__FacMode_Start.Enabled = false;
- //记录配置文件
- richTextBox_FacModeLog.AppendText("配置文件:" + comboBox_FacModeCfgDate.Text + " / " + comboBox_FacModeCfgFile.Text + "\r\n");
- //检查打标信息格式
- label_FacModeStatus.Text = "检查扫码信息";
- Delay_ms(500);
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
- if (textBox_FacModeScan.Text == string.Empty)
- {
- MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- try
- {
- if (!textBox_FacModeScan.Text.Contains(" "))
- {
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "标签格式错误";
- button__FacMode_Start.Enabled = true;
- return;
- }
- }
- catch (System.Exception)
- {
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "标签格式错误";
- button__FacMode_Start.Enabled = true;
- return;
- }
- //流水号计数
- //...
- //创建线程,执行测试任务
- Thread th = new Thread(FacModeTest_Task);
- th.Start();
- }
- /// <summary>
- /// 执行一次测试任务
- /// </summary>
- private void FacModeTest_Task()
- {
- //开始测试
- richTextBox_FacModeLog.AppendText("产品标签:" + textBox_FacModeScan.Text + "\r\n");
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
- //变量定义
- var Code = new byte[255];//发送的指令数据
- ushort DataTemp;
- short DataTemp_Int16;
- string ResultPathName = "";
-
- label_FacModeStatus.Text = "开始测试";
- Delay_ms(500);
- label_FacModeStatus.Text = "系统开机";
- //系统开机,确保测试前先关机,发送关机指令再发送开机指令
- BootInfo = "";
- Code[0] = 0xF0;
- mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
- Delay_ms(1500);
- Code[0] = 0xF1;
- mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2); //1s
- //检查BOOT版本
- if (BootInfo != string.Empty)
- {
- label_FacModeBootVer.BackColor = Color.Green;
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
- Delay_ms(500);
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- //系统清除
- if (checkBox_FacModeSysClear.Checked)
- {
- do
- {
- //发送系统清除指令
- label_FacModeStatus.Text = "系统清除";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除" + "\r\n");
- Code[0] = (byte)'C';
- Code[1] = (byte)'L';
- Code[2] = (byte)'E';
- Code[3] = (byte)'A';
- Code[4] = (byte)'R';
-
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
- WriteACK = false;
- WriteCnt = 0;
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 6); //3s
- //等待系统清除完成指令
- if (WriteACK == true)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
- label_FacModeSysClear.BackColor = Color.Green;
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除失败" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- //系统重新开机
- label_FacModeStatus.Text = "重新开机";
- BootInfo = "";
- Code[0] = 0xF1;
- mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 4); //2s
- //获取Boot版本信息
- if (BootInfo != string.Empty)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机成功" + "\r\n");
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机失败" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- } while (false);
- }
- else
- {
- label_FacModeSysClear.BackColor = Color.Yellow;
- label_FacModeStatus.Text = "跳过系统清除!";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过系统清除" + "\r\n");
- Delay_ms(500);
- }
- //检查是否有故障
- if (textBox_ErrorCode.Text.Contains("H"))
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "故障码:" + textBox_ErrorCode.Text + "\r\n");
- label_FacModeStatus.Text = "电机存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- //参数写入
- if (checkBox_FacModeCfgWrite.Checked)
- {
- label_FacModeStatus.Text = "参数写入";
- //写入产品型号和SN
- do
- {
- //根据扫码信息获取型号和SN
- string ScanInfo = textBox_FacModeScan.Text;
- string regexInfo = "";
- string[] InfoList = { "" };
- try
- {
- if (中置电机ToolStripMenuItem.Checked == true)
- {
- regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
- InfoList = Regex.Split(ScanInfo, regexInfo, RegexOptions.IgnoreCase);
- }
- else if (轮毂电机ToolStripMenuItem.Checked == true)
- {
- InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
- string Model = InfoList[0];
- string Spec = InfoList[1];
- string Sn = InfoList[2];
- InfoList[0] = Model.Replace("-", "").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
- InfoList[1] = Sn;
- }
- }
- catch
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + BootInfo + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "标签格式错误";
- return;
- }
-
- if (InfoList.Length >= 2)
- {
- //检查配置文件是否与打标信息一致
- //...
- //写入型号
- label_FacModeStatus.Text = "写入型号";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号" + "\r\n");
- textBox_FacModeName.Text = InfoList[0];
- string Mode = textBox_FacModeName.Text;
- var ModeArray = new byte[16];
- for (ushort i = 0; i < Mode.Length; i++)
- {
- ModeArray[i] = (byte)Mode[i];
- }
- if (Mode.Length < 16)
- {
- ModeArray[Mode.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
- {
- ModeArray[Mode.Length + 1 + i] = 0x20;
- }
- }
-
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
- WriteACK = false;
- WriteCnt = 0;
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2); //1s
- if (WriteACK == true)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入失败" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- //写入SN
- label_FacModeStatus.Text = "写入SN";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN" + "\r\n");
- textBox_FacModeNum.Text = InfoList[1];
- string SN = textBox_FacModeNum.Text;
- var SNArray = new byte[16];
- for (ushort i = 0; i < SN.Length; i++)
- {
- SNArray[i] = (byte)SN[i];
- }
- if (SN.Length < 16)
- {
- SNArray[SN.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - SN.Length - 1; i++)
- {
- SNArray[SN.Length + 1 + i] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
- WriteACK = false;
- WriteCnt = 0;
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2); //1s
- if (WriteACK == true)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入失败" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- }
- else
- {
- MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- } while (false);
- //写入配置文件
- do
- {
- label_FacModeStatus.Text = "写入配置文件";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
- //配置文件
- List<byte[]> CmdList = new List<byte[]>();
- //从服务器下载文件
- string SelectFile = "";
- SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "/" + comboBox_FacModeCfgFile.SelectedItem.ToString();
- if (File.Exists(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
- {
- File.Delete(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
- }
- myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
- //打开文件
- StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
- CmdList.Clear();
- while (streamReader.Peek() != -1)
- {
- string fileLineInfo = streamReader.ReadLine();
- if (fileLineInfo.IndexOf("[") != -1)
- {
- continue;
- }
- CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
- }
- streamReader.Close();
- int CmdNum = CmdList.Count(); //指令个数
- Delay_ms(500);
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "开始写入" + "\r\n");
- Delay_ms(500);
- //开始写入
- WriteCnt = 0;
- for (int i = 0; i < CmdList.Count; i++)
- {
- mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
- Thread.Sleep(200);
- }
- //判断写入是否完整
- if (CmdNum == WriteCnt)
- {
- label_FacMode_CfgWrite.BackColor = Color.Green;
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入成功" + "\r\n");
- Delay_ms(500);
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入失败" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- } while (false);
- }
- else
- {
- label_FacMode_CfgWrite.BackColor = Color.Yellow;
- label_FacModeStatus.Text = "跳过参数写入!";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数写入" + "\r\n");
- Delay_ms(500);
- }
- //BMS通讯
- if (checkBox_FacModeBMS.Checked)
- {
- if (label_FacModeBMS.BackColor == Color.Red)
- {
- label_FacModeStatus.Text = "BMS通讯异常!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- }
- else
- {
- label_FacModeBMS.BackColor = Color.Yellow;
- label_FacModeStatus.Text = "跳过BMS通讯检测!";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过BMS通讯检测" + "\r\n");
- Delay_ms(500);
- }
- //基础功能检测
- if (checkBox_FacBaseFucTest.Checked)
- {
- label_FacModeStatus.Text = "基础功能检测";
- //发送指令进入配置模式
- do
- {
- Code[0] = 0x01;
- mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
- WriteACK = false;
- WriteCnt = 0;
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2); //1s
- if (textBox_RunInfo_Vol.Text != "---")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- } while (false);
- //发送指令启动电机
- do
- {
- //发送指令读取调试信息
- richTextBox_DebugParam.Clear();
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
- WriteACK = false;
- WriteCnt = 0;
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2); //1s
- //获取调试信息
- string DebugDefaultInfo = "";
- if (richTextBox_DebugParam.Text == string.Empty)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- else
- {
- DebugDefaultInfo = richTextBox_DebugParam.Text;
- }
- //设置模式
- string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
- strDataTemp[0] = "整体运行模式=3";
- //发送数据
- Code[0] = 0;
- Code[1] = 0;
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
- Code[2 * i + 2] = (byte)uwDataTemp;
- Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
- label_FacModeStatus.Text = "启动电机";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "启动电机" + "\r\n");
- //设置转速100%
- var Data = new byte[1];
- Data[0] = (byte)100;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
- Delay_ms(3000);
- } while (false);
- //判断车速
- if (Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) != 0)
- {
- label_FacModeSpeed.BackColor = Color.Green;
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器正常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器异常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- //判断电压
- if (((Convert.ToInt32(textBox_RunInfo_Vol.Text.Split(' ')[0]) > 35000) || (Convert.ToInt32(textBox_RunInfo_Vol.Text.Split(' ')[0]) < 37000)) ||
- ((Convert.ToInt32(textBox_RunInfo_Vol.Text.Split(' ')[0]) > 47000) || (Convert.ToInt32(textBox_RunInfo_Vol.Text.Split(' ')[0]) < 49000)))
- {
- label_FacModeVolTest.BackColor = Color.Green;
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量正常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量异常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- //判断电流
- if ((Convert.ToInt32(textBox_RunInfo_Current.Text.Split(' ')[0]) > 0) && (Convert.ToInt32(textBox_RunInfo_Current.Text.Split(' ')[0]) < 3000))
- {
- label_FacModeCurrentTest.BackColor = Color.Green;
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量正常" + " " + textBox_RunInfo_Current.Text + "\r\n");
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量异常" + " " + textBox_RunInfo_Current.Text + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- //判断温度
- if (((Convert.ToInt32(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) > -20) && (Convert.ToInt32(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) < 100)) &&
- ((Convert.ToInt32(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) > -20) && (Convert.ToInt32(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) < 100)) &&
- ((Convert.ToInt32(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) > -20) && (Convert.ToInt32(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) < 100)))
- {
- label_FacModeNTC.BackColor = Color.Green;
- 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");
- }
- else
- {
- 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");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- //判断转速
- if ((Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) > 200) && (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 6000))
- {
- label_FacModeMotorSpeed.BackColor = Color.Green;
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速正常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速异常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- //发送指令停止电机
- do
- {
- //设置转速0%
- var Data = new byte[1];
- Data[0] = (byte)0;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
- //获取调试信息
- string DebugDefaultInfo = "";
- if (richTextBox_DebugParam.Text == string.Empty)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- else
- {
- DebugDefaultInfo = richTextBox_DebugParam.Text;
- }
- //设置模式
- string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
- //发送数据
- Code[0] = 0;
- Code[1] = 0;
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
- Code[2 * i + 2] = (byte)uwDataTemp;
- Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
- label_FacModeStatus.Text = "停止电机";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "停止电机" + "\r\n");
- Delay_ms(2000);
- } while (false);
- }
- else
- {
- label_FacModeSpeed.BackColor = Color.Yellow;
- label_FacModeVolTest.BackColor = Color.Yellow;
- label_FacModeCurrentTest.BackColor = Color.Yellow;
- label_FacModeNTC.BackColor = Color.Yellow;
- label_FacModeMotorSpeed.BackColor = Color.Yellow;
- label_FacModeStatus.Text = "跳过基础功能检测!";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过基础功能检测" + "\r\n");
- Delay_ms(500);
- }
- //力矩检测
- if (checkBox_FacTor.Checked)
- {
- label_FacModeStatus.Text = "力矩传感器检测!";
- //发送指令进入配置模式
- do
- {
- if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
- {
- break;
- }
- Code[0] = 0x01;
- mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
- WriteACK = false;
- WriteCnt = 0;
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (textBox_RunInfo_Vol.Text != "---")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
- Delay_ms(500);
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- } while (false);
- ushort Max = 0, Torque = 0;
- //提示输入力矩信号
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟力矩信号输入" + "\r\n");
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 20) //10s
- {
- //获取力矩值
- Torque = (ushort)Convert.ToInt16(textBox_RunInfo_Torque.Text.Split(' ')[0]);
- if (Torque > Max)
- Max = Torque;
- if ((Max >= 70) && (Max <= 85) && (ACK_WaitCnt >= 6))
- {
- label_FacModeTq.BackColor = Color.Green;
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器正常" + " " + textBox_RunInfo_Torque.Text + "\r\n");
- break;
- }
- }
- if (ACK_WaitCnt >= 20)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器异常" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- }
- else
- {
- label_FacModeTq.BackColor = Color.Yellow;
- label_FacModeCad.BackColor = Color.Yellow;
- label_FacModeStatus.Text = "跳过力矩检测!";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过力矩检测" + "\r\n");
- Delay_ms(500);
- }
- //踏频检测
- if (checkBox_FacCad.Checked)
- {
- label_FacModeStatus.Text = "踏频传感器检测!";
- //发送指令进入配置模式
- do
- {
- if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
- {
- break;
- }
- Code[0] = 0x01;
- mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
- WriteACK = false;
- WriteCnt = 0;
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (textBox_RunInfo_Vol.Text != "---")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
- Delay_ms(500);
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- } while (false);
- ushort Max = 0, Cadence = 0;
- //提示输入踏频信号
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟踏频信号输入" + "\r\n");
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 20) //10s
- {
- //获取踏频
- Cadence = (ushort)Convert.ToInt16(textBox_RunInfo_Cadence.Text.Split(' ')[0]);
- if (Cadence > Max)
- Max = Cadence;
- if ((Max >= 35) && (Max <= 45) && (ACK_WaitCnt >= 6))
- {
- label_FacModeCad.BackColor = Color.Green;
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器正常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
- break;
- }
- }
- if (ACK_WaitCnt >= 20)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器异常" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- }
- else
- {
- label_FacModeTq.BackColor = Color.Yellow;
- label_FacModeCad.BackColor = Color.Yellow;
- label_FacModeStatus.Text = "跳过踏频检测!";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过踏频检测" + "\r\n");
- Delay_ms(500);
- }
- //转把检测
- if (checkBox_FacThrrotleTest.Checked)
- {
- label_FacModeStatus.Text = "转把检测";
- //发送指令进入配置模式
- do
- {
- if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
- {
- break;
- }
- Code[0] = 0x01;
- mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
- WriteACK = false;
- WriteCnt = 0;
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (textBox_RunInfo_Vol.Text != "---")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
- Delay_ms(500);
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- } while (false);
- //进入TURBO档
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把检测,发送指令进入TURBO" + "\r\n");
- Code[0] = 0x04;
- Code[1] = 0xF0;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
- WriteACK = false;
- WriteCnt = 0;
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (textBox_RunInfo_GearSt.Text != "TURBO")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO异常" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO,10s内转动转把" + "\r\n");
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 20)
- {
- if ((Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) > 500) && (ACK_WaitCnt >= 10))
- {
- label_FacModeGas.BackColor = Color.Green;
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能正常,松开转把" + "\r\n");
- break;
- }
- }
- if (ACK_WaitCnt >= 20) //转把超时
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能异常,松开转把" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- }
- else
- {
- label_FacModeGas.BackColor = Color.Yellow;
- label_FacModeStatus.Text = "跳过转把检测!";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过转把检测" + "\r\n");
- Delay_ms(500);
- }
- //刹车检测
- if (checkBox_FacBreakTest.Checked)
- {
- label_FacModeStatus.Text = "刹把检测";
- //发送指令进入配置模式
- do
- {
- if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
- {
- break;
- }
- Code[0] = 0x01;
- mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
- WriteACK = false;
- WriteCnt = 0;
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (textBox_RunInfo_Vol.Text != "---")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
- Delay_ms(500);
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- } while (false);
- //启动电机进入WALK模式
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把检测,进入WALK" + "\r\n");
- Code[0] = 0x22;
- Code[1] = 0xF0;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
- WriteACK = false;
- WriteCnt = 0;
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (textBox_RunInfo_GearSt.Text != "WALK")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,10s内操作剎把" + "\r\n");
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 20)
- {
- if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 100)
- {
- label_FacModeBreak.BackColor = Color.Green;
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把功能正常,松开剎把" + "\r\n");
- break;
- }
- }
- if (ACK_WaitCnt >= 20) //剎把超时
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把功能异常,松开剎把" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- //停止电机
- Code[0] = 0x00;
- Code[1] = 0xF0;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
- WriteACK = false;
- WriteCnt = 0;
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (textBox_RunInfo_GearSt.Text != "OFF")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK" + "\r\n");
- Delay_ms(500);
- }
- else
- {
- label_FacModeBreak.BackColor = Color.Yellow;
- label_FacModeStatus.Text = "跳过刹车检测!";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过刹车检测" + "\r\n");
- Delay_ms(500);
- }
- //前后灯检测
- if (checkBox_FacLightTest.Checked)
- {
- //前后灯检测
- label_FacModeStatus.Text = "前后灯检测";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开灯指令" + "\r\n");
- //发送指令打开车灯
- Code[0] = 0x00;
- Code[1] = 0xF1;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
- WriteACK = false;
- WriteCnt = 0;
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (textBox_RunInfo_LightSwitch.Text != "ON")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令发送异常" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已打开前后灯" + "\r\n");
- Delay_ms(500);
- //提示检查灯压是否正确
- if (MessageBox.Show("前后灯是否正常?", "前后灯判断", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- label_FacModeLightF.BackColor = Color.Green;
- label_FacModeLightB.BackColor = Color.Green;
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯正常" + "\r\n");
- Delay_ms(500);
- }
- else
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯异常" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- //发送指令关闭车灯
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关灯指令" + "\r\n");
- Code[0] = 0x00;
- Code[1] = 0xF0;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
- WriteACK = false;
- WriteCnt = 0;
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (textBox_RunInfo_LightSwitch.Text != "OFF")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令发送异常" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已关闭前后灯" + "\r\n");
- Delay_ms(500);
- }
- else
- {
- label_FacModeLightF.BackColor = Color.Yellow;
- label_FacModeLightB.BackColor = Color.Yellow;
- label_FacModeStatus.Text = "跳过前后灯检测!";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过前后灯检测" + "\r\n");
- Delay_ms(500);
- }
- //软件版本检测
- do
- {
- label_FacModeStatus.Text = "软件版本确认";
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
- //发送指令读取版本
- Class_Motor_Ver.Mode = "---";
- Class_Motor_Ver.SN = "---";
- Class_Motor_Ver.HW = "---";
- Class_Motor_Ver.FW = "---";
- Class_Motor_Ver.Special = "---";
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (Class_Motor_Ver.Mode == "---")
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息失败" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
- richTextBox_FacModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
- richTextBox_FacModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
- richTextBox_FacModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
- richTextBox_FacModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
- richTextBox_FacModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
- //判断版本是否正确
- string VerCheck = comboBox_FacModeCfgFile.Text.Split('_')[3] + "_" + comboBox_FacModeCfgFile.Text.Split('_')[4];
- string VerRead = "";
- try
- {
- VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
- }
- catch (System.Exception)
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
- {
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- FacMode_Stop(false);
- return;
- }
- label_FacModeFWVersion.BackColor = Color.Green;
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
- Delay_ms(500);
- } while (false);
- //测试合格
- richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
- label_FacModeStatus.Text = "测试结束!";
- label_FacModeResult.BackColor = Color.Green;
- label_FacModeResult.Text = "测试合格";
- Delay_ms(500);
- //存储并上传
- FacMode_Stop(true);
- return;
- }
- private void FacModelLabelInit()
- {
- //测试状态标签
- label_FacModeResult.BackColor = Color.Yellow;
- label_FacModeResult.Text = "测试中";
- //测试过程标签
- label_FacModeStatus.Text = "测试就绪";
- //测试结果标签
- foreach (Control c in groupBox28.Controls)
- {
- if (c is Label)
- {
- if (c.Text == string.Empty)
- c.BackColor = Color.Red;
- }
- }
- }
- private void comboBox_CheckModeCfgDate_Click(object sender, EventArgs e)
- {
- //更新生产配置文件目录
- GetDateList(false);
- }
- private void comboBox_FacModeCfgDate_Click(object sender, EventArgs e)
- {
- //更新生产配置文件目录
- GetDateList(false);
- }
- private void richTextBox_FacModeLog_TextChanged(object sender, EventArgs e)
- {
- richTextBox_FacModeLog.SelectionStart = richTextBox_FacModeLog.Text.Length;
- richTextBox_FacModeLog.ScrollToCaret();
- }
- /// <summary>
- /// 参数检验测试停止
- /// </summary>
- /// <param name="OK_Flag"></param>
- private void CheckMode_Stop(bool OK_Flag)
- {
- //打开开始按钮
- button_CheckModeStart.Enabled = true;
- //系统关机
- var Code = new byte[32];//发送的指令数据
- Code[0] = 0xF0;
- mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
- //路径设置
- string LocalSavePath = "";
- string ServerSavePath = "";
- if (OK_Flag)
- {
- LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "OK\\";
- ServerSavePath = toolStripTextBox_ServerPath + "/qcTest/OK/";
- }
- else
- {
- LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "FAIL\\";
- ServerSavePath = toolStripTextBox_ServerPath + "/qcTest/FAIL/";
- }
- if (Directory.Exists(LocalSavePath) == false)
- {
- Directory.CreateDirectory(LocalSavePath);
- }
- //保存和上传
- string LogSavePath = "";
- string LogSaveFileName = "";
- string ProductInfo = textBox_CheckModeScan.Text;
- LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
- if (Directory.Exists(LogSavePath) == false)
- {
- Directory.CreateDirectory(LogSavePath);
- }
- //测试页面
- Bitmap bit = new Bitmap(this.Width, this.Height);//实例化一个和窗体一样大的bitmap
- Graphics g = Graphics.FromImage(bit);
- g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));//保存整个窗体为图片
- LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
- bit.Save(LogSaveFileName);
- //上传测试页面到服务器
- if (myFtp.IsNetConnected == true)
- {
- string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
- if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
- {
- myFtp.MakeDir(ServerSavePath + DateNow);
- }
- if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
- {
- myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
- }
- bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
- if (result == true)
- richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
- }
- //测试记录
- LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
- string file_str = "";
- file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
- file_str += "检验记录:\r\n" + richTextBox_CheckModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
- file_str += "检验结果:\r\n" + label_CheckModeResult.Text + "\r\n\r\n";
- System.IO.File.WriteAllText(LogSaveFileName, file_str);
- //上传测试记录到服务器
- if (myFtp.IsNetConnected == true)
- {
- string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
- if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
- {
- myFtp.MakeDir(ServerSavePath + DateNow);
- }
- if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
- {
- myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
- }
- bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
- if (result == true)
- richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
- }
- }
- /// <summary>
- /// 参数检验开始
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_CheckModeStart_Click(object sender, EventArgs e)
- {
- if (!mySerialProcess.mySerial.IsOpen)
- {
- MessageBox.Show("请检查串口连接!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- CheckTestStart();
- }
- /// <summary>
- /// 参数检验测试子函数
- /// </summary>
- private void CheckTestStart()
- {
- //初始化标签
- CheckModeLabelInit();
- richTextBox_CheckModeLog.Clear();
- //按钮禁止操作
- button_CheckModeStart.Enabled = false;
- //记录配置文件
- richTextBox_CheckModeLog.AppendText("配置文件:" + comboBox_CheckModeCfgDate.Text + " / " + comboBox_CheckModeCfgFile.Text + "\r\n");
- //检查打标信息
- label_CheckModeStatus.Text = "检查扫码信息";
- Delay_ms(500);
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
- if (textBox_CheckModeScan.Text == string.Empty)
- {
- MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- try
- {
- if (!textBox_CheckModeScan.Text.Contains(" "))
- {
- label_CheckModeStatus.Text = "存在故障!";
- label_CheckModeResult.BackColor = Color.Red;
- label_CheckModeResult.Text = "标签格式错误";
- button_CheckModeStart.Enabled = true;
- return;
- }
- }
- catch (System.Exception)
- {
- label_CheckModeStatus.Text = "存在故障!";
- label_CheckModeResult.BackColor = Color.Red;
- label_CheckModeResult.Text = "标签格式错误";
- button_CheckModeStart.Enabled = true;
- return;
- }
- //流水号计数
- //...
- //创建线程,执行测试任务
- Thread th = new Thread(CheckModeTest_Task);
- th.Start();
- }
- /// <summary>
- /// 执行一次测试任务
- /// </summary>
- private void CheckModeTest_Task()
- {
- //开始测试
- richTextBox_CheckModeLog.AppendText("产品标签:" + textBox_CheckModeScan.Text + "\r\n");
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
- //变量定义
- var Code = new byte[255];//发送的指令数据
- ushort DataTemp;
- short DataTemp_Int16;
- string ResultPathName = "";
- label_CheckModeStatus.Text = "开始测试";
- Delay_ms(500);
- label_CheckModeStatus.Text = "系统开机";
- //系统开机,确保测试前先关机,发送关机指令再发送开机指令
- BootInfo = "";
- Code[0] = 0xF0;
- mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
- Delay_ms(1500);
- Code[0] = 0xF1;
- mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- //检查BOOT版本
- if (BootInfo != string.Empty)
- {
- label_CheckModeBoot.BackColor = Color.Green;
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
- Delay_ms(500);
- }
- else
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
- label_CheckModeStatus.Text = "存在故障!";
- label_CheckModeResult.BackColor = Color.Red;
- label_CheckModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- CheckMode_Stop(false);
- return;
- }
- //发送指令读取版本信息
- do
- {
- label_CheckModeStatus.Text = "读取版本信息";
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
- //发送指令读取版本
- Class_Motor_Ver.Mode = "---";
- Class_Motor_Ver.SN = "---";
- Class_Motor_Ver.HW = "---";
- Class_Motor_Ver.FW = "---";
- Class_Motor_Ver.Special = "---";
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (Class_Motor_Ver.Mode == "---")
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取失败" + "\r\n");
- label_CheckModeStatus.Text = "存在故障!";
- label_CheckModeResult.BackColor = Color.Red;
- label_CheckModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- CheckMode_Stop(false);
- return;
- }
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
- Delay_ms(500);
- } while (false);
- //软件版本检查
- if (checkBox_CheckModeFWVer.Checked)
- {
- richTextBox_CheckModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
- richTextBox_CheckModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
- richTextBox_CheckModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
- richTextBox_CheckModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
- richTextBox_CheckModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
- //判断版本是否正确
- string VerCheck = comboBox_CheckModeCfgFile.Text.Split('_')[3] + "_" + comboBox_CheckModeCfgFile.Text.Split('_')[4];
- string VerRead = "";
- try
- {
- VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
- }
- catch (System.Exception)
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
- label_CheckModeStatus.Text = "存在故障!";
- label_CheckModeResult.BackColor = Color.Red;
- label_CheckModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- CheckMode_Stop(false);
- return;
- }
- if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
- label_CheckModeStatus.Text = "存在故障!";
- label_CheckModeResult.BackColor = Color.Red;
- label_CheckModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- CheckMode_Stop(false);
- return;
- }
- label_CheckModeFWVer.BackColor = Color.Green;
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
- Delay_ms(500);
- }
- else
- {
- label_CheckModeFWVer.BackColor = Color.Yellow;
- label_CheckModeStatus.Text = "跳过软件版本查询";
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过软件版本查询" + "\r\n");
- Delay_ms(500);
- }
- //打标信息核对
- if (checkBox_CheckModeSN.Checked)
- {
- label_CheckModeStatus.Text = "核对打标信息";
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "核对打标信息" + "\r\n");
- //根据扫码信息获取型号和SN
- string ScanInfo = textBox_CheckModeScan.Text;
- string regexInfo = "";
- string[] InfoList = { "" };
- try
- {
- if (中置电机ToolStripMenuItem.Checked == true)
- {
- regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
- InfoList = Regex.Split(ScanInfo, regexInfo, RegexOptions.IgnoreCase);
- }
- else if (轮毂电机ToolStripMenuItem.Checked == true)
- {
- InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
- string Model = InfoList[0];
- string Spec = InfoList[1];
- string Sn = InfoList[2];
- InfoList[0] = Model.Replace("-", "").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
- InfoList[1] = Sn;
- }
- }
- catch
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
- label_FacModeStatus.Text = "存在故障!";
- label_FacModeResult.BackColor = Color.Red;
- label_FacModeResult.Text = "标签格式错误";
- Delay_ms(500);
- //存储异常并上传
- CheckMode_Stop(false);
- return;
- }
- //核对型号
- if (string.Equals(InfoList[0], Class_Motor_Ver.Mode) == false) //型号错误,直接结束
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号不一致" + "\r\n");
- label_CheckModeStatus.Text = "存在故障!";
- label_CheckModeResult.BackColor = Color.Red;
- label_CheckModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- CheckMode_Stop(false);
- return;
- }
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号一致" + "\r\n");
- Delay_ms(500);
- //核对SN
- if (string.Equals(InfoList[1], Class_Motor_Ver.SN) == false) //型号错误,直接结束
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN不一致" + "\r\n");
- label_CheckModeStatus.Text = "存在故障!";
- label_CheckModeResult.BackColor = Color.Red;
- label_CheckModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- CheckMode_Stop(false);
- return;
- }
- label_CheckModeSN.BackColor = Color.Green;
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN一致" + "\r\n");
- Delay_ms(500);
- }
- else
- {
- label_CheckModeSN.BackColor = Color.Yellow;
- label_CheckModeStatus.Text = "跳过打标信息确认";
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过打标信息确认" + "\r\n");
- Delay_ms(500);
- }
- //参数检验
- if (checkBox_CheckModeCfg.Checked)
- {
- //读取配置文件信息
- label_CheckModeStatus.Text = "参数检查";
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
- //配置文件
- List<byte[]> CmdList = new List<byte[]>();
- //从服务器下载文件
- string SelectFile = "";
- SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "/" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
- if (File.Exists(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
- {
- File.Delete(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
- }
- myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
- //打开文件
- Dictionary<string, string> ConfigCmd = new Dictionary<string, string>();//配置文件格式
- StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
- ConfigCmd.Clear();
- while (streamReader.Peek() != -1)
- {
- string fileLineInfo = streamReader.ReadLine(); //读指令名称
- if (fileLineInfo.Contains("["))
- {
- if (fileLineInfo.Contains("助力参数"))
- {
- fileLineInfo = streamReader.ReadLine();
- }
- ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
- }
- }
- streamReader.Close();
- int CmdNum = ConfigCmd.Count(); //指令个数
- Delay_ms(500);
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "\r\n");
- Delay_ms(500);
- //逐条读取比较
- try
- {
- foreach (string key in ConfigCmd.Keys)
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令:" + "\r\n");
- CmdRevStrTemp = "";
- if (key.Contains("曲线"))
- {
- byte LineNum = 0;
- var code = new byte[4];
- LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
- if (LineNum <= 5)
- {
- code[0] = (byte)(LineNum & 0xFF);
- code[1] = (byte)((LineNum >> 8) & 0xFF);
- code[2] = (byte)(LineNum & 0xFF);
- code[3] = (byte)((LineNum >> 8) & 0xFF);
- }
- else
- {
- code[0] = (byte)(LineNum & 0xFF);
- code[1] = (byte)((LineNum >> 8) & 0xFF);
- code[2] = (byte)(5 & 0xFF);
- code[3] = (byte)((5 >> 8) & 0xFF);
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
- }
- else
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
- Delay_ms(500);
- if (CmdRevStrTemp == string.Empty)
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "指令读取失败" + "\r\n");
- label_CheckModeStatus.Text = "存在故障!";
- label_CheckModeResult.BackColor = Color.Red;
- label_CheckModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- CheckMode_Stop(false);
- return;
- }
- //比较当前指令,读取的配置文件和返回数据比较
- string ParamWrite = ConfigCmd[key].Substring(24, ConfigCmd[key].Length - 40).Trim();
- string ParamRead = "";
- if (string.Compare(key, "[其它传感器参数]") == 0)
- ParamRead = CmdRevStrTemp.Substring(90, CmdRevStrTemp.Length - 90).Trim(); //该指令包含力矩参数
- else
- ParamRead = CmdRevStrTemp.Substring(6, CmdRevStrTemp.Length - 6).Trim();
- if (ParamWrite.Contains(ParamRead))
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "一致" + "\r\n");
- continue;
- }
- else
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "不一致" + "\r\n");
- label_CheckModeStatus.Text = "存在故障!";
- label_CheckModeResult.BackColor = Color.Red;
- label_CheckModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- CheckMode_Stop(false);
- return;
- }
- }
- }
- catch (System.Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("参数检验失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_1s.Enabled = true;
- ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- }
- else
- {
- label_CheckModeCfg.BackColor = Color.Yellow;
- label_CheckModeStatus.Text = "跳过参数检验";
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数检验" + "\r\n");
- Delay_ms(500);
- }
- label_CheckModeCfg.BackColor = Color.Green;
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数检验正确" + "\r\n");
- Delay_ms(500);
- //读取力矩传感器
- do
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据" + "\r\n");
- //发送指令读取力矩传感器标定数据
- CmdRevStrTemp = "";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
- ACK_WaitCnt = 0;
- while (ACK_WaitCnt <= 2) ; //1s
- if (CmdRevStrTemp == "---")
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取失败" + "\r\n");
- label_CheckModeStatus.Text = "存在故障!";
- label_CheckModeResult.BackColor = Color.Red;
- label_CheckModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- CheckMode_Stop(false);
- return;
- }
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取成功" + "\r\n");
- //取力矩传感器数据
- ushort ZeroInit, Zero1, Zero2, Zero3, ZeroNew;
- ushort MaxTorque;
- ushort K1_T, K1, K2_T, K2, K3_T, K3, K4_T, K4;
- byte[] DataArray = mySerialProcess.HexStringToBytes(CmdRevStrTemp, true);
- ZeroInit = (ushort)((DataArray[3] << 8) + DataArray[2]);
- Zero1 = (ushort)((DataArray[5] << 8) + DataArray[4]);
- Zero2 = (ushort)((DataArray[7] << 8) + DataArray[6]);
- Zero3 = (ushort)((DataArray[9] << 8) + DataArray[8]);
- ZeroNew = (ushort)((DataArray[11] << 8) + DataArray[10]);
- MaxTorque = (ushort)((DataArray[13] << 8) + DataArray[12]);
- K1_T = (ushort)((DataArray[15] << 8) + DataArray[14]);
- K1 = (ushort)((DataArray[17] << 8) + DataArray[16]);
- K2_T = (ushort)((DataArray[19] << 8) + DataArray[18]);
- K2 = (ushort)((DataArray[21] << 8) + DataArray[20]);
- K3_T = (ushort)((DataArray[23] << 8) + DataArray[22]);
- K3 = (ushort)((DataArray[25] << 8) + DataArray[24]);
- K4_T = (ushort)((DataArray[27] << 8) + DataArray[26]);
- K4 = (ushort)((DataArray[29] << 8) + DataArray[28]);
- richTextBox_CheckModeLog.AppendText("力矩传感器零点: " + ZeroInit.ToString() + "," + Zero1.ToString() + "," +
- Zero2.ToString() + "," + Zero3.ToString() + "," + ZeroNew.ToString() + "\r\n");
- richTextBox_CheckModeLog.AppendText("最大力矩: " + MaxTorque.ToString() + "\r\n");
- richTextBox_CheckModeLog.AppendText("力矩传感器标定: " + "[" + K1_T.ToString() + "," + K1.ToString() + "]" + "," +
- "[" + K2_T.ToString() + "," + K2.ToString() + "]" + "," + "[" + K3_T.ToString() + "," + K3.ToString() + "]" + "," +
- "[" + K4_T.ToString() + "," + K4.ToString() + "]" + "\r\n");
- //传感器标定检验
- if (checkBox_CheckModeTorque.Checked)
- {
- richTextBox_CheckModeLog.AppendText("力矩零点范围: " + TorqueParamsForm.Zero.Min.ToString() + " - " + TorqueParamsForm.Zero.Max.ToString() + "\r\n");
- richTextBox_CheckModeLog.AppendText("K1范围: " + TorqueParamsForm.K1.T.ToString() + "," + TorqueParamsForm.K1.Min.ToString() + " - " + TorqueParamsForm.K1.Max.ToString() + "\r\n");
- richTextBox_CheckModeLog.AppendText("K2范围: " + TorqueParamsForm.K2.T.ToString() + "," + TorqueParamsForm.K2.Min.ToString() + " - " + TorqueParamsForm.K2.Max.ToString() + "\r\n");
- richTextBox_CheckModeLog.AppendText("K3范围: " + TorqueParamsForm.K3.T.ToString() + "," + TorqueParamsForm.K3.Min.ToString() + " - " + TorqueParamsForm.K3.Max.ToString() + "\r\n");
- richTextBox_CheckModeLog.AppendText("K4范围: " + TorqueParamsForm.K4.T.ToString() + "," + TorqueParamsForm.K4.Min.ToString() + " - " + TorqueParamsForm.K4.Max.ToString() + "\r\n");
- //与设置值比较
- if ((ZeroInit <= TorqueParamsForm.Zero.Max) && (ZeroInit >= TorqueParamsForm.Zero.Min)
- && (K1_T == TorqueParamsForm.K1.T) && (K1 <= TorqueParamsForm.K1.Max) && (K1 >= TorqueParamsForm.K1.Min)
- && (K2_T == TorqueParamsForm.K2.T) && (K2 <= TorqueParamsForm.K2.Max) && (K2 >= TorqueParamsForm.K2.Min)
- && (K3_T == TorqueParamsForm.K3.T) && (K3 <= TorqueParamsForm.K3.Max) && (K3 >= TorqueParamsForm.K3.Min)
- && (K4_T == TorqueParamsForm.K4.T) && (K4 <= TorqueParamsForm.K4.Max) && (K4 >= TorqueParamsForm.K4.Min)
- )
- {
- label_CheckModeTorque.BackColor = Color.Green;
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定正常" + "\r\n");
- Delay_ms(500);
- }
- else
- {
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定超范围" + "\r\n");
- label_CheckModeStatus.Text = "存在故障!";
- label_CheckModeResult.BackColor = Color.Red;
- label_CheckModeResult.Text = "测试异常";
- Delay_ms(500);
- //存储异常并上传
- CheckMode_Stop(false);
- return;
- }
- }
- else
- {
- label_CheckModeFWVer.BackColor = Color.Yellow;
- label_CheckModeStatus.Text = "跳过传感器标定检验";
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过传感器标定检验" + "\r\n");
- Delay_ms(500);
- }
- } while (false);
- //测试合格
- richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
- label_CheckModeStatus.Text = "测试结束!";
- label_CheckModeResult.BackColor = Color.Green;
- label_CheckModeResult.Text = "测试合格";
- Delay_ms(500);
- //存储并上传
- CheckMode_Stop(true);
- return;
- }
- private void CheckModeLabelInit()
- {
- //测试状态标签
- label_CheckModeResult.BackColor = Color.Yellow;
- label_CheckModeResult.Text = "测试中";
- //测试过程标签
- label_CheckModeStatus.Text = "测试就绪";
- //测试结果标签
- foreach (Control c in groupBox31.Controls)
- {
- if (c is Label)
- {
- if (c.Text == string.Empty)
- c.BackColor = Color.Red;
- }
- }
- }
- private void 调试记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- System.Diagnostics.Process.Start("explorer.exe", Directory.GetCurrentDirectory());
- }
- private void 生产记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- System.Diagnostics.Process.Start("explorer.exe", localInfo.LocalDataPath);
- }
- private void 累计运行时间ToolStripMenuItem_MouseHover(object sender, EventArgs e)
- {
- UInt32 Time = (UInt32)stopwatch.ElapsedMilliseconds / 1000;
- UInt32 hour = Time / 3600;
- UInt32 min = (Time % 3600) / 60;
- UInt32 s = (Time % 60);
- toolStripMenuItem_RunTime.Text = hour.ToString() + ":" + min.ToString("00") + ":" + s.ToString("00");
- }
- private void richTextBox_CheckModeLog_TextChanged(object sender, EventArgs e)
- {
- richTextBox_CheckModeLog.SelectionStart = richTextBox_CheckModeLog.Text.Length;
- richTextBox_CheckModeLog.ScrollToCaret();
- }
- private void 力矩传感器检验ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- EnterForm1.ShowDialog();
- try
- {
- if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
- {
- if (EnterForm1.comboBox_User.Text == "工程配置")
- {
- TorqueParamsForm.ShowDialog();
- }
- else
- {
- MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else
- {
- MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- catch (Exception)
- {
- MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- private void textBox_CheckModeScan_KeyUp(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- CheckTestStart();
- }
- private void textBox_FacModeScan_KeyUp(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- TestStart();
- }
- private void button_SpeedDec10_Click(object sender, EventArgs e)
- {
- if (numericUpDown_SpeedAdj.Value <= 10)
- numericUpDown_SpeedAdj.Value = 0;
- else
- numericUpDown_SpeedAdj.Value -= 10;
- }
- private void button_SpeedAdd10_Click(object sender, EventArgs e)
- {
- if (numericUpDown_SpeedAdj.Value >= 90)
- numericUpDown_SpeedAdj.Value = 100;
- else
- numericUpDown_SpeedAdj.Value += 10;
- }
- private void button_SpeedDec1_Click(object sender, EventArgs e)
- {
- if (numericUpDown_SpeedAdj.Value <= 1)
- numericUpDown_SpeedAdj.Value = 0;
- else
- numericUpDown_SpeedAdj.Value -= 1;
- }
- private void button_SpeedAdd1_Click(object sender, EventArgs e)
- {
- if(numericUpDown_SpeedAdj.Value >= 99)
- numericUpDown_SpeedAdj.Value = 100;
- else
- numericUpDown_SpeedAdj.Value += 1;
- }
- }
- }
|