mainForm.cs 520 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945
  1. using NPOI.POIFS.Crypt.Dsig;
  2. using NPOI.SS.Formula.Functions;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.Diagnostics;
  7. using System.Diagnostics.Eventing.Reader;
  8. using System.Drawing;
  9. using System.Globalization;
  10. using System.IO;
  11. using System.IO.Ports;
  12. using System.Linq;
  13. using System.Reflection;
  14. using System.Runtime.InteropServices;
  15. using System.Runtime.InteropServices.ComTypes;
  16. using System.Text;
  17. using System.Text.RegularExpressions;
  18. using System.Threading;
  19. using System.Web;
  20. using System.Windows.Forms;
  21. using System.Xml.Linq;
  22. namespace Welling_Motor_Debug_Tool
  23. {
  24. public partial class mainForm : Form
  25. {
  26. #region 变量定义
  27. //版本号
  28. public static string Version = "2.5.1";
  29. //串口实例
  30. Serial_Process mySerialProcess = new Serial_Process();
  31. string PortNumSave = "";
  32. string PortBaudrateSave = "";
  33. //本地信息定义
  34. LocalInfo localInfo = new LocalInfo();
  35. //FTP实例
  36. ftp myFtp = new ftp();
  37. public string ServerIP = "";
  38. public string ServerPort = "";
  39. public string ServerUser = "";
  40. public string ServerPassWd = "";
  41. public bool OfflineFlag = false;
  42. //MC运行信息超时计数
  43. bool MC_RunInfo_Refresh = false;
  44. ushort MC_RunInfo_Refresh_Cnt = 0;
  45. //MC调试信息超时计数
  46. bool MC_DebugInfo_Refresh = false;
  47. ushort MC_DebugInfo_Refresh_Cnt = 0;
  48. //MC故障码超时计数
  49. bool MC_ErrorCode_Refresh = false;
  50. ushort MC_ErrorCode_Refresh_Cnt = 0;
  51. //配置参数实例
  52. Params myParams = new Params();
  53. //记录文件名称
  54. string RunInfoSaveFilename = "";
  55. //BMS运行信息超时计数
  56. bool BMS_RunInfo_Refresh = false;
  57. ushort BMS_RunInfo_Refresh_Cnt = 0;
  58. //生产模式关机指令反馈状态
  59. bool PowerOffAckStatus = false;
  60. //登录窗口
  61. public static Login EnterForm1 = new Login();
  62. //生产配置文件信息
  63. ArrayList array_CfgInfo = new ArrayList();
  64. //写入参数返回标志和计数
  65. public bool WriteACK = false;
  66. public ushort ACK_WaitCnt = 0;
  67. //写入参数返回提示标志
  68. public bool ACK_DisFlag = true;
  69. //Boot版本信息
  70. public string BootInfo = "";
  71. //接收指令临时缓存,转string
  72. public string CmdRevStrTemp = "";
  73. //计时器,用于统计运行时间
  74. public Stopwatch stopwatch = new Stopwatch();
  75. //力矩传感器检验参数窗口
  76. public static TorqueParams TorqueParamsForm = new TorqueParams();
  77. //参数生成窗口
  78. public static GenerateParams GenerateParamsForm = new GenerateParams();
  79. //版本信息窗口
  80. public static Version VersionForm = new Version();
  81. //本机硬件信息
  82. public string Local_HdInformation = "";
  83. //指令窗口显示
  84. public bool DebugWindowIsOpen = false, DebugDataDisplayEnable = false;
  85. //位置传感器数据记录
  86. string[] AngledataRecord = new string[42];
  87. //服务器设置窗口
  88. public static ServerSelect ServerCfgForm1 = new ServerSelect();
  89. #endregion
  90. #region 故障日志结构体定义
  91. //故障日志记录信息 60 bytes,1K空间可以保存最近16条故障记录
  92. [StructLayout(LayoutKind.Sequential)]
  93. public struct MC_ErrorLogSaveInfo_Struct_t
  94. {
  95. public UInt16 Error_Index; //故障列表索引 2 bytes, 地址偏移 0
  96. public UInt16 NotesInfo1; //备注信息1,地址偏移 2
  97. public UInt16 NotesInfo2; //备注信息2,地址偏移 4
  98. public UInt16 NotesInfo3; //备注信息3,地址偏移 6
  99. public UInt32 ErrorCode; //故障码 4 bytes, 地址偏移 8
  100. public UInt32 RunTime; //运行时间 4bytes, 地址偏移 12
  101. //电机运行信息,占用空间32bytes
  102. [StructLayout(LayoutKind.Sequential)]
  103. public struct MC_RunInfo_Struct_t
  104. {
  105. public ushort BikeSpeed; //车速 0.1km/h,地址偏移0
  106. public ushort MotorSpeed; //输出转速 1rpm,地址偏移2
  107. public ushort Power; //电功率 1W,地址偏移4
  108. public ushort BusVoltage; //母线电压 1mV,地址偏移6
  109. public ushort BusCurrent; //母线电流 1mA,地址偏移8
  110. public byte Cadence; //踏频 1rpm,地址偏移10
  111. public byte Torque; //踩踏力矩 1Nm,地址偏移11
  112. public byte CadenceDir; //踩踏方向 0-正,1-反,2-停止,地址偏移12
  113. public byte GearSt; //助力档位,地址偏移13
  114. public byte LightSwitch; //灯开关 0xF0-关,0xF1-开,地址偏移14
  115. public byte SOC; //剩余电量 1%,地址偏移15
  116. public ushort RemainDistance; //续航里程 1km,地址偏移16
  117. public ushort Torque_AD; //力矩寄存器,地址偏移18
  118. public byte PowerPerKm; //平均功耗 0.01Ah/km ,地址偏移20
  119. public byte T_PCB; //PCB温度 +40℃,地址偏移21
  120. public byte T_Coil; //绕组温度 +40℃,地址偏移22
  121. public byte T_MCU; //MCU温度 +40℃,地址偏移23
  122. public ushort Ride_Km; //开机后骑行里程 0.1km, 地址偏移24
  123. public ushort Ride_Time; //开机后骑行时间 1s,地址偏移26
  124. public UInt32 RS; //预留 4bytes
  125. };
  126. [MarshalAs(UnmanagedType.Struct)]
  127. public MC_RunInfo_Struct_t RunInfo; //运行信息 32bytes, 地址偏移 16
  128. //控制变量
  129. public Int16 IqCurrent; //Pu, 地址偏移 48
  130. public Int16 IqVoltage; //Pu, 地址偏移 50
  131. public Int16 IdCurrent; //Pu, 地址偏移 52
  132. public Int16 IdVoltage; //Pu, 地址偏移 54
  133. //状态机
  134. public UInt16 FSM; //高到低依次表示系统状态机、二层状态机、电机状态机、助力状态机, 地址偏移 56
  135. //预留
  136. public UInt16 RS1;
  137. public UInt16 RS2;
  138. public UInt16 RS3;
  139. };
  140. #endregion
  141. #region 屏幕缩放比例获取
  142. public class PrimaryScreen
  143. {
  144. #region Win32 API
  145. [DllImport("user32.dll")]
  146. static extern IntPtr GetDC(IntPtr ptr);
  147. [DllImport("gdi32.dll")]
  148. static extern int GetDeviceCaps(
  149. IntPtr hdc, // handle to DC
  150. int nIndex // index of capability
  151. );
  152. [DllImport("user32.dll", EntryPoint = "ReleaseDC")]
  153. static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDc);
  154. #endregion
  155. #region DeviceCaps常量
  156. const int HORZRES = 8;
  157. const int VERTRES = 10;
  158. const int LOGPIXELSX = 88;
  159. const int LOGPIXELSY = 90;
  160. const int DESKTOPVERTRES = 117;
  161. const int DESKTOPHORZRES = 118;
  162. #endregion
  163. #region 属性
  164. /// <summary>
  165. /// 获取屏幕分辨率当前物理大小
  166. /// </summary>
  167. public static Size WorkingArea
  168. {
  169. get
  170. {
  171. IntPtr hdc = GetDC(IntPtr.Zero);
  172. Size size = new Size();
  173. size.Width = GetDeviceCaps(hdc, HORZRES);
  174. size.Height = GetDeviceCaps(hdc, VERTRES);
  175. ReleaseDC(IntPtr.Zero, hdc);
  176. return size;
  177. }
  178. }
  179. /// <summary>
  180. /// 当前系统DPI_X 大小 一般为96
  181. /// </summary>
  182. public static int DpiX
  183. {
  184. get
  185. {
  186. IntPtr hdc = GetDC(IntPtr.Zero);
  187. int DpiX = GetDeviceCaps(hdc, LOGPIXELSX);
  188. ReleaseDC(IntPtr.Zero, hdc);
  189. return DpiX;
  190. }
  191. }
  192. /// <summary>
  193. /// 当前系统DPI_Y 大小 一般为96
  194. /// </summary>
  195. public static int DpiY
  196. {
  197. get
  198. {
  199. IntPtr hdc = GetDC(IntPtr.Zero);
  200. int DpiX = GetDeviceCaps(hdc, LOGPIXELSY);
  201. ReleaseDC(IntPtr.Zero, hdc);
  202. return DpiX;
  203. }
  204. }
  205. /// <summary>
  206. /// 获取真实设置的桌面分辨率大小
  207. /// </summary>
  208. public static Size DESKTOP
  209. {
  210. get
  211. {
  212. IntPtr hdc = GetDC(IntPtr.Zero);
  213. Size size = new Size();
  214. size.Width = GetDeviceCaps(hdc, DESKTOPHORZRES);
  215. size.Height = GetDeviceCaps(hdc, DESKTOPVERTRES);
  216. ReleaseDC(IntPtr.Zero, hdc);
  217. return size;
  218. }
  219. }
  220. /// <summary>
  221. /// 获取宽度缩放百分比
  222. /// </summary>
  223. public static float ScaleX
  224. {
  225. get
  226. {
  227. IntPtr hdc = GetDC(IntPtr.Zero);
  228. int t = GetDeviceCaps(hdc, DESKTOPHORZRES);
  229. int d = GetDeviceCaps(hdc, HORZRES);
  230. float ScaleX = (float)GetDeviceCaps(hdc, DESKTOPHORZRES) / (float)GetDeviceCaps(hdc, HORZRES);
  231. ReleaseDC(IntPtr.Zero, hdc);
  232. return ScaleX;
  233. }
  234. }
  235. /// <summary>
  236. /// 获取高度缩放百分比
  237. /// </summary>
  238. public static float ScaleY
  239. {
  240. get
  241. {
  242. IntPtr hdc = GetDC(IntPtr.Zero);
  243. float ScaleY = (float)(float)GetDeviceCaps(hdc, DESKTOPVERTRES) / (float)GetDeviceCaps(hdc, VERTRES);
  244. ReleaseDC(IntPtr.Zero, hdc);
  245. return ScaleY;
  246. }
  247. }
  248. #endregion
  249. }
  250. #endregion
  251. public static mainForm mainform1 = null;
  252. public mainForm()
  253. {
  254. InitializeComponent();
  255. mainform1 = this;
  256. System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
  257. stopwatch.Start();
  258. //端口初始化
  259. mySerialProcess.Init();
  260. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  261. //检查文件夹
  262. if (!Directory.Exists(localInfo.LocalPath))
  263. {
  264. Directory.CreateDirectory(localInfo.LocalPath);
  265. }
  266. if (!Directory.Exists(localInfo.LocalDataPath))
  267. {
  268. Directory.CreateDirectory(localInfo.LocalDataPath);
  269. }
  270. if (!Directory.Exists(localInfo.ToolsPath))
  271. {
  272. Directory.CreateDirectory(localInfo.ToolsPath);
  273. }
  274. if (!Directory.Exists(localInfo.LocalPath + localInfo.CfgPathName))
  275. {
  276. Directory.CreateDirectory(localInfo.LocalPath + localInfo.CfgPathName);
  277. }
  278. //检查备忘录文件
  279. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.NoteFileName))
  280. {
  281. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.NoteFileName, "");
  282. }
  283. //检验流水号记录文件
  284. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.SerialNumFileName1))
  285. {
  286. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, "0");
  287. }
  288. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.SerialNumFileName2))
  289. {
  290. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, "0");
  291. }
  292. //服务器初始化
  293. do
  294. {
  295. //检查是否存在配置文件
  296. if (File.Exists(localInfo.LocalPath + localInfo.ServerCfgFileName)) //存在配置文件从文件选择
  297. {
  298. //解密
  299. string sLine = aes.DecryptFromFile(localInfo.LocalPath + localInfo.ServerCfgFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  300. string[] array_CfgInfo = sLine.Split(',');
  301. //解析配置文件
  302. ServerIP = array_CfgInfo[0].ToString();
  303. ServerPort = array_CfgInfo[1].ToString();
  304. ServerUser = array_CfgInfo[2].ToString();
  305. ServerPassWd = array_CfgInfo[3].ToString();
  306. if (array_CfgInfo[4].ToString() == "True")
  307. {
  308. OfflineFlag = true;
  309. checkBox_OffLineFacMode.Checked = true;
  310. checkBox_OffLineCheckMode.Checked = true;
  311. }
  312. }
  313. else //不存在配置文件由用户选择
  314. {
  315. ServerCfgForm1.ShowDialog();
  316. switch (ServerCfgForm1.comboBox_Server.SelectedIndex)
  317. {
  318. case 0: //武汉园区
  319. case 1: //顺德工厂
  320. {
  321. ServerIP = "10.177.130.30";
  322. ServerPort = "15021";
  323. ServerUser = "factory_test";
  324. ServerPassWd = "ttium";
  325. OfflineFlag = false;
  326. checkBox_OffLineFacMode.Checked = false;
  327. checkBox_OffLineCheckMode.Checked = false;
  328. break;
  329. }
  330. case 2: //威灵园区
  331. case 3: //越南工厂
  332. case 4: //公司外部
  333. {
  334. ServerIP = "8.134.109.44";
  335. ServerPort = "21";
  336. ServerUser = "ttium";
  337. ServerPassWd = "ttium123";
  338. OfflineFlag = false;
  339. checkBox_OffLineFacMode.Checked = false;
  340. checkBox_OffLineCheckMode.Checked = false;
  341. break;
  342. }
  343. case 5: //离线使用
  344. {
  345. //输入管理员密码
  346. Scan scan_form = new Scan();
  347. scan_form.label1.Text = "请输入管理员密码";
  348. scan_form.textBox_Scan.UseSystemPasswordChar = true;
  349. scan_form.ShowDialog();
  350. if (scan_form.textBox_Scan.Text == "ttium.123")
  351. {
  352. //检查许可
  353. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.OffLineUseKeyFileName)) //未许可
  354. {
  355. if (MessageBox.Show("无离线授权,请导入许可文件!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
  356. {
  357. Licences myLicences = new Licences();
  358. myLicences.ShowDialog();
  359. //从许可文件读取内容
  360. string str_lic = aes.DecryptFromFile(myLicences.textBox_LicencePath.Text, "2D820F88F60A39D5", "3687C5216B19D16B");
  361. string PC_Code = PC_Information.GetCPUSerialNumber();
  362. if (PC_Code == str_lic) //授权码正确
  363. {
  364. aes.EncryptToFile(PC_Code, localInfo.LocalPath + localInfo.OffLineUseKeyFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  365. string strInfo = "";
  366. strInfo = "0;" + DateTime.Now.ToString("yyyyMMdd");
  367. aes.EncryptToFile(strInfo, localInfo.LocalPath + localInfo.OfflineUseLogFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  368. }
  369. else //授权码错误
  370. {
  371. MessageBox.Show("许可文件无效,请联系管理员!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  372. System.Environment.Exit(0);
  373. }
  374. }
  375. else
  376. {
  377. System.Environment.Exit(0);
  378. }
  379. }
  380. else //已授权
  381. {
  382. string str_Key = aes.DecryptFromFile(localInfo.LocalPath + localInfo.OffLineUseKeyFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  383. //判断授权是否正确
  384. if (PC_Information.GetCPUSerialNumber() == str_Key) //授权正确
  385. {
  386. //检查离线使用记录文件
  387. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.OfflineUseLogFileName))
  388. {
  389. MessageBox.Show("许可文件内容缺失,请联系管理员!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  390. File.Delete(localInfo.LocalPath + localInfo.OffLineUseKeyFileName);//缺少离线使用记录文件时,自动删除许可文件,下次打开重新导入许可
  391. System.Environment.Exit(0);
  392. }
  393. //获取离线使用记录并更新
  394. string UseLog = aes.DecryptFromFile(localInfo.LocalPath + localInfo.OfflineUseLogFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  395. UInt32 UseTimes = Convert.ToUInt32(UseLog.Split(';')[0]);
  396. UseTimes++;
  397. string str = UseTimes.ToString() + ";" + UseLog.Split(';')[1];
  398. aes.EncryptToFile(str, localInfo.LocalPath + localInfo.OfflineUseLogFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  399. //判断授权期限
  400. DateTime DataOrigin = new DateTime();
  401. DateTime.TryParseExact(UseLog.Split(';')[1], "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None, out DataOrigin);
  402. DateTime DataEnd = DataOrigin.AddDays(90);
  403. DateTime NowDate = DateTime.Now.Date;
  404. if ((NowDate > DataEnd) || (UseTimes > 1000)) //第一次打开软件90天内,或1000次内
  405. {
  406. MessageBox.Show("离线授权过期,请联系管理员!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  407. File.Delete(localInfo.LocalPath + localInfo.OffLineUseKeyFileName);//许可过期或超出使用次数,自动删除许可文件和使用记录,下次打开重新导入许可
  408. File.Delete(localInfo.LocalPath + localInfo.OfflineUseLogFileName);//许可过期或超出使用次数,自动删除许可文件和使用记录,下次打开重新导入许可
  409. System.Environment.Exit(0);
  410. }
  411. }
  412. else
  413. {
  414. MessageBox.Show("离线授权错误,请联系管理员!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  415. File.Delete(localInfo.LocalPath + localInfo.OffLineUseKeyFileName);//许可文件不匹配,自动删除许可文件和使用记录,下次打开重新导入许可
  416. File.Delete(localInfo.LocalPath + localInfo.OfflineUseLogFileName);//许可文件不匹配,自动删除许可文件和使用记录,下次打开重新导入许可
  417. System.Environment.Exit(0);
  418. }
  419. }
  420. OfflineFlag = true;
  421. checkBox_OffLineFacMode.Checked = true;
  422. checkBox_OffLineCheckMode.Checked = true;
  423. }
  424. else
  425. {
  426. MessageBox.Show("密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  427. System.Environment.Exit(0);
  428. }
  429. break;
  430. }
  431. default: //无效
  432. {
  433. System.Environment.Exit(0);
  434. break;
  435. }
  436. }
  437. //保存网络配置文件
  438. if (ServerCfgForm1.checkBox_NoticeSw.Checked)
  439. {
  440. string str = ServerIP + "," + ServerPort + "," + ServerUser + "," + ServerPassWd + "," + (OfflineFlag == true).ToString();
  441. //加密保存
  442. aes.EncryptToFile(str, localInfo.LocalPath + localInfo.ServerCfgFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  443. }
  444. }
  445. } while (false);
  446. //检查配置文件
  447. if (File.Exists(localInfo.LocalPath + localInfo.ConfigFileName)) //存在配置文件,导入配置信息
  448. {
  449. //打开文件
  450. StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.ConfigFileName);
  451. string sLine = "";
  452. ArrayList array_CfgInfo = new ArrayList();
  453. array_CfgInfo.Clear();
  454. while (sLine != null)
  455. {
  456. sLine = objReader.ReadLine();
  457. array_CfgInfo.Add(sLine);
  458. }
  459. objReader.Close();
  460. //解析配置文件
  461. try
  462. {
  463. //Port Set
  464. PortNumSave = array_CfgInfo[1].ToString().Split(':')[1];
  465. PortBaudrateSave = array_CfgInfo[2].ToString().Split(':')[1];
  466. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.IndexOf(PortNumSave);
  467. toolStripComboBox_Baudrate.SelectedIndex = toolStripComboBox_Baudrate.Items.IndexOf(PortBaudrateSave);
  468. 连接开机ToolStripMenuItem.Checked = (array_CfgInfo[3].ToString().Split(':')[1] == "True");
  469. 断开关机ToolStripMenuItem.Checked = (array_CfgInfo[4].ToString().Split(':')[1] == "True");
  470. 识别通讯盒ToolStripMenuItem.Checked = (array_CfgInfo[5].ToString().Split(':')[1] == "True");
  471. //Option
  472. 写入存储ToolStripMenuItem.Checked = (array_CfgInfo[8].ToString().Split(':')[1] == "True");
  473. //Server Set
  474. toolStripTextBox_ServerPath.Text = array_CfgInfo[11].ToString().Split(':')[1];
  475. //MacInfo
  476. toolStripTextBox_MAC.Text = array_CfgInfo[14].ToString().Split(':')[1];
  477. toolStripTextBoxMACAddr.Text = array_CfgInfo[15].ToString().Split(':')[1];
  478. toolStripTextBox_MACDate.Text = DateTime.Now.ToString("yyyyMMdd");
  479. toolStripTextBox_MACPD.Text = array_CfgInfo[17].ToString().Split(':')[1];
  480. //Log Address
  481. textBox_LogAddrBegin.Text = array_CfgInfo[20].ToString().Split(':')[1];
  482. textBox_LogAddrEnd.Text = array_CfgInfo[21].ToString().Split(':')[1];
  483. //电机类型
  484. 中置电机ToolStripMenuItem.Checked = (array_CfgInfo[24].ToString().Split(':')[1] == "True");
  485. 轮毂电机ToolStripMenuItem.Checked = !中置电机ToolStripMenuItem.Checked;
  486. //检测阈值
  487. toolStripTextBox_ThVol.Text = array_CfgInfo[28].ToString().Split(':')[1];
  488. toolStripTextBox_ThCur.Text = array_CfgInfo[29].ToString().Split(':')[1];
  489. toolStripTextBox_ThSpeed.Text = array_CfgInfo[30].ToString().Split(':')[1];
  490. toolStripTextBox_ThTor.Text = array_CfgInfo[31].ToString().Split(':')[1];
  491. toolStripTextBox_ThCad.Text = array_CfgInfo[32].ToString().Split(':')[1];
  492. toolStripTextBox_ThBikeSpeed.Text = array_CfgInfo[33].ToString().Split(':')[1];
  493. toolStripTextBox_ThT_PCB.Text = array_CfgInfo[34].ToString().Split(':')[1];
  494. toolStripTextBox_ThT_MCU.Text = array_CfgInfo[35].ToString().Split(':')[1];
  495. toolStripTextBox_ThT_Motor.Text = array_CfgInfo[36].ToString().Split(':')[1];
  496. //MOS内阻校准系数
  497. toolStripTextBox_MosCalK.Text = array_CfgInfo[39].ToString().Split(':')[1];
  498. toolStripTextBox_MOS1.Text= array_CfgInfo[40].ToString().Split(':')[1];
  499. toolStripTextBox_MOS2.Text = array_CfgInfo[41].ToString().Split(':')[1];
  500. toolStripTextBox_MOS3.Text = array_CfgInfo[42].ToString().Split(':')[1];
  501. //通信协议类型
  502. cANToolStripMenuItem.Checked = (array_CfgInfo[45].ToString().Split(':')[1] == "True");
  503. uARTToolStripMenuItem.Checked = !cANToolStripMenuItem.Checked;
  504. //自动更新开关
  505. 打开ToolStripMenuItem.Checked = (array_CfgInfo[49].ToString().Split(':')[1] == "True");
  506. 关闭ToolStripMenuItem.Checked = !打开ToolStripMenuItem.Checked;
  507. //位置校准偏差
  508. textBox_AngleDiffTh.Text = array_CfgInfo[52].ToString().Split(':')[1];
  509. toolStripTextBox_AngleAvgMax.Text = textBox_AngleDiffTh.Text;
  510. textBox_AngleZeroTh.Text = array_CfgInfo[53].ToString().Split(':')[1];
  511. toolStripTextBox_AngleZeroMax.Text = textBox_AngleZeroTh.Text;
  512. }
  513. catch (System.Exception)
  514. {
  515. timer_500ms.Enabled = false;
  516. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  517. timer_500ms.Enabled = true;
  518. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  519. }
  520. }
  521. else //不存在配置文件,生成文件写入默认值
  522. {
  523. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  524. }
  525. //解析本地流水号记录
  526. do
  527. {
  528. //测试模式
  529. label_FacModeSerial.Text = File.ReadAllText(localInfo.LocalPath + localInfo.SerialNumFileName1);
  530. //检验模式
  531. label_CheckModeSerial.Text = File.ReadAllText(localInfo.LocalPath + localInfo.SerialNumFileName2);
  532. } while (false);
  533. //获取本机信息,读取时间较长,优先从本地文件获取
  534. do
  535. {
  536. try
  537. {
  538. //本地文件为空,读取信息保存
  539. if (!File.Exists(localInfo.LocalPath + localInfo.PC_InfoFileName))
  540. {
  541. Local_HdInformation = "";
  542. Local_HdInformation += "计算机名称: " + System.Environment.UserName + "\r\n";
  543. Local_HdInformation += "IP地址: " + PC_Information.GetIpAddress() + "\r\n";
  544. Local_HdInformation += "系统ID: " + PC_Information.GetSystemID() + "\r\n";
  545. Local_HdInformation += "操作系统类型: " + PC_Information.GetSystemType() + "\r\n";
  546. Local_HdInformation += "主板型号: " + PC_Information.GetBoardType() + "\r\n";
  547. Local_HdInformation += "主板厂商: " + PC_Information.GetBoardManufacturer() + "\r\n";
  548. Local_HdInformation += "主板ID: " + PC_Information.GetBIOSSerialNumber() + "\r\n";
  549. Local_HdInformation += "CPU型号: " + PC_Information.GetCpuName() + "\r\n";
  550. Local_HdInformation += "CPU厂商: " + PC_Information.GetCpuManufacturer() + "\r\n";
  551. Local_HdInformation += "CPU ID: " + PC_Information.GetCPUSerialNumber() + "\r\n";
  552. Local_HdInformation += "内存容量: " + PC_Information.GetPhysicalMemory() + " GB" + "\r\n";
  553. Local_HdInformation += "MAC ID: " + PC_Information.GetNetCardMACAddress().Replace(":", "-") + "\r\n";
  554. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.PC_InfoFileName, Local_HdInformation);
  555. }
  556. //从本地读取,计算机名和IP地址重新读
  557. else
  558. {
  559. Local_HdInformation = "";
  560. string[] fileInfo = File.ReadAllLines(localInfo.LocalPath + localInfo.PC_InfoFileName, Encoding.UTF8);
  561. fileInfo[0] = "计算机名称: " + System.Environment.UserName;
  562. fileInfo[1] = "IP地址: " + PC_Information.GetIpAddress();
  563. for (int i = 0; i < fileInfo.Length; i++)
  564. Local_HdInformation += fileInfo[i] + "\r\n";
  565. File.Delete(localInfo.LocalPath + localInfo.PC_InfoFileName);
  566. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.PC_InfoFileName, Local_HdInformation);
  567. }
  568. }
  569. catch(Exception)
  570. {
  571. }
  572. } while (false);
  573. //系统登录
  574. do
  575. {
  576. EnterForm1.ShowDialog();
  577. try
  578. {
  579. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  580. {
  581. if (EnterForm1.comboBox_User.Text.Contains("量产"))
  582. {
  583. //隐藏设置项
  584. 其它配置项ToolStripMenuItem.Visible = false;
  585. 写入存储ToolStripMenuItem.Visible = false;
  586. 服务器配置ToolStripMenuItem.Visible = false;
  587. 判断阈值ToolStripMenuItem.Visible = false;
  588. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  589. mOS内阻范围ToolStripMenuItem.Visible = false;
  590. 力矩传感器检验ToolStripMenuItem.Visible = false;
  591. 位置校准偏差范围ToolStripMenuItem.Visible = false;
  592. //显示生产信息
  593. 生产信息ToolStripMenuItem.Visible = true;
  594. //显示电机类型,但不可编辑
  595. 电机类型ToolStripMenuItem.Visible = true;
  596. 中置电机ToolStripMenuItem.Enabled = false;
  597. 轮毂电机ToolStripMenuItem.Enabled = false;
  598. if (uARTToolStripMenuItem.Checked)
  599. UART协议ToolStripMenuItem.Visible = true;
  600. //隐藏研发调试界面
  601. tabPage_MotorParam.Parent = null;
  602. tabPage_BikeParam.Parent = null;
  603. tabPage_BikeParam2.Parent = null;
  604. tabPage_ControlParam.Parent = null;
  605. tabPage_SensorParam.Parent = null;
  606. tabPage_AssistParam.Parent = null;
  607. tabPage_UsrRideParam.Parent = null;
  608. tabPage_DebugParam.Parent = null;
  609. tabPage_RecordInfo.Parent = null;
  610. tabPage_OtherInfo.Parent = null;
  611. tabPage_OBC.Parent = null;
  612. tabPage_RAMorFLASH.Parent = null;
  613. tabPage_FactoryMode.Parent = null;
  614. tabPage_DebugInfo.Parent = null;
  615. tabPage_AngleCal.Parent = null;
  616. tabPage_FuncSet.Parent = null;
  617. //显示运行信息
  618. tabPage_RunInfo.Parent = tabControl2;
  619. //根据电机类型修改生产信息和电机类型
  620. if (EnterForm1.comboBox_User.Text.Contains("中置"))
  621. {
  622. 中置电机ToolStripMenuItem.Checked = true;
  623. 轮毂电机ToolStripMenuItem.Checked = false;
  624. toolStripTextBox_MACPD.Text = "MM_MC1";
  625. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  626. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  627. }
  628. else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
  629. {
  630. 中置电机ToolStripMenuItem.Checked = false;
  631. 轮毂电机ToolStripMenuItem.Checked = true;
  632. toolStripTextBox_MACPD.Text = "GF_250_1";
  633. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  634. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  635. }
  636. //显示对应生产测试界面
  637. if (EnterForm1.comboBox_User.Text.Contains("写入"))
  638. {
  639. tabPage_ProductMode_Write.Parent = tabControl1;
  640. tabPage_ProductMode_Write.Select();
  641. tabPage_ProductMode_Read.Parent = null;
  642. }
  643. else if (EnterForm1.comboBox_User.Text.Contains("检验"))
  644. {
  645. tabPage_ProductMode_Read.Parent = tabControl1;
  646. tabPage_ProductMode_Read.Select();
  647. tabPage_ProductMode_Write.Parent = null;
  648. }
  649. //应答指令不提示
  650. ACK_DisFlag = false;
  651. //退出登录
  652. break;
  653. }
  654. else if (EnterForm1.comboBox_User.Text == "工程参数配置")
  655. {
  656. //隐藏工作台内容,新建窗口完成配置
  657. groupBox1.Visible = false;
  658. groupBox3.Visible = false;
  659. tabControl2.Visible = false;
  660. //隐藏提示信息
  661. label_StarInfo.Visible = false;
  662. //打开参数配置框
  663. GenerateParamsForm.ShowDialog();
  664. System.Environment.Exit(0);
  665. //退出登录
  666. break;
  667. }
  668. else if (EnterForm1.comboBox_User.Text.Contains("样机"))
  669. {
  670. //隐藏量产界面
  671. tabPage_ProductMode_Read.Parent = null;
  672. tabPage_ProductMode_Write.Parent = null;
  673. //隐藏配置项
  674. 其它配置项ToolStripMenuItem.Visible = false;
  675. 服务器配置ToolStripMenuItem.Visible = false;
  676. 判断阈值ToolStripMenuItem.Visible = false;
  677. 力矩传感器检验ToolStripMenuItem.Visible = false;
  678. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  679. mOS内阻范围ToolStripMenuItem.Visible = false;
  680. 位置校准偏差范围ToolStripMenuItem.Visible = false;
  681. //显示生产信息
  682. 生产信息ToolStripMenuItem.Visible = true;
  683. //显示电机类型,但不可编辑
  684. 电机类型ToolStripMenuItem.Visible = true;
  685. 中置电机ToolStripMenuItem.Enabled = true;
  686. 轮毂电机ToolStripMenuItem.Enabled = true;
  687. if (uARTToolStripMenuItem.Checked)
  688. UART协议ToolStripMenuItem.Visible = true;
  689. if (EnterForm1.comboBox_User.Text.Contains("中置"))
  690. {
  691. 中置电机ToolStripMenuItem.Checked = true;
  692. 轮毂电机ToolStripMenuItem.Checked = false;
  693. toolStripTextBox_MACPD.Text = "MM_MC1";
  694. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  695. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  696. }
  697. else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
  698. {
  699. 中置电机ToolStripMenuItem.Checked = false;
  700. 轮毂电机ToolStripMenuItem.Checked = true;
  701. toolStripTextBox_MACPD.Text = "GF_250_1";
  702. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  703. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  704. }
  705. //退出登录
  706. break;
  707. }
  708. else if (EnterForm1.comboBox_User.Text == "FCT治具测试")
  709. {
  710. //隐藏设置项
  711. 其它配置项ToolStripMenuItem.Visible = false;
  712. 写入存储ToolStripMenuItem.Visible = false;
  713. 服务器配置ToolStripMenuItem.Visible = false;
  714. 判断阈值ToolStripMenuItem.Visible = false;
  715. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  716. mOS内阻范围ToolStripMenuItem.Visible = false;
  717. 力矩传感器检验ToolStripMenuItem.Visible = false;
  718. 位置校准偏差范围ToolStripMenuItem.Visible = false;
  719. //显示生产信息
  720. 生产信息ToolStripMenuItem.Visible = true;
  721. //显示电机类型,但不可编辑
  722. 电机类型ToolStripMenuItem.Visible = false;
  723. 中置电机ToolStripMenuItem.Enabled = false;
  724. 轮毂电机ToolStripMenuItem.Enabled = false;
  725. if (uARTToolStripMenuItem.Checked)
  726. UART协议ToolStripMenuItem.Visible = true;
  727. //隐藏研发调试界面
  728. tabPage_MotorParam.Parent = null;
  729. tabPage_BikeParam.Parent = null;
  730. tabPage_BikeParam2.Parent = null;
  731. tabPage_ControlParam.Parent = null;
  732. tabPage_SensorParam.Parent = null;
  733. tabPage_AssistParam.Parent = null;
  734. tabPage_UsrRideParam.Parent = null;
  735. tabPage_DebugParam.Parent = null;
  736. tabPage_RecordInfo.Parent = null;
  737. tabPage_OtherInfo.Parent = null;
  738. tabPage_OBC.Parent = null;
  739. tabPage_RAMorFLASH.Parent = null;
  740. tabPage_FactoryMode.Parent = null;
  741. tabPage_DebugInfo.Parent = null;
  742. tabPage_AngleCal.Parent = null;
  743. tabPage_FuncSet.Parent = null;
  744. //显示运行信息
  745. tabPage_RunInfo.Parent = tabControl2;
  746. //目前仅轮毂使用
  747. 中置电机ToolStripMenuItem.Checked = false;
  748. 轮毂电机ToolStripMenuItem.Checked = true;
  749. toolStripTextBox_MACPD.Text = "GF_250_1";
  750. toolStripTextBox_ServerPath.Text = "HUB_Control_FCT";
  751. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  752. //显示量产测试界面
  753. tabPage_ProductMode_Write.Parent = tabControl1;
  754. tabPage_ProductMode_Write.Select();
  755. tabPage_ProductMode_Read.Parent = null;
  756. checkBox_OffLineFacMode.Checked = false;
  757. checkBox_OffLineFacMode.Enabled = true;
  758. checkBox_OffLineCheckMode.Checked = false;
  759. checkBox_OffLineCheckMode.Enabled = true;
  760. //应答指令不提示
  761. ACK_DisFlag = false;
  762. //退出登录
  763. break;
  764. }
  765. else if (EnterForm1.comboBox_User.Text == "研发调试")
  766. {
  767. //隐藏量产界面
  768. tabPage_ProductMode_Read.Parent = null;
  769. tabPage_ProductMode_Write.Parent = null;
  770. 服务器配置ToolStripMenuItem.Visible = false;
  771. if (uARTToolStripMenuItem.Checked)
  772. UART协议ToolStripMenuItem.Visible = true;
  773. //退出登录
  774. break;
  775. }
  776. else if (EnterForm1.comboBox_User.Text == "管理员")
  777. {
  778. //不隐藏任何界面
  779. //...
  780. //退出登录
  781. break;
  782. }
  783. else
  784. {
  785. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  786. //重新登录
  787. continue;
  788. }
  789. }
  790. else
  791. {
  792. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  793. //重新登录
  794. continue;
  795. }
  796. }
  797. catch (Exception)
  798. {
  799. System.Environment.Exit(0);
  800. }
  801. } while (true);
  802. //配置网络FTP服务器
  803. myFtp.FtpOption(ServerIP, ServerPort, ServerUser, ServerPassWd, "admin", "ttium_admin");
  804. //创建线程,定时检测网络连接状态
  805. Thread th = new Thread(NetworkCheck);
  806. th.IsBackground = true;
  807. th.Start();
  808. //允许跨线程访问
  809. Control.CheckForIllegalCrossThreadCalls = false;
  810. }
  811. /// <summary>
  812. /// 检查网络状态线程
  813. /// </summary>
  814. private void NetworkCheck()
  815. {
  816. //允许离线使用,直接退出
  817. if (OfflineFlag == true) //允许离线使用
  818. {
  819. MessageBoxTimeOut.Show("离线使用,不检测网络状态!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  820. return;
  821. }
  822. //不允许离线使用,实时监测网络状态
  823. else
  824. {
  825. //初始化第一次连接FTP服务器
  826. bool Result = myFtp.CheckFtp();
  827. if (Result == true)//服务器连接成功
  828. {
  829. myFtp.IsNetConnected = true;
  830. //上传登录日志
  831. do
  832. {
  833. //日志文件名
  834. string date = DateTime.Now.ToString("yyyy-MM-dd_HHmmss_fff");
  835. string fileName = date;
  836. //日志内容
  837. string fileInfo = Local_HdInformation;
  838. //保存本地
  839. if (!Directory.Exists(localInfo.LocalLogPath))
  840. Directory.CreateDirectory(localInfo.LocalLogPath);
  841. System.IO.File.WriteAllText(localInfo.LocalLogPath + fileName, fileInfo);
  842. //上传服务器
  843. myFtp.UploadFile(localInfo.LocalLogPath + fileName, "/Tools/Welling_Motor_Debug_Tool/log");
  844. } while (false);
  845. }
  846. else//服务器连接失败
  847. {
  848. myFtp.IsNetConnected = false;
  849. if (EnterForm1.comboBox_User.Text != "管理员")
  850. {
  851. MessageBoxTimeOut.Show("网络断开,将自动关闭!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  852. this.Close();
  853. }
  854. }
  855. //创建定时器,定时30s检查网络
  856. System.Timers.Timer timer_CheckNet = new System.Timers.Timer();
  857. timer_CheckNet.Enabled = true;
  858. timer_CheckNet.Interval = 30000;
  859. timer_CheckNet.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_CheckNet_Tick);
  860. timer_CheckNet.Start();
  861. while (true)
  862. {
  863. Thread.Sleep(1);
  864. if (myFtp.IsNetConnected == false)
  865. {
  866. label_Server_ComStatus.Text = "网络已断开";
  867. label_ServerStatus.BackColor = Color.Red;
  868. }
  869. else
  870. {
  871. label_Server_ComStatus.Text = "网络已连接";
  872. label_ServerStatus.BackColor = Color.Green;
  873. }
  874. }
  875. }
  876. }
  877. /// <summary>
  878. /// 线程中定时任务,检查网络状态
  879. /// </summary>
  880. /// <param name="sender"></param>
  881. /// <param name="e"></param>
  882. private void timer_CheckNet_Tick(object sender, EventArgs e)
  883. {
  884. //连接FTP服务器
  885. bool Result = myFtp.CheckFtp();
  886. if (Result == true)//服务器连接成功
  887. {
  888. myFtp.IsNetConnected = true;
  889. //允许使用
  890. groupBox1.Enabled = true;
  891. groupBox3.Enabled = true;
  892. tabControl2.Enabled = true;
  893. }
  894. else//服务器连接失败
  895. {
  896. myFtp.IsNetConnected = false;
  897. if (EnterForm1.comboBox_User.Text != "管理员")
  898. {
  899. MessageBoxTimeOut.Show("网络断开, 请检查网络!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Warning); //提示框自动3s关闭
  900. //禁止使用
  901. groupBox1.Enabled = false;
  902. groupBox3.Enabled = false;
  903. tabControl2.Enabled = false;
  904. }
  905. }
  906. }
  907. #region 非独占性延时函数
  908. public static void Delay_ms(int milliSecond)
  909. {
  910. int start = Environment.TickCount;
  911. while (Math.Abs(Environment.TickCount - start) < milliSecond)//毫秒
  912. {
  913. Application.DoEvents();
  914. }
  915. }
  916. #endregion
  917. private void MainForm_Load(object sender, System.EventArgs e)
  918. {
  919. timer_500ms.Start();
  920. //页面初始化
  921. label_BuildTime.Text = "编译时间:" + System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString("yyyy-MM-dd HH:mm:ss");
  922. label_Computername.Text = System.Environment.UserName;
  923. label_UserName.Text = EnterForm1.comboBox_User.Text;
  924. //位置校准表格初始化
  925. for (int i = 0; i < 7; i++)
  926. {
  927. int index = dataGridView_AngleCal.Rows.Add();
  928. dataGridView_AngleCal.Rows[index].Cells[0].Value = i + 1;
  929. }
  930. dataGridView_AngleCal.AllowUserToAddRows = false;
  931. //拓展功能表格初始化
  932. for (int i = 0; i < 8; i++)
  933. {
  934. int index = dataGridView_FunSet.Rows.Add();
  935. dataGridView_FunSet.Rows[index].Cells[0].Value = "#" + (i + 1).ToString();
  936. }
  937. dataGridView_FunSet.AllowUserToAddRows = false;
  938. //窗体显示版本
  939. this.Text += Version;
  940. //检查版本,自动更新
  941. do
  942. {
  943. if ((打开ToolStripMenuItem.Checked == false) || OfflineFlag == true)//关闭自动更新或离线时
  944. {
  945. break;
  946. }
  947. //检查网络状态
  948. if (myFtp.CheckFtp() == false)
  949. {
  950. MessageBoxTimeOut.Show("网络断开,自动更新失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  951. break;
  952. }
  953. else
  954. {
  955. //检查本地文件删除
  956. if (System.IO.File.Exists(localInfo.LocalPath + "\\Version"))
  957. System.IO.File.Delete(localInfo.LocalPath + "\\Version");
  958. //读取最新版本号
  959. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/Version", localInfo.LocalPath);
  960. StreamReader objReader = new StreamReader(localInfo.LocalPath + "\\Version");
  961. string sLine = "";
  962. ArrayList arrText = new ArrayList();//创建一个动态数组
  963. while (sLine != null)
  964. {
  965. sLine = objReader.ReadLine();
  966. arrText.Add(sLine);
  967. }
  968. objReader.Close();
  969. System.IO.File.Delete(localInfo.LocalPath + "\\Version");
  970. //检查是否有最新版本
  971. string[] VerOld = mainForm.Version.Trim().Split('.');
  972. string[] VerNew = arrText[0].ToString().Trim().Split('.');
  973. int VerOld_int = Convert.ToInt32(VerOld[0]) * 10000 + Convert.ToInt32(VerOld[1].PadLeft(2, '0')) * 100 + Convert.ToInt32(VerOld[2].PadLeft(2, '0'));
  974. int VerNew_int = Convert.ToInt32(VerNew[0]) * 10000 + Convert.ToInt32(VerNew[1].PadLeft(2, '0')) * 100 + Convert.ToInt32(VerNew[2].PadLeft(2, '0'));
  975. if (VerNew_int <= VerOld_int)
  976. {
  977. //版本已是最新,跳出
  978. break;
  979. }
  980. //确认下载最新版本
  981. if (MessageBox.Show("是否更新新版本?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  982. {
  983. string SavePath = Directory.GetCurrentDirectory();
  984. string[] FileList = myFtp.GetFileNameList("/Tools/Welling_Motor_Debug_Tool");
  985. foreach (string file in FileList)
  986. {
  987. if (file.Contains(".exe"))
  988. {
  989. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/" + file, SavePath);
  990. MessageBox.Show("新版本下载完成,请手动删除旧版本!\r\n最新版本:" + file, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  991. System.Environment.Exit(0);
  992. }
  993. }
  994. }
  995. }
  996. } while (false);
  997. //下拉控件初始值设定
  998. comboBox_WorkMode.SelectedIndex = 0;
  999. comboBox_GearSt.SelectedIndex = 0;
  1000. comboBox_LightSwitch.SelectedIndex = 1;
  1001. comboBox_OBC_SetGearST.SelectedIndex = 0;
  1002. comboBox_OBC_LightSw.SelectedIndex = 1;
  1003. comboBox_AssistTorque.SelectedIndex = 0;
  1004. comboBox_AssistCadence.SelectedIndex = 0;
  1005. //combobox事件定义
  1006. this.comboBox_WorkMode.SelectedIndexChanged += new System.EventHandler(this.comboBox_WorkMode_SelectedIndexChanged);
  1007. this.comboBox_GearSt.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  1008. this.comboBox_LightSwitch.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  1009. this.comboBox_OBC_SetGearST.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  1010. this.comboBox_OBC_LightSw.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  1011. //端口自动连接
  1012. if ((PortNumSave != string.Empty) && (PortBaudrateSave != string.Empty)) //有数值时采用上次使用的值
  1013. {
  1014. try
  1015. {
  1016. PortConnect();
  1017. }
  1018. catch (System.Exception)
  1019. {
  1020. timer_500ms.Enabled = false;
  1021. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  1022. timer_500ms.Enabled = true;
  1023. }
  1024. }
  1025. //不识别联动装置盒自动打开界面
  1026. #if true
  1027. groupBox1.Visible = true;
  1028. groupBox3.Visible = true;
  1029. tabControl2.Visible = true;
  1030. label_StarInfo.Visible = false;
  1031. #endif
  1032. //创建线程,定时解析数据
  1033. Thread th = new Thread(Task_SerialProcess);
  1034. th.IsBackground = true;
  1035. th.Start();
  1036. }
  1037. #region 结构体与字节流相互转换
  1038. public static class MyConverter
  1039. {
  1040. /// <summary>
  1041. /// 由结构体转换为byte数组
  1042. /// </summary>
  1043. public static byte[] StructureToByte<T>(T structure)
  1044. {
  1045. int size = Marshal.SizeOf(typeof(T));
  1046. byte[] buffer = new byte[size];
  1047. IntPtr bufferIntPtr = Marshal.AllocHGlobal(size);
  1048. try
  1049. {
  1050. Marshal.StructureToPtr(structure, bufferIntPtr, true);
  1051. Marshal.Copy(bufferIntPtr, buffer, 0, size);
  1052. }
  1053. finally
  1054. {
  1055. Marshal.FreeHGlobal(bufferIntPtr);
  1056. }
  1057. return buffer;
  1058. }
  1059. /// <summary>
  1060. /// 由byte数组转换为结构体
  1061. /// </summary>
  1062. public static T ByteToStructure<T>(byte[] dataBuffer, ushort StarIndex)
  1063. {
  1064. object structure = null;
  1065. int size = Marshal.SizeOf(typeof(T));
  1066. IntPtr allocIntPtr = Marshal.AllocHGlobal(size);
  1067. try
  1068. {
  1069. Marshal.Copy(dataBuffer, StarIndex, allocIntPtr, size);
  1070. structure = Marshal.PtrToStructure(allocIntPtr, typeof(T));
  1071. }
  1072. finally
  1073. {
  1074. Marshal.FreeHGlobal(allocIntPtr);
  1075. }
  1076. return (T)structure;
  1077. }
  1078. }
  1079. #endregion
  1080. #region 故障日志解析显示
  1081. private void ErrorLogDisplay(MC_ErrorLogSaveInfo_Struct_t Log1, MC_ErrorLogSaveInfo_Struct_t Log2)
  1082. {
  1083. string SaveData = "";
  1084. //Log1
  1085. if (Log1.Error_Index != 0xFFFF)
  1086. {
  1087. SaveData += "故障序号:" + Convert.ToString(Log1.Error_Index) + ", ";
  1088. SaveData += "备注1:" + Convert.ToString(Log1.NotesInfo1) + ", ";
  1089. SaveData += "备注2:" + Convert.ToString(Log1.NotesInfo2) + ", ";
  1090. SaveData += "备注3:" + Convert.ToString(Log1.NotesInfo3) + ", ";
  1091. SaveData += "故障码:" + "0x" + Convert.ToString(Log1.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  1092. SaveData += "运行时间:" + Convert.ToString(Log1.RunTime) + "min" + ", ";
  1093. SaveData += "车速:" + ((float)Log1.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  1094. SaveData += "电机转速:" + Convert.ToString(Log1.RunInfo.MotorSpeed) + "rpm" + ", ";
  1095. SaveData += "功率:" + Convert.ToString(Log1.RunInfo.Power * 2) + "w" + ", ";
  1096. SaveData += "电压:" + Convert.ToString(Log1.RunInfo.BusVoltage) + "mV" + ", ";
  1097. SaveData += "电流:" + Convert.ToString(Log1.RunInfo.BusCurrent) + "mA" + ", ";
  1098. SaveData += "踏频:" + Convert.ToString(Log1.RunInfo.Cadence) + "rpm" + ", ";
  1099. SaveData += "力矩:" + Convert.ToString(Log1.RunInfo.Torque) + "N.m" + ", ";
  1100. SaveData += "方向:" + ((Log1.RunInfo.CadenceDir == 0) ? "正" : ((Log1.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  1101. SaveData += "档位:" + "0x" + Convert.ToString(Log1.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  1102. SaveData += "灯开关:" + ((Log1.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  1103. SaveData += "电量:" + Convert.ToString(Log1.RunInfo.SOC) + "%" + ", ";
  1104. if ((Log1.RunInfo.RemainDistance == 0xEEEE) || (Log1.RunInfo.RemainDistance == 0xFFFF))
  1105. {
  1106. SaveData += "续航:" + "---km" + ", ";
  1107. }
  1108. else
  1109. {
  1110. SaveData += "续航:" + Convert.ToString(Log1.RunInfo.RemainDistance) + "km" + ", ";
  1111. }
  1112. SaveData += "力矩AD:" + Convert.ToString(Log1.RunInfo.Torque_AD) + ", ";
  1113. SaveData += "功耗:" + Convert.ToString(Log1.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  1114. SaveData += "PCB温度:" + Convert.ToString((int)(Log1.RunInfo.T_PCB - 40)) + "℃" + ", ";
  1115. SaveData += "绕组温度:" + Convert.ToString((int)(Log1.RunInfo.T_Coil - 40)) + "℃" + ", ";
  1116. SaveData += "MCU温度:" + Convert.ToString((int)(Log1.RunInfo.T_MCU - 40)) + "℃" + ", ";
  1117. SaveData += "单次里程:" + Convert.ToString((float)Log1.RunInfo.Ride_Km / 10f) + "km" + ", ";
  1118. SaveData += "单次时间:" + Convert.ToString(Log1.RunInfo.Ride_Time) + "s" + ", ";
  1119. SaveData += "q轴电流:" + Convert.ToString(Log1.IqCurrent) + ", ";
  1120. SaveData += "q轴电压:" + Convert.ToString(Log1.IqVoltage) + ", ";
  1121. SaveData += "d轴电流:" + Convert.ToString(Log1.IdCurrent) + ", ";
  1122. SaveData += "d轴电压:" + Convert.ToString(Log1.IdVoltage) + ", ";
  1123. SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
  1124. SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
  1125. SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
  1126. SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
  1127. SaveData += "\r\n\r\n";
  1128. richTextBox_Record.AppendText(SaveData);
  1129. SaveData = "";
  1130. }
  1131. //Log2
  1132. if (Log2.Error_Index != 0xFFFF)
  1133. {
  1134. SaveData += "故障序号:" + Convert.ToString(Log2.Error_Index) + ", ";
  1135. SaveData += "备注1:" + Convert.ToString(Log2.NotesInfo1) + ", ";
  1136. SaveData += "备注2:" + Convert.ToString(Log2.NotesInfo2) + ", ";
  1137. SaveData += "备注3:" + Convert.ToString(Log2.NotesInfo3) + ", ";
  1138. SaveData += "故障码:" + "0x" + Convert.ToString(Log2.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  1139. SaveData += "运行时间:" + Convert.ToString(Log2.RunTime) + "min" + ", ";
  1140. SaveData += "车速:" + ((float)Log2.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  1141. SaveData += "电机转速:" + Convert.ToString(Log2.RunInfo.MotorSpeed) + "rpm" + ", ";
  1142. SaveData += "功率:" + Convert.ToString(Log2.RunInfo.Power * 2) + "w" + ", ";
  1143. SaveData += "电压:" + Convert.ToString(Log2.RunInfo.BusVoltage) + "mV" + ", ";
  1144. SaveData += "电流:" + Convert.ToString(Log2.RunInfo.BusCurrent) + "mA" + ", ";
  1145. SaveData += "踏频:" + Convert.ToString(Log2.RunInfo.Cadence) + "rpm" + ", ";
  1146. SaveData += "力矩:" + Convert.ToString(Log2.RunInfo.Torque) + "N.m" + ", ";
  1147. SaveData += "方向:" + ((Log2.RunInfo.CadenceDir == 0) ? "正" : ((Log2.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  1148. SaveData += "档位:" + "0x" + Convert.ToString(Log2.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  1149. SaveData += "灯开关:" + ((Log2.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  1150. SaveData += "电量:" + Convert.ToString(Log2.RunInfo.SOC) + "%" + ", ";
  1151. if ((Log2.RunInfo.RemainDistance == 0xEEEE) || (Log2.RunInfo.RemainDistance == 0xFFFF))
  1152. {
  1153. SaveData += "续航:" + "---km" + ", ";
  1154. }
  1155. else
  1156. {
  1157. SaveData += "续航:" + Convert.ToString(Log2.RunInfo.RemainDistance) + "km" + ", ";
  1158. }
  1159. SaveData += "力矩AD:" + Convert.ToString(Log2.RunInfo.Torque_AD) + ", ";
  1160. SaveData += "功耗:" + Convert.ToString(Log2.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  1161. SaveData += "PCB温度:" + Convert.ToString((int)(Log2.RunInfo.T_PCB - 40)) + "DegreeC" + ", ";
  1162. SaveData += "绕组温度:" + Convert.ToString((int)(Log2.RunInfo.T_Coil - 40)) + "DegreeC" + ", ";
  1163. SaveData += "MCU温度:" + Convert.ToString((int)(Log2.RunInfo.T_MCU - 40)) + "DegreeC" + ", ";
  1164. SaveData += "单次里程:" + Convert.ToString((float)Log2.RunInfo.Ride_Km / 10f) + "km" + ", ";
  1165. SaveData += "单次时间:" + Convert.ToString(Log2.RunInfo.Ride_Time) + "s" + ", ";
  1166. SaveData += "q轴电流:" + Convert.ToString(Log2.IqCurrent) + ", ";
  1167. SaveData += "q轴电压:" + Convert.ToString(Log2.IqVoltage) + ", ";
  1168. SaveData += "d轴电流:" + Convert.ToString(Log2.IdCurrent) + ", ";
  1169. SaveData += "d轴电压:" + Convert.ToString(Log2.IdVoltage) + ", ";
  1170. SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
  1171. SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
  1172. SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
  1173. SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
  1174. SaveData += "\r\n\r\n";
  1175. richTextBox_Record.AppendText(SaveData);
  1176. SaveData = "";
  1177. }
  1178. }
  1179. #endregion
  1180. #region 串口数据解析线程
  1181. /// <summary>
  1182. /// 串口数据解析线程
  1183. /// </summary>
  1184. private void Task_SerialProcess()
  1185. {
  1186. //创建定时器,定时读取串口数据
  1187. System.Timers.Timer timer_ReadSerial = new System.Timers.Timer();
  1188. timer_ReadSerial.Enabled = true;
  1189. timer_ReadSerial.Interval = 20;
  1190. timer_ReadSerial.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_ReadSerial_Tick);
  1191. timer_ReadSerial.Start();
  1192. while (true)
  1193. {
  1194. Thread.Sleep(1);
  1195. };
  1196. }
  1197. /// <summary>
  1198. /// 串口解析定时器
  1199. /// </summary>
  1200. /// <param name="sender"></param>
  1201. /// <param name="e"></param>
  1202. private void timer_ReadSerial_Tick(object sender, EventArgs e)
  1203. {
  1204. //串口解析
  1205. Serial_process(mySerialProcess.buffer);
  1206. }
  1207. #endregion
  1208. #region 数据解析
  1209. public void Serial_process(List<byte> buffer)
  1210. {
  1211. byte DataNum = 0; //记录每条命令数据段的长度
  1212. ushort PackageID, Cmd;
  1213. byte[] Data = new byte[1024];
  1214. try
  1215. {
  1216. while (buffer.Count >= 13)//当buffer中的数据的个数大于等于4个时,即每一帧的数据长度所在位(第4位)出现时
  1217. {
  1218. if (buffer[0] == 0x55 && buffer[1] == 0xAA)//判断帧头
  1219. {
  1220. PackageID = (ushort)(buffer[2] * 256 + buffer[3]);
  1221. if ((PackageID == 0x0710) || (PackageID == 0x0715) || (PackageID == 0x07FF) || (PackageID == 0x0720) || (PackageID == 0x0713))
  1222. {
  1223. int CmdLen = buffer[5];
  1224. if (buffer.Count < CmdLen + 11) break;//如果接收到的数据没有达到一帧数据的指定长度, 则执行下次循环
  1225. while (CmdLen > 0) //读取命令段
  1226. {
  1227. Cmd = (ushort)(buffer[6] * 256 + buffer[7]);
  1228. DataNum = (byte)(buffer[7]);//命令字的第二个字节的表示数据位的长度
  1229. if (DataNum <= (CmdLen - 2))
  1230. {
  1231. for (int i = 0; i < DataNum; i++)
  1232. {
  1233. Data[i] = buffer[i + 8];
  1234. }
  1235. // 串口接收的数据 显示在子窗口
  1236. if (this.DebugWindowIsOpen && this.DebugDataDisplayEnable)
  1237. {
  1238. string strTemp = String.Empty;
  1239. strTemp += System.DateTimeOffset.Now.ToString("HH:mm:ss.fff") + " <-- ";
  1240. for (int i = 0; i < CmdLen + 11; i++)
  1241. {
  1242. strTemp += (buffer[i].ToString("X2") + " ");
  1243. }
  1244. strTemp += "\n";
  1245. DebugForm.debug1.richTextBox_DebugRev.Text += strTemp;
  1246. }
  1247. buffer.RemoveRange(0, CmdLen + 11);
  1248. DataCmdProcess(PackageID, Cmd, Data);//对于不同的命令段,做不同的处理
  1249. DataRevToString(Cmd, Data);//指令数据转为字符串
  1250. }
  1251. }
  1252. }
  1253. else
  1254. {
  1255. buffer.RemoveAt(0);//ID不对
  1256. }
  1257. }
  1258. else
  1259. {
  1260. buffer.RemoveAt(0);//帧头不对,删除帧头高字节
  1261. }
  1262. }
  1263. }
  1264. catch (Exception)
  1265. {
  1266. }
  1267. }
  1268. private void DataCmdProcess(ushort ID, ushort CmdTemp, byte[] Data)
  1269. {
  1270. int DataTemp;
  1271. ushort uData16;
  1272. unchecked
  1273. {
  1274. this.Invoke((EventHandler)(delegate { label_RecCount.Text = Convert.ToString(Convert.ToInt32(label_RecCount.Text) + 1); }));
  1275. }
  1276. #region 解析发送给CDL的指令
  1277. if (ID == 0x7FF)
  1278. {
  1279. switch (CmdTemp)
  1280. {
  1281. case 0x1100://
  1282. {
  1283. unchecked
  1284. {
  1285. this.Invoke((EventHandler)(delegate
  1286. {
  1287. //CDL连接成功
  1288. mySerialProcess.CDL_Online_Flag = true;
  1289. MessageBoxTimeOut.Show("连接成功!", "提示", 500);
  1290. groupBox1.Visible = true;
  1291. groupBox3.Visible = true;
  1292. tabControl2.Visible = true;
  1293. label_StarInfo.Visible = false;
  1294. }));
  1295. }
  1296. break;
  1297. }
  1298. default: break;
  1299. }
  1300. }
  1301. #endregion
  1302. #region 解析电机的命令
  1303. else if ((ID == 0x715) || (ID == 0x710))
  1304. {
  1305. switch (CmdTemp)
  1306. {
  1307. case 0x1020://电机运行信息
  1308. {
  1309. unchecked
  1310. {
  1311. this.Invoke((EventHandler)(delegate
  1312. {
  1313. MC_RunInfo_Refresh = true;
  1314. //车速
  1315. DataTemp = (int)(Data[1] * 256 + Data[0]);
  1316. textBox_RunInfo_BikeSpeed.Text = ((float)DataTemp / 10f).ToString("0.0") + " km/h";
  1317. //输出转速
  1318. DataTemp = (ushort)(Data[3] * 256 + Data[2]);
  1319. textBox_RunInfo_MotorSpeed.Text = Convert.ToString(DataTemp) + " rpm";
  1320. Class_MotorSpeed.String = textBox_RunInfo_MotorSpeed.Text;
  1321. Class_MotorSpeed.Data = DataTemp;
  1322. //电功率
  1323. DataTemp = (ushort)(Data[5] * 256 + Data[4]);
  1324. textBox_RunInfo_Power.Text = Convert.ToString(DataTemp) + " W";
  1325. //母线电压
  1326. DataTemp = (ushort)(Data[7] * 256 + Data[6]);
  1327. textBox_RunInfo_Vol.Text = Convert.ToString(DataTemp) + " mV";
  1328. //textBox_RunInfo_Vol.Text = (DataTemp / 1000f).ToString("0.0") + " V";
  1329. //母线电流
  1330. DataTemp = (short)(Data[9] * 256 + Data[8]);
  1331. textBox_RunInfo_Current.Text = Convert.ToString(DataTemp) + " mA";
  1332. //textBox_RunInfo_Current.Text = (DataTemp / 1000f).ToString("0.0") + " A";
  1333. Class_CurrentData.String = textBox_RunInfo_Current.Text;
  1334. Class_CurrentData.Data = DataTemp;
  1335. //踏频
  1336. DataTemp = (ushort)(Data[10]);
  1337. textBox_RunInfo_Cadence.Text = Convert.ToString(DataTemp) + " rpm";
  1338. Class_CadenceData.String = textBox_RunInfo_Cadence.Text;
  1339. Class_CadenceData.Data = DataTemp;
  1340. //踩踏力矩
  1341. DataTemp = (ushort)(Data[11]);
  1342. textBox_RunInfo_Torque.Text = Convert.ToString(DataTemp) + " N.m";
  1343. Class_TorqueData.String = textBox_RunInfo_Torque.Text;
  1344. Class_TorqueData.Data = DataTemp;
  1345. //踩踏方向
  1346. DataTemp = (ushort)(Data[12]);
  1347. if (DataTemp == 0)
  1348. {
  1349. textBox_RunInfo_Dir.Text = "正向";
  1350. }
  1351. else if (DataTemp == 1)
  1352. {
  1353. textBox_RunInfo_Dir.Text = "反向";
  1354. }
  1355. else if (DataTemp == 2)
  1356. {
  1357. textBox_RunInfo_Dir.Text = "停止";
  1358. }
  1359. //助力档位
  1360. DataTemp = (ushort)(Data[13]);
  1361. if (DataTemp == 0x33)
  1362. {
  1363. textBox_RunInfo_GearSt.Text = "SMART";
  1364. //comboBox_GearSt.SelectedIndex = 5;
  1365. //comboBox_OBC_SetGearST.SelectedIndex = 5;
  1366. }
  1367. else if (DataTemp == 0x22)
  1368. {
  1369. textBox_RunInfo_GearSt.Text = "WALK";
  1370. //comboBox_GearSt.SelectedIndex = 6;
  1371. //comboBox_OBC_SetGearST.SelectedIndex = 6;
  1372. }
  1373. else
  1374. {
  1375. string[] Gears = new string[5] { "OFF", "ECO", "NORM", "SPORT", "TURBO" };
  1376. textBox_RunInfo_GearSt.Text = Gears[DataTemp];
  1377. //comboBox_GearSt.SelectedIndex = DataTemp;
  1378. //comboBox_OBC_SetGearST.SelectedIndex = DataTemp;
  1379. }
  1380. //大灯状态
  1381. DataTemp = (ushort)(Data[14]);
  1382. if (DataTemp == 0xF0)
  1383. {
  1384. textBox_RunInfo_LightSwitch.Text = "OFF";
  1385. //comboBox_LightSwitch.SelectedIndex = 1;
  1386. //comboBox_OBC_LightSw.SelectedIndex = 1;
  1387. }
  1388. else if (DataTemp == 0xF1)
  1389. {
  1390. textBox_RunInfo_LightSwitch.Text = "ON";
  1391. //comboBox_LightSwitch.SelectedIndex = 0;
  1392. //comboBox_OBC_LightSw.SelectedIndex = 0;
  1393. }
  1394. //剩余电量
  1395. DataTemp = (ushort)(Data[15]);
  1396. textBox_RunInfo_SOC.Text = Convert.ToString(DataTemp) + " %";
  1397. //剩余续航里程
  1398. DataTemp = (ushort)(Data[17] * 256 + Data[16]);
  1399. if ((DataTemp == 0xEEEE) || (DataTemp == 0xFFFF))
  1400. {
  1401. textBox_RunInfo_Range.Text = "---";
  1402. }
  1403. else
  1404. {
  1405. textBox_RunInfo_Range.Text = Convert.ToString(DataTemp) + " km";
  1406. }
  1407. //预留(显示力矩Reg),空2bytes
  1408. DataTemp = (ushort)(Data[19] * 256 + Data[18]);
  1409. textBox_TorqueReg.Text = Convert.ToString(DataTemp);
  1410. //平均功耗
  1411. DataTemp = (ushort)(Data[20]);
  1412. textBox_RunInfo_AvgPower.Text = Convert.ToString(DataTemp * 10) + " mAh/km";
  1413. //PCB温度
  1414. DataTemp = (ushort)(Data[21]);
  1415. textBox_RunInfo_T_PCB.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1416. Class_MotorTemp.String = textBox_RunInfo_T_PCB.Text;
  1417. Class_MotorTemp.Data = DataTemp - 40;
  1418. //绕组温度
  1419. DataTemp = (ushort)(Data[22]);
  1420. textBox_RunInfo_T_Coil.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1421. //MCU温度
  1422. DataTemp = (ushort)(Data[23]);
  1423. textBox_RunInfo_T_MCU.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1424. //单次里程
  1425. DataTemp = (ushort)(Data[25] * 256 + Data[24]);
  1426. textBox_RunInfo_Trip.Text = ((float)DataTemp / 10f).ToString("0.0") + " km";
  1427. //单次时间
  1428. DataTemp = (ushort)(Data[27] * 256 + Data[26]);
  1429. textBox_RunInfo_Trip_Time.Text = Convert.ToString(DataTemp) + " s";
  1430. //RSV1
  1431. DataTemp = (ushort)(Data[28]);
  1432. textBox_RunInfo_RSV1.Text = Convert.ToString(DataTemp);
  1433. //RSV2
  1434. DataTemp = (ushort)(Data[29]);
  1435. textBox_RunInfo_RSV2.Text = Convert.ToString(DataTemp);
  1436. //RSV3
  1437. DataTemp = (ushort)(Data[30]);
  1438. textBox_RunInfo_RSV3.Text = Convert.ToString(DataTemp);
  1439. //GearBox
  1440. DataTemp = (ushort)(Data[31]);
  1441. textBox_RunInfo_GearBox.Text = Convert.ToString(DataTemp);
  1442. //数据保存
  1443. RunInfoAutoSave();
  1444. }));
  1445. }
  1446. break;
  1447. }
  1448. case 0x1104://故障码
  1449. {
  1450. unchecked
  1451. {
  1452. this.Invoke((EventHandler)(delegate
  1453. {
  1454. MC_ErrorCode_Refresh = true;
  1455. textBox_ErrorCode.Text =
  1456. Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() +
  1457. Convert.ToString(Data[2], 16).PadLeft(2, '0').ToUpper() +
  1458. Convert.ToString(Data[1], 16).PadLeft(2, '0').ToUpper() +
  1459. Convert.ToString(Data[0], 16).PadLeft(2, '0').ToUpper() +
  1460. "H";
  1461. }));
  1462. }
  1463. break;
  1464. }
  1465. case 0xA903://反馈指令
  1466. {
  1467. unchecked
  1468. {
  1469. this.Invoke((EventHandler)(delegate
  1470. {
  1471. if (ACK_DisFlag == true)
  1472. {
  1473. MessageBoxTimeOut.Show("OK", "反馈指令", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  1474. //关机反馈
  1475. PowerOffAckStatus = true;
  1476. }
  1477. //应答标志置位
  1478. WriteACK = true;
  1479. }));
  1480. }
  1481. break;
  1482. }
  1483. case 0xB226://马达参数
  1484. {
  1485. unchecked
  1486. {
  1487. this.Invoke((EventHandler)(delegate
  1488. {
  1489. richTextBox_MotorParam.Clear();
  1490. for (int i = 0; i < myParams.MotorParam.Count; i++)
  1491. {
  1492. if (i == 6)
  1493. richTextBox_MotorParam.AppendText(myParams.MotorParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1494. else
  1495. richTextBox_MotorParam.AppendText(myParams.MotorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1496. }
  1497. richTextBox_MotorParam.Text = richTextBox_MotorParam.Text.Substring(0, richTextBox_MotorParam.Text.Length - 2);
  1498. }));
  1499. }
  1500. break;
  1501. }
  1502. case 0xB31A://整车信息
  1503. {
  1504. unchecked
  1505. {
  1506. this.Invoke((EventHandler)(delegate
  1507. {
  1508. richTextBox_BikeParam.Clear();
  1509. for (int i = 0; i < myParams.BikeParam.Count; i++)
  1510. {
  1511. if (i == 9)
  1512. richTextBox_BikeParam.AppendText(myParams.BikeParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1513. else
  1514. richTextBox_BikeParam.AppendText(myParams.BikeParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1515. //更新前后灯参数
  1516. if (i == 8)
  1517. {
  1518. comboBox_TailLightMode.SelectedIndex = ((Data[2 * i + 1] >> 4) & 0x0F) - 1;
  1519. comboBox_TailLightVol.SelectedIndex = ((Data[2 * i + 1] & 0x0F) == 6) ? 0 : 1;
  1520. comboBox_FrontLightVol.SelectedIndex = ((Data[2 * i] & 0x0F) == 6) ? 0 : 1;
  1521. }
  1522. //更新开关机参数
  1523. else if (i == 11)
  1524. {
  1525. textBox_PowerOnDelay.Text = Convert.ToString((Data[2 * i + 1] >> 4) & 0x0F);
  1526. textBox_PowerOffDelay.Text = Convert.ToString(Data[2 * i + 1] & 0x0F);
  1527. textBox_AutoPowerOff.Text = Convert.ToString(Data[2 * i]);
  1528. }
  1529. }
  1530. richTextBox_BikeParam.Text = richTextBox_BikeParam.Text.Substring(0, richTextBox_BikeParam.Text.Length - 2);
  1531. }));
  1532. }
  1533. break;
  1534. }
  1535. case 0xB420://控制器参数
  1536. {
  1537. unchecked
  1538. {
  1539. this.Invoke((EventHandler)(delegate
  1540. {
  1541. richTextBox_ControlParam.Clear();
  1542. for (int i = 0; i < myParams.ControlParam.Count; i++)
  1543. {
  1544. richTextBox_ControlParam.AppendText(myParams.ControlParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1545. //转把定速巡航
  1546. if (i == 13)
  1547. {
  1548. comboBox_Bike_CCS.SelectedIndex = ((Data[2 * i]) == 0xAA) ? 1 : 2;
  1549. }
  1550. }
  1551. richTextBox_ControlParam.Text = richTextBox_ControlParam.Text.Substring(0, richTextBox_ControlParam.Text.Length - 2);
  1552. }));
  1553. }
  1554. break;
  1555. }
  1556. case 0xB528://传感器参数
  1557. {
  1558. unchecked
  1559. {
  1560. this.Invoke((EventHandler)(delegate
  1561. {
  1562. richTextBox_SensorParam.Clear();
  1563. for (int i = 0; i < myParams.SensorParam.Count; i++)
  1564. {
  1565. richTextBox_SensorParam.AppendText(myParams.SensorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1566. }
  1567. richTextBox_SensorParam.Text = richTextBox_SensorParam.Text.Substring(0, richTextBox_SensorParam.Text.Length - 2);
  1568. //更新生产模式页面传感器零点和标定值
  1569. textBox_FacModeSensorADC0.Text = (Data[9] * 256 + Data[8]).ToString();
  1570. textBox_FacModeSensorADC1.Text = (Data[15] * 256 + Data[14]).ToString();
  1571. textBox_FacModeSensorADC2.Text = (Data[19] * 256 + Data[18]).ToString();
  1572. textBox_FacModeSensorADC3.Text = (Data[23] * 256 + Data[22]).ToString();
  1573. textBox_FacModeSensorADC4.Text = (Data[27] * 256 + Data[26]).ToString();
  1574. WriteACK = true;
  1575. }));
  1576. }
  1577. break;
  1578. }
  1579. case 0xB64C://助力参数
  1580. {
  1581. unchecked
  1582. {
  1583. this.Invoke((EventHandler)(delegate
  1584. {
  1585. richTextBox_AssistParam.Clear();
  1586. int index_1 = myParams.AssistParam.IndexOf("转矩曲线.a");
  1587. int index_2 = myParams.AssistParam.IndexOf("踏频曲线.d");
  1588. int index_3 = myParams.AssistParam.IndexOf("踏频助力加速限制");
  1589. int index_4 = myParams.AssistParam.IndexOf("踏频助力电流步进");
  1590. for (int i = 0; i < myParams.AssistParam.Count; i++)
  1591. {
  1592. if (i < index_1) //数据占用2bytes
  1593. {
  1594. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1595. }
  1596. else if (i <= index_2) //数据占用4bytes
  1597. {
  1598. 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])) + ", ");
  1599. }
  1600. else if (i < index_3) //数据占用2bytes,无符号
  1601. {
  1602. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1603. }
  1604. else if (i <= index_4) //数据占用2bytes,有符号
  1605. {
  1606. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1607. }
  1608. else //数据占用2bytes,无符号
  1609. {
  1610. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1611. }
  1612. }
  1613. richTextBox_AssistParam.Text = richTextBox_AssistParam.Text.Substring(0, richTextBox_AssistParam.Text.Length - 2);
  1614. }));
  1615. }
  1616. break;
  1617. }
  1618. case 0xB74C://历史记录
  1619. {
  1620. unchecked
  1621. {
  1622. this.Invoke((EventHandler)(delegate
  1623. {
  1624. richTextBox_Record.Clear();
  1625. for (int i = 0; i < myParams.Record.Count; i++)
  1626. {
  1627. richTextBox_Record.AppendText(myParams.Record[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  1628. }
  1629. richTextBox_Record.Text = richTextBox_Record.Text.Substring(0, richTextBox_Record.Text.Length - 2);
  1630. }));
  1631. }
  1632. break;
  1633. }
  1634. case 0xB83A://调试参数
  1635. {
  1636. unchecked
  1637. {
  1638. this.Invoke((EventHandler)(delegate
  1639. {
  1640. richTextBox_DebugParam.Clear();
  1641. for (int i = 0; i < myParams.DebugParam.Count; i++)
  1642. {
  1643. richTextBox_DebugParam.AppendText(myParams.DebugParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1644. }
  1645. richTextBox_DebugParam.Text = richTextBox_DebugParam.Text.Substring(0, richTextBox_DebugParam.Text.Length - 2);
  1646. }));
  1647. }
  1648. break;
  1649. }
  1650. case 0xB904://存储标志
  1651. {
  1652. unchecked
  1653. {
  1654. this.Invoke((EventHandler)(delegate
  1655. {
  1656. ushort Flag = 0;
  1657. Flag = (ushort)(Data[1] * 256 + Data[0]);//EEPROM存储标志
  1658. if (Flag == 0)
  1659. {
  1660. radioButton_EE_SaveNo.Checked = true;
  1661. radioButton_EE_SaveYes.Checked = false;
  1662. }
  1663. else
  1664. {
  1665. radioButton_EE_SaveNo.Checked = false;
  1666. radioButton_EE_SaveYes.Checked = true;
  1667. }
  1668. Flag = (ushort)(Data[3] * 256 + Data[2]);//SIP偏移校准存储标志
  1669. if (Flag == 0)
  1670. {
  1671. radioButton_SIP_SaveNo.Checked = true;
  1672. radioButton_SIP_SaveYes.Checked = false;
  1673. }
  1674. else
  1675. {
  1676. radioButton_SIP_SaveNo.Checked = false;
  1677. radioButton_SIP_SaveYes.Checked = true;
  1678. }
  1679. }));
  1680. }
  1681. break;
  1682. }
  1683. case 0x1240://电机版本信息
  1684. {
  1685. unchecked
  1686. {
  1687. this.Invoke((EventHandler)(delegate
  1688. {
  1689. //电机型号
  1690. textBox_Model.Text = "";
  1691. textBox_OBC_ReadModel.Text = "";
  1692. textBox_FacModeName.Text = "";
  1693. for (ushort i = 0; i < 16; i++)
  1694. {
  1695. if (Data[i] == 0x2E)
  1696. {
  1697. break;
  1698. }
  1699. textBox_Model.Text += ((char)Data[i]).ToString();
  1700. textBox_OBC_ReadModel.Text += ((char)Data[i]).ToString();
  1701. textBox_FacModeName.Text += ((char)Data[i]).ToString();
  1702. }
  1703. Class_Motor_Ver.Mode = textBox_Model.Text;
  1704. //电机SN
  1705. textBox_SN.Text = "";
  1706. textBox_OBC_ReadSN.Text = "";
  1707. textBox_FacModeNum.Text = "";
  1708. for (ushort i = 0; i < 16; i++)
  1709. {
  1710. if (Data[16 + i] == 0x2E)
  1711. {
  1712. break;
  1713. }
  1714. textBox_SN.Text += ((char)Data[16 + i]).ToString();
  1715. textBox_OBC_ReadSN.Text += ((char)Data[16 + i]).ToString();
  1716. textBox_FacModeNum.Text += ((char)Data[16 + i]).ToString();
  1717. }
  1718. Class_Motor_Ver.SN = textBox_SN.Text;
  1719. //电机HW
  1720. textBox_HW.Text = "";
  1721. textBox_OBC_ReadHW.Text = "";
  1722. textBox_FacModeHW.Text = "";
  1723. for (ushort i = 0; i < 8; i++)//前8位:硬件板号
  1724. {
  1725. if (Data[32 + i] == 0x2E)
  1726. {
  1727. break;
  1728. }
  1729. else if (Data[32 + i] == 'r')
  1730. {
  1731. Data[32 + i] = (byte)'.';
  1732. break;
  1733. }
  1734. string strTemp = "";
  1735. strTemp = ((char)Data[32 + i]).ToString();
  1736. textBox_HW.Text += strTemp;
  1737. textBox_OBC_ReadHW.Text += strTemp;
  1738. textBox_FacModeHW.Text += strTemp;
  1739. }
  1740. for (ushort i = 0; i < 4; i++)//9-12位:单片机型号
  1741. {
  1742. if (Data[40 + i] == 0x2E)
  1743. {
  1744. break;
  1745. }
  1746. else if (Data[40 + i] == 'r')
  1747. {
  1748. Data[40 + i] = (byte)'.';
  1749. break;
  1750. }
  1751. string strTemp = "";
  1752. strTemp = ((char)Data[40 + i]).ToString();
  1753. textBox_HW.Text += strTemp;
  1754. textBox_OBC_ReadHW.Text += strTemp;
  1755. textBox_FacModeHW.Text += strTemp;
  1756. }
  1757. for (ushort i = 0; i < 4; i++)//13-16位:单片机ID
  1758. {
  1759. string strTemp = "";
  1760. strTemp = Convert.ToString(Data[44 + i], 16).PadLeft(2, '0').ToUpper();
  1761. textBox_HW.Text += strTemp;
  1762. textBox_OBC_ReadHW.Text += strTemp;
  1763. textBox_FacModeHW.Text += strTemp;
  1764. }
  1765. Class_Motor_Ver.HW = textBox_HW.Text;
  1766. //电机FW
  1767. textBox_FW.Text = "";
  1768. textBox_OBC_ReadFW.Text = "";
  1769. textBox_FacModeFW.Text = "";
  1770. for (ushort i = 0; i < 16; i++)
  1771. {
  1772. if ((Data[48 + i] == 0x2E) || (Data[48 + i] == 0x00) || (Data[48 + i] == (char)' '))
  1773. {
  1774. break;
  1775. }
  1776. if (Data[48 + i] == 'r')
  1777. {
  1778. Data[48 + i] = (byte)'.';
  1779. }
  1780. textBox_FW.Text += ((char)Data[48 + i]).ToString();
  1781. textBox_OBC_ReadFW.Text += ((char)Data[48 + i]).ToString();
  1782. textBox_FacModeFW.Text += ((char)Data[48 + i]).ToString();
  1783. }
  1784. Class_Motor_Ver.FW = textBox_FW.Text;
  1785. }));
  1786. }
  1787. break;
  1788. }
  1789. case 0xA610://自定义1
  1790. {
  1791. unchecked
  1792. {
  1793. this.Invoke((EventHandler)(delegate
  1794. {
  1795. textBox_User1.Text = "";
  1796. for (ushort i = 0; i < 16; i++)
  1797. {
  1798. if (Data[i] == 0x2E)
  1799. {
  1800. break;
  1801. }
  1802. textBox_User1.Text += ((char)Data[i]).ToString();
  1803. }
  1804. }));
  1805. }
  1806. break;
  1807. }
  1808. case 0xA710://自定义2
  1809. {
  1810. unchecked
  1811. {
  1812. this.Invoke((EventHandler)(delegate
  1813. {
  1814. textBox_User2.Text = "";
  1815. for (ushort i = 0; i < 16; i++)
  1816. {
  1817. if (Data[i] == 0x2E)
  1818. {
  1819. break;
  1820. }
  1821. textBox_User2.Text += ((char)Data[i]).ToString();
  1822. }
  1823. }));
  1824. }
  1825. break;
  1826. }
  1827. case 0xA810://自定义1
  1828. {
  1829. unchecked
  1830. {
  1831. this.Invoke((EventHandler)(delegate
  1832. {
  1833. textBox_User3.Text = "";
  1834. for (ushort i = 0; i < 16; i++)
  1835. {
  1836. if (Data[i] == 0x2E)
  1837. {
  1838. break;
  1839. }
  1840. textBox_User3.Text += ((char)Data[i]).ToString();
  1841. }
  1842. }));
  1843. }
  1844. break;
  1845. }
  1846. case 0xA520://生产信息
  1847. {
  1848. unchecked
  1849. {
  1850. this.Invoke((EventHandler)(delegate
  1851. {
  1852. //生产商
  1853. textBox_MAC.Text = "";
  1854. for (ushort i = 0; i < 8; i++)
  1855. {
  1856. if (Data[i] == 0x2E)
  1857. {
  1858. break;
  1859. }
  1860. textBox_MAC.Text += ((char)Data[i]).ToString();
  1861. }
  1862. //生产地
  1863. textBox_MACAdd.Text = "";
  1864. for (ushort i = 0; i < 8; i++)
  1865. {
  1866. if (Data[8 + i] == 0x2E)
  1867. {
  1868. break;
  1869. }
  1870. textBox_MACAdd.Text += ((char)Data[8 + i]).ToString();
  1871. }
  1872. //生产日期
  1873. textBox_MACDate.Text = "";
  1874. for (ushort i = 0; i < 8; i++)
  1875. {
  1876. if (Data[16 + i] == 0x2E)
  1877. {
  1878. break;
  1879. }
  1880. textBox_MACDate.Text += ((char)Data[16 + i]).ToString();
  1881. }
  1882. //品牌信息
  1883. textBox_PP.Text = "";
  1884. for (ushort i = 0; i < 8; i++)
  1885. {
  1886. if (Data[24 + i] == 0x2E)
  1887. {
  1888. break;
  1889. }
  1890. textBox_PP.Text += ((char)Data[24 + i]).ToString();
  1891. }
  1892. }));
  1893. }
  1894. break;
  1895. }
  1896. case 0xA408://密钥
  1897. {
  1898. unchecked
  1899. {
  1900. this.Invoke((EventHandler)(delegate
  1901. {
  1902. textBox_Key.Text = "";
  1903. for (ushort i = 0; i < 8; i++)
  1904. {
  1905. textBox_Key.Text += ((char)Data[i]).ToString();
  1906. }
  1907. }));
  1908. }
  1909. break;
  1910. }
  1911. case 0xAB09://存储器数据
  1912. case 0xAB0A:
  1913. case 0xAB0B:
  1914. case 0xAB0C:
  1915. {
  1916. unchecked
  1917. {
  1918. this.Invoke((EventHandler)(delegate
  1919. {
  1920. long ByteNum = 0;
  1921. ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
  1922. if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
  1923. {
  1924. for (int i = 0; i < ByteNum; i++)
  1925. {
  1926. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  1927. }
  1928. }
  1929. else //根据设置自动转换10进制显示
  1930. {
  1931. if (checkBox_ReadRanFlash_ChangeFormat.Checked == true) //10进制显示
  1932. {
  1933. switch (ByteNum)
  1934. {
  1935. case 1:
  1936. {
  1937. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8]) + ", ");
  1938. break;
  1939. }
  1940. case 2:
  1941. {
  1942. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8)) + ", ");
  1943. break;
  1944. }
  1945. case 3:
  1946. {
  1947. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16)) + ", ");
  1948. break;
  1949. }
  1950. case 4:
  1951. {
  1952. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24)) + ", ");
  1953. break;
  1954. }
  1955. default:
  1956. {
  1957. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  1958. break;
  1959. }
  1960. }
  1961. }
  1962. else //16进制显示
  1963. {
  1964. switch (ByteNum)
  1965. {
  1966. case 1:
  1967. {
  1968. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8], 16).PadLeft(2, '0').ToUpper() + ", ");
  1969. break;
  1970. }
  1971. case 2:
  1972. {
  1973. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8), 16).PadLeft(4, '0').ToUpper() + ", ");
  1974. break;
  1975. }
  1976. case 3:
  1977. {
  1978. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16), 16).PadLeft(6, '0').ToUpper() + ", ");
  1979. break;
  1980. }
  1981. case 4:
  1982. {
  1983. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24), 16).PadLeft(8, '0').ToUpper() + ", ");
  1984. break;
  1985. }
  1986. default:
  1987. {
  1988. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  1989. break;
  1990. }
  1991. }
  1992. }
  1993. }
  1994. }));
  1995. }
  1996. break;
  1997. }
  1998. case 0xAB88://故障日志
  1999. {
  2000. unchecked
  2001. {
  2002. this.Invoke((EventHandler)(delegate
  2003. {
  2004. //电机存储的故障日志,一包128字节包含2条故障日志
  2005. var ErrorLogSaveInfo1 = new MC_ErrorLogSaveInfo_Struct_t();
  2006. var ErrorLogSaveInfo2 = new MC_ErrorLogSaveInfo_Struct_t();
  2007. ErrorLogSaveInfo1 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 8);
  2008. ErrorLogSaveInfo2 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 72);
  2009. //数据显示
  2010. ErrorLogDisplay(ErrorLogSaveInfo1, ErrorLogSaveInfo2);
  2011. }));
  2012. }
  2013. break;
  2014. }
  2015. case 0x1401://在线检测结果
  2016. {
  2017. unchecked
  2018. {
  2019. this.Invoke((EventHandler)(delegate
  2020. {
  2021. textBox_Online.Text = Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() + "H";
  2022. }));
  2023. }
  2024. break;
  2025. }
  2026. case 0x1510://骑行历史信息
  2027. {
  2028. unchecked
  2029. {
  2030. this.Invoke((EventHandler)(delegate
  2031. {
  2032. long DataTemp32;
  2033. //ODO里程
  2034. DataTemp32 = (long)((Data[3] << 24) + (Data[2] << 16) + (Data[1] << 8) + Data[0]);
  2035. textBox_OBC_ODO_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  2036. textBox_ODO_KM.Text = DataTemp32.ToString();
  2037. //ODO时间
  2038. DataTemp32 = (long)((Data[7] << 24) + (Data[6] << 16) + (Data[5] << 8) + Data[4]);
  2039. if (DataTemp32 >= 60 * 100000)
  2040. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  2041. else
  2042. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  2043. textBox_ODO_TIME.Text = DataTemp32.ToString();
  2044. //TRIP里程
  2045. DataTemp32 = (long)((Data[11] << 24) + (Data[10] << 16) + (Data[9] << 8) + Data[8]);
  2046. textBox_OBC_TRIP_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  2047. textBox_TRIP_KM.Text = DataTemp32.ToString();
  2048. //TRIP时间
  2049. DataTemp32 = (long)((Data[15] << 24) + (Data[14] << 16) + (Data[13] << 8) + Data[12]);
  2050. if (DataTemp32 >= 60 * 100000)
  2051. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  2052. else
  2053. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  2054. textBox_TRIP_TIME.Text = DataTemp32.ToString();
  2055. }));
  2056. }
  2057. break;
  2058. }
  2059. case 0x1720://客户信息
  2060. {
  2061. unchecked
  2062. {
  2063. this.Invoke((EventHandler)(delegate
  2064. {
  2065. //软件标识
  2066. textBox_SP.Text = "";
  2067. textBox_OBC_ReadSP.Text = "";
  2068. textBox_FacModeSP.Text = "";
  2069. for (ushort i = 0; i < 23; i++)
  2070. {
  2071. if (Data[i] == 'r')
  2072. {
  2073. Data[i] = (byte)'.';
  2074. }
  2075. textBox_SP.Text += ((char)Data[i]).ToString();
  2076. textBox_OBC_ReadSP.Text += ((char)Data[i]).ToString();
  2077. textBox_FacModeSP.Text += ((char)Data[i]).ToString();
  2078. }
  2079. //Git提交版本信息
  2080. textBox_FacModeGit.Text = "";
  2081. for (ushort i = 0; i < 9; i++)
  2082. {
  2083. textBox_SP.Text += ((char)Data[23 + i]).ToString();
  2084. textBox_FacModeGit.Text += ((char)Data[23 + i]).ToString();
  2085. }
  2086. Class_Motor_Ver.Special = textBox_SP.Text;
  2087. }));
  2088. }
  2089. break;
  2090. }
  2091. case 0xBA20: //调试信息
  2092. {
  2093. unchecked
  2094. {
  2095. this.Invoke((EventHandler)(delegate
  2096. {
  2097. MC_DebugInfo_Refresh = true;
  2098. //系统状态机
  2099. DataTemp = (short)(Data[0]);
  2100. textBox_DebugInfo_SysFun.Text = Convert.ToString(DataTemp);
  2101. //二层状态机
  2102. DataTemp = (short)(Data[1]);
  2103. textBox_DebugInfo_SecondFun.Text = Convert.ToString(DataTemp);
  2104. //电机状态机
  2105. DataTemp = (short)(Data[2]);
  2106. textBox_DebugInfo_MotorFun.Text = Convert.ToString(DataTemp);
  2107. //助力状态机
  2108. DataTemp = (short)(Data[3]);
  2109. textBox_DebugInfo_AssistFun.Text = Convert.ToString(DataTemp);
  2110. //IdRef
  2111. DataTemp = (short)(Data[5] * 256 + Data[4]);
  2112. textBox_DebugInfo_IdRef.Text = Convert.ToString(DataTemp);
  2113. //IqRef
  2114. DataTemp = (short)(Data[7] * 256 + Data[6]);
  2115. textBox_DebugInfo_IqRef.Text = Convert.ToString(DataTemp);
  2116. //UdRef
  2117. DataTemp = (short)(Data[9] * 256 + Data[8]);
  2118. textBox_DebugInfo_UdRef.Text = Convert.ToString(DataTemp);
  2119. //UqRef
  2120. DataTemp = (short)(Data[11] * 256 + Data[10]);
  2121. textBox_DebugInfo_UqRef.Text = Convert.ToString(DataTemp);
  2122. //瞬时力矩
  2123. DataTemp = (short)(Data[13] * 256 + Data[12]);
  2124. textBox_DebugInfo_TorquePu.Text = Convert.ToString(DataTemp);
  2125. //时间滤波力矩
  2126. DataTemp = (short)(Data[15] * 256 + Data[14]);
  2127. textBox_DebugInfo_TorqueFil.Text = Convert.ToString(DataTemp);
  2128. //踏频滤波力矩
  2129. DataTemp = (short)(Data[17] * 256 + Data[16]);
  2130. textBox_DebugInfo_TorqueCadence.Text = Convert.ToString(DataTemp);
  2131. //IdFdb
  2132. DataTemp = (short)(Data[19] * 256 + Data[18]);
  2133. textBox_DebugInfo_IdFdb.Text = Convert.ToString(DataTemp);
  2134. //IqFdb
  2135. DataTemp = (short)(Data[21] * 256 + Data[20]);
  2136. textBox_DebugInfo_IqFdb.Text = Convert.ToString(DataTemp);
  2137. //助力输出
  2138. DataTemp = (short)(Data[23] * 256 + Data[22]);
  2139. textBox_DebugInfo_AssistOut.Text = Convert.ToString(DataTemp);
  2140. //转把百分比
  2141. DataTemp = (short)(Data[25] * 256 + Data[24]);
  2142. textBox_DebugInfo_ThrottlePer.Text = Convert.ToString(DataTemp);
  2143. //数据保存
  2144. RunInfoAutoSave();
  2145. }));
  2146. }
  2147. break;
  2148. }
  2149. case 0xBB20: //产品标签信息
  2150. {
  2151. unchecked
  2152. {
  2153. this.Invoke((EventHandler)(delegate
  2154. {
  2155. //产品标签
  2156. textBox_TagInfo.Text = "";
  2157. for (ushort i = 0; i < 32; i++)
  2158. {
  2159. textBox_TagInfo.Text += ((char)Data[i]).ToString();
  2160. }
  2161. }));
  2162. }
  2163. break;
  2164. }
  2165. case 0xBC20: //内阻校正信息
  2166. {
  2167. unchecked
  2168. {
  2169. this.Invoke((EventHandler)(delegate
  2170. {
  2171. //内阻1
  2172. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  2173. textBox_MOS_R1.Text = Convert.ToString(uData16);
  2174. //内阻2
  2175. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  2176. textBox_MOS_R2.Text = Convert.ToString(uData16);
  2177. //内阻3
  2178. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  2179. textBox_MOS_R3.Text = Convert.ToString(uData16);
  2180. //K1
  2181. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  2182. textBox_MOS_K1.Text = Convert.ToString(uData16);
  2183. //K2
  2184. uData16 = (ushort)(Data[9] * 256 + Data[8]);
  2185. textBox_MOS_K2.Text = Convert.ToString(uData16);
  2186. //K3
  2187. uData16 = (ushort)(Data[11] * 256 + Data[10]);
  2188. textBox_MOS_K3.Text = Convert.ToString(uData16);
  2189. //K4
  2190. uData16 = (ushort)(Data[13] * 256 + Data[12]);
  2191. textBox_MOS_K4.Text = Convert.ToString(uData16);
  2192. //K5
  2193. uData16 = (ushort)(Data[15] * 256 + Data[14]);
  2194. textBox_MOS_K5.Text = Convert.ToString(uData16);
  2195. }));
  2196. }
  2197. break;
  2198. }
  2199. case 0xBD20: //整车信息2
  2200. {
  2201. unchecked
  2202. {
  2203. this.Invoke((EventHandler)(delegate
  2204. {
  2205. richTextBox_BikeParam2.Clear();
  2206. for (int i = 0; i < myParams.BikeParam2.Count; i++)
  2207. {
  2208. richTextBox_BikeParam2.AppendText(myParams.BikeParam2[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  2209. }
  2210. richTextBox_BikeParam2.Text = richTextBox_BikeParam2.Text.Substring(0, richTextBox_BikeParam2.Text.Length - 2);
  2211. }));
  2212. }
  2213. break;
  2214. }
  2215. case 0xBE20: //用户骑行参数
  2216. {
  2217. unchecked
  2218. {
  2219. this.Invoke((EventHandler)(delegate
  2220. {
  2221. richTextBox_UsrRidesParam.Clear();
  2222. for (int i = 0; i < myParams.UsrRideParam.Count; i++)
  2223. {
  2224. richTextBox_UsrRidesParam.AppendText(myParams.UsrRideParam[i] + "=" + Convert.ToString(Data[i]) + ", ");
  2225. }
  2226. richTextBox_UsrRidesParam.Text = richTextBox_UsrRidesParam.Text.Substring(0, richTextBox_UsrRidesParam.Text.Length - 2);
  2227. }));
  2228. }
  2229. break;
  2230. }
  2231. case 0xBF58: //位置传感器校准值
  2232. {
  2233. unchecked
  2234. {
  2235. this.Invoke((EventHandler)(delegate
  2236. {
  2237. string[] str1 = new string[42];
  2238. double[] error1 = new double[42];
  2239. //更新校准数据
  2240. for (int i = 0; i < 42; i++)
  2241. {
  2242. double data1 = (Data[4 + i * 2] + (Data[4 + i * 2 + 1] << 8)) / 32767.0 * 360;
  2243. error1[i] = data1 - (60 * (i % 6) + 60);
  2244. if (error1[i] < -180)
  2245. {
  2246. error1[i] = error1[i] + 360;
  2247. }
  2248. str1[i] = data1.ToString("F2");
  2249. AngledataRecord[i] = str1[i];
  2250. }
  2251. for (int i = 0; i < 7; i++)
  2252. for (int j = 0; j < 6; j++)
  2253. {
  2254. dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = str1[6 * i + j];
  2255. }
  2256. //计算偏差最小值、最大值和平均值
  2257. //Array.ConvertAll(error1, Math.Abs);
  2258. textBox_AngleDiffMin.Text = error1.Min().ToString("F2");
  2259. textBox_AngleDiffMax.Text = error1.Max().ToString("F2");
  2260. textBox_AngleDiffAvg.Text = error1.Average().ToString("F2");
  2261. //计算零点偏差
  2262. double tmp1 = ((Int16)(Data[0] + (Data[1] << 8))) / 32767.0 * 360;
  2263. textBox_AngleZeroInit.Text = tmp1.ToString("F2");
  2264. double tmp2 = ((Int16)(Data[2] + (Data[3] << 8))) / 32767.0 * 360;
  2265. textBox_AngleZeroCur.Text = tmp2.ToString("F2");
  2266. double tmp3 = (tmp2 - tmp1);
  2267. textBox_AngleZeroDiff.Text = tmp3.ToString("F2");
  2268. }));
  2269. }
  2270. break;
  2271. }
  2272. case 0xC008: //故障日志地址
  2273. {
  2274. unchecked
  2275. {
  2276. this.Invoke((EventHandler)(delegate
  2277. {
  2278. uint Addr_Begin = 0, Addr_End = 0;
  2279. Addr_Begin = (uint)((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]);
  2280. Addr_End = (uint)((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]);
  2281. textBox_LogAddrBegin.Text = Convert.ToString(Addr_Begin, 16).PadLeft(8, '0').ToUpper();
  2282. textBox_LogAddrEnd.Text = Convert.ToString(Addr_End, 16).PadLeft(8, '0').ToUpper();
  2283. }));
  2284. }
  2285. break;
  2286. }
  2287. case 0xC109: //Boot版本信息
  2288. {
  2289. BootInfo = "";
  2290. for (ushort i = 0; i < 9; i++)
  2291. {
  2292. BootInfo += ((char)Data[i]).ToString();
  2293. }
  2294. break;
  2295. }
  2296. case 0xC142: //功能配置表
  2297. {
  2298. unchecked
  2299. {
  2300. this.Invoke((EventHandler)(delegate
  2301. {
  2302. //块编号
  2303. ushort Num = (ushort)(Data[1] * 256 + Data[0]);
  2304. comboBox_FunSet_BlockNum.SelectedIndex = Num - 1;
  2305. //显示数据
  2306. for (int i = 0; i < 64; i++)
  2307. {
  2308. dataGridView_FunSet.Rows[i / 8].Cells[i % 8 + 1].Value = Data[i + 2].ToString();
  2309. }
  2310. }));
  2311. }
  2312. break;
  2313. }
  2314. case 0xC220: //定制编号
  2315. {
  2316. unchecked
  2317. {
  2318. this.Invoke((EventHandler)(delegate
  2319. {
  2320. //定制编号
  2321. textBox_UserNum.Text = "";
  2322. for (ushort i = 0; i < 32; i++)
  2323. {
  2324. textBox_UserNum.Text += ((char)Data[i]).ToString();
  2325. }
  2326. }));
  2327. }
  2328. break;
  2329. }
  2330. default:
  2331. {
  2332. break;
  2333. }
  2334. }
  2335. //存储器导出数据显示
  2336. if ((CmdTemp & 0xFF00) == 0xAB00)
  2337. {
  2338. unchecked
  2339. {
  2340. this.Invoke((EventHandler)(delegate
  2341. {
  2342. long ByteNum = 0;
  2343. ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
  2344. if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
  2345. {
  2346. for (int i = 0; i < ByteNum; i++)
  2347. {
  2348. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  2349. }
  2350. }
  2351. }));
  2352. }
  2353. }
  2354. }
  2355. #endregion
  2356. #region 解析BMS广播的命令
  2357. else if (ID == 0x720)
  2358. {
  2359. switch (CmdTemp)
  2360. {
  2361. case 0x1010://BMS运行信息
  2362. {
  2363. unchecked
  2364. {
  2365. this.Invoke((EventHandler)(delegate
  2366. {
  2367. BMS_RunInfo_Refresh = true;
  2368. richTextBox_OBC_BMS_RunInfo.Clear();
  2369. //电压
  2370. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  2371. richTextBox_OBC_BMS_RunInfo.AppendText("电压:" + Convert.ToString(uData16) + " mV" + "\r\n");
  2372. //电流
  2373. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  2374. richTextBox_OBC_BMS_RunInfo.AppendText("电流:" + Convert.ToString(uData16) + " mA" + "\r\n");
  2375. //剩余容量
  2376. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  2377. richTextBox_OBC_BMS_RunInfo.AppendText("剩余容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  2378. //满充容量
  2379. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  2380. richTextBox_OBC_BMS_RunInfo.AppendText("满充容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  2381. //电芯温度
  2382. richTextBox_OBC_BMS_RunInfo.AppendText("电芯温度:" + Convert.ToString((int)(Data[8] - 40) + " ℃" + "\r\n"));
  2383. //剩余电量
  2384. richTextBox_OBC_BMS_RunInfo.AppendText("剩余电量:" + Convert.ToString(Data[9]) + " %" + "\r\n");
  2385. //电池状态
  2386. richTextBox_OBC_BMS_RunInfo.AppendText("电池状态:" + Convert.ToString(Data[10], 16).PadLeft(2, '0').ToUpper() + " H" + "\r\n");
  2387. //SOH
  2388. richTextBox_OBC_BMS_RunInfo.AppendText("电池寿命:" + Convert.ToString(Data[11]) + " %" + "\r\n");
  2389. //循环次数
  2390. richTextBox_OBC_BMS_RunInfo.AppendText("循环次数:" + Convert.ToString((ushort)(Data[13] * 256 + Data[12])) + " 次");
  2391. }));
  2392. }
  2393. break;
  2394. }
  2395. default: break;
  2396. }
  2397. }
  2398. #endregion
  2399. #region 解析电机发送OBC的命令
  2400. else if (ID == 0x713)
  2401. {
  2402. switch (CmdTemp)
  2403. {
  2404. case 0x5408://电机用户参数
  2405. {
  2406. unchecked
  2407. {
  2408. this.Invoke((EventHandler)(delegate
  2409. {
  2410. richTextBox_OBC_ReadUserInfo.Clear();
  2411. //默认周长
  2412. richTextBox_OBC_ReadUserInfo.AppendText("默认周长:" + Convert.ToString((int)Data[0]) + " cm" + "\r\n");
  2413. //启动模式
  2414. richTextBox_OBC_ReadUserInfo.AppendText("启动模式:" + ((Data[1] == 0x01) ? "柔和" : (Data[1] == 0x02) ? "正常" : (Data[1] == 0x03) ? "强劲" : "无效") + "\r\n");
  2415. comboBox_OBC_StartMode.SelectedIndex = Data[1] - 1;
  2416. //限速
  2417. richTextBox_OBC_ReadUserInfo.AppendText("限速:" + Convert.ToString(Data[2]) + " km/h" + "\r\n");
  2418. //周长微调
  2419. numericUpDown_OBC_WheelAdj.Value = (int)(Data[3] > 128 ? (Data[3] - 256) : Data[3]);
  2420. richTextBox_OBC_ReadUserInfo.AppendText("周长微调:" + Convert.ToString(numericUpDown_OBC_WheelAdj.Value) + " cm" + "\r\n");
  2421. //助力方案
  2422. richTextBox_OBC_ReadUserInfo.AppendText("助力方案:" + Convert.ToString(Data[4]) + "\r\n");
  2423. comboBox_OBC_AssistFunc.SelectedIndex = Data[4] - 1;
  2424. //关机时间
  2425. richTextBox_OBC_ReadUserInfo.AppendText("关机时间:" + Convert.ToString(Data[5]) + " min" + "\r\n");
  2426. numericUpDown_OBC_OffTime.Value = (int)Data[5];
  2427. //限速微调
  2428. numericUpDown_OBC_SpeedLimitAdj.Value = (int)(Data[6] > 128 ? (Data[6] - 256) : Data[6]);
  2429. richTextBox_OBC_ReadUserInfo.AppendText("限速微调:" + Convert.ToString(numericUpDown_OBC_SpeedLimitAdj.Value) + " km/h" + "\r\n");
  2430. //定速巡航
  2431. comboBox_OBC_BikeCCS.SelectedIndex = (Data[7] == 0xAA) ? 1 : 2;
  2432. richTextBox_OBC_ReadUserInfo.AppendText("转把巡航:" + comboBox_OBC_BikeCCS.Text + "\r\n");
  2433. }));
  2434. }
  2435. break;
  2436. }
  2437. case 0x5303://电机应答反馈
  2438. {
  2439. unchecked
  2440. {
  2441. this.Invoke((EventHandler)(delegate
  2442. {
  2443. MessageBoxTimeOut.Show("OK", "反馈指令", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  2444. }));
  2445. }
  2446. break;
  2447. }
  2448. case 0x5620: //用户骑行参数
  2449. {
  2450. unchecked
  2451. {
  2452. this.Invoke((EventHandler)(delegate
  2453. {
  2454. richTextBox_UsrRidesParam.Clear();
  2455. for (int i = 0; i < myParams.UsrRideParam.Count; i++)
  2456. {
  2457. richTextBox_UsrRidesParam.AppendText(myParams.UsrRideParam[i] + "=" + Convert.ToString(Data[i]) + ", ");
  2458. }
  2459. richTextBox_UsrRidesParam.Text = richTextBox_UsrRidesParam.Text.Substring(0, richTextBox_UsrRidesParam.Text.Length - 2);
  2460. }));
  2461. }
  2462. break;
  2463. }
  2464. default: break;
  2465. }
  2466. }
  2467. #endregion
  2468. }
  2469. private void DataRevToString(ushort CmdTemp, byte[] Data)
  2470. {
  2471. CmdRevStrTemp = "";
  2472. CmdRevStrTemp += Convert.ToString(CmdTemp >> 8, 16).PadLeft(2, '0').ToUpper() + " ";
  2473. CmdRevStrTemp += Convert.ToString(CmdTemp & 0xFF, 16).PadLeft(2, '0').ToUpper() + " ";
  2474. ushort len = (ushort)(CmdTemp & 0x00FF);
  2475. for (int i = 0; i < len ; i++)
  2476. {
  2477. CmdRevStrTemp += Convert.ToString(Data[i], 16).PadLeft(2, '0').ToUpper() + " ";
  2478. }
  2479. }
  2480. #endregion
  2481. /// <summary>
  2482. /// 端口连接或断开
  2483. /// </summary>
  2484. private void PortConnect()
  2485. {
  2486. bool result = false;
  2487. if (连接ToolStripMenuItem.Text == "连接")
  2488. {
  2489. result = mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, 连接开机ToolStripMenuItem.Checked, 识别通讯盒ToolStripMenuItem.Checked);
  2490. if (result)
  2491. {
  2492. toolStripComboBox_ComNum.Enabled = false;
  2493. toolStripComboBox_Baudrate.Enabled = false;
  2494. 刷新ToolStripMenuItem.Enabled = false;
  2495. 连接ToolStripMenuItem.Text = "断开";
  2496. 连接ToolStripMenuItem.Checked = true;
  2497. label_COM_Sta.Text = toolStripComboBox_ComNum.Text + "已连接," + toolStripComboBox_Baudrate.Text;
  2498. label_PortStatus.BackColor = Color.Green;
  2499. }
  2500. }
  2501. else if (连接ToolStripMenuItem.Text == "断开")
  2502. {
  2503. checkBox_OBC_StartSetGearSt.Checked = false;
  2504. checkBox_OBC_StartReadBMS.Checked = false;
  2505. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2506. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  2507. toolStripComboBox_ComNum.Enabled = true;
  2508. toolStripComboBox_Baudrate.Enabled = true;
  2509. 刷新ToolStripMenuItem.Enabled = true;
  2510. 连接ToolStripMenuItem.Text = "连接";
  2511. 连接ToolStripMenuItem.Checked = false;
  2512. label_COM_Sta.Text = "连接状态:未连接";
  2513. label_PortStatus.BackColor = Color.Red;
  2514. }
  2515. }
  2516. /// <summary>
  2517. /// 端口连接事件
  2518. /// </summary>
  2519. /// <param name="sender"></param>
  2520. /// <param name="e"></param>
  2521. private void 连接ToolStripMenuItem_Click(object sender, System.EventArgs e)
  2522. {
  2523. PortConnect();
  2524. }
  2525. /// <summary>
  2526. /// 端口号刷新事件
  2527. /// </summary>
  2528. /// <param name="sender"></param>
  2529. /// <param name="e"></param>
  2530. private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
  2531. {
  2532. toolStripComboBox_ComNum.Items.Clear();
  2533. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  2534. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
  2535. }
  2536. /// <summary>
  2537. /// 存储标志修改事件
  2538. /// </summary>
  2539. /// <param name="sender"></param>
  2540. /// <param name="e"></param>
  2541. private void 写入存储ToolStripMenuItem_Click(object sender, EventArgs e)
  2542. {
  2543. if (写入存储ToolStripMenuItem.Checked)
  2544. {
  2545. EnterForm1.ShowDialog();
  2546. try
  2547. {
  2548. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  2549. {
  2550. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  2551. {
  2552. 写入存储ToolStripMenuItem.Checked = false;
  2553. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  2554. }
  2555. else
  2556. {
  2557. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2558. }
  2559. }
  2560. else
  2561. {
  2562. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2563. }
  2564. }
  2565. catch (Exception)
  2566. {
  2567. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2568. }
  2569. }
  2570. else
  2571. {
  2572. 写入存储ToolStripMenuItem.Checked = true;
  2573. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  2574. }
  2575. }
  2576. /// <summary>
  2577. /// 1s定时器
  2578. /// </summary>
  2579. /// <param name="sender"></param>
  2580. /// <param name="e"></param>
  2581. private void timer_1s_Tick(object sender, EventArgs e)
  2582. {
  2583. //时间更新
  2584. label_SystemTime.Text = "系统时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2585. //MC_Runinfo超时清除
  2586. if (MC_RunInfo_Refresh == false)
  2587. {
  2588. MC_RunInfo_Refresh_Cnt++;
  2589. if (MC_RunInfo_Refresh_Cnt > 10)//5s
  2590. {
  2591. MC_RunInfo_Clear();
  2592. MC_RunInfo_Refresh_Cnt = 0;
  2593. }
  2594. }
  2595. else
  2596. {
  2597. MC_RunInfo_Refresh_Cnt = 0;
  2598. }
  2599. MC_RunInfo_Refresh = false;
  2600. //MC_Debuginfo超时清除
  2601. if (MC_DebugInfo_Refresh == false)
  2602. {
  2603. MC_DebugInfo_Refresh_Cnt++;
  2604. if (MC_DebugInfo_Refresh_Cnt > 10)//5s
  2605. {
  2606. MC_DebugInfo_Clear();
  2607. MC_DebugInfo_Refresh_Cnt = 0;
  2608. }
  2609. }
  2610. else
  2611. {
  2612. MC_DebugInfo_Refresh_Cnt = 0;
  2613. }
  2614. MC_DebugInfo_Refresh = false;
  2615. //BMS_RunInfo超时清除
  2616. if (BMS_RunInfo_Refresh == false)
  2617. {
  2618. BMS_RunInfo_Refresh_Cnt++;
  2619. if (BMS_RunInfo_Refresh_Cnt > 10)//5s
  2620. {
  2621. richTextBox_OBC_BMS_RunInfo.Clear();
  2622. BMS_RunInfo_Refresh_Cnt = 0;
  2623. }
  2624. }
  2625. else
  2626. {
  2627. BMS_RunInfo_Refresh_Cnt = 0;
  2628. }
  2629. BMS_RunInfo_Refresh = false;
  2630. //故障码超时清除
  2631. if (MC_ErrorCode_Refresh == false)
  2632. {
  2633. MC_ErrorCode_Refresh_Cnt++;
  2634. if (MC_ErrorCode_Refresh_Cnt > 10)//5s
  2635. {
  2636. textBox_ErrorCode.Text = "---";
  2637. MC_ErrorCode_Refresh_Cnt = 0;
  2638. }
  2639. }
  2640. else
  2641. {
  2642. MC_ErrorCode_Refresh_Cnt = 0;
  2643. }
  2644. MC_ErrorCode_Refresh = false;
  2645. //CDL连接超时
  2646. if (识别通讯盒ToolStripMenuItem.Checked)
  2647. {
  2648. if (mySerialProcess.CDL_Online_Flag == false)
  2649. {
  2650. mySerialProcess.CDL_OnlineCheck_Cnt++;
  2651. if (mySerialProcess.CDL_OnlineCheck_Cnt > 1)//1s
  2652. {
  2653. timer_500ms.Enabled = false;
  2654. MessageBox.Show("连接失败!", "提示");
  2655. timer_500ms.Enabled = true;
  2656. //关闭串口
  2657. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  2658. toolStripComboBox_ComNum.Enabled = true;
  2659. toolStripComboBox_Baudrate.Enabled = true;
  2660. 刷新ToolStripMenuItem.Enabled = true;
  2661. 连接ToolStripMenuItem.Text = "连接";
  2662. 连接ToolStripMenuItem.Checked = false;
  2663. label_COM_Sta.Text = "连接状态:未连接";
  2664. label_PortStatus.BackColor = Color.Red;
  2665. }
  2666. }
  2667. }
  2668. //OBC定时发送设置档位
  2669. if (checkBox_OBC_StartSetGearSt.Checked == true)
  2670. {
  2671. var CtrlCode = new byte[2];
  2672. if (comboBox_OBC_SetGearST.SelectedIndex == 5)//档位
  2673. CtrlCode[0] = 0x33;
  2674. else if (comboBox_OBC_SetGearST.SelectedIndex == 6)//档位
  2675. CtrlCode[0] = 0x22;
  2676. else
  2677. CtrlCode[0] = (byte)comboBox_OBC_SetGearST.SelectedIndex;
  2678. if (comboBox_OBC_LightSw.SelectedIndex == 0)//车灯
  2679. CtrlCode[1] = 0xF1;
  2680. else
  2681. CtrlCode[1] = 0xF0;
  2682. if (!mySerialProcess.SendCmdWithoutNotice((ushort)0x731, (byte)0x0C, (ushort)0x3002, CtrlCode))
  2683. {
  2684. checkBox_OBC_StartSetGearSt.Checked = false;
  2685. }
  2686. }
  2687. //OBC定时发送查询电池
  2688. if (checkBox_OBC_StartReadBMS.Checked == true)
  2689. {
  2690. if (!mySerialProcess.SendCmd((ushort)0x732, (byte)0x11, (ushort)0x5000, null))
  2691. {
  2692. checkBox_OBC_StartReadBMS.Checked = false;
  2693. }
  2694. }
  2695. //定时读取存储器
  2696. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  2697. {
  2698. var Address = new byte[4];
  2699. UInt32 Address_Begin;
  2700. UInt32 Addres_End;
  2701. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  2702. richTextBox_RamFlasgData.Clear();
  2703. do
  2704. {
  2705. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  2706. {
  2707. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2708. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2709. continue;
  2710. }
  2711. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  2712. {
  2713. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2714. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2715. continue;
  2716. }
  2717. else
  2718. {
  2719. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  2720. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2721. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  2722. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2723. if (Addres_End < Address_Begin)
  2724. {
  2725. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2726. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2727. continue;
  2728. }
  2729. else
  2730. {
  2731. var SendByte = new byte[8];
  2732. SendByte[0] = (byte)(Address_Begin >> 24);
  2733. SendByte[1] = (byte)(Address_Begin >> 16);
  2734. SendByte[2] = (byte)(Address_Begin >> 8);
  2735. SendByte[3] = (byte)(Address_Begin);
  2736. SendByte[4] = (byte)(Addres_End >> 24);
  2737. SendByte[5] = (byte)(Addres_End >> 16);
  2738. SendByte[6] = (byte)(Addres_End >> 8);
  2739. SendByte[7] = (byte)(Addres_End);
  2740. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte))
  2741. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2742. }
  2743. }
  2744. } while (false);
  2745. }
  2746. //写入参数等待计时
  2747. ACK_WaitCnt++;
  2748. }
  2749. /// <summary>
  2750. /// 运行信息清除
  2751. /// </summary>
  2752. private void MC_RunInfo_Clear()
  2753. {
  2754. foreach (Control c in tabPage_RunInfo.Controls)
  2755. {
  2756. if ((c is TextBox))
  2757. {
  2758. if (c.Name != textBox_ErrorCode.ToString())
  2759. c.Text = "---";
  2760. }
  2761. }
  2762. }
  2763. /// <summary>
  2764. /// 调试信息清除
  2765. /// </summary>
  2766. private void MC_DebugInfo_Clear()
  2767. {
  2768. foreach (Control c in tabPage_DebugInfo.Controls)
  2769. {
  2770. if ((c is TextBox))
  2771. {
  2772. if (c.Name != textBox_ErrorCode.ToString())
  2773. c.Text = "---";
  2774. }
  2775. }
  2776. }
  2777. /// <summary>
  2778. /// 读取马达参数
  2779. /// </summary>
  2780. /// <param name="sender"></param>
  2781. /// <param name="e"></param>
  2782. private void button_Read_MotorParam_Click(object sender, EventArgs e)
  2783. {
  2784. richTextBox_MotorParam.Clear();
  2785. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null);
  2786. }
  2787. /// <summary>
  2788. /// 写入马达参数
  2789. /// </summary>
  2790. /// <param name="sender"></param>
  2791. /// <param name="e"></param>
  2792. private void button_Write_Click(object sender, EventArgs e)
  2793. {
  2794. var ConfigParam = new byte[40];
  2795. for (int i = 0; i < 40; i++)
  2796. ConfigParam[i] = 0;
  2797. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2798. short wDataTemp = 0;
  2799. ushort DataTemp = 0;
  2800. string[] strDataTemp = richTextBox_MotorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2801. try
  2802. {
  2803. for (int i = 0; i < strDataTemp.Length; i++)
  2804. {
  2805. if (i == 6)
  2806. {
  2807. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  2808. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  2809. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  2810. }
  2811. else
  2812. {
  2813. DataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2814. ConfigParam[2 * i + 2] = (byte)DataTemp;
  2815. ConfigParam[2 * i + 3] = (byte)(DataTemp >> 8);
  2816. }
  2817. }
  2818. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B28, ConfigParam);
  2819. }
  2820. catch (Exception)
  2821. {
  2822. timer_500ms.Enabled = false;
  2823. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2824. timer_500ms.Enabled = true;
  2825. }
  2826. }
  2827. /// <summary>
  2828. /// 读取整车信息
  2829. /// </summary>
  2830. /// <param name="sender"></param>
  2831. /// <param name="e"></param>
  2832. private void button_ReadBikeParam_Click(object sender, EventArgs e)
  2833. {
  2834. richTextBox_BikeParam.Clear();
  2835. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null);
  2836. }
  2837. /// <summary>
  2838. /// 写入整车信息
  2839. /// </summary>
  2840. /// <param name="sender"></param>
  2841. /// <param name="e"></param>
  2842. private void button_WriteBikeParam_Click(object sender, EventArgs e)
  2843. {
  2844. var ConfigParam = new byte[28];
  2845. for (int i = 0; i < 28; i++)
  2846. ConfigParam[i] = 0;
  2847. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2848. string[] strDataTemp = richTextBox_BikeParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2849. try
  2850. {
  2851. for (int i = 0; i < strDataTemp.Length; i++)
  2852. {
  2853. short wDataTemp = 0;
  2854. //前后灯参数修改
  2855. if (i == 8)
  2856. {
  2857. wDataTemp |= (short)((comboBox_TailLightMode.SelectedIndex + 1) << 12); //Bit15~Bit12:尾灯模式
  2858. wDataTemp |= (short)((comboBox_TailLightVol.SelectedIndex == 0 ? 6 : 12) << 8); //Bit11~Bit8:尾灯电压
  2859. wDataTemp |= (short)(comboBox_FrontLightVol.SelectedIndex == 0 ? 6 : 12); //Bit7~Bit0:前灯电压
  2860. }
  2861. //开关机参数
  2862. else if (i == 11)
  2863. {
  2864. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOnDelay.Text) << 12);
  2865. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOffDelay.Text) << 8);
  2866. wDataTemp |= (short)(Convert.ToInt16(textBox_AutoPowerOff.Text));
  2867. }
  2868. else
  2869. {
  2870. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  2871. }
  2872. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  2873. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  2874. }
  2875. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D1C, ConfigParam);
  2876. }
  2877. catch (Exception)
  2878. {
  2879. timer_500ms.Enabled = false;
  2880. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2881. timer_500ms.Enabled = true;
  2882. }
  2883. }
  2884. /// <summary>
  2885. /// 读取控制器参数
  2886. /// </summary>
  2887. /// <param name="sender"></param>
  2888. /// <param name="e"></param>
  2889. private void button_ReadControlParam_Click(object sender, EventArgs e)
  2890. {
  2891. richTextBox_ControlParam.Clear();
  2892. comboBox_Bike_CCS.SelectedIndex = 0;
  2893. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
  2894. }
  2895. /// <summary>
  2896. /// 写入控制器参数
  2897. /// </summary>
  2898. /// <param name="sender"></param>
  2899. /// <param name="e"></param>
  2900. private void button_WriteControlParam_Click(object sender, EventArgs e)
  2901. {
  2902. var ConfigParam = new byte[34];
  2903. for (int i = 0; i < 34; i++)
  2904. ConfigParam[i] = 0;
  2905. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2906. ushort uwDataTemp = 0;
  2907. string[] strDataTemp = richTextBox_ControlParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2908. try
  2909. {
  2910. for (int i = 0; i < strDataTemp.Length; i++)
  2911. {
  2912. if (i == 13)
  2913. {
  2914. uwDataTemp = (comboBox_Bike_CCS.SelectedIndex == 1) ? (ushort)0x00AA : (ushort)0x0000;
  2915. }
  2916. else
  2917. {
  2918. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2919. }
  2920. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2921. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2922. }
  2923. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3F22, ConfigParam);
  2924. }
  2925. catch (Exception)
  2926. {
  2927. timer_500ms.Enabled = false;
  2928. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2929. timer_500ms.Enabled = true;
  2930. }
  2931. }
  2932. /// <summary>
  2933. /// 读取助力参数
  2934. /// </summary>
  2935. /// <param name="sender"></param>
  2936. /// <param name="e"></param>
  2937. private void button_ReadAssistParam_Click(object sender, EventArgs e)
  2938. {
  2939. var ConfigParam = new byte[4];
  2940. int AssistNum = 0;
  2941. try
  2942. {
  2943. AssistNum = Convert.ToInt32(comboBox_AssistTorque.Text);
  2944. ConfigParam[0] = (byte)(AssistNum & 0xFF);
  2945. ConfigParam[1] = (byte)(AssistNum >> 8);
  2946. AssistNum = Convert.ToInt32(comboBox_AssistCadence.Text);
  2947. ConfigParam[2] = (byte)(AssistNum & 0xFF);
  2948. ConfigParam[3] = (byte)(AssistNum >> 8);
  2949. richTextBox_AssistParam.Clear();
  2950. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam);
  2951. }
  2952. catch (Exception)
  2953. {
  2954. timer_500ms.Enabled = false;
  2955. MessageBox.Show("请选择助力参数编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2956. timer_500ms.Enabled = true;
  2957. }
  2958. }
  2959. /// <summary>
  2960. /// 写入助力参数
  2961. /// </summary>
  2962. /// <param name="sender"></param>
  2963. /// <param name="e"></param>
  2964. private void button_WriteAssistParam_Click(object sender, EventArgs e)
  2965. {
  2966. var ConfigParam = new byte[80];
  2967. for (int i = 0; i < 80; i++)
  2968. ConfigParam[i] = 0;
  2969. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2970. long lDataTemp = 0;
  2971. string[] strDataTemp = richTextBox_AssistParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2972. int index_1 = 0, index_2 = 0;
  2973. try
  2974. {
  2975. for (int i = 0; i < strDataTemp.Length; i++)
  2976. {
  2977. if (strDataTemp[i].Split('=')[0] == "转矩曲线.a")
  2978. {
  2979. index_1 = i;
  2980. break;
  2981. }
  2982. }
  2983. for (int i = 0; i < strDataTemp.Length; i++)
  2984. {
  2985. if (strDataTemp[i].Split('=')[0] == "踏频曲线.d")
  2986. {
  2987. index_2 = i;
  2988. break;
  2989. }
  2990. }
  2991. for (int i = 0; i < strDataTemp.Length; i++)
  2992. {
  2993. lDataTemp = Convert.ToInt32(strDataTemp[i].Split('=')[1]);
  2994. if (i < index_1)
  2995. {
  2996. ConfigParam[2 * i + 4] = (byte)lDataTemp;
  2997. ConfigParam[2 * i + 5] = (byte)(lDataTemp >> 8);
  2998. }
  2999. else if (i <= index_2)
  3000. {
  3001. ConfigParam[4 * i - 4] = (byte)lDataTemp;
  3002. ConfigParam[4 * i - 3] = (byte)(lDataTemp >> 8);
  3003. ConfigParam[4 * i - 2] = (byte)(lDataTemp >> 16);
  3004. ConfigParam[4 * i - 1] = (byte)(lDataTemp >> 24);
  3005. }
  3006. else
  3007. {
  3008. ConfigParam[2 * i + 20] = (byte)lDataTemp;
  3009. ConfigParam[2 * i + 21] = (byte)(lDataTemp >> 8);
  3010. }
  3011. }
  3012. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4450, ConfigParam);
  3013. }
  3014. catch (Exception)
  3015. {
  3016. timer_500ms.Enabled = false;
  3017. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3018. timer_500ms.Enabled = true;
  3019. }
  3020. }
  3021. /// <summary>
  3022. /// 读取调试参数
  3023. /// </summary>
  3024. /// <param name="sender"></param>
  3025. /// <param name="e"></param>
  3026. private void button_ReadDebugParam_Click(object sender, EventArgs e)
  3027. {
  3028. richTextBox_DebugParam.Clear();
  3029. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  3030. }
  3031. /// <summary>
  3032. /// 写入调试参数
  3033. /// </summary>
  3034. /// <param name="sender"></param>
  3035. /// <param name="e"></param>
  3036. private void button_WriteDebugParam_Click(object sender, EventArgs e)
  3037. {
  3038. var ConfigParam = new byte[60];
  3039. for (int i = 0; i < 60; i++)
  3040. ConfigParam[i] = 0;
  3041. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  3042. ushort uwDataTemp = 0;
  3043. string[] strDataTemp = richTextBox_DebugParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  3044. try
  3045. {
  3046. for (int i = 0; i < strDataTemp.Length; i++)
  3047. {
  3048. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  3049. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3050. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3051. }
  3052. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam);
  3053. }
  3054. catch (Exception)
  3055. {
  3056. timer_500ms.Enabled = false;
  3057. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3058. timer_500ms.Enabled = true;
  3059. }
  3060. }
  3061. /// <summary>
  3062. /// 读取历史
  3063. /// </summary>
  3064. /// <param name="sender"></param>
  3065. /// <param name="e"></param>
  3066. private void button_ReadRecord_Click(object sender, EventArgs e)
  3067. {
  3068. richTextBox_Record.Clear();
  3069. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null);
  3070. }
  3071. /// <summary>
  3072. /// 读取传感器参数
  3073. /// </summary>
  3074. /// <param name="sender"></param>
  3075. /// <param name="e"></param>
  3076. private void button_ReadSensorParam_Click(object sender, EventArgs e)
  3077. {
  3078. richTextBox_SensorParam.Clear();
  3079. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3080. }
  3081. /// <summary>
  3082. /// 写入力矩传感器标定值
  3083. /// </summary>
  3084. /// <param name="sender"></param>
  3085. /// <param name="e"></param>
  3086. private void button_Write_Cal_Click(object sender, EventArgs e)
  3087. {
  3088. var ConfigParam = new byte[4];
  3089. for (int i = 0; i < 4; i++)
  3090. ConfigParam[i] = 0;
  3091. ushort uwDataTemp = 0;
  3092. try
  3093. {
  3094. uwDataTemp = Convert.ToUInt16(comboBox_TorqueSet.Text);//负载序号
  3095. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  3096. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  3097. uwDataTemp = (ushort)(decimal.Parse(textBox_Load.Text) * 10); ;//负载值0.1Nm
  3098. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  3099. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  3100. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  3101. }
  3102. catch (Exception)
  3103. {
  3104. timer_500ms.Enabled = false;
  3105. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3106. timer_500ms.Enabled = true;
  3107. }
  3108. }
  3109. /// <summary>
  3110. /// 写入传感器参数
  3111. /// </summary>
  3112. /// <param name="sender"></param>
  3113. /// <param name="e"></param>
  3114. private void button_WriteSensorParam_Click(object sender, EventArgs e)
  3115. {
  3116. var ConfigParam = new byte[14];
  3117. for (int i = 0; i < 14; i++)
  3118. ConfigParam[i] = 0;
  3119. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  3120. ushort uwDataTemp = 0;
  3121. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  3122. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  3123. int index = 0;
  3124. try
  3125. {
  3126. for (int i = 0; i < strDataTemp.Length; i++)
  3127. {
  3128. if (strDataTemp[i].Split('=')[0] == "力矩传感器踏频脉冲数")
  3129. {
  3130. index = i;
  3131. break;
  3132. }
  3133. }
  3134. for (int i = 0; i < (strDataTemp.Length - index); i++)
  3135. {
  3136. uwDataTemp = Convert.ToUInt16(strDataTemp[i + index].Split('=')[1]);
  3137. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3138. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3139. }
  3140. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x420E, ConfigParam);
  3141. }
  3142. catch (Exception)
  3143. {
  3144. timer_500ms.Enabled = false;
  3145. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3146. timer_500ms.Enabled = true;
  3147. }
  3148. }
  3149. /// <summary>
  3150. /// 写入型号
  3151. /// </summary>
  3152. /// <param name="sender"></param>
  3153. /// <param name="e"></param>
  3154. private void button_WriteModel_Click(object sender, EventArgs e)
  3155. {
  3156. string Mode = textBox_Model.Text;
  3157. var ModeArray = new byte[16];
  3158. for (ushort i = 0; i < Mode.Length; i++)
  3159. {
  3160. ModeArray[i] = (byte)Mode[i];
  3161. }
  3162. if (Mode.Length < 16)
  3163. {
  3164. ModeArray[Mode.Length] = (byte)'.';
  3165. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  3166. {
  3167. ModeArray[Mode.Length + 1 + i] = 0x20;
  3168. }
  3169. }
  3170. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  3171. }
  3172. /// <summary>
  3173. /// 写入SN
  3174. /// </summary>
  3175. /// <param name="sender"></param>
  3176. /// <param name="e"></param>
  3177. private void button_WriteSN_Click(object sender, EventArgs e)
  3178. {
  3179. string SN = textBox_SN.Text;
  3180. var SNArray = new byte[16];
  3181. for (ushort i = 0; i < SN.Length; i++)
  3182. {
  3183. SNArray[i] = (byte)SN[i];
  3184. }
  3185. if (SN.Length < 16)
  3186. {
  3187. SNArray[SN.Length] = (byte)'.';
  3188. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  3189. {
  3190. SNArray[SN.Length + 1 + i] = 0x20;
  3191. }
  3192. }
  3193. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  3194. }
  3195. /// <summary>
  3196. /// 查询版本信息
  3197. /// </summary>
  3198. /// <param name="sender"></param>
  3199. /// <param name="e"></param>
  3200. private void button_ReadVersion_Click(object sender, EventArgs e)
  3201. {
  3202. textBox_Model.Text = "---";
  3203. textBox_SN.Text = "---";
  3204. textBox_HW.Text = "---";
  3205. textBox_FW.Text = "---";
  3206. textBox_SP.Text = "---";
  3207. textBox_OBC_ReadModel.Text = "---";
  3208. textBox_OBC_ReadSN.Text = "---";
  3209. textBox_OBC_ReadHW.Text = "---";
  3210. textBox_OBC_ReadFW.Text = "---";
  3211. textBox_OBC_ReadSP.Text = "---";
  3212. textBox_FacModeName.Text = "---";
  3213. textBox_FacModeNum.Text = "---";
  3214. textBox_FacModeHW.Text = "---";
  3215. textBox_FacModeFW.Text = "---";
  3216. textBox_FacModeSP.Text = "---";
  3217. Class_Motor_Ver.Mode = "---";
  3218. Class_Motor_Ver.SN = "---";
  3219. Class_Motor_Ver.HW = "---";
  3220. Class_Motor_Ver.FW = "---";
  3221. Class_Motor_Ver.Special = "---";
  3222. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  3223. }
  3224. /// <summary>
  3225. /// 查询自定义1
  3226. /// </summary>
  3227. /// <param name="sender"></param>
  3228. /// <param name="e"></param>
  3229. private void button_ReadUser1_Click(object sender, EventArgs e)
  3230. {
  3231. textBox_User1.Text = "---";
  3232. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null);
  3233. }
  3234. /// <summary>
  3235. /// 查询自定义2
  3236. /// </summary>
  3237. /// <param name="sender"></param>
  3238. /// <param name="e"></param>
  3239. private void button_ReadUser2_Click(object sender, EventArgs e)
  3240. {
  3241. textBox_User2.Text = "---";
  3242. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null);
  3243. }
  3244. /// <summary>
  3245. /// 查询自定义3
  3246. /// </summary>
  3247. /// <param name="sender"></param>
  3248. /// <param name="e"></param>
  3249. private void button_ReadUser3_Click(object sender, EventArgs e)
  3250. {
  3251. textBox_User3.Text = "---";
  3252. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null);
  3253. }
  3254. /// <summary>
  3255. /// 写入自定义字符串1
  3256. /// </summary>
  3257. /// <param name="sender"></param>
  3258. /// <param name="e"></param>
  3259. private void button_WriteUser1_Click(object sender, EventArgs e)
  3260. {
  3261. string User = textBox_User1.Text;
  3262. var UserArray = new byte[16];
  3263. for (ushort i = 0; i < User.Length; i++)
  3264. {
  3265. UserArray[i] = (byte)User[i];
  3266. }
  3267. if (User.Length < 16)
  3268. {
  3269. UserArray[User.Length] = (byte)'.';
  3270. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3271. {
  3272. UserArray[User.Length + 1 + i] = 0x20;
  3273. }
  3274. }
  3275. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1410, UserArray);
  3276. }
  3277. /// <summary>
  3278. /// 写入自定义字符串2
  3279. /// </summary>
  3280. /// <param name="sender"></param>
  3281. /// <param name="e"></param>
  3282. private void button_WriteUser2_Click(object sender, EventArgs e)
  3283. {
  3284. string User = textBox_User2.Text;
  3285. var UserArray = new byte[16];
  3286. for (ushort i = 0; i < User.Length; i++)
  3287. {
  3288. UserArray[i] = (byte)User[i];
  3289. }
  3290. if (User.Length < 16)
  3291. {
  3292. UserArray[User.Length] = (byte)'.';
  3293. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3294. {
  3295. UserArray[User.Length + 1 + i] = 0x20;
  3296. }
  3297. }
  3298. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1610, UserArray);
  3299. }
  3300. /// <summary>
  3301. /// 写入自定义字符串3
  3302. /// </summary>
  3303. /// <param name="sender"></param>
  3304. /// <param name="e"></param>
  3305. private void button_WriteUser3_Click(object sender, EventArgs e)
  3306. {
  3307. string User = textBox_User3.Text;
  3308. var UserArray = new byte[16];
  3309. for (ushort i = 0; i < User.Length; i++)
  3310. {
  3311. UserArray[i] = (byte)User[i];
  3312. }
  3313. if (User.Length < 16)
  3314. {
  3315. UserArray[User.Length] = (byte)'.';
  3316. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3317. {
  3318. UserArray[User.Length + 1 + i] = 0x20;
  3319. }
  3320. }
  3321. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1810, UserArray);
  3322. }
  3323. /// <summary>
  3324. /// 查询生产信息
  3325. /// </summary>
  3326. /// <param name="sender"></param>
  3327. /// <param name="e"></param>
  3328. private void button_ReadMAC_Click(object sender, EventArgs e)
  3329. {
  3330. textBox_MAC.Text = "---";
  3331. textBox_MACAdd.Text = "---";
  3332. textBox_MACDate.Text = "---";
  3333. textBox_PP.Text = "---";
  3334. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null);
  3335. }
  3336. /// <summary>
  3337. /// 写入生产信息
  3338. /// </summary>
  3339. /// <param name="sender"></param>
  3340. /// <param name="e"></param>
  3341. private void button_WriteMac_Click(object sender, EventArgs e)
  3342. {
  3343. var MACArray = new byte[32];
  3344. //填入生产商
  3345. for (ushort i = 0; i < textBox_MAC.Text.Length; i++)
  3346. {
  3347. MACArray[i] = (byte)textBox_MAC.Text[i];
  3348. }
  3349. if (textBox_MAC.Text.Length < 8)
  3350. {
  3351. MACArray[textBox_MAC.Text.Length] = (byte)'.';
  3352. for (ushort i = 0; i < 8 - textBox_MAC.Text.Length - 1; i++)
  3353. {
  3354. MACArray[textBox_MAC.Text.Length + 1 + i] = 0x20;
  3355. }
  3356. }
  3357. //填入生产地
  3358. for (ushort i = 0; i < textBox_MACAdd.Text.Length; i++)
  3359. {
  3360. MACArray[8 + i] = (byte)textBox_MACAdd.Text[i];
  3361. }
  3362. if (textBox_MACAdd.Text.Length < 8)
  3363. {
  3364. MACArray[textBox_MACAdd.Text.Length + 8] = (byte)'.';
  3365. for (ushort i = 0; i < 8 - textBox_MACAdd.Text.Length - 1; i++)
  3366. {
  3367. MACArray[textBox_MACAdd.Text.Length + 1 + i + 8] = 0x20;
  3368. }
  3369. }
  3370. //填入生产日期
  3371. for (ushort i = 0; i < textBox_MACDate.Text.Length; i++)
  3372. {
  3373. MACArray[16 + i] = (byte)textBox_MACDate.Text[i];
  3374. }
  3375. if (textBox_MACDate.Text.Length < 8)
  3376. {
  3377. MACArray[textBox_MACDate.Text.Length + 16] = (byte)'.';
  3378. for (ushort i = 0; i < 8 - textBox_MACDate.Text.Length - 1; i++)
  3379. {
  3380. MACArray[textBox_MACDate.Text.Length + 1 + i + 16] = 0x20;
  3381. }
  3382. }
  3383. //填入品牌
  3384. for (ushort i = 0; i < textBox_PP.Text.Length; i++)
  3385. {
  3386. MACArray[24 + i] = (byte)textBox_PP.Text[i];
  3387. }
  3388. if (textBox_PP.Text.Length < 8)
  3389. {
  3390. MACArray[textBox_PP.Text.Length + 24] = (byte)'.';
  3391. for (ushort i = 0; i < 8 - textBox_PP.Text.Length - 1; i++)
  3392. {
  3393. MACArray[textBox_PP.Text.Length + 1 + i + 24] = 0x20;
  3394. }
  3395. }
  3396. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  3397. }
  3398. /// <summary>
  3399. /// 查询密钥
  3400. /// </summary>
  3401. /// <param name="sender"></param>
  3402. /// <param name="e"></param>
  3403. private void button_ReadKey_Click(object sender, EventArgs e)
  3404. {
  3405. textBox_Key.Text = "---";
  3406. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null);
  3407. }
  3408. /// <summary>
  3409. /// 写入校验密钥
  3410. /// </summary>
  3411. /// <param name="sender"></param>
  3412. /// <param name="e"></param>
  3413. private void button_WriteKey_Click(object sender, EventArgs e)
  3414. {
  3415. string Key = textBox_Key.Text;
  3416. var KeyArray = new byte[8];
  3417. if (Key.Length != 8)
  3418. {
  3419. timer_500ms.Enabled = false;
  3420. MessageBox.Show("请检查字符长度是否为8", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3421. timer_500ms.Enabled = true;
  3422. return;
  3423. }
  3424. for (ushort i = 0; i < Key.Length; i++)
  3425. {
  3426. KeyArray[i] = (byte)Key[i];
  3427. }
  3428. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1108, KeyArray);
  3429. }
  3430. /// <summary>
  3431. /// 查询在线检测结果
  3432. /// </summary>
  3433. /// <param name="sender"></param>
  3434. /// <param name="e"></param>
  3435. private void button_ReadOnLine_Click(object sender, EventArgs e)
  3436. {
  3437. textBox_Online.Text = "---";
  3438. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2100, null);
  3439. }
  3440. /// <summary>
  3441. /// 系统清除
  3442. /// </summary>
  3443. /// <param name="sender"></param>
  3444. /// <param name="e"></param>
  3445. private void button_SystemClear_Click(object sender, EventArgs e)
  3446. {
  3447. var Code = new byte[5];
  3448. Code[0] = (byte)'C';
  3449. Code[1] = (byte)'L';
  3450. Code[2] = (byte)'E';
  3451. Code[3] = (byte)'A';
  3452. Code[4] = (byte)'R';
  3453. timer_500ms.Enabled = false;
  3454. if (MessageBox.Show("系统清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3455. {
  3456. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3457. {
  3458. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3459. {
  3460. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  3461. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3462. }
  3463. }
  3464. }
  3465. timer_500ms.Enabled = true;
  3466. }
  3467. /// <summary>
  3468. /// 参数还原
  3469. /// </summary>
  3470. /// <param name="sender"></param>
  3471. /// <param name="e"></param>
  3472. private void button_Recovery_Click(object sender, EventArgs e)
  3473. {
  3474. var Code = new byte[8];
  3475. Code[0] = (byte)'R';
  3476. Code[1] = (byte)'E';
  3477. Code[2] = (byte)'C';
  3478. Code[3] = (byte)'O';
  3479. Code[4] = (byte)'V';
  3480. Code[5] = (byte)'E';
  3481. Code[6] = (byte)'R';
  3482. Code[7] = (byte)'Y';
  3483. timer_500ms.Enabled = false;
  3484. if (MessageBox.Show("参数还原后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3485. {
  3486. if (MessageBox.Show("请再次确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3487. {
  3488. if (MessageBox.Show("请最后确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3489. {
  3490. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2708, Code);
  3491. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3492. }
  3493. }
  3494. }
  3495. timer_500ms.Enabled = true;
  3496. }
  3497. /// <summary>
  3498. /// 系统复位
  3499. /// </summary>
  3500. /// <param name="sender"></param>
  3501. /// <param name="e"></param>
  3502. private void button_Reset_Click(object sender, EventArgs e)
  3503. {
  3504. var Code_Off = new byte[5];
  3505. var Code_Reset = new byte[5];
  3506. Code_Off[0] = (byte)'O';
  3507. Code_Off[1] = (byte)'F';
  3508. Code_Off[2] = (byte)'F';
  3509. Code_Off[3] = (byte)'.';
  3510. Code_Off[4] = (byte)'.';
  3511. Code_Reset[0] = (byte)'R';
  3512. Code_Reset[1] = (byte)'E';
  3513. Code_Reset[2] = (byte)'S';
  3514. Code_Reset[3] = (byte)'E';
  3515. Code_Reset[4] = (byte)'T';
  3516. timer_500ms.Enabled = false;
  3517. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3518. {
  3519. timer_500ms.Enabled = true;
  3520. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  3521. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  3522. PowerOffAckStatus = false;
  3523. Delay_ms(250);
  3524. int TryCnt = 3;
  3525. while ((TryCnt--) >= 0)
  3526. {
  3527. if (!PowerOffAckStatus)
  3528. {
  3529. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  3530. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  3531. PowerOffAckStatus = false;
  3532. Delay_ms(250);
  3533. }
  3534. else break;
  3535. }
  3536. if (PowerOffAckStatus)
  3537. {
  3538. MessageBoxTimeOut.Show("已关机!", "提示", 3000, MessageBoxButtons.OK, MessageBoxIcon.None);
  3539. }
  3540. else
  3541. {
  3542. timer_500ms.Enabled = false;
  3543. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3544. timer_500ms.Enabled = true;
  3545. }
  3546. }
  3547. timer_500ms.Enabled = true;
  3548. }
  3549. /// <summary>
  3550. /// 记录清除
  3551. /// </summary>
  3552. /// <param name="sender"></param>
  3553. /// <param name="e"></param>
  3554. private void button_ClearLog_Click(object sender, EventArgs e)
  3555. {
  3556. var Code = new byte[9];
  3557. Code[0] = (byte)'L';
  3558. Code[1] = (byte)'O';
  3559. Code[2] = (byte)'G';
  3560. Code[3] = (byte)' ';
  3561. Code[4] = (byte)'C';
  3562. Code[5] = (byte)'L';
  3563. Code[6] = (byte)'E';
  3564. Code[7] = (byte)'A';
  3565. Code[8] = (byte)'R';
  3566. timer_500ms.Enabled = false;
  3567. if (MessageBox.Show("历史记录信息清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3568. {
  3569. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3570. {
  3571. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3572. {
  3573. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3909, Code);
  3574. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3575. }
  3576. }
  3577. }
  3578. timer_500ms.Enabled = true;
  3579. }
  3580. /// <summary>
  3581. /// 打开系统计算器
  3582. /// </summary>
  3583. /// <param name="sender"></param>
  3584. /// <param name="e"></param>
  3585. private void 计算器ToolStripMenuItem_Click(object sender, EventArgs e)
  3586. {
  3587. System.Diagnostics.Process.Start("calc.exe");
  3588. }
  3589. /// <summary>
  3590. ///故障转换和显示
  3591. /// </summary>
  3592. List<string> ErrorInfo = new List<string>{ "过流保护", "低压保护", "过压保护", "堵转保护","过热保护","速度传感器故障","力矩传感器故障","霍尔故障",
  3593. "马达缺相","NTC故障","BMS校验失败","","OBC校验失败","MCU故障","踏频传感器故障","指拨故障","MOS短路","电压异常","","","","","","","","","","","","",
  3594. "",""};
  3595. private string ErrorInfoDisplay(UInt32 Code)
  3596. {
  3597. string Result = "";
  3598. if (Code == 0)
  3599. {
  3600. Result = "无故障";
  3601. }
  3602. else
  3603. {
  3604. for (int i = 0; i < 32; i++)
  3605. {
  3606. if ((Code & 0x01) == 0x01)
  3607. {
  3608. Result += ErrorInfo[i] + " ";
  3609. }
  3610. Code >>= 1;
  3611. }
  3612. }
  3613. return Result;
  3614. }
  3615. /// <summary>
  3616. /// 鼠标滑过故障码显示具体内容
  3617. /// </summary>
  3618. /// <param name="sender"></param>
  3619. /// <param name="e"></param>
  3620. private void textBox_ErrorCode_MouseHover(object sender, EventArgs e)
  3621. {
  3622. // 创建the ToolTip
  3623. ToolTip toolTip1 = new ToolTip();
  3624. // 设置显示样式
  3625. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  3626. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  3627. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  3628. toolTip1.ShowAlways = true;//是否显示提示框
  3629. // 设置伴随的对象.
  3630. string ErrorCode = this.textBox_ErrorCode.Text;
  3631. UInt32 Code = ErrorCode.Contains("H") ? Convert.ToUInt32(ErrorCode.Split('H')[0], 16) : 0;
  3632. toolTip1.SetToolTip(this.textBox_ErrorCode, ErrorInfoDisplay(Code));//设置故障内容显示
  3633. }
  3634. /// <summary>
  3635. /// 数据记录
  3636. /// </summary>
  3637. private void RunInfoAutoSave()
  3638. {
  3639. if (运行信息记录ToolStripMenuItem.Checked == true)
  3640. {
  3641. if (RunInfoSaveFilename == string.Empty)
  3642. {
  3643. return;
  3644. }
  3645. string SaveData = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff").Replace(" ", "_") + " --> ";
  3646. foreach (Control c in tabPage_RunInfo.Controls)
  3647. {
  3648. if (c is TextBox)
  3649. {
  3650. SaveData += c.Text + " , ";
  3651. }
  3652. }
  3653. foreach (Control c in tabPage_DebugInfo.Controls)
  3654. {
  3655. if (c is TextBox)
  3656. {
  3657. SaveData += c.Text + " , ";
  3658. }
  3659. }
  3660. SaveData += "\r\n";
  3661. System.IO.File.AppendAllText(RunInfoSaveFilename, SaveData);//sb.ToString());
  3662. }
  3663. }
  3664. /// <summary>
  3665. /// 打开或关闭数据记录
  3666. /// </summary>
  3667. /// <param name="sender"></param>
  3668. /// <param name="e"></param>
  3669. private void 记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  3670. {
  3671. if (运行信息记录ToolStripMenuItem.Checked == false)
  3672. {
  3673. if (mySerialProcess.mySerial.IsOpen == true)
  3674. {
  3675. RunInfoSaveFilename = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_运行信息" + ".txt";
  3676. System.IO.File.AppendAllText(RunInfoSaveFilename, "时间 --> 车速 , 转速 , 踏频 , 力矩Reg , 力矩 , 踩踏方向 , 电压 , 电流 , 功率 , 电量 , " +
  3677. "PCB温度 , 绕组温度 , MOS温度 , 挡位 , 灯开关 , 续航 , 平均功耗 , 单次里程 , 单次时间 , 故障码 , " +
  3678. "系统状态机 , 二层状态机 , 电机状态机 , 助力状态机 , D轴电流给定 , Q轴电流给定 , D轴电压给定 , Q轴电压给定 , 瞬时力矩 , 时间滤波力矩 , 踏频滤波力矩 , D轴电流反馈 , Q轴电流反馈 , 助力函数输出" + "\r\n");
  3679. MessageBoxTimeOut.Show("开始记录", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  3680. 运行信息记录ToolStripMenuItem.Checked = true;
  3681. }
  3682. else
  3683. {
  3684. timer_500ms.Enabled = false;
  3685. MessageBox.Show("请连接电机", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3686. timer_500ms.Enabled = true;
  3687. }
  3688. }
  3689. else
  3690. {
  3691. 运行信息记录ToolStripMenuItem.Checked = false;
  3692. MessageBoxTimeOut.Show("停止记录", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  3693. }
  3694. }
  3695. /// <summary>
  3696. /// 仪表启动控制档位开关事件
  3697. /// </summary>
  3698. /// <param name="sender"></param>
  3699. /// <param name="e"></param>
  3700. private void checkBox_OBC_StartSetGearSt_CheckedChanged(object sender, EventArgs e)
  3701. {
  3702. if (checkBox_OBC_StartSetGearSt.Checked == true)
  3703. {
  3704. //检查串口是否打开
  3705. if (!mySerialProcess.mySerial.IsOpen)
  3706. {
  3707. timer_500ms.Enabled = false;
  3708. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3709. timer_500ms.Enabled = true;
  3710. checkBox_OBC_StartSetGearSt.Checked = false;
  3711. return;
  3712. }
  3713. //检查是否选择档位和打开车灯
  3714. if ((comboBox_OBC_SetGearST.SelectedIndex == -1) || (comboBox_OBC_LightSw.SelectedIndex == -1))
  3715. {
  3716. timer_500ms.Enabled = false;
  3717. MessageBox.Show("请检查档位设置和大灯开关!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3718. timer_500ms.Enabled = true;
  3719. checkBox_OBC_StartSetGearSt.Checked = false;
  3720. return;
  3721. }
  3722. }
  3723. }
  3724. /// <summary>
  3725. /// OBC查询电机用户参数
  3726. /// </summary>
  3727. /// <param name="sender"></param>
  3728. /// <param name="e"></param>
  3729. private void button_OBC_ReadUserInfo_Click(object sender, EventArgs e)
  3730. {
  3731. richTextBox_OBC_ReadUserInfo.Clear();
  3732. comboBox_OBC_BikeCCS.SelectedIndex = 0;
  3733. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3300, null);
  3734. }
  3735. /// <summary>
  3736. /// OBC设置电机用户参数
  3737. /// </summary>
  3738. /// <param name="sender"></param>
  3739. /// <param name="e"></param>
  3740. private void button_OBC_WriteUserInfo_Click(object sender, EventArgs e)
  3741. {
  3742. var UserInfoCode = new byte[8];
  3743. for (int i = 0; i < UserInfoCode.Length; i++)
  3744. UserInfoCode[i] = 0;
  3745. if (comboBox_OBC_StartMode.SelectedIndex == -1)//检查数据有效性
  3746. {
  3747. timer_500ms.Enabled = false;
  3748. MessageBox.Show("请选择启动模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3749. timer_500ms.Enabled = true;
  3750. return;
  3751. }
  3752. if (comboBox_OBC_AssistFunc.SelectedIndex == -1)//检查数据有效性
  3753. {
  3754. timer_500ms.Enabled = false;
  3755. MessageBox.Show("请选择助力方案!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3756. timer_500ms.Enabled = true;
  3757. return;
  3758. }
  3759. //周长微调
  3760. UserInfoCode[0] = (byte)(int)numericUpDown_OBC_WheelAdj.Value;
  3761. //启动模式
  3762. UserInfoCode[1] = (byte)(comboBox_OBC_StartMode.SelectedIndex + 1);
  3763. //助力方案
  3764. UserInfoCode[2] = (byte)(comboBox_OBC_AssistFunc.SelectedIndex + 1);
  3765. //自动关机时间
  3766. UserInfoCode[3] = (byte)(uint)numericUpDown_OBC_OffTime.Value;
  3767. //限速微调
  3768. UserInfoCode[4] = (byte)(int)numericUpDown_OBC_SpeedLimitAdj.Value;
  3769. //定速巡航开关
  3770. UserInfoCode[5] = (byte)((comboBox_OBC_BikeCCS.SelectedIndex == 1) ? 0xAA : 0x00);
  3771. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3408, UserInfoCode);
  3772. }
  3773. /// <summary>
  3774. /// OBC查询电机版本信息
  3775. /// </summary>
  3776. /// <param name="sender"></param>
  3777. /// <param name="e"></param>
  3778. private void button_OBC_ReadVerInfo_Click(object sender, EventArgs e)
  3779. {
  3780. textBox_Model.Text = "---";
  3781. textBox_SN.Text = "---";
  3782. textBox_HW.Text = "---";
  3783. textBox_FW.Text = "---";
  3784. textBox_SP.Text = "---";
  3785. textBox_OBC_ReadModel.Text = "---";
  3786. textBox_OBC_ReadSN.Text = "---";
  3787. textBox_OBC_ReadHW.Text = "---";
  3788. textBox_OBC_ReadFW.Text = "---";
  3789. textBox_OBC_ReadSP.Text = "---";
  3790. textBox_FacModeName.Text = "---";
  3791. textBox_FacModeNum.Text = "---";
  3792. textBox_FacModeHW.Text = "---";
  3793. textBox_FacModeFW.Text = "---";
  3794. textBox_FacModeSP.Text = "---";
  3795. Class_Motor_Ver.Mode = "---";
  3796. Class_Motor_Ver.SN = "---";
  3797. Class_Motor_Ver.HW = "---";
  3798. Class_Motor_Ver.FW = "---";
  3799. Class_Motor_Ver.Special = "---";
  3800. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  3801. }
  3802. /// <summary>
  3803. /// OBC读取骑行历史
  3804. /// </summary>
  3805. /// <param name="sender"></param>
  3806. /// <param name="e"></param>
  3807. private void button_OBC_ReadRideInfo_Click(object sender, EventArgs e)
  3808. {
  3809. textBox_OBC_TRIP_KM.Text = "";
  3810. textBox_OBC_TRIP_TIME.Text = "";
  3811. textBox_OBC_ODO_KM.Text = "";
  3812. textBox_OBC_ODO_TIME.Text = "";
  3813. textBox_ODO_KM.Text = "---";
  3814. textBox_ODO_TIME.Text = "---";
  3815. textBox_TRIP_KM.Text = "---";
  3816. textBox_TRIP_TIME.Text = "---";
  3817. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3500, null);
  3818. }
  3819. /// <summary>
  3820. /// OBC清除TRIP里程
  3821. /// </summary>
  3822. /// <param name="sender"></param>
  3823. /// <param name="e"></param>
  3824. private void button_OBC_ClearTrip_Click(object sender, EventArgs e)
  3825. {
  3826. var Code = new byte[5];
  3827. Code[0] = (byte)'C';
  3828. Code[1] = (byte)'L';
  3829. Code[2] = (byte)'E';
  3830. Code[3] = (byte)'A';
  3831. Code[4] = (byte)'R';
  3832. timer_500ms.Enabled = false;
  3833. if (MessageBox.Show("TRIP清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3834. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3605, Code);
  3835. timer_500ms.Enabled = true;
  3836. }
  3837. private void checkBox_OBC_StartReadBMS_CheckedChanged(object sender, EventArgs e)
  3838. {
  3839. if (checkBox_OBC_StartReadBMS.Checked == true)
  3840. {
  3841. //检查串口是否打开
  3842. if (!mySerialProcess.mySerial.IsOpen)
  3843. {
  3844. timer_500ms.Enabled = false;
  3845. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3846. timer_500ms.Enabled = true;
  3847. checkBox_OBC_StartReadBMS.Checked = false;
  3848. return;
  3849. }
  3850. }
  3851. }
  3852. /// <summary>
  3853. /// 写入力矩传感器参数
  3854. /// </summary>
  3855. /// <param name="sender"></param>
  3856. /// <param name="e"></param>
  3857. private void button_WriteTqSensorParam_Click(object sender, EventArgs e)
  3858. {
  3859. var ConfigParam = new byte[46];
  3860. for (int i = 0; i < 14; i++)
  3861. ConfigParam[i] = 0;
  3862. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  3863. ushort uwDataTemp = 0;
  3864. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  3865. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  3866. int index = 0;
  3867. try
  3868. {
  3869. for (int i = 0; i < strDataTemp.Length; i++)
  3870. {
  3871. if (strDataTemp[i].Split('=')[0] == "第四阶段转矩点采集值")
  3872. {
  3873. index = i;
  3874. break;
  3875. }
  3876. }
  3877. for (int i = 0; i < (index + 1); i++)
  3878. {
  3879. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  3880. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3881. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3882. }
  3883. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x472E, ConfigParam);
  3884. }
  3885. catch (Exception)
  3886. {
  3887. timer_500ms.Enabled = false;
  3888. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3889. timer_500ms.Enabled = true;
  3890. }
  3891. }
  3892. /// <summary>
  3893. /// 查询存储标志
  3894. /// </summary>
  3895. /// <param name="sender"></param>
  3896. /// <param name="e"></param>
  3897. private void button_ReadSaveFlag_Click(object sender, EventArgs e)
  3898. {
  3899. radioButton_EE_SaveYes.Checked = false;
  3900. radioButton_EE_SaveNo.Checked = false;
  3901. radioButton_SIP_SaveYes.Checked = false;
  3902. radioButton_SIP_SaveNo.Checked = false;
  3903. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null);
  3904. }
  3905. /// <summary>
  3906. /// 写入存储标志
  3907. /// </summary>
  3908. /// <param name="sender"></param>
  3909. /// <param name="e"></param>
  3910. private void button_WriteSaveFlag_Click(object sender, EventArgs e)
  3911. {
  3912. var SaveFlag = new byte[6];
  3913. for (int i = 0; i < 6; i++)
  3914. SaveFlag[i] = 0;
  3915. if ((radioButton_EE_SaveYes.Checked == false) && (radioButton_EE_SaveNo.Checked == false))
  3916. {
  3917. timer_500ms.Enabled = false;
  3918. MessageBox.Show("请选择EEPROM存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3919. timer_500ms.Enabled = true;
  3920. return;
  3921. }
  3922. if ((radioButton_SIP_SaveYes.Checked == false) && (radioButton_SIP_SaveNo.Checked == false))
  3923. {
  3924. timer_500ms.Enabled = false;
  3925. MessageBox.Show("请选择SIP校验存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3926. timer_500ms.Enabled = true;
  3927. return;
  3928. }
  3929. SaveFlag[0] = (byte)((checkBox_SaveYes.Checked) ? 0x01 : 0x00);
  3930. SaveFlag[2] = (byte)(radioButton_EE_SaveYes.Checked ? 0x01 : 0x00);
  3931. SaveFlag[3] = 0;
  3932. SaveFlag[4] = (byte)(radioButton_SIP_SaveYes.Checked ? 0x01 : 0x00);
  3933. SaveFlag[5] = 0;
  3934. timer_500ms.Enabled = false;
  3935. if (MessageBox.Show("确认修改存储标志?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3936. {
  3937. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4906, SaveFlag);
  3938. }
  3939. timer_500ms.Enabled = true;
  3940. }
  3941. /// <summary>
  3942. /// 读取指定地址数据
  3943. /// </summary>
  3944. /// <param name="sender"></param>
  3945. /// <param name="e"></param>
  3946. private void button_ReadRamFlash_Click(object sender, EventArgs e)
  3947. {
  3948. var Address = new byte[4];
  3949. UInt32 Address_Begin;
  3950. UInt32 Addres_End;
  3951. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  3952. richTextBox_RamFlasgData.Clear();
  3953. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  3954. {
  3955. timer_500ms.Enabled = false;
  3956. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3957. timer_500ms.Enabled = true;
  3958. return;
  3959. }
  3960. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  3961. {
  3962. timer_500ms.Enabled = false;
  3963. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3964. timer_500ms.Enabled = true;
  3965. return;
  3966. }
  3967. else
  3968. {
  3969. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  3970. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  3971. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  3972. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  3973. if (Addres_End < Address_Begin)
  3974. {
  3975. timer_500ms.Enabled = false;
  3976. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3977. timer_500ms.Enabled = true;
  3978. return;
  3979. }
  3980. else
  3981. {
  3982. var SendByte = new byte[8];
  3983. SendByte[0] = (byte)(Address_Begin >> 24);
  3984. SendByte[1] = (byte)(Address_Begin >> 16);
  3985. SendByte[2] = (byte)(Address_Begin >> 8);
  3986. SendByte[3] = (byte)(Address_Begin);
  3987. SendByte[4] = (byte)(Addres_End >> 24);
  3988. SendByte[5] = (byte)(Addres_End >> 16);
  3989. SendByte[6] = (byte)(Addres_End >> 8);
  3990. SendByte[7] = (byte)(Addres_End);
  3991. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  3992. }
  3993. }
  3994. }
  3995. /// <summary>
  3996. /// 工作模式选择
  3997. /// </summary>
  3998. /// <param name="sender"></param>
  3999. /// <param name="e"></param>
  4000. private void comboBox_WorkMode_SelectedIndexChanged(object sender, EventArgs e)
  4001. {
  4002. var RunMode = new byte[1];
  4003. if (comboBox_WorkMode.Text == "配置模式")
  4004. RunMode[0] = 0x01;
  4005. else if (comboBox_WorkMode.Text == "调试模式")
  4006. RunMode[0] = 0x02;
  4007. else
  4008. RunMode[0] = 0x00;
  4009. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  4010. }
  4011. /// <summary>
  4012. /// 助力档位选择
  4013. /// </summary>
  4014. /// <param name="sender"></param>
  4015. /// <param name="e"></param>
  4016. private void comboBox_GearSt_SelectedIndexChanged(object sender, EventArgs e)
  4017. {
  4018. var CtrlCode = new byte[2];
  4019. if (comboBox_GearSt.SelectedIndex == 5)//档位
  4020. CtrlCode[0] = 0x33;
  4021. else if (comboBox_GearSt.SelectedIndex == 6)//档位
  4022. CtrlCode[0] = 0x22;
  4023. else
  4024. CtrlCode[0] = (byte)comboBox_GearSt.SelectedIndex;
  4025. if (comboBox_LightSwitch.SelectedIndex == 0)//车灯
  4026. CtrlCode[1] = 0xF1;
  4027. else
  4028. CtrlCode[1] = 0xF0;
  4029. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
  4030. comboBox_OBC_SetGearST.SelectedIndex = comboBox_GearSt.SelectedIndex;
  4031. comboBox_OBC_LightSw.SelectedIndex = comboBox_LightSwitch.SelectedIndex;
  4032. Delay_ms(500);
  4033. //设置百分比
  4034. do
  4035. {
  4036. var PercentCode = new byte[1];
  4037. if (comboBox_GearSt.SelectedIndex == 0) //Off
  4038. {
  4039. PercentCode[0] = 0;
  4040. textBox_MotorSpeedPercent.Text = "0";
  4041. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, PercentCode);
  4042. }
  4043. else if (comboBox_GearSt.SelectedIndex == 6) //Walk
  4044. {
  4045. if (comboBox_WorkMode.SelectedIndex != 0)
  4046. {
  4047. PercentCode[0] = 100;
  4048. textBox_MotorSpeedPercent.Text = "100";
  4049. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, PercentCode);
  4050. }
  4051. }
  4052. } while (false);
  4053. }
  4054. /// <summary>
  4055. /// 仪表档位选择
  4056. /// </summary>
  4057. /// <param name="sender"></param>
  4058. /// <param name="e"></param>
  4059. private void comboBox_OBC_SetGearST_SelectedIndexChanged(object sender, EventArgs e)
  4060. {
  4061. comboBox_GearSt.SelectedIndex = comboBox_OBC_SetGearST.SelectedIndex;
  4062. comboBox_LightSwitch.SelectedIndex = comboBox_OBC_LightSw.SelectedIndex;
  4063. }
  4064. /// <summary>
  4065. /// 生产模式初始化
  4066. /// </summary>
  4067. /// <param name="sender"></param>
  4068. /// <param name="e"></param>
  4069. private void button_FacModeInit_Click(object sender, EventArgs e)
  4070. {
  4071. var Code = new byte[5];
  4072. Code[0] = (byte)'C';
  4073. Code[1] = (byte)'L';
  4074. Code[2] = (byte)'E';
  4075. Code[3] = (byte)'A';
  4076. Code[4] = (byte)'R';
  4077. timer_500ms.Enabled = false;
  4078. if (MessageBox.Show("电机即将初始化!", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  4079. {
  4080. if (MessageBox.Show("请再次确认", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  4081. {
  4082. timer_500ms.Enabled = true;
  4083. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  4084. PowerOffAckStatus = false;
  4085. Delay_ms(250);
  4086. int TryCnt = 3;
  4087. while ((TryCnt--) >= 0)
  4088. {
  4089. if (!PowerOffAckStatus)
  4090. {
  4091. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  4092. PowerOffAckStatus = false;
  4093. Delay_ms(250);
  4094. }
  4095. else break;
  4096. }
  4097. if (PowerOffAckStatus)
  4098. {
  4099. timer_500ms.Enabled = false;
  4100. MessageBox.Show("系统已关机,请保持无负载重新开机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  4101. timer_500ms.Enabled = true;
  4102. }
  4103. else
  4104. {
  4105. timer_500ms.Enabled = false;
  4106. MessageBox.Show("初始化失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4107. timer_500ms.Enabled = true;
  4108. }
  4109. timer_500ms.Enabled = true;
  4110. }
  4111. }
  4112. timer_500ms.Enabled = true;
  4113. //清除历史测试记录
  4114. textBox_FacModeSensorADC0.Text = "";
  4115. textBox_FacModeSensorADC1.Text = "";
  4116. textBox_FacModeSensorADC2.Text = "";
  4117. textBox_FacModeSensorADC3.Text = "";
  4118. textBox_FacModeSensorADC4.Text = "";
  4119. LightSwitchStatus = false;
  4120. MotorRunStatus = false;
  4121. textBox_MotorSpeedPercent.Text = "5";
  4122. textBox_FacModeName.Text = "";
  4123. textBox_FacModeNum.Text = "";
  4124. textBox_FacModeHW.Text = "";
  4125. textBox_FacModeFW.Text = "";
  4126. }
  4127. /// <summary>
  4128. /// 生产模式读取传感器参数
  4129. /// </summary>
  4130. /// <param name="sender"></param>
  4131. /// <param name="e"></param>
  4132. private void button_FacModeSensorRead_Click(object sender, EventArgs e)
  4133. {
  4134. richTextBox_SensorParam.Clear();
  4135. textBox_FacModeSensorADC0.Text = "";
  4136. textBox_FacModeSensorADC1.Text = "";
  4137. textBox_FacModeSensorADC2.Text = "";
  4138. textBox_FacModeSensorADC3.Text = "";
  4139. textBox_FacModeSensorADC4.Text = "";
  4140. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4141. //零点判断
  4142. label1_TorqueCal0.BackColor = Color.Red;
  4143. WriteACK = false;
  4144. ACK_WaitCnt = 0;
  4145. Delay_ms(200);
  4146. if (WriteACK == true) //力矩读取正常
  4147. {
  4148. WriteACK = false;
  4149. //获取零点
  4150. ushort ZeroNew;
  4151. ZeroNew = (ushort)Convert.ToUInt16(textBox_FacModeSensorADC0.Text);
  4152. //比较零点
  4153. if ((ZeroNew <= TorqueParamsForm.Zero.Max) && (ZeroNew >= TorqueParamsForm.Zero.Min))
  4154. {
  4155. label1_TorqueCal0.BackColor = Color.Green;
  4156. }
  4157. else
  4158. {
  4159. MessageBoxTimeOut.Show("力矩传感器零点超范围!\r\n" + "最新零点:" + ZeroNew.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4160. }
  4161. }
  4162. else //力矩读取不正常
  4163. {
  4164. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4165. }
  4166. }
  4167. /// <summary>
  4168. /// 生产模式传感器标定1
  4169. /// </summary>
  4170. /// <param name="sender"></param>
  4171. /// <param name="e"></param>
  4172. private void buttonFacModeSet1_Click(object sender, EventArgs e)
  4173. {
  4174. var ConfigParam = new byte[4];
  4175. for (int i = 0; i < 4; i++)
  4176. ConfigParam[i] = 0;
  4177. ushort uwDataTemp = 0;
  4178. try
  4179. {
  4180. uwDataTemp = 1;//负载序号
  4181. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4182. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4183. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal1.Text) * 10); ;//负载值0.1Nm
  4184. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4185. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4186. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4187. Delay_ms(200);
  4188. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4189. //标定1判断
  4190. label1_TorqueCal1.BackColor = Color.Red;
  4191. WriteACK = false;
  4192. ACK_WaitCnt = 0;
  4193. Delay_ms(200);
  4194. if (WriteACK == true) //力矩读取正常
  4195. {
  4196. WriteACK = false;
  4197. //获取标定1
  4198. ushort K1_T, K1;
  4199. K1_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal1.Text) * 10);
  4200. K1 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC1.Text));
  4201. //比较标定1
  4202. if ((K1_T == TorqueParamsForm.K1.T) && (K1 <= TorqueParamsForm.K1.Max) && (K1 >= TorqueParamsForm.K1.Min))
  4203. {
  4204. label1_TorqueCal1.BackColor = Color.Green;
  4205. }
  4206. else
  4207. {
  4208. MessageBoxTimeOut.Show("力矩传感器标定1超范围!\r\n" + "加载扭矩:" + K1_T.ToString() + "\r\n标定值:" + K1.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4209. }
  4210. }
  4211. else //力矩读取不正常
  4212. {
  4213. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4214. }
  4215. }
  4216. catch (Exception)
  4217. {
  4218. timer_500ms.Enabled = false;
  4219. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4220. timer_500ms.Enabled = true;
  4221. }
  4222. }
  4223. /// <summary>
  4224. /// 生产模式传感器标定2
  4225. /// </summary>
  4226. /// <param name="sender"></param>
  4227. /// <param name="e"></param>
  4228. private void buttonFacModeSet2_Click(object sender, EventArgs e)
  4229. {
  4230. var ConfigParam = new byte[4];
  4231. for (int i = 0; i < 4; i++)
  4232. ConfigParam[i] = 0;
  4233. ushort uwDataTemp = 0;
  4234. try
  4235. {
  4236. uwDataTemp = 2;//负载序号
  4237. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4238. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4239. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal2.Text) * 10); ;//负载值0.1Nm
  4240. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4241. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4242. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4243. Delay_ms(200);
  4244. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4245. //标定2判断
  4246. label1_TorqueCal2.BackColor = Color.Red;
  4247. WriteACK = false;
  4248. ACK_WaitCnt = 0;
  4249. Delay_ms(200);
  4250. if (WriteACK == true) //力矩读取正常
  4251. {
  4252. WriteACK = false;
  4253. //获取标定2
  4254. ushort K2_T, K2;
  4255. K2_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal2.Text) * 10);
  4256. K2 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC2.Text));
  4257. //比较标定1
  4258. if ((K2_T == TorqueParamsForm.K2.T) && (K2 <= TorqueParamsForm.K2.Max) && (K2 >= TorqueParamsForm.K2.Min))
  4259. {
  4260. label1_TorqueCal2.BackColor = Color.Green;
  4261. }
  4262. else
  4263. {
  4264. MessageBoxTimeOut.Show("力矩传感器标定2超范围!\r\n" + "加载扭矩:" + K2_T.ToString() + "\r\n标定值:" + K2.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4265. }
  4266. }
  4267. else //力矩读取不正常
  4268. {
  4269. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4270. }
  4271. }
  4272. catch (Exception)
  4273. {
  4274. timer_500ms.Enabled = false;
  4275. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4276. timer_500ms.Enabled = true;
  4277. }
  4278. }
  4279. /// <summary>
  4280. /// 生产模式传感器标定3
  4281. /// </summary>
  4282. /// <param name="sender"></param>
  4283. /// <param name="e"></param>
  4284. private void buttonFacModeSet3_Click(object sender, EventArgs e)
  4285. {
  4286. var ConfigParam = new byte[4];
  4287. for (int i = 0; i < 4; i++)
  4288. ConfigParam[i] = 0;
  4289. ushort uwDataTemp = 0;
  4290. try
  4291. {
  4292. uwDataTemp = 3;//负载序号
  4293. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4294. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4295. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal3.Text) * 10); ;//负载值0.1Nm
  4296. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4297. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4298. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4299. Delay_ms(200);
  4300. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4301. //标定3判断
  4302. label1_TorqueCal3.BackColor = Color.Red;
  4303. WriteACK = false;
  4304. ACK_WaitCnt = 0;
  4305. Delay_ms(200);
  4306. if (WriteACK == true) //力矩读取正常
  4307. {
  4308. WriteACK = false;
  4309. //获取标定3
  4310. ushort K3_T, K3;
  4311. K3_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal3.Text) * 10);
  4312. K3 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC3.Text));
  4313. //比较标定1
  4314. if ((K3_T == TorqueParamsForm.K3.T) && (K3 <= TorqueParamsForm.K3.Max) && (K3 >= TorqueParamsForm.K3.Min))
  4315. {
  4316. label1_TorqueCal3.BackColor = Color.Green;
  4317. }
  4318. else
  4319. {
  4320. MessageBoxTimeOut.Show("力矩传感器标定3超范围!\r\n" + "加载扭矩:" + K3_T.ToString() + "\r\n标定值:" + K3.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4321. }
  4322. }
  4323. else //力矩读取不正常
  4324. {
  4325. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4326. }
  4327. }
  4328. catch (Exception)
  4329. {
  4330. timer_500ms.Enabled = false;
  4331. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4332. timer_500ms.Enabled = true;
  4333. }
  4334. }
  4335. /// <summary>
  4336. /// 生产模式传感器标定4
  4337. /// </summary>
  4338. /// <param name="sender"></param>
  4339. /// <param name="e"></param>
  4340. private void buttonFacModeSet4_Click(object sender, EventArgs e)
  4341. {
  4342. var ConfigParam = new byte[4];
  4343. for (int i = 0; i < 4; i++)
  4344. ConfigParam[i] = 0;
  4345. ushort uwDataTemp = 0;
  4346. try
  4347. {
  4348. WriteACK = false;
  4349. uwDataTemp = 4;//负载序号
  4350. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4351. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4352. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal4.Text) * 10); ;//负载值0.1Nm
  4353. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4354. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4355. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4356. Delay_ms(200);
  4357. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4358. //标定4判断
  4359. label1_TorqueCal4.BackColor = Color.Red;
  4360. WriteACK = false;
  4361. ACK_WaitCnt = 0;
  4362. Delay_ms(200);
  4363. if (WriteACK == true) //力矩读取正常
  4364. {
  4365. //获取标定4
  4366. ushort K4_T, K4;
  4367. K4_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal4.Text) * 10);
  4368. K4 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC4.Text));
  4369. //比较标定1
  4370. if ((K4_T == TorqueParamsForm.K4.T) && (K4 <= TorqueParamsForm.K4.Max) && (K4 >= TorqueParamsForm.K4.Min))
  4371. {
  4372. label1_TorqueCal4.BackColor = Color.Green;
  4373. }
  4374. else
  4375. {
  4376. MessageBoxTimeOut.Show("力矩传感器标定4超范围!\r\n" + "加载扭矩:" + K4_T.ToString() + "\r\n标定值:" + K4.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4377. }
  4378. }
  4379. else //力矩读取不正常
  4380. {
  4381. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4382. }
  4383. }
  4384. catch (Exception)
  4385. {
  4386. timer_500ms.Enabled = false;
  4387. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4388. timer_500ms.Enabled = true;
  4389. }
  4390. }
  4391. /// <summary>
  4392. /// 生产模式开关灯
  4393. /// </summary>
  4394. /// <param name="sender"></param>
  4395. /// <param name="e"></param>
  4396. bool LightSwitchStatus = false;
  4397. private void button_FacModeLightSW_Click(object sender, EventArgs e)
  4398. {
  4399. var CtrlCode = new byte[2];
  4400. CtrlCode[0] = 0x00;
  4401. if (LightSwitchStatus)
  4402. {
  4403. CtrlCode[1] = 0xF0;
  4404. button_FacModeLightSW.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(128)))));
  4405. }
  4406. else
  4407. {
  4408. CtrlCode[1] = 0xF1;
  4409. button_FacModeLightSW.BackColor = Color.Yellow;
  4410. }
  4411. if (mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode))
  4412. {
  4413. LightSwitchStatus = !LightSwitchStatus;
  4414. comboBox_LightSwitch.SelectedIndex = LightSwitchStatus ? 0 : 1;
  4415. comboBox_OBC_LightSw.SelectedIndex = LightSwitchStatus ? 0 : 1;
  4416. }
  4417. }
  4418. /// <summary>
  4419. /// 生产模式电机控制
  4420. /// </summary>
  4421. /// <param name="sender"></param>
  4422. /// <param name="e"></param>
  4423. bool MotorRunStatus = false;
  4424. private void button_FacModeMotorRun_Click(object sender, EventArgs e)
  4425. {
  4426. string DebugDefaultInfo = "";
  4427. //获取调试信息
  4428. if (richTextBox_DebugParam.Text == string.Empty)
  4429. {
  4430. richTextBox_DebugParam.Clear();
  4431. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  4432. }
  4433. Delay_ms(200);
  4434. DebugDefaultInfo = richTextBox_DebugParam.Text;
  4435. //获取参数
  4436. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  4437. if (strDataTemp.Length != 29)
  4438. {
  4439. timer_500ms.Enabled = false;
  4440. MessageBox.Show("数据格式不正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4441. timer_500ms.Enabled = true;
  4442. return;
  4443. }
  4444. //设置参数
  4445. var ConfigParam = new byte[60];
  4446. for (int i = 0; i < 60; i++)
  4447. ConfigParam[i] = 0;
  4448. ConfigParam[0] = 0x00;
  4449. ushort uwDataTemp = 0;
  4450. if (!MotorRunStatus) //停止状态
  4451. {
  4452. //设置速度环
  4453. strDataTemp[0] = "整体运行模式=3";
  4454. //发送数据
  4455. try
  4456. {
  4457. for (int i = 0; i < strDataTemp.Length; i++)
  4458. {
  4459. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  4460. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  4461. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  4462. }
  4463. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  4464. return;
  4465. }
  4466. catch (Exception)
  4467. {
  4468. timer_500ms.Enabled = false;
  4469. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4470. timer_500ms.Enabled = true;
  4471. }
  4472. Delay_ms(200);
  4473. //设置转速百分比100%
  4474. textBox_MotorSpeedPercent.Text = "100";
  4475. ConfigParam[0] = (byte)100;
  4476. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, ConfigParam);
  4477. MotorRunStatus = !MotorRunStatus;
  4478. button_FacModeMotorRun.BackColor = Color.Yellow;
  4479. Delay_ms(200);
  4480. //电机进入配置模式
  4481. var RunMode = new byte[1];
  4482. RunMode[0] = 0x01;
  4483. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  4484. }
  4485. else //运转状态
  4486. {
  4487. //设置转速百分比0%
  4488. textBox_MotorSpeedPercent.Text = "0";
  4489. ConfigParam[0] = (byte)0;
  4490. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, ConfigParam);
  4491. MotorRunStatus = !MotorRunStatus;
  4492. button_FacModeMotorRun.BackColor = Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
  4493. Delay_ms(200);
  4494. //还原为原始值
  4495. strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  4496. try
  4497. {
  4498. for (int i = 0; i < strDataTemp.Length; i++)
  4499. {
  4500. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  4501. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  4502. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  4503. }
  4504. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  4505. return;
  4506. }
  4507. catch (Exception)
  4508. {
  4509. timer_500ms.Enabled = false;
  4510. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4511. timer_500ms.Enabled = true;
  4512. }
  4513. Delay_ms(200);
  4514. //电机退出配置模式
  4515. var RunMode = new byte[1];
  4516. RunMode[0] = 0x00;
  4517. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  4518. }
  4519. }
  4520. /// <summary>
  4521. /// 生产模式写入型号
  4522. /// </summary>
  4523. /// <param name="sender"></param>
  4524. /// <param name="e"></param>
  4525. private void button_FacModeSetName_Click(object sender, EventArgs e)
  4526. {
  4527. string Mode = textBox_FacModeName.Text;
  4528. var ModeArray = new byte[16];
  4529. for (ushort i = 0; i < Mode.Length; i++)
  4530. {
  4531. ModeArray[i] = (byte)Mode[i];
  4532. }
  4533. if (Mode.Length < 16)
  4534. {
  4535. ModeArray[Mode.Length] = (byte)'.';
  4536. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  4537. {
  4538. ModeArray[Mode.Length + 1 + i] = 0x20;
  4539. }
  4540. }
  4541. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  4542. }
  4543. /// <summary>
  4544. /// 生产模式写入SN
  4545. /// </summary>
  4546. /// <param name="sender"></param>
  4547. /// <param name="e"></param>
  4548. private void Button_FacModeSetNum_Click(object sender, EventArgs e)
  4549. {
  4550. string SN = textBox_FacModeNum.Text;
  4551. var SNArray = new byte[16];
  4552. for (ushort i = 0; i < SN.Length; i++)
  4553. {
  4554. SNArray[i] = (byte)SN[i];
  4555. }
  4556. if (SN.Length < 16)
  4557. {
  4558. SNArray[SN.Length] = (byte)'.';
  4559. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  4560. {
  4561. SNArray[SN.Length + 1 + i] = 0x20;
  4562. }
  4563. }
  4564. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  4565. }
  4566. /// <summary>
  4567. /// 生产模式读取版本信息
  4568. /// </summary>
  4569. /// <param name="sender"></param>
  4570. /// <param name="e"></param>
  4571. private void Button_FacModeReadVer_Click_1(object sender, EventArgs e)
  4572. {
  4573. textBox_Model.Text = "---";
  4574. textBox_SN.Text = "---";
  4575. textBox_HW.Text = "---";
  4576. textBox_FW.Text = "---";
  4577. textBox_SP.Text = "---";
  4578. textBox_OBC_ReadModel.Text = "---";
  4579. textBox_OBC_ReadSN.Text = "---";
  4580. textBox_OBC_ReadHW.Text = "---";
  4581. textBox_OBC_ReadFW.Text = "---";
  4582. textBox_OBC_ReadSP.Text = "---";
  4583. textBox_FacModeName.Text = "---";
  4584. textBox_FacModeNum.Text = "---";
  4585. textBox_FacModeHW.Text = "---";
  4586. textBox_FacModeFW.Text = "---";
  4587. textBox_FacModeSP.Text = "---";
  4588. textBox_FacModeGit.Text = "---";
  4589. Class_Motor_Ver.Mode = "---";
  4590. Class_Motor_Ver.SN = "---";
  4591. Class_Motor_Ver.HW = "---";
  4592. Class_Motor_Ver.FW = "---";
  4593. Class_Motor_Ver.Special = "---";
  4594. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  4595. }
  4596. /// <summary>
  4597. /// 生产模式写入生产信息
  4598. /// </summary>
  4599. /// <param name="sender"></param>
  4600. /// <param name="e"></param>
  4601. private void Button_FacModeSetMacDate_Click(object sender, EventArgs e)
  4602. {
  4603. var MACArray = new byte[32];
  4604. string MacDefaultInfo = "";
  4605. string MacAddDefaultInfo = "";
  4606. string MacDateDefaultInfo = DateTime.Now.ToString("yyyyMMdd");
  4607. string MacPPDefaultInfo = "";
  4608. do
  4609. {
  4610. //填入生产商
  4611. if (toolStripTextBox_MAC.Text == string.Empty)
  4612. {
  4613. break;
  4614. }
  4615. MacDefaultInfo = toolStripTextBox_MAC.Text;
  4616. for (ushort i = 0; i < MacDefaultInfo.Length; i++)
  4617. {
  4618. MACArray[i] = (byte)MacDefaultInfo[i];
  4619. }
  4620. if (MacDefaultInfo.Length < 8)
  4621. {
  4622. MACArray[MacDefaultInfo.Length] = (byte)'.';
  4623. for (ushort i = 0; i < 8 - MacDefaultInfo.Length - 1; i++)
  4624. {
  4625. MACArray[MacDefaultInfo.Length + 1 + i] = 0x20;
  4626. }
  4627. }
  4628. //填入生产地
  4629. if (toolStripTextBoxMACAddr.Text == string.Empty)
  4630. {
  4631. break;
  4632. }
  4633. MacAddDefaultInfo = toolStripTextBoxMACAddr.Text;
  4634. for (ushort i = 0; i < MacAddDefaultInfo.Length; i++)
  4635. {
  4636. MACArray[8 + i] = (byte)MacAddDefaultInfo[i];
  4637. }
  4638. if (MacAddDefaultInfo.Length < 8)
  4639. {
  4640. MACArray[MacAddDefaultInfo.Length + 8] = (byte)'.';
  4641. for (ushort i = 0; i < 8 - MacAddDefaultInfo.Length - 1; i++)
  4642. {
  4643. MACArray[MacAddDefaultInfo.Length + 1 + i + 8] = 0x20;
  4644. }
  4645. }
  4646. //填入生产日期
  4647. if (toolStripTextBox_MACDate.Text == string.Empty)
  4648. {
  4649. break;
  4650. }
  4651. MacDateDefaultInfo = toolStripTextBox_MACDate.Text;
  4652. for (ushort i = 0; i < MacDateDefaultInfo.Length; i++)
  4653. {
  4654. MACArray[16 + i] = (byte)MacDateDefaultInfo[i];
  4655. }
  4656. if (MacDateDefaultInfo.Length < 8)
  4657. {
  4658. MACArray[MacDateDefaultInfo.Length + 16] = (byte)'.';
  4659. for (ushort i = 0; i < 8 - MacDateDefaultInfo.Length - 1; i++)
  4660. {
  4661. MACArray[MacDateDefaultInfo.Length + 1 + i + 16] = 0x20;
  4662. }
  4663. }
  4664. //填入产品标识
  4665. if (toolStripTextBox_MACPD.Text == string.Empty)
  4666. {
  4667. break;
  4668. }
  4669. MacPPDefaultInfo = toolStripTextBox_MACPD.Text;
  4670. for (ushort i = 0; i < MacPPDefaultInfo.Length; i++)
  4671. {
  4672. MACArray[24 + i] = (byte)MacPPDefaultInfo[i];
  4673. }
  4674. if (MacPPDefaultInfo.Length < 8)
  4675. {
  4676. MACArray[MacPPDefaultInfo.Length + 24] = (byte)'.';
  4677. for (ushort i = 0; i < 8 - MacPPDefaultInfo.Length - 1; i++)
  4678. {
  4679. MACArray[MacPPDefaultInfo.Length + 1 + i + 24] = 0x20;
  4680. }
  4681. }
  4682. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  4683. return;
  4684. } while (false);
  4685. timer_500ms.Enabled = false;
  4686. MessageBox.Show("生产信息配置不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4687. timer_500ms.Enabled = true;
  4688. }
  4689. /// <summary>
  4690. /// 生产模式保存测试页面
  4691. /// </summary>
  4692. /// <param name="sender"></param>
  4693. /// <param name="e"></param>
  4694. private void Button_FacModeSaveResult_Click(object sender, EventArgs e)
  4695. {
  4696. Button_FacModeSaveResult.Text = "存储中…";
  4697. string[] AssistParams = new string[15];
  4698. do
  4699. {
  4700. //读取一次马达参数
  4701. richTextBox_MotorParam.Clear();
  4702. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break; ;
  4703. Delay_ms(100);
  4704. //读取一次整车参数
  4705. richTextBox_BikeParam.Clear();
  4706. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  4707. Delay_ms(100);
  4708. //读取一次整车参数2
  4709. richTextBox_BikeParam2.Clear();
  4710. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null)) break;
  4711. Delay_ms(100);
  4712. //读取一次控制参数
  4713. richTextBox_ControlParam.Clear();
  4714. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  4715. Delay_ms(100);
  4716. //查询传感器
  4717. richTextBox_SensorParam.Clear();
  4718. textBox_FacModeSensorADC0.Text = "";
  4719. textBox_FacModeSensorADC1.Text = "";
  4720. textBox_FacModeSensorADC2.Text = "";
  4721. textBox_FacModeSensorADC3.Text = "";
  4722. textBox_FacModeSensorADC4.Text = "";
  4723. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  4724. Delay_ms(100);
  4725. //读取15次助力参数
  4726. for (int i = 1; i <= 15; i++)
  4727. {
  4728. var ConfigParam = new byte[4];
  4729. richTextBox_AssistParam.Clear();
  4730. ConfigParam[0] = (byte)(i & 0xFF);
  4731. ConfigParam[1] = (byte)(i >> 8);
  4732. ConfigParam[2] = (byte)(((i >= 5) ? 5 : i) & 0xFF);
  4733. ConfigParam[3] = (byte)(((i >= 5) ? 5 : i) >> 8);
  4734. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  4735. Delay_ms(200);
  4736. AssistParams[i - 1] = richTextBox_AssistParam.Text + "\r\n";
  4737. }
  4738. //读取一次用户骑行参数
  4739. richTextBox_UsrRidesParam.Clear();
  4740. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  4741. Delay_ms(100);
  4742. //读取一次调试信息
  4743. richTextBox_DebugParam.Clear();
  4744. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  4745. Delay_ms(100);
  4746. //读取一次历史信息
  4747. richTextBox_Record.Clear();
  4748. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  4749. Delay_ms(100);
  4750. //读取一次电机运行信息
  4751. var CtrlCode = new byte[2];
  4752. CtrlCode[0] = 0x00;
  4753. CtrlCode[1] = 0xF0;
  4754. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode)) break;
  4755. Delay_ms(100);
  4756. //读取一次版本信息
  4757. textBox_Model.Text = "---";
  4758. textBox_SN.Text = "---";
  4759. textBox_HW.Text = "---";
  4760. textBox_FW.Text = "---";
  4761. textBox_OBC_ReadModel.Text = "---";
  4762. textBox_OBC_ReadSN.Text = "---";
  4763. textBox_OBC_ReadHW.Text = "---";
  4764. textBox_OBC_ReadFW.Text = "---";
  4765. textBox_FacModeName.Text = "---";
  4766. textBox_FacModeNum.Text = "---";
  4767. textBox_FacModeHW.Text = "---";
  4768. textBox_FacModeFW.Text = "---";
  4769. Class_Motor_Ver.Mode = "---";
  4770. Class_Motor_Ver.SN = "---";
  4771. Class_Motor_Ver.HW = "---";
  4772. Class_Motor_Ver.FW = "---";
  4773. Class_Motor_Ver.Special = "---";
  4774. if (!mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null)) break;
  4775. Delay_ms(100);
  4776. //读取一次生产信息
  4777. textBox_MAC.Text = "";
  4778. textBox_MACAdd.Text = "";
  4779. textBox_MACDate.Text = "";
  4780. textBox_PP.Text = "";
  4781. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  4782. Delay_ms(100);
  4783. //读取一次自定义信息
  4784. textBox_User1.Text = "---";
  4785. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  4786. Delay_ms(100);
  4787. textBox_User2.Text = "---";
  4788. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  4789. Delay_ms(100);
  4790. textBox_User3.Text = "---";
  4791. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  4792. Delay_ms(100);
  4793. //读取一次密钥
  4794. textBox_Key.Text = "---";
  4795. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  4796. Delay_ms(100);
  4797. //读取一次存储标志
  4798. radioButton_EE_SaveYes.Checked = false;
  4799. radioButton_EE_SaveNo.Checked = false;
  4800. radioButton_SIP_SaveYes.Checked = false;
  4801. radioButton_SIP_SaveNo.Checked = false;
  4802. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  4803. Delay_ms(100);
  4804. //读取一次MOS内阻校准参数
  4805. foreach (Control c in groupBox21.Controls)
  4806. {
  4807. if (c is TextBox)
  4808. c.Text = "";
  4809. }
  4810. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  4811. Delay_ms(100);
  4812. //提示检查
  4813. #if false
  4814. timer_1s.Enabled = false;
  4815. if (MessageBox.Show("请检查信息是否完整!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  4816. {
  4817. MessageBox.Show("请检查参数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4818. timer_1s.Enabled = true;
  4819. return;
  4820. }
  4821. timer_1s.Enabled = true;
  4822. Delay_ms(200);
  4823. #endif
  4824. //判断数据是否有效
  4825. if ((textBox_FacModeName.Text == "---") || (textBox_FacModeNum.Text == "---"))
  4826. {
  4827. MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4828. break;
  4829. }
  4830. if ((textBox_FacModeName.Text == string.Empty) || (textBox_FacModeNum.Text == string.Empty))
  4831. {
  4832. MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4833. break;
  4834. }
  4835. //设置文件存储路径
  4836. string Save_Path = localInfo.LocalPath + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
  4837. string PD_PathName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_"); ;
  4838. Save_Path += PD_PathName;
  4839. if (!Directory.Exists(Save_Path))
  4840. Directory.CreateDirectory(Save_Path);
  4841. //保存页面
  4842. string PIC_SaveFileName = "";
  4843. Double scaleX = PrimaryScreen.ScaleX;
  4844. Double scaleY = PrimaryScreen.ScaleY;
  4845. //保存页面
  4846. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  4847. Graphics g = Graphics.FromImage(bit);
  4848. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  4849. PIC_SaveFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_测试页面" + ".png";
  4850. bit.Save(PIC_SaveFileName);
  4851. //保存数据
  4852. string DataFileName = "";
  4853. string FileInfo = "";
  4854. DataFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_记录数据" + ".txt";
  4855. FileInfo += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  4856. FileInfo += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  4857. FileInfo += "\r\n";
  4858. FileInfo += "[电机信息]\r\n";
  4859. FileInfo += "电机型号: " + textBox_FacModeName.Text + "\r\n";
  4860. FileInfo += "电机编号: " + textBox_FacModeNum.Text + "\r\n";
  4861. FileInfo += "硬件版本: " + textBox_HW.Text + "\r\n";
  4862. FileInfo += "软件版本: " + textBox_FW.Text + "\r\n";
  4863. FileInfo += "软件标识: " + textBox_SP.Text + "\r\n";
  4864. FileInfo += "Git信息: " + textBox_FacModeGit.Text + "\r\n";
  4865. FileInfo += "\r\n";
  4866. FileInfo += "[马达参数]\r\n";
  4867. FileInfo += richTextBox_MotorParam.Text + "\r\n";
  4868. FileInfo += "\r\n";
  4869. FileInfo += "[整车参数]\r\n";
  4870. FileInfo += richTextBox_BikeParam.Text + "\r\n";
  4871. FileInfo += "\r\n";
  4872. FileInfo += "[控制参数]\r\n";
  4873. FileInfo += richTextBox_ControlParam.Text + "\r\n";
  4874. FileInfo += "\r\n";
  4875. FileInfo += "[传感器参数]\r\n";
  4876. FileInfo += richTextBox_SensorParam.Text + "\r\n";
  4877. FileInfo += "\r\n";
  4878. FileInfo += "[助力参数]\r\n";
  4879. for(int i=0;i<15;i++)
  4880. {
  4881. FileInfo += AssistParams[i] + "\r\n";
  4882. }
  4883. FileInfo += "[调试参数]\r\n";
  4884. FileInfo += richTextBox_DebugParam.Text + "\r\n";
  4885. FileInfo += "\r\n";
  4886. FileInfo += "[历史信息]\r\n";
  4887. FileInfo += richTextBox_Record.Text + "\r\n";
  4888. FileInfo += "\r\n";
  4889. FileInfo += "[MOS内阻校准参数]\r\n";
  4890. FileInfo += textBox_MOS_K1.Text + ", ";
  4891. FileInfo += textBox_MOS_K2.Text + ", ";
  4892. FileInfo += textBox_MOS_K3.Text + ", ";
  4893. FileInfo += textBox_MOS_K4.Text + ", ";
  4894. FileInfo += textBox_MOS_K5.Text + ", ";
  4895. FileInfo += textBox_MOS_R1.Text + ", ";
  4896. FileInfo += textBox_MOS_R2.Text + ", ";
  4897. FileInfo += textBox_MOS_R3.Text + "\r\n";
  4898. FileInfo += "\r\n";
  4899. FileInfo += "[整车参数2]\r\n";
  4900. FileInfo += richTextBox_BikeParam2.Text + "\r\n";
  4901. FileInfo += "\r\n";
  4902. FileInfo += "[用户骑行参数]\r\n";
  4903. FileInfo += richTextBox_UsrRidesParam.Text + "\r\n";
  4904. FileInfo += "\r\n";
  4905. FileInfo += "[生产信息]\r\n";
  4906. FileInfo += "生产商: " + textBox_MAC.Text + "\r\n";
  4907. FileInfo += "生产地: " + textBox_MACAdd.Text + "\r\n";
  4908. FileInfo += "生产日期: " + textBox_MACDate.Text + "\r\n";
  4909. FileInfo += "产品标识: " + textBox_PP.Text + "\r\n";
  4910. FileInfo += "\r\n";
  4911. FileInfo += "[自定义信息]\r\n";
  4912. FileInfo += "自定义1: " + textBox_User1.Text + "\r\n";
  4913. FileInfo += "自定义2: " + textBox_User2.Text + "\r\n";
  4914. FileInfo += "自定义3: " + textBox_User3.Text + "\r\n";
  4915. FileInfo += "\r\n";
  4916. FileInfo += "[校验密钥]\r\n";
  4917. FileInfo += textBox_Key.Text + "\r\n";
  4918. FileInfo += "\r\n";
  4919. FileInfo += "[存储标志]\r\n";
  4920. FileInfo += "EEPROM: " + ((radioButton_EE_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  4921. FileInfo += "SIP: " + ((radioButton_SIP_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  4922. FileInfo += "\r\n";
  4923. FileInfo += Local_HdInformation;
  4924. FileInfo += "\r\n";
  4925. FileInfo += "文件格式: V2.0\r\n";
  4926. System.IO.File.WriteAllText(DataFileName, FileInfo);
  4927. Delay_ms(1000);
  4928. timer_500ms.Enabled = false;
  4929. MessageBox.Show("存储完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  4930. timer_500ms.Enabled = true;
  4931. //数据上传
  4932. if (myFtp.IsNetConnected == true)
  4933. {
  4934. string DataNow = DateTime.Now.ToString("yyyy-MM-dd");
  4935. //检查路径
  4936. if (myFtp.DirectoryExist("\\", toolStripTextBox_ServerPath.Text) == false)
  4937. {
  4938. myFtp.MakeDir(toolStripTextBox_ServerPath.Text);
  4939. }
  4940. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text, "Samples") == false)
  4941. {
  4942. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples");
  4943. }
  4944. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples", DataNow) == false)
  4945. {
  4946. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow);
  4947. }
  4948. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow, PD_PathName) == false)
  4949. {
  4950. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4951. }
  4952. //上传文件
  4953. bool result1 = myFtp.UploadFile(PIC_SaveFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4954. bool result2 = myFtp.UploadFile(DataFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4955. if ((result1 & result2) == true)
  4956. {
  4957. MessageBoxTimeOut.Show("数据已上传!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  4958. }
  4959. else
  4960. {
  4961. timer_500ms.Enabled = false;
  4962. MessageBox.Show("数据上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4963. timer_500ms.Enabled = true;
  4964. }
  4965. }
  4966. else
  4967. {
  4968. timer_500ms.Enabled = false;
  4969. MessageBox.Show("服务器断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4970. timer_500ms.Enabled = true;
  4971. }
  4972. Button_FacModeSaveResult.Text = "保存数据";
  4973. return;
  4974. } while (false);
  4975. timer_500ms.Enabled = false;
  4976. MessageBox.Show("保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4977. timer_500ms.Enabled = true;
  4978. Button_FacModeSaveResult.Text = "保存数据";
  4979. }
  4980. /// <summary>
  4981. /// 工具箱页面保存
  4982. /// </summary>
  4983. /// <param name="sender"></param>
  4984. /// <param name="e"></param>
  4985. private void 页面保存ToolStripMenuItem_Click(object sender, EventArgs e)
  4986. {
  4987. Double scaleX = PrimaryScreen.ScaleX;
  4988. Double scaleY = PrimaryScreen.ScaleY;
  4989. //保存页面
  4990. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  4991. Graphics g = Graphics.FromImage(bit);
  4992. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  4993. SaveFileDialog sf = new SaveFileDialog();
  4994. sf.Title = "页面保存";
  4995. sf.FileName = "MotorInfo_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".png";
  4996. sf.Filter = "图片|*.png";
  4997. timer_500ms.Enabled = false;
  4998. if (sf.ShowDialog() == DialogResult.OK)
  4999. {
  5000. bit.Save(sf.FileName);//默认保存格式为PNG,保存成jpg格式质量不是很好
  5001. }
  5002. timer_500ms.Enabled = true;
  5003. }
  5004. /// <summary>
  5005. /// 生产模式关机
  5006. /// </summary>
  5007. /// <param name="sender"></param>
  5008. /// <param name="e"></param>
  5009. private void Button_FacModePowerOff_Click(object sender, EventArgs e)
  5010. {
  5011. var Code_Off = new byte[5];
  5012. var Code_Reset = new byte[5];
  5013. Code_Off[0] = (byte)'O';
  5014. Code_Off[1] = (byte)'F';
  5015. Code_Off[2] = (byte)'F';
  5016. Code_Off[3] = (byte)'.';
  5017. Code_Off[4] = (byte)'.';
  5018. Code_Reset[0] = (byte)'R';
  5019. Code_Reset[1] = (byte)'E';
  5020. Code_Reset[2] = (byte)'S';
  5021. Code_Reset[3] = (byte)'E';
  5022. Code_Reset[4] = (byte)'T';
  5023. timer_500ms.Enabled = false;
  5024. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  5025. {
  5026. timer_500ms.Enabled = true;
  5027. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  5028. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  5029. PowerOffAckStatus = false;
  5030. Delay_ms(250);
  5031. int TryCnt = 3;
  5032. while ((TryCnt--) >= 0)
  5033. {
  5034. if (!PowerOffAckStatus)
  5035. {
  5036. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  5037. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  5038. PowerOffAckStatus = false;
  5039. Delay_ms(250);
  5040. }
  5041. else break;
  5042. }
  5043. if (PowerOffAckStatus)
  5044. {
  5045. timer_500ms.Enabled = false;
  5046. MessageBox.Show("已关机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  5047. timer_500ms.Enabled = true;
  5048. }
  5049. else
  5050. {
  5051. timer_500ms.Enabled = false;
  5052. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5053. timer_500ms.Enabled = true;
  5054. }
  5055. }
  5056. timer_500ms.Enabled = true;
  5057. }
  5058. //仪表电源键按下
  5059. private void button_OBC_ButtonPower_Click(object sender, EventArgs e)
  5060. {
  5061. var Code = new byte[2];
  5062. Code[0] = 0;
  5063. Code[1] = 0b00100000;
  5064. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5065. }
  5066. /// <summary>
  5067. /// 仪表加键按下
  5068. /// </summary>
  5069. /// <param name="sender"></param>
  5070. /// <param name="e"></param>
  5071. private void button_OBC_ButtonAcc_Click(object sender, EventArgs e)
  5072. {
  5073. var Code = new byte[2];
  5074. Code[0] = 0;
  5075. Code[1] = 0b00010000;
  5076. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5077. }
  5078. /// <summary>
  5079. /// 仪表减键按下
  5080. /// </summary>
  5081. /// <param name="sender"></param>
  5082. /// <param name="e"></param>
  5083. private void button_OBC_ButtonDec_Click(object sender, EventArgs e)
  5084. {
  5085. var Code = new byte[2];
  5086. Code[0] = 0;
  5087. Code[1] = 0b00001000;
  5088. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5089. }
  5090. /// <summary>
  5091. /// 仪表Walk键按下
  5092. /// </summary>
  5093. /// <param name="sender"></param>
  5094. /// <param name="e"></param>
  5095. private void button_OBC_ButtonWalk_Click(object sender, EventArgs e)
  5096. {
  5097. var Code = new byte[2];
  5098. Code[0] = 0;
  5099. Code[1] = 0b00000100;
  5100. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5101. }
  5102. /// <summary>
  5103. /// 仪表Light键按下
  5104. /// </summary>
  5105. /// <param name="sender"></param>
  5106. /// <param name="e"></param>
  5107. private void button_OBC_ButtonLight_Click(object sender, EventArgs e)
  5108. {
  5109. var Code = new byte[2];
  5110. Code[0] = 0;
  5111. Code[1] = 0b00000010;
  5112. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5113. }
  5114. /// <summary>
  5115. /// 仪表Set键按下
  5116. /// </summary>
  5117. /// <param name="sender"></param>
  5118. /// <param name="e"></param>
  5119. private void button_OBC_ButtonSet_Click(object sender, EventArgs e)
  5120. {
  5121. var Code = new byte[2];
  5122. Code[0] = 0;
  5123. Code[1] = 0b00000001;
  5124. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5125. }
  5126. /// <summary>
  5127. /// 导出电机故障日志
  5128. /// </summary>
  5129. /// <param name="sender"></param>
  5130. /// <param name="e"></param>
  5131. private void button_ExportLog_Click(object sender, EventArgs e)
  5132. {
  5133. var Address = new byte[4];
  5134. UInt32 Address_Begin;
  5135. UInt32 Addres_End;
  5136. string textBox_Address_Begin = textBox_LogAddrBegin.Text;
  5137. string textBox_Address_End = textBox_LogAddrEnd.Text;
  5138. richTextBox_Record.Clear();
  5139. textBox_LogAddrBegin.ReadOnly = true;
  5140. textBox_LogAddrEnd.ReadOnly = true;
  5141. if (!mySerialProcess.mySerial.IsOpen)
  5142. {
  5143. timer_500ms.Enabled = false;
  5144. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5145. timer_500ms.Enabled = true;
  5146. return;
  5147. }
  5148. if ((textBox_Address_Begin == string.Empty) || (textBox_Address_End == string.Empty))
  5149. {
  5150. timer_500ms.Enabled = false;
  5151. MessageBox.Show("请输入日志存储起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5152. timer_500ms.Enabled = true;
  5153. return;
  5154. }
  5155. else
  5156. {
  5157. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin, false);
  5158. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  5159. Address = mySerialProcess.HexStringToBytes(textBox_Address_End, false);
  5160. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  5161. if (Addres_End <= Address_Begin)
  5162. {
  5163. timer_500ms.Enabled = false;
  5164. MessageBox.Show("结束地址应大于起始地址!", "提示");
  5165. timer_500ms.Enabled = true;
  5166. return;
  5167. }
  5168. else if (((Addres_End - Address_Begin + 1) % 128) != 0) //
  5169. {
  5170. timer_500ms.Enabled = false;
  5171. MessageBox.Show("(结束地址 - 起始地址 + 1)应为128整数倍!", "提示");
  5172. timer_500ms.Enabled = true;
  5173. return;
  5174. }
  5175. else
  5176. {
  5177. UInt32 ReadCount = 0;
  5178. button_ExportLog.Text = "导出中...";
  5179. button_ExportLog.Enabled = false;
  5180. ReadCount = (Addres_End - Address_Begin + 1) / 128;
  5181. for (ushort i = 0; i < ReadCount; i++)
  5182. {
  5183. var SendByte = new byte[8];
  5184. UInt32 Address_Temp_Begin;
  5185. UInt32 Address_Temp_End;
  5186. Address_Temp_Begin = Address_Begin + 128 * (UInt32)i;
  5187. SendByte[0] = (byte)(Address_Temp_Begin >> 24);
  5188. SendByte[1] = (byte)(Address_Temp_Begin >> 16);
  5189. SendByte[2] = (byte)(Address_Temp_Begin >> 8);
  5190. SendByte[3] = (byte)(Address_Temp_Begin);
  5191. Address_Temp_End = Address_Temp_Begin + 127;
  5192. SendByte[4] = (byte)(Address_Temp_End >> 24);
  5193. SendByte[5] = (byte)(Address_Temp_End >> 16);
  5194. SendByte[6] = (byte)(Address_Temp_End >> 8);
  5195. SendByte[7] = (byte)(Address_Temp_End);
  5196. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  5197. Delay_ms(200);//Thread.Sleep(200);
  5198. }
  5199. button_ExportLog.Text = "导出日志";
  5200. button_ExportLog.Enabled = true;
  5201. }
  5202. }
  5203. }
  5204. /// <summary>
  5205. /// 保存日志信息
  5206. /// </summary>
  5207. /// <param name="sender"></param>
  5208. /// <param name="e"></param>
  5209. private void button_SaveRecordInfo_Click(object sender, EventArgs e)
  5210. {
  5211. string SaveInfo = "";
  5212. if (richTextBox_Record.Text == string.Empty)
  5213. {
  5214. timer_500ms.Enabled = false;
  5215. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  5216. timer_500ms.Enabled = true;
  5217. return;
  5218. }
  5219. //获取保存信息
  5220. SaveInfo += "读取时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  5221. SaveInfo += "电机型号:" + textBox_FacModeName.Text + "\r\n";
  5222. SaveInfo += "电机SN:" + textBox_FacModeNum.Text + "\r\n";
  5223. SaveInfo += "硬件版本:" + textBox_FacModeHW.Text + "\r\n";
  5224. SaveInfo += "软件版本:" + textBox_FacModeFW.Text + "\r\n";
  5225. SaveInfo += "\r\n";
  5226. SaveInfo += richTextBox_Record.Text;
  5227. //设置保存路径和文件名
  5228. SaveFileDialog sf = new SaveFileDialog();
  5229. sf.Title = "数据保存";
  5230. sf.FileName = "MotorLog_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".ttlog";
  5231. sf.FileName.Replace(" ", "");
  5232. sf.Filter = "日志|*.ttlog";
  5233. if (sf.ShowDialog() == DialogResult.OK)
  5234. {
  5235. System.IO.File.AppendAllText(sf.FileName, SaveInfo);
  5236. }
  5237. }
  5238. /// <summary>
  5239. /// 双击修改日志起始地址
  5240. /// </summary>
  5241. /// <param name="sender"></param>
  5242. /// <param name="e"></param>
  5243. private void label_LogAddrBegin_DoubleClick_1(object sender, EventArgs e)
  5244. {
  5245. textBox_LogAddrBegin.ReadOnly = false;
  5246. }
  5247. /// <summary>
  5248. /// 双击修改日志结束地址
  5249. /// </summary>
  5250. /// <param name="sender"></param>
  5251. /// <param name="e"></param>
  5252. private void label88_DoubleClick(object sender, EventArgs e)
  5253. {
  5254. textBox_LogAddrEnd.ReadOnly = false;
  5255. }
  5256. /// <summary>
  5257. /// 存储器自动读取选择
  5258. /// </summary>
  5259. /// <param name="sender"></param>
  5260. /// <param name="e"></param>
  5261. private void checkBox_ReadRanFlash_AutoSW_CheckedChanged(object sender, EventArgs e)
  5262. {
  5263. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  5264. {
  5265. //检查串口是否打开
  5266. if (!mySerialProcess.mySerial.IsOpen)
  5267. {
  5268. timer_500ms.Enabled = false;
  5269. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5270. timer_500ms.Enabled = true;
  5271. checkBox_ReadRanFlash_AutoSW.Checked = false;
  5272. return;
  5273. }
  5274. }
  5275. }
  5276. /// <summary>
  5277. /// 系统开机按钮
  5278. /// </summary>
  5279. /// <param name="sender"></param>
  5280. /// <param name="e"></param>
  5281. private void 开机ToolStripMenuItem_Click(object sender, EventArgs e)
  5282. {
  5283. byte[] Data = new byte[1];
  5284. Data[0] = 0xF1;
  5285. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  5286. }
  5287. /// <summary>
  5288. /// 系统关机按钮
  5289. /// </summary>
  5290. /// <param name="sender"></param>
  5291. /// <param name="e"></param>
  5292. private void 关机ToolStripMenuItem_Click(object sender, EventArgs e)
  5293. {
  5294. byte[] Data = new byte[1];
  5295. Data[0] = 0xF0;
  5296. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  5297. }
  5298. /// <summary>
  5299. /// 连接开机选择
  5300. /// </summary>
  5301. /// <param name="sender"></param>
  5302. /// <param name="e"></param>
  5303. private void 连接开机ToolStripMenuItem_Click(object sender, EventArgs e)
  5304. {
  5305. //输入用户名
  5306. EnterForm1.ShowDialog();
  5307. try
  5308. {
  5309. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5310. {
  5311. if (EnterForm1.comboBox_User.Text == "管理员")
  5312. {
  5313. 连接开机ToolStripMenuItem.Checked = !连接开机ToolStripMenuItem.Checked;
  5314. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5315. }
  5316. else
  5317. {
  5318. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5319. }
  5320. }
  5321. else
  5322. {
  5323. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5324. }
  5325. }
  5326. catch (Exception)
  5327. {
  5328. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5329. }
  5330. }
  5331. /// <summary>
  5332. /// 断开关机选择
  5333. /// </summary>
  5334. /// <param name="sender"></param>
  5335. /// <param name="e"></param>
  5336. private void 断开关机ToolStripMenuItem_Click(object sender, EventArgs e)
  5337. {
  5338. //输入用户名
  5339. EnterForm1.ShowDialog();
  5340. try
  5341. {
  5342. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5343. {
  5344. if (EnterForm1.comboBox_User.Text == "管理员")
  5345. {
  5346. 断开关机ToolStripMenuItem.Checked = !断开关机ToolStripMenuItem.Checked;
  5347. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5348. }
  5349. else
  5350. {
  5351. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5352. }
  5353. }
  5354. else
  5355. {
  5356. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5357. }
  5358. }
  5359. catch (Exception)
  5360. {
  5361. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5362. }
  5363. }
  5364. /// <summary>
  5365. /// 识别通讯盒选择
  5366. /// </summary>
  5367. /// <param name="sender"></param>
  5368. /// <param name="e"></param>
  5369. private void 识别通讯盒ToolStripMenuItem_Click(object sender, EventArgs e)
  5370. {
  5371. //输入用户名
  5372. EnterForm1.ShowDialog();
  5373. try
  5374. {
  5375. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5376. {
  5377. if (EnterForm1.comboBox_User.Text == "管理员")
  5378. {
  5379. 识别通讯盒ToolStripMenuItem.Checked = !识别通讯盒ToolStripMenuItem.Checked;
  5380. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5381. }
  5382. else
  5383. {
  5384. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5385. }
  5386. }
  5387. else
  5388. {
  5389. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5390. }
  5391. }
  5392. catch (Exception)
  5393. {
  5394. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5395. }
  5396. }
  5397. /// <summary>
  5398. /// 将配置信息导出为cfg文件
  5399. /// </summary>
  5400. private void ConfigFileSave(bool DeleteFlag, string FileName)
  5401. {
  5402. if (DeleteFlag)
  5403. {
  5404. if (File.Exists(FileName))
  5405. File.Delete(FileName);
  5406. }
  5407. string CfgFileInfo = "";
  5408. CfgFileInfo += "[PortSet]" + "\r\n";
  5409. CfgFileInfo += "PortNum:" + toolStripComboBox_ComNum.Text + "\r\n";
  5410. CfgFileInfo += "PortBaudrate:" + "115200" + "\r\n";
  5411. CfgFileInfo += "AutoOn:" + 连接开机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5412. CfgFileInfo += "AutoOff:" + 断开关机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5413. CfgFileInfo += "CheckCDL:" + 识别通讯盒ToolStripMenuItem.Checked.ToString() + "\r\n";
  5414. CfgFileInfo += "\r\n";
  5415. CfgFileInfo += "[Option]" + "\r\n";
  5416. CfgFileInfo += "SaveWhenWrite:" + 写入存储ToolStripMenuItem.Checked.ToString() + "\r\n";
  5417. CfgFileInfo += "\r\n";
  5418. CfgFileInfo += "[ServerSet]" + "\r\n";
  5419. CfgFileInfo += "PathName:" + toolStripTextBox_ServerPath.Text + "\r\n";
  5420. CfgFileInfo += "\r\n";
  5421. CfgFileInfo += "[MacInfo]" + "\r\n";
  5422. CfgFileInfo += "MacName:" + toolStripTextBox_MAC.Text + "\r\n";
  5423. CfgFileInfo += "MacAddress:" + toolStripTextBoxMACAddr.Text + "\r\n";
  5424. CfgFileInfo += "MacDate:" + toolStripTextBox_MACDate.Text + "\r\n";
  5425. CfgFileInfo += "MacPdInfo:" + toolStripTextBox_MACPD.Text + "\r\n";
  5426. CfgFileInfo += "\r\n";
  5427. CfgFileInfo += "[LogAddress]" + "\r\n";
  5428. CfgFileInfo += "BeginAddress:" + textBox_LogAddrBegin.Text + "\r\n";
  5429. CfgFileInfo += "EndAddress:" + textBox_LogAddrEnd.Text + "\r\n";
  5430. CfgFileInfo += "\r\n";
  5431. CfgFileInfo += "[MotorType]" + "\r\n";
  5432. CfgFileInfo += "MidMotor:" + 中置电机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5433. CfgFileInfo += "HubMotor:" + 轮毂电机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5434. CfgFileInfo += "\r\n";
  5435. CfgFileInfo += "[CheckValue]" + "\r\n";
  5436. CfgFileInfo += "Voltage:" + toolStripTextBox_ThVol.Text + "\r\n";
  5437. CfgFileInfo += "Current:" + toolStripTextBox_ThCur.Text + "\r\n";
  5438. CfgFileInfo += "MotorSpeed:" + toolStripTextBox_ThSpeed.Text + "\r\n";
  5439. CfgFileInfo += "Torque:" + toolStripTextBox_ThTor.Text + "\r\n";
  5440. CfgFileInfo += "Cadence:" + toolStripTextBox_ThCad.Text + "\r\n";
  5441. CfgFileInfo += "BikeSpeed:" + toolStripTextBox_ThBikeSpeed.Text + "\r\n";
  5442. CfgFileInfo += "T_PCB:" + toolStripTextBox_ThT_PCB.Text + "\r\n";
  5443. CfgFileInfo += "T_MCU:" + toolStripTextBox_ThT_MCU.Text + "\r\n";
  5444. CfgFileInfo += "T_Motor:" + toolStripTextBox_ThT_Motor.Text + "\r\n";
  5445. CfgFileInfo += "\r\n";
  5446. CfgFileInfo += "[MosCalK]" + "\r\n";
  5447. CfgFileInfo += "K1-K5:" + toolStripTextBox_MosCalK.Text + "\r\n";
  5448. CfgFileInfo += "MOS1:" + toolStripTextBox_MOS1.Text + "\r\n";
  5449. CfgFileInfo += "MOS2:" + toolStripTextBox_MOS2.Text + "\r\n";
  5450. CfgFileInfo += "MOS3:" + toolStripTextBox_MOS3.Text + "\r\n";
  5451. CfgFileInfo += "\r\n";
  5452. CfgFileInfo += "[ProtocolType]" + "\r\n";
  5453. CfgFileInfo += "CAN:" + cANToolStripMenuItem.Checked.ToString() + "\r\n";
  5454. CfgFileInfo += "UART:" + uARTToolStripMenuItem.Checked.ToString() + "\r\n";
  5455. CfgFileInfo += "\r\n";
  5456. CfgFileInfo += "[AutoUpdate]" + "\r\n";
  5457. CfgFileInfo += "AutoUpdate:" + 打开ToolStripMenuItem.Checked.ToString() + "\r\n";
  5458. CfgFileInfo += "\r\n";
  5459. CfgFileInfo += "[AngleCal]" + "\r\n";
  5460. CfgFileInfo += "MaxDiffLimit:" + textBox_AngleDiffTh.Text + "\r\n";
  5461. CfgFileInfo += "ZeroDiffLimit:" + textBox_AngleZeroTh.Text + "\r\n";
  5462. System.IO.File.WriteAllText(FileName, CfgFileInfo);
  5463. }
  5464. /// <summary>
  5465. /// 配置状态更新,点击时保存
  5466. /// </summary>
  5467. private void ConfigFileSave_Click(object sender, EventArgs e)
  5468. {
  5469. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5470. }
  5471. /// <summary>
  5472. /// 文本框修改结束,回车保存
  5473. /// </summary>
  5474. /// <param name="sender"></param>
  5475. /// <param name="e"></param>
  5476. private void ConfigFileSave_KeyDown(object sender, KeyEventArgs e)
  5477. {
  5478. if (e.KeyCode == Keys.Enter)
  5479. {
  5480. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5481. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  5482. }
  5483. }
  5484. /// <summary>
  5485. /// 弹出扫码按钮
  5486. /// </summary>
  5487. /// <param name="sender"></param>
  5488. /// <param name="e"></param>
  5489. private void button_ScanCode_Click(object sender, EventArgs e)
  5490. {
  5491. Scan scan_form = new Scan();
  5492. scan_form.ShowDialog();
  5493. do
  5494. {
  5495. if (scan_form.textBox_Scan.Text == string.Empty)
  5496. {
  5497. timer_500ms.Enabled = false;
  5498. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5499. timer_500ms.Enabled = true;
  5500. break;
  5501. }
  5502. string ScanInfo = scan_form.textBox_Scan.Text;
  5503. string regexInfo = "";
  5504. string[] InfoList = { "" };
  5505. try
  5506. {
  5507. if (中置电机ToolStripMenuItem.Checked == true)
  5508. {
  5509. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  5510. InfoList = Regex.Split(ScanInfo, regexInfo, RegexOptions.IgnoreCase);
  5511. }
  5512. else if (轮毂电机ToolStripMenuItem.Checked == true)
  5513. {
  5514. if (!ScanInfo.Contains("/")) //老编码规则
  5515. {
  5516. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  5517. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  5518. string Spec = InfoList[1];
  5519. string Sn = InfoList[2];
  5520. InfoList[0] = Model.Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  5521. InfoList[1] = Sn;
  5522. }
  5523. else //新编码规则
  5524. {
  5525. Dictionary<string, string> Dic_Ver = new Dictionary<string, string>
  5526. {
  5527. { "01", "A" },
  5528. { "02", "B" },
  5529. { "03", "C" },
  5530. { "04", "D" },
  5531. { "05", "E" },
  5532. { "06", "F" },
  5533. { "07", "G" },
  5534. { "08", "H" },
  5535. { "09", "I" }
  5536. };
  5537. Dictionary<string, string> Dic_Vol = new Dictionary<string, string>
  5538. {
  5539. { "24V", "A" },
  5540. { "36V", "B" },
  5541. { "42V", "C" },
  5542. { "48V", "D" },
  5543. { "52V", "E" },
  5544. { "60V", "F" }
  5545. };
  5546. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  5547. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  5548. string Spec = InfoList[1].Replace("-", "").Replace("/","");
  5549. string Sn = InfoList[2];
  5550. InfoList[0] = Model[2] + Dic_Ver[Model.Substring(3, 2)] + Model[5] + Dic_Ver[Model.Substring(6, 2)] + Model[9];
  5551. InfoList[0] += Dic_Vol[Spec.Substring(0, 3)] + Spec.Substring(3, 3) + Spec.Substring(13, 4) + Spec.Substring(Spec.Length - 4, 3);
  5552. InfoList[1] = Sn;
  5553. }
  5554. }
  5555. }
  5556. catch (Exception)
  5557. {
  5558. MessageBox.Show("格式错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5559. return;
  5560. }
  5561. if (InfoList.Length >= 2)
  5562. {
  5563. //写入型号
  5564. textBox_FacModeName.Text = InfoList[0];
  5565. string Mode = textBox_FacModeName.Text;
  5566. var ModeArray = new byte[16];
  5567. for (ushort i = 0; i < Mode.Length; i++)
  5568. {
  5569. ModeArray[i] = (byte)Mode[i];
  5570. }
  5571. if (Mode.Length < 16)
  5572. {
  5573. ModeArray[Mode.Length] = (byte)'.';
  5574. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  5575. {
  5576. ModeArray[Mode.Length + 1 + i] = 0x20;
  5577. }
  5578. }
  5579. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  5580. //写入SN
  5581. textBox_FacModeNum.Text = InfoList[1];
  5582. string SN = textBox_FacModeNum.Text;
  5583. var SNArray = new byte[16];
  5584. for (ushort i = 0; i < SN.Length; i++)
  5585. {
  5586. SNArray[i] = (byte)SN[i];
  5587. }
  5588. if (SN.Length < 16)
  5589. {
  5590. SNArray[SN.Length] = (byte)'.';
  5591. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  5592. {
  5593. SNArray[SN.Length + 1 + i] = 0x20;
  5594. }
  5595. }
  5596. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  5597. }
  5598. else
  5599. {
  5600. timer_500ms.Enabled = false;
  5601. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5602. timer_500ms.Enabled = true;
  5603. break;
  5604. }
  5605. } while (false);
  5606. scan_form.Dispose();
  5607. }
  5608. /// <summary>
  5609. /// 切换电机类型
  5610. /// </summary>
  5611. /// <param name="sender"></param>
  5612. /// <param name="e"></param>
  5613. private void 中置电机ToolStripMenuItem_Click(object sender, EventArgs e)
  5614. {
  5615. 中置电机ToolStripMenuItem.Checked = true;
  5616. 轮毂电机ToolStripMenuItem.Checked = false;
  5617. toolStripTextBox_MACPD.Text = "MM_MC1";
  5618. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  5619. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5620. }
  5621. /// <summary>
  5622. /// 切换电机类型
  5623. /// </summary>
  5624. /// <param name="sender"></param>
  5625. /// <param name="e"></param>
  5626. private void 轮毂电机ToolStripMenuItem_Click(object sender, EventArgs e)
  5627. {
  5628. 中置电机ToolStripMenuItem.Checked = false;
  5629. 轮毂电机ToolStripMenuItem.Checked = true;
  5630. toolStripTextBox_MACPD.Text = "GF_250_1";
  5631. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  5632. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5633. }
  5634. /// <summary>
  5635. /// 获取配置文件日期
  5636. /// </summary>
  5637. /// <param name="DisAll"></param>
  5638. private void GetDateList(bool DisAll)
  5639. {
  5640. string[] DateList = { "" };
  5641. //从服务器更新日期列表
  5642. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  5643. {
  5644. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
  5645. }
  5646. //从本地更新日期列表
  5647. else
  5648. {
  5649. DateList = Directory.GetDirectories(localInfo.LocalPath + "\\" + localInfo.CfgPathName);
  5650. }
  5651. comboBox_FacModeCfgDate.Items.Clear();
  5652. comboBox_CheckModeCfgDate.Items.Clear();
  5653. //日期列表加载
  5654. if (DisAll == true)
  5655. {
  5656. comboBox_FacModeCfgDate.Items.Add("显示近期");
  5657. comboBox_CheckModeCfgDate.Items.Add("显示近期");
  5658. comboBox_FacModeCfgDate.Items.Add("---");
  5659. comboBox_CheckModeCfgDate.Items.Add("---");
  5660. foreach (var file in DateList)
  5661. {
  5662. comboBox_FacModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5663. comboBox_CheckModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5664. }
  5665. }
  5666. else
  5667. {
  5668. if (DateList.Length > 10)
  5669. {
  5670. comboBox_FacModeCfgDate.Items.Add("显示全部");
  5671. comboBox_CheckModeCfgDate.Items.Add("显示全部");
  5672. comboBox_FacModeCfgDate.Items.Add("---");
  5673. comboBox_CheckModeCfgDate.Items.Add("---");
  5674. }
  5675. for (int i = (DateList.Length > 10) ? (DateList.Length - 10) : 0; i < DateList.Length; i++)//显示最近10个日期
  5676. {
  5677. comboBox_FacModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  5678. comboBox_CheckModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  5679. }
  5680. }
  5681. }
  5682. /// <summary>
  5683. /// 获取配置文件列表
  5684. /// </summary>
  5685. /// <param name="date"></param>
  5686. private void GetFileListFrom(string date)
  5687. {
  5688. string[] FileList = { "" };
  5689. //从服务器更新文件列表
  5690. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  5691. {
  5692. FileList = myFtp.GetFileNameList(toolStripTextBox_ServerPath.Text + "/cfg/" + date);
  5693. }
  5694. else
  5695. {
  5696. FileList = Directory.GetFiles(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + date);
  5697. }
  5698. comboBox_CheckModeCfgFile.Items.Clear();
  5699. comboBox_FacModeCfgFile.Items.Clear();
  5700. foreach (var file in FileList)
  5701. {
  5702. if (file.Contains(".ttcfg"))
  5703. {
  5704. comboBox_CheckModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5705. comboBox_FacModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5706. }
  5707. }
  5708. }
  5709. /// <summary>
  5710. /// 检验模式选择文件日期
  5711. /// </summary>
  5712. /// <param name="sender"></param>
  5713. /// <param name="e"></param>
  5714. private void comboBox_CheckModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  5715. {
  5716. if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示全部")
  5717. {
  5718. GetDateList(true);
  5719. }
  5720. else if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示近期")
  5721. {
  5722. GetDateList(false);
  5723. }
  5724. else
  5725. {
  5726. comboBox_CheckModeCfgFile.Text = "";
  5727. GetFileListFrom(comboBox_CheckModeCfgDate.SelectedItem.ToString());
  5728. }
  5729. }
  5730. /// <summary>
  5731. /// 配置模式选择文件日期
  5732. /// </summary>
  5733. /// <param name="sender"></param>
  5734. /// <param name="e"></param>
  5735. private void comboBox_FacModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  5736. {
  5737. if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示全部")
  5738. {
  5739. GetDateList(true);
  5740. }
  5741. else if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示近期")
  5742. {
  5743. GetDateList(false);
  5744. }
  5745. else
  5746. {
  5747. comboBox_FacModeCfgFile.Text = "";
  5748. GetFileListFrom(comboBox_FacModeCfgDate.SelectedItem.ToString());
  5749. }
  5750. }
  5751. /// <summary>
  5752. /// 选中量产模式
  5753. /// </summary>
  5754. /// <param name="sender"></param>
  5755. /// <param name="e"></param>
  5756. private void tabControl1_Selected(object sender, TabControlEventArgs e)
  5757. {
  5758. //更新生产配置文件目录
  5759. GetDateList(false);
  5760. }
  5761. /// <summary>
  5762. /// 量产测试结束
  5763. /// </summary>
  5764. /// <param name=""></param>
  5765. private void FacMode_Stop(bool OK_Flag)
  5766. {
  5767. //打开开始按钮
  5768. button__FacMode_Start.Enabled = true;
  5769. //系统关机
  5770. var Code = new byte[32];//发送的指令数据
  5771. Code[0] = 0xF0;
  5772. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5773. //关闭串口
  5774. //mySerialProcess.SerialClose(false);
  5775. //路径设置
  5776. string LocalSavePath = "";
  5777. string ServerSavePath = "";
  5778. if (OK_Flag)
  5779. {
  5780. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "OK\\";
  5781. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/OK/";
  5782. }
  5783. else
  5784. {
  5785. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "FAIL\\";
  5786. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/FAIL/";
  5787. }
  5788. if (Directory.Exists(LocalSavePath) == false)
  5789. {
  5790. Directory.CreateDirectory(LocalSavePath);
  5791. }
  5792. //保存和上传
  5793. string LogSavePath = "";
  5794. string LogSaveFileName = "";
  5795. string ProductInfo = textBox_FacModeScan.Text.Replace(" ", "_").Replace("/", "-");
  5796. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  5797. if (Directory.Exists(LogSavePath) == false)
  5798. {
  5799. Directory.CreateDirectory(LogSavePath);
  5800. }
  5801. //测试页面
  5802. Double scaleX = PrimaryScreen.ScaleX;
  5803. Double scaleY = PrimaryScreen.ScaleY;
  5804. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  5805. Graphics g = Graphics.FromImage(bit);
  5806. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  5807. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  5808. bit.Save(LogSaveFileName);
  5809. //上传测试页面到服务器
  5810. if (myFtp.IsNetConnected == true)
  5811. {
  5812. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  5813. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  5814. {
  5815. myFtp.MakeDir(ServerSavePath + DateNow);
  5816. }
  5817. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  5818. {
  5819. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  5820. }
  5821. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  5822. if (result == true)
  5823. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  5824. }
  5825. else
  5826. {
  5827. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  5828. }
  5829. //测试记录
  5830. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  5831. string file_str = "";
  5832. file_str += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  5833. file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  5834. file_str += "检验记录:\r\n" + richTextBox_FacModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  5835. file_str += "检验结果:\r\n" + label_FacModeResult.Text + "\r\n\r\n";
  5836. file_str += Local_HdInformation;
  5837. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  5838. //上传测试记录到服务器
  5839. if (myFtp.IsNetConnected == true)
  5840. {
  5841. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  5842. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  5843. {
  5844. myFtp.MakeDir(ServerSavePath + DateNow);
  5845. }
  5846. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  5847. {
  5848. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  5849. }
  5850. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  5851. if (result == true)
  5852. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  5853. }
  5854. else
  5855. {
  5856. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  5857. }
  5858. //扫码框清空
  5859. textBox_FacModeScan.Text = "";
  5860. }
  5861. /// <summary>
  5862. /// 量产测试开始
  5863. /// </summary>
  5864. /// <param name="sender"></param>
  5865. /// <param name="e"></param>
  5866. private void button__FacMode_Start_Click(object sender, EventArgs e)
  5867. {
  5868. //关闭测试项目编辑
  5869. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  5870. foreach (Control c in groupBox2.Controls)
  5871. {
  5872. if (c is CheckBox)
  5873. c.Enabled = false;
  5874. }
  5875. WriteLockStatus = true;
  5876. //检查配置文件
  5877. if (comboBox_FacModeCfgFile.Text == "")
  5878. {
  5879. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5880. return;
  5881. }
  5882. //开始测试
  5883. TestStart();
  5884. }
  5885. /// <summary>
  5886. /// 测试子函数
  5887. /// </summary>
  5888. private void TestStart()
  5889. {
  5890. //初始化标签
  5891. FacModelLabelInit();
  5892. richTextBox_FacModeLog.Clear();
  5893. //按钮禁止操作
  5894. button__FacMode_Start.Enabled = false;
  5895. //记录配置文件
  5896. richTextBox_FacModeLog.AppendText("配置文件:" + comboBox_FacModeCfgDate.Text + " / " + comboBox_FacModeCfgFile.Text + "\r\n");
  5897. //检查打标信息格式
  5898. label_FacModeStatus.Text = "检查扫码信息";
  5899. Delay_ms(500);
  5900. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  5901. if (textBox_FacModeScan.Text == string.Empty)
  5902. {
  5903. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5904. button__FacMode_Start.Enabled = true;
  5905. return;
  5906. }
  5907. try
  5908. {
  5909. if (中置电机ToolStripMenuItem.Checked == true)
  5910. {
  5911. if (textBox_FacModeScan.Text.Split(' ').Length != 7)
  5912. {
  5913. label_FacModeStatus.Text = "存在故障!";
  5914. label_FacModeResult.BackColor = Color.Red;
  5915. label_FacModeResult.Text = "标签格式错误";
  5916. button__FacMode_Start.Enabled = true;
  5917. return;
  5918. }
  5919. }
  5920. else if (轮毂电机ToolStripMenuItem.Checked == true)
  5921. {
  5922. if (textBox_FacModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  5923. {
  5924. label_FacModeStatus.Text = "存在故障!";
  5925. label_FacModeResult.BackColor = Color.Red;
  5926. label_FacModeResult.Text = "标签格式错误";
  5927. button__FacMode_Start.Enabled = true;
  5928. return;
  5929. }
  5930. }
  5931. }
  5932. catch (System.Exception)
  5933. {
  5934. label_FacModeStatus.Text = "存在故障!";
  5935. label_FacModeResult.BackColor = Color.Red;
  5936. label_FacModeResult.Text = "标签格式错误";
  5937. button__FacMode_Start.Enabled = true;
  5938. return;
  5939. }
  5940. //打开串口
  5941. mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false);
  5942. if (!mySerialProcess.mySerial.IsOpen)
  5943. {
  5944. MessageBox.Show("请检查串口连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5945. //按钮禁止操作
  5946. button__FacMode_Start.Enabled = true;
  5947. return;
  5948. }
  5949. //流水号计数
  5950. int serial = Convert.ToInt32(label_FacModeSerial.Text);
  5951. serial += 1;
  5952. label_FacModeSerial.Text = serial.ToString();
  5953. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, serial.ToString());
  5954. //创建线程,执行测试任务
  5955. Thread th = new Thread(FacModeTest_Task);
  5956. th.Start();
  5957. }
  5958. /// <summary>
  5959. /// 执行一次测试任务
  5960. /// </summary>
  5961. private void FacModeTest_Task()
  5962. {
  5963. //开始测试
  5964. richTextBox_FacModeLog.AppendText("产品标签:" + textBox_FacModeScan.Text + "\r\n");
  5965. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  5966. //变量定义
  5967. var Code = new byte[255];//发送的指令数据
  5968. label_FacModeStatus.Text = "开始测试";
  5969. BootInfo = "";
  5970. Delay_ms(500);
  5971. label_FacModeStatus.Text = "系统开机";
  5972. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  5973. if (uARTToolStripMenuItem.Checked)
  5974. {
  5975. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送复位指令,切换联动装置盒波特率" + "\r\n");
  5976. Code[0] = (byte)'R';
  5977. Code[1] = (byte)'E';
  5978. Code[2] = (byte)'S';
  5979. Code[3] = (byte)'E';
  5980. Code[4] = (byte)'T';
  5981. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  5982. Delay_ms(500);
  5983. }
  5984. //发送开机指令
  5985. //确保测试前先关机,发送关机指令再发送开机指令
  5986. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  5987. Code[0] = 0xF0;
  5988. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5989. Delay_ms(1500);
  5990. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  5991. Code[0] = 0xF1;
  5992. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5993. ACK_WaitCnt = 0;
  5994. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  5995. while (ACK_WaitCnt <= 20) ; //10s,等待开机成功,联动装置盒控制器接口波特率需等待5s接口自动切换为9600
  5996. //检查BOOT版本
  5997. if (BootInfo != string.Empty)
  5998. {
  5999. label_FacModeBootVer.BackColor = Color.Green;
  6000. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  6001. Delay_ms(500);
  6002. }
  6003. else
  6004. {
  6005. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
  6006. label_FacModeStatus.Text = "存在故障!";
  6007. label_FacModeResult.BackColor = Color.Red;
  6008. label_FacModeResult.Text = "测试异常";
  6009. Delay_ms(500);
  6010. //存储异常并上传
  6011. FacMode_Stop(false);
  6012. return;
  6013. }
  6014. //系统清除
  6015. if (checkBox_FacModeSysClear.Checked)
  6016. {
  6017. do
  6018. {
  6019. #if false
  6020. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  6021. {
  6022. Code[0] = 0x00;//5S协议
  6023. Code[1] = 0x00;
  6024. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6025. Delay_ms(500);
  6026. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6027. Delay_ms(500);
  6028. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  6029. }
  6030. #endif
  6031. //发送系统清除指令
  6032. label_FacModeStatus.Text = "系统清除";
  6033. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除" + "\r\n");
  6034. Code[0] = (byte)'C';
  6035. Code[1] = (byte)'L';
  6036. Code[2] = (byte)'E';
  6037. Code[3] = (byte)'A';
  6038. Code[4] = (byte)'R';
  6039. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  6040. WriteACK = false;
  6041. ACK_WaitCnt = 0;
  6042. while (ACK_WaitCnt <= 6); //3s
  6043. //等待系统清除完成指令
  6044. if (WriteACK == true)
  6045. {
  6046. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  6047. label_FacModeSysClear.BackColor = Color.Green;
  6048. }
  6049. else
  6050. {
  6051. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除,重发第1次" + "\r\n");
  6052. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  6053. ACK_WaitCnt = 0;
  6054. while (ACK_WaitCnt <= 6) ; //3s
  6055. //等待系统清除完成指令
  6056. if (WriteACK == true)
  6057. {
  6058. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  6059. label_FacModeSysClear.BackColor = Color.Green;
  6060. }
  6061. else
  6062. {
  6063. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除,重发第2次" + "\r\n");
  6064. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  6065. ACK_WaitCnt = 0;
  6066. while (ACK_WaitCnt <= 6) ; //3s
  6067. //等待系统清除完成指令
  6068. if (WriteACK == true)
  6069. {
  6070. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  6071. label_FacModeSysClear.BackColor = Color.Green;
  6072. }
  6073. else
  6074. {
  6075. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除失败" + "\r\n");
  6076. label_FacModeStatus.Text = "存在故障!";
  6077. label_FacModeResult.BackColor = Color.Red;
  6078. label_FacModeResult.Text = "测试异常";
  6079. Delay_ms(500);
  6080. //存储异常并上传
  6081. FacMode_Stop(false);
  6082. return;
  6083. }
  6084. }
  6085. }
  6086. BootInfo = "";
  6087. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  6088. if (uARTToolStripMenuItem.Checked)
  6089. {
  6090. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送复位指令,切换联动装置盒波特率" + "\r\n");
  6091. Code[0] = (byte)'R';
  6092. Code[1] = (byte)'E';
  6093. Code[2] = (byte)'S';
  6094. Code[3] = (byte)'E';
  6095. Code[4] = (byte)'T';
  6096. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  6097. Delay_ms(500);
  6098. }
  6099. //系统清除后需重新开机
  6100. label_FacModeStatus.Text = "重新开机";
  6101. //确保测试前先关机,发送关机指令再发送开机指令
  6102. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新发送关机指令" + "\r\n");
  6103. Code[0] = 0xF0;
  6104. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6105. Delay_ms(1500);
  6106. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新发送开机指令" + "\r\n");
  6107. Code[0] = 0xF1;
  6108. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6109. ACK_WaitCnt = 0;
  6110. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  6111. while (ACK_WaitCnt <= 20); //10s
  6112. //获取Boot版本信息
  6113. if (BootInfo != string.Empty)
  6114. {
  6115. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机成功" + "\r\n");
  6116. Delay_ms(500);
  6117. }
  6118. else
  6119. {
  6120. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机失败" + "\r\n");
  6121. label_FacModeStatus.Text = "存在故障!";
  6122. label_FacModeResult.BackColor = Color.Red;
  6123. label_FacModeResult.Text = "测试异常";
  6124. Delay_ms(500);
  6125. //存储异常并上传
  6126. FacMode_Stop(false);
  6127. return;
  6128. }
  6129. } while (false);
  6130. }
  6131. else
  6132. {
  6133. label_FacModeSysClear.BackColor = Color.Yellow;
  6134. label_FacModeStatus.Text = "跳过系统清除!";
  6135. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过系统清除" + "\r\n");
  6136. Delay_ms(500);
  6137. }
  6138. #if false
  6139. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  6140. {
  6141. Code[0] = 0x00;//5S协议
  6142. Code[1] = 0x00;
  6143. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6144. Delay_ms(500);
  6145. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6146. Delay_ms(500);
  6147. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  6148. }
  6149. #endif
  6150. //检查是否有故障
  6151. if (textBox_ErrorCode.Text.Contains("H"))
  6152. {
  6153. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "故障码:" + textBox_ErrorCode.Text + "\r\n");
  6154. label_FacModeStatus.Text = "电机存在故障!";
  6155. label_FacModeResult.BackColor = Color.Red;
  6156. label_FacModeResult.Text = "测试异常";
  6157. Delay_ms(500);
  6158. //存储异常并上传
  6159. FacMode_Stop(false);
  6160. return;
  6161. }
  6162. //MOS内阻校准
  6163. if (checkBox_FacMode_MosCal.Checked)
  6164. {
  6165. label_FacModeStatus.Text = "MOS内阻校准";
  6166. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始MOS内阻校准" + "\r\n");
  6167. Delay_ms(500);
  6168. //提示进行负载切换
  6169. if (MessageBox.Show("电阻负载切换完成,开始校准?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
  6170. {
  6171. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "取消MOS内阻校准" + "\r\n");
  6172. label_FacModeStatus.Text = "存在故障!";
  6173. label_FacModeResult.BackColor = Color.Red;
  6174. label_FacModeResult.Text = "测试异常";
  6175. Delay_ms(500);
  6176. //存储异常并上传
  6177. FacMode_Stop(false);
  6178. return;
  6179. }
  6180. //确认后发送校准指令
  6181. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令" + "\r\n");
  6182. string[] K = toolStripTextBox_MosCalK.Text.Split(',');
  6183. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  6184. ushort uwDataTemp = 0;
  6185. uwDataTemp = Convert.ToUInt16(K[0]);
  6186. Code[2] = (byte)(uwDataTemp & 0xFF);
  6187. Code[3] = (byte)(uwDataTemp >> 8);
  6188. uwDataTemp = Convert.ToUInt16(K[1]);
  6189. Code[4] = (byte)(uwDataTemp & 0xFF);
  6190. Code[5] = (byte)(uwDataTemp >> 8);
  6191. uwDataTemp = Convert.ToUInt16(K[2]);
  6192. Code[6] = (byte)(uwDataTemp & 0xFF);
  6193. Code[7] = (byte)(uwDataTemp >> 8);
  6194. uwDataTemp = Convert.ToUInt16(K[3]);
  6195. Code[8] = (byte)(uwDataTemp & 0xFF);
  6196. Code[9] = (byte)(uwDataTemp >> 8);
  6197. uwDataTemp = Convert.ToUInt16(K[4]);
  6198. Code[10] = (byte)(uwDataTemp & 0xFF);
  6199. Code[11] = (byte)(uwDataTemp >> 8);
  6200. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  6201. WriteACK = false;
  6202. ACK_WaitCnt = 0;
  6203. while (ACK_WaitCnt <= 6) ; //3s
  6204. if (WriteACK == true)
  6205. {
  6206. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  6207. }
  6208. else
  6209. {
  6210. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令,第1次重发" + "\r\n");
  6211. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  6212. ACK_WaitCnt = 0;
  6213. while (ACK_WaitCnt <= 6) ; //3s
  6214. if (WriteACK == true)
  6215. {
  6216. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  6217. }
  6218. else
  6219. {
  6220. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令,第2次重发" + "\r\n");
  6221. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  6222. ACK_WaitCnt = 0;
  6223. while (ACK_WaitCnt <= 6) ; //3s
  6224. if (WriteACK == true)
  6225. {
  6226. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  6227. }
  6228. else
  6229. {
  6230. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准异常" + "\r\n");
  6231. label_FacModeStatus.Text = "存在故障!";
  6232. label_FacModeResult.BackColor = Color.Red;
  6233. label_FacModeResult.Text = "测试异常";
  6234. Delay_ms(500);
  6235. //存储异常并上传
  6236. FacMode_Stop(false);
  6237. return;
  6238. }
  6239. }
  6240. }
  6241. #if false
  6242. //因控制器复位需发送指令重新进入5S协议
  6243. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  6244. {
  6245. Code[0] = 0x00;//5S协议
  6246. Code[1] = 0x00;
  6247. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6248. Delay_ms(500);
  6249. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6250. Delay_ms(500);
  6251. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  6252. }
  6253. #endif
  6254. //读取显示校准返回数据
  6255. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果" + "\r\n");
  6256. foreach (Control c in groupBox21.Controls)
  6257. {
  6258. if (c is TextBox)
  6259. c.Text = "";
  6260. }
  6261. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  6262. ACK_WaitCnt = 0;
  6263. while (ACK_WaitCnt <= 2) ; //1s
  6264. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  6265. {
  6266. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果,第1次重发" + "\r\n");
  6267. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  6268. ACK_WaitCnt = 0;
  6269. while (ACK_WaitCnt <= 2) ; //1s
  6270. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  6271. {
  6272. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果,第2次重发" + "\r\n");
  6273. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  6274. ACK_WaitCnt = 0;
  6275. while (ACK_WaitCnt <= 2) ; //1s
  6276. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  6277. {
  6278. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果异常" + "\r\n");
  6279. label_FacModeStatus.Text = "存在故障!";
  6280. label_FacModeResult.BackColor = Color.Red;
  6281. label_FacModeResult.Text = "测试异常";
  6282. Delay_ms(500);
  6283. //存储异常并上传
  6284. FacMode_Stop(false);
  6285. return;
  6286. }
  6287. }
  6288. }
  6289. else
  6290. {
  6291. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻:" + textBox_MOS_R1.Text + " " + textBox_MOS_R2.Text + " " + textBox_MOS_R3.Text + "\r\n");
  6292. }
  6293. //与校准返回数据对比
  6294. string[] MOS_R1_Th = toolStripTextBox_MOS1.Text.Split(',');
  6295. string[] MOS_R2_Th = toolStripTextBox_MOS2.Text.Split(',');
  6296. string[] MOS_R3_Th = toolStripTextBox_MOS3.Text.Split(',');
  6297. if ((Convert.ToUInt16(textBox_MOS_R1.Text) >= Convert.ToUInt16(MOS_R1_Th[0])) && (Convert.ToUInt16(textBox_MOS_R1.Text) <= Convert.ToUInt16(MOS_R1_Th[1])) &&
  6298. (Convert.ToUInt16(textBox_MOS_R2.Text) >= Convert.ToUInt16(MOS_R2_Th[0])) && (Convert.ToUInt16(textBox_MOS_R2.Text) <= Convert.ToUInt16(MOS_R2_Th[1])) &&
  6299. (Convert.ToUInt16(textBox_MOS_R3.Text) >= Convert.ToUInt16(MOS_R3_Th[0])) && (Convert.ToUInt16(textBox_MOS_R3.Text) <= Convert.ToUInt16(MOS_R3_Th[1]))
  6300. )
  6301. {
  6302. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准合格" + "\r\n");
  6303. label_FacModeMosCal.BackColor = Color.Green;
  6304. //提示切换负载
  6305. MessageBox.Show("请将负载切换回电机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  6306. }
  6307. else
  6308. {
  6309. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准超范围" + "\r\n");
  6310. label_FacModeStatus.Text = "存在故障!";
  6311. label_FacModeResult.BackColor = Color.Red;
  6312. label_FacModeResult.Text = "测试异常";
  6313. Delay_ms(500);
  6314. //存储异常并上传
  6315. FacMode_Stop(false);
  6316. //提示切换负载
  6317. MessageBox.Show("请将负载切换回电机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  6318. return;
  6319. }
  6320. }
  6321. else
  6322. {
  6323. label_FacModeMosCal.BackColor = Color.Yellow;
  6324. label_FacModeStatus.Text = "跳过MOS内阻校准!";
  6325. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过MOS内阻校准" + "\r\n");
  6326. Delay_ms(500);
  6327. }
  6328. //位置校准
  6329. if (checkBox_FacMode_AngleCal.Checked)
  6330. {
  6331. //校准前进行一次开关机保存初始化数据
  6332. BootInfo = "";
  6333. label_FacModeStatus.Text = "位置校准";
  6334. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始位置校准" + "\r\n");
  6335. //确保测试前先关机,发送关机指令再发送开机指令
  6336. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  6337. Code[0] = 0xF0;
  6338. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6339. Delay_ms(1500);
  6340. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  6341. Code[0] = 0xF1;
  6342. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6343. ACK_WaitCnt = 0;
  6344. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  6345. while (ACK_WaitCnt <= 10) ; //5s
  6346. //获取Boot版本信息
  6347. if (BootInfo != string.Empty)
  6348. {
  6349. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机成功" + "\r\n");
  6350. Delay_ms(500);
  6351. }
  6352. else
  6353. {
  6354. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机失败" + "\r\n");
  6355. label_FacModeStatus.Text = "存在故障!";
  6356. label_FacModeResult.BackColor = Color.Red;
  6357. label_FacModeResult.Text = "测试异常";
  6358. Delay_ms(500);
  6359. //存储异常并上传
  6360. FacMode_Stop(false);
  6361. return;
  6362. }
  6363. //发送位置校准指令
  6364. for (int i = 0; i < 7; i++)
  6365. for (int j = 0; j < 6; j++)
  6366. {
  6367. dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = "";
  6368. }
  6369. foreach (Control cr in tabPage_AngleCal.Controls)
  6370. {
  6371. if (cr is TextBox)
  6372. {
  6373. if ((cr != textBox_AngleDiffTh) && (cr != textBox_AngleZeroTh))
  6374. cr.Text = "";
  6375. }
  6376. }
  6377. Code[0] = 0;
  6378. Code[1] = 0;
  6379. mySerialProcess.SendCmd((ushort)0x751, (byte)0x0C, (ushort)0x5002, Code);
  6380. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准中,请等待" + "\r\n");
  6381. ACK_WaitCnt = 0;
  6382. while (ACK_WaitCnt <= 50) ; //25s
  6383. //读取位置校准数据
  6384. if (textBox_AngleDiffAvg.Text == string.Empty)
  6385. {
  6386. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准失败" + "\r\n");
  6387. label_FacModeStatus.Text = "存在故障!";
  6388. label_FacModeResult.BackColor = Color.Red;
  6389. label_FacModeResult.Text = "测试异常";
  6390. Delay_ms(500);
  6391. //存储异常并上传
  6392. FacMode_Stop(false);
  6393. return;
  6394. }
  6395. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准数据:" + "\r\n");
  6396. for (int i = 0; i < 7; i++)
  6397. {
  6398. richTextBox_FacModeLog.AppendText("电周期" + (i + 1).ToString()+":");
  6399. for (int j = 0; j < 6; j++)
  6400. {
  6401. richTextBox_FacModeLog.AppendText(dataGridView_AngleCal.Rows[i].Cells[j + 1].Value.ToString() + ", ");
  6402. }
  6403. richTextBox_FacModeLog.AppendText("\r\n");
  6404. Delay_ms(200);
  6405. }
  6406. richTextBox_FacModeLog.AppendText("最小偏差:" + textBox_AngleDiffMin.Text+ ", " + "\r\n");
  6407. richTextBox_FacModeLog.AppendText("最大偏差:" + textBox_AngleDiffMax.Text + ", " + "\r\n");
  6408. richTextBox_FacModeLog.AppendText("平均偏差:" + textBox_AngleDiffAvg.Text + ", " + "\r\n");
  6409. richTextBox_FacModeLog.AppendText("历史零点:" + textBox_AngleZeroInit.Text + ", " + "\r\n");
  6410. richTextBox_FacModeLog.AppendText("当前零点:" + textBox_AngleZeroCur.Text + ", " + "\r\n");
  6411. richTextBox_FacModeLog.AppendText("零点偏差:" + textBox_AngleZeroDiff.Text + ", " + "\r\n");
  6412. //比较位置偏差
  6413. if ((Math.Abs(Convert.ToDouble(textBox_AngleDiffMin.Text)) > Convert.ToDouble(textBox_AngleDiffTh.Text)) ||
  6414. (Math.Abs(Convert.ToDouble(textBox_AngleDiffMax.Text)) > Convert.ToDouble(textBox_AngleDiffTh.Text)) ||
  6415. (Math.Abs(Convert.ToDouble(textBox_AngleDiffAvg.Text)) > Convert.ToDouble(textBox_AngleZeroTh.Text))
  6416. )
  6417. {
  6418. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差过大,无法校准" + "\r\n");
  6419. label_FacModeStatus.Text = "存在故障!";
  6420. label_FacModeResult.BackColor = Color.Red;
  6421. label_FacModeResult.Text = "测试异常";
  6422. Delay_ms(500);
  6423. //存储异常并上传
  6424. FacMode_Stop(false);
  6425. return;
  6426. }
  6427. //写入校准偏差值
  6428. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差满足要求,写入校准数据" + "\r\n");
  6429. double data1 = Convert.ToDouble(textBox_AngleZeroInit.Text) - Convert.ToDouble(textBox_AngleDiffAvg.Text);
  6430. if (data1 > 360)
  6431. {
  6432. data1 -= 360;
  6433. }
  6434. else if (data1 < -360)
  6435. {
  6436. data1 += 360;
  6437. }
  6438. Int16 data2 = (Int16)(data1 * 32768 / 360);
  6439. Code[0] = 0x01;
  6440. Code[1] = 0x00;
  6441. Code[2] = (byte)(data2);
  6442. Code[3] = (byte)(data2 >> 8);
  6443. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
  6444. WriteACK = false;
  6445. ACK_WaitCnt = 0;
  6446. while (ACK_WaitCnt <= 2) ; //1s
  6447. if (WriteACK == true)
  6448. {
  6449. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
  6450. }
  6451. else
  6452. {
  6453. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入位置偏差,第1次重发" + "\r\n");
  6454. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
  6455. WriteACK = false;
  6456. ACK_WaitCnt = 0;
  6457. while (ACK_WaitCnt <= 2) ; //1s
  6458. if (WriteACK == true)
  6459. {
  6460. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
  6461. }
  6462. else
  6463. {
  6464. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入位置偏差,第2次重发" + "\r\n");
  6465. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
  6466. WriteACK = false;
  6467. ACK_WaitCnt = 0;
  6468. while (ACK_WaitCnt <= 2) ; //1s
  6469. if (WriteACK == true)
  6470. {
  6471. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
  6472. }
  6473. else
  6474. {
  6475. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入失败" + "\r\n");
  6476. label_FacModeStatus.Text = "存在故障!";
  6477. label_FacModeResult.BackColor = Color.Red;
  6478. label_FacModeResult.Text = "测试异常";
  6479. Delay_ms(500);
  6480. //存储异常并上传
  6481. FacMode_Stop(false);
  6482. return;
  6483. }
  6484. }
  6485. }
  6486. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准正常,位置偏差值:" + textBox_AngleDiffAvg.Text + "\r\n");
  6487. label_FacModeAngleCal.BackColor = Color.Green;
  6488. }
  6489. else
  6490. {
  6491. label_FacModeAngleCal.BackColor = Color.Yellow;
  6492. label_FacModeStatus.Text = "跳过位置校准!";
  6493. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过位置校准" + "\r\n");
  6494. Delay_ms(500);
  6495. }
  6496. //参数写入
  6497. if (checkBox_FacModeCfgWrite.Checked)
  6498. {
  6499. label_FacModeStatus.Text = "参数写入";
  6500. //写入产品型号和SN
  6501. do
  6502. {
  6503. //根据扫码信息获取型号和SN
  6504. string ScanInfo = textBox_FacModeScan.Text;
  6505. string regexInfo = "";
  6506. string[] InfoList = { "" };
  6507. try
  6508. {
  6509. if (中置电机ToolStripMenuItem.Checked == true)
  6510. {
  6511. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  6512. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  6513. }
  6514. else if (轮毂电机ToolStripMenuItem.Checked == true)
  6515. {
  6516. if (!ScanInfo.Contains("/")) //老编码规则
  6517. {
  6518. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  6519. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  6520. string Spec = InfoList[1];
  6521. string Sn = InfoList[2];
  6522. InfoList[0] = Model.Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  6523. InfoList[1] = Sn;
  6524. }
  6525. else //新编码规则
  6526. {
  6527. Dictionary<string, string> Dic_Ver = new Dictionary<string, string>
  6528. {
  6529. { "01", "A" },
  6530. { "02", "B" },
  6531. { "03", "C" },
  6532. { "04", "D" },
  6533. { "05", "E" },
  6534. { "06", "F" },
  6535. { "07", "G" },
  6536. { "08", "H" },
  6537. { "09", "I" }
  6538. };
  6539. Dictionary<string, string> Dic_Vol = new Dictionary<string, string>
  6540. {
  6541. { "24V", "A" },
  6542. { "36V", "B" },
  6543. { "42V", "C" },
  6544. { "48V", "D" },
  6545. { "52V", "E" },
  6546. { "60V", "F" }
  6547. };
  6548. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  6549. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  6550. string Spec = InfoList[1].Replace("-", "").Replace("/", "");
  6551. string Sn = InfoList[2];
  6552. InfoList[0] = Model[2] + Dic_Ver[Model.Substring(3, 2)] + Model[5] + Dic_Ver[Model.Substring(6, 2)] + Model[9];
  6553. InfoList[0] += Dic_Vol[Spec.Substring(0, 3)] + Spec.Substring(3, 3) + Spec.Substring(13, 4) + Spec.Substring(Spec.Length - 4, 3);
  6554. InfoList[1] = Sn;
  6555. }
  6556. }
  6557. }
  6558. catch
  6559. {
  6560. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  6561. label_FacModeStatus.Text = "存在故障!";
  6562. label_FacModeResult.BackColor = Color.Red;
  6563. label_FacModeResult.Text = "标签格式错误";
  6564. Delay_ms(500);
  6565. //存储异常并上传
  6566. FacMode_Stop(false);
  6567. return;
  6568. }
  6569. if (InfoList.Length >= 2)
  6570. {
  6571. //检查配置文件是否与打标信息一致
  6572. //...
  6573. //写入型号
  6574. label_FacModeStatus.Text = "写入型号";
  6575. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号" + "\r\n");
  6576. textBox_FacModeName.Text = InfoList[0];
  6577. string Mode = textBox_FacModeName.Text;
  6578. var ModeArray = new byte[16];
  6579. for (ushort i = 0; i < Mode.Length; i++)
  6580. {
  6581. ModeArray[i] = (byte)Mode[i];
  6582. }
  6583. if (Mode.Length < 16)
  6584. {
  6585. ModeArray[Mode.Length] = (byte)'.';
  6586. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  6587. {
  6588. ModeArray[Mode.Length + 1 + i] = 0x20;
  6589. }
  6590. }
  6591. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6592. WriteACK = false;
  6593. ACK_WaitCnt = 0;
  6594. while (ACK_WaitCnt <= 2); //1s
  6595. if (WriteACK == true)
  6596. {
  6597. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6598. }
  6599. else
  6600. {
  6601. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号,第1次重发" + "\r\n");
  6602. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6603. ACK_WaitCnt = 0;
  6604. while (ACK_WaitCnt <= 2) ; //1s
  6605. if (WriteACK == true)
  6606. {
  6607. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6608. }
  6609. else
  6610. {
  6611. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号,第2次重发" + "\r\n");
  6612. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6613. ACK_WaitCnt = 0;
  6614. while (ACK_WaitCnt <= 2) ; //1s
  6615. if (WriteACK == true)
  6616. {
  6617. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6618. }
  6619. else
  6620. {
  6621. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入失败" + "\r\n");
  6622. label_FacModeStatus.Text = "存在故障!";
  6623. label_FacModeResult.BackColor = Color.Red;
  6624. label_FacModeResult.Text = "测试异常";
  6625. Delay_ms(500);
  6626. //存储异常并上传
  6627. FacMode_Stop(false);
  6628. return;
  6629. }
  6630. }
  6631. }
  6632. //写入SN
  6633. label_FacModeStatus.Text = "写入SN";
  6634. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN" + "\r\n");
  6635. textBox_FacModeNum.Text = InfoList[1];
  6636. string SN = textBox_FacModeNum.Text;
  6637. var SNArray = new byte[16];
  6638. for (ushort i = 0; i < SN.Length; i++)
  6639. {
  6640. SNArray[i] = (byte)SN[i];
  6641. }
  6642. if (SN.Length < 16)
  6643. {
  6644. SNArray[SN.Length] = (byte)'.';
  6645. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  6646. {
  6647. SNArray[SN.Length + 1 + i] = 0x20;
  6648. }
  6649. }
  6650. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6651. WriteACK = false;
  6652. ACK_WaitCnt = 0;
  6653. while (ACK_WaitCnt <= 2); //1s
  6654. if (WriteACK == true)
  6655. {
  6656. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  6657. }
  6658. else
  6659. {
  6660. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN,第1次重发" + "\r\n");
  6661. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6662. ACK_WaitCnt = 0;
  6663. while (ACK_WaitCnt <= 2) ; //1s
  6664. if (WriteACK == true)
  6665. {
  6666. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  6667. }
  6668. else
  6669. {
  6670. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN,第2次重发" + "\r\n");
  6671. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6672. ACK_WaitCnt = 0;
  6673. while (ACK_WaitCnt <= 2) ; //1s
  6674. if (WriteACK == true)
  6675. {
  6676. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  6677. }
  6678. else
  6679. {
  6680. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入失败" + "\r\n");
  6681. label_FacModeStatus.Text = "存在故障!";
  6682. label_FacModeResult.BackColor = Color.Red;
  6683. label_FacModeResult.Text = "测试异常";
  6684. Delay_ms(500);
  6685. //存储异常并上传
  6686. FacMode_Stop(false);
  6687. return;
  6688. }
  6689. }
  6690. }
  6691. }
  6692. else
  6693. {
  6694. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6695. return;
  6696. }
  6697. } while (false);
  6698. //写入配置文件
  6699. do
  6700. {
  6701. label_FacModeStatus.Text = "写入配置文件";
  6702. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  6703. //配置文件
  6704. List<byte[]> CmdList = new List<byte[]>();
  6705. //从服务器下载文件
  6706. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  6707. {
  6708. string SelectFile = "";
  6709. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "/" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  6710. if (File.Exists(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  6711. {
  6712. File.Delete(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  6713. }
  6714. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  6715. //打开文件
  6716. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  6717. CmdList.Clear();
  6718. while (streamReader.Peek() != -1)
  6719. {
  6720. string fileLineInfo = streamReader.ReadLine();
  6721. if (fileLineInfo.IndexOf("[") != -1)
  6722. {
  6723. continue;
  6724. }
  6725. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  6726. }
  6727. streamReader.Close();
  6728. }
  6729. //加载本地文件
  6730. else
  6731. {
  6732. string SelectFile = "";
  6733. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  6734. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  6735. CmdList.Clear();
  6736. while (streamReader.Peek() != -1)
  6737. {
  6738. string fileLineInfo = streamReader.ReadLine();
  6739. if (fileLineInfo.IndexOf("[") != -1)
  6740. {
  6741. continue;
  6742. }
  6743. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  6744. }
  6745. streamReader.Close();
  6746. }
  6747. int CmdNum = CmdList.Count(); //指令个数
  6748. Delay_ms(500);
  6749. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "开始写入" + "\r\n");
  6750. Delay_ms(500);
  6751. //开始写入
  6752. for (int i = 0; i < CmdList.Count; i++)
  6753. {
  6754. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令" + "\r\n");
  6755. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6756. WriteACK = false;
  6757. ACK_WaitCnt = 0;
  6758. while (ACK_WaitCnt <= 2) ; //1s
  6759. if (WriteACK == true)
  6760. {
  6761. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6762. }
  6763. else
  6764. {
  6765. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令,第1次重发" + "\r\n");
  6766. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6767. WriteACK = false;
  6768. ACK_WaitCnt = 0;
  6769. while (ACK_WaitCnt <= 2) ; //1s
  6770. if (WriteACK == true)
  6771. {
  6772. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6773. }
  6774. else
  6775. {
  6776. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令,第2次重发" + "\r\n");
  6777. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6778. WriteACK = false;
  6779. ACK_WaitCnt = 0;
  6780. while (ACK_WaitCnt <= 2) ; //1s
  6781. if (WriteACK == true)
  6782. {
  6783. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6784. }
  6785. else
  6786. {
  6787. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入失败," + "共" + CmdNum.ToString() + "条指令," + "写入成功" + i.ToString() + "条" + "\r\n");
  6788. label_FacModeStatus.Text = "存在故障!";
  6789. label_FacModeResult.BackColor = Color.Red;
  6790. label_FacModeResult.Text = "测试异常";
  6791. Delay_ms(500);
  6792. //存储异常并上传
  6793. FacMode_Stop(false);
  6794. return;
  6795. }
  6796. }
  6797. }
  6798. }
  6799. //写入完成
  6800. label_FacMode_CfgWrite.BackColor = Color.Green;
  6801. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入成功" + "\r\n");
  6802. Delay_ms(500);
  6803. } while (false);
  6804. }
  6805. else
  6806. {
  6807. label_FacMode_CfgWrite.BackColor = Color.Yellow;
  6808. label_FacModeStatus.Text = "跳过参数写入!";
  6809. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数写入" + "\r\n");
  6810. Delay_ms(500);
  6811. }
  6812. //BMS通讯
  6813. if (checkBox_FacModeBMS.Checked)
  6814. {
  6815. if (label_FacModeBMS.BackColor == Color.Red)
  6816. {
  6817. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "BMS通讯异常" + "\r\n");
  6818. label_FacModeStatus.Text = "存在故障!";
  6819. label_FacModeResult.BackColor = Color.Red;
  6820. label_FacModeResult.Text = "测试异常";
  6821. Delay_ms(500);
  6822. //存储异常并上传
  6823. FacMode_Stop(false);
  6824. return;
  6825. }
  6826. }
  6827. else
  6828. {
  6829. label_FacModeBMS.BackColor = Color.Yellow;
  6830. label_FacModeStatus.Text = "跳过BMS通讯检测!";
  6831. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过BMS通讯检测" + "\r\n");
  6832. Delay_ms(500);
  6833. }
  6834. //基础功能检测
  6835. if (checkBox_FacBaseFucTest.Checked)
  6836. {
  6837. label_FacModeStatus.Text = "基础功能检测";
  6838. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始基础功能检测" + "\r\n");
  6839. //确认负载位置
  6840. if (checkBox_FacMode_MosCal.Checked)
  6841. {
  6842. if (MessageBox.Show("请再次确认负载是否切换回电机?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  6843. {
  6844. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "负载已切换为电机,继续测试" + "\r\n");
  6845. }
  6846. else
  6847. {
  6848. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试取消" + "\r\n");
  6849. label_FacModeStatus.Text = "存在故障!";
  6850. label_FacModeResult.BackColor = Color.Red;
  6851. label_FacModeResult.Text = "测试异常";
  6852. Delay_ms(500);
  6853. //存储异常并上传
  6854. FacMode_Stop(false);
  6855. return;
  6856. }
  6857. }
  6858. //发送指令进入配置模式
  6859. do
  6860. {
  6861. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6862. Code[0] = 0x01;
  6863. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6864. WriteACK = false;
  6865. ACK_WaitCnt = 0;
  6866. while (ACK_WaitCnt <= 2); //1s
  6867. if (textBox_RunInfo_Vol.Text != "---")
  6868. {
  6869. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6870. }
  6871. else
  6872. {
  6873. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  6874. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6875. ACK_WaitCnt = 0;
  6876. while (ACK_WaitCnt <= 2) ; //1s
  6877. if (textBox_RunInfo_Vol.Text != "---")
  6878. {
  6879. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6880. }
  6881. else
  6882. {
  6883. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  6884. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6885. ACK_WaitCnt = 0;
  6886. while (ACK_WaitCnt <= 2) ; //1s
  6887. if (textBox_RunInfo_Vol.Text != "---")
  6888. {
  6889. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6890. }
  6891. else
  6892. {
  6893. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  6894. label_FacModeStatus.Text = "存在故障!";
  6895. label_FacModeResult.BackColor = Color.Red;
  6896. label_FacModeResult.Text = "测试异常";
  6897. Delay_ms(500);
  6898. //存储异常并上传
  6899. FacMode_Stop(false);
  6900. return;
  6901. }
  6902. }
  6903. }
  6904. } while (false);
  6905. //发送指令启动电机
  6906. do
  6907. {
  6908. #if false //通过运行模式3启动电机
  6909. //发送指令读取调试信息
  6910. richTextBox_DebugParam.Clear();
  6911. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  6912. WriteACK = false;
  6913. ACK_WaitCnt = 0;
  6914. while (ACK_WaitCnt <= 2); //1s
  6915. //获取调试信息
  6916. string DebugDefaultInfo = "";
  6917. if (richTextBox_DebugParam.Text == string.Empty)
  6918. {
  6919. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
  6920. label_FacModeStatus.Text = "存在故障!";
  6921. label_FacModeResult.BackColor = Color.Red;
  6922. label_FacModeResult.Text = "测试异常";
  6923. Delay_ms(500);
  6924. //存储异常并上传
  6925. FacMode_Stop(false);
  6926. return;
  6927. }
  6928. else
  6929. {
  6930. DebugDefaultInfo = richTextBox_DebugParam.Text;
  6931. }
  6932. //设置模式
  6933. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  6934. strDataTemp[0] = "整体运行模式=3";
  6935. //发送数据
  6936. Code[0] = 0;
  6937. Code[1] = 0;
  6938. for (int i = 0; i < strDataTemp.Length; i++)
  6939. {
  6940. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  6941. Code[2 * i + 2] = (byte)uwDataTemp;
  6942. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  6943. }
  6944. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  6945. label_FacModeStatus.Text = "启动电机";
  6946. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "启动电机" + "\r\n");
  6947. #else //通过Walk模式启动电机
  6948. //设置转速100%
  6949. var Data = new byte[1];
  6950. Data[0] = (byte)100;
  6951. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6952. Delay_ms(500);
  6953. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6954. Delay_ms(500);
  6955. //启动电机进入WALK模式
  6956. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "基础功能检测,进入WALK" + "\r\n");
  6957. Code[0] = 0x22;
  6958. Code[1] = 0xF0;
  6959. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6960. WriteACK = false;
  6961. ACK_WaitCnt = 0;
  6962. while (ACK_WaitCnt <= 2) ; //1s
  6963. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6964. {
  6965. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第1次重发" + "\r\n");
  6966. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6967. ACK_WaitCnt = 0;
  6968. while (ACK_WaitCnt <= 2) ; //1s
  6969. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6970. {
  6971. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第2次重发" + "\r\n");
  6972. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6973. ACK_WaitCnt = 0;
  6974. while (ACK_WaitCnt <= 2) ; //1s
  6975. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6976. {
  6977. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
  6978. label_FacModeStatus.Text = "存在故障!";
  6979. label_FacModeResult.BackColor = Color.Red;
  6980. label_FacModeResult.Text = "测试异常";
  6981. Delay_ms(500);
  6982. //存储异常并上传
  6983. FacMode_Stop(false);
  6984. return;
  6985. }
  6986. }
  6987. }
  6988. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入WALK,开始检测" + "\r\n");
  6989. #endif
  6990. Delay_ms(3000);
  6991. } while (false);
  6992. //判断车速
  6993. if ((Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) <= Convert.ToDouble( toolStripTextBox_ThBikeSpeed.Text.Split(',')[1])) &&
  6994. (Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThBikeSpeed.Text.Split(',')[0])))
  6995. {
  6996. label_FacModeSpeed.BackColor = Color.Green;
  6997. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器正常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
  6998. }
  6999. else
  7000. {
  7001. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器异常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
  7002. label_FacModeStatus.Text = "存在故障!";
  7003. label_FacModeResult.BackColor = Color.Red;
  7004. label_FacModeResult.Text = "测试异常";
  7005. Delay_ms(500);
  7006. //存储异常并上传
  7007. FacMode_Stop(false);
  7008. return;
  7009. }
  7010. //判断电压
  7011. if ((Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[1])) &&
  7012. (Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[0])))
  7013. {
  7014. label_FacModeVolTest.BackColor = Color.Green;
  7015. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量正常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
  7016. }
  7017. else
  7018. {
  7019. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量异常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
  7020. label_FacModeStatus.Text = "存在故障!";
  7021. label_FacModeResult.BackColor = Color.Red;
  7022. label_FacModeResult.Text = "测试异常";
  7023. Delay_ms(500);
  7024. //存储异常并上传
  7025. FacMode_Stop(false);
  7026. return;
  7027. }
  7028. //判断电流
  7029. if ((Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[1])) &&
  7030. (Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[0])))
  7031. {
  7032. label_FacModeCurrentTest.BackColor = Color.Green;
  7033. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量正常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  7034. }
  7035. else
  7036. {
  7037. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量异常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  7038. label_FacModeStatus.Text = "存在故障!";
  7039. label_FacModeResult.BackColor = Color.Red;
  7040. label_FacModeResult.Text = "测试异常";
  7041. Delay_ms(500);
  7042. //存储异常并上传
  7043. FacMode_Stop(false);
  7044. return;
  7045. }
  7046. //判断温度
  7047. if ((Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[1])) &&
  7048. (Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[0])) &&
  7049. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[1])) &&
  7050. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[0])) &&
  7051. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[1])) &&
  7052. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[0])))
  7053. {
  7054. label_FacModeNTC.BackColor = Color.Green;
  7055. 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");
  7056. }
  7057. else
  7058. {
  7059. 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");
  7060. label_FacModeStatus.Text = "存在故障!";
  7061. label_FacModeResult.BackColor = Color.Red;
  7062. label_FacModeResult.Text = "测试异常";
  7063. Delay_ms(500);
  7064. //存储异常并上传
  7065. FacMode_Stop(false);
  7066. return;
  7067. }
  7068. //判断转速
  7069. if ((Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[1])) &&
  7070. (Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[0])))
  7071. {
  7072. label_FacModeMotorSpeed.BackColor = Color.Green;
  7073. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速正常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
  7074. }
  7075. else
  7076. {
  7077. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速异常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
  7078. label_FacModeStatus.Text = "存在故障!";
  7079. label_FacModeResult.BackColor = Color.Red;
  7080. label_FacModeResult.Text = "测试异常";
  7081. Delay_ms(500);
  7082. //存储异常并上传
  7083. FacMode_Stop(false);
  7084. return;
  7085. }
  7086. //发送指令停止电机
  7087. do
  7088. {
  7089. //设置转速0%
  7090. var Data = new byte[1];
  7091. Data[0] = (byte)0;
  7092. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7093. Delay_ms(500);
  7094. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7095. Delay_ms(500);
  7096. #if false //通过修改调试模式停止电机
  7097. //获取调试信息
  7098. string DebugDefaultInfo = "";
  7099. if (richTextBox_DebugParam.Text == string.Empty)
  7100. {
  7101. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
  7102. label_FacModeStatus.Text = "存在故障!";
  7103. label_FacModeResult.BackColor = Color.Red;
  7104. label_FacModeResult.Text = "测试异常";
  7105. Delay_ms(500);
  7106. //存储异常并上传
  7107. FacMode_Stop(false);
  7108. return;
  7109. }
  7110. else
  7111. {
  7112. DebugDefaultInfo = richTextBox_DebugParam.Text;
  7113. }
  7114. //设置模式
  7115. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  7116. //发送数据
  7117. Code[0] = 0;
  7118. Code[1] = 0;
  7119. for (int i = 0; i < strDataTemp.Length; i++)
  7120. {
  7121. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  7122. Code[2 * i + 2] = (byte)uwDataTemp;
  7123. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  7124. }
  7125. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  7126. label_FacModeStatus.Text = "停止电机";
  7127. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "停止电机" + "\r\n");
  7128. #else //通过调整档位停止电机
  7129. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK" + "\r\n");
  7130. Code[0] = 0x00;
  7131. Code[1] = 0xF0;
  7132. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7133. WriteACK = false;
  7134. ACK_WaitCnt = 0;
  7135. while (ACK_WaitCnt <= 2) ; //1s
  7136. if (textBox_RunInfo_GearSt.Text != "OFF")
  7137. {
  7138. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK,第1次重发" + "\r\n");
  7139. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7140. ACK_WaitCnt = 0;
  7141. while (ACK_WaitCnt <= 2) ; //1s
  7142. if (textBox_RunInfo_GearSt.Text != "OFF")
  7143. {
  7144. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK,第2次重发" + "\r\n");
  7145. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7146. ACK_WaitCnt = 0;
  7147. while (ACK_WaitCnt <= 2) ; //1s
  7148. if (textBox_RunInfo_GearSt.Text != "OFF")
  7149. {
  7150. }
  7151. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
  7152. label_FacModeStatus.Text = "存在故障!";
  7153. label_FacModeResult.BackColor = Color.Red;
  7154. label_FacModeResult.Text = "测试异常";
  7155. Delay_ms(500);
  7156. //存储异常并上传
  7157. FacMode_Stop(false);
  7158. return;
  7159. }
  7160. }
  7161. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已退出WALK,基础功能检测完成" + "\r\n");
  7162. #endif
  7163. Delay_ms(2000);
  7164. } while (false);
  7165. }
  7166. else
  7167. {
  7168. label_FacModeSpeed.BackColor = Color.Yellow;
  7169. label_FacModeVolTest.BackColor = Color.Yellow;
  7170. label_FacModeCurrentTest.BackColor = Color.Yellow;
  7171. label_FacModeNTC.BackColor = Color.Yellow;
  7172. label_FacModeMotorSpeed.BackColor = Color.Yellow;
  7173. label_FacModeStatus.Text = "跳过基础功能检测!";
  7174. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过基础功能检测" + "\r\n");
  7175. Delay_ms(500);
  7176. }
  7177. //力矩检测
  7178. if (checkBox_FacTor.Checked)
  7179. {
  7180. label_FacModeStatus.Text = "力矩传感器检测!";
  7181. //发送指令进入配置模式
  7182. do
  7183. {
  7184. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  7185. {
  7186. break;
  7187. }
  7188. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  7189. Code[0] = 0x01;
  7190. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7191. WriteACK = false;
  7192. ACK_WaitCnt = 0;
  7193. while (ACK_WaitCnt <= 2) ; //1s
  7194. if (textBox_RunInfo_Vol.Text != "---")
  7195. {
  7196. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7197. Delay_ms(500);
  7198. }
  7199. else
  7200. {
  7201. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  7202. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7203. ACK_WaitCnt = 0;
  7204. while (ACK_WaitCnt <= 2) ; //1s
  7205. if (textBox_RunInfo_Vol.Text != "---")
  7206. {
  7207. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7208. Delay_ms(500);
  7209. }
  7210. else
  7211. {
  7212. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7213. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7214. ACK_WaitCnt = 0;
  7215. while (ACK_WaitCnt <= 2) ; //1s
  7216. if (textBox_RunInfo_Vol.Text != "---")
  7217. {
  7218. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7219. Delay_ms(500);
  7220. }
  7221. else
  7222. {
  7223. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7224. label_FacModeStatus.Text = "存在故障!";
  7225. label_FacModeResult.BackColor = Color.Red;
  7226. label_FacModeResult.Text = "测试异常";
  7227. Delay_ms(500);
  7228. //存储异常并上传
  7229. FacMode_Stop(false);
  7230. return;
  7231. }
  7232. }
  7233. }
  7234. } while (false);
  7235. ushort Max = 0, Torque = 0;
  7236. //提示输入力矩信号
  7237. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟力矩信号输入" + "\r\n");
  7238. ACK_WaitCnt = 0;
  7239. while (ACK_WaitCnt <= 20) //10s
  7240. {
  7241. //获取力矩值
  7242. Torque = (ushort)Convert.ToInt16(textBox_RunInfo_Torque.Text.Split(' ')[0]);
  7243. if (Torque > Max)
  7244. Max = Torque;
  7245. if ((Max <= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[1])) &&
  7246. (Max >= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[0])) &&
  7247. (ACK_WaitCnt >= 6))
  7248. {
  7249. label_FacModeTq.BackColor = Color.Green;
  7250. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器正常" + " " + textBox_RunInfo_Torque.Text + "\r\n");
  7251. break;
  7252. }
  7253. }
  7254. if (ACK_WaitCnt >= 20)
  7255. {
  7256. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器异常" + " " + textBox_RunInfo_Torque.Text + "\r\n");
  7257. label_FacModeStatus.Text = "存在故障!";
  7258. label_FacModeResult.BackColor = Color.Red;
  7259. label_FacModeResult.Text = "测试异常";
  7260. Delay_ms(500);
  7261. //存储异常并上传
  7262. FacMode_Stop(false);
  7263. return;
  7264. }
  7265. }
  7266. else
  7267. {
  7268. label_FacModeTq.BackColor = Color.Yellow;
  7269. label_FacModeStatus.Text = "跳过力矩检测!";
  7270. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过力矩检测" + "\r\n");
  7271. Delay_ms(500);
  7272. }
  7273. //踏频检测
  7274. if (checkBox_FacCad.Checked)
  7275. {
  7276. label_FacModeStatus.Text = "踏频传感器检测!";
  7277. //发送指令进入配置模式
  7278. do
  7279. {
  7280. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  7281. {
  7282. break;
  7283. }
  7284. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  7285. Code[0] = 0x01;
  7286. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7287. WriteACK = false;
  7288. ACK_WaitCnt = 0;
  7289. while (ACK_WaitCnt <= 2) ; //1s
  7290. if (textBox_RunInfo_Vol.Text != "---")
  7291. {
  7292. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7293. Delay_ms(500);
  7294. }
  7295. else
  7296. {
  7297. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  7298. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7299. ACK_WaitCnt = 0;
  7300. while (ACK_WaitCnt <= 2) ; //1s
  7301. if (textBox_RunInfo_Vol.Text != "---")
  7302. {
  7303. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7304. Delay_ms(500);
  7305. }
  7306. else
  7307. {
  7308. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7309. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7310. ACK_WaitCnt = 0;
  7311. while (ACK_WaitCnt <= 2) ; //1s
  7312. if (textBox_RunInfo_Vol.Text != "---")
  7313. {
  7314. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7315. Delay_ms(500);
  7316. }
  7317. else
  7318. {
  7319. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7320. label_FacModeStatus.Text = "存在故障!";
  7321. label_FacModeResult.BackColor = Color.Red;
  7322. label_FacModeResult.Text = "测试异常";
  7323. Delay_ms(500);
  7324. //存储异常并上传
  7325. FacMode_Stop(false);
  7326. return;
  7327. }
  7328. }
  7329. }
  7330. } while (false);
  7331. ushort Max = 0, Cadence = 0;
  7332. //提示输入踏频信号
  7333. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟踏频信号输入" + "\r\n");
  7334. ACK_WaitCnt = 0;
  7335. while (ACK_WaitCnt <= 20) //10s
  7336. {
  7337. //获取踏频
  7338. Cadence = (ushort)Convert.ToInt16(textBox_RunInfo_Cadence.Text.Split(' ')[0]);
  7339. if (Cadence > Max)
  7340. Max = Cadence;
  7341. if ((Max <= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[1])) &&
  7342. (Max >= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[0])) &&
  7343. (ACK_WaitCnt >= 6))
  7344. {
  7345. label_FacModeCad.BackColor = Color.Green;
  7346. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器正常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  7347. break;
  7348. }
  7349. }
  7350. if (ACK_WaitCnt >= 20)
  7351. {
  7352. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器异常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  7353. label_FacModeStatus.Text = "存在故障!";
  7354. label_FacModeResult.BackColor = Color.Red;
  7355. label_FacModeResult.Text = "测试异常";
  7356. Delay_ms(500);
  7357. //存储异常并上传
  7358. FacMode_Stop(false);
  7359. return;
  7360. }
  7361. }
  7362. else
  7363. {
  7364. label_FacModeCad.BackColor = Color.Yellow;
  7365. label_FacModeStatus.Text = "跳过踏频检测!";
  7366. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过踏频检测" + "\r\n");
  7367. Delay_ms(500);
  7368. }
  7369. //转把检测
  7370. if (checkBox_FacThrrotleTest.Checked)
  7371. {
  7372. label_FacModeStatus.Text = "转把检测";
  7373. //发送指令进入配置模式
  7374. do
  7375. {
  7376. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  7377. {
  7378. break;
  7379. }
  7380. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  7381. Code[0] = 0x01;
  7382. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7383. WriteACK = false;
  7384. ACK_WaitCnt = 0;
  7385. while (ACK_WaitCnt <= 2) ; //1s
  7386. if (textBox_RunInfo_Vol.Text != "---")
  7387. {
  7388. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7389. Delay_ms(500);
  7390. }
  7391. else
  7392. {
  7393. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  7394. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7395. ACK_WaitCnt = 0;
  7396. while (ACK_WaitCnt <= 2) ; //1s
  7397. if (textBox_RunInfo_Vol.Text != "---")
  7398. {
  7399. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7400. Delay_ms(500);
  7401. }
  7402. else
  7403. {
  7404. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7405. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7406. ACK_WaitCnt = 0;
  7407. while (ACK_WaitCnt <= 2) ; //1s
  7408. if (textBox_RunInfo_Vol.Text != "---")
  7409. {
  7410. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7411. Delay_ms(500);
  7412. }
  7413. else
  7414. {
  7415. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7416. label_FacModeStatus.Text = "存在故障!";
  7417. label_FacModeResult.BackColor = Color.Red;
  7418. label_FacModeResult.Text = "测试异常";
  7419. Delay_ms(500);
  7420. //存储异常并上传
  7421. FacMode_Stop(false);
  7422. return;
  7423. }
  7424. }
  7425. }
  7426. } while (false);
  7427. //进入TURBO档
  7428. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把检测,发送指令进入TURBO" + "\r\n");
  7429. Code[0] = 0x04;
  7430. Code[1] = 0xF0;
  7431. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7432. WriteACK = false;
  7433. ACK_WaitCnt = 0;
  7434. while (ACK_WaitCnt <= 2) ; //1s
  7435. if (textBox_RunInfo_GearSt.Text != "TURBO")
  7436. {
  7437. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO,第1次重发" + "\r\n");
  7438. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7439. ACK_WaitCnt = 0;
  7440. while (ACK_WaitCnt <= 2) ; //1s
  7441. if (textBox_RunInfo_GearSt.Text != "TURBO")
  7442. {
  7443. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO,第2次重发" + "\r\n");
  7444. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7445. ACK_WaitCnt = 0;
  7446. while (ACK_WaitCnt <= 2) ; //1s
  7447. if (textBox_RunInfo_GearSt.Text != "TURBO")
  7448. {
  7449. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO异常" + "\r\n");
  7450. label_FacModeStatus.Text = "存在故障!";
  7451. label_FacModeResult.BackColor = Color.Red;
  7452. label_FacModeResult.Text = "测试异常";
  7453. Delay_ms(500);
  7454. //存储异常并上传
  7455. FacMode_Stop(false);
  7456. return;
  7457. }
  7458. }
  7459. }
  7460. //进入TURBO后,如果电机直接启动,认为转把电压异常
  7461. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把自检,请松开转把" + "\r\n");
  7462. Delay_ms(3000);
  7463. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) > 500)
  7464. {
  7465. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把电压异常" + "\r\n");
  7466. label_FacModeStatus.Text = "存在故障!";
  7467. label_FacModeResult.BackColor = Color.Red;
  7468. label_FacModeResult.Text = "测试异常";
  7469. Delay_ms(500);
  7470. //存储异常并上传
  7471. FacMode_Stop(false);
  7472. return;
  7473. }
  7474. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把自检正常" + "\r\n");
  7475. Delay_ms(500);
  7476. //提示转动转把
  7477. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入TURBO,10s内转动转把" + "\r\n");
  7478. ACK_WaitCnt = 0;
  7479. while (ACK_WaitCnt <= 20)
  7480. {
  7481. if ((Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) > 500) && (ACK_WaitCnt >= 10))
  7482. {
  7483. label_FacModeGas.BackColor = Color.Green;
  7484. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能正常,松开转把" + "\r\n");
  7485. break;
  7486. }
  7487. }
  7488. if (ACK_WaitCnt >= 20) //转把超时
  7489. {
  7490. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能异常,松开转把" + "\r\n");
  7491. label_FacModeStatus.Text = "存在故障!";
  7492. label_FacModeResult.BackColor = Color.Red;
  7493. label_FacModeResult.Text = "测试异常";
  7494. Delay_ms(500);
  7495. //存储异常并上传
  7496. FacMode_Stop(false);
  7497. return;
  7498. }
  7499. }
  7500. else
  7501. {
  7502. label_FacModeGas.BackColor = Color.Yellow;
  7503. label_FacModeStatus.Text = "跳过转把检测!";
  7504. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过转把检测" + "\r\n");
  7505. Delay_ms(500);
  7506. }
  7507. //刹车检测
  7508. if (checkBox_FacBreakTest.Checked)
  7509. {
  7510. label_FacModeStatus.Text = "刹把检测";
  7511. //发送指令进入配置模式
  7512. do
  7513. {
  7514. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  7515. {
  7516. break;
  7517. }
  7518. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  7519. Code[0] = 0x01;
  7520. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7521. WriteACK = false;
  7522. ACK_WaitCnt = 0;
  7523. while (ACK_WaitCnt <= 2) ; //1s
  7524. if (textBox_RunInfo_Vol.Text != "---")
  7525. {
  7526. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7527. Delay_ms(500);
  7528. }
  7529. else
  7530. {
  7531. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  7532. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7533. ACK_WaitCnt = 0;
  7534. while (ACK_WaitCnt <= 2) ; //1s
  7535. if (textBox_RunInfo_Vol.Text != "---")
  7536. {
  7537. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7538. Delay_ms(500);
  7539. }
  7540. else
  7541. {
  7542. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7543. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7544. ACK_WaitCnt = 0;
  7545. while (ACK_WaitCnt <= 2) ; //1s
  7546. if (textBox_RunInfo_Vol.Text != "---")
  7547. {
  7548. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7549. Delay_ms(500);
  7550. }
  7551. else
  7552. {
  7553. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7554. label_FacModeStatus.Text = "存在故障!";
  7555. label_FacModeResult.BackColor = Color.Red;
  7556. label_FacModeResult.Text = "测试异常";
  7557. Delay_ms(500);
  7558. //存储异常并上传
  7559. FacMode_Stop(false);
  7560. return;
  7561. }
  7562. }
  7563. }
  7564. } while (false);
  7565. //测试前先确定电机已停止
  7566. UInt16 WaitTime = 10;
  7567. do
  7568. {
  7569. WaitTime--;
  7570. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 100)
  7571. {
  7572. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机停止,开始进行剎把检测,进入WALK" + "\r\n");
  7573. break;
  7574. }
  7575. if (WaitTime == 0)
  7576. {
  7577. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机无法停止,剎把检测异常" + "\r\n");
  7578. label_FacModeStatus.Text = "存在故障!";
  7579. label_FacModeResult.BackColor = Color.Red;
  7580. label_FacModeResult.Text = "测试异常";
  7581. Delay_ms(500);
  7582. //存储异常并上传
  7583. FacMode_Stop(false);
  7584. return;
  7585. }
  7586. Delay_ms(500);
  7587. } while (true);
  7588. //设置转速100%
  7589. var Data = new byte[1];
  7590. Data[0] = (byte)100;
  7591. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7592. Delay_ms(500);
  7593. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7594. Delay_ms(500);
  7595. //启动电机进入WALK模式
  7596. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把检测,进入WALK" + "\r\n");
  7597. Code[0] = 0x22;
  7598. Code[1] = 0xF0;
  7599. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7600. WriteACK = false;
  7601. ACK_WaitCnt = 0;
  7602. while (ACK_WaitCnt <= 2) ; //1s
  7603. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 500))
  7604. {
  7605. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第1次重发" + "\r\n");
  7606. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7607. ACK_WaitCnt = 0;
  7608. while (ACK_WaitCnt <= 2) ; //1s
  7609. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 500))
  7610. {
  7611. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第2次重发" + "\r\n");
  7612. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7613. ACK_WaitCnt = 0;
  7614. while (ACK_WaitCnt <= 2) ; //1s
  7615. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 500))
  7616. {
  7617. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
  7618. label_FacModeStatus.Text = "存在故障!";
  7619. label_FacModeResult.BackColor = Color.Red;
  7620. label_FacModeResult.Text = "测试异常";
  7621. Delay_ms(500);
  7622. //存储异常并上传
  7623. FacMode_Stop(false);
  7624. return;
  7625. }
  7626. }
  7627. }
  7628. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,10s内操作剎把" + "\r\n");
  7629. ACK_WaitCnt = 0;
  7630. while (ACK_WaitCnt <= 20)
  7631. {
  7632. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 100)
  7633. {
  7634. label_FacModeBreak.BackColor = Color.Green;
  7635. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把功能正常,松开剎把" + "\r\n");
  7636. break;
  7637. }
  7638. }
  7639. if (ACK_WaitCnt >= 20) //剎把超时
  7640. {
  7641. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速:" + textBox_RunInfo_MotorSpeed.Text + "," + "剎把功能异常,松开剎把" + "\r\n");
  7642. label_FacModeStatus.Text = "存在故障!";
  7643. label_FacModeResult.BackColor = Color.Red;
  7644. label_FacModeResult.Text = "测试异常";
  7645. Delay_ms(500);
  7646. //存储异常并上传
  7647. FacMode_Stop(false);
  7648. return;
  7649. }
  7650. //停止电机
  7651. Code[0] = 0x00;
  7652. Code[1] = 0xF0;
  7653. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7654. WriteACK = false;
  7655. ACK_WaitCnt = 0;
  7656. while (ACK_WaitCnt <= 2) ; //1s
  7657. if (textBox_RunInfo_GearSt.Text != "OFF")
  7658. {
  7659. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK,第1次重发" + "\r\n");
  7660. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7661. ACK_WaitCnt = 0;
  7662. while (ACK_WaitCnt <= 2) ; //1s
  7663. if (textBox_RunInfo_GearSt.Text != "OFF")
  7664. {
  7665. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK,第2次重发" + "\r\n");
  7666. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7667. ACK_WaitCnt = 0;
  7668. while (ACK_WaitCnt <= 2) ; //1s
  7669. if (textBox_RunInfo_GearSt.Text != "OFF")
  7670. {
  7671. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
  7672. label_FacModeStatus.Text = "存在故障!";
  7673. label_FacModeResult.BackColor = Color.Red;
  7674. label_FacModeResult.Text = "测试异常";
  7675. Delay_ms(500);
  7676. //存储异常并上传
  7677. FacMode_Stop(false);
  7678. return;
  7679. }
  7680. }
  7681. }
  7682. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK" + "\r\n");
  7683. Delay_ms(500);
  7684. }
  7685. else
  7686. {
  7687. label_FacModeBreak.BackColor = Color.Yellow;
  7688. label_FacModeStatus.Text = "跳过刹车检测!";
  7689. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过刹车检测" + "\r\n");
  7690. Delay_ms(500);
  7691. }
  7692. //前后灯检测
  7693. if (checkBox_FacLightTest.Checked)
  7694. {
  7695. //前后灯检测
  7696. label_FacModeStatus.Text = "前后灯检测";
  7697. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开灯指令" + "\r\n");
  7698. //发送指令打开车灯
  7699. Code[0] = 0x00;
  7700. Code[1] = 0xF1;
  7701. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7702. WriteACK = false;
  7703. ACK_WaitCnt = 0;
  7704. while (ACK_WaitCnt <= 2) ; //1s
  7705. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7706. {
  7707. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令,第1次重发" + "\r\n");
  7708. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7709. ACK_WaitCnt = 0;
  7710. while (ACK_WaitCnt <= 2); //1s
  7711. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7712. {
  7713. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令,第2次重发" + "\r\n");
  7714. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7715. ACK_WaitCnt = 0;
  7716. while (ACK_WaitCnt <= 2) ; //1s
  7717. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7718. {
  7719. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令发送异常" + "\r\n");
  7720. label_FacModeStatus.Text = "存在故障!";
  7721. label_FacModeResult.BackColor = Color.Red;
  7722. label_FacModeResult.Text = "测试异常";
  7723. Delay_ms(500);
  7724. //存储异常并上传
  7725. FacMode_Stop(false);
  7726. return;
  7727. }
  7728. }
  7729. }
  7730. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已打开前后灯" + "\r\n");
  7731. Delay_ms(500);
  7732. //提示检查灯压是否正确
  7733. if (MessageBox.Show("前后灯是否正常开启?", "前后灯判断", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  7734. {
  7735. label_FacModeLightF.BackColor = Color.Green;
  7736. label_FacModeLightB.BackColor = Color.Green;
  7737. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯正常" + "\r\n");
  7738. Delay_ms(500);
  7739. }
  7740. else
  7741. {
  7742. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯异常" + "\r\n");
  7743. label_FacModeStatus.Text = "存在故障!";
  7744. label_FacModeResult.BackColor = Color.Red;
  7745. label_FacModeResult.Text = "测试异常";
  7746. Delay_ms(500);
  7747. //存储异常并上传
  7748. FacMode_Stop(false);
  7749. return;
  7750. }
  7751. //发送指令关闭车灯
  7752. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关灯指令" + "\r\n");
  7753. Code[0] = 0x00;
  7754. Code[1] = 0xF0;
  7755. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7756. WriteACK = false;
  7757. ACK_WaitCnt = 0;
  7758. while (ACK_WaitCnt <= 2) ; //1s
  7759. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7760. {
  7761. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令,第1次重发" + "\r\n");
  7762. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7763. ACK_WaitCnt = 0;
  7764. while (ACK_WaitCnt <= 2) ; //1s
  7765. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7766. {
  7767. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令,第2次重发" + "\r\n");
  7768. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7769. ACK_WaitCnt = 0;
  7770. while (ACK_WaitCnt <= 2) ; //1s
  7771. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7772. {
  7773. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令发送异常" + "\r\n");
  7774. label_FacModeStatus.Text = "存在故障!";
  7775. label_FacModeResult.BackColor = Color.Red;
  7776. label_FacModeResult.Text = "测试异常";
  7777. Delay_ms(500);
  7778. //存储异常并上传
  7779. FacMode_Stop(false);
  7780. return;
  7781. }
  7782. }
  7783. }
  7784. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已关闭前后灯" + "\r\n");
  7785. Delay_ms(500);
  7786. }
  7787. else
  7788. {
  7789. label_FacModeLightF.BackColor = Color.Yellow;
  7790. label_FacModeLightB.BackColor = Color.Yellow;
  7791. label_FacModeStatus.Text = "跳过前后灯检测!";
  7792. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过前后灯检测" + "\r\n");
  7793. Delay_ms(500);
  7794. }
  7795. //软件版本检测
  7796. do
  7797. {
  7798. label_FacModeStatus.Text = "软件版本确认";
  7799. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  7800. //发送指令读取版本
  7801. Class_Motor_Ver.Mode = "---";
  7802. Class_Motor_Ver.SN = "---";
  7803. Class_Motor_Ver.HW = "---";
  7804. Class_Motor_Ver.FW = "---";
  7805. Class_Motor_Ver.Special = "---";
  7806. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7807. ACK_WaitCnt = 0;
  7808. while (ACK_WaitCnt <= 2) ; //1s
  7809. if (Class_Motor_Ver.Mode == "---")
  7810. {
  7811. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第1次重发" + "\r\n");
  7812. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7813. ACK_WaitCnt = 0;
  7814. while (ACK_WaitCnt <= 2) ; //1s
  7815. if (Class_Motor_Ver.Mode == "---")
  7816. {
  7817. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第2次重发" + "\r\n");
  7818. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7819. ACK_WaitCnt = 0;
  7820. while (ACK_WaitCnt <= 2) ; //1s
  7821. if (Class_Motor_Ver.Mode == "---")
  7822. {
  7823. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息失败" + "\r\n");
  7824. label_FacModeStatus.Text = "存在故障!";
  7825. label_FacModeResult.BackColor = Color.Red;
  7826. label_FacModeResult.Text = "测试异常";
  7827. Delay_ms(500);
  7828. //存储异常并上传
  7829. FacMode_Stop(false);
  7830. return;
  7831. }
  7832. }
  7833. }
  7834. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  7835. richTextBox_FacModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  7836. richTextBox_FacModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  7837. richTextBox_FacModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  7838. richTextBox_FacModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  7839. richTextBox_FacModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  7840. //判断版本是否正确
  7841. string VerCheck = comboBox_FacModeCfgFile.Text.Split('_')[3] + "_" + comboBox_FacModeCfgFile.Text.Split('_')[4];
  7842. string VerRead = "";
  7843. try
  7844. {
  7845. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  7846. }
  7847. catch (System.Exception)
  7848. {
  7849. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  7850. label_FacModeStatus.Text = "存在故障!";
  7851. label_FacModeResult.BackColor = Color.Red;
  7852. label_FacModeResult.Text = "测试异常";
  7853. Delay_ms(500);
  7854. //存储异常并上传
  7855. FacMode_Stop(false);
  7856. return;
  7857. }
  7858. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  7859. {
  7860. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
  7861. label_FacModeStatus.Text = "存在故障!";
  7862. label_FacModeResult.BackColor = Color.Red;
  7863. label_FacModeResult.Text = "测试异常";
  7864. Delay_ms(500);
  7865. //存储异常并上传
  7866. FacMode_Stop(false);
  7867. return;
  7868. }
  7869. label_FacModeFWVersion.BackColor = Color.Green;
  7870. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  7871. Delay_ms(500);
  7872. } while (false);
  7873. //测试合格
  7874. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  7875. label_FacModeStatus.Text = "测试结束!";
  7876. label_FacModeResult.BackColor = Color.Green;
  7877. label_FacModeResult.Text = "测试合格";
  7878. Delay_ms(500);
  7879. //存储并上传
  7880. FacMode_Stop(true);
  7881. return;
  7882. }
  7883. private void FacModelLabelInit()
  7884. {
  7885. //测试状态标签
  7886. label_FacModeResult.BackColor = Color.Yellow;
  7887. label_FacModeResult.Text = "测试中";
  7888. //测试过程标签
  7889. label_FacModeStatus.Text = "测试就绪";
  7890. //测试结果标签
  7891. foreach (Control c in groupBox28.Controls)
  7892. {
  7893. if (c is Label)
  7894. {
  7895. if (c.Text == string.Empty)
  7896. c.BackColor = Color.Red;
  7897. }
  7898. }
  7899. }
  7900. private void comboBox_CheckModeCfgDate_Click(object sender, EventArgs e)
  7901. {
  7902. //更新生产配置文件目录
  7903. GetDateList(false);
  7904. }
  7905. private void comboBox_FacModeCfgDate_Click(object sender, EventArgs e)
  7906. {
  7907. //更新生产配置文件目录
  7908. GetDateList(false);
  7909. }
  7910. private void richTextBox_FacModeLog_TextChanged(object sender, EventArgs e)
  7911. {
  7912. richTextBox_FacModeLog.SelectionStart = richTextBox_FacModeLog.Text.Length;
  7913. richTextBox_FacModeLog.ScrollToCaret();
  7914. }
  7915. /// <summary>
  7916. /// 参数检验测试停止
  7917. /// </summary>
  7918. /// <param name="OK_Flag"></param>
  7919. private void CheckMode_Stop(bool OK_Flag)
  7920. {
  7921. //打开开始按钮
  7922. button_CheckModeStart.Enabled = true;
  7923. //导出电机参数
  7924. string Params = "";
  7925. do
  7926. {
  7927. if (!OK_Flag)
  7928. {
  7929. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试异常,停止导出" + "\r\n");
  7930. break;
  7931. }
  7932. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "导出电机存储参数" + "\r\n");
  7933. //读取一次马达参数
  7934. richTextBox_MotorParam.Clear();
  7935. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break; ;
  7936. Delay_ms(100);
  7937. Params += "[马达参数]" + "\r\n" + richTextBox_MotorParam.Text + "\r\n";
  7938. Params += "\r\n";
  7939. //读取一次整车参数
  7940. richTextBox_BikeParam.Clear();
  7941. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  7942. Delay_ms(100);
  7943. Params += "[整车参数]" + "\r\n" + richTextBox_BikeParam.Text + "\r\n";
  7944. Params += "\r\n";
  7945. //读取一次控制参数
  7946. richTextBox_ControlParam.Clear();
  7947. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  7948. Delay_ms(100);
  7949. Params += "[控制参数]" + "\r\n" + richTextBox_ControlParam.Text + "\r\n";
  7950. Params += "\r\n";
  7951. //查询传感器
  7952. richTextBox_SensorParam.Clear();
  7953. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  7954. Delay_ms(100);
  7955. Params += "[传感器参数]" + "\r\n" + richTextBox_SensorParam.Text + "\r\n";
  7956. Params += "\r\n";
  7957. //读取15次助力参数
  7958. Params += "[助力参数]" + "\r\n";
  7959. for (int i = 1; i <= 15; i++)
  7960. {
  7961. var ConfigParam = new byte[4];
  7962. richTextBox_AssistParam.Clear();
  7963. ConfigParam[0] = (byte)(i & 0xFF);
  7964. ConfigParam[1] = (byte)(i >> 8);
  7965. ConfigParam[2] = (byte)(((i >= 5) ? 5 : i) & 0xFF);
  7966. ConfigParam[3] = (byte)(((i >= 5) ? 5 : i) >> 8);
  7967. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  7968. Delay_ms(200);
  7969. Params += richTextBox_AssistParam.Text + "\r\n";
  7970. Params += "\r\n";
  7971. }
  7972. //读取一次调试信息
  7973. richTextBox_DebugParam.Clear();
  7974. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  7975. Delay_ms(100);
  7976. Params += "[调试参数]" + "\r\n" + richTextBox_DebugParam.Text + "\r\n";
  7977. Params += "\r\n";
  7978. //读取一次历史信息
  7979. richTextBox_Record.Clear();
  7980. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  7981. Delay_ms(100);
  7982. Params += "[历史信息]" + "\r\n" + richTextBox_Record.Text + "\r\n";
  7983. Params += "\r\n";
  7984. //读取一次MOS内阻校准参数
  7985. foreach (Control c in groupBox21.Controls)
  7986. {
  7987. if (c is TextBox)
  7988. c.Text = "";
  7989. }
  7990. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  7991. Delay_ms(100);
  7992. Params += "[MOS内阻校准参数]" + "\r\n";
  7993. Params += textBox_MOS_K1.Text + ", " + textBox_MOS_K2.Text + ", " + textBox_MOS_K3.Text + ", " + textBox_MOS_K4.Text + ", "
  7994. + textBox_MOS_K5.Text + ", " + textBox_MOS_R1.Text + ", " + textBox_MOS_R2.Text + ", " + textBox_MOS_R3.Text + ", " + "\r\n";
  7995. Params += "\r\n";
  7996. //读取一次整车参数2
  7997. richTextBox_BikeParam2.Clear();
  7998. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null)) break;
  7999. Delay_ms(100);
  8000. Params += "[整车参数2]" + "\r\n" + richTextBox_BikeParam2.Text + "\r\n";
  8001. Params += "\r\n";
  8002. //读取一次用户骑行参数
  8003. richTextBox_UsrRidesParam.Clear();
  8004. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  8005. Delay_ms(100);
  8006. Params += "[用户骑行参数]" + "\r\n" + richTextBox_UsrRidesParam.Text + "\r\n";
  8007. Params += "\r\n";
  8008. //读取一次生产信息
  8009. textBox_MAC.Text = "";
  8010. textBox_MACAdd.Text = "";
  8011. textBox_MACDate.Text = "";
  8012. textBox_PP.Text = "";
  8013. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  8014. Delay_ms(100);
  8015. Params += "[生产信息]" + "\r\n";
  8016. Params += "生产商: " + textBox_MAC.Text + "\r\n";
  8017. Params += "生产地: " + textBox_MACAdd.Text + "\r\n";
  8018. Params += "生产日期: " + textBox_MACDate.Text + "\r\n";
  8019. Params += "产品标识: " + textBox_PP.Text + "\r\n";
  8020. Params += "\r\n";
  8021. //读取一次自定义信息
  8022. textBox_User1.Text = "---";
  8023. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  8024. Delay_ms(100);
  8025. textBox_User2.Text = "---";
  8026. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  8027. Delay_ms(100);
  8028. textBox_User3.Text = "---";
  8029. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  8030. Delay_ms(100);
  8031. Params += "[自定义信息]" + "\r\n";
  8032. Params += "自定义1: " + textBox_User1.Text + "\r\n";
  8033. Params += "自定义2: " + textBox_User2.Text + "\r\n";
  8034. Params += "自定义3: " + textBox_User3.Text + "\r\n";
  8035. Params += "\r\n";
  8036. //读取一次密钥
  8037. textBox_Key.Text = "---";
  8038. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  8039. Delay_ms(100);
  8040. Params += "[校验密钥]" + "\r\n" + textBox_Key.Text + "\r\n";
  8041. Params += "\r\n";
  8042. //读取一次存储标志
  8043. radioButton_EE_SaveYes.Checked = false;
  8044. radioButton_EE_SaveNo.Checked = false;
  8045. radioButton_SIP_SaveYes.Checked = false;
  8046. radioButton_SIP_SaveNo.Checked = false;
  8047. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  8048. Delay_ms(100);
  8049. Params += "[存储标志]" + "\r\n";
  8050. Params += "EEPROM: " + ((radioButton_EE_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  8051. Params += "SIP: " + ((radioButton_SIP_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  8052. Params += "\r\n";
  8053. } while (false);
  8054. //系统关机
  8055. var Code = new byte[32];//发送的指令数据
  8056. Code[0] = 0xF0;
  8057. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  8058. //关闭串口
  8059. //mySerialProcess.SerialClose(false);
  8060. //路径设置
  8061. string LocalSavePath = "";
  8062. string ServerSavePath = "";
  8063. if (OK_Flag)
  8064. {
  8065. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "OK\\";
  8066. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/OK/";
  8067. }
  8068. else
  8069. {
  8070. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "FAIL\\";
  8071. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/FAIL/";
  8072. }
  8073. if (Directory.Exists(LocalSavePath) == false)
  8074. {
  8075. Directory.CreateDirectory(LocalSavePath);
  8076. }
  8077. //保存和上传
  8078. string LogSavePath = "";
  8079. string LogSaveFileName = "";
  8080. string ProductInfo = textBox_CheckModeScan.Text.Replace(" ", "_").Replace("/", "-"); ;
  8081. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  8082. if (Directory.Exists(LogSavePath) == false)
  8083. {
  8084. Directory.CreateDirectory(LogSavePath);
  8085. }
  8086. //测试页面
  8087. Double scaleX = PrimaryScreen.ScaleX;
  8088. Double scaleY = PrimaryScreen.ScaleY;
  8089. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  8090. Graphics g = Graphics.FromImage(bit);
  8091. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  8092. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  8093. bit.Save(LogSaveFileName);
  8094. //上传测试页面到服务器
  8095. if (myFtp.IsNetConnected == true)
  8096. {
  8097. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  8098. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  8099. {
  8100. myFtp.MakeDir(ServerSavePath + DateNow);
  8101. }
  8102. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  8103. {
  8104. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  8105. }
  8106. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  8107. if (result == true)
  8108. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  8109. }
  8110. //测试记录
  8111. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  8112. string file_str = "";
  8113. file_str += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  8114. file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  8115. file_str += "检验记录:\r\n" + richTextBox_CheckModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  8116. file_str += "检验结果:\r\n" + label_CheckModeResult.Text + "\r\n\r\n";
  8117. file_str += Local_HdInformation;
  8118. file_str += "\r\n电机存储参数:\r\n" + Params + "\r\n";
  8119. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  8120. //上传测试记录到服务器
  8121. if (myFtp.IsNetConnected == true)
  8122. {
  8123. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  8124. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  8125. {
  8126. myFtp.MakeDir(ServerSavePath + DateNow);
  8127. }
  8128. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  8129. {
  8130. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  8131. }
  8132. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  8133. if (result == true)
  8134. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  8135. }
  8136. //扫码框清空
  8137. textBox_CheckModeScan.Text = "";
  8138. }
  8139. /// <summary>
  8140. /// 参数检验开始
  8141. /// </summary>
  8142. /// <param name="sender"></param>
  8143. /// <param name="e"></param>
  8144. private void button_CheckModeStart_Click(object sender, EventArgs e)
  8145. {
  8146. //测试项目关闭编辑
  8147. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  8148. foreach (Control c in groupBox29.Controls)
  8149. {
  8150. if (c is CheckBox)
  8151. c.Enabled = false;
  8152. }
  8153. ReadLockStatus = true;
  8154. //检查配置文件
  8155. if (comboBox_CheckModeCfgFile.Text == "")
  8156. {
  8157. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  8158. return;
  8159. }
  8160. //开始测试
  8161. CheckTestStart();
  8162. }
  8163. /// <summary>
  8164. /// 参数检验测试子函数
  8165. /// </summary>
  8166. private void CheckTestStart()
  8167. {
  8168. //初始化标签
  8169. CheckModeLabelInit();
  8170. richTextBox_CheckModeLog.Clear();
  8171. //按钮禁止操作
  8172. button_CheckModeStart.Enabled = false;
  8173. //记录配置文件
  8174. richTextBox_CheckModeLog.AppendText("配置文件:" + comboBox_CheckModeCfgDate.Text + " / " + comboBox_CheckModeCfgFile.Text + "\r\n");
  8175. //检查打标信息
  8176. label_CheckModeStatus.Text = "检查扫码信息";
  8177. Delay_ms(500);
  8178. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  8179. if (textBox_CheckModeScan.Text == string.Empty)
  8180. {
  8181. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  8182. button__FacMode_Start.Enabled = false;
  8183. return;
  8184. }
  8185. try
  8186. {
  8187. if (中置电机ToolStripMenuItem.Checked == true)
  8188. {
  8189. if (textBox_CheckModeScan.Text.Split(' ').Length != 7)
  8190. {
  8191. label_CheckModeStatus.Text = "存在故障!";
  8192. label_CheckModeResult.BackColor = Color.Red;
  8193. label_CheckModeResult.Text = "标签格式错误";
  8194. button_CheckModeStart.Enabled = true;
  8195. return;
  8196. }
  8197. }
  8198. else if (轮毂电机ToolStripMenuItem.Checked == true)
  8199. {
  8200. if (textBox_CheckModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  8201. {
  8202. label_CheckModeStatus.Text = "存在故障!";
  8203. label_CheckModeResult.BackColor = Color.Red;
  8204. label_CheckModeResult.Text = "标签格式错误";
  8205. button_CheckModeStart.Enabled = true;
  8206. return;
  8207. }
  8208. }
  8209. }
  8210. catch (System.Exception)
  8211. {
  8212. label_CheckModeStatus.Text = "存在故障!";
  8213. label_CheckModeResult.BackColor = Color.Red;
  8214. label_CheckModeResult.Text = "标签格式错误";
  8215. button_CheckModeStart.Enabled = true;
  8216. return;
  8217. }
  8218. //打开串口
  8219. mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false);
  8220. if (!mySerialProcess.mySerial.IsOpen)
  8221. {
  8222. MessageBox.Show("请检查串口连接!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  8223. button__FacMode_Start.Enabled = false;
  8224. return;
  8225. }
  8226. //流水号计数
  8227. int serial = Convert.ToInt32(label_CheckModeSerial.Text);
  8228. serial += 1;
  8229. label_CheckModeSerial.Text = serial.ToString();
  8230. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, serial.ToString());
  8231. //创建线程,执行测试任务
  8232. Thread th = new Thread(CheckModeTest_Task);
  8233. th.Start();
  8234. }
  8235. /// <summary>
  8236. /// 执行一次测试任务
  8237. /// </summary>
  8238. private void CheckModeTest_Task()
  8239. {
  8240. //开始测试
  8241. richTextBox_CheckModeLog.AppendText("产品标签:" + textBox_CheckModeScan.Text + "\r\n");
  8242. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  8243. //变量定义
  8244. var Code = new byte[255];//发送的指令数据
  8245. ushort DataTemp;
  8246. short DataTemp_Int16;
  8247. string ResultPathName = "";
  8248. label_CheckModeStatus.Text = "开始测试";
  8249. BootInfo = "";
  8250. Delay_ms(500);
  8251. label_CheckModeStatus.Text = "系统开机";
  8252. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  8253. if (uARTToolStripMenuItem.Checked)
  8254. {
  8255. Code[0] = (byte)'R';
  8256. Code[1] = (byte)'E';
  8257. Code[2] = (byte)'S';
  8258. Code[3] = (byte)'E';
  8259. Code[4] = (byte)'T';
  8260. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  8261. Delay_ms(500);
  8262. }
  8263. //系统开机,确保测试前先关机,发送关机指令再发送开机指令
  8264. //确保测试前先关机,发送关机指令再发送开机指令
  8265. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  8266. Code[0] = 0xF0;
  8267. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  8268. Delay_ms(1500);
  8269. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  8270. Code[0] = 0xF1;
  8271. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  8272. ACK_WaitCnt = 0;
  8273. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  8274. while (ACK_WaitCnt <= 20) ; //10s
  8275. //检查BOOT版本
  8276. if (BootInfo != string.Empty)
  8277. {
  8278. label_CheckModeBoot.BackColor = Color.Green;
  8279. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  8280. Delay_ms(500);
  8281. }
  8282. else
  8283. {
  8284. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
  8285. label_CheckModeStatus.Text = "存在故障!";
  8286. label_CheckModeResult.BackColor = Color.Red;
  8287. label_CheckModeResult.Text = "测试异常";
  8288. Delay_ms(500);
  8289. //存储异常并上传
  8290. CheckMode_Stop(false);
  8291. return;
  8292. }
  8293. #if false
  8294. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  8295. {
  8296. Code[0] = 0x00;//5S协议
  8297. Code[1] = 0x00;
  8298. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  8299. Delay_ms(500);
  8300. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  8301. Delay_ms(500);
  8302. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  8303. }
  8304. #endif
  8305. //发送指令读取版本信息
  8306. do
  8307. {
  8308. label_CheckModeStatus.Text = "读取版本信息";
  8309. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  8310. //发送指令读取版本
  8311. Class_Motor_Ver.Mode = "---";
  8312. Class_Motor_Ver.SN = "---";
  8313. Class_Motor_Ver.HW = "---";
  8314. Class_Motor_Ver.FW = "---";
  8315. Class_Motor_Ver.Special = "---";
  8316. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  8317. ACK_WaitCnt = 0;
  8318. while (ACK_WaitCnt <= 2) ; //1s
  8319. if (Class_Motor_Ver.Mode == "---")
  8320. {
  8321. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第1次重发" + "\r\n");
  8322. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  8323. ACK_WaitCnt = 0;
  8324. while (ACK_WaitCnt <= 2) ; //1s
  8325. if (Class_Motor_Ver.Mode == "---")
  8326. {
  8327. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第2次重发" + "\r\n");
  8328. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  8329. ACK_WaitCnt = 0;
  8330. while (ACK_WaitCnt <= 2) ; //1s
  8331. if (Class_Motor_Ver.Mode == "---")
  8332. {
  8333. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取失败" + "\r\n");
  8334. label_CheckModeStatus.Text = "存在故障!";
  8335. label_CheckModeResult.BackColor = Color.Red;
  8336. label_CheckModeResult.Text = "测试异常";
  8337. Delay_ms(500);
  8338. //存储异常并上传
  8339. CheckMode_Stop(false);
  8340. return;
  8341. }
  8342. }
  8343. }
  8344. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  8345. richTextBox_CheckModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  8346. richTextBox_CheckModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  8347. richTextBox_CheckModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  8348. richTextBox_CheckModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  8349. richTextBox_CheckModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  8350. Delay_ms(500);
  8351. } while (false);
  8352. //软件版本检查
  8353. if (checkBox_CheckModeFWVer.Checked)
  8354. {
  8355. //判断版本是否正确
  8356. string VerCheck = comboBox_CheckModeCfgFile.Text.Split('_')[3] + "_" + comboBox_CheckModeCfgFile.Text.Split('_')[4];
  8357. string VerRead = "";
  8358. try
  8359. {
  8360. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  8361. }
  8362. catch (System.Exception)
  8363. {
  8364. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  8365. label_CheckModeStatus.Text = "存在故障!";
  8366. label_CheckModeResult.BackColor = Color.Red;
  8367. label_CheckModeResult.Text = "测试异常";
  8368. Delay_ms(500);
  8369. //存储异常并上传
  8370. CheckMode_Stop(false);
  8371. return;
  8372. }
  8373. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  8374. {
  8375. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
  8376. label_CheckModeStatus.Text = "存在故障!";
  8377. label_CheckModeResult.BackColor = Color.Red;
  8378. label_CheckModeResult.Text = "测试异常";
  8379. Delay_ms(500);
  8380. //存储异常并上传
  8381. CheckMode_Stop(false);
  8382. return;
  8383. }
  8384. label_CheckModeFWVer.BackColor = Color.Green;
  8385. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  8386. Delay_ms(500);
  8387. }
  8388. else
  8389. {
  8390. label_CheckModeFWVer.BackColor = Color.Yellow;
  8391. label_CheckModeStatus.Text = "跳过软件版本查询";
  8392. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过软件版本查询" + "\r\n");
  8393. Delay_ms(500);
  8394. }
  8395. //打标信息核对
  8396. if (checkBox_CheckModeSN.Checked)
  8397. {
  8398. label_CheckModeStatus.Text = "核对打标信息";
  8399. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "核对打标信息" + "\r\n");
  8400. //根据扫码信息获取型号和SN
  8401. string ScanInfo = textBox_CheckModeScan.Text;
  8402. string regexInfo = "";
  8403. string[] InfoList = { "" };
  8404. try
  8405. {
  8406. if (中置电机ToolStripMenuItem.Checked == true)
  8407. {
  8408. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  8409. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  8410. }
  8411. else if (轮毂电机ToolStripMenuItem.Checked == true)
  8412. {
  8413. if (!ScanInfo.Contains("/")) //老编码规则
  8414. {
  8415. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  8416. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  8417. string Spec = InfoList[1];
  8418. string Sn = InfoList[2];
  8419. InfoList[0] = Model.Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  8420. InfoList[1] = Sn;
  8421. }
  8422. else //新编码规则
  8423. {
  8424. Dictionary<string, string> Dic_Ver = new Dictionary<string, string>
  8425. {
  8426. { "01", "A" },
  8427. { "02", "B" },
  8428. { "03", "C" },
  8429. { "04", "D" },
  8430. { "05", "E" },
  8431. { "06", "F" },
  8432. { "07", "G" },
  8433. { "08", "H" },
  8434. { "09", "I" }
  8435. };
  8436. Dictionary<string, string> Dic_Vol = new Dictionary<string, string>
  8437. {
  8438. { "24V", "A" },
  8439. { "36V", "B" },
  8440. { "42V", "C" },
  8441. { "48V", "D" },
  8442. { "52V", "E" },
  8443. { "60V", "F" }
  8444. };
  8445. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  8446. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  8447. string Spec = InfoList[1].Replace("-", "").Replace("/", "");
  8448. string Sn = InfoList[2];
  8449. InfoList[0] = Model[2] + Dic_Ver[Model.Substring(3, 2)] + Model[5] + Dic_Ver[Model.Substring(6, 2)] + Model[9];
  8450. InfoList[0] += Dic_Vol[Spec.Substring(0, 3)] + Spec.Substring(3, 3) + Spec.Substring(13, 4) + Spec.Substring(Spec.Length - 4, 3);
  8451. InfoList[1] = Sn;
  8452. }
  8453. }
  8454. }
  8455. catch
  8456. {
  8457. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  8458. label_FacModeStatus.Text = "存在故障!";
  8459. label_FacModeResult.BackColor = Color.Red;
  8460. label_FacModeResult.Text = "标签格式错误";
  8461. Delay_ms(500);
  8462. //存储异常并上传
  8463. CheckMode_Stop(false);
  8464. return;
  8465. }
  8466. //核对型号
  8467. if (string.Equals(InfoList[0], Class_Motor_Ver.Mode) == false) //型号错误,直接结束
  8468. {
  8469. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号不一致" + "\r\n");
  8470. label_CheckModeStatus.Text = "存在故障!";
  8471. label_CheckModeResult.BackColor = Color.Red;
  8472. label_CheckModeResult.Text = "测试异常";
  8473. Delay_ms(500);
  8474. //存储异常并上传
  8475. CheckMode_Stop(false);
  8476. return;
  8477. }
  8478. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号一致" + "\r\n");
  8479. Delay_ms(500);
  8480. //核对SN
  8481. if (string.Equals(InfoList[1], Class_Motor_Ver.SN) == false) //型号错误,直接结束
  8482. {
  8483. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN不一致" + "\r\n");
  8484. label_CheckModeStatus.Text = "存在故障!";
  8485. label_CheckModeResult.BackColor = Color.Red;
  8486. label_CheckModeResult.Text = "测试异常";
  8487. Delay_ms(500);
  8488. //存储异常并上传
  8489. CheckMode_Stop(false);
  8490. return;
  8491. }
  8492. label_CheckModeSN.BackColor = Color.Green;
  8493. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN一致" + "\r\n");
  8494. Delay_ms(500);
  8495. }
  8496. else
  8497. {
  8498. label_CheckModeSN.BackColor = Color.Yellow;
  8499. label_CheckModeStatus.Text = "跳过打标信息确认";
  8500. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过打标信息确认" + "\r\n");
  8501. Delay_ms(500);
  8502. }
  8503. //参数检验
  8504. if (checkBox_CheckModeCfg.Checked)
  8505. {
  8506. //读取配置文件信息
  8507. label_CheckModeStatus.Text = "参数检查";
  8508. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  8509. //配置文件
  8510. List<byte[]> CmdList = new List<byte[]>();
  8511. Dictionary<string, string> ConfigCmd = new Dictionary<string, string>();//配置文件格式
  8512. //从服务器下载文件
  8513. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  8514. {
  8515. string SelectFile = "";
  8516. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "/" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  8517. if (File.Exists(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  8518. {
  8519. File.Delete(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  8520. }
  8521. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  8522. //打开文件
  8523. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  8524. ConfigCmd.Clear();
  8525. while (streamReader.Peek() != -1)
  8526. {
  8527. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  8528. if (fileLineInfo.Contains("["))
  8529. {
  8530. if (fileLineInfo.Contains("助力参数"))
  8531. {
  8532. fileLineInfo = streamReader.ReadLine();
  8533. }
  8534. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  8535. }
  8536. }
  8537. streamReader.Close();
  8538. }
  8539. //从本地加载文件
  8540. else
  8541. {
  8542. string SelectFile = "";
  8543. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  8544. //打开文件
  8545. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  8546. ConfigCmd.Clear();
  8547. while (streamReader.Peek() != -1)
  8548. {
  8549. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  8550. if (fileLineInfo.Contains("["))
  8551. {
  8552. if (fileLineInfo.Contains("助力参数"))
  8553. {
  8554. fileLineInfo = streamReader.ReadLine();
  8555. }
  8556. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  8557. }
  8558. }
  8559. streamReader.Close();
  8560. }
  8561. int CmdNum = ConfigCmd.Count(); //指令个数
  8562. Delay_ms(500);
  8563. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "\r\n");
  8564. Delay_ms(500);
  8565. //逐条读取比较
  8566. try
  8567. {
  8568. foreach (string key in ConfigCmd.Keys)
  8569. {
  8570. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令:" + "\r\n");
  8571. CmdRevStrTemp = "";
  8572. if (key.Contains("曲线"))
  8573. {
  8574. byte LineNum = 0;
  8575. var code = new byte[4];
  8576. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  8577. if (LineNum <= 5)
  8578. {
  8579. code[0] = (byte)(LineNum & 0xFF);
  8580. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8581. code[2] = (byte)(LineNum & 0xFF);
  8582. code[3] = (byte)((LineNum >> 8) & 0xFF);
  8583. }
  8584. else
  8585. {
  8586. code[0] = (byte)(LineNum & 0xFF);
  8587. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8588. code[2] = (byte)(5 & 0xFF);
  8589. code[3] = (byte)((5 >> 8) & 0xFF);
  8590. }
  8591. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  8592. }
  8593. else
  8594. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  8595. Delay_ms(500);
  8596. if (CmdRevStrTemp == string.Empty)
  8597. {
  8598. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令,第1次重发" + "\r\n");
  8599. if (key.Contains("曲线"))
  8600. {
  8601. byte LineNum = 0;
  8602. var code = new byte[4];
  8603. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  8604. if (LineNum <= 5)
  8605. {
  8606. code[0] = (byte)(LineNum & 0xFF);
  8607. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8608. code[2] = (byte)(LineNum & 0xFF);
  8609. code[3] = (byte)((LineNum >> 8) & 0xFF);
  8610. }
  8611. else
  8612. {
  8613. code[0] = (byte)(LineNum & 0xFF);
  8614. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8615. code[2] = (byte)(5 & 0xFF);
  8616. code[3] = (byte)((5 >> 8) & 0xFF);
  8617. }
  8618. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  8619. }
  8620. else
  8621. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  8622. Delay_ms(500);
  8623. if (CmdRevStrTemp == string.Empty)
  8624. {
  8625. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令,第2次重发" + "\r\n");
  8626. if (key.Contains("曲线"))
  8627. {
  8628. byte LineNum = 0;
  8629. var code = new byte[4];
  8630. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  8631. if (LineNum <= 5)
  8632. {
  8633. code[0] = (byte)(LineNum & 0xFF);
  8634. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8635. code[2] = (byte)(LineNum & 0xFF);
  8636. code[3] = (byte)((LineNum >> 8) & 0xFF);
  8637. }
  8638. else
  8639. {
  8640. code[0] = (byte)(LineNum & 0xFF);
  8641. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8642. code[2] = (byte)(5 & 0xFF);
  8643. code[3] = (byte)((5 >> 8) & 0xFF);
  8644. }
  8645. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  8646. }
  8647. else
  8648. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  8649. Delay_ms(500);
  8650. if (CmdRevStrTemp == string.Empty)
  8651. {
  8652. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "指令读取失败" + "\r\n");
  8653. label_CheckModeStatus.Text = "存在故障!";
  8654. label_CheckModeResult.BackColor = Color.Red;
  8655. label_CheckModeResult.Text = "测试异常";
  8656. Delay_ms(500);
  8657. //存储异常并上传
  8658. CheckMode_Stop(false);
  8659. return;
  8660. }
  8661. }
  8662. }
  8663. //比较当前指令,读取的配置文件和返回数据比较
  8664. string ParamWrite = ConfigCmd[key].Substring(24, ConfigCmd[key].Length - 40).Trim();
  8665. string ParamRead = "";
  8666. ushort CmdGet = Convert.ToUInt16(CmdRevStrTemp.Substring(0, 6).Trim().Replace(" ", ""), 16);//接收到指令的命令字
  8667. ushort CmdRev = myParams.ConfigCheckRevCmd[key];//接收指令设计值
  8668. if (CmdGet != CmdRev)
  8669. {
  8670. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "接收指令不正确" + "\r\n");
  8671. richTextBox_CheckModeLog.AppendText("接收指令:" + "0x" + CmdGet.ToString("X2") + "\r\n");
  8672. richTextBox_CheckModeLog.AppendText("正确指令应为:" + "0x" + CmdRev.ToString("X2") + "\r\n");
  8673. label_CheckModeStatus.Text = "存在故障!";
  8674. label_CheckModeResult.BackColor = Color.Red;
  8675. label_CheckModeResult.Text = "测试异常";
  8676. Delay_ms(500);
  8677. //存储异常并上传
  8678. CheckMode_Stop(false);
  8679. return;
  8680. }
  8681. if (string.Compare(key, "[其它传感器参数]") == 0)
  8682. ParamRead = CmdRevStrTemp.Substring(90, CmdRevStrTemp.Length - 90).Trim(); //去掉命令字、力矩传感器标定参数
  8683. else if (string.Compare(key, "[力矩传感器参数]") == 0)
  8684. ParamRead = CmdRevStrTemp.Substring(6, CmdRevStrTemp.Length - 6 - 36).Trim(); //去掉命令字、其它传感器参数
  8685. else if (string.Compare(key, "[控制参数]") == 0)
  8686. ParamRead = CmdRevStrTemp.Substring(18, CmdRevStrTemp.Length - 18).Trim(); //去掉命令字、位置零点
  8687. else
  8688. ParamRead = CmdRevStrTemp.Substring(6, CmdRevStrTemp.Length - 6).Trim(); //去掉命令字
  8689. if (ParamWrite.Contains(ParamRead))
  8690. {
  8691. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "一致" + "\r\n");
  8692. continue;
  8693. }
  8694. else
  8695. {
  8696. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "不一致" + "\r\n");
  8697. richTextBox_CheckModeLog.AppendText("写入参数:" + ParamWrite + "\r\n");
  8698. richTextBox_CheckModeLog.AppendText("读出参数:" + ParamRead + "\r\n");
  8699. label_CheckModeStatus.Text = "存在故障!";
  8700. label_CheckModeResult.BackColor = Color.Red;
  8701. label_CheckModeResult.Text = "测试异常";
  8702. Delay_ms(500);
  8703. //存储异常并上传
  8704. CheckMode_Stop(false);
  8705. return;
  8706. }
  8707. }
  8708. }
  8709. catch (System.Exception)
  8710. {
  8711. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数检验失败" + "\r\n");
  8712. label_CheckModeStatus.Text = "存在故障!";
  8713. label_CheckModeResult.BackColor = Color.Red;
  8714. label_CheckModeResult.Text = "测试异常";
  8715. Delay_ms(500);
  8716. //存储异常并上传
  8717. CheckMode_Stop(false);
  8718. return;
  8719. }
  8720. label_CheckModeCfg.BackColor = Color.Green;
  8721. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数检验正确" + "\r\n");
  8722. Delay_ms(500);
  8723. }
  8724. else
  8725. {
  8726. label_CheckModeCfg.BackColor = Color.Yellow;
  8727. label_CheckModeStatus.Text = "跳过参数检验";
  8728. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数检验" + "\r\n");
  8729. Delay_ms(500);
  8730. }
  8731. //读取力矩传感器
  8732. do
  8733. {
  8734. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据" + "\r\n");
  8735. //发送指令读取力矩传感器标定数据
  8736. CmdRevStrTemp = "";
  8737. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  8738. ACK_WaitCnt = 0;
  8739. while (ACK_WaitCnt <= 2) ; //1s
  8740. if (CmdRevStrTemp == string.Empty)
  8741. {
  8742. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据,第1次重发" + "\r\n");
  8743. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  8744. ACK_WaitCnt = 0;
  8745. while (ACK_WaitCnt <= 2) ; //1s
  8746. if (CmdRevStrTemp == string.Empty)
  8747. {
  8748. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据,第2次重发" + "\r\n");
  8749. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  8750. ACK_WaitCnt = 0;
  8751. while (ACK_WaitCnt <= 2) ; //1s
  8752. if (CmdRevStrTemp == string.Empty)
  8753. {
  8754. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取失败" + "\r\n");
  8755. label_CheckModeStatus.Text = "存在故障!";
  8756. label_CheckModeResult.BackColor = Color.Red;
  8757. label_CheckModeResult.Text = "测试异常";
  8758. Delay_ms(500);
  8759. //存储异常并上传
  8760. CheckMode_Stop(false);
  8761. return;
  8762. }
  8763. }
  8764. }
  8765. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取成功" + "\r\n");
  8766. //取力矩传感器数据
  8767. ushort ZeroInit, Zero1, Zero2, Zero3, ZeroNew;
  8768. ushort MaxTorque;
  8769. ushort K1_T, K1, K2_T, K2, K3_T, K3, K4_T, K4;
  8770. byte[] DataArray = mySerialProcess.HexStringToBytes(CmdRevStrTemp, true);
  8771. ushort Cmd = (ushort)((DataArray[0] << 8) + DataArray[1]);
  8772. if (Cmd != 0xB528)
  8773. {
  8774. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器参数错误,CMD: 0x" + Convert.ToString(Cmd, 16).PadLeft(2, '0').ToUpper() + "\r\n");
  8775. label_CheckModeStatus.Text = "存在故障!";
  8776. label_CheckModeResult.BackColor = Color.Red;
  8777. label_CheckModeResult.Text = "测试异常";
  8778. Delay_ms(500);
  8779. //存储异常并上传
  8780. CheckMode_Stop(false);
  8781. return;
  8782. }
  8783. ZeroInit = (ushort)((DataArray[3] << 8) + DataArray[2]);
  8784. Zero1 = (ushort)((DataArray[5] << 8) + DataArray[4]);
  8785. Zero2 = (ushort)((DataArray[7] << 8) + DataArray[6]);
  8786. Zero3 = (ushort)((DataArray[9] << 8) + DataArray[8]);
  8787. ZeroNew = (ushort)((DataArray[11] << 8) + DataArray[10]);
  8788. MaxTorque = (ushort)((DataArray[13] << 8) + DataArray[12]);
  8789. K1_T = (ushort)((DataArray[15] << 8) + DataArray[14]);
  8790. K1 = (ushort)((DataArray[17] << 8) + DataArray[16]);
  8791. K2_T = (ushort)((DataArray[19] << 8) + DataArray[18]);
  8792. K2 = (ushort)((DataArray[21] << 8) + DataArray[20]);
  8793. K3_T = (ushort)((DataArray[23] << 8) + DataArray[22]);
  8794. K3 = (ushort)((DataArray[25] << 8) + DataArray[24]);
  8795. K4_T = (ushort)((DataArray[27] << 8) + DataArray[26]);
  8796. K4 = (ushort)((DataArray[29] << 8) + DataArray[28]);
  8797. richTextBox_CheckModeLog.AppendText("力矩传感器零点: " + ZeroInit.ToString() + "," + Zero1.ToString() + "," +
  8798. Zero2.ToString() + "," + Zero3.ToString() + "," + ZeroNew.ToString() + "\r\n");
  8799. richTextBox_CheckModeLog.AppendText("最大力矩: " + MaxTorque.ToString() + "\r\n");
  8800. richTextBox_CheckModeLog.AppendText("力矩传感器标定: " + "[" + K1_T.ToString() + "," + K1.ToString() + "]" + "," +
  8801. "[" + K2_T.ToString() + "," + K2.ToString() + "]" + "," + "[" + K3_T.ToString() + "," + K3.ToString() + "]" + "," +
  8802. "[" + K4_T.ToString() + "," + K4.ToString() + "]" + "\r\n");
  8803. //传感器标定检验
  8804. if (checkBox_CheckModeTorque.Checked)
  8805. {
  8806. richTextBox_CheckModeLog.AppendText("力矩零点范围: " + TorqueParamsForm.Zero.Min.ToString() + " - " + TorqueParamsForm.Zero.Max.ToString() + "\r\n");
  8807. richTextBox_CheckModeLog.AppendText("K1范围: " + TorqueParamsForm.K1.T.ToString() + "," + TorqueParamsForm.K1.Min.ToString() + " - " + TorqueParamsForm.K1.Max.ToString() + "\r\n");
  8808. richTextBox_CheckModeLog.AppendText("K2范围: " + TorqueParamsForm.K2.T.ToString() + "," + TorqueParamsForm.K2.Min.ToString() + " - " + TorqueParamsForm.K2.Max.ToString() + "\r\n");
  8809. richTextBox_CheckModeLog.AppendText("K3范围: " + TorqueParamsForm.K3.T.ToString() + "," + TorqueParamsForm.K3.Min.ToString() + " - " + TorqueParamsForm.K3.Max.ToString() + "\r\n");
  8810. richTextBox_CheckModeLog.AppendText("K4范围: " + TorqueParamsForm.K4.T.ToString() + "," + TorqueParamsForm.K4.Min.ToString() + " - " + TorqueParamsForm.K4.Max.ToString() + "\r\n");
  8811. //与设置值比较
  8812. if ((ZeroInit <= TorqueParamsForm.Zero.Max) && (ZeroInit >= TorqueParamsForm.Zero.Min)
  8813. && (K1_T == TorqueParamsForm.K1.T) && (K1 <= TorqueParamsForm.K1.Max) && (K1 >= TorqueParamsForm.K1.Min)
  8814. && (K2_T == TorqueParamsForm.K2.T) && (K2 <= TorqueParamsForm.K2.Max) && (K2 >= TorqueParamsForm.K2.Min)
  8815. && (K3_T == TorqueParamsForm.K3.T) && (K3 <= TorqueParamsForm.K3.Max) && (K3 >= TorqueParamsForm.K3.Min)
  8816. && (K4_T == TorqueParamsForm.K4.T) && (K4 <= TorqueParamsForm.K4.Max) && (K4 >= TorqueParamsForm.K4.Min)
  8817. )
  8818. {
  8819. label_CheckModeTorque.BackColor = Color.Green;
  8820. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定正常" + "\r\n");
  8821. Delay_ms(500);
  8822. }
  8823. else
  8824. {
  8825. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定超范围" + "\r\n");
  8826. label_CheckModeStatus.Text = "存在故障!";
  8827. label_CheckModeResult.BackColor = Color.Red;
  8828. label_CheckModeResult.Text = "测试异常";
  8829. Delay_ms(500);
  8830. //存储异常并上传
  8831. CheckMode_Stop(false);
  8832. return;
  8833. }
  8834. }
  8835. else
  8836. {
  8837. label_CheckModeTorque.BackColor = Color.Yellow;
  8838. label_CheckModeStatus.Text = "跳过传感器标定检验";
  8839. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过传感器标定检验" + "\r\n");
  8840. Delay_ms(500);
  8841. }
  8842. } while (false);
  8843. //读取MOS内阻校准参数
  8844. do
  8845. {
  8846. if (checkBox_CheckModeMos.Checked)
  8847. {
  8848. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据" + "\r\n");
  8849. //读取显示校准返回数据
  8850. foreach (Control c in groupBox21.Controls)
  8851. {
  8852. if (c is TextBox)
  8853. c.Text = "";
  8854. }
  8855. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8856. ACK_WaitCnt = 0;
  8857. while (ACK_WaitCnt <= 2) ; //1s
  8858. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  8859. {
  8860. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据,第1次重发" + "\r\n");
  8861. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8862. ACK_WaitCnt = 0;
  8863. while (ACK_WaitCnt <= 2) ; //1s
  8864. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  8865. {
  8866. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据,第2次重发" + "\r\n");
  8867. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8868. ACK_WaitCnt = 0;
  8869. while (ACK_WaitCnt <= 2) ; //1s
  8870. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  8871. {
  8872. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果异常" + "\r\n");
  8873. label_CheckModeStatus.Text = "存在故障!";
  8874. label_CheckModeResult.BackColor = Color.Red;
  8875. label_CheckModeResult.Text = "测试异常";
  8876. Delay_ms(500);
  8877. //存储异常并上传
  8878. CheckMode_Stop(false);
  8879. return;
  8880. }
  8881. }
  8882. }
  8883. else
  8884. {
  8885. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻:" + textBox_MOS_R1.Text + " " + textBox_MOS_R2.Text + " " + textBox_MOS_R3.Text + "\r\n");
  8886. }
  8887. //与校准返回数据对比
  8888. string[] MOS_R1_Th = toolStripTextBox_MOS1.Text.Split(',');
  8889. string[] MOS_R2_Th = toolStripTextBox_MOS2.Text.Split(',');
  8890. string[] MOS_R3_Th = toolStripTextBox_MOS3.Text.Split(',');
  8891. if ((Convert.ToUInt16(textBox_MOS_R1.Text) >= Convert.ToUInt16(MOS_R1_Th[0])) && (Convert.ToUInt16(textBox_MOS_R1.Text) <= Convert.ToUInt16(MOS_R1_Th[1])) &&
  8892. (Convert.ToUInt16(textBox_MOS_R2.Text) >= Convert.ToUInt16(MOS_R2_Th[0])) && (Convert.ToUInt16(textBox_MOS_R2.Text) <= Convert.ToUInt16(MOS_R2_Th[1])) &&
  8893. (Convert.ToUInt16(textBox_MOS_R3.Text) >= Convert.ToUInt16(MOS_R3_Th[0])) && (Convert.ToUInt16(textBox_MOS_R3.Text) <= Convert.ToUInt16(MOS_R3_Th[1]))
  8894. )
  8895. {
  8896. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准合格" + "\r\n");
  8897. label_CheckModeMos.BackColor = Color.Green;
  8898. }
  8899. else
  8900. {
  8901. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准超范围" + "\r\n");
  8902. label_CheckModeStatus.Text = "存在故障!";
  8903. label_CheckModeResult.BackColor = Color.Red;
  8904. label_CheckModeResult.Text = "测试异常";
  8905. Delay_ms(500);
  8906. //存储异常并上传
  8907. CheckMode_Stop(false);
  8908. return;
  8909. }
  8910. }
  8911. else
  8912. {
  8913. label_CheckModeMos.BackColor = Color.Yellow;
  8914. label_CheckModeStatus.Text = "跳过MOS内阻校准检验";
  8915. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过MOS内阻校准检验" + "\r\n");
  8916. Delay_ms(500);
  8917. }
  8918. } while (false);
  8919. //读取位置校准参数
  8920. do
  8921. {
  8922. if (checkBox_CheckModeAngle.Checked)
  8923. {
  8924. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取位置校准数据" + "\r\n");
  8925. //发送指令读取位置
  8926. CmdRevStrTemp = "";
  8927. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
  8928. ACK_WaitCnt = 0;
  8929. while (ACK_WaitCnt <= 2) ; //1s
  8930. if (CmdRevStrTemp == string.Empty)
  8931. {
  8932. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取位置校准数据,第1次重发" + "\r\n");
  8933. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x3E00, null);
  8934. ACK_WaitCnt = 0;
  8935. while (ACK_WaitCnt <= 2) ; //1s
  8936. if (CmdRevStrTemp == string.Empty)
  8937. {
  8938. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取位置校准数据,第2次重发" + "\r\n");
  8939. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x3E00, null);
  8940. ACK_WaitCnt = 0;
  8941. while (ACK_WaitCnt <= 2) ; //1s
  8942. if (CmdRevStrTemp == string.Empty)
  8943. {
  8944. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准数据读取失败" + "\r\n");
  8945. label_CheckModeStatus.Text = "存在故障!";
  8946. label_CheckModeResult.BackColor = Color.Red;
  8947. label_CheckModeResult.Text = "测试异常";
  8948. Delay_ms(500);
  8949. //存储异常并上传
  8950. CheckMode_Stop(false);
  8951. return;
  8952. }
  8953. }
  8954. }
  8955. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准数据读取成功" + "\r\n");
  8956. //取零点数据
  8957. UInt16 AngleZero_Init = 0, AngleZero_Cur = 0;
  8958. byte[] DataArray = mySerialProcess.HexStringToBytes(CmdRevStrTemp, true);
  8959. ushort Cmd = (ushort)((DataArray[0] << 8) + DataArray[1]);
  8960. if (Cmd != 0xB420)
  8961. {
  8962. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置传感器参数错误,CMD: 0x" + Convert.ToString(Cmd, 16).PadLeft(2, '0').ToUpper() + "\r\n");
  8963. label_CheckModeStatus.Text = "存在故障!";
  8964. label_CheckModeResult.BackColor = Color.Red;
  8965. label_CheckModeResult.Text = "测试异常";
  8966. Delay_ms(500);
  8967. //存储异常并上传
  8968. CheckMode_Stop(false);
  8969. return;
  8970. }
  8971. AngleZero_Init = (ushort)((DataArray[3] << 8) + DataArray[2]);
  8972. AngleZero_Cur = (ushort)((DataArray[5] << 8) + DataArray[4]);
  8973. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置出厂零点: " + AngleZero_Init.ToString() + ",位置当前零点: " + AngleZero_Cur.ToString() + "\r\n");
  8974. int AngleZeroDiff = Math.Abs(AngleZero_Cur - AngleZero_Init);
  8975. int AngleZeroTH = Convert.ToInt32(textBox_AngleZeroTh.Text);
  8976. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置零点校准值: " + AngleZeroDiff.ToString() + ",判断阈值: " + AngleZeroTH.ToString() + "\r\n");
  8977. //判断
  8978. if (AngleZeroDiff <= AngleZeroTH)
  8979. {
  8980. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置传感器校准合格" + "\r\n");
  8981. label_CheckModeAngle.BackColor = Color.Green;
  8982. }
  8983. else
  8984. {
  8985. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置传感器校准超范围" + "\r\n");
  8986. label_CheckModeStatus.Text = "存在故障!";
  8987. label_CheckModeResult.BackColor = Color.Red;
  8988. label_CheckModeResult.Text = "测试异常";
  8989. Delay_ms(500);
  8990. //存储异常并上传
  8991. CheckMode_Stop(false);
  8992. return;
  8993. }
  8994. }
  8995. else
  8996. {
  8997. label_CheckModeAngle.BackColor = Color.Yellow;
  8998. label_CheckModeStatus.Text = "跳过位置传感器校准检验";
  8999. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过位置传感器校准检验" + "\r\n");
  9000. Delay_ms(500);
  9001. }
  9002. } while (false);
  9003. //测试合格
  9004. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  9005. label_CheckModeStatus.Text = "测试结束!";
  9006. label_CheckModeResult.BackColor = Color.Green;
  9007. label_CheckModeResult.Text = "测试合格";
  9008. Delay_ms(500);
  9009. //存储并上传
  9010. CheckMode_Stop(true);
  9011. return;
  9012. }
  9013. private void CheckModeLabelInit()
  9014. {
  9015. //测试状态标签
  9016. label_CheckModeResult.BackColor = Color.Yellow;
  9017. label_CheckModeResult.Text = "测试中";
  9018. //测试过程标签
  9019. label_CheckModeStatus.Text = "测试就绪";
  9020. //测试结果标签
  9021. foreach (Control c in groupBox31.Controls)
  9022. {
  9023. if (c is Label)
  9024. {
  9025. if (c.Text == string.Empty)
  9026. c.BackColor = Color.Red;
  9027. }
  9028. }
  9029. }
  9030. private void 调试记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  9031. {
  9032. System.Diagnostics.Process.Start("explorer.exe", Directory.GetCurrentDirectory());
  9033. }
  9034. private void 生产记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  9035. {
  9036. System.Diagnostics.Process.Start("explorer.exe", localInfo.LocalDataPath);
  9037. }
  9038. private void 累计运行时间ToolStripMenuItem_MouseHover(object sender, EventArgs e)
  9039. {
  9040. UInt32 Time = (UInt32)stopwatch.ElapsedMilliseconds / 1000;
  9041. UInt32 hour = Time / 3600;
  9042. UInt32 min = (Time % 3600) / 60;
  9043. UInt32 s = (Time % 60);
  9044. toolStripMenuItem_RunTime.Text = hour.ToString() + ":" + min.ToString("00") + ":" + s.ToString("00");
  9045. }
  9046. private void richTextBox_CheckModeLog_TextChanged(object sender, EventArgs e)
  9047. {
  9048. richTextBox_CheckModeLog.SelectionStart = richTextBox_CheckModeLog.Text.Length;
  9049. richTextBox_CheckModeLog.ScrollToCaret();
  9050. }
  9051. private void 力矩传感器检验ToolStripMenuItem_Click(object sender, EventArgs e)
  9052. {
  9053. TorqueParamsForm.ShowDialog();
  9054. }
  9055. private void textBox_CheckModeScan_KeyUp(object sender, KeyEventArgs e)
  9056. {
  9057. if (e.KeyCode == Keys.Enter)
  9058. CheckTestStart();
  9059. }
  9060. private void textBox_FacModeScan_KeyUp(object sender, KeyEventArgs e)
  9061. {
  9062. if (e.KeyCode == Keys.Enter)
  9063. TestStart();
  9064. }
  9065. private void button_SpeedDec10_Click(object sender, EventArgs e)
  9066. {
  9067. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  9068. if (Percent <= 10)
  9069. Percent = 0;
  9070. else
  9071. Percent -= 10;
  9072. //生产模式转速设置值更新
  9073. textBox_MotorSpeedPercent.Text = Percent.ToString();
  9074. //设置转速百分比
  9075. var Data = new byte[1];
  9076. Data[0] = (byte)Percent;
  9077. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  9078. }
  9079. private void button_SpeedAdd10_Click(object sender, EventArgs e)
  9080. {
  9081. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  9082. if (Percent >= 90)
  9083. Percent = 100;
  9084. else
  9085. Percent += 10;
  9086. //生产模式转速设置值更新
  9087. textBox_MotorSpeedPercent.Text = Percent.ToString();
  9088. //设置转速百分比
  9089. var Data = new byte[1];
  9090. Data[0] = (byte)Percent;
  9091. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  9092. }
  9093. private void button_SpeedDec1_Click(object sender, EventArgs e)
  9094. {
  9095. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  9096. if (Percent <= 1)
  9097. Percent = 0;
  9098. else
  9099. Percent -= 1;
  9100. //生产模式转速设置值更新
  9101. textBox_MotorSpeedPercent.Text = Percent.ToString();
  9102. //设置转速百分比
  9103. var Data = new byte[1];
  9104. Data[0] = (byte)Percent;
  9105. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  9106. }
  9107. private void button_SpeedAdd1_Click(object sender, EventArgs e)
  9108. {
  9109. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  9110. if (Percent >= 99)
  9111. Percent = 100;
  9112. else
  9113. Percent += 1;
  9114. //生产模式转速设置值更新
  9115. textBox_MotorSpeedPercent.Text = Percent.ToString();
  9116. //设置转速百分比
  9117. var Data = new byte[1];
  9118. Data[0] = (byte)Percent;
  9119. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  9120. }
  9121. bool WriteLockStatus = true;
  9122. private void pictureBox_WriteLock_Click(object sender, EventArgs e)
  9123. {
  9124. if (WriteLockStatus == true)
  9125. {
  9126. EnterForm1.ShowDialog();
  9127. try
  9128. {
  9129. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9130. {
  9131. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  9132. {
  9133. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  9134. foreach (Control c in groupBox2.Controls)
  9135. {
  9136. if (c is CheckBox)
  9137. c.Enabled = true;
  9138. }
  9139. WriteLockStatus = !WriteLockStatus;
  9140. }
  9141. else
  9142. {
  9143. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9144. }
  9145. }
  9146. else
  9147. {
  9148. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9149. }
  9150. }
  9151. catch (Exception)
  9152. {
  9153. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9154. }
  9155. }
  9156. else
  9157. {
  9158. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  9159. foreach (Control c in groupBox2.Controls)
  9160. {
  9161. if (c is CheckBox)
  9162. c.Enabled = false;
  9163. }
  9164. WriteLockStatus = !WriteLockStatus;
  9165. }
  9166. }
  9167. bool ReadLockStatus = true;
  9168. private void pictureBox_ReadLock_Click(object sender, EventArgs e)
  9169. {
  9170. if (ReadLockStatus == true)
  9171. {
  9172. EnterForm1.ShowDialog();
  9173. try
  9174. {
  9175. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9176. {
  9177. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  9178. {
  9179. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  9180. foreach (Control c in groupBox29.Controls)
  9181. {
  9182. if (c is CheckBox)
  9183. c.Enabled = true;
  9184. }
  9185. ReadLockStatus = !ReadLockStatus;
  9186. }
  9187. else
  9188. {
  9189. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9190. }
  9191. }
  9192. else
  9193. {
  9194. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9195. }
  9196. }
  9197. catch (Exception)
  9198. {
  9199. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9200. }
  9201. }
  9202. else
  9203. {
  9204. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  9205. foreach (Control c in groupBox29.Controls)
  9206. {
  9207. if (c is CheckBox)
  9208. c.Enabled = false;
  9209. }
  9210. ReadLockStatus = !ReadLockStatus;
  9211. }
  9212. }
  9213. private void 屏幕键盘ToolStripMenuItem_Click(object sender, EventArgs e)
  9214. {
  9215. System.Diagnostics.Process.Start("osk.exe");
  9216. }
  9217. private void checkBox_OffLineCheckMode_CheckedChanged(object sender, EventArgs e)
  9218. {
  9219. comboBox_CheckModeCfgDate.SelectedIndex = -1;
  9220. comboBox_CheckModeCfgFile.SelectedIndex = -1;
  9221. checkBox_OffLineFacMode.Checked = checkBox_OffLineCheckMode.Checked;
  9222. }
  9223. private void checkBox_OffLineFacMode_CheckedChanged(object sender, EventArgs e)
  9224. {
  9225. comboBox_FacModeCfgDate.SelectedIndex = -1;
  9226. comboBox_FacModeCfgFile.SelectedIndex = -1;
  9227. checkBox_OffLineCheckMode.Checked = checkBox_OffLineFacMode.Checked;
  9228. }
  9229. private void 版本ToolStripMenuItem_Click(object sender, EventArgs e)
  9230. {
  9231. VersionForm.ShowDialog();
  9232. }
  9233. private void button_MOS_Cal_Click(object sender, EventArgs e)
  9234. {
  9235. textBox_MOS_R1.Text = "";
  9236. textBox_MOS_R2.Text = "";
  9237. textBox_MOS_R3.Text = "";
  9238. try
  9239. {
  9240. var Code = new byte[18];
  9241. for (int i = 0; i < 18; i++)
  9242. Code[i] = 0;
  9243. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  9244. ushort uwDataTemp = 0;
  9245. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  9246. Code[2] = (byte)(uwDataTemp & 0xFF);
  9247. Code[3] = (byte)(uwDataTemp >> 8);
  9248. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  9249. Code[4] = (byte)(uwDataTemp & 0xFF);
  9250. Code[5] = (byte)(uwDataTemp >> 8);
  9251. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  9252. Code[6] = (byte)(uwDataTemp & 0xFF);
  9253. Code[7] = (byte)(uwDataTemp >> 8);
  9254. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  9255. Code[8] = (byte)(uwDataTemp & 0xFF);
  9256. Code[9] = (byte)(uwDataTemp >> 8);
  9257. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  9258. Code[10] = (byte)(uwDataTemp & 0xFF);
  9259. Code[11] = (byte)(uwDataTemp >> 8);
  9260. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  9261. }
  9262. catch (Exception)
  9263. {
  9264. MessageBox.Show("系数填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9265. }
  9266. }
  9267. private void button_MOS_Read_Click(object sender, EventArgs e)
  9268. {
  9269. foreach (Control c in groupBox21.Controls)
  9270. {
  9271. if (c is TextBox)
  9272. c.Text = "";
  9273. }
  9274. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  9275. }
  9276. private void button_MOS_Write_Click(object sender, EventArgs e)
  9277. {
  9278. try
  9279. {
  9280. var Code = new byte[34];
  9281. for (int i = 0; i < 34; i++)
  9282. Code[i] = 0;
  9283. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  9284. ushort uwDataTemp = 0;
  9285. uwDataTemp = Convert.ToUInt16(textBox_MOS_R1.Text);
  9286. Code[2] = (byte)(uwDataTemp & 0xFF);
  9287. Code[3] = (byte)(uwDataTemp >> 8);
  9288. uwDataTemp = Convert.ToUInt16(textBox_MOS_R2.Text);
  9289. Code[4] = (byte)(uwDataTemp & 0xFF);
  9290. Code[5] = (byte)(uwDataTemp >> 8);
  9291. uwDataTemp = Convert.ToUInt16(textBox_MOS_R3.Text);
  9292. Code[6] = (byte)(uwDataTemp & 0xFF);
  9293. Code[7] = (byte)(uwDataTemp >> 8);
  9294. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  9295. Code[8] = (byte)(uwDataTemp & 0xFF);
  9296. Code[9] = (byte)(uwDataTemp >> 8);
  9297. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  9298. Code[10] = (byte)(uwDataTemp & 0xFF);
  9299. Code[11] = (byte)(uwDataTemp >> 8);
  9300. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  9301. Code[12] = (byte)(uwDataTemp & 0xFF);
  9302. Code[13] = (byte)(uwDataTemp >> 8);
  9303. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  9304. Code[14] = (byte)(uwDataTemp & 0xFF);
  9305. Code[15] = (byte)(uwDataTemp >> 8);
  9306. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  9307. Code[16] = (byte)(uwDataTemp & 0xFF);
  9308. Code[17] = (byte)(uwDataTemp >> 8);
  9309. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4C22, Code);
  9310. }
  9311. catch (Exception)
  9312. {
  9313. MessageBox.Show("数据填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9314. }
  9315. }
  9316. /// <summary>
  9317. /// 测试模式点击文本框自动全选
  9318. /// </summary>
  9319. /// <param name="sender"></param>
  9320. /// <param name="e"></param>
  9321. private void textBox_FacModeScan_MouseClick(object sender, MouseEventArgs e)
  9322. {
  9323. textBox_FacModeScan.SelectAll();
  9324. }
  9325. /// <summary>
  9326. /// 检验模式点击文本框自动全选
  9327. /// </summary>
  9328. /// <param name="sender"></param>
  9329. /// <param name="e"></param>
  9330. private void textBox_CheckModeScan_MouseClick(object sender, MouseEventArgs e)
  9331. {
  9332. textBox_CheckModeScan.SelectAll();
  9333. }
  9334. /// <summary>
  9335. /// 鼠标放置显示连接服务器信息
  9336. /// </summary>
  9337. /// <param name="sender"></param>
  9338. /// <param name="e"></param>
  9339. private void label_ServerStatus_MouseHover(object sender, EventArgs e)
  9340. {
  9341. // 创建the ToolTip
  9342. ToolTip toolTip1 = new ToolTip();
  9343. // 设置显示样式
  9344. toolTip1.AutoPopDelay = 30000;//提示信息的可见时间
  9345. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  9346. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  9347. toolTip1.ShowAlways = true;//是否显示提示框
  9348. if (myFtp.IsNetConnected)
  9349. {
  9350. toolTip1.SetToolTip(this.label_ServerStatus, "IP: " + ServerIP);//设置故障内容显示
  9351. }
  9352. else
  9353. {
  9354. toolTip1.SetToolTip(this.label_ServerStatus, "网络断开");//设置故障内容显示
  9355. }
  9356. }
  9357. /// <summary>
  9358. /// UART协议类型修改
  9359. /// </summary>
  9360. /// <param name="sender"></param>
  9361. /// <param name="e"></param>
  9362. private void 协议类型ToolStripMenuItem_SelectedIndexChanged(object sender, EventArgs e)
  9363. {
  9364. var Code = new byte[2];
  9365. Code[0] = (byte)协议类型ToolStripMenuItem.SelectedIndex;
  9366. Code[1] = 0x00;
  9367. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  9368. }
  9369. /// <summary>
  9370. /// 显示本机信息
  9371. /// </summary>
  9372. /// <param name="sender"></param>
  9373. /// <param name="e"></param>
  9374. private void 本机信息ToolStripMenuItem_Click(object sender, EventArgs e)
  9375. {
  9376. MessageBox.Show(Local_HdInformation, "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
  9377. }
  9378. /// <summary>
  9379. /// 量产模式删除当前选中文件
  9380. /// </summary>
  9381. /// <param name="sender"></param>
  9382. /// <param name="e"></param>
  9383. private void label112_DoubleClick(object sender, EventArgs e)
  9384. {
  9385. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9386. {
  9387. EnterForm1.ShowDialog();
  9388. try
  9389. {
  9390. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9391. {
  9392. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  9393. {
  9394. try
  9395. {
  9396. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + comboBox_FacModeCfgFile.Text);
  9397. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_FacModeCfgFile.Text) + ".src");
  9398. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_FacModeCfgFile.Text) + ".png");
  9399. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9400. }
  9401. catch (Exception)
  9402. {
  9403. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9404. }
  9405. }
  9406. else
  9407. {
  9408. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9409. }
  9410. }
  9411. }
  9412. catch (Exception)
  9413. {
  9414. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9415. }
  9416. }
  9417. }
  9418. /// <summary>
  9419. /// 检验模式删除当前选中文件
  9420. /// </summary>
  9421. /// <param name="sender"></param>
  9422. /// <param name="e"></param>
  9423. private void label138_DoubleClick(object sender, EventArgs e)
  9424. {
  9425. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9426. {
  9427. EnterForm1.ShowDialog();
  9428. try
  9429. {
  9430. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9431. {
  9432. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  9433. {
  9434. try
  9435. {
  9436. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + comboBox_CheckModeCfgFile.Text);
  9437. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_CheckModeCfgFile.Text) + ".src");
  9438. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_CheckModeCfgFile.Text) + ".png");
  9439. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9440. }
  9441. catch (Exception)
  9442. {
  9443. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9444. }
  9445. }
  9446. else
  9447. {
  9448. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9449. }
  9450. }
  9451. }
  9452. catch (Exception)
  9453. {
  9454. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9455. }
  9456. }
  9457. }
  9458. /// <summary>
  9459. /// 读取整车信息2
  9460. /// </summary>
  9461. /// <param name="sender"></param>
  9462. /// <param name="e"></param>
  9463. private void button_ReadBikeParam2_Click(object sender, EventArgs e)
  9464. {
  9465. richTextBox_BikeParam2.Clear();
  9466. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null);
  9467. }
  9468. /// <summary>
  9469. /// 写入整车信息2
  9470. /// </summary>
  9471. /// <param name="sender"></param>
  9472. /// <param name="e"></param>
  9473. private void button_WriteBikeParam2_Click(object sender, EventArgs e)
  9474. {
  9475. var ConfigParam = new byte[34];
  9476. for (int i = 0; i < 34; i++)
  9477. ConfigParam[i] = 0;
  9478. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  9479. string[] strDataTemp = richTextBox_BikeParam2.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  9480. try
  9481. {
  9482. for (int i = 0; i < strDataTemp.Length; i++)
  9483. {
  9484. short wDataTemp = 0;
  9485. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  9486. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  9487. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  9488. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  9489. }
  9490. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4D22, ConfigParam);
  9491. }
  9492. catch (Exception)
  9493. {
  9494. timer_500ms.Enabled = false;
  9495. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9496. timer_500ms.Enabled = true;
  9497. }
  9498. }
  9499. /// <summary>
  9500. /// 读取用户骑行参数
  9501. /// </summary>
  9502. /// <param name="sender"></param>
  9503. /// <param name="e"></param>
  9504. private void button_ReadUsrRideParam_Click(object sender, EventArgs e)
  9505. {
  9506. richTextBox_UsrRidesParam.Clear();
  9507. if (checkBox_UserRideParam_OBC.Checked)
  9508. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x4300, null);
  9509. else
  9510. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  9511. }
  9512. /// <summary>
  9513. /// 写入用户骑行参数
  9514. /// </summary>
  9515. /// <param name="sender"></param>
  9516. /// <param name="e"></param>
  9517. private void button_WriteUsrRidetParam_Click(object sender, EventArgs e)
  9518. {
  9519. var ConfigParam = new byte[34];
  9520. for (int i = 0; i < 34; i++)
  9521. ConfigParam[i] = 0;
  9522. if (checkBox_UserRideParam_OBC.Checked)
  9523. {
  9524. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  9525. string[] strDataTemp = richTextBox_UsrRidesParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  9526. try
  9527. {
  9528. for (int i = 0; i < strDataTemp.Length; i++)
  9529. {
  9530. ConfigParam[i + 2] = Convert.ToByte(strDataTemp[i].Split('=')[1]);
  9531. }
  9532. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4B22, ConfigParam);
  9533. }
  9534. catch (Exception)
  9535. {
  9536. timer_500ms.Enabled = false;
  9537. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9538. timer_500ms.Enabled = true;
  9539. }
  9540. }
  9541. else
  9542. {
  9543. string[] strDataTemp = richTextBox_UsrRidesParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  9544. try
  9545. {
  9546. for (int i = 0; i < strDataTemp.Length; i++)
  9547. {
  9548. ConfigParam[i] = Convert.ToByte(strDataTemp[i].Split('=')[1]);
  9549. }
  9550. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x4420, ConfigParam);
  9551. }
  9552. catch (Exception)
  9553. {
  9554. timer_500ms.Enabled = false;
  9555. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9556. timer_500ms.Enabled = true;
  9557. }
  9558. }
  9559. }
  9560. /// <summary>
  9561. /// 读取产品标签
  9562. /// </summary>
  9563. /// <param name="sender"></param>
  9564. /// <param name="e"></param>
  9565. private void button_ReadTag_Click(object sender, EventArgs e)
  9566. {
  9567. textBox_TagInfo.Text = "---";
  9568. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4E00, null);
  9569. }
  9570. /// <summary>
  9571. /// 写入产品标签
  9572. /// </summary>
  9573. /// <param name="sender"></param>
  9574. /// <param name="e"></param>
  9575. private void button_WriteTag_Click(object sender, EventArgs e)
  9576. {
  9577. string User = textBox_TagInfo.Text;
  9578. var UserArray = new byte[32];
  9579. for (ushort i = 0; i < User.Length; i++)
  9580. {
  9581. UserArray[i] = (byte)User[i];
  9582. }
  9583. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D20, UserArray);
  9584. }
  9585. /// <summary>
  9586. /// 上位机读取骑行历史
  9587. /// </summary>
  9588. /// <param name="sender"></param>
  9589. /// <param name="e"></param>
  9590. private void button_ReadRideLog_Click(object sender, EventArgs e)
  9591. {
  9592. textBox_ODO_KM.Text = "---";
  9593. textBox_ODO_TIME.Text = "---";
  9594. textBox_TRIP_KM.Text = "---";
  9595. textBox_TRIP_TIME.Text = "---";
  9596. textBox_OBC_TRIP_KM.Text = "";
  9597. textBox_OBC_TRIP_TIME.Text = "";
  9598. textBox_OBC_ODO_KM.Text = "";
  9599. textBox_OBC_ODO_TIME.Text = "";
  9600. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2E00, null);
  9601. }
  9602. /// <summary>
  9603. /// 上位机写入骑行历史
  9604. /// </summary>
  9605. /// <param name="sender"></param>
  9606. /// <param name="e"></param>
  9607. private void button_WriteRideLog_Click(object sender, EventArgs e)
  9608. {
  9609. UInt32 Data;
  9610. var UserArray = new byte[16];
  9611. try
  9612. {
  9613. Data = Convert.ToUInt32(textBox_ODO_KM.Text);
  9614. UserArray[0] = (byte)(Data & 0xFF);
  9615. UserArray[1] = (byte)(Data >> 8);
  9616. UserArray[2] = (byte)(Data >> 16);
  9617. UserArray[3] = (byte)(Data >> 24);
  9618. Data = Convert.ToUInt32(textBox_ODO_TIME.Text);
  9619. UserArray[4] = (byte)(Data & 0xFF);
  9620. UserArray[5] = (byte)(Data >> 8);
  9621. UserArray[6] = (byte)(Data >> 16);
  9622. UserArray[7] = (byte)(Data >> 24);
  9623. Data = Convert.ToUInt32(textBox_TRIP_KM.Text);
  9624. UserArray[8] = (byte)(Data & 0xFF);
  9625. UserArray[9] = (byte)(Data >> 8);
  9626. UserArray[10] = (byte)(Data >> 16);
  9627. UserArray[11] = (byte)(Data >> 24);
  9628. Data = Convert.ToUInt32(textBox_TRIP_TIME.Text);
  9629. UserArray[12] = (byte)(Data & 0xFF);
  9630. UserArray[13] = (byte)(Data >> 8);
  9631. UserArray[14] = (byte)(Data >> 16);
  9632. UserArray[15] = (byte)(Data >> 24);
  9633. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B10, UserArray);
  9634. }
  9635. catch (Exception ex)
  9636. {
  9637. MessageBox.Show("数据格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9638. }
  9639. }
  9640. /// <summary>
  9641. /// 获取删除配置文件日期列表
  9642. /// </summary>
  9643. /// <param name="sender"></param>
  9644. /// <param name="e"></param>
  9645. private void toolStripTextBox_DelCfgFile_Click(object sender, EventArgs e)
  9646. {
  9647. string[] DateList = { "" };
  9648. //网络断开时直接退出
  9649. if (!myFtp.IsNetConnected)
  9650. return;
  9651. //从服务器更新日期列表
  9652. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
  9653. toolStripTextBox_DelCfgFile.Items.Clear();
  9654. //日期列表加载,显示最近30条
  9655. if (DateList.Length > 30)
  9656. {
  9657. toolStripTextBox_DelCfgFile.Items.Add("支持最近30条");
  9658. toolStripTextBox_DelCfgFile.Items.Add("-----");
  9659. }
  9660. for (int i = (DateList.Length > 30) ? (DateList.Length - 30) : 0; i < DateList.Length; i++)//显示最近30个日期
  9661. {
  9662. toolStripTextBox_DelCfgFile.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  9663. }
  9664. }
  9665. /// <summary>
  9666. /// 删除指定配置文件
  9667. /// </summary>
  9668. /// <param name="sender"></param>
  9669. /// <param name="e"></param>
  9670. private void toolStripTextBox_DelCfgFile_SelectedIndexChanged(object sender, EventArgs e)
  9671. {
  9672. //提示输入文件名
  9673. Scan scan_form = new Scan();
  9674. scan_form.ShowDialog();
  9675. do
  9676. {
  9677. if (scan_form.textBox_Scan.Text == string.Empty)
  9678. {
  9679. timer_500ms.Enabled = false;
  9680. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9681. timer_500ms.Enabled = true;
  9682. break;
  9683. }
  9684. string DelFile = scan_form.textBox_Scan.Text;
  9685. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9686. {
  9687. EnterForm1.ShowDialog();
  9688. try
  9689. {
  9690. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9691. {
  9692. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  9693. {
  9694. try
  9695. {
  9696. if (DelFile.Contains("."))
  9697. DelFile = Path.GetFileNameWithoutExtension(DelFile);
  9698. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".ttcfg");
  9699. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".src");
  9700. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".png");
  9701. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9702. }
  9703. catch (Exception)
  9704. {
  9705. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9706. }
  9707. }
  9708. else
  9709. {
  9710. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9711. }
  9712. }
  9713. }
  9714. catch (Exception)
  9715. {
  9716. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9717. }
  9718. }
  9719. } while (false);
  9720. }
  9721. /// <summary>
  9722. /// 获取删除样机测试记录日期列表
  9723. /// </summary>
  9724. /// <param name="sender"></param>
  9725. /// <param name="e"></param>
  9726. private void toolStripTextBox_DelLogFile_Click(object sender, EventArgs e)
  9727. {
  9728. string[] DateList = { "" };
  9729. //网络断开时直接退出
  9730. if (!myFtp.IsNetConnected)
  9731. return;
  9732. //从服务器更新日期列表
  9733. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName);
  9734. toolStripTextBox_DelLogFile.Items.Clear();
  9735. //日期列表加载,显示最近30天
  9736. if (DateList.Length > 30)
  9737. {
  9738. toolStripTextBox_DelLogFile.Items.Add("支持最近30条");
  9739. toolStripTextBox_DelLogFile.Items.Add("-----");
  9740. }
  9741. for (int i = (DateList.Length > 30) ? (DateList.Length - 30) : 0; i < DateList.Length; i++)//显示最近30个日期
  9742. {
  9743. toolStripTextBox_DelLogFile.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  9744. }
  9745. }
  9746. /// <summary>
  9747. /// 删除指定的样机测试记录
  9748. /// </summary>
  9749. /// <param name="sender"></param>
  9750. /// <param name="e"></param>
  9751. private void toolStripTextBox_DelLogFile_SelectedIndexChanged(object sender, EventArgs e)
  9752. {
  9753. //提示输入文件名
  9754. Scan scan_form = new Scan();
  9755. scan_form.ShowDialog();
  9756. do
  9757. {
  9758. if (scan_form.textBox_Scan.Text == string.Empty)
  9759. {
  9760. timer_500ms.Enabled = false;
  9761. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9762. timer_500ms.Enabled = true;
  9763. break;
  9764. }
  9765. string DelFile = scan_form.textBox_Scan.Text;
  9766. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9767. {
  9768. EnterForm1.ShowDialog();
  9769. try
  9770. {
  9771. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9772. {
  9773. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  9774. {
  9775. try
  9776. {
  9777. //删除指定目录下面所有文件和文件夹
  9778. myFtp.DelDirectoryWithAll(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName + "\\" + toolStripTextBox_DelLogFile.Text + "\\" + DelFile);
  9779. myFtp.RemoveDirectory(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName + "\\" + toolStripTextBox_DelLogFile.Text + "\\" + DelFile);
  9780. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9781. }
  9782. catch (Exception)
  9783. {
  9784. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9785. }
  9786. }
  9787. else
  9788. {
  9789. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9790. }
  9791. }
  9792. }
  9793. catch (Exception)
  9794. {
  9795. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9796. }
  9797. }
  9798. } while (false);
  9799. }
  9800. /// <summary>
  9801. /// CAN协议选择
  9802. /// </summary>
  9803. /// <param name="sender"></param>
  9804. /// <param name="e"></param>
  9805. private void cANToolStripMenuItem_Click(object sender, EventArgs e)
  9806. {
  9807. cANToolStripMenuItem.Checked= true;
  9808. uARTToolStripMenuItem.Checked = false;
  9809. UART协议ToolStripMenuItem.Visible = false;
  9810. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9811. }
  9812. /// <summary>
  9813. /// UART协议选择
  9814. /// </summary>
  9815. /// <param name="sender"></param>
  9816. /// <param name="e"></param>
  9817. private void uARTToolStripMenuItem_Click(object sender, EventArgs e)
  9818. {
  9819. cANToolStripMenuItem.Checked = false;
  9820. uARTToolStripMenuItem.Checked = true;
  9821. UART协议ToolStripMenuItem.Visible = true;
  9822. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9823. }
  9824. /// <summary>
  9825. /// 清除流水号
  9826. /// </summary>
  9827. /// <param name="sender"></param>
  9828. /// <param name="e"></param>
  9829. private void label131_DoubleClick(object sender, EventArgs e)
  9830. {
  9831. if (MessageBox.Show("确认清零流水号?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9832. {
  9833. label_FacModeSerial.Text = "0";
  9834. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, label_FacModeSerial.Text);
  9835. }
  9836. }
  9837. /// <summary>
  9838. /// 清除流水号
  9839. /// </summary>
  9840. /// <param name="sender"></param>
  9841. /// <param name="e"></param>
  9842. private void label135_DoubleClick(object sender, EventArgs e)
  9843. {
  9844. if (MessageBox.Show("确认清零流水号?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9845. {
  9846. label_CheckModeSerial.Text = "0";
  9847. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, label_CheckModeSerial.Text);
  9848. }
  9849. }
  9850. /// <summary>
  9851. /// 打开自动更新
  9852. /// </summary>
  9853. /// <param name="sender"></param>
  9854. /// <param name="e"></param>
  9855. private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
  9856. {
  9857. 打开ToolStripMenuItem.Checked = true;
  9858. 关闭ToolStripMenuItem.Checked = false;
  9859. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9860. }
  9861. /// <summary>
  9862. /// 关闭自动更新
  9863. /// </summary>
  9864. /// <param name="sender"></param>
  9865. /// <param name="e"></param>
  9866. private void 关闭ToolStripMenuItem_Click(object sender, EventArgs e)
  9867. {
  9868. 打开ToolStripMenuItem.Checked = false;
  9869. 关闭ToolStripMenuItem.Checked = true;
  9870. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9871. }
  9872. /// <summary>
  9873. /// 显示完整配置文件
  9874. /// </summary>
  9875. /// <param name="sender"></param>
  9876. /// <param name="e"></param>
  9877. private void comboBox_FacModeCfgFile_MouseHover_1(object sender, EventArgs e)
  9878. {
  9879. // 创建the ToolTip
  9880. ToolTip toolTip1 = new ToolTip();
  9881. // 设置显示样式
  9882. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  9883. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  9884. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  9885. toolTip1.ShowAlways = true;//是否显示提示框
  9886. // 设置伴随的对象.
  9887. toolTip1.SetToolTip(this.comboBox_FacModeCfgFile, comboBox_FacModeCfgFile.Text);//设置故障内容显示
  9888. }
  9889. /// <summary>
  9890. /// 显示完整配置文件
  9891. /// </summary>
  9892. /// <param name="sender"></param>
  9893. /// <param name="e"></param>
  9894. private void comboBox_CheckModeCfgFile_MouseHover_1(object sender, EventArgs e)
  9895. {
  9896. // 创建the ToolTip
  9897. ToolTip toolTip1 = new ToolTip();
  9898. // 设置显示样式
  9899. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  9900. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  9901. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  9902. toolTip1.ShowAlways = true;//是否显示提示框
  9903. // 设置伴随的对象.
  9904. toolTip1.SetToolTip(this.comboBox_CheckModeCfgFile, comboBox_CheckModeCfgFile.Text);//设置故障内容显示
  9905. }
  9906. /// <summary>
  9907. /// 手动发送指令
  9908. /// </summary>
  9909. /// <param name="sender"></param>
  9910. /// <param name="e"></param>
  9911. private void 发送指令ToolStripMenuItem_Click(object sender, EventArgs e)
  9912. {
  9913. //提示
  9914. Scan scan_form = new Scan();
  9915. scan_form.label1.Text = "按照16进制填写,相邻字节用空格隔开,依次填写ID、Mode、Cmd、Data\r\n例如:07 31 16 22 05 01 02 03 04 05";
  9916. scan_form.ShowDialog();
  9917. //发送写入的指令,填写ID、类型、命令字、数据
  9918. do
  9919. {
  9920. if (scan_form.textBox_Scan.Text == string.Empty)
  9921. {
  9922. timer_500ms.Enabled = false;
  9923. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9924. timer_500ms.Enabled = true;
  9925. break;
  9926. }
  9927. //输入文本转换为字节流
  9928. var InputData = new byte[256];
  9929. InputData = mySerialProcess.HexStringToBytes(scan_form.textBox_Scan.Text, true);
  9930. //ID
  9931. ushort ID;
  9932. ID = (ushort)((InputData[0] << 8) + InputData[1]);
  9933. //Mode
  9934. byte Mode;
  9935. Mode = InputData[2];
  9936. //Cmd
  9937. ushort Cmd;
  9938. Cmd = (ushort)((InputData[3] << 8) + InputData[4]);
  9939. //Data
  9940. var Data = new byte[Cmd & 0x00FF];
  9941. for (int i = 0; i < (Cmd & 0x00FF); i++)
  9942. Data[i] = InputData[5 + i];
  9943. //发送数据
  9944. mySerialProcess.SendCmdWithoutNotice(ID, Mode, Cmd, Data);
  9945. } while (false);
  9946. }
  9947. /// <summary>
  9948. /// 启动位置传感器校准
  9949. /// </summary>
  9950. /// <param name="sender"></param>
  9951. /// <param name="e"></param>
  9952. private void button_AngleCalStart_Click(object sender, EventArgs e)
  9953. {
  9954. for (int i = 0; i < 7; i++)
  9955. for (int j = 0; j < 6; j++)
  9956. {
  9957. dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = "";
  9958. }
  9959. foreach (Control cr in tabPage_AngleCal.Controls)
  9960. {
  9961. if (cr is TextBox)
  9962. {
  9963. if ((cr != textBox_AngleDiffTh) && (cr != textBox_AngleZeroTh))
  9964. cr.Text = "";
  9965. }
  9966. }
  9967. var Data = new byte[2];
  9968. mySerialProcess.SendCmd((ushort)0x751, (byte)0x0C, (ushort)0x5002, Data);
  9969. }
  9970. /// <summary>
  9971. /// 导出位置传感器校准数据
  9972. /// </summary>
  9973. /// <param name="sender"></param>
  9974. /// <param name="e"></param>
  9975. private void button_AngleExportData_Click(object sender, EventArgs e)
  9976. {
  9977. //读出产品信息
  9978. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  9979. Delay_ms(200);
  9980. SaveFileDialog sfd = new SaveFileDialog
  9981. {
  9982. FileName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + "位置传感器角度数据_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt",
  9983. Filter = "文本文档(*.txt)|*.txt",
  9984. Title = "Save"
  9985. };
  9986. if (sfd.ShowDialog() != DialogResult.OK)
  9987. {
  9988. return;
  9989. }
  9990. string filepath = sfd.FileName;
  9991. FileStream fs = new FileStream(filepath, FileMode.OpenOrCreate);
  9992. using (StreamWriter sw = new StreamWriter(fs))
  9993. {
  9994. sw.Write("标准值 ");
  9995. sw.Write("60.00 ");
  9996. sw.Write("120.00 ");
  9997. sw.Write("180.00 ");
  9998. sw.Write("240.00 ");
  9999. sw.Write("300.00 ");
  10000. sw.Write("360.00 ");
  10001. for (int i = 0; i < 42; i++)
  10002. {
  10003. if ((i % 6 == 0))
  10004. {
  10005. sw.Write("\r\n" + "采集值" + (i / 6 + 1).ToString() + " ");
  10006. }
  10007. sw.Write(AngledataRecord[i] + " ");
  10008. }
  10009. sw.Write("\r\n" + "历史零点位置 " + textBox_AngleZeroInit.Text);
  10010. sw.Write("\r\n" + "当前零点位置 " + textBox_AngleZeroCur.Text);
  10011. sw.Write("\r\n" + "零点误差 " + textBox_AngleZeroDiff.Text);
  10012. sw.Write("\r\n" + "最小偏差值 " + textBox_AngleDiffMin.Text);
  10013. sw.Write("\r\n" + "最大偏差值 " + textBox_AngleDiffMax.Text);
  10014. sw.Write("\r\n" + "平均偏差值 " + textBox_AngleDiffAvg.Text);
  10015. sw.Flush();
  10016. }
  10017. fs.Close();
  10018. }
  10019. /// <summary>
  10020. /// 写入校准数据
  10021. /// </summary>
  10022. /// <param name="sender"></param>
  10023. /// <param name="e"></param>
  10024. private void button_AngleWrite_Click(object sender, EventArgs e)
  10025. {
  10026. if ((textBox_AngleDiffAvg.Text == "") || (textBox_AngleZeroInit.Text == ""))
  10027. {
  10028. timer_500ms.Enabled = false;
  10029. MessageBox.Show("请先启动校准,以确认校准数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  10030. timer_500ms.Enabled = true;
  10031. return;
  10032. }
  10033. timer_500ms.Enabled = false;
  10034. string str1 = "确认校准数据,历史零点: " + textBox_AngleZeroInit.Text + ", 偏差平均值: " + textBox_AngleDiffAvg.Text;
  10035. if (MessageBox.Show(str1, "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  10036. {
  10037. var SaveFlag = new byte[4];
  10038. for (int i = 0; i < 4; i++)
  10039. SaveFlag[i] = 0;
  10040. SaveFlag[0] = (byte)(1);
  10041. double data1 = Convert.ToDouble(textBox_AngleZeroInit.Text) - Convert.ToDouble(textBox_AngleDiffAvg.Text);
  10042. if (data1 > 360)
  10043. {
  10044. data1 -= 360;
  10045. }
  10046. else if (data1 < -360)
  10047. {
  10048. data1 += 360;
  10049. }
  10050. Int16 data2 = (Int16)(data1 * 32768 / 360);
  10051. SaveFlag[2] = (byte)(data2);
  10052. SaveFlag[3] = (byte)(data2 >> 8);
  10053. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, SaveFlag);
  10054. timer_500ms.Enabled = true;
  10055. }
  10056. else
  10057. {
  10058. timer_500ms.Enabled = true;
  10059. MessageBoxTimeOut.Show("写入取消", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  10060. }
  10061. }
  10062. /// <summary>
  10063. /// 存储允许偏差
  10064. /// </summary>
  10065. /// <param name="sender"></param>
  10066. /// <param name="e"></param>
  10067. private void textBox_AngleDiffTh_KeyDown(object sender, KeyEventArgs e)
  10068. {
  10069. if (e.KeyCode == Keys.Enter)
  10070. {
  10071. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  10072. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  10073. }
  10074. }
  10075. /// <summary>
  10076. /// 存储零点允许偏差
  10077. /// </summary>
  10078. /// <param name="sender"></param>
  10079. /// <param name="e"></param>
  10080. private void textBox_AngleZeroTh_KeyDown(object sender, KeyEventArgs e)
  10081. {
  10082. if (e.KeyCode == Keys.Enter)
  10083. {
  10084. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  10085. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  10086. }
  10087. }
  10088. /// <summary>
  10089. /// 删除服务器配置文件
  10090. /// </summary>
  10091. /// <param name="sender"></param>
  10092. /// <param name="e"></param>
  10093. private void 重置ToolStripMenuItem_Click(object sender, EventArgs e)
  10094. {
  10095. if (MessageBox.Show("重置后软件自动关闭,确认重置?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  10096. {
  10097. if(File.Exists(localInfo.LocalPath + localInfo.ServerCfgFileName))
  10098. File.Delete(localInfo.LocalPath + localInfo.ServerCfgFileName);
  10099. if(File.Exists(localInfo.LocalPath + localInfo.ConfigFileName))
  10100. File.Delete(localInfo.LocalPath + localInfo.ConfigFileName);
  10101. System.Environment.Exit(0);
  10102. }
  10103. }
  10104. /// <summary>
  10105. /// 按下Enter保存数据
  10106. /// </summary>
  10107. /// <param name="sender"></param>
  10108. /// <param name="e"></param>
  10109. private void toolStripTextBox_AngleAvgMax_KeyDown(object sender, KeyEventArgs e)
  10110. {
  10111. textBox_AngleDiffTh.Text = toolStripTextBox_AngleAvgMax.Text;
  10112. if (e.KeyCode == Keys.Enter)
  10113. {
  10114. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  10115. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  10116. }
  10117. }
  10118. /// <summary>
  10119. /// 按下Enter保存数据
  10120. /// </summary>
  10121. /// <param name="sender"></param>
  10122. /// <param name="e"></param>
  10123. private void toolStripTextBox_AngleZeroMax_KeyDown(object sender, KeyEventArgs e)
  10124. {
  10125. textBox_AngleZeroTh.Text = toolStripTextBox_AngleZeroMax.Text;
  10126. if (e.KeyCode == Keys.Enter)
  10127. {
  10128. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  10129. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  10130. }
  10131. }
  10132. private void 帮助ToolStripMenuItem_Click(object sender, EventArgs e)
  10133. {
  10134. //检查本地文件
  10135. if (!File.Exists(localInfo.LocalPath + localInfo.HelpFilename))
  10136. {
  10137. if (!OfflineFlag)
  10138. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/help/" + localInfo.HelpFilename, localInfo.LocalPath);
  10139. else
  10140. {
  10141. MessageBoxTimeOut.Show("未找到帮助文件!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10142. return;
  10143. }
  10144. }
  10145. //调用本地浏览器打开帮助文件
  10146. System.Diagnostics.Process.Start("explorer", localInfo.LocalPath + localInfo.HelpFilename);
  10147. }
  10148. /// <summary>
  10149. /// 读取故障日志地址
  10150. /// </summary>
  10151. /// <param name="sender"></param>
  10152. /// <param name="e"></param>
  10153. private void button_ReadLogAddr_Click(object sender, EventArgs e)
  10154. {
  10155. textBox_LogAddrBegin.Text = "";
  10156. textBox_LogAddrEnd.Text = "";
  10157. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x5200, null);
  10158. }
  10159. /// <summary>
  10160. /// 写入硬件版本
  10161. /// </summary>
  10162. /// <param name="sender"></param>
  10163. /// <param name="e"></param>
  10164. private void button_WriteHW_Click(object sender, EventArgs e)
  10165. {
  10166. string HW = textBox_HW.Text;
  10167. var HWArray = new byte[16];
  10168. for (ushort i = 0; i < HW.Length; i++)
  10169. {
  10170. HWArray[i] = (byte)HW[i];
  10171. }
  10172. if (HW.Length < 16)
  10173. {
  10174. HWArray[HW.Length] = (byte)'.';
  10175. for (ushort i = 0; i < 16 - HW.Length - 1; i++)
  10176. {
  10177. HWArray[HW.Length + 1 + i] = 0x20;
  10178. }
  10179. }
  10180. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5310, HWArray);
  10181. }
  10182. /// <summary>
  10183. /// 生产模式写入HW
  10184. /// </summary>
  10185. /// <param name="sender"></param>
  10186. /// <param name="e"></param>
  10187. private void Button_FacModeSetHW_Click(object sender, EventArgs e)
  10188. {
  10189. string HW = textBox_FacModeHW.Text;
  10190. var HWArray = new byte[16];
  10191. for (ushort i = 0; i < HW.Length; i++)
  10192. {
  10193. HWArray[i] = (byte)HW[i];
  10194. }
  10195. if (HW.Length < 16)
  10196. {
  10197. HWArray[HW.Length] = (byte)'.';
  10198. for (ushort i = 0; i < 16 - HW.Length - 1; i++)
  10199. {
  10200. HWArray[HW.Length + 1 + i] = 0x20;
  10201. }
  10202. }
  10203. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5310, HWArray);
  10204. }
  10205. /// <summary>
  10206. /// 读取定制编号
  10207. /// </summary>
  10208. /// <param name="sender"></param>
  10209. /// <param name="e"></param>
  10210. private void button_ReadUserNum_Click(object sender, EventArgs e)
  10211. {
  10212. textBox_UserNum.Text = "---";
  10213. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x5600, null);
  10214. }
  10215. /// <summary>
  10216. /// 写入定制编号
  10217. /// </summary>
  10218. /// <param name="sender"></param>
  10219. /// <param name="e"></param>
  10220. private void button_WriteUserNum_Click(object sender, EventArgs e)
  10221. {
  10222. string User = textBox_UserNum.Text;
  10223. var UserArray = new byte[32];
  10224. for (ushort i = 0; i < User.Length; i++)
  10225. {
  10226. UserArray[i] = (byte)User[i];
  10227. }
  10228. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5720, UserArray);
  10229. }
  10230. /// <summary>
  10231. /// 读取指定块拓展功能
  10232. /// </summary>
  10233. /// <param name="sender"></param>
  10234. /// <param name="e"></param>
  10235. private void button_FunSet_Read_Click(object sender, EventArgs e)
  10236. {
  10237. if (comboBox_FunSet_BlockNum.SelectedIndex < 0)
  10238. {
  10239. MessageBox.Show("请选择块编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10240. }
  10241. else
  10242. {
  10243. //清空当前内容
  10244. for (int i = 0; i < 8; i++)
  10245. for (int j = 0; j < 8; j++)
  10246. {
  10247. dataGridView_FunSet.Rows[i].Cells[j + 1].Value = "";
  10248. }
  10249. //发送读取指令
  10250. ushort Num = (ushort)(comboBox_FunSet_BlockNum.SelectedIndex + 1);
  10251. var Code = new byte[2];
  10252. Code[0] = (byte)(Num & 0xFF);
  10253. Code[1] = (byte)(Num >> 8);
  10254. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x5402, Code);
  10255. }
  10256. }
  10257. /// <summary>
  10258. /// 写入指定块或指定单元参数
  10259. /// </summary>
  10260. /// <param name="sender"></param>
  10261. /// <param name="e"></param>
  10262. private void button_FunSet_Write_Click(object sender, EventArgs e)
  10263. {
  10264. if (radioButton_WriteByBlock.Checked == true)
  10265. {
  10266. if (comboBox_FunSet_BlockNum.SelectedIndex < 0)
  10267. MessageBox.Show("请选择块编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10268. else
  10269. {
  10270. //开始按块写入
  10271. ushort Num = (ushort)(comboBox_FunSet_BlockNum.SelectedIndex + 1);
  10272. var Code = new byte[66];
  10273. Code[0] = (byte)(Num & 0xFF);
  10274. Code[1] = (byte)(Num >> 8);
  10275. for (int i = 0; i < 8; i++)
  10276. for (int j = 0; j < 8; j++)
  10277. {
  10278. try
  10279. {
  10280. byte Data = Convert.ToByte(dataGridView_FunSet.Rows[i].Cells[j + 1].Value);
  10281. Code[i * 8 + j + 2] = (byte)(Data & 0xFF);
  10282. }
  10283. catch (Exception)
  10284. {
  10285. MessageBox.Show("数据格式错误或超范围!\r\n" + "单元编号:" + (i + 1).ToString() + "\r\n" + "参数:" + (j + 1).ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10286. return;
  10287. }
  10288. }
  10289. if (MessageBox.Show("请核对块编号!\r\n" + "块编号:" + (Num).ToString(), "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  10290. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5542, Code);
  10291. else
  10292. MessageBoxTimeOut.Show("取消写入", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  10293. }
  10294. }
  10295. else if (radioButton_WriteByUnit.Checked == true)
  10296. {
  10297. if (comboBox_FunSet_BlockNum.SelectedIndex < 0)
  10298. MessageBox.Show("请选择块编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10299. else
  10300. {
  10301. if (comboBox_FunSet_UnitNum.SelectedIndex < 0)
  10302. MessageBox.Show("请选择单元编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10303. else
  10304. {
  10305. //开始按单元写入
  10306. ushort Num1 = (ushort)(comboBox_FunSet_BlockNum.SelectedIndex + 1);
  10307. ushort Num2 = (ushort)(comboBox_FunSet_UnitNum.SelectedIndex + 1);
  10308. var Code = new byte[12];
  10309. Code[0] = (byte)(Num1 & 0xFF);
  10310. Code[1] = (byte)(Num1 >> 8);
  10311. Code[2] = (byte)(Num2 & 0xFF);
  10312. Code[3] = (byte)(Num2 >> 8);
  10313. for (int i = 0; i < 8; i++)
  10314. {
  10315. try
  10316. {
  10317. byte Data = Convert.ToByte(dataGridView_FunSet.Rows[Num2 - 1].Cells[i + 1].Value);
  10318. Code[i + 4] = (byte)(Data & 0xFF);
  10319. }
  10320. catch (Exception)
  10321. {
  10322. MessageBox.Show("数据格式错误或超范围!\r\n" + "单元编号:" + Num2.ToString() + "\r\n" + "参数:" + (i + 1).ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10323. return;
  10324. }
  10325. }
  10326. if (MessageBox.Show("请核对块编号和单元编号!\r\n" + "块编号:" + Num1.ToString() + "\r\n" + "单元编号:" + Num2.ToString(), "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  10327. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x550C, Code);
  10328. else
  10329. MessageBoxTimeOut.Show("取消写入", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  10330. }
  10331. }
  10332. }
  10333. else
  10334. {
  10335. MessageBox.Show("请选择写入方式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10336. }
  10337. }
  10338. /// <summary>
  10339. /// 按块写入时隐藏单元编号
  10340. /// </summary>
  10341. /// <param name="sender"></param>
  10342. /// <param name="e"></param>
  10343. private void radioButton_WriteByUnit_CheckedChanged(object sender, EventArgs e)
  10344. {
  10345. if (radioButton_WriteByUnit.Checked == true)
  10346. {
  10347. label159.Visible = true;
  10348. comboBox_FunSet_UnitNum.Visible = true;
  10349. }
  10350. else
  10351. {
  10352. label159.Visible = false;
  10353. comboBox_FunSet_UnitNum.Visible = false;
  10354. }
  10355. }
  10356. /// <summary>
  10357. /// 打开或关闭指令窗口
  10358. /// </summary>
  10359. /// <param name="sender"></param>
  10360. /// <param name="e"></param>
  10361. private void 指令调试ToolStripMenuItem_Click(object sender, EventArgs e)
  10362. {
  10363. if (指令调试ToolStripMenuItem.Checked == false)
  10364. {
  10365. if (DebugForm.debug1 == null || DebugForm.debug1.IsDisposed)
  10366. {
  10367. DebugForm.debug1 = new DebugForm();
  10368. DebugForm.debug1.Show();
  10369. this.DebugWindowIsOpen = true;
  10370. }
  10371. else
  10372. {
  10373. DebugForm.debug1.Activate();
  10374. this.DebugWindowIsOpen = true;
  10375. }
  10376. 指令调试ToolStripMenuItem.Checked = true;
  10377. }
  10378. else
  10379. {
  10380. if (this.DebugWindowIsOpen == true)
  10381. {
  10382. DebugForm.debug1.Close();
  10383. this.DebugWindowIsOpen = false;
  10384. this.DebugDataDisplayEnable = false;
  10385. }
  10386. 指令调试ToolStripMenuItem.Checked = false;
  10387. }
  10388. }
  10389. }
  10390. }