mainForm.cs 489 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354
  1. using NPOI.POIFS.Crypt.Dsig;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Diagnostics;
  6. using System.Diagnostics.Eventing.Reader;
  7. using System.Drawing;
  8. using System.IO;
  9. using System.IO.Ports;
  10. using System.Linq;
  11. using System.Reflection;
  12. using System.Runtime.InteropServices;
  13. using System.Runtime.InteropServices.ComTypes;
  14. using System.Text;
  15. using System.Text.RegularExpressions;
  16. using System.Threading;
  17. using System.Web;
  18. using System.Windows.Forms;
  19. using System.Xml.Linq;
  20. namespace Welling_Motor_Debug_Tool
  21. {
  22. public partial class mainForm : Form
  23. {
  24. #region 变量定义
  25. //版本号
  26. public static string Version = "2.4.0";
  27. //串口实例
  28. Serial_Process mySerialProcess = new Serial_Process();
  29. string PortNumSave = "";
  30. string PortBaudrateSave = "";
  31. //本地信息定义
  32. LocalInfo localInfo = new LocalInfo();
  33. //FTP实例
  34. ftp myFtp = new ftp();
  35. public string ServerIP = "";
  36. public string ServerPort = "";
  37. public string ServerUser = "";
  38. public string ServerPassWd = "";
  39. public bool OfflineFlag = false;
  40. //MC运行信息超时计数
  41. bool MC_RunInfo_Refresh = false;
  42. ushort MC_RunInfo_Refresh_Cnt = 0;
  43. //MC调试信息超时计数
  44. bool MC_DebugInfo_Refresh = false;
  45. ushort MC_DebugInfo_Refresh_Cnt = 0;
  46. //MC故障码超时计数
  47. bool MC_ErrorCode_Refresh = false;
  48. ushort MC_ErrorCode_Refresh_Cnt = 0;
  49. //配置参数实例
  50. Params myParams = new Params();
  51. //记录文件名称
  52. string RunInfoSaveFilename = "";
  53. //BMS运行信息超时计数
  54. bool BMS_RunInfo_Refresh = false;
  55. ushort BMS_RunInfo_Refresh_Cnt = 0;
  56. //生产模式关机指令反馈状态
  57. bool PowerOffAckStatus = false;
  58. //登录窗口
  59. public static Login EnterForm1 = new Login();
  60. //生产配置文件信息
  61. ArrayList array_CfgInfo = new ArrayList();
  62. //写入参数返回标志和计数
  63. public bool WriteACK = false;
  64. public ushort WriteCnt = 0;
  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. //显示运行信息
  548. tabPage_RunInfo.Parent = tabControl2;
  549. //根据电机类型修改生产信息和电机类型
  550. if (EnterForm1.comboBox_User.Text.Contains("中置"))
  551. {
  552. 中置电机ToolStripMenuItem.Checked = true;
  553. 轮毂电机ToolStripMenuItem.Checked = false;
  554. toolStripTextBox_MACPD.Text = "MM_MC1";
  555. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  556. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  557. }
  558. else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
  559. {
  560. 中置电机ToolStripMenuItem.Checked = false;
  561. 轮毂电机ToolStripMenuItem.Checked = true;
  562. toolStripTextBox_MACPD.Text = "GF_250_1";
  563. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  564. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  565. }
  566. //显示对应生产测试界面
  567. if (EnterForm1.comboBox_User.Text.Contains("写入"))
  568. {
  569. tabPage_ProductMode_Write.Parent = tabControl1;
  570. tabPage_ProductMode_Write.Select();
  571. tabPage_ProductMode_Read.Parent = null;
  572. }
  573. else if (EnterForm1.comboBox_User.Text.Contains("检验"))
  574. {
  575. tabPage_ProductMode_Read.Parent = tabControl1;
  576. tabPage_ProductMode_Read.Select();
  577. tabPage_ProductMode_Write.Parent = null;
  578. }
  579. //应答指令不提示
  580. ACK_DisFlag = false;
  581. //退出登录
  582. break;
  583. }
  584. else if (EnterForm1.comboBox_User.Text == "工程参数配置")
  585. {
  586. //隐藏工作台内容,新建窗口完成配置
  587. groupBox1.Visible = false;
  588. groupBox3.Visible = false;
  589. tabControl2.Visible = false;
  590. //隐藏提示信息
  591. label_StarInfo.Visible = false;
  592. //打开参数配置框
  593. GenerateParamsForm.ShowDialog();
  594. System.Environment.Exit(0);
  595. //退出登录
  596. break;
  597. }
  598. else if (EnterForm1.comboBox_User.Text.Contains("样机"))
  599. {
  600. //隐藏量产界面
  601. tabPage_ProductMode_Read.Parent = null;
  602. tabPage_ProductMode_Write.Parent = null;
  603. //隐藏配置项
  604. 其它配置项ToolStripMenuItem.Visible = false;
  605. 服务器配置ToolStripMenuItem.Visible = false;
  606. 判断阈值ToolStripMenuItem.Visible = false;
  607. 力矩传感器检验ToolStripMenuItem.Visible = false;
  608. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  609. mOS内阻范围ToolStripMenuItem.Visible = false;
  610. 位置校准偏差范围ToolStripMenuItem.Visible = false;
  611. //显示生产信息
  612. 生产信息ToolStripMenuItem.Visible = true;
  613. //显示电机类型,但不可编辑
  614. 电机类型ToolStripMenuItem.Visible = true;
  615. 中置电机ToolStripMenuItem.Enabled = true;
  616. 轮毂电机ToolStripMenuItem.Enabled = true;
  617. if (uARTToolStripMenuItem.Checked)
  618. UART协议ToolStripMenuItem.Visible = true;
  619. if (EnterForm1.comboBox_User.Text.Contains("中置"))
  620. {
  621. 中置电机ToolStripMenuItem.Checked = true;
  622. 轮毂电机ToolStripMenuItem.Checked = false;
  623. toolStripTextBox_MACPD.Text = "MM_MC1";
  624. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  625. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  626. }
  627. else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
  628. {
  629. 中置电机ToolStripMenuItem.Checked = false;
  630. 轮毂电机ToolStripMenuItem.Checked = true;
  631. toolStripTextBox_MACPD.Text = "GF_250_1";
  632. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  633. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  634. }
  635. //退出登录
  636. break;
  637. }
  638. else if (EnterForm1.comboBox_User.Text == "FCT治具测试")
  639. {
  640. //隐藏设置项
  641. 其它配置项ToolStripMenuItem.Visible = false;
  642. 写入存储ToolStripMenuItem.Visible = false;
  643. 服务器配置ToolStripMenuItem.Visible = false;
  644. 判断阈值ToolStripMenuItem.Visible = false;
  645. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  646. mOS内阻范围ToolStripMenuItem.Visible = false;
  647. 力矩传感器检验ToolStripMenuItem.Visible = false;
  648. 位置校准偏差范围ToolStripMenuItem.Visible = false;
  649. //显示生产信息
  650. 生产信息ToolStripMenuItem.Visible = true;
  651. //显示电机类型,但不可编辑
  652. 电机类型ToolStripMenuItem.Visible = false;
  653. 中置电机ToolStripMenuItem.Enabled = false;
  654. 轮毂电机ToolStripMenuItem.Enabled = false;
  655. if (uARTToolStripMenuItem.Checked)
  656. UART协议ToolStripMenuItem.Visible = true;
  657. //隐藏研发调试界面
  658. tabPage_MotorParam.Parent = null;
  659. tabPage_BikeParam.Parent = null;
  660. tabPage_BikeParam2.Parent = null;
  661. tabPage_ControlParam.Parent = null;
  662. tabPage_SensorParam.Parent = null;
  663. tabPage_AssistParam.Parent = null;
  664. tabPage_UsrRideParam.Parent = null;
  665. tabPage_DebugParam.Parent = null;
  666. tabPage_RecordInfo.Parent = null;
  667. tabPage_OtherInfo.Parent = null;
  668. tabPage_OBC.Parent = null;
  669. tabPage_RAMorFLASH.Parent = null;
  670. tabPage_FactoryMode.Parent = null;
  671. tabPage_DebugInfo.Parent = null;
  672. tabPage_AngleCal.Parent = null;
  673. //显示运行信息
  674. tabPage_RunInfo.Parent = tabControl2;
  675. //目前仅轮毂使用
  676. 中置电机ToolStripMenuItem.Checked = false;
  677. 轮毂电机ToolStripMenuItem.Checked = true;
  678. toolStripTextBox_MACPD.Text = "GF_250_1";
  679. toolStripTextBox_ServerPath.Text = "HUB_Control_FCT";
  680. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  681. //显示量产测试界面
  682. tabPage_ProductMode_Write.Parent = tabControl1;
  683. tabPage_ProductMode_Write.Select();
  684. tabPage_ProductMode_Read.Parent = null;
  685. checkBox_OffLineFacMode.Checked = false;
  686. checkBox_OffLineFacMode.Enabled = true;
  687. checkBox_OffLineCheckMode.Checked = false;
  688. checkBox_OffLineCheckMode.Enabled = true;
  689. //应答指令不提示
  690. ACK_DisFlag = false;
  691. //退出登录
  692. break;
  693. }
  694. else if (EnterForm1.comboBox_User.Text == "研发调试")
  695. {
  696. //隐藏量产界面
  697. tabPage_ProductMode_Read.Parent = null;
  698. tabPage_ProductMode_Write.Parent = null;
  699. 服务器配置ToolStripMenuItem.Visible = false;
  700. if (uARTToolStripMenuItem.Checked)
  701. UART协议ToolStripMenuItem.Visible = true;
  702. //退出登录
  703. break;
  704. }
  705. else if (EnterForm1.comboBox_User.Text == "管理员")
  706. {
  707. //不隐藏任何界面
  708. //...
  709. //退出登录
  710. break;
  711. }
  712. else
  713. {
  714. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  715. //重新登录
  716. continue;
  717. }
  718. }
  719. else
  720. {
  721. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  722. //重新登录
  723. continue;
  724. }
  725. }
  726. catch (Exception)
  727. {
  728. System.Environment.Exit(0);
  729. }
  730. } while (true);
  731. //配置网络FTP服务器
  732. myFtp.FtpOption(ServerIP, ServerPort, ServerUser, ServerPassWd, "admin", "ttium_admin");
  733. //创建线程,定时检测网络连接状态
  734. Thread th = new Thread(NetworkCheck);
  735. th.IsBackground = true;
  736. th.Start();
  737. //允许跨线程访问
  738. Control.CheckForIllegalCrossThreadCalls = false;
  739. }
  740. /// <summary>
  741. /// 检查网络状态线程
  742. /// </summary>
  743. private void NetworkCheck()
  744. {
  745. //允许离线使用,直接退出
  746. if (OfflineFlag == true) //允许离线使用
  747. {
  748. timer_500ms.Enabled = false;
  749. MessageBoxTimeOut.Show("离线使用,不检测网络状态!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  750. timer_500ms.Enabled = true;
  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. timer_500ms.Enabled = false;
  783. MessageBoxTimeOut.Show("网络断开,将自动关闭!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  784. timer_500ms.Enabled = true;
  785. this.Close();
  786. }
  787. }
  788. //创建定时器,定时30s检查网络
  789. System.Timers.Timer timer_CheckNet = new System.Timers.Timer();
  790. timer_CheckNet.Enabled = true;
  791. timer_CheckNet.Interval = 30000;
  792. timer_CheckNet.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_CheckNet_Tick);
  793. timer_CheckNet.Start();
  794. while (true)
  795. {
  796. Thread.Sleep(1);
  797. if (myFtp.IsNetConnected == false)
  798. {
  799. label_Server_ComStatus.Text = "网络已断开";
  800. label_ServerStatus.BackColor = Color.Red;
  801. }
  802. else
  803. {
  804. label_Server_ComStatus.Text = "网络已连接";
  805. label_ServerStatus.BackColor = Color.Green;
  806. }
  807. }
  808. }
  809. }
  810. /// <summary>
  811. /// 线程中定时任务,检查网络状态
  812. /// </summary>
  813. /// <param name="sender"></param>
  814. /// <param name="e"></param>
  815. private void timer_CheckNet_Tick(object sender, EventArgs e)
  816. {
  817. //连接FTP服务器
  818. bool Result = myFtp.CheckFtp();
  819. if (Result == true)//服务器连接成功
  820. {
  821. myFtp.IsNetConnected = true;
  822. //允许使用
  823. groupBox1.Enabled = true;
  824. groupBox3.Enabled = true;
  825. tabControl2.Enabled = true;
  826. }
  827. else//服务器连接失败
  828. {
  829. myFtp.IsNetConnected = false;
  830. if (EnterForm1.comboBox_User.Text != "管理员")
  831. {
  832. timer_500ms.Enabled = false;
  833. MessageBoxTimeOut.Show("网络断开, 请检查网络!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Warning); //提示框自动3s关闭
  834. timer_500ms.Enabled = true;
  835. //禁止使用
  836. groupBox1.Enabled = false;
  837. groupBox3.Enabled = false;
  838. tabControl2.Enabled = false;
  839. }
  840. }
  841. }
  842. #region 非独占性延时函数
  843. public static void Delay_ms(int milliSecond)
  844. {
  845. int start = Environment.TickCount;
  846. while (Math.Abs(Environment.TickCount - start) < milliSecond)//毫秒
  847. {
  848. Application.DoEvents();
  849. }
  850. }
  851. #endregion
  852. private void MainForm_Load(object sender, System.EventArgs e)
  853. {
  854. //页面初始化
  855. label_BuildTime.Text = "编译时间:" + System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString("yyyy-MM-dd HH:mm:ss");
  856. label_Computername.Text = System.Environment.UserName;
  857. label_UserName.Text = EnterForm1.comboBox_User.Text;
  858. //位置校准表格初始化
  859. for (int i = 0; i < 7; i++)
  860. {
  861. int index = dataGridView_AngleCal.Rows.Add();
  862. dataGridView_AngleCal.Rows[index].Cells[0].Value = i + 1;
  863. }
  864. dataGridView_AngleCal.AllowUserToAddRows = false;
  865. this.Text += Version;
  866. //检查版本,自动更新
  867. do
  868. {
  869. if ((打开ToolStripMenuItem.Checked == false) || OfflineFlag == true)//关闭自动更新或离线时
  870. {
  871. break;
  872. }
  873. //检查网络状态
  874. if (myFtp.CheckFtp() == false)
  875. {
  876. MessageBoxTimeOut.Show("网络断开,自动更新失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  877. break;
  878. }
  879. else
  880. {
  881. //检查本地文件删除
  882. if (System.IO.File.Exists(localInfo.LocalPath + "\\Version"))
  883. System.IO.File.Delete(localInfo.LocalPath + "\\Version");
  884. //读取最新版本号
  885. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/Version", localInfo.LocalPath);
  886. StreamReader objReader = new StreamReader(localInfo.LocalPath + "\\Version");
  887. string sLine = "";
  888. ArrayList arrText = new ArrayList();//创建一个动态数组
  889. while (sLine != null)
  890. {
  891. sLine = objReader.ReadLine();
  892. arrText.Add(sLine);
  893. }
  894. objReader.Close();
  895. System.IO.File.Delete(localInfo.LocalPath + "\\Version");
  896. //检查是否有最新版本
  897. string[] VerOld = mainForm.Version.Trim().Split('.');
  898. string[] VerNew = arrText[0].ToString().Trim().Split('.');
  899. int VerOld_int = Convert.ToInt32(VerOld[0]) * 10000 + Convert.ToInt32(VerOld[1].PadLeft(2, '0')) * 100 + Convert.ToInt32(VerOld[2].PadLeft(2, '0'));
  900. int VerNew_int = Convert.ToInt32(VerNew[0]) * 10000 + Convert.ToInt32(VerNew[1].PadLeft(2, '0')) * 100 + Convert.ToInt32(VerNew[2].PadLeft(2, '0'));
  901. if (VerNew_int <= VerOld_int)
  902. {
  903. //版本已是最新,跳出
  904. break;
  905. }
  906. //确认下载最新版本
  907. if (MessageBox.Show("是否更新新版本?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  908. {
  909. string SavePath = Directory.GetCurrentDirectory();
  910. string[] FileList = myFtp.GetFileNameList("/Tools/Welling_Motor_Debug_Tool");
  911. foreach (string file in FileList)
  912. {
  913. if (file.Contains(".exe"))
  914. {
  915. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/" + file, SavePath);
  916. MessageBox.Show("新版本下载完成,请手动删除旧版本!\r\n最新版本:" + file, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  917. System.Environment.Exit(0);
  918. }
  919. }
  920. }
  921. }
  922. } while (false);
  923. //下拉控件初始值设定
  924. comboBox_WorkMode.SelectedIndex = 0;
  925. comboBox_GearSt.SelectedIndex = 0;
  926. comboBox_LightSwitch.SelectedIndex = 1;
  927. comboBox_OBC_SetGearST.SelectedIndex = 0;
  928. comboBox_OBC_LightSw.SelectedIndex = 1;
  929. comboBox_AssistTorque.SelectedIndex = 0;
  930. comboBox_AssistCadence.SelectedIndex = 0;
  931. //combobox事件定义
  932. this.comboBox_WorkMode.SelectedIndexChanged += new System.EventHandler(this.comboBox_WorkMode_SelectedIndexChanged);
  933. this.comboBox_GearSt.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  934. this.comboBox_LightSwitch.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  935. this.comboBox_OBC_SetGearST.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  936. this.comboBox_OBC_LightSw.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  937. //端口自动连接
  938. if ((PortNumSave != string.Empty) && (PortBaudrateSave != string.Empty)) //有数值时采用上次使用的值
  939. {
  940. try
  941. {
  942. PortConnect();
  943. }
  944. catch (System.Exception)
  945. {
  946. timer_500ms.Enabled = false;
  947. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  948. timer_500ms.Enabled = true;
  949. }
  950. }
  951. //不识别联动装置盒自动打开界面
  952. #if true
  953. groupBox1.Visible = true;
  954. groupBox3.Visible = true;
  955. tabControl2.Visible = true;
  956. label_StarInfo.Visible = false;
  957. #endif
  958. //创建线程,定时解析数据
  959. Thread th = new Thread(Task_SerialProcess);
  960. th.IsBackground = true;
  961. th.Start();
  962. }
  963. #region 结构体与字节流相互转换
  964. public static class MyConverter
  965. {
  966. /// <summary>
  967. /// 由结构体转换为byte数组
  968. /// </summary>
  969. public static byte[] StructureToByte<T>(T structure)
  970. {
  971. int size = Marshal.SizeOf(typeof(T));
  972. byte[] buffer = new byte[size];
  973. IntPtr bufferIntPtr = Marshal.AllocHGlobal(size);
  974. try
  975. {
  976. Marshal.StructureToPtr(structure, bufferIntPtr, true);
  977. Marshal.Copy(bufferIntPtr, buffer, 0, size);
  978. }
  979. finally
  980. {
  981. Marshal.FreeHGlobal(bufferIntPtr);
  982. }
  983. return buffer;
  984. }
  985. /// <summary>
  986. /// 由byte数组转换为结构体
  987. /// </summary>
  988. public static T ByteToStructure<T>(byte[] dataBuffer, ushort StarIndex)
  989. {
  990. object structure = null;
  991. int size = Marshal.SizeOf(typeof(T));
  992. IntPtr allocIntPtr = Marshal.AllocHGlobal(size);
  993. try
  994. {
  995. Marshal.Copy(dataBuffer, StarIndex, allocIntPtr, size);
  996. structure = Marshal.PtrToStructure(allocIntPtr, typeof(T));
  997. }
  998. finally
  999. {
  1000. Marshal.FreeHGlobal(allocIntPtr);
  1001. }
  1002. return (T)structure;
  1003. }
  1004. }
  1005. #endregion
  1006. #region 故障日志解析显示
  1007. private void ErrorLogDisplay(MC_ErrorLogSaveInfo_Struct_t Log1, MC_ErrorLogSaveInfo_Struct_t Log2)
  1008. {
  1009. string SaveData = "";
  1010. //Log1
  1011. if (Log1.Error_Index != 0xFFFF)
  1012. {
  1013. SaveData += "故障序号:" + Convert.ToString(Log1.Error_Index) + ", ";
  1014. SaveData += "备注1:" + Convert.ToString(Log1.NotesInfo1) + ", ";
  1015. SaveData += "备注2:" + Convert.ToString(Log1.NotesInfo2) + ", ";
  1016. SaveData += "备注3:" + Convert.ToString(Log1.NotesInfo3) + ", ";
  1017. SaveData += "故障码:" + "0x" + Convert.ToString(Log1.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  1018. SaveData += "运行时间:" + Convert.ToString(Log1.RunTime) + "min" + ", ";
  1019. SaveData += "车速:" + ((float)Log1.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  1020. SaveData += "电机转速:" + Convert.ToString(Log1.RunInfo.MotorSpeed) + "rpm" + ", ";
  1021. SaveData += "功率:" + Convert.ToString(Log1.RunInfo.Power * 2) + "w" + ", ";
  1022. SaveData += "电压:" + Convert.ToString(Log1.RunInfo.BusVoltage) + "mV" + ", ";
  1023. SaveData += "电流:" + Convert.ToString(Log1.RunInfo.BusCurrent) + "mA" + ", ";
  1024. SaveData += "踏频:" + Convert.ToString(Log1.RunInfo.Cadence) + "rpm" + ", ";
  1025. SaveData += "力矩:" + Convert.ToString(Log1.RunInfo.Torque) + "N.m" + ", ";
  1026. SaveData += "方向:" + ((Log1.RunInfo.CadenceDir == 0) ? "正" : ((Log1.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  1027. SaveData += "档位:" + "0x" + Convert.ToString(Log1.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  1028. SaveData += "灯开关:" + ((Log1.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  1029. SaveData += "电量:" + Convert.ToString(Log1.RunInfo.SOC) + "%" + ", ";
  1030. if ((Log1.RunInfo.RemainDistance == 0xEEEE) || (Log1.RunInfo.RemainDistance == 0xFFFF))
  1031. {
  1032. SaveData += "续航:" + "---km" + ", ";
  1033. }
  1034. else
  1035. {
  1036. SaveData += "续航:" + Convert.ToString(Log1.RunInfo.RemainDistance) + "km" + ", ";
  1037. }
  1038. SaveData += "力矩AD:" + Convert.ToString(Log1.RunInfo.Torque_AD) + ", ";
  1039. SaveData += "功耗:" + Convert.ToString(Log1.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  1040. SaveData += "PCB温度:" + Convert.ToString((int)(Log1.RunInfo.T_PCB - 40)) + "℃" + ", ";
  1041. SaveData += "绕组温度:" + Convert.ToString((int)(Log1.RunInfo.T_Coil - 40)) + "℃" + ", ";
  1042. SaveData += "MCU温度:" + Convert.ToString((int)(Log1.RunInfo.T_MCU - 40)) + "℃" + ", ";
  1043. SaveData += "单次里程:" + Convert.ToString((float)Log1.RunInfo.Ride_Km / 10f) + "km" + ", ";
  1044. SaveData += "单次时间:" + Convert.ToString(Log1.RunInfo.Ride_Time) + "s" + ", ";
  1045. SaveData += "q轴电流:" + Convert.ToString(Log1.IqCurrent) + ", ";
  1046. SaveData += "q轴电压:" + Convert.ToString(Log1.IqVoltage) + ", ";
  1047. SaveData += "d轴电流:" + Convert.ToString(Log1.IdCurrent) + ", ";
  1048. SaveData += "d轴电压:" + Convert.ToString(Log1.IdVoltage) + ", ";
  1049. SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
  1050. SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
  1051. SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
  1052. SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
  1053. SaveData += "\r\n\r\n";
  1054. richTextBox_Record.AppendText(SaveData);
  1055. SaveData = "";
  1056. }
  1057. //Log2
  1058. if (Log2.Error_Index != 0xFFFF)
  1059. {
  1060. SaveData += "故障序号:" + Convert.ToString(Log2.Error_Index) + ", ";
  1061. SaveData += "备注1:" + Convert.ToString(Log2.NotesInfo1) + ", ";
  1062. SaveData += "备注2:" + Convert.ToString(Log2.NotesInfo2) + ", ";
  1063. SaveData += "备注3:" + Convert.ToString(Log2.NotesInfo3) + ", ";
  1064. SaveData += "故障码:" + "0x" + Convert.ToString(Log2.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  1065. SaveData += "运行时间:" + Convert.ToString(Log2.RunTime) + "min" + ", ";
  1066. SaveData += "车速:" + ((float)Log2.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  1067. SaveData += "电机转速:" + Convert.ToString(Log2.RunInfo.MotorSpeed) + "rpm" + ", ";
  1068. SaveData += "功率:" + Convert.ToString(Log2.RunInfo.Power * 2) + "w" + ", ";
  1069. SaveData += "电压:" + Convert.ToString(Log2.RunInfo.BusVoltage) + "mV" + ", ";
  1070. SaveData += "电流:" + Convert.ToString(Log2.RunInfo.BusCurrent) + "mA" + ", ";
  1071. SaveData += "踏频:" + Convert.ToString(Log2.RunInfo.Cadence) + "rpm" + ", ";
  1072. SaveData += "力矩:" + Convert.ToString(Log2.RunInfo.Torque) + "N.m" + ", ";
  1073. SaveData += "方向:" + ((Log2.RunInfo.CadenceDir == 0) ? "正" : ((Log2.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  1074. SaveData += "档位:" + "0x" + Convert.ToString(Log2.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  1075. SaveData += "灯开关:" + ((Log2.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  1076. SaveData += "电量:" + Convert.ToString(Log2.RunInfo.SOC) + "%" + ", ";
  1077. if ((Log2.RunInfo.RemainDistance == 0xEEEE) || (Log2.RunInfo.RemainDistance == 0xFFFF))
  1078. {
  1079. SaveData += "续航:" + "---km" + ", ";
  1080. }
  1081. else
  1082. {
  1083. SaveData += "续航:" + Convert.ToString(Log2.RunInfo.RemainDistance) + "km" + ", ";
  1084. }
  1085. SaveData += "力矩AD:" + Convert.ToString(Log2.RunInfo.Torque_AD) + ", ";
  1086. SaveData += "功耗:" + Convert.ToString(Log2.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  1087. SaveData += "PCB温度:" + Convert.ToString((int)(Log2.RunInfo.T_PCB - 40)) + "DegreeC" + ", ";
  1088. SaveData += "绕组温度:" + Convert.ToString((int)(Log2.RunInfo.T_Coil - 40)) + "DegreeC" + ", ";
  1089. SaveData += "MCU温度:" + Convert.ToString((int)(Log2.RunInfo.T_MCU - 40)) + "DegreeC" + ", ";
  1090. SaveData += "单次里程:" + Convert.ToString((float)Log2.RunInfo.Ride_Km / 10f) + "km" + ", ";
  1091. SaveData += "单次时间:" + Convert.ToString(Log2.RunInfo.Ride_Time) + "s" + ", ";
  1092. SaveData += "q轴电流:" + Convert.ToString(Log2.IqCurrent) + ", ";
  1093. SaveData += "q轴电压:" + Convert.ToString(Log2.IqVoltage) + ", ";
  1094. SaveData += "d轴电流:" + Convert.ToString(Log2.IdCurrent) + ", ";
  1095. SaveData += "d轴电压:" + Convert.ToString(Log2.IdVoltage) + ", ";
  1096. SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
  1097. SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
  1098. SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
  1099. SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
  1100. SaveData += "\r\n\r\n";
  1101. richTextBox_Record.AppendText(SaveData);
  1102. SaveData = "";
  1103. }
  1104. }
  1105. #endregion
  1106. #region 串口数据解析线程
  1107. /// <summary>
  1108. /// 串口数据解析线程
  1109. /// </summary>
  1110. private void Task_SerialProcess()
  1111. {
  1112. //创建定时器,定时读取串口数据
  1113. System.Timers.Timer timer_ReadSerial = new System.Timers.Timer();
  1114. timer_ReadSerial.Enabled = true;
  1115. timer_ReadSerial.Interval = 20;
  1116. timer_ReadSerial.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_ReadSerial_Tick);
  1117. timer_ReadSerial.Start();
  1118. while (true)
  1119. {
  1120. Thread.Sleep(1);
  1121. };
  1122. }
  1123. /// <summary>
  1124. /// 串口解析定时器
  1125. /// </summary>
  1126. /// <param name="sender"></param>
  1127. /// <param name="e"></param>
  1128. private void timer_ReadSerial_Tick(object sender, EventArgs e)
  1129. {
  1130. //串口解析
  1131. Serial_process(mySerialProcess.buffer);
  1132. }
  1133. #endregion
  1134. #region 数据解析
  1135. public void Serial_process(List<byte> buffer)
  1136. {
  1137. byte DataNum = 0; //记录每条命令数据段的长度
  1138. ushort PackageID, Cmd;
  1139. byte[] Data = new byte[1024];
  1140. try
  1141. {
  1142. while (buffer.Count >= 13)//当buffer中的数据的个数大于等于4个时,即每一帧的数据长度所在位(第4位)出现时
  1143. {
  1144. if (buffer[0] == 0x55 && buffer[1] == 0xAA)//判断帧头
  1145. {
  1146. PackageID = (ushort)(buffer[2] * 256 + buffer[3]);
  1147. if ((PackageID == 0x0710) || (PackageID == 0x0715) || (PackageID == 0x07FF) || (PackageID == 0x0720) || (PackageID == 0x0713))
  1148. {
  1149. int CmdLen = buffer[5];
  1150. if (buffer.Count < CmdLen + 11) break;//如果接收到的数据没有达到一帧数据的指定长度, 则执行下次循环
  1151. while (CmdLen > 0) //读取命令段
  1152. {
  1153. Cmd = (ushort)(buffer[6] * 256 + buffer[7]);
  1154. DataNum = (byte)(buffer[7]);//命令字的第二个字节的表示数据位的长度
  1155. if (DataNum <= (CmdLen - 2))
  1156. {
  1157. for (int i = 0; i < DataNum; i++)
  1158. {
  1159. Data[i] = buffer[i + 8];
  1160. }
  1161. // 串口接收的数据 显示在子窗口
  1162. if (this.DebugWindowIsOpen && this.DebugDataDisplayEnable)
  1163. {
  1164. string strTemp = String.Empty;
  1165. strTemp += System.DateTimeOffset.Now.ToString("HH:mm:ss.fff") + " <-- ";
  1166. for (int i = 0; i < CmdLen + 11; i++)
  1167. {
  1168. strTemp += (buffer[i].ToString("X2") + " ");
  1169. }
  1170. strTemp += "\n";
  1171. DebugForm.debug1.richTextBox_DebugRev.Text += strTemp;
  1172. }
  1173. buffer.RemoveRange(0, CmdLen + 11);
  1174. DataCmdProcess(PackageID, Cmd, Data);//对于不同的命令段,做不同的处理
  1175. DataRevToString(Cmd, Data);//指令数据转为字符串
  1176. }
  1177. }
  1178. }
  1179. else
  1180. {
  1181. buffer.RemoveAt(0);//ID不对
  1182. }
  1183. }
  1184. else
  1185. {
  1186. buffer.RemoveAt(0);//帧头不对,删除帧头高字节
  1187. }
  1188. }
  1189. }
  1190. catch (Exception)
  1191. {
  1192. }
  1193. }
  1194. private void DataCmdProcess(ushort ID, ushort CmdTemp, byte[] Data)
  1195. {
  1196. int DataTemp;
  1197. ushort uData16;
  1198. unchecked
  1199. {
  1200. this.Invoke((EventHandler)(delegate { label_RecCount.Text = Convert.ToString(Convert.ToInt32(label_RecCount.Text) + 1); }));
  1201. }
  1202. #region 解析发送给CDL的指令
  1203. if (ID == 0x7FF)
  1204. {
  1205. switch (CmdTemp)
  1206. {
  1207. case 0x1100://
  1208. {
  1209. unchecked
  1210. {
  1211. this.Invoke((EventHandler)(delegate
  1212. {
  1213. //CDL连接成功
  1214. mySerialProcess.CDL_Online_Flag = true;
  1215. MessageBoxTimeOut.Show("连接成功!", "提示", 500);
  1216. groupBox1.Visible = true;
  1217. groupBox3.Visible = true;
  1218. tabControl2.Visible = true;
  1219. label_StarInfo.Visible = false;
  1220. }));
  1221. }
  1222. break;
  1223. }
  1224. default: break;
  1225. }
  1226. }
  1227. #endregion
  1228. #region 解析电机的命令
  1229. else if ((ID == 0x715) || (ID == 0x710))
  1230. {
  1231. switch (CmdTemp)
  1232. {
  1233. case 0x1020://电机运行信息
  1234. {
  1235. unchecked
  1236. {
  1237. this.Invoke((EventHandler)(delegate
  1238. {
  1239. MC_RunInfo_Refresh = true;
  1240. //车速
  1241. DataTemp = (int)(Data[1] * 256 + Data[0]);
  1242. textBox_RunInfo_BikeSpeed.Text = ((float)DataTemp / 10f).ToString("0.0") + " km/h";
  1243. //输出转速
  1244. DataTemp = (ushort)(Data[3] * 256 + Data[2]);
  1245. textBox_RunInfo_MotorSpeed.Text = Convert.ToString(DataTemp) + " rpm";
  1246. Class_MotorSpeed.String = textBox_RunInfo_MotorSpeed.Text;
  1247. Class_MotorSpeed.Data = DataTemp;
  1248. //电功率
  1249. DataTemp = (ushort)(Data[5] * 256 + Data[4]);
  1250. textBox_RunInfo_Power.Text = Convert.ToString(DataTemp) + " W";
  1251. //母线电压
  1252. DataTemp = (ushort)(Data[7] * 256 + Data[6]);
  1253. textBox_RunInfo_Vol.Text = Convert.ToString(DataTemp) + " mV";
  1254. //textBox_RunInfo_Vol.Text = (DataTemp / 1000f).ToString("0.0") + " V";
  1255. //母线电流
  1256. DataTemp = (short)(Data[9] * 256 + Data[8]);
  1257. textBox_RunInfo_Current.Text = Convert.ToString(DataTemp) + " mA";
  1258. //textBox_RunInfo_Current.Text = (DataTemp / 1000f).ToString("0.0") + " A";
  1259. Class_CurrentData.String = textBox_RunInfo_Current.Text;
  1260. Class_CurrentData.Data = DataTemp;
  1261. //踏频
  1262. DataTemp = (ushort)(Data[10]);
  1263. textBox_RunInfo_Cadence.Text = Convert.ToString(DataTemp) + " rpm";
  1264. Class_CadenceData.String = textBox_RunInfo_Cadence.Text;
  1265. Class_CadenceData.Data = DataTemp;
  1266. //踩踏力矩
  1267. DataTemp = (ushort)(Data[11]);
  1268. textBox_RunInfo_Torque.Text = Convert.ToString(DataTemp) + " N.m";
  1269. Class_TorqueData.String = textBox_RunInfo_Torque.Text;
  1270. Class_TorqueData.Data = DataTemp;
  1271. //踩踏方向
  1272. DataTemp = (ushort)(Data[12]);
  1273. if (DataTemp == 0)
  1274. {
  1275. textBox_RunInfo_Dir.Text = "正向";
  1276. }
  1277. else if (DataTemp == 1)
  1278. {
  1279. textBox_RunInfo_Dir.Text = "反向";
  1280. }
  1281. else if (DataTemp == 2)
  1282. {
  1283. textBox_RunInfo_Dir.Text = "停止";
  1284. }
  1285. //助力档位
  1286. DataTemp = (ushort)(Data[13]);
  1287. if (DataTemp == 0x33)
  1288. {
  1289. textBox_RunInfo_GearSt.Text = "SMART";
  1290. //comboBox_GearSt.SelectedIndex = 5;
  1291. //comboBox_OBC_SetGearST.SelectedIndex = 5;
  1292. }
  1293. else if (DataTemp == 0x22)
  1294. {
  1295. textBox_RunInfo_GearSt.Text = "WALK";
  1296. //comboBox_GearSt.SelectedIndex = 6;
  1297. //comboBox_OBC_SetGearST.SelectedIndex = 6;
  1298. }
  1299. else
  1300. {
  1301. string[] Gears = new string[5] { "OFF", "ECO", "NORM", "SPORT", "TURBO" };
  1302. textBox_RunInfo_GearSt.Text = Gears[DataTemp];
  1303. //comboBox_GearSt.SelectedIndex = DataTemp;
  1304. //comboBox_OBC_SetGearST.SelectedIndex = DataTemp;
  1305. }
  1306. //大灯状态
  1307. DataTemp = (ushort)(Data[14]);
  1308. if (DataTemp == 0xF0)
  1309. {
  1310. textBox_RunInfo_LightSwitch.Text = "OFF";
  1311. //comboBox_LightSwitch.SelectedIndex = 1;
  1312. //comboBox_OBC_LightSw.SelectedIndex = 1;
  1313. }
  1314. else if (DataTemp == 0xF1)
  1315. {
  1316. textBox_RunInfo_LightSwitch.Text = "ON";
  1317. //comboBox_LightSwitch.SelectedIndex = 0;
  1318. //comboBox_OBC_LightSw.SelectedIndex = 0;
  1319. }
  1320. //剩余电量
  1321. DataTemp = (ushort)(Data[15]);
  1322. textBox_RunInfo_SOC.Text = Convert.ToString(DataTemp) + " %";
  1323. //剩余续航里程
  1324. DataTemp = (ushort)(Data[17] * 256 + Data[16]);
  1325. if ((DataTemp == 0xEEEE) || (DataTemp == 0xFFFF))
  1326. {
  1327. textBox_RunInfo_Range.Text = "---";
  1328. }
  1329. else
  1330. {
  1331. textBox_RunInfo_Range.Text = Convert.ToString(DataTemp) + " km";
  1332. }
  1333. //预留(显示力矩Reg),空2bytes
  1334. DataTemp = (ushort)(Data[19] * 256 + Data[18]);
  1335. textBox_TorqueReg.Text = Convert.ToString(DataTemp);
  1336. //平均功耗
  1337. DataTemp = (ushort)(Data[20]);
  1338. textBox_RunInfo_AvgPower.Text = Convert.ToString(DataTemp * 10) + " mAh/km";
  1339. //PCB温度
  1340. DataTemp = (ushort)(Data[21]);
  1341. textBox_RunInfo_T_PCB.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1342. Class_MotorTemp.String = textBox_RunInfo_T_PCB.Text;
  1343. Class_MotorTemp.Data = DataTemp - 40;
  1344. //绕组温度
  1345. DataTemp = (ushort)(Data[22]);
  1346. textBox_RunInfo_T_Coil.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1347. //MCU温度
  1348. DataTemp = (ushort)(Data[23]);
  1349. textBox_RunInfo_T_MCU.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1350. //单次里程
  1351. DataTemp = (ushort)(Data[25] * 256 + Data[24]);
  1352. textBox_RunInfo_Trip.Text = ((float)DataTemp / 10f).ToString("0.0") + " km";
  1353. //单次时间
  1354. DataTemp = (ushort)(Data[27] * 256 + Data[26]);
  1355. textBox_RunInfo_Trip_Time.Text = Convert.ToString(DataTemp) + " s";
  1356. //数据保存
  1357. RunInfoAutoSave();
  1358. }));
  1359. }
  1360. break;
  1361. }
  1362. case 0x1104://故障码
  1363. {
  1364. unchecked
  1365. {
  1366. this.Invoke((EventHandler)(delegate
  1367. {
  1368. MC_ErrorCode_Refresh = true;
  1369. textBox_ErrorCode.Text =
  1370. Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() +
  1371. Convert.ToString(Data[2], 16).PadLeft(2, '0').ToUpper() +
  1372. Convert.ToString(Data[1], 16).PadLeft(2, '0').ToUpper() +
  1373. Convert.ToString(Data[0], 16).PadLeft(2, '0').ToUpper() +
  1374. "H";
  1375. }));
  1376. }
  1377. break;
  1378. }
  1379. case 0xA903://反馈指令
  1380. {
  1381. unchecked
  1382. {
  1383. this.Invoke((EventHandler)(delegate
  1384. {
  1385. if (ACK_DisFlag == true)
  1386. {
  1387. timer_500ms.Enabled = false;
  1388. MessageBoxTimeOut.Show("OK", "反馈指令", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  1389. timer_500ms.Enabled = true;
  1390. //关机反馈
  1391. PowerOffAckStatus = true;
  1392. }
  1393. //应答标志置位
  1394. WriteACK = true;
  1395. WriteCnt++;
  1396. }));
  1397. }
  1398. break;
  1399. }
  1400. case 0xB226://马达参数
  1401. {
  1402. unchecked
  1403. {
  1404. this.Invoke((EventHandler)(delegate
  1405. {
  1406. richTextBox_MotorParam.Clear();
  1407. for (int i = 0; i < myParams.MotorParam.Count; i++)
  1408. {
  1409. if (i == 6)
  1410. richTextBox_MotorParam.AppendText(myParams.MotorParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1411. else
  1412. richTextBox_MotorParam.AppendText(myParams.MotorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1413. }
  1414. richTextBox_MotorParam.Text = richTextBox_MotorParam.Text.Substring(0, richTextBox_MotorParam.Text.Length - 2);
  1415. }));
  1416. }
  1417. break;
  1418. }
  1419. case 0xB31A://整车信息
  1420. {
  1421. unchecked
  1422. {
  1423. this.Invoke((EventHandler)(delegate
  1424. {
  1425. richTextBox_BikeParam.Clear();
  1426. for (int i = 0; i < myParams.BikeParam.Count; i++)
  1427. {
  1428. if (i == 9)
  1429. richTextBox_BikeParam.AppendText(myParams.BikeParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1430. else
  1431. richTextBox_BikeParam.AppendText(myParams.BikeParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1432. //更新前后灯参数
  1433. if (i == 8)
  1434. {
  1435. comboBox_TailLightMode.SelectedIndex = ((Data[2 * i + 1] >> 4) & 0x0F) - 1;
  1436. comboBox_TailLightVol.SelectedIndex = ((Data[2 * i + 1] & 0x0F) == 6) ? 0 : 1;
  1437. comboBox_FrontLightVol.SelectedIndex = ((Data[2 * i] & 0x0F) == 6) ? 0 : 1;
  1438. }
  1439. //更新开关机参数
  1440. else if (i == 11)
  1441. {
  1442. textBox_PowerOnDelay.Text = Convert.ToString((Data[2 * i + 1] >> 4) & 0x0F);
  1443. textBox_PowerOffDelay.Text = Convert.ToString(Data[2 * i + 1] & 0x0F);
  1444. textBox_AutoPowerOff.Text = Convert.ToString(Data[2 * i]);
  1445. }
  1446. }
  1447. richTextBox_BikeParam.Text = richTextBox_BikeParam.Text.Substring(0, richTextBox_BikeParam.Text.Length - 2);
  1448. }));
  1449. }
  1450. break;
  1451. }
  1452. case 0xB420://控制器参数
  1453. {
  1454. unchecked
  1455. {
  1456. this.Invoke((EventHandler)(delegate
  1457. {
  1458. richTextBox_ControlParam.Clear();
  1459. for (int i = 0; i < myParams.ControlParam.Count; i++)
  1460. {
  1461. richTextBox_ControlParam.AppendText(myParams.ControlParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1462. //转把定速巡航
  1463. if (i == 13)
  1464. {
  1465. comboBox_Bike_CCS.SelectedIndex = ((Data[2 * i]) == 0xAA) ? 1 : 2;
  1466. }
  1467. }
  1468. richTextBox_ControlParam.Text = richTextBox_ControlParam.Text.Substring(0, richTextBox_ControlParam.Text.Length - 2);
  1469. }));
  1470. }
  1471. break;
  1472. }
  1473. case 0xB528://传感器参数
  1474. {
  1475. unchecked
  1476. {
  1477. this.Invoke((EventHandler)(delegate
  1478. {
  1479. richTextBox_SensorParam.Clear();
  1480. for (int i = 0; i < myParams.SensorParam.Count; i++)
  1481. {
  1482. richTextBox_SensorParam.AppendText(myParams.SensorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1483. }
  1484. richTextBox_SensorParam.Text = richTextBox_SensorParam.Text.Substring(0, richTextBox_SensorParam.Text.Length - 2);
  1485. //更新生产模式页面传感器零点和标定值
  1486. textBox_FacModeSensorADC0.Text = (Data[1] * 256 + Data[0]).ToString();
  1487. textBox_FacModeSensorADC1.Text = (Data[15] * 256 + Data[14]).ToString();
  1488. textBox_FacModeSensorADC2.Text = (Data[19] * 256 + Data[18]).ToString();
  1489. textBox_FacModeSensorADC3.Text = (Data[23] * 256 + Data[22]).ToString();
  1490. textBox_FacModeSensorADC4.Text = (Data[27] * 256 + Data[26]).ToString();
  1491. }));
  1492. }
  1493. break;
  1494. }
  1495. case 0xB64C://助力参数
  1496. {
  1497. unchecked
  1498. {
  1499. this.Invoke((EventHandler)(delegate
  1500. {
  1501. richTextBox_AssistParam.Clear();
  1502. int index_1 = myParams.AssistParam.IndexOf("转矩曲线.a");
  1503. int index_2 = myParams.AssistParam.IndexOf("踏频曲线.d");
  1504. int index_3 = myParams.AssistParam.IndexOf("踏频助力加速限制");
  1505. int index_4 = myParams.AssistParam.IndexOf("踏频助力电流步进");
  1506. for (int i = 0; i < myParams.AssistParam.Count; i++)
  1507. {
  1508. if (i < index_1) //数据占用2bytes
  1509. {
  1510. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1511. }
  1512. else if (i <= index_2) //数据占用4bytes
  1513. {
  1514. 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])) + ", ");
  1515. }
  1516. else if (i < index_3) //数据占用2bytes,无符号
  1517. {
  1518. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1519. }
  1520. else if (i <= index_4) //数据占用2bytes,有符号
  1521. {
  1522. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1523. }
  1524. else //数据占用2bytes,无符号
  1525. {
  1526. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1527. }
  1528. }
  1529. richTextBox_AssistParam.Text = richTextBox_AssistParam.Text.Substring(0, richTextBox_AssistParam.Text.Length - 2);
  1530. }));
  1531. }
  1532. break;
  1533. }
  1534. case 0xB74C://历史记录
  1535. {
  1536. unchecked
  1537. {
  1538. this.Invoke((EventHandler)(delegate
  1539. {
  1540. richTextBox_Record.Clear();
  1541. for (int i = 0; i < myParams.Record.Count; i++)
  1542. {
  1543. richTextBox_Record.AppendText(myParams.Record[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  1544. }
  1545. richTextBox_Record.Text = richTextBox_Record.Text.Substring(0, richTextBox_Record.Text.Length - 2);
  1546. }));
  1547. }
  1548. break;
  1549. }
  1550. case 0xB83A://调试参数
  1551. {
  1552. unchecked
  1553. {
  1554. this.Invoke((EventHandler)(delegate
  1555. {
  1556. richTextBox_DebugParam.Clear();
  1557. for (int i = 0; i < myParams.DebugParam.Count; i++)
  1558. {
  1559. richTextBox_DebugParam.AppendText(myParams.DebugParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1560. }
  1561. richTextBox_DebugParam.Text = richTextBox_DebugParam.Text.Substring(0, richTextBox_DebugParam.Text.Length - 2);
  1562. }));
  1563. }
  1564. break;
  1565. }
  1566. case 0xB904://存储标志
  1567. {
  1568. unchecked
  1569. {
  1570. this.Invoke((EventHandler)(delegate
  1571. {
  1572. ushort Flag = 0;
  1573. Flag = (ushort)(Data[1] * 256 + Data[0]);//EEPROM存储标志
  1574. if (Flag == 0)
  1575. {
  1576. radioButton_EE_SaveNo.Checked = true;
  1577. radioButton_EE_SaveYes.Checked = false;
  1578. }
  1579. else
  1580. {
  1581. radioButton_EE_SaveNo.Checked = false;
  1582. radioButton_EE_SaveYes.Checked = true;
  1583. }
  1584. Flag = (ushort)(Data[3] * 256 + Data[2]);//SIP偏移校准存储标志
  1585. if (Flag == 0)
  1586. {
  1587. radioButton_SIP_SaveNo.Checked = true;
  1588. radioButton_SIP_SaveYes.Checked = false;
  1589. }
  1590. else
  1591. {
  1592. radioButton_SIP_SaveNo.Checked = false;
  1593. radioButton_SIP_SaveYes.Checked = true;
  1594. }
  1595. }));
  1596. }
  1597. break;
  1598. }
  1599. case 0x1240://电机版本信息
  1600. {
  1601. unchecked
  1602. {
  1603. this.Invoke((EventHandler)(delegate
  1604. {
  1605. //电机型号
  1606. textBox_Model.Text = "";
  1607. textBox_OBC_ReadModel.Text = "";
  1608. textBox_FacModeName.Text = "";
  1609. for (ushort i = 0; i < 16; i++)
  1610. {
  1611. if (Data[i] == 0x2E)
  1612. {
  1613. break;
  1614. }
  1615. textBox_Model.Text += ((char)Data[i]).ToString();
  1616. textBox_OBC_ReadModel.Text += ((char)Data[i]).ToString();
  1617. textBox_FacModeName.Text += ((char)Data[i]).ToString();
  1618. }
  1619. Class_Motor_Ver.Mode = textBox_Model.Text;
  1620. //电机SN
  1621. textBox_SN.Text = "";
  1622. textBox_OBC_ReadSN.Text = "";
  1623. textBox_FacModeNum.Text = "";
  1624. for (ushort i = 0; i < 16; i++)
  1625. {
  1626. if (Data[16 + i] == 0x2E)
  1627. {
  1628. break;
  1629. }
  1630. textBox_SN.Text += ((char)Data[16 + i]).ToString();
  1631. textBox_OBC_ReadSN.Text += ((char)Data[16 + i]).ToString();
  1632. textBox_FacModeNum.Text += ((char)Data[16 + i]).ToString();
  1633. }
  1634. Class_Motor_Ver.SN = textBox_SN.Text;
  1635. //电机HW
  1636. textBox_HW.Text = "";
  1637. textBox_OBC_ReadHW.Text = "";
  1638. textBox_FacModeHW.Text = "";
  1639. for (ushort i = 0; i < 8; i++)//前8位:硬件板号
  1640. {
  1641. if (Data[32 + i] == 0x2E)
  1642. {
  1643. break;
  1644. }
  1645. else if (Data[32 + i] == 'r')
  1646. {
  1647. Data[32 + i] = (byte)'.';
  1648. break;
  1649. }
  1650. string strTemp = "";
  1651. strTemp = ((char)Data[32 + i]).ToString();
  1652. textBox_HW.Text += strTemp;
  1653. textBox_OBC_ReadHW.Text += strTemp;
  1654. textBox_FacModeHW.Text += strTemp;
  1655. }
  1656. for (ushort i = 0; i < 4; i++)//9-12位:单片机型号
  1657. {
  1658. if (Data[40 + i] == 0x2E)
  1659. {
  1660. break;
  1661. }
  1662. else if (Data[40 + i] == 'r')
  1663. {
  1664. Data[40 + i] = (byte)'.';
  1665. break;
  1666. }
  1667. string strTemp = "";
  1668. strTemp = ((char)Data[40 + i]).ToString();
  1669. textBox_HW.Text += strTemp;
  1670. textBox_OBC_ReadHW.Text += strTemp;
  1671. textBox_FacModeHW.Text += strTemp;
  1672. }
  1673. for (ushort i = 0; i < 4; i++)//13-16位:单片机ID
  1674. {
  1675. string strTemp = "";
  1676. strTemp = Convert.ToString(Data[44 + i], 16).PadLeft(2, '0').ToUpper();
  1677. textBox_HW.Text += strTemp;
  1678. textBox_OBC_ReadHW.Text += strTemp;
  1679. textBox_FacModeHW.Text += strTemp;
  1680. }
  1681. Class_Motor_Ver.HW = textBox_HW.Text;
  1682. //电机FW
  1683. textBox_FW.Text = "";
  1684. textBox_OBC_ReadFW.Text = "";
  1685. textBox_FacModeFW.Text = "";
  1686. for (ushort i = 0; i < 16; i++)
  1687. {
  1688. if ((Data[48 + i] == 0x2E) || (Data[48 + i] == 0x00) || (Data[48 + i] == (char)' '))
  1689. {
  1690. break;
  1691. }
  1692. if (Data[48 + i] == 'r')
  1693. {
  1694. Data[48 + i] = (byte)'.';
  1695. }
  1696. textBox_FW.Text += ((char)Data[48 + i]).ToString();
  1697. textBox_OBC_ReadFW.Text += ((char)Data[48 + i]).ToString();
  1698. textBox_FacModeFW.Text += ((char)Data[48 + i]).ToString();
  1699. }
  1700. Class_Motor_Ver.FW = textBox_FW.Text;
  1701. }));
  1702. }
  1703. break;
  1704. }
  1705. case 0xA610://自定义1
  1706. {
  1707. unchecked
  1708. {
  1709. this.Invoke((EventHandler)(delegate
  1710. {
  1711. textBox_User1.Text = "";
  1712. for (ushort i = 0; i < 16; i++)
  1713. {
  1714. if (Data[i] == 0x2E)
  1715. {
  1716. break;
  1717. }
  1718. textBox_User1.Text += ((char)Data[i]).ToString();
  1719. }
  1720. }));
  1721. }
  1722. break;
  1723. }
  1724. case 0xA710://自定义2
  1725. {
  1726. unchecked
  1727. {
  1728. this.Invoke((EventHandler)(delegate
  1729. {
  1730. textBox_User2.Text = "";
  1731. for (ushort i = 0; i < 16; i++)
  1732. {
  1733. if (Data[i] == 0x2E)
  1734. {
  1735. break;
  1736. }
  1737. textBox_User2.Text += ((char)Data[i]).ToString();
  1738. }
  1739. }));
  1740. }
  1741. break;
  1742. }
  1743. case 0xA810://自定义1
  1744. {
  1745. unchecked
  1746. {
  1747. this.Invoke((EventHandler)(delegate
  1748. {
  1749. textBox_User3.Text = "";
  1750. for (ushort i = 0; i < 16; i++)
  1751. {
  1752. if (Data[i] == 0x2E)
  1753. {
  1754. break;
  1755. }
  1756. textBox_User3.Text += ((char)Data[i]).ToString();
  1757. }
  1758. }));
  1759. }
  1760. break;
  1761. }
  1762. case 0xA520://生产信息
  1763. {
  1764. unchecked
  1765. {
  1766. this.Invoke((EventHandler)(delegate
  1767. {
  1768. //生产商
  1769. textBox_MAC.Text = "";
  1770. for (ushort i = 0; i < 8; i++)
  1771. {
  1772. if (Data[i] == 0x2E)
  1773. {
  1774. break;
  1775. }
  1776. textBox_MAC.Text += ((char)Data[i]).ToString();
  1777. }
  1778. //生产地
  1779. textBox_MACAdd.Text = "";
  1780. for (ushort i = 0; i < 8; i++)
  1781. {
  1782. if (Data[8 + i] == 0x2E)
  1783. {
  1784. break;
  1785. }
  1786. textBox_MACAdd.Text += ((char)Data[8 + i]).ToString();
  1787. }
  1788. //生产日期
  1789. textBox_MACDate.Text = "";
  1790. for (ushort i = 0; i < 8; i++)
  1791. {
  1792. if (Data[16 + i] == 0x2E)
  1793. {
  1794. break;
  1795. }
  1796. textBox_MACDate.Text += ((char)Data[16 + i]).ToString();
  1797. }
  1798. //品牌信息
  1799. textBox_PP.Text = "";
  1800. for (ushort i = 0; i < 8; i++)
  1801. {
  1802. if (Data[24 + i] == 0x2E)
  1803. {
  1804. break;
  1805. }
  1806. textBox_PP.Text += ((char)Data[24 + i]).ToString();
  1807. }
  1808. }));
  1809. }
  1810. break;
  1811. }
  1812. case 0xA408://密钥
  1813. {
  1814. unchecked
  1815. {
  1816. this.Invoke((EventHandler)(delegate
  1817. {
  1818. textBox_Key.Text = "";
  1819. for (ushort i = 0; i < 8; i++)
  1820. {
  1821. textBox_Key.Text += ((char)Data[i]).ToString();
  1822. }
  1823. }));
  1824. }
  1825. break;
  1826. }
  1827. case 0xAB09://存储器数据
  1828. case 0xAB0A:
  1829. case 0xAB0B:
  1830. case 0xAB0C:
  1831. {
  1832. unchecked
  1833. {
  1834. this.Invoke((EventHandler)(delegate
  1835. {
  1836. long ByteNum = 0;
  1837. ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
  1838. if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
  1839. {
  1840. for (int i = 0; i < ByteNum; i++)
  1841. {
  1842. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  1843. }
  1844. }
  1845. else //根据设置自动转换10进制显示
  1846. {
  1847. if (checkBox_ReadRanFlash_ChangeFormat.Checked == true) //10进制显示
  1848. {
  1849. switch (ByteNum)
  1850. {
  1851. case 1:
  1852. {
  1853. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8]) + ", ");
  1854. break;
  1855. }
  1856. case 2:
  1857. {
  1858. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8)) + ", ");
  1859. break;
  1860. }
  1861. case 3:
  1862. {
  1863. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16)) + ", ");
  1864. break;
  1865. }
  1866. case 4:
  1867. {
  1868. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24)) + ", ");
  1869. break;
  1870. }
  1871. default:
  1872. {
  1873. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  1874. break;
  1875. }
  1876. }
  1877. }
  1878. else //16进制显示
  1879. {
  1880. switch (ByteNum)
  1881. {
  1882. case 1:
  1883. {
  1884. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8], 16).PadLeft(2, '0').ToUpper() + ", ");
  1885. break;
  1886. }
  1887. case 2:
  1888. {
  1889. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8), 16).PadLeft(4, '0').ToUpper() + ", ");
  1890. break;
  1891. }
  1892. case 3:
  1893. {
  1894. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16), 16).PadLeft(6, '0').ToUpper() + ", ");
  1895. break;
  1896. }
  1897. case 4:
  1898. {
  1899. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24), 16).PadLeft(8, '0').ToUpper() + ", ");
  1900. break;
  1901. }
  1902. default:
  1903. {
  1904. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  1905. break;
  1906. }
  1907. }
  1908. }
  1909. }
  1910. }));
  1911. }
  1912. break;
  1913. }
  1914. case 0xAB88://故障日志
  1915. {
  1916. unchecked
  1917. {
  1918. this.Invoke((EventHandler)(delegate
  1919. {
  1920. //电机存储的故障日志,一包128字节包含2条故障日志
  1921. var ErrorLogSaveInfo1 = new MC_ErrorLogSaveInfo_Struct_t();
  1922. var ErrorLogSaveInfo2 = new MC_ErrorLogSaveInfo_Struct_t();
  1923. ErrorLogSaveInfo1 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 8);
  1924. ErrorLogSaveInfo2 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 72);
  1925. //数据显示
  1926. ErrorLogDisplay(ErrorLogSaveInfo1, ErrorLogSaveInfo2);
  1927. }));
  1928. }
  1929. break;
  1930. }
  1931. case 0x1401://在线检测结果
  1932. {
  1933. unchecked
  1934. {
  1935. this.Invoke((EventHandler)(delegate
  1936. {
  1937. textBox_Online.Text = Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() + "H";
  1938. }));
  1939. }
  1940. break;
  1941. }
  1942. case 0x1510://骑行历史信息
  1943. {
  1944. unchecked
  1945. {
  1946. this.Invoke((EventHandler)(delegate
  1947. {
  1948. long DataTemp32;
  1949. //ODO里程
  1950. DataTemp32 = (long)((Data[3] << 24) + (Data[2] << 16) + (Data[1] << 8) + Data[0]);
  1951. textBox_OBC_ODO_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  1952. textBox_ODO_KM.Text = DataTemp32.ToString();
  1953. //ODO时间
  1954. DataTemp32 = (long)((Data[7] << 24) + (Data[6] << 16) + (Data[5] << 8) + Data[4]);
  1955. if (DataTemp32 >= 60 * 100000)
  1956. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  1957. else
  1958. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  1959. textBox_ODO_TIME.Text = DataTemp32.ToString();
  1960. //TRIP里程
  1961. DataTemp32 = (long)((Data[11] << 24) + (Data[10] << 16) + (Data[9] << 8) + Data[8]);
  1962. textBox_OBC_TRIP_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  1963. textBox_TRIP_KM.Text = DataTemp32.ToString();
  1964. //TRIP时间
  1965. DataTemp32 = (long)((Data[15] << 24) + (Data[14] << 16) + (Data[13] << 8) + Data[12]);
  1966. if (DataTemp32 >= 60 * 100000)
  1967. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  1968. else
  1969. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  1970. textBox_TRIP_TIME.Text = DataTemp32.ToString();
  1971. }));
  1972. }
  1973. break;
  1974. }
  1975. case 0x1720://客户信息
  1976. {
  1977. unchecked
  1978. {
  1979. this.Invoke((EventHandler)(delegate
  1980. {
  1981. //软件标识
  1982. textBox_SP.Text = "";
  1983. textBox_OBC_ReadSP.Text = "";
  1984. textBox_FacModeSP.Text = "";
  1985. for (ushort i = 0; i < 23; i++)
  1986. {
  1987. if (Data[i] == 'r')
  1988. {
  1989. Data[i] = (byte)'.';
  1990. }
  1991. textBox_SP.Text += ((char)Data[i]).ToString();
  1992. textBox_OBC_ReadSP.Text += ((char)Data[i]).ToString();
  1993. textBox_FacModeSP.Text += ((char)Data[i]).ToString();
  1994. }
  1995. //Git提交版本信息
  1996. textBox_FacModeGit.Text = "";
  1997. for (ushort i = 0; i < 9; i++)
  1998. {
  1999. textBox_SP.Text += ((char)Data[23 + i]).ToString();
  2000. textBox_FacModeGit.Text += ((char)Data[23 + i]).ToString();
  2001. }
  2002. Class_Motor_Ver.Special = textBox_SP.Text;
  2003. }));
  2004. }
  2005. break;
  2006. }
  2007. case 0xBA20: //调试信息
  2008. {
  2009. unchecked
  2010. {
  2011. this.Invoke((EventHandler)(delegate
  2012. {
  2013. MC_DebugInfo_Refresh = true;
  2014. //系统状态机
  2015. DataTemp = (short)(Data[0]);
  2016. textBox_DebugInfo_SysFun.Text = Convert.ToString(DataTemp);
  2017. //二层状态机
  2018. DataTemp = (short)(Data[1]);
  2019. textBox_DebugInfo_SecondFun.Text = Convert.ToString(DataTemp);
  2020. //电机状态机
  2021. DataTemp = (short)(Data[2]);
  2022. textBox_DebugInfo_MotorFun.Text = Convert.ToString(DataTemp);
  2023. //助力状态机
  2024. DataTemp = (short)(Data[3]);
  2025. textBox_DebugInfo_AssistFun.Text = Convert.ToString(DataTemp);
  2026. //IdRef
  2027. DataTemp = (short)(Data[5] * 256 + Data[4]);
  2028. textBox_DebugInfo_IdRef.Text = Convert.ToString(DataTemp);
  2029. //IqRef
  2030. DataTemp = (short)(Data[7] * 256 + Data[6]);
  2031. textBox_DebugInfo_IqRef.Text = Convert.ToString(DataTemp);
  2032. //UdRef
  2033. DataTemp = (short)(Data[9] * 256 + Data[8]);
  2034. textBox_DebugInfo_UdRef.Text = Convert.ToString(DataTemp);
  2035. //UqRef
  2036. DataTemp = (short)(Data[11] * 256 + Data[10]);
  2037. textBox_DebugInfo_UqRef.Text = Convert.ToString(DataTemp);
  2038. //瞬时力矩
  2039. DataTemp = (short)(Data[13] * 256 + Data[12]);
  2040. textBox_DebugInfo_TorquePu.Text = Convert.ToString(DataTemp);
  2041. //时间滤波力矩
  2042. DataTemp = (short)(Data[15] * 256 + Data[14]);
  2043. textBox_DebugInfo_TorqueFil.Text = Convert.ToString(DataTemp);
  2044. //踏频滤波力矩
  2045. DataTemp = (short)(Data[17] * 256 + Data[16]);
  2046. textBox_DebugInfo_TorqueCadence.Text = Convert.ToString(DataTemp);
  2047. //IdFdb
  2048. DataTemp = (short)(Data[19] * 256 + Data[18]);
  2049. textBox_DebugInfo_IdFdb.Text = Convert.ToString(DataTemp);
  2050. //IqFdb
  2051. DataTemp = (short)(Data[21] * 256 + Data[20]);
  2052. textBox_DebugInfo_IqFdb.Text = Convert.ToString(DataTemp);
  2053. //助力输出
  2054. DataTemp = (short)(Data[23] * 256 + Data[22]);
  2055. textBox_DebugInfo_AssistOut.Text = Convert.ToString(DataTemp);
  2056. //转把百分比
  2057. DataTemp = (short)(Data[25] * 256 + Data[24]);
  2058. textBox_DebugInfo_ThrottlePer.Text = Convert.ToString(DataTemp);
  2059. //数据保存
  2060. RunInfoAutoSave();
  2061. }));
  2062. }
  2063. break;
  2064. }
  2065. case 0xBB20: //产品标签信息
  2066. {
  2067. unchecked
  2068. {
  2069. this.Invoke((EventHandler)(delegate
  2070. {
  2071. //产品标签
  2072. textBox_TagInfo.Text = "";
  2073. for (ushort i = 0; i < 32; i++)
  2074. {
  2075. textBox_TagInfo.Text += ((char)Data[i]).ToString();
  2076. }
  2077. }));
  2078. }
  2079. break;
  2080. }
  2081. case 0xBC20: //内阻校正信息
  2082. {
  2083. unchecked
  2084. {
  2085. this.Invoke((EventHandler)(delegate
  2086. {
  2087. //内阻1
  2088. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  2089. textBox_MOS_R1.Text = Convert.ToString(uData16);
  2090. //内阻2
  2091. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  2092. textBox_MOS_R2.Text = Convert.ToString(uData16);
  2093. //内阻3
  2094. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  2095. textBox_MOS_R3.Text = Convert.ToString(uData16);
  2096. //K1
  2097. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  2098. textBox_MOS_K1.Text = Convert.ToString(uData16);
  2099. //K2
  2100. uData16 = (ushort)(Data[9] * 256 + Data[8]);
  2101. textBox_MOS_K2.Text = Convert.ToString(uData16);
  2102. //K3
  2103. uData16 = (ushort)(Data[11] * 256 + Data[10]);
  2104. textBox_MOS_K3.Text = Convert.ToString(uData16);
  2105. //K4
  2106. uData16 = (ushort)(Data[13] * 256 + Data[12]);
  2107. textBox_MOS_K4.Text = Convert.ToString(uData16);
  2108. //K5
  2109. uData16 = (ushort)(Data[15] * 256 + Data[14]);
  2110. textBox_MOS_K5.Text = Convert.ToString(uData16);
  2111. }));
  2112. }
  2113. break;
  2114. }
  2115. case 0xBD20: //整车信息2
  2116. {
  2117. unchecked
  2118. {
  2119. this.Invoke((EventHandler)(delegate
  2120. {
  2121. richTextBox_BikeParam2.Clear();
  2122. for (int i = 0; i < myParams.BikeParam2.Count; i++)
  2123. {
  2124. richTextBox_BikeParam2.AppendText(myParams.BikeParam2[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  2125. }
  2126. richTextBox_BikeParam2.Text = richTextBox_BikeParam2.Text.Substring(0, richTextBox_BikeParam2.Text.Length - 2);
  2127. }));
  2128. }
  2129. break;
  2130. }
  2131. case 0xBE20: //用户骑行参数
  2132. {
  2133. unchecked
  2134. {
  2135. this.Invoke((EventHandler)(delegate
  2136. {
  2137. richTextBox_UsrRidesParam.Clear();
  2138. for (int i = 0; i < myParams.UsrRideParam.Count; i++)
  2139. {
  2140. richTextBox_UsrRidesParam.AppendText(myParams.UsrRideParam[i] + "=" + Convert.ToString(Data[i]) + ", ");
  2141. }
  2142. richTextBox_UsrRidesParam.Text = richTextBox_UsrRidesParam.Text.Substring(0, richTextBox_UsrRidesParam.Text.Length - 2);
  2143. }));
  2144. }
  2145. break;
  2146. }
  2147. case 0xBF58:
  2148. {
  2149. unchecked
  2150. {
  2151. this.Invoke((EventHandler)(delegate
  2152. {
  2153. string[] str1 = new string[42];
  2154. double[] error1 = new double[42];
  2155. //更新校准数据
  2156. for (int i = 0; i < 42; i++)
  2157. {
  2158. double data1 = (Data[4 + i * 2] + (Data[4 + i * 2 + 1] << 8)) / 32767.0 * 360;
  2159. error1[i] = data1 - (60 * (i % 6) + 60);
  2160. if (error1[i] < -180)
  2161. {
  2162. error1[i] = error1[i] + 360;
  2163. }
  2164. str1[i] = data1.ToString("F2");
  2165. AngledataRecord[i] = str1[i];
  2166. }
  2167. for (int i = 0; i < 7; i++)
  2168. for (int j = 0; j < 6; j++)
  2169. {
  2170. dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = str1[6 * i + j];
  2171. }
  2172. //计算偏差最小值、最大值和平均值
  2173. //Array.ConvertAll(error1, Math.Abs);
  2174. textBox_AngleDiffMin.Text = error1.Min().ToString("F2");
  2175. textBox_AngleDiffMax.Text = error1.Max().ToString("F2");
  2176. textBox_AngleDiffAvg.Text = error1.Average().ToString("F2");
  2177. //计算零点偏差
  2178. double tmp1 = ((Int16)(Data[0] + (Data[1] << 8))) / 32767.0 * 360;
  2179. textBox_AngleZeroInit.Text = tmp1.ToString("F2");
  2180. double tmp2 = ((Int16)(Data[2] + (Data[3] << 8))) / 32767.0 * 360;
  2181. textBox_AngleZeroCur.Text = tmp2.ToString("F2");
  2182. double tmp3 = (tmp2 - tmp1);
  2183. textBox_AngleZeroDiff.Text = tmp3.ToString("F2");
  2184. }));
  2185. }
  2186. break;
  2187. }
  2188. case 0xC109: //Boot版本信息
  2189. {
  2190. BootInfo = "";
  2191. for (ushort i = 0; i < 9; i++)
  2192. {
  2193. BootInfo += ((char)Data[i]).ToString();
  2194. }
  2195. break;
  2196. }
  2197. default:
  2198. {
  2199. break;
  2200. }
  2201. }
  2202. //存储器导出数据显示
  2203. if ((CmdTemp & 0xFF00) == 0xAB00)
  2204. {
  2205. unchecked
  2206. {
  2207. this.Invoke((EventHandler)(delegate
  2208. {
  2209. long ByteNum = 0;
  2210. ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
  2211. if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
  2212. {
  2213. for (int i = 0; i < ByteNum; i++)
  2214. {
  2215. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  2216. }
  2217. }
  2218. }));
  2219. }
  2220. }
  2221. }
  2222. #endregion
  2223. #region 解析BMS广播的命令
  2224. else if (ID == 0x720)
  2225. {
  2226. switch (CmdTemp)
  2227. {
  2228. case 0x1010://BMS运行信息
  2229. {
  2230. unchecked
  2231. {
  2232. this.Invoke((EventHandler)(delegate
  2233. {
  2234. BMS_RunInfo_Refresh = true;
  2235. richTextBox_OBC_BMS_RunInfo.Clear();
  2236. //电压
  2237. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  2238. richTextBox_OBC_BMS_RunInfo.AppendText("电压:" + Convert.ToString(uData16) + " mV" + "\r\n");
  2239. //电流
  2240. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  2241. richTextBox_OBC_BMS_RunInfo.AppendText("电流:" + Convert.ToString(uData16) + " mA" + "\r\n");
  2242. //剩余容量
  2243. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  2244. richTextBox_OBC_BMS_RunInfo.AppendText("剩余容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  2245. //满充容量
  2246. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  2247. richTextBox_OBC_BMS_RunInfo.AppendText("满充容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  2248. //电芯温度
  2249. richTextBox_OBC_BMS_RunInfo.AppendText("电芯温度:" + Convert.ToString((int)(Data[8] - 40) + " ℃" + "\r\n"));
  2250. //剩余电量
  2251. richTextBox_OBC_BMS_RunInfo.AppendText("剩余电量:" + Convert.ToString(Data[9]) + " %" + "\r\n");
  2252. //电池状态
  2253. richTextBox_OBC_BMS_RunInfo.AppendText("电池状态:" + Convert.ToString(Data[10], 16).PadLeft(2, '0').ToUpper() + " H" + "\r\n");
  2254. //SOH
  2255. richTextBox_OBC_BMS_RunInfo.AppendText("电池寿命:" + Convert.ToString(Data[11]) + " %" + "\r\n");
  2256. //循环次数
  2257. richTextBox_OBC_BMS_RunInfo.AppendText("循环次数:" + Convert.ToString((ushort)(Data[13] * 256 + Data[12])) + " 次");
  2258. }));
  2259. }
  2260. break;
  2261. }
  2262. default: break;
  2263. }
  2264. }
  2265. #endregion
  2266. #region 解析电机发送OBC的命令
  2267. else if (ID == 0x713)
  2268. {
  2269. switch (CmdTemp)
  2270. {
  2271. case 0x5408://电机用户参数
  2272. {
  2273. unchecked
  2274. {
  2275. this.Invoke((EventHandler)(delegate
  2276. {
  2277. richTextBox_OBC_ReadUserInfo.Clear();
  2278. //默认周长
  2279. richTextBox_OBC_ReadUserInfo.AppendText("默认周长:" + Convert.ToString((int)Data[0]) + " cm" + "\r\n");
  2280. //启动模式
  2281. richTextBox_OBC_ReadUserInfo.AppendText("启动模式:" + ((Data[1] == 0x01) ? "柔和" : (Data[1] == 0x02) ? "正常" : (Data[1] == 0x03) ? "强劲" : "无效") + "\r\n");
  2282. comboBox_OBC_StartMode.SelectedIndex = Data[1] - 1;
  2283. //限速
  2284. richTextBox_OBC_ReadUserInfo.AppendText("限速:" + Convert.ToString(Data[2]) + " km/h" + "\r\n");
  2285. //周长微调
  2286. numericUpDown_OBC_WheelAdj.Value = (int)(Data[3] > 128 ? (Data[3] - 256) : Data[3]);
  2287. richTextBox_OBC_ReadUserInfo.AppendText("周长微调:" + Convert.ToString(numericUpDown_OBC_WheelAdj.Value) + " cm" + "\r\n");
  2288. //助力方案
  2289. richTextBox_OBC_ReadUserInfo.AppendText("助力方案:" + Convert.ToString(Data[4]) + "\r\n");
  2290. comboBox_OBC_AssistFunc.SelectedIndex = Data[4] - 1;
  2291. //关机时间
  2292. richTextBox_OBC_ReadUserInfo.AppendText("关机时间:" + Convert.ToString(Data[5]) + " min" + "\r\n");
  2293. numericUpDown_OBC_OffTime.Value = (int)Data[5];
  2294. //限速微调
  2295. numericUpDown_OBC_SpeedLimitAdj.Value = (int)(Data[6] > 128 ? (Data[6] - 256) : Data[6]);
  2296. richTextBox_OBC_ReadUserInfo.AppendText("限速微调:" + Convert.ToString(numericUpDown_OBC_SpeedLimitAdj.Value) + " km/h" + "\r\n");
  2297. //定速巡航
  2298. comboBox_OBC_BikeCCS.SelectedIndex = (Data[7] == 0xAA) ? 1 : 2;
  2299. richTextBox_OBC_ReadUserInfo.AppendText("转把巡航:" + comboBox_OBC_BikeCCS.Text + "\r\n");
  2300. }));
  2301. }
  2302. break;
  2303. }
  2304. case 0x5303://电机应答反馈
  2305. {
  2306. unchecked
  2307. {
  2308. this.Invoke((EventHandler)(delegate
  2309. {
  2310. timer_500ms.Enabled = false;
  2311. MessageBoxTimeOut.Show("OK", "反馈指令", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  2312. timer_500ms.Enabled = true;
  2313. }));
  2314. }
  2315. break;
  2316. }
  2317. case 0x5620: //用户骑行参数
  2318. {
  2319. unchecked
  2320. {
  2321. this.Invoke((EventHandler)(delegate
  2322. {
  2323. richTextBox_UsrRidesParam.Clear();
  2324. for (int i = 0; i < myParams.UsrRideParam.Count; i++)
  2325. {
  2326. richTextBox_UsrRidesParam.AppendText(myParams.UsrRideParam[i] + "=" + Convert.ToString(Data[i]) + ", ");
  2327. }
  2328. richTextBox_UsrRidesParam.Text = richTextBox_UsrRidesParam.Text.Substring(0, richTextBox_UsrRidesParam.Text.Length - 2);
  2329. }));
  2330. }
  2331. break;
  2332. }
  2333. default: break;
  2334. }
  2335. }
  2336. #endregion
  2337. }
  2338. private void DataRevToString(ushort CmdTemp, byte[] Data)
  2339. {
  2340. CmdRevStrTemp = "";
  2341. CmdRevStrTemp += Convert.ToString(CmdTemp >> 8, 16).PadLeft(2, '0').ToUpper() + " ";
  2342. CmdRevStrTemp += Convert.ToString(CmdTemp & 0xFF, 16).PadLeft(2, '0').ToUpper() + " ";
  2343. ushort len = (ushort)(CmdTemp & 0x00FF);
  2344. for (int i = 0; i < len ; i++)
  2345. {
  2346. CmdRevStrTemp += Convert.ToString(Data[i], 16).PadLeft(2, '0').ToUpper() + " ";
  2347. }
  2348. }
  2349. #endregion
  2350. /// <summary>
  2351. /// 端口连接或断开
  2352. /// </summary>
  2353. private void PortConnect()
  2354. {
  2355. bool result = false;
  2356. if (连接ToolStripMenuItem.Text == "连接")
  2357. {
  2358. result = mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, 连接开机ToolStripMenuItem.Checked, 识别通讯盒ToolStripMenuItem.Checked);
  2359. if (result)
  2360. {
  2361. toolStripComboBox_ComNum.Enabled = false;
  2362. toolStripComboBox_Baudrate.Enabled = false;
  2363. 刷新ToolStripMenuItem.Enabled = false;
  2364. 连接ToolStripMenuItem.Text = "断开";
  2365. 连接ToolStripMenuItem.Checked = true;
  2366. label_COM_Sta.Text = toolStripComboBox_ComNum.Text + "已连接," + toolStripComboBox_Baudrate.Text;
  2367. label_PortStatus.BackColor = Color.Green;
  2368. }
  2369. }
  2370. else if (连接ToolStripMenuItem.Text == "断开")
  2371. {
  2372. checkBox_OBC_StartSetGearSt.Checked = false;
  2373. checkBox_OBC_StartReadBMS.Checked = false;
  2374. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2375. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  2376. toolStripComboBox_ComNum.Enabled = true;
  2377. toolStripComboBox_Baudrate.Enabled = true;
  2378. 刷新ToolStripMenuItem.Enabled = true;
  2379. 连接ToolStripMenuItem.Text = "连接";
  2380. 连接ToolStripMenuItem.Checked = false;
  2381. label_COM_Sta.Text = "连接状态:未连接";
  2382. label_PortStatus.BackColor = Color.Red;
  2383. }
  2384. }
  2385. /// <summary>
  2386. /// 端口连接事件
  2387. /// </summary>
  2388. /// <param name="sender"></param>
  2389. /// <param name="e"></param>
  2390. private void 连接ToolStripMenuItem_Click(object sender, System.EventArgs e)
  2391. {
  2392. PortConnect();
  2393. }
  2394. /// <summary>
  2395. /// 端口号刷新事件
  2396. /// </summary>
  2397. /// <param name="sender"></param>
  2398. /// <param name="e"></param>
  2399. private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
  2400. {
  2401. toolStripComboBox_ComNum.Items.Clear();
  2402. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  2403. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
  2404. }
  2405. /// <summary>
  2406. /// 存储标志修改事件
  2407. /// </summary>
  2408. /// <param name="sender"></param>
  2409. /// <param name="e"></param>
  2410. private void 写入存储ToolStripMenuItem_Click(object sender, EventArgs e)
  2411. {
  2412. if (写入存储ToolStripMenuItem.Checked)
  2413. {
  2414. EnterForm1.ShowDialog();
  2415. try
  2416. {
  2417. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  2418. {
  2419. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  2420. {
  2421. 写入存储ToolStripMenuItem.Checked = false;
  2422. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  2423. }
  2424. else
  2425. {
  2426. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2427. }
  2428. }
  2429. else
  2430. {
  2431. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2432. }
  2433. }
  2434. catch (Exception)
  2435. {
  2436. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2437. }
  2438. }
  2439. else
  2440. {
  2441. 写入存储ToolStripMenuItem.Checked = true;
  2442. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  2443. }
  2444. }
  2445. /// <summary>
  2446. /// 1s定时器
  2447. /// </summary>
  2448. /// <param name="sender"></param>
  2449. /// <param name="e"></param>
  2450. private void timer_1s_Tick(object sender, EventArgs e)
  2451. {
  2452. //时间更新
  2453. label_SystemTime.Text = "系统时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2454. //MC_Runinfo超时清除
  2455. if (MC_RunInfo_Refresh == false)
  2456. {
  2457. MC_RunInfo_Refresh_Cnt++;
  2458. if (MC_RunInfo_Refresh_Cnt > 10)//5s
  2459. {
  2460. MC_RunInfo_Clear();
  2461. MC_RunInfo_Refresh_Cnt = 0;
  2462. }
  2463. }
  2464. else
  2465. {
  2466. MC_RunInfo_Refresh_Cnt = 0;
  2467. }
  2468. MC_RunInfo_Refresh = false;
  2469. //MC_Debuginfo超时清除
  2470. if (MC_DebugInfo_Refresh == false)
  2471. {
  2472. MC_DebugInfo_Refresh_Cnt++;
  2473. if (MC_DebugInfo_Refresh_Cnt > 10)//5s
  2474. {
  2475. MC_DebugInfo_Clear();
  2476. MC_DebugInfo_Refresh_Cnt = 0;
  2477. }
  2478. }
  2479. else
  2480. {
  2481. MC_DebugInfo_Refresh_Cnt = 0;
  2482. }
  2483. MC_DebugInfo_Refresh = false;
  2484. //BMS_RunInfo超时清除
  2485. if (BMS_RunInfo_Refresh == false)
  2486. {
  2487. BMS_RunInfo_Refresh_Cnt++;
  2488. if (BMS_RunInfo_Refresh_Cnt > 10)//5s
  2489. {
  2490. richTextBox_OBC_BMS_RunInfo.Clear();
  2491. BMS_RunInfo_Refresh_Cnt = 0;
  2492. }
  2493. }
  2494. else
  2495. {
  2496. BMS_RunInfo_Refresh_Cnt = 0;
  2497. }
  2498. BMS_RunInfo_Refresh = false;
  2499. //故障码超时清除
  2500. if (MC_ErrorCode_Refresh == false)
  2501. {
  2502. MC_ErrorCode_Refresh_Cnt++;
  2503. if (MC_ErrorCode_Refresh_Cnt > 10)//5s
  2504. {
  2505. textBox_ErrorCode.Text = "---";
  2506. MC_ErrorCode_Refresh_Cnt = 0;
  2507. }
  2508. }
  2509. else
  2510. {
  2511. MC_ErrorCode_Refresh_Cnt = 0;
  2512. }
  2513. MC_ErrorCode_Refresh = false;
  2514. //CDL连接超时
  2515. if (识别通讯盒ToolStripMenuItem.Checked)
  2516. {
  2517. if (mySerialProcess.CDL_Online_Flag == false)
  2518. {
  2519. mySerialProcess.CDL_OnlineCheck_Cnt++;
  2520. if (mySerialProcess.CDL_OnlineCheck_Cnt > 1)//1s
  2521. {
  2522. timer_500ms.Enabled = false;
  2523. MessageBox.Show("连接失败!", "提示");
  2524. timer_500ms.Enabled = true;
  2525. //关闭串口
  2526. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  2527. toolStripComboBox_ComNum.Enabled = true;
  2528. toolStripComboBox_Baudrate.Enabled = true;
  2529. 刷新ToolStripMenuItem.Enabled = true;
  2530. 连接ToolStripMenuItem.Text = "连接";
  2531. 连接ToolStripMenuItem.Checked = false;
  2532. label_COM_Sta.Text = "连接状态:未连接";
  2533. label_PortStatus.BackColor = Color.Red;
  2534. }
  2535. }
  2536. }
  2537. //OBC定时发送设置档位
  2538. if (checkBox_OBC_StartSetGearSt.Checked == true)
  2539. {
  2540. var CtrlCode = new byte[2];
  2541. if (comboBox_OBC_SetGearST.SelectedIndex == 5)//档位
  2542. CtrlCode[0] = 0x33;
  2543. else if (comboBox_OBC_SetGearST.SelectedIndex == 6)//档位
  2544. CtrlCode[0] = 0x22;
  2545. else
  2546. CtrlCode[0] = (byte)comboBox_OBC_SetGearST.SelectedIndex;
  2547. if (comboBox_OBC_LightSw.SelectedIndex == 0)//车灯
  2548. CtrlCode[1] = 0xF1;
  2549. else
  2550. CtrlCode[1] = 0xF0;
  2551. if (!mySerialProcess.SendCmdWithoutNotice((ushort)0x731, (byte)0x0C, (ushort)0x3002, CtrlCode))
  2552. {
  2553. checkBox_OBC_StartSetGearSt.Checked = false;
  2554. }
  2555. }
  2556. //OBC定时发送查询电池
  2557. if (checkBox_OBC_StartReadBMS.Checked == true)
  2558. {
  2559. if (!mySerialProcess.SendCmd((ushort)0x732, (byte)0x11, (ushort)0x5000, null))
  2560. {
  2561. checkBox_OBC_StartReadBMS.Checked = false;
  2562. }
  2563. }
  2564. //定时读取存储器
  2565. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  2566. {
  2567. var Address = new byte[4];
  2568. UInt32 Address_Begin;
  2569. UInt32 Addres_End;
  2570. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  2571. richTextBox_RamFlasgData.Clear();
  2572. do
  2573. {
  2574. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  2575. {
  2576. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2577. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2578. continue;
  2579. }
  2580. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  2581. {
  2582. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2583. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2584. continue;
  2585. }
  2586. else
  2587. {
  2588. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  2589. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2590. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  2591. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2592. if (Addres_End < Address_Begin)
  2593. {
  2594. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2595. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2596. continue;
  2597. }
  2598. else
  2599. {
  2600. var SendByte = new byte[8];
  2601. SendByte[0] = (byte)(Address_Begin >> 24);
  2602. SendByte[1] = (byte)(Address_Begin >> 16);
  2603. SendByte[2] = (byte)(Address_Begin >> 8);
  2604. SendByte[3] = (byte)(Address_Begin);
  2605. SendByte[4] = (byte)(Addres_End >> 24);
  2606. SendByte[5] = (byte)(Addres_End >> 16);
  2607. SendByte[6] = (byte)(Addres_End >> 8);
  2608. SendByte[7] = (byte)(Addres_End);
  2609. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte))
  2610. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2611. }
  2612. }
  2613. } while (false);
  2614. }
  2615. //写入参数等待计时
  2616. ACK_WaitCnt++;
  2617. }
  2618. /// <summary>
  2619. /// 运行信息清除
  2620. /// </summary>
  2621. private void MC_RunInfo_Clear()
  2622. {
  2623. foreach (Control c in tabPage_RunInfo.Controls)
  2624. {
  2625. if ((c is TextBox))
  2626. {
  2627. if (c.Name != textBox_ErrorCode.ToString())
  2628. c.Text = "---";
  2629. }
  2630. }
  2631. }
  2632. /// <summary>
  2633. /// 调试信息清除
  2634. /// </summary>
  2635. private void MC_DebugInfo_Clear()
  2636. {
  2637. foreach (Control c in tabPage_DebugInfo.Controls)
  2638. {
  2639. if ((c is TextBox))
  2640. {
  2641. if (c.Name != textBox_ErrorCode.ToString())
  2642. c.Text = "---";
  2643. }
  2644. }
  2645. }
  2646. /// <summary>
  2647. /// 读取马达参数
  2648. /// </summary>
  2649. /// <param name="sender"></param>
  2650. /// <param name="e"></param>
  2651. private void button_Read_MotorParam_Click(object sender, EventArgs e)
  2652. {
  2653. richTextBox_MotorParam.Clear();
  2654. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null);
  2655. }
  2656. /// <summary>
  2657. /// 写入马达参数
  2658. /// </summary>
  2659. /// <param name="sender"></param>
  2660. /// <param name="e"></param>
  2661. private void button_Write_Click(object sender, EventArgs e)
  2662. {
  2663. var ConfigParam = new byte[40];
  2664. for (int i = 0; i < 40; i++)
  2665. ConfigParam[i] = 0;
  2666. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2667. short wDataTemp = 0;
  2668. ushort DataTemp = 0;
  2669. string[] strDataTemp = richTextBox_MotorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2670. try
  2671. {
  2672. for (int i = 0; i < strDataTemp.Length; i++)
  2673. {
  2674. if (i == 6)
  2675. {
  2676. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  2677. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  2678. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  2679. }
  2680. else
  2681. {
  2682. DataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2683. ConfigParam[2 * i + 2] = (byte)DataTemp;
  2684. ConfigParam[2 * i + 3] = (byte)(DataTemp >> 8);
  2685. }
  2686. }
  2687. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B28, ConfigParam);
  2688. }
  2689. catch (Exception)
  2690. {
  2691. timer_500ms.Enabled = false;
  2692. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2693. timer_500ms.Enabled = true;
  2694. }
  2695. }
  2696. /// <summary>
  2697. /// 读取整车信息
  2698. /// </summary>
  2699. /// <param name="sender"></param>
  2700. /// <param name="e"></param>
  2701. private void button_ReadBikeParam_Click(object sender, EventArgs e)
  2702. {
  2703. richTextBox_BikeParam.Clear();
  2704. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null);
  2705. }
  2706. /// <summary>
  2707. /// 写入整车信息
  2708. /// </summary>
  2709. /// <param name="sender"></param>
  2710. /// <param name="e"></param>
  2711. private void button_WriteBikeParam_Click(object sender, EventArgs e)
  2712. {
  2713. var ConfigParam = new byte[28];
  2714. for (int i = 0; i < 28; i++)
  2715. ConfigParam[i] = 0;
  2716. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2717. string[] strDataTemp = richTextBox_BikeParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2718. try
  2719. {
  2720. for (int i = 0; i < strDataTemp.Length; i++)
  2721. {
  2722. short wDataTemp = 0;
  2723. //前后灯参数修改
  2724. if (i == 8)
  2725. {
  2726. wDataTemp |= (short)((comboBox_TailLightMode.SelectedIndex + 1) << 12); //Bit15~Bit12:尾灯模式
  2727. wDataTemp |= (short)((comboBox_TailLightVol.SelectedIndex == 0 ? 6 : 12) << 8); //Bit11~Bit8:尾灯电压
  2728. wDataTemp |= (short)(comboBox_FrontLightVol.SelectedIndex == 0 ? 6 : 12); //Bit7~Bit0:前灯电压
  2729. }
  2730. //开关机参数
  2731. else if (i == 11)
  2732. {
  2733. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOnDelay.Text) << 12);
  2734. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOffDelay.Text) << 8);
  2735. wDataTemp |= (short)(Convert.ToInt16(textBox_AutoPowerOff.Text));
  2736. }
  2737. else
  2738. {
  2739. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  2740. }
  2741. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  2742. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  2743. }
  2744. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D1C, ConfigParam);
  2745. }
  2746. catch (Exception)
  2747. {
  2748. timer_500ms.Enabled = false;
  2749. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2750. timer_500ms.Enabled = true;
  2751. }
  2752. }
  2753. /// <summary>
  2754. /// 读取控制器参数
  2755. /// </summary>
  2756. /// <param name="sender"></param>
  2757. /// <param name="e"></param>
  2758. private void button_ReadControlParam_Click(object sender, EventArgs e)
  2759. {
  2760. richTextBox_ControlParam.Clear();
  2761. comboBox_Bike_CCS.SelectedIndex = 0;
  2762. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
  2763. }
  2764. /// <summary>
  2765. /// 写入控制器参数
  2766. /// </summary>
  2767. /// <param name="sender"></param>
  2768. /// <param name="e"></param>
  2769. private void button_WriteControlParam_Click(object sender, EventArgs e)
  2770. {
  2771. var ConfigParam = new byte[34];
  2772. for (int i = 0; i < 34; i++)
  2773. ConfigParam[i] = 0;
  2774. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2775. ushort uwDataTemp = 0;
  2776. string[] strDataTemp = richTextBox_ControlParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2777. try
  2778. {
  2779. for (int i = 0; i < strDataTemp.Length; i++)
  2780. {
  2781. if (i == 13)
  2782. {
  2783. uwDataTemp = (comboBox_Bike_CCS.SelectedIndex == 1) ? (ushort)0x00AA : (ushort)0x0000;
  2784. }
  2785. else
  2786. {
  2787. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2788. }
  2789. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2790. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2791. }
  2792. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3F22, ConfigParam);
  2793. }
  2794. catch (Exception)
  2795. {
  2796. timer_500ms.Enabled = false;
  2797. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2798. timer_500ms.Enabled = true;
  2799. }
  2800. }
  2801. /// <summary>
  2802. /// 读取助力参数
  2803. /// </summary>
  2804. /// <param name="sender"></param>
  2805. /// <param name="e"></param>
  2806. private void button_ReadAssistParam_Click(object sender, EventArgs e)
  2807. {
  2808. var ConfigParam = new byte[4];
  2809. int AssistNum = 0;
  2810. try
  2811. {
  2812. AssistNum = Convert.ToInt32(comboBox_AssistTorque.Text);
  2813. ConfigParam[0] = (byte)(AssistNum & 0xFF);
  2814. ConfigParam[1] = (byte)(AssistNum >> 8);
  2815. AssistNum = Convert.ToInt32(comboBox_AssistCadence.Text);
  2816. ConfigParam[2] = (byte)(AssistNum & 0xFF);
  2817. ConfigParam[3] = (byte)(AssistNum >> 8);
  2818. richTextBox_AssistParam.Clear();
  2819. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam);
  2820. }
  2821. catch (Exception)
  2822. {
  2823. timer_500ms.Enabled = false;
  2824. MessageBox.Show("请选择助力参数编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2825. timer_500ms.Enabled = true;
  2826. }
  2827. }
  2828. /// <summary>
  2829. /// 写入助力参数
  2830. /// </summary>
  2831. /// <param name="sender"></param>
  2832. /// <param name="e"></param>
  2833. private void button_WriteAssistParam_Click(object sender, EventArgs e)
  2834. {
  2835. var ConfigParam = new byte[80];
  2836. for (int i = 0; i < 80; i++)
  2837. ConfigParam[i] = 0;
  2838. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2839. long lDataTemp = 0;
  2840. string[] strDataTemp = richTextBox_AssistParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2841. int index_1 = 0, index_2 = 0;
  2842. try
  2843. {
  2844. for (int i = 0; i < strDataTemp.Length; i++)
  2845. {
  2846. if (strDataTemp[i].Split('=')[0] == "转矩曲线.a")
  2847. {
  2848. index_1 = i;
  2849. break;
  2850. }
  2851. }
  2852. for (int i = 0; i < strDataTemp.Length; i++)
  2853. {
  2854. if (strDataTemp[i].Split('=')[0] == "踏频曲线.d")
  2855. {
  2856. index_2 = i;
  2857. break;
  2858. }
  2859. }
  2860. for (int i = 0; i < strDataTemp.Length; i++)
  2861. {
  2862. lDataTemp = Convert.ToInt32(strDataTemp[i].Split('=')[1]);
  2863. if (i < index_1)
  2864. {
  2865. ConfigParam[2 * i + 4] = (byte)lDataTemp;
  2866. ConfigParam[2 * i + 5] = (byte)(lDataTemp >> 8);
  2867. }
  2868. else if (i <= index_2)
  2869. {
  2870. ConfigParam[4 * i - 4] = (byte)lDataTemp;
  2871. ConfigParam[4 * i - 3] = (byte)(lDataTemp >> 8);
  2872. ConfigParam[4 * i - 2] = (byte)(lDataTemp >> 16);
  2873. ConfigParam[4 * i - 1] = (byte)(lDataTemp >> 24);
  2874. }
  2875. else
  2876. {
  2877. ConfigParam[2 * i + 20] = (byte)lDataTemp;
  2878. ConfigParam[2 * i + 21] = (byte)(lDataTemp >> 8);
  2879. }
  2880. }
  2881. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4450, 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_ReadDebugParam_Click(object sender, EventArgs e)
  2896. {
  2897. richTextBox_DebugParam.Clear();
  2898. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  2899. }
  2900. /// <summary>
  2901. /// 写入调试参数
  2902. /// </summary>
  2903. /// <param name="sender"></param>
  2904. /// <param name="e"></param>
  2905. private void button_WriteDebugParam_Click(object sender, EventArgs e)
  2906. {
  2907. var ConfigParam = new byte[60];
  2908. for (int i = 0; i < 60; i++)
  2909. ConfigParam[i] = 0;
  2910. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2911. ushort uwDataTemp = 0;
  2912. string[] strDataTemp = richTextBox_DebugParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2913. try
  2914. {
  2915. for (int i = 0; i < strDataTemp.Length; i++)
  2916. {
  2917. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2918. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2919. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2920. }
  2921. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam);
  2922. }
  2923. catch (Exception)
  2924. {
  2925. timer_500ms.Enabled = false;
  2926. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2927. timer_500ms.Enabled = true;
  2928. }
  2929. }
  2930. /// <summary>
  2931. /// 读取历史
  2932. /// </summary>
  2933. /// <param name="sender"></param>
  2934. /// <param name="e"></param>
  2935. private void button_ReadRecord_Click(object sender, EventArgs e)
  2936. {
  2937. richTextBox_Record.Clear();
  2938. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null);
  2939. }
  2940. /// <summary>
  2941. /// 读取传感器参数
  2942. /// </summary>
  2943. /// <param name="sender"></param>
  2944. /// <param name="e"></param>
  2945. private void button_ReadSensorParam_Click(object sender, EventArgs e)
  2946. {
  2947. richTextBox_SensorParam.Clear();
  2948. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  2949. }
  2950. /// <summary>
  2951. /// 写入力矩传感器标定值
  2952. /// </summary>
  2953. /// <param name="sender"></param>
  2954. /// <param name="e"></param>
  2955. private void button_Write_Cal_Click(object sender, EventArgs e)
  2956. {
  2957. var ConfigParam = new byte[4];
  2958. for (int i = 0; i < 4; i++)
  2959. ConfigParam[i] = 0;
  2960. ushort uwDataTemp = 0;
  2961. try
  2962. {
  2963. uwDataTemp = Convert.ToUInt16(comboBox_TorqueSet.Text);//负载序号
  2964. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  2965. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  2966. uwDataTemp = (ushort)(decimal.Parse(textBox_Load.Text) * 10); ;//负载值0.1Nm
  2967. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  2968. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  2969. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  2970. }
  2971. catch (Exception)
  2972. {
  2973. timer_500ms.Enabled = false;
  2974. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2975. timer_500ms.Enabled = true;
  2976. }
  2977. }
  2978. /// <summary>
  2979. /// 写入传感器参数
  2980. /// </summary>
  2981. /// <param name="sender"></param>
  2982. /// <param name="e"></param>
  2983. private void button_WriteSensorParam_Click(object sender, EventArgs e)
  2984. {
  2985. var ConfigParam = new byte[14];
  2986. for (int i = 0; i < 14; i++)
  2987. ConfigParam[i] = 0;
  2988. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2989. ushort uwDataTemp = 0;
  2990. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  2991. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2992. int index = 0;
  2993. try
  2994. {
  2995. for (int i = 0; i < strDataTemp.Length; i++)
  2996. {
  2997. if (strDataTemp[i].Split('=')[0] == "力矩传感器踏频脉冲数")
  2998. {
  2999. index = i;
  3000. break;
  3001. }
  3002. }
  3003. for (int i = 0; i < (strDataTemp.Length - index); i++)
  3004. {
  3005. uwDataTemp = Convert.ToUInt16(strDataTemp[i + index].Split('=')[1]);
  3006. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3007. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3008. }
  3009. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x420E, ConfigParam);
  3010. }
  3011. catch (Exception)
  3012. {
  3013. timer_500ms.Enabled = false;
  3014. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3015. timer_500ms.Enabled = true;
  3016. }
  3017. }
  3018. /// <summary>
  3019. /// 写入型号
  3020. /// </summary>
  3021. /// <param name="sender"></param>
  3022. /// <param name="e"></param>
  3023. private void button_WriteModel_Click(object sender, EventArgs e)
  3024. {
  3025. string Mode = textBox_Model.Text;
  3026. var ModeArray = new byte[16];
  3027. for (ushort i = 0; i < Mode.Length; i++)
  3028. {
  3029. ModeArray[i] = (byte)Mode[i];
  3030. }
  3031. if (Mode.Length < 16)
  3032. {
  3033. ModeArray[Mode.Length] = (byte)'.';
  3034. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  3035. {
  3036. ModeArray[Mode.Length + 1 + i] = 0x20;
  3037. }
  3038. }
  3039. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  3040. }
  3041. /// <summary>
  3042. /// 写入SN
  3043. /// </summary>
  3044. /// <param name="sender"></param>
  3045. /// <param name="e"></param>
  3046. private void button_WriteSN_Click(object sender, EventArgs e)
  3047. {
  3048. string SN = textBox_SN.Text;
  3049. var SNArray = new byte[16];
  3050. for (ushort i = 0; i < SN.Length; i++)
  3051. {
  3052. SNArray[i] = (byte)SN[i];
  3053. }
  3054. if (SN.Length < 16)
  3055. {
  3056. SNArray[SN.Length] = (byte)'.';
  3057. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  3058. {
  3059. SNArray[SN.Length + 1 + i] = 0x20;
  3060. }
  3061. }
  3062. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  3063. }
  3064. /// <summary>
  3065. /// 查询版本信息
  3066. /// </summary>
  3067. /// <param name="sender"></param>
  3068. /// <param name="e"></param>
  3069. private void button_ReadVersion_Click(object sender, EventArgs e)
  3070. {
  3071. textBox_Model.Text = "---";
  3072. textBox_SN.Text = "---";
  3073. textBox_HW.Text = "---";
  3074. textBox_FW.Text = "---";
  3075. textBox_SP.Text = "---";
  3076. textBox_OBC_ReadModel.Text = "---";
  3077. textBox_OBC_ReadSN.Text = "---";
  3078. textBox_OBC_ReadHW.Text = "---";
  3079. textBox_OBC_ReadFW.Text = "---";
  3080. textBox_OBC_ReadSP.Text = "---";
  3081. textBox_FacModeName.Text = "---";
  3082. textBox_FacModeNum.Text = "---";
  3083. textBox_FacModeHW.Text = "---";
  3084. textBox_FacModeFW.Text = "---";
  3085. textBox_FacModeSP.Text = "---";
  3086. Class_Motor_Ver.Mode = "---";
  3087. Class_Motor_Ver.SN = "---";
  3088. Class_Motor_Ver.HW = "---";
  3089. Class_Motor_Ver.FW = "---";
  3090. Class_Motor_Ver.Special = "---";
  3091. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  3092. }
  3093. /// <summary>
  3094. /// 查询自定义1
  3095. /// </summary>
  3096. /// <param name="sender"></param>
  3097. /// <param name="e"></param>
  3098. private void button_ReadUser1_Click(object sender, EventArgs e)
  3099. {
  3100. textBox_User1.Text = "---";
  3101. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null);
  3102. }
  3103. /// <summary>
  3104. /// 查询自定义2
  3105. /// </summary>
  3106. /// <param name="sender"></param>
  3107. /// <param name="e"></param>
  3108. private void button_ReadUser2_Click(object sender, EventArgs e)
  3109. {
  3110. textBox_User2.Text = "---";
  3111. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null);
  3112. }
  3113. /// <summary>
  3114. /// 查询自定义3
  3115. /// </summary>
  3116. /// <param name="sender"></param>
  3117. /// <param name="e"></param>
  3118. private void button_ReadUser3_Click(object sender, EventArgs e)
  3119. {
  3120. textBox_User3.Text = "---";
  3121. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null);
  3122. }
  3123. /// <summary>
  3124. /// 写入自定义字符串1
  3125. /// </summary>
  3126. /// <param name="sender"></param>
  3127. /// <param name="e"></param>
  3128. private void button_WriteUser1_Click(object sender, EventArgs e)
  3129. {
  3130. string User = textBox_User1.Text;
  3131. var UserArray = new byte[16];
  3132. for (ushort i = 0; i < User.Length; i++)
  3133. {
  3134. UserArray[i] = (byte)User[i];
  3135. }
  3136. if (User.Length < 16)
  3137. {
  3138. UserArray[User.Length] = (byte)'.';
  3139. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3140. {
  3141. UserArray[User.Length + 1 + i] = 0x20;
  3142. }
  3143. }
  3144. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1410, UserArray);
  3145. }
  3146. /// <summary>
  3147. /// 写入自定义字符串2
  3148. /// </summary>
  3149. /// <param name="sender"></param>
  3150. /// <param name="e"></param>
  3151. private void button_WriteUser2_Click(object sender, EventArgs e)
  3152. {
  3153. string User = textBox_User2.Text;
  3154. var UserArray = new byte[16];
  3155. for (ushort i = 0; i < User.Length; i++)
  3156. {
  3157. UserArray[i] = (byte)User[i];
  3158. }
  3159. if (User.Length < 16)
  3160. {
  3161. UserArray[User.Length] = (byte)'.';
  3162. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3163. {
  3164. UserArray[User.Length + 1 + i] = 0x20;
  3165. }
  3166. }
  3167. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1610, UserArray);
  3168. }
  3169. /// <summary>
  3170. /// 写入自定义字符串3
  3171. /// </summary>
  3172. /// <param name="sender"></param>
  3173. /// <param name="e"></param>
  3174. private void button_WriteUser3_Click(object sender, EventArgs e)
  3175. {
  3176. string User = textBox_User3.Text;
  3177. var UserArray = new byte[16];
  3178. for (ushort i = 0; i < User.Length; i++)
  3179. {
  3180. UserArray[i] = (byte)User[i];
  3181. }
  3182. if (User.Length < 16)
  3183. {
  3184. UserArray[User.Length] = (byte)'.';
  3185. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3186. {
  3187. UserArray[User.Length + 1 + i] = 0x20;
  3188. }
  3189. }
  3190. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1810, UserArray);
  3191. }
  3192. /// <summary>
  3193. /// 查询生产信息
  3194. /// </summary>
  3195. /// <param name="sender"></param>
  3196. /// <param name="e"></param>
  3197. private void button_ReadMAC_Click(object sender, EventArgs e)
  3198. {
  3199. textBox_MAC.Text = "---";
  3200. textBox_MACAdd.Text = "---";
  3201. textBox_MACDate.Text = "---";
  3202. textBox_PP.Text = "---";
  3203. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null);
  3204. }
  3205. /// <summary>
  3206. /// 写入生产信息
  3207. /// </summary>
  3208. /// <param name="sender"></param>
  3209. /// <param name="e"></param>
  3210. private void button_WriteMac_Click(object sender, EventArgs e)
  3211. {
  3212. var MACArray = new byte[32];
  3213. //填入生产商
  3214. for (ushort i = 0; i < textBox_MAC.Text.Length; i++)
  3215. {
  3216. MACArray[i] = (byte)textBox_MAC.Text[i];
  3217. }
  3218. if (textBox_MAC.Text.Length < 8)
  3219. {
  3220. MACArray[textBox_MAC.Text.Length] = (byte)'.';
  3221. for (ushort i = 0; i < 8 - textBox_MAC.Text.Length - 1; i++)
  3222. {
  3223. MACArray[textBox_MAC.Text.Length + 1 + i] = 0x20;
  3224. }
  3225. }
  3226. //填入生产地
  3227. for (ushort i = 0; i < textBox_MACAdd.Text.Length; i++)
  3228. {
  3229. MACArray[8 + i] = (byte)textBox_MACAdd.Text[i];
  3230. }
  3231. if (textBox_MACAdd.Text.Length < 8)
  3232. {
  3233. MACArray[textBox_MACAdd.Text.Length + 8] = (byte)'.';
  3234. for (ushort i = 0; i < 8 - textBox_MACAdd.Text.Length - 1; i++)
  3235. {
  3236. MACArray[textBox_MACAdd.Text.Length + 1 + i + 8] = 0x20;
  3237. }
  3238. }
  3239. //填入生产日期
  3240. for (ushort i = 0; i < textBox_MACDate.Text.Length; i++)
  3241. {
  3242. MACArray[16 + i] = (byte)textBox_MACDate.Text[i];
  3243. }
  3244. if (textBox_MACDate.Text.Length < 8)
  3245. {
  3246. MACArray[textBox_MACDate.Text.Length + 16] = (byte)'.';
  3247. for (ushort i = 0; i < 8 - textBox_MACDate.Text.Length - 1; i++)
  3248. {
  3249. MACArray[textBox_MACDate.Text.Length + 1 + i + 16] = 0x20;
  3250. }
  3251. }
  3252. //填入品牌
  3253. for (ushort i = 0; i < textBox_PP.Text.Length; i++)
  3254. {
  3255. MACArray[24 + i] = (byte)textBox_PP.Text[i];
  3256. }
  3257. if (textBox_PP.Text.Length < 8)
  3258. {
  3259. MACArray[textBox_PP.Text.Length + 24] = (byte)'.';
  3260. for (ushort i = 0; i < 8 - textBox_PP.Text.Length - 1; i++)
  3261. {
  3262. MACArray[textBox_PP.Text.Length + 1 + i + 24] = 0x20;
  3263. }
  3264. }
  3265. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  3266. }
  3267. /// <summary>
  3268. /// 查询密钥
  3269. /// </summary>
  3270. /// <param name="sender"></param>
  3271. /// <param name="e"></param>
  3272. private void button_ReadKey_Click(object sender, EventArgs e)
  3273. {
  3274. textBox_Key.Text = "---";
  3275. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null);
  3276. }
  3277. /// <summary>
  3278. /// 写入校验密钥
  3279. /// </summary>
  3280. /// <param name="sender"></param>
  3281. /// <param name="e"></param>
  3282. private void button_WriteKey_Click(object sender, EventArgs e)
  3283. {
  3284. string Key = textBox_Key.Text;
  3285. var KeyArray = new byte[8];
  3286. if (Key.Length != 8)
  3287. {
  3288. timer_500ms.Enabled = false;
  3289. MessageBox.Show("请检查字符长度是否为8", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3290. timer_500ms.Enabled = true;
  3291. return;
  3292. }
  3293. for (ushort i = 0; i < Key.Length; i++)
  3294. {
  3295. KeyArray[i] = (byte)Key[i];
  3296. }
  3297. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1108, KeyArray);
  3298. }
  3299. /// <summary>
  3300. /// 查询在线检测结果
  3301. /// </summary>
  3302. /// <param name="sender"></param>
  3303. /// <param name="e"></param>
  3304. private void button_ReadOnLine_Click(object sender, EventArgs e)
  3305. {
  3306. textBox_Online.Text = "---";
  3307. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2100, null);
  3308. }
  3309. /// <summary>
  3310. /// 系统清除
  3311. /// </summary>
  3312. /// <param name="sender"></param>
  3313. /// <param name="e"></param>
  3314. private void button_SystemClear_Click(object sender, EventArgs e)
  3315. {
  3316. var Code = new byte[5];
  3317. Code[0] = (byte)'C';
  3318. Code[1] = (byte)'L';
  3319. Code[2] = (byte)'E';
  3320. Code[3] = (byte)'A';
  3321. Code[4] = (byte)'R';
  3322. timer_500ms.Enabled = false;
  3323. if (MessageBox.Show("系统清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3324. {
  3325. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3326. {
  3327. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3328. {
  3329. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  3330. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3331. }
  3332. }
  3333. }
  3334. timer_500ms.Enabled = true;
  3335. }
  3336. /// <summary>
  3337. /// 参数还原
  3338. /// </summary>
  3339. /// <param name="sender"></param>
  3340. /// <param name="e"></param>
  3341. private void button_Recovery_Click(object sender, EventArgs e)
  3342. {
  3343. var Code = new byte[8];
  3344. Code[0] = (byte)'R';
  3345. Code[1] = (byte)'E';
  3346. Code[2] = (byte)'C';
  3347. Code[3] = (byte)'O';
  3348. Code[4] = (byte)'V';
  3349. Code[5] = (byte)'E';
  3350. Code[6] = (byte)'R';
  3351. Code[7] = (byte)'Y';
  3352. timer_500ms.Enabled = false;
  3353. if (MessageBox.Show("参数还原后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3354. {
  3355. if (MessageBox.Show("请再次确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3356. {
  3357. if (MessageBox.Show("请最后确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3358. {
  3359. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2708, Code);
  3360. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3361. }
  3362. }
  3363. }
  3364. timer_500ms.Enabled = true;
  3365. }
  3366. /// <summary>
  3367. /// 系统复位
  3368. /// </summary>
  3369. /// <param name="sender"></param>
  3370. /// <param name="e"></param>
  3371. private void button_Reset_Click(object sender, EventArgs e)
  3372. {
  3373. var Code_Off = new byte[5];
  3374. var Code_Reset = new byte[5];
  3375. Code_Off[0] = (byte)'O';
  3376. Code_Off[1] = (byte)'F';
  3377. Code_Off[2] = (byte)'F';
  3378. Code_Off[3] = (byte)'.';
  3379. Code_Off[4] = (byte)'.';
  3380. Code_Reset[0] = (byte)'R';
  3381. Code_Reset[1] = (byte)'E';
  3382. Code_Reset[2] = (byte)'S';
  3383. Code_Reset[3] = (byte)'E';
  3384. Code_Reset[4] = (byte)'T';
  3385. timer_500ms.Enabled = false;
  3386. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3387. {
  3388. timer_500ms.Enabled = true;
  3389. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  3390. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  3391. PowerOffAckStatus = false;
  3392. Delay_ms(250);
  3393. int TryCnt = 3;
  3394. while ((TryCnt--) >= 0)
  3395. {
  3396. if (!PowerOffAckStatus)
  3397. {
  3398. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  3399. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  3400. PowerOffAckStatus = false;
  3401. Delay_ms(250);
  3402. }
  3403. else break;
  3404. }
  3405. if (PowerOffAckStatus)
  3406. {
  3407. timer_500ms.Enabled = false;
  3408. MessageBoxTimeOut.Show("已关机!", "提示", 3000, MessageBoxButtons.OK, MessageBoxIcon.None);
  3409. timer_500ms.Enabled = true;
  3410. }
  3411. else
  3412. {
  3413. timer_500ms.Enabled = false;
  3414. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3415. timer_500ms.Enabled = true;
  3416. }
  3417. }
  3418. timer_500ms.Enabled = true;
  3419. }
  3420. /// <summary>
  3421. /// 记录清除
  3422. /// </summary>
  3423. /// <param name="sender"></param>
  3424. /// <param name="e"></param>
  3425. private void button_ClearLog_Click(object sender, EventArgs e)
  3426. {
  3427. var Code = new byte[9];
  3428. Code[0] = (byte)'L';
  3429. Code[1] = (byte)'O';
  3430. Code[2] = (byte)'G';
  3431. Code[3] = (byte)' ';
  3432. Code[4] = (byte)'C';
  3433. Code[5] = (byte)'L';
  3434. Code[6] = (byte)'E';
  3435. Code[7] = (byte)'A';
  3436. Code[8] = (byte)'R';
  3437. timer_500ms.Enabled = false;
  3438. if (MessageBox.Show("历史记录信息清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3439. {
  3440. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3441. {
  3442. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3443. {
  3444. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3909, Code);
  3445. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3446. }
  3447. }
  3448. }
  3449. timer_500ms.Enabled = true;
  3450. }
  3451. /// <summary>
  3452. /// 打开系统计算器
  3453. /// </summary>
  3454. /// <param name="sender"></param>
  3455. /// <param name="e"></param>
  3456. private void 计算器ToolStripMenuItem_Click(object sender, EventArgs e)
  3457. {
  3458. System.Diagnostics.Process.Start("calc.exe");
  3459. }
  3460. /// <summary>
  3461. ///故障转换和显示
  3462. /// </summary>
  3463. List<string> ErrorInfo = new List<string>{ "过流保护", "低压保护", "过压保护", "堵转保护","过热保护","速度传感器故障","力矩传感器故障","霍尔故障",
  3464. "马达缺相","NTC故障","BMS校验失败","","OBC校验失败","MCU故障","踏频传感器故障","指拨故障","MOS短路","电压异常","","","","","","","","","","","","",
  3465. "",""};
  3466. private string ErrorInfoDisplay(UInt32 Code)
  3467. {
  3468. string Result = "";
  3469. if (Code == 0)
  3470. {
  3471. Result = "无故障";
  3472. }
  3473. else
  3474. {
  3475. for (int i = 0; i < 32; i++)
  3476. {
  3477. if ((Code & 0x01) == 0x01)
  3478. {
  3479. Result += ErrorInfo[i] + " ";
  3480. }
  3481. Code >>= 1;
  3482. }
  3483. }
  3484. return Result;
  3485. }
  3486. /// <summary>
  3487. /// 鼠标滑过故障码显示具体内容
  3488. /// </summary>
  3489. /// <param name="sender"></param>
  3490. /// <param name="e"></param>
  3491. private void textBox_ErrorCode_MouseHover(object sender, EventArgs e)
  3492. {
  3493. // 创建the ToolTip
  3494. ToolTip toolTip1 = new ToolTip();
  3495. // 设置显示样式
  3496. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  3497. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  3498. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  3499. toolTip1.ShowAlways = true;//是否显示提示框
  3500. // 设置伴随的对象.
  3501. string ErrorCode = this.textBox_ErrorCode.Text;
  3502. UInt32 Code = ErrorCode.Contains("H") ? Convert.ToUInt32(ErrorCode.Split('H')[0], 16) : 0;
  3503. toolTip1.SetToolTip(this.textBox_ErrorCode, ErrorInfoDisplay(Code));//设置故障内容显示
  3504. }
  3505. /// <summary>
  3506. /// 数据记录
  3507. /// </summary>
  3508. private void RunInfoAutoSave()
  3509. {
  3510. if (运行信息记录ToolStripMenuItem.Checked == true)
  3511. {
  3512. if (RunInfoSaveFilename == string.Empty)
  3513. {
  3514. return;
  3515. }
  3516. string SaveData = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff").Replace(" ", "_") + " --> ";
  3517. foreach (Control c in tabPage_RunInfo.Controls)
  3518. {
  3519. if (c is TextBox)
  3520. {
  3521. SaveData += c.Text + " , ";
  3522. }
  3523. }
  3524. foreach (Control c in tabPage_DebugInfo.Controls)
  3525. {
  3526. if (c is TextBox)
  3527. {
  3528. SaveData += c.Text + " , ";
  3529. }
  3530. }
  3531. SaveData += "\r\n";
  3532. System.IO.File.AppendAllText(RunInfoSaveFilename, SaveData);//sb.ToString());
  3533. }
  3534. }
  3535. /// <summary>
  3536. /// 打开或关闭数据记录
  3537. /// </summary>
  3538. /// <param name="sender"></param>
  3539. /// <param name="e"></param>
  3540. private void 记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  3541. {
  3542. if (运行信息记录ToolStripMenuItem.Checked == false)
  3543. {
  3544. if (mySerialProcess.mySerial.IsOpen == true)
  3545. {
  3546. RunInfoSaveFilename = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_运行信息" + ".txt";
  3547. System.IO.File.AppendAllText(RunInfoSaveFilename, "时间 --> 车速 , 转速 , 踏频 , 力矩Reg , 力矩 , 踩踏方向 , 电压 , 电流 , 功率 , 电量 , " +
  3548. "PCB温度 , 绕组温度 , MOS温度 , 挡位 , 灯开关 , 续航 , 平均功耗 , 单次里程 , 单次时间 , 故障码 , " +
  3549. "系统状态机 , 二层状态机 , 电机状态机 , 助力状态机 , D轴电流给定 , Q轴电流给定 , D轴电压给定 , Q轴电压给定 , 瞬时力矩 , 时间滤波力矩 , 踏频滤波力矩 , D轴电流反馈 , Q轴电流反馈 , 助力函数输出" + "\r\n");
  3550. timer_500ms.Enabled = false;
  3551. MessageBoxTimeOut.Show("开始记录", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  3552. timer_500ms.Enabled = true;
  3553. 运行信息记录ToolStripMenuItem.Checked = true;
  3554. }
  3555. else
  3556. {
  3557. timer_500ms.Enabled = false;
  3558. MessageBox.Show("请连接电机", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3559. timer_500ms.Enabled = true;
  3560. }
  3561. }
  3562. else
  3563. {
  3564. 运行信息记录ToolStripMenuItem.Checked = false;
  3565. timer_500ms.Enabled = false;
  3566. MessageBoxTimeOut.Show("停止记录", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  3567. timer_500ms.Enabled = true;
  3568. }
  3569. }
  3570. /// <summary>
  3571. /// 仪表启动控制档位开关事件
  3572. /// </summary>
  3573. /// <param name="sender"></param>
  3574. /// <param name="e"></param>
  3575. private void checkBox_OBC_StartSetGearSt_CheckedChanged(object sender, EventArgs e)
  3576. {
  3577. if (checkBox_OBC_StartSetGearSt.Checked == true)
  3578. {
  3579. //检查串口是否打开
  3580. if (!mySerialProcess.mySerial.IsOpen)
  3581. {
  3582. timer_500ms.Enabled = false;
  3583. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3584. timer_500ms.Enabled = true;
  3585. checkBox_OBC_StartSetGearSt.Checked = false;
  3586. return;
  3587. }
  3588. //检查是否选择档位和打开车灯
  3589. if ((comboBox_OBC_SetGearST.SelectedIndex == -1) || (comboBox_OBC_LightSw.SelectedIndex == -1))
  3590. {
  3591. timer_500ms.Enabled = false;
  3592. MessageBox.Show("请检查档位设置和大灯开关!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3593. timer_500ms.Enabled = true;
  3594. checkBox_OBC_StartSetGearSt.Checked = false;
  3595. return;
  3596. }
  3597. }
  3598. }
  3599. /// <summary>
  3600. /// OBC查询电机用户参数
  3601. /// </summary>
  3602. /// <param name="sender"></param>
  3603. /// <param name="e"></param>
  3604. private void button_OBC_ReadUserInfo_Click(object sender, EventArgs e)
  3605. {
  3606. richTextBox_OBC_ReadUserInfo.Clear();
  3607. comboBox_OBC_BikeCCS.SelectedIndex = 0;
  3608. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3300, null);
  3609. }
  3610. /// <summary>
  3611. /// OBC设置电机用户参数
  3612. /// </summary>
  3613. /// <param name="sender"></param>
  3614. /// <param name="e"></param>
  3615. private void button_OBC_WriteUserInfo_Click(object sender, EventArgs e)
  3616. {
  3617. var UserInfoCode = new byte[8];
  3618. for (int i = 0; i < UserInfoCode.Length; i++)
  3619. UserInfoCode[i] = 0;
  3620. if (comboBox_OBC_StartMode.SelectedIndex == -1)//检查数据有效性
  3621. {
  3622. timer_500ms.Enabled = false;
  3623. MessageBox.Show("请选择启动模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3624. timer_500ms.Enabled = true;
  3625. return;
  3626. }
  3627. if (comboBox_OBC_AssistFunc.SelectedIndex == -1)//检查数据有效性
  3628. {
  3629. timer_500ms.Enabled = false;
  3630. MessageBox.Show("请选择助力方案!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3631. timer_500ms.Enabled = true;
  3632. return;
  3633. }
  3634. //周长微调
  3635. UserInfoCode[0] = (byte)(int)numericUpDown_OBC_WheelAdj.Value;
  3636. //启动模式
  3637. UserInfoCode[1] = (byte)(comboBox_OBC_StartMode.SelectedIndex + 1);
  3638. //助力方案
  3639. UserInfoCode[2] = (byte)(comboBox_OBC_AssistFunc.SelectedIndex + 1);
  3640. //自动关机时间
  3641. UserInfoCode[3] = (byte)(uint)numericUpDown_OBC_OffTime.Value;
  3642. //限速微调
  3643. UserInfoCode[4] = (byte)(int)numericUpDown_OBC_SpeedLimitAdj.Value;
  3644. //定速巡航开关
  3645. UserInfoCode[5] = (byte)((comboBox_OBC_BikeCCS.SelectedIndex == 1) ? 0xAA : 0x00);
  3646. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3408, UserInfoCode);
  3647. }
  3648. /// <summary>
  3649. /// OBC查询电机版本信息
  3650. /// </summary>
  3651. /// <param name="sender"></param>
  3652. /// <param name="e"></param>
  3653. private void button_OBC_ReadVerInfo_Click(object sender, EventArgs e)
  3654. {
  3655. textBox_Model.Text = "---";
  3656. textBox_SN.Text = "---";
  3657. textBox_HW.Text = "---";
  3658. textBox_FW.Text = "---";
  3659. textBox_SP.Text = "---";
  3660. textBox_OBC_ReadModel.Text = "---";
  3661. textBox_OBC_ReadSN.Text = "---";
  3662. textBox_OBC_ReadHW.Text = "---";
  3663. textBox_OBC_ReadFW.Text = "---";
  3664. textBox_OBC_ReadSP.Text = "---";
  3665. textBox_FacModeName.Text = "---";
  3666. textBox_FacModeNum.Text = "---";
  3667. textBox_FacModeHW.Text = "---";
  3668. textBox_FacModeFW.Text = "---";
  3669. textBox_FacModeSP.Text = "---";
  3670. Class_Motor_Ver.Mode = "---";
  3671. Class_Motor_Ver.SN = "---";
  3672. Class_Motor_Ver.HW = "---";
  3673. Class_Motor_Ver.FW = "---";
  3674. Class_Motor_Ver.Special = "---";
  3675. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  3676. }
  3677. /// <summary>
  3678. /// OBC读取骑行历史
  3679. /// </summary>
  3680. /// <param name="sender"></param>
  3681. /// <param name="e"></param>
  3682. private void button_OBC_ReadRideInfo_Click(object sender, EventArgs e)
  3683. {
  3684. textBox_OBC_TRIP_KM.Text = "";
  3685. textBox_OBC_TRIP_TIME.Text = "";
  3686. textBox_OBC_ODO_KM.Text = "";
  3687. textBox_OBC_ODO_TIME.Text = "";
  3688. textBox_ODO_KM.Text = "---";
  3689. textBox_ODO_TIME.Text = "---";
  3690. textBox_TRIP_KM.Text = "---";
  3691. textBox_TRIP_TIME.Text = "---";
  3692. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3500, null);
  3693. }
  3694. /// <summary>
  3695. /// OBC清除TRIP里程
  3696. /// </summary>
  3697. /// <param name="sender"></param>
  3698. /// <param name="e"></param>
  3699. private void button_OBC_ClearTrip_Click(object sender, EventArgs e)
  3700. {
  3701. var Code = new byte[5];
  3702. Code[0] = (byte)'C';
  3703. Code[1] = (byte)'L';
  3704. Code[2] = (byte)'E';
  3705. Code[3] = (byte)'A';
  3706. Code[4] = (byte)'R';
  3707. timer_500ms.Enabled = false;
  3708. if (MessageBox.Show("TRIP清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3709. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3605, Code);
  3710. timer_500ms.Enabled = true;
  3711. }
  3712. private void checkBox_OBC_StartReadBMS_CheckedChanged(object sender, EventArgs e)
  3713. {
  3714. if (checkBox_OBC_StartReadBMS.Checked == true)
  3715. {
  3716. //检查串口是否打开
  3717. if (!mySerialProcess.mySerial.IsOpen)
  3718. {
  3719. timer_500ms.Enabled = false;
  3720. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3721. timer_500ms.Enabled = true;
  3722. checkBox_OBC_StartReadBMS.Checked = false;
  3723. return;
  3724. }
  3725. }
  3726. }
  3727. /// <summary>
  3728. /// 写入力矩传感器参数
  3729. /// </summary>
  3730. /// <param name="sender"></param>
  3731. /// <param name="e"></param>
  3732. private void button_WriteTqSensorParam_Click(object sender, EventArgs e)
  3733. {
  3734. var ConfigParam = new byte[46];
  3735. for (int i = 0; i < 14; i++)
  3736. ConfigParam[i] = 0;
  3737. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  3738. ushort uwDataTemp = 0;
  3739. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  3740. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  3741. int index = 0;
  3742. try
  3743. {
  3744. for (int i = 0; i < strDataTemp.Length; i++)
  3745. {
  3746. if (strDataTemp[i].Split('=')[0] == "第四阶段转矩点采集值")
  3747. {
  3748. index = i;
  3749. break;
  3750. }
  3751. }
  3752. for (int i = 0; i < (index + 1); i++)
  3753. {
  3754. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  3755. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3756. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3757. }
  3758. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x472E, ConfigParam);
  3759. }
  3760. catch (Exception)
  3761. {
  3762. timer_500ms.Enabled = false;
  3763. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3764. timer_500ms.Enabled = true;
  3765. }
  3766. }
  3767. /// <summary>
  3768. /// 查询存储标志
  3769. /// </summary>
  3770. /// <param name="sender"></param>
  3771. /// <param name="e"></param>
  3772. private void button_ReadSaveFlag_Click(object sender, EventArgs e)
  3773. {
  3774. radioButton_EE_SaveYes.Checked = false;
  3775. radioButton_EE_SaveNo.Checked = false;
  3776. radioButton_SIP_SaveYes.Checked = false;
  3777. radioButton_SIP_SaveNo.Checked = false;
  3778. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null);
  3779. }
  3780. /// <summary>
  3781. /// 写入存储标志
  3782. /// </summary>
  3783. /// <param name="sender"></param>
  3784. /// <param name="e"></param>
  3785. private void button_WriteSaveFlag_Click(object sender, EventArgs e)
  3786. {
  3787. var SaveFlag = new byte[6];
  3788. for (int i = 0; i < 6; i++)
  3789. SaveFlag[i] = 0;
  3790. if ((radioButton_EE_SaveYes.Checked == false) && (radioButton_EE_SaveNo.Checked == false))
  3791. {
  3792. timer_500ms.Enabled = false;
  3793. MessageBox.Show("请选择EEPROM存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3794. timer_500ms.Enabled = true;
  3795. return;
  3796. }
  3797. if ((radioButton_SIP_SaveYes.Checked == false) && (radioButton_SIP_SaveNo.Checked == false))
  3798. {
  3799. timer_500ms.Enabled = false;
  3800. MessageBox.Show("请选择SIP校验存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3801. timer_500ms.Enabled = true;
  3802. return;
  3803. }
  3804. SaveFlag[0] = (byte)((checkBox_SaveYes.Checked) ? 0x01 : 0x00);
  3805. SaveFlag[2] = (byte)(radioButton_EE_SaveYes.Checked ? 0x01 : 0x00);
  3806. SaveFlag[3] = 0;
  3807. SaveFlag[4] = (byte)(radioButton_SIP_SaveYes.Checked ? 0x01 : 0x00);
  3808. SaveFlag[5] = 0;
  3809. timer_500ms.Enabled = false;
  3810. if (MessageBox.Show("确认修改存储标志?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3811. {
  3812. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4906, SaveFlag);
  3813. }
  3814. timer_500ms.Enabled = true;
  3815. }
  3816. /// <summary>
  3817. /// 读取指定地址数据
  3818. /// </summary>
  3819. /// <param name="sender"></param>
  3820. /// <param name="e"></param>
  3821. private void button_ReadRamFlash_Click(object sender, EventArgs e)
  3822. {
  3823. var Address = new byte[4];
  3824. UInt32 Address_Begin;
  3825. UInt32 Addres_End;
  3826. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  3827. richTextBox_RamFlasgData.Clear();
  3828. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  3829. {
  3830. timer_500ms.Enabled = false;
  3831. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3832. timer_500ms.Enabled = true;
  3833. return;
  3834. }
  3835. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  3836. {
  3837. timer_500ms.Enabled = false;
  3838. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3839. timer_500ms.Enabled = true;
  3840. return;
  3841. }
  3842. else
  3843. {
  3844. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  3845. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  3846. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  3847. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  3848. if (Addres_End < Address_Begin)
  3849. {
  3850. timer_500ms.Enabled = false;
  3851. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3852. timer_500ms.Enabled = true;
  3853. return;
  3854. }
  3855. else
  3856. {
  3857. var SendByte = new byte[8];
  3858. SendByte[0] = (byte)(Address_Begin >> 24);
  3859. SendByte[1] = (byte)(Address_Begin >> 16);
  3860. SendByte[2] = (byte)(Address_Begin >> 8);
  3861. SendByte[3] = (byte)(Address_Begin);
  3862. SendByte[4] = (byte)(Addres_End >> 24);
  3863. SendByte[5] = (byte)(Addres_End >> 16);
  3864. SendByte[6] = (byte)(Addres_End >> 8);
  3865. SendByte[7] = (byte)(Addres_End);
  3866. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  3867. }
  3868. }
  3869. }
  3870. /// <summary>
  3871. /// 工作模式选择
  3872. /// </summary>
  3873. /// <param name="sender"></param>
  3874. /// <param name="e"></param>
  3875. private void comboBox_WorkMode_SelectedIndexChanged(object sender, EventArgs e)
  3876. {
  3877. var RunMode = new byte[1];
  3878. if (comboBox_WorkMode.Text == "配置模式")
  3879. RunMode[0] = 0x01;
  3880. else if (comboBox_WorkMode.Text == "调试模式")
  3881. RunMode[0] = 0x02;
  3882. else
  3883. RunMode[0] = 0x00;
  3884. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  3885. }
  3886. /// <summary>
  3887. /// 助力档位选择
  3888. /// </summary>
  3889. /// <param name="sender"></param>
  3890. /// <param name="e"></param>
  3891. private void comboBox_GearSt_SelectedIndexChanged(object sender, EventArgs e)
  3892. {
  3893. var CtrlCode = new byte[2];
  3894. if (comboBox_GearSt.SelectedIndex == 5)//档位
  3895. CtrlCode[0] = 0x33;
  3896. else if (comboBox_GearSt.SelectedIndex == 6)//档位
  3897. CtrlCode[0] = 0x22;
  3898. else
  3899. CtrlCode[0] = (byte)comboBox_GearSt.SelectedIndex;
  3900. if (comboBox_LightSwitch.SelectedIndex == 0)//车灯
  3901. CtrlCode[1] = 0xF1;
  3902. else
  3903. CtrlCode[1] = 0xF0;
  3904. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
  3905. comboBox_OBC_SetGearST.SelectedIndex = comboBox_GearSt.SelectedIndex;
  3906. comboBox_OBC_LightSw.SelectedIndex = comboBox_LightSwitch.SelectedIndex;
  3907. Delay_ms(500);
  3908. //设置百分比
  3909. do
  3910. {
  3911. var PercentCode = new byte[1];
  3912. if (comboBox_GearSt.SelectedIndex == 0) //Off
  3913. {
  3914. PercentCode[0] = 0;
  3915. textBox_MotorSpeedPercent.Text = "0";
  3916. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, PercentCode);
  3917. }
  3918. else if (comboBox_GearSt.SelectedIndex == 6) //Walk
  3919. {
  3920. if (comboBox_WorkMode.SelectedIndex != 0)
  3921. {
  3922. PercentCode[0] = 100;
  3923. textBox_MotorSpeedPercent.Text = "100";
  3924. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, PercentCode);
  3925. }
  3926. }
  3927. } while (false);
  3928. }
  3929. /// <summary>
  3930. /// 仪表档位选择
  3931. /// </summary>
  3932. /// <param name="sender"></param>
  3933. /// <param name="e"></param>
  3934. private void comboBox_OBC_SetGearST_SelectedIndexChanged(object sender, EventArgs e)
  3935. {
  3936. comboBox_GearSt.SelectedIndex = comboBox_OBC_SetGearST.SelectedIndex;
  3937. comboBox_LightSwitch.SelectedIndex = comboBox_OBC_LightSw.SelectedIndex;
  3938. }
  3939. /// <summary>
  3940. /// 生产模式初始化
  3941. /// </summary>
  3942. /// <param name="sender"></param>
  3943. /// <param name="e"></param>
  3944. private void button_FacModeInit_Click(object sender, EventArgs e)
  3945. {
  3946. var Code = new byte[5];
  3947. Code[0] = (byte)'C';
  3948. Code[1] = (byte)'L';
  3949. Code[2] = (byte)'E';
  3950. Code[3] = (byte)'A';
  3951. Code[4] = (byte)'R';
  3952. timer_500ms.Enabled = false;
  3953. if (MessageBox.Show("电机即将初始化!", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3954. {
  3955. if (MessageBox.Show("请再次确认", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3956. {
  3957. timer_500ms.Enabled = true;
  3958. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  3959. PowerOffAckStatus = false;
  3960. Delay_ms(250);
  3961. int TryCnt = 3;
  3962. while ((TryCnt--) >= 0)
  3963. {
  3964. if (!PowerOffAckStatus)
  3965. {
  3966. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  3967. PowerOffAckStatus = false;
  3968. Delay_ms(250);
  3969. }
  3970. else break;
  3971. }
  3972. if (PowerOffAckStatus)
  3973. {
  3974. timer_500ms.Enabled = false;
  3975. MessageBox.Show("系统已关机,请保持无负载重新开机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  3976. timer_500ms.Enabled = true;
  3977. }
  3978. else
  3979. {
  3980. timer_500ms.Enabled = false;
  3981. MessageBox.Show("初始化失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3982. timer_500ms.Enabled = true;
  3983. }
  3984. timer_500ms.Enabled = true;
  3985. }
  3986. }
  3987. timer_500ms.Enabled = true;
  3988. //清除历史测试记录
  3989. textBox_FacModeSensorADC0.Text = "";
  3990. textBox_FacModeSensorADC1.Text = "";
  3991. textBox_FacModeSensorADC2.Text = "";
  3992. textBox_FacModeSensorADC3.Text = "";
  3993. textBox_FacModeSensorADC4.Text = "";
  3994. LightSwitchStatus = false;
  3995. MotorRunStatus = false;
  3996. textBox_MotorSpeedPercent.Text = "5";
  3997. textBox_FacModeName.Text = "";
  3998. textBox_FacModeNum.Text = "";
  3999. textBox_FacModeHW.Text = "";
  4000. textBox_FacModeFW.Text = "";
  4001. }
  4002. /// <summary>
  4003. /// 生产模式读取传感器参数
  4004. /// </summary>
  4005. /// <param name="sender"></param>
  4006. /// <param name="e"></param>
  4007. private void button_FacModeSensorRead_Click(object sender, EventArgs e)
  4008. {
  4009. richTextBox_SensorParam.Clear();
  4010. textBox_FacModeSensorADC0.Text = "";
  4011. textBox_FacModeSensorADC1.Text = "";
  4012. textBox_FacModeSensorADC2.Text = "";
  4013. textBox_FacModeSensorADC3.Text = "";
  4014. textBox_FacModeSensorADC4.Text = "";
  4015. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4016. }
  4017. /// <summary>
  4018. /// 生产模式传感器标定1
  4019. /// </summary>
  4020. /// <param name="sender"></param>
  4021. /// <param name="e"></param>
  4022. private void buttonFacModeSet1_Click(object sender, EventArgs e)
  4023. {
  4024. var ConfigParam = new byte[4];
  4025. for (int i = 0; i < 4; i++)
  4026. ConfigParam[i] = 0;
  4027. ushort uwDataTemp = 0;
  4028. try
  4029. {
  4030. uwDataTemp = 1;//负载序号
  4031. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4032. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4033. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal1.Text) * 10); ;//负载值0.1Nm
  4034. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4035. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4036. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4037. Delay_ms(200);
  4038. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4039. }
  4040. catch (Exception)
  4041. {
  4042. timer_500ms.Enabled = false;
  4043. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4044. timer_500ms.Enabled = true;
  4045. }
  4046. }
  4047. /// <summary>
  4048. /// 生产模式传感器标定2
  4049. /// </summary>
  4050. /// <param name="sender"></param>
  4051. /// <param name="e"></param>
  4052. private void buttonFacModeSet2_Click(object sender, EventArgs e)
  4053. {
  4054. var ConfigParam = new byte[4];
  4055. for (int i = 0; i < 4; i++)
  4056. ConfigParam[i] = 0;
  4057. ushort uwDataTemp = 0;
  4058. try
  4059. {
  4060. uwDataTemp = 2;//负载序号
  4061. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4062. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4063. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal2.Text) * 10); ;//负载值0.1Nm
  4064. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4065. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4066. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4067. Delay_ms(200);
  4068. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4069. }
  4070. catch (Exception)
  4071. {
  4072. timer_500ms.Enabled = false;
  4073. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4074. timer_500ms.Enabled = true;
  4075. }
  4076. }
  4077. /// <summary>
  4078. /// 生产模式传感器标定3
  4079. /// </summary>
  4080. /// <param name="sender"></param>
  4081. /// <param name="e"></param>
  4082. private void buttonFacModeSet3_Click(object sender, EventArgs e)
  4083. {
  4084. var ConfigParam = new byte[4];
  4085. for (int i = 0; i < 4; i++)
  4086. ConfigParam[i] = 0;
  4087. ushort uwDataTemp = 0;
  4088. try
  4089. {
  4090. uwDataTemp = 3;//负载序号
  4091. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4092. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4093. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal3.Text) * 10); ;//负载值0.1Nm
  4094. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4095. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4096. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4097. Delay_ms(200);
  4098. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4099. }
  4100. catch (Exception)
  4101. {
  4102. timer_500ms.Enabled = false;
  4103. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4104. timer_500ms.Enabled = true;
  4105. }
  4106. }
  4107. /// <summary>
  4108. /// 生产模式传感器标定3
  4109. /// </summary>
  4110. /// <param name="sender"></param>
  4111. /// <param name="e"></param>
  4112. private void buttonFacModeSet4_Click(object sender, EventArgs e)
  4113. {
  4114. var ConfigParam = new byte[4];
  4115. for (int i = 0; i < 4; i++)
  4116. ConfigParam[i] = 0;
  4117. ushort uwDataTemp = 0;
  4118. try
  4119. {
  4120. uwDataTemp = 4;//负载序号
  4121. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4122. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4123. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal4.Text) * 10); ;//负载值0.1Nm
  4124. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4125. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4126. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4127. Delay_ms(200);
  4128. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4129. }
  4130. catch (Exception)
  4131. {
  4132. timer_500ms.Enabled = false;
  4133. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4134. timer_500ms.Enabled = true;
  4135. }
  4136. }
  4137. /// <summary>
  4138. /// 生产模式开关灯
  4139. /// </summary>
  4140. /// <param name="sender"></param>
  4141. /// <param name="e"></param>
  4142. bool LightSwitchStatus = false;
  4143. private void button_FacModeLightSW_Click(object sender, EventArgs e)
  4144. {
  4145. var CtrlCode = new byte[2];
  4146. CtrlCode[0] = 0x00;
  4147. if (LightSwitchStatus)
  4148. {
  4149. CtrlCode[1] = 0xF0;
  4150. button_FacModeLightSW.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(128)))));
  4151. }
  4152. else
  4153. {
  4154. CtrlCode[1] = 0xF1;
  4155. button_FacModeLightSW.BackColor = Color.Yellow;
  4156. }
  4157. if (mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode))
  4158. {
  4159. LightSwitchStatus = !LightSwitchStatus;
  4160. comboBox_LightSwitch.SelectedIndex = LightSwitchStatus ? 0 : 1;
  4161. comboBox_OBC_LightSw.SelectedIndex = LightSwitchStatus ? 0 : 1;
  4162. }
  4163. }
  4164. /// <summary>
  4165. /// 生产模式电机控制
  4166. /// </summary>
  4167. /// <param name="sender"></param>
  4168. /// <param name="e"></param>
  4169. bool MotorRunStatus = false;
  4170. private void button_FacModeMotorRun_Click(object sender, EventArgs e)
  4171. {
  4172. string DebugDefaultInfo = "";
  4173. //获取调试信息
  4174. if (richTextBox_DebugParam.Text == string.Empty)
  4175. {
  4176. richTextBox_DebugParam.Clear();
  4177. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  4178. }
  4179. Delay_ms(200);
  4180. DebugDefaultInfo = richTextBox_DebugParam.Text;
  4181. //获取参数
  4182. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  4183. if (strDataTemp.Length != 29)
  4184. {
  4185. timer_500ms.Enabled = false;
  4186. MessageBox.Show("数据格式不正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4187. timer_500ms.Enabled = true;
  4188. return;
  4189. }
  4190. //设置参数
  4191. var ConfigParam = new byte[60];
  4192. for (int i = 0; i < 60; i++)
  4193. ConfigParam[i] = 0;
  4194. ConfigParam[0] = 0x00;
  4195. ushort uwDataTemp = 0;
  4196. if (!MotorRunStatus) //停止状态
  4197. {
  4198. //设置速度环
  4199. strDataTemp[0] = "整体运行模式=3";
  4200. //发送数据
  4201. try
  4202. {
  4203. for (int i = 0; i < strDataTemp.Length; i++)
  4204. {
  4205. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  4206. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  4207. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  4208. }
  4209. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  4210. return;
  4211. }
  4212. catch (Exception)
  4213. {
  4214. timer_500ms.Enabled = false;
  4215. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4216. timer_500ms.Enabled = true;
  4217. }
  4218. Delay_ms(200);
  4219. //设置转速百分比100%
  4220. textBox_MotorSpeedPercent.Text = "100";
  4221. ConfigParam[0] = (byte)100;
  4222. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, ConfigParam);
  4223. MotorRunStatus = !MotorRunStatus;
  4224. button_FacModeMotorRun.BackColor = Color.Yellow;
  4225. Delay_ms(200);
  4226. //电机进入配置模式
  4227. var RunMode = new byte[1];
  4228. RunMode[0] = 0x01;
  4229. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  4230. }
  4231. else //运转状态
  4232. {
  4233. //设置转速百分比0%
  4234. textBox_MotorSpeedPercent.Text = "0";
  4235. ConfigParam[0] = (byte)0;
  4236. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, ConfigParam);
  4237. MotorRunStatus = !MotorRunStatus;
  4238. button_FacModeMotorRun.BackColor = Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
  4239. Delay_ms(200);
  4240. //还原为原始值
  4241. strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  4242. try
  4243. {
  4244. for (int i = 0; i < strDataTemp.Length; i++)
  4245. {
  4246. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  4247. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  4248. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  4249. }
  4250. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  4251. return;
  4252. }
  4253. catch (Exception)
  4254. {
  4255. timer_500ms.Enabled = false;
  4256. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4257. timer_500ms.Enabled = true;
  4258. }
  4259. Delay_ms(200);
  4260. //电机退出配置模式
  4261. var RunMode = new byte[1];
  4262. RunMode[0] = 0x00;
  4263. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  4264. }
  4265. }
  4266. /// <summary>
  4267. /// 生产模式写入型号
  4268. /// </summary>
  4269. /// <param name="sender"></param>
  4270. /// <param name="e"></param>
  4271. private void button_FacModeSetName_Click(object sender, EventArgs e)
  4272. {
  4273. string Mode = textBox_FacModeName.Text;
  4274. var ModeArray = new byte[16];
  4275. for (ushort i = 0; i < Mode.Length; i++)
  4276. {
  4277. ModeArray[i] = (byte)Mode[i];
  4278. }
  4279. if (Mode.Length < 16)
  4280. {
  4281. ModeArray[Mode.Length] = (byte)'.';
  4282. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  4283. {
  4284. ModeArray[Mode.Length + 1 + i] = 0x20;
  4285. }
  4286. }
  4287. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  4288. }
  4289. /// <summary>
  4290. /// 生产模式写入SN
  4291. /// </summary>
  4292. /// <param name="sender"></param>
  4293. /// <param name="e"></param>
  4294. private void Button_FacModeSetNum_Click(object sender, EventArgs e)
  4295. {
  4296. string SN = textBox_FacModeNum.Text;
  4297. var SNArray = new byte[16];
  4298. for (ushort i = 0; i < SN.Length; i++)
  4299. {
  4300. SNArray[i] = (byte)SN[i];
  4301. }
  4302. if (SN.Length < 16)
  4303. {
  4304. SNArray[SN.Length] = (byte)'.';
  4305. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  4306. {
  4307. SNArray[SN.Length + 1 + i] = 0x20;
  4308. }
  4309. }
  4310. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  4311. }
  4312. /// <summary>
  4313. /// 生产模式读取版本信息
  4314. /// </summary>
  4315. /// <param name="sender"></param>
  4316. /// <param name="e"></param>
  4317. private void Button_FacModeReadVer_Click_1(object sender, EventArgs e)
  4318. {
  4319. textBox_Model.Text = "---";
  4320. textBox_SN.Text = "---";
  4321. textBox_HW.Text = "---";
  4322. textBox_FW.Text = "---";
  4323. textBox_SP.Text = "---";
  4324. textBox_OBC_ReadModel.Text = "---";
  4325. textBox_OBC_ReadSN.Text = "---";
  4326. textBox_OBC_ReadHW.Text = "---";
  4327. textBox_OBC_ReadFW.Text = "---";
  4328. textBox_OBC_ReadSP.Text = "---";
  4329. textBox_FacModeName.Text = "---";
  4330. textBox_FacModeNum.Text = "---";
  4331. textBox_FacModeHW.Text = "---";
  4332. textBox_FacModeFW.Text = "---";
  4333. textBox_FacModeSP.Text = "---";
  4334. textBox_FacModeGit.Text = "---";
  4335. Class_Motor_Ver.Mode = "---";
  4336. Class_Motor_Ver.SN = "---";
  4337. Class_Motor_Ver.HW = "---";
  4338. Class_Motor_Ver.FW = "---";
  4339. Class_Motor_Ver.Special = "---";
  4340. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  4341. }
  4342. /// <summary>
  4343. /// 生产模式写入生产信息
  4344. /// </summary>
  4345. /// <param name="sender"></param>
  4346. /// <param name="e"></param>
  4347. private void Button_FacModeSetMacDate_Click(object sender, EventArgs e)
  4348. {
  4349. var MACArray = new byte[32];
  4350. string MacDefaultInfo = "";
  4351. string MacAddDefaultInfo = "";
  4352. string MacDateDefaultInfo = DateTime.Now.ToString("yyyyMMdd");
  4353. string MacPPDefaultInfo = "";
  4354. do
  4355. {
  4356. //填入生产商
  4357. if (toolStripTextBox_MAC.Text == string.Empty)
  4358. {
  4359. break;
  4360. }
  4361. MacDefaultInfo = toolStripTextBox_MAC.Text;
  4362. for (ushort i = 0; i < MacDefaultInfo.Length; i++)
  4363. {
  4364. MACArray[i] = (byte)MacDefaultInfo[i];
  4365. }
  4366. if (MacDefaultInfo.Length < 8)
  4367. {
  4368. MACArray[MacDefaultInfo.Length] = (byte)'.';
  4369. for (ushort i = 0; i < 8 - MacDefaultInfo.Length - 1; i++)
  4370. {
  4371. MACArray[MacDefaultInfo.Length + 1 + i] = 0x20;
  4372. }
  4373. }
  4374. //填入生产地
  4375. if (toolStripTextBoxMACAddr.Text == string.Empty)
  4376. {
  4377. break;
  4378. }
  4379. MacAddDefaultInfo = toolStripTextBoxMACAddr.Text;
  4380. for (ushort i = 0; i < MacAddDefaultInfo.Length; i++)
  4381. {
  4382. MACArray[8 + i] = (byte)MacAddDefaultInfo[i];
  4383. }
  4384. if (MacAddDefaultInfo.Length < 8)
  4385. {
  4386. MACArray[MacAddDefaultInfo.Length + 8] = (byte)'.';
  4387. for (ushort i = 0; i < 8 - MacAddDefaultInfo.Length - 1; i++)
  4388. {
  4389. MACArray[MacAddDefaultInfo.Length + 1 + i + 8] = 0x20;
  4390. }
  4391. }
  4392. //填入生产日期
  4393. if (toolStripTextBox_MACDate.Text == string.Empty)
  4394. {
  4395. break;
  4396. }
  4397. MacDateDefaultInfo = toolStripTextBox_MACDate.Text;
  4398. for (ushort i = 0; i < MacDateDefaultInfo.Length; i++)
  4399. {
  4400. MACArray[16 + i] = (byte)MacDateDefaultInfo[i];
  4401. }
  4402. if (MacDateDefaultInfo.Length < 8)
  4403. {
  4404. MACArray[MacDateDefaultInfo.Length + 16] = (byte)'.';
  4405. for (ushort i = 0; i < 8 - MacDateDefaultInfo.Length - 1; i++)
  4406. {
  4407. MACArray[MacDateDefaultInfo.Length + 1 + i + 16] = 0x20;
  4408. }
  4409. }
  4410. //填入产品标识
  4411. if (toolStripTextBox_MACPD.Text == string.Empty)
  4412. {
  4413. break;
  4414. }
  4415. MacPPDefaultInfo = toolStripTextBox_MACPD.Text;
  4416. for (ushort i = 0; i < MacPPDefaultInfo.Length; i++)
  4417. {
  4418. MACArray[24 + i] = (byte)MacPPDefaultInfo[i];
  4419. }
  4420. if (MacPPDefaultInfo.Length < 8)
  4421. {
  4422. MACArray[MacPPDefaultInfo.Length + 24] = (byte)'.';
  4423. for (ushort i = 0; i < 8 - MacPPDefaultInfo.Length - 1; i++)
  4424. {
  4425. MACArray[MacPPDefaultInfo.Length + 1 + i + 24] = 0x20;
  4426. }
  4427. }
  4428. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  4429. return;
  4430. } while (false);
  4431. timer_500ms.Enabled = false;
  4432. MessageBox.Show("生产信息配置不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4433. timer_500ms.Enabled = true;
  4434. }
  4435. /// <summary>
  4436. /// 生产模式保存测试页面
  4437. /// </summary>
  4438. /// <param name="sender"></param>
  4439. /// <param name="e"></param>
  4440. private void Button_FacModeSaveResult_Click(object sender, EventArgs e)
  4441. {
  4442. Button_FacModeSaveResult.Text = "存储中…";
  4443. string[] AssistParams = new string[15];
  4444. do
  4445. {
  4446. //读取一次马达参数
  4447. richTextBox_MotorParam.Clear();
  4448. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break; ;
  4449. Delay_ms(100);
  4450. //读取一次整车参数
  4451. richTextBox_BikeParam.Clear();
  4452. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  4453. Delay_ms(100);
  4454. //读取一次整车参数2
  4455. richTextBox_BikeParam2.Clear();
  4456. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null)) break;
  4457. Delay_ms(100);
  4458. //读取一次控制参数
  4459. richTextBox_ControlParam.Clear();
  4460. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  4461. Delay_ms(100);
  4462. //查询传感器
  4463. richTextBox_SensorParam.Clear();
  4464. textBox_FacModeSensorADC0.Text = "";
  4465. textBox_FacModeSensorADC1.Text = "";
  4466. textBox_FacModeSensorADC2.Text = "";
  4467. textBox_FacModeSensorADC3.Text = "";
  4468. textBox_FacModeSensorADC4.Text = "";
  4469. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  4470. Delay_ms(100);
  4471. //读取15次助力参数
  4472. for (int i = 1; i <= 15; i++)
  4473. {
  4474. var ConfigParam = new byte[4];
  4475. richTextBox_AssistParam.Clear();
  4476. ConfigParam[0] = (byte)(i & 0xFF);
  4477. ConfigParam[1] = (byte)(i >> 8);
  4478. ConfigParam[2] = (byte)(((i >= 5) ? 5 : i) & 0xFF);
  4479. ConfigParam[3] = (byte)(((i >= 5) ? 5 : i) >> 8);
  4480. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  4481. Delay_ms(200);
  4482. AssistParams[i - 1] = richTextBox_AssistParam.Text + "\r\n";
  4483. }
  4484. //读取一次用户骑行参数
  4485. richTextBox_UsrRidesParam.Clear();
  4486. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  4487. Delay_ms(100);
  4488. //读取一次调试信息
  4489. richTextBox_DebugParam.Clear();
  4490. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  4491. Delay_ms(100);
  4492. //读取一次历史信息
  4493. richTextBox_Record.Clear();
  4494. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  4495. Delay_ms(100);
  4496. //读取一次电机运行信息
  4497. var CtrlCode = new byte[2];
  4498. CtrlCode[0] = 0x00;
  4499. CtrlCode[1] = 0xF0;
  4500. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode)) break;
  4501. Delay_ms(100);
  4502. //读取一次版本信息
  4503. textBox_Model.Text = "---";
  4504. textBox_SN.Text = "---";
  4505. textBox_HW.Text = "---";
  4506. textBox_FW.Text = "---";
  4507. textBox_OBC_ReadModel.Text = "---";
  4508. textBox_OBC_ReadSN.Text = "---";
  4509. textBox_OBC_ReadHW.Text = "---";
  4510. textBox_OBC_ReadFW.Text = "---";
  4511. textBox_FacModeName.Text = "---";
  4512. textBox_FacModeNum.Text = "---";
  4513. textBox_FacModeHW.Text = "---";
  4514. textBox_FacModeFW.Text = "---";
  4515. Class_Motor_Ver.Mode = "---";
  4516. Class_Motor_Ver.SN = "---";
  4517. Class_Motor_Ver.HW = "---";
  4518. Class_Motor_Ver.FW = "---";
  4519. Class_Motor_Ver.Special = "---";
  4520. if (!mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null)) break;
  4521. Delay_ms(100);
  4522. //读取一次生产信息
  4523. textBox_MAC.Text = "";
  4524. textBox_MACAdd.Text = "";
  4525. textBox_MACDate.Text = "";
  4526. textBox_PP.Text = "";
  4527. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  4528. Delay_ms(100);
  4529. //读取一次自定义信息
  4530. textBox_User1.Text = "---";
  4531. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  4532. Delay_ms(100);
  4533. textBox_User2.Text = "---";
  4534. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  4535. Delay_ms(100);
  4536. textBox_User3.Text = "---";
  4537. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  4538. Delay_ms(100);
  4539. //读取一次密钥
  4540. textBox_Key.Text = "---";
  4541. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  4542. Delay_ms(100);
  4543. //读取一次存储标志
  4544. radioButton_EE_SaveYes.Checked = false;
  4545. radioButton_EE_SaveNo.Checked = false;
  4546. radioButton_SIP_SaveYes.Checked = false;
  4547. radioButton_SIP_SaveNo.Checked = false;
  4548. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  4549. Delay_ms(100);
  4550. //读取一次MOS内阻校准参数
  4551. foreach (Control c in groupBox21.Controls)
  4552. {
  4553. if (c is TextBox)
  4554. c.Text = "";
  4555. }
  4556. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  4557. Delay_ms(100);
  4558. //提示检查
  4559. #if false
  4560. timer_1s.Enabled = false;
  4561. if (MessageBox.Show("请检查信息是否完整!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  4562. {
  4563. MessageBox.Show("请检查参数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4564. timer_1s.Enabled = true;
  4565. return;
  4566. }
  4567. timer_1s.Enabled = true;
  4568. Delay_ms(200);
  4569. #endif
  4570. //判断数据是否有效
  4571. if ((textBox_FacModeName.Text == "---") || (textBox_FacModeNum.Text == "---"))
  4572. {
  4573. MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4574. break;
  4575. }
  4576. if ((textBox_FacModeName.Text == string.Empty) || (textBox_FacModeNum.Text == string.Empty))
  4577. {
  4578. MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4579. break;
  4580. }
  4581. //设置文件存储路径
  4582. string Save_Path = localInfo.LocalPath + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
  4583. string PD_PathName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_"); ;
  4584. Save_Path += PD_PathName;
  4585. if (!Directory.Exists(Save_Path))
  4586. Directory.CreateDirectory(Save_Path);
  4587. //保存页面
  4588. string PIC_SaveFileName = "";
  4589. Double scaleX = PrimaryScreen.ScaleX;
  4590. Double scaleY = PrimaryScreen.ScaleY;
  4591. //保存页面
  4592. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  4593. Graphics g = Graphics.FromImage(bit);
  4594. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  4595. PIC_SaveFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_测试页面" + ".png";
  4596. bit.Save(PIC_SaveFileName);
  4597. //保存数据
  4598. string DataFileName = "";
  4599. string FileInfo = "";
  4600. DataFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_记录数据" + ".txt";
  4601. FileInfo += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  4602. FileInfo += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  4603. FileInfo += "\r\n";
  4604. FileInfo += "[电机信息]\r\n";
  4605. FileInfo += "电机型号: " + textBox_FacModeName.Text + "\r\n";
  4606. FileInfo += "电机编号: " + textBox_FacModeNum.Text + "\r\n";
  4607. FileInfo += "硬件版本: " + textBox_HW.Text + "\r\n";
  4608. FileInfo += "软件版本: " + textBox_FW.Text + "\r\n";
  4609. FileInfo += "软件标识: " + textBox_SP.Text + "\r\n";
  4610. FileInfo += "Git信息: " + textBox_FacModeGit.Text + "\r\n";
  4611. FileInfo += "\r\n";
  4612. FileInfo += "[马达参数]\r\n";
  4613. FileInfo += richTextBox_MotorParam.Text + "\r\n";
  4614. FileInfo += "\r\n";
  4615. FileInfo += "[整车参数]\r\n";
  4616. FileInfo += richTextBox_BikeParam.Text + "\r\n";
  4617. FileInfo += "\r\n";
  4618. FileInfo += "[控制参数]\r\n";
  4619. FileInfo += richTextBox_ControlParam.Text + "\r\n";
  4620. FileInfo += "\r\n";
  4621. FileInfo += "[传感器参数]\r\n";
  4622. FileInfo += richTextBox_SensorParam.Text + "\r\n";
  4623. FileInfo += "\r\n";
  4624. FileInfo += "[助力参数]\r\n";
  4625. for(int i=0;i<15;i++)
  4626. {
  4627. FileInfo += AssistParams[i] + "\r\n";
  4628. }
  4629. FileInfo += "[调试参数]\r\n";
  4630. FileInfo += richTextBox_DebugParam.Text + "\r\n";
  4631. FileInfo += "\r\n";
  4632. FileInfo += "[历史信息]\r\n";
  4633. FileInfo += richTextBox_Record.Text + "\r\n";
  4634. FileInfo += "\r\n";
  4635. FileInfo += "[MOS内阻校准参数]\r\n";
  4636. FileInfo += textBox_MOS_K1.Text + ", ";
  4637. FileInfo += textBox_MOS_K2.Text + ", ";
  4638. FileInfo += textBox_MOS_K3.Text + ", ";
  4639. FileInfo += textBox_MOS_K4.Text + ", ";
  4640. FileInfo += textBox_MOS_K5.Text + ", ";
  4641. FileInfo += textBox_MOS_R1.Text + ", ";
  4642. FileInfo += textBox_MOS_R2.Text + ", ";
  4643. FileInfo += textBox_MOS_R3.Text + "\r\n";
  4644. FileInfo += "\r\n";
  4645. FileInfo += "[整车参数2]\r\n";
  4646. FileInfo += richTextBox_BikeParam2.Text + "\r\n";
  4647. FileInfo += "\r\n";
  4648. FileInfo += "[用户骑行参数]\r\n";
  4649. FileInfo += richTextBox_UsrRidesParam.Text + "\r\n";
  4650. FileInfo += "\r\n";
  4651. FileInfo += "[生产信息]\r\n";
  4652. FileInfo += "生产商: " + textBox_MAC.Text + "\r\n";
  4653. FileInfo += "生产地: " + textBox_MACAdd.Text + "\r\n";
  4654. FileInfo += "生产日期: " + textBox_MACDate.Text + "\r\n";
  4655. FileInfo += "产品标识: " + textBox_PP.Text + "\r\n";
  4656. FileInfo += "\r\n";
  4657. FileInfo += "[自定义信息]\r\n";
  4658. FileInfo += "自定义1: " + textBox_User1.Text + "\r\n";
  4659. FileInfo += "自定义2: " + textBox_User2.Text + "\r\n";
  4660. FileInfo += "自定义3: " + textBox_User3.Text + "\r\n";
  4661. FileInfo += "\r\n";
  4662. FileInfo += "[校验密钥]\r\n";
  4663. FileInfo += textBox_Key.Text + "\r\n";
  4664. FileInfo += "\r\n";
  4665. FileInfo += "[存储标志]\r\n";
  4666. FileInfo += "EEPROM: " + ((radioButton_EE_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  4667. FileInfo += "SIP: " + ((radioButton_SIP_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  4668. FileInfo += "\r\n";
  4669. FileInfo += Local_HdInformation;
  4670. FileInfo += "\r\n";
  4671. FileInfo += "文件格式: V2.0\r\n";
  4672. System.IO.File.WriteAllText(DataFileName, FileInfo);
  4673. Delay_ms(1000);
  4674. timer_500ms.Enabled = false;
  4675. MessageBox.Show("存储完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  4676. timer_500ms.Enabled = true;
  4677. //数据上传
  4678. if (myFtp.IsNetConnected == true)
  4679. {
  4680. string DataNow = DateTime.Now.ToString("yyyy-MM-dd");
  4681. //检查路径
  4682. if (myFtp.DirectoryExist("\\", toolStripTextBox_ServerPath.Text) == false)
  4683. {
  4684. myFtp.MakeDir(toolStripTextBox_ServerPath.Text);
  4685. }
  4686. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text, "Samples") == false)
  4687. {
  4688. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples");
  4689. }
  4690. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples", DataNow) == false)
  4691. {
  4692. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow);
  4693. }
  4694. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow, PD_PathName) == false)
  4695. {
  4696. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4697. }
  4698. //上传文件
  4699. bool result1 = myFtp.UploadFile(PIC_SaveFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4700. bool result2 = myFtp.UploadFile(DataFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4701. if ((result1 & result2) == true)
  4702. {
  4703. timer_500ms.Enabled = false;
  4704. MessageBoxTimeOut.Show("数据已上传!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  4705. timer_500ms.Enabled = true;
  4706. }
  4707. else
  4708. {
  4709. timer_500ms.Enabled = false;
  4710. MessageBox.Show("数据上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4711. timer_500ms.Enabled = true;
  4712. }
  4713. }
  4714. else
  4715. {
  4716. timer_500ms.Enabled = false;
  4717. MessageBox.Show("服务器断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4718. timer_500ms.Enabled = true;
  4719. }
  4720. Button_FacModeSaveResult.Text = "保存数据";
  4721. return;
  4722. } while (false);
  4723. timer_500ms.Enabled = false;
  4724. MessageBox.Show("保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4725. timer_500ms.Enabled = true;
  4726. Button_FacModeSaveResult.Text = "保存数据";
  4727. }
  4728. /// <summary>
  4729. /// 工具箱页面保存
  4730. /// </summary>
  4731. /// <param name="sender"></param>
  4732. /// <param name="e"></param>
  4733. private void 页面保存ToolStripMenuItem_Click(object sender, EventArgs e)
  4734. {
  4735. Double scaleX = PrimaryScreen.ScaleX;
  4736. Double scaleY = PrimaryScreen.ScaleY;
  4737. //保存页面
  4738. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  4739. Graphics g = Graphics.FromImage(bit);
  4740. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  4741. SaveFileDialog sf = new SaveFileDialog();
  4742. sf.Title = "页面保存";
  4743. sf.FileName = "MotorInfo_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".png";
  4744. sf.Filter = "图片|*.png";
  4745. timer_500ms.Enabled = false;
  4746. if (sf.ShowDialog() == DialogResult.OK)
  4747. {
  4748. bit.Save(sf.FileName);//默认保存格式为PNG,保存成jpg格式质量不是很好
  4749. }
  4750. timer_500ms.Enabled = true;
  4751. }
  4752. /// <summary>
  4753. /// 生产模式关机
  4754. /// </summary>
  4755. /// <param name="sender"></param>
  4756. /// <param name="e"></param>
  4757. private void Button_FacModePowerOff_Click(object sender, EventArgs e)
  4758. {
  4759. var Code_Off = new byte[5];
  4760. var Code_Reset = new byte[5];
  4761. Code_Off[0] = (byte)'O';
  4762. Code_Off[1] = (byte)'F';
  4763. Code_Off[2] = (byte)'F';
  4764. Code_Off[3] = (byte)'.';
  4765. Code_Off[4] = (byte)'.';
  4766. Code_Reset[0] = (byte)'R';
  4767. Code_Reset[1] = (byte)'E';
  4768. Code_Reset[2] = (byte)'S';
  4769. Code_Reset[3] = (byte)'E';
  4770. Code_Reset[4] = (byte)'T';
  4771. timer_500ms.Enabled = false;
  4772. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  4773. {
  4774. timer_500ms.Enabled = true;
  4775. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  4776. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  4777. PowerOffAckStatus = false;
  4778. Delay_ms(250);
  4779. int TryCnt = 3;
  4780. while ((TryCnt--) >= 0)
  4781. {
  4782. if (!PowerOffAckStatus)
  4783. {
  4784. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  4785. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  4786. PowerOffAckStatus = false;
  4787. Delay_ms(250);
  4788. }
  4789. else break;
  4790. }
  4791. if (PowerOffAckStatus)
  4792. {
  4793. timer_500ms.Enabled = false;
  4794. MessageBox.Show("已关机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  4795. timer_500ms.Enabled = true;
  4796. }
  4797. else
  4798. {
  4799. timer_500ms.Enabled = false;
  4800. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4801. timer_500ms.Enabled = true;
  4802. }
  4803. }
  4804. timer_500ms.Enabled = true;
  4805. }
  4806. //仪表电源键按下
  4807. private void button_OBC_ButtonPower_Click(object sender, EventArgs e)
  4808. {
  4809. var Code = new byte[2];
  4810. Code[0] = 0;
  4811. Code[1] = 0b00100000;
  4812. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4813. }
  4814. /// <summary>
  4815. /// 仪表加键按下
  4816. /// </summary>
  4817. /// <param name="sender"></param>
  4818. /// <param name="e"></param>
  4819. private void button_OBC_ButtonAcc_Click(object sender, EventArgs e)
  4820. {
  4821. var Code = new byte[2];
  4822. Code[0] = 0;
  4823. Code[1] = 0b00010000;
  4824. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4825. }
  4826. /// <summary>
  4827. /// 仪表减键按下
  4828. /// </summary>
  4829. /// <param name="sender"></param>
  4830. /// <param name="e"></param>
  4831. private void button_OBC_ButtonDec_Click(object sender, EventArgs e)
  4832. {
  4833. var Code = new byte[2];
  4834. Code[0] = 0;
  4835. Code[1] = 0b00001000;
  4836. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4837. }
  4838. /// <summary>
  4839. /// 仪表Walk键按下
  4840. /// </summary>
  4841. /// <param name="sender"></param>
  4842. /// <param name="e"></param>
  4843. private void button_OBC_ButtonWalk_Click(object sender, EventArgs e)
  4844. {
  4845. var Code = new byte[2];
  4846. Code[0] = 0;
  4847. Code[1] = 0b00000100;
  4848. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4849. }
  4850. /// <summary>
  4851. /// 仪表Light键按下
  4852. /// </summary>
  4853. /// <param name="sender"></param>
  4854. /// <param name="e"></param>
  4855. private void button_OBC_ButtonLight_Click(object sender, EventArgs e)
  4856. {
  4857. var Code = new byte[2];
  4858. Code[0] = 0;
  4859. Code[1] = 0b00000010;
  4860. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4861. }
  4862. /// <summary>
  4863. /// 仪表Set键按下
  4864. /// </summary>
  4865. /// <param name="sender"></param>
  4866. /// <param name="e"></param>
  4867. private void button_OBC_ButtonSet_Click(object sender, EventArgs e)
  4868. {
  4869. var Code = new byte[2];
  4870. Code[0] = 0;
  4871. Code[1] = 0b00000001;
  4872. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4873. }
  4874. /// <summary>
  4875. /// 导出电机故障日志
  4876. /// </summary>
  4877. /// <param name="sender"></param>
  4878. /// <param name="e"></param>
  4879. private void button_ExportLog_Click(object sender, EventArgs e)
  4880. {
  4881. var Address = new byte[4];
  4882. UInt32 Address_Begin;
  4883. UInt32 Addres_End;
  4884. string textBox_Address_Begin = textBox_LogAddrBegin.Text;
  4885. string textBox_Address_End = textBox_LogAddrEnd.Text;
  4886. richTextBox_Record.Clear();
  4887. textBox_LogAddrBegin.ReadOnly = true;
  4888. textBox_LogAddrEnd.ReadOnly = true;
  4889. if (!mySerialProcess.mySerial.IsOpen)
  4890. {
  4891. timer_500ms.Enabled = false;
  4892. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4893. timer_500ms.Enabled = true;
  4894. return;
  4895. }
  4896. if ((textBox_Address_Begin == string.Empty) || (textBox_Address_End == string.Empty))
  4897. {
  4898. timer_500ms.Enabled = false;
  4899. MessageBox.Show("请输入日志存储起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4900. timer_500ms.Enabled = true;
  4901. return;
  4902. }
  4903. else
  4904. {
  4905. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin, false);
  4906. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  4907. Address = mySerialProcess.HexStringToBytes(textBox_Address_End, false);
  4908. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  4909. if (Addres_End <= Address_Begin)
  4910. {
  4911. timer_500ms.Enabled = false;
  4912. MessageBox.Show("结束地址应大于起始地址!", "提示");
  4913. timer_500ms.Enabled = true;
  4914. return;
  4915. }
  4916. else if (((Addres_End - Address_Begin + 1) % 128) != 0) //
  4917. {
  4918. timer_500ms.Enabled = false;
  4919. MessageBox.Show("(结束地址 - 起始地址 + 1)应为128整数倍!", "提示");
  4920. timer_500ms.Enabled = true;
  4921. return;
  4922. }
  4923. else
  4924. {
  4925. UInt32 ReadCount = 0;
  4926. button_ExportLog.Text = "导出中...";
  4927. button_ExportLog.Enabled = false;
  4928. ReadCount = (Addres_End - Address_Begin + 1) / 128;
  4929. for (ushort i = 0; i < ReadCount; i++)
  4930. {
  4931. var SendByte = new byte[8];
  4932. UInt32 Address_Temp_Begin;
  4933. UInt32 Address_Temp_End;
  4934. Address_Temp_Begin = Address_Begin + 128 * (UInt32)i;
  4935. SendByte[0] = (byte)(Address_Temp_Begin >> 24);
  4936. SendByte[1] = (byte)(Address_Temp_Begin >> 16);
  4937. SendByte[2] = (byte)(Address_Temp_Begin >> 8);
  4938. SendByte[3] = (byte)(Address_Temp_Begin);
  4939. Address_Temp_End = Address_Temp_Begin + 127;
  4940. SendByte[4] = (byte)(Address_Temp_End >> 24);
  4941. SendByte[5] = (byte)(Address_Temp_End >> 16);
  4942. SendByte[6] = (byte)(Address_Temp_End >> 8);
  4943. SendByte[7] = (byte)(Address_Temp_End);
  4944. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  4945. Delay_ms(200);//Thread.Sleep(200);
  4946. }
  4947. button_ExportLog.Text = "导出日志";
  4948. button_ExportLog.Enabled = true;
  4949. }
  4950. }
  4951. }
  4952. /// <summary>
  4953. /// 保存日志信息
  4954. /// </summary>
  4955. /// <param name="sender"></param>
  4956. /// <param name="e"></param>
  4957. private void button_SaveRecordInfo_Click(object sender, EventArgs e)
  4958. {
  4959. string SaveInfo = "";
  4960. if (richTextBox_Record.Text == string.Empty)
  4961. {
  4962. timer_500ms.Enabled = false;
  4963. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  4964. timer_500ms.Enabled = true;
  4965. return;
  4966. }
  4967. //获取保存信息
  4968. SaveInfo += "读取时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  4969. SaveInfo += "电机型号:" + textBox_FacModeName.Text + "\r\n";
  4970. SaveInfo += "电机SN:" + textBox_FacModeNum.Text + "\r\n";
  4971. SaveInfo += "硬件版本:" + textBox_FacModeHW.Text + "\r\n";
  4972. SaveInfo += "软件版本:" + textBox_FacModeFW.Text + "\r\n";
  4973. SaveInfo += "\r\n";
  4974. SaveInfo += richTextBox_Record.Text;
  4975. //设置保存路径和文件名
  4976. SaveFileDialog sf = new SaveFileDialog();
  4977. sf.Title = "数据保存";
  4978. sf.FileName = "MotorLog_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".ttlog";
  4979. sf.FileName.Replace(" ", "");
  4980. sf.Filter = "日志|*.ttlog";
  4981. if (sf.ShowDialog() == DialogResult.OK)
  4982. {
  4983. System.IO.File.AppendAllText(sf.FileName, SaveInfo);
  4984. }
  4985. }
  4986. /// <summary>
  4987. /// 双击修改日志起始地址
  4988. /// </summary>
  4989. /// <param name="sender"></param>
  4990. /// <param name="e"></param>
  4991. private void label_LogAddrBegin_DoubleClick_1(object sender, EventArgs e)
  4992. {
  4993. textBox_LogAddrBegin.ReadOnly = false;
  4994. }
  4995. /// <summary>
  4996. /// 双击修改日志结束地址
  4997. /// </summary>
  4998. /// <param name="sender"></param>
  4999. /// <param name="e"></param>
  5000. private void label88_DoubleClick(object sender, EventArgs e)
  5001. {
  5002. textBox_LogAddrEnd.ReadOnly = false;
  5003. }
  5004. /// <summary>
  5005. /// 存储器自动读取选择
  5006. /// </summary>
  5007. /// <param name="sender"></param>
  5008. /// <param name="e"></param>
  5009. private void checkBox_ReadRanFlash_AutoSW_CheckedChanged(object sender, EventArgs e)
  5010. {
  5011. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  5012. {
  5013. //检查串口是否打开
  5014. if (!mySerialProcess.mySerial.IsOpen)
  5015. {
  5016. timer_500ms.Enabled = false;
  5017. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5018. timer_500ms.Enabled = true;
  5019. checkBox_ReadRanFlash_AutoSW.Checked = false;
  5020. return;
  5021. }
  5022. }
  5023. }
  5024. /// <summary>
  5025. /// 系统开机按钮
  5026. /// </summary>
  5027. /// <param name="sender"></param>
  5028. /// <param name="e"></param>
  5029. private void 开机ToolStripMenuItem_Click(object sender, EventArgs e)
  5030. {
  5031. byte[] Data = new byte[1];
  5032. Data[0] = 0xF1;
  5033. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  5034. }
  5035. /// <summary>
  5036. /// 系统关机按钮
  5037. /// </summary>
  5038. /// <param name="sender"></param>
  5039. /// <param name="e"></param>
  5040. private void 关机ToolStripMenuItem_Click(object sender, EventArgs e)
  5041. {
  5042. byte[] Data = new byte[1];
  5043. Data[0] = 0xF0;
  5044. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  5045. }
  5046. /// <summary>
  5047. /// 连接开机选择
  5048. /// </summary>
  5049. /// <param name="sender"></param>
  5050. /// <param name="e"></param>
  5051. private void 连接开机ToolStripMenuItem_Click(object sender, EventArgs e)
  5052. {
  5053. //输入用户名
  5054. EnterForm1.ShowDialog();
  5055. try
  5056. {
  5057. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5058. {
  5059. if (EnterForm1.comboBox_User.Text == "管理员")
  5060. {
  5061. 连接开机ToolStripMenuItem.Checked = !连接开机ToolStripMenuItem.Checked;
  5062. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5063. }
  5064. else
  5065. {
  5066. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5067. }
  5068. }
  5069. else
  5070. {
  5071. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5072. }
  5073. }
  5074. catch (Exception)
  5075. {
  5076. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5077. }
  5078. }
  5079. /// <summary>
  5080. /// 断开关机选择
  5081. /// </summary>
  5082. /// <param name="sender"></param>
  5083. /// <param name="e"></param>
  5084. private void 断开关机ToolStripMenuItem_Click(object sender, EventArgs e)
  5085. {
  5086. //输入用户名
  5087. EnterForm1.ShowDialog();
  5088. try
  5089. {
  5090. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5091. {
  5092. if (EnterForm1.comboBox_User.Text == "管理员")
  5093. {
  5094. 断开关机ToolStripMenuItem.Checked = !断开关机ToolStripMenuItem.Checked;
  5095. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5096. }
  5097. else
  5098. {
  5099. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5100. }
  5101. }
  5102. else
  5103. {
  5104. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5105. }
  5106. }
  5107. catch (Exception)
  5108. {
  5109. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5110. }
  5111. }
  5112. /// <summary>
  5113. /// 识别通讯盒选择
  5114. /// </summary>
  5115. /// <param name="sender"></param>
  5116. /// <param name="e"></param>
  5117. private void 识别通讯盒ToolStripMenuItem_Click(object sender, EventArgs e)
  5118. {
  5119. //输入用户名
  5120. EnterForm1.ShowDialog();
  5121. try
  5122. {
  5123. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5124. {
  5125. if (EnterForm1.comboBox_User.Text == "管理员")
  5126. {
  5127. 识别通讯盒ToolStripMenuItem.Checked = !识别通讯盒ToolStripMenuItem.Checked;
  5128. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5129. }
  5130. else
  5131. {
  5132. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5133. }
  5134. }
  5135. else
  5136. {
  5137. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5138. }
  5139. }
  5140. catch (Exception)
  5141. {
  5142. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5143. }
  5144. }
  5145. /// <summary>
  5146. /// 将配置信息导出为cfg文件
  5147. /// </summary>
  5148. private void ConfigFileSave(bool DeleteFlag, string FileName)
  5149. {
  5150. if (DeleteFlag)
  5151. {
  5152. if (File.Exists(FileName))
  5153. File.Delete(FileName);
  5154. }
  5155. string CfgFileInfo = "";
  5156. CfgFileInfo += "[PortSet]" + "\r\n";
  5157. CfgFileInfo += "PortNum:" + toolStripComboBox_ComNum.Text + "\r\n";
  5158. CfgFileInfo += "PortBaudrate:" + "115200" + "\r\n";
  5159. CfgFileInfo += "AutoOn:" + 连接开机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5160. CfgFileInfo += "AutoOff:" + 断开关机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5161. CfgFileInfo += "CheckCDL:" + 识别通讯盒ToolStripMenuItem.Checked.ToString() + "\r\n";
  5162. CfgFileInfo += "\r\n";
  5163. CfgFileInfo += "[Option]" + "\r\n";
  5164. CfgFileInfo += "SaveWhenWrite:" + 写入存储ToolStripMenuItem.Checked.ToString() + "\r\n";
  5165. CfgFileInfo += "\r\n";
  5166. CfgFileInfo += "[ServerSet]" + "\r\n";
  5167. CfgFileInfo += "PathName:" + toolStripTextBox_ServerPath.Text + "\r\n";
  5168. CfgFileInfo += "\r\n";
  5169. CfgFileInfo += "[MacInfo]" + "\r\n";
  5170. CfgFileInfo += "MacName:" + toolStripTextBox_MAC.Text + "\r\n";
  5171. CfgFileInfo += "MacAddress:" + toolStripTextBoxMACAddr.Text + "\r\n";
  5172. CfgFileInfo += "MacDate:" + toolStripTextBox_MACDate.Text + "\r\n";
  5173. CfgFileInfo += "MacPdInfo:" + toolStripTextBox_MACPD.Text + "\r\n";
  5174. CfgFileInfo += "\r\n";
  5175. CfgFileInfo += "[LogAddress]" + "\r\n";
  5176. CfgFileInfo += "BeginAddress:" + textBox_LogAddrBegin.Text + "\r\n";
  5177. CfgFileInfo += "EndAddress:" + textBox_LogAddrEnd.Text + "\r\n";
  5178. CfgFileInfo += "\r\n";
  5179. CfgFileInfo += "[MotorType]" + "\r\n";
  5180. CfgFileInfo += "MidMotor:" + 中置电机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5181. CfgFileInfo += "HubMotor:" + 轮毂电机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5182. CfgFileInfo += "\r\n";
  5183. CfgFileInfo += "[CheckValue]" + "\r\n";
  5184. CfgFileInfo += "Voltage:" + toolStripTextBox_ThVol.Text + "\r\n";
  5185. CfgFileInfo += "Current:" + toolStripTextBox_ThCur.Text + "\r\n";
  5186. CfgFileInfo += "MotorSpeed:" + toolStripTextBox_ThSpeed.Text + "\r\n";
  5187. CfgFileInfo += "Torque:" + toolStripTextBox_ThTor.Text + "\r\n";
  5188. CfgFileInfo += "Cadence:" + toolStripTextBox_ThCad.Text + "\r\n";
  5189. CfgFileInfo += "BikeSpeed:" + toolStripTextBox_ThBikeSpeed.Text + "\r\n";
  5190. CfgFileInfo += "T_PCB:" + toolStripTextBox_ThT_PCB.Text + "\r\n";
  5191. CfgFileInfo += "T_MCU:" + toolStripTextBox_ThT_MCU.Text + "\r\n";
  5192. CfgFileInfo += "T_Motor:" + toolStripTextBox_ThT_Motor.Text + "\r\n";
  5193. CfgFileInfo += "\r\n";
  5194. CfgFileInfo += "[MosCalK]" + "\r\n";
  5195. CfgFileInfo += "K1-K5:" + toolStripTextBox_MosCalK.Text + "\r\n";
  5196. CfgFileInfo += "MOS1:" + toolStripTextBox_MOS1.Text + "\r\n";
  5197. CfgFileInfo += "MOS2:" + toolStripTextBox_MOS2.Text + "\r\n";
  5198. CfgFileInfo += "MOS3:" + toolStripTextBox_MOS3.Text + "\r\n";
  5199. CfgFileInfo += "\r\n";
  5200. CfgFileInfo += "[ProtocolType]" + "\r\n";
  5201. CfgFileInfo += "CAN:" + cANToolStripMenuItem.Checked.ToString() + "\r\n";
  5202. CfgFileInfo += "UART:" + uARTToolStripMenuItem.Checked.ToString() + "\r\n";
  5203. CfgFileInfo += "\r\n";
  5204. CfgFileInfo += "[AutoUpdate]" + "\r\n";
  5205. CfgFileInfo += "AutoUpdate:" + 打开ToolStripMenuItem.Checked.ToString() + "\r\n";
  5206. CfgFileInfo += "\r\n";
  5207. CfgFileInfo += "[AngleCal]" + "\r\n";
  5208. CfgFileInfo += "MaxDiffLimit:" + textBox_AngleDiffTh.Text + "\r\n";
  5209. CfgFileInfo += "ZeroDiffLimit:" + textBox_AngleZeroTh.Text + "\r\n";
  5210. System.IO.File.WriteAllText(FileName, CfgFileInfo);
  5211. }
  5212. /// <summary>
  5213. /// 配置状态更新,点击时保存
  5214. /// </summary>
  5215. private void ConfigFileSave_Click(object sender, EventArgs e)
  5216. {
  5217. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5218. }
  5219. /// <summary>
  5220. /// 文本框修改结束,回车保存
  5221. /// </summary>
  5222. /// <param name="sender"></param>
  5223. /// <param name="e"></param>
  5224. private void ConfigFileSave_KeyDown(object sender, KeyEventArgs e)
  5225. {
  5226. if (e.KeyCode == Keys.Enter)
  5227. {
  5228. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5229. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  5230. }
  5231. }
  5232. /// <summary>
  5233. /// 弹出扫码按钮
  5234. /// </summary>
  5235. /// <param name="sender"></param>
  5236. /// <param name="e"></param>
  5237. private void button_ScanCode_Click(object sender, EventArgs e)
  5238. {
  5239. Scan scan_form = new Scan();
  5240. scan_form.ShowDialog();
  5241. do
  5242. {
  5243. if (scan_form.textBox_Scan.Text == string.Empty)
  5244. {
  5245. timer_500ms.Enabled = false;
  5246. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5247. timer_500ms.Enabled = true;
  5248. break;
  5249. }
  5250. string ScanInfo = scan_form.textBox_Scan.Text;
  5251. string regexInfo = "";
  5252. string[] InfoList = { "" };
  5253. try
  5254. {
  5255. if (中置电机ToolStripMenuItem.Checked == true)
  5256. {
  5257. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  5258. InfoList = Regex.Split(ScanInfo, regexInfo, RegexOptions.IgnoreCase);
  5259. }
  5260. else if (轮毂电机ToolStripMenuItem.Checked == true)
  5261. {
  5262. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  5263. string Model = InfoList[0];
  5264. string Spec = InfoList[1];
  5265. string Sn = InfoList[2];
  5266. InfoList[0] = Model.Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  5267. InfoList[1] = Sn;
  5268. }
  5269. }
  5270. catch (Exception)
  5271. {
  5272. MessageBox.Show("格式错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5273. return;
  5274. }
  5275. if (InfoList.Length >= 2)
  5276. {
  5277. //写入型号
  5278. textBox_FacModeName.Text = InfoList[0];
  5279. string Mode = textBox_FacModeName.Text;
  5280. var ModeArray = new byte[16];
  5281. for (ushort i = 0; i < Mode.Length; i++)
  5282. {
  5283. ModeArray[i] = (byte)Mode[i];
  5284. }
  5285. if (Mode.Length < 16)
  5286. {
  5287. ModeArray[Mode.Length] = (byte)'.';
  5288. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  5289. {
  5290. ModeArray[Mode.Length + 1 + i] = 0x20;
  5291. }
  5292. }
  5293. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  5294. //写入SN
  5295. textBox_FacModeNum.Text = InfoList[1];
  5296. string SN = textBox_FacModeNum.Text;
  5297. var SNArray = new byte[16];
  5298. for (ushort i = 0; i < SN.Length; i++)
  5299. {
  5300. SNArray[i] = (byte)SN[i];
  5301. }
  5302. if (SN.Length < 16)
  5303. {
  5304. SNArray[SN.Length] = (byte)'.';
  5305. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  5306. {
  5307. SNArray[SN.Length + 1 + i] = 0x20;
  5308. }
  5309. }
  5310. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  5311. }
  5312. else
  5313. {
  5314. timer_500ms.Enabled = false;
  5315. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5316. timer_500ms.Enabled = true;
  5317. break;
  5318. }
  5319. } while (false);
  5320. scan_form.Dispose();
  5321. }
  5322. /// <summary>
  5323. /// 切换电机类型
  5324. /// </summary>
  5325. /// <param name="sender"></param>
  5326. /// <param name="e"></param>
  5327. private void 中置电机ToolStripMenuItem_Click(object sender, EventArgs e)
  5328. {
  5329. 中置电机ToolStripMenuItem.Checked = true;
  5330. 轮毂电机ToolStripMenuItem.Checked = false;
  5331. toolStripTextBox_MACPD.Text = "MM_MC1";
  5332. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  5333. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5334. }
  5335. /// <summary>
  5336. /// 切换电机类型
  5337. /// </summary>
  5338. /// <param name="sender"></param>
  5339. /// <param name="e"></param>
  5340. private void 轮毂电机ToolStripMenuItem_Click(object sender, EventArgs e)
  5341. {
  5342. 中置电机ToolStripMenuItem.Checked = false;
  5343. 轮毂电机ToolStripMenuItem.Checked = true;
  5344. toolStripTextBox_MACPD.Text = "GF_250_1";
  5345. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  5346. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5347. }
  5348. /// <summary>
  5349. /// 获取配置文件日期
  5350. /// </summary>
  5351. /// <param name="DisAll"></param>
  5352. private void GetDateList(bool DisAll)
  5353. {
  5354. string[] DateList = { "" };
  5355. //从服务器更新日期列表
  5356. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  5357. {
  5358. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
  5359. }
  5360. //从本地更新日期列表
  5361. else
  5362. {
  5363. DateList = Directory.GetDirectories(localInfo.LocalPath + "\\" + localInfo.CfgPathName);
  5364. }
  5365. comboBox_FacModeCfgDate.Items.Clear();
  5366. comboBox_CheckModeCfgDate.Items.Clear();
  5367. //日期列表加载
  5368. if (DisAll == true)
  5369. {
  5370. comboBox_FacModeCfgDate.Items.Add("显示近期");
  5371. comboBox_CheckModeCfgDate.Items.Add("显示近期");
  5372. comboBox_FacModeCfgDate.Items.Add("---");
  5373. comboBox_CheckModeCfgDate.Items.Add("---");
  5374. foreach (var file in DateList)
  5375. {
  5376. comboBox_FacModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5377. comboBox_CheckModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5378. }
  5379. }
  5380. else
  5381. {
  5382. if (DateList.Length > 10)
  5383. {
  5384. comboBox_FacModeCfgDate.Items.Add("显示全部");
  5385. comboBox_CheckModeCfgDate.Items.Add("显示全部");
  5386. comboBox_FacModeCfgDate.Items.Add("---");
  5387. comboBox_CheckModeCfgDate.Items.Add("---");
  5388. }
  5389. for (int i = (DateList.Length > 10) ? (DateList.Length - 10) : 0; i < DateList.Length; i++)//显示最近10个日期
  5390. {
  5391. comboBox_FacModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  5392. comboBox_CheckModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  5393. }
  5394. }
  5395. }
  5396. /// <summary>
  5397. /// 获取配置文件列表
  5398. /// </summary>
  5399. /// <param name="date"></param>
  5400. private void GetFileListFrom(string date)
  5401. {
  5402. string[] FileList = { "" };
  5403. //从服务器更新文件列表
  5404. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  5405. {
  5406. FileList = myFtp.GetFileNameList(toolStripTextBox_ServerPath.Text + "/cfg/" + date);
  5407. }
  5408. else
  5409. {
  5410. FileList = Directory.GetFiles(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + date);
  5411. }
  5412. comboBox_CheckModeCfgFile.Items.Clear();
  5413. comboBox_FacModeCfgFile.Items.Clear();
  5414. foreach (var file in FileList)
  5415. {
  5416. if (file.Contains(".ttcfg"))
  5417. {
  5418. comboBox_CheckModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5419. comboBox_FacModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5420. }
  5421. }
  5422. }
  5423. /// <summary>
  5424. /// 检验模式选择文件日期
  5425. /// </summary>
  5426. /// <param name="sender"></param>
  5427. /// <param name="e"></param>
  5428. private void comboBox_CheckModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  5429. {
  5430. if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示全部")
  5431. {
  5432. GetDateList(true);
  5433. }
  5434. else if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示近期")
  5435. {
  5436. GetDateList(false);
  5437. }
  5438. else
  5439. {
  5440. comboBox_CheckModeCfgFile.Text = "";
  5441. GetFileListFrom(comboBox_CheckModeCfgDate.SelectedItem.ToString());
  5442. }
  5443. }
  5444. /// <summary>
  5445. /// 配置模式选择文件日期
  5446. /// </summary>
  5447. /// <param name="sender"></param>
  5448. /// <param name="e"></param>
  5449. private void comboBox_FacModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  5450. {
  5451. if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示全部")
  5452. {
  5453. GetDateList(true);
  5454. }
  5455. else if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示近期")
  5456. {
  5457. GetDateList(false);
  5458. }
  5459. else
  5460. {
  5461. comboBox_FacModeCfgFile.Text = "";
  5462. GetFileListFrom(comboBox_FacModeCfgDate.SelectedItem.ToString());
  5463. }
  5464. }
  5465. /// <summary>
  5466. /// 选中量产模式
  5467. /// </summary>
  5468. /// <param name="sender"></param>
  5469. /// <param name="e"></param>
  5470. private void tabControl1_Selected(object sender, TabControlEventArgs e)
  5471. {
  5472. //更新生产配置文件目录
  5473. GetDateList(false);
  5474. }
  5475. /// <summary>
  5476. /// 量产测试结束
  5477. /// </summary>
  5478. /// <param name=""></param>
  5479. private void FacMode_Stop(bool OK_Flag)
  5480. {
  5481. //打开开始按钮
  5482. button__FacMode_Start.Enabled = true;
  5483. //系统关机
  5484. var Code = new byte[32];//发送的指令数据
  5485. Code[0] = 0xF0;
  5486. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5487. //关闭串口
  5488. //mySerialProcess.SerialClose(false);
  5489. //路径设置
  5490. string LocalSavePath = "";
  5491. string ServerSavePath = "";
  5492. if (OK_Flag)
  5493. {
  5494. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "OK\\";
  5495. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/OK/";
  5496. }
  5497. else
  5498. {
  5499. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "FAIL\\";
  5500. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/FAIL/";
  5501. }
  5502. if (Directory.Exists(LocalSavePath) == false)
  5503. {
  5504. Directory.CreateDirectory(LocalSavePath);
  5505. }
  5506. //保存和上传
  5507. string LogSavePath = "";
  5508. string LogSaveFileName = "";
  5509. string ProductInfo = textBox_FacModeScan.Text.Replace(" ", "_");
  5510. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  5511. if (Directory.Exists(LogSavePath) == false)
  5512. {
  5513. Directory.CreateDirectory(LogSavePath);
  5514. }
  5515. //测试页面
  5516. Double scaleX = PrimaryScreen.ScaleX;
  5517. Double scaleY = PrimaryScreen.ScaleY;
  5518. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  5519. Graphics g = Graphics.FromImage(bit);
  5520. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  5521. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  5522. bit.Save(LogSaveFileName);
  5523. //上传测试页面到服务器
  5524. if (myFtp.IsNetConnected == true)
  5525. {
  5526. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  5527. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  5528. {
  5529. myFtp.MakeDir(ServerSavePath + DateNow);
  5530. }
  5531. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  5532. {
  5533. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  5534. }
  5535. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  5536. if (result == true)
  5537. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  5538. }
  5539. else
  5540. {
  5541. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  5542. }
  5543. //测试记录
  5544. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  5545. string file_str = "";
  5546. file_str += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  5547. file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  5548. file_str += "检验记录:\r\n" + richTextBox_FacModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  5549. file_str += "检验结果:\r\n" + label_FacModeResult.Text + "\r\n\r\n";
  5550. file_str += Local_HdInformation;
  5551. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  5552. //上传测试记录到服务器
  5553. if (myFtp.IsNetConnected == true)
  5554. {
  5555. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  5556. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  5557. {
  5558. myFtp.MakeDir(ServerSavePath + DateNow);
  5559. }
  5560. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  5561. {
  5562. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  5563. }
  5564. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  5565. if (result == true)
  5566. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  5567. }
  5568. else
  5569. {
  5570. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  5571. }
  5572. //扫码框清空
  5573. textBox_FacModeScan.Text = "";
  5574. }
  5575. /// <summary>
  5576. /// 量产测试开始
  5577. /// </summary>
  5578. /// <param name="sender"></param>
  5579. /// <param name="e"></param>
  5580. private void button__FacMode_Start_Click(object sender, EventArgs e)
  5581. {
  5582. //关闭测试项目编辑
  5583. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  5584. foreach (Control c in groupBox2.Controls)
  5585. {
  5586. if (c is CheckBox)
  5587. c.Enabled = false;
  5588. }
  5589. WriteLockStatus = true;
  5590. //检查配置文件
  5591. if (comboBox_FacModeCfgFile.Text == "")
  5592. {
  5593. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5594. return;
  5595. }
  5596. //开始测试
  5597. TestStart();
  5598. }
  5599. /// <summary>
  5600. /// 测试子函数
  5601. /// </summary>
  5602. private void TestStart()
  5603. {
  5604. //初始化标签
  5605. FacModelLabelInit();
  5606. richTextBox_FacModeLog.Clear();
  5607. //按钮禁止操作
  5608. button__FacMode_Start.Enabled = false;
  5609. //记录配置文件
  5610. richTextBox_FacModeLog.AppendText("配置文件:" + comboBox_FacModeCfgDate.Text + " / " + comboBox_FacModeCfgFile.Text + "\r\n");
  5611. //检查打标信息格式
  5612. label_FacModeStatus.Text = "检查扫码信息";
  5613. Delay_ms(500);
  5614. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  5615. if (textBox_FacModeScan.Text == string.Empty)
  5616. {
  5617. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5618. button__FacMode_Start.Enabled = true;
  5619. return;
  5620. }
  5621. try
  5622. {
  5623. if (中置电机ToolStripMenuItem.Checked == true)
  5624. {
  5625. if (textBox_FacModeScan.Text.Split(' ').Length != 7)
  5626. {
  5627. label_FacModeStatus.Text = "存在故障!";
  5628. label_FacModeResult.BackColor = Color.Red;
  5629. label_FacModeResult.Text = "标签格式错误";
  5630. button__FacMode_Start.Enabled = true;
  5631. return;
  5632. }
  5633. }
  5634. else if (轮毂电机ToolStripMenuItem.Checked == true)
  5635. {
  5636. if (textBox_FacModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  5637. {
  5638. label_FacModeStatus.Text = "存在故障!";
  5639. label_FacModeResult.BackColor = Color.Red;
  5640. label_FacModeResult.Text = "标签格式错误";
  5641. button__FacMode_Start.Enabled = true;
  5642. return;
  5643. }
  5644. }
  5645. }
  5646. catch (System.Exception)
  5647. {
  5648. label_FacModeStatus.Text = "存在故障!";
  5649. label_FacModeResult.BackColor = Color.Red;
  5650. label_FacModeResult.Text = "标签格式错误";
  5651. button__FacMode_Start.Enabled = true;
  5652. return;
  5653. }
  5654. //打开串口
  5655. mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false);
  5656. if (!mySerialProcess.mySerial.IsOpen)
  5657. {
  5658. MessageBox.Show("请检查串口连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5659. //按钮禁止操作
  5660. button__FacMode_Start.Enabled = true;
  5661. return;
  5662. }
  5663. //流水号计数
  5664. int serial = Convert.ToInt32(label_FacModeSerial.Text);
  5665. serial += 1;
  5666. label_FacModeSerial.Text = serial.ToString();
  5667. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, serial.ToString());
  5668. //创建线程,执行测试任务
  5669. Thread th = new Thread(FacModeTest_Task);
  5670. th.Start();
  5671. }
  5672. /// <summary>
  5673. /// 执行一次测试任务
  5674. /// </summary>
  5675. private void FacModeTest_Task()
  5676. {
  5677. //开始测试
  5678. richTextBox_FacModeLog.AppendText("产品标签:" + textBox_FacModeScan.Text + "\r\n");
  5679. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  5680. //变量定义
  5681. var Code = new byte[255];//发送的指令数据
  5682. label_FacModeStatus.Text = "开始测试";
  5683. BootInfo = "";
  5684. Delay_ms(500);
  5685. label_FacModeStatus.Text = "系统开机";
  5686. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  5687. if (uARTToolStripMenuItem.Checked)
  5688. {
  5689. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送复位指令,切换联动装置盒波特率" + "\r\n");
  5690. Code[0] = (byte)'R';
  5691. Code[1] = (byte)'E';
  5692. Code[2] = (byte)'S';
  5693. Code[3] = (byte)'E';
  5694. Code[4] = (byte)'T';
  5695. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  5696. Delay_ms(500);
  5697. }
  5698. //发送开机指令
  5699. //确保测试前先关机,发送关机指令再发送开机指令
  5700. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  5701. Code[0] = 0xF0;
  5702. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5703. Delay_ms(1500);
  5704. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  5705. Code[0] = 0xF1;
  5706. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5707. ACK_WaitCnt = 0;
  5708. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  5709. while (ACK_WaitCnt <= 20) ; //10s,等待开机成功,联动装置盒控制器接口波特率需等待5s接口自动切换为9600
  5710. //检查BOOT版本
  5711. if (BootInfo != string.Empty)
  5712. {
  5713. label_FacModeBootVer.BackColor = Color.Green;
  5714. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  5715. Delay_ms(500);
  5716. }
  5717. else
  5718. {
  5719. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
  5720. label_FacModeStatus.Text = "存在故障!";
  5721. label_FacModeResult.BackColor = Color.Red;
  5722. label_FacModeResult.Text = "测试异常";
  5723. Delay_ms(500);
  5724. //存储异常并上传
  5725. FacMode_Stop(false);
  5726. return;
  5727. }
  5728. //系统清除
  5729. if (checkBox_FacModeSysClear.Checked)
  5730. {
  5731. do
  5732. {
  5733. #if false
  5734. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  5735. {
  5736. Code[0] = 0x00;//5S协议
  5737. Code[1] = 0x00;
  5738. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5739. Delay_ms(500);
  5740. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5741. Delay_ms(500);
  5742. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  5743. }
  5744. #endif
  5745. //发送系统清除指令
  5746. label_FacModeStatus.Text = "系统清除";
  5747. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除" + "\r\n");
  5748. Code[0] = (byte)'C';
  5749. Code[1] = (byte)'L';
  5750. Code[2] = (byte)'E';
  5751. Code[3] = (byte)'A';
  5752. Code[4] = (byte)'R';
  5753. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  5754. WriteACK = false;
  5755. WriteCnt = 0;
  5756. ACK_WaitCnt = 0;
  5757. while (ACK_WaitCnt <= 6); //3s
  5758. //等待系统清除完成指令
  5759. if (WriteACK == true)
  5760. {
  5761. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  5762. label_FacModeSysClear.BackColor = Color.Green;
  5763. }
  5764. else
  5765. {
  5766. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除,重发第1次" + "\r\n");
  5767. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  5768. ACK_WaitCnt = 0;
  5769. while (ACK_WaitCnt <= 6) ; //3s
  5770. //等待系统清除完成指令
  5771. if (WriteACK == true)
  5772. {
  5773. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  5774. label_FacModeSysClear.BackColor = Color.Green;
  5775. }
  5776. else
  5777. {
  5778. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除,重发第2次" + "\r\n");
  5779. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  5780. ACK_WaitCnt = 0;
  5781. while (ACK_WaitCnt <= 6) ; //3s
  5782. //等待系统清除完成指令
  5783. if (WriteACK == true)
  5784. {
  5785. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  5786. label_FacModeSysClear.BackColor = Color.Green;
  5787. }
  5788. else
  5789. {
  5790. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除失败" + "\r\n");
  5791. label_FacModeStatus.Text = "存在故障!";
  5792. label_FacModeResult.BackColor = Color.Red;
  5793. label_FacModeResult.Text = "测试异常";
  5794. Delay_ms(500);
  5795. //存储异常并上传
  5796. FacMode_Stop(false);
  5797. return;
  5798. }
  5799. }
  5800. }
  5801. BootInfo = "";
  5802. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  5803. if (uARTToolStripMenuItem.Checked)
  5804. {
  5805. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送复位指令,切换联动装置盒波特率" + "\r\n");
  5806. Code[0] = (byte)'R';
  5807. Code[1] = (byte)'E';
  5808. Code[2] = (byte)'S';
  5809. Code[3] = (byte)'E';
  5810. Code[4] = (byte)'T';
  5811. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  5812. Delay_ms(500);
  5813. }
  5814. //系统清除后需重新开机
  5815. label_FacModeStatus.Text = "重新开机";
  5816. //确保测试前先关机,发送关机指令再发送开机指令
  5817. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新发送关机指令" + "\r\n");
  5818. Code[0] = 0xF0;
  5819. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5820. Delay_ms(1500);
  5821. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新发送开机指令" + "\r\n");
  5822. Code[0] = 0xF1;
  5823. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5824. ACK_WaitCnt = 0;
  5825. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  5826. while (ACK_WaitCnt <= 20); //10s
  5827. //获取Boot版本信息
  5828. if (BootInfo != string.Empty)
  5829. {
  5830. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机成功" + "\r\n");
  5831. Delay_ms(500);
  5832. }
  5833. else
  5834. {
  5835. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机失败" + "\r\n");
  5836. label_FacModeStatus.Text = "存在故障!";
  5837. label_FacModeResult.BackColor = Color.Red;
  5838. label_FacModeResult.Text = "测试异常";
  5839. Delay_ms(500);
  5840. //存储异常并上传
  5841. FacMode_Stop(false);
  5842. return;
  5843. }
  5844. } while (false);
  5845. }
  5846. else
  5847. {
  5848. label_FacModeSysClear.BackColor = Color.Yellow;
  5849. label_FacModeStatus.Text = "跳过系统清除!";
  5850. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过系统清除" + "\r\n");
  5851. Delay_ms(500);
  5852. }
  5853. #if false
  5854. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  5855. {
  5856. Code[0] = 0x00;//5S协议
  5857. Code[1] = 0x00;
  5858. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5859. Delay_ms(500);
  5860. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5861. Delay_ms(500);
  5862. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  5863. }
  5864. #endif
  5865. //检查是否有故障
  5866. if (textBox_ErrorCode.Text.Contains("H"))
  5867. {
  5868. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "故障码:" + textBox_ErrorCode.Text + "\r\n");
  5869. label_FacModeStatus.Text = "电机存在故障!";
  5870. label_FacModeResult.BackColor = Color.Red;
  5871. label_FacModeResult.Text = "测试异常";
  5872. Delay_ms(500);
  5873. //存储异常并上传
  5874. FacMode_Stop(false);
  5875. return;
  5876. }
  5877. //MOS内阻校准
  5878. if (checkBox_FacMode_MosCal.Checked)
  5879. {
  5880. label_FacModeStatus.Text = "MOS内阻校准";
  5881. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始MOS内阻校准" + "\r\n");
  5882. Delay_ms(500);
  5883. //提示进行负载切换
  5884. if (MessageBox.Show("电阻负载切换完成,开始校准?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
  5885. {
  5886. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "取消MOS内阻校准" + "\r\n");
  5887. label_FacModeStatus.Text = "存在故障!";
  5888. label_FacModeResult.BackColor = Color.Red;
  5889. label_FacModeResult.Text = "测试异常";
  5890. Delay_ms(500);
  5891. //存储异常并上传
  5892. FacMode_Stop(false);
  5893. return;
  5894. }
  5895. //确认后发送校准指令
  5896. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令" + "\r\n");
  5897. string[] K = toolStripTextBox_MosCalK.Text.Split(',');
  5898. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  5899. ushort uwDataTemp = 0;
  5900. uwDataTemp = Convert.ToUInt16(K[0]);
  5901. Code[2] = (byte)(uwDataTemp & 0xFF);
  5902. Code[3] = (byte)(uwDataTemp >> 8);
  5903. uwDataTemp = Convert.ToUInt16(K[1]);
  5904. Code[4] = (byte)(uwDataTemp & 0xFF);
  5905. Code[5] = (byte)(uwDataTemp >> 8);
  5906. uwDataTemp = Convert.ToUInt16(K[2]);
  5907. Code[6] = (byte)(uwDataTemp & 0xFF);
  5908. Code[7] = (byte)(uwDataTemp >> 8);
  5909. uwDataTemp = Convert.ToUInt16(K[3]);
  5910. Code[8] = (byte)(uwDataTemp & 0xFF);
  5911. Code[9] = (byte)(uwDataTemp >> 8);
  5912. uwDataTemp = Convert.ToUInt16(K[4]);
  5913. Code[10] = (byte)(uwDataTemp & 0xFF);
  5914. Code[11] = (byte)(uwDataTemp >> 8);
  5915. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  5916. WriteACK = false;
  5917. WriteCnt = 0;
  5918. ACK_WaitCnt = 0;
  5919. while (ACK_WaitCnt <= 6) ; //3s
  5920. if (WriteACK == true)
  5921. {
  5922. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  5923. }
  5924. else
  5925. {
  5926. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令,第1次重发" + "\r\n");
  5927. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  5928. ACK_WaitCnt = 0;
  5929. while (ACK_WaitCnt <= 6) ; //3s
  5930. if (WriteACK == true)
  5931. {
  5932. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  5933. }
  5934. else
  5935. {
  5936. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令,第2次重发" + "\r\n");
  5937. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  5938. ACK_WaitCnt = 0;
  5939. while (ACK_WaitCnt <= 6) ; //3s
  5940. if (WriteACK == true)
  5941. {
  5942. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  5943. }
  5944. else
  5945. {
  5946. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准异常" + "\r\n");
  5947. label_FacModeStatus.Text = "存在故障!";
  5948. label_FacModeResult.BackColor = Color.Red;
  5949. label_FacModeResult.Text = "测试异常";
  5950. Delay_ms(500);
  5951. //存储异常并上传
  5952. FacMode_Stop(false);
  5953. return;
  5954. }
  5955. }
  5956. }
  5957. #if false
  5958. //因控制器复位需发送指令重新进入5S协议
  5959. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  5960. {
  5961. Code[0] = 0x00;//5S协议
  5962. Code[1] = 0x00;
  5963. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5964. Delay_ms(500);
  5965. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5966. Delay_ms(500);
  5967. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  5968. }
  5969. #endif
  5970. //读取显示校准返回数据
  5971. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果" + "\r\n");
  5972. foreach (Control c in groupBox21.Controls)
  5973. {
  5974. if (c is TextBox)
  5975. c.Text = "";
  5976. }
  5977. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  5978. ACK_WaitCnt = 0;
  5979. while (ACK_WaitCnt <= 2) ; //1s
  5980. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  5981. {
  5982. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果,第1次重发" + "\r\n");
  5983. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  5984. ACK_WaitCnt = 0;
  5985. while (ACK_WaitCnt <= 2) ; //1s
  5986. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  5987. {
  5988. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果,第2次重发" + "\r\n");
  5989. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  5990. ACK_WaitCnt = 0;
  5991. while (ACK_WaitCnt <= 2) ; //1s
  5992. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  5993. {
  5994. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果异常" + "\r\n");
  5995. label_FacModeStatus.Text = "存在故障!";
  5996. label_FacModeResult.BackColor = Color.Red;
  5997. label_FacModeResult.Text = "测试异常";
  5998. Delay_ms(500);
  5999. //存储异常并上传
  6000. FacMode_Stop(false);
  6001. return;
  6002. }
  6003. }
  6004. }
  6005. else
  6006. {
  6007. 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");
  6008. }
  6009. //与校准返回数据对比
  6010. string[] MOS_R1_Th = toolStripTextBox_MOS1.Text.Split(',');
  6011. string[] MOS_R2_Th = toolStripTextBox_MOS2.Text.Split(',');
  6012. string[] MOS_R3_Th = toolStripTextBox_MOS3.Text.Split(',');
  6013. 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])) &&
  6014. (Convert.ToUInt16(textBox_MOS_R2.Text) >= Convert.ToUInt16(MOS_R2_Th[0])) && (Convert.ToUInt16(textBox_MOS_R2.Text) <= Convert.ToUInt16(MOS_R2_Th[1])) &&
  6015. (Convert.ToUInt16(textBox_MOS_R3.Text) >= Convert.ToUInt16(MOS_R3_Th[0])) && (Convert.ToUInt16(textBox_MOS_R3.Text) <= Convert.ToUInt16(MOS_R3_Th[1]))
  6016. )
  6017. {
  6018. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准合格" + "\r\n");
  6019. label_FacModeMosCal.BackColor = Color.Green;
  6020. //提示切换负载
  6021. MessageBox.Show("请将负载切换回电机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  6022. }
  6023. else
  6024. {
  6025. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准超范围" + "\r\n");
  6026. label_FacModeStatus.Text = "存在故障!";
  6027. label_FacModeResult.BackColor = Color.Red;
  6028. label_FacModeResult.Text = "测试异常";
  6029. Delay_ms(500);
  6030. //存储异常并上传
  6031. FacMode_Stop(false);
  6032. //提示切换负载
  6033. MessageBox.Show("请将负载切换回电机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  6034. return;
  6035. }
  6036. }
  6037. else
  6038. {
  6039. label_FacModeMosCal.BackColor = Color.Yellow;
  6040. label_FacModeStatus.Text = "跳过MOS内阻校准!";
  6041. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过MOS内阻校准" + "\r\n");
  6042. Delay_ms(500);
  6043. }
  6044. //位置校准
  6045. if (checkBox_FacMode_AngleCal.Checked)
  6046. {
  6047. //校准前进行一次开关机保存初始化数据
  6048. BootInfo = "";
  6049. label_FacModeStatus.Text = "位置校准";
  6050. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始位置校准" + "\r\n");
  6051. //确保测试前先关机,发送关机指令再发送开机指令
  6052. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  6053. Code[0] = 0xF0;
  6054. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6055. Delay_ms(1500);
  6056. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  6057. Code[0] = 0xF1;
  6058. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6059. ACK_WaitCnt = 0;
  6060. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  6061. while (ACK_WaitCnt <= 10) ; //5s
  6062. //获取Boot版本信息
  6063. if (BootInfo != string.Empty)
  6064. {
  6065. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机成功" + "\r\n");
  6066. Delay_ms(500);
  6067. }
  6068. else
  6069. {
  6070. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机失败" + "\r\n");
  6071. label_FacModeStatus.Text = "存在故障!";
  6072. label_FacModeResult.BackColor = Color.Red;
  6073. label_FacModeResult.Text = "测试异常";
  6074. Delay_ms(500);
  6075. //存储异常并上传
  6076. FacMode_Stop(false);
  6077. return;
  6078. }
  6079. //发送位置校准指令
  6080. for (int i = 0; i < 7; i++)
  6081. for (int j = 0; j < 6; j++)
  6082. {
  6083. dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = "";
  6084. }
  6085. foreach (Control cr in tabPage_AngleCal.Controls)
  6086. {
  6087. if (cr is TextBox)
  6088. {
  6089. if ((cr != textBox_AngleDiffTh) && (cr != textBox_AngleZeroTh))
  6090. cr.Text = "";
  6091. }
  6092. }
  6093. Code[0] = 0;
  6094. Code[1] = 0;
  6095. mySerialProcess.SendCmd((ushort)0x751, (byte)0x0C, (ushort)0x5002, Code);
  6096. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准中,请等待" + "\r\n");
  6097. ACK_WaitCnt = 0;
  6098. while (ACK_WaitCnt <= 50) ; //25s
  6099. //读取位置校准数据
  6100. if (textBox_AngleDiffAvg.Text == string.Empty)
  6101. {
  6102. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准失败" + "\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. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准数据:" + "\r\n");
  6112. for (int i = 0; i < 7; i++)
  6113. {
  6114. richTextBox_FacModeLog.AppendText("电周期" + (i + 1).ToString()+":");
  6115. for (int j = 0; j < 6; j++)
  6116. {
  6117. richTextBox_FacModeLog.AppendText(dataGridView_AngleCal.Rows[i].Cells[j + 1].Value.ToString() + ", ");
  6118. }
  6119. richTextBox_FacModeLog.AppendText("\r\n");
  6120. Delay_ms(200);
  6121. }
  6122. richTextBox_FacModeLog.AppendText("最小偏差:" + textBox_AngleDiffMin.Text+ ", " + "\r\n");
  6123. richTextBox_FacModeLog.AppendText("最大偏差:" + textBox_AngleDiffMax.Text + ", " + "\r\n");
  6124. richTextBox_FacModeLog.AppendText("平均偏差:" + textBox_AngleDiffAvg.Text + ", " + "\r\n");
  6125. richTextBox_FacModeLog.AppendText("历史零点:" + textBox_AngleZeroInit.Text + ", " + "\r\n");
  6126. richTextBox_FacModeLog.AppendText("当前零点:" + textBox_AngleZeroCur.Text + ", " + "\r\n");
  6127. richTextBox_FacModeLog.AppendText("零点偏差:" + textBox_AngleZeroDiff.Text + ", " + "\r\n");
  6128. //比较位置偏差
  6129. if ((Math.Abs(Convert.ToDouble(textBox_AngleDiffMin.Text)) > Convert.ToDouble(textBox_AngleDiffTh.Text)) ||
  6130. (Math.Abs(Convert.ToDouble(textBox_AngleDiffMax.Text)) > Convert.ToDouble(textBox_AngleDiffTh.Text)) ||
  6131. (Math.Abs(Convert.ToDouble(textBox_AngleDiffAvg.Text)) > Convert.ToDouble(textBox_AngleZeroTh.Text))
  6132. )
  6133. {
  6134. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差过大,无法校准" + "\r\n");
  6135. label_FacModeStatus.Text = "存在故障!";
  6136. label_FacModeResult.BackColor = Color.Red;
  6137. label_FacModeResult.Text = "测试异常";
  6138. Delay_ms(500);
  6139. //存储异常并上传
  6140. FacMode_Stop(false);
  6141. return;
  6142. }
  6143. //写入校准偏差值
  6144. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差满足要求,写入校准数据" + "\r\n");
  6145. double data1 = Convert.ToDouble(textBox_AngleZeroInit.Text) - Convert.ToDouble(textBox_AngleDiffAvg.Text);
  6146. if (data1 > 360)
  6147. {
  6148. data1 -= 360;
  6149. }
  6150. else if (data1 < -360)
  6151. {
  6152. data1 += 360;
  6153. }
  6154. Int16 data2 = (Int16)(data1 * 32768 / 360);
  6155. Code[0] = 0x01;
  6156. Code[1] = 0x00;
  6157. Code[2] = (byte)(data2);
  6158. Code[3] = (byte)(data2 >> 8);
  6159. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
  6160. WriteACK = false;
  6161. ACK_WaitCnt = 0;
  6162. while (ACK_WaitCnt <= 2) ; //1s
  6163. if (WriteACK == true)
  6164. {
  6165. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
  6166. }
  6167. else
  6168. {
  6169. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入位置偏差,第1次重发" + "\r\n");
  6170. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
  6171. WriteACK = false;
  6172. ACK_WaitCnt = 0;
  6173. while (ACK_WaitCnt <= 2) ; //1s
  6174. if (WriteACK == true)
  6175. {
  6176. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
  6177. }
  6178. else
  6179. {
  6180. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入位置偏差,第2次重发" + "\r\n");
  6181. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
  6182. WriteACK = false;
  6183. ACK_WaitCnt = 0;
  6184. while (ACK_WaitCnt <= 2) ; //1s
  6185. if (WriteACK == true)
  6186. {
  6187. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
  6188. }
  6189. else
  6190. {
  6191. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入失败" + "\r\n");
  6192. label_FacModeStatus.Text = "存在故障!";
  6193. label_FacModeResult.BackColor = Color.Red;
  6194. label_FacModeResult.Text = "测试异常";
  6195. Delay_ms(500);
  6196. //存储异常并上传
  6197. FacMode_Stop(false);
  6198. return;
  6199. }
  6200. }
  6201. }
  6202. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准正常,位置偏差值:" + textBox_AngleDiffAvg.Text + "\r\n");
  6203. label_FacModeAngleCal.BackColor = Color.Green;
  6204. }
  6205. else
  6206. {
  6207. label_FacModeAngleCal.BackColor = Color.Yellow;
  6208. label_FacModeStatus.Text = "跳过位置校准!";
  6209. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过位置校准" + "\r\n");
  6210. Delay_ms(500);
  6211. }
  6212. //参数写入
  6213. if (checkBox_FacModeCfgWrite.Checked)
  6214. {
  6215. label_FacModeStatus.Text = "参数写入";
  6216. //写入产品型号和SN
  6217. do
  6218. {
  6219. //根据扫码信息获取型号和SN
  6220. string ScanInfo = textBox_FacModeScan.Text;
  6221. string regexInfo = "";
  6222. string[] InfoList = { "" };
  6223. try
  6224. {
  6225. if (中置电机ToolStripMenuItem.Checked == true)
  6226. {
  6227. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  6228. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  6229. }
  6230. else if (轮毂电机ToolStripMenuItem.Checked == true)
  6231. {
  6232. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  6233. string Model = InfoList[0];
  6234. string Spec = InfoList[1];
  6235. string Sn = InfoList[2];
  6236. InfoList[0] = Model.Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  6237. InfoList[1] = Sn;
  6238. }
  6239. }
  6240. catch
  6241. {
  6242. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  6243. label_FacModeStatus.Text = "存在故障!";
  6244. label_FacModeResult.BackColor = Color.Red;
  6245. label_FacModeResult.Text = "标签格式错误";
  6246. Delay_ms(500);
  6247. //存储异常并上传
  6248. FacMode_Stop(false);
  6249. return;
  6250. }
  6251. if (InfoList.Length >= 2)
  6252. {
  6253. //检查配置文件是否与打标信息一致
  6254. //...
  6255. //写入型号
  6256. label_FacModeStatus.Text = "写入型号";
  6257. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号" + "\r\n");
  6258. textBox_FacModeName.Text = InfoList[0];
  6259. string Mode = textBox_FacModeName.Text;
  6260. var ModeArray = new byte[16];
  6261. for (ushort i = 0; i < Mode.Length; i++)
  6262. {
  6263. ModeArray[i] = (byte)Mode[i];
  6264. }
  6265. if (Mode.Length < 16)
  6266. {
  6267. ModeArray[Mode.Length] = (byte)'.';
  6268. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  6269. {
  6270. ModeArray[Mode.Length + 1 + i] = 0x20;
  6271. }
  6272. }
  6273. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6274. WriteACK = false;
  6275. WriteCnt = 0;
  6276. ACK_WaitCnt = 0;
  6277. while (ACK_WaitCnt <= 2); //1s
  6278. if (WriteACK == true)
  6279. {
  6280. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6281. }
  6282. else
  6283. {
  6284. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号,第1次重发" + "\r\n");
  6285. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6286. ACK_WaitCnt = 0;
  6287. while (ACK_WaitCnt <= 2) ; //1s
  6288. if (WriteACK == true)
  6289. {
  6290. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6291. }
  6292. else
  6293. {
  6294. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号,第2次重发" + "\r\n");
  6295. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6296. ACK_WaitCnt = 0;
  6297. while (ACK_WaitCnt <= 2) ; //1s
  6298. if (WriteACK == true)
  6299. {
  6300. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6301. }
  6302. else
  6303. {
  6304. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入失败" + "\r\n");
  6305. label_FacModeStatus.Text = "存在故障!";
  6306. label_FacModeResult.BackColor = Color.Red;
  6307. label_FacModeResult.Text = "测试异常";
  6308. Delay_ms(500);
  6309. //存储异常并上传
  6310. FacMode_Stop(false);
  6311. return;
  6312. }
  6313. }
  6314. }
  6315. //写入SN
  6316. label_FacModeStatus.Text = "写入SN";
  6317. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN" + "\r\n");
  6318. textBox_FacModeNum.Text = InfoList[1];
  6319. string SN = textBox_FacModeNum.Text;
  6320. var SNArray = new byte[16];
  6321. for (ushort i = 0; i < SN.Length; i++)
  6322. {
  6323. SNArray[i] = (byte)SN[i];
  6324. }
  6325. if (SN.Length < 16)
  6326. {
  6327. SNArray[SN.Length] = (byte)'.';
  6328. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  6329. {
  6330. SNArray[SN.Length + 1 + i] = 0x20;
  6331. }
  6332. }
  6333. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6334. WriteACK = false;
  6335. WriteCnt = 0;
  6336. ACK_WaitCnt = 0;
  6337. while (ACK_WaitCnt <= 2); //1s
  6338. if (WriteACK == true)
  6339. {
  6340. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  6341. }
  6342. else
  6343. {
  6344. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN,第1次重发" + "\r\n");
  6345. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6346. ACK_WaitCnt = 0;
  6347. while (ACK_WaitCnt <= 2) ; //1s
  6348. if (WriteACK == true)
  6349. {
  6350. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  6351. }
  6352. else
  6353. {
  6354. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN,第2次重发" + "\r\n");
  6355. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6356. ACK_WaitCnt = 0;
  6357. while (ACK_WaitCnt <= 2) ; //1s
  6358. if (WriteACK == true)
  6359. {
  6360. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  6361. }
  6362. else
  6363. {
  6364. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入失败" + "\r\n");
  6365. label_FacModeStatus.Text = "存在故障!";
  6366. label_FacModeResult.BackColor = Color.Red;
  6367. label_FacModeResult.Text = "测试异常";
  6368. Delay_ms(500);
  6369. //存储异常并上传
  6370. FacMode_Stop(false);
  6371. return;
  6372. }
  6373. }
  6374. }
  6375. }
  6376. else
  6377. {
  6378. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6379. return;
  6380. }
  6381. } while (false);
  6382. //写入配置文件
  6383. do
  6384. {
  6385. label_FacModeStatus.Text = "写入配置文件";
  6386. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  6387. //配置文件
  6388. List<byte[]> CmdList = new List<byte[]>();
  6389. //从服务器下载文件
  6390. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  6391. {
  6392. string SelectFile = "";
  6393. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "/" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  6394. if (File.Exists(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  6395. {
  6396. File.Delete(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  6397. }
  6398. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  6399. //打开文件
  6400. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  6401. CmdList.Clear();
  6402. while (streamReader.Peek() != -1)
  6403. {
  6404. string fileLineInfo = streamReader.ReadLine();
  6405. if (fileLineInfo.IndexOf("[") != -1)
  6406. {
  6407. continue;
  6408. }
  6409. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  6410. }
  6411. streamReader.Close();
  6412. }
  6413. //加载本地文件
  6414. else
  6415. {
  6416. string SelectFile = "";
  6417. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  6418. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  6419. CmdList.Clear();
  6420. while (streamReader.Peek() != -1)
  6421. {
  6422. string fileLineInfo = streamReader.ReadLine();
  6423. if (fileLineInfo.IndexOf("[") != -1)
  6424. {
  6425. continue;
  6426. }
  6427. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  6428. }
  6429. streamReader.Close();
  6430. }
  6431. int CmdNum = CmdList.Count(); //指令个数
  6432. Delay_ms(500);
  6433. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "开始写入" + "\r\n");
  6434. Delay_ms(500);
  6435. //开始写入
  6436. WriteCnt = 0;
  6437. for (int i = 0; i < CmdList.Count; i++)
  6438. {
  6439. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令" + "\r\n");
  6440. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6441. WriteACK = false;
  6442. ACK_WaitCnt = 0;
  6443. while (ACK_WaitCnt <= 2) ; //1s
  6444. if (WriteACK == true)
  6445. {
  6446. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6447. }
  6448. else
  6449. {
  6450. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令,第1次重发" + "\r\n");
  6451. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6452. WriteACK = false;
  6453. ACK_WaitCnt = 0;
  6454. while (ACK_WaitCnt <= 2) ; //1s
  6455. if (WriteACK == true)
  6456. {
  6457. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6458. }
  6459. else
  6460. {
  6461. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令,第2次重发" + "\r\n");
  6462. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6463. WriteACK = false;
  6464. ACK_WaitCnt = 0;
  6465. while (ACK_WaitCnt <= 2) ; //1s
  6466. if (WriteACK == true)
  6467. {
  6468. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6469. }
  6470. else
  6471. {
  6472. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入失败," + "共" + CmdNum.ToString() + "条指令," + "写入成功" + i.ToString() + "条" + "\r\n");
  6473. label_FacModeStatus.Text = "存在故障!";
  6474. label_FacModeResult.BackColor = Color.Red;
  6475. label_FacModeResult.Text = "测试异常";
  6476. Delay_ms(500);
  6477. //存储异常并上传
  6478. FacMode_Stop(false);
  6479. return;
  6480. }
  6481. }
  6482. }
  6483. }
  6484. //写入完成
  6485. label_FacMode_CfgWrite.BackColor = Color.Green;
  6486. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入成功" + "\r\n");
  6487. Delay_ms(500);
  6488. } while (false);
  6489. }
  6490. else
  6491. {
  6492. label_FacMode_CfgWrite.BackColor = Color.Yellow;
  6493. label_FacModeStatus.Text = "跳过参数写入!";
  6494. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数写入" + "\r\n");
  6495. Delay_ms(500);
  6496. }
  6497. //BMS通讯
  6498. if (checkBox_FacModeBMS.Checked)
  6499. {
  6500. if (label_FacModeBMS.BackColor == Color.Red)
  6501. {
  6502. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "BMS通讯异常" + "\r\n");
  6503. label_FacModeStatus.Text = "存在故障!";
  6504. label_FacModeResult.BackColor = Color.Red;
  6505. label_FacModeResult.Text = "测试异常";
  6506. Delay_ms(500);
  6507. //存储异常并上传
  6508. FacMode_Stop(false);
  6509. return;
  6510. }
  6511. }
  6512. else
  6513. {
  6514. label_FacModeBMS.BackColor = Color.Yellow;
  6515. label_FacModeStatus.Text = "跳过BMS通讯检测!";
  6516. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过BMS通讯检测" + "\r\n");
  6517. Delay_ms(500);
  6518. }
  6519. //基础功能检测
  6520. if (checkBox_FacBaseFucTest.Checked)
  6521. {
  6522. label_FacModeStatus.Text = "基础功能检测";
  6523. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始基础功能检测" + "\r\n");
  6524. //确认负载位置
  6525. if (checkBox_FacMode_MosCal.Checked)
  6526. {
  6527. if (MessageBox.Show("请再次确认负载是否切换回电机?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  6528. {
  6529. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "负载已切换为电机,继续测试" + "\r\n");
  6530. }
  6531. else
  6532. {
  6533. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试取消" + "\r\n");
  6534. label_FacModeStatus.Text = "存在故障!";
  6535. label_FacModeResult.BackColor = Color.Red;
  6536. label_FacModeResult.Text = "测试异常";
  6537. Delay_ms(500);
  6538. //存储异常并上传
  6539. FacMode_Stop(false);
  6540. return;
  6541. }
  6542. }
  6543. //发送指令进入配置模式
  6544. do
  6545. {
  6546. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6547. Code[0] = 0x01;
  6548. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6549. WriteACK = false;
  6550. WriteCnt = 0;
  6551. ACK_WaitCnt = 0;
  6552. while (ACK_WaitCnt <= 2); //1s
  6553. if (textBox_RunInfo_Vol.Text != "---")
  6554. {
  6555. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6556. }
  6557. else
  6558. {
  6559. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  6560. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6561. ACK_WaitCnt = 0;
  6562. while (ACK_WaitCnt <= 2) ; //1s
  6563. if (textBox_RunInfo_Vol.Text != "---")
  6564. {
  6565. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6566. }
  6567. else
  6568. {
  6569. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  6570. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6571. ACK_WaitCnt = 0;
  6572. while (ACK_WaitCnt <= 2) ; //1s
  6573. if (textBox_RunInfo_Vol.Text != "---")
  6574. {
  6575. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6576. }
  6577. else
  6578. {
  6579. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  6580. label_FacModeStatus.Text = "存在故障!";
  6581. label_FacModeResult.BackColor = Color.Red;
  6582. label_FacModeResult.Text = "测试异常";
  6583. Delay_ms(500);
  6584. //存储异常并上传
  6585. FacMode_Stop(false);
  6586. return;
  6587. }
  6588. }
  6589. }
  6590. } while (false);
  6591. //发送指令启动电机
  6592. do
  6593. {
  6594. #if false //通过运行模式3启动电机
  6595. //发送指令读取调试信息
  6596. richTextBox_DebugParam.Clear();
  6597. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  6598. WriteACK = false;
  6599. WriteCnt = 0;
  6600. ACK_WaitCnt = 0;
  6601. while (ACK_WaitCnt <= 2); //1s
  6602. //获取调试信息
  6603. string DebugDefaultInfo = "";
  6604. if (richTextBox_DebugParam.Text == string.Empty)
  6605. {
  6606. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
  6607. label_FacModeStatus.Text = "存在故障!";
  6608. label_FacModeResult.BackColor = Color.Red;
  6609. label_FacModeResult.Text = "测试异常";
  6610. Delay_ms(500);
  6611. //存储异常并上传
  6612. FacMode_Stop(false);
  6613. return;
  6614. }
  6615. else
  6616. {
  6617. DebugDefaultInfo = richTextBox_DebugParam.Text;
  6618. }
  6619. //设置模式
  6620. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  6621. strDataTemp[0] = "整体运行模式=3";
  6622. //发送数据
  6623. Code[0] = 0;
  6624. Code[1] = 0;
  6625. for (int i = 0; i < strDataTemp.Length; i++)
  6626. {
  6627. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  6628. Code[2 * i + 2] = (byte)uwDataTemp;
  6629. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  6630. }
  6631. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  6632. label_FacModeStatus.Text = "启动电机";
  6633. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "启动电机" + "\r\n");
  6634. #else //通过Walk模式启动电机
  6635. //设置转速100%
  6636. var Data = new byte[1];
  6637. Data[0] = (byte)100;
  6638. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6639. Delay_ms(500);
  6640. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6641. Delay_ms(500);
  6642. //启动电机进入WALK模式
  6643. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "基础功能检测,进入WALK" + "\r\n");
  6644. Code[0] = 0x22;
  6645. Code[1] = 0xF0;
  6646. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6647. WriteACK = false;
  6648. WriteCnt = 0;
  6649. ACK_WaitCnt = 0;
  6650. while (ACK_WaitCnt <= 2) ; //1s
  6651. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6652. {
  6653. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第1次重发" + "\r\n");
  6654. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6655. ACK_WaitCnt = 0;
  6656. while (ACK_WaitCnt <= 2) ; //1s
  6657. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6658. {
  6659. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第2次重发" + "\r\n");
  6660. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6661. ACK_WaitCnt = 0;
  6662. while (ACK_WaitCnt <= 2) ; //1s
  6663. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6664. {
  6665. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
  6666. label_FacModeStatus.Text = "存在故障!";
  6667. label_FacModeResult.BackColor = Color.Red;
  6668. label_FacModeResult.Text = "测试异常";
  6669. Delay_ms(500);
  6670. //存储异常并上传
  6671. FacMode_Stop(false);
  6672. return;
  6673. }
  6674. }
  6675. }
  6676. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入WALK,开始检测" + "\r\n");
  6677. #endif
  6678. Delay_ms(3000);
  6679. } while (false);
  6680. //判断车速
  6681. if ((Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) <= Convert.ToDouble( toolStripTextBox_ThBikeSpeed.Text.Split(',')[1])) &&
  6682. (Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThBikeSpeed.Text.Split(',')[0])))
  6683. {
  6684. label_FacModeSpeed.BackColor = Color.Green;
  6685. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器正常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
  6686. }
  6687. else
  6688. {
  6689. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器异常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
  6690. label_FacModeStatus.Text = "存在故障!";
  6691. label_FacModeResult.BackColor = Color.Red;
  6692. label_FacModeResult.Text = "测试异常";
  6693. Delay_ms(500);
  6694. //存储异常并上传
  6695. FacMode_Stop(false);
  6696. return;
  6697. }
  6698. //判断电压
  6699. if ((Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[1])) &&
  6700. (Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[0])))
  6701. {
  6702. label_FacModeVolTest.BackColor = Color.Green;
  6703. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量正常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
  6704. }
  6705. else
  6706. {
  6707. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量异常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
  6708. label_FacModeStatus.Text = "存在故障!";
  6709. label_FacModeResult.BackColor = Color.Red;
  6710. label_FacModeResult.Text = "测试异常";
  6711. Delay_ms(500);
  6712. //存储异常并上传
  6713. FacMode_Stop(false);
  6714. return;
  6715. }
  6716. //判断电流
  6717. if ((Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[1])) &&
  6718. (Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[0])))
  6719. {
  6720. label_FacModeCurrentTest.BackColor = Color.Green;
  6721. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量正常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  6722. }
  6723. else
  6724. {
  6725. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量异常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  6726. label_FacModeStatus.Text = "存在故障!";
  6727. label_FacModeResult.BackColor = Color.Red;
  6728. label_FacModeResult.Text = "测试异常";
  6729. Delay_ms(500);
  6730. //存储异常并上传
  6731. FacMode_Stop(false);
  6732. return;
  6733. }
  6734. //判断温度
  6735. if ((Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[1])) &&
  6736. (Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[0])) &&
  6737. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[1])) &&
  6738. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[0])) &&
  6739. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[1])) &&
  6740. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[0])))
  6741. {
  6742. label_FacModeNTC.BackColor = Color.Green;
  6743. 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");
  6744. }
  6745. else
  6746. {
  6747. 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");
  6748. label_FacModeStatus.Text = "存在故障!";
  6749. label_FacModeResult.BackColor = Color.Red;
  6750. label_FacModeResult.Text = "测试异常";
  6751. Delay_ms(500);
  6752. //存储异常并上传
  6753. FacMode_Stop(false);
  6754. return;
  6755. }
  6756. //判断转速
  6757. if ((Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[1])) &&
  6758. (Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[0])))
  6759. {
  6760. label_FacModeMotorSpeed.BackColor = Color.Green;
  6761. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速正常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
  6762. }
  6763. else
  6764. {
  6765. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速异常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
  6766. label_FacModeStatus.Text = "存在故障!";
  6767. label_FacModeResult.BackColor = Color.Red;
  6768. label_FacModeResult.Text = "测试异常";
  6769. Delay_ms(500);
  6770. //存储异常并上传
  6771. FacMode_Stop(false);
  6772. return;
  6773. }
  6774. //发送指令停止电机
  6775. do
  6776. {
  6777. //设置转速0%
  6778. var Data = new byte[1];
  6779. Data[0] = (byte)0;
  6780. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6781. Delay_ms(500);
  6782. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6783. Delay_ms(500);
  6784. #if false //通过修改调试模式停止电机
  6785. //获取调试信息
  6786. string DebugDefaultInfo = "";
  6787. if (richTextBox_DebugParam.Text == string.Empty)
  6788. {
  6789. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
  6790. label_FacModeStatus.Text = "存在故障!";
  6791. label_FacModeResult.BackColor = Color.Red;
  6792. label_FacModeResult.Text = "测试异常";
  6793. Delay_ms(500);
  6794. //存储异常并上传
  6795. FacMode_Stop(false);
  6796. return;
  6797. }
  6798. else
  6799. {
  6800. DebugDefaultInfo = richTextBox_DebugParam.Text;
  6801. }
  6802. //设置模式
  6803. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  6804. //发送数据
  6805. Code[0] = 0;
  6806. Code[1] = 0;
  6807. for (int i = 0; i < strDataTemp.Length; i++)
  6808. {
  6809. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  6810. Code[2 * i + 2] = (byte)uwDataTemp;
  6811. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  6812. }
  6813. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  6814. label_FacModeStatus.Text = "停止电机";
  6815. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "停止电机" + "\r\n");
  6816. #else //通过调整档位停止电机
  6817. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK" + "\r\n");
  6818. Code[0] = 0x00;
  6819. Code[1] = 0xF0;
  6820. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6821. WriteACK = false;
  6822. WriteCnt = 0;
  6823. ACK_WaitCnt = 0;
  6824. while (ACK_WaitCnt <= 2) ; //1s
  6825. if (textBox_RunInfo_GearSt.Text != "OFF")
  6826. {
  6827. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK,第1次重发" + "\r\n");
  6828. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6829. ACK_WaitCnt = 0;
  6830. while (ACK_WaitCnt <= 2) ; //1s
  6831. if (textBox_RunInfo_GearSt.Text != "OFF")
  6832. {
  6833. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK,第2次重发" + "\r\n");
  6834. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6835. ACK_WaitCnt = 0;
  6836. while (ACK_WaitCnt <= 2) ; //1s
  6837. if (textBox_RunInfo_GearSt.Text != "OFF")
  6838. {
  6839. }
  6840. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
  6841. label_FacModeStatus.Text = "存在故障!";
  6842. label_FacModeResult.BackColor = Color.Red;
  6843. label_FacModeResult.Text = "测试异常";
  6844. Delay_ms(500);
  6845. //存储异常并上传
  6846. FacMode_Stop(false);
  6847. return;
  6848. }
  6849. }
  6850. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已退出WALK,基础功能检测完成" + "\r\n");
  6851. #endif
  6852. Delay_ms(2000);
  6853. } while (false);
  6854. }
  6855. else
  6856. {
  6857. label_FacModeSpeed.BackColor = Color.Yellow;
  6858. label_FacModeVolTest.BackColor = Color.Yellow;
  6859. label_FacModeCurrentTest.BackColor = Color.Yellow;
  6860. label_FacModeNTC.BackColor = Color.Yellow;
  6861. label_FacModeMotorSpeed.BackColor = Color.Yellow;
  6862. label_FacModeStatus.Text = "跳过基础功能检测!";
  6863. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过基础功能检测" + "\r\n");
  6864. Delay_ms(500);
  6865. }
  6866. //力矩检测
  6867. if (checkBox_FacTor.Checked)
  6868. {
  6869. label_FacModeStatus.Text = "力矩传感器检测!";
  6870. //发送指令进入配置模式
  6871. do
  6872. {
  6873. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  6874. {
  6875. break;
  6876. }
  6877. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6878. Code[0] = 0x01;
  6879. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6880. WriteACK = false;
  6881. WriteCnt = 0;
  6882. ACK_WaitCnt = 0;
  6883. while (ACK_WaitCnt <= 2) ; //1s
  6884. if (textBox_RunInfo_Vol.Text != "---")
  6885. {
  6886. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6887. Delay_ms(500);
  6888. }
  6889. else
  6890. {
  6891. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  6892. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6893. ACK_WaitCnt = 0;
  6894. while (ACK_WaitCnt <= 2) ; //1s
  6895. if (textBox_RunInfo_Vol.Text != "---")
  6896. {
  6897. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6898. Delay_ms(500);
  6899. }
  6900. else
  6901. {
  6902. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  6903. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6904. ACK_WaitCnt = 0;
  6905. while (ACK_WaitCnt <= 2) ; //1s
  6906. if (textBox_RunInfo_Vol.Text != "---")
  6907. {
  6908. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6909. Delay_ms(500);
  6910. }
  6911. else
  6912. {
  6913. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  6914. label_FacModeStatus.Text = "存在故障!";
  6915. label_FacModeResult.BackColor = Color.Red;
  6916. label_FacModeResult.Text = "测试异常";
  6917. Delay_ms(500);
  6918. //存储异常并上传
  6919. FacMode_Stop(false);
  6920. return;
  6921. }
  6922. }
  6923. }
  6924. } while (false);
  6925. ushort Max = 0, Torque = 0;
  6926. //提示输入力矩信号
  6927. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟力矩信号输入" + "\r\n");
  6928. ACK_WaitCnt = 0;
  6929. while (ACK_WaitCnt <= 20) //10s
  6930. {
  6931. //获取力矩值
  6932. Torque = (ushort)Convert.ToInt16(textBox_RunInfo_Torque.Text.Split(' ')[0]);
  6933. if (Torque > Max)
  6934. Max = Torque;
  6935. if ((Max <= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[1])) &&
  6936. (Max >= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[0])) &&
  6937. (ACK_WaitCnt >= 6))
  6938. {
  6939. label_FacModeTq.BackColor = Color.Green;
  6940. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器正常" + " " + textBox_RunInfo_Torque.Text + "\r\n");
  6941. break;
  6942. }
  6943. }
  6944. if (ACK_WaitCnt >= 20)
  6945. {
  6946. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器异常" + " " + textBox_RunInfo_Torque.Text + "\r\n");
  6947. label_FacModeStatus.Text = "存在故障!";
  6948. label_FacModeResult.BackColor = Color.Red;
  6949. label_FacModeResult.Text = "测试异常";
  6950. Delay_ms(500);
  6951. //存储异常并上传
  6952. FacMode_Stop(false);
  6953. return;
  6954. }
  6955. }
  6956. else
  6957. {
  6958. label_FacModeTq.BackColor = Color.Yellow;
  6959. label_FacModeStatus.Text = "跳过力矩检测!";
  6960. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过力矩检测" + "\r\n");
  6961. Delay_ms(500);
  6962. }
  6963. //踏频检测
  6964. if (checkBox_FacCad.Checked)
  6965. {
  6966. label_FacModeStatus.Text = "踏频传感器检测!";
  6967. //发送指令进入配置模式
  6968. do
  6969. {
  6970. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  6971. {
  6972. break;
  6973. }
  6974. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6975. Code[0] = 0x01;
  6976. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6977. WriteACK = false;
  6978. WriteCnt = 0;
  6979. ACK_WaitCnt = 0;
  6980. while (ACK_WaitCnt <= 2) ; //1s
  6981. if (textBox_RunInfo_Vol.Text != "---")
  6982. {
  6983. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6984. Delay_ms(500);
  6985. }
  6986. else
  6987. {
  6988. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  6989. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6990. ACK_WaitCnt = 0;
  6991. while (ACK_WaitCnt <= 2) ; //1s
  6992. if (textBox_RunInfo_Vol.Text != "---")
  6993. {
  6994. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6995. Delay_ms(500);
  6996. }
  6997. else
  6998. {
  6999. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7000. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7001. ACK_WaitCnt = 0;
  7002. while (ACK_WaitCnt <= 2) ; //1s
  7003. if (textBox_RunInfo_Vol.Text != "---")
  7004. {
  7005. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7006. Delay_ms(500);
  7007. }
  7008. else
  7009. {
  7010. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7011. label_FacModeStatus.Text = "存在故障!";
  7012. label_FacModeResult.BackColor = Color.Red;
  7013. label_FacModeResult.Text = "测试异常";
  7014. Delay_ms(500);
  7015. //存储异常并上传
  7016. FacMode_Stop(false);
  7017. return;
  7018. }
  7019. }
  7020. }
  7021. } while (false);
  7022. ushort Max = 0, Cadence = 0;
  7023. //提示输入踏频信号
  7024. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟踏频信号输入" + "\r\n");
  7025. ACK_WaitCnt = 0;
  7026. while (ACK_WaitCnt <= 20) //10s
  7027. {
  7028. //获取踏频
  7029. Cadence = (ushort)Convert.ToInt16(textBox_RunInfo_Cadence.Text.Split(' ')[0]);
  7030. if (Cadence > Max)
  7031. Max = Cadence;
  7032. if ((Max <= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[1])) &&
  7033. (Max >= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[0])) &&
  7034. (ACK_WaitCnt >= 6))
  7035. {
  7036. label_FacModeCad.BackColor = Color.Green;
  7037. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器正常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  7038. break;
  7039. }
  7040. }
  7041. if (ACK_WaitCnt >= 20)
  7042. {
  7043. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器异常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  7044. label_FacModeStatus.Text = "存在故障!";
  7045. label_FacModeResult.BackColor = Color.Red;
  7046. label_FacModeResult.Text = "测试异常";
  7047. Delay_ms(500);
  7048. //存储异常并上传
  7049. FacMode_Stop(false);
  7050. return;
  7051. }
  7052. }
  7053. else
  7054. {
  7055. label_FacModeCad.BackColor = Color.Yellow;
  7056. label_FacModeStatus.Text = "跳过踏频检测!";
  7057. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过踏频检测" + "\r\n");
  7058. Delay_ms(500);
  7059. }
  7060. //转把检测
  7061. if (checkBox_FacThrrotleTest.Checked)
  7062. {
  7063. label_FacModeStatus.Text = "转把检测";
  7064. //发送指令进入配置模式
  7065. do
  7066. {
  7067. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  7068. {
  7069. break;
  7070. }
  7071. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  7072. Code[0] = 0x01;
  7073. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7074. WriteACK = false;
  7075. WriteCnt = 0;
  7076. ACK_WaitCnt = 0;
  7077. while (ACK_WaitCnt <= 2) ; //1s
  7078. if (textBox_RunInfo_Vol.Text != "---")
  7079. {
  7080. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7081. Delay_ms(500);
  7082. }
  7083. else
  7084. {
  7085. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  7086. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7087. ACK_WaitCnt = 0;
  7088. while (ACK_WaitCnt <= 2) ; //1s
  7089. if (textBox_RunInfo_Vol.Text != "---")
  7090. {
  7091. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7092. Delay_ms(500);
  7093. }
  7094. else
  7095. {
  7096. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7097. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7098. ACK_WaitCnt = 0;
  7099. while (ACK_WaitCnt <= 2) ; //1s
  7100. if (textBox_RunInfo_Vol.Text != "---")
  7101. {
  7102. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7103. Delay_ms(500);
  7104. }
  7105. else
  7106. {
  7107. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7108. label_FacModeStatus.Text = "存在故障!";
  7109. label_FacModeResult.BackColor = Color.Red;
  7110. label_FacModeResult.Text = "测试异常";
  7111. Delay_ms(500);
  7112. //存储异常并上传
  7113. FacMode_Stop(false);
  7114. return;
  7115. }
  7116. }
  7117. }
  7118. } while (false);
  7119. //进入TURBO档
  7120. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把检测,发送指令进入TURBO" + "\r\n");
  7121. Code[0] = 0x04;
  7122. Code[1] = 0xF0;
  7123. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7124. WriteACK = false;
  7125. WriteCnt = 0;
  7126. ACK_WaitCnt = 0;
  7127. while (ACK_WaitCnt <= 2) ; //1s
  7128. if (textBox_RunInfo_GearSt.Text != "TURBO")
  7129. {
  7130. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO,第1次重发" + "\r\n");
  7131. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7132. ACK_WaitCnt = 0;
  7133. while (ACK_WaitCnt <= 2) ; //1s
  7134. if (textBox_RunInfo_GearSt.Text != "TURBO")
  7135. {
  7136. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO,第2次重发" + "\r\n");
  7137. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7138. ACK_WaitCnt = 0;
  7139. while (ACK_WaitCnt <= 2) ; //1s
  7140. if (textBox_RunInfo_GearSt.Text != "TURBO")
  7141. {
  7142. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO异常" + "\r\n");
  7143. label_FacModeStatus.Text = "存在故障!";
  7144. label_FacModeResult.BackColor = Color.Red;
  7145. label_FacModeResult.Text = "测试异常";
  7146. Delay_ms(500);
  7147. //存储异常并上传
  7148. FacMode_Stop(false);
  7149. return;
  7150. }
  7151. }
  7152. }
  7153. //进入TURBO后,如果电机直接启动,认为转把电压异常
  7154. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把自检,请松开转把" + "\r\n");
  7155. Delay_ms(3000);
  7156. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) > 500)
  7157. {
  7158. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把电压异常" + "\r\n");
  7159. label_FacModeStatus.Text = "存在故障!";
  7160. label_FacModeResult.BackColor = Color.Red;
  7161. label_FacModeResult.Text = "测试异常";
  7162. Delay_ms(500);
  7163. //存储异常并上传
  7164. FacMode_Stop(false);
  7165. return;
  7166. }
  7167. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把自检正常" + "\r\n");
  7168. Delay_ms(500);
  7169. //提示转动转把
  7170. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入TURBO,10s内转动转把" + "\r\n");
  7171. ACK_WaitCnt = 0;
  7172. while (ACK_WaitCnt <= 20)
  7173. {
  7174. if ((Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) > 500) && (ACK_WaitCnt >= 10))
  7175. {
  7176. label_FacModeGas.BackColor = Color.Green;
  7177. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能正常,松开转把" + "\r\n");
  7178. break;
  7179. }
  7180. }
  7181. if (ACK_WaitCnt >= 20) //转把超时
  7182. {
  7183. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能异常,松开转把" + "\r\n");
  7184. label_FacModeStatus.Text = "存在故障!";
  7185. label_FacModeResult.BackColor = Color.Red;
  7186. label_FacModeResult.Text = "测试异常";
  7187. Delay_ms(500);
  7188. //存储异常并上传
  7189. FacMode_Stop(false);
  7190. return;
  7191. }
  7192. }
  7193. else
  7194. {
  7195. label_FacModeGas.BackColor = Color.Yellow;
  7196. label_FacModeStatus.Text = "跳过转把检测!";
  7197. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过转把检测" + "\r\n");
  7198. Delay_ms(500);
  7199. }
  7200. //刹车检测
  7201. if (checkBox_FacBreakTest.Checked)
  7202. {
  7203. label_FacModeStatus.Text = "刹把检测";
  7204. //发送指令进入配置模式
  7205. do
  7206. {
  7207. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  7208. {
  7209. break;
  7210. }
  7211. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  7212. Code[0] = 0x01;
  7213. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7214. WriteACK = false;
  7215. WriteCnt = 0;
  7216. ACK_WaitCnt = 0;
  7217. while (ACK_WaitCnt <= 2) ; //1s
  7218. if (textBox_RunInfo_Vol.Text != "---")
  7219. {
  7220. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7221. Delay_ms(500);
  7222. }
  7223. else
  7224. {
  7225. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  7226. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7227. ACK_WaitCnt = 0;
  7228. while (ACK_WaitCnt <= 2) ; //1s
  7229. if (textBox_RunInfo_Vol.Text != "---")
  7230. {
  7231. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7232. Delay_ms(500);
  7233. }
  7234. else
  7235. {
  7236. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7237. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7238. ACK_WaitCnt = 0;
  7239. while (ACK_WaitCnt <= 2) ; //1s
  7240. if (textBox_RunInfo_Vol.Text != "---")
  7241. {
  7242. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7243. Delay_ms(500);
  7244. }
  7245. else
  7246. {
  7247. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7248. label_FacModeStatus.Text = "存在故障!";
  7249. label_FacModeResult.BackColor = Color.Red;
  7250. label_FacModeResult.Text = "测试异常";
  7251. Delay_ms(500);
  7252. //存储异常并上传
  7253. FacMode_Stop(false);
  7254. return;
  7255. }
  7256. }
  7257. }
  7258. } while (false);
  7259. //测试前先确定电机已停止
  7260. UInt16 WaitTime = 10;
  7261. do
  7262. {
  7263. WaitTime--;
  7264. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 100)
  7265. {
  7266. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机停止,开始进行剎把检测,进入WALK" + "\r\n");
  7267. break;
  7268. }
  7269. if (WaitTime == 0)
  7270. {
  7271. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机无法停止,剎把检测异常" + "\r\n");
  7272. label_FacModeStatus.Text = "存在故障!";
  7273. label_FacModeResult.BackColor = Color.Red;
  7274. label_FacModeResult.Text = "测试异常";
  7275. Delay_ms(500);
  7276. //存储异常并上传
  7277. FacMode_Stop(false);
  7278. return;
  7279. }
  7280. Delay_ms(500);
  7281. } while (true);
  7282. //设置转速100%
  7283. var Data = new byte[1];
  7284. Data[0] = (byte)100;
  7285. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7286. Delay_ms(500);
  7287. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7288. Delay_ms(500);
  7289. //启动电机进入WALK模式
  7290. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把检测,进入WALK" + "\r\n");
  7291. Code[0] = 0x22;
  7292. Code[1] = 0xF0;
  7293. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7294. WriteACK = false;
  7295. WriteCnt = 0;
  7296. ACK_WaitCnt = 0;
  7297. while (ACK_WaitCnt <= 2) ; //1s
  7298. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 500))
  7299. {
  7300. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第1次重发" + "\r\n");
  7301. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7302. ACK_WaitCnt = 0;
  7303. while (ACK_WaitCnt <= 2) ; //1s
  7304. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 500))
  7305. {
  7306. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第2次重发" + "\r\n");
  7307. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7308. ACK_WaitCnt = 0;
  7309. while (ACK_WaitCnt <= 2) ; //1s
  7310. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 500))
  7311. {
  7312. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
  7313. label_FacModeStatus.Text = "存在故障!";
  7314. label_FacModeResult.BackColor = Color.Red;
  7315. label_FacModeResult.Text = "测试异常";
  7316. Delay_ms(500);
  7317. //存储异常并上传
  7318. FacMode_Stop(false);
  7319. return;
  7320. }
  7321. }
  7322. }
  7323. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,10s内操作剎把" + "\r\n");
  7324. ACK_WaitCnt = 0;
  7325. while (ACK_WaitCnt <= 20)
  7326. {
  7327. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 100)
  7328. {
  7329. label_FacModeBreak.BackColor = Color.Green;
  7330. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把功能正常,松开剎把" + "\r\n");
  7331. break;
  7332. }
  7333. }
  7334. if (ACK_WaitCnt >= 20) //剎把超时
  7335. {
  7336. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速:" + textBox_RunInfo_MotorSpeed.Text + "," + "剎把功能异常,松开剎把" + "\r\n");
  7337. label_FacModeStatus.Text = "存在故障!";
  7338. label_FacModeResult.BackColor = Color.Red;
  7339. label_FacModeResult.Text = "测试异常";
  7340. Delay_ms(500);
  7341. //存储异常并上传
  7342. FacMode_Stop(false);
  7343. return;
  7344. }
  7345. //停止电机
  7346. Code[0] = 0x00;
  7347. Code[1] = 0xF0;
  7348. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7349. WriteACK = false;
  7350. WriteCnt = 0;
  7351. ACK_WaitCnt = 0;
  7352. while (ACK_WaitCnt <= 2) ; //1s
  7353. if (textBox_RunInfo_GearSt.Text != "OFF")
  7354. {
  7355. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK,第1次重发" + "\r\n");
  7356. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7357. ACK_WaitCnt = 0;
  7358. while (ACK_WaitCnt <= 2) ; //1s
  7359. if (textBox_RunInfo_GearSt.Text != "OFF")
  7360. {
  7361. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK,第2次重发" + "\r\n");
  7362. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7363. ACK_WaitCnt = 0;
  7364. while (ACK_WaitCnt <= 2) ; //1s
  7365. if (textBox_RunInfo_GearSt.Text != "OFF")
  7366. {
  7367. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
  7368. label_FacModeStatus.Text = "存在故障!";
  7369. label_FacModeResult.BackColor = Color.Red;
  7370. label_FacModeResult.Text = "测试异常";
  7371. Delay_ms(500);
  7372. //存储异常并上传
  7373. FacMode_Stop(false);
  7374. return;
  7375. }
  7376. }
  7377. }
  7378. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK" + "\r\n");
  7379. Delay_ms(500);
  7380. }
  7381. else
  7382. {
  7383. label_FacModeBreak.BackColor = Color.Yellow;
  7384. label_FacModeStatus.Text = "跳过刹车检测!";
  7385. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过刹车检测" + "\r\n");
  7386. Delay_ms(500);
  7387. }
  7388. //前后灯检测
  7389. if (checkBox_FacLightTest.Checked)
  7390. {
  7391. //前后灯检测
  7392. label_FacModeStatus.Text = "前后灯检测";
  7393. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开灯指令" + "\r\n");
  7394. //发送指令打开车灯
  7395. Code[0] = 0x00;
  7396. Code[1] = 0xF1;
  7397. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7398. WriteACK = false;
  7399. WriteCnt = 0;
  7400. ACK_WaitCnt = 0;
  7401. while (ACK_WaitCnt <= 2) ; //1s
  7402. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7403. {
  7404. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令,第1次重发" + "\r\n");
  7405. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7406. ACK_WaitCnt = 0;
  7407. while (ACK_WaitCnt <= 2); //1s
  7408. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7409. {
  7410. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令,第2次重发" + "\r\n");
  7411. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7412. ACK_WaitCnt = 0;
  7413. while (ACK_WaitCnt <= 2) ; //1s
  7414. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7415. {
  7416. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令发送异常" + "\r\n");
  7417. label_FacModeStatus.Text = "存在故障!";
  7418. label_FacModeResult.BackColor = Color.Red;
  7419. label_FacModeResult.Text = "测试异常";
  7420. Delay_ms(500);
  7421. //存储异常并上传
  7422. FacMode_Stop(false);
  7423. return;
  7424. }
  7425. }
  7426. }
  7427. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已打开前后灯" + "\r\n");
  7428. Delay_ms(500);
  7429. //提示检查灯压是否正确
  7430. if (MessageBox.Show("前后灯是否正常开启?", "前后灯判断", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  7431. {
  7432. label_FacModeLightF.BackColor = Color.Green;
  7433. label_FacModeLightB.BackColor = Color.Green;
  7434. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯正常" + "\r\n");
  7435. Delay_ms(500);
  7436. }
  7437. else
  7438. {
  7439. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯异常" + "\r\n");
  7440. label_FacModeStatus.Text = "存在故障!";
  7441. label_FacModeResult.BackColor = Color.Red;
  7442. label_FacModeResult.Text = "测试异常";
  7443. Delay_ms(500);
  7444. //存储异常并上传
  7445. FacMode_Stop(false);
  7446. return;
  7447. }
  7448. //发送指令关闭车灯
  7449. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关灯指令" + "\r\n");
  7450. Code[0] = 0x00;
  7451. Code[1] = 0xF0;
  7452. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7453. WriteACK = false;
  7454. WriteCnt = 0;
  7455. ACK_WaitCnt = 0;
  7456. while (ACK_WaitCnt <= 2) ; //1s
  7457. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7458. {
  7459. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令,第1次重发" + "\r\n");
  7460. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7461. ACK_WaitCnt = 0;
  7462. while (ACK_WaitCnt <= 2) ; //1s
  7463. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7464. {
  7465. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令,第2次重发" + "\r\n");
  7466. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7467. ACK_WaitCnt = 0;
  7468. while (ACK_WaitCnt <= 2) ; //1s
  7469. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7470. {
  7471. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令发送异常" + "\r\n");
  7472. label_FacModeStatus.Text = "存在故障!";
  7473. label_FacModeResult.BackColor = Color.Red;
  7474. label_FacModeResult.Text = "测试异常";
  7475. Delay_ms(500);
  7476. //存储异常并上传
  7477. FacMode_Stop(false);
  7478. return;
  7479. }
  7480. }
  7481. }
  7482. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已关闭前后灯" + "\r\n");
  7483. Delay_ms(500);
  7484. }
  7485. else
  7486. {
  7487. label_FacModeLightF.BackColor = Color.Yellow;
  7488. label_FacModeLightB.BackColor = Color.Yellow;
  7489. label_FacModeStatus.Text = "跳过前后灯检测!";
  7490. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过前后灯检测" + "\r\n");
  7491. Delay_ms(500);
  7492. }
  7493. //软件版本检测
  7494. do
  7495. {
  7496. label_FacModeStatus.Text = "软件版本确认";
  7497. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  7498. //发送指令读取版本
  7499. Class_Motor_Ver.Mode = "---";
  7500. Class_Motor_Ver.SN = "---";
  7501. Class_Motor_Ver.HW = "---";
  7502. Class_Motor_Ver.FW = "---";
  7503. Class_Motor_Ver.Special = "---";
  7504. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7505. ACK_WaitCnt = 0;
  7506. while (ACK_WaitCnt <= 2) ; //1s
  7507. if (Class_Motor_Ver.Mode == "---")
  7508. {
  7509. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第1次重发" + "\r\n");
  7510. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7511. ACK_WaitCnt = 0;
  7512. while (ACK_WaitCnt <= 2) ; //1s
  7513. if (Class_Motor_Ver.Mode == "---")
  7514. {
  7515. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第2次重发" + "\r\n");
  7516. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7517. ACK_WaitCnt = 0;
  7518. while (ACK_WaitCnt <= 2) ; //1s
  7519. if (Class_Motor_Ver.Mode == "---")
  7520. {
  7521. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息失败" + "\r\n");
  7522. label_FacModeStatus.Text = "存在故障!";
  7523. label_FacModeResult.BackColor = Color.Red;
  7524. label_FacModeResult.Text = "测试异常";
  7525. Delay_ms(500);
  7526. //存储异常并上传
  7527. FacMode_Stop(false);
  7528. return;
  7529. }
  7530. }
  7531. }
  7532. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  7533. richTextBox_FacModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  7534. richTextBox_FacModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  7535. richTextBox_FacModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  7536. richTextBox_FacModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  7537. richTextBox_FacModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  7538. //判断版本是否正确
  7539. string VerCheck = comboBox_FacModeCfgFile.Text.Split('_')[3] + "_" + comboBox_FacModeCfgFile.Text.Split('_')[4];
  7540. string VerRead = "";
  7541. try
  7542. {
  7543. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  7544. }
  7545. catch (System.Exception)
  7546. {
  7547. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  7548. label_FacModeStatus.Text = "存在故障!";
  7549. label_FacModeResult.BackColor = Color.Red;
  7550. label_FacModeResult.Text = "测试异常";
  7551. Delay_ms(500);
  7552. //存储异常并上传
  7553. FacMode_Stop(false);
  7554. return;
  7555. }
  7556. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  7557. {
  7558. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
  7559. label_FacModeStatus.Text = "存在故障!";
  7560. label_FacModeResult.BackColor = Color.Red;
  7561. label_FacModeResult.Text = "测试异常";
  7562. Delay_ms(500);
  7563. //存储异常并上传
  7564. FacMode_Stop(false);
  7565. return;
  7566. }
  7567. label_FacModeFWVersion.BackColor = Color.Green;
  7568. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  7569. Delay_ms(500);
  7570. } while (false);
  7571. //测试合格
  7572. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  7573. label_FacModeStatus.Text = "测试结束!";
  7574. label_FacModeResult.BackColor = Color.Green;
  7575. label_FacModeResult.Text = "测试合格";
  7576. Delay_ms(500);
  7577. //存储并上传
  7578. FacMode_Stop(true);
  7579. return;
  7580. }
  7581. private void FacModelLabelInit()
  7582. {
  7583. //测试状态标签
  7584. label_FacModeResult.BackColor = Color.Yellow;
  7585. label_FacModeResult.Text = "测试中";
  7586. //测试过程标签
  7587. label_FacModeStatus.Text = "测试就绪";
  7588. //测试结果标签
  7589. foreach (Control c in groupBox28.Controls)
  7590. {
  7591. if (c is Label)
  7592. {
  7593. if (c.Text == string.Empty)
  7594. c.BackColor = Color.Red;
  7595. }
  7596. }
  7597. }
  7598. private void comboBox_CheckModeCfgDate_Click(object sender, EventArgs e)
  7599. {
  7600. //更新生产配置文件目录
  7601. GetDateList(false);
  7602. }
  7603. private void comboBox_FacModeCfgDate_Click(object sender, EventArgs e)
  7604. {
  7605. //更新生产配置文件目录
  7606. GetDateList(false);
  7607. }
  7608. private void richTextBox_FacModeLog_TextChanged(object sender, EventArgs e)
  7609. {
  7610. richTextBox_FacModeLog.SelectionStart = richTextBox_FacModeLog.Text.Length;
  7611. richTextBox_FacModeLog.ScrollToCaret();
  7612. }
  7613. /// <summary>
  7614. /// 参数检验测试停止
  7615. /// </summary>
  7616. /// <param name="OK_Flag"></param>
  7617. private void CheckMode_Stop(bool OK_Flag)
  7618. {
  7619. //打开开始按钮
  7620. button_CheckModeStart.Enabled = true;
  7621. //导出电机参数
  7622. string Params = "";
  7623. do
  7624. {
  7625. if (!OK_Flag)
  7626. {
  7627. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试异常,停止导出" + "\r\n");
  7628. break;
  7629. }
  7630. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "导出电机存储参数" + "\r\n");
  7631. //读取一次马达参数
  7632. richTextBox_MotorParam.Clear();
  7633. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break; ;
  7634. Delay_ms(100);
  7635. Params += "[马达参数]" + "\r\n" + richTextBox_MotorParam.Text + "\r\n";
  7636. Params += "\r\n";
  7637. //读取一次整车参数
  7638. richTextBox_BikeParam.Clear();
  7639. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  7640. Delay_ms(100);
  7641. Params += "[整车参数]" + "\r\n" + richTextBox_BikeParam.Text + "\r\n";
  7642. Params += "\r\n";
  7643. //读取一次控制参数
  7644. richTextBox_ControlParam.Clear();
  7645. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  7646. Delay_ms(100);
  7647. Params += "[控制参数]" + "\r\n" + richTextBox_ControlParam.Text + "\r\n";
  7648. Params += "\r\n";
  7649. //查询传感器
  7650. richTextBox_SensorParam.Clear();
  7651. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  7652. Delay_ms(100);
  7653. Params += "[传感器参数]" + "\r\n" + richTextBox_SensorParam.Text + "\r\n";
  7654. Params += "\r\n";
  7655. //读取15次助力参数
  7656. Params += "[助力参数]" + "\r\n";
  7657. for (int i = 1; i <= 15; i++)
  7658. {
  7659. var ConfigParam = new byte[4];
  7660. richTextBox_AssistParam.Clear();
  7661. ConfigParam[0] = (byte)(i & 0xFF);
  7662. ConfigParam[1] = (byte)(i >> 8);
  7663. ConfigParam[2] = (byte)(((i >= 5) ? 5 : i) & 0xFF);
  7664. ConfigParam[3] = (byte)(((i >= 5) ? 5 : i) >> 8);
  7665. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  7666. Delay_ms(200);
  7667. Params += richTextBox_AssistParam.Text + "\r\n";
  7668. Params += "\r\n";
  7669. }
  7670. //读取一次调试信息
  7671. richTextBox_DebugParam.Clear();
  7672. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  7673. Delay_ms(100);
  7674. Params += "[调试参数]" + "\r\n" + richTextBox_DebugParam.Text + "\r\n";
  7675. Params += "\r\n";
  7676. //读取一次历史信息
  7677. richTextBox_Record.Clear();
  7678. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  7679. Delay_ms(100);
  7680. Params += "[历史信息]" + "\r\n" + richTextBox_Record.Text + "\r\n";
  7681. Params += "\r\n";
  7682. //读取一次MOS内阻校准参数
  7683. foreach (Control c in groupBox21.Controls)
  7684. {
  7685. if (c is TextBox)
  7686. c.Text = "";
  7687. }
  7688. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  7689. Delay_ms(100);
  7690. Params += "[MOS内阻校准参数]" + "\r\n";
  7691. Params += textBox_MOS_K1.Text + ", " + textBox_MOS_K2.Text + ", " + textBox_MOS_K3.Text + ", " + textBox_MOS_K4.Text + ", "
  7692. + textBox_MOS_K5.Text + ", " + textBox_MOS_R1.Text + ", " + textBox_MOS_R2.Text + ", " + textBox_MOS_R3.Text + ", " + "\r\n";
  7693. Params += "\r\n";
  7694. //读取一次整车参数2
  7695. richTextBox_BikeParam2.Clear();
  7696. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null)) break;
  7697. Delay_ms(100);
  7698. Params += "[整车参数2]" + "\r\n" + richTextBox_BikeParam2.Text + "\r\n";
  7699. Params += "\r\n";
  7700. //读取一次用户骑行参数
  7701. richTextBox_UsrRidesParam.Clear();
  7702. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  7703. Delay_ms(100);
  7704. Params += "[用户骑行参数]" + "\r\n" + richTextBox_UsrRidesParam.Text + "\r\n";
  7705. Params += "\r\n";
  7706. //读取一次生产信息
  7707. textBox_MAC.Text = "";
  7708. textBox_MACAdd.Text = "";
  7709. textBox_MACDate.Text = "";
  7710. textBox_PP.Text = "";
  7711. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  7712. Delay_ms(100);
  7713. Params += "[生产信息]" + "\r\n";
  7714. Params += "生产商: " + textBox_MAC.Text + "\r\n";
  7715. Params += "生产地: " + textBox_MACAdd.Text + "\r\n";
  7716. Params += "生产日期: " + textBox_MACDate.Text + "\r\n";
  7717. Params += "产品标识: " + textBox_PP.Text + "\r\n";
  7718. Params += "\r\n";
  7719. //读取一次自定义信息
  7720. textBox_User1.Text = "---";
  7721. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  7722. Delay_ms(100);
  7723. textBox_User2.Text = "---";
  7724. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  7725. Delay_ms(100);
  7726. textBox_User3.Text = "---";
  7727. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  7728. Delay_ms(100);
  7729. Params += "[自定义信息]" + "\r\n";
  7730. Params += "自定义1: " + textBox_User1.Text + "\r\n";
  7731. Params += "自定义2: " + textBox_User2.Text + "\r\n";
  7732. Params += "自定义3: " + textBox_User3.Text + "\r\n";
  7733. Params += "\r\n";
  7734. //读取一次密钥
  7735. textBox_Key.Text = "---";
  7736. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  7737. Delay_ms(100);
  7738. Params += "[校验密钥]" + "\r\n" + textBox_Key.Text + "\r\n";
  7739. Params += "\r\n";
  7740. //读取一次存储标志
  7741. radioButton_EE_SaveYes.Checked = false;
  7742. radioButton_EE_SaveNo.Checked = false;
  7743. radioButton_SIP_SaveYes.Checked = false;
  7744. radioButton_SIP_SaveNo.Checked = false;
  7745. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  7746. Delay_ms(100);
  7747. Params += "[存储标志]" + "\r\n";
  7748. Params += "EEPROM: " + ((radioButton_EE_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  7749. Params += "SIP: " + ((radioButton_SIP_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  7750. Params += "\r\n";
  7751. } while (false);
  7752. //系统关机
  7753. var Code = new byte[32];//发送的指令数据
  7754. Code[0] = 0xF0;
  7755. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  7756. //关闭串口
  7757. //mySerialProcess.SerialClose(false);
  7758. //路径设置
  7759. string LocalSavePath = "";
  7760. string ServerSavePath = "";
  7761. if (OK_Flag)
  7762. {
  7763. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "OK\\";
  7764. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/OK/";
  7765. }
  7766. else
  7767. {
  7768. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "FAIL\\";
  7769. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/FAIL/";
  7770. }
  7771. if (Directory.Exists(LocalSavePath) == false)
  7772. {
  7773. Directory.CreateDirectory(LocalSavePath);
  7774. }
  7775. //保存和上传
  7776. string LogSavePath = "";
  7777. string LogSaveFileName = "";
  7778. string ProductInfo = textBox_CheckModeScan.Text.Replace(" ", "_"); ;
  7779. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  7780. if (Directory.Exists(LogSavePath) == false)
  7781. {
  7782. Directory.CreateDirectory(LogSavePath);
  7783. }
  7784. //测试页面
  7785. Double scaleX = PrimaryScreen.ScaleX;
  7786. Double scaleY = PrimaryScreen.ScaleY;
  7787. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  7788. Graphics g = Graphics.FromImage(bit);
  7789. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  7790. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  7791. bit.Save(LogSaveFileName);
  7792. //上传测试页面到服务器
  7793. if (myFtp.IsNetConnected == true)
  7794. {
  7795. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  7796. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  7797. {
  7798. myFtp.MakeDir(ServerSavePath + DateNow);
  7799. }
  7800. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  7801. {
  7802. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  7803. }
  7804. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  7805. if (result == true)
  7806. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  7807. }
  7808. //测试记录
  7809. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  7810. string file_str = "";
  7811. file_str += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  7812. file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  7813. file_str += "检验记录:\r\n" + richTextBox_CheckModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  7814. file_str += "检验结果:\r\n" + label_CheckModeResult.Text + "\r\n\r\n";
  7815. file_str += Local_HdInformation;
  7816. file_str += "\r\n电机存储参数:\r\n" + Params + "\r\n";
  7817. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  7818. //上传测试记录到服务器
  7819. if (myFtp.IsNetConnected == true)
  7820. {
  7821. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  7822. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  7823. {
  7824. myFtp.MakeDir(ServerSavePath + DateNow);
  7825. }
  7826. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  7827. {
  7828. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  7829. }
  7830. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  7831. if (result == true)
  7832. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  7833. }
  7834. //扫码框清空
  7835. textBox_CheckModeScan.Text = "";
  7836. }
  7837. /// <summary>
  7838. /// 参数检验开始
  7839. /// </summary>
  7840. /// <param name="sender"></param>
  7841. /// <param name="e"></param>
  7842. private void button_CheckModeStart_Click(object sender, EventArgs e)
  7843. {
  7844. //测试项目关闭编辑
  7845. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  7846. foreach (Control c in groupBox29.Controls)
  7847. {
  7848. if (c is CheckBox)
  7849. c.Enabled = false;
  7850. }
  7851. ReadLockStatus = true;
  7852. //检查配置文件
  7853. if (comboBox_CheckModeCfgFile.Text == "")
  7854. {
  7855. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  7856. return;
  7857. }
  7858. //开始测试
  7859. CheckTestStart();
  7860. }
  7861. /// <summary>
  7862. /// 参数检验测试子函数
  7863. /// </summary>
  7864. private void CheckTestStart()
  7865. {
  7866. //初始化标签
  7867. CheckModeLabelInit();
  7868. richTextBox_CheckModeLog.Clear();
  7869. //按钮禁止操作
  7870. button_CheckModeStart.Enabled = false;
  7871. //记录配置文件
  7872. richTextBox_CheckModeLog.AppendText("配置文件:" + comboBox_CheckModeCfgDate.Text + " / " + comboBox_CheckModeCfgFile.Text + "\r\n");
  7873. //检查打标信息
  7874. label_CheckModeStatus.Text = "检查扫码信息";
  7875. Delay_ms(500);
  7876. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  7877. if (textBox_CheckModeScan.Text == string.Empty)
  7878. {
  7879. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  7880. button__FacMode_Start.Enabled = false;
  7881. return;
  7882. }
  7883. try
  7884. {
  7885. if (中置电机ToolStripMenuItem.Checked == true)
  7886. {
  7887. if (textBox_CheckModeScan.Text.Split(' ').Length != 7)
  7888. {
  7889. label_CheckModeStatus.Text = "存在故障!";
  7890. label_CheckModeResult.BackColor = Color.Red;
  7891. label_CheckModeResult.Text = "标签格式错误";
  7892. button_CheckModeStart.Enabled = true;
  7893. return;
  7894. }
  7895. }
  7896. else if (轮毂电机ToolStripMenuItem.Checked == true)
  7897. {
  7898. if (textBox_CheckModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  7899. {
  7900. label_CheckModeStatus.Text = "存在故障!";
  7901. label_CheckModeResult.BackColor = Color.Red;
  7902. label_CheckModeResult.Text = "标签格式错误";
  7903. button_CheckModeStart.Enabled = true;
  7904. return;
  7905. }
  7906. }
  7907. }
  7908. catch (System.Exception)
  7909. {
  7910. label_CheckModeStatus.Text = "存在故障!";
  7911. label_CheckModeResult.BackColor = Color.Red;
  7912. label_CheckModeResult.Text = "标签格式错误";
  7913. button_CheckModeStart.Enabled = true;
  7914. return;
  7915. }
  7916. //打开串口
  7917. mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false);
  7918. if (!mySerialProcess.mySerial.IsOpen)
  7919. {
  7920. MessageBox.Show("请检查串口连接!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  7921. button__FacMode_Start.Enabled = false;
  7922. return;
  7923. }
  7924. //流水号计数
  7925. int serial = Convert.ToInt32(label_CheckModeSerial.Text);
  7926. serial += 1;
  7927. label_CheckModeSerial.Text = serial.ToString();
  7928. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, serial.ToString());
  7929. //创建线程,执行测试任务
  7930. Thread th = new Thread(CheckModeTest_Task);
  7931. th.Start();
  7932. }
  7933. /// <summary>
  7934. /// 执行一次测试任务
  7935. /// </summary>
  7936. private void CheckModeTest_Task()
  7937. {
  7938. //开始测试
  7939. richTextBox_CheckModeLog.AppendText("产品标签:" + textBox_CheckModeScan.Text + "\r\n");
  7940. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  7941. //变量定义
  7942. var Code = new byte[255];//发送的指令数据
  7943. ushort DataTemp;
  7944. short DataTemp_Int16;
  7945. string ResultPathName = "";
  7946. label_CheckModeStatus.Text = "开始测试";
  7947. BootInfo = "";
  7948. Delay_ms(500);
  7949. label_CheckModeStatus.Text = "系统开机";
  7950. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  7951. if (uARTToolStripMenuItem.Checked)
  7952. {
  7953. Code[0] = (byte)'R';
  7954. Code[1] = (byte)'E';
  7955. Code[2] = (byte)'S';
  7956. Code[3] = (byte)'E';
  7957. Code[4] = (byte)'T';
  7958. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  7959. Delay_ms(500);
  7960. }
  7961. //系统开机,确保测试前先关机,发送关机指令再发送开机指令
  7962. //确保测试前先关机,发送关机指令再发送开机指令
  7963. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  7964. Code[0] = 0xF0;
  7965. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  7966. Delay_ms(1500);
  7967. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  7968. Code[0] = 0xF1;
  7969. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  7970. ACK_WaitCnt = 0;
  7971. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  7972. while (ACK_WaitCnt <= 20) ; //10s
  7973. //检查BOOT版本
  7974. if (BootInfo != string.Empty)
  7975. {
  7976. label_CheckModeBoot.BackColor = Color.Green;
  7977. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  7978. Delay_ms(500);
  7979. }
  7980. else
  7981. {
  7982. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
  7983. label_CheckModeStatus.Text = "存在故障!";
  7984. label_CheckModeResult.BackColor = Color.Red;
  7985. label_CheckModeResult.Text = "测试异常";
  7986. Delay_ms(500);
  7987. //存储异常并上传
  7988. CheckMode_Stop(false);
  7989. return;
  7990. }
  7991. #if false
  7992. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  7993. {
  7994. Code[0] = 0x00;//5S协议
  7995. Code[1] = 0x00;
  7996. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  7997. Delay_ms(500);
  7998. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  7999. Delay_ms(500);
  8000. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  8001. }
  8002. #endif
  8003. //发送指令读取版本信息
  8004. do
  8005. {
  8006. label_CheckModeStatus.Text = "读取版本信息";
  8007. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  8008. //发送指令读取版本
  8009. Class_Motor_Ver.Mode = "---";
  8010. Class_Motor_Ver.SN = "---";
  8011. Class_Motor_Ver.HW = "---";
  8012. Class_Motor_Ver.FW = "---";
  8013. Class_Motor_Ver.Special = "---";
  8014. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  8015. ACK_WaitCnt = 0;
  8016. while (ACK_WaitCnt <= 2) ; //1s
  8017. if (Class_Motor_Ver.Mode == "---")
  8018. {
  8019. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第1次重发" + "\r\n");
  8020. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  8021. ACK_WaitCnt = 0;
  8022. while (ACK_WaitCnt <= 2) ; //1s
  8023. if (Class_Motor_Ver.Mode == "---")
  8024. {
  8025. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第2次重发" + "\r\n");
  8026. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  8027. ACK_WaitCnt = 0;
  8028. while (ACK_WaitCnt <= 2) ; //1s
  8029. if (Class_Motor_Ver.Mode == "---")
  8030. {
  8031. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取失败" + "\r\n");
  8032. label_CheckModeStatus.Text = "存在故障!";
  8033. label_CheckModeResult.BackColor = Color.Red;
  8034. label_CheckModeResult.Text = "测试异常";
  8035. Delay_ms(500);
  8036. //存储异常并上传
  8037. CheckMode_Stop(false);
  8038. return;
  8039. }
  8040. }
  8041. }
  8042. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  8043. Delay_ms(500);
  8044. } while (false);
  8045. //软件版本检查
  8046. if (checkBox_CheckModeFWVer.Checked)
  8047. {
  8048. richTextBox_CheckModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  8049. richTextBox_CheckModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  8050. richTextBox_CheckModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  8051. richTextBox_CheckModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  8052. richTextBox_CheckModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  8053. //判断版本是否正确
  8054. string VerCheck = comboBox_CheckModeCfgFile.Text.Split('_')[3] + "_" + comboBox_CheckModeCfgFile.Text.Split('_')[4];
  8055. string VerRead = "";
  8056. try
  8057. {
  8058. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  8059. }
  8060. catch (System.Exception)
  8061. {
  8062. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  8063. label_CheckModeStatus.Text = "存在故障!";
  8064. label_CheckModeResult.BackColor = Color.Red;
  8065. label_CheckModeResult.Text = "测试异常";
  8066. Delay_ms(500);
  8067. //存储异常并上传
  8068. CheckMode_Stop(false);
  8069. return;
  8070. }
  8071. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  8072. {
  8073. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
  8074. label_CheckModeStatus.Text = "存在故障!";
  8075. label_CheckModeResult.BackColor = Color.Red;
  8076. label_CheckModeResult.Text = "测试异常";
  8077. Delay_ms(500);
  8078. //存储异常并上传
  8079. CheckMode_Stop(false);
  8080. return;
  8081. }
  8082. label_CheckModeFWVer.BackColor = Color.Green;
  8083. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  8084. Delay_ms(500);
  8085. }
  8086. else
  8087. {
  8088. label_CheckModeFWVer.BackColor = Color.Yellow;
  8089. label_CheckModeStatus.Text = "跳过软件版本查询";
  8090. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过软件版本查询" + "\r\n");
  8091. Delay_ms(500);
  8092. }
  8093. //打标信息核对
  8094. if (checkBox_CheckModeSN.Checked)
  8095. {
  8096. label_CheckModeStatus.Text = "核对打标信息";
  8097. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "核对打标信息" + "\r\n");
  8098. //根据扫码信息获取型号和SN
  8099. string ScanInfo = textBox_CheckModeScan.Text;
  8100. string regexInfo = "";
  8101. string[] InfoList = { "" };
  8102. try
  8103. {
  8104. if (中置电机ToolStripMenuItem.Checked == true)
  8105. {
  8106. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  8107. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  8108. }
  8109. else if (轮毂电机ToolStripMenuItem.Checked == true)
  8110. {
  8111. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  8112. string Model = InfoList[0];
  8113. string Spec = InfoList[1];
  8114. string Sn = InfoList[2];
  8115. InfoList[0] = Model.Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  8116. InfoList[1] = Sn;
  8117. }
  8118. }
  8119. catch
  8120. {
  8121. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  8122. label_FacModeStatus.Text = "存在故障!";
  8123. label_FacModeResult.BackColor = Color.Red;
  8124. label_FacModeResult.Text = "标签格式错误";
  8125. Delay_ms(500);
  8126. //存储异常并上传
  8127. CheckMode_Stop(false);
  8128. return;
  8129. }
  8130. //核对型号
  8131. if (string.Equals(InfoList[0], Class_Motor_Ver.Mode) == false) //型号错误,直接结束
  8132. {
  8133. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号不一致" + "\r\n");
  8134. label_CheckModeStatus.Text = "存在故障!";
  8135. label_CheckModeResult.BackColor = Color.Red;
  8136. label_CheckModeResult.Text = "测试异常";
  8137. Delay_ms(500);
  8138. //存储异常并上传
  8139. CheckMode_Stop(false);
  8140. return;
  8141. }
  8142. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号一致" + "\r\n");
  8143. Delay_ms(500);
  8144. //核对SN
  8145. if (string.Equals(InfoList[1], Class_Motor_Ver.SN) == false) //型号错误,直接结束
  8146. {
  8147. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN不一致" + "\r\n");
  8148. label_CheckModeStatus.Text = "存在故障!";
  8149. label_CheckModeResult.BackColor = Color.Red;
  8150. label_CheckModeResult.Text = "测试异常";
  8151. Delay_ms(500);
  8152. //存储异常并上传
  8153. CheckMode_Stop(false);
  8154. return;
  8155. }
  8156. label_CheckModeSN.BackColor = Color.Green;
  8157. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN一致" + "\r\n");
  8158. Delay_ms(500);
  8159. }
  8160. else
  8161. {
  8162. label_CheckModeSN.BackColor = Color.Yellow;
  8163. label_CheckModeStatus.Text = "跳过打标信息确认";
  8164. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过打标信息确认" + "\r\n");
  8165. Delay_ms(500);
  8166. }
  8167. //参数检验
  8168. if (checkBox_CheckModeCfg.Checked)
  8169. {
  8170. //读取配置文件信息
  8171. label_CheckModeStatus.Text = "参数检查";
  8172. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  8173. //配置文件
  8174. List<byte[]> CmdList = new List<byte[]>();
  8175. Dictionary<string, string> ConfigCmd = new Dictionary<string, string>();//配置文件格式
  8176. //从服务器下载文件
  8177. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  8178. {
  8179. string SelectFile = "";
  8180. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "/" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  8181. if (File.Exists(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  8182. {
  8183. File.Delete(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  8184. }
  8185. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  8186. //打开文件
  8187. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  8188. ConfigCmd.Clear();
  8189. while (streamReader.Peek() != -1)
  8190. {
  8191. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  8192. if (fileLineInfo.Contains("["))
  8193. {
  8194. if (fileLineInfo.Contains("助力参数"))
  8195. {
  8196. fileLineInfo = streamReader.ReadLine();
  8197. }
  8198. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  8199. }
  8200. }
  8201. streamReader.Close();
  8202. }
  8203. //从本地加载文件
  8204. else
  8205. {
  8206. string SelectFile = "";
  8207. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  8208. //打开文件
  8209. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  8210. ConfigCmd.Clear();
  8211. while (streamReader.Peek() != -1)
  8212. {
  8213. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  8214. if (fileLineInfo.Contains("["))
  8215. {
  8216. if (fileLineInfo.Contains("助力参数"))
  8217. {
  8218. fileLineInfo = streamReader.ReadLine();
  8219. }
  8220. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  8221. }
  8222. }
  8223. streamReader.Close();
  8224. }
  8225. int CmdNum = ConfigCmd.Count(); //指令个数
  8226. Delay_ms(500);
  8227. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "\r\n");
  8228. Delay_ms(500);
  8229. //逐条读取比较
  8230. try
  8231. {
  8232. foreach (string key in ConfigCmd.Keys)
  8233. {
  8234. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令:" + "\r\n");
  8235. CmdRevStrTemp = "";
  8236. if (key.Contains("曲线"))
  8237. {
  8238. byte LineNum = 0;
  8239. var code = new byte[4];
  8240. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  8241. if (LineNum <= 5)
  8242. {
  8243. code[0] = (byte)(LineNum & 0xFF);
  8244. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8245. code[2] = (byte)(LineNum & 0xFF);
  8246. code[3] = (byte)((LineNum >> 8) & 0xFF);
  8247. }
  8248. else
  8249. {
  8250. code[0] = (byte)(LineNum & 0xFF);
  8251. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8252. code[2] = (byte)(5 & 0xFF);
  8253. code[3] = (byte)((5 >> 8) & 0xFF);
  8254. }
  8255. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  8256. }
  8257. else
  8258. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  8259. Delay_ms(500);
  8260. if (CmdRevStrTemp == string.Empty)
  8261. {
  8262. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令,第1次重发" + "\r\n");
  8263. if (key.Contains("曲线"))
  8264. {
  8265. byte LineNum = 0;
  8266. var code = new byte[4];
  8267. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  8268. if (LineNum <= 5)
  8269. {
  8270. code[0] = (byte)(LineNum & 0xFF);
  8271. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8272. code[2] = (byte)(LineNum & 0xFF);
  8273. code[3] = (byte)((LineNum >> 8) & 0xFF);
  8274. }
  8275. else
  8276. {
  8277. code[0] = (byte)(LineNum & 0xFF);
  8278. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8279. code[2] = (byte)(5 & 0xFF);
  8280. code[3] = (byte)((5 >> 8) & 0xFF);
  8281. }
  8282. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  8283. }
  8284. else
  8285. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  8286. Delay_ms(500);
  8287. if (CmdRevStrTemp == string.Empty)
  8288. {
  8289. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令,第2次重发" + "\r\n");
  8290. if (key.Contains("曲线"))
  8291. {
  8292. byte LineNum = 0;
  8293. var code = new byte[4];
  8294. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  8295. if (LineNum <= 5)
  8296. {
  8297. code[0] = (byte)(LineNum & 0xFF);
  8298. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8299. code[2] = (byte)(LineNum & 0xFF);
  8300. code[3] = (byte)((LineNum >> 8) & 0xFF);
  8301. }
  8302. else
  8303. {
  8304. code[0] = (byte)(LineNum & 0xFF);
  8305. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8306. code[2] = (byte)(5 & 0xFF);
  8307. code[3] = (byte)((5 >> 8) & 0xFF);
  8308. }
  8309. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  8310. }
  8311. else
  8312. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  8313. Delay_ms(500);
  8314. if (CmdRevStrTemp == string.Empty)
  8315. {
  8316. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "指令读取失败" + "\r\n");
  8317. label_CheckModeStatus.Text = "存在故障!";
  8318. label_CheckModeResult.BackColor = Color.Red;
  8319. label_CheckModeResult.Text = "测试异常";
  8320. Delay_ms(500);
  8321. //存储异常并上传
  8322. CheckMode_Stop(false);
  8323. return;
  8324. }
  8325. }
  8326. }
  8327. //比较当前指令,读取的配置文件和返回数据比较
  8328. string ParamWrite = ConfigCmd[key].Substring(24, ConfigCmd[key].Length - 40).Trim();
  8329. string ParamRead = "";
  8330. if (string.Compare(key, "[其它传感器参数]") == 0)
  8331. ParamRead = CmdRevStrTemp.Substring(90, CmdRevStrTemp.Length - 90).Trim(); //去掉去掉命令字、力矩传感器参数
  8332. else if (string.Compare(key, "[控制参数]") == 0)
  8333. ParamRead = CmdRevStrTemp.Substring(18, CmdRevStrTemp.Length - 18).Trim(); //去掉去掉命令字、位置零点
  8334. else
  8335. ParamRead = CmdRevStrTemp.Substring(6, CmdRevStrTemp.Length - 6).Trim(); //去掉命令字
  8336. if (ParamWrite.Contains(ParamRead))
  8337. {
  8338. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "一致" + "\r\n");
  8339. continue;
  8340. }
  8341. else
  8342. {
  8343. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "不一致" + "\r\n");
  8344. richTextBox_CheckModeLog.AppendText("写入参数:" + ParamWrite + "\r\n");
  8345. richTextBox_CheckModeLog.AppendText("读出参数:" + ParamRead + "\r\n");
  8346. label_CheckModeStatus.Text = "存在故障!";
  8347. label_CheckModeResult.BackColor = Color.Red;
  8348. label_CheckModeResult.Text = "测试异常";
  8349. Delay_ms(500);
  8350. //存储异常并上传
  8351. CheckMode_Stop(false);
  8352. return;
  8353. }
  8354. }
  8355. }
  8356. catch (System.Exception)
  8357. {
  8358. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数检验失败" + "\r\n");
  8359. label_CheckModeStatus.Text = "存在故障!";
  8360. label_CheckModeResult.BackColor = Color.Red;
  8361. label_CheckModeResult.Text = "测试异常";
  8362. Delay_ms(500);
  8363. //存储异常并上传
  8364. CheckMode_Stop(false);
  8365. return;
  8366. }
  8367. label_CheckModeCfg.BackColor = Color.Green;
  8368. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数检验正确" + "\r\n");
  8369. Delay_ms(500);
  8370. }
  8371. else
  8372. {
  8373. label_CheckModeCfg.BackColor = Color.Yellow;
  8374. label_CheckModeStatus.Text = "跳过参数检验";
  8375. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数检验" + "\r\n");
  8376. Delay_ms(500);
  8377. }
  8378. //读取力矩传感器
  8379. do
  8380. {
  8381. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据" + "\r\n");
  8382. //发送指令读取力矩传感器标定数据
  8383. CmdRevStrTemp = "";
  8384. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  8385. ACK_WaitCnt = 0;
  8386. while (ACK_WaitCnt <= 2) ; //1s
  8387. if (CmdRevStrTemp == string.Empty)
  8388. {
  8389. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据,第1次重发" + "\r\n");
  8390. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  8391. ACK_WaitCnt = 0;
  8392. while (ACK_WaitCnt <= 2) ; //1s
  8393. if (CmdRevStrTemp == string.Empty)
  8394. {
  8395. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据,第2次重发" + "\r\n");
  8396. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  8397. ACK_WaitCnt = 0;
  8398. while (ACK_WaitCnt <= 2) ; //1s
  8399. if (CmdRevStrTemp == string.Empty)
  8400. {
  8401. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取失败" + "\r\n");
  8402. label_CheckModeStatus.Text = "存在故障!";
  8403. label_CheckModeResult.BackColor = Color.Red;
  8404. label_CheckModeResult.Text = "测试异常";
  8405. Delay_ms(500);
  8406. //存储异常并上传
  8407. CheckMode_Stop(false);
  8408. return;
  8409. }
  8410. }
  8411. }
  8412. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取成功" + "\r\n");
  8413. //取力矩传感器数据
  8414. ushort ZeroInit, Zero1, Zero2, Zero3, ZeroNew;
  8415. ushort MaxTorque;
  8416. ushort K1_T, K1, K2_T, K2, K3_T, K3, K4_T, K4;
  8417. byte[] DataArray = mySerialProcess.HexStringToBytes(CmdRevStrTemp, true);
  8418. ushort Cmd = (ushort)((DataArray[0] << 8) + DataArray[1]);
  8419. if (Cmd != 0xB528)
  8420. {
  8421. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器参数错误,CMD: 0x" + Convert.ToString(Cmd, 16).PadLeft(2, '0').ToUpper() + "\r\n");
  8422. label_CheckModeStatus.Text = "存在故障!";
  8423. label_CheckModeResult.BackColor = Color.Red;
  8424. label_CheckModeResult.Text = "测试异常";
  8425. Delay_ms(500);
  8426. //存储异常并上传
  8427. CheckMode_Stop(false);
  8428. return;
  8429. }
  8430. ZeroInit = (ushort)((DataArray[3] << 8) + DataArray[2]);
  8431. Zero1 = (ushort)((DataArray[5] << 8) + DataArray[4]);
  8432. Zero2 = (ushort)((DataArray[7] << 8) + DataArray[6]);
  8433. Zero3 = (ushort)((DataArray[9] << 8) + DataArray[8]);
  8434. ZeroNew = (ushort)((DataArray[11] << 8) + DataArray[10]);
  8435. MaxTorque = (ushort)((DataArray[13] << 8) + DataArray[12]);
  8436. K1_T = (ushort)((DataArray[15] << 8) + DataArray[14]);
  8437. K1 = (ushort)((DataArray[17] << 8) + DataArray[16]);
  8438. K2_T = (ushort)((DataArray[19] << 8) + DataArray[18]);
  8439. K2 = (ushort)((DataArray[21] << 8) + DataArray[20]);
  8440. K3_T = (ushort)((DataArray[23] << 8) + DataArray[22]);
  8441. K3 = (ushort)((DataArray[25] << 8) + DataArray[24]);
  8442. K4_T = (ushort)((DataArray[27] << 8) + DataArray[26]);
  8443. K4 = (ushort)((DataArray[29] << 8) + DataArray[28]);
  8444. richTextBox_CheckModeLog.AppendText("力矩传感器零点: " + ZeroInit.ToString() + "," + Zero1.ToString() + "," +
  8445. Zero2.ToString() + "," + Zero3.ToString() + "," + ZeroNew.ToString() + "\r\n");
  8446. richTextBox_CheckModeLog.AppendText("最大力矩: " + MaxTorque.ToString() + "\r\n");
  8447. richTextBox_CheckModeLog.AppendText("力矩传感器标定: " + "[" + K1_T.ToString() + "," + K1.ToString() + "]" + "," +
  8448. "[" + K2_T.ToString() + "," + K2.ToString() + "]" + "," + "[" + K3_T.ToString() + "," + K3.ToString() + "]" + "," +
  8449. "[" + K4_T.ToString() + "," + K4.ToString() + "]" + "\r\n");
  8450. //传感器标定检验
  8451. if (checkBox_CheckModeTorque.Checked)
  8452. {
  8453. richTextBox_CheckModeLog.AppendText("力矩零点范围: " + TorqueParamsForm.Zero.Min.ToString() + " - " + TorqueParamsForm.Zero.Max.ToString() + "\r\n");
  8454. richTextBox_CheckModeLog.AppendText("K1范围: " + TorqueParamsForm.K1.T.ToString() + "," + TorqueParamsForm.K1.Min.ToString() + " - " + TorqueParamsForm.K1.Max.ToString() + "\r\n");
  8455. richTextBox_CheckModeLog.AppendText("K2范围: " + TorqueParamsForm.K2.T.ToString() + "," + TorqueParamsForm.K2.Min.ToString() + " - " + TorqueParamsForm.K2.Max.ToString() + "\r\n");
  8456. richTextBox_CheckModeLog.AppendText("K3范围: " + TorqueParamsForm.K3.T.ToString() + "," + TorqueParamsForm.K3.Min.ToString() + " - " + TorqueParamsForm.K3.Max.ToString() + "\r\n");
  8457. richTextBox_CheckModeLog.AppendText("K4范围: " + TorqueParamsForm.K4.T.ToString() + "," + TorqueParamsForm.K4.Min.ToString() + " - " + TorqueParamsForm.K4.Max.ToString() + "\r\n");
  8458. //与设置值比较
  8459. if ((ZeroInit <= TorqueParamsForm.Zero.Max) && (ZeroInit >= TorqueParamsForm.Zero.Min)
  8460. && (K1_T == TorqueParamsForm.K1.T) && (K1 <= TorqueParamsForm.K1.Max) && (K1 >= TorqueParamsForm.K1.Min)
  8461. && (K2_T == TorqueParamsForm.K2.T) && (K2 <= TorqueParamsForm.K2.Max) && (K2 >= TorqueParamsForm.K2.Min)
  8462. && (K3_T == TorqueParamsForm.K3.T) && (K3 <= TorqueParamsForm.K3.Max) && (K3 >= TorqueParamsForm.K3.Min)
  8463. && (K4_T == TorqueParamsForm.K4.T) && (K4 <= TorqueParamsForm.K4.Max) && (K4 >= TorqueParamsForm.K4.Min)
  8464. )
  8465. {
  8466. label_CheckModeTorque.BackColor = Color.Green;
  8467. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定正常" + "\r\n");
  8468. Delay_ms(500);
  8469. }
  8470. else
  8471. {
  8472. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定超范围" + "\r\n");
  8473. label_CheckModeStatus.Text = "存在故障!";
  8474. label_CheckModeResult.BackColor = Color.Red;
  8475. label_CheckModeResult.Text = "测试异常";
  8476. Delay_ms(500);
  8477. //存储异常并上传
  8478. CheckMode_Stop(false);
  8479. return;
  8480. }
  8481. }
  8482. else
  8483. {
  8484. label_CheckModeTorque.BackColor = Color.Yellow;
  8485. label_CheckModeStatus.Text = "跳过传感器标定检验";
  8486. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过传感器标定检验" + "\r\n");
  8487. Delay_ms(500);
  8488. }
  8489. } while (false);
  8490. //读取MOS内阻校准参数
  8491. do
  8492. {
  8493. if (checkBox_CheckModeMos.Checked)
  8494. {
  8495. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据" + "\r\n");
  8496. //读取显示校准返回数据
  8497. foreach (Control c in groupBox21.Controls)
  8498. {
  8499. if (c is TextBox)
  8500. c.Text = "";
  8501. }
  8502. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8503. ACK_WaitCnt = 0;
  8504. while (ACK_WaitCnt <= 2) ; //1s
  8505. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  8506. {
  8507. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据,第1次重发" + "\r\n");
  8508. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8509. ACK_WaitCnt = 0;
  8510. while (ACK_WaitCnt <= 2) ; //1s
  8511. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  8512. {
  8513. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据,第2次重发" + "\r\n");
  8514. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8515. ACK_WaitCnt = 0;
  8516. while (ACK_WaitCnt <= 2) ; //1s
  8517. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  8518. {
  8519. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果异常" + "\r\n");
  8520. label_CheckModeStatus.Text = "存在故障!";
  8521. label_CheckModeResult.BackColor = Color.Red;
  8522. label_CheckModeResult.Text = "测试异常";
  8523. Delay_ms(500);
  8524. //存储异常并上传
  8525. CheckMode_Stop(false);
  8526. return;
  8527. }
  8528. }
  8529. }
  8530. else
  8531. {
  8532. 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");
  8533. }
  8534. //与校准返回数据对比
  8535. string[] MOS_R1_Th = toolStripTextBox_MOS1.Text.Split(',');
  8536. string[] MOS_R2_Th = toolStripTextBox_MOS2.Text.Split(',');
  8537. string[] MOS_R3_Th = toolStripTextBox_MOS3.Text.Split(',');
  8538. 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])) &&
  8539. (Convert.ToUInt16(textBox_MOS_R2.Text) >= Convert.ToUInt16(MOS_R2_Th[0])) && (Convert.ToUInt16(textBox_MOS_R2.Text) <= Convert.ToUInt16(MOS_R2_Th[1])) &&
  8540. (Convert.ToUInt16(textBox_MOS_R3.Text) >= Convert.ToUInt16(MOS_R3_Th[0])) && (Convert.ToUInt16(textBox_MOS_R3.Text) <= Convert.ToUInt16(MOS_R3_Th[1]))
  8541. )
  8542. {
  8543. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准合格" + "\r\n");
  8544. label_CheckModeMos.BackColor = Color.Green;
  8545. }
  8546. else
  8547. {
  8548. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准超范围" + "\r\n");
  8549. label_CheckModeStatus.Text = "存在故障!";
  8550. label_CheckModeResult.BackColor = Color.Red;
  8551. label_CheckModeResult.Text = "测试异常";
  8552. Delay_ms(500);
  8553. //存储异常并上传
  8554. CheckMode_Stop(false);
  8555. return;
  8556. }
  8557. }
  8558. else
  8559. {
  8560. label_CheckModeMos.BackColor = Color.Yellow;
  8561. label_CheckModeStatus.Text = "跳过MOS内阻校准检验";
  8562. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过MOS内阻校准检验" + "\r\n");
  8563. Delay_ms(500);
  8564. }
  8565. } while (false);
  8566. //读取位置校准参数
  8567. do
  8568. {
  8569. if (checkBox_CheckModeAngle.Checked)
  8570. {
  8571. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取位置校准数据" + "\r\n");
  8572. //发送指令读取位置
  8573. CmdRevStrTemp = "";
  8574. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
  8575. ACK_WaitCnt = 0;
  8576. while (ACK_WaitCnt <= 2) ; //1s
  8577. if (CmdRevStrTemp == string.Empty)
  8578. {
  8579. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取位置校准数据,第1次重发" + "\r\n");
  8580. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x3E00, null);
  8581. ACK_WaitCnt = 0;
  8582. while (ACK_WaitCnt <= 2) ; //1s
  8583. if (CmdRevStrTemp == string.Empty)
  8584. {
  8585. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取位置校准数据,第2次重发" + "\r\n");
  8586. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x3E00, null);
  8587. ACK_WaitCnt = 0;
  8588. while (ACK_WaitCnt <= 2) ; //1s
  8589. if (CmdRevStrTemp == string.Empty)
  8590. {
  8591. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准数据读取失败" + "\r\n");
  8592. label_CheckModeStatus.Text = "存在故障!";
  8593. label_CheckModeResult.BackColor = Color.Red;
  8594. label_CheckModeResult.Text = "测试异常";
  8595. Delay_ms(500);
  8596. //存储异常并上传
  8597. CheckMode_Stop(false);
  8598. return;
  8599. }
  8600. }
  8601. }
  8602. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准数据读取成功" + "\r\n");
  8603. //取零点数据
  8604. UInt16 AngleZero_Init = 0, AngleZero_Cur = 0;
  8605. byte[] DataArray = mySerialProcess.HexStringToBytes(CmdRevStrTemp, true);
  8606. ushort Cmd = (ushort)((DataArray[0] << 8) + DataArray[1]);
  8607. if (Cmd != 0xB420)
  8608. {
  8609. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置传感器参数错误,CMD: 0x" + Convert.ToString(Cmd, 16).PadLeft(2, '0').ToUpper() + "\r\n");
  8610. label_CheckModeStatus.Text = "存在故障!";
  8611. label_CheckModeResult.BackColor = Color.Red;
  8612. label_CheckModeResult.Text = "测试异常";
  8613. Delay_ms(500);
  8614. //存储异常并上传
  8615. CheckMode_Stop(false);
  8616. return;
  8617. }
  8618. AngleZero_Init = (ushort)((DataArray[3] << 8) + DataArray[2]);
  8619. AngleZero_Cur = (ushort)((DataArray[5] << 8) + DataArray[4]);
  8620. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置出厂零点: " + AngleZero_Init.ToString() + ",位置当前零点: " + AngleZero_Cur.ToString() + "\r\n");
  8621. int AngleZeroDiff = Math.Abs(AngleZero_Cur - AngleZero_Init);
  8622. int AngleZeroTH = Convert.ToInt32(textBox_AngleZeroTh.Text);
  8623. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置零点校准值: " + AngleZeroDiff.ToString() + ",判断阈值: " + AngleZeroTH.ToString() + "\r\n");
  8624. //判断
  8625. if (AngleZeroDiff <= AngleZeroTH)
  8626. {
  8627. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置传感器校准合格" + "\r\n");
  8628. label_CheckModeAngle.BackColor = Color.Green;
  8629. }
  8630. else
  8631. {
  8632. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置传感器校准超范围" + "\r\n");
  8633. label_CheckModeStatus.Text = "存在故障!";
  8634. label_CheckModeResult.BackColor = Color.Red;
  8635. label_CheckModeResult.Text = "测试异常";
  8636. Delay_ms(500);
  8637. //存储异常并上传
  8638. CheckMode_Stop(false);
  8639. return;
  8640. }
  8641. }
  8642. else
  8643. {
  8644. label_CheckModeAngle.BackColor = Color.Yellow;
  8645. label_CheckModeStatus.Text = "跳过位置传感器校准检验";
  8646. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过位置传感器校准检验" + "\r\n");
  8647. Delay_ms(500);
  8648. }
  8649. } while (false);
  8650. //测试合格
  8651. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  8652. label_CheckModeStatus.Text = "测试结束!";
  8653. label_CheckModeResult.BackColor = Color.Green;
  8654. label_CheckModeResult.Text = "测试合格";
  8655. Delay_ms(500);
  8656. //存储并上传
  8657. CheckMode_Stop(true);
  8658. return;
  8659. }
  8660. private void CheckModeLabelInit()
  8661. {
  8662. //测试状态标签
  8663. label_CheckModeResult.BackColor = Color.Yellow;
  8664. label_CheckModeResult.Text = "测试中";
  8665. //测试过程标签
  8666. label_CheckModeStatus.Text = "测试就绪";
  8667. //测试结果标签
  8668. foreach (Control c in groupBox31.Controls)
  8669. {
  8670. if (c is Label)
  8671. {
  8672. if (c.Text == string.Empty)
  8673. c.BackColor = Color.Red;
  8674. }
  8675. }
  8676. }
  8677. private void 调试记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  8678. {
  8679. System.Diagnostics.Process.Start("explorer.exe", Directory.GetCurrentDirectory());
  8680. }
  8681. private void 生产记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  8682. {
  8683. System.Diagnostics.Process.Start("explorer.exe", localInfo.LocalDataPath);
  8684. }
  8685. private void 累计运行时间ToolStripMenuItem_MouseHover(object sender, EventArgs e)
  8686. {
  8687. UInt32 Time = (UInt32)stopwatch.ElapsedMilliseconds / 1000;
  8688. UInt32 hour = Time / 3600;
  8689. UInt32 min = (Time % 3600) / 60;
  8690. UInt32 s = (Time % 60);
  8691. toolStripMenuItem_RunTime.Text = hour.ToString() + ":" + min.ToString("00") + ":" + s.ToString("00");
  8692. }
  8693. private void richTextBox_CheckModeLog_TextChanged(object sender, EventArgs e)
  8694. {
  8695. richTextBox_CheckModeLog.SelectionStart = richTextBox_CheckModeLog.Text.Length;
  8696. richTextBox_CheckModeLog.ScrollToCaret();
  8697. }
  8698. private void 力矩传感器检验ToolStripMenuItem_Click(object sender, EventArgs e)
  8699. {
  8700. TorqueParamsForm.ShowDialog();
  8701. }
  8702. private void textBox_CheckModeScan_KeyUp(object sender, KeyEventArgs e)
  8703. {
  8704. if (e.KeyCode == Keys.Enter)
  8705. CheckTestStart();
  8706. }
  8707. private void textBox_FacModeScan_KeyUp(object sender, KeyEventArgs e)
  8708. {
  8709. if (e.KeyCode == Keys.Enter)
  8710. TestStart();
  8711. }
  8712. private void button_SpeedDec10_Click(object sender, EventArgs e)
  8713. {
  8714. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  8715. if (Percent <= 10)
  8716. Percent = 0;
  8717. else
  8718. Percent -= 10;
  8719. //生产模式转速设置值更新
  8720. textBox_MotorSpeedPercent.Text = Percent.ToString();
  8721. //设置转速百分比
  8722. var Data = new byte[1];
  8723. Data[0] = (byte)Percent;
  8724. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  8725. }
  8726. private void button_SpeedAdd10_Click(object sender, EventArgs e)
  8727. {
  8728. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  8729. if (Percent >= 90)
  8730. Percent = 100;
  8731. else
  8732. Percent += 10;
  8733. //生产模式转速设置值更新
  8734. textBox_MotorSpeedPercent.Text = Percent.ToString();
  8735. //设置转速百分比
  8736. var Data = new byte[1];
  8737. Data[0] = (byte)Percent;
  8738. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  8739. }
  8740. private void button_SpeedDec1_Click(object sender, EventArgs e)
  8741. {
  8742. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  8743. if (Percent <= 1)
  8744. Percent = 0;
  8745. else
  8746. Percent -= 1;
  8747. //生产模式转速设置值更新
  8748. textBox_MotorSpeedPercent.Text = Percent.ToString();
  8749. //设置转速百分比
  8750. var Data = new byte[1];
  8751. Data[0] = (byte)Percent;
  8752. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  8753. }
  8754. private void button_SpeedAdd1_Click(object sender, EventArgs e)
  8755. {
  8756. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  8757. if (Percent >= 99)
  8758. Percent = 100;
  8759. else
  8760. Percent += 1;
  8761. //生产模式转速设置值更新
  8762. textBox_MotorSpeedPercent.Text = Percent.ToString();
  8763. //设置转速百分比
  8764. var Data = new byte[1];
  8765. Data[0] = (byte)Percent;
  8766. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  8767. }
  8768. bool WriteLockStatus = true;
  8769. private void pictureBox_WriteLock_Click(object sender, EventArgs e)
  8770. {
  8771. if (WriteLockStatus == true)
  8772. {
  8773. EnterForm1.ShowDialog();
  8774. try
  8775. {
  8776. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  8777. {
  8778. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  8779. {
  8780. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  8781. foreach (Control c in groupBox2.Controls)
  8782. {
  8783. if (c is CheckBox)
  8784. c.Enabled = true;
  8785. }
  8786. WriteLockStatus = !WriteLockStatus;
  8787. }
  8788. else
  8789. {
  8790. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8791. }
  8792. }
  8793. else
  8794. {
  8795. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8796. }
  8797. }
  8798. catch (Exception)
  8799. {
  8800. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8801. }
  8802. }
  8803. else
  8804. {
  8805. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  8806. foreach (Control c in groupBox2.Controls)
  8807. {
  8808. if (c is CheckBox)
  8809. c.Enabled = false;
  8810. }
  8811. WriteLockStatus = !WriteLockStatus;
  8812. }
  8813. }
  8814. bool ReadLockStatus = true;
  8815. private void pictureBox_ReadLock_Click(object sender, EventArgs e)
  8816. {
  8817. if (ReadLockStatus == true)
  8818. {
  8819. EnterForm1.ShowDialog();
  8820. try
  8821. {
  8822. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  8823. {
  8824. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  8825. {
  8826. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  8827. foreach (Control c in groupBox29.Controls)
  8828. {
  8829. if (c is CheckBox)
  8830. c.Enabled = true;
  8831. }
  8832. ReadLockStatus = !ReadLockStatus;
  8833. }
  8834. else
  8835. {
  8836. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8837. }
  8838. }
  8839. else
  8840. {
  8841. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8842. }
  8843. }
  8844. catch (Exception)
  8845. {
  8846. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8847. }
  8848. }
  8849. else
  8850. {
  8851. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  8852. foreach (Control c in groupBox29.Controls)
  8853. {
  8854. if (c is CheckBox)
  8855. c.Enabled = false;
  8856. }
  8857. ReadLockStatus = !ReadLockStatus;
  8858. }
  8859. }
  8860. private void 屏幕键盘ToolStripMenuItem_Click(object sender, EventArgs e)
  8861. {
  8862. System.Diagnostics.Process.Start("osk.exe");
  8863. }
  8864. private void checkBox_OffLineCheckMode_CheckedChanged(object sender, EventArgs e)
  8865. {
  8866. comboBox_CheckModeCfgDate.SelectedIndex = -1;
  8867. comboBox_CheckModeCfgFile.SelectedIndex = -1;
  8868. checkBox_OffLineFacMode.Checked = checkBox_OffLineCheckMode.Checked;
  8869. }
  8870. private void checkBox_OffLineFacMode_CheckedChanged(object sender, EventArgs e)
  8871. {
  8872. comboBox_FacModeCfgDate.SelectedIndex = -1;
  8873. comboBox_FacModeCfgFile.SelectedIndex = -1;
  8874. checkBox_OffLineCheckMode.Checked = checkBox_OffLineFacMode.Checked;
  8875. }
  8876. private void 版本ToolStripMenuItem_Click(object sender, EventArgs e)
  8877. {
  8878. VersionForm.ShowDialog();
  8879. }
  8880. private void button_MOS_Cal_Click(object sender, EventArgs e)
  8881. {
  8882. textBox_MOS_R1.Text = "";
  8883. textBox_MOS_R2.Text = "";
  8884. textBox_MOS_R3.Text = "";
  8885. try
  8886. {
  8887. var Code = new byte[18];
  8888. for (int i = 0; i < 18; i++)
  8889. Code[i] = 0;
  8890. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  8891. ushort uwDataTemp = 0;
  8892. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  8893. Code[2] = (byte)(uwDataTemp & 0xFF);
  8894. Code[3] = (byte)(uwDataTemp >> 8);
  8895. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  8896. Code[4] = (byte)(uwDataTemp & 0xFF);
  8897. Code[5] = (byte)(uwDataTemp >> 8);
  8898. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  8899. Code[6] = (byte)(uwDataTemp & 0xFF);
  8900. Code[7] = (byte)(uwDataTemp >> 8);
  8901. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  8902. Code[8] = (byte)(uwDataTemp & 0xFF);
  8903. Code[9] = (byte)(uwDataTemp >> 8);
  8904. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  8905. Code[10] = (byte)(uwDataTemp & 0xFF);
  8906. Code[11] = (byte)(uwDataTemp >> 8);
  8907. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  8908. }
  8909. catch (Exception)
  8910. {
  8911. MessageBox.Show("系数填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8912. }
  8913. }
  8914. private void button_MOS_Read_Click(object sender, EventArgs e)
  8915. {
  8916. foreach (Control c in groupBox21.Controls)
  8917. {
  8918. if (c is TextBox)
  8919. c.Text = "";
  8920. }
  8921. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8922. }
  8923. private void button_MOS_Write_Click(object sender, EventArgs e)
  8924. {
  8925. try
  8926. {
  8927. var Code = new byte[34];
  8928. for (int i = 0; i < 34; i++)
  8929. Code[i] = 0;
  8930. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  8931. ushort uwDataTemp = 0;
  8932. uwDataTemp = Convert.ToUInt16(textBox_MOS_R1.Text);
  8933. Code[2] = (byte)(uwDataTemp & 0xFF);
  8934. Code[3] = (byte)(uwDataTemp >> 8);
  8935. uwDataTemp = Convert.ToUInt16(textBox_MOS_R2.Text);
  8936. Code[4] = (byte)(uwDataTemp & 0xFF);
  8937. Code[5] = (byte)(uwDataTemp >> 8);
  8938. uwDataTemp = Convert.ToUInt16(textBox_MOS_R3.Text);
  8939. Code[6] = (byte)(uwDataTemp & 0xFF);
  8940. Code[7] = (byte)(uwDataTemp >> 8);
  8941. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  8942. Code[8] = (byte)(uwDataTemp & 0xFF);
  8943. Code[9] = (byte)(uwDataTemp >> 8);
  8944. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  8945. Code[10] = (byte)(uwDataTemp & 0xFF);
  8946. Code[11] = (byte)(uwDataTemp >> 8);
  8947. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  8948. Code[12] = (byte)(uwDataTemp & 0xFF);
  8949. Code[13] = (byte)(uwDataTemp >> 8);
  8950. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  8951. Code[14] = (byte)(uwDataTemp & 0xFF);
  8952. Code[15] = (byte)(uwDataTemp >> 8);
  8953. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  8954. Code[16] = (byte)(uwDataTemp & 0xFF);
  8955. Code[17] = (byte)(uwDataTemp >> 8);
  8956. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4C22, Code);
  8957. }
  8958. catch (Exception)
  8959. {
  8960. MessageBox.Show("数据填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8961. }
  8962. }
  8963. /// <summary>
  8964. /// 测试模式点击文本框自动全选
  8965. /// </summary>
  8966. /// <param name="sender"></param>
  8967. /// <param name="e"></param>
  8968. private void textBox_FacModeScan_MouseClick(object sender, MouseEventArgs e)
  8969. {
  8970. textBox_FacModeScan.SelectAll();
  8971. }
  8972. /// <summary>
  8973. /// 检验模式点击文本框自动全选
  8974. /// </summary>
  8975. /// <param name="sender"></param>
  8976. /// <param name="e"></param>
  8977. private void textBox_CheckModeScan_MouseClick(object sender, MouseEventArgs e)
  8978. {
  8979. textBox_CheckModeScan.SelectAll();
  8980. }
  8981. /// <summary>
  8982. /// 鼠标放置显示连接服务器信息
  8983. /// </summary>
  8984. /// <param name="sender"></param>
  8985. /// <param name="e"></param>
  8986. private void label_ServerStatus_MouseHover(object sender, EventArgs e)
  8987. {
  8988. // 创建the ToolTip
  8989. ToolTip toolTip1 = new ToolTip();
  8990. // 设置显示样式
  8991. toolTip1.AutoPopDelay = 30000;//提示信息的可见时间
  8992. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  8993. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  8994. toolTip1.ShowAlways = true;//是否显示提示框
  8995. if (myFtp.IsNetConnected)
  8996. {
  8997. toolTip1.SetToolTip(this.label_ServerStatus, "IP: " + ServerIP);//设置故障内容显示
  8998. }
  8999. else
  9000. {
  9001. toolTip1.SetToolTip(this.label_ServerStatus, "网络断开");//设置故障内容显示
  9002. }
  9003. }
  9004. /// <summary>
  9005. /// UART协议类型修改
  9006. /// </summary>
  9007. /// <param name="sender"></param>
  9008. /// <param name="e"></param>
  9009. private void 协议类型ToolStripMenuItem_SelectedIndexChanged(object sender, EventArgs e)
  9010. {
  9011. var Code = new byte[2];
  9012. Code[0] = (byte)协议类型ToolStripMenuItem.SelectedIndex;
  9013. Code[1] = 0x00;
  9014. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  9015. }
  9016. /// <summary>
  9017. /// 显示本机信息
  9018. /// </summary>
  9019. /// <param name="sender"></param>
  9020. /// <param name="e"></param>
  9021. private void 本机信息ToolStripMenuItem_Click(object sender, EventArgs e)
  9022. {
  9023. MessageBox.Show(Local_HdInformation, "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
  9024. }
  9025. /// <summary>
  9026. /// 量产模式删除当前选中文件
  9027. /// </summary>
  9028. /// <param name="sender"></param>
  9029. /// <param name="e"></param>
  9030. private void label112_DoubleClick(object sender, EventArgs e)
  9031. {
  9032. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9033. {
  9034. EnterForm1.ShowDialog();
  9035. try
  9036. {
  9037. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9038. {
  9039. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  9040. {
  9041. try
  9042. {
  9043. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + comboBox_FacModeCfgFile.Text);
  9044. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_FacModeCfgFile.Text) + ".src");
  9045. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_FacModeCfgFile.Text) + ".png");
  9046. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9047. }
  9048. catch (Exception)
  9049. {
  9050. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9051. }
  9052. }
  9053. else
  9054. {
  9055. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9056. }
  9057. }
  9058. }
  9059. catch (Exception)
  9060. {
  9061. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9062. }
  9063. }
  9064. }
  9065. /// <summary>
  9066. /// 检验模式删除当前选中文件
  9067. /// </summary>
  9068. /// <param name="sender"></param>
  9069. /// <param name="e"></param>
  9070. private void label138_DoubleClick(object sender, EventArgs e)
  9071. {
  9072. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9073. {
  9074. EnterForm1.ShowDialog();
  9075. try
  9076. {
  9077. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9078. {
  9079. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  9080. {
  9081. try
  9082. {
  9083. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + comboBox_CheckModeCfgFile.Text);
  9084. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_CheckModeCfgFile.Text) + ".src");
  9085. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_CheckModeCfgFile.Text) + ".png");
  9086. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9087. }
  9088. catch (Exception)
  9089. {
  9090. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9091. }
  9092. }
  9093. else
  9094. {
  9095. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9096. }
  9097. }
  9098. }
  9099. catch (Exception)
  9100. {
  9101. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9102. }
  9103. }
  9104. }
  9105. /// <summary>
  9106. /// 读取整车信息2
  9107. /// </summary>
  9108. /// <param name="sender"></param>
  9109. /// <param name="e"></param>
  9110. private void button_ReadBikeParam2_Click(object sender, EventArgs e)
  9111. {
  9112. richTextBox_BikeParam2.Clear();
  9113. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null);
  9114. }
  9115. /// <summary>
  9116. /// 写入整车信息2
  9117. /// </summary>
  9118. /// <param name="sender"></param>
  9119. /// <param name="e"></param>
  9120. private void button_WriteBikeParam2_Click(object sender, EventArgs e)
  9121. {
  9122. var ConfigParam = new byte[34];
  9123. for (int i = 0; i < 34; i++)
  9124. ConfigParam[i] = 0;
  9125. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  9126. string[] strDataTemp = richTextBox_BikeParam2.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  9127. try
  9128. {
  9129. for (int i = 0; i < strDataTemp.Length; i++)
  9130. {
  9131. short wDataTemp = 0;
  9132. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  9133. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  9134. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  9135. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  9136. }
  9137. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4D22, ConfigParam);
  9138. }
  9139. catch (Exception)
  9140. {
  9141. timer_500ms.Enabled = false;
  9142. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9143. timer_500ms.Enabled = true;
  9144. }
  9145. }
  9146. /// <summary>
  9147. /// 读取用户骑行参数
  9148. /// </summary>
  9149. /// <param name="sender"></param>
  9150. /// <param name="e"></param>
  9151. private void button_ReadUsrRideParam_Click(object sender, EventArgs e)
  9152. {
  9153. richTextBox_UsrRidesParam.Clear();
  9154. if (checkBox_UserRideParam_OBC.Checked)
  9155. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x4300, null);
  9156. else
  9157. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  9158. }
  9159. /// <summary>
  9160. /// 写入用户骑行参数
  9161. /// </summary>
  9162. /// <param name="sender"></param>
  9163. /// <param name="e"></param>
  9164. private void button_WriteUsrRidetParam_Click(object sender, EventArgs e)
  9165. {
  9166. var ConfigParam = new byte[34];
  9167. for (int i = 0; i < 34; i++)
  9168. ConfigParam[i] = 0;
  9169. if (checkBox_UserRideParam_OBC.Checked)
  9170. {
  9171. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  9172. string[] strDataTemp = richTextBox_UsrRidesParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  9173. try
  9174. {
  9175. for (int i = 0; i < strDataTemp.Length; i++)
  9176. {
  9177. ConfigParam[i + 2] = Convert.ToByte(strDataTemp[i].Split('=')[1]);
  9178. }
  9179. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4B22, ConfigParam);
  9180. }
  9181. catch (Exception)
  9182. {
  9183. timer_500ms.Enabled = false;
  9184. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9185. timer_500ms.Enabled = true;
  9186. }
  9187. }
  9188. else
  9189. {
  9190. string[] strDataTemp = richTextBox_UsrRidesParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  9191. try
  9192. {
  9193. for (int i = 0; i < strDataTemp.Length; i++)
  9194. {
  9195. ConfigParam[i] = Convert.ToByte(strDataTemp[i].Split('=')[1]);
  9196. }
  9197. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x4420, ConfigParam);
  9198. }
  9199. catch (Exception)
  9200. {
  9201. timer_500ms.Enabled = false;
  9202. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9203. timer_500ms.Enabled = true;
  9204. }
  9205. }
  9206. }
  9207. /// <summary>
  9208. /// 读取产品标签
  9209. /// </summary>
  9210. /// <param name="sender"></param>
  9211. /// <param name="e"></param>
  9212. private void button_ReadTag_Click(object sender, EventArgs e)
  9213. {
  9214. textBox_TagInfo.Text = "---";
  9215. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4E00, null);
  9216. }
  9217. /// <summary>
  9218. /// 写入产品标签
  9219. /// </summary>
  9220. /// <param name="sender"></param>
  9221. /// <param name="e"></param>
  9222. private void button_WriteTag_Click(object sender, EventArgs e)
  9223. {
  9224. string User = textBox_TagInfo.Text;
  9225. var UserArray = new byte[32];
  9226. for (ushort i = 0; i < User.Length; i++)
  9227. {
  9228. UserArray[i] = (byte)User[i];
  9229. }
  9230. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D20, UserArray);
  9231. }
  9232. /// <summary>
  9233. /// 上位机读取骑行历史
  9234. /// </summary>
  9235. /// <param name="sender"></param>
  9236. /// <param name="e"></param>
  9237. private void button_ReadRideLog_Click(object sender, EventArgs e)
  9238. {
  9239. textBox_ODO_KM.Text = "---";
  9240. textBox_ODO_TIME.Text = "---";
  9241. textBox_TRIP_KM.Text = "---";
  9242. textBox_TRIP_TIME.Text = "---";
  9243. textBox_OBC_TRIP_KM.Text = "";
  9244. textBox_OBC_TRIP_TIME.Text = "";
  9245. textBox_OBC_ODO_KM.Text = "";
  9246. textBox_OBC_ODO_TIME.Text = "";
  9247. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2E00, null);
  9248. }
  9249. /// <summary>
  9250. /// 上位机写入骑行历史
  9251. /// </summary>
  9252. /// <param name="sender"></param>
  9253. /// <param name="e"></param>
  9254. private void button_WriteRideLog_Click(object sender, EventArgs e)
  9255. {
  9256. UInt32 Data;
  9257. var UserArray = new byte[16];
  9258. try
  9259. {
  9260. Data = Convert.ToUInt32(textBox_ODO_KM.Text);
  9261. UserArray[0] = (byte)(Data & 0xFF);
  9262. UserArray[1] = (byte)(Data >> 8);
  9263. UserArray[2] = (byte)(Data >> 16);
  9264. UserArray[3] = (byte)(Data >> 24);
  9265. Data = Convert.ToUInt32(textBox_ODO_TIME.Text);
  9266. UserArray[4] = (byte)(Data & 0xFF);
  9267. UserArray[5] = (byte)(Data >> 8);
  9268. UserArray[6] = (byte)(Data >> 16);
  9269. UserArray[7] = (byte)(Data >> 24);
  9270. Data = Convert.ToUInt32(textBox_TRIP_KM.Text);
  9271. UserArray[8] = (byte)(Data & 0xFF);
  9272. UserArray[9] = (byte)(Data >> 8);
  9273. UserArray[10] = (byte)(Data >> 16);
  9274. UserArray[11] = (byte)(Data >> 24);
  9275. Data = Convert.ToUInt32(textBox_TRIP_TIME.Text);
  9276. UserArray[12] = (byte)(Data & 0xFF);
  9277. UserArray[13] = (byte)(Data >> 8);
  9278. UserArray[14] = (byte)(Data >> 16);
  9279. UserArray[15] = (byte)(Data >> 24);
  9280. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B10, UserArray);
  9281. }
  9282. catch (Exception ex)
  9283. {
  9284. MessageBox.Show("数据格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9285. }
  9286. }
  9287. /// <summary>
  9288. /// 获取删除配置文件日期列表
  9289. /// </summary>
  9290. /// <param name="sender"></param>
  9291. /// <param name="e"></param>
  9292. private void toolStripTextBox_DelCfgFile_Click(object sender, EventArgs e)
  9293. {
  9294. string[] DateList = { "" };
  9295. //网络断开时直接退出
  9296. if (!myFtp.IsNetConnected)
  9297. return;
  9298. //从服务器更新日期列表
  9299. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
  9300. toolStripTextBox_DelCfgFile.Items.Clear();
  9301. //日期列表加载,显示最近30条
  9302. if (DateList.Length > 30)
  9303. {
  9304. toolStripTextBox_DelCfgFile.Items.Add("支持最近30条");
  9305. toolStripTextBox_DelCfgFile.Items.Add("-----");
  9306. }
  9307. for (int i = (DateList.Length > 30) ? (DateList.Length - 30) : 0; i < DateList.Length; i++)//显示最近30个日期
  9308. {
  9309. toolStripTextBox_DelCfgFile.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  9310. }
  9311. }
  9312. /// <summary>
  9313. /// 删除指定配置文件
  9314. /// </summary>
  9315. /// <param name="sender"></param>
  9316. /// <param name="e"></param>
  9317. private void toolStripTextBox_DelCfgFile_SelectedIndexChanged(object sender, EventArgs e)
  9318. {
  9319. //提示输入文件名
  9320. Scan scan_form = new Scan();
  9321. scan_form.ShowDialog();
  9322. do
  9323. {
  9324. if (scan_form.textBox_Scan.Text == string.Empty)
  9325. {
  9326. timer_500ms.Enabled = false;
  9327. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9328. timer_500ms.Enabled = true;
  9329. break;
  9330. }
  9331. string DelFile = scan_form.textBox_Scan.Text;
  9332. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9333. {
  9334. EnterForm1.ShowDialog();
  9335. try
  9336. {
  9337. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9338. {
  9339. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  9340. {
  9341. try
  9342. {
  9343. if (DelFile.Contains("."))
  9344. DelFile = Path.GetFileNameWithoutExtension(DelFile);
  9345. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".ttcfg");
  9346. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".src");
  9347. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".png");
  9348. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9349. }
  9350. catch (Exception)
  9351. {
  9352. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9353. }
  9354. }
  9355. else
  9356. {
  9357. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9358. }
  9359. }
  9360. }
  9361. catch (Exception)
  9362. {
  9363. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9364. }
  9365. }
  9366. } while (false);
  9367. }
  9368. /// <summary>
  9369. /// 获取删除样机测试记录日期列表
  9370. /// </summary>
  9371. /// <param name="sender"></param>
  9372. /// <param name="e"></param>
  9373. private void toolStripTextBox_DelLogFile_Click(object sender, EventArgs e)
  9374. {
  9375. string[] DateList = { "" };
  9376. //网络断开时直接退出
  9377. if (!myFtp.IsNetConnected)
  9378. return;
  9379. //从服务器更新日期列表
  9380. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName);
  9381. toolStripTextBox_DelLogFile.Items.Clear();
  9382. //日期列表加载,显示最近30天
  9383. if (DateList.Length > 30)
  9384. {
  9385. toolStripTextBox_DelLogFile.Items.Add("支持最近30条");
  9386. toolStripTextBox_DelLogFile.Items.Add("-----");
  9387. }
  9388. for (int i = (DateList.Length > 30) ? (DateList.Length - 30) : 0; i < DateList.Length; i++)//显示最近30个日期
  9389. {
  9390. toolStripTextBox_DelLogFile.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  9391. }
  9392. }
  9393. /// <summary>
  9394. /// 删除指定的样机测试记录
  9395. /// </summary>
  9396. /// <param name="sender"></param>
  9397. /// <param name="e"></param>
  9398. private void toolStripTextBox_DelLogFile_SelectedIndexChanged(object sender, EventArgs e)
  9399. {
  9400. //提示输入文件名
  9401. Scan scan_form = new Scan();
  9402. scan_form.ShowDialog();
  9403. do
  9404. {
  9405. if (scan_form.textBox_Scan.Text == string.Empty)
  9406. {
  9407. timer_500ms.Enabled = false;
  9408. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9409. timer_500ms.Enabled = true;
  9410. break;
  9411. }
  9412. string DelFile = scan_form.textBox_Scan.Text;
  9413. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9414. {
  9415. EnterForm1.ShowDialog();
  9416. try
  9417. {
  9418. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9419. {
  9420. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  9421. {
  9422. try
  9423. {
  9424. //删除指定目录下面所有文件和文件夹
  9425. myFtp.DelDirectoryWithAll(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName + "\\" + toolStripTextBox_DelLogFile.Text + "\\" + DelFile);
  9426. myFtp.RemoveDirectory(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName + "\\" + toolStripTextBox_DelLogFile.Text + "\\" + DelFile);
  9427. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9428. }
  9429. catch (Exception)
  9430. {
  9431. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9432. }
  9433. }
  9434. else
  9435. {
  9436. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9437. }
  9438. }
  9439. }
  9440. catch (Exception)
  9441. {
  9442. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9443. }
  9444. }
  9445. } while (false);
  9446. }
  9447. /// <summary>
  9448. /// CAN协议选择
  9449. /// </summary>
  9450. /// <param name="sender"></param>
  9451. /// <param name="e"></param>
  9452. private void cANToolStripMenuItem_Click(object sender, EventArgs e)
  9453. {
  9454. cANToolStripMenuItem.Checked= true;
  9455. uARTToolStripMenuItem.Checked = false;
  9456. UART协议ToolStripMenuItem.Visible = false;
  9457. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9458. }
  9459. /// <summary>
  9460. /// UART协议选择
  9461. /// </summary>
  9462. /// <param name="sender"></param>
  9463. /// <param name="e"></param>
  9464. private void uARTToolStripMenuItem_Click(object sender, EventArgs e)
  9465. {
  9466. cANToolStripMenuItem.Checked = false;
  9467. uARTToolStripMenuItem.Checked = true;
  9468. UART协议ToolStripMenuItem.Visible = true;
  9469. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9470. }
  9471. /// <summary>
  9472. /// 清除流水号
  9473. /// </summary>
  9474. /// <param name="sender"></param>
  9475. /// <param name="e"></param>
  9476. private void label131_DoubleClick(object sender, EventArgs e)
  9477. {
  9478. if (MessageBox.Show("确认清零流水号?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9479. {
  9480. label_FacModeSerial.Text = "0";
  9481. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, label_FacModeSerial.Text);
  9482. }
  9483. }
  9484. /// <summary>
  9485. /// 清除流水号
  9486. /// </summary>
  9487. /// <param name="sender"></param>
  9488. /// <param name="e"></param>
  9489. private void label135_DoubleClick(object sender, EventArgs e)
  9490. {
  9491. if (MessageBox.Show("确认清零流水号?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9492. {
  9493. label_CheckModeSerial.Text = "0";
  9494. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, label_CheckModeSerial.Text);
  9495. }
  9496. }
  9497. /// <summary>
  9498. /// 打开自动更新
  9499. /// </summary>
  9500. /// <param name="sender"></param>
  9501. /// <param name="e"></param>
  9502. private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
  9503. {
  9504. 打开ToolStripMenuItem.Checked = true;
  9505. 关闭ToolStripMenuItem.Checked = false;
  9506. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9507. }
  9508. /// <summary>
  9509. /// 关闭自动更新
  9510. /// </summary>
  9511. /// <param name="sender"></param>
  9512. /// <param name="e"></param>
  9513. private void 关闭ToolStripMenuItem_Click(object sender, EventArgs e)
  9514. {
  9515. 打开ToolStripMenuItem.Checked = false;
  9516. 关闭ToolStripMenuItem.Checked = true;
  9517. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9518. }
  9519. /// <summary>
  9520. /// 显示完整配置文件
  9521. /// </summary>
  9522. /// <param name="sender"></param>
  9523. /// <param name="e"></param>
  9524. private void comboBox_FacModeCfgFile_MouseHover_1(object sender, EventArgs e)
  9525. {
  9526. // 创建the ToolTip
  9527. ToolTip toolTip1 = new ToolTip();
  9528. // 设置显示样式
  9529. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  9530. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  9531. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  9532. toolTip1.ShowAlways = true;//是否显示提示框
  9533. // 设置伴随的对象.
  9534. toolTip1.SetToolTip(this.comboBox_FacModeCfgFile, comboBox_FacModeCfgFile.Text);//设置故障内容显示
  9535. }
  9536. /// <summary>
  9537. /// 显示完整配置文件
  9538. /// </summary>
  9539. /// <param name="sender"></param>
  9540. /// <param name="e"></param>
  9541. private void comboBox_CheckModeCfgFile_MouseHover_1(object sender, EventArgs e)
  9542. {
  9543. // 创建the ToolTip
  9544. ToolTip toolTip1 = new ToolTip();
  9545. // 设置显示样式
  9546. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  9547. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  9548. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  9549. toolTip1.ShowAlways = true;//是否显示提示框
  9550. // 设置伴随的对象.
  9551. toolTip1.SetToolTip(this.comboBox_CheckModeCfgFile, comboBox_CheckModeCfgFile.Text);//设置故障内容显示
  9552. }
  9553. /// <summary>
  9554. /// 手动发送指令
  9555. /// </summary>
  9556. /// <param name="sender"></param>
  9557. /// <param name="e"></param>
  9558. private void 发送指令ToolStripMenuItem_Click(object sender, EventArgs e)
  9559. {
  9560. //提示
  9561. Scan scan_form = new Scan();
  9562. scan_form.label1.Text = "按照16进制填写,相邻字节用空格隔开,依次填写ID、Mode、Cmd、Data\r\n例如:07 31 16 22 05 01 02 03 04 05";
  9563. scan_form.ShowDialog();
  9564. //发送写入的指令,填写ID、类型、命令字、数据
  9565. do
  9566. {
  9567. if (scan_form.textBox_Scan.Text == string.Empty)
  9568. {
  9569. timer_500ms.Enabled = false;
  9570. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9571. timer_500ms.Enabled = true;
  9572. break;
  9573. }
  9574. //输入文本转换为字节流
  9575. var InputData = new byte[256];
  9576. InputData = mySerialProcess.HexStringToBytes(scan_form.textBox_Scan.Text, true);
  9577. //ID
  9578. ushort ID;
  9579. ID = (ushort)((InputData[0] << 8) + InputData[1]);
  9580. //Mode
  9581. byte Mode;
  9582. Mode = InputData[2];
  9583. //Cmd
  9584. ushort Cmd;
  9585. Cmd = (ushort)((InputData[3] << 8) + InputData[4]);
  9586. //Data
  9587. var Data = new byte[Cmd & 0x00FF];
  9588. for (int i = 0; i < (Cmd & 0x00FF); i++)
  9589. Data[i] = InputData[5 + i];
  9590. //发送数据
  9591. mySerialProcess.SendCmdWithoutNotice(ID, Mode, Cmd, Data);
  9592. } while (false);
  9593. }
  9594. /// <summary>
  9595. /// 启动位置传感器校准
  9596. /// </summary>
  9597. /// <param name="sender"></param>
  9598. /// <param name="e"></param>
  9599. private void button_AngleCalStart_Click(object sender, EventArgs e)
  9600. {
  9601. for (int i = 0; i < 7; i++)
  9602. for (int j = 0; j < 6; j++)
  9603. {
  9604. dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = "";
  9605. }
  9606. foreach (Control cr in tabPage_AngleCal.Controls)
  9607. {
  9608. if (cr is TextBox)
  9609. {
  9610. if ((cr != textBox_AngleDiffTh) && (cr != textBox_AngleZeroTh))
  9611. cr.Text = "";
  9612. }
  9613. }
  9614. var Data = new byte[2];
  9615. mySerialProcess.SendCmd((ushort)0x751, (byte)0x0C, (ushort)0x5002, Data);
  9616. }
  9617. /// <summary>
  9618. /// 导出位置传感器校准数据
  9619. /// </summary>
  9620. /// <param name="sender"></param>
  9621. /// <param name="e"></param>
  9622. private void button_AngleExportData_Click(object sender, EventArgs e)
  9623. {
  9624. //读出产品信息
  9625. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  9626. Delay_ms(200);
  9627. SaveFileDialog sfd = new SaveFileDialog
  9628. {
  9629. FileName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + "位置传感器角度数据_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt",
  9630. Filter = "文本文档(*.txt)|*.txt",
  9631. Title = "Save"
  9632. };
  9633. if (sfd.ShowDialog() != DialogResult.OK)
  9634. {
  9635. return;
  9636. }
  9637. string filepath = sfd.FileName;
  9638. FileStream fs = new FileStream(filepath, FileMode.OpenOrCreate);
  9639. using (StreamWriter sw = new StreamWriter(fs))
  9640. {
  9641. sw.Write("标准值 ");
  9642. sw.Write("60.00 ");
  9643. sw.Write("120.00 ");
  9644. sw.Write("180.00 ");
  9645. sw.Write("240.00 ");
  9646. sw.Write("300.00 ");
  9647. sw.Write("360.00 ");
  9648. for (int i = 0; i < 42; i++)
  9649. {
  9650. if ((i % 6 == 0))
  9651. {
  9652. sw.Write("\r\n" + "采集值" + (i / 6 + 1).ToString() + " ");
  9653. }
  9654. sw.Write(AngledataRecord[i] + " ");
  9655. }
  9656. sw.Write("\r\n" + "历史零点位置 " + textBox_AngleZeroInit.Text);
  9657. sw.Write("\r\n" + "当前零点位置 " + textBox_AngleZeroCur.Text);
  9658. sw.Write("\r\n" + "零点误差 " + textBox_AngleZeroDiff.Text);
  9659. sw.Write("\r\n" + "最小偏差值 " + textBox_AngleDiffMin.Text);
  9660. sw.Write("\r\n" + "最大偏差值 " + textBox_AngleDiffMax.Text);
  9661. sw.Write("\r\n" + "平均偏差值 " + textBox_AngleDiffAvg.Text);
  9662. sw.Flush();
  9663. }
  9664. fs.Close();
  9665. }
  9666. /// <summary>
  9667. /// 写入校准数据
  9668. /// </summary>
  9669. /// <param name="sender"></param>
  9670. /// <param name="e"></param>
  9671. private void button_AngleWrite_Click(object sender, EventArgs e)
  9672. {
  9673. if ((textBox_AngleDiffAvg.Text == "") || (textBox_AngleZeroInit.Text == ""))
  9674. {
  9675. timer_500ms.Enabled = false;
  9676. MessageBox.Show("请先启动校准,以确认校准数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9677. timer_500ms.Enabled = true;
  9678. return;
  9679. }
  9680. timer_500ms.Enabled = false;
  9681. string str1 = "确认校准数据,历史零点: " + textBox_AngleZeroInit.Text + ", 偏差平均值: " + textBox_AngleDiffAvg.Text;
  9682. if (MessageBox.Show(str1, "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9683. {
  9684. var SaveFlag = new byte[4];
  9685. for (int i = 0; i < 4; i++)
  9686. SaveFlag[i] = 0;
  9687. SaveFlag[0] = (byte)(1);
  9688. double data1 = Convert.ToDouble(textBox_AngleZeroInit.Text) - Convert.ToDouble(textBox_AngleDiffAvg.Text);
  9689. if (data1 > 360)
  9690. {
  9691. data1 -= 360;
  9692. }
  9693. else if (data1 < -360)
  9694. {
  9695. data1 += 360;
  9696. }
  9697. Int16 data2 = (Int16)(data1 * 32768 / 360);
  9698. SaveFlag[2] = (byte)(data2);
  9699. SaveFlag[3] = (byte)(data2 >> 8);
  9700. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, SaveFlag);
  9701. }
  9702. else
  9703. MessageBoxTimeOut.Show("写入取消", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9704. timer_500ms.Enabled = true;
  9705. }
  9706. /// <summary>
  9707. /// 存储允许偏差
  9708. /// </summary>
  9709. /// <param name="sender"></param>
  9710. /// <param name="e"></param>
  9711. private void textBox_AngleDiffTh_KeyDown(object sender, KeyEventArgs e)
  9712. {
  9713. if (e.KeyCode == Keys.Enter)
  9714. {
  9715. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9716. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  9717. }
  9718. }
  9719. /// <summary>
  9720. /// 存储零点允许偏差
  9721. /// </summary>
  9722. /// <param name="sender"></param>
  9723. /// <param name="e"></param>
  9724. private void textBox_AngleZeroTh_KeyDown(object sender, KeyEventArgs e)
  9725. {
  9726. if (e.KeyCode == Keys.Enter)
  9727. {
  9728. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9729. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  9730. }
  9731. }
  9732. /// <summary>
  9733. /// 删除服务器配置文件
  9734. /// </summary>
  9735. /// <param name="sender"></param>
  9736. /// <param name="e"></param>
  9737. private void 重置ToolStripMenuItem_Click(object sender, EventArgs e)
  9738. {
  9739. if (MessageBox.Show("重置后软件自动关闭,确认重置?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9740. {
  9741. if(File.Exists(localInfo.LocalPath + localInfo.ServerCfgFileName))
  9742. File.Delete(localInfo.LocalPath + localInfo.ServerCfgFileName);
  9743. if(File.Exists(localInfo.LocalPath + localInfo.ConfigFileName))
  9744. File.Delete(localInfo.LocalPath + localInfo.ConfigFileName);
  9745. System.Environment.Exit(0);
  9746. }
  9747. }
  9748. /// <summary>
  9749. /// 按下Enter保存数据
  9750. /// </summary>
  9751. /// <param name="sender"></param>
  9752. /// <param name="e"></param>
  9753. private void toolStripTextBox_AngleAvgMax_KeyDown(object sender, KeyEventArgs e)
  9754. {
  9755. textBox_AngleDiffTh.Text = toolStripTextBox_AngleAvgMax.Text;
  9756. if (e.KeyCode == Keys.Enter)
  9757. {
  9758. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9759. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  9760. }
  9761. }
  9762. /// <summary>
  9763. /// 按下Enter保存数据
  9764. /// </summary>
  9765. /// <param name="sender"></param>
  9766. /// <param name="e"></param>
  9767. private void toolStripTextBox_AngleZeroMax_KeyDown(object sender, KeyEventArgs e)
  9768. {
  9769. textBox_AngleZeroTh.Text = toolStripTextBox_AngleZeroMax.Text;
  9770. if (e.KeyCode == Keys.Enter)
  9771. {
  9772. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9773. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  9774. }
  9775. }
  9776. private void 帮助ToolStripMenuItem_Click(object sender, EventArgs e)
  9777. {
  9778. //检查本地文件
  9779. if (!File.Exists(localInfo.LocalPath + localInfo.HelpFilename))
  9780. {
  9781. if (!OfflineFlag)
  9782. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/help/" + localInfo.HelpFilename, localInfo.LocalPath);
  9783. else
  9784. {
  9785. MessageBoxTimeOut.Show("未找到帮助文件!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9786. return;
  9787. }
  9788. }
  9789. //调用本地浏览器打开帮助文件
  9790. System.Diagnostics.Process.Start("explorer", localInfo.LocalPath + localInfo.HelpFilename);
  9791. }
  9792. /// <summary>
  9793. /// 打开或关闭指令窗口
  9794. /// </summary>
  9795. /// <param name="sender"></param>
  9796. /// <param name="e"></param>
  9797. private void 指令调试ToolStripMenuItem_Click(object sender, EventArgs e)
  9798. {
  9799. if (指令调试ToolStripMenuItem.Checked == false)
  9800. {
  9801. if (DebugForm.debug1 == null || DebugForm.debug1.IsDisposed)
  9802. {
  9803. DebugForm.debug1 = new DebugForm();
  9804. DebugForm.debug1.Show();
  9805. this.DebugWindowIsOpen = true;
  9806. }
  9807. else
  9808. {
  9809. DebugForm.debug1.Activate();
  9810. this.DebugWindowIsOpen = true;
  9811. }
  9812. 指令调试ToolStripMenuItem.Checked = true;
  9813. }
  9814. else
  9815. {
  9816. if (this.DebugWindowIsOpen == true)
  9817. {
  9818. DebugForm.debug1.Close();
  9819. this.DebugWindowIsOpen = false;
  9820. this.DebugDataDisplayEnable = false;
  9821. }
  9822. 指令调试ToolStripMenuItem.Checked = false;
  9823. }
  9824. }
  9825. }
  9826. }