mainForm.cs 384 KB

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