mainForm.cs 514 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873
  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.IO;
  10. using System.IO.Ports;
  11. using System.Linq;
  12. using System.Reflection;
  13. using System.Runtime.InteropServices;
  14. using System.Runtime.InteropServices.ComTypes;
  15. using System.Text;
  16. using System.Text.RegularExpressions;
  17. using System.Threading;
  18. using System.Web;
  19. using System.Windows.Forms;
  20. using System.Xml.Linq;
  21. namespace Welling_Motor_Debug_Tool
  22. {
  23. public partial class mainForm : Form
  24. {
  25. #region 变量定义
  26. //版本号
  27. public static string Version = "2.5.0";
  28. //串口实例
  29. Serial_Process mySerialProcess = new Serial_Process();
  30. string PortNumSave = "";
  31. string PortBaudrateSave = "";
  32. //本地信息定义
  33. LocalInfo localInfo = new LocalInfo();
  34. //FTP实例
  35. ftp myFtp = new ftp();
  36. public string ServerIP = "";
  37. public string ServerPort = "";
  38. public string ServerUser = "";
  39. public string ServerPassWd = "";
  40. public bool OfflineFlag = false;
  41. //MC运行信息超时计数
  42. bool MC_RunInfo_Refresh = false;
  43. ushort MC_RunInfo_Refresh_Cnt = 0;
  44. //MC调试信息超时计数
  45. bool MC_DebugInfo_Refresh = false;
  46. ushort MC_DebugInfo_Refresh_Cnt = 0;
  47. //MC故障码超时计数
  48. bool MC_ErrorCode_Refresh = false;
  49. ushort MC_ErrorCode_Refresh_Cnt = 0;
  50. //配置参数实例
  51. Params myParams = new Params();
  52. //记录文件名称
  53. string RunInfoSaveFilename = "";
  54. //BMS运行信息超时计数
  55. bool BMS_RunInfo_Refresh = false;
  56. ushort BMS_RunInfo_Refresh_Cnt = 0;
  57. //生产模式关机指令反馈状态
  58. bool PowerOffAckStatus = false;
  59. //登录窗口
  60. public static Login EnterForm1 = new Login();
  61. //生产配置文件信息
  62. ArrayList array_CfgInfo = new ArrayList();
  63. //写入参数返回标志和计数
  64. public bool WriteACK = false;
  65. public ushort ACK_WaitCnt = 0;
  66. //写入参数返回提示标志
  67. public bool ACK_DisFlag = true;
  68. //Boot版本信息
  69. public string BootInfo = "";
  70. //接收指令临时缓存,转string
  71. public string CmdRevStrTemp = "";
  72. //计时器,用于统计运行时间
  73. public Stopwatch stopwatch = new Stopwatch();
  74. //力矩传感器检验参数窗口
  75. public static TorqueParams TorqueParamsForm = new TorqueParams();
  76. //参数生成窗口
  77. public static GenerateParams GenerateParamsForm = new GenerateParams();
  78. //版本信息窗口
  79. public static Version VersionForm = new Version();
  80. //本机硬件信息
  81. public string Local_HdInformation = "";
  82. //指令窗口显示
  83. public bool DebugWindowIsOpen = false, DebugDataDisplayEnable = false;
  84. //位置传感器数据记录
  85. string[] AngledataRecord = new string[42];
  86. //服务器设置窗口
  87. public static ServerSelect ServerCfgForm1 = new ServerSelect();
  88. #endregion
  89. #region 故障日志结构体定义
  90. //故障日志记录信息 60 bytes,1K空间可以保存最近16条故障记录
  91. [StructLayout(LayoutKind.Sequential)]
  92. public struct MC_ErrorLogSaveInfo_Struct_t
  93. {
  94. public UInt16 Error_Index; //故障列表索引 2 bytes, 地址偏移 0
  95. public UInt16 NotesInfo1; //备注信息1,地址偏移 2
  96. public UInt16 NotesInfo2; //备注信息2,地址偏移 4
  97. public UInt16 NotesInfo3; //备注信息3,地址偏移 6
  98. public UInt32 ErrorCode; //故障码 4 bytes, 地址偏移 8
  99. public UInt32 RunTime; //运行时间 4bytes, 地址偏移 12
  100. //电机运行信息,占用空间32bytes
  101. [StructLayout(LayoutKind.Sequential)]
  102. public struct MC_RunInfo_Struct_t
  103. {
  104. public ushort BikeSpeed; //车速 0.1km/h,地址偏移0
  105. public ushort MotorSpeed; //输出转速 1rpm,地址偏移2
  106. public ushort Power; //电功率 1W,地址偏移4
  107. public ushort BusVoltage; //母线电压 1mV,地址偏移6
  108. public ushort BusCurrent; //母线电流 1mA,地址偏移8
  109. public byte Cadence; //踏频 1rpm,地址偏移10
  110. public byte Torque; //踩踏力矩 1Nm,地址偏移11
  111. public byte CadenceDir; //踩踏方向 0-正,1-反,2-停止,地址偏移12
  112. public byte GearSt; //助力档位,地址偏移13
  113. public byte LightSwitch; //灯开关 0xF0-关,0xF1-开,地址偏移14
  114. public byte SOC; //剩余电量 1%,地址偏移15
  115. public ushort RemainDistance; //续航里程 1km,地址偏移16
  116. public ushort Torque_AD; //力矩寄存器,地址偏移18
  117. public byte PowerPerKm; //平均功耗 0.01Ah/km ,地址偏移20
  118. public byte T_PCB; //PCB温度 +40℃,地址偏移21
  119. public byte T_Coil; //绕组温度 +40℃,地址偏移22
  120. public byte T_MCU; //MCU温度 +40℃,地址偏移23
  121. public ushort Ride_Km; //开机后骑行里程 0.1km, 地址偏移24
  122. public ushort Ride_Time; //开机后骑行时间 1s,地址偏移26
  123. public UInt32 RS; //预留 4bytes
  124. };
  125. [MarshalAs(UnmanagedType.Struct)]
  126. public MC_RunInfo_Struct_t RunInfo; //运行信息 32bytes, 地址偏移 16
  127. //控制变量
  128. public Int16 IqCurrent; //Pu, 地址偏移 48
  129. public Int16 IqVoltage; //Pu, 地址偏移 50
  130. public Int16 IdCurrent; //Pu, 地址偏移 52
  131. public Int16 IdVoltage; //Pu, 地址偏移 54
  132. //状态机
  133. public UInt16 FSM; //高到低依次表示系统状态机、二层状态机、电机状态机、助力状态机, 地址偏移 56
  134. //预留
  135. public UInt16 RS1;
  136. public UInt16 RS2;
  137. public UInt16 RS3;
  138. };
  139. #endregion
  140. #region 屏幕缩放比例获取
  141. public class PrimaryScreen
  142. {
  143. #region Win32 API
  144. [DllImport("user32.dll")]
  145. static extern IntPtr GetDC(IntPtr ptr);
  146. [DllImport("gdi32.dll")]
  147. static extern int GetDeviceCaps(
  148. IntPtr hdc, // handle to DC
  149. int nIndex // index of capability
  150. );
  151. [DllImport("user32.dll", EntryPoint = "ReleaseDC")]
  152. static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDc);
  153. #endregion
  154. #region DeviceCaps常量
  155. const int HORZRES = 8;
  156. const int VERTRES = 10;
  157. const int LOGPIXELSX = 88;
  158. const int LOGPIXELSY = 90;
  159. const int DESKTOPVERTRES = 117;
  160. const int DESKTOPHORZRES = 118;
  161. #endregion
  162. #region 属性
  163. /// <summary>
  164. /// 获取屏幕分辨率当前物理大小
  165. /// </summary>
  166. public static Size WorkingArea
  167. {
  168. get
  169. {
  170. IntPtr hdc = GetDC(IntPtr.Zero);
  171. Size size = new Size();
  172. size.Width = GetDeviceCaps(hdc, HORZRES);
  173. size.Height = GetDeviceCaps(hdc, VERTRES);
  174. ReleaseDC(IntPtr.Zero, hdc);
  175. return size;
  176. }
  177. }
  178. /// <summary>
  179. /// 当前系统DPI_X 大小 一般为96
  180. /// </summary>
  181. public static int DpiX
  182. {
  183. get
  184. {
  185. IntPtr hdc = GetDC(IntPtr.Zero);
  186. int DpiX = GetDeviceCaps(hdc, LOGPIXELSX);
  187. ReleaseDC(IntPtr.Zero, hdc);
  188. return DpiX;
  189. }
  190. }
  191. /// <summary>
  192. /// 当前系统DPI_Y 大小 一般为96
  193. /// </summary>
  194. public static int DpiY
  195. {
  196. get
  197. {
  198. IntPtr hdc = GetDC(IntPtr.Zero);
  199. int DpiX = GetDeviceCaps(hdc, LOGPIXELSY);
  200. ReleaseDC(IntPtr.Zero, hdc);
  201. return DpiX;
  202. }
  203. }
  204. /// <summary>
  205. /// 获取真实设置的桌面分辨率大小
  206. /// </summary>
  207. public static Size DESKTOP
  208. {
  209. get
  210. {
  211. IntPtr hdc = GetDC(IntPtr.Zero);
  212. Size size = new Size();
  213. size.Width = GetDeviceCaps(hdc, DESKTOPHORZRES);
  214. size.Height = GetDeviceCaps(hdc, DESKTOPVERTRES);
  215. ReleaseDC(IntPtr.Zero, hdc);
  216. return size;
  217. }
  218. }
  219. /// <summary>
  220. /// 获取宽度缩放百分比
  221. /// </summary>
  222. public static float ScaleX
  223. {
  224. get
  225. {
  226. IntPtr hdc = GetDC(IntPtr.Zero);
  227. int t = GetDeviceCaps(hdc, DESKTOPHORZRES);
  228. int d = GetDeviceCaps(hdc, HORZRES);
  229. float ScaleX = (float)GetDeviceCaps(hdc, DESKTOPHORZRES) / (float)GetDeviceCaps(hdc, HORZRES);
  230. ReleaseDC(IntPtr.Zero, hdc);
  231. return ScaleX;
  232. }
  233. }
  234. /// <summary>
  235. /// 获取高度缩放百分比
  236. /// </summary>
  237. public static float ScaleY
  238. {
  239. get
  240. {
  241. IntPtr hdc = GetDC(IntPtr.Zero);
  242. float ScaleY = (float)(float)GetDeviceCaps(hdc, DESKTOPVERTRES) / (float)GetDeviceCaps(hdc, VERTRES);
  243. ReleaseDC(IntPtr.Zero, hdc);
  244. return ScaleY;
  245. }
  246. }
  247. #endregion
  248. }
  249. #endregion
  250. public static mainForm mainform1 = null;
  251. public mainForm()
  252. {
  253. InitializeComponent();
  254. mainform1 = this;
  255. System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
  256. stopwatch.Start();
  257. //端口初始化
  258. mySerialProcess.Init();
  259. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  260. //检查备忘录文件
  261. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.NoteFileName))
  262. {
  263. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.NoteFileName, "");
  264. }
  265. //检验流水号记录文件
  266. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.SerialNumFileName1))
  267. {
  268. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, "0");
  269. }
  270. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.SerialNumFileName2))
  271. {
  272. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, "0");
  273. }
  274. //检查文件夹
  275. if (!Directory.Exists(localInfo.LocalPath))
  276. {
  277. Directory.CreateDirectory(localInfo.LocalPath);
  278. }
  279. if (!Directory.Exists(localInfo.LocalDataPath))
  280. {
  281. Directory.CreateDirectory(localInfo.LocalDataPath);
  282. }
  283. if (!Directory.Exists(localInfo.ToolsPath))
  284. {
  285. Directory.CreateDirectory(localInfo.ToolsPath);
  286. }
  287. if (!Directory.Exists(localInfo.LocalPath + localInfo.CfgPathName))
  288. {
  289. Directory.CreateDirectory(localInfo.LocalPath + localInfo.CfgPathName);
  290. }
  291. //服务器初始化
  292. do
  293. {
  294. //检查是否存在配置文件
  295. if (File.Exists(localInfo.LocalPath + localInfo.ServerCfgFileName)) //存在配置文件从文件选择
  296. {
  297. //解密
  298. string sLine = aes.DecryptFromFile(localInfo.LocalPath + localInfo.ServerCfgFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  299. string[] array_CfgInfo = sLine.Split(',');
  300. //解析配置文件
  301. ServerIP = array_CfgInfo[0].ToString();
  302. ServerPort = array_CfgInfo[1].ToString();
  303. ServerUser = array_CfgInfo[2].ToString();
  304. ServerPassWd = array_CfgInfo[3].ToString();
  305. if (array_CfgInfo[4].ToString() == "True")
  306. {
  307. OfflineFlag = true;
  308. checkBox_OffLineFacMode.Checked = true;
  309. checkBox_OffLineCheckMode.Checked = true;
  310. }
  311. }
  312. else //不存在配置文件由用户选择
  313. {
  314. ServerCfgForm1.ShowDialog();
  315. switch (ServerCfgForm1.comboBox_Server.SelectedIndex)
  316. {
  317. case 0: //武汉园区
  318. case 1: //顺德工厂
  319. {
  320. ServerIP = "10.177.130.30";
  321. ServerPort = "15021";
  322. ServerUser = "factory_test";
  323. ServerPassWd = "ttium";
  324. OfflineFlag = false;
  325. checkBox_OffLineFacMode.Checked = false;
  326. checkBox_OffLineCheckMode.Checked = false;
  327. break;
  328. }
  329. case 2: //威灵园区
  330. case 3: //越南工厂
  331. case 4: //公司外部
  332. {
  333. ServerIP = "8.134.109.44";
  334. ServerPort = "21";
  335. ServerUser = "ttium";
  336. ServerPassWd = "ttium123";
  337. OfflineFlag = false;
  338. checkBox_OffLineFacMode.Checked = false;
  339. checkBox_OffLineCheckMode.Checked = false;
  340. break;
  341. }
  342. case 5: //离线使用
  343. {
  344. //输入管理员密码
  345. Scan scan_form = new Scan();
  346. scan_form.label1.Text = "请输入管理员密码";
  347. scan_form.textBox_Scan.UseSystemPasswordChar = true;
  348. scan_form.ShowDialog();
  349. if (scan_form.textBox_Scan.Text == "ttium.123")
  350. {
  351. OfflineFlag = true;
  352. checkBox_OffLineFacMode.Checked = true;
  353. checkBox_OffLineCheckMode.Checked = true;
  354. }
  355. else
  356. {
  357. MessageBox.Show("密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  358. System.Environment.Exit(0);
  359. }
  360. break;
  361. }
  362. default: //无效
  363. {
  364. System.Environment.Exit(0);
  365. break;
  366. }
  367. }
  368. //保存网络配置文件
  369. if (ServerCfgForm1.checkBox_NoticeSw.Checked)
  370. {
  371. string str = ServerIP + "," + ServerPort + "," + ServerUser + "," + ServerPassWd + "," + (OfflineFlag == true).ToString();
  372. //加密保存
  373. aes.EncryptToFile(str, localInfo.LocalPath + localInfo.ServerCfgFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  374. }
  375. }
  376. } while (false);
  377. //检查配置文件
  378. if (File.Exists(localInfo.LocalPath + localInfo.ConfigFileName)) //存在配置文件,导入配置信息
  379. {
  380. //打开文件
  381. StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.ConfigFileName);
  382. string sLine = "";
  383. ArrayList array_CfgInfo = new ArrayList();
  384. array_CfgInfo.Clear();
  385. while (sLine != null)
  386. {
  387. sLine = objReader.ReadLine();
  388. array_CfgInfo.Add(sLine);
  389. }
  390. objReader.Close();
  391. //解析配置文件
  392. try
  393. {
  394. //Port Set
  395. PortNumSave = array_CfgInfo[1].ToString().Split(':')[1];
  396. PortBaudrateSave = array_CfgInfo[2].ToString().Split(':')[1];
  397. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.IndexOf(PortNumSave);
  398. toolStripComboBox_Baudrate.SelectedIndex = toolStripComboBox_Baudrate.Items.IndexOf(PortBaudrateSave);
  399. 连接开机ToolStripMenuItem.Checked = (array_CfgInfo[3].ToString().Split(':')[1] == "True");
  400. 断开关机ToolStripMenuItem.Checked = (array_CfgInfo[4].ToString().Split(':')[1] == "True");
  401. 识别通讯盒ToolStripMenuItem.Checked = (array_CfgInfo[5].ToString().Split(':')[1] == "True");
  402. //Option
  403. 写入存储ToolStripMenuItem.Checked = (array_CfgInfo[8].ToString().Split(':')[1] == "True");
  404. //Server Set
  405. toolStripTextBox_ServerPath.Text = array_CfgInfo[11].ToString().Split(':')[1];
  406. //MacInfo
  407. toolStripTextBox_MAC.Text = array_CfgInfo[14].ToString().Split(':')[1];
  408. toolStripTextBoxMACAddr.Text = array_CfgInfo[15].ToString().Split(':')[1];
  409. toolStripTextBox_MACDate.Text = DateTime.Now.ToString("yyyyMMdd");
  410. toolStripTextBox_MACPD.Text = array_CfgInfo[17].ToString().Split(':')[1];
  411. //Log Address
  412. textBox_LogAddrBegin.Text = array_CfgInfo[20].ToString().Split(':')[1];
  413. textBox_LogAddrEnd.Text = array_CfgInfo[21].ToString().Split(':')[1];
  414. //电机类型
  415. 中置电机ToolStripMenuItem.Checked = (array_CfgInfo[24].ToString().Split(':')[1] == "True");
  416. 轮毂电机ToolStripMenuItem.Checked = !中置电机ToolStripMenuItem.Checked;
  417. //检测阈值
  418. toolStripTextBox_ThVol.Text = array_CfgInfo[28].ToString().Split(':')[1];
  419. toolStripTextBox_ThCur.Text = array_CfgInfo[29].ToString().Split(':')[1];
  420. toolStripTextBox_ThSpeed.Text = array_CfgInfo[30].ToString().Split(':')[1];
  421. toolStripTextBox_ThTor.Text = array_CfgInfo[31].ToString().Split(':')[1];
  422. toolStripTextBox_ThCad.Text = array_CfgInfo[32].ToString().Split(':')[1];
  423. toolStripTextBox_ThBikeSpeed.Text = array_CfgInfo[33].ToString().Split(':')[1];
  424. toolStripTextBox_ThT_PCB.Text = array_CfgInfo[34].ToString().Split(':')[1];
  425. toolStripTextBox_ThT_MCU.Text = array_CfgInfo[35].ToString().Split(':')[1];
  426. toolStripTextBox_ThT_Motor.Text = array_CfgInfo[36].ToString().Split(':')[1];
  427. //MOS内阻校准系数
  428. toolStripTextBox_MosCalK.Text = array_CfgInfo[39].ToString().Split(':')[1];
  429. toolStripTextBox_MOS1.Text= array_CfgInfo[40].ToString().Split(':')[1];
  430. toolStripTextBox_MOS2.Text = array_CfgInfo[41].ToString().Split(':')[1];
  431. toolStripTextBox_MOS3.Text = array_CfgInfo[42].ToString().Split(':')[1];
  432. //通信协议类型
  433. cANToolStripMenuItem.Checked = (array_CfgInfo[45].ToString().Split(':')[1] == "True");
  434. uARTToolStripMenuItem.Checked = !cANToolStripMenuItem.Checked;
  435. //自动更新开关
  436. 打开ToolStripMenuItem.Checked = (array_CfgInfo[49].ToString().Split(':')[1] == "True");
  437. 关闭ToolStripMenuItem.Checked = !打开ToolStripMenuItem.Checked;
  438. //位置校准偏差
  439. textBox_AngleDiffTh.Text = array_CfgInfo[52].ToString().Split(':')[1];
  440. toolStripTextBox_AngleAvgMax.Text = textBox_AngleDiffTh.Text;
  441. textBox_AngleZeroTh.Text = array_CfgInfo[53].ToString().Split(':')[1];
  442. toolStripTextBox_AngleZeroMax.Text = textBox_AngleZeroTh.Text;
  443. }
  444. catch (System.Exception)
  445. {
  446. timer_500ms.Enabled = false;
  447. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  448. timer_500ms.Enabled = true;
  449. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  450. }
  451. }
  452. else //不存在配置文件,生成文件写入默认值
  453. {
  454. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  455. }
  456. //解析本地流水号记录
  457. do
  458. {
  459. //测试模式
  460. label_FacModeSerial.Text = File.ReadAllText(localInfo.LocalPath + localInfo.SerialNumFileName1);
  461. //检验模式
  462. label_CheckModeSerial.Text = File.ReadAllText(localInfo.LocalPath + localInfo.SerialNumFileName2);
  463. } while (false);
  464. //获取本机信息,读取时间较长,优先从本地文件获取
  465. do
  466. {
  467. try
  468. {
  469. //本地文件为空,读取信息保存
  470. if (!File.Exists(localInfo.LocalPath + localInfo.PC_InfoFileName))
  471. {
  472. Local_HdInformation = "";
  473. Local_HdInformation += "计算机名称: " + System.Environment.UserName + "\r\n";
  474. Local_HdInformation += "IP地址: " + PC_Information.GetIpAddress() + "\r\n";
  475. Local_HdInformation += "系统ID: " + PC_Information.GetSystemID() + "\r\n";
  476. Local_HdInformation += "操作系统类型: " + PC_Information.GetSystemType() + "\r\n";
  477. Local_HdInformation += "主板型号: " + PC_Information.GetBoardType() + "\r\n";
  478. Local_HdInformation += "主板厂商: " + PC_Information.GetBoardManufacturer() + "\r\n";
  479. Local_HdInformation += "主板ID: " + PC_Information.GetBIOSSerialNumber() + "\r\n";
  480. Local_HdInformation += "CPU型号: " + PC_Information.GetCpuName() + "\r\n";
  481. Local_HdInformation += "CPU厂商: " + PC_Information.GetCpuManufacturer() + "\r\n";
  482. Local_HdInformation += "CPU ID: " + PC_Information.GetCPUSerialNumber() + "\r\n";
  483. Local_HdInformation += "内存容量: " + PC_Information.GetPhysicalMemory() + " GB" + "\r\n";
  484. Local_HdInformation += "MAC ID: " + PC_Information.GetNetCardMACAddress().Replace(":", "-") + "\r\n";
  485. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.PC_InfoFileName, Local_HdInformation);
  486. }
  487. //从本地读取,计算机名和IP地址重新读
  488. else
  489. {
  490. Local_HdInformation = "";
  491. string[] fileInfo = File.ReadAllLines(localInfo.LocalPath + localInfo.PC_InfoFileName, Encoding.UTF8);
  492. fileInfo[0] = "计算机名称: " + System.Environment.UserName;
  493. fileInfo[1] = "IP地址: " + PC_Information.GetIpAddress();
  494. for (int i = 0; i < fileInfo.Length; i++)
  495. Local_HdInformation += fileInfo[i] + "\r\n";
  496. File.Delete(localInfo.LocalPath + localInfo.PC_InfoFileName);
  497. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.PC_InfoFileName, Local_HdInformation);
  498. }
  499. }
  500. catch(Exception)
  501. {
  502. }
  503. } while (false);
  504. //系统登录
  505. do
  506. {
  507. EnterForm1.ShowDialog();
  508. try
  509. {
  510. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  511. {
  512. if (EnterForm1.comboBox_User.Text.Contains("量产"))
  513. {
  514. //隐藏设置项
  515. 其它配置项ToolStripMenuItem.Visible = false;
  516. 写入存储ToolStripMenuItem.Visible = false;
  517. 服务器配置ToolStripMenuItem.Visible = false;
  518. 判断阈值ToolStripMenuItem.Visible = false;
  519. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  520. mOS内阻范围ToolStripMenuItem.Visible = false;
  521. 力矩传感器检验ToolStripMenuItem.Visible = false;
  522. 位置校准偏差范围ToolStripMenuItem.Visible = false;
  523. //显示生产信息
  524. 生产信息ToolStripMenuItem.Visible = true;
  525. //显示电机类型,但不可编辑
  526. 电机类型ToolStripMenuItem.Visible = true;
  527. 中置电机ToolStripMenuItem.Enabled = false;
  528. 轮毂电机ToolStripMenuItem.Enabled = false;
  529. if (uARTToolStripMenuItem.Checked)
  530. UART协议ToolStripMenuItem.Visible = true;
  531. //隐藏研发调试界面
  532. tabPage_MotorParam.Parent = null;
  533. tabPage_BikeParam.Parent = null;
  534. tabPage_BikeParam2.Parent = null;
  535. tabPage_ControlParam.Parent = null;
  536. tabPage_SensorParam.Parent = null;
  537. tabPage_AssistParam.Parent = null;
  538. tabPage_UsrRideParam.Parent = null;
  539. tabPage_DebugParam.Parent = null;
  540. tabPage_RecordInfo.Parent = null;
  541. tabPage_OtherInfo.Parent = null;
  542. tabPage_OBC.Parent = null;
  543. tabPage_RAMorFLASH.Parent = null;
  544. tabPage_FactoryMode.Parent = null;
  545. tabPage_DebugInfo.Parent = null;
  546. tabPage_AngleCal.Parent = null;
  547. tabPage_FuncSet.Parent = null;
  548. //显示运行信息
  549. tabPage_RunInfo.Parent = tabControl2;
  550. //根据电机类型修改生产信息和电机类型
  551. if (EnterForm1.comboBox_User.Text.Contains("中置"))
  552. {
  553. 中置电机ToolStripMenuItem.Checked = true;
  554. 轮毂电机ToolStripMenuItem.Checked = false;
  555. toolStripTextBox_MACPD.Text = "MM_MC1";
  556. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  557. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  558. }
  559. else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
  560. {
  561. 中置电机ToolStripMenuItem.Checked = false;
  562. 轮毂电机ToolStripMenuItem.Checked = true;
  563. toolStripTextBox_MACPD.Text = "GF_250_1";
  564. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  565. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  566. }
  567. //显示对应生产测试界面
  568. if (EnterForm1.comboBox_User.Text.Contains("写入"))
  569. {
  570. tabPage_ProductMode_Write.Parent = tabControl1;
  571. tabPage_ProductMode_Write.Select();
  572. tabPage_ProductMode_Read.Parent = null;
  573. }
  574. else if (EnterForm1.comboBox_User.Text.Contains("检验"))
  575. {
  576. tabPage_ProductMode_Read.Parent = tabControl1;
  577. tabPage_ProductMode_Read.Select();
  578. tabPage_ProductMode_Write.Parent = null;
  579. }
  580. //应答指令不提示
  581. ACK_DisFlag = false;
  582. //退出登录
  583. break;
  584. }
  585. else if (EnterForm1.comboBox_User.Text == "工程参数配置")
  586. {
  587. //隐藏工作台内容,新建窗口完成配置
  588. groupBox1.Visible = false;
  589. groupBox3.Visible = false;
  590. tabControl2.Visible = false;
  591. //隐藏提示信息
  592. label_StarInfo.Visible = false;
  593. //打开参数配置框
  594. GenerateParamsForm.ShowDialog();
  595. System.Environment.Exit(0);
  596. //退出登录
  597. break;
  598. }
  599. else if (EnterForm1.comboBox_User.Text.Contains("样机"))
  600. {
  601. //隐藏量产界面
  602. tabPage_ProductMode_Read.Parent = null;
  603. tabPage_ProductMode_Write.Parent = null;
  604. //隐藏配置项
  605. 其它配置项ToolStripMenuItem.Visible = false;
  606. 服务器配置ToolStripMenuItem.Visible = false;
  607. 判断阈值ToolStripMenuItem.Visible = false;
  608. 力矩传感器检验ToolStripMenuItem.Visible = false;
  609. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  610. mOS内阻范围ToolStripMenuItem.Visible = false;
  611. 位置校准偏差范围ToolStripMenuItem.Visible = false;
  612. //显示生产信息
  613. 生产信息ToolStripMenuItem.Visible = true;
  614. //显示电机类型,但不可编辑
  615. 电机类型ToolStripMenuItem.Visible = true;
  616. 中置电机ToolStripMenuItem.Enabled = true;
  617. 轮毂电机ToolStripMenuItem.Enabled = true;
  618. if (uARTToolStripMenuItem.Checked)
  619. UART协议ToolStripMenuItem.Visible = true;
  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. break;
  638. }
  639. else if (EnterForm1.comboBox_User.Text == "FCT治具测试")
  640. {
  641. //隐藏设置项
  642. 其它配置项ToolStripMenuItem.Visible = false;
  643. 写入存储ToolStripMenuItem.Visible = false;
  644. 服务器配置ToolStripMenuItem.Visible = false;
  645. 判断阈值ToolStripMenuItem.Visible = false;
  646. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  647. mOS内阻范围ToolStripMenuItem.Visible = false;
  648. 力矩传感器检验ToolStripMenuItem.Visible = false;
  649. 位置校准偏差范围ToolStripMenuItem.Visible = false;
  650. //显示生产信息
  651. 生产信息ToolStripMenuItem.Visible = true;
  652. //显示电机类型,但不可编辑
  653. 电机类型ToolStripMenuItem.Visible = false;
  654. 中置电机ToolStripMenuItem.Enabled = false;
  655. 轮毂电机ToolStripMenuItem.Enabled = false;
  656. if (uARTToolStripMenuItem.Checked)
  657. UART协议ToolStripMenuItem.Visible = true;
  658. //隐藏研发调试界面
  659. tabPage_MotorParam.Parent = null;
  660. tabPage_BikeParam.Parent = null;
  661. tabPage_BikeParam2.Parent = null;
  662. tabPage_ControlParam.Parent = null;
  663. tabPage_SensorParam.Parent = null;
  664. tabPage_AssistParam.Parent = null;
  665. tabPage_UsrRideParam.Parent = null;
  666. tabPage_DebugParam.Parent = null;
  667. tabPage_RecordInfo.Parent = null;
  668. tabPage_OtherInfo.Parent = null;
  669. tabPage_OBC.Parent = null;
  670. tabPage_RAMorFLASH.Parent = null;
  671. tabPage_FactoryMode.Parent = null;
  672. tabPage_DebugInfo.Parent = null;
  673. tabPage_AngleCal.Parent = null;
  674. tabPage_FuncSet.Parent = null;
  675. //显示运行信息
  676. tabPage_RunInfo.Parent = tabControl2;
  677. //目前仅轮毂使用
  678. 中置电机ToolStripMenuItem.Checked = false;
  679. 轮毂电机ToolStripMenuItem.Checked = true;
  680. toolStripTextBox_MACPD.Text = "GF_250_1";
  681. toolStripTextBox_ServerPath.Text = "HUB_Control_FCT";
  682. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  683. //显示量产测试界面
  684. tabPage_ProductMode_Write.Parent = tabControl1;
  685. tabPage_ProductMode_Write.Select();
  686. tabPage_ProductMode_Read.Parent = null;
  687. checkBox_OffLineFacMode.Checked = false;
  688. checkBox_OffLineFacMode.Enabled = true;
  689. checkBox_OffLineCheckMode.Checked = false;
  690. checkBox_OffLineCheckMode.Enabled = true;
  691. //应答指令不提示
  692. ACK_DisFlag = false;
  693. //退出登录
  694. break;
  695. }
  696. else if (EnterForm1.comboBox_User.Text == "研发调试")
  697. {
  698. //隐藏量产界面
  699. tabPage_ProductMode_Read.Parent = null;
  700. tabPage_ProductMode_Write.Parent = null;
  701. 服务器配置ToolStripMenuItem.Visible = false;
  702. if (uARTToolStripMenuItem.Checked)
  703. UART协议ToolStripMenuItem.Visible = true;
  704. //退出登录
  705. break;
  706. }
  707. else if (EnterForm1.comboBox_User.Text == "管理员")
  708. {
  709. //不隐藏任何界面
  710. //...
  711. //退出登录
  712. break;
  713. }
  714. else
  715. {
  716. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  717. //重新登录
  718. continue;
  719. }
  720. }
  721. else
  722. {
  723. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  724. //重新登录
  725. continue;
  726. }
  727. }
  728. catch (Exception)
  729. {
  730. System.Environment.Exit(0);
  731. }
  732. } while (true);
  733. //配置网络FTP服务器
  734. myFtp.FtpOption(ServerIP, ServerPort, ServerUser, ServerPassWd, "admin", "ttium_admin");
  735. //创建线程,定时检测网络连接状态
  736. Thread th = new Thread(NetworkCheck);
  737. th.IsBackground = true;
  738. th.Start();
  739. //允许跨线程访问
  740. Control.CheckForIllegalCrossThreadCalls = false;
  741. }
  742. /// <summary>
  743. /// 检查网络状态线程
  744. /// </summary>
  745. private void NetworkCheck()
  746. {
  747. //允许离线使用,直接退出
  748. if (OfflineFlag == true) //允许离线使用
  749. {
  750. MessageBoxTimeOut.Show("离线使用,不检测网络状态!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  751. return;
  752. }
  753. //不允许离线使用,实时监测网络状态
  754. else
  755. {
  756. //初始化第一次连接FTP服务器
  757. bool Result = myFtp.CheckFtp();
  758. if (Result == true)//服务器连接成功
  759. {
  760. myFtp.IsNetConnected = true;
  761. //上传登录日志
  762. do
  763. {
  764. //日志文件名
  765. string date = DateTime.Now.ToString("yyyy-MM-dd_HHmmss_fff");
  766. string fileName = date;
  767. //日志内容
  768. string fileInfo = Local_HdInformation;
  769. //保存本地
  770. if (!Directory.Exists(localInfo.LocalLogPath))
  771. Directory.CreateDirectory(localInfo.LocalLogPath);
  772. System.IO.File.WriteAllText(localInfo.LocalLogPath + fileName, fileInfo);
  773. //上传服务器
  774. myFtp.UploadFile(localInfo.LocalLogPath + fileName, "/Tools/Welling_Motor_Debug_Tool/log");
  775. } while (false);
  776. }
  777. else//服务器连接失败
  778. {
  779. myFtp.IsNetConnected = false;
  780. if (EnterForm1.comboBox_User.Text != "管理员")
  781. {
  782. MessageBoxTimeOut.Show("网络断开,将自动关闭!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  783. this.Close();
  784. }
  785. }
  786. //创建定时器,定时30s检查网络
  787. System.Timers.Timer timer_CheckNet = new System.Timers.Timer();
  788. timer_CheckNet.Enabled = true;
  789. timer_CheckNet.Interval = 30000;
  790. timer_CheckNet.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_CheckNet_Tick);
  791. timer_CheckNet.Start();
  792. while (true)
  793. {
  794. Thread.Sleep(1);
  795. if (myFtp.IsNetConnected == false)
  796. {
  797. label_Server_ComStatus.Text = "网络已断开";
  798. label_ServerStatus.BackColor = Color.Red;
  799. }
  800. else
  801. {
  802. label_Server_ComStatus.Text = "网络已连接";
  803. label_ServerStatus.BackColor = Color.Green;
  804. }
  805. }
  806. }
  807. }
  808. /// <summary>
  809. /// 线程中定时任务,检查网络状态
  810. /// </summary>
  811. /// <param name="sender"></param>
  812. /// <param name="e"></param>
  813. private void timer_CheckNet_Tick(object sender, EventArgs e)
  814. {
  815. //连接FTP服务器
  816. bool Result = myFtp.CheckFtp();
  817. if (Result == true)//服务器连接成功
  818. {
  819. myFtp.IsNetConnected = true;
  820. //允许使用
  821. groupBox1.Enabled = true;
  822. groupBox3.Enabled = true;
  823. tabControl2.Enabled = true;
  824. }
  825. else//服务器连接失败
  826. {
  827. myFtp.IsNetConnected = false;
  828. if (EnterForm1.comboBox_User.Text != "管理员")
  829. {
  830. MessageBoxTimeOut.Show("网络断开, 请检查网络!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Warning); //提示框自动3s关闭
  831. //禁止使用
  832. groupBox1.Enabled = false;
  833. groupBox3.Enabled = false;
  834. tabControl2.Enabled = false;
  835. }
  836. }
  837. }
  838. #region 非独占性延时函数
  839. public static void Delay_ms(int milliSecond)
  840. {
  841. int start = Environment.TickCount;
  842. while (Math.Abs(Environment.TickCount - start) < milliSecond)//毫秒
  843. {
  844. Application.DoEvents();
  845. }
  846. }
  847. #endregion
  848. private void MainForm_Load(object sender, System.EventArgs e)
  849. {
  850. timer_500ms.Start();
  851. //页面初始化
  852. label_BuildTime.Text = "编译时间:" + System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString("yyyy-MM-dd HH:mm:ss");
  853. label_Computername.Text = System.Environment.UserName;
  854. label_UserName.Text = EnterForm1.comboBox_User.Text;
  855. //位置校准表格初始化
  856. for (int i = 0; i < 7; i++)
  857. {
  858. int index = dataGridView_AngleCal.Rows.Add();
  859. dataGridView_AngleCal.Rows[index].Cells[0].Value = i + 1;
  860. }
  861. dataGridView_AngleCal.AllowUserToAddRows = false;
  862. //拓展功能表格初始化
  863. for (int i = 0; i < 8; i++)
  864. {
  865. int index = dataGridView_FunSet.Rows.Add();
  866. dataGridView_FunSet.Rows[index].Cells[0].Value = "#" + (i + 1).ToString();
  867. }
  868. dataGridView_FunSet.AllowUserToAddRows = false;
  869. //窗体显示版本
  870. this.Text += Version;
  871. //检查版本,自动更新
  872. do
  873. {
  874. if ((打开ToolStripMenuItem.Checked == false) || OfflineFlag == true)//关闭自动更新或离线时
  875. {
  876. break;
  877. }
  878. //检查网络状态
  879. if (myFtp.CheckFtp() == false)
  880. {
  881. MessageBoxTimeOut.Show("网络断开,自动更新失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  882. break;
  883. }
  884. else
  885. {
  886. //检查本地文件删除
  887. if (System.IO.File.Exists(localInfo.LocalPath + "\\Version"))
  888. System.IO.File.Delete(localInfo.LocalPath + "\\Version");
  889. //读取最新版本号
  890. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/Version", localInfo.LocalPath);
  891. StreamReader objReader = new StreamReader(localInfo.LocalPath + "\\Version");
  892. string sLine = "";
  893. ArrayList arrText = new ArrayList();//创建一个动态数组
  894. while (sLine != null)
  895. {
  896. sLine = objReader.ReadLine();
  897. arrText.Add(sLine);
  898. }
  899. objReader.Close();
  900. System.IO.File.Delete(localInfo.LocalPath + "\\Version");
  901. //检查是否有最新版本
  902. string[] VerOld = mainForm.Version.Trim().Split('.');
  903. string[] VerNew = arrText[0].ToString().Trim().Split('.');
  904. int VerOld_int = Convert.ToInt32(VerOld[0]) * 10000 + Convert.ToInt32(VerOld[1].PadLeft(2, '0')) * 100 + Convert.ToInt32(VerOld[2].PadLeft(2, '0'));
  905. int VerNew_int = Convert.ToInt32(VerNew[0]) * 10000 + Convert.ToInt32(VerNew[1].PadLeft(2, '0')) * 100 + Convert.ToInt32(VerNew[2].PadLeft(2, '0'));
  906. if (VerNew_int <= VerOld_int)
  907. {
  908. //版本已是最新,跳出
  909. break;
  910. }
  911. //确认下载最新版本
  912. if (MessageBox.Show("是否更新新版本?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  913. {
  914. string SavePath = Directory.GetCurrentDirectory();
  915. string[] FileList = myFtp.GetFileNameList("/Tools/Welling_Motor_Debug_Tool");
  916. foreach (string file in FileList)
  917. {
  918. if (file.Contains(".exe"))
  919. {
  920. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/" + file, SavePath);
  921. MessageBox.Show("新版本下载完成,请手动删除旧版本!\r\n最新版本:" + file, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  922. System.Environment.Exit(0);
  923. }
  924. }
  925. }
  926. }
  927. } while (false);
  928. //下拉控件初始值设定
  929. comboBox_WorkMode.SelectedIndex = 0;
  930. comboBox_GearSt.SelectedIndex = 0;
  931. comboBox_LightSwitch.SelectedIndex = 1;
  932. comboBox_OBC_SetGearST.SelectedIndex = 0;
  933. comboBox_OBC_LightSw.SelectedIndex = 1;
  934. comboBox_AssistTorque.SelectedIndex = 0;
  935. comboBox_AssistCadence.SelectedIndex = 0;
  936. //combobox事件定义
  937. this.comboBox_WorkMode.SelectedIndexChanged += new System.EventHandler(this.comboBox_WorkMode_SelectedIndexChanged);
  938. this.comboBox_GearSt.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  939. this.comboBox_LightSwitch.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  940. this.comboBox_OBC_SetGearST.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  941. this.comboBox_OBC_LightSw.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  942. //端口自动连接
  943. if ((PortNumSave != string.Empty) && (PortBaudrateSave != string.Empty)) //有数值时采用上次使用的值
  944. {
  945. try
  946. {
  947. PortConnect();
  948. }
  949. catch (System.Exception)
  950. {
  951. timer_500ms.Enabled = false;
  952. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  953. timer_500ms.Enabled = true;
  954. }
  955. }
  956. //不识别联动装置盒自动打开界面
  957. #if true
  958. groupBox1.Visible = true;
  959. groupBox3.Visible = true;
  960. tabControl2.Visible = true;
  961. label_StarInfo.Visible = false;
  962. #endif
  963. //创建线程,定时解析数据
  964. Thread th = new Thread(Task_SerialProcess);
  965. th.IsBackground = true;
  966. th.Start();
  967. }
  968. #region 结构体与字节流相互转换
  969. public static class MyConverter
  970. {
  971. /// <summary>
  972. /// 由结构体转换为byte数组
  973. /// </summary>
  974. public static byte[] StructureToByte<T>(T structure)
  975. {
  976. int size = Marshal.SizeOf(typeof(T));
  977. byte[] buffer = new byte[size];
  978. IntPtr bufferIntPtr = Marshal.AllocHGlobal(size);
  979. try
  980. {
  981. Marshal.StructureToPtr(structure, bufferIntPtr, true);
  982. Marshal.Copy(bufferIntPtr, buffer, 0, size);
  983. }
  984. finally
  985. {
  986. Marshal.FreeHGlobal(bufferIntPtr);
  987. }
  988. return buffer;
  989. }
  990. /// <summary>
  991. /// 由byte数组转换为结构体
  992. /// </summary>
  993. public static T ByteToStructure<T>(byte[] dataBuffer, ushort StarIndex)
  994. {
  995. object structure = null;
  996. int size = Marshal.SizeOf(typeof(T));
  997. IntPtr allocIntPtr = Marshal.AllocHGlobal(size);
  998. try
  999. {
  1000. Marshal.Copy(dataBuffer, StarIndex, allocIntPtr, size);
  1001. structure = Marshal.PtrToStructure(allocIntPtr, typeof(T));
  1002. }
  1003. finally
  1004. {
  1005. Marshal.FreeHGlobal(allocIntPtr);
  1006. }
  1007. return (T)structure;
  1008. }
  1009. }
  1010. #endregion
  1011. #region 故障日志解析显示
  1012. private void ErrorLogDisplay(MC_ErrorLogSaveInfo_Struct_t Log1, MC_ErrorLogSaveInfo_Struct_t Log2)
  1013. {
  1014. string SaveData = "";
  1015. //Log1
  1016. if (Log1.Error_Index != 0xFFFF)
  1017. {
  1018. SaveData += "故障序号:" + Convert.ToString(Log1.Error_Index) + ", ";
  1019. SaveData += "备注1:" + Convert.ToString(Log1.NotesInfo1) + ", ";
  1020. SaveData += "备注2:" + Convert.ToString(Log1.NotesInfo2) + ", ";
  1021. SaveData += "备注3:" + Convert.ToString(Log1.NotesInfo3) + ", ";
  1022. SaveData += "故障码:" + "0x" + Convert.ToString(Log1.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  1023. SaveData += "运行时间:" + Convert.ToString(Log1.RunTime) + "min" + ", ";
  1024. SaveData += "车速:" + ((float)Log1.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  1025. SaveData += "电机转速:" + Convert.ToString(Log1.RunInfo.MotorSpeed) + "rpm" + ", ";
  1026. SaveData += "功率:" + Convert.ToString(Log1.RunInfo.Power * 2) + "w" + ", ";
  1027. SaveData += "电压:" + Convert.ToString(Log1.RunInfo.BusVoltage) + "mV" + ", ";
  1028. SaveData += "电流:" + Convert.ToString(Log1.RunInfo.BusCurrent) + "mA" + ", ";
  1029. SaveData += "踏频:" + Convert.ToString(Log1.RunInfo.Cadence) + "rpm" + ", ";
  1030. SaveData += "力矩:" + Convert.ToString(Log1.RunInfo.Torque) + "N.m" + ", ";
  1031. SaveData += "方向:" + ((Log1.RunInfo.CadenceDir == 0) ? "正" : ((Log1.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  1032. SaveData += "档位:" + "0x" + Convert.ToString(Log1.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  1033. SaveData += "灯开关:" + ((Log1.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  1034. SaveData += "电量:" + Convert.ToString(Log1.RunInfo.SOC) + "%" + ", ";
  1035. if ((Log1.RunInfo.RemainDistance == 0xEEEE) || (Log1.RunInfo.RemainDistance == 0xFFFF))
  1036. {
  1037. SaveData += "续航:" + "---km" + ", ";
  1038. }
  1039. else
  1040. {
  1041. SaveData += "续航:" + Convert.ToString(Log1.RunInfo.RemainDistance) + "km" + ", ";
  1042. }
  1043. SaveData += "力矩AD:" + Convert.ToString(Log1.RunInfo.Torque_AD) + ", ";
  1044. SaveData += "功耗:" + Convert.ToString(Log1.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  1045. SaveData += "PCB温度:" + Convert.ToString((int)(Log1.RunInfo.T_PCB - 40)) + "℃" + ", ";
  1046. SaveData += "绕组温度:" + Convert.ToString((int)(Log1.RunInfo.T_Coil - 40)) + "℃" + ", ";
  1047. SaveData += "MCU温度:" + Convert.ToString((int)(Log1.RunInfo.T_MCU - 40)) + "℃" + ", ";
  1048. SaveData += "单次里程:" + Convert.ToString((float)Log1.RunInfo.Ride_Km / 10f) + "km" + ", ";
  1049. SaveData += "单次时间:" + Convert.ToString(Log1.RunInfo.Ride_Time) + "s" + ", ";
  1050. SaveData += "q轴电流:" + Convert.ToString(Log1.IqCurrent) + ", ";
  1051. SaveData += "q轴电压:" + Convert.ToString(Log1.IqVoltage) + ", ";
  1052. SaveData += "d轴电流:" + Convert.ToString(Log1.IdCurrent) + ", ";
  1053. SaveData += "d轴电压:" + Convert.ToString(Log1.IdVoltage) + ", ";
  1054. SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
  1055. SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
  1056. SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
  1057. SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
  1058. SaveData += "\r\n\r\n";
  1059. richTextBox_Record.AppendText(SaveData);
  1060. SaveData = "";
  1061. }
  1062. //Log2
  1063. if (Log2.Error_Index != 0xFFFF)
  1064. {
  1065. SaveData += "故障序号:" + Convert.ToString(Log2.Error_Index) + ", ";
  1066. SaveData += "备注1:" + Convert.ToString(Log2.NotesInfo1) + ", ";
  1067. SaveData += "备注2:" + Convert.ToString(Log2.NotesInfo2) + ", ";
  1068. SaveData += "备注3:" + Convert.ToString(Log2.NotesInfo3) + ", ";
  1069. SaveData += "故障码:" + "0x" + Convert.ToString(Log2.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  1070. SaveData += "运行时间:" + Convert.ToString(Log2.RunTime) + "min" + ", ";
  1071. SaveData += "车速:" + ((float)Log2.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  1072. SaveData += "电机转速:" + Convert.ToString(Log2.RunInfo.MotorSpeed) + "rpm" + ", ";
  1073. SaveData += "功率:" + Convert.ToString(Log2.RunInfo.Power * 2) + "w" + ", ";
  1074. SaveData += "电压:" + Convert.ToString(Log2.RunInfo.BusVoltage) + "mV" + ", ";
  1075. SaveData += "电流:" + Convert.ToString(Log2.RunInfo.BusCurrent) + "mA" + ", ";
  1076. SaveData += "踏频:" + Convert.ToString(Log2.RunInfo.Cadence) + "rpm" + ", ";
  1077. SaveData += "力矩:" + Convert.ToString(Log2.RunInfo.Torque) + "N.m" + ", ";
  1078. SaveData += "方向:" + ((Log2.RunInfo.CadenceDir == 0) ? "正" : ((Log2.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  1079. SaveData += "档位:" + "0x" + Convert.ToString(Log2.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  1080. SaveData += "灯开关:" + ((Log2.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  1081. SaveData += "电量:" + Convert.ToString(Log2.RunInfo.SOC) + "%" + ", ";
  1082. if ((Log2.RunInfo.RemainDistance == 0xEEEE) || (Log2.RunInfo.RemainDistance == 0xFFFF))
  1083. {
  1084. SaveData += "续航:" + "---km" + ", ";
  1085. }
  1086. else
  1087. {
  1088. SaveData += "续航:" + Convert.ToString(Log2.RunInfo.RemainDistance) + "km" + ", ";
  1089. }
  1090. SaveData += "力矩AD:" + Convert.ToString(Log2.RunInfo.Torque_AD) + ", ";
  1091. SaveData += "功耗:" + Convert.ToString(Log2.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  1092. SaveData += "PCB温度:" + Convert.ToString((int)(Log2.RunInfo.T_PCB - 40)) + "DegreeC" + ", ";
  1093. SaveData += "绕组温度:" + Convert.ToString((int)(Log2.RunInfo.T_Coil - 40)) + "DegreeC" + ", ";
  1094. SaveData += "MCU温度:" + Convert.ToString((int)(Log2.RunInfo.T_MCU - 40)) + "DegreeC" + ", ";
  1095. SaveData += "单次里程:" + Convert.ToString((float)Log2.RunInfo.Ride_Km / 10f) + "km" + ", ";
  1096. SaveData += "单次时间:" + Convert.ToString(Log2.RunInfo.Ride_Time) + "s" + ", ";
  1097. SaveData += "q轴电流:" + Convert.ToString(Log2.IqCurrent) + ", ";
  1098. SaveData += "q轴电压:" + Convert.ToString(Log2.IqVoltage) + ", ";
  1099. SaveData += "d轴电流:" + Convert.ToString(Log2.IdCurrent) + ", ";
  1100. SaveData += "d轴电压:" + Convert.ToString(Log2.IdVoltage) + ", ";
  1101. SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
  1102. SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
  1103. SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
  1104. SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
  1105. SaveData += "\r\n\r\n";
  1106. richTextBox_Record.AppendText(SaveData);
  1107. SaveData = "";
  1108. }
  1109. }
  1110. #endregion
  1111. #region 串口数据解析线程
  1112. /// <summary>
  1113. /// 串口数据解析线程
  1114. /// </summary>
  1115. private void Task_SerialProcess()
  1116. {
  1117. //创建定时器,定时读取串口数据
  1118. System.Timers.Timer timer_ReadSerial = new System.Timers.Timer();
  1119. timer_ReadSerial.Enabled = true;
  1120. timer_ReadSerial.Interval = 20;
  1121. timer_ReadSerial.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_ReadSerial_Tick);
  1122. timer_ReadSerial.Start();
  1123. while (true)
  1124. {
  1125. Thread.Sleep(1);
  1126. };
  1127. }
  1128. /// <summary>
  1129. /// 串口解析定时器
  1130. /// </summary>
  1131. /// <param name="sender"></param>
  1132. /// <param name="e"></param>
  1133. private void timer_ReadSerial_Tick(object sender, EventArgs e)
  1134. {
  1135. //串口解析
  1136. Serial_process(mySerialProcess.buffer);
  1137. }
  1138. #endregion
  1139. #region 数据解析
  1140. public void Serial_process(List<byte> buffer)
  1141. {
  1142. byte DataNum = 0; //记录每条命令数据段的长度
  1143. ushort PackageID, Cmd;
  1144. byte[] Data = new byte[1024];
  1145. try
  1146. {
  1147. while (buffer.Count >= 13)//当buffer中的数据的个数大于等于4个时,即每一帧的数据长度所在位(第4位)出现时
  1148. {
  1149. if (buffer[0] == 0x55 && buffer[1] == 0xAA)//判断帧头
  1150. {
  1151. PackageID = (ushort)(buffer[2] * 256 + buffer[3]);
  1152. if ((PackageID == 0x0710) || (PackageID == 0x0715) || (PackageID == 0x07FF) || (PackageID == 0x0720) || (PackageID == 0x0713))
  1153. {
  1154. int CmdLen = buffer[5];
  1155. if (buffer.Count < CmdLen + 11) break;//如果接收到的数据没有达到一帧数据的指定长度, 则执行下次循环
  1156. while (CmdLen > 0) //读取命令段
  1157. {
  1158. Cmd = (ushort)(buffer[6] * 256 + buffer[7]);
  1159. DataNum = (byte)(buffer[7]);//命令字的第二个字节的表示数据位的长度
  1160. if (DataNum <= (CmdLen - 2))
  1161. {
  1162. for (int i = 0; i < DataNum; i++)
  1163. {
  1164. Data[i] = buffer[i + 8];
  1165. }
  1166. // 串口接收的数据 显示在子窗口
  1167. if (this.DebugWindowIsOpen && this.DebugDataDisplayEnable)
  1168. {
  1169. string strTemp = String.Empty;
  1170. strTemp += System.DateTimeOffset.Now.ToString("HH:mm:ss.fff") + " <-- ";
  1171. for (int i = 0; i < CmdLen + 11; i++)
  1172. {
  1173. strTemp += (buffer[i].ToString("X2") + " ");
  1174. }
  1175. strTemp += "\n";
  1176. DebugForm.debug1.richTextBox_DebugRev.Text += strTemp;
  1177. }
  1178. buffer.RemoveRange(0, CmdLen + 11);
  1179. DataCmdProcess(PackageID, Cmd, Data);//对于不同的命令段,做不同的处理
  1180. DataRevToString(Cmd, Data);//指令数据转为字符串
  1181. }
  1182. }
  1183. }
  1184. else
  1185. {
  1186. buffer.RemoveAt(0);//ID不对
  1187. }
  1188. }
  1189. else
  1190. {
  1191. buffer.RemoveAt(0);//帧头不对,删除帧头高字节
  1192. }
  1193. }
  1194. }
  1195. catch (Exception)
  1196. {
  1197. }
  1198. }
  1199. private void DataCmdProcess(ushort ID, ushort CmdTemp, byte[] Data)
  1200. {
  1201. int DataTemp;
  1202. ushort uData16;
  1203. unchecked
  1204. {
  1205. this.Invoke((EventHandler)(delegate { label_RecCount.Text = Convert.ToString(Convert.ToInt32(label_RecCount.Text) + 1); }));
  1206. }
  1207. #region 解析发送给CDL的指令
  1208. if (ID == 0x7FF)
  1209. {
  1210. switch (CmdTemp)
  1211. {
  1212. case 0x1100://
  1213. {
  1214. unchecked
  1215. {
  1216. this.Invoke((EventHandler)(delegate
  1217. {
  1218. //CDL连接成功
  1219. mySerialProcess.CDL_Online_Flag = true;
  1220. MessageBoxTimeOut.Show("连接成功!", "提示", 500);
  1221. groupBox1.Visible = true;
  1222. groupBox3.Visible = true;
  1223. tabControl2.Visible = true;
  1224. label_StarInfo.Visible = false;
  1225. }));
  1226. }
  1227. break;
  1228. }
  1229. default: break;
  1230. }
  1231. }
  1232. #endregion
  1233. #region 解析电机的命令
  1234. else if ((ID == 0x715) || (ID == 0x710))
  1235. {
  1236. switch (CmdTemp)
  1237. {
  1238. case 0x1020://电机运行信息
  1239. {
  1240. unchecked
  1241. {
  1242. this.Invoke((EventHandler)(delegate
  1243. {
  1244. MC_RunInfo_Refresh = true;
  1245. //车速
  1246. DataTemp = (int)(Data[1] * 256 + Data[0]);
  1247. textBox_RunInfo_BikeSpeed.Text = ((float)DataTemp / 10f).ToString("0.0") + " km/h";
  1248. //输出转速
  1249. DataTemp = (ushort)(Data[3] * 256 + Data[2]);
  1250. textBox_RunInfo_MotorSpeed.Text = Convert.ToString(DataTemp) + " rpm";
  1251. Class_MotorSpeed.String = textBox_RunInfo_MotorSpeed.Text;
  1252. Class_MotorSpeed.Data = DataTemp;
  1253. //电功率
  1254. DataTemp = (ushort)(Data[5] * 256 + Data[4]);
  1255. textBox_RunInfo_Power.Text = Convert.ToString(DataTemp) + " W";
  1256. //母线电压
  1257. DataTemp = (ushort)(Data[7] * 256 + Data[6]);
  1258. textBox_RunInfo_Vol.Text = Convert.ToString(DataTemp) + " mV";
  1259. //textBox_RunInfo_Vol.Text = (DataTemp / 1000f).ToString("0.0") + " V";
  1260. //母线电流
  1261. DataTemp = (short)(Data[9] * 256 + Data[8]);
  1262. textBox_RunInfo_Current.Text = Convert.ToString(DataTemp) + " mA";
  1263. //textBox_RunInfo_Current.Text = (DataTemp / 1000f).ToString("0.0") + " A";
  1264. Class_CurrentData.String = textBox_RunInfo_Current.Text;
  1265. Class_CurrentData.Data = DataTemp;
  1266. //踏频
  1267. DataTemp = (ushort)(Data[10]);
  1268. textBox_RunInfo_Cadence.Text = Convert.ToString(DataTemp) + " rpm";
  1269. Class_CadenceData.String = textBox_RunInfo_Cadence.Text;
  1270. Class_CadenceData.Data = DataTemp;
  1271. //踩踏力矩
  1272. DataTemp = (ushort)(Data[11]);
  1273. textBox_RunInfo_Torque.Text = Convert.ToString(DataTemp) + " N.m";
  1274. Class_TorqueData.String = textBox_RunInfo_Torque.Text;
  1275. Class_TorqueData.Data = DataTemp;
  1276. //踩踏方向
  1277. DataTemp = (ushort)(Data[12]);
  1278. if (DataTemp == 0)
  1279. {
  1280. textBox_RunInfo_Dir.Text = "正向";
  1281. }
  1282. else if (DataTemp == 1)
  1283. {
  1284. textBox_RunInfo_Dir.Text = "反向";
  1285. }
  1286. else if (DataTemp == 2)
  1287. {
  1288. textBox_RunInfo_Dir.Text = "停止";
  1289. }
  1290. //助力档位
  1291. DataTemp = (ushort)(Data[13]);
  1292. if (DataTemp == 0x33)
  1293. {
  1294. textBox_RunInfo_GearSt.Text = "SMART";
  1295. //comboBox_GearSt.SelectedIndex = 5;
  1296. //comboBox_OBC_SetGearST.SelectedIndex = 5;
  1297. }
  1298. else if (DataTemp == 0x22)
  1299. {
  1300. textBox_RunInfo_GearSt.Text = "WALK";
  1301. //comboBox_GearSt.SelectedIndex = 6;
  1302. //comboBox_OBC_SetGearST.SelectedIndex = 6;
  1303. }
  1304. else
  1305. {
  1306. string[] Gears = new string[5] { "OFF", "ECO", "NORM", "SPORT", "TURBO" };
  1307. textBox_RunInfo_GearSt.Text = Gears[DataTemp];
  1308. //comboBox_GearSt.SelectedIndex = DataTemp;
  1309. //comboBox_OBC_SetGearST.SelectedIndex = DataTemp;
  1310. }
  1311. //大灯状态
  1312. DataTemp = (ushort)(Data[14]);
  1313. if (DataTemp == 0xF0)
  1314. {
  1315. textBox_RunInfo_LightSwitch.Text = "OFF";
  1316. //comboBox_LightSwitch.SelectedIndex = 1;
  1317. //comboBox_OBC_LightSw.SelectedIndex = 1;
  1318. }
  1319. else if (DataTemp == 0xF1)
  1320. {
  1321. textBox_RunInfo_LightSwitch.Text = "ON";
  1322. //comboBox_LightSwitch.SelectedIndex = 0;
  1323. //comboBox_OBC_LightSw.SelectedIndex = 0;
  1324. }
  1325. //剩余电量
  1326. DataTemp = (ushort)(Data[15]);
  1327. textBox_RunInfo_SOC.Text = Convert.ToString(DataTemp) + " %";
  1328. //剩余续航里程
  1329. DataTemp = (ushort)(Data[17] * 256 + Data[16]);
  1330. if ((DataTemp == 0xEEEE) || (DataTemp == 0xFFFF))
  1331. {
  1332. textBox_RunInfo_Range.Text = "---";
  1333. }
  1334. else
  1335. {
  1336. textBox_RunInfo_Range.Text = Convert.ToString(DataTemp) + " km";
  1337. }
  1338. //预留(显示力矩Reg),空2bytes
  1339. DataTemp = (ushort)(Data[19] * 256 + Data[18]);
  1340. textBox_TorqueReg.Text = Convert.ToString(DataTemp);
  1341. //平均功耗
  1342. DataTemp = (ushort)(Data[20]);
  1343. textBox_RunInfo_AvgPower.Text = Convert.ToString(DataTemp * 10) + " mAh/km";
  1344. //PCB温度
  1345. DataTemp = (ushort)(Data[21]);
  1346. textBox_RunInfo_T_PCB.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1347. Class_MotorTemp.String = textBox_RunInfo_T_PCB.Text;
  1348. Class_MotorTemp.Data = DataTemp - 40;
  1349. //绕组温度
  1350. DataTemp = (ushort)(Data[22]);
  1351. textBox_RunInfo_T_Coil.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1352. //MCU温度
  1353. DataTemp = (ushort)(Data[23]);
  1354. textBox_RunInfo_T_MCU.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1355. //单次里程
  1356. DataTemp = (ushort)(Data[25] * 256 + Data[24]);
  1357. textBox_RunInfo_Trip.Text = ((float)DataTemp / 10f).ToString("0.0") + " km";
  1358. //单次时间
  1359. DataTemp = (ushort)(Data[27] * 256 + Data[26]);
  1360. textBox_RunInfo_Trip_Time.Text = Convert.ToString(DataTemp) + " s";
  1361. //RSV1
  1362. DataTemp = (ushort)(Data[28]);
  1363. textBox_RunInfo_RSV1.Text = Convert.ToString(DataTemp);
  1364. //RSV2
  1365. DataTemp = (ushort)(Data[29]);
  1366. textBox_RunInfo_RSV2.Text = Convert.ToString(DataTemp);
  1367. //RSV3
  1368. DataTemp = (ushort)(Data[30]);
  1369. textBox_RunInfo_RSV3.Text = Convert.ToString(DataTemp);
  1370. //GearBox
  1371. DataTemp = (ushort)(Data[31]);
  1372. textBox_RunInfo_GearBox.Text = Convert.ToString(DataTemp);
  1373. //数据保存
  1374. RunInfoAutoSave();
  1375. }));
  1376. }
  1377. break;
  1378. }
  1379. case 0x1104://故障码
  1380. {
  1381. unchecked
  1382. {
  1383. this.Invoke((EventHandler)(delegate
  1384. {
  1385. MC_ErrorCode_Refresh = true;
  1386. textBox_ErrorCode.Text =
  1387. Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() +
  1388. Convert.ToString(Data[2], 16).PadLeft(2, '0').ToUpper() +
  1389. Convert.ToString(Data[1], 16).PadLeft(2, '0').ToUpper() +
  1390. Convert.ToString(Data[0], 16).PadLeft(2, '0').ToUpper() +
  1391. "H";
  1392. }));
  1393. }
  1394. break;
  1395. }
  1396. case 0xA903://反馈指令
  1397. {
  1398. unchecked
  1399. {
  1400. this.Invoke((EventHandler)(delegate
  1401. {
  1402. if (ACK_DisFlag == true)
  1403. {
  1404. MessageBoxTimeOut.Show("OK", "反馈指令", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  1405. //关机反馈
  1406. PowerOffAckStatus = true;
  1407. }
  1408. //应答标志置位
  1409. WriteACK = true;
  1410. }));
  1411. }
  1412. break;
  1413. }
  1414. case 0xB226://马达参数
  1415. {
  1416. unchecked
  1417. {
  1418. this.Invoke((EventHandler)(delegate
  1419. {
  1420. richTextBox_MotorParam.Clear();
  1421. for (int i = 0; i < myParams.MotorParam.Count; i++)
  1422. {
  1423. if (i == 6)
  1424. richTextBox_MotorParam.AppendText(myParams.MotorParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1425. else
  1426. richTextBox_MotorParam.AppendText(myParams.MotorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1427. }
  1428. richTextBox_MotorParam.Text = richTextBox_MotorParam.Text.Substring(0, richTextBox_MotorParam.Text.Length - 2);
  1429. }));
  1430. }
  1431. break;
  1432. }
  1433. case 0xB31A://整车信息
  1434. {
  1435. unchecked
  1436. {
  1437. this.Invoke((EventHandler)(delegate
  1438. {
  1439. richTextBox_BikeParam.Clear();
  1440. for (int i = 0; i < myParams.BikeParam.Count; i++)
  1441. {
  1442. if (i == 9)
  1443. richTextBox_BikeParam.AppendText(myParams.BikeParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1444. else
  1445. richTextBox_BikeParam.AppendText(myParams.BikeParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1446. //更新前后灯参数
  1447. if (i == 8)
  1448. {
  1449. comboBox_TailLightMode.SelectedIndex = ((Data[2 * i + 1] >> 4) & 0x0F) - 1;
  1450. comboBox_TailLightVol.SelectedIndex = ((Data[2 * i + 1] & 0x0F) == 6) ? 0 : 1;
  1451. comboBox_FrontLightVol.SelectedIndex = ((Data[2 * i] & 0x0F) == 6) ? 0 : 1;
  1452. }
  1453. //更新开关机参数
  1454. else if (i == 11)
  1455. {
  1456. textBox_PowerOnDelay.Text = Convert.ToString((Data[2 * i + 1] >> 4) & 0x0F);
  1457. textBox_PowerOffDelay.Text = Convert.ToString(Data[2 * i + 1] & 0x0F);
  1458. textBox_AutoPowerOff.Text = Convert.ToString(Data[2 * i]);
  1459. }
  1460. }
  1461. richTextBox_BikeParam.Text = richTextBox_BikeParam.Text.Substring(0, richTextBox_BikeParam.Text.Length - 2);
  1462. }));
  1463. }
  1464. break;
  1465. }
  1466. case 0xB420://控制器参数
  1467. {
  1468. unchecked
  1469. {
  1470. this.Invoke((EventHandler)(delegate
  1471. {
  1472. richTextBox_ControlParam.Clear();
  1473. for (int i = 0; i < myParams.ControlParam.Count; i++)
  1474. {
  1475. richTextBox_ControlParam.AppendText(myParams.ControlParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1476. //转把定速巡航
  1477. if (i == 13)
  1478. {
  1479. comboBox_Bike_CCS.SelectedIndex = ((Data[2 * i]) == 0xAA) ? 1 : 2;
  1480. }
  1481. }
  1482. richTextBox_ControlParam.Text = richTextBox_ControlParam.Text.Substring(0, richTextBox_ControlParam.Text.Length - 2);
  1483. }));
  1484. }
  1485. break;
  1486. }
  1487. case 0xB528://传感器参数
  1488. {
  1489. unchecked
  1490. {
  1491. this.Invoke((EventHandler)(delegate
  1492. {
  1493. richTextBox_SensorParam.Clear();
  1494. for (int i = 0; i < myParams.SensorParam.Count; i++)
  1495. {
  1496. richTextBox_SensorParam.AppendText(myParams.SensorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1497. }
  1498. richTextBox_SensorParam.Text = richTextBox_SensorParam.Text.Substring(0, richTextBox_SensorParam.Text.Length - 2);
  1499. //更新生产模式页面传感器零点和标定值
  1500. textBox_FacModeSensorADC0.Text = (Data[9] * 256 + Data[8]).ToString();
  1501. textBox_FacModeSensorADC1.Text = (Data[15] * 256 + Data[14]).ToString();
  1502. textBox_FacModeSensorADC2.Text = (Data[19] * 256 + Data[18]).ToString();
  1503. textBox_FacModeSensorADC3.Text = (Data[23] * 256 + Data[22]).ToString();
  1504. textBox_FacModeSensorADC4.Text = (Data[27] * 256 + Data[26]).ToString();
  1505. WriteACK = true;
  1506. }));
  1507. }
  1508. break;
  1509. }
  1510. case 0xB64C://助力参数
  1511. {
  1512. unchecked
  1513. {
  1514. this.Invoke((EventHandler)(delegate
  1515. {
  1516. richTextBox_AssistParam.Clear();
  1517. int index_1 = myParams.AssistParam.IndexOf("转矩曲线.a");
  1518. int index_2 = myParams.AssistParam.IndexOf("踏频曲线.d");
  1519. int index_3 = myParams.AssistParam.IndexOf("踏频助力加速限制");
  1520. int index_4 = myParams.AssistParam.IndexOf("踏频助力电流步进");
  1521. for (int i = 0; i < myParams.AssistParam.Count; i++)
  1522. {
  1523. if (i < index_1) //数据占用2bytes
  1524. {
  1525. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1526. }
  1527. else if (i <= index_2) //数据占用4bytes
  1528. {
  1529. 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])) + ", ");
  1530. }
  1531. else if (i < index_3) //数据占用2bytes,无符号
  1532. {
  1533. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1534. }
  1535. else if (i <= index_4) //数据占用2bytes,有符号
  1536. {
  1537. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1538. }
  1539. else //数据占用2bytes,无符号
  1540. {
  1541. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1542. }
  1543. }
  1544. richTextBox_AssistParam.Text = richTextBox_AssistParam.Text.Substring(0, richTextBox_AssistParam.Text.Length - 2);
  1545. }));
  1546. }
  1547. break;
  1548. }
  1549. case 0xB74C://历史记录
  1550. {
  1551. unchecked
  1552. {
  1553. this.Invoke((EventHandler)(delegate
  1554. {
  1555. richTextBox_Record.Clear();
  1556. for (int i = 0; i < myParams.Record.Count; i++)
  1557. {
  1558. richTextBox_Record.AppendText(myParams.Record[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  1559. }
  1560. richTextBox_Record.Text = richTextBox_Record.Text.Substring(0, richTextBox_Record.Text.Length - 2);
  1561. }));
  1562. }
  1563. break;
  1564. }
  1565. case 0xB83A://调试参数
  1566. {
  1567. unchecked
  1568. {
  1569. this.Invoke((EventHandler)(delegate
  1570. {
  1571. richTextBox_DebugParam.Clear();
  1572. for (int i = 0; i < myParams.DebugParam.Count; i++)
  1573. {
  1574. richTextBox_DebugParam.AppendText(myParams.DebugParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1575. }
  1576. richTextBox_DebugParam.Text = richTextBox_DebugParam.Text.Substring(0, richTextBox_DebugParam.Text.Length - 2);
  1577. }));
  1578. }
  1579. break;
  1580. }
  1581. case 0xB904://存储标志
  1582. {
  1583. unchecked
  1584. {
  1585. this.Invoke((EventHandler)(delegate
  1586. {
  1587. ushort Flag = 0;
  1588. Flag = (ushort)(Data[1] * 256 + Data[0]);//EEPROM存储标志
  1589. if (Flag == 0)
  1590. {
  1591. radioButton_EE_SaveNo.Checked = true;
  1592. radioButton_EE_SaveYes.Checked = false;
  1593. }
  1594. else
  1595. {
  1596. radioButton_EE_SaveNo.Checked = false;
  1597. radioButton_EE_SaveYes.Checked = true;
  1598. }
  1599. Flag = (ushort)(Data[3] * 256 + Data[2]);//SIP偏移校准存储标志
  1600. if (Flag == 0)
  1601. {
  1602. radioButton_SIP_SaveNo.Checked = true;
  1603. radioButton_SIP_SaveYes.Checked = false;
  1604. }
  1605. else
  1606. {
  1607. radioButton_SIP_SaveNo.Checked = false;
  1608. radioButton_SIP_SaveYes.Checked = true;
  1609. }
  1610. }));
  1611. }
  1612. break;
  1613. }
  1614. case 0x1240://电机版本信息
  1615. {
  1616. unchecked
  1617. {
  1618. this.Invoke((EventHandler)(delegate
  1619. {
  1620. //电机型号
  1621. textBox_Model.Text = "";
  1622. textBox_OBC_ReadModel.Text = "";
  1623. textBox_FacModeName.Text = "";
  1624. for (ushort i = 0; i < 16; i++)
  1625. {
  1626. if (Data[i] == 0x2E)
  1627. {
  1628. break;
  1629. }
  1630. textBox_Model.Text += ((char)Data[i]).ToString();
  1631. textBox_OBC_ReadModel.Text += ((char)Data[i]).ToString();
  1632. textBox_FacModeName.Text += ((char)Data[i]).ToString();
  1633. }
  1634. Class_Motor_Ver.Mode = textBox_Model.Text;
  1635. //电机SN
  1636. textBox_SN.Text = "";
  1637. textBox_OBC_ReadSN.Text = "";
  1638. textBox_FacModeNum.Text = "";
  1639. for (ushort i = 0; i < 16; i++)
  1640. {
  1641. if (Data[16 + i] == 0x2E)
  1642. {
  1643. break;
  1644. }
  1645. textBox_SN.Text += ((char)Data[16 + i]).ToString();
  1646. textBox_OBC_ReadSN.Text += ((char)Data[16 + i]).ToString();
  1647. textBox_FacModeNum.Text += ((char)Data[16 + i]).ToString();
  1648. }
  1649. Class_Motor_Ver.SN = textBox_SN.Text;
  1650. //电机HW
  1651. textBox_HW.Text = "";
  1652. textBox_OBC_ReadHW.Text = "";
  1653. textBox_FacModeHW.Text = "";
  1654. for (ushort i = 0; i < 8; i++)//前8位:硬件板号
  1655. {
  1656. if (Data[32 + i] == 0x2E)
  1657. {
  1658. break;
  1659. }
  1660. else if (Data[32 + i] == 'r')
  1661. {
  1662. Data[32 + i] = (byte)'.';
  1663. break;
  1664. }
  1665. string strTemp = "";
  1666. strTemp = ((char)Data[32 + i]).ToString();
  1667. textBox_HW.Text += strTemp;
  1668. textBox_OBC_ReadHW.Text += strTemp;
  1669. textBox_FacModeHW.Text += strTemp;
  1670. }
  1671. for (ushort i = 0; i < 4; i++)//9-12位:单片机型号
  1672. {
  1673. if (Data[40 + i] == 0x2E)
  1674. {
  1675. break;
  1676. }
  1677. else if (Data[40 + i] == 'r')
  1678. {
  1679. Data[40 + i] = (byte)'.';
  1680. break;
  1681. }
  1682. string strTemp = "";
  1683. strTemp = ((char)Data[40 + i]).ToString();
  1684. textBox_HW.Text += strTemp;
  1685. textBox_OBC_ReadHW.Text += strTemp;
  1686. textBox_FacModeHW.Text += strTemp;
  1687. }
  1688. for (ushort i = 0; i < 4; i++)//13-16位:单片机ID
  1689. {
  1690. string strTemp = "";
  1691. strTemp = Convert.ToString(Data[44 + i], 16).PadLeft(2, '0').ToUpper();
  1692. textBox_HW.Text += strTemp;
  1693. textBox_OBC_ReadHW.Text += strTemp;
  1694. textBox_FacModeHW.Text += strTemp;
  1695. }
  1696. Class_Motor_Ver.HW = textBox_HW.Text;
  1697. //电机FW
  1698. textBox_FW.Text = "";
  1699. textBox_OBC_ReadFW.Text = "";
  1700. textBox_FacModeFW.Text = "";
  1701. for (ushort i = 0; i < 16; i++)
  1702. {
  1703. if ((Data[48 + i] == 0x2E) || (Data[48 + i] == 0x00) || (Data[48 + i] == (char)' '))
  1704. {
  1705. break;
  1706. }
  1707. if (Data[48 + i] == 'r')
  1708. {
  1709. Data[48 + i] = (byte)'.';
  1710. }
  1711. textBox_FW.Text += ((char)Data[48 + i]).ToString();
  1712. textBox_OBC_ReadFW.Text += ((char)Data[48 + i]).ToString();
  1713. textBox_FacModeFW.Text += ((char)Data[48 + i]).ToString();
  1714. }
  1715. Class_Motor_Ver.FW = textBox_FW.Text;
  1716. }));
  1717. }
  1718. break;
  1719. }
  1720. case 0xA610://自定义1
  1721. {
  1722. unchecked
  1723. {
  1724. this.Invoke((EventHandler)(delegate
  1725. {
  1726. textBox_User1.Text = "";
  1727. for (ushort i = 0; i < 16; i++)
  1728. {
  1729. if (Data[i] == 0x2E)
  1730. {
  1731. break;
  1732. }
  1733. textBox_User1.Text += ((char)Data[i]).ToString();
  1734. }
  1735. }));
  1736. }
  1737. break;
  1738. }
  1739. case 0xA710://自定义2
  1740. {
  1741. unchecked
  1742. {
  1743. this.Invoke((EventHandler)(delegate
  1744. {
  1745. textBox_User2.Text = "";
  1746. for (ushort i = 0; i < 16; i++)
  1747. {
  1748. if (Data[i] == 0x2E)
  1749. {
  1750. break;
  1751. }
  1752. textBox_User2.Text += ((char)Data[i]).ToString();
  1753. }
  1754. }));
  1755. }
  1756. break;
  1757. }
  1758. case 0xA810://自定义1
  1759. {
  1760. unchecked
  1761. {
  1762. this.Invoke((EventHandler)(delegate
  1763. {
  1764. textBox_User3.Text = "";
  1765. for (ushort i = 0; i < 16; i++)
  1766. {
  1767. if (Data[i] == 0x2E)
  1768. {
  1769. break;
  1770. }
  1771. textBox_User3.Text += ((char)Data[i]).ToString();
  1772. }
  1773. }));
  1774. }
  1775. break;
  1776. }
  1777. case 0xA520://生产信息
  1778. {
  1779. unchecked
  1780. {
  1781. this.Invoke((EventHandler)(delegate
  1782. {
  1783. //生产商
  1784. textBox_MAC.Text = "";
  1785. for (ushort i = 0; i < 8; i++)
  1786. {
  1787. if (Data[i] == 0x2E)
  1788. {
  1789. break;
  1790. }
  1791. textBox_MAC.Text += ((char)Data[i]).ToString();
  1792. }
  1793. //生产地
  1794. textBox_MACAdd.Text = "";
  1795. for (ushort i = 0; i < 8; i++)
  1796. {
  1797. if (Data[8 + i] == 0x2E)
  1798. {
  1799. break;
  1800. }
  1801. textBox_MACAdd.Text += ((char)Data[8 + i]).ToString();
  1802. }
  1803. //生产日期
  1804. textBox_MACDate.Text = "";
  1805. for (ushort i = 0; i < 8; i++)
  1806. {
  1807. if (Data[16 + i] == 0x2E)
  1808. {
  1809. break;
  1810. }
  1811. textBox_MACDate.Text += ((char)Data[16 + i]).ToString();
  1812. }
  1813. //品牌信息
  1814. textBox_PP.Text = "";
  1815. for (ushort i = 0; i < 8; i++)
  1816. {
  1817. if (Data[24 + i] == 0x2E)
  1818. {
  1819. break;
  1820. }
  1821. textBox_PP.Text += ((char)Data[24 + i]).ToString();
  1822. }
  1823. }));
  1824. }
  1825. break;
  1826. }
  1827. case 0xA408://密钥
  1828. {
  1829. unchecked
  1830. {
  1831. this.Invoke((EventHandler)(delegate
  1832. {
  1833. textBox_Key.Text = "";
  1834. for (ushort i = 0; i < 8; i++)
  1835. {
  1836. textBox_Key.Text += ((char)Data[i]).ToString();
  1837. }
  1838. }));
  1839. }
  1840. break;
  1841. }
  1842. case 0xAB09://存储器数据
  1843. case 0xAB0A:
  1844. case 0xAB0B:
  1845. case 0xAB0C:
  1846. {
  1847. unchecked
  1848. {
  1849. this.Invoke((EventHandler)(delegate
  1850. {
  1851. long ByteNum = 0;
  1852. ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
  1853. if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
  1854. {
  1855. for (int i = 0; i < ByteNum; i++)
  1856. {
  1857. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  1858. }
  1859. }
  1860. else //根据设置自动转换10进制显示
  1861. {
  1862. if (checkBox_ReadRanFlash_ChangeFormat.Checked == true) //10进制显示
  1863. {
  1864. switch (ByteNum)
  1865. {
  1866. case 1:
  1867. {
  1868. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8]) + ", ");
  1869. break;
  1870. }
  1871. case 2:
  1872. {
  1873. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8)) + ", ");
  1874. break;
  1875. }
  1876. case 3:
  1877. {
  1878. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16)) + ", ");
  1879. break;
  1880. }
  1881. case 4:
  1882. {
  1883. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24)) + ", ");
  1884. break;
  1885. }
  1886. default:
  1887. {
  1888. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  1889. break;
  1890. }
  1891. }
  1892. }
  1893. else //16进制显示
  1894. {
  1895. switch (ByteNum)
  1896. {
  1897. case 1:
  1898. {
  1899. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8], 16).PadLeft(2, '0').ToUpper() + ", ");
  1900. break;
  1901. }
  1902. case 2:
  1903. {
  1904. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8), 16).PadLeft(4, '0').ToUpper() + ", ");
  1905. break;
  1906. }
  1907. case 3:
  1908. {
  1909. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16), 16).PadLeft(6, '0').ToUpper() + ", ");
  1910. break;
  1911. }
  1912. case 4:
  1913. {
  1914. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24), 16).PadLeft(8, '0').ToUpper() + ", ");
  1915. break;
  1916. }
  1917. default:
  1918. {
  1919. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  1920. break;
  1921. }
  1922. }
  1923. }
  1924. }
  1925. }));
  1926. }
  1927. break;
  1928. }
  1929. case 0xAB88://故障日志
  1930. {
  1931. unchecked
  1932. {
  1933. this.Invoke((EventHandler)(delegate
  1934. {
  1935. //电机存储的故障日志,一包128字节包含2条故障日志
  1936. var ErrorLogSaveInfo1 = new MC_ErrorLogSaveInfo_Struct_t();
  1937. var ErrorLogSaveInfo2 = new MC_ErrorLogSaveInfo_Struct_t();
  1938. ErrorLogSaveInfo1 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 8);
  1939. ErrorLogSaveInfo2 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 72);
  1940. //数据显示
  1941. ErrorLogDisplay(ErrorLogSaveInfo1, ErrorLogSaveInfo2);
  1942. }));
  1943. }
  1944. break;
  1945. }
  1946. case 0x1401://在线检测结果
  1947. {
  1948. unchecked
  1949. {
  1950. this.Invoke((EventHandler)(delegate
  1951. {
  1952. textBox_Online.Text = Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() + "H";
  1953. }));
  1954. }
  1955. break;
  1956. }
  1957. case 0x1510://骑行历史信息
  1958. {
  1959. unchecked
  1960. {
  1961. this.Invoke((EventHandler)(delegate
  1962. {
  1963. long DataTemp32;
  1964. //ODO里程
  1965. DataTemp32 = (long)((Data[3] << 24) + (Data[2] << 16) + (Data[1] << 8) + Data[0]);
  1966. textBox_OBC_ODO_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  1967. textBox_ODO_KM.Text = DataTemp32.ToString();
  1968. //ODO时间
  1969. DataTemp32 = (long)((Data[7] << 24) + (Data[6] << 16) + (Data[5] << 8) + Data[4]);
  1970. if (DataTemp32 >= 60 * 100000)
  1971. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  1972. else
  1973. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  1974. textBox_ODO_TIME.Text = DataTemp32.ToString();
  1975. //TRIP里程
  1976. DataTemp32 = (long)((Data[11] << 24) + (Data[10] << 16) + (Data[9] << 8) + Data[8]);
  1977. textBox_OBC_TRIP_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  1978. textBox_TRIP_KM.Text = DataTemp32.ToString();
  1979. //TRIP时间
  1980. DataTemp32 = (long)((Data[15] << 24) + (Data[14] << 16) + (Data[13] << 8) + Data[12]);
  1981. if (DataTemp32 >= 60 * 100000)
  1982. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  1983. else
  1984. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  1985. textBox_TRIP_TIME.Text = DataTemp32.ToString();
  1986. }));
  1987. }
  1988. break;
  1989. }
  1990. case 0x1720://客户信息
  1991. {
  1992. unchecked
  1993. {
  1994. this.Invoke((EventHandler)(delegate
  1995. {
  1996. //软件标识
  1997. textBox_SP.Text = "";
  1998. textBox_OBC_ReadSP.Text = "";
  1999. textBox_FacModeSP.Text = "";
  2000. for (ushort i = 0; i < 23; i++)
  2001. {
  2002. if (Data[i] == 'r')
  2003. {
  2004. Data[i] = (byte)'.';
  2005. }
  2006. textBox_SP.Text += ((char)Data[i]).ToString();
  2007. textBox_OBC_ReadSP.Text += ((char)Data[i]).ToString();
  2008. textBox_FacModeSP.Text += ((char)Data[i]).ToString();
  2009. }
  2010. //Git提交版本信息
  2011. textBox_FacModeGit.Text = "";
  2012. for (ushort i = 0; i < 9; i++)
  2013. {
  2014. textBox_SP.Text += ((char)Data[23 + i]).ToString();
  2015. textBox_FacModeGit.Text += ((char)Data[23 + i]).ToString();
  2016. }
  2017. Class_Motor_Ver.Special = textBox_SP.Text;
  2018. }));
  2019. }
  2020. break;
  2021. }
  2022. case 0xBA20: //调试信息
  2023. {
  2024. unchecked
  2025. {
  2026. this.Invoke((EventHandler)(delegate
  2027. {
  2028. MC_DebugInfo_Refresh = true;
  2029. //系统状态机
  2030. DataTemp = (short)(Data[0]);
  2031. textBox_DebugInfo_SysFun.Text = Convert.ToString(DataTemp);
  2032. //二层状态机
  2033. DataTemp = (short)(Data[1]);
  2034. textBox_DebugInfo_SecondFun.Text = Convert.ToString(DataTemp);
  2035. //电机状态机
  2036. DataTemp = (short)(Data[2]);
  2037. textBox_DebugInfo_MotorFun.Text = Convert.ToString(DataTemp);
  2038. //助力状态机
  2039. DataTemp = (short)(Data[3]);
  2040. textBox_DebugInfo_AssistFun.Text = Convert.ToString(DataTemp);
  2041. //IdRef
  2042. DataTemp = (short)(Data[5] * 256 + Data[4]);
  2043. textBox_DebugInfo_IdRef.Text = Convert.ToString(DataTemp);
  2044. //IqRef
  2045. DataTemp = (short)(Data[7] * 256 + Data[6]);
  2046. textBox_DebugInfo_IqRef.Text = Convert.ToString(DataTemp);
  2047. //UdRef
  2048. DataTemp = (short)(Data[9] * 256 + Data[8]);
  2049. textBox_DebugInfo_UdRef.Text = Convert.ToString(DataTemp);
  2050. //UqRef
  2051. DataTemp = (short)(Data[11] * 256 + Data[10]);
  2052. textBox_DebugInfo_UqRef.Text = Convert.ToString(DataTemp);
  2053. //瞬时力矩
  2054. DataTemp = (short)(Data[13] * 256 + Data[12]);
  2055. textBox_DebugInfo_TorquePu.Text = Convert.ToString(DataTemp);
  2056. //时间滤波力矩
  2057. DataTemp = (short)(Data[15] * 256 + Data[14]);
  2058. textBox_DebugInfo_TorqueFil.Text = Convert.ToString(DataTemp);
  2059. //踏频滤波力矩
  2060. DataTemp = (short)(Data[17] * 256 + Data[16]);
  2061. textBox_DebugInfo_TorqueCadence.Text = Convert.ToString(DataTemp);
  2062. //IdFdb
  2063. DataTemp = (short)(Data[19] * 256 + Data[18]);
  2064. textBox_DebugInfo_IdFdb.Text = Convert.ToString(DataTemp);
  2065. //IqFdb
  2066. DataTemp = (short)(Data[21] * 256 + Data[20]);
  2067. textBox_DebugInfo_IqFdb.Text = Convert.ToString(DataTemp);
  2068. //助力输出
  2069. DataTemp = (short)(Data[23] * 256 + Data[22]);
  2070. textBox_DebugInfo_AssistOut.Text = Convert.ToString(DataTemp);
  2071. //转把百分比
  2072. DataTemp = (short)(Data[25] * 256 + Data[24]);
  2073. textBox_DebugInfo_ThrottlePer.Text = Convert.ToString(DataTemp);
  2074. //数据保存
  2075. RunInfoAutoSave();
  2076. }));
  2077. }
  2078. break;
  2079. }
  2080. case 0xBB20: //产品标签信息
  2081. {
  2082. unchecked
  2083. {
  2084. this.Invoke((EventHandler)(delegate
  2085. {
  2086. //产品标签
  2087. textBox_TagInfo.Text = "";
  2088. for (ushort i = 0; i < 32; i++)
  2089. {
  2090. textBox_TagInfo.Text += ((char)Data[i]).ToString();
  2091. }
  2092. }));
  2093. }
  2094. break;
  2095. }
  2096. case 0xBC20: //内阻校正信息
  2097. {
  2098. unchecked
  2099. {
  2100. this.Invoke((EventHandler)(delegate
  2101. {
  2102. //内阻1
  2103. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  2104. textBox_MOS_R1.Text = Convert.ToString(uData16);
  2105. //内阻2
  2106. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  2107. textBox_MOS_R2.Text = Convert.ToString(uData16);
  2108. //内阻3
  2109. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  2110. textBox_MOS_R3.Text = Convert.ToString(uData16);
  2111. //K1
  2112. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  2113. textBox_MOS_K1.Text = Convert.ToString(uData16);
  2114. //K2
  2115. uData16 = (ushort)(Data[9] * 256 + Data[8]);
  2116. textBox_MOS_K2.Text = Convert.ToString(uData16);
  2117. //K3
  2118. uData16 = (ushort)(Data[11] * 256 + Data[10]);
  2119. textBox_MOS_K3.Text = Convert.ToString(uData16);
  2120. //K4
  2121. uData16 = (ushort)(Data[13] * 256 + Data[12]);
  2122. textBox_MOS_K4.Text = Convert.ToString(uData16);
  2123. //K5
  2124. uData16 = (ushort)(Data[15] * 256 + Data[14]);
  2125. textBox_MOS_K5.Text = Convert.ToString(uData16);
  2126. }));
  2127. }
  2128. break;
  2129. }
  2130. case 0xBD20: //整车信息2
  2131. {
  2132. unchecked
  2133. {
  2134. this.Invoke((EventHandler)(delegate
  2135. {
  2136. richTextBox_BikeParam2.Clear();
  2137. for (int i = 0; i < myParams.BikeParam2.Count; i++)
  2138. {
  2139. richTextBox_BikeParam2.AppendText(myParams.BikeParam2[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  2140. }
  2141. richTextBox_BikeParam2.Text = richTextBox_BikeParam2.Text.Substring(0, richTextBox_BikeParam2.Text.Length - 2);
  2142. }));
  2143. }
  2144. break;
  2145. }
  2146. case 0xBE20: //用户骑行参数
  2147. {
  2148. unchecked
  2149. {
  2150. this.Invoke((EventHandler)(delegate
  2151. {
  2152. richTextBox_UsrRidesParam.Clear();
  2153. for (int i = 0; i < myParams.UsrRideParam.Count; i++)
  2154. {
  2155. richTextBox_UsrRidesParam.AppendText(myParams.UsrRideParam[i] + "=" + Convert.ToString(Data[i]) + ", ");
  2156. }
  2157. richTextBox_UsrRidesParam.Text = richTextBox_UsrRidesParam.Text.Substring(0, richTextBox_UsrRidesParam.Text.Length - 2);
  2158. }));
  2159. }
  2160. break;
  2161. }
  2162. case 0xBF58: //位置传感器校准值
  2163. {
  2164. unchecked
  2165. {
  2166. this.Invoke((EventHandler)(delegate
  2167. {
  2168. string[] str1 = new string[42];
  2169. double[] error1 = new double[42];
  2170. //更新校准数据
  2171. for (int i = 0; i < 42; i++)
  2172. {
  2173. double data1 = (Data[4 + i * 2] + (Data[4 + i * 2 + 1] << 8)) / 32767.0 * 360;
  2174. error1[i] = data1 - (60 * (i % 6) + 60);
  2175. if (error1[i] < -180)
  2176. {
  2177. error1[i] = error1[i] + 360;
  2178. }
  2179. str1[i] = data1.ToString("F2");
  2180. AngledataRecord[i] = str1[i];
  2181. }
  2182. for (int i = 0; i < 7; i++)
  2183. for (int j = 0; j < 6; j++)
  2184. {
  2185. dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = str1[6 * i + j];
  2186. }
  2187. //计算偏差最小值、最大值和平均值
  2188. //Array.ConvertAll(error1, Math.Abs);
  2189. textBox_AngleDiffMin.Text = error1.Min().ToString("F2");
  2190. textBox_AngleDiffMax.Text = error1.Max().ToString("F2");
  2191. textBox_AngleDiffAvg.Text = error1.Average().ToString("F2");
  2192. //计算零点偏差
  2193. double tmp1 = ((Int16)(Data[0] + (Data[1] << 8))) / 32767.0 * 360;
  2194. textBox_AngleZeroInit.Text = tmp1.ToString("F2");
  2195. double tmp2 = ((Int16)(Data[2] + (Data[3] << 8))) / 32767.0 * 360;
  2196. textBox_AngleZeroCur.Text = tmp2.ToString("F2");
  2197. double tmp3 = (tmp2 - tmp1);
  2198. textBox_AngleZeroDiff.Text = tmp3.ToString("F2");
  2199. }));
  2200. }
  2201. break;
  2202. }
  2203. case 0xC008: //故障日志地址
  2204. {
  2205. unchecked
  2206. {
  2207. this.Invoke((EventHandler)(delegate
  2208. {
  2209. uint Addr_Begin = 0, Addr_End = 0;
  2210. Addr_Begin = (uint)((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]);
  2211. Addr_End = (uint)((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]);
  2212. textBox_LogAddrBegin.Text = Convert.ToString(Addr_Begin, 16).PadLeft(8, '0').ToUpper();
  2213. textBox_LogAddrEnd.Text = Convert.ToString(Addr_End, 16).PadLeft(8, '0').ToUpper();
  2214. }));
  2215. }
  2216. break;
  2217. }
  2218. case 0xC109: //Boot版本信息
  2219. {
  2220. BootInfo = "";
  2221. for (ushort i = 0; i < 9; i++)
  2222. {
  2223. BootInfo += ((char)Data[i]).ToString();
  2224. }
  2225. break;
  2226. }
  2227. case 0xC142: //功能配置表
  2228. {
  2229. unchecked
  2230. {
  2231. this.Invoke((EventHandler)(delegate
  2232. {
  2233. //块编号
  2234. ushort Num = (ushort)(Data[1] * 256 + Data[0]);
  2235. comboBox_FunSet_BlockNum.SelectedIndex = Num - 1;
  2236. //显示数据
  2237. for (int i = 0; i < 64; i++)
  2238. {
  2239. dataGridView_FunSet.Rows[i / 8].Cells[i % 8 + 1].Value = Data[i + 2].ToString();
  2240. }
  2241. }));
  2242. }
  2243. break;
  2244. }
  2245. case 0xC220: //定制编号
  2246. {
  2247. unchecked
  2248. {
  2249. this.Invoke((EventHandler)(delegate
  2250. {
  2251. //定制编号
  2252. textBox_UserNum.Text = "";
  2253. for (ushort i = 0; i < 32; i++)
  2254. {
  2255. textBox_UserNum.Text += ((char)Data[i]).ToString();
  2256. }
  2257. }));
  2258. }
  2259. break;
  2260. }
  2261. default:
  2262. {
  2263. break;
  2264. }
  2265. }
  2266. //存储器导出数据显示
  2267. if ((CmdTemp & 0xFF00) == 0xAB00)
  2268. {
  2269. unchecked
  2270. {
  2271. this.Invoke((EventHandler)(delegate
  2272. {
  2273. long ByteNum = 0;
  2274. ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
  2275. if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
  2276. {
  2277. for (int i = 0; i < ByteNum; i++)
  2278. {
  2279. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  2280. }
  2281. }
  2282. }));
  2283. }
  2284. }
  2285. }
  2286. #endregion
  2287. #region 解析BMS广播的命令
  2288. else if (ID == 0x720)
  2289. {
  2290. switch (CmdTemp)
  2291. {
  2292. case 0x1010://BMS运行信息
  2293. {
  2294. unchecked
  2295. {
  2296. this.Invoke((EventHandler)(delegate
  2297. {
  2298. BMS_RunInfo_Refresh = true;
  2299. richTextBox_OBC_BMS_RunInfo.Clear();
  2300. //电压
  2301. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  2302. richTextBox_OBC_BMS_RunInfo.AppendText("电压:" + Convert.ToString(uData16) + " mV" + "\r\n");
  2303. //电流
  2304. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  2305. richTextBox_OBC_BMS_RunInfo.AppendText("电流:" + Convert.ToString(uData16) + " mA" + "\r\n");
  2306. //剩余容量
  2307. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  2308. richTextBox_OBC_BMS_RunInfo.AppendText("剩余容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  2309. //满充容量
  2310. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  2311. richTextBox_OBC_BMS_RunInfo.AppendText("满充容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  2312. //电芯温度
  2313. richTextBox_OBC_BMS_RunInfo.AppendText("电芯温度:" + Convert.ToString((int)(Data[8] - 40) + " ℃" + "\r\n"));
  2314. //剩余电量
  2315. richTextBox_OBC_BMS_RunInfo.AppendText("剩余电量:" + Convert.ToString(Data[9]) + " %" + "\r\n");
  2316. //电池状态
  2317. richTextBox_OBC_BMS_RunInfo.AppendText("电池状态:" + Convert.ToString(Data[10], 16).PadLeft(2, '0').ToUpper() + " H" + "\r\n");
  2318. //SOH
  2319. richTextBox_OBC_BMS_RunInfo.AppendText("电池寿命:" + Convert.ToString(Data[11]) + " %" + "\r\n");
  2320. //循环次数
  2321. richTextBox_OBC_BMS_RunInfo.AppendText("循环次数:" + Convert.ToString((ushort)(Data[13] * 256 + Data[12])) + " 次");
  2322. }));
  2323. }
  2324. break;
  2325. }
  2326. default: break;
  2327. }
  2328. }
  2329. #endregion
  2330. #region 解析电机发送OBC的命令
  2331. else if (ID == 0x713)
  2332. {
  2333. switch (CmdTemp)
  2334. {
  2335. case 0x5408://电机用户参数
  2336. {
  2337. unchecked
  2338. {
  2339. this.Invoke((EventHandler)(delegate
  2340. {
  2341. richTextBox_OBC_ReadUserInfo.Clear();
  2342. //默认周长
  2343. richTextBox_OBC_ReadUserInfo.AppendText("默认周长:" + Convert.ToString((int)Data[0]) + " cm" + "\r\n");
  2344. //启动模式
  2345. richTextBox_OBC_ReadUserInfo.AppendText("启动模式:" + ((Data[1] == 0x01) ? "柔和" : (Data[1] == 0x02) ? "正常" : (Data[1] == 0x03) ? "强劲" : "无效") + "\r\n");
  2346. comboBox_OBC_StartMode.SelectedIndex = Data[1] - 1;
  2347. //限速
  2348. richTextBox_OBC_ReadUserInfo.AppendText("限速:" + Convert.ToString(Data[2]) + " km/h" + "\r\n");
  2349. //周长微调
  2350. numericUpDown_OBC_WheelAdj.Value = (int)(Data[3] > 128 ? (Data[3] - 256) : Data[3]);
  2351. richTextBox_OBC_ReadUserInfo.AppendText("周长微调:" + Convert.ToString(numericUpDown_OBC_WheelAdj.Value) + " cm" + "\r\n");
  2352. //助力方案
  2353. richTextBox_OBC_ReadUserInfo.AppendText("助力方案:" + Convert.ToString(Data[4]) + "\r\n");
  2354. comboBox_OBC_AssistFunc.SelectedIndex = Data[4] - 1;
  2355. //关机时间
  2356. richTextBox_OBC_ReadUserInfo.AppendText("关机时间:" + Convert.ToString(Data[5]) + " min" + "\r\n");
  2357. numericUpDown_OBC_OffTime.Value = (int)Data[5];
  2358. //限速微调
  2359. numericUpDown_OBC_SpeedLimitAdj.Value = (int)(Data[6] > 128 ? (Data[6] - 256) : Data[6]);
  2360. richTextBox_OBC_ReadUserInfo.AppendText("限速微调:" + Convert.ToString(numericUpDown_OBC_SpeedLimitAdj.Value) + " km/h" + "\r\n");
  2361. //定速巡航
  2362. comboBox_OBC_BikeCCS.SelectedIndex = (Data[7] == 0xAA) ? 1 : 2;
  2363. richTextBox_OBC_ReadUserInfo.AppendText("转把巡航:" + comboBox_OBC_BikeCCS.Text + "\r\n");
  2364. }));
  2365. }
  2366. break;
  2367. }
  2368. case 0x5303://电机应答反馈
  2369. {
  2370. unchecked
  2371. {
  2372. this.Invoke((EventHandler)(delegate
  2373. {
  2374. MessageBoxTimeOut.Show("OK", "反馈指令", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  2375. }));
  2376. }
  2377. break;
  2378. }
  2379. case 0x5620: //用户骑行参数
  2380. {
  2381. unchecked
  2382. {
  2383. this.Invoke((EventHandler)(delegate
  2384. {
  2385. richTextBox_UsrRidesParam.Clear();
  2386. for (int i = 0; i < myParams.UsrRideParam.Count; i++)
  2387. {
  2388. richTextBox_UsrRidesParam.AppendText(myParams.UsrRideParam[i] + "=" + Convert.ToString(Data[i]) + ", ");
  2389. }
  2390. richTextBox_UsrRidesParam.Text = richTextBox_UsrRidesParam.Text.Substring(0, richTextBox_UsrRidesParam.Text.Length - 2);
  2391. }));
  2392. }
  2393. break;
  2394. }
  2395. default: break;
  2396. }
  2397. }
  2398. #endregion
  2399. }
  2400. private void DataRevToString(ushort CmdTemp, byte[] Data)
  2401. {
  2402. CmdRevStrTemp = "";
  2403. CmdRevStrTemp += Convert.ToString(CmdTemp >> 8, 16).PadLeft(2, '0').ToUpper() + " ";
  2404. CmdRevStrTemp += Convert.ToString(CmdTemp & 0xFF, 16).PadLeft(2, '0').ToUpper() + " ";
  2405. ushort len = (ushort)(CmdTemp & 0x00FF);
  2406. for (int i = 0; i < len ; i++)
  2407. {
  2408. CmdRevStrTemp += Convert.ToString(Data[i], 16).PadLeft(2, '0').ToUpper() + " ";
  2409. }
  2410. }
  2411. #endregion
  2412. /// <summary>
  2413. /// 端口连接或断开
  2414. /// </summary>
  2415. private void PortConnect()
  2416. {
  2417. bool result = false;
  2418. if (连接ToolStripMenuItem.Text == "连接")
  2419. {
  2420. result = mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, 连接开机ToolStripMenuItem.Checked, 识别通讯盒ToolStripMenuItem.Checked);
  2421. if (result)
  2422. {
  2423. toolStripComboBox_ComNum.Enabled = false;
  2424. toolStripComboBox_Baudrate.Enabled = false;
  2425. 刷新ToolStripMenuItem.Enabled = false;
  2426. 连接ToolStripMenuItem.Text = "断开";
  2427. 连接ToolStripMenuItem.Checked = true;
  2428. label_COM_Sta.Text = toolStripComboBox_ComNum.Text + "已连接," + toolStripComboBox_Baudrate.Text;
  2429. label_PortStatus.BackColor = Color.Green;
  2430. }
  2431. }
  2432. else if (连接ToolStripMenuItem.Text == "断开")
  2433. {
  2434. checkBox_OBC_StartSetGearSt.Checked = false;
  2435. checkBox_OBC_StartReadBMS.Checked = false;
  2436. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2437. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  2438. toolStripComboBox_ComNum.Enabled = true;
  2439. toolStripComboBox_Baudrate.Enabled = true;
  2440. 刷新ToolStripMenuItem.Enabled = true;
  2441. 连接ToolStripMenuItem.Text = "连接";
  2442. 连接ToolStripMenuItem.Checked = false;
  2443. label_COM_Sta.Text = "连接状态:未连接";
  2444. label_PortStatus.BackColor = Color.Red;
  2445. }
  2446. }
  2447. /// <summary>
  2448. /// 端口连接事件
  2449. /// </summary>
  2450. /// <param name="sender"></param>
  2451. /// <param name="e"></param>
  2452. private void 连接ToolStripMenuItem_Click(object sender, System.EventArgs e)
  2453. {
  2454. PortConnect();
  2455. }
  2456. /// <summary>
  2457. /// 端口号刷新事件
  2458. /// </summary>
  2459. /// <param name="sender"></param>
  2460. /// <param name="e"></param>
  2461. private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
  2462. {
  2463. toolStripComboBox_ComNum.Items.Clear();
  2464. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  2465. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
  2466. }
  2467. /// <summary>
  2468. /// 存储标志修改事件
  2469. /// </summary>
  2470. /// <param name="sender"></param>
  2471. /// <param name="e"></param>
  2472. private void 写入存储ToolStripMenuItem_Click(object sender, EventArgs e)
  2473. {
  2474. if (写入存储ToolStripMenuItem.Checked)
  2475. {
  2476. EnterForm1.ShowDialog();
  2477. try
  2478. {
  2479. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  2480. {
  2481. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  2482. {
  2483. 写入存储ToolStripMenuItem.Checked = false;
  2484. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  2485. }
  2486. else
  2487. {
  2488. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2489. }
  2490. }
  2491. else
  2492. {
  2493. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2494. }
  2495. }
  2496. catch (Exception)
  2497. {
  2498. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2499. }
  2500. }
  2501. else
  2502. {
  2503. 写入存储ToolStripMenuItem.Checked = true;
  2504. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  2505. }
  2506. }
  2507. /// <summary>
  2508. /// 1s定时器
  2509. /// </summary>
  2510. /// <param name="sender"></param>
  2511. /// <param name="e"></param>
  2512. private void timer_1s_Tick(object sender, EventArgs e)
  2513. {
  2514. //时间更新
  2515. label_SystemTime.Text = "系统时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2516. //MC_Runinfo超时清除
  2517. if (MC_RunInfo_Refresh == false)
  2518. {
  2519. MC_RunInfo_Refresh_Cnt++;
  2520. if (MC_RunInfo_Refresh_Cnt > 10)//5s
  2521. {
  2522. MC_RunInfo_Clear();
  2523. MC_RunInfo_Refresh_Cnt = 0;
  2524. }
  2525. }
  2526. else
  2527. {
  2528. MC_RunInfo_Refresh_Cnt = 0;
  2529. }
  2530. MC_RunInfo_Refresh = false;
  2531. //MC_Debuginfo超时清除
  2532. if (MC_DebugInfo_Refresh == false)
  2533. {
  2534. MC_DebugInfo_Refresh_Cnt++;
  2535. if (MC_DebugInfo_Refresh_Cnt > 10)//5s
  2536. {
  2537. MC_DebugInfo_Clear();
  2538. MC_DebugInfo_Refresh_Cnt = 0;
  2539. }
  2540. }
  2541. else
  2542. {
  2543. MC_DebugInfo_Refresh_Cnt = 0;
  2544. }
  2545. MC_DebugInfo_Refresh = false;
  2546. //BMS_RunInfo超时清除
  2547. if (BMS_RunInfo_Refresh == false)
  2548. {
  2549. BMS_RunInfo_Refresh_Cnt++;
  2550. if (BMS_RunInfo_Refresh_Cnt > 10)//5s
  2551. {
  2552. richTextBox_OBC_BMS_RunInfo.Clear();
  2553. BMS_RunInfo_Refresh_Cnt = 0;
  2554. }
  2555. }
  2556. else
  2557. {
  2558. BMS_RunInfo_Refresh_Cnt = 0;
  2559. }
  2560. BMS_RunInfo_Refresh = false;
  2561. //故障码超时清除
  2562. if (MC_ErrorCode_Refresh == false)
  2563. {
  2564. MC_ErrorCode_Refresh_Cnt++;
  2565. if (MC_ErrorCode_Refresh_Cnt > 10)//5s
  2566. {
  2567. textBox_ErrorCode.Text = "---";
  2568. MC_ErrorCode_Refresh_Cnt = 0;
  2569. }
  2570. }
  2571. else
  2572. {
  2573. MC_ErrorCode_Refresh_Cnt = 0;
  2574. }
  2575. MC_ErrorCode_Refresh = false;
  2576. //CDL连接超时
  2577. if (识别通讯盒ToolStripMenuItem.Checked)
  2578. {
  2579. if (mySerialProcess.CDL_Online_Flag == false)
  2580. {
  2581. mySerialProcess.CDL_OnlineCheck_Cnt++;
  2582. if (mySerialProcess.CDL_OnlineCheck_Cnt > 1)//1s
  2583. {
  2584. timer_500ms.Enabled = false;
  2585. MessageBox.Show("连接失败!", "提示");
  2586. timer_500ms.Enabled = true;
  2587. //关闭串口
  2588. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  2589. toolStripComboBox_ComNum.Enabled = true;
  2590. toolStripComboBox_Baudrate.Enabled = true;
  2591. 刷新ToolStripMenuItem.Enabled = true;
  2592. 连接ToolStripMenuItem.Text = "连接";
  2593. 连接ToolStripMenuItem.Checked = false;
  2594. label_COM_Sta.Text = "连接状态:未连接";
  2595. label_PortStatus.BackColor = Color.Red;
  2596. }
  2597. }
  2598. }
  2599. //OBC定时发送设置档位
  2600. if (checkBox_OBC_StartSetGearSt.Checked == true)
  2601. {
  2602. var CtrlCode = new byte[2];
  2603. if (comboBox_OBC_SetGearST.SelectedIndex == 5)//档位
  2604. CtrlCode[0] = 0x33;
  2605. else if (comboBox_OBC_SetGearST.SelectedIndex == 6)//档位
  2606. CtrlCode[0] = 0x22;
  2607. else
  2608. CtrlCode[0] = (byte)comboBox_OBC_SetGearST.SelectedIndex;
  2609. if (comboBox_OBC_LightSw.SelectedIndex == 0)//车灯
  2610. CtrlCode[1] = 0xF1;
  2611. else
  2612. CtrlCode[1] = 0xF0;
  2613. if (!mySerialProcess.SendCmdWithoutNotice((ushort)0x731, (byte)0x0C, (ushort)0x3002, CtrlCode))
  2614. {
  2615. checkBox_OBC_StartSetGearSt.Checked = false;
  2616. }
  2617. }
  2618. //OBC定时发送查询电池
  2619. if (checkBox_OBC_StartReadBMS.Checked == true)
  2620. {
  2621. if (!mySerialProcess.SendCmd((ushort)0x732, (byte)0x11, (ushort)0x5000, null))
  2622. {
  2623. checkBox_OBC_StartReadBMS.Checked = false;
  2624. }
  2625. }
  2626. //定时读取存储器
  2627. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  2628. {
  2629. var Address = new byte[4];
  2630. UInt32 Address_Begin;
  2631. UInt32 Addres_End;
  2632. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  2633. richTextBox_RamFlasgData.Clear();
  2634. do
  2635. {
  2636. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  2637. {
  2638. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2639. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2640. continue;
  2641. }
  2642. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  2643. {
  2644. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2645. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2646. continue;
  2647. }
  2648. else
  2649. {
  2650. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  2651. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2652. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  2653. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2654. if (Addres_End < Address_Begin)
  2655. {
  2656. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2657. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2658. continue;
  2659. }
  2660. else
  2661. {
  2662. var SendByte = new byte[8];
  2663. SendByte[0] = (byte)(Address_Begin >> 24);
  2664. SendByte[1] = (byte)(Address_Begin >> 16);
  2665. SendByte[2] = (byte)(Address_Begin >> 8);
  2666. SendByte[3] = (byte)(Address_Begin);
  2667. SendByte[4] = (byte)(Addres_End >> 24);
  2668. SendByte[5] = (byte)(Addres_End >> 16);
  2669. SendByte[6] = (byte)(Addres_End >> 8);
  2670. SendByte[7] = (byte)(Addres_End);
  2671. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte))
  2672. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2673. }
  2674. }
  2675. } while (false);
  2676. }
  2677. //写入参数等待计时
  2678. ACK_WaitCnt++;
  2679. }
  2680. /// <summary>
  2681. /// 运行信息清除
  2682. /// </summary>
  2683. private void MC_RunInfo_Clear()
  2684. {
  2685. foreach (Control c in tabPage_RunInfo.Controls)
  2686. {
  2687. if ((c is TextBox))
  2688. {
  2689. if (c.Name != textBox_ErrorCode.ToString())
  2690. c.Text = "---";
  2691. }
  2692. }
  2693. }
  2694. /// <summary>
  2695. /// 调试信息清除
  2696. /// </summary>
  2697. private void MC_DebugInfo_Clear()
  2698. {
  2699. foreach (Control c in tabPage_DebugInfo.Controls)
  2700. {
  2701. if ((c is TextBox))
  2702. {
  2703. if (c.Name != textBox_ErrorCode.ToString())
  2704. c.Text = "---";
  2705. }
  2706. }
  2707. }
  2708. /// <summary>
  2709. /// 读取马达参数
  2710. /// </summary>
  2711. /// <param name="sender"></param>
  2712. /// <param name="e"></param>
  2713. private void button_Read_MotorParam_Click(object sender, EventArgs e)
  2714. {
  2715. richTextBox_MotorParam.Clear();
  2716. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null);
  2717. }
  2718. /// <summary>
  2719. /// 写入马达参数
  2720. /// </summary>
  2721. /// <param name="sender"></param>
  2722. /// <param name="e"></param>
  2723. private void button_Write_Click(object sender, EventArgs e)
  2724. {
  2725. var ConfigParam = new byte[40];
  2726. for (int i = 0; i < 40; i++)
  2727. ConfigParam[i] = 0;
  2728. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2729. short wDataTemp = 0;
  2730. ushort DataTemp = 0;
  2731. string[] strDataTemp = richTextBox_MotorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2732. try
  2733. {
  2734. for (int i = 0; i < strDataTemp.Length; i++)
  2735. {
  2736. if (i == 6)
  2737. {
  2738. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  2739. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  2740. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  2741. }
  2742. else
  2743. {
  2744. DataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2745. ConfigParam[2 * i + 2] = (byte)DataTemp;
  2746. ConfigParam[2 * i + 3] = (byte)(DataTemp >> 8);
  2747. }
  2748. }
  2749. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B28, ConfigParam);
  2750. }
  2751. catch (Exception)
  2752. {
  2753. timer_500ms.Enabled = false;
  2754. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2755. timer_500ms.Enabled = true;
  2756. }
  2757. }
  2758. /// <summary>
  2759. /// 读取整车信息
  2760. /// </summary>
  2761. /// <param name="sender"></param>
  2762. /// <param name="e"></param>
  2763. private void button_ReadBikeParam_Click(object sender, EventArgs e)
  2764. {
  2765. richTextBox_BikeParam.Clear();
  2766. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null);
  2767. }
  2768. /// <summary>
  2769. /// 写入整车信息
  2770. /// </summary>
  2771. /// <param name="sender"></param>
  2772. /// <param name="e"></param>
  2773. private void button_WriteBikeParam_Click(object sender, EventArgs e)
  2774. {
  2775. var ConfigParam = new byte[28];
  2776. for (int i = 0; i < 28; i++)
  2777. ConfigParam[i] = 0;
  2778. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2779. string[] strDataTemp = richTextBox_BikeParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2780. try
  2781. {
  2782. for (int i = 0; i < strDataTemp.Length; i++)
  2783. {
  2784. short wDataTemp = 0;
  2785. //前后灯参数修改
  2786. if (i == 8)
  2787. {
  2788. wDataTemp |= (short)((comboBox_TailLightMode.SelectedIndex + 1) << 12); //Bit15~Bit12:尾灯模式
  2789. wDataTemp |= (short)((comboBox_TailLightVol.SelectedIndex == 0 ? 6 : 12) << 8); //Bit11~Bit8:尾灯电压
  2790. wDataTemp |= (short)(comboBox_FrontLightVol.SelectedIndex == 0 ? 6 : 12); //Bit7~Bit0:前灯电压
  2791. }
  2792. //开关机参数
  2793. else if (i == 11)
  2794. {
  2795. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOnDelay.Text) << 12);
  2796. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOffDelay.Text) << 8);
  2797. wDataTemp |= (short)(Convert.ToInt16(textBox_AutoPowerOff.Text));
  2798. }
  2799. else
  2800. {
  2801. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  2802. }
  2803. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  2804. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  2805. }
  2806. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D1C, ConfigParam);
  2807. }
  2808. catch (Exception)
  2809. {
  2810. timer_500ms.Enabled = false;
  2811. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2812. timer_500ms.Enabled = true;
  2813. }
  2814. }
  2815. /// <summary>
  2816. /// 读取控制器参数
  2817. /// </summary>
  2818. /// <param name="sender"></param>
  2819. /// <param name="e"></param>
  2820. private void button_ReadControlParam_Click(object sender, EventArgs e)
  2821. {
  2822. richTextBox_ControlParam.Clear();
  2823. comboBox_Bike_CCS.SelectedIndex = 0;
  2824. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
  2825. }
  2826. /// <summary>
  2827. /// 写入控制器参数
  2828. /// </summary>
  2829. /// <param name="sender"></param>
  2830. /// <param name="e"></param>
  2831. private void button_WriteControlParam_Click(object sender, EventArgs e)
  2832. {
  2833. var ConfigParam = new byte[34];
  2834. for (int i = 0; i < 34; i++)
  2835. ConfigParam[i] = 0;
  2836. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2837. ushort uwDataTemp = 0;
  2838. string[] strDataTemp = richTextBox_ControlParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2839. try
  2840. {
  2841. for (int i = 0; i < strDataTemp.Length; i++)
  2842. {
  2843. if (i == 13)
  2844. {
  2845. uwDataTemp = (comboBox_Bike_CCS.SelectedIndex == 1) ? (ushort)0x00AA : (ushort)0x0000;
  2846. }
  2847. else
  2848. {
  2849. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2850. }
  2851. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2852. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2853. }
  2854. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3F22, ConfigParam);
  2855. }
  2856. catch (Exception)
  2857. {
  2858. timer_500ms.Enabled = false;
  2859. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2860. timer_500ms.Enabled = true;
  2861. }
  2862. }
  2863. /// <summary>
  2864. /// 读取助力参数
  2865. /// </summary>
  2866. /// <param name="sender"></param>
  2867. /// <param name="e"></param>
  2868. private void button_ReadAssistParam_Click(object sender, EventArgs e)
  2869. {
  2870. var ConfigParam = new byte[4];
  2871. int AssistNum = 0;
  2872. try
  2873. {
  2874. AssistNum = Convert.ToInt32(comboBox_AssistTorque.Text);
  2875. ConfigParam[0] = (byte)(AssistNum & 0xFF);
  2876. ConfigParam[1] = (byte)(AssistNum >> 8);
  2877. AssistNum = Convert.ToInt32(comboBox_AssistCadence.Text);
  2878. ConfigParam[2] = (byte)(AssistNum & 0xFF);
  2879. ConfigParam[3] = (byte)(AssistNum >> 8);
  2880. richTextBox_AssistParam.Clear();
  2881. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam);
  2882. }
  2883. catch (Exception)
  2884. {
  2885. timer_500ms.Enabled = false;
  2886. MessageBox.Show("请选择助力参数编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2887. timer_500ms.Enabled = true;
  2888. }
  2889. }
  2890. /// <summary>
  2891. /// 写入助力参数
  2892. /// </summary>
  2893. /// <param name="sender"></param>
  2894. /// <param name="e"></param>
  2895. private void button_WriteAssistParam_Click(object sender, EventArgs e)
  2896. {
  2897. var ConfigParam = new byte[80];
  2898. for (int i = 0; i < 80; i++)
  2899. ConfigParam[i] = 0;
  2900. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2901. long lDataTemp = 0;
  2902. string[] strDataTemp = richTextBox_AssistParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2903. int index_1 = 0, index_2 = 0;
  2904. try
  2905. {
  2906. for (int i = 0; i < strDataTemp.Length; i++)
  2907. {
  2908. if (strDataTemp[i].Split('=')[0] == "转矩曲线.a")
  2909. {
  2910. index_1 = i;
  2911. break;
  2912. }
  2913. }
  2914. for (int i = 0; i < strDataTemp.Length; i++)
  2915. {
  2916. if (strDataTemp[i].Split('=')[0] == "踏频曲线.d")
  2917. {
  2918. index_2 = i;
  2919. break;
  2920. }
  2921. }
  2922. for (int i = 0; i < strDataTemp.Length; i++)
  2923. {
  2924. lDataTemp = Convert.ToInt32(strDataTemp[i].Split('=')[1]);
  2925. if (i < index_1)
  2926. {
  2927. ConfigParam[2 * i + 4] = (byte)lDataTemp;
  2928. ConfigParam[2 * i + 5] = (byte)(lDataTemp >> 8);
  2929. }
  2930. else if (i <= index_2)
  2931. {
  2932. ConfigParam[4 * i - 4] = (byte)lDataTemp;
  2933. ConfigParam[4 * i - 3] = (byte)(lDataTemp >> 8);
  2934. ConfigParam[4 * i - 2] = (byte)(lDataTemp >> 16);
  2935. ConfigParam[4 * i - 1] = (byte)(lDataTemp >> 24);
  2936. }
  2937. else
  2938. {
  2939. ConfigParam[2 * i + 20] = (byte)lDataTemp;
  2940. ConfigParam[2 * i + 21] = (byte)(lDataTemp >> 8);
  2941. }
  2942. }
  2943. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4450, ConfigParam);
  2944. }
  2945. catch (Exception)
  2946. {
  2947. timer_500ms.Enabled = false;
  2948. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2949. timer_500ms.Enabled = true;
  2950. }
  2951. }
  2952. /// <summary>
  2953. /// 读取调试参数
  2954. /// </summary>
  2955. /// <param name="sender"></param>
  2956. /// <param name="e"></param>
  2957. private void button_ReadDebugParam_Click(object sender, EventArgs e)
  2958. {
  2959. richTextBox_DebugParam.Clear();
  2960. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  2961. }
  2962. /// <summary>
  2963. /// 写入调试参数
  2964. /// </summary>
  2965. /// <param name="sender"></param>
  2966. /// <param name="e"></param>
  2967. private void button_WriteDebugParam_Click(object sender, EventArgs e)
  2968. {
  2969. var ConfigParam = new byte[60];
  2970. for (int i = 0; i < 60; i++)
  2971. ConfigParam[i] = 0;
  2972. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2973. ushort uwDataTemp = 0;
  2974. string[] strDataTemp = richTextBox_DebugParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2975. try
  2976. {
  2977. for (int i = 0; i < strDataTemp.Length; i++)
  2978. {
  2979. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2980. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2981. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2982. }
  2983. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam);
  2984. }
  2985. catch (Exception)
  2986. {
  2987. timer_500ms.Enabled = false;
  2988. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2989. timer_500ms.Enabled = true;
  2990. }
  2991. }
  2992. /// <summary>
  2993. /// 读取历史
  2994. /// </summary>
  2995. /// <param name="sender"></param>
  2996. /// <param name="e"></param>
  2997. private void button_ReadRecord_Click(object sender, EventArgs e)
  2998. {
  2999. richTextBox_Record.Clear();
  3000. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null);
  3001. }
  3002. /// <summary>
  3003. /// 读取传感器参数
  3004. /// </summary>
  3005. /// <param name="sender"></param>
  3006. /// <param name="e"></param>
  3007. private void button_ReadSensorParam_Click(object sender, EventArgs e)
  3008. {
  3009. richTextBox_SensorParam.Clear();
  3010. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3011. }
  3012. /// <summary>
  3013. /// 写入力矩传感器标定值
  3014. /// </summary>
  3015. /// <param name="sender"></param>
  3016. /// <param name="e"></param>
  3017. private void button_Write_Cal_Click(object sender, EventArgs e)
  3018. {
  3019. var ConfigParam = new byte[4];
  3020. for (int i = 0; i < 4; i++)
  3021. ConfigParam[i] = 0;
  3022. ushort uwDataTemp = 0;
  3023. try
  3024. {
  3025. uwDataTemp = Convert.ToUInt16(comboBox_TorqueSet.Text);//负载序号
  3026. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  3027. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  3028. uwDataTemp = (ushort)(decimal.Parse(textBox_Load.Text) * 10); ;//负载值0.1Nm
  3029. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  3030. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  3031. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  3032. }
  3033. catch (Exception)
  3034. {
  3035. timer_500ms.Enabled = false;
  3036. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3037. timer_500ms.Enabled = true;
  3038. }
  3039. }
  3040. /// <summary>
  3041. /// 写入传感器参数
  3042. /// </summary>
  3043. /// <param name="sender"></param>
  3044. /// <param name="e"></param>
  3045. private void button_WriteSensorParam_Click(object sender, EventArgs e)
  3046. {
  3047. var ConfigParam = new byte[14];
  3048. for (int i = 0; i < 14; i++)
  3049. ConfigParam[i] = 0;
  3050. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  3051. ushort uwDataTemp = 0;
  3052. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  3053. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  3054. int index = 0;
  3055. try
  3056. {
  3057. for (int i = 0; i < strDataTemp.Length; i++)
  3058. {
  3059. if (strDataTemp[i].Split('=')[0] == "力矩传感器踏频脉冲数")
  3060. {
  3061. index = i;
  3062. break;
  3063. }
  3064. }
  3065. for (int i = 0; i < (strDataTemp.Length - index); i++)
  3066. {
  3067. uwDataTemp = Convert.ToUInt16(strDataTemp[i + index].Split('=')[1]);
  3068. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3069. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3070. }
  3071. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x420E, ConfigParam);
  3072. }
  3073. catch (Exception)
  3074. {
  3075. timer_500ms.Enabled = false;
  3076. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3077. timer_500ms.Enabled = true;
  3078. }
  3079. }
  3080. /// <summary>
  3081. /// 写入型号
  3082. /// </summary>
  3083. /// <param name="sender"></param>
  3084. /// <param name="e"></param>
  3085. private void button_WriteModel_Click(object sender, EventArgs e)
  3086. {
  3087. string Mode = textBox_Model.Text;
  3088. var ModeArray = new byte[16];
  3089. for (ushort i = 0; i < Mode.Length; i++)
  3090. {
  3091. ModeArray[i] = (byte)Mode[i];
  3092. }
  3093. if (Mode.Length < 16)
  3094. {
  3095. ModeArray[Mode.Length] = (byte)'.';
  3096. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  3097. {
  3098. ModeArray[Mode.Length + 1 + i] = 0x20;
  3099. }
  3100. }
  3101. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  3102. }
  3103. /// <summary>
  3104. /// 写入SN
  3105. /// </summary>
  3106. /// <param name="sender"></param>
  3107. /// <param name="e"></param>
  3108. private void button_WriteSN_Click(object sender, EventArgs e)
  3109. {
  3110. string SN = textBox_SN.Text;
  3111. var SNArray = new byte[16];
  3112. for (ushort i = 0; i < SN.Length; i++)
  3113. {
  3114. SNArray[i] = (byte)SN[i];
  3115. }
  3116. if (SN.Length < 16)
  3117. {
  3118. SNArray[SN.Length] = (byte)'.';
  3119. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  3120. {
  3121. SNArray[SN.Length + 1 + i] = 0x20;
  3122. }
  3123. }
  3124. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  3125. }
  3126. /// <summary>
  3127. /// 查询版本信息
  3128. /// </summary>
  3129. /// <param name="sender"></param>
  3130. /// <param name="e"></param>
  3131. private void button_ReadVersion_Click(object sender, EventArgs e)
  3132. {
  3133. textBox_Model.Text = "---";
  3134. textBox_SN.Text = "---";
  3135. textBox_HW.Text = "---";
  3136. textBox_FW.Text = "---";
  3137. textBox_SP.Text = "---";
  3138. textBox_OBC_ReadModel.Text = "---";
  3139. textBox_OBC_ReadSN.Text = "---";
  3140. textBox_OBC_ReadHW.Text = "---";
  3141. textBox_OBC_ReadFW.Text = "---";
  3142. textBox_OBC_ReadSP.Text = "---";
  3143. textBox_FacModeName.Text = "---";
  3144. textBox_FacModeNum.Text = "---";
  3145. textBox_FacModeHW.Text = "---";
  3146. textBox_FacModeFW.Text = "---";
  3147. textBox_FacModeSP.Text = "---";
  3148. Class_Motor_Ver.Mode = "---";
  3149. Class_Motor_Ver.SN = "---";
  3150. Class_Motor_Ver.HW = "---";
  3151. Class_Motor_Ver.FW = "---";
  3152. Class_Motor_Ver.Special = "---";
  3153. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  3154. }
  3155. /// <summary>
  3156. /// 查询自定义1
  3157. /// </summary>
  3158. /// <param name="sender"></param>
  3159. /// <param name="e"></param>
  3160. private void button_ReadUser1_Click(object sender, EventArgs e)
  3161. {
  3162. textBox_User1.Text = "---";
  3163. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null);
  3164. }
  3165. /// <summary>
  3166. /// 查询自定义2
  3167. /// </summary>
  3168. /// <param name="sender"></param>
  3169. /// <param name="e"></param>
  3170. private void button_ReadUser2_Click(object sender, EventArgs e)
  3171. {
  3172. textBox_User2.Text = "---";
  3173. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null);
  3174. }
  3175. /// <summary>
  3176. /// 查询自定义3
  3177. /// </summary>
  3178. /// <param name="sender"></param>
  3179. /// <param name="e"></param>
  3180. private void button_ReadUser3_Click(object sender, EventArgs e)
  3181. {
  3182. textBox_User3.Text = "---";
  3183. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null);
  3184. }
  3185. /// <summary>
  3186. /// 写入自定义字符串1
  3187. /// </summary>
  3188. /// <param name="sender"></param>
  3189. /// <param name="e"></param>
  3190. private void button_WriteUser1_Click(object sender, EventArgs e)
  3191. {
  3192. string User = textBox_User1.Text;
  3193. var UserArray = new byte[16];
  3194. for (ushort i = 0; i < User.Length; i++)
  3195. {
  3196. UserArray[i] = (byte)User[i];
  3197. }
  3198. if (User.Length < 16)
  3199. {
  3200. UserArray[User.Length] = (byte)'.';
  3201. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3202. {
  3203. UserArray[User.Length + 1 + i] = 0x20;
  3204. }
  3205. }
  3206. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1410, UserArray);
  3207. }
  3208. /// <summary>
  3209. /// 写入自定义字符串2
  3210. /// </summary>
  3211. /// <param name="sender"></param>
  3212. /// <param name="e"></param>
  3213. private void button_WriteUser2_Click(object sender, EventArgs e)
  3214. {
  3215. string User = textBox_User2.Text;
  3216. var UserArray = new byte[16];
  3217. for (ushort i = 0; i < User.Length; i++)
  3218. {
  3219. UserArray[i] = (byte)User[i];
  3220. }
  3221. if (User.Length < 16)
  3222. {
  3223. UserArray[User.Length] = (byte)'.';
  3224. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3225. {
  3226. UserArray[User.Length + 1 + i] = 0x20;
  3227. }
  3228. }
  3229. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1610, UserArray);
  3230. }
  3231. /// <summary>
  3232. /// 写入自定义字符串3
  3233. /// </summary>
  3234. /// <param name="sender"></param>
  3235. /// <param name="e"></param>
  3236. private void button_WriteUser3_Click(object sender, EventArgs e)
  3237. {
  3238. string User = textBox_User3.Text;
  3239. var UserArray = new byte[16];
  3240. for (ushort i = 0; i < User.Length; i++)
  3241. {
  3242. UserArray[i] = (byte)User[i];
  3243. }
  3244. if (User.Length < 16)
  3245. {
  3246. UserArray[User.Length] = (byte)'.';
  3247. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3248. {
  3249. UserArray[User.Length + 1 + i] = 0x20;
  3250. }
  3251. }
  3252. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1810, UserArray);
  3253. }
  3254. /// <summary>
  3255. /// 查询生产信息
  3256. /// </summary>
  3257. /// <param name="sender"></param>
  3258. /// <param name="e"></param>
  3259. private void button_ReadMAC_Click(object sender, EventArgs e)
  3260. {
  3261. textBox_MAC.Text = "---";
  3262. textBox_MACAdd.Text = "---";
  3263. textBox_MACDate.Text = "---";
  3264. textBox_PP.Text = "---";
  3265. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null);
  3266. }
  3267. /// <summary>
  3268. /// 写入生产信息
  3269. /// </summary>
  3270. /// <param name="sender"></param>
  3271. /// <param name="e"></param>
  3272. private void button_WriteMac_Click(object sender, EventArgs e)
  3273. {
  3274. var MACArray = new byte[32];
  3275. //填入生产商
  3276. for (ushort i = 0; i < textBox_MAC.Text.Length; i++)
  3277. {
  3278. MACArray[i] = (byte)textBox_MAC.Text[i];
  3279. }
  3280. if (textBox_MAC.Text.Length < 8)
  3281. {
  3282. MACArray[textBox_MAC.Text.Length] = (byte)'.';
  3283. for (ushort i = 0; i < 8 - textBox_MAC.Text.Length - 1; i++)
  3284. {
  3285. MACArray[textBox_MAC.Text.Length + 1 + i] = 0x20;
  3286. }
  3287. }
  3288. //填入生产地
  3289. for (ushort i = 0; i < textBox_MACAdd.Text.Length; i++)
  3290. {
  3291. MACArray[8 + i] = (byte)textBox_MACAdd.Text[i];
  3292. }
  3293. if (textBox_MACAdd.Text.Length < 8)
  3294. {
  3295. MACArray[textBox_MACAdd.Text.Length + 8] = (byte)'.';
  3296. for (ushort i = 0; i < 8 - textBox_MACAdd.Text.Length - 1; i++)
  3297. {
  3298. MACArray[textBox_MACAdd.Text.Length + 1 + i + 8] = 0x20;
  3299. }
  3300. }
  3301. //填入生产日期
  3302. for (ushort i = 0; i < textBox_MACDate.Text.Length; i++)
  3303. {
  3304. MACArray[16 + i] = (byte)textBox_MACDate.Text[i];
  3305. }
  3306. if (textBox_MACDate.Text.Length < 8)
  3307. {
  3308. MACArray[textBox_MACDate.Text.Length + 16] = (byte)'.';
  3309. for (ushort i = 0; i < 8 - textBox_MACDate.Text.Length - 1; i++)
  3310. {
  3311. MACArray[textBox_MACDate.Text.Length + 1 + i + 16] = 0x20;
  3312. }
  3313. }
  3314. //填入品牌
  3315. for (ushort i = 0; i < textBox_PP.Text.Length; i++)
  3316. {
  3317. MACArray[24 + i] = (byte)textBox_PP.Text[i];
  3318. }
  3319. if (textBox_PP.Text.Length < 8)
  3320. {
  3321. MACArray[textBox_PP.Text.Length + 24] = (byte)'.';
  3322. for (ushort i = 0; i < 8 - textBox_PP.Text.Length - 1; i++)
  3323. {
  3324. MACArray[textBox_PP.Text.Length + 1 + i + 24] = 0x20;
  3325. }
  3326. }
  3327. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  3328. }
  3329. /// <summary>
  3330. /// 查询密钥
  3331. /// </summary>
  3332. /// <param name="sender"></param>
  3333. /// <param name="e"></param>
  3334. private void button_ReadKey_Click(object sender, EventArgs e)
  3335. {
  3336. textBox_Key.Text = "---";
  3337. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null);
  3338. }
  3339. /// <summary>
  3340. /// 写入校验密钥
  3341. /// </summary>
  3342. /// <param name="sender"></param>
  3343. /// <param name="e"></param>
  3344. private void button_WriteKey_Click(object sender, EventArgs e)
  3345. {
  3346. string Key = textBox_Key.Text;
  3347. var KeyArray = new byte[8];
  3348. if (Key.Length != 8)
  3349. {
  3350. timer_500ms.Enabled = false;
  3351. MessageBox.Show("请检查字符长度是否为8", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3352. timer_500ms.Enabled = true;
  3353. return;
  3354. }
  3355. for (ushort i = 0; i < Key.Length; i++)
  3356. {
  3357. KeyArray[i] = (byte)Key[i];
  3358. }
  3359. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1108, KeyArray);
  3360. }
  3361. /// <summary>
  3362. /// 查询在线检测结果
  3363. /// </summary>
  3364. /// <param name="sender"></param>
  3365. /// <param name="e"></param>
  3366. private void button_ReadOnLine_Click(object sender, EventArgs e)
  3367. {
  3368. textBox_Online.Text = "---";
  3369. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2100, null);
  3370. }
  3371. /// <summary>
  3372. /// 系统清除
  3373. /// </summary>
  3374. /// <param name="sender"></param>
  3375. /// <param name="e"></param>
  3376. private void button_SystemClear_Click(object sender, EventArgs e)
  3377. {
  3378. var Code = new byte[5];
  3379. Code[0] = (byte)'C';
  3380. Code[1] = (byte)'L';
  3381. Code[2] = (byte)'E';
  3382. Code[3] = (byte)'A';
  3383. Code[4] = (byte)'R';
  3384. timer_500ms.Enabled = false;
  3385. if (MessageBox.Show("系统清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3386. {
  3387. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3388. {
  3389. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3390. {
  3391. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  3392. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3393. }
  3394. }
  3395. }
  3396. timer_500ms.Enabled = true;
  3397. }
  3398. /// <summary>
  3399. /// 参数还原
  3400. /// </summary>
  3401. /// <param name="sender"></param>
  3402. /// <param name="e"></param>
  3403. private void button_Recovery_Click(object sender, EventArgs e)
  3404. {
  3405. var Code = new byte[8];
  3406. Code[0] = (byte)'R';
  3407. Code[1] = (byte)'E';
  3408. Code[2] = (byte)'C';
  3409. Code[3] = (byte)'O';
  3410. Code[4] = (byte)'V';
  3411. Code[5] = (byte)'E';
  3412. Code[6] = (byte)'R';
  3413. Code[7] = (byte)'Y';
  3414. timer_500ms.Enabled = false;
  3415. if (MessageBox.Show("参数还原后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3416. {
  3417. if (MessageBox.Show("请再次确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3418. {
  3419. if (MessageBox.Show("请最后确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3420. {
  3421. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2708, Code);
  3422. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3423. }
  3424. }
  3425. }
  3426. timer_500ms.Enabled = true;
  3427. }
  3428. /// <summary>
  3429. /// 系统复位
  3430. /// </summary>
  3431. /// <param name="sender"></param>
  3432. /// <param name="e"></param>
  3433. private void button_Reset_Click(object sender, EventArgs e)
  3434. {
  3435. var Code_Off = new byte[5];
  3436. var Code_Reset = new byte[5];
  3437. Code_Off[0] = (byte)'O';
  3438. Code_Off[1] = (byte)'F';
  3439. Code_Off[2] = (byte)'F';
  3440. Code_Off[3] = (byte)'.';
  3441. Code_Off[4] = (byte)'.';
  3442. Code_Reset[0] = (byte)'R';
  3443. Code_Reset[1] = (byte)'E';
  3444. Code_Reset[2] = (byte)'S';
  3445. Code_Reset[3] = (byte)'E';
  3446. Code_Reset[4] = (byte)'T';
  3447. timer_500ms.Enabled = false;
  3448. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3449. {
  3450. timer_500ms.Enabled = true;
  3451. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  3452. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  3453. PowerOffAckStatus = false;
  3454. Delay_ms(250);
  3455. int TryCnt = 3;
  3456. while ((TryCnt--) >= 0)
  3457. {
  3458. if (!PowerOffAckStatus)
  3459. {
  3460. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  3461. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  3462. PowerOffAckStatus = false;
  3463. Delay_ms(250);
  3464. }
  3465. else break;
  3466. }
  3467. if (PowerOffAckStatus)
  3468. {
  3469. MessageBoxTimeOut.Show("已关机!", "提示", 3000, MessageBoxButtons.OK, MessageBoxIcon.None);
  3470. }
  3471. else
  3472. {
  3473. timer_500ms.Enabled = false;
  3474. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3475. timer_500ms.Enabled = true;
  3476. }
  3477. }
  3478. timer_500ms.Enabled = true;
  3479. }
  3480. /// <summary>
  3481. /// 记录清除
  3482. /// </summary>
  3483. /// <param name="sender"></param>
  3484. /// <param name="e"></param>
  3485. private void button_ClearLog_Click(object sender, EventArgs e)
  3486. {
  3487. var Code = new byte[9];
  3488. Code[0] = (byte)'L';
  3489. Code[1] = (byte)'O';
  3490. Code[2] = (byte)'G';
  3491. Code[3] = (byte)' ';
  3492. Code[4] = (byte)'C';
  3493. Code[5] = (byte)'L';
  3494. Code[6] = (byte)'E';
  3495. Code[7] = (byte)'A';
  3496. Code[8] = (byte)'R';
  3497. timer_500ms.Enabled = false;
  3498. if (MessageBox.Show("历史记录信息清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3499. {
  3500. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3501. {
  3502. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3503. {
  3504. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3909, Code);
  3505. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3506. }
  3507. }
  3508. }
  3509. timer_500ms.Enabled = true;
  3510. }
  3511. /// <summary>
  3512. /// 打开系统计算器
  3513. /// </summary>
  3514. /// <param name="sender"></param>
  3515. /// <param name="e"></param>
  3516. private void 计算器ToolStripMenuItem_Click(object sender, EventArgs e)
  3517. {
  3518. System.Diagnostics.Process.Start("calc.exe");
  3519. }
  3520. /// <summary>
  3521. ///故障转换和显示
  3522. /// </summary>
  3523. List<string> ErrorInfo = new List<string>{ "过流保护", "低压保护", "过压保护", "堵转保护","过热保护","速度传感器故障","力矩传感器故障","霍尔故障",
  3524. "马达缺相","NTC故障","BMS校验失败","","OBC校验失败","MCU故障","踏频传感器故障","指拨故障","MOS短路","电压异常","","","","","","","","","","","","",
  3525. "",""};
  3526. private string ErrorInfoDisplay(UInt32 Code)
  3527. {
  3528. string Result = "";
  3529. if (Code == 0)
  3530. {
  3531. Result = "无故障";
  3532. }
  3533. else
  3534. {
  3535. for (int i = 0; i < 32; i++)
  3536. {
  3537. if ((Code & 0x01) == 0x01)
  3538. {
  3539. Result += ErrorInfo[i] + " ";
  3540. }
  3541. Code >>= 1;
  3542. }
  3543. }
  3544. return Result;
  3545. }
  3546. /// <summary>
  3547. /// 鼠标滑过故障码显示具体内容
  3548. /// </summary>
  3549. /// <param name="sender"></param>
  3550. /// <param name="e"></param>
  3551. private void textBox_ErrorCode_MouseHover(object sender, EventArgs e)
  3552. {
  3553. // 创建the ToolTip
  3554. ToolTip toolTip1 = new ToolTip();
  3555. // 设置显示样式
  3556. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  3557. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  3558. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  3559. toolTip1.ShowAlways = true;//是否显示提示框
  3560. // 设置伴随的对象.
  3561. string ErrorCode = this.textBox_ErrorCode.Text;
  3562. UInt32 Code = ErrorCode.Contains("H") ? Convert.ToUInt32(ErrorCode.Split('H')[0], 16) : 0;
  3563. toolTip1.SetToolTip(this.textBox_ErrorCode, ErrorInfoDisplay(Code));//设置故障内容显示
  3564. }
  3565. /// <summary>
  3566. /// 数据记录
  3567. /// </summary>
  3568. private void RunInfoAutoSave()
  3569. {
  3570. if (运行信息记录ToolStripMenuItem.Checked == true)
  3571. {
  3572. if (RunInfoSaveFilename == string.Empty)
  3573. {
  3574. return;
  3575. }
  3576. string SaveData = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff").Replace(" ", "_") + " --> ";
  3577. foreach (Control c in tabPage_RunInfo.Controls)
  3578. {
  3579. if (c is TextBox)
  3580. {
  3581. SaveData += c.Text + " , ";
  3582. }
  3583. }
  3584. foreach (Control c in tabPage_DebugInfo.Controls)
  3585. {
  3586. if (c is TextBox)
  3587. {
  3588. SaveData += c.Text + " , ";
  3589. }
  3590. }
  3591. SaveData += "\r\n";
  3592. System.IO.File.AppendAllText(RunInfoSaveFilename, SaveData);//sb.ToString());
  3593. }
  3594. }
  3595. /// <summary>
  3596. /// 打开或关闭数据记录
  3597. /// </summary>
  3598. /// <param name="sender"></param>
  3599. /// <param name="e"></param>
  3600. private void 记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  3601. {
  3602. if (运行信息记录ToolStripMenuItem.Checked == false)
  3603. {
  3604. if (mySerialProcess.mySerial.IsOpen == true)
  3605. {
  3606. RunInfoSaveFilename = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_运行信息" + ".txt";
  3607. System.IO.File.AppendAllText(RunInfoSaveFilename, "时间 --> 车速 , 转速 , 踏频 , 力矩Reg , 力矩 , 踩踏方向 , 电压 , 电流 , 功率 , 电量 , " +
  3608. "PCB温度 , 绕组温度 , MOS温度 , 挡位 , 灯开关 , 续航 , 平均功耗 , 单次里程 , 单次时间 , 故障码 , " +
  3609. "系统状态机 , 二层状态机 , 电机状态机 , 助力状态机 , D轴电流给定 , Q轴电流给定 , D轴电压给定 , Q轴电压给定 , 瞬时力矩 , 时间滤波力矩 , 踏频滤波力矩 , D轴电流反馈 , Q轴电流反馈 , 助力函数输出" + "\r\n");
  3610. MessageBoxTimeOut.Show("开始记录", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  3611. 运行信息记录ToolStripMenuItem.Checked = true;
  3612. }
  3613. else
  3614. {
  3615. timer_500ms.Enabled = false;
  3616. MessageBox.Show("请连接电机", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3617. timer_500ms.Enabled = true;
  3618. }
  3619. }
  3620. else
  3621. {
  3622. 运行信息记录ToolStripMenuItem.Checked = false;
  3623. MessageBoxTimeOut.Show("停止记录", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  3624. }
  3625. }
  3626. /// <summary>
  3627. /// 仪表启动控制档位开关事件
  3628. /// </summary>
  3629. /// <param name="sender"></param>
  3630. /// <param name="e"></param>
  3631. private void checkBox_OBC_StartSetGearSt_CheckedChanged(object sender, EventArgs e)
  3632. {
  3633. if (checkBox_OBC_StartSetGearSt.Checked == true)
  3634. {
  3635. //检查串口是否打开
  3636. if (!mySerialProcess.mySerial.IsOpen)
  3637. {
  3638. timer_500ms.Enabled = false;
  3639. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3640. timer_500ms.Enabled = true;
  3641. checkBox_OBC_StartSetGearSt.Checked = false;
  3642. return;
  3643. }
  3644. //检查是否选择档位和打开车灯
  3645. if ((comboBox_OBC_SetGearST.SelectedIndex == -1) || (comboBox_OBC_LightSw.SelectedIndex == -1))
  3646. {
  3647. timer_500ms.Enabled = false;
  3648. MessageBox.Show("请检查档位设置和大灯开关!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3649. timer_500ms.Enabled = true;
  3650. checkBox_OBC_StartSetGearSt.Checked = false;
  3651. return;
  3652. }
  3653. }
  3654. }
  3655. /// <summary>
  3656. /// OBC查询电机用户参数
  3657. /// </summary>
  3658. /// <param name="sender"></param>
  3659. /// <param name="e"></param>
  3660. private void button_OBC_ReadUserInfo_Click(object sender, EventArgs e)
  3661. {
  3662. richTextBox_OBC_ReadUserInfo.Clear();
  3663. comboBox_OBC_BikeCCS.SelectedIndex = 0;
  3664. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3300, null);
  3665. }
  3666. /// <summary>
  3667. /// OBC设置电机用户参数
  3668. /// </summary>
  3669. /// <param name="sender"></param>
  3670. /// <param name="e"></param>
  3671. private void button_OBC_WriteUserInfo_Click(object sender, EventArgs e)
  3672. {
  3673. var UserInfoCode = new byte[8];
  3674. for (int i = 0; i < UserInfoCode.Length; i++)
  3675. UserInfoCode[i] = 0;
  3676. if (comboBox_OBC_StartMode.SelectedIndex == -1)//检查数据有效性
  3677. {
  3678. timer_500ms.Enabled = false;
  3679. MessageBox.Show("请选择启动模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3680. timer_500ms.Enabled = true;
  3681. return;
  3682. }
  3683. if (comboBox_OBC_AssistFunc.SelectedIndex == -1)//检查数据有效性
  3684. {
  3685. timer_500ms.Enabled = false;
  3686. MessageBox.Show("请选择助力方案!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3687. timer_500ms.Enabled = true;
  3688. return;
  3689. }
  3690. //周长微调
  3691. UserInfoCode[0] = (byte)(int)numericUpDown_OBC_WheelAdj.Value;
  3692. //启动模式
  3693. UserInfoCode[1] = (byte)(comboBox_OBC_StartMode.SelectedIndex + 1);
  3694. //助力方案
  3695. UserInfoCode[2] = (byte)(comboBox_OBC_AssistFunc.SelectedIndex + 1);
  3696. //自动关机时间
  3697. UserInfoCode[3] = (byte)(uint)numericUpDown_OBC_OffTime.Value;
  3698. //限速微调
  3699. UserInfoCode[4] = (byte)(int)numericUpDown_OBC_SpeedLimitAdj.Value;
  3700. //定速巡航开关
  3701. UserInfoCode[5] = (byte)((comboBox_OBC_BikeCCS.SelectedIndex == 1) ? 0xAA : 0x00);
  3702. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3408, UserInfoCode);
  3703. }
  3704. /// <summary>
  3705. /// OBC查询电机版本信息
  3706. /// </summary>
  3707. /// <param name="sender"></param>
  3708. /// <param name="e"></param>
  3709. private void button_OBC_ReadVerInfo_Click(object sender, EventArgs e)
  3710. {
  3711. textBox_Model.Text = "---";
  3712. textBox_SN.Text = "---";
  3713. textBox_HW.Text = "---";
  3714. textBox_FW.Text = "---";
  3715. textBox_SP.Text = "---";
  3716. textBox_OBC_ReadModel.Text = "---";
  3717. textBox_OBC_ReadSN.Text = "---";
  3718. textBox_OBC_ReadHW.Text = "---";
  3719. textBox_OBC_ReadFW.Text = "---";
  3720. textBox_OBC_ReadSP.Text = "---";
  3721. textBox_FacModeName.Text = "---";
  3722. textBox_FacModeNum.Text = "---";
  3723. textBox_FacModeHW.Text = "---";
  3724. textBox_FacModeFW.Text = "---";
  3725. textBox_FacModeSP.Text = "---";
  3726. Class_Motor_Ver.Mode = "---";
  3727. Class_Motor_Ver.SN = "---";
  3728. Class_Motor_Ver.HW = "---";
  3729. Class_Motor_Ver.FW = "---";
  3730. Class_Motor_Ver.Special = "---";
  3731. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  3732. }
  3733. /// <summary>
  3734. /// OBC读取骑行历史
  3735. /// </summary>
  3736. /// <param name="sender"></param>
  3737. /// <param name="e"></param>
  3738. private void button_OBC_ReadRideInfo_Click(object sender, EventArgs e)
  3739. {
  3740. textBox_OBC_TRIP_KM.Text = "";
  3741. textBox_OBC_TRIP_TIME.Text = "";
  3742. textBox_OBC_ODO_KM.Text = "";
  3743. textBox_OBC_ODO_TIME.Text = "";
  3744. textBox_ODO_KM.Text = "---";
  3745. textBox_ODO_TIME.Text = "---";
  3746. textBox_TRIP_KM.Text = "---";
  3747. textBox_TRIP_TIME.Text = "---";
  3748. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3500, null);
  3749. }
  3750. /// <summary>
  3751. /// OBC清除TRIP里程
  3752. /// </summary>
  3753. /// <param name="sender"></param>
  3754. /// <param name="e"></param>
  3755. private void button_OBC_ClearTrip_Click(object sender, EventArgs e)
  3756. {
  3757. var Code = new byte[5];
  3758. Code[0] = (byte)'C';
  3759. Code[1] = (byte)'L';
  3760. Code[2] = (byte)'E';
  3761. Code[3] = (byte)'A';
  3762. Code[4] = (byte)'R';
  3763. timer_500ms.Enabled = false;
  3764. if (MessageBox.Show("TRIP清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3765. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3605, Code);
  3766. timer_500ms.Enabled = true;
  3767. }
  3768. private void checkBox_OBC_StartReadBMS_CheckedChanged(object sender, EventArgs e)
  3769. {
  3770. if (checkBox_OBC_StartReadBMS.Checked == true)
  3771. {
  3772. //检查串口是否打开
  3773. if (!mySerialProcess.mySerial.IsOpen)
  3774. {
  3775. timer_500ms.Enabled = false;
  3776. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3777. timer_500ms.Enabled = true;
  3778. checkBox_OBC_StartReadBMS.Checked = false;
  3779. return;
  3780. }
  3781. }
  3782. }
  3783. /// <summary>
  3784. /// 写入力矩传感器参数
  3785. /// </summary>
  3786. /// <param name="sender"></param>
  3787. /// <param name="e"></param>
  3788. private void button_WriteTqSensorParam_Click(object sender, EventArgs e)
  3789. {
  3790. var ConfigParam = new byte[46];
  3791. for (int i = 0; i < 14; i++)
  3792. ConfigParam[i] = 0;
  3793. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  3794. ushort uwDataTemp = 0;
  3795. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  3796. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  3797. int index = 0;
  3798. try
  3799. {
  3800. for (int i = 0; i < strDataTemp.Length; i++)
  3801. {
  3802. if (strDataTemp[i].Split('=')[0] == "第四阶段转矩点采集值")
  3803. {
  3804. index = i;
  3805. break;
  3806. }
  3807. }
  3808. for (int i = 0; i < (index + 1); i++)
  3809. {
  3810. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  3811. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3812. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3813. }
  3814. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x472E, ConfigParam);
  3815. }
  3816. catch (Exception)
  3817. {
  3818. timer_500ms.Enabled = false;
  3819. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3820. timer_500ms.Enabled = true;
  3821. }
  3822. }
  3823. /// <summary>
  3824. /// 查询存储标志
  3825. /// </summary>
  3826. /// <param name="sender"></param>
  3827. /// <param name="e"></param>
  3828. private void button_ReadSaveFlag_Click(object sender, EventArgs e)
  3829. {
  3830. radioButton_EE_SaveYes.Checked = false;
  3831. radioButton_EE_SaveNo.Checked = false;
  3832. radioButton_SIP_SaveYes.Checked = false;
  3833. radioButton_SIP_SaveNo.Checked = false;
  3834. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null);
  3835. }
  3836. /// <summary>
  3837. /// 写入存储标志
  3838. /// </summary>
  3839. /// <param name="sender"></param>
  3840. /// <param name="e"></param>
  3841. private void button_WriteSaveFlag_Click(object sender, EventArgs e)
  3842. {
  3843. var SaveFlag = new byte[6];
  3844. for (int i = 0; i < 6; i++)
  3845. SaveFlag[i] = 0;
  3846. if ((radioButton_EE_SaveYes.Checked == false) && (radioButton_EE_SaveNo.Checked == false))
  3847. {
  3848. timer_500ms.Enabled = false;
  3849. MessageBox.Show("请选择EEPROM存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3850. timer_500ms.Enabled = true;
  3851. return;
  3852. }
  3853. if ((radioButton_SIP_SaveYes.Checked == false) && (radioButton_SIP_SaveNo.Checked == false))
  3854. {
  3855. timer_500ms.Enabled = false;
  3856. MessageBox.Show("请选择SIP校验存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3857. timer_500ms.Enabled = true;
  3858. return;
  3859. }
  3860. SaveFlag[0] = (byte)((checkBox_SaveYes.Checked) ? 0x01 : 0x00);
  3861. SaveFlag[2] = (byte)(radioButton_EE_SaveYes.Checked ? 0x01 : 0x00);
  3862. SaveFlag[3] = 0;
  3863. SaveFlag[4] = (byte)(radioButton_SIP_SaveYes.Checked ? 0x01 : 0x00);
  3864. SaveFlag[5] = 0;
  3865. timer_500ms.Enabled = false;
  3866. if (MessageBox.Show("确认修改存储标志?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3867. {
  3868. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4906, SaveFlag);
  3869. }
  3870. timer_500ms.Enabled = true;
  3871. }
  3872. /// <summary>
  3873. /// 读取指定地址数据
  3874. /// </summary>
  3875. /// <param name="sender"></param>
  3876. /// <param name="e"></param>
  3877. private void button_ReadRamFlash_Click(object sender, EventArgs e)
  3878. {
  3879. var Address = new byte[4];
  3880. UInt32 Address_Begin;
  3881. UInt32 Addres_End;
  3882. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  3883. richTextBox_RamFlasgData.Clear();
  3884. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  3885. {
  3886. timer_500ms.Enabled = false;
  3887. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3888. timer_500ms.Enabled = true;
  3889. return;
  3890. }
  3891. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  3892. {
  3893. timer_500ms.Enabled = false;
  3894. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3895. timer_500ms.Enabled = true;
  3896. return;
  3897. }
  3898. else
  3899. {
  3900. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  3901. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  3902. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  3903. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  3904. if (Addres_End < Address_Begin)
  3905. {
  3906. timer_500ms.Enabled = false;
  3907. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3908. timer_500ms.Enabled = true;
  3909. return;
  3910. }
  3911. else
  3912. {
  3913. var SendByte = new byte[8];
  3914. SendByte[0] = (byte)(Address_Begin >> 24);
  3915. SendByte[1] = (byte)(Address_Begin >> 16);
  3916. SendByte[2] = (byte)(Address_Begin >> 8);
  3917. SendByte[3] = (byte)(Address_Begin);
  3918. SendByte[4] = (byte)(Addres_End >> 24);
  3919. SendByte[5] = (byte)(Addres_End >> 16);
  3920. SendByte[6] = (byte)(Addres_End >> 8);
  3921. SendByte[7] = (byte)(Addres_End);
  3922. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  3923. }
  3924. }
  3925. }
  3926. /// <summary>
  3927. /// 工作模式选择
  3928. /// </summary>
  3929. /// <param name="sender"></param>
  3930. /// <param name="e"></param>
  3931. private void comboBox_WorkMode_SelectedIndexChanged(object sender, EventArgs e)
  3932. {
  3933. var RunMode = new byte[1];
  3934. if (comboBox_WorkMode.Text == "配置模式")
  3935. RunMode[0] = 0x01;
  3936. else if (comboBox_WorkMode.Text == "调试模式")
  3937. RunMode[0] = 0x02;
  3938. else
  3939. RunMode[0] = 0x00;
  3940. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  3941. }
  3942. /// <summary>
  3943. /// 助力档位选择
  3944. /// </summary>
  3945. /// <param name="sender"></param>
  3946. /// <param name="e"></param>
  3947. private void comboBox_GearSt_SelectedIndexChanged(object sender, EventArgs e)
  3948. {
  3949. var CtrlCode = new byte[2];
  3950. if (comboBox_GearSt.SelectedIndex == 5)//档位
  3951. CtrlCode[0] = 0x33;
  3952. else if (comboBox_GearSt.SelectedIndex == 6)//档位
  3953. CtrlCode[0] = 0x22;
  3954. else
  3955. CtrlCode[0] = (byte)comboBox_GearSt.SelectedIndex;
  3956. if (comboBox_LightSwitch.SelectedIndex == 0)//车灯
  3957. CtrlCode[1] = 0xF1;
  3958. else
  3959. CtrlCode[1] = 0xF0;
  3960. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
  3961. comboBox_OBC_SetGearST.SelectedIndex = comboBox_GearSt.SelectedIndex;
  3962. comboBox_OBC_LightSw.SelectedIndex = comboBox_LightSwitch.SelectedIndex;
  3963. Delay_ms(500);
  3964. //设置百分比
  3965. do
  3966. {
  3967. var PercentCode = new byte[1];
  3968. if (comboBox_GearSt.SelectedIndex == 0) //Off
  3969. {
  3970. PercentCode[0] = 0;
  3971. textBox_MotorSpeedPercent.Text = "0";
  3972. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, PercentCode);
  3973. }
  3974. else if (comboBox_GearSt.SelectedIndex == 6) //Walk
  3975. {
  3976. if (comboBox_WorkMode.SelectedIndex != 0)
  3977. {
  3978. PercentCode[0] = 100;
  3979. textBox_MotorSpeedPercent.Text = "100";
  3980. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, PercentCode);
  3981. }
  3982. }
  3983. } while (false);
  3984. }
  3985. /// <summary>
  3986. /// 仪表档位选择
  3987. /// </summary>
  3988. /// <param name="sender"></param>
  3989. /// <param name="e"></param>
  3990. private void comboBox_OBC_SetGearST_SelectedIndexChanged(object sender, EventArgs e)
  3991. {
  3992. comboBox_GearSt.SelectedIndex = comboBox_OBC_SetGearST.SelectedIndex;
  3993. comboBox_LightSwitch.SelectedIndex = comboBox_OBC_LightSw.SelectedIndex;
  3994. }
  3995. /// <summary>
  3996. /// 生产模式初始化
  3997. /// </summary>
  3998. /// <param name="sender"></param>
  3999. /// <param name="e"></param>
  4000. private void button_FacModeInit_Click(object sender, EventArgs e)
  4001. {
  4002. var Code = new byte[5];
  4003. Code[0] = (byte)'C';
  4004. Code[1] = (byte)'L';
  4005. Code[2] = (byte)'E';
  4006. Code[3] = (byte)'A';
  4007. Code[4] = (byte)'R';
  4008. timer_500ms.Enabled = false;
  4009. if (MessageBox.Show("电机即将初始化!", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  4010. {
  4011. if (MessageBox.Show("请再次确认", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  4012. {
  4013. timer_500ms.Enabled = true;
  4014. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  4015. PowerOffAckStatus = false;
  4016. Delay_ms(250);
  4017. int TryCnt = 3;
  4018. while ((TryCnt--) >= 0)
  4019. {
  4020. if (!PowerOffAckStatus)
  4021. {
  4022. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  4023. PowerOffAckStatus = false;
  4024. Delay_ms(250);
  4025. }
  4026. else break;
  4027. }
  4028. if (PowerOffAckStatus)
  4029. {
  4030. timer_500ms.Enabled = false;
  4031. MessageBox.Show("系统已关机,请保持无负载重新开机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  4032. timer_500ms.Enabled = true;
  4033. }
  4034. else
  4035. {
  4036. timer_500ms.Enabled = false;
  4037. MessageBox.Show("初始化失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4038. timer_500ms.Enabled = true;
  4039. }
  4040. timer_500ms.Enabled = true;
  4041. }
  4042. }
  4043. timer_500ms.Enabled = true;
  4044. //清除历史测试记录
  4045. textBox_FacModeSensorADC0.Text = "";
  4046. textBox_FacModeSensorADC1.Text = "";
  4047. textBox_FacModeSensorADC2.Text = "";
  4048. textBox_FacModeSensorADC3.Text = "";
  4049. textBox_FacModeSensorADC4.Text = "";
  4050. LightSwitchStatus = false;
  4051. MotorRunStatus = false;
  4052. textBox_MotorSpeedPercent.Text = "5";
  4053. textBox_FacModeName.Text = "";
  4054. textBox_FacModeNum.Text = "";
  4055. textBox_FacModeHW.Text = "";
  4056. textBox_FacModeFW.Text = "";
  4057. }
  4058. /// <summary>
  4059. /// 生产模式读取传感器参数
  4060. /// </summary>
  4061. /// <param name="sender"></param>
  4062. /// <param name="e"></param>
  4063. private void button_FacModeSensorRead_Click(object sender, EventArgs e)
  4064. {
  4065. richTextBox_SensorParam.Clear();
  4066. textBox_FacModeSensorADC0.Text = "";
  4067. textBox_FacModeSensorADC1.Text = "";
  4068. textBox_FacModeSensorADC2.Text = "";
  4069. textBox_FacModeSensorADC3.Text = "";
  4070. textBox_FacModeSensorADC4.Text = "";
  4071. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4072. //零点判断
  4073. label1_TorqueCal0.BackColor = Color.Red;
  4074. WriteACK = false;
  4075. ACK_WaitCnt = 0;
  4076. Delay_ms(200);
  4077. if (WriteACK == true) //力矩读取正常
  4078. {
  4079. WriteACK = false;
  4080. //获取零点
  4081. ushort ZeroNew;
  4082. ZeroNew = (ushort)Convert.ToUInt16(textBox_FacModeSensorADC0.Text);
  4083. //比较零点
  4084. if ((ZeroNew <= TorqueParamsForm.Zero.Max) && (ZeroNew >= TorqueParamsForm.Zero.Min))
  4085. {
  4086. label1_TorqueCal0.BackColor = Color.Green;
  4087. }
  4088. else
  4089. {
  4090. MessageBoxTimeOut.Show("力矩传感器零点超范围!\r\n" + "最新零点:" + ZeroNew.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4091. }
  4092. }
  4093. else //力矩读取不正常
  4094. {
  4095. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4096. }
  4097. }
  4098. /// <summary>
  4099. /// 生产模式传感器标定1
  4100. /// </summary>
  4101. /// <param name="sender"></param>
  4102. /// <param name="e"></param>
  4103. private void buttonFacModeSet1_Click(object sender, EventArgs e)
  4104. {
  4105. var ConfigParam = new byte[4];
  4106. for (int i = 0; i < 4; i++)
  4107. ConfigParam[i] = 0;
  4108. ushort uwDataTemp = 0;
  4109. try
  4110. {
  4111. uwDataTemp = 1;//负载序号
  4112. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4113. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4114. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal1.Text) * 10); ;//负载值0.1Nm
  4115. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4116. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4117. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4118. Delay_ms(200);
  4119. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4120. //标定1判断
  4121. label1_TorqueCal1.BackColor = Color.Red;
  4122. WriteACK = false;
  4123. ACK_WaitCnt = 0;
  4124. Delay_ms(200);
  4125. if (WriteACK == true) //力矩读取正常
  4126. {
  4127. WriteACK = false;
  4128. //获取标定1
  4129. ushort K1_T, K1;
  4130. K1_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal1.Text) * 10);
  4131. K1 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC1.Text));
  4132. //比较标定1
  4133. if ((K1_T == TorqueParamsForm.K1.T) && (K1 <= TorqueParamsForm.K1.Max) && (K1 >= TorqueParamsForm.K1.Min))
  4134. {
  4135. label1_TorqueCal1.BackColor = Color.Green;
  4136. }
  4137. else
  4138. {
  4139. MessageBoxTimeOut.Show("力矩传感器标定1超范围!\r\n" + "加载扭矩:" + K1_T.ToString() + "\r\n标定值:" + K1.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4140. }
  4141. }
  4142. else //力矩读取不正常
  4143. {
  4144. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4145. }
  4146. }
  4147. catch (Exception)
  4148. {
  4149. timer_500ms.Enabled = false;
  4150. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4151. timer_500ms.Enabled = true;
  4152. }
  4153. }
  4154. /// <summary>
  4155. /// 生产模式传感器标定2
  4156. /// </summary>
  4157. /// <param name="sender"></param>
  4158. /// <param name="e"></param>
  4159. private void buttonFacModeSet2_Click(object sender, EventArgs e)
  4160. {
  4161. var ConfigParam = new byte[4];
  4162. for (int i = 0; i < 4; i++)
  4163. ConfigParam[i] = 0;
  4164. ushort uwDataTemp = 0;
  4165. try
  4166. {
  4167. uwDataTemp = 2;//负载序号
  4168. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4169. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4170. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal2.Text) * 10); ;//负载值0.1Nm
  4171. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4172. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4173. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4174. Delay_ms(200);
  4175. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4176. //标定2判断
  4177. label1_TorqueCal2.BackColor = Color.Red;
  4178. WriteACK = false;
  4179. ACK_WaitCnt = 0;
  4180. Delay_ms(200);
  4181. if (WriteACK == true) //力矩读取正常
  4182. {
  4183. WriteACK = false;
  4184. //获取标定2
  4185. ushort K2_T, K2;
  4186. K2_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal2.Text) * 10);
  4187. K2 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC2.Text));
  4188. //比较标定1
  4189. if ((K2_T == TorqueParamsForm.K2.T) && (K2 <= TorqueParamsForm.K2.Max) && (K2 >= TorqueParamsForm.K2.Min))
  4190. {
  4191. label1_TorqueCal2.BackColor = Color.Green;
  4192. }
  4193. else
  4194. {
  4195. MessageBoxTimeOut.Show("力矩传感器标定2超范围!\r\n" + "加载扭矩:" + K2_T.ToString() + "\r\n标定值:" + K2.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4196. }
  4197. }
  4198. else //力矩读取不正常
  4199. {
  4200. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4201. }
  4202. }
  4203. catch (Exception)
  4204. {
  4205. timer_500ms.Enabled = false;
  4206. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4207. timer_500ms.Enabled = true;
  4208. }
  4209. }
  4210. /// <summary>
  4211. /// 生产模式传感器标定3
  4212. /// </summary>
  4213. /// <param name="sender"></param>
  4214. /// <param name="e"></param>
  4215. private void buttonFacModeSet3_Click(object sender, EventArgs e)
  4216. {
  4217. var ConfigParam = new byte[4];
  4218. for (int i = 0; i < 4; i++)
  4219. ConfigParam[i] = 0;
  4220. ushort uwDataTemp = 0;
  4221. try
  4222. {
  4223. uwDataTemp = 3;//负载序号
  4224. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4225. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4226. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal3.Text) * 10); ;//负载值0.1Nm
  4227. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4228. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4229. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4230. Delay_ms(200);
  4231. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4232. //标定3判断
  4233. label1_TorqueCal3.BackColor = Color.Red;
  4234. WriteACK = false;
  4235. ACK_WaitCnt = 0;
  4236. Delay_ms(200);
  4237. if (WriteACK == true) //力矩读取正常
  4238. {
  4239. WriteACK = false;
  4240. //获取标定3
  4241. ushort K3_T, K3;
  4242. K3_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal3.Text) * 10);
  4243. K3 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC3.Text));
  4244. //比较标定1
  4245. if ((K3_T == TorqueParamsForm.K3.T) && (K3 <= TorqueParamsForm.K3.Max) && (K3 >= TorqueParamsForm.K3.Min))
  4246. {
  4247. label1_TorqueCal3.BackColor = Color.Green;
  4248. }
  4249. else
  4250. {
  4251. MessageBoxTimeOut.Show("力矩传感器标定3超范围!\r\n" + "加载扭矩:" + K3_T.ToString() + "\r\n标定值:" + K3.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4252. }
  4253. }
  4254. else //力矩读取不正常
  4255. {
  4256. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4257. }
  4258. }
  4259. catch (Exception)
  4260. {
  4261. timer_500ms.Enabled = false;
  4262. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4263. timer_500ms.Enabled = true;
  4264. }
  4265. }
  4266. /// <summary>
  4267. /// 生产模式传感器标定4
  4268. /// </summary>
  4269. /// <param name="sender"></param>
  4270. /// <param name="e"></param>
  4271. private void buttonFacModeSet4_Click(object sender, EventArgs e)
  4272. {
  4273. var ConfigParam = new byte[4];
  4274. for (int i = 0; i < 4; i++)
  4275. ConfigParam[i] = 0;
  4276. ushort uwDataTemp = 0;
  4277. try
  4278. {
  4279. WriteACK = false;
  4280. uwDataTemp = 4;//负载序号
  4281. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4282. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4283. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal4.Text) * 10); ;//负载值0.1Nm
  4284. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4285. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4286. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4287. Delay_ms(200);
  4288. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4289. //标定4判断
  4290. label1_TorqueCal4.BackColor = Color.Red;
  4291. WriteACK = false;
  4292. ACK_WaitCnt = 0;
  4293. Delay_ms(200);
  4294. if (WriteACK == true) //力矩读取正常
  4295. {
  4296. //获取标定4
  4297. ushort K4_T, K4;
  4298. K4_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal4.Text) * 10);
  4299. K4 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC4.Text));
  4300. //比较标定1
  4301. if ((K4_T == TorqueParamsForm.K4.T) && (K4 <= TorqueParamsForm.K4.Max) && (K4 >= TorqueParamsForm.K4.Min))
  4302. {
  4303. label1_TorqueCal4.BackColor = Color.Green;
  4304. }
  4305. else
  4306. {
  4307. MessageBoxTimeOut.Show("力矩传感器标定4超范围!\r\n" + "加载扭矩:" + K4_T.ToString() + "\r\n标定值:" + K4.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4308. }
  4309. }
  4310. else //力矩读取不正常
  4311. {
  4312. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4313. }
  4314. }
  4315. catch (Exception)
  4316. {
  4317. timer_500ms.Enabled = false;
  4318. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4319. timer_500ms.Enabled = true;
  4320. }
  4321. }
  4322. /// <summary>
  4323. /// 生产模式开关灯
  4324. /// </summary>
  4325. /// <param name="sender"></param>
  4326. /// <param name="e"></param>
  4327. bool LightSwitchStatus = false;
  4328. private void button_FacModeLightSW_Click(object sender, EventArgs e)
  4329. {
  4330. var CtrlCode = new byte[2];
  4331. CtrlCode[0] = 0x00;
  4332. if (LightSwitchStatus)
  4333. {
  4334. CtrlCode[1] = 0xF0;
  4335. button_FacModeLightSW.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(128)))));
  4336. }
  4337. else
  4338. {
  4339. CtrlCode[1] = 0xF1;
  4340. button_FacModeLightSW.BackColor = Color.Yellow;
  4341. }
  4342. if (mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode))
  4343. {
  4344. LightSwitchStatus = !LightSwitchStatus;
  4345. comboBox_LightSwitch.SelectedIndex = LightSwitchStatus ? 0 : 1;
  4346. comboBox_OBC_LightSw.SelectedIndex = LightSwitchStatus ? 0 : 1;
  4347. }
  4348. }
  4349. /// <summary>
  4350. /// 生产模式电机控制
  4351. /// </summary>
  4352. /// <param name="sender"></param>
  4353. /// <param name="e"></param>
  4354. bool MotorRunStatus = false;
  4355. private void button_FacModeMotorRun_Click(object sender, EventArgs e)
  4356. {
  4357. string DebugDefaultInfo = "";
  4358. //获取调试信息
  4359. if (richTextBox_DebugParam.Text == string.Empty)
  4360. {
  4361. richTextBox_DebugParam.Clear();
  4362. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  4363. }
  4364. Delay_ms(200);
  4365. DebugDefaultInfo = richTextBox_DebugParam.Text;
  4366. //获取参数
  4367. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  4368. if (strDataTemp.Length != 29)
  4369. {
  4370. timer_500ms.Enabled = false;
  4371. MessageBox.Show("数据格式不正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4372. timer_500ms.Enabled = true;
  4373. return;
  4374. }
  4375. //设置参数
  4376. var ConfigParam = new byte[60];
  4377. for (int i = 0; i < 60; i++)
  4378. ConfigParam[i] = 0;
  4379. ConfigParam[0] = 0x00;
  4380. ushort uwDataTemp = 0;
  4381. if (!MotorRunStatus) //停止状态
  4382. {
  4383. //设置速度环
  4384. strDataTemp[0] = "整体运行模式=3";
  4385. //发送数据
  4386. try
  4387. {
  4388. for (int i = 0; i < strDataTemp.Length; i++)
  4389. {
  4390. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  4391. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  4392. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  4393. }
  4394. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  4395. return;
  4396. }
  4397. catch (Exception)
  4398. {
  4399. timer_500ms.Enabled = false;
  4400. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4401. timer_500ms.Enabled = true;
  4402. }
  4403. Delay_ms(200);
  4404. //设置转速百分比100%
  4405. textBox_MotorSpeedPercent.Text = "100";
  4406. ConfigParam[0] = (byte)100;
  4407. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, ConfigParam);
  4408. MotorRunStatus = !MotorRunStatus;
  4409. button_FacModeMotorRun.BackColor = Color.Yellow;
  4410. Delay_ms(200);
  4411. //电机进入配置模式
  4412. var RunMode = new byte[1];
  4413. RunMode[0] = 0x01;
  4414. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  4415. }
  4416. else //运转状态
  4417. {
  4418. //设置转速百分比0%
  4419. textBox_MotorSpeedPercent.Text = "0";
  4420. ConfigParam[0] = (byte)0;
  4421. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, ConfigParam);
  4422. MotorRunStatus = !MotorRunStatus;
  4423. button_FacModeMotorRun.BackColor = Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
  4424. Delay_ms(200);
  4425. //还原为原始值
  4426. strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  4427. try
  4428. {
  4429. for (int i = 0; i < strDataTemp.Length; i++)
  4430. {
  4431. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  4432. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  4433. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  4434. }
  4435. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  4436. return;
  4437. }
  4438. catch (Exception)
  4439. {
  4440. timer_500ms.Enabled = false;
  4441. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4442. timer_500ms.Enabled = true;
  4443. }
  4444. Delay_ms(200);
  4445. //电机退出配置模式
  4446. var RunMode = new byte[1];
  4447. RunMode[0] = 0x00;
  4448. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  4449. }
  4450. }
  4451. /// <summary>
  4452. /// 生产模式写入型号
  4453. /// </summary>
  4454. /// <param name="sender"></param>
  4455. /// <param name="e"></param>
  4456. private void button_FacModeSetName_Click(object sender, EventArgs e)
  4457. {
  4458. string Mode = textBox_FacModeName.Text;
  4459. var ModeArray = new byte[16];
  4460. for (ushort i = 0; i < Mode.Length; i++)
  4461. {
  4462. ModeArray[i] = (byte)Mode[i];
  4463. }
  4464. if (Mode.Length < 16)
  4465. {
  4466. ModeArray[Mode.Length] = (byte)'.';
  4467. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  4468. {
  4469. ModeArray[Mode.Length + 1 + i] = 0x20;
  4470. }
  4471. }
  4472. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  4473. }
  4474. /// <summary>
  4475. /// 生产模式写入SN
  4476. /// </summary>
  4477. /// <param name="sender"></param>
  4478. /// <param name="e"></param>
  4479. private void Button_FacModeSetNum_Click(object sender, EventArgs e)
  4480. {
  4481. string SN = textBox_FacModeNum.Text;
  4482. var SNArray = new byte[16];
  4483. for (ushort i = 0; i < SN.Length; i++)
  4484. {
  4485. SNArray[i] = (byte)SN[i];
  4486. }
  4487. if (SN.Length < 16)
  4488. {
  4489. SNArray[SN.Length] = (byte)'.';
  4490. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  4491. {
  4492. SNArray[SN.Length + 1 + i] = 0x20;
  4493. }
  4494. }
  4495. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  4496. }
  4497. /// <summary>
  4498. /// 生产模式读取版本信息
  4499. /// </summary>
  4500. /// <param name="sender"></param>
  4501. /// <param name="e"></param>
  4502. private void Button_FacModeReadVer_Click_1(object sender, EventArgs e)
  4503. {
  4504. textBox_Model.Text = "---";
  4505. textBox_SN.Text = "---";
  4506. textBox_HW.Text = "---";
  4507. textBox_FW.Text = "---";
  4508. textBox_SP.Text = "---";
  4509. textBox_OBC_ReadModel.Text = "---";
  4510. textBox_OBC_ReadSN.Text = "---";
  4511. textBox_OBC_ReadHW.Text = "---";
  4512. textBox_OBC_ReadFW.Text = "---";
  4513. textBox_OBC_ReadSP.Text = "---";
  4514. textBox_FacModeName.Text = "---";
  4515. textBox_FacModeNum.Text = "---";
  4516. textBox_FacModeHW.Text = "---";
  4517. textBox_FacModeFW.Text = "---";
  4518. textBox_FacModeSP.Text = "---";
  4519. textBox_FacModeGit.Text = "---";
  4520. Class_Motor_Ver.Mode = "---";
  4521. Class_Motor_Ver.SN = "---";
  4522. Class_Motor_Ver.HW = "---";
  4523. Class_Motor_Ver.FW = "---";
  4524. Class_Motor_Ver.Special = "---";
  4525. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  4526. }
  4527. /// <summary>
  4528. /// 生产模式写入生产信息
  4529. /// </summary>
  4530. /// <param name="sender"></param>
  4531. /// <param name="e"></param>
  4532. private void Button_FacModeSetMacDate_Click(object sender, EventArgs e)
  4533. {
  4534. var MACArray = new byte[32];
  4535. string MacDefaultInfo = "";
  4536. string MacAddDefaultInfo = "";
  4537. string MacDateDefaultInfo = DateTime.Now.ToString("yyyyMMdd");
  4538. string MacPPDefaultInfo = "";
  4539. do
  4540. {
  4541. //填入生产商
  4542. if (toolStripTextBox_MAC.Text == string.Empty)
  4543. {
  4544. break;
  4545. }
  4546. MacDefaultInfo = toolStripTextBox_MAC.Text;
  4547. for (ushort i = 0; i < MacDefaultInfo.Length; i++)
  4548. {
  4549. MACArray[i] = (byte)MacDefaultInfo[i];
  4550. }
  4551. if (MacDefaultInfo.Length < 8)
  4552. {
  4553. MACArray[MacDefaultInfo.Length] = (byte)'.';
  4554. for (ushort i = 0; i < 8 - MacDefaultInfo.Length - 1; i++)
  4555. {
  4556. MACArray[MacDefaultInfo.Length + 1 + i] = 0x20;
  4557. }
  4558. }
  4559. //填入生产地
  4560. if (toolStripTextBoxMACAddr.Text == string.Empty)
  4561. {
  4562. break;
  4563. }
  4564. MacAddDefaultInfo = toolStripTextBoxMACAddr.Text;
  4565. for (ushort i = 0; i < MacAddDefaultInfo.Length; i++)
  4566. {
  4567. MACArray[8 + i] = (byte)MacAddDefaultInfo[i];
  4568. }
  4569. if (MacAddDefaultInfo.Length < 8)
  4570. {
  4571. MACArray[MacAddDefaultInfo.Length + 8] = (byte)'.';
  4572. for (ushort i = 0; i < 8 - MacAddDefaultInfo.Length - 1; i++)
  4573. {
  4574. MACArray[MacAddDefaultInfo.Length + 1 + i + 8] = 0x20;
  4575. }
  4576. }
  4577. //填入生产日期
  4578. if (toolStripTextBox_MACDate.Text == string.Empty)
  4579. {
  4580. break;
  4581. }
  4582. MacDateDefaultInfo = toolStripTextBox_MACDate.Text;
  4583. for (ushort i = 0; i < MacDateDefaultInfo.Length; i++)
  4584. {
  4585. MACArray[16 + i] = (byte)MacDateDefaultInfo[i];
  4586. }
  4587. if (MacDateDefaultInfo.Length < 8)
  4588. {
  4589. MACArray[MacDateDefaultInfo.Length + 16] = (byte)'.';
  4590. for (ushort i = 0; i < 8 - MacDateDefaultInfo.Length - 1; i++)
  4591. {
  4592. MACArray[MacDateDefaultInfo.Length + 1 + i + 16] = 0x20;
  4593. }
  4594. }
  4595. //填入产品标识
  4596. if (toolStripTextBox_MACPD.Text == string.Empty)
  4597. {
  4598. break;
  4599. }
  4600. MacPPDefaultInfo = toolStripTextBox_MACPD.Text;
  4601. for (ushort i = 0; i < MacPPDefaultInfo.Length; i++)
  4602. {
  4603. MACArray[24 + i] = (byte)MacPPDefaultInfo[i];
  4604. }
  4605. if (MacPPDefaultInfo.Length < 8)
  4606. {
  4607. MACArray[MacPPDefaultInfo.Length + 24] = (byte)'.';
  4608. for (ushort i = 0; i < 8 - MacPPDefaultInfo.Length - 1; i++)
  4609. {
  4610. MACArray[MacPPDefaultInfo.Length + 1 + i + 24] = 0x20;
  4611. }
  4612. }
  4613. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  4614. return;
  4615. } while (false);
  4616. timer_500ms.Enabled = false;
  4617. MessageBox.Show("生产信息配置不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4618. timer_500ms.Enabled = true;
  4619. }
  4620. /// <summary>
  4621. /// 生产模式保存测试页面
  4622. /// </summary>
  4623. /// <param name="sender"></param>
  4624. /// <param name="e"></param>
  4625. private void Button_FacModeSaveResult_Click(object sender, EventArgs e)
  4626. {
  4627. Button_FacModeSaveResult.Text = "存储中…";
  4628. string[] AssistParams = new string[15];
  4629. do
  4630. {
  4631. //读取一次马达参数
  4632. richTextBox_MotorParam.Clear();
  4633. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break; ;
  4634. Delay_ms(100);
  4635. //读取一次整车参数
  4636. richTextBox_BikeParam.Clear();
  4637. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  4638. Delay_ms(100);
  4639. //读取一次整车参数2
  4640. richTextBox_BikeParam2.Clear();
  4641. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null)) break;
  4642. Delay_ms(100);
  4643. //读取一次控制参数
  4644. richTextBox_ControlParam.Clear();
  4645. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  4646. Delay_ms(100);
  4647. //查询传感器
  4648. richTextBox_SensorParam.Clear();
  4649. textBox_FacModeSensorADC0.Text = "";
  4650. textBox_FacModeSensorADC1.Text = "";
  4651. textBox_FacModeSensorADC2.Text = "";
  4652. textBox_FacModeSensorADC3.Text = "";
  4653. textBox_FacModeSensorADC4.Text = "";
  4654. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  4655. Delay_ms(100);
  4656. //读取15次助力参数
  4657. for (int i = 1; i <= 15; i++)
  4658. {
  4659. var ConfigParam = new byte[4];
  4660. richTextBox_AssistParam.Clear();
  4661. ConfigParam[0] = (byte)(i & 0xFF);
  4662. ConfigParam[1] = (byte)(i >> 8);
  4663. ConfigParam[2] = (byte)(((i >= 5) ? 5 : i) & 0xFF);
  4664. ConfigParam[3] = (byte)(((i >= 5) ? 5 : i) >> 8);
  4665. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  4666. Delay_ms(200);
  4667. AssistParams[i - 1] = richTextBox_AssistParam.Text + "\r\n";
  4668. }
  4669. //读取一次用户骑行参数
  4670. richTextBox_UsrRidesParam.Clear();
  4671. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  4672. Delay_ms(100);
  4673. //读取一次调试信息
  4674. richTextBox_DebugParam.Clear();
  4675. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  4676. Delay_ms(100);
  4677. //读取一次历史信息
  4678. richTextBox_Record.Clear();
  4679. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  4680. Delay_ms(100);
  4681. //读取一次电机运行信息
  4682. var CtrlCode = new byte[2];
  4683. CtrlCode[0] = 0x00;
  4684. CtrlCode[1] = 0xF0;
  4685. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode)) break;
  4686. Delay_ms(100);
  4687. //读取一次版本信息
  4688. textBox_Model.Text = "---";
  4689. textBox_SN.Text = "---";
  4690. textBox_HW.Text = "---";
  4691. textBox_FW.Text = "---";
  4692. textBox_OBC_ReadModel.Text = "---";
  4693. textBox_OBC_ReadSN.Text = "---";
  4694. textBox_OBC_ReadHW.Text = "---";
  4695. textBox_OBC_ReadFW.Text = "---";
  4696. textBox_FacModeName.Text = "---";
  4697. textBox_FacModeNum.Text = "---";
  4698. textBox_FacModeHW.Text = "---";
  4699. textBox_FacModeFW.Text = "---";
  4700. Class_Motor_Ver.Mode = "---";
  4701. Class_Motor_Ver.SN = "---";
  4702. Class_Motor_Ver.HW = "---";
  4703. Class_Motor_Ver.FW = "---";
  4704. Class_Motor_Ver.Special = "---";
  4705. if (!mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null)) break;
  4706. Delay_ms(100);
  4707. //读取一次生产信息
  4708. textBox_MAC.Text = "";
  4709. textBox_MACAdd.Text = "";
  4710. textBox_MACDate.Text = "";
  4711. textBox_PP.Text = "";
  4712. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  4713. Delay_ms(100);
  4714. //读取一次自定义信息
  4715. textBox_User1.Text = "---";
  4716. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  4717. Delay_ms(100);
  4718. textBox_User2.Text = "---";
  4719. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  4720. Delay_ms(100);
  4721. textBox_User3.Text = "---";
  4722. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  4723. Delay_ms(100);
  4724. //读取一次密钥
  4725. textBox_Key.Text = "---";
  4726. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  4727. Delay_ms(100);
  4728. //读取一次存储标志
  4729. radioButton_EE_SaveYes.Checked = false;
  4730. radioButton_EE_SaveNo.Checked = false;
  4731. radioButton_SIP_SaveYes.Checked = false;
  4732. radioButton_SIP_SaveNo.Checked = false;
  4733. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  4734. Delay_ms(100);
  4735. //读取一次MOS内阻校准参数
  4736. foreach (Control c in groupBox21.Controls)
  4737. {
  4738. if (c is TextBox)
  4739. c.Text = "";
  4740. }
  4741. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  4742. Delay_ms(100);
  4743. //提示检查
  4744. #if false
  4745. timer_1s.Enabled = false;
  4746. if (MessageBox.Show("请检查信息是否完整!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  4747. {
  4748. MessageBox.Show("请检查参数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4749. timer_1s.Enabled = true;
  4750. return;
  4751. }
  4752. timer_1s.Enabled = true;
  4753. Delay_ms(200);
  4754. #endif
  4755. //判断数据是否有效
  4756. if ((textBox_FacModeName.Text == "---") || (textBox_FacModeNum.Text == "---"))
  4757. {
  4758. MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4759. break;
  4760. }
  4761. if ((textBox_FacModeName.Text == string.Empty) || (textBox_FacModeNum.Text == string.Empty))
  4762. {
  4763. MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4764. break;
  4765. }
  4766. //设置文件存储路径
  4767. string Save_Path = localInfo.LocalPath + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
  4768. string PD_PathName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_"); ;
  4769. Save_Path += PD_PathName;
  4770. if (!Directory.Exists(Save_Path))
  4771. Directory.CreateDirectory(Save_Path);
  4772. //保存页面
  4773. string PIC_SaveFileName = "";
  4774. Double scaleX = PrimaryScreen.ScaleX;
  4775. Double scaleY = PrimaryScreen.ScaleY;
  4776. //保存页面
  4777. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  4778. Graphics g = Graphics.FromImage(bit);
  4779. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  4780. PIC_SaveFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_测试页面" + ".png";
  4781. bit.Save(PIC_SaveFileName);
  4782. //保存数据
  4783. string DataFileName = "";
  4784. string FileInfo = "";
  4785. DataFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_记录数据" + ".txt";
  4786. FileInfo += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  4787. FileInfo += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  4788. FileInfo += "\r\n";
  4789. FileInfo += "[电机信息]\r\n";
  4790. FileInfo += "电机型号: " + textBox_FacModeName.Text + "\r\n";
  4791. FileInfo += "电机编号: " + textBox_FacModeNum.Text + "\r\n";
  4792. FileInfo += "硬件版本: " + textBox_HW.Text + "\r\n";
  4793. FileInfo += "软件版本: " + textBox_FW.Text + "\r\n";
  4794. FileInfo += "软件标识: " + textBox_SP.Text + "\r\n";
  4795. FileInfo += "Git信息: " + textBox_FacModeGit.Text + "\r\n";
  4796. FileInfo += "\r\n";
  4797. FileInfo += "[马达参数]\r\n";
  4798. FileInfo += richTextBox_MotorParam.Text + "\r\n";
  4799. FileInfo += "\r\n";
  4800. FileInfo += "[整车参数]\r\n";
  4801. FileInfo += richTextBox_BikeParam.Text + "\r\n";
  4802. FileInfo += "\r\n";
  4803. FileInfo += "[控制参数]\r\n";
  4804. FileInfo += richTextBox_ControlParam.Text + "\r\n";
  4805. FileInfo += "\r\n";
  4806. FileInfo += "[传感器参数]\r\n";
  4807. FileInfo += richTextBox_SensorParam.Text + "\r\n";
  4808. FileInfo += "\r\n";
  4809. FileInfo += "[助力参数]\r\n";
  4810. for(int i=0;i<15;i++)
  4811. {
  4812. FileInfo += AssistParams[i] + "\r\n";
  4813. }
  4814. FileInfo += "[调试参数]\r\n";
  4815. FileInfo += richTextBox_DebugParam.Text + "\r\n";
  4816. FileInfo += "\r\n";
  4817. FileInfo += "[历史信息]\r\n";
  4818. FileInfo += richTextBox_Record.Text + "\r\n";
  4819. FileInfo += "\r\n";
  4820. FileInfo += "[MOS内阻校准参数]\r\n";
  4821. FileInfo += textBox_MOS_K1.Text + ", ";
  4822. FileInfo += textBox_MOS_K2.Text + ", ";
  4823. FileInfo += textBox_MOS_K3.Text + ", ";
  4824. FileInfo += textBox_MOS_K4.Text + ", ";
  4825. FileInfo += textBox_MOS_K5.Text + ", ";
  4826. FileInfo += textBox_MOS_R1.Text + ", ";
  4827. FileInfo += textBox_MOS_R2.Text + ", ";
  4828. FileInfo += textBox_MOS_R3.Text + "\r\n";
  4829. FileInfo += "\r\n";
  4830. FileInfo += "[整车参数2]\r\n";
  4831. FileInfo += richTextBox_BikeParam2.Text + "\r\n";
  4832. FileInfo += "\r\n";
  4833. FileInfo += "[用户骑行参数]\r\n";
  4834. FileInfo += richTextBox_UsrRidesParam.Text + "\r\n";
  4835. FileInfo += "\r\n";
  4836. FileInfo += "[生产信息]\r\n";
  4837. FileInfo += "生产商: " + textBox_MAC.Text + "\r\n";
  4838. FileInfo += "生产地: " + textBox_MACAdd.Text + "\r\n";
  4839. FileInfo += "生产日期: " + textBox_MACDate.Text + "\r\n";
  4840. FileInfo += "产品标识: " + textBox_PP.Text + "\r\n";
  4841. FileInfo += "\r\n";
  4842. FileInfo += "[自定义信息]\r\n";
  4843. FileInfo += "自定义1: " + textBox_User1.Text + "\r\n";
  4844. FileInfo += "自定义2: " + textBox_User2.Text + "\r\n";
  4845. FileInfo += "自定义3: " + textBox_User3.Text + "\r\n";
  4846. FileInfo += "\r\n";
  4847. FileInfo += "[校验密钥]\r\n";
  4848. FileInfo += textBox_Key.Text + "\r\n";
  4849. FileInfo += "\r\n";
  4850. FileInfo += "[存储标志]\r\n";
  4851. FileInfo += "EEPROM: " + ((radioButton_EE_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  4852. FileInfo += "SIP: " + ((radioButton_SIP_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  4853. FileInfo += "\r\n";
  4854. FileInfo += Local_HdInformation;
  4855. FileInfo += "\r\n";
  4856. FileInfo += "文件格式: V2.0\r\n";
  4857. System.IO.File.WriteAllText(DataFileName, FileInfo);
  4858. Delay_ms(1000);
  4859. timer_500ms.Enabled = false;
  4860. MessageBox.Show("存储完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  4861. timer_500ms.Enabled = true;
  4862. //数据上传
  4863. if (myFtp.IsNetConnected == true)
  4864. {
  4865. string DataNow = DateTime.Now.ToString("yyyy-MM-dd");
  4866. //检查路径
  4867. if (myFtp.DirectoryExist("\\", toolStripTextBox_ServerPath.Text) == false)
  4868. {
  4869. myFtp.MakeDir(toolStripTextBox_ServerPath.Text);
  4870. }
  4871. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text, "Samples") == false)
  4872. {
  4873. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples");
  4874. }
  4875. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples", DataNow) == false)
  4876. {
  4877. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow);
  4878. }
  4879. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow, PD_PathName) == false)
  4880. {
  4881. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4882. }
  4883. //上传文件
  4884. bool result1 = myFtp.UploadFile(PIC_SaveFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4885. bool result2 = myFtp.UploadFile(DataFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4886. if ((result1 & result2) == true)
  4887. {
  4888. MessageBoxTimeOut.Show("数据已上传!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  4889. }
  4890. else
  4891. {
  4892. timer_500ms.Enabled = false;
  4893. MessageBox.Show("数据上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4894. timer_500ms.Enabled = true;
  4895. }
  4896. }
  4897. else
  4898. {
  4899. timer_500ms.Enabled = false;
  4900. MessageBox.Show("服务器断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4901. timer_500ms.Enabled = true;
  4902. }
  4903. Button_FacModeSaveResult.Text = "保存数据";
  4904. return;
  4905. } while (false);
  4906. timer_500ms.Enabled = false;
  4907. MessageBox.Show("保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4908. timer_500ms.Enabled = true;
  4909. Button_FacModeSaveResult.Text = "保存数据";
  4910. }
  4911. /// <summary>
  4912. /// 工具箱页面保存
  4913. /// </summary>
  4914. /// <param name="sender"></param>
  4915. /// <param name="e"></param>
  4916. private void 页面保存ToolStripMenuItem_Click(object sender, EventArgs e)
  4917. {
  4918. Double scaleX = PrimaryScreen.ScaleX;
  4919. Double scaleY = PrimaryScreen.ScaleY;
  4920. //保存页面
  4921. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  4922. Graphics g = Graphics.FromImage(bit);
  4923. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  4924. SaveFileDialog sf = new SaveFileDialog();
  4925. sf.Title = "页面保存";
  4926. sf.FileName = "MotorInfo_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".png";
  4927. sf.Filter = "图片|*.png";
  4928. timer_500ms.Enabled = false;
  4929. if (sf.ShowDialog() == DialogResult.OK)
  4930. {
  4931. bit.Save(sf.FileName);//默认保存格式为PNG,保存成jpg格式质量不是很好
  4932. }
  4933. timer_500ms.Enabled = true;
  4934. }
  4935. /// <summary>
  4936. /// 生产模式关机
  4937. /// </summary>
  4938. /// <param name="sender"></param>
  4939. /// <param name="e"></param>
  4940. private void Button_FacModePowerOff_Click(object sender, EventArgs e)
  4941. {
  4942. var Code_Off = new byte[5];
  4943. var Code_Reset = new byte[5];
  4944. Code_Off[0] = (byte)'O';
  4945. Code_Off[1] = (byte)'F';
  4946. Code_Off[2] = (byte)'F';
  4947. Code_Off[3] = (byte)'.';
  4948. Code_Off[4] = (byte)'.';
  4949. Code_Reset[0] = (byte)'R';
  4950. Code_Reset[1] = (byte)'E';
  4951. Code_Reset[2] = (byte)'S';
  4952. Code_Reset[3] = (byte)'E';
  4953. Code_Reset[4] = (byte)'T';
  4954. timer_500ms.Enabled = false;
  4955. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  4956. {
  4957. timer_500ms.Enabled = true;
  4958. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  4959. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  4960. PowerOffAckStatus = false;
  4961. Delay_ms(250);
  4962. int TryCnt = 3;
  4963. while ((TryCnt--) >= 0)
  4964. {
  4965. if (!PowerOffAckStatus)
  4966. {
  4967. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  4968. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  4969. PowerOffAckStatus = false;
  4970. Delay_ms(250);
  4971. }
  4972. else break;
  4973. }
  4974. if (PowerOffAckStatus)
  4975. {
  4976. timer_500ms.Enabled = false;
  4977. MessageBox.Show("已关机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  4978. timer_500ms.Enabled = true;
  4979. }
  4980. else
  4981. {
  4982. timer_500ms.Enabled = false;
  4983. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4984. timer_500ms.Enabled = true;
  4985. }
  4986. }
  4987. timer_500ms.Enabled = true;
  4988. }
  4989. //仪表电源键按下
  4990. private void button_OBC_ButtonPower_Click(object sender, EventArgs e)
  4991. {
  4992. var Code = new byte[2];
  4993. Code[0] = 0;
  4994. Code[1] = 0b00100000;
  4995. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4996. }
  4997. /// <summary>
  4998. /// 仪表加键按下
  4999. /// </summary>
  5000. /// <param name="sender"></param>
  5001. /// <param name="e"></param>
  5002. private void button_OBC_ButtonAcc_Click(object sender, EventArgs e)
  5003. {
  5004. var Code = new byte[2];
  5005. Code[0] = 0;
  5006. Code[1] = 0b00010000;
  5007. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5008. }
  5009. /// <summary>
  5010. /// 仪表减键按下
  5011. /// </summary>
  5012. /// <param name="sender"></param>
  5013. /// <param name="e"></param>
  5014. private void button_OBC_ButtonDec_Click(object sender, EventArgs e)
  5015. {
  5016. var Code = new byte[2];
  5017. Code[0] = 0;
  5018. Code[1] = 0b00001000;
  5019. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5020. }
  5021. /// <summary>
  5022. /// 仪表Walk键按下
  5023. /// </summary>
  5024. /// <param name="sender"></param>
  5025. /// <param name="e"></param>
  5026. private void button_OBC_ButtonWalk_Click(object sender, EventArgs e)
  5027. {
  5028. var Code = new byte[2];
  5029. Code[0] = 0;
  5030. Code[1] = 0b00000100;
  5031. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5032. }
  5033. /// <summary>
  5034. /// 仪表Light键按下
  5035. /// </summary>
  5036. /// <param name="sender"></param>
  5037. /// <param name="e"></param>
  5038. private void button_OBC_ButtonLight_Click(object sender, EventArgs e)
  5039. {
  5040. var Code = new byte[2];
  5041. Code[0] = 0;
  5042. Code[1] = 0b00000010;
  5043. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5044. }
  5045. /// <summary>
  5046. /// 仪表Set键按下
  5047. /// </summary>
  5048. /// <param name="sender"></param>
  5049. /// <param name="e"></param>
  5050. private void button_OBC_ButtonSet_Click(object sender, EventArgs e)
  5051. {
  5052. var Code = new byte[2];
  5053. Code[0] = 0;
  5054. Code[1] = 0b00000001;
  5055. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5056. }
  5057. /// <summary>
  5058. /// 导出电机故障日志
  5059. /// </summary>
  5060. /// <param name="sender"></param>
  5061. /// <param name="e"></param>
  5062. private void button_ExportLog_Click(object sender, EventArgs e)
  5063. {
  5064. var Address = new byte[4];
  5065. UInt32 Address_Begin;
  5066. UInt32 Addres_End;
  5067. string textBox_Address_Begin = textBox_LogAddrBegin.Text;
  5068. string textBox_Address_End = textBox_LogAddrEnd.Text;
  5069. richTextBox_Record.Clear();
  5070. textBox_LogAddrBegin.ReadOnly = true;
  5071. textBox_LogAddrEnd.ReadOnly = true;
  5072. if (!mySerialProcess.mySerial.IsOpen)
  5073. {
  5074. timer_500ms.Enabled = false;
  5075. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5076. timer_500ms.Enabled = true;
  5077. return;
  5078. }
  5079. if ((textBox_Address_Begin == string.Empty) || (textBox_Address_End == string.Empty))
  5080. {
  5081. timer_500ms.Enabled = false;
  5082. MessageBox.Show("请输入日志存储起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5083. timer_500ms.Enabled = true;
  5084. return;
  5085. }
  5086. else
  5087. {
  5088. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin, false);
  5089. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  5090. Address = mySerialProcess.HexStringToBytes(textBox_Address_End, false);
  5091. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  5092. if (Addres_End <= Address_Begin)
  5093. {
  5094. timer_500ms.Enabled = false;
  5095. MessageBox.Show("结束地址应大于起始地址!", "提示");
  5096. timer_500ms.Enabled = true;
  5097. return;
  5098. }
  5099. else if (((Addres_End - Address_Begin + 1) % 128) != 0) //
  5100. {
  5101. timer_500ms.Enabled = false;
  5102. MessageBox.Show("(结束地址 - 起始地址 + 1)应为128整数倍!", "提示");
  5103. timer_500ms.Enabled = true;
  5104. return;
  5105. }
  5106. else
  5107. {
  5108. UInt32 ReadCount = 0;
  5109. button_ExportLog.Text = "导出中...";
  5110. button_ExportLog.Enabled = false;
  5111. ReadCount = (Addres_End - Address_Begin + 1) / 128;
  5112. for (ushort i = 0; i < ReadCount; i++)
  5113. {
  5114. var SendByte = new byte[8];
  5115. UInt32 Address_Temp_Begin;
  5116. UInt32 Address_Temp_End;
  5117. Address_Temp_Begin = Address_Begin + 128 * (UInt32)i;
  5118. SendByte[0] = (byte)(Address_Temp_Begin >> 24);
  5119. SendByte[1] = (byte)(Address_Temp_Begin >> 16);
  5120. SendByte[2] = (byte)(Address_Temp_Begin >> 8);
  5121. SendByte[3] = (byte)(Address_Temp_Begin);
  5122. Address_Temp_End = Address_Temp_Begin + 127;
  5123. SendByte[4] = (byte)(Address_Temp_End >> 24);
  5124. SendByte[5] = (byte)(Address_Temp_End >> 16);
  5125. SendByte[6] = (byte)(Address_Temp_End >> 8);
  5126. SendByte[7] = (byte)(Address_Temp_End);
  5127. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  5128. Delay_ms(200);//Thread.Sleep(200);
  5129. }
  5130. button_ExportLog.Text = "导出日志";
  5131. button_ExportLog.Enabled = true;
  5132. }
  5133. }
  5134. }
  5135. /// <summary>
  5136. /// 保存日志信息
  5137. /// </summary>
  5138. /// <param name="sender"></param>
  5139. /// <param name="e"></param>
  5140. private void button_SaveRecordInfo_Click(object sender, EventArgs e)
  5141. {
  5142. string SaveInfo = "";
  5143. if (richTextBox_Record.Text == string.Empty)
  5144. {
  5145. timer_500ms.Enabled = false;
  5146. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  5147. timer_500ms.Enabled = true;
  5148. return;
  5149. }
  5150. //获取保存信息
  5151. SaveInfo += "读取时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  5152. SaveInfo += "电机型号:" + textBox_FacModeName.Text + "\r\n";
  5153. SaveInfo += "电机SN:" + textBox_FacModeNum.Text + "\r\n";
  5154. SaveInfo += "硬件版本:" + textBox_FacModeHW.Text + "\r\n";
  5155. SaveInfo += "软件版本:" + textBox_FacModeFW.Text + "\r\n";
  5156. SaveInfo += "\r\n";
  5157. SaveInfo += richTextBox_Record.Text;
  5158. //设置保存路径和文件名
  5159. SaveFileDialog sf = new SaveFileDialog();
  5160. sf.Title = "数据保存";
  5161. sf.FileName = "MotorLog_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".ttlog";
  5162. sf.FileName.Replace(" ", "");
  5163. sf.Filter = "日志|*.ttlog";
  5164. if (sf.ShowDialog() == DialogResult.OK)
  5165. {
  5166. System.IO.File.AppendAllText(sf.FileName, SaveInfo);
  5167. }
  5168. }
  5169. /// <summary>
  5170. /// 双击修改日志起始地址
  5171. /// </summary>
  5172. /// <param name="sender"></param>
  5173. /// <param name="e"></param>
  5174. private void label_LogAddrBegin_DoubleClick_1(object sender, EventArgs e)
  5175. {
  5176. textBox_LogAddrBegin.ReadOnly = false;
  5177. }
  5178. /// <summary>
  5179. /// 双击修改日志结束地址
  5180. /// </summary>
  5181. /// <param name="sender"></param>
  5182. /// <param name="e"></param>
  5183. private void label88_DoubleClick(object sender, EventArgs e)
  5184. {
  5185. textBox_LogAddrEnd.ReadOnly = false;
  5186. }
  5187. /// <summary>
  5188. /// 存储器自动读取选择
  5189. /// </summary>
  5190. /// <param name="sender"></param>
  5191. /// <param name="e"></param>
  5192. private void checkBox_ReadRanFlash_AutoSW_CheckedChanged(object sender, EventArgs e)
  5193. {
  5194. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  5195. {
  5196. //检查串口是否打开
  5197. if (!mySerialProcess.mySerial.IsOpen)
  5198. {
  5199. timer_500ms.Enabled = false;
  5200. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5201. timer_500ms.Enabled = true;
  5202. checkBox_ReadRanFlash_AutoSW.Checked = false;
  5203. return;
  5204. }
  5205. }
  5206. }
  5207. /// <summary>
  5208. /// 系统开机按钮
  5209. /// </summary>
  5210. /// <param name="sender"></param>
  5211. /// <param name="e"></param>
  5212. private void 开机ToolStripMenuItem_Click(object sender, EventArgs e)
  5213. {
  5214. byte[] Data = new byte[1];
  5215. Data[0] = 0xF1;
  5216. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  5217. }
  5218. /// <summary>
  5219. /// 系统关机按钮
  5220. /// </summary>
  5221. /// <param name="sender"></param>
  5222. /// <param name="e"></param>
  5223. private void 关机ToolStripMenuItem_Click(object sender, EventArgs e)
  5224. {
  5225. byte[] Data = new byte[1];
  5226. Data[0] = 0xF0;
  5227. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  5228. }
  5229. /// <summary>
  5230. /// 连接开机选择
  5231. /// </summary>
  5232. /// <param name="sender"></param>
  5233. /// <param name="e"></param>
  5234. private void 连接开机ToolStripMenuItem_Click(object sender, EventArgs e)
  5235. {
  5236. //输入用户名
  5237. EnterForm1.ShowDialog();
  5238. try
  5239. {
  5240. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5241. {
  5242. if (EnterForm1.comboBox_User.Text == "管理员")
  5243. {
  5244. 连接开机ToolStripMenuItem.Checked = !连接开机ToolStripMenuItem.Checked;
  5245. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5246. }
  5247. else
  5248. {
  5249. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5250. }
  5251. }
  5252. else
  5253. {
  5254. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5255. }
  5256. }
  5257. catch (Exception)
  5258. {
  5259. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5260. }
  5261. }
  5262. /// <summary>
  5263. /// 断开关机选择
  5264. /// </summary>
  5265. /// <param name="sender"></param>
  5266. /// <param name="e"></param>
  5267. private void 断开关机ToolStripMenuItem_Click(object sender, EventArgs e)
  5268. {
  5269. //输入用户名
  5270. EnterForm1.ShowDialog();
  5271. try
  5272. {
  5273. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5274. {
  5275. if (EnterForm1.comboBox_User.Text == "管理员")
  5276. {
  5277. 断开关机ToolStripMenuItem.Checked = !断开关机ToolStripMenuItem.Checked;
  5278. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5279. }
  5280. else
  5281. {
  5282. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5283. }
  5284. }
  5285. else
  5286. {
  5287. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5288. }
  5289. }
  5290. catch (Exception)
  5291. {
  5292. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5293. }
  5294. }
  5295. /// <summary>
  5296. /// 识别通讯盒选择
  5297. /// </summary>
  5298. /// <param name="sender"></param>
  5299. /// <param name="e"></param>
  5300. private void 识别通讯盒ToolStripMenuItem_Click(object sender, EventArgs e)
  5301. {
  5302. //输入用户名
  5303. EnterForm1.ShowDialog();
  5304. try
  5305. {
  5306. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5307. {
  5308. if (EnterForm1.comboBox_User.Text == "管理员")
  5309. {
  5310. 识别通讯盒ToolStripMenuItem.Checked = !识别通讯盒ToolStripMenuItem.Checked;
  5311. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5312. }
  5313. else
  5314. {
  5315. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5316. }
  5317. }
  5318. else
  5319. {
  5320. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5321. }
  5322. }
  5323. catch (Exception)
  5324. {
  5325. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5326. }
  5327. }
  5328. /// <summary>
  5329. /// 将配置信息导出为cfg文件
  5330. /// </summary>
  5331. private void ConfigFileSave(bool DeleteFlag, string FileName)
  5332. {
  5333. if (DeleteFlag)
  5334. {
  5335. if (File.Exists(FileName))
  5336. File.Delete(FileName);
  5337. }
  5338. string CfgFileInfo = "";
  5339. CfgFileInfo += "[PortSet]" + "\r\n";
  5340. CfgFileInfo += "PortNum:" + toolStripComboBox_ComNum.Text + "\r\n";
  5341. CfgFileInfo += "PortBaudrate:" + "115200" + "\r\n";
  5342. CfgFileInfo += "AutoOn:" + 连接开机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5343. CfgFileInfo += "AutoOff:" + 断开关机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5344. CfgFileInfo += "CheckCDL:" + 识别通讯盒ToolStripMenuItem.Checked.ToString() + "\r\n";
  5345. CfgFileInfo += "\r\n";
  5346. CfgFileInfo += "[Option]" + "\r\n";
  5347. CfgFileInfo += "SaveWhenWrite:" + 写入存储ToolStripMenuItem.Checked.ToString() + "\r\n";
  5348. CfgFileInfo += "\r\n";
  5349. CfgFileInfo += "[ServerSet]" + "\r\n";
  5350. CfgFileInfo += "PathName:" + toolStripTextBox_ServerPath.Text + "\r\n";
  5351. CfgFileInfo += "\r\n";
  5352. CfgFileInfo += "[MacInfo]" + "\r\n";
  5353. CfgFileInfo += "MacName:" + toolStripTextBox_MAC.Text + "\r\n";
  5354. CfgFileInfo += "MacAddress:" + toolStripTextBoxMACAddr.Text + "\r\n";
  5355. CfgFileInfo += "MacDate:" + toolStripTextBox_MACDate.Text + "\r\n";
  5356. CfgFileInfo += "MacPdInfo:" + toolStripTextBox_MACPD.Text + "\r\n";
  5357. CfgFileInfo += "\r\n";
  5358. CfgFileInfo += "[LogAddress]" + "\r\n";
  5359. CfgFileInfo += "BeginAddress:" + textBox_LogAddrBegin.Text + "\r\n";
  5360. CfgFileInfo += "EndAddress:" + textBox_LogAddrEnd.Text + "\r\n";
  5361. CfgFileInfo += "\r\n";
  5362. CfgFileInfo += "[MotorType]" + "\r\n";
  5363. CfgFileInfo += "MidMotor:" + 中置电机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5364. CfgFileInfo += "HubMotor:" + 轮毂电机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5365. CfgFileInfo += "\r\n";
  5366. CfgFileInfo += "[CheckValue]" + "\r\n";
  5367. CfgFileInfo += "Voltage:" + toolStripTextBox_ThVol.Text + "\r\n";
  5368. CfgFileInfo += "Current:" + toolStripTextBox_ThCur.Text + "\r\n";
  5369. CfgFileInfo += "MotorSpeed:" + toolStripTextBox_ThSpeed.Text + "\r\n";
  5370. CfgFileInfo += "Torque:" + toolStripTextBox_ThTor.Text + "\r\n";
  5371. CfgFileInfo += "Cadence:" + toolStripTextBox_ThCad.Text + "\r\n";
  5372. CfgFileInfo += "BikeSpeed:" + toolStripTextBox_ThBikeSpeed.Text + "\r\n";
  5373. CfgFileInfo += "T_PCB:" + toolStripTextBox_ThT_PCB.Text + "\r\n";
  5374. CfgFileInfo += "T_MCU:" + toolStripTextBox_ThT_MCU.Text + "\r\n";
  5375. CfgFileInfo += "T_Motor:" + toolStripTextBox_ThT_Motor.Text + "\r\n";
  5376. CfgFileInfo += "\r\n";
  5377. CfgFileInfo += "[MosCalK]" + "\r\n";
  5378. CfgFileInfo += "K1-K5:" + toolStripTextBox_MosCalK.Text + "\r\n";
  5379. CfgFileInfo += "MOS1:" + toolStripTextBox_MOS1.Text + "\r\n";
  5380. CfgFileInfo += "MOS2:" + toolStripTextBox_MOS2.Text + "\r\n";
  5381. CfgFileInfo += "MOS3:" + toolStripTextBox_MOS3.Text + "\r\n";
  5382. CfgFileInfo += "\r\n";
  5383. CfgFileInfo += "[ProtocolType]" + "\r\n";
  5384. CfgFileInfo += "CAN:" + cANToolStripMenuItem.Checked.ToString() + "\r\n";
  5385. CfgFileInfo += "UART:" + uARTToolStripMenuItem.Checked.ToString() + "\r\n";
  5386. CfgFileInfo += "\r\n";
  5387. CfgFileInfo += "[AutoUpdate]" + "\r\n";
  5388. CfgFileInfo += "AutoUpdate:" + 打开ToolStripMenuItem.Checked.ToString() + "\r\n";
  5389. CfgFileInfo += "\r\n";
  5390. CfgFileInfo += "[AngleCal]" + "\r\n";
  5391. CfgFileInfo += "MaxDiffLimit:" + textBox_AngleDiffTh.Text + "\r\n";
  5392. CfgFileInfo += "ZeroDiffLimit:" + textBox_AngleZeroTh.Text + "\r\n";
  5393. System.IO.File.WriteAllText(FileName, CfgFileInfo);
  5394. }
  5395. /// <summary>
  5396. /// 配置状态更新,点击时保存
  5397. /// </summary>
  5398. private void ConfigFileSave_Click(object sender, EventArgs e)
  5399. {
  5400. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5401. }
  5402. /// <summary>
  5403. /// 文本框修改结束,回车保存
  5404. /// </summary>
  5405. /// <param name="sender"></param>
  5406. /// <param name="e"></param>
  5407. private void ConfigFileSave_KeyDown(object sender, KeyEventArgs e)
  5408. {
  5409. if (e.KeyCode == Keys.Enter)
  5410. {
  5411. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5412. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  5413. }
  5414. }
  5415. /// <summary>
  5416. /// 弹出扫码按钮
  5417. /// </summary>
  5418. /// <param name="sender"></param>
  5419. /// <param name="e"></param>
  5420. private void button_ScanCode_Click(object sender, EventArgs e)
  5421. {
  5422. Scan scan_form = new Scan();
  5423. scan_form.ShowDialog();
  5424. do
  5425. {
  5426. if (scan_form.textBox_Scan.Text == string.Empty)
  5427. {
  5428. timer_500ms.Enabled = false;
  5429. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5430. timer_500ms.Enabled = true;
  5431. break;
  5432. }
  5433. string ScanInfo = scan_form.textBox_Scan.Text;
  5434. string regexInfo = "";
  5435. string[] InfoList = { "" };
  5436. try
  5437. {
  5438. if (中置电机ToolStripMenuItem.Checked == true)
  5439. {
  5440. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  5441. InfoList = Regex.Split(ScanInfo, regexInfo, RegexOptions.IgnoreCase);
  5442. }
  5443. else if (轮毂电机ToolStripMenuItem.Checked == true)
  5444. {
  5445. if (!ScanInfo.Contains("/")) //老编码规则
  5446. {
  5447. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  5448. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  5449. string Spec = InfoList[1];
  5450. string Sn = InfoList[2];
  5451. InfoList[0] = Model.Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  5452. InfoList[1] = Sn;
  5453. }
  5454. else //新编码规则
  5455. {
  5456. Dictionary<string, string> Dic_Ver = new Dictionary<string, string>
  5457. {
  5458. { "01", "A" },
  5459. { "02", "B" },
  5460. { "03", "C" },
  5461. { "04", "D" },
  5462. { "05", "E" },
  5463. { "06", "F" },
  5464. { "07", "G" },
  5465. { "08", "H" },
  5466. { "09", "I" }
  5467. };
  5468. Dictionary<string, string> Dic_Vol = new Dictionary<string, string>
  5469. {
  5470. { "24V", "A" },
  5471. { "36V", "B" },
  5472. { "42V", "C" },
  5473. { "48V", "D" },
  5474. { "52V", "E" },
  5475. { "60V", "F" }
  5476. };
  5477. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  5478. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  5479. string Spec = InfoList[1].Replace("-", "").Replace("/","");
  5480. string Sn = InfoList[2];
  5481. InfoList[0] = Model[2] + Dic_Ver[Model.Substring(3, 2)] + Model[5] + Dic_Ver[Model.Substring(6, 2)] + Model[9];
  5482. InfoList[0] += Dic_Vol[Spec.Substring(0, 3)] + Spec.Substring(3, 3) + Spec.Substring(13, 4) + Spec.Substring(Spec.Length - 4, 3);
  5483. InfoList[1] = Sn;
  5484. }
  5485. }
  5486. }
  5487. catch (Exception)
  5488. {
  5489. MessageBox.Show("格式错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5490. return;
  5491. }
  5492. if (InfoList.Length >= 2)
  5493. {
  5494. //写入型号
  5495. textBox_FacModeName.Text = InfoList[0];
  5496. string Mode = textBox_FacModeName.Text;
  5497. var ModeArray = new byte[16];
  5498. for (ushort i = 0; i < Mode.Length; i++)
  5499. {
  5500. ModeArray[i] = (byte)Mode[i];
  5501. }
  5502. if (Mode.Length < 16)
  5503. {
  5504. ModeArray[Mode.Length] = (byte)'.';
  5505. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  5506. {
  5507. ModeArray[Mode.Length + 1 + i] = 0x20;
  5508. }
  5509. }
  5510. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  5511. //写入SN
  5512. textBox_FacModeNum.Text = InfoList[1];
  5513. string SN = textBox_FacModeNum.Text;
  5514. var SNArray = new byte[16];
  5515. for (ushort i = 0; i < SN.Length; i++)
  5516. {
  5517. SNArray[i] = (byte)SN[i];
  5518. }
  5519. if (SN.Length < 16)
  5520. {
  5521. SNArray[SN.Length] = (byte)'.';
  5522. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  5523. {
  5524. SNArray[SN.Length + 1 + i] = 0x20;
  5525. }
  5526. }
  5527. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  5528. }
  5529. else
  5530. {
  5531. timer_500ms.Enabled = false;
  5532. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5533. timer_500ms.Enabled = true;
  5534. break;
  5535. }
  5536. } while (false);
  5537. scan_form.Dispose();
  5538. }
  5539. /// <summary>
  5540. /// 切换电机类型
  5541. /// </summary>
  5542. /// <param name="sender"></param>
  5543. /// <param name="e"></param>
  5544. private void 中置电机ToolStripMenuItem_Click(object sender, EventArgs e)
  5545. {
  5546. 中置电机ToolStripMenuItem.Checked = true;
  5547. 轮毂电机ToolStripMenuItem.Checked = false;
  5548. toolStripTextBox_MACPD.Text = "MM_MC1";
  5549. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  5550. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5551. }
  5552. /// <summary>
  5553. /// 切换电机类型
  5554. /// </summary>
  5555. /// <param name="sender"></param>
  5556. /// <param name="e"></param>
  5557. private void 轮毂电机ToolStripMenuItem_Click(object sender, EventArgs e)
  5558. {
  5559. 中置电机ToolStripMenuItem.Checked = false;
  5560. 轮毂电机ToolStripMenuItem.Checked = true;
  5561. toolStripTextBox_MACPD.Text = "GF_250_1";
  5562. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  5563. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5564. }
  5565. /// <summary>
  5566. /// 获取配置文件日期
  5567. /// </summary>
  5568. /// <param name="DisAll"></param>
  5569. private void GetDateList(bool DisAll)
  5570. {
  5571. string[] DateList = { "" };
  5572. //从服务器更新日期列表
  5573. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  5574. {
  5575. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
  5576. }
  5577. //从本地更新日期列表
  5578. else
  5579. {
  5580. DateList = Directory.GetDirectories(localInfo.LocalPath + "\\" + localInfo.CfgPathName);
  5581. }
  5582. comboBox_FacModeCfgDate.Items.Clear();
  5583. comboBox_CheckModeCfgDate.Items.Clear();
  5584. //日期列表加载
  5585. if (DisAll == true)
  5586. {
  5587. comboBox_FacModeCfgDate.Items.Add("显示近期");
  5588. comboBox_CheckModeCfgDate.Items.Add("显示近期");
  5589. comboBox_FacModeCfgDate.Items.Add("---");
  5590. comboBox_CheckModeCfgDate.Items.Add("---");
  5591. foreach (var file in DateList)
  5592. {
  5593. comboBox_FacModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5594. comboBox_CheckModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5595. }
  5596. }
  5597. else
  5598. {
  5599. if (DateList.Length > 10)
  5600. {
  5601. comboBox_FacModeCfgDate.Items.Add("显示全部");
  5602. comboBox_CheckModeCfgDate.Items.Add("显示全部");
  5603. comboBox_FacModeCfgDate.Items.Add("---");
  5604. comboBox_CheckModeCfgDate.Items.Add("---");
  5605. }
  5606. for (int i = (DateList.Length > 10) ? (DateList.Length - 10) : 0; i < DateList.Length; i++)//显示最近10个日期
  5607. {
  5608. comboBox_FacModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  5609. comboBox_CheckModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  5610. }
  5611. }
  5612. }
  5613. /// <summary>
  5614. /// 获取配置文件列表
  5615. /// </summary>
  5616. /// <param name="date"></param>
  5617. private void GetFileListFrom(string date)
  5618. {
  5619. string[] FileList = { "" };
  5620. //从服务器更新文件列表
  5621. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  5622. {
  5623. FileList = myFtp.GetFileNameList(toolStripTextBox_ServerPath.Text + "/cfg/" + date);
  5624. }
  5625. else
  5626. {
  5627. FileList = Directory.GetFiles(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + date);
  5628. }
  5629. comboBox_CheckModeCfgFile.Items.Clear();
  5630. comboBox_FacModeCfgFile.Items.Clear();
  5631. foreach (var file in FileList)
  5632. {
  5633. if (file.Contains(".ttcfg"))
  5634. {
  5635. comboBox_CheckModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5636. comboBox_FacModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5637. }
  5638. }
  5639. }
  5640. /// <summary>
  5641. /// 检验模式选择文件日期
  5642. /// </summary>
  5643. /// <param name="sender"></param>
  5644. /// <param name="e"></param>
  5645. private void comboBox_CheckModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  5646. {
  5647. if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示全部")
  5648. {
  5649. GetDateList(true);
  5650. }
  5651. else if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示近期")
  5652. {
  5653. GetDateList(false);
  5654. }
  5655. else
  5656. {
  5657. comboBox_CheckModeCfgFile.Text = "";
  5658. GetFileListFrom(comboBox_CheckModeCfgDate.SelectedItem.ToString());
  5659. }
  5660. }
  5661. /// <summary>
  5662. /// 配置模式选择文件日期
  5663. /// </summary>
  5664. /// <param name="sender"></param>
  5665. /// <param name="e"></param>
  5666. private void comboBox_FacModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  5667. {
  5668. if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示全部")
  5669. {
  5670. GetDateList(true);
  5671. }
  5672. else if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示近期")
  5673. {
  5674. GetDateList(false);
  5675. }
  5676. else
  5677. {
  5678. comboBox_FacModeCfgFile.Text = "";
  5679. GetFileListFrom(comboBox_FacModeCfgDate.SelectedItem.ToString());
  5680. }
  5681. }
  5682. /// <summary>
  5683. /// 选中量产模式
  5684. /// </summary>
  5685. /// <param name="sender"></param>
  5686. /// <param name="e"></param>
  5687. private void tabControl1_Selected(object sender, TabControlEventArgs e)
  5688. {
  5689. //更新生产配置文件目录
  5690. GetDateList(false);
  5691. }
  5692. /// <summary>
  5693. /// 量产测试结束
  5694. /// </summary>
  5695. /// <param name=""></param>
  5696. private void FacMode_Stop(bool OK_Flag)
  5697. {
  5698. //打开开始按钮
  5699. button__FacMode_Start.Enabled = true;
  5700. //系统关机
  5701. var Code = new byte[32];//发送的指令数据
  5702. Code[0] = 0xF0;
  5703. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5704. //关闭串口
  5705. //mySerialProcess.SerialClose(false);
  5706. //路径设置
  5707. string LocalSavePath = "";
  5708. string ServerSavePath = "";
  5709. if (OK_Flag)
  5710. {
  5711. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "OK\\";
  5712. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/OK/";
  5713. }
  5714. else
  5715. {
  5716. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "FAIL\\";
  5717. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/FAIL/";
  5718. }
  5719. if (Directory.Exists(LocalSavePath) == false)
  5720. {
  5721. Directory.CreateDirectory(LocalSavePath);
  5722. }
  5723. //保存和上传
  5724. string LogSavePath = "";
  5725. string LogSaveFileName = "";
  5726. string ProductInfo = textBox_FacModeScan.Text.Replace(" ", "_").Replace("/", "-");
  5727. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  5728. if (Directory.Exists(LogSavePath) == false)
  5729. {
  5730. Directory.CreateDirectory(LogSavePath);
  5731. }
  5732. //测试页面
  5733. Double scaleX = PrimaryScreen.ScaleX;
  5734. Double scaleY = PrimaryScreen.ScaleY;
  5735. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  5736. Graphics g = Graphics.FromImage(bit);
  5737. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  5738. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  5739. bit.Save(LogSaveFileName);
  5740. //上传测试页面到服务器
  5741. if (myFtp.IsNetConnected == true)
  5742. {
  5743. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  5744. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  5745. {
  5746. myFtp.MakeDir(ServerSavePath + DateNow);
  5747. }
  5748. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  5749. {
  5750. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  5751. }
  5752. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  5753. if (result == true)
  5754. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  5755. }
  5756. else
  5757. {
  5758. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  5759. }
  5760. //测试记录
  5761. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  5762. string file_str = "";
  5763. file_str += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  5764. file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  5765. file_str += "检验记录:\r\n" + richTextBox_FacModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  5766. file_str += "检验结果:\r\n" + label_FacModeResult.Text + "\r\n\r\n";
  5767. file_str += Local_HdInformation;
  5768. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  5769. //上传测试记录到服务器
  5770. if (myFtp.IsNetConnected == true)
  5771. {
  5772. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  5773. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  5774. {
  5775. myFtp.MakeDir(ServerSavePath + DateNow);
  5776. }
  5777. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  5778. {
  5779. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  5780. }
  5781. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  5782. if (result == true)
  5783. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  5784. }
  5785. else
  5786. {
  5787. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  5788. }
  5789. //扫码框清空
  5790. textBox_FacModeScan.Text = "";
  5791. }
  5792. /// <summary>
  5793. /// 量产测试开始
  5794. /// </summary>
  5795. /// <param name="sender"></param>
  5796. /// <param name="e"></param>
  5797. private void button__FacMode_Start_Click(object sender, EventArgs e)
  5798. {
  5799. //关闭测试项目编辑
  5800. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  5801. foreach (Control c in groupBox2.Controls)
  5802. {
  5803. if (c is CheckBox)
  5804. c.Enabled = false;
  5805. }
  5806. WriteLockStatus = true;
  5807. //检查配置文件
  5808. if (comboBox_FacModeCfgFile.Text == "")
  5809. {
  5810. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5811. return;
  5812. }
  5813. //开始测试
  5814. TestStart();
  5815. }
  5816. /// <summary>
  5817. /// 测试子函数
  5818. /// </summary>
  5819. private void TestStart()
  5820. {
  5821. //初始化标签
  5822. FacModelLabelInit();
  5823. richTextBox_FacModeLog.Clear();
  5824. //按钮禁止操作
  5825. button__FacMode_Start.Enabled = false;
  5826. //记录配置文件
  5827. richTextBox_FacModeLog.AppendText("配置文件:" + comboBox_FacModeCfgDate.Text + " / " + comboBox_FacModeCfgFile.Text + "\r\n");
  5828. //检查打标信息格式
  5829. label_FacModeStatus.Text = "检查扫码信息";
  5830. Delay_ms(500);
  5831. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  5832. if (textBox_FacModeScan.Text == string.Empty)
  5833. {
  5834. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5835. button__FacMode_Start.Enabled = true;
  5836. return;
  5837. }
  5838. try
  5839. {
  5840. if (中置电机ToolStripMenuItem.Checked == true)
  5841. {
  5842. if (textBox_FacModeScan.Text.Split(' ').Length != 7)
  5843. {
  5844. label_FacModeStatus.Text = "存在故障!";
  5845. label_FacModeResult.BackColor = Color.Red;
  5846. label_FacModeResult.Text = "标签格式错误";
  5847. button__FacMode_Start.Enabled = true;
  5848. return;
  5849. }
  5850. }
  5851. else if (轮毂电机ToolStripMenuItem.Checked == true)
  5852. {
  5853. if (textBox_FacModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  5854. {
  5855. label_FacModeStatus.Text = "存在故障!";
  5856. label_FacModeResult.BackColor = Color.Red;
  5857. label_FacModeResult.Text = "标签格式错误";
  5858. button__FacMode_Start.Enabled = true;
  5859. return;
  5860. }
  5861. }
  5862. }
  5863. catch (System.Exception)
  5864. {
  5865. label_FacModeStatus.Text = "存在故障!";
  5866. label_FacModeResult.BackColor = Color.Red;
  5867. label_FacModeResult.Text = "标签格式错误";
  5868. button__FacMode_Start.Enabled = true;
  5869. return;
  5870. }
  5871. //打开串口
  5872. mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false);
  5873. if (!mySerialProcess.mySerial.IsOpen)
  5874. {
  5875. MessageBox.Show("请检查串口连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5876. //按钮禁止操作
  5877. button__FacMode_Start.Enabled = true;
  5878. return;
  5879. }
  5880. //流水号计数
  5881. int serial = Convert.ToInt32(label_FacModeSerial.Text);
  5882. serial += 1;
  5883. label_FacModeSerial.Text = serial.ToString();
  5884. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, serial.ToString());
  5885. //创建线程,执行测试任务
  5886. Thread th = new Thread(FacModeTest_Task);
  5887. th.Start();
  5888. }
  5889. /// <summary>
  5890. /// 执行一次测试任务
  5891. /// </summary>
  5892. private void FacModeTest_Task()
  5893. {
  5894. //开始测试
  5895. richTextBox_FacModeLog.AppendText("产品标签:" + textBox_FacModeScan.Text + "\r\n");
  5896. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  5897. //变量定义
  5898. var Code = new byte[255];//发送的指令数据
  5899. label_FacModeStatus.Text = "开始测试";
  5900. BootInfo = "";
  5901. Delay_ms(500);
  5902. label_FacModeStatus.Text = "系统开机";
  5903. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  5904. if (uARTToolStripMenuItem.Checked)
  5905. {
  5906. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送复位指令,切换联动装置盒波特率" + "\r\n");
  5907. Code[0] = (byte)'R';
  5908. Code[1] = (byte)'E';
  5909. Code[2] = (byte)'S';
  5910. Code[3] = (byte)'E';
  5911. Code[4] = (byte)'T';
  5912. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  5913. Delay_ms(500);
  5914. }
  5915. //发送开机指令
  5916. //确保测试前先关机,发送关机指令再发送开机指令
  5917. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  5918. Code[0] = 0xF0;
  5919. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5920. Delay_ms(1500);
  5921. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  5922. Code[0] = 0xF1;
  5923. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5924. ACK_WaitCnt = 0;
  5925. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  5926. while (ACK_WaitCnt <= 20) ; //10s,等待开机成功,联动装置盒控制器接口波特率需等待5s接口自动切换为9600
  5927. //检查BOOT版本
  5928. if (BootInfo != string.Empty)
  5929. {
  5930. label_FacModeBootVer.BackColor = Color.Green;
  5931. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  5932. Delay_ms(500);
  5933. }
  5934. else
  5935. {
  5936. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
  5937. label_FacModeStatus.Text = "存在故障!";
  5938. label_FacModeResult.BackColor = Color.Red;
  5939. label_FacModeResult.Text = "测试异常";
  5940. Delay_ms(500);
  5941. //存储异常并上传
  5942. FacMode_Stop(false);
  5943. return;
  5944. }
  5945. //系统清除
  5946. if (checkBox_FacModeSysClear.Checked)
  5947. {
  5948. do
  5949. {
  5950. #if false
  5951. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  5952. {
  5953. Code[0] = 0x00;//5S协议
  5954. Code[1] = 0x00;
  5955. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5956. Delay_ms(500);
  5957. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5958. Delay_ms(500);
  5959. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  5960. }
  5961. #endif
  5962. //发送系统清除指令
  5963. label_FacModeStatus.Text = "系统清除";
  5964. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除" + "\r\n");
  5965. Code[0] = (byte)'C';
  5966. Code[1] = (byte)'L';
  5967. Code[2] = (byte)'E';
  5968. Code[3] = (byte)'A';
  5969. Code[4] = (byte)'R';
  5970. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  5971. WriteACK = false;
  5972. ACK_WaitCnt = 0;
  5973. while (ACK_WaitCnt <= 6); //3s
  5974. //等待系统清除完成指令
  5975. if (WriteACK == true)
  5976. {
  5977. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  5978. label_FacModeSysClear.BackColor = Color.Green;
  5979. }
  5980. else
  5981. {
  5982. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除,重发第1次" + "\r\n");
  5983. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  5984. ACK_WaitCnt = 0;
  5985. while (ACK_WaitCnt <= 6) ; //3s
  5986. //等待系统清除完成指令
  5987. if (WriteACK == true)
  5988. {
  5989. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  5990. label_FacModeSysClear.BackColor = Color.Green;
  5991. }
  5992. else
  5993. {
  5994. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除,重发第2次" + "\r\n");
  5995. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  5996. ACK_WaitCnt = 0;
  5997. while (ACK_WaitCnt <= 6) ; //3s
  5998. //等待系统清除完成指令
  5999. if (WriteACK == true)
  6000. {
  6001. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  6002. label_FacModeSysClear.BackColor = Color.Green;
  6003. }
  6004. else
  6005. {
  6006. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除失败" + "\r\n");
  6007. label_FacModeStatus.Text = "存在故障!";
  6008. label_FacModeResult.BackColor = Color.Red;
  6009. label_FacModeResult.Text = "测试异常";
  6010. Delay_ms(500);
  6011. //存储异常并上传
  6012. FacMode_Stop(false);
  6013. return;
  6014. }
  6015. }
  6016. }
  6017. BootInfo = "";
  6018. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  6019. if (uARTToolStripMenuItem.Checked)
  6020. {
  6021. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送复位指令,切换联动装置盒波特率" + "\r\n");
  6022. Code[0] = (byte)'R';
  6023. Code[1] = (byte)'E';
  6024. Code[2] = (byte)'S';
  6025. Code[3] = (byte)'E';
  6026. Code[4] = (byte)'T';
  6027. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  6028. Delay_ms(500);
  6029. }
  6030. //系统清除后需重新开机
  6031. label_FacModeStatus.Text = "重新开机";
  6032. //确保测试前先关机,发送关机指令再发送开机指令
  6033. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新发送关机指令" + "\r\n");
  6034. Code[0] = 0xF0;
  6035. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6036. Delay_ms(1500);
  6037. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新发送开机指令" + "\r\n");
  6038. Code[0] = 0xF1;
  6039. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6040. ACK_WaitCnt = 0;
  6041. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  6042. while (ACK_WaitCnt <= 20); //10s
  6043. //获取Boot版本信息
  6044. if (BootInfo != string.Empty)
  6045. {
  6046. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机成功" + "\r\n");
  6047. Delay_ms(500);
  6048. }
  6049. else
  6050. {
  6051. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机失败" + "\r\n");
  6052. label_FacModeStatus.Text = "存在故障!";
  6053. label_FacModeResult.BackColor = Color.Red;
  6054. label_FacModeResult.Text = "测试异常";
  6055. Delay_ms(500);
  6056. //存储异常并上传
  6057. FacMode_Stop(false);
  6058. return;
  6059. }
  6060. } while (false);
  6061. }
  6062. else
  6063. {
  6064. label_FacModeSysClear.BackColor = Color.Yellow;
  6065. label_FacModeStatus.Text = "跳过系统清除!";
  6066. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过系统清除" + "\r\n");
  6067. Delay_ms(500);
  6068. }
  6069. #if false
  6070. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  6071. {
  6072. Code[0] = 0x00;//5S协议
  6073. Code[1] = 0x00;
  6074. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6075. Delay_ms(500);
  6076. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6077. Delay_ms(500);
  6078. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  6079. }
  6080. #endif
  6081. //检查是否有故障
  6082. if (textBox_ErrorCode.Text.Contains("H"))
  6083. {
  6084. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "故障码:" + textBox_ErrorCode.Text + "\r\n");
  6085. label_FacModeStatus.Text = "电机存在故障!";
  6086. label_FacModeResult.BackColor = Color.Red;
  6087. label_FacModeResult.Text = "测试异常";
  6088. Delay_ms(500);
  6089. //存储异常并上传
  6090. FacMode_Stop(false);
  6091. return;
  6092. }
  6093. //MOS内阻校准
  6094. if (checkBox_FacMode_MosCal.Checked)
  6095. {
  6096. label_FacModeStatus.Text = "MOS内阻校准";
  6097. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始MOS内阻校准" + "\r\n");
  6098. Delay_ms(500);
  6099. //提示进行负载切换
  6100. if (MessageBox.Show("电阻负载切换完成,开始校准?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
  6101. {
  6102. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "取消MOS内阻校准" + "\r\n");
  6103. label_FacModeStatus.Text = "存在故障!";
  6104. label_FacModeResult.BackColor = Color.Red;
  6105. label_FacModeResult.Text = "测试异常";
  6106. Delay_ms(500);
  6107. //存储异常并上传
  6108. FacMode_Stop(false);
  6109. return;
  6110. }
  6111. //确认后发送校准指令
  6112. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令" + "\r\n");
  6113. string[] K = toolStripTextBox_MosCalK.Text.Split(',');
  6114. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  6115. ushort uwDataTemp = 0;
  6116. uwDataTemp = Convert.ToUInt16(K[0]);
  6117. Code[2] = (byte)(uwDataTemp & 0xFF);
  6118. Code[3] = (byte)(uwDataTemp >> 8);
  6119. uwDataTemp = Convert.ToUInt16(K[1]);
  6120. Code[4] = (byte)(uwDataTemp & 0xFF);
  6121. Code[5] = (byte)(uwDataTemp >> 8);
  6122. uwDataTemp = Convert.ToUInt16(K[2]);
  6123. Code[6] = (byte)(uwDataTemp & 0xFF);
  6124. Code[7] = (byte)(uwDataTemp >> 8);
  6125. uwDataTemp = Convert.ToUInt16(K[3]);
  6126. Code[8] = (byte)(uwDataTemp & 0xFF);
  6127. Code[9] = (byte)(uwDataTemp >> 8);
  6128. uwDataTemp = Convert.ToUInt16(K[4]);
  6129. Code[10] = (byte)(uwDataTemp & 0xFF);
  6130. Code[11] = (byte)(uwDataTemp >> 8);
  6131. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  6132. WriteACK = false;
  6133. ACK_WaitCnt = 0;
  6134. while (ACK_WaitCnt <= 6) ; //3s
  6135. if (WriteACK == true)
  6136. {
  6137. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  6138. }
  6139. else
  6140. {
  6141. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令,第1次重发" + "\r\n");
  6142. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  6143. ACK_WaitCnt = 0;
  6144. while (ACK_WaitCnt <= 6) ; //3s
  6145. if (WriteACK == true)
  6146. {
  6147. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  6148. }
  6149. else
  6150. {
  6151. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令,第2次重发" + "\r\n");
  6152. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  6153. ACK_WaitCnt = 0;
  6154. while (ACK_WaitCnt <= 6) ; //3s
  6155. if (WriteACK == true)
  6156. {
  6157. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  6158. }
  6159. else
  6160. {
  6161. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准异常" + "\r\n");
  6162. label_FacModeStatus.Text = "存在故障!";
  6163. label_FacModeResult.BackColor = Color.Red;
  6164. label_FacModeResult.Text = "测试异常";
  6165. Delay_ms(500);
  6166. //存储异常并上传
  6167. FacMode_Stop(false);
  6168. return;
  6169. }
  6170. }
  6171. }
  6172. #if false
  6173. //因控制器复位需发送指令重新进入5S协议
  6174. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  6175. {
  6176. Code[0] = 0x00;//5S协议
  6177. Code[1] = 0x00;
  6178. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6179. Delay_ms(500);
  6180. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6181. Delay_ms(500);
  6182. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  6183. }
  6184. #endif
  6185. //读取显示校准返回数据
  6186. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果" + "\r\n");
  6187. foreach (Control c in groupBox21.Controls)
  6188. {
  6189. if (c is TextBox)
  6190. c.Text = "";
  6191. }
  6192. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  6193. ACK_WaitCnt = 0;
  6194. while (ACK_WaitCnt <= 2) ; //1s
  6195. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  6196. {
  6197. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果,第1次重发" + "\r\n");
  6198. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  6199. ACK_WaitCnt = 0;
  6200. while (ACK_WaitCnt <= 2) ; //1s
  6201. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  6202. {
  6203. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果,第2次重发" + "\r\n");
  6204. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  6205. ACK_WaitCnt = 0;
  6206. while (ACK_WaitCnt <= 2) ; //1s
  6207. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  6208. {
  6209. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果异常" + "\r\n");
  6210. label_FacModeStatus.Text = "存在故障!";
  6211. label_FacModeResult.BackColor = Color.Red;
  6212. label_FacModeResult.Text = "测试异常";
  6213. Delay_ms(500);
  6214. //存储异常并上传
  6215. FacMode_Stop(false);
  6216. return;
  6217. }
  6218. }
  6219. }
  6220. else
  6221. {
  6222. 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");
  6223. }
  6224. //与校准返回数据对比
  6225. string[] MOS_R1_Th = toolStripTextBox_MOS1.Text.Split(',');
  6226. string[] MOS_R2_Th = toolStripTextBox_MOS2.Text.Split(',');
  6227. string[] MOS_R3_Th = toolStripTextBox_MOS3.Text.Split(',');
  6228. 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])) &&
  6229. (Convert.ToUInt16(textBox_MOS_R2.Text) >= Convert.ToUInt16(MOS_R2_Th[0])) && (Convert.ToUInt16(textBox_MOS_R2.Text) <= Convert.ToUInt16(MOS_R2_Th[1])) &&
  6230. (Convert.ToUInt16(textBox_MOS_R3.Text) >= Convert.ToUInt16(MOS_R3_Th[0])) && (Convert.ToUInt16(textBox_MOS_R3.Text) <= Convert.ToUInt16(MOS_R3_Th[1]))
  6231. )
  6232. {
  6233. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准合格" + "\r\n");
  6234. label_FacModeMosCal.BackColor = Color.Green;
  6235. //提示切换负载
  6236. MessageBox.Show("请将负载切换回电机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  6237. }
  6238. else
  6239. {
  6240. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准超范围" + "\r\n");
  6241. label_FacModeStatus.Text = "存在故障!";
  6242. label_FacModeResult.BackColor = Color.Red;
  6243. label_FacModeResult.Text = "测试异常";
  6244. Delay_ms(500);
  6245. //存储异常并上传
  6246. FacMode_Stop(false);
  6247. //提示切换负载
  6248. MessageBox.Show("请将负载切换回电机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  6249. return;
  6250. }
  6251. }
  6252. else
  6253. {
  6254. label_FacModeMosCal.BackColor = Color.Yellow;
  6255. label_FacModeStatus.Text = "跳过MOS内阻校准!";
  6256. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过MOS内阻校准" + "\r\n");
  6257. Delay_ms(500);
  6258. }
  6259. //位置校准
  6260. if (checkBox_FacMode_AngleCal.Checked)
  6261. {
  6262. //校准前进行一次开关机保存初始化数据
  6263. BootInfo = "";
  6264. label_FacModeStatus.Text = "位置校准";
  6265. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始位置校准" + "\r\n");
  6266. //确保测试前先关机,发送关机指令再发送开机指令
  6267. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  6268. Code[0] = 0xF0;
  6269. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6270. Delay_ms(1500);
  6271. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  6272. Code[0] = 0xF1;
  6273. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6274. ACK_WaitCnt = 0;
  6275. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  6276. while (ACK_WaitCnt <= 10) ; //5s
  6277. //获取Boot版本信息
  6278. if (BootInfo != string.Empty)
  6279. {
  6280. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机成功" + "\r\n");
  6281. Delay_ms(500);
  6282. }
  6283. else
  6284. {
  6285. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机失败" + "\r\n");
  6286. label_FacModeStatus.Text = "存在故障!";
  6287. label_FacModeResult.BackColor = Color.Red;
  6288. label_FacModeResult.Text = "测试异常";
  6289. Delay_ms(500);
  6290. //存储异常并上传
  6291. FacMode_Stop(false);
  6292. return;
  6293. }
  6294. //发送位置校准指令
  6295. for (int i = 0; i < 7; i++)
  6296. for (int j = 0; j < 6; j++)
  6297. {
  6298. dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = "";
  6299. }
  6300. foreach (Control cr in tabPage_AngleCal.Controls)
  6301. {
  6302. if (cr is TextBox)
  6303. {
  6304. if ((cr != textBox_AngleDiffTh) && (cr != textBox_AngleZeroTh))
  6305. cr.Text = "";
  6306. }
  6307. }
  6308. Code[0] = 0;
  6309. Code[1] = 0;
  6310. mySerialProcess.SendCmd((ushort)0x751, (byte)0x0C, (ushort)0x5002, Code);
  6311. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准中,请等待" + "\r\n");
  6312. ACK_WaitCnt = 0;
  6313. while (ACK_WaitCnt <= 50) ; //25s
  6314. //读取位置校准数据
  6315. if (textBox_AngleDiffAvg.Text == string.Empty)
  6316. {
  6317. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准失败" + "\r\n");
  6318. label_FacModeStatus.Text = "存在故障!";
  6319. label_FacModeResult.BackColor = Color.Red;
  6320. label_FacModeResult.Text = "测试异常";
  6321. Delay_ms(500);
  6322. //存储异常并上传
  6323. FacMode_Stop(false);
  6324. return;
  6325. }
  6326. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准数据:" + "\r\n");
  6327. for (int i = 0; i < 7; i++)
  6328. {
  6329. richTextBox_FacModeLog.AppendText("电周期" + (i + 1).ToString()+":");
  6330. for (int j = 0; j < 6; j++)
  6331. {
  6332. richTextBox_FacModeLog.AppendText(dataGridView_AngleCal.Rows[i].Cells[j + 1].Value.ToString() + ", ");
  6333. }
  6334. richTextBox_FacModeLog.AppendText("\r\n");
  6335. Delay_ms(200);
  6336. }
  6337. richTextBox_FacModeLog.AppendText("最小偏差:" + textBox_AngleDiffMin.Text+ ", " + "\r\n");
  6338. richTextBox_FacModeLog.AppendText("最大偏差:" + textBox_AngleDiffMax.Text + ", " + "\r\n");
  6339. richTextBox_FacModeLog.AppendText("平均偏差:" + textBox_AngleDiffAvg.Text + ", " + "\r\n");
  6340. richTextBox_FacModeLog.AppendText("历史零点:" + textBox_AngleZeroInit.Text + ", " + "\r\n");
  6341. richTextBox_FacModeLog.AppendText("当前零点:" + textBox_AngleZeroCur.Text + ", " + "\r\n");
  6342. richTextBox_FacModeLog.AppendText("零点偏差:" + textBox_AngleZeroDiff.Text + ", " + "\r\n");
  6343. //比较位置偏差
  6344. if ((Math.Abs(Convert.ToDouble(textBox_AngleDiffMin.Text)) > Convert.ToDouble(textBox_AngleDiffTh.Text)) ||
  6345. (Math.Abs(Convert.ToDouble(textBox_AngleDiffMax.Text)) > Convert.ToDouble(textBox_AngleDiffTh.Text)) ||
  6346. (Math.Abs(Convert.ToDouble(textBox_AngleDiffAvg.Text)) > Convert.ToDouble(textBox_AngleZeroTh.Text))
  6347. )
  6348. {
  6349. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差过大,无法校准" + "\r\n");
  6350. label_FacModeStatus.Text = "存在故障!";
  6351. label_FacModeResult.BackColor = Color.Red;
  6352. label_FacModeResult.Text = "测试异常";
  6353. Delay_ms(500);
  6354. //存储异常并上传
  6355. FacMode_Stop(false);
  6356. return;
  6357. }
  6358. //写入校准偏差值
  6359. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差满足要求,写入校准数据" + "\r\n");
  6360. double data1 = Convert.ToDouble(textBox_AngleZeroInit.Text) - Convert.ToDouble(textBox_AngleDiffAvg.Text);
  6361. if (data1 > 360)
  6362. {
  6363. data1 -= 360;
  6364. }
  6365. else if (data1 < -360)
  6366. {
  6367. data1 += 360;
  6368. }
  6369. Int16 data2 = (Int16)(data1 * 32768 / 360);
  6370. Code[0] = 0x01;
  6371. Code[1] = 0x00;
  6372. Code[2] = (byte)(data2);
  6373. Code[3] = (byte)(data2 >> 8);
  6374. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
  6375. WriteACK = false;
  6376. ACK_WaitCnt = 0;
  6377. while (ACK_WaitCnt <= 2) ; //1s
  6378. if (WriteACK == true)
  6379. {
  6380. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
  6381. }
  6382. else
  6383. {
  6384. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入位置偏差,第1次重发" + "\r\n");
  6385. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
  6386. WriteACK = false;
  6387. ACK_WaitCnt = 0;
  6388. while (ACK_WaitCnt <= 2) ; //1s
  6389. if (WriteACK == true)
  6390. {
  6391. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
  6392. }
  6393. else
  6394. {
  6395. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入位置偏差,第2次重发" + "\r\n");
  6396. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
  6397. WriteACK = false;
  6398. ACK_WaitCnt = 0;
  6399. while (ACK_WaitCnt <= 2) ; //1s
  6400. if (WriteACK == true)
  6401. {
  6402. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
  6403. }
  6404. else
  6405. {
  6406. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入失败" + "\r\n");
  6407. label_FacModeStatus.Text = "存在故障!";
  6408. label_FacModeResult.BackColor = Color.Red;
  6409. label_FacModeResult.Text = "测试异常";
  6410. Delay_ms(500);
  6411. //存储异常并上传
  6412. FacMode_Stop(false);
  6413. return;
  6414. }
  6415. }
  6416. }
  6417. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准正常,位置偏差值:" + textBox_AngleDiffAvg.Text + "\r\n");
  6418. label_FacModeAngleCal.BackColor = Color.Green;
  6419. }
  6420. else
  6421. {
  6422. label_FacModeAngleCal.BackColor = Color.Yellow;
  6423. label_FacModeStatus.Text = "跳过位置校准!";
  6424. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过位置校准" + "\r\n");
  6425. Delay_ms(500);
  6426. }
  6427. //参数写入
  6428. if (checkBox_FacModeCfgWrite.Checked)
  6429. {
  6430. label_FacModeStatus.Text = "参数写入";
  6431. //写入产品型号和SN
  6432. do
  6433. {
  6434. //根据扫码信息获取型号和SN
  6435. string ScanInfo = textBox_FacModeScan.Text;
  6436. string regexInfo = "";
  6437. string[] InfoList = { "" };
  6438. try
  6439. {
  6440. if (中置电机ToolStripMenuItem.Checked == true)
  6441. {
  6442. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  6443. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  6444. }
  6445. else if (轮毂电机ToolStripMenuItem.Checked == true)
  6446. {
  6447. if (!ScanInfo.Contains("/")) //老编码规则
  6448. {
  6449. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  6450. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  6451. string Spec = InfoList[1];
  6452. string Sn = InfoList[2];
  6453. InfoList[0] = Model.Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  6454. InfoList[1] = Sn;
  6455. }
  6456. else //新编码规则
  6457. {
  6458. Dictionary<string, string> Dic_Ver = new Dictionary<string, string>
  6459. {
  6460. { "01", "A" },
  6461. { "02", "B" },
  6462. { "03", "C" },
  6463. { "04", "D" },
  6464. { "05", "E" },
  6465. { "06", "F" },
  6466. { "07", "G" },
  6467. { "08", "H" },
  6468. { "09", "I" }
  6469. };
  6470. Dictionary<string, string> Dic_Vol = new Dictionary<string, string>
  6471. {
  6472. { "24V", "A" },
  6473. { "36V", "B" },
  6474. { "42V", "C" },
  6475. { "48V", "D" },
  6476. { "52V", "E" },
  6477. { "60V", "F" }
  6478. };
  6479. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  6480. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  6481. string Spec = InfoList[1].Replace("-", "").Replace("/", "");
  6482. string Sn = InfoList[2];
  6483. InfoList[0] = Model[2] + Dic_Ver[Model.Substring(3, 2)] + Model[5] + Dic_Ver[Model.Substring(6, 2)] + Model[9];
  6484. InfoList[0] += Dic_Vol[Spec.Substring(0, 3)] + Spec.Substring(3, 3) + Spec.Substring(13, 4) + Spec.Substring(Spec.Length - 4, 3);
  6485. InfoList[1] = Sn;
  6486. }
  6487. }
  6488. }
  6489. catch
  6490. {
  6491. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  6492. label_FacModeStatus.Text = "存在故障!";
  6493. label_FacModeResult.BackColor = Color.Red;
  6494. label_FacModeResult.Text = "标签格式错误";
  6495. Delay_ms(500);
  6496. //存储异常并上传
  6497. FacMode_Stop(false);
  6498. return;
  6499. }
  6500. if (InfoList.Length >= 2)
  6501. {
  6502. //检查配置文件是否与打标信息一致
  6503. //...
  6504. //写入型号
  6505. label_FacModeStatus.Text = "写入型号";
  6506. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号" + "\r\n");
  6507. textBox_FacModeName.Text = InfoList[0];
  6508. string Mode = textBox_FacModeName.Text;
  6509. var ModeArray = new byte[16];
  6510. for (ushort i = 0; i < Mode.Length; i++)
  6511. {
  6512. ModeArray[i] = (byte)Mode[i];
  6513. }
  6514. if (Mode.Length < 16)
  6515. {
  6516. ModeArray[Mode.Length] = (byte)'.';
  6517. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  6518. {
  6519. ModeArray[Mode.Length + 1 + i] = 0x20;
  6520. }
  6521. }
  6522. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6523. WriteACK = false;
  6524. ACK_WaitCnt = 0;
  6525. while (ACK_WaitCnt <= 2); //1s
  6526. if (WriteACK == true)
  6527. {
  6528. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6529. }
  6530. else
  6531. {
  6532. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号,第1次重发" + "\r\n");
  6533. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6534. ACK_WaitCnt = 0;
  6535. while (ACK_WaitCnt <= 2) ; //1s
  6536. if (WriteACK == true)
  6537. {
  6538. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6539. }
  6540. else
  6541. {
  6542. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号,第2次重发" + "\r\n");
  6543. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6544. ACK_WaitCnt = 0;
  6545. while (ACK_WaitCnt <= 2) ; //1s
  6546. if (WriteACK == true)
  6547. {
  6548. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6549. }
  6550. else
  6551. {
  6552. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入失败" + "\r\n");
  6553. label_FacModeStatus.Text = "存在故障!";
  6554. label_FacModeResult.BackColor = Color.Red;
  6555. label_FacModeResult.Text = "测试异常";
  6556. Delay_ms(500);
  6557. //存储异常并上传
  6558. FacMode_Stop(false);
  6559. return;
  6560. }
  6561. }
  6562. }
  6563. //写入SN
  6564. label_FacModeStatus.Text = "写入SN";
  6565. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN" + "\r\n");
  6566. textBox_FacModeNum.Text = InfoList[1];
  6567. string SN = textBox_FacModeNum.Text;
  6568. var SNArray = new byte[16];
  6569. for (ushort i = 0; i < SN.Length; i++)
  6570. {
  6571. SNArray[i] = (byte)SN[i];
  6572. }
  6573. if (SN.Length < 16)
  6574. {
  6575. SNArray[SN.Length] = (byte)'.';
  6576. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  6577. {
  6578. SNArray[SN.Length + 1 + i] = 0x20;
  6579. }
  6580. }
  6581. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6582. WriteACK = false;
  6583. ACK_WaitCnt = 0;
  6584. while (ACK_WaitCnt <= 2); //1s
  6585. if (WriteACK == true)
  6586. {
  6587. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  6588. }
  6589. else
  6590. {
  6591. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN,第1次重发" + "\r\n");
  6592. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  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") + "->" + "SN写入成功" + "\r\n");
  6598. }
  6599. else
  6600. {
  6601. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN,第2次重发" + "\r\n");
  6602. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  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") + "->" + "SN写入成功" + "\r\n");
  6608. }
  6609. else
  6610. {
  6611. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入失败" + "\r\n");
  6612. label_FacModeStatus.Text = "存在故障!";
  6613. label_FacModeResult.BackColor = Color.Red;
  6614. label_FacModeResult.Text = "测试异常";
  6615. Delay_ms(500);
  6616. //存储异常并上传
  6617. FacMode_Stop(false);
  6618. return;
  6619. }
  6620. }
  6621. }
  6622. }
  6623. else
  6624. {
  6625. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6626. return;
  6627. }
  6628. } while (false);
  6629. //写入配置文件
  6630. do
  6631. {
  6632. label_FacModeStatus.Text = "写入配置文件";
  6633. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  6634. //配置文件
  6635. List<byte[]> CmdList = new List<byte[]>();
  6636. //从服务器下载文件
  6637. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  6638. {
  6639. string SelectFile = "";
  6640. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "/" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  6641. if (File.Exists(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  6642. {
  6643. File.Delete(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  6644. }
  6645. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  6646. //打开文件
  6647. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  6648. CmdList.Clear();
  6649. while (streamReader.Peek() != -1)
  6650. {
  6651. string fileLineInfo = streamReader.ReadLine();
  6652. if (fileLineInfo.IndexOf("[") != -1)
  6653. {
  6654. continue;
  6655. }
  6656. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  6657. }
  6658. streamReader.Close();
  6659. }
  6660. //加载本地文件
  6661. else
  6662. {
  6663. string SelectFile = "";
  6664. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  6665. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  6666. CmdList.Clear();
  6667. while (streamReader.Peek() != -1)
  6668. {
  6669. string fileLineInfo = streamReader.ReadLine();
  6670. if (fileLineInfo.IndexOf("[") != -1)
  6671. {
  6672. continue;
  6673. }
  6674. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  6675. }
  6676. streamReader.Close();
  6677. }
  6678. int CmdNum = CmdList.Count(); //指令个数
  6679. Delay_ms(500);
  6680. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "开始写入" + "\r\n");
  6681. Delay_ms(500);
  6682. //开始写入
  6683. for (int i = 0; i < CmdList.Count; i++)
  6684. {
  6685. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令" + "\r\n");
  6686. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6687. WriteACK = false;
  6688. ACK_WaitCnt = 0;
  6689. while (ACK_WaitCnt <= 2) ; //1s
  6690. if (WriteACK == true)
  6691. {
  6692. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6693. }
  6694. else
  6695. {
  6696. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令,第1次重发" + "\r\n");
  6697. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6698. WriteACK = false;
  6699. ACK_WaitCnt = 0;
  6700. while (ACK_WaitCnt <= 2) ; //1s
  6701. if (WriteACK == true)
  6702. {
  6703. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6704. }
  6705. else
  6706. {
  6707. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令,第2次重发" + "\r\n");
  6708. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6709. WriteACK = false;
  6710. ACK_WaitCnt = 0;
  6711. while (ACK_WaitCnt <= 2) ; //1s
  6712. if (WriteACK == true)
  6713. {
  6714. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6715. }
  6716. else
  6717. {
  6718. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入失败," + "共" + CmdNum.ToString() + "条指令," + "写入成功" + i.ToString() + "条" + "\r\n");
  6719. label_FacModeStatus.Text = "存在故障!";
  6720. label_FacModeResult.BackColor = Color.Red;
  6721. label_FacModeResult.Text = "测试异常";
  6722. Delay_ms(500);
  6723. //存储异常并上传
  6724. FacMode_Stop(false);
  6725. return;
  6726. }
  6727. }
  6728. }
  6729. }
  6730. //写入完成
  6731. label_FacMode_CfgWrite.BackColor = Color.Green;
  6732. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入成功" + "\r\n");
  6733. Delay_ms(500);
  6734. } while (false);
  6735. }
  6736. else
  6737. {
  6738. label_FacMode_CfgWrite.BackColor = Color.Yellow;
  6739. label_FacModeStatus.Text = "跳过参数写入!";
  6740. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数写入" + "\r\n");
  6741. Delay_ms(500);
  6742. }
  6743. //BMS通讯
  6744. if (checkBox_FacModeBMS.Checked)
  6745. {
  6746. if (label_FacModeBMS.BackColor == Color.Red)
  6747. {
  6748. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "BMS通讯异常" + "\r\n");
  6749. label_FacModeStatus.Text = "存在故障!";
  6750. label_FacModeResult.BackColor = Color.Red;
  6751. label_FacModeResult.Text = "测试异常";
  6752. Delay_ms(500);
  6753. //存储异常并上传
  6754. FacMode_Stop(false);
  6755. return;
  6756. }
  6757. }
  6758. else
  6759. {
  6760. label_FacModeBMS.BackColor = Color.Yellow;
  6761. label_FacModeStatus.Text = "跳过BMS通讯检测!";
  6762. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过BMS通讯检测" + "\r\n");
  6763. Delay_ms(500);
  6764. }
  6765. //基础功能检测
  6766. if (checkBox_FacBaseFucTest.Checked)
  6767. {
  6768. label_FacModeStatus.Text = "基础功能检测";
  6769. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始基础功能检测" + "\r\n");
  6770. //确认负载位置
  6771. if (checkBox_FacMode_MosCal.Checked)
  6772. {
  6773. if (MessageBox.Show("请再次确认负载是否切换回电机?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  6774. {
  6775. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "负载已切换为电机,继续测试" + "\r\n");
  6776. }
  6777. else
  6778. {
  6779. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试取消" + "\r\n");
  6780. label_FacModeStatus.Text = "存在故障!";
  6781. label_FacModeResult.BackColor = Color.Red;
  6782. label_FacModeResult.Text = "测试异常";
  6783. Delay_ms(500);
  6784. //存储异常并上传
  6785. FacMode_Stop(false);
  6786. return;
  6787. }
  6788. }
  6789. //发送指令进入配置模式
  6790. do
  6791. {
  6792. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6793. Code[0] = 0x01;
  6794. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6795. WriteACK = false;
  6796. ACK_WaitCnt = 0;
  6797. while (ACK_WaitCnt <= 2); //1s
  6798. if (textBox_RunInfo_Vol.Text != "---")
  6799. {
  6800. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6801. }
  6802. else
  6803. {
  6804. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  6805. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6806. ACK_WaitCnt = 0;
  6807. while (ACK_WaitCnt <= 2) ; //1s
  6808. if (textBox_RunInfo_Vol.Text != "---")
  6809. {
  6810. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6811. }
  6812. else
  6813. {
  6814. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  6815. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6816. ACK_WaitCnt = 0;
  6817. while (ACK_WaitCnt <= 2) ; //1s
  6818. if (textBox_RunInfo_Vol.Text != "---")
  6819. {
  6820. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6821. }
  6822. else
  6823. {
  6824. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  6825. label_FacModeStatus.Text = "存在故障!";
  6826. label_FacModeResult.BackColor = Color.Red;
  6827. label_FacModeResult.Text = "测试异常";
  6828. Delay_ms(500);
  6829. //存储异常并上传
  6830. FacMode_Stop(false);
  6831. return;
  6832. }
  6833. }
  6834. }
  6835. } while (false);
  6836. //发送指令启动电机
  6837. do
  6838. {
  6839. #if false //通过运行模式3启动电机
  6840. //发送指令读取调试信息
  6841. richTextBox_DebugParam.Clear();
  6842. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  6843. WriteACK = false;
  6844. ACK_WaitCnt = 0;
  6845. while (ACK_WaitCnt <= 2); //1s
  6846. //获取调试信息
  6847. string DebugDefaultInfo = "";
  6848. if (richTextBox_DebugParam.Text == string.Empty)
  6849. {
  6850. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
  6851. label_FacModeStatus.Text = "存在故障!";
  6852. label_FacModeResult.BackColor = Color.Red;
  6853. label_FacModeResult.Text = "测试异常";
  6854. Delay_ms(500);
  6855. //存储异常并上传
  6856. FacMode_Stop(false);
  6857. return;
  6858. }
  6859. else
  6860. {
  6861. DebugDefaultInfo = richTextBox_DebugParam.Text;
  6862. }
  6863. //设置模式
  6864. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  6865. strDataTemp[0] = "整体运行模式=3";
  6866. //发送数据
  6867. Code[0] = 0;
  6868. Code[1] = 0;
  6869. for (int i = 0; i < strDataTemp.Length; i++)
  6870. {
  6871. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  6872. Code[2 * i + 2] = (byte)uwDataTemp;
  6873. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  6874. }
  6875. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  6876. label_FacModeStatus.Text = "启动电机";
  6877. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "启动电机" + "\r\n");
  6878. #else //通过Walk模式启动电机
  6879. //设置转速100%
  6880. var Data = new byte[1];
  6881. Data[0] = (byte)100;
  6882. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6883. Delay_ms(500);
  6884. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6885. Delay_ms(500);
  6886. //启动电机进入WALK模式
  6887. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "基础功能检测,进入WALK" + "\r\n");
  6888. Code[0] = 0x22;
  6889. Code[1] = 0xF0;
  6890. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6891. WriteACK = false;
  6892. ACK_WaitCnt = 0;
  6893. while (ACK_WaitCnt <= 2) ; //1s
  6894. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6895. {
  6896. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第1次重发" + "\r\n");
  6897. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6898. ACK_WaitCnt = 0;
  6899. while (ACK_WaitCnt <= 2) ; //1s
  6900. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6901. {
  6902. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第2次重发" + "\r\n");
  6903. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6904. ACK_WaitCnt = 0;
  6905. while (ACK_WaitCnt <= 2) ; //1s
  6906. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6907. {
  6908. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
  6909. label_FacModeStatus.Text = "存在故障!";
  6910. label_FacModeResult.BackColor = Color.Red;
  6911. label_FacModeResult.Text = "测试异常";
  6912. Delay_ms(500);
  6913. //存储异常并上传
  6914. FacMode_Stop(false);
  6915. return;
  6916. }
  6917. }
  6918. }
  6919. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入WALK,开始检测" + "\r\n");
  6920. #endif
  6921. Delay_ms(3000);
  6922. } while (false);
  6923. //判断车速
  6924. if ((Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) <= Convert.ToDouble( toolStripTextBox_ThBikeSpeed.Text.Split(',')[1])) &&
  6925. (Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThBikeSpeed.Text.Split(',')[0])))
  6926. {
  6927. label_FacModeSpeed.BackColor = Color.Green;
  6928. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器正常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
  6929. }
  6930. else
  6931. {
  6932. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器异常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
  6933. label_FacModeStatus.Text = "存在故障!";
  6934. label_FacModeResult.BackColor = Color.Red;
  6935. label_FacModeResult.Text = "测试异常";
  6936. Delay_ms(500);
  6937. //存储异常并上传
  6938. FacMode_Stop(false);
  6939. return;
  6940. }
  6941. //判断电压
  6942. if ((Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[1])) &&
  6943. (Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[0])))
  6944. {
  6945. label_FacModeVolTest.BackColor = Color.Green;
  6946. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量正常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
  6947. }
  6948. else
  6949. {
  6950. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量异常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
  6951. label_FacModeStatus.Text = "存在故障!";
  6952. label_FacModeResult.BackColor = Color.Red;
  6953. label_FacModeResult.Text = "测试异常";
  6954. Delay_ms(500);
  6955. //存储异常并上传
  6956. FacMode_Stop(false);
  6957. return;
  6958. }
  6959. //判断电流
  6960. if ((Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[1])) &&
  6961. (Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[0])))
  6962. {
  6963. label_FacModeCurrentTest.BackColor = Color.Green;
  6964. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量正常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  6965. }
  6966. else
  6967. {
  6968. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量异常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  6969. label_FacModeStatus.Text = "存在故障!";
  6970. label_FacModeResult.BackColor = Color.Red;
  6971. label_FacModeResult.Text = "测试异常";
  6972. Delay_ms(500);
  6973. //存储异常并上传
  6974. FacMode_Stop(false);
  6975. return;
  6976. }
  6977. //判断温度
  6978. if ((Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[1])) &&
  6979. (Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[0])) &&
  6980. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[1])) &&
  6981. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[0])) &&
  6982. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[1])) &&
  6983. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[0])))
  6984. {
  6985. label_FacModeNTC.BackColor = Color.Green;
  6986. 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");
  6987. }
  6988. else
  6989. {
  6990. 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");
  6991. label_FacModeStatus.Text = "存在故障!";
  6992. label_FacModeResult.BackColor = Color.Red;
  6993. label_FacModeResult.Text = "测试异常";
  6994. Delay_ms(500);
  6995. //存储异常并上传
  6996. FacMode_Stop(false);
  6997. return;
  6998. }
  6999. //判断转速
  7000. if ((Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[1])) &&
  7001. (Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[0])))
  7002. {
  7003. label_FacModeMotorSpeed.BackColor = Color.Green;
  7004. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速正常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
  7005. }
  7006. else
  7007. {
  7008. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速异常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
  7009. label_FacModeStatus.Text = "存在故障!";
  7010. label_FacModeResult.BackColor = Color.Red;
  7011. label_FacModeResult.Text = "测试异常";
  7012. Delay_ms(500);
  7013. //存储异常并上传
  7014. FacMode_Stop(false);
  7015. return;
  7016. }
  7017. //发送指令停止电机
  7018. do
  7019. {
  7020. //设置转速0%
  7021. var Data = new byte[1];
  7022. Data[0] = (byte)0;
  7023. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7024. Delay_ms(500);
  7025. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7026. Delay_ms(500);
  7027. #if false //通过修改调试模式停止电机
  7028. //获取调试信息
  7029. string DebugDefaultInfo = "";
  7030. if (richTextBox_DebugParam.Text == string.Empty)
  7031. {
  7032. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
  7033. label_FacModeStatus.Text = "存在故障!";
  7034. label_FacModeResult.BackColor = Color.Red;
  7035. label_FacModeResult.Text = "测试异常";
  7036. Delay_ms(500);
  7037. //存储异常并上传
  7038. FacMode_Stop(false);
  7039. return;
  7040. }
  7041. else
  7042. {
  7043. DebugDefaultInfo = richTextBox_DebugParam.Text;
  7044. }
  7045. //设置模式
  7046. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  7047. //发送数据
  7048. Code[0] = 0;
  7049. Code[1] = 0;
  7050. for (int i = 0; i < strDataTemp.Length; i++)
  7051. {
  7052. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  7053. Code[2 * i + 2] = (byte)uwDataTemp;
  7054. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  7055. }
  7056. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  7057. label_FacModeStatus.Text = "停止电机";
  7058. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "停止电机" + "\r\n");
  7059. #else //通过调整档位停止电机
  7060. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK" + "\r\n");
  7061. Code[0] = 0x00;
  7062. Code[1] = 0xF0;
  7063. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7064. WriteACK = false;
  7065. ACK_WaitCnt = 0;
  7066. while (ACK_WaitCnt <= 2) ; //1s
  7067. if (textBox_RunInfo_GearSt.Text != "OFF")
  7068. {
  7069. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK,第1次重发" + "\r\n");
  7070. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7071. ACK_WaitCnt = 0;
  7072. while (ACK_WaitCnt <= 2) ; //1s
  7073. if (textBox_RunInfo_GearSt.Text != "OFF")
  7074. {
  7075. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK,第2次重发" + "\r\n");
  7076. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7077. ACK_WaitCnt = 0;
  7078. while (ACK_WaitCnt <= 2) ; //1s
  7079. if (textBox_RunInfo_GearSt.Text != "OFF")
  7080. {
  7081. }
  7082. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
  7083. label_FacModeStatus.Text = "存在故障!";
  7084. label_FacModeResult.BackColor = Color.Red;
  7085. label_FacModeResult.Text = "测试异常";
  7086. Delay_ms(500);
  7087. //存储异常并上传
  7088. FacMode_Stop(false);
  7089. return;
  7090. }
  7091. }
  7092. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已退出WALK,基础功能检测完成" + "\r\n");
  7093. #endif
  7094. Delay_ms(2000);
  7095. } while (false);
  7096. }
  7097. else
  7098. {
  7099. label_FacModeSpeed.BackColor = Color.Yellow;
  7100. label_FacModeVolTest.BackColor = Color.Yellow;
  7101. label_FacModeCurrentTest.BackColor = Color.Yellow;
  7102. label_FacModeNTC.BackColor = Color.Yellow;
  7103. label_FacModeMotorSpeed.BackColor = Color.Yellow;
  7104. label_FacModeStatus.Text = "跳过基础功能检测!";
  7105. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过基础功能检测" + "\r\n");
  7106. Delay_ms(500);
  7107. }
  7108. //力矩检测
  7109. if (checkBox_FacTor.Checked)
  7110. {
  7111. label_FacModeStatus.Text = "力矩传感器检测!";
  7112. //发送指令进入配置模式
  7113. do
  7114. {
  7115. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  7116. {
  7117. break;
  7118. }
  7119. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  7120. Code[0] = 0x01;
  7121. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7122. WriteACK = false;
  7123. ACK_WaitCnt = 0;
  7124. while (ACK_WaitCnt <= 2) ; //1s
  7125. if (textBox_RunInfo_Vol.Text != "---")
  7126. {
  7127. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7128. Delay_ms(500);
  7129. }
  7130. else
  7131. {
  7132. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  7133. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7134. ACK_WaitCnt = 0;
  7135. while (ACK_WaitCnt <= 2) ; //1s
  7136. if (textBox_RunInfo_Vol.Text != "---")
  7137. {
  7138. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7139. Delay_ms(500);
  7140. }
  7141. else
  7142. {
  7143. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7144. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7145. ACK_WaitCnt = 0;
  7146. while (ACK_WaitCnt <= 2) ; //1s
  7147. if (textBox_RunInfo_Vol.Text != "---")
  7148. {
  7149. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7150. Delay_ms(500);
  7151. }
  7152. else
  7153. {
  7154. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7155. label_FacModeStatus.Text = "存在故障!";
  7156. label_FacModeResult.BackColor = Color.Red;
  7157. label_FacModeResult.Text = "测试异常";
  7158. Delay_ms(500);
  7159. //存储异常并上传
  7160. FacMode_Stop(false);
  7161. return;
  7162. }
  7163. }
  7164. }
  7165. } while (false);
  7166. ushort Max = 0, Torque = 0;
  7167. //提示输入力矩信号
  7168. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟力矩信号输入" + "\r\n");
  7169. ACK_WaitCnt = 0;
  7170. while (ACK_WaitCnt <= 20) //10s
  7171. {
  7172. //获取力矩值
  7173. Torque = (ushort)Convert.ToInt16(textBox_RunInfo_Torque.Text.Split(' ')[0]);
  7174. if (Torque > Max)
  7175. Max = Torque;
  7176. if ((Max <= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[1])) &&
  7177. (Max >= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[0])) &&
  7178. (ACK_WaitCnt >= 6))
  7179. {
  7180. label_FacModeTq.BackColor = Color.Green;
  7181. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器正常" + " " + textBox_RunInfo_Torque.Text + "\r\n");
  7182. break;
  7183. }
  7184. }
  7185. if (ACK_WaitCnt >= 20)
  7186. {
  7187. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器异常" + " " + textBox_RunInfo_Torque.Text + "\r\n");
  7188. label_FacModeStatus.Text = "存在故障!";
  7189. label_FacModeResult.BackColor = Color.Red;
  7190. label_FacModeResult.Text = "测试异常";
  7191. Delay_ms(500);
  7192. //存储异常并上传
  7193. FacMode_Stop(false);
  7194. return;
  7195. }
  7196. }
  7197. else
  7198. {
  7199. label_FacModeTq.BackColor = Color.Yellow;
  7200. label_FacModeStatus.Text = "跳过力矩检测!";
  7201. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过力矩检测" + "\r\n");
  7202. Delay_ms(500);
  7203. }
  7204. //踏频检测
  7205. if (checkBox_FacCad.Checked)
  7206. {
  7207. label_FacModeStatus.Text = "踏频传感器检测!";
  7208. //发送指令进入配置模式
  7209. do
  7210. {
  7211. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  7212. {
  7213. break;
  7214. }
  7215. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  7216. Code[0] = 0x01;
  7217. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7218. WriteACK = false;
  7219. ACK_WaitCnt = 0;
  7220. while (ACK_WaitCnt <= 2) ; //1s
  7221. if (textBox_RunInfo_Vol.Text != "---")
  7222. {
  7223. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7224. Delay_ms(500);
  7225. }
  7226. else
  7227. {
  7228. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  7229. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7230. ACK_WaitCnt = 0;
  7231. while (ACK_WaitCnt <= 2) ; //1s
  7232. if (textBox_RunInfo_Vol.Text != "---")
  7233. {
  7234. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7235. Delay_ms(500);
  7236. }
  7237. else
  7238. {
  7239. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7240. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7241. ACK_WaitCnt = 0;
  7242. while (ACK_WaitCnt <= 2) ; //1s
  7243. if (textBox_RunInfo_Vol.Text != "---")
  7244. {
  7245. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7246. Delay_ms(500);
  7247. }
  7248. else
  7249. {
  7250. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7251. label_FacModeStatus.Text = "存在故障!";
  7252. label_FacModeResult.BackColor = Color.Red;
  7253. label_FacModeResult.Text = "测试异常";
  7254. Delay_ms(500);
  7255. //存储异常并上传
  7256. FacMode_Stop(false);
  7257. return;
  7258. }
  7259. }
  7260. }
  7261. } while (false);
  7262. ushort Max = 0, Cadence = 0;
  7263. //提示输入踏频信号
  7264. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟踏频信号输入" + "\r\n");
  7265. ACK_WaitCnt = 0;
  7266. while (ACK_WaitCnt <= 20) //10s
  7267. {
  7268. //获取踏频
  7269. Cadence = (ushort)Convert.ToInt16(textBox_RunInfo_Cadence.Text.Split(' ')[0]);
  7270. if (Cadence > Max)
  7271. Max = Cadence;
  7272. if ((Max <= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[1])) &&
  7273. (Max >= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[0])) &&
  7274. (ACK_WaitCnt >= 6))
  7275. {
  7276. label_FacModeCad.BackColor = Color.Green;
  7277. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器正常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  7278. break;
  7279. }
  7280. }
  7281. if (ACK_WaitCnt >= 20)
  7282. {
  7283. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器异常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  7284. label_FacModeStatus.Text = "存在故障!";
  7285. label_FacModeResult.BackColor = Color.Red;
  7286. label_FacModeResult.Text = "测试异常";
  7287. Delay_ms(500);
  7288. //存储异常并上传
  7289. FacMode_Stop(false);
  7290. return;
  7291. }
  7292. }
  7293. else
  7294. {
  7295. label_FacModeCad.BackColor = Color.Yellow;
  7296. label_FacModeStatus.Text = "跳过踏频检测!";
  7297. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过踏频检测" + "\r\n");
  7298. Delay_ms(500);
  7299. }
  7300. //转把检测
  7301. if (checkBox_FacThrrotleTest.Checked)
  7302. {
  7303. label_FacModeStatus.Text = "转把检测";
  7304. //发送指令进入配置模式
  7305. do
  7306. {
  7307. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  7308. {
  7309. break;
  7310. }
  7311. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  7312. Code[0] = 0x01;
  7313. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7314. WriteACK = false;
  7315. ACK_WaitCnt = 0;
  7316. while (ACK_WaitCnt <= 2) ; //1s
  7317. if (textBox_RunInfo_Vol.Text != "---")
  7318. {
  7319. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7320. Delay_ms(500);
  7321. }
  7322. else
  7323. {
  7324. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  7325. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7326. ACK_WaitCnt = 0;
  7327. while (ACK_WaitCnt <= 2) ; //1s
  7328. if (textBox_RunInfo_Vol.Text != "---")
  7329. {
  7330. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7331. Delay_ms(500);
  7332. }
  7333. else
  7334. {
  7335. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7336. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7337. ACK_WaitCnt = 0;
  7338. while (ACK_WaitCnt <= 2) ; //1s
  7339. if (textBox_RunInfo_Vol.Text != "---")
  7340. {
  7341. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7342. Delay_ms(500);
  7343. }
  7344. else
  7345. {
  7346. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7347. label_FacModeStatus.Text = "存在故障!";
  7348. label_FacModeResult.BackColor = Color.Red;
  7349. label_FacModeResult.Text = "测试异常";
  7350. Delay_ms(500);
  7351. //存储异常并上传
  7352. FacMode_Stop(false);
  7353. return;
  7354. }
  7355. }
  7356. }
  7357. } while (false);
  7358. //进入TURBO档
  7359. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把检测,发送指令进入TURBO" + "\r\n");
  7360. Code[0] = 0x04;
  7361. Code[1] = 0xF0;
  7362. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7363. WriteACK = false;
  7364. ACK_WaitCnt = 0;
  7365. while (ACK_WaitCnt <= 2) ; //1s
  7366. if (textBox_RunInfo_GearSt.Text != "TURBO")
  7367. {
  7368. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO,第1次重发" + "\r\n");
  7369. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7370. ACK_WaitCnt = 0;
  7371. while (ACK_WaitCnt <= 2) ; //1s
  7372. if (textBox_RunInfo_GearSt.Text != "TURBO")
  7373. {
  7374. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO,第2次重发" + "\r\n");
  7375. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7376. ACK_WaitCnt = 0;
  7377. while (ACK_WaitCnt <= 2) ; //1s
  7378. if (textBox_RunInfo_GearSt.Text != "TURBO")
  7379. {
  7380. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO异常" + "\r\n");
  7381. label_FacModeStatus.Text = "存在故障!";
  7382. label_FacModeResult.BackColor = Color.Red;
  7383. label_FacModeResult.Text = "测试异常";
  7384. Delay_ms(500);
  7385. //存储异常并上传
  7386. FacMode_Stop(false);
  7387. return;
  7388. }
  7389. }
  7390. }
  7391. //进入TURBO后,如果电机直接启动,认为转把电压异常
  7392. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把自检,请松开转把" + "\r\n");
  7393. Delay_ms(3000);
  7394. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) > 500)
  7395. {
  7396. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把电压异常" + "\r\n");
  7397. label_FacModeStatus.Text = "存在故障!";
  7398. label_FacModeResult.BackColor = Color.Red;
  7399. label_FacModeResult.Text = "测试异常";
  7400. Delay_ms(500);
  7401. //存储异常并上传
  7402. FacMode_Stop(false);
  7403. return;
  7404. }
  7405. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把自检正常" + "\r\n");
  7406. Delay_ms(500);
  7407. //提示转动转把
  7408. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入TURBO,10s内转动转把" + "\r\n");
  7409. ACK_WaitCnt = 0;
  7410. while (ACK_WaitCnt <= 20)
  7411. {
  7412. if ((Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) > 500) && (ACK_WaitCnt >= 10))
  7413. {
  7414. label_FacModeGas.BackColor = Color.Green;
  7415. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能正常,松开转把" + "\r\n");
  7416. break;
  7417. }
  7418. }
  7419. if (ACK_WaitCnt >= 20) //转把超时
  7420. {
  7421. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能异常,松开转把" + "\r\n");
  7422. label_FacModeStatus.Text = "存在故障!";
  7423. label_FacModeResult.BackColor = Color.Red;
  7424. label_FacModeResult.Text = "测试异常";
  7425. Delay_ms(500);
  7426. //存储异常并上传
  7427. FacMode_Stop(false);
  7428. return;
  7429. }
  7430. }
  7431. else
  7432. {
  7433. label_FacModeGas.BackColor = Color.Yellow;
  7434. label_FacModeStatus.Text = "跳过转把检测!";
  7435. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过转把检测" + "\r\n");
  7436. Delay_ms(500);
  7437. }
  7438. //刹车检测
  7439. if (checkBox_FacBreakTest.Checked)
  7440. {
  7441. label_FacModeStatus.Text = "刹把检测";
  7442. //发送指令进入配置模式
  7443. do
  7444. {
  7445. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  7446. {
  7447. break;
  7448. }
  7449. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  7450. Code[0] = 0x01;
  7451. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7452. WriteACK = false;
  7453. ACK_WaitCnt = 0;
  7454. while (ACK_WaitCnt <= 2) ; //1s
  7455. if (textBox_RunInfo_Vol.Text != "---")
  7456. {
  7457. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7458. Delay_ms(500);
  7459. }
  7460. else
  7461. {
  7462. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  7463. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7464. ACK_WaitCnt = 0;
  7465. while (ACK_WaitCnt <= 2) ; //1s
  7466. if (textBox_RunInfo_Vol.Text != "---")
  7467. {
  7468. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7469. Delay_ms(500);
  7470. }
  7471. else
  7472. {
  7473. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7474. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7475. ACK_WaitCnt = 0;
  7476. while (ACK_WaitCnt <= 2) ; //1s
  7477. if (textBox_RunInfo_Vol.Text != "---")
  7478. {
  7479. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7480. Delay_ms(500);
  7481. }
  7482. else
  7483. {
  7484. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7485. label_FacModeStatus.Text = "存在故障!";
  7486. label_FacModeResult.BackColor = Color.Red;
  7487. label_FacModeResult.Text = "测试异常";
  7488. Delay_ms(500);
  7489. //存储异常并上传
  7490. FacMode_Stop(false);
  7491. return;
  7492. }
  7493. }
  7494. }
  7495. } while (false);
  7496. //测试前先确定电机已停止
  7497. UInt16 WaitTime = 10;
  7498. do
  7499. {
  7500. WaitTime--;
  7501. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 100)
  7502. {
  7503. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机停止,开始进行剎把检测,进入WALK" + "\r\n");
  7504. break;
  7505. }
  7506. if (WaitTime == 0)
  7507. {
  7508. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机无法停止,剎把检测异常" + "\r\n");
  7509. label_FacModeStatus.Text = "存在故障!";
  7510. label_FacModeResult.BackColor = Color.Red;
  7511. label_FacModeResult.Text = "测试异常";
  7512. Delay_ms(500);
  7513. //存储异常并上传
  7514. FacMode_Stop(false);
  7515. return;
  7516. }
  7517. Delay_ms(500);
  7518. } while (true);
  7519. //设置转速100%
  7520. var Data = new byte[1];
  7521. Data[0] = (byte)100;
  7522. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7523. Delay_ms(500);
  7524. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7525. Delay_ms(500);
  7526. //启动电机进入WALK模式
  7527. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把检测,进入WALK" + "\r\n");
  7528. Code[0] = 0x22;
  7529. Code[1] = 0xF0;
  7530. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7531. WriteACK = false;
  7532. ACK_WaitCnt = 0;
  7533. while (ACK_WaitCnt <= 2) ; //1s
  7534. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 500))
  7535. {
  7536. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第1次重发" + "\r\n");
  7537. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7538. ACK_WaitCnt = 0;
  7539. while (ACK_WaitCnt <= 2) ; //1s
  7540. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 500))
  7541. {
  7542. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第2次重发" + "\r\n");
  7543. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7544. ACK_WaitCnt = 0;
  7545. while (ACK_WaitCnt <= 2) ; //1s
  7546. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 500))
  7547. {
  7548. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
  7549. label_FacModeStatus.Text = "存在故障!";
  7550. label_FacModeResult.BackColor = Color.Red;
  7551. label_FacModeResult.Text = "测试异常";
  7552. Delay_ms(500);
  7553. //存储异常并上传
  7554. FacMode_Stop(false);
  7555. return;
  7556. }
  7557. }
  7558. }
  7559. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,10s内操作剎把" + "\r\n");
  7560. ACK_WaitCnt = 0;
  7561. while (ACK_WaitCnt <= 20)
  7562. {
  7563. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 100)
  7564. {
  7565. label_FacModeBreak.BackColor = Color.Green;
  7566. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把功能正常,松开剎把" + "\r\n");
  7567. break;
  7568. }
  7569. }
  7570. if (ACK_WaitCnt >= 20) //剎把超时
  7571. {
  7572. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速:" + textBox_RunInfo_MotorSpeed.Text + "," + "剎把功能异常,松开剎把" + "\r\n");
  7573. label_FacModeStatus.Text = "存在故障!";
  7574. label_FacModeResult.BackColor = Color.Red;
  7575. label_FacModeResult.Text = "测试异常";
  7576. Delay_ms(500);
  7577. //存储异常并上传
  7578. FacMode_Stop(false);
  7579. return;
  7580. }
  7581. //停止电机
  7582. Code[0] = 0x00;
  7583. Code[1] = 0xF0;
  7584. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7585. WriteACK = false;
  7586. ACK_WaitCnt = 0;
  7587. while (ACK_WaitCnt <= 2) ; //1s
  7588. if (textBox_RunInfo_GearSt.Text != "OFF")
  7589. {
  7590. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK,第1次重发" + "\r\n");
  7591. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7592. ACK_WaitCnt = 0;
  7593. while (ACK_WaitCnt <= 2) ; //1s
  7594. if (textBox_RunInfo_GearSt.Text != "OFF")
  7595. {
  7596. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK,第2次重发" + "\r\n");
  7597. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7598. ACK_WaitCnt = 0;
  7599. while (ACK_WaitCnt <= 2) ; //1s
  7600. if (textBox_RunInfo_GearSt.Text != "OFF")
  7601. {
  7602. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
  7603. label_FacModeStatus.Text = "存在故障!";
  7604. label_FacModeResult.BackColor = Color.Red;
  7605. label_FacModeResult.Text = "测试异常";
  7606. Delay_ms(500);
  7607. //存储异常并上传
  7608. FacMode_Stop(false);
  7609. return;
  7610. }
  7611. }
  7612. }
  7613. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK" + "\r\n");
  7614. Delay_ms(500);
  7615. }
  7616. else
  7617. {
  7618. label_FacModeBreak.BackColor = Color.Yellow;
  7619. label_FacModeStatus.Text = "跳过刹车检测!";
  7620. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过刹车检测" + "\r\n");
  7621. Delay_ms(500);
  7622. }
  7623. //前后灯检测
  7624. if (checkBox_FacLightTest.Checked)
  7625. {
  7626. //前后灯检测
  7627. label_FacModeStatus.Text = "前后灯检测";
  7628. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开灯指令" + "\r\n");
  7629. //发送指令打开车灯
  7630. Code[0] = 0x00;
  7631. Code[1] = 0xF1;
  7632. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7633. WriteACK = false;
  7634. ACK_WaitCnt = 0;
  7635. while (ACK_WaitCnt <= 2) ; //1s
  7636. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7637. {
  7638. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令,第1次重发" + "\r\n");
  7639. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7640. ACK_WaitCnt = 0;
  7641. while (ACK_WaitCnt <= 2); //1s
  7642. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7643. {
  7644. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令,第2次重发" + "\r\n");
  7645. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7646. ACK_WaitCnt = 0;
  7647. while (ACK_WaitCnt <= 2) ; //1s
  7648. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7649. {
  7650. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令发送异常" + "\r\n");
  7651. label_FacModeStatus.Text = "存在故障!";
  7652. label_FacModeResult.BackColor = Color.Red;
  7653. label_FacModeResult.Text = "测试异常";
  7654. Delay_ms(500);
  7655. //存储异常并上传
  7656. FacMode_Stop(false);
  7657. return;
  7658. }
  7659. }
  7660. }
  7661. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已打开前后灯" + "\r\n");
  7662. Delay_ms(500);
  7663. //提示检查灯压是否正确
  7664. if (MessageBox.Show("前后灯是否正常开启?", "前后灯判断", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  7665. {
  7666. label_FacModeLightF.BackColor = Color.Green;
  7667. label_FacModeLightB.BackColor = Color.Green;
  7668. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯正常" + "\r\n");
  7669. Delay_ms(500);
  7670. }
  7671. else
  7672. {
  7673. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯异常" + "\r\n");
  7674. label_FacModeStatus.Text = "存在故障!";
  7675. label_FacModeResult.BackColor = Color.Red;
  7676. label_FacModeResult.Text = "测试异常";
  7677. Delay_ms(500);
  7678. //存储异常并上传
  7679. FacMode_Stop(false);
  7680. return;
  7681. }
  7682. //发送指令关闭车灯
  7683. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关灯指令" + "\r\n");
  7684. Code[0] = 0x00;
  7685. Code[1] = 0xF0;
  7686. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7687. WriteACK = false;
  7688. ACK_WaitCnt = 0;
  7689. while (ACK_WaitCnt <= 2) ; //1s
  7690. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7691. {
  7692. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令,第1次重发" + "\r\n");
  7693. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7694. ACK_WaitCnt = 0;
  7695. while (ACK_WaitCnt <= 2) ; //1s
  7696. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7697. {
  7698. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令,第2次重发" + "\r\n");
  7699. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7700. ACK_WaitCnt = 0;
  7701. while (ACK_WaitCnt <= 2) ; //1s
  7702. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7703. {
  7704. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令发送异常" + "\r\n");
  7705. label_FacModeStatus.Text = "存在故障!";
  7706. label_FacModeResult.BackColor = Color.Red;
  7707. label_FacModeResult.Text = "测试异常";
  7708. Delay_ms(500);
  7709. //存储异常并上传
  7710. FacMode_Stop(false);
  7711. return;
  7712. }
  7713. }
  7714. }
  7715. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已关闭前后灯" + "\r\n");
  7716. Delay_ms(500);
  7717. }
  7718. else
  7719. {
  7720. label_FacModeLightF.BackColor = Color.Yellow;
  7721. label_FacModeLightB.BackColor = Color.Yellow;
  7722. label_FacModeStatus.Text = "跳过前后灯检测!";
  7723. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过前后灯检测" + "\r\n");
  7724. Delay_ms(500);
  7725. }
  7726. //软件版本检测
  7727. do
  7728. {
  7729. label_FacModeStatus.Text = "软件版本确认";
  7730. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  7731. //发送指令读取版本
  7732. Class_Motor_Ver.Mode = "---";
  7733. Class_Motor_Ver.SN = "---";
  7734. Class_Motor_Ver.HW = "---";
  7735. Class_Motor_Ver.FW = "---";
  7736. Class_Motor_Ver.Special = "---";
  7737. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7738. ACK_WaitCnt = 0;
  7739. while (ACK_WaitCnt <= 2) ; //1s
  7740. if (Class_Motor_Ver.Mode == "---")
  7741. {
  7742. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第1次重发" + "\r\n");
  7743. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7744. ACK_WaitCnt = 0;
  7745. while (ACK_WaitCnt <= 2) ; //1s
  7746. if (Class_Motor_Ver.Mode == "---")
  7747. {
  7748. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第2次重发" + "\r\n");
  7749. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7750. ACK_WaitCnt = 0;
  7751. while (ACK_WaitCnt <= 2) ; //1s
  7752. if (Class_Motor_Ver.Mode == "---")
  7753. {
  7754. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息失败" + "\r\n");
  7755. label_FacModeStatus.Text = "存在故障!";
  7756. label_FacModeResult.BackColor = Color.Red;
  7757. label_FacModeResult.Text = "测试异常";
  7758. Delay_ms(500);
  7759. //存储异常并上传
  7760. FacMode_Stop(false);
  7761. return;
  7762. }
  7763. }
  7764. }
  7765. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  7766. richTextBox_FacModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  7767. richTextBox_FacModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  7768. richTextBox_FacModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  7769. richTextBox_FacModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  7770. richTextBox_FacModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  7771. //判断版本是否正确
  7772. string VerCheck = comboBox_FacModeCfgFile.Text.Split('_')[3] + "_" + comboBox_FacModeCfgFile.Text.Split('_')[4];
  7773. string VerRead = "";
  7774. try
  7775. {
  7776. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  7777. }
  7778. catch (System.Exception)
  7779. {
  7780. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  7781. label_FacModeStatus.Text = "存在故障!";
  7782. label_FacModeResult.BackColor = Color.Red;
  7783. label_FacModeResult.Text = "测试异常";
  7784. Delay_ms(500);
  7785. //存储异常并上传
  7786. FacMode_Stop(false);
  7787. return;
  7788. }
  7789. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  7790. {
  7791. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
  7792. label_FacModeStatus.Text = "存在故障!";
  7793. label_FacModeResult.BackColor = Color.Red;
  7794. label_FacModeResult.Text = "测试异常";
  7795. Delay_ms(500);
  7796. //存储异常并上传
  7797. FacMode_Stop(false);
  7798. return;
  7799. }
  7800. label_FacModeFWVersion.BackColor = Color.Green;
  7801. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  7802. Delay_ms(500);
  7803. } while (false);
  7804. //测试合格
  7805. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  7806. label_FacModeStatus.Text = "测试结束!";
  7807. label_FacModeResult.BackColor = Color.Green;
  7808. label_FacModeResult.Text = "测试合格";
  7809. Delay_ms(500);
  7810. //存储并上传
  7811. FacMode_Stop(true);
  7812. return;
  7813. }
  7814. private void FacModelLabelInit()
  7815. {
  7816. //测试状态标签
  7817. label_FacModeResult.BackColor = Color.Yellow;
  7818. label_FacModeResult.Text = "测试中";
  7819. //测试过程标签
  7820. label_FacModeStatus.Text = "测试就绪";
  7821. //测试结果标签
  7822. foreach (Control c in groupBox28.Controls)
  7823. {
  7824. if (c is Label)
  7825. {
  7826. if (c.Text == string.Empty)
  7827. c.BackColor = Color.Red;
  7828. }
  7829. }
  7830. }
  7831. private void comboBox_CheckModeCfgDate_Click(object sender, EventArgs e)
  7832. {
  7833. //更新生产配置文件目录
  7834. GetDateList(false);
  7835. }
  7836. private void comboBox_FacModeCfgDate_Click(object sender, EventArgs e)
  7837. {
  7838. //更新生产配置文件目录
  7839. GetDateList(false);
  7840. }
  7841. private void richTextBox_FacModeLog_TextChanged(object sender, EventArgs e)
  7842. {
  7843. richTextBox_FacModeLog.SelectionStart = richTextBox_FacModeLog.Text.Length;
  7844. richTextBox_FacModeLog.ScrollToCaret();
  7845. }
  7846. /// <summary>
  7847. /// 参数检验测试停止
  7848. /// </summary>
  7849. /// <param name="OK_Flag"></param>
  7850. private void CheckMode_Stop(bool OK_Flag)
  7851. {
  7852. //打开开始按钮
  7853. button_CheckModeStart.Enabled = true;
  7854. //导出电机参数
  7855. string Params = "";
  7856. do
  7857. {
  7858. if (!OK_Flag)
  7859. {
  7860. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试异常,停止导出" + "\r\n");
  7861. break;
  7862. }
  7863. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "导出电机存储参数" + "\r\n");
  7864. //读取一次马达参数
  7865. richTextBox_MotorParam.Clear();
  7866. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break; ;
  7867. Delay_ms(100);
  7868. Params += "[马达参数]" + "\r\n" + richTextBox_MotorParam.Text + "\r\n";
  7869. Params += "\r\n";
  7870. //读取一次整车参数
  7871. richTextBox_BikeParam.Clear();
  7872. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  7873. Delay_ms(100);
  7874. Params += "[整车参数]" + "\r\n" + richTextBox_BikeParam.Text + "\r\n";
  7875. Params += "\r\n";
  7876. //读取一次控制参数
  7877. richTextBox_ControlParam.Clear();
  7878. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  7879. Delay_ms(100);
  7880. Params += "[控制参数]" + "\r\n" + richTextBox_ControlParam.Text + "\r\n";
  7881. Params += "\r\n";
  7882. //查询传感器
  7883. richTextBox_SensorParam.Clear();
  7884. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  7885. Delay_ms(100);
  7886. Params += "[传感器参数]" + "\r\n" + richTextBox_SensorParam.Text + "\r\n";
  7887. Params += "\r\n";
  7888. //读取15次助力参数
  7889. Params += "[助力参数]" + "\r\n";
  7890. for (int i = 1; i <= 15; i++)
  7891. {
  7892. var ConfigParam = new byte[4];
  7893. richTextBox_AssistParam.Clear();
  7894. ConfigParam[0] = (byte)(i & 0xFF);
  7895. ConfigParam[1] = (byte)(i >> 8);
  7896. ConfigParam[2] = (byte)(((i >= 5) ? 5 : i) & 0xFF);
  7897. ConfigParam[3] = (byte)(((i >= 5) ? 5 : i) >> 8);
  7898. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  7899. Delay_ms(200);
  7900. Params += richTextBox_AssistParam.Text + "\r\n";
  7901. Params += "\r\n";
  7902. }
  7903. //读取一次调试信息
  7904. richTextBox_DebugParam.Clear();
  7905. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  7906. Delay_ms(100);
  7907. Params += "[调试参数]" + "\r\n" + richTextBox_DebugParam.Text + "\r\n";
  7908. Params += "\r\n";
  7909. //读取一次历史信息
  7910. richTextBox_Record.Clear();
  7911. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  7912. Delay_ms(100);
  7913. Params += "[历史信息]" + "\r\n" + richTextBox_Record.Text + "\r\n";
  7914. Params += "\r\n";
  7915. //读取一次MOS内阻校准参数
  7916. foreach (Control c in groupBox21.Controls)
  7917. {
  7918. if (c is TextBox)
  7919. c.Text = "";
  7920. }
  7921. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  7922. Delay_ms(100);
  7923. Params += "[MOS内阻校准参数]" + "\r\n";
  7924. Params += textBox_MOS_K1.Text + ", " + textBox_MOS_K2.Text + ", " + textBox_MOS_K3.Text + ", " + textBox_MOS_K4.Text + ", "
  7925. + textBox_MOS_K5.Text + ", " + textBox_MOS_R1.Text + ", " + textBox_MOS_R2.Text + ", " + textBox_MOS_R3.Text + ", " + "\r\n";
  7926. Params += "\r\n";
  7927. //读取一次整车参数2
  7928. richTextBox_BikeParam2.Clear();
  7929. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null)) break;
  7930. Delay_ms(100);
  7931. Params += "[整车参数2]" + "\r\n" + richTextBox_BikeParam2.Text + "\r\n";
  7932. Params += "\r\n";
  7933. //读取一次用户骑行参数
  7934. richTextBox_UsrRidesParam.Clear();
  7935. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  7936. Delay_ms(100);
  7937. Params += "[用户骑行参数]" + "\r\n" + richTextBox_UsrRidesParam.Text + "\r\n";
  7938. Params += "\r\n";
  7939. //读取一次生产信息
  7940. textBox_MAC.Text = "";
  7941. textBox_MACAdd.Text = "";
  7942. textBox_MACDate.Text = "";
  7943. textBox_PP.Text = "";
  7944. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  7945. Delay_ms(100);
  7946. Params += "[生产信息]" + "\r\n";
  7947. Params += "生产商: " + textBox_MAC.Text + "\r\n";
  7948. Params += "生产地: " + textBox_MACAdd.Text + "\r\n";
  7949. Params += "生产日期: " + textBox_MACDate.Text + "\r\n";
  7950. Params += "产品标识: " + textBox_PP.Text + "\r\n";
  7951. Params += "\r\n";
  7952. //读取一次自定义信息
  7953. textBox_User1.Text = "---";
  7954. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  7955. Delay_ms(100);
  7956. textBox_User2.Text = "---";
  7957. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  7958. Delay_ms(100);
  7959. textBox_User3.Text = "---";
  7960. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  7961. Delay_ms(100);
  7962. Params += "[自定义信息]" + "\r\n";
  7963. Params += "自定义1: " + textBox_User1.Text + "\r\n";
  7964. Params += "自定义2: " + textBox_User2.Text + "\r\n";
  7965. Params += "自定义3: " + textBox_User3.Text + "\r\n";
  7966. Params += "\r\n";
  7967. //读取一次密钥
  7968. textBox_Key.Text = "---";
  7969. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  7970. Delay_ms(100);
  7971. Params += "[校验密钥]" + "\r\n" + textBox_Key.Text + "\r\n";
  7972. Params += "\r\n";
  7973. //读取一次存储标志
  7974. radioButton_EE_SaveYes.Checked = false;
  7975. radioButton_EE_SaveNo.Checked = false;
  7976. radioButton_SIP_SaveYes.Checked = false;
  7977. radioButton_SIP_SaveNo.Checked = false;
  7978. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  7979. Delay_ms(100);
  7980. Params += "[存储标志]" + "\r\n";
  7981. Params += "EEPROM: " + ((radioButton_EE_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  7982. Params += "SIP: " + ((radioButton_SIP_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  7983. Params += "\r\n";
  7984. } while (false);
  7985. //系统关机
  7986. var Code = new byte[32];//发送的指令数据
  7987. Code[0] = 0xF0;
  7988. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  7989. //关闭串口
  7990. //mySerialProcess.SerialClose(false);
  7991. //路径设置
  7992. string LocalSavePath = "";
  7993. string ServerSavePath = "";
  7994. if (OK_Flag)
  7995. {
  7996. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "OK\\";
  7997. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/OK/";
  7998. }
  7999. else
  8000. {
  8001. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "FAIL\\";
  8002. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/FAIL/";
  8003. }
  8004. if (Directory.Exists(LocalSavePath) == false)
  8005. {
  8006. Directory.CreateDirectory(LocalSavePath);
  8007. }
  8008. //保存和上传
  8009. string LogSavePath = "";
  8010. string LogSaveFileName = "";
  8011. string ProductInfo = textBox_CheckModeScan.Text.Replace(" ", "_").Replace("/", "-"); ;
  8012. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  8013. if (Directory.Exists(LogSavePath) == false)
  8014. {
  8015. Directory.CreateDirectory(LogSavePath);
  8016. }
  8017. //测试页面
  8018. Double scaleX = PrimaryScreen.ScaleX;
  8019. Double scaleY = PrimaryScreen.ScaleY;
  8020. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  8021. Graphics g = Graphics.FromImage(bit);
  8022. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  8023. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  8024. bit.Save(LogSaveFileName);
  8025. //上传测试页面到服务器
  8026. if (myFtp.IsNetConnected == true)
  8027. {
  8028. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  8029. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  8030. {
  8031. myFtp.MakeDir(ServerSavePath + DateNow);
  8032. }
  8033. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  8034. {
  8035. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  8036. }
  8037. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  8038. if (result == true)
  8039. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  8040. }
  8041. //测试记录
  8042. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  8043. string file_str = "";
  8044. file_str += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  8045. file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  8046. file_str += "检验记录:\r\n" + richTextBox_CheckModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  8047. file_str += "检验结果:\r\n" + label_CheckModeResult.Text + "\r\n\r\n";
  8048. file_str += Local_HdInformation;
  8049. file_str += "\r\n电机存储参数:\r\n" + Params + "\r\n";
  8050. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  8051. //上传测试记录到服务器
  8052. if (myFtp.IsNetConnected == true)
  8053. {
  8054. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  8055. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  8056. {
  8057. myFtp.MakeDir(ServerSavePath + DateNow);
  8058. }
  8059. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  8060. {
  8061. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  8062. }
  8063. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  8064. if (result == true)
  8065. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  8066. }
  8067. //扫码框清空
  8068. textBox_CheckModeScan.Text = "";
  8069. }
  8070. /// <summary>
  8071. /// 参数检验开始
  8072. /// </summary>
  8073. /// <param name="sender"></param>
  8074. /// <param name="e"></param>
  8075. private void button_CheckModeStart_Click(object sender, EventArgs e)
  8076. {
  8077. //测试项目关闭编辑
  8078. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  8079. foreach (Control c in groupBox29.Controls)
  8080. {
  8081. if (c is CheckBox)
  8082. c.Enabled = false;
  8083. }
  8084. ReadLockStatus = true;
  8085. //检查配置文件
  8086. if (comboBox_CheckModeCfgFile.Text == "")
  8087. {
  8088. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  8089. return;
  8090. }
  8091. //开始测试
  8092. CheckTestStart();
  8093. }
  8094. /// <summary>
  8095. /// 参数检验测试子函数
  8096. /// </summary>
  8097. private void CheckTestStart()
  8098. {
  8099. //初始化标签
  8100. CheckModeLabelInit();
  8101. richTextBox_CheckModeLog.Clear();
  8102. //按钮禁止操作
  8103. button_CheckModeStart.Enabled = false;
  8104. //记录配置文件
  8105. richTextBox_CheckModeLog.AppendText("配置文件:" + comboBox_CheckModeCfgDate.Text + " / " + comboBox_CheckModeCfgFile.Text + "\r\n");
  8106. //检查打标信息
  8107. label_CheckModeStatus.Text = "检查扫码信息";
  8108. Delay_ms(500);
  8109. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  8110. if (textBox_CheckModeScan.Text == string.Empty)
  8111. {
  8112. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  8113. button__FacMode_Start.Enabled = false;
  8114. return;
  8115. }
  8116. try
  8117. {
  8118. if (中置电机ToolStripMenuItem.Checked == true)
  8119. {
  8120. if (textBox_CheckModeScan.Text.Split(' ').Length != 7)
  8121. {
  8122. label_CheckModeStatus.Text = "存在故障!";
  8123. label_CheckModeResult.BackColor = Color.Red;
  8124. label_CheckModeResult.Text = "标签格式错误";
  8125. button_CheckModeStart.Enabled = true;
  8126. return;
  8127. }
  8128. }
  8129. else if (轮毂电机ToolStripMenuItem.Checked == true)
  8130. {
  8131. if (textBox_CheckModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  8132. {
  8133. label_CheckModeStatus.Text = "存在故障!";
  8134. label_CheckModeResult.BackColor = Color.Red;
  8135. label_CheckModeResult.Text = "标签格式错误";
  8136. button_CheckModeStart.Enabled = true;
  8137. return;
  8138. }
  8139. }
  8140. }
  8141. catch (System.Exception)
  8142. {
  8143. label_CheckModeStatus.Text = "存在故障!";
  8144. label_CheckModeResult.BackColor = Color.Red;
  8145. label_CheckModeResult.Text = "标签格式错误";
  8146. button_CheckModeStart.Enabled = true;
  8147. return;
  8148. }
  8149. //打开串口
  8150. mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false);
  8151. if (!mySerialProcess.mySerial.IsOpen)
  8152. {
  8153. MessageBox.Show("请检查串口连接!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  8154. button__FacMode_Start.Enabled = false;
  8155. return;
  8156. }
  8157. //流水号计数
  8158. int serial = Convert.ToInt32(label_CheckModeSerial.Text);
  8159. serial += 1;
  8160. label_CheckModeSerial.Text = serial.ToString();
  8161. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, serial.ToString());
  8162. //创建线程,执行测试任务
  8163. Thread th = new Thread(CheckModeTest_Task);
  8164. th.Start();
  8165. }
  8166. /// <summary>
  8167. /// 执行一次测试任务
  8168. /// </summary>
  8169. private void CheckModeTest_Task()
  8170. {
  8171. //开始测试
  8172. richTextBox_CheckModeLog.AppendText("产品标签:" + textBox_CheckModeScan.Text + "\r\n");
  8173. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  8174. //变量定义
  8175. var Code = new byte[255];//发送的指令数据
  8176. ushort DataTemp;
  8177. short DataTemp_Int16;
  8178. string ResultPathName = "";
  8179. label_CheckModeStatus.Text = "开始测试";
  8180. BootInfo = "";
  8181. Delay_ms(500);
  8182. label_CheckModeStatus.Text = "系统开机";
  8183. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  8184. if (uARTToolStripMenuItem.Checked)
  8185. {
  8186. Code[0] = (byte)'R';
  8187. Code[1] = (byte)'E';
  8188. Code[2] = (byte)'S';
  8189. Code[3] = (byte)'E';
  8190. Code[4] = (byte)'T';
  8191. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  8192. Delay_ms(500);
  8193. }
  8194. //系统开机,确保测试前先关机,发送关机指令再发送开机指令
  8195. //确保测试前先关机,发送关机指令再发送开机指令
  8196. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  8197. Code[0] = 0xF0;
  8198. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  8199. Delay_ms(1500);
  8200. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  8201. Code[0] = 0xF1;
  8202. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  8203. ACK_WaitCnt = 0;
  8204. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  8205. while (ACK_WaitCnt <= 20) ; //10s
  8206. //检查BOOT版本
  8207. if (BootInfo != string.Empty)
  8208. {
  8209. label_CheckModeBoot.BackColor = Color.Green;
  8210. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  8211. Delay_ms(500);
  8212. }
  8213. else
  8214. {
  8215. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
  8216. label_CheckModeStatus.Text = "存在故障!";
  8217. label_CheckModeResult.BackColor = Color.Red;
  8218. label_CheckModeResult.Text = "测试异常";
  8219. Delay_ms(500);
  8220. //存储异常并上传
  8221. CheckMode_Stop(false);
  8222. return;
  8223. }
  8224. #if false
  8225. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  8226. {
  8227. Code[0] = 0x00;//5S协议
  8228. Code[1] = 0x00;
  8229. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  8230. Delay_ms(500);
  8231. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  8232. Delay_ms(500);
  8233. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  8234. }
  8235. #endif
  8236. //发送指令读取版本信息
  8237. do
  8238. {
  8239. label_CheckModeStatus.Text = "读取版本信息";
  8240. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  8241. //发送指令读取版本
  8242. Class_Motor_Ver.Mode = "---";
  8243. Class_Motor_Ver.SN = "---";
  8244. Class_Motor_Ver.HW = "---";
  8245. Class_Motor_Ver.FW = "---";
  8246. Class_Motor_Ver.Special = "---";
  8247. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  8248. ACK_WaitCnt = 0;
  8249. while (ACK_WaitCnt <= 2) ; //1s
  8250. if (Class_Motor_Ver.Mode == "---")
  8251. {
  8252. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第1次重发" + "\r\n");
  8253. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  8254. ACK_WaitCnt = 0;
  8255. while (ACK_WaitCnt <= 2) ; //1s
  8256. if (Class_Motor_Ver.Mode == "---")
  8257. {
  8258. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第2次重发" + "\r\n");
  8259. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  8260. ACK_WaitCnt = 0;
  8261. while (ACK_WaitCnt <= 2) ; //1s
  8262. if (Class_Motor_Ver.Mode == "---")
  8263. {
  8264. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取失败" + "\r\n");
  8265. label_CheckModeStatus.Text = "存在故障!";
  8266. label_CheckModeResult.BackColor = Color.Red;
  8267. label_CheckModeResult.Text = "测试异常";
  8268. Delay_ms(500);
  8269. //存储异常并上传
  8270. CheckMode_Stop(false);
  8271. return;
  8272. }
  8273. }
  8274. }
  8275. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  8276. richTextBox_CheckModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  8277. richTextBox_CheckModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  8278. richTextBox_CheckModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  8279. richTextBox_CheckModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  8280. richTextBox_CheckModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  8281. Delay_ms(500);
  8282. } while (false);
  8283. //软件版本检查
  8284. if (checkBox_CheckModeFWVer.Checked)
  8285. {
  8286. //判断版本是否正确
  8287. string VerCheck = comboBox_CheckModeCfgFile.Text.Split('_')[3] + "_" + comboBox_CheckModeCfgFile.Text.Split('_')[4];
  8288. string VerRead = "";
  8289. try
  8290. {
  8291. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  8292. }
  8293. catch (System.Exception)
  8294. {
  8295. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  8296. label_CheckModeStatus.Text = "存在故障!";
  8297. label_CheckModeResult.BackColor = Color.Red;
  8298. label_CheckModeResult.Text = "测试异常";
  8299. Delay_ms(500);
  8300. //存储异常并上传
  8301. CheckMode_Stop(false);
  8302. return;
  8303. }
  8304. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  8305. {
  8306. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
  8307. label_CheckModeStatus.Text = "存在故障!";
  8308. label_CheckModeResult.BackColor = Color.Red;
  8309. label_CheckModeResult.Text = "测试异常";
  8310. Delay_ms(500);
  8311. //存储异常并上传
  8312. CheckMode_Stop(false);
  8313. return;
  8314. }
  8315. label_CheckModeFWVer.BackColor = Color.Green;
  8316. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  8317. Delay_ms(500);
  8318. }
  8319. else
  8320. {
  8321. label_CheckModeFWVer.BackColor = Color.Yellow;
  8322. label_CheckModeStatus.Text = "跳过软件版本查询";
  8323. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过软件版本查询" + "\r\n");
  8324. Delay_ms(500);
  8325. }
  8326. //打标信息核对
  8327. if (checkBox_CheckModeSN.Checked)
  8328. {
  8329. label_CheckModeStatus.Text = "核对打标信息";
  8330. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "核对打标信息" + "\r\n");
  8331. //根据扫码信息获取型号和SN
  8332. string ScanInfo = textBox_CheckModeScan.Text;
  8333. string regexInfo = "";
  8334. string[] InfoList = { "" };
  8335. try
  8336. {
  8337. if (中置电机ToolStripMenuItem.Checked == true)
  8338. {
  8339. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  8340. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  8341. }
  8342. else if (轮毂电机ToolStripMenuItem.Checked == true)
  8343. {
  8344. if (!ScanInfo.Contains("/")) //老编码规则
  8345. {
  8346. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  8347. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  8348. string Spec = InfoList[1];
  8349. string Sn = InfoList[2];
  8350. InfoList[0] = Model.Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  8351. InfoList[1] = Sn;
  8352. }
  8353. else //新编码规则
  8354. {
  8355. Dictionary<string, string> Dic_Ver = new Dictionary<string, string>
  8356. {
  8357. { "01", "A" },
  8358. { "02", "B" },
  8359. { "03", "C" },
  8360. { "04", "D" },
  8361. { "05", "E" },
  8362. { "06", "F" },
  8363. { "07", "G" },
  8364. { "08", "H" },
  8365. { "09", "I" }
  8366. };
  8367. Dictionary<string, string> Dic_Vol = new Dictionary<string, string>
  8368. {
  8369. { "24V", "A" },
  8370. { "36V", "B" },
  8371. { "42V", "C" },
  8372. { "48V", "D" },
  8373. { "52V", "E" },
  8374. { "60V", "F" }
  8375. };
  8376. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  8377. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  8378. string Spec = InfoList[1].Replace("-", "").Replace("/", "");
  8379. string Sn = InfoList[2];
  8380. InfoList[0] = Model[2] + Dic_Ver[Model.Substring(3, 2)] + Model[5] + Dic_Ver[Model.Substring(6, 2)] + Model[9];
  8381. InfoList[0] += Dic_Vol[Spec.Substring(0, 3)] + Spec.Substring(3, 3) + Spec.Substring(13, 4) + Spec.Substring(Spec.Length - 4, 3);
  8382. InfoList[1] = Sn;
  8383. }
  8384. }
  8385. }
  8386. catch
  8387. {
  8388. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  8389. label_FacModeStatus.Text = "存在故障!";
  8390. label_FacModeResult.BackColor = Color.Red;
  8391. label_FacModeResult.Text = "标签格式错误";
  8392. Delay_ms(500);
  8393. //存储异常并上传
  8394. CheckMode_Stop(false);
  8395. return;
  8396. }
  8397. //核对型号
  8398. if (string.Equals(InfoList[0], Class_Motor_Ver.Mode) == false) //型号错误,直接结束
  8399. {
  8400. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号不一致" + "\r\n");
  8401. label_CheckModeStatus.Text = "存在故障!";
  8402. label_CheckModeResult.BackColor = Color.Red;
  8403. label_CheckModeResult.Text = "测试异常";
  8404. Delay_ms(500);
  8405. //存储异常并上传
  8406. CheckMode_Stop(false);
  8407. return;
  8408. }
  8409. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号一致" + "\r\n");
  8410. Delay_ms(500);
  8411. //核对SN
  8412. if (string.Equals(InfoList[1], Class_Motor_Ver.SN) == false) //型号错误,直接结束
  8413. {
  8414. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN不一致" + "\r\n");
  8415. label_CheckModeStatus.Text = "存在故障!";
  8416. label_CheckModeResult.BackColor = Color.Red;
  8417. label_CheckModeResult.Text = "测试异常";
  8418. Delay_ms(500);
  8419. //存储异常并上传
  8420. CheckMode_Stop(false);
  8421. return;
  8422. }
  8423. label_CheckModeSN.BackColor = Color.Green;
  8424. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN一致" + "\r\n");
  8425. Delay_ms(500);
  8426. }
  8427. else
  8428. {
  8429. label_CheckModeSN.BackColor = Color.Yellow;
  8430. label_CheckModeStatus.Text = "跳过打标信息确认";
  8431. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过打标信息确认" + "\r\n");
  8432. Delay_ms(500);
  8433. }
  8434. //参数检验
  8435. if (checkBox_CheckModeCfg.Checked)
  8436. {
  8437. //读取配置文件信息
  8438. label_CheckModeStatus.Text = "参数检查";
  8439. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  8440. //配置文件
  8441. List<byte[]> CmdList = new List<byte[]>();
  8442. Dictionary<string, string> ConfigCmd = new Dictionary<string, string>();//配置文件格式
  8443. //从服务器下载文件
  8444. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  8445. {
  8446. string SelectFile = "";
  8447. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "/" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  8448. if (File.Exists(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  8449. {
  8450. File.Delete(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  8451. }
  8452. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  8453. //打开文件
  8454. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  8455. ConfigCmd.Clear();
  8456. while (streamReader.Peek() != -1)
  8457. {
  8458. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  8459. if (fileLineInfo.Contains("["))
  8460. {
  8461. if (fileLineInfo.Contains("助力参数"))
  8462. {
  8463. fileLineInfo = streamReader.ReadLine();
  8464. }
  8465. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  8466. }
  8467. }
  8468. streamReader.Close();
  8469. }
  8470. //从本地加载文件
  8471. else
  8472. {
  8473. string SelectFile = "";
  8474. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  8475. //打开文件
  8476. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  8477. ConfigCmd.Clear();
  8478. while (streamReader.Peek() != -1)
  8479. {
  8480. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  8481. if (fileLineInfo.Contains("["))
  8482. {
  8483. if (fileLineInfo.Contains("助力参数"))
  8484. {
  8485. fileLineInfo = streamReader.ReadLine();
  8486. }
  8487. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  8488. }
  8489. }
  8490. streamReader.Close();
  8491. }
  8492. int CmdNum = ConfigCmd.Count(); //指令个数
  8493. Delay_ms(500);
  8494. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "\r\n");
  8495. Delay_ms(500);
  8496. //逐条读取比较
  8497. try
  8498. {
  8499. foreach (string key in ConfigCmd.Keys)
  8500. {
  8501. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令:" + "\r\n");
  8502. CmdRevStrTemp = "";
  8503. if (key.Contains("曲线"))
  8504. {
  8505. byte LineNum = 0;
  8506. var code = new byte[4];
  8507. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  8508. if (LineNum <= 5)
  8509. {
  8510. code[0] = (byte)(LineNum & 0xFF);
  8511. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8512. code[2] = (byte)(LineNum & 0xFF);
  8513. code[3] = (byte)((LineNum >> 8) & 0xFF);
  8514. }
  8515. else
  8516. {
  8517. code[0] = (byte)(LineNum & 0xFF);
  8518. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8519. code[2] = (byte)(5 & 0xFF);
  8520. code[3] = (byte)((5 >> 8) & 0xFF);
  8521. }
  8522. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  8523. }
  8524. else
  8525. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  8526. Delay_ms(500);
  8527. if (CmdRevStrTemp == string.Empty)
  8528. {
  8529. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令,第1次重发" + "\r\n");
  8530. if (key.Contains("曲线"))
  8531. {
  8532. byte LineNum = 0;
  8533. var code = new byte[4];
  8534. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  8535. if (LineNum <= 5)
  8536. {
  8537. code[0] = (byte)(LineNum & 0xFF);
  8538. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8539. code[2] = (byte)(LineNum & 0xFF);
  8540. code[3] = (byte)((LineNum >> 8) & 0xFF);
  8541. }
  8542. else
  8543. {
  8544. code[0] = (byte)(LineNum & 0xFF);
  8545. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8546. code[2] = (byte)(5 & 0xFF);
  8547. code[3] = (byte)((5 >> 8) & 0xFF);
  8548. }
  8549. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  8550. }
  8551. else
  8552. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  8553. Delay_ms(500);
  8554. if (CmdRevStrTemp == string.Empty)
  8555. {
  8556. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令,第2次重发" + "\r\n");
  8557. if (key.Contains("曲线"))
  8558. {
  8559. byte LineNum = 0;
  8560. var code = new byte[4];
  8561. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  8562. if (LineNum <= 5)
  8563. {
  8564. code[0] = (byte)(LineNum & 0xFF);
  8565. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8566. code[2] = (byte)(LineNum & 0xFF);
  8567. code[3] = (byte)((LineNum >> 8) & 0xFF);
  8568. }
  8569. else
  8570. {
  8571. code[0] = (byte)(LineNum & 0xFF);
  8572. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8573. code[2] = (byte)(5 & 0xFF);
  8574. code[3] = (byte)((5 >> 8) & 0xFF);
  8575. }
  8576. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  8577. }
  8578. else
  8579. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  8580. Delay_ms(500);
  8581. if (CmdRevStrTemp == string.Empty)
  8582. {
  8583. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "指令读取失败" + "\r\n");
  8584. label_CheckModeStatus.Text = "存在故障!";
  8585. label_CheckModeResult.BackColor = Color.Red;
  8586. label_CheckModeResult.Text = "测试异常";
  8587. Delay_ms(500);
  8588. //存储异常并上传
  8589. CheckMode_Stop(false);
  8590. return;
  8591. }
  8592. }
  8593. }
  8594. //比较当前指令,读取的配置文件和返回数据比较
  8595. string ParamWrite = ConfigCmd[key].Substring(24, ConfigCmd[key].Length - 40).Trim();
  8596. string ParamRead = "";
  8597. ushort CmdGet = Convert.ToUInt16(CmdRevStrTemp.Substring(0, 6).Trim().Replace(" ", ""), 16);//接收到指令的命令字
  8598. ushort CmdRev = myParams.ConfigCheckRevCmd[key];//接收指令设计值
  8599. if (CmdGet != CmdRev)
  8600. {
  8601. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "接收指令不正确" + "\r\n");
  8602. richTextBox_CheckModeLog.AppendText("接收指令:" + "0x" + CmdGet.ToString("X2") + "\r\n");
  8603. richTextBox_CheckModeLog.AppendText("正确指令应为:" + "0x" + CmdRev.ToString("X2") + "\r\n");
  8604. label_CheckModeStatus.Text = "存在故障!";
  8605. label_CheckModeResult.BackColor = Color.Red;
  8606. label_CheckModeResult.Text = "测试异常";
  8607. Delay_ms(500);
  8608. //存储异常并上传
  8609. CheckMode_Stop(false);
  8610. return;
  8611. }
  8612. if (string.Compare(key, "[其它传感器参数]") == 0)
  8613. ParamRead = CmdRevStrTemp.Substring(90, CmdRevStrTemp.Length - 90).Trim(); //去掉命令字、力矩传感器标定参数
  8614. else if (string.Compare(key, "[控制参数]") == 0)
  8615. ParamRead = CmdRevStrTemp.Substring(18, CmdRevStrTemp.Length - 18).Trim(); //去掉命令字、位置零点
  8616. else
  8617. ParamRead = CmdRevStrTemp.Substring(6, CmdRevStrTemp.Length - 6).Trim(); //去掉命令字
  8618. if (ParamWrite.Contains(ParamRead))
  8619. {
  8620. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "一致" + "\r\n");
  8621. continue;
  8622. }
  8623. else
  8624. {
  8625. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "不一致" + "\r\n");
  8626. richTextBox_CheckModeLog.AppendText("写入参数:" + ParamWrite + "\r\n");
  8627. richTextBox_CheckModeLog.AppendText("读出参数:" + ParamRead + "\r\n");
  8628. label_CheckModeStatus.Text = "存在故障!";
  8629. label_CheckModeResult.BackColor = Color.Red;
  8630. label_CheckModeResult.Text = "测试异常";
  8631. Delay_ms(500);
  8632. //存储异常并上传
  8633. CheckMode_Stop(false);
  8634. return;
  8635. }
  8636. }
  8637. }
  8638. catch (System.Exception)
  8639. {
  8640. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数检验失败" + "\r\n");
  8641. label_CheckModeStatus.Text = "存在故障!";
  8642. label_CheckModeResult.BackColor = Color.Red;
  8643. label_CheckModeResult.Text = "测试异常";
  8644. Delay_ms(500);
  8645. //存储异常并上传
  8646. CheckMode_Stop(false);
  8647. return;
  8648. }
  8649. label_CheckModeCfg.BackColor = Color.Green;
  8650. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数检验正确" + "\r\n");
  8651. Delay_ms(500);
  8652. }
  8653. else
  8654. {
  8655. label_CheckModeCfg.BackColor = Color.Yellow;
  8656. label_CheckModeStatus.Text = "跳过参数检验";
  8657. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数检验" + "\r\n");
  8658. Delay_ms(500);
  8659. }
  8660. //读取力矩传感器
  8661. do
  8662. {
  8663. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据" + "\r\n");
  8664. //发送指令读取力矩传感器标定数据
  8665. CmdRevStrTemp = "";
  8666. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  8667. ACK_WaitCnt = 0;
  8668. while (ACK_WaitCnt <= 2) ; //1s
  8669. if (CmdRevStrTemp == string.Empty)
  8670. {
  8671. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据,第1次重发" + "\r\n");
  8672. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  8673. ACK_WaitCnt = 0;
  8674. while (ACK_WaitCnt <= 2) ; //1s
  8675. if (CmdRevStrTemp == string.Empty)
  8676. {
  8677. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据,第2次重发" + "\r\n");
  8678. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  8679. ACK_WaitCnt = 0;
  8680. while (ACK_WaitCnt <= 2) ; //1s
  8681. if (CmdRevStrTemp == string.Empty)
  8682. {
  8683. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取失败" + "\r\n");
  8684. label_CheckModeStatus.Text = "存在故障!";
  8685. label_CheckModeResult.BackColor = Color.Red;
  8686. label_CheckModeResult.Text = "测试异常";
  8687. Delay_ms(500);
  8688. //存储异常并上传
  8689. CheckMode_Stop(false);
  8690. return;
  8691. }
  8692. }
  8693. }
  8694. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取成功" + "\r\n");
  8695. //取力矩传感器数据
  8696. ushort ZeroInit, Zero1, Zero2, Zero3, ZeroNew;
  8697. ushort MaxTorque;
  8698. ushort K1_T, K1, K2_T, K2, K3_T, K3, K4_T, K4;
  8699. byte[] DataArray = mySerialProcess.HexStringToBytes(CmdRevStrTemp, true);
  8700. ushort Cmd = (ushort)((DataArray[0] << 8) + DataArray[1]);
  8701. if (Cmd != 0xB528)
  8702. {
  8703. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器参数错误,CMD: 0x" + Convert.ToString(Cmd, 16).PadLeft(2, '0').ToUpper() + "\r\n");
  8704. label_CheckModeStatus.Text = "存在故障!";
  8705. label_CheckModeResult.BackColor = Color.Red;
  8706. label_CheckModeResult.Text = "测试异常";
  8707. Delay_ms(500);
  8708. //存储异常并上传
  8709. CheckMode_Stop(false);
  8710. return;
  8711. }
  8712. ZeroInit = (ushort)((DataArray[3] << 8) + DataArray[2]);
  8713. Zero1 = (ushort)((DataArray[5] << 8) + DataArray[4]);
  8714. Zero2 = (ushort)((DataArray[7] << 8) + DataArray[6]);
  8715. Zero3 = (ushort)((DataArray[9] << 8) + DataArray[8]);
  8716. ZeroNew = (ushort)((DataArray[11] << 8) + DataArray[10]);
  8717. MaxTorque = (ushort)((DataArray[13] << 8) + DataArray[12]);
  8718. K1_T = (ushort)((DataArray[15] << 8) + DataArray[14]);
  8719. K1 = (ushort)((DataArray[17] << 8) + DataArray[16]);
  8720. K2_T = (ushort)((DataArray[19] << 8) + DataArray[18]);
  8721. K2 = (ushort)((DataArray[21] << 8) + DataArray[20]);
  8722. K3_T = (ushort)((DataArray[23] << 8) + DataArray[22]);
  8723. K3 = (ushort)((DataArray[25] << 8) + DataArray[24]);
  8724. K4_T = (ushort)((DataArray[27] << 8) + DataArray[26]);
  8725. K4 = (ushort)((DataArray[29] << 8) + DataArray[28]);
  8726. richTextBox_CheckModeLog.AppendText("力矩传感器零点: " + ZeroInit.ToString() + "," + Zero1.ToString() + "," +
  8727. Zero2.ToString() + "," + Zero3.ToString() + "," + ZeroNew.ToString() + "\r\n");
  8728. richTextBox_CheckModeLog.AppendText("最大力矩: " + MaxTorque.ToString() + "\r\n");
  8729. richTextBox_CheckModeLog.AppendText("力矩传感器标定: " + "[" + K1_T.ToString() + "," + K1.ToString() + "]" + "," +
  8730. "[" + K2_T.ToString() + "," + K2.ToString() + "]" + "," + "[" + K3_T.ToString() + "," + K3.ToString() + "]" + "," +
  8731. "[" + K4_T.ToString() + "," + K4.ToString() + "]" + "\r\n");
  8732. //传感器标定检验
  8733. if (checkBox_CheckModeTorque.Checked)
  8734. {
  8735. richTextBox_CheckModeLog.AppendText("力矩零点范围: " + TorqueParamsForm.Zero.Min.ToString() + " - " + TorqueParamsForm.Zero.Max.ToString() + "\r\n");
  8736. richTextBox_CheckModeLog.AppendText("K1范围: " + TorqueParamsForm.K1.T.ToString() + "," + TorqueParamsForm.K1.Min.ToString() + " - " + TorqueParamsForm.K1.Max.ToString() + "\r\n");
  8737. richTextBox_CheckModeLog.AppendText("K2范围: " + TorqueParamsForm.K2.T.ToString() + "," + TorqueParamsForm.K2.Min.ToString() + " - " + TorqueParamsForm.K2.Max.ToString() + "\r\n");
  8738. richTextBox_CheckModeLog.AppendText("K3范围: " + TorqueParamsForm.K3.T.ToString() + "," + TorqueParamsForm.K3.Min.ToString() + " - " + TorqueParamsForm.K3.Max.ToString() + "\r\n");
  8739. richTextBox_CheckModeLog.AppendText("K4范围: " + TorqueParamsForm.K4.T.ToString() + "," + TorqueParamsForm.K4.Min.ToString() + " - " + TorqueParamsForm.K4.Max.ToString() + "\r\n");
  8740. //与设置值比较
  8741. if ((ZeroInit <= TorqueParamsForm.Zero.Max) && (ZeroInit >= TorqueParamsForm.Zero.Min)
  8742. && (K1_T == TorqueParamsForm.K1.T) && (K1 <= TorqueParamsForm.K1.Max) && (K1 >= TorqueParamsForm.K1.Min)
  8743. && (K2_T == TorqueParamsForm.K2.T) && (K2 <= TorqueParamsForm.K2.Max) && (K2 >= TorqueParamsForm.K2.Min)
  8744. && (K3_T == TorqueParamsForm.K3.T) && (K3 <= TorqueParamsForm.K3.Max) && (K3 >= TorqueParamsForm.K3.Min)
  8745. && (K4_T == TorqueParamsForm.K4.T) && (K4 <= TorqueParamsForm.K4.Max) && (K4 >= TorqueParamsForm.K4.Min)
  8746. )
  8747. {
  8748. label_CheckModeTorque.BackColor = Color.Green;
  8749. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定正常" + "\r\n");
  8750. Delay_ms(500);
  8751. }
  8752. else
  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. else
  8765. {
  8766. label_CheckModeTorque.BackColor = Color.Yellow;
  8767. label_CheckModeStatus.Text = "跳过传感器标定检验";
  8768. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过传感器标定检验" + "\r\n");
  8769. Delay_ms(500);
  8770. }
  8771. } while (false);
  8772. //读取MOS内阻校准参数
  8773. do
  8774. {
  8775. if (checkBox_CheckModeMos.Checked)
  8776. {
  8777. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据" + "\r\n");
  8778. //读取显示校准返回数据
  8779. foreach (Control c in groupBox21.Controls)
  8780. {
  8781. if (c is TextBox)
  8782. c.Text = "";
  8783. }
  8784. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8785. ACK_WaitCnt = 0;
  8786. while (ACK_WaitCnt <= 2) ; //1s
  8787. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  8788. {
  8789. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据,第1次重发" + "\r\n");
  8790. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8791. ACK_WaitCnt = 0;
  8792. while (ACK_WaitCnt <= 2) ; //1s
  8793. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  8794. {
  8795. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据,第2次重发" + "\r\n");
  8796. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8797. ACK_WaitCnt = 0;
  8798. while (ACK_WaitCnt <= 2) ; //1s
  8799. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  8800. {
  8801. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果异常" + "\r\n");
  8802. label_CheckModeStatus.Text = "存在故障!";
  8803. label_CheckModeResult.BackColor = Color.Red;
  8804. label_CheckModeResult.Text = "测试异常";
  8805. Delay_ms(500);
  8806. //存储异常并上传
  8807. CheckMode_Stop(false);
  8808. return;
  8809. }
  8810. }
  8811. }
  8812. else
  8813. {
  8814. 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");
  8815. }
  8816. //与校准返回数据对比
  8817. string[] MOS_R1_Th = toolStripTextBox_MOS1.Text.Split(',');
  8818. string[] MOS_R2_Th = toolStripTextBox_MOS2.Text.Split(',');
  8819. string[] MOS_R3_Th = toolStripTextBox_MOS3.Text.Split(',');
  8820. 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])) &&
  8821. (Convert.ToUInt16(textBox_MOS_R2.Text) >= Convert.ToUInt16(MOS_R2_Th[0])) && (Convert.ToUInt16(textBox_MOS_R2.Text) <= Convert.ToUInt16(MOS_R2_Th[1])) &&
  8822. (Convert.ToUInt16(textBox_MOS_R3.Text) >= Convert.ToUInt16(MOS_R3_Th[0])) && (Convert.ToUInt16(textBox_MOS_R3.Text) <= Convert.ToUInt16(MOS_R3_Th[1]))
  8823. )
  8824. {
  8825. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准合格" + "\r\n");
  8826. label_CheckModeMos.BackColor = Color.Green;
  8827. }
  8828. else
  8829. {
  8830. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准超范围" + "\r\n");
  8831. label_CheckModeStatus.Text = "存在故障!";
  8832. label_CheckModeResult.BackColor = Color.Red;
  8833. label_CheckModeResult.Text = "测试异常";
  8834. Delay_ms(500);
  8835. //存储异常并上传
  8836. CheckMode_Stop(false);
  8837. return;
  8838. }
  8839. }
  8840. else
  8841. {
  8842. label_CheckModeMos.BackColor = Color.Yellow;
  8843. label_CheckModeStatus.Text = "跳过MOS内阻校准检验";
  8844. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过MOS内阻校准检验" + "\r\n");
  8845. Delay_ms(500);
  8846. }
  8847. } while (false);
  8848. //读取位置校准参数
  8849. do
  8850. {
  8851. if (checkBox_CheckModeAngle.Checked)
  8852. {
  8853. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取位置校准数据" + "\r\n");
  8854. //发送指令读取位置
  8855. CmdRevStrTemp = "";
  8856. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
  8857. ACK_WaitCnt = 0;
  8858. while (ACK_WaitCnt <= 2) ; //1s
  8859. if (CmdRevStrTemp == string.Empty)
  8860. {
  8861. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取位置校准数据,第1次重发" + "\r\n");
  8862. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x3E00, null);
  8863. ACK_WaitCnt = 0;
  8864. while (ACK_WaitCnt <= 2) ; //1s
  8865. if (CmdRevStrTemp == string.Empty)
  8866. {
  8867. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取位置校准数据,第2次重发" + "\r\n");
  8868. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x3E00, null);
  8869. ACK_WaitCnt = 0;
  8870. while (ACK_WaitCnt <= 2) ; //1s
  8871. if (CmdRevStrTemp == string.Empty)
  8872. {
  8873. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准数据读取失败" + "\r\n");
  8874. label_CheckModeStatus.Text = "存在故障!";
  8875. label_CheckModeResult.BackColor = Color.Red;
  8876. label_CheckModeResult.Text = "测试异常";
  8877. Delay_ms(500);
  8878. //存储异常并上传
  8879. CheckMode_Stop(false);
  8880. return;
  8881. }
  8882. }
  8883. }
  8884. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准数据读取成功" + "\r\n");
  8885. //取零点数据
  8886. UInt16 AngleZero_Init = 0, AngleZero_Cur = 0;
  8887. byte[] DataArray = mySerialProcess.HexStringToBytes(CmdRevStrTemp, true);
  8888. ushort Cmd = (ushort)((DataArray[0] << 8) + DataArray[1]);
  8889. if (Cmd != 0xB420)
  8890. {
  8891. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置传感器参数错误,CMD: 0x" + Convert.ToString(Cmd, 16).PadLeft(2, '0').ToUpper() + "\r\n");
  8892. label_CheckModeStatus.Text = "存在故障!";
  8893. label_CheckModeResult.BackColor = Color.Red;
  8894. label_CheckModeResult.Text = "测试异常";
  8895. Delay_ms(500);
  8896. //存储异常并上传
  8897. CheckMode_Stop(false);
  8898. return;
  8899. }
  8900. AngleZero_Init = (ushort)((DataArray[3] << 8) + DataArray[2]);
  8901. AngleZero_Cur = (ushort)((DataArray[5] << 8) + DataArray[4]);
  8902. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置出厂零点: " + AngleZero_Init.ToString() + ",位置当前零点: " + AngleZero_Cur.ToString() + "\r\n");
  8903. int AngleZeroDiff = Math.Abs(AngleZero_Cur - AngleZero_Init);
  8904. int AngleZeroTH = Convert.ToInt32(textBox_AngleZeroTh.Text);
  8905. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置零点校准值: " + AngleZeroDiff.ToString() + ",判断阈值: " + AngleZeroTH.ToString() + "\r\n");
  8906. //判断
  8907. if (AngleZeroDiff <= AngleZeroTH)
  8908. {
  8909. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置传感器校准合格" + "\r\n");
  8910. label_CheckModeAngle.BackColor = Color.Green;
  8911. }
  8912. else
  8913. {
  8914. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置传感器校准超范围" + "\r\n");
  8915. label_CheckModeStatus.Text = "存在故障!";
  8916. label_CheckModeResult.BackColor = Color.Red;
  8917. label_CheckModeResult.Text = "测试异常";
  8918. Delay_ms(500);
  8919. //存储异常并上传
  8920. CheckMode_Stop(false);
  8921. return;
  8922. }
  8923. }
  8924. else
  8925. {
  8926. label_CheckModeAngle.BackColor = Color.Yellow;
  8927. label_CheckModeStatus.Text = "跳过位置传感器校准检验";
  8928. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过位置传感器校准检验" + "\r\n");
  8929. Delay_ms(500);
  8930. }
  8931. } while (false);
  8932. //测试合格
  8933. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  8934. label_CheckModeStatus.Text = "测试结束!";
  8935. label_CheckModeResult.BackColor = Color.Green;
  8936. label_CheckModeResult.Text = "测试合格";
  8937. Delay_ms(500);
  8938. //存储并上传
  8939. CheckMode_Stop(true);
  8940. return;
  8941. }
  8942. private void CheckModeLabelInit()
  8943. {
  8944. //测试状态标签
  8945. label_CheckModeResult.BackColor = Color.Yellow;
  8946. label_CheckModeResult.Text = "测试中";
  8947. //测试过程标签
  8948. label_CheckModeStatus.Text = "测试就绪";
  8949. //测试结果标签
  8950. foreach (Control c in groupBox31.Controls)
  8951. {
  8952. if (c is Label)
  8953. {
  8954. if (c.Text == string.Empty)
  8955. c.BackColor = Color.Red;
  8956. }
  8957. }
  8958. }
  8959. private void 调试记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  8960. {
  8961. System.Diagnostics.Process.Start("explorer.exe", Directory.GetCurrentDirectory());
  8962. }
  8963. private void 生产记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  8964. {
  8965. System.Diagnostics.Process.Start("explorer.exe", localInfo.LocalDataPath);
  8966. }
  8967. private void 累计运行时间ToolStripMenuItem_MouseHover(object sender, EventArgs e)
  8968. {
  8969. UInt32 Time = (UInt32)stopwatch.ElapsedMilliseconds / 1000;
  8970. UInt32 hour = Time / 3600;
  8971. UInt32 min = (Time % 3600) / 60;
  8972. UInt32 s = (Time % 60);
  8973. toolStripMenuItem_RunTime.Text = hour.ToString() + ":" + min.ToString("00") + ":" + s.ToString("00");
  8974. }
  8975. private void richTextBox_CheckModeLog_TextChanged(object sender, EventArgs e)
  8976. {
  8977. richTextBox_CheckModeLog.SelectionStart = richTextBox_CheckModeLog.Text.Length;
  8978. richTextBox_CheckModeLog.ScrollToCaret();
  8979. }
  8980. private void 力矩传感器检验ToolStripMenuItem_Click(object sender, EventArgs e)
  8981. {
  8982. TorqueParamsForm.ShowDialog();
  8983. }
  8984. private void textBox_CheckModeScan_KeyUp(object sender, KeyEventArgs e)
  8985. {
  8986. if (e.KeyCode == Keys.Enter)
  8987. CheckTestStart();
  8988. }
  8989. private void textBox_FacModeScan_KeyUp(object sender, KeyEventArgs e)
  8990. {
  8991. if (e.KeyCode == Keys.Enter)
  8992. TestStart();
  8993. }
  8994. private void button_SpeedDec10_Click(object sender, EventArgs e)
  8995. {
  8996. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  8997. if (Percent <= 10)
  8998. Percent = 0;
  8999. else
  9000. Percent -= 10;
  9001. //生产模式转速设置值更新
  9002. textBox_MotorSpeedPercent.Text = Percent.ToString();
  9003. //设置转速百分比
  9004. var Data = new byte[1];
  9005. Data[0] = (byte)Percent;
  9006. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  9007. }
  9008. private void button_SpeedAdd10_Click(object sender, EventArgs e)
  9009. {
  9010. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  9011. if (Percent >= 90)
  9012. Percent = 100;
  9013. else
  9014. Percent += 10;
  9015. //生产模式转速设置值更新
  9016. textBox_MotorSpeedPercent.Text = Percent.ToString();
  9017. //设置转速百分比
  9018. var Data = new byte[1];
  9019. Data[0] = (byte)Percent;
  9020. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  9021. }
  9022. private void button_SpeedDec1_Click(object sender, EventArgs e)
  9023. {
  9024. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  9025. if (Percent <= 1)
  9026. Percent = 0;
  9027. else
  9028. Percent -= 1;
  9029. //生产模式转速设置值更新
  9030. textBox_MotorSpeedPercent.Text = Percent.ToString();
  9031. //设置转速百分比
  9032. var Data = new byte[1];
  9033. Data[0] = (byte)Percent;
  9034. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  9035. }
  9036. private void button_SpeedAdd1_Click(object sender, EventArgs e)
  9037. {
  9038. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  9039. if (Percent >= 99)
  9040. Percent = 100;
  9041. else
  9042. Percent += 1;
  9043. //生产模式转速设置值更新
  9044. textBox_MotorSpeedPercent.Text = Percent.ToString();
  9045. //设置转速百分比
  9046. var Data = new byte[1];
  9047. Data[0] = (byte)Percent;
  9048. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  9049. }
  9050. bool WriteLockStatus = true;
  9051. private void pictureBox_WriteLock_Click(object sender, EventArgs e)
  9052. {
  9053. if (WriteLockStatus == true)
  9054. {
  9055. EnterForm1.ShowDialog();
  9056. try
  9057. {
  9058. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9059. {
  9060. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  9061. {
  9062. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  9063. foreach (Control c in groupBox2.Controls)
  9064. {
  9065. if (c is CheckBox)
  9066. c.Enabled = true;
  9067. }
  9068. WriteLockStatus = !WriteLockStatus;
  9069. }
  9070. else
  9071. {
  9072. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9073. }
  9074. }
  9075. else
  9076. {
  9077. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9078. }
  9079. }
  9080. catch (Exception)
  9081. {
  9082. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9083. }
  9084. }
  9085. else
  9086. {
  9087. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  9088. foreach (Control c in groupBox2.Controls)
  9089. {
  9090. if (c is CheckBox)
  9091. c.Enabled = false;
  9092. }
  9093. WriteLockStatus = !WriteLockStatus;
  9094. }
  9095. }
  9096. bool ReadLockStatus = true;
  9097. private void pictureBox_ReadLock_Click(object sender, EventArgs e)
  9098. {
  9099. if (ReadLockStatus == true)
  9100. {
  9101. EnterForm1.ShowDialog();
  9102. try
  9103. {
  9104. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9105. {
  9106. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  9107. {
  9108. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  9109. foreach (Control c in groupBox29.Controls)
  9110. {
  9111. if (c is CheckBox)
  9112. c.Enabled = true;
  9113. }
  9114. ReadLockStatus = !ReadLockStatus;
  9115. }
  9116. else
  9117. {
  9118. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9119. }
  9120. }
  9121. else
  9122. {
  9123. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9124. }
  9125. }
  9126. catch (Exception)
  9127. {
  9128. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9129. }
  9130. }
  9131. else
  9132. {
  9133. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  9134. foreach (Control c in groupBox29.Controls)
  9135. {
  9136. if (c is CheckBox)
  9137. c.Enabled = false;
  9138. }
  9139. ReadLockStatus = !ReadLockStatus;
  9140. }
  9141. }
  9142. private void 屏幕键盘ToolStripMenuItem_Click(object sender, EventArgs e)
  9143. {
  9144. System.Diagnostics.Process.Start("osk.exe");
  9145. }
  9146. private void checkBox_OffLineCheckMode_CheckedChanged(object sender, EventArgs e)
  9147. {
  9148. comboBox_CheckModeCfgDate.SelectedIndex = -1;
  9149. comboBox_CheckModeCfgFile.SelectedIndex = -1;
  9150. checkBox_OffLineFacMode.Checked = checkBox_OffLineCheckMode.Checked;
  9151. }
  9152. private void checkBox_OffLineFacMode_CheckedChanged(object sender, EventArgs e)
  9153. {
  9154. comboBox_FacModeCfgDate.SelectedIndex = -1;
  9155. comboBox_FacModeCfgFile.SelectedIndex = -1;
  9156. checkBox_OffLineCheckMode.Checked = checkBox_OffLineFacMode.Checked;
  9157. }
  9158. private void 版本ToolStripMenuItem_Click(object sender, EventArgs e)
  9159. {
  9160. VersionForm.ShowDialog();
  9161. }
  9162. private void button_MOS_Cal_Click(object sender, EventArgs e)
  9163. {
  9164. textBox_MOS_R1.Text = "";
  9165. textBox_MOS_R2.Text = "";
  9166. textBox_MOS_R3.Text = "";
  9167. try
  9168. {
  9169. var Code = new byte[18];
  9170. for (int i = 0; i < 18; i++)
  9171. Code[i] = 0;
  9172. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  9173. ushort uwDataTemp = 0;
  9174. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  9175. Code[2] = (byte)(uwDataTemp & 0xFF);
  9176. Code[3] = (byte)(uwDataTemp >> 8);
  9177. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  9178. Code[4] = (byte)(uwDataTemp & 0xFF);
  9179. Code[5] = (byte)(uwDataTemp >> 8);
  9180. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  9181. Code[6] = (byte)(uwDataTemp & 0xFF);
  9182. Code[7] = (byte)(uwDataTemp >> 8);
  9183. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  9184. Code[8] = (byte)(uwDataTemp & 0xFF);
  9185. Code[9] = (byte)(uwDataTemp >> 8);
  9186. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  9187. Code[10] = (byte)(uwDataTemp & 0xFF);
  9188. Code[11] = (byte)(uwDataTemp >> 8);
  9189. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  9190. }
  9191. catch (Exception)
  9192. {
  9193. MessageBox.Show("系数填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9194. }
  9195. }
  9196. private void button_MOS_Read_Click(object sender, EventArgs e)
  9197. {
  9198. foreach (Control c in groupBox21.Controls)
  9199. {
  9200. if (c is TextBox)
  9201. c.Text = "";
  9202. }
  9203. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  9204. }
  9205. private void button_MOS_Write_Click(object sender, EventArgs e)
  9206. {
  9207. try
  9208. {
  9209. var Code = new byte[34];
  9210. for (int i = 0; i < 34; i++)
  9211. Code[i] = 0;
  9212. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  9213. ushort uwDataTemp = 0;
  9214. uwDataTemp = Convert.ToUInt16(textBox_MOS_R1.Text);
  9215. Code[2] = (byte)(uwDataTemp & 0xFF);
  9216. Code[3] = (byte)(uwDataTemp >> 8);
  9217. uwDataTemp = Convert.ToUInt16(textBox_MOS_R2.Text);
  9218. Code[4] = (byte)(uwDataTemp & 0xFF);
  9219. Code[5] = (byte)(uwDataTemp >> 8);
  9220. uwDataTemp = Convert.ToUInt16(textBox_MOS_R3.Text);
  9221. Code[6] = (byte)(uwDataTemp & 0xFF);
  9222. Code[7] = (byte)(uwDataTemp >> 8);
  9223. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  9224. Code[8] = (byte)(uwDataTemp & 0xFF);
  9225. Code[9] = (byte)(uwDataTemp >> 8);
  9226. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  9227. Code[10] = (byte)(uwDataTemp & 0xFF);
  9228. Code[11] = (byte)(uwDataTemp >> 8);
  9229. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  9230. Code[12] = (byte)(uwDataTemp & 0xFF);
  9231. Code[13] = (byte)(uwDataTemp >> 8);
  9232. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  9233. Code[14] = (byte)(uwDataTemp & 0xFF);
  9234. Code[15] = (byte)(uwDataTemp >> 8);
  9235. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  9236. Code[16] = (byte)(uwDataTemp & 0xFF);
  9237. Code[17] = (byte)(uwDataTemp >> 8);
  9238. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4C22, Code);
  9239. }
  9240. catch (Exception)
  9241. {
  9242. MessageBox.Show("数据填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9243. }
  9244. }
  9245. /// <summary>
  9246. /// 测试模式点击文本框自动全选
  9247. /// </summary>
  9248. /// <param name="sender"></param>
  9249. /// <param name="e"></param>
  9250. private void textBox_FacModeScan_MouseClick(object sender, MouseEventArgs e)
  9251. {
  9252. textBox_FacModeScan.SelectAll();
  9253. }
  9254. /// <summary>
  9255. /// 检验模式点击文本框自动全选
  9256. /// </summary>
  9257. /// <param name="sender"></param>
  9258. /// <param name="e"></param>
  9259. private void textBox_CheckModeScan_MouseClick(object sender, MouseEventArgs e)
  9260. {
  9261. textBox_CheckModeScan.SelectAll();
  9262. }
  9263. /// <summary>
  9264. /// 鼠标放置显示连接服务器信息
  9265. /// </summary>
  9266. /// <param name="sender"></param>
  9267. /// <param name="e"></param>
  9268. private void label_ServerStatus_MouseHover(object sender, EventArgs e)
  9269. {
  9270. // 创建the ToolTip
  9271. ToolTip toolTip1 = new ToolTip();
  9272. // 设置显示样式
  9273. toolTip1.AutoPopDelay = 30000;//提示信息的可见时间
  9274. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  9275. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  9276. toolTip1.ShowAlways = true;//是否显示提示框
  9277. if (myFtp.IsNetConnected)
  9278. {
  9279. toolTip1.SetToolTip(this.label_ServerStatus, "IP: " + ServerIP);//设置故障内容显示
  9280. }
  9281. else
  9282. {
  9283. toolTip1.SetToolTip(this.label_ServerStatus, "网络断开");//设置故障内容显示
  9284. }
  9285. }
  9286. /// <summary>
  9287. /// UART协议类型修改
  9288. /// </summary>
  9289. /// <param name="sender"></param>
  9290. /// <param name="e"></param>
  9291. private void 协议类型ToolStripMenuItem_SelectedIndexChanged(object sender, EventArgs e)
  9292. {
  9293. var Code = new byte[2];
  9294. Code[0] = (byte)协议类型ToolStripMenuItem.SelectedIndex;
  9295. Code[1] = 0x00;
  9296. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  9297. }
  9298. /// <summary>
  9299. /// 显示本机信息
  9300. /// </summary>
  9301. /// <param name="sender"></param>
  9302. /// <param name="e"></param>
  9303. private void 本机信息ToolStripMenuItem_Click(object sender, EventArgs e)
  9304. {
  9305. MessageBox.Show(Local_HdInformation, "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
  9306. }
  9307. /// <summary>
  9308. /// 量产模式删除当前选中文件
  9309. /// </summary>
  9310. /// <param name="sender"></param>
  9311. /// <param name="e"></param>
  9312. private void label112_DoubleClick(object sender, EventArgs e)
  9313. {
  9314. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9315. {
  9316. EnterForm1.ShowDialog();
  9317. try
  9318. {
  9319. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9320. {
  9321. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  9322. {
  9323. try
  9324. {
  9325. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + comboBox_FacModeCfgFile.Text);
  9326. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_FacModeCfgFile.Text) + ".src");
  9327. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_FacModeCfgFile.Text) + ".png");
  9328. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9329. }
  9330. catch (Exception)
  9331. {
  9332. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9333. }
  9334. }
  9335. else
  9336. {
  9337. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9338. }
  9339. }
  9340. }
  9341. catch (Exception)
  9342. {
  9343. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9344. }
  9345. }
  9346. }
  9347. /// <summary>
  9348. /// 检验模式删除当前选中文件
  9349. /// </summary>
  9350. /// <param name="sender"></param>
  9351. /// <param name="e"></param>
  9352. private void label138_DoubleClick(object sender, EventArgs e)
  9353. {
  9354. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9355. {
  9356. EnterForm1.ShowDialog();
  9357. try
  9358. {
  9359. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9360. {
  9361. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  9362. {
  9363. try
  9364. {
  9365. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + comboBox_CheckModeCfgFile.Text);
  9366. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_CheckModeCfgFile.Text) + ".src");
  9367. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_CheckModeCfgFile.Text) + ".png");
  9368. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9369. }
  9370. catch (Exception)
  9371. {
  9372. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9373. }
  9374. }
  9375. else
  9376. {
  9377. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9378. }
  9379. }
  9380. }
  9381. catch (Exception)
  9382. {
  9383. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9384. }
  9385. }
  9386. }
  9387. /// <summary>
  9388. /// 读取整车信息2
  9389. /// </summary>
  9390. /// <param name="sender"></param>
  9391. /// <param name="e"></param>
  9392. private void button_ReadBikeParam2_Click(object sender, EventArgs e)
  9393. {
  9394. richTextBox_BikeParam2.Clear();
  9395. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null);
  9396. }
  9397. /// <summary>
  9398. /// 写入整车信息2
  9399. /// </summary>
  9400. /// <param name="sender"></param>
  9401. /// <param name="e"></param>
  9402. private void button_WriteBikeParam2_Click(object sender, EventArgs e)
  9403. {
  9404. var ConfigParam = new byte[34];
  9405. for (int i = 0; i < 34; i++)
  9406. ConfigParam[i] = 0;
  9407. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  9408. string[] strDataTemp = richTextBox_BikeParam2.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  9409. try
  9410. {
  9411. for (int i = 0; i < strDataTemp.Length; i++)
  9412. {
  9413. short wDataTemp = 0;
  9414. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  9415. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  9416. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  9417. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  9418. }
  9419. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4D22, ConfigParam);
  9420. }
  9421. catch (Exception)
  9422. {
  9423. timer_500ms.Enabled = false;
  9424. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9425. timer_500ms.Enabled = true;
  9426. }
  9427. }
  9428. /// <summary>
  9429. /// 读取用户骑行参数
  9430. /// </summary>
  9431. /// <param name="sender"></param>
  9432. /// <param name="e"></param>
  9433. private void button_ReadUsrRideParam_Click(object sender, EventArgs e)
  9434. {
  9435. richTextBox_UsrRidesParam.Clear();
  9436. if (checkBox_UserRideParam_OBC.Checked)
  9437. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x4300, null);
  9438. else
  9439. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  9440. }
  9441. /// <summary>
  9442. /// 写入用户骑行参数
  9443. /// </summary>
  9444. /// <param name="sender"></param>
  9445. /// <param name="e"></param>
  9446. private void button_WriteUsrRidetParam_Click(object sender, EventArgs e)
  9447. {
  9448. var ConfigParam = new byte[34];
  9449. for (int i = 0; i < 34; i++)
  9450. ConfigParam[i] = 0;
  9451. if (checkBox_UserRideParam_OBC.Checked)
  9452. {
  9453. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  9454. string[] strDataTemp = richTextBox_UsrRidesParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  9455. try
  9456. {
  9457. for (int i = 0; i < strDataTemp.Length; i++)
  9458. {
  9459. ConfigParam[i + 2] = Convert.ToByte(strDataTemp[i].Split('=')[1]);
  9460. }
  9461. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4B22, ConfigParam);
  9462. }
  9463. catch (Exception)
  9464. {
  9465. timer_500ms.Enabled = false;
  9466. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9467. timer_500ms.Enabled = true;
  9468. }
  9469. }
  9470. else
  9471. {
  9472. string[] strDataTemp = richTextBox_UsrRidesParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  9473. try
  9474. {
  9475. for (int i = 0; i < strDataTemp.Length; i++)
  9476. {
  9477. ConfigParam[i] = Convert.ToByte(strDataTemp[i].Split('=')[1]);
  9478. }
  9479. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x4420, ConfigParam);
  9480. }
  9481. catch (Exception)
  9482. {
  9483. timer_500ms.Enabled = false;
  9484. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9485. timer_500ms.Enabled = true;
  9486. }
  9487. }
  9488. }
  9489. /// <summary>
  9490. /// 读取产品标签
  9491. /// </summary>
  9492. /// <param name="sender"></param>
  9493. /// <param name="e"></param>
  9494. private void button_ReadTag_Click(object sender, EventArgs e)
  9495. {
  9496. textBox_TagInfo.Text = "---";
  9497. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4E00, null);
  9498. }
  9499. /// <summary>
  9500. /// 写入产品标签
  9501. /// </summary>
  9502. /// <param name="sender"></param>
  9503. /// <param name="e"></param>
  9504. private void button_WriteTag_Click(object sender, EventArgs e)
  9505. {
  9506. string User = textBox_TagInfo.Text;
  9507. var UserArray = new byte[32];
  9508. for (ushort i = 0; i < User.Length; i++)
  9509. {
  9510. UserArray[i] = (byte)User[i];
  9511. }
  9512. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D20, UserArray);
  9513. }
  9514. /// <summary>
  9515. /// 上位机读取骑行历史
  9516. /// </summary>
  9517. /// <param name="sender"></param>
  9518. /// <param name="e"></param>
  9519. private void button_ReadRideLog_Click(object sender, EventArgs e)
  9520. {
  9521. textBox_ODO_KM.Text = "---";
  9522. textBox_ODO_TIME.Text = "---";
  9523. textBox_TRIP_KM.Text = "---";
  9524. textBox_TRIP_TIME.Text = "---";
  9525. textBox_OBC_TRIP_KM.Text = "";
  9526. textBox_OBC_TRIP_TIME.Text = "";
  9527. textBox_OBC_ODO_KM.Text = "";
  9528. textBox_OBC_ODO_TIME.Text = "";
  9529. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2E00, null);
  9530. }
  9531. /// <summary>
  9532. /// 上位机写入骑行历史
  9533. /// </summary>
  9534. /// <param name="sender"></param>
  9535. /// <param name="e"></param>
  9536. private void button_WriteRideLog_Click(object sender, EventArgs e)
  9537. {
  9538. UInt32 Data;
  9539. var UserArray = new byte[16];
  9540. try
  9541. {
  9542. Data = Convert.ToUInt32(textBox_ODO_KM.Text);
  9543. UserArray[0] = (byte)(Data & 0xFF);
  9544. UserArray[1] = (byte)(Data >> 8);
  9545. UserArray[2] = (byte)(Data >> 16);
  9546. UserArray[3] = (byte)(Data >> 24);
  9547. Data = Convert.ToUInt32(textBox_ODO_TIME.Text);
  9548. UserArray[4] = (byte)(Data & 0xFF);
  9549. UserArray[5] = (byte)(Data >> 8);
  9550. UserArray[6] = (byte)(Data >> 16);
  9551. UserArray[7] = (byte)(Data >> 24);
  9552. Data = Convert.ToUInt32(textBox_TRIP_KM.Text);
  9553. UserArray[8] = (byte)(Data & 0xFF);
  9554. UserArray[9] = (byte)(Data >> 8);
  9555. UserArray[10] = (byte)(Data >> 16);
  9556. UserArray[11] = (byte)(Data >> 24);
  9557. Data = Convert.ToUInt32(textBox_TRIP_TIME.Text);
  9558. UserArray[12] = (byte)(Data & 0xFF);
  9559. UserArray[13] = (byte)(Data >> 8);
  9560. UserArray[14] = (byte)(Data >> 16);
  9561. UserArray[15] = (byte)(Data >> 24);
  9562. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B10, UserArray);
  9563. }
  9564. catch (Exception ex)
  9565. {
  9566. MessageBox.Show("数据格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9567. }
  9568. }
  9569. /// <summary>
  9570. /// 获取删除配置文件日期列表
  9571. /// </summary>
  9572. /// <param name="sender"></param>
  9573. /// <param name="e"></param>
  9574. private void toolStripTextBox_DelCfgFile_Click(object sender, EventArgs e)
  9575. {
  9576. string[] DateList = { "" };
  9577. //网络断开时直接退出
  9578. if (!myFtp.IsNetConnected)
  9579. return;
  9580. //从服务器更新日期列表
  9581. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
  9582. toolStripTextBox_DelCfgFile.Items.Clear();
  9583. //日期列表加载,显示最近30条
  9584. if (DateList.Length > 30)
  9585. {
  9586. toolStripTextBox_DelCfgFile.Items.Add("支持最近30条");
  9587. toolStripTextBox_DelCfgFile.Items.Add("-----");
  9588. }
  9589. for (int i = (DateList.Length > 30) ? (DateList.Length - 30) : 0; i < DateList.Length; i++)//显示最近30个日期
  9590. {
  9591. toolStripTextBox_DelCfgFile.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  9592. }
  9593. }
  9594. /// <summary>
  9595. /// 删除指定配置文件
  9596. /// </summary>
  9597. /// <param name="sender"></param>
  9598. /// <param name="e"></param>
  9599. private void toolStripTextBox_DelCfgFile_SelectedIndexChanged(object sender, EventArgs e)
  9600. {
  9601. //提示输入文件名
  9602. Scan scan_form = new Scan();
  9603. scan_form.ShowDialog();
  9604. do
  9605. {
  9606. if (scan_form.textBox_Scan.Text == string.Empty)
  9607. {
  9608. timer_500ms.Enabled = false;
  9609. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9610. timer_500ms.Enabled = true;
  9611. break;
  9612. }
  9613. string DelFile = scan_form.textBox_Scan.Text;
  9614. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9615. {
  9616. EnterForm1.ShowDialog();
  9617. try
  9618. {
  9619. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9620. {
  9621. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  9622. {
  9623. try
  9624. {
  9625. if (DelFile.Contains("."))
  9626. DelFile = Path.GetFileNameWithoutExtension(DelFile);
  9627. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".ttcfg");
  9628. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".src");
  9629. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".png");
  9630. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9631. }
  9632. catch (Exception)
  9633. {
  9634. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9635. }
  9636. }
  9637. else
  9638. {
  9639. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9640. }
  9641. }
  9642. }
  9643. catch (Exception)
  9644. {
  9645. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9646. }
  9647. }
  9648. } while (false);
  9649. }
  9650. /// <summary>
  9651. /// 获取删除样机测试记录日期列表
  9652. /// </summary>
  9653. /// <param name="sender"></param>
  9654. /// <param name="e"></param>
  9655. private void toolStripTextBox_DelLogFile_Click(object sender, EventArgs e)
  9656. {
  9657. string[] DateList = { "" };
  9658. //网络断开时直接退出
  9659. if (!myFtp.IsNetConnected)
  9660. return;
  9661. //从服务器更新日期列表
  9662. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName);
  9663. toolStripTextBox_DelLogFile.Items.Clear();
  9664. //日期列表加载,显示最近30天
  9665. if (DateList.Length > 30)
  9666. {
  9667. toolStripTextBox_DelLogFile.Items.Add("支持最近30条");
  9668. toolStripTextBox_DelLogFile.Items.Add("-----");
  9669. }
  9670. for (int i = (DateList.Length > 30) ? (DateList.Length - 30) : 0; i < DateList.Length; i++)//显示最近30个日期
  9671. {
  9672. toolStripTextBox_DelLogFile.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  9673. }
  9674. }
  9675. /// <summary>
  9676. /// 删除指定的样机测试记录
  9677. /// </summary>
  9678. /// <param name="sender"></param>
  9679. /// <param name="e"></param>
  9680. private void toolStripTextBox_DelLogFile_SelectedIndexChanged(object sender, EventArgs e)
  9681. {
  9682. //提示输入文件名
  9683. Scan scan_form = new Scan();
  9684. scan_form.ShowDialog();
  9685. do
  9686. {
  9687. if (scan_form.textBox_Scan.Text == string.Empty)
  9688. {
  9689. timer_500ms.Enabled = false;
  9690. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9691. timer_500ms.Enabled = true;
  9692. break;
  9693. }
  9694. string DelFile = scan_form.textBox_Scan.Text;
  9695. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9696. {
  9697. EnterForm1.ShowDialog();
  9698. try
  9699. {
  9700. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9701. {
  9702. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  9703. {
  9704. try
  9705. {
  9706. //删除指定目录下面所有文件和文件夹
  9707. myFtp.DelDirectoryWithAll(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName + "\\" + toolStripTextBox_DelLogFile.Text + "\\" + DelFile);
  9708. myFtp.RemoveDirectory(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName + "\\" + toolStripTextBox_DelLogFile.Text + "\\" + DelFile);
  9709. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9710. }
  9711. catch (Exception)
  9712. {
  9713. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9714. }
  9715. }
  9716. else
  9717. {
  9718. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9719. }
  9720. }
  9721. }
  9722. catch (Exception)
  9723. {
  9724. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9725. }
  9726. }
  9727. } while (false);
  9728. }
  9729. /// <summary>
  9730. /// CAN协议选择
  9731. /// </summary>
  9732. /// <param name="sender"></param>
  9733. /// <param name="e"></param>
  9734. private void cANToolStripMenuItem_Click(object sender, EventArgs e)
  9735. {
  9736. cANToolStripMenuItem.Checked= true;
  9737. uARTToolStripMenuItem.Checked = false;
  9738. UART协议ToolStripMenuItem.Visible = false;
  9739. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9740. }
  9741. /// <summary>
  9742. /// UART协议选择
  9743. /// </summary>
  9744. /// <param name="sender"></param>
  9745. /// <param name="e"></param>
  9746. private void uARTToolStripMenuItem_Click(object sender, EventArgs e)
  9747. {
  9748. cANToolStripMenuItem.Checked = false;
  9749. uARTToolStripMenuItem.Checked = true;
  9750. UART协议ToolStripMenuItem.Visible = true;
  9751. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9752. }
  9753. /// <summary>
  9754. /// 清除流水号
  9755. /// </summary>
  9756. /// <param name="sender"></param>
  9757. /// <param name="e"></param>
  9758. private void label131_DoubleClick(object sender, EventArgs e)
  9759. {
  9760. if (MessageBox.Show("确认清零流水号?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9761. {
  9762. label_FacModeSerial.Text = "0";
  9763. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, label_FacModeSerial.Text);
  9764. }
  9765. }
  9766. /// <summary>
  9767. /// 清除流水号
  9768. /// </summary>
  9769. /// <param name="sender"></param>
  9770. /// <param name="e"></param>
  9771. private void label135_DoubleClick(object sender, EventArgs e)
  9772. {
  9773. if (MessageBox.Show("确认清零流水号?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9774. {
  9775. label_CheckModeSerial.Text = "0";
  9776. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, label_CheckModeSerial.Text);
  9777. }
  9778. }
  9779. /// <summary>
  9780. /// 打开自动更新
  9781. /// </summary>
  9782. /// <param name="sender"></param>
  9783. /// <param name="e"></param>
  9784. private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
  9785. {
  9786. 打开ToolStripMenuItem.Checked = true;
  9787. 关闭ToolStripMenuItem.Checked = false;
  9788. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9789. }
  9790. /// <summary>
  9791. /// 关闭自动更新
  9792. /// </summary>
  9793. /// <param name="sender"></param>
  9794. /// <param name="e"></param>
  9795. private void 关闭ToolStripMenuItem_Click(object sender, EventArgs e)
  9796. {
  9797. 打开ToolStripMenuItem.Checked = false;
  9798. 关闭ToolStripMenuItem.Checked = true;
  9799. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9800. }
  9801. /// <summary>
  9802. /// 显示完整配置文件
  9803. /// </summary>
  9804. /// <param name="sender"></param>
  9805. /// <param name="e"></param>
  9806. private void comboBox_FacModeCfgFile_MouseHover_1(object sender, EventArgs e)
  9807. {
  9808. // 创建the ToolTip
  9809. ToolTip toolTip1 = new ToolTip();
  9810. // 设置显示样式
  9811. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  9812. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  9813. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  9814. toolTip1.ShowAlways = true;//是否显示提示框
  9815. // 设置伴随的对象.
  9816. toolTip1.SetToolTip(this.comboBox_FacModeCfgFile, comboBox_FacModeCfgFile.Text);//设置故障内容显示
  9817. }
  9818. /// <summary>
  9819. /// 显示完整配置文件
  9820. /// </summary>
  9821. /// <param name="sender"></param>
  9822. /// <param name="e"></param>
  9823. private void comboBox_CheckModeCfgFile_MouseHover_1(object sender, EventArgs e)
  9824. {
  9825. // 创建the ToolTip
  9826. ToolTip toolTip1 = new ToolTip();
  9827. // 设置显示样式
  9828. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  9829. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  9830. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  9831. toolTip1.ShowAlways = true;//是否显示提示框
  9832. // 设置伴随的对象.
  9833. toolTip1.SetToolTip(this.comboBox_CheckModeCfgFile, comboBox_CheckModeCfgFile.Text);//设置故障内容显示
  9834. }
  9835. /// <summary>
  9836. /// 手动发送指令
  9837. /// </summary>
  9838. /// <param name="sender"></param>
  9839. /// <param name="e"></param>
  9840. private void 发送指令ToolStripMenuItem_Click(object sender, EventArgs e)
  9841. {
  9842. //提示
  9843. Scan scan_form = new Scan();
  9844. scan_form.label1.Text = "按照16进制填写,相邻字节用空格隔开,依次填写ID、Mode、Cmd、Data\r\n例如:07 31 16 22 05 01 02 03 04 05";
  9845. scan_form.ShowDialog();
  9846. //发送写入的指令,填写ID、类型、命令字、数据
  9847. do
  9848. {
  9849. if (scan_form.textBox_Scan.Text == string.Empty)
  9850. {
  9851. timer_500ms.Enabled = false;
  9852. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9853. timer_500ms.Enabled = true;
  9854. break;
  9855. }
  9856. //输入文本转换为字节流
  9857. var InputData = new byte[256];
  9858. InputData = mySerialProcess.HexStringToBytes(scan_form.textBox_Scan.Text, true);
  9859. //ID
  9860. ushort ID;
  9861. ID = (ushort)((InputData[0] << 8) + InputData[1]);
  9862. //Mode
  9863. byte Mode;
  9864. Mode = InputData[2];
  9865. //Cmd
  9866. ushort Cmd;
  9867. Cmd = (ushort)((InputData[3] << 8) + InputData[4]);
  9868. //Data
  9869. var Data = new byte[Cmd & 0x00FF];
  9870. for (int i = 0; i < (Cmd & 0x00FF); i++)
  9871. Data[i] = InputData[5 + i];
  9872. //发送数据
  9873. mySerialProcess.SendCmdWithoutNotice(ID, Mode, Cmd, Data);
  9874. } while (false);
  9875. }
  9876. /// <summary>
  9877. /// 启动位置传感器校准
  9878. /// </summary>
  9879. /// <param name="sender"></param>
  9880. /// <param name="e"></param>
  9881. private void button_AngleCalStart_Click(object sender, EventArgs e)
  9882. {
  9883. for (int i = 0; i < 7; i++)
  9884. for (int j = 0; j < 6; j++)
  9885. {
  9886. dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = "";
  9887. }
  9888. foreach (Control cr in tabPage_AngleCal.Controls)
  9889. {
  9890. if (cr is TextBox)
  9891. {
  9892. if ((cr != textBox_AngleDiffTh) && (cr != textBox_AngleZeroTh))
  9893. cr.Text = "";
  9894. }
  9895. }
  9896. var Data = new byte[2];
  9897. mySerialProcess.SendCmd((ushort)0x751, (byte)0x0C, (ushort)0x5002, Data);
  9898. }
  9899. /// <summary>
  9900. /// 导出位置传感器校准数据
  9901. /// </summary>
  9902. /// <param name="sender"></param>
  9903. /// <param name="e"></param>
  9904. private void button_AngleExportData_Click(object sender, EventArgs e)
  9905. {
  9906. //读出产品信息
  9907. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  9908. Delay_ms(200);
  9909. SaveFileDialog sfd = new SaveFileDialog
  9910. {
  9911. FileName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + "位置传感器角度数据_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt",
  9912. Filter = "文本文档(*.txt)|*.txt",
  9913. Title = "Save"
  9914. };
  9915. if (sfd.ShowDialog() != DialogResult.OK)
  9916. {
  9917. return;
  9918. }
  9919. string filepath = sfd.FileName;
  9920. FileStream fs = new FileStream(filepath, FileMode.OpenOrCreate);
  9921. using (StreamWriter sw = new StreamWriter(fs))
  9922. {
  9923. sw.Write("标准值 ");
  9924. sw.Write("60.00 ");
  9925. sw.Write("120.00 ");
  9926. sw.Write("180.00 ");
  9927. sw.Write("240.00 ");
  9928. sw.Write("300.00 ");
  9929. sw.Write("360.00 ");
  9930. for (int i = 0; i < 42; i++)
  9931. {
  9932. if ((i % 6 == 0))
  9933. {
  9934. sw.Write("\r\n" + "采集值" + (i / 6 + 1).ToString() + " ");
  9935. }
  9936. sw.Write(AngledataRecord[i] + " ");
  9937. }
  9938. sw.Write("\r\n" + "历史零点位置 " + textBox_AngleZeroInit.Text);
  9939. sw.Write("\r\n" + "当前零点位置 " + textBox_AngleZeroCur.Text);
  9940. sw.Write("\r\n" + "零点误差 " + textBox_AngleZeroDiff.Text);
  9941. sw.Write("\r\n" + "最小偏差值 " + textBox_AngleDiffMin.Text);
  9942. sw.Write("\r\n" + "最大偏差值 " + textBox_AngleDiffMax.Text);
  9943. sw.Write("\r\n" + "平均偏差值 " + textBox_AngleDiffAvg.Text);
  9944. sw.Flush();
  9945. }
  9946. fs.Close();
  9947. }
  9948. /// <summary>
  9949. /// 写入校准数据
  9950. /// </summary>
  9951. /// <param name="sender"></param>
  9952. /// <param name="e"></param>
  9953. private void button_AngleWrite_Click(object sender, EventArgs e)
  9954. {
  9955. if ((textBox_AngleDiffAvg.Text == "") || (textBox_AngleZeroInit.Text == ""))
  9956. {
  9957. timer_500ms.Enabled = false;
  9958. MessageBox.Show("请先启动校准,以确认校准数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9959. timer_500ms.Enabled = true;
  9960. return;
  9961. }
  9962. timer_500ms.Enabled = false;
  9963. string str1 = "确认校准数据,历史零点: " + textBox_AngleZeroInit.Text + ", 偏差平均值: " + textBox_AngleDiffAvg.Text;
  9964. if (MessageBox.Show(str1, "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9965. {
  9966. var SaveFlag = new byte[4];
  9967. for (int i = 0; i < 4; i++)
  9968. SaveFlag[i] = 0;
  9969. SaveFlag[0] = (byte)(1);
  9970. double data1 = Convert.ToDouble(textBox_AngleZeroInit.Text) - Convert.ToDouble(textBox_AngleDiffAvg.Text);
  9971. if (data1 > 360)
  9972. {
  9973. data1 -= 360;
  9974. }
  9975. else if (data1 < -360)
  9976. {
  9977. data1 += 360;
  9978. }
  9979. Int16 data2 = (Int16)(data1 * 32768 / 360);
  9980. SaveFlag[2] = (byte)(data2);
  9981. SaveFlag[3] = (byte)(data2 >> 8);
  9982. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, SaveFlag);
  9983. timer_500ms.Enabled = true;
  9984. }
  9985. else
  9986. {
  9987. timer_500ms.Enabled = true;
  9988. MessageBoxTimeOut.Show("写入取消", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9989. }
  9990. }
  9991. /// <summary>
  9992. /// 存储允许偏差
  9993. /// </summary>
  9994. /// <param name="sender"></param>
  9995. /// <param name="e"></param>
  9996. private void textBox_AngleDiffTh_KeyDown(object sender, KeyEventArgs e)
  9997. {
  9998. if (e.KeyCode == Keys.Enter)
  9999. {
  10000. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  10001. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  10002. }
  10003. }
  10004. /// <summary>
  10005. /// 存储零点允许偏差
  10006. /// </summary>
  10007. /// <param name="sender"></param>
  10008. /// <param name="e"></param>
  10009. private void textBox_AngleZeroTh_KeyDown(object sender, KeyEventArgs e)
  10010. {
  10011. if (e.KeyCode == Keys.Enter)
  10012. {
  10013. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  10014. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  10015. }
  10016. }
  10017. /// <summary>
  10018. /// 删除服务器配置文件
  10019. /// </summary>
  10020. /// <param name="sender"></param>
  10021. /// <param name="e"></param>
  10022. private void 重置ToolStripMenuItem_Click(object sender, EventArgs e)
  10023. {
  10024. if (MessageBox.Show("重置后软件自动关闭,确认重置?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  10025. {
  10026. if(File.Exists(localInfo.LocalPath + localInfo.ServerCfgFileName))
  10027. File.Delete(localInfo.LocalPath + localInfo.ServerCfgFileName);
  10028. if(File.Exists(localInfo.LocalPath + localInfo.ConfigFileName))
  10029. File.Delete(localInfo.LocalPath + localInfo.ConfigFileName);
  10030. System.Environment.Exit(0);
  10031. }
  10032. }
  10033. /// <summary>
  10034. /// 按下Enter保存数据
  10035. /// </summary>
  10036. /// <param name="sender"></param>
  10037. /// <param name="e"></param>
  10038. private void toolStripTextBox_AngleAvgMax_KeyDown(object sender, KeyEventArgs e)
  10039. {
  10040. textBox_AngleDiffTh.Text = toolStripTextBox_AngleAvgMax.Text;
  10041. if (e.KeyCode == Keys.Enter)
  10042. {
  10043. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  10044. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  10045. }
  10046. }
  10047. /// <summary>
  10048. /// 按下Enter保存数据
  10049. /// </summary>
  10050. /// <param name="sender"></param>
  10051. /// <param name="e"></param>
  10052. private void toolStripTextBox_AngleZeroMax_KeyDown(object sender, KeyEventArgs e)
  10053. {
  10054. textBox_AngleZeroTh.Text = toolStripTextBox_AngleZeroMax.Text;
  10055. if (e.KeyCode == Keys.Enter)
  10056. {
  10057. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  10058. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  10059. }
  10060. }
  10061. private void 帮助ToolStripMenuItem_Click(object sender, EventArgs e)
  10062. {
  10063. //检查本地文件
  10064. if (!File.Exists(localInfo.LocalPath + localInfo.HelpFilename))
  10065. {
  10066. if (!OfflineFlag)
  10067. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/help/" + localInfo.HelpFilename, localInfo.LocalPath);
  10068. else
  10069. {
  10070. MessageBoxTimeOut.Show("未找到帮助文件!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10071. return;
  10072. }
  10073. }
  10074. //调用本地浏览器打开帮助文件
  10075. System.Diagnostics.Process.Start("explorer", localInfo.LocalPath + localInfo.HelpFilename);
  10076. }
  10077. /// <summary>
  10078. /// 读取故障日志地址
  10079. /// </summary>
  10080. /// <param name="sender"></param>
  10081. /// <param name="e"></param>
  10082. private void button_ReadLogAddr_Click(object sender, EventArgs e)
  10083. {
  10084. textBox_LogAddrBegin.Text = "";
  10085. textBox_LogAddrEnd.Text = "";
  10086. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x5200, null);
  10087. }
  10088. /// <summary>
  10089. /// 写入硬件版本
  10090. /// </summary>
  10091. /// <param name="sender"></param>
  10092. /// <param name="e"></param>
  10093. private void button_WriteHW_Click(object sender, EventArgs e)
  10094. {
  10095. string HW = textBox_HW.Text;
  10096. var HWArray = new byte[16];
  10097. for (ushort i = 0; i < HW.Length; i++)
  10098. {
  10099. HWArray[i] = (byte)HW[i];
  10100. }
  10101. if (HW.Length < 16)
  10102. {
  10103. HWArray[HW.Length] = (byte)'.';
  10104. for (ushort i = 0; i < 16 - HW.Length - 1; i++)
  10105. {
  10106. HWArray[HW.Length + 1 + i] = 0x20;
  10107. }
  10108. }
  10109. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5310, HWArray);
  10110. }
  10111. /// <summary>
  10112. /// 生产模式写入HW
  10113. /// </summary>
  10114. /// <param name="sender"></param>
  10115. /// <param name="e"></param>
  10116. private void Button_FacModeSetHW_Click(object sender, EventArgs e)
  10117. {
  10118. string HW = textBox_FacModeHW.Text;
  10119. var HWArray = new byte[16];
  10120. for (ushort i = 0; i < HW.Length; i++)
  10121. {
  10122. HWArray[i] = (byte)HW[i];
  10123. }
  10124. if (HW.Length < 16)
  10125. {
  10126. HWArray[HW.Length] = (byte)'.';
  10127. for (ushort i = 0; i < 16 - HW.Length - 1; i++)
  10128. {
  10129. HWArray[HW.Length + 1 + i] = 0x20;
  10130. }
  10131. }
  10132. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5310, HWArray);
  10133. }
  10134. /// <summary>
  10135. /// 读取定制编号
  10136. /// </summary>
  10137. /// <param name="sender"></param>
  10138. /// <param name="e"></param>
  10139. private void button_ReadUserNum_Click(object sender, EventArgs e)
  10140. {
  10141. textBox_UserNum.Text = "---";
  10142. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x5600, null);
  10143. }
  10144. /// <summary>
  10145. /// 写入定制编号
  10146. /// </summary>
  10147. /// <param name="sender"></param>
  10148. /// <param name="e"></param>
  10149. private void button_WriteUserNum_Click(object sender, EventArgs e)
  10150. {
  10151. string User = textBox_UserNum.Text;
  10152. var UserArray = new byte[32];
  10153. for (ushort i = 0; i < User.Length; i++)
  10154. {
  10155. UserArray[i] = (byte)User[i];
  10156. }
  10157. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5720, UserArray);
  10158. }
  10159. /// <summary>
  10160. /// 读取指定块拓展功能
  10161. /// </summary>
  10162. /// <param name="sender"></param>
  10163. /// <param name="e"></param>
  10164. private void button_FunSet_Read_Click(object sender, EventArgs e)
  10165. {
  10166. if (comboBox_FunSet_BlockNum.SelectedIndex < 0)
  10167. {
  10168. MessageBox.Show("请选择块编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10169. }
  10170. else
  10171. {
  10172. //清空当前内容
  10173. for (int i = 0; i < 8; i++)
  10174. for (int j = 0; j < 8; j++)
  10175. {
  10176. dataGridView_FunSet.Rows[i].Cells[j + 1].Value = "";
  10177. }
  10178. //发送读取指令
  10179. ushort Num = (ushort)(comboBox_FunSet_BlockNum.SelectedIndex + 1);
  10180. var Code = new byte[2];
  10181. Code[0] = (byte)(Num & 0xFF);
  10182. Code[1] = (byte)(Num >> 8);
  10183. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x5402, Code);
  10184. }
  10185. }
  10186. /// <summary>
  10187. /// 写入指定块或指定单元参数
  10188. /// </summary>
  10189. /// <param name="sender"></param>
  10190. /// <param name="e"></param>
  10191. private void button_FunSet_Write_Click(object sender, EventArgs e)
  10192. {
  10193. if (radioButton_WriteByBlock.Checked == true)
  10194. {
  10195. if (comboBox_FunSet_BlockNum.SelectedIndex < 0)
  10196. MessageBox.Show("请选择块编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10197. else
  10198. {
  10199. //开始按块写入
  10200. ushort Num = (ushort)(comboBox_FunSet_BlockNum.SelectedIndex + 1);
  10201. var Code = new byte[66];
  10202. Code[0] = (byte)(Num & 0xFF);
  10203. Code[1] = (byte)(Num >> 8);
  10204. for (int i = 0; i < 8; i++)
  10205. for (int j = 0; j < 8; j++)
  10206. {
  10207. try
  10208. {
  10209. byte Data = Convert.ToByte(dataGridView_FunSet.Rows[i].Cells[j + 1].Value);
  10210. Code[i * 8 + j + 2] = (byte)(Data & 0xFF);
  10211. }
  10212. catch (Exception)
  10213. {
  10214. MessageBox.Show("数据格式错误或超范围!\r\n" + "单元编号:" + (i + 1).ToString() + "\r\n" + "参数:" + (j + 1).ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10215. return;
  10216. }
  10217. }
  10218. if (MessageBox.Show("请核对块编号!\r\n" + "块编号:" + (Num).ToString(), "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  10219. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5542, Code);
  10220. else
  10221. MessageBoxTimeOut.Show("取消写入", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  10222. }
  10223. }
  10224. else if (radioButton_WriteByUnit.Checked == true)
  10225. {
  10226. if (comboBox_FunSet_BlockNum.SelectedIndex < 0)
  10227. MessageBox.Show("请选择块编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10228. else
  10229. {
  10230. if (comboBox_FunSet_UnitNum.SelectedIndex < 0)
  10231. MessageBox.Show("请选择单元编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10232. else
  10233. {
  10234. //开始按单元写入
  10235. ushort Num1 = (ushort)(comboBox_FunSet_BlockNum.SelectedIndex + 1);
  10236. ushort Num2 = (ushort)(comboBox_FunSet_UnitNum.SelectedIndex + 1);
  10237. var Code = new byte[12];
  10238. Code[0] = (byte)(Num1 & 0xFF);
  10239. Code[1] = (byte)(Num1 >> 8);
  10240. Code[2] = (byte)(Num2 & 0xFF);
  10241. Code[3] = (byte)(Num2 >> 8);
  10242. for (int i = 0; i < 8; i++)
  10243. {
  10244. try
  10245. {
  10246. byte Data = Convert.ToByte(dataGridView_FunSet.Rows[Num2 - 1].Cells[i + 1].Value);
  10247. Code[i + 4] = (byte)(Data & 0xFF);
  10248. }
  10249. catch (Exception)
  10250. {
  10251. MessageBox.Show("数据格式错误或超范围!\r\n" + "单元编号:" + Num2.ToString() + "\r\n" + "参数:" + (i + 1).ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10252. return;
  10253. }
  10254. }
  10255. if (MessageBox.Show("请核对块编号和单元编号!\r\n" + "块编号:" + Num1.ToString() + "\r\n" + "单元编号:" + Num2.ToString(), "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  10256. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x550C, Code);
  10257. else
  10258. MessageBoxTimeOut.Show("取消写入", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  10259. }
  10260. }
  10261. }
  10262. else
  10263. {
  10264. MessageBox.Show("请选择写入方式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10265. }
  10266. }
  10267. /// <summary>
  10268. /// 按块写入时隐藏单元编号
  10269. /// </summary>
  10270. /// <param name="sender"></param>
  10271. /// <param name="e"></param>
  10272. private void radioButton_WriteByUnit_CheckedChanged(object sender, EventArgs e)
  10273. {
  10274. if (radioButton_WriteByUnit.Checked == true)
  10275. {
  10276. label159.Visible = true;
  10277. comboBox_FunSet_UnitNum.Visible = true;
  10278. }
  10279. else
  10280. {
  10281. label159.Visible = false;
  10282. comboBox_FunSet_UnitNum.Visible = false;
  10283. }
  10284. }
  10285. /// <summary>
  10286. /// 打开或关闭指令窗口
  10287. /// </summary>
  10288. /// <param name="sender"></param>
  10289. /// <param name="e"></param>
  10290. private void 指令调试ToolStripMenuItem_Click(object sender, EventArgs e)
  10291. {
  10292. if (指令调试ToolStripMenuItem.Checked == false)
  10293. {
  10294. if (DebugForm.debug1 == null || DebugForm.debug1.IsDisposed)
  10295. {
  10296. DebugForm.debug1 = new DebugForm();
  10297. DebugForm.debug1.Show();
  10298. this.DebugWindowIsOpen = true;
  10299. }
  10300. else
  10301. {
  10302. DebugForm.debug1.Activate();
  10303. this.DebugWindowIsOpen = true;
  10304. }
  10305. 指令调试ToolStripMenuItem.Checked = true;
  10306. }
  10307. else
  10308. {
  10309. if (this.DebugWindowIsOpen == true)
  10310. {
  10311. DebugForm.debug1.Close();
  10312. this.DebugWindowIsOpen = false;
  10313. this.DebugDataDisplayEnable = false;
  10314. }
  10315. 指令调试ToolStripMenuItem.Checked = false;
  10316. }
  10317. }
  10318. }
  10319. }